<?
session_start();
error_reporting(0);
require_once("./inc/functions.class.php");
require_once("./inc/document.class.php");
require_once("./externe/pclzip.lib.php");
$doc=new etude;
if(isset($_GET["langue_choisie"])) $lang_to_register= $_GET["langue_choisie"];
elseif(isset($_COOKIE["etude_lang_cookie"])) $lang_to_register=$_COOKIE["etude_lang_cookie"];
else $lang_to_register="fr";
setcookie("etude_lang_cookie", "$lang_to_register", time()+2600000);
$_SESSION=array(); //si on se reconnecte, c'est pour supprimer la session existante, pas pour en garder une trace !
$doc->title();
$doc->body(1);
echo "\n<br>";
$select=$doc->read_and_prepare("./lang/langs.php");
foreach($select as $option)
{
list($nom, $base)=split(",", $option);
$class="";
if($lang_to_register==$base) $class="class=attention";
echo "\n<a href=\"./index.php?langue_choisie=$base\" $class>$nom</a> ";
}
echo "\n<br><h1>{$doc->lang["index_h1"]}</h1>";
echo "\n<h3>({$doc->lang["general_version"]} {$doc->settings["version"]})</h3>";
echo "\n<br>";
echo "\n<br>";
//test de l'existence d'un administrateur
$verif1=FALSE;
$verif2=TRUE;
$verif3=FALSE;
if(!is_dir("./config_files")) mkdir("config_files");
if(is_file("{$doc->settings["passfile"]}"))
{
$arr=$doc->read_and_prepare("{$doc->settings["passfile"]}");
foreach($arr as $option)
{
list(,,,$fonction)=split(",", $option);
if($fonction=="administrateur")
{
$verif1=TRUE;
break;
}
}
}else{
if($_POST["restauration"])
{
$zip = new PclZip('config.zip');
$cur_dir=getcwd();
chdir("./config_files");
if (is_uploaded_file($_FILES["fichier"]["tmp_name"]))
{
copy($_FILES["fichier"]["tmp_name"], "config.zip");
}
$zip -> extract();
if(is_file("config.zip"))
{
unlink("config.zip");
}
}
}
if(isset($settings["database"])) $verif2=TRUE;
//test de la configuration à jour
$ajour=$doc->read_and_prepare("./config_files/checkversion.php");
foreach($ajour as $line) if(trim($line) == trim($doc->settings["version"])) $verif3=TRUE;
if($verif1==FALSE || $verif2==FALSE)
{
echo "{$doc->lang["index_not_config_1"]} <a href=\"./config/config.php\">{$doc->lang["index_not_config_2"]}</a> {$doc->lang["index_not_config_3"]}.";
echo "\n<h3>{$doc->lang["index_restaurer"]}</h3>";
echo "\n<form method=\"post\" action=\"./index.php\" enctype=\"multipart/form-data\">
{$doc->lang["index_choisir_fichier"]} <input type=file name=\"fichier\">\n";
echo $doc->input_hidden("restauration", "", "on");
echo $doc->button("{$doc->lang["operations_valider"]}");
echo "\n</form>";
}elseif($verif3==FALSE){
echo "\n{$doc->lang["index_not_config_1bis"]}.\n<br>{$doc->lang["index_not_config_1ter"]} <a href=\"./config/config.php\">{$doc->lang["index_not_config_2"]}</a> {$doc->lang["index_not_config_3"]}.";
}else{
echo "{$doc->lang["index_insert_data"]}";
echo "\n<form name=\"form\" method=\"post\" action=\"./verify.php\">";
echo "\n <table>";
echo "\n <tr>";
echo "\n <td>{$doc->lang["index_nom"]} :</td><td><input type=\"text\" name=\"start_utilisateur\" onfocus=\"select()\"></td>";
echo "\n </tr>";
echo "\n <tr>";
echo "\n <td>{$doc->lang["index_password"]} :</td><td><input type=\"password\" name=\"start_pwd\" onfocus=\"select()\"></td>";
echo "\n </tr>";
echo "\n <tr>";
echo "\n <td>";
echo $doc->button("{$doc->lang["index_connect"]}");
echo "</td>";
echo "\n </tr>";
echo "\n </table>";
echo "\n</form>";
}
if($verif1 AND $verif2 AND $verif3) echo "\n<a href=\"./config/config.php\">{$doc->lang["index_admin"]}</a>";
$doc->close();
?>