Exemplo n.º 1
0
 public static function lance_maj($lang, $installed_version, $config_php_conges_version, $etape)
 {
     $PHP_SELF = $_SERVER['PHP_SELF'];
     include CONFIG_PATH . 'dbconnect.php';
     //*** ETAPE 0
     if ($etape == 0) {
         //avant tout , on conseille une sauvegarde de la database !! (cf vieux index.php)
         echo "<h3>" . _('install_maj_passer_de') . " <font color=\"black\">{$installed_version}</font> " . _('install_maj_a_version') . " <font color=\"black\">{$config_php_conges_version}</font> .</h3>\n";
         echo "<h3><font color=\"red\">" . _('install_maj_sauvegardez') . " !!!</font></h3>\n";
         echo "<h2>....</h2>\n";
         echo "<br>\n";
         echo "<form action=\"{$PHP_SELF}?lang={$lang}\" method=\"POST\">\n";
         echo "<input type=\"hidden\" name=\"etape\" value=\"1\">\n";
         echo "<input type=\"hidden\" name=\"version\" value=\"{$installed_version}\">\n";
         echo "<input type=\"submit\" value=\"" . _('form_continuer') . "\">\n";
         echo "</form>\n";
         echo "<br><br>\n";
     } elseif ($etape == 1) {
         //verif si create / alter table possible !!!
         if (!\install\Fonctions::test_create_table()) {
             echo "<font color=\"red\"><b>CREATE TABLE</b> " . _('install_impossible_sur_db') . " <b>{$mysql_database}</b> (" . _('install_verif_droits_mysql') . " <b>{$mysql_user}</b>)...</font><br> \n";
             echo "<br>puis ...<br>\n";
             echo "<form action=\"{$PHP_SELF}?lang={$lang}\" method=\"POST\">\n";
             echo "<input type=\"hidden\" name=\"etape\"value=\"1\" >\n";
             echo "<input type=\"hidden\" name=\"version\" value=\"{$installed_version}\">\n";
             echo "<input type=\"submit\" value=\"" . _('form_redo') . "\">\n";
             echo "</form>\n";
         } elseif (!\install\Fonctions::test_alter_table()) {
             echo "<font color=\"red\"><b>ALTER TABLE</b> " . _('install_impossible_sur_db') . " <b>{$mysql_database}</b> (" . _('install_verif_droits_mysql') . " <b>{$mysql_user}</b>)...</font><br> \n";
             echo "<br>puis ...<br>\n";
             echo "<form action=\"{$PHP_SELF}?lang={$lang}\" method=\"POST\">\n";
             echo "<input type=\"hidden\" name=\"etape\"value=\"1\" >\n";
             echo "<input type=\"hidden\" name=\"version\" value=\"{$installed_version}\">\n";
             echo "<input type=\"submit\" value=\"" . _('form_redo') . "\">\n";
             echo "</form>\n";
         } elseif (!\install\Fonctions::test_drop_table()) {
             echo "<font color=\"red\"><b>DROP TABLE</b> " . _('install_impossible_sur_db') . " <b>{$mysql_database}</b> (" . _('install_verif_droits_mysql') . " <b>{$mysql_user}</b>)...</font><br> \n";
             echo "<br>puis ...<br>\n";
             echo "<form action=\"{$PHP_SELF}?lang={$lang}\">\n";
             echo "<input type=\"hidden\" name=\"etape\"value=\"1\" >\n";
             echo "<input type=\"hidden\" name=\"version\" value=\"{$installed_version}\">\n";
             echo "<input type=\"submit\" value=\"" . _('form_redo') . "\">\n";
             echo "</form>\n";
         } else {
             echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$PHP_SELF}?etape=2&version={$installed_version}&lang={$lang}\">";
         }
     } elseif ($etape == 2) {
         $start_version = $installed_version;
         //on lance l'execution (include) des scripts d'upgrade l'un après l'autre jusqu a la version voulue ($config_php_conges_version) ..
         if ($start_version == "1.5.0" || $start_version == "1.5.1") {
             $file_upgrade = 'upgrade_from_v1.5.0.php';
             $new_installed_version = "1.6.0";
             // execute le script php d'upgrade de la version1.5.0 (vers la suivante (1.6.0))
             echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
         } elseif ($start_version == "1.6.0") {
             $file_upgrade = 'upgrade_from_v1.6.0.php';
             $new_installed_version = "1.7.0";
             // execute le script php d'upgrade de la version1.6.0 (vers la suivante (1.7.0))
             echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
         } elseif ($start_version == "1.7.0") {
             $file_upgrade = 'upgrade_from_v1.7.0.php';
             $new_installed_version = "1.8";
             // execute le script php d'upgrade de la version1.7.0 (vers la suivante (1.8))
             echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
         } else {
             echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$PHP_SELF}?etape=5&version={$new_installed_version}&lang={$lang}\">";
         }
     } elseif ($etape == 3) {
         // FIN
         // test si fichiers config.php ou config_old.php existent encore (si oui : demande de les éffacer !
         if (\install\Fonctions::test_config_file() || \install\Fonctions::test_old_config_file()) {
             if (test_config_file()) {
                 echo _('install_le_fichier') . " <b>\"config.php\"</b> " . _('install_remove_fichier') . ".<br> \n";
             }
             if (test_old_config_file()) {
                 echo _('install_le_fichier') . " <b>\"install/config_old.php\"</b> " . _('install_remove_fichier') . ".<br> \n";
             }
             echo "<br><a href=\"{$PHP_SELF}?etape=5&version={$config_php_conges_version}&lang={$lang}\">" . _('install_reload_page') . " ....</a><br>\n";
         } else {
             // mise à jour de la "installed_version" et de la langue dans la table conges_config
             $sql_update_version = "UPDATE conges_config SET conf_valeur = '{$config_php_conges_version}' WHERE conf_nom='installed_version' ";
             $result_update_version = \includes\SQL::query($sql_update_version);
             $sql_update_lang = "UPDATE conges_config SET conf_valeur = '{$lang}' WHERE conf_nom='lang' ";
             $result_update_lang = \includes\SQL::query($sql_update_lang);
             $comment_log = _('install_maj_titre_2') . " (version {$installed_version} --> version {$config_php_conges_version}) ";
             log_action(0, "", "", $comment_log);
             // on propose la page de config ....
             echo "<br><br><h2>" . _('install_ok') . " !</h2><br>\n";
             echo "<META HTTP-EQUIV=REFRESH CONTENT=\"2; URL=../config/\">";
         }
     }
 }
Exemplo n.º 2
0
function lance_maj($lang, $installed_version, $config_php_conges_version, $etape, $DEBUG = FALSE)
{
    if ($DEBUG) {
        echo " lang = {$lang}  ##  etape = {$etape} ## version = {$installed_version}<br>\n";
    }
    $PHP_SELF = $_SERVER['PHP_SELF'];
    include CONFIG_PATH . 'dbconnect.php';
    //*** ETAPE 0
    if ($etape == 0) {
        //avant tout , on conseille une sauvegarde de la database !! (cf vieux index.php)
        echo "<h3>" . _('install_maj_passer_de') . " <font color=\"black\">{$installed_version}</font> " . _('install_maj_a_version') . " <font color=\"black\">{$config_php_conges_version}</font> .</h3>\n";
        echo "<h3><font color=\"red\">" . _('install_maj_sauvegardez') . " !!!</font></h3>\n";
        echo "<h2>....</h2>\n";
        echo "<br>\n";
        echo "<form action=\"{$PHP_SELF}?lang={$lang}\" method=\"POST\">\n";
        echo "<input type=\"hidden\" name=\"etape\" value=\"1\">\n";
        echo "<input type=\"hidden\" name=\"version\" value=\"{$installed_version}\">\n";
        echo "<input type=\"submit\" value=\"" . _('form_continuer') . "\">\n";
        echo "</form>\n";
        echo "<br><br>\n";
    } elseif ($etape == 1) {
        //verif si create / alter table possible !!!
        if (!test_create_table($DEBUG)) {
            echo "<font color=\"red\"><b>CREATE TABLE</b> " . _('install_impossible_sur_db') . " <b>{$mysql_database}</b> (" . _('install_verif_droits_mysql') . " <b>{$mysql_user}</b>)...</font><br> \n";
            echo "<br>puis ...<br>\n";
            echo "<form action=\"{$PHP_SELF}?lang={$lang}\" method=\"POST\">\n";
            echo "<input type=\"hidden\" name=\"etape\"value=\"1\" >\n";
            echo "<input type=\"hidden\" name=\"version\" value=\"{$installed_version}\">\n";
            echo "<input type=\"submit\" value=\"" . _('form_redo') . "\">\n";
            echo "</form>\n";
        } elseif (!test_alter_table($DEBUG)) {
            echo "<font color=\"red\"><b>ALTER TABLE</b> " . _('install_impossible_sur_db') . " <b>{$mysql_database}</b> (" . _('install_verif_droits_mysql') . " <b>{$mysql_user}</b>)...</font><br> \n";
            echo "<br>puis ...<br>\n";
            echo "<form action=\"{$PHP_SELF}?lang={$lang}\" method=\"POST\">\n";
            echo "<input type=\"hidden\" name=\"etape\"value=\"1\" >\n";
            echo "<input type=\"hidden\" name=\"version\" value=\"{$installed_version}\">\n";
            echo "<input type=\"submit\" value=\"" . _('form_redo') . "\">\n";
            echo "</form>\n";
        } elseif (!test_drop_table($DEBUG)) {
            echo "<font color=\"red\"><b>DROP TABLE</b> " . _('install_impossible_sur_db') . " <b>{$mysql_database}</b> (" . _('install_verif_droits_mysql') . " <b>{$mysql_user}</b>)...</font><br> \n";
            echo "<br>puis ...<br>\n";
            echo "<form action=\"{$PHP_SELF}?lang={$lang}\">\n";
            echo "<input type=\"hidden\" name=\"etape\"value=\"1\" >\n";
            echo "<input type=\"hidden\" name=\"version\" value=\"{$installed_version}\">\n";
            echo "<input type=\"submit\" value=\"" . _('form_redo') . "\">\n";
            echo "</form>\n";
        } else {
            if (!$DEBUG) {
                echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$PHP_SELF}?etape=2&version={$installed_version}&lang={$lang}\">";
            } else {
                echo "<a href=\"{$PHP_SELF}?etape=2&version={$installed_version}&lang={$lang}\">" . _('install_etape') . " 1  OK</a><br>\n";
            }
        }
    } elseif ($etape == 2) {
        // si on part d'une version <= v1.0 : on travaille sinon, on passe à l'étape 3
        if (substr($installed_version, 0, 1) == "0" || $installed_version == "1.0") {
            //verif si la copie de l'ancien fichier de config est présent et lisible (install/config_old.php)
            if (!test_old_config_file($DEBUG)) {
                echo "<font color=\"red\">\n";
                echo _('install_le_fichier') . " \"<b>install / config_old.php</b>\" " . _('install_inaccessible') . " !<br>\n";
                echo _('install_maj_conserv_config') . "<br>\n";
                echo _('install_maj_copy_config_file') . " \"<b>install</b>\" " . _('install_maj_whith_name') . " \"<b>config_old.php</b>\" " . _('install_maj_and') . "<br>\n";
                echo _('install_maj_verif_droit_fichier') . " <br>\n";
                echo "</font><br> \n";
                echo "<br>" . _('install_puis') . " ...<br>\n";
                echo "<form action=\"{$PHP_SELF}?lang={$lang}\" method=\"POST\">\n";
                echo "<input type=\"hidden\" name=\"etape\"value=\"2\" >\n";
                echo "<input type=\"hidden\" name=\"version\" value=\"{$installed_version}\">\n";
                echo "<input type=\"submit\" value=\"" . _('form_continuer') . "\">\n";
                echo "</form>\n";
            } else {
                if (!$DEBUG) {
                    echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$PHP_SELF}?etape=3&version={$installed_version}&lang={$lang}\">";
                } else {
                    echo "<a href=\"{$PHP_SELF}?etape=3&version={$installed_version}&lang={$lang}\">" . _('install_etape') . " 2  OK</a><br>\n";
                }
            }
        } else {
            if (!$DEBUG) {
                echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$PHP_SELF}?etape=3&version={$installed_version}&lang={$lang}\">";
            } else {
                echo "<a href=\"{$PHP_SELF}?etape=3&version={$installed_version}&lang={$lang}\">" . _('install_etape') . " 2  OK</a><br>\n";
            }
        }
    } elseif ($etape == 3) {
        // ATTENTION on ne passe cette étape que si on est en version inferieure à 1.0 ! (donc en v0.xxx) (sinon on passe à l'étape 4)
        if (substr($installed_version, 0, 1) != "0") {
            if (!$DEBUG) {
                echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$PHP_SELF}?etape=4&version={$installed_version}&lang={$lang}\">";
            } else {
                echo "<a href=\"{$PHP_SELF}?etape=4&version={$installed_version}&lang={$lang}\">" . _('install_etape') . " 3  OK</a><br>\n";
            }
        } else {
            //on lance l'execution de fichier sql de migration l'un après l'autre jusqu a la version 0.10.1 ..
            $db_version = explode(".", $installed_version);
            $db_sub_version = (int) $db_version[1];
            for ($i = $db_sub_version; $i <= 10; $i++) {
                if ($i == 10) {
                    // si on en est à v0.10 on passe en v1.0
                    $sql_file = "sql/upgrade_v0.10_to_v1.0.sql";
                } else {
                    $j = $i + 1;
                    $sql_file = "sql/upgrade_v0." . $i . "_to_v0." . $j . ".sql";
                }
                if ($DEBUG) {
                    echo "sql_file = {$sql_file}<br>\n";
                }
                execute_sql_file($sql_file, $DEBUG);
            }
            if (!$DEBUG) {
                echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$PHP_SELF}?etape=4&version=1.0&lang={$lang}\">";
            } else {
                echo "<a href=\"{$PHP_SELF}?etape=4&version=1.0&lang={$lang}\">" . _('install_etape') . " 3  OK</a><br>\n";
            }
        }
    } elseif ($etape == 4) {
        // on est au moins à la version 1.0 ....
        // ensuite tout se fait en php (plus de script de migration sql)
        // on determine la version la + élevée entre $installed_version et 1.0  , et on part de celle là !
        if (substr($installed_version, 0, 1) == "0") {
            $start_version = "1.0";
        } else {
            $start_version = $installed_version;
        }
        //on lance l'execution (include) des scripts d'upgrade l'un après l'autre jusqu a la version voulue ($config_php_conges_version) ..
        if ($start_version == "1.0") {
            $file_upgrade = 'upgrade_from_v1.0.php';
            $new_installed_version = "1.1";
            // execute le script php d'upgrade de la version1.0 (vers la suivante (1.1))
            echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
        } elseif ($start_version == "1.1") {
            $file_upgrade = 'upgrade_from_v1.1.php';
            $new_installed_version = "1.1.1";
            // execute le script php d'upgrade de la version1.1 (vers la suivante (1.1.1))
            echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
        } elseif ($start_version == "1.1.1") {
            $file_upgrade = 'upgrade_from_v1.1.1.php';
            $new_installed_version = "1.2";
            // execute le script php d'upgrade de la version1.1.1 (vers la suivante (1.2))
            echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
        } elseif ($start_version == "1.2") {
            $file_upgrade = 'upgrade_from_v1.2.php';
            $new_installed_version = "1.2.1";
            // execute le script php d'upgrade de la version1.2 (vers la suivante (1.2.1))
            echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
        } elseif ($start_version == "1.2.1") {
            $file_upgrade = 'upgrade_from_v1.2.1.php';
            $new_installed_version = "1.3.0";
            // execute le script php d'upgrade de la version1.2.1 (vers la suivante (1.3.0))
            echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
        } elseif ($start_version == "1.3.0") {
            $file_upgrade = 'upgrade_from_v1.3.0.php';
            $new_installed_version = "1.3.1";
            // execute le script php d'upgrade de la version1.3.0 (vers la suivante (1.3.1))
            echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
        } elseif ($start_version == "1.3.1") {
            $file_upgrade = 'upgrade_from_v1.3.1.php';
            $new_installed_version = "1.3.2";
            // execute le script php d'upgrade de la version1.3.1 (vers la suivante (1.3.2))
            echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
        } elseif ($start_version == "1.3.2") {
            $file_upgrade = 'upgrade_from_v1.3.2.php';
            $new_installed_version = "1.4.0";
            // execute le script php d'upgrade de la version1.3.1.2 (vers la suivante (1.4.0))
            echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
        } elseif ($start_version == "1.4.0") {
            $file_upgrade = 'upgrade_from_v1.4.0.php';
            $new_installed_version = "1.4.1";
            // execute le script php d'upgrade de la version1.4.0 (vers la suivante (1.4.1))
            echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
        } elseif ($start_version == "1.4.1" || $start_version == "1.4.2") {
            $file_upgrade = 'upgrade_from_v1.4.2.php';
            $new_installed_version = "1.5.0";
            // execute le script php d'upgrade de la version1.4.2 (vers la suivante (1.5.0))
            echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
        } elseif ($start_version == "1.5.0" || $start_version == "1.5.1") {
            $file_upgrade = 'upgrade_from_v1.5.0.php';
            $new_installed_version = "1.6.0";
            // execute le script php d'upgrade de la version1.5.0 (vers la suivante (1.6.0))
            echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
        } elseif ($start_version == "1.6.0") {
            $file_upgrade = 'upgrade_from_v1.6.0.php';
            $new_installed_version = "1.7.0";
            // execute le script php d'upgrade de la version1.6.0 (vers la suivante (1.7.0))
            echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$file_upgrade}?version={$new_installed_version}&lang={$lang}\">";
        } else {
            if (!$DEBUG) {
                echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL={$PHP_SELF}?etape=5&version=1.4.1&lang={$lang}\">";
            } else {
                echo "<a href=\"{$PHP_SELF}?etape=5&version=1.5.0&lang={$lang}\">" . _('install_etape') . " 4  OK</a><br>\n";
            }
        }
    } elseif ($etape == 5) {
        // FIN
        // test si fichiers config.php ou config_old.php existent encore (si oui : demande de les éffacer !
        if (test_config_file($DEBUG) || test_old_config_file($DEBUG)) {
            if (test_config_file($DEBUG)) {
                echo _('install_le_fichier') . " <b>\"config.php\"</b> " . _('install_remove_fichier') . ".<br> \n";
            }
            if (test_old_config_file($DEBUG)) {
                echo _('install_le_fichier') . " <b>\"install/config_old.php\"</b> " . _('install_remove_fichier') . ".<br> \n";
            }
            echo "<br><a href=\"{$PHP_SELF}?etape=5&version={$config_php_conges_version}&lang={$lang}\">" . _('install_reload_page') . " ....</a><br>\n";
        } else {
            // mise à jour de la "installed_version" et de la langue dans la table conges_config
            $sql_update_version = "UPDATE conges_config SET conf_valeur = '{$config_php_conges_version}' WHERE conf_nom='installed_version' ";
            $result_update_version = SQL::query($sql_update_version);
            $sql_update_lang = "UPDATE conges_config SET conf_valeur = '{$lang}' WHERE conf_nom='lang' ";
            $result_update_lang = SQL::query($sql_update_lang);
            $comment_log = "Mise a jour de php_conges (version {$installed_version} --> version {$config_php_conges_version}) ";
            log_action(0, "", "", $comment_log, $DEBUG);
            // on propose la page de config ....
            echo "<br><br><h2>" . _('install_ok') . " !</h2><br>\n";
            echo "<META HTTP-EQUIV=REFRESH CONTENT=\"2; URL=../config/\">";
        }
    } else {
        // rien, on ne devrait jammais arriver dans ce else !!!
    }
}