noalyss Version-9
restore.inc.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21if ( !defined ('ALLOWED')) die('Forbidden');
24/*!\file
25 * \brief restaure a database
26 */
27if ( isset ($_REQUEST['sa'] ))
28{
29 if ( defined ('PG_PATH') )
30 putenv("PATH=".PG_PATH);
31
32 $cmd=escapeshellcmd (PG_RESTORE);
33 if (defined("noalyss_user"))
34 {
35 putenv("PGPASSWORD=" . noalyss_password);
36 putenv("PGUSER=" . noalyss_user);
37 putenv("PGHOST=" . noalyss_psql_host);
38 putenv("PGPORT=" . noalyss_psql_port);
39 } else if (defined("phpcompta_user"))
40 {
41 putenv("PGPASSWORD=" . phpcompta_password);
42 putenv("PGUSER=" . phpcompta_user);
43 putenv("PGHOST=" . phpcompta_psql_host);
44 putenv("PGPORT=" . phpcompta_psql_port);
45 } else {
46 die ('Aucune connection');
47 }
48
49 $retour='<hr>'.HtmlInput::button_anchor(_("Retour"),"?action=restore","","smallbutton");
50 if ( ! isset($_REQUEST['t']))
51 {
52 echo '<div class="content">';
53 echo ("<span class=\"error\">"._("Vous devez préciser s'il s'agit d'un modèle ou d'un dossier")."</span>");
54 echo $retour;
55 echo '</div>';
56 exit();
57 }
58 if ( empty ($_FILES['file']['name']) ||
59 noalyss_strlentrim($_FILES['file']['name'])==0
60 )
61 {
62 echo '<div class="content">';
63
64 echo ("<span class=\"error\">"._('Vous devez donner un fichier')." </span>");
65 echo $retour;
66 echo '</div>';
67 exit();
68 }
69 //---------------------------------------------------------------------------
70 // Restore a folder (dossier)
71 if ( $_REQUEST['t']=='d')
72 {
73 echo '<div class="content">';
74
75 $cn=new Database();
76 $id=$cn->get_next_seq('dossier_id');
77
78 if ( noalyss_strlentrim($_REQUEST['database']) == 0 )
79 {
80 $lname=$id." Restauration :".sql_string($_FILES['file']['name']);
81 }
82 else
83 {
84 $lname=$id." ".$_REQUEST['database'];
85 }
86
87 if (noalyss_strlentrim($_REQUEST['desc'])==0)
88 {
89 $ldesc=$lname;
90 }
91 else
92 {
93 $ldesc=sql_string($_REQUEST['desc']);
94 }
95
96 $sql="insert into ac_dossier (dos_id,dos_name,dos_description) values ($1,$2,$3)";
97 $cn->start();
98 try
99 {
100 $cn->get_value($sql,array($id,$lname,$ldesc));
101
102
103 }
104 catch ( Exception $e)
105 {
106 echo '<span class="error">'._("Echec de la restauration ").'</span>';
107 $cn->rollback();
108 exit();
109 }
110 $cn->commit();
111 $name=domaine."dossier".$id;
112 echo $name;
113 $cn->exec_sql("create database ".$name." encoding='utf8'");
114 $args=" --no-owner -d $name ".$_FILES['file']['tmp_name'];
115 $cmd= escapeshellcmd(PG_RESTORE);
116 exec($cmd.$args);
117 $test=new Database($id);
118 if ( $test->exist_table('version') )
119 {
120 echo '<h2 class="info"> '._('Restauration réussie du dossier ').$lname.'</h2>';
121 $test->close();
122 }
123 else
124 {
125 $test->close();
126 echo '<h2 class="error"> '._('Problème lors de la restauration ').$lname.'</h2>';
127 $cn->exec_sql('delete from ac_dossier where dos_id=$1',array($id));
128 $cn->exec_sql('drop database '.$name);
129 exit();
130 }
131 $new_cn=new Database($id);
132
133 $new_cn->apply_patch($name);
134 echo '<span class="error">'._('Ne pas recharger la page, sinon votre base de données sera restaurée une fois de plus').'</span>';
136 Noalyss_user::remove_inexistant_user($id);
137 $new_cn->clean_orphan_lob();
138 echo $retour;
139
140 echo '</div>';
141 }
142 //---------------------------------------------------------------------------
143 // Restore a modele
144
145 if ( $_REQUEST['t']=='m')
146 {
147 echo '<div class="content">';
148
149 $cn=new Database();
150 $id=$cn->get_next_seq('s_modid');
151
152 if ( noalyss_strlentrim($_REQUEST['database']) == 0 )
153 $lname=$id." Restauration :".$_FILES['file']['name'];
154 else
155 $lname=$id." ".$_REQUEST['database'];
156
157 $ldesc=$http->post("desc");
158 $sql="insert into modeledef (mod_id,mod_name,mod_desc) values ($1,$2,$3)";
159 $cn->start();
160 try
161 {
162 $cn->exec_sql($sql,array($id,$lname,$ldesc));
163
164 }
165 catch ( Exception $e)
166 {
167 echo '<span class="error">'._("Echec de la restauration ").'</span>';
168 $cn->rollback();
169 exit();
170 }
171 $cn->commit();
172
173 $name=domaine."mod".$id;
174 $cn->exec_sql("create database ".$name." encoding='utf8'");
175 $args=" -d $name ".$_FILES['file']['tmp_name'];
176 $status=exec(PG_RESTORE.$args);
177
178 $test=new Database($id,'mod');
179 if ( $test->exist_table('version') )
180 {
181 echo '<h2 class="info"> '._('Restauration réussie du dossier ').$lname.'</h2>';
182 $test->close();
183 }
184 else
185 {
186 $test->close();
187 echo '<h2 class="error"> '._('Problème lors de la restauration ').$lname.'</h2>';
188 $cn->exec_sql('delete from modeledef where mod_id=$1',array($id));
189 $cn->exec_sql('drop database '.$name);
190 exit();
191 }
192
193 $new_cn=new Database($id,'mod');
194
195 $new_cn->apply_patch($name);
196 $new_cn->clean_orphan_lob();
197 echo '<span class="error">'._('Ne pas recharger la page, sinon votre base de données sera restaurée une fois de plus').'</span>';
198 echo $retour;
199
200 echo '</div>';
201 }
202}
203else
204{
205 echo '<div class="content" style="width:80%;margin-left:10%">';
206 printf( '<form method="POST" action="admin-noalyss.php" enctype="multipart/form-data" onsubmit="return check_file_size(this,%s) " >',MAX_FILE_SIZE);
207 echo HtmlInput::hidden('action','restore');
208 echo HtmlInput::hidden('sa','r');
209 echo '<table>';
210 echo '<tr><td>'._("Nom de la base de donnée").Icon_Action::infobulle(29)
211 .'</td>';
212 echo HtmlInput::hidden("MAX_FILE_SIZE",MAX_FILE_SIZE);
214 $wNom->name="database";
215 $wNom->size=30;
216 echo '<td>'.$wNom->input().'</td></tr>';
217 echo '<tr><td>'._("Type de backup")." :".'</td>';
219 $chk->name="t";
220 $chk->value="d";
221 echo '<td> '.$chk->input()._("Dossier").'</td>';
222 echo '</tr><tr><td></td>';
223 $chk->name="t";
224 $chk->value="m";
225 echo '<td>'.$chk->input()._("Modele").'</td>';
226 echo '<tr>';
228 $file->name="file";
229 $file->value="mod";
230 echo td(_('Fichier ')).
231 td($file->input());
232 $desc=new ITextarea('desc');
233 echo '</tr>';
234 echo '</table>';
235 echo "<p>Description </p>";
236 $desc->heigh=4;$desc->width=60;
237 echo $desc->input();
238 echo '<p>';
239 echo HtmlInput::submit("",_("Restauration"));
240 echo '</p>';
241 echo '</form>';
242 echo '</div>';
243}
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:511
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
$retour
Definition: action.inc.php:27
$_REQUEST['ac']
contains the class for connecting to Noalyss
static synchro_admin($p_id)
connect to folder and give to admin.
static hidden($p_name, $p_value, $p_id="")
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
manage the http input (get , post, request) and extract from an array
Html Input for uploading file, must be in a form with enctype="multipart/form-data".
Definition: ifile.class.php:31
Html Input.
Html Input.
Definition: itext.class.php:30
Manage the TEXTAREA html element.
static echo_file($msg, $print=true)
display the file
Definition: dbg.php:88
for($e=0; $e< count($afiche); $e++) exit
domaine
Definition: install.php:370
$desc
$http
Definition: restore.inc.php:23
$wNom
$file
$chk