2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/../core.php';
|
|
|
|
|
|
|
|
$updateRate = 20;
|
2017-08-31 10:09:06 +02:00
|
|
|
$scriptValue = $updateRate * 5;
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Aggiornamento tramite AJAX
|
|
|
|
*/
|
|
|
|
if (filter('action') == 'do_update') {
|
|
|
|
// Aggiornamento in progresso
|
|
|
|
if (Update::isUpdateAvailable()) {
|
|
|
|
$update = Update::getUpdate();
|
|
|
|
|
|
|
|
$result = Update::doUpdate($updateRate);
|
|
|
|
|
|
|
|
if (!empty($result)) {
|
|
|
|
// Aggiunta del messaggio generico riguardante l'aggiornamento
|
|
|
|
echo '
|
|
|
|
<script>
|
|
|
|
addVersion("'.$update['version'].'");
|
|
|
|
</script>';
|
|
|
|
|
|
|
|
if (is_array($result)) {
|
|
|
|
// Aggiunta del messaggio riguardante la conclusione dell'aggiornamento del database
|
|
|
|
if (!empty($update['sql']) && $result[1] == $result[2]) {
|
|
|
|
echo '
|
|
|
|
<script>
|
2017-09-10 14:35:41 +02:00
|
|
|
$("#progress .info").html($("#progress .info").html() + "<p> <i class=\"fa fa-check\"></i> '.tr('Aggiornamento del database (_FILENAME_)', [
|
|
|
|
'_FILENAME_' => '<i>'.$update['filename'].'.sql</i>',
|
|
|
|
]).'</p>");
|
2017-08-04 16:28:16 +02:00
|
|
|
</script>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$rate = $result[1] - $result[0];
|
|
|
|
} elseif (!empty($update['script'])) {
|
|
|
|
// Aggiunta del messaggio riguardante la conclusione dello script
|
|
|
|
echo '
|
|
|
|
<script>
|
2017-09-10 14:35:41 +02:00
|
|
|
$("#progress .info").html($("#progress .info").html() + "<p> <i class=\"fa fa-check\"></i> '.tr('Esecuzione dello script di aggiornamento (_FILENAME_)', [
|
|
|
|
'_FILENAME_' => '<i>'.$update['filename'].'.php</i>',
|
|
|
|
]).'</p>");
|
2017-08-04 16:28:16 +02:00
|
|
|
</script>';
|
|
|
|
|
|
|
|
$rate = $scriptValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Aumento della percentuale di completameno totale
|
|
|
|
if (!empty($rate)) {
|
|
|
|
echo '
|
|
|
|
<script>
|
|
|
|
addProgress('.$rate.');
|
|
|
|
</script>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<script>
|
|
|
|
$("#result").load("index.php?action=do_update&firstuse='.$_GET['firstuse'].'");
|
|
|
|
</script>';
|
|
|
|
} else {
|
|
|
|
// Fallimento
|
|
|
|
echo '
|
|
|
|
<div class="alert alert-danger">
|
2017-09-10 14:35:41 +02:00
|
|
|
<i class="fa fa-times"></i> '.tr("Errore durante l'esecuzione dell'aggiornamento alla versione _VERSION_", [
|
|
|
|
'_VERSION_' => $update['version'],
|
|
|
|
]).'
|
2017-08-04 16:28:16 +02:00
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Aggiornamento completato
|
|
|
|
elseif (Update::isUpdateCompleted()) {
|
|
|
|
Update::updateCleanup();
|
|
|
|
|
|
|
|
echo '
|
2017-09-04 12:02:29 +02:00
|
|
|
<p><strong>'.tr('Aggiornamento completato!!!').'</strong> <i class="fa fa-smile-o"></i></p>';
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Rimostro la finestra di login
|
|
|
|
echo '
|
|
|
|
<script>
|
|
|
|
$(".login-box").fadeIn();
|
|
|
|
</script>';
|
|
|
|
|
|
|
|
// Istruzioni per la prima installazione
|
|
|
|
if ($_GET['firstuse'] == 'true') {
|
|
|
|
if (!empty($_SESSION['osm_password'])) {
|
|
|
|
$password = $_SESSION['osm_password'];
|
|
|
|
} else {
|
|
|
|
$password = 'admin';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
2017-09-04 12:02:29 +02:00
|
|
|
<p>'.tr('Puoi procedere al login con i seguenti dati').':</p>
|
|
|
|
<p>'.tr('Username').': <i>admin</i></p>
|
|
|
|
<p>'.tr('Password').': <i> '.$password.'</i></p>
|
2017-09-10 14:35:41 +02:00
|
|
|
<p class="text-danger">'.tr("E' fortemente consigliato rimuovere i permessi di scrittura dal file _FILE_", [
|
|
|
|
'_FILE_' => '<b>config.inc.php</b>',
|
|
|
|
]).'.</p>';
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Imposto la password di admin che l'utente ha selezionato all'inizio
|
|
|
|
if (isset($_SESSION['osm_password'])) {
|
|
|
|
$dbo->query('UPDATE `zz_users` SET `password`='.prepare(Auth::hashPassword($password))." WHERE `username`='admin'");
|
|
|
|
|
|
|
|
unset($_SESSION['osm_password']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_SESSION['osm_email'])) {
|
|
|
|
if (!empty($_SESSION['osm_email'])) {
|
|
|
|
$dbo->query('UPDATE `zz_users` SET `email`='.preare($_SESSION['osm_email'])." WHERE `username`='admin' ");
|
|
|
|
}
|
|
|
|
unset($_SESSION['osm_email']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit();
|
|
|
|
} elseif (Update::isUpdateAvailable()) {
|
|
|
|
// Controllo se l'aggiornamento è in esecuzione
|
|
|
|
if (Update::isUpdateLocked() && filter('force') === null) {
|
2017-09-04 12:02:29 +02:00
|
|
|
$pageTitle = tr('Aggiornamento in corso!');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
if (file_exists($docroot.'/include/custom/top.php')) {
|
|
|
|
include_once $docroot.'/include/custom/top.php';
|
|
|
|
} else {
|
|
|
|
include_once $docroot.'/include/top.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<div class="box box-center box-danger box-solid text-center">
|
|
|
|
<div class="box-header with-border">
|
2017-09-04 12:02:29 +02:00
|
|
|
<h3 class="box-title">'.tr('Aggiornamento in corso!').'</h3>
|
2017-08-04 16:28:16 +02:00
|
|
|
</div>
|
|
|
|
<div class="box-body">
|
2017-09-04 12:02:29 +02:00
|
|
|
<p>'.tr("E' attualmente in corso la procedura di aggiornamento del software, e pertanto siete pregati di attendere fino alla sua conclusione").'.</p>
|
|
|
|
<p>'.tr("Nel caso il problema persista, rivolgersi all'amministratore o all'assistenza ufficiale").'.</p>
|
|
|
|
<a class="btn btn-info" href="'.$rootdir.'/index.php"><i class="fa fa-repeat"></i> '.tr('Riprova').'</a>
|
2017-08-04 16:28:16 +02:00
|
|
|
</div>
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
if (file_exists($docroot.'/include/custom/bottom.php')) {
|
|
|
|
include_once $docroot.'/include/custom/bottom.php';
|
|
|
|
} else {
|
|
|
|
include_once $docroot.'/include/bottom.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$firstuse = !$dbo->isInstalled() ? 'true' : 'false';
|
|
|
|
|
2017-09-04 12:02:29 +02:00
|
|
|
$button = !$dbo->isInstalled() ? tr('Installa!') : tr('Aggiorna!');
|
|
|
|
$pageTitle = !$dbo->isInstalled() ? tr('Installazione') : tr('Aggiornamento');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
if (file_exists($docroot.'/include/custom/top.php')) {
|
|
|
|
include_once $docroot.'/include/custom/top.php';
|
|
|
|
} else {
|
|
|
|
include_once $docroot.'/include/top.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<div class="box box-center-large box-warning text-center">
|
|
|
|
<div class="box-header with-border">
|
2017-09-04 12:02:29 +02:00
|
|
|
<h3 class="box-title">'.(!$dbo->isInstalled() ? tr('Installazione') : tr('Aggiornamento')).'</h3>
|
2017-08-04 16:28:16 +02:00
|
|
|
</div>
|
|
|
|
<div class="box-body">';
|
|
|
|
if (!$dbo->isInstalled()) {
|
|
|
|
echo '
|
2017-09-04 12:02:29 +02:00
|
|
|
<p><strong>'.tr("E' la prima volta che avvii OpenSTAManager e non hai ancora installato il database").'.</strong></p>';
|
2017-08-04 16:28:16 +02:00
|
|
|
} else {
|
|
|
|
echo '
|
2017-09-04 12:02:29 +02:00
|
|
|
<p>'.tr("E' necessario aggiornare il database a una nuova versione").'.</p>';
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
echo '
|
2017-09-10 14:35:41 +02:00
|
|
|
<p>'.tr("Premi il tasto _BUTTON_ per procedere con l'aggiornamento!", [
|
|
|
|
'_BUTTON_' => '<b>"'.$button.'"</b>',
|
|
|
|
]).'</p>
|
2017-08-04 16:28:16 +02:00
|
|
|
<input type="button" class="btn btn-primary" value="'.$button.'" onclick="continue_update()" id="contine_button">
|
|
|
|
|
|
|
|
<script>
|
|
|
|
function continue_update(){
|
|
|
|
swal({
|
2017-09-04 12:02:29 +02:00
|
|
|
title: "'.tr('Sei sicuro?').'",
|
|
|
|
text: "'.tr("Continuare con l'aggiornamento?").'",
|
2017-08-04 16:28:16 +02:00
|
|
|
type: "warning",
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonClass: "btn btn-lg btn-success",
|
2017-09-04 12:02:29 +02:00
|
|
|
confirmButtonText: "'.tr('Procedi').'",
|
2017-08-04 16:28:16 +02:00
|
|
|
}).then(
|
|
|
|
function(){
|
|
|
|
$("#progress").show();
|
|
|
|
$("#result").load("index.php?action=do_update&firstuse='.$firstuse.'");
|
|
|
|
$("#contine_button").remove();
|
|
|
|
}, function(){});
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div id="progress">
|
|
|
|
<div class="progress">
|
|
|
|
<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%">
|
|
|
|
<span>0%</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<hr>
|
|
|
|
<div class="box box-info text-center collapsed-box">
|
|
|
|
<div class="box-header with-border">
|
2017-09-04 12:02:29 +02:00
|
|
|
<h3 class="box-title"><a class="clickable" data-widget="collapse">'.tr('Log').'</a></h3>
|
2017-08-04 16:28:16 +02:00
|
|
|
<div class="box-tools pull-right">
|
|
|
|
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-plus"></i></button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="box-body info text-left"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="result"></div>';
|
|
|
|
|
|
|
|
$total = 0;
|
|
|
|
$updates = Update::getTodos();
|
2017-08-31 10:09:06 +02:00
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
foreach ($updates as $update) {
|
2017-08-31 10:09:06 +02:00
|
|
|
if ($update['sql'] && (!empty($update['done']) || is_null($update['done']))) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$queries = readSQLFile(DOCROOT.$update['directory'].$update['filename'].'.sql', ';');
|
|
|
|
$total += count($queries);
|
2017-08-31 10:09:06 +02:00
|
|
|
|
|
|
|
if (intval($update['done']) > 1) {
|
|
|
|
$total -= intval($update['done']) - 2;
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($update['script']) {
|
|
|
|
$total += $scriptValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<script>
|
|
|
|
$(document).ready(function(){
|
|
|
|
$(".login-box").fadeOut();
|
|
|
|
|
|
|
|
count = '.count($updates).';
|
|
|
|
current = 0;
|
|
|
|
versions = [];
|
|
|
|
|
|
|
|
progress = 0;
|
|
|
|
total = '.$total.';
|
|
|
|
});
|
|
|
|
|
|
|
|
function addProgress(rate){
|
|
|
|
progress += rate;
|
|
|
|
percent = progress / total * 100;
|
|
|
|
percent = Math.round(percent);
|
2017-09-06 10:48:59 +02:00
|
|
|
percent = percent > 100 ? 100 : percent;
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
$("#progress .progress-bar").width(percent + "%");
|
|
|
|
$("#progress .progress-bar span").text(percent + "%");
|
|
|
|
}
|
|
|
|
|
|
|
|
function addVersion(version){
|
|
|
|
if(versions.indexOf(version) === -1){
|
|
|
|
versions.push(version);
|
|
|
|
current += 1;
|
|
|
|
|
2017-09-10 14:35:41 +02:00
|
|
|
$("#progress .info").html($("#progress .info").html() + "<p><strong>'.tr('Aggiornamento _DONE_ di _TODO_ (_VERSION_)', [
|
|
|
|
'_DONE_' => '" + current + "',
|
|
|
|
'_TODO_' => '" + count + "',
|
|
|
|
'_VERSION_' => '" + version + "',
|
|
|
|
]).'</strong></p>");
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</div>
|
|
|
|
</div>';
|
|
|
|
}
|