Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 if ( !defined ('ALLOWED')) die('Forbidden');
00022 require_once('class_iradio.php');
00023 require_once('class_ifile.php');
00024
00025
00026
00027
00028 if ( isset ($_REQUEST['sa'] ))
00029 {
00030 if ( defined ('PG_PATH') )
00031 putenv("PATH=".PG_PATH);
00032
00033 $cmd=escapeshellcmd (PG_RESTORE);
00034 if (defined("noalyss_user"))
00035 {
00036 putenv("PGPASSWORD=" . noalyss_password);
00037 putenv("PGUSER=" . noalyss_user);
00038 putenv("PGHOST=" . noalyss_psql_host);
00039 putenv("PGPORT=" . noalyss_psql_port);
00040 } else if (defined("phpcompta_user"))
00041 {
00042 putenv("PGPASSWORD=" . phpcompta_password);
00043 putenv("PGUSER=" . phpcompta_user);
00044 putenv("PGHOST=" . phpcompta_psql_host);
00045 putenv("PGPORT=" . phpcompta_psql_port);
00046 } else {
00047 die ('Aucune connection');
00048 }
00049
00050 $retour='<hr>'.HtmlInput::button_anchor("Retour","?action=restore");
00051 if ( ! isset($_REQUEST['t']))
00052 {
00053 echo '<div class="content">';
00054 echo ("<span class=\"error\">Vous devez préciser s'il s'agit d'un modèle ou d'un dossier</span>");
00055 echo $retour;
00056 echo '</div>';
00057 exit();
00058 }
00059 if ( empty ($_FILES['file']['name']) ||
00060 strlen(trim($_FILES['file']['name']))==0
00061 )
00062 {
00063 echo '<div class="content">';
00064
00065 echo ("<span class=\"error\">Vous devez donner un fichier </span>");
00066 echo $retour;
00067 echo '</div>';
00068 exit();
00069 }
00070
00071
00072 if ( $_REQUEST['t']=='d')
00073 {
00074 echo '<div class="content" style="width:80%;margin-left:10%">';
00075
00076 $cn=new Database();
00077 $id=$cn->get_next_seq('dossier_id');
00078
00079 if ( strlen(trim($_REQUEST['database'])) == 0 )
00080 {
00081 $lname=$id." Restauration :".sql_string($_FILES['file']['name']);
00082 }
00083 else
00084 {
00085 $lname=$id." ".$_REQUEST['database'];
00086 }
00087
00088 if (strlen(trim($_REQUEST['desc']))==0)
00089 {
00090 $ldesc=$lname;
00091 }
00092 else
00093 {
00094 $ldesc=sql_string($_REQUEST['desc']);
00095 }
00096
00097 $sql="insert into ac_dossier (dos_id,dos_name,dos_description) values (".$id.",'".$lname."','".$ldesc."') ";
00098 $cn->start();
00099 try
00100 {
00101 $cn->get_value($sql);
00102
00103
00104 }
00105 catch ( Exception $e)
00106 {
00107 echo '<span class="error">'."Echec de la restauration ".'</span>';
00108 $cn->rollback();
00109 exit();
00110 }
00111 $cn->commit();
00112 $name=domaine."dossier".$id;
00113 echo $name;
00114 $cn->exec_sql("create database ".$name." encoding='utf8'");
00115 $args=" --no-owner -d $name ".$_FILES['file']['tmp_name'];
00116 $cmd= escapeshellcmd(PG_RESTORE);
00117 exec($cmd.$args);
00118 $test=new Database($id);
00119 if ( $test->exist_table('version') )
00120 {
00121 echo '<h2 class="info"> Restauration réussie du dossier '.$lname.'</h2>';
00122 $test->close();
00123 }
00124 else
00125 {
00126 $test->close();
00127 echo '<h2 class="error"> Problème lors de la restauration '.$lname.'</h2>';
00128 $cn->exec_sql('delete from ac_dossier where dos_id=$1',array($id));
00129 $cn->exec_sql('drop database '.$name);
00130 exit();
00131 }
00132 $new_cn=new Database($id);
00133
00134 $new_cn->apply_patch($name,0);
00135 echo '<span class="error">'.'Ne pas recharger la page, sinon votre base de données sera restaurée une fois de plus'.'</span>';
00136 Dossier::synchro_admin($id);
00137 echo $retour;
00138
00139 echo '</div>';
00140 }
00141
00142
00143
00144 if ( $_REQUEST['t']=='m')
00145 {
00146 echo '<div class="content">';
00147
00148 $cn=new Database();
00149 $id=$cn->get_next_seq('s_modid');
00150
00151 if ( strlen(trim($_REQUEST['database'])) == 0 )
00152 $lname=$id." Restauration :".sql_string($_FILES['file']['name']);
00153 else
00154 $lname=$id." ".$_REQUEST['database'];
00155
00156
00157 $sql="insert into modeledef (mod_id,mod_name,mod_desc) values (".$id.",'Restauration".$lname."','".$ldesc."') ";
00158 $cn->start();
00159 try
00160 {
00161 $cn->get_value($sql);
00162
00163 }
00164 catch ( Exception $e)
00165 {
00166 echo '<span class="error">'."Echec de la restauration ".'</span>';
00167 $cn->rollback();
00168 exit();
00169 }
00170 $cn->commit();
00171
00172 $name=domaine."mod".$id;
00173 $cn->exec_sql("create database ".$name." encoding='utf8'");
00174 $args=" -d $name ".$_FILES['file']['tmp_name'];
00175 $status=exec(PG_RESTORE.$args);
00176
00177 $test=new Database($id,'mod');
00178 if ( $test->exist_table('version') )
00179 {
00180 echo '<h2 class="info"> Restauration réussie du dossier '.$lname.'</h2>';
00181 $test->close();
00182 }
00183 else
00184 {
00185 $test->close();
00186 echo '<h2 class="error"> Problème lors de la restauration '.$lname.'</h2>';
00187 $cn->exec_sql('delete from modeledef where mod_id=$1',array($id));
00188 $cn->exec_sql('drop database '.$name);
00189 exit();
00190 }
00191
00192 $new_cn=new Database($id,'mod');
00193
00194 $new_cn->apply_patch($name,0);
00195
00196 echo '<span class="error">'._('Ne pas recharger la page, sinon votre base de données sera restaurée une fois de plus').'</span>';
00197 echo $retour;
00198
00199 echo '</div>';
00200 }
00201 }
00202 else
00203 {
00204 echo '<div class="content" style="width:80%;margin-left:10%">';
00205 echo '<form method="POST" action="admin_repo.php" enctype="multipart/form-data" >';
00206 echo HtmlInput::hidden('action','restore');
00207 echo HtmlInput::hidden('sa','r');
00208 echo '<table>';
00209 echo '<tr><td>'."Nom de la base de donnée".HtmlInput::infobulle(29)
00210 .'</td>';
00211 $wNom=new IText();
00212 $wNom->name="database";
00213 $wNom->size=30;
00214 echo '<td>'.$wNom->input().'</td></tr>';
00215 echo '<tr><td>'."Type de backup :".'</td>';
00216 $chk=new IRadio();
00217 $chk->name="t";
00218 $chk->value="d";
00219 echo '<td> '.$chk->input()."Dossier".'</td>';
00220 echo '</tr><tr><td></td>';
00221 $chk->name="t";
00222 $chk->value="m";
00223 echo '<td>'.$chk->input()."Modele".'</td>';
00224 echo '<tr>';
00225 $file=new IFile();
00226 $file->name="file";
00227 $file->value="mod";
00228 echo td('Fichier ').
00229 td($file->input());
00230 $desc=new ITextarea('desc');
00231 echo '</tr>';
00232 echo '</table>';
00233 echo "<p>Description </p>";
00234 $desc->heigh=4;$desc->width=60;
00235 echo $desc->input();
00236 echo '<p>';
00237 echo HtmlInput::submit("","Restauration");
00238 echo '</p>';
00239 echo '</form>';
00240 echo '</div>';
00241 }