noalyss Version-9
dossier.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');
22/*!\file
23* \brief Management of the folder
24 *
25 */
26global $http;
28$sa=$http->request('sa','string','list');
29//---------------------------------------------------------------------------
30// Update
31$dossier_id=$http->request('d', "string",-1);
32
33if ( isset ($_POST['upd']) && isNumber($dossier_id) == 1 && $dossier_id != -1)
34{
35 $dos=new dossier($dossier_id);
36 $name=$http->post('name');
37 $desc=$http->post('desc');
38 $max_email=$http->post("max_email");
39 $dos->set_parameter('name',$name);
40 $dos->set_parameter('desc',$desc);
41 $dos->set_parameter("max_email", $max_email);
42 $dos->save();
43}
44echo '<div class="content">';
45/*
46 * check and add an new folder
47 */
48if ( isset ($_POST["DATABASE"]) )
49{
50 $repo=new Database();
51 try {
52 $dos=$http->post('DATABASE');
53 $template=$http->post("FMOD_ID","number");
54 } catch (Exception $ex) {
55 echo $ex->getMessage();
56 return;
57 }
58 $dos=sql_string($dos);
59 if (strlen($dos)==0)
60 {
61 echo _("Le nom du dossier est vide");
62 exit -1;
63 }
64 /*
65 * check template encoding
66 */
67
68 // Get the modeledef.mod_id
69
70 /*
71 * If template is not empty
72 */
73 if ( $template != 0 )
74 {
75 // compute template name
76 $template_name=domaine.'mod'.$template;
77
78
79 $encoding=$repo->get_value("select encoding from pg_database where ".
80 " datname=$1",array($template_name));
81 if ( $encoding != 6 )
82 {
83 alert(_('Désolé vous devez migrer ce modèle en unicode'));
84 echo '<span class="error">';
85 echo _('le modele ').domaine.'mod'.$http->post("FMOD_ID","number")._(" doit être migré en unicode.");
86 echo _('Pour le passer en unicode, faites-en une sauvegarde puis restaurez le fichier reçu').'</span>';
87 echo HtmlInput::button_anchor('Retour','admin-noalyss.php?action=dossier_mgt');
88 return;
89 }
90 }
91 /*
92 * Insert new dossier with description
93 */
94 $desc=$http->post("DESCRIPTION");
95 $max_email=$http->post("max_email","number");
96 try
97 {
98 $repo->start();
99 if (isNumber($max_email) == 0) $max_email=-1;
100 $Res=$repo->exec_sql("insert into ac_dossier(dos_name,dos_description,dos_email)
101 values ($1,$2,$3)",array($dos,$desc,$max_email));
102 $l_id=$repo->get_current_seq('dossier_id');
103 $repo->commit();
104
105
106 }
107 catch (Exception $e)
108 {
109 $msg=_("Desole la creation de ce dossier a echoue,\n la cause la plus probable est".
110 ' deux fois le même nom de dossier');
111 alert($msg);
112 $l_id=0;
113 $repo->rollback();
114
115 }
116 // If the id is not null, name successfully inserted
117 // Database created
118
119 if ( $l_id != 0)
120 {
121 /*
122 * We don't create and empty database
123 */
124 if ($template != 0 )
125 {
126 //--
127 // setting the year
128 //--
129 $year=sql_string($_POST['YEAR']);
130 if ( strlen($year) != 4 || isNumber($year) == 0 || $year > 2100 || $year < 2000 || $year != round($year,0))
131 {
132 echo "$year"._(" est une année invalide");
133 $Res=$repo->exec_sql("delete from ac_dossier where dos_id=$1",[$l_id]);
134 }
135 else
136 {
137 $Sql=sprintf("CREATE DATABASE %sDOSSIER%d encoding='UTF8' TEMPLATE %sMOD%d",
138 domaine,
139 $l_id,
140 domaine,
141 sql_string($_POST["FMOD_ID"]));
142 ob_start();
143 if ( $repo->exec_sql($Sql)==false)
144 {
145 echo "[".$Sql."]";
146
147 //ob_end_clean();
148 $repo->exec_sql("delete from ac_dossier where dos_id=$l_id");
149 echo "<h2 class=\"error\">"._(" Base de donnée ").domaine."mod".$_POST['FMOD_ID']." ".
150 _("est accèdée, déconnectez-vous d'abord")."</h2>";
151 exit;
152 }
153 ob_flush();
154 // Connect to the new database
155 $cn=new Database($l_id);
156 //--year --
157 $Res=$cn->exec_sql("delete from parm_periode");
158 if ( ($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0 )
159 $fev=29;
160 else
161 $fev=28;
162 $Res=$cn->exec_sql("delete from user_local_pref where parameter_type='PERIODE'");
163 $nb_day=array(31,$fev,31,30,31,30,31,31,30,31,30,31);
164 $m=1;
165 foreach ($nb_day as $day)
166 {
167 $p_start=sprintf("01-%d-%s",$m,$year);
168 $p_end=sprintf("%d-%d-%s",$day,$m,$year);
169 $sql=sprintf("insert into parm_periode (p_start,p_end,p_exercice)
170 values (to_date('%s','DD-MM-YYYY'),to_date('%s','DD-MM-YYYY'),'%s')",
172 $Res=$cn->exec_sql($sql);
173 $m++;
174 }
175 $sql=" insert into jrn_periode(p_id,jrn_def_id,status) ".
176 "select p_id,jrn_def_id, 'OP'".
177 " from parm_periode cross join jrn_def";
178 $Res=$cn->exec_sql($sql);
179
181 Noalyss_user::remove_inexistant_user($l_id);
182 Noalyss_user::audit_admin(sprintf('CREATE DATABASE %s %s',$l_id,$dos));
183
184 // -- patch it if need
185 $db=new Database($l_id, 'dos');
186 echo h2("$l_id - $dos");
187 $db->apply_patch($db->format_name($l_id, "dos"));
188
189 echo '<p class="text-center">';
190 echo HtmlInput::button_anchor(_("Retour"), "?action=dossier_mgt", uniqid(),"","button");
191 echo '</p>';
192 return ;
193 }
194 }
195 else {
196 /*
197 * An empty database is asked, it is created
198 */
199 $Sql=sprintf("CREATE DATABASE %sDOSSIER%d encoding='UTF8' ",
200 domaine,
201 $l_id,
202 domaine
203 );
204 ob_start();
205 if ( $repo->exec_sql($Sql)==false)
206 {
207 echo "[".$Sql."]";
208
209 //ob_end_clean();
210 $repo->exec_sql("delete from ac_dossier where dos_id=$l_id");
211 echo _("Echec création ");
212 exit;
213 }
214 Noalyss_user::audit_admin(sprintf('CREATE DATABASE %s %s',$l_id,$dos));
215 ob_flush();
216
217 }
218 } // if $l_id != 0
219} // $_POST[DATABASE]
220?>
221<h2> <?php echo _('Dossier Management')?></h2>
222
223<?php
224//---------------------------------------------------------------------------
225// List of folder
226if ( $sa == 'list' )
227{
228 echo '<p>';
229 echo HtmlInput::button(_('Ajouter'),_('Ajouter un dossier')," onclick=\$('folder_add_id').show()");
230 echo '</p>';
231 $header=new Sort_Table();
232 $url=$_SERVER['PHP_SELF']."?sa=list&action=".$_REQUEST['action'];
233 $header->add(_("id"),$url," order by dos_id asc"," order by dos_id desc","da","dd");
234 $header->add(_("Nom"),$url," order by dos_name asc"," order by dos_name desc","na","nd");
235 $header->add(_("Description"),$url," order by dos_description asc"," order by dos_description desc","da","dd");
236 $repo=new Dossier(0);
237 $repocn=new Database();
238 $ord=(isset($_REQUEST['ord']))?$_REQUEST['ord']:'na';
239 $sql_order=$header->get_sql_order($ord);
240 $Res=$repocn->get_array("select * from ac_dossier $sql_order");
241
242 $compteur=1;
243 $template="";
244 echo '<div class="content">';
245 echo '<span style="display:block">';
246 echo _('Cherche').Icon_Action::infobulle(23);
247 echo HtmlInput::filter_table("t_dossier", "0,1,2","1");
248 echo '</span>';
249 echo '<TABLE id="t_dossier" class="table_large" >';
250 $r="";
251 $r.='<th>'.$header->get_header(0).'</td>';
252 $r.='<th>'.$header->get_header(1).'</td>';
253 $r.='<th>'.$header->get_header(2).'</td>';
254 $r.=th(_('Taille')).th(_('Nom base de données'));
255
256 $r=tr($r);
257 echo $r;
258 // show all dossiers
259 if ( $Res != null )
260 {
261 foreach ( $Res as $Dossier)
262 {
263
264 if ( $compteur%2 == 0 )
265 $cl='class="odd"';
266 else
267 $cl='class="even"';
268
269 echo "<TR id=\"folder{$Dossier['dos_id']}\" $cl><TD style=\"vertical-align:top\"> ".
270 $Dossier['dos_id']."</td><td> <B>".h($Dossier['dos_name'])."</B> </TD>";
271 $str_name=domaine.'dossier'.$Dossier['dos_id'];
272
273 echo "<TD><I> ".h($Dossier['dos_description'])."</I></td>";
274
275 $database_exist=$repocn->exist_database($str_name);
276
277 if ($database_exist > 0 )
278 {
279 $size=$repocn->get_value("select pg_database_size($1)/(1024*1024)::float",
280 array($str_name));
281 echo td(nbm($size)."MB",' style="text-align:right"');
282 } else {
283 echo td(_("Dossier inexistant"),'style="color:red"');
284 }
285 echo td($str_name);
286 if ( $database_exist > 0)
287 {
288 echo td(HtmlInput::anchor(_('Effacer'),'?action=dossier_mgt&sa=del&d='.$Dossier['dos_id']," onclick=\"folder_drop('".$Dossier['dos_id']."')\""));
289
290 echo td(HtmlInput::anchor(_('Modifier'),'?action=dossier_mgt&sa=mod&d='
291 .$Dossier['dos_id']," onclick=\"folder_modify('".$Dossier['dos_id']."')\""));
292
293 echo td(HtmlInput::anchor(_('Sauvegarde'),'?action=backup&sa=b&t=d&d='
294 .$Dossier['dos_id']));
295 } else
296 {
297 echo td(HtmlInput::anchor(_('Effacer'),'?action=dossier_mgt&sa=del&d='.$Dossier['dos_id']," onclick=\"folder_drop('".$Dossier['dos_id']."')\""));
298 }
299 $compteur++;
300
301 }
302 echo "</TR>";
303
304 }
305 echo '</table>';
306
307
308}
309?>
310<div id="folder_add_id" class="inner_box" style="display:none;top:50px">
311 <?php
312//---------------------------------------------------------------------------
313// Add a new folder
314 echo HtmlInput::title_box(_("Ajout d'un dossier"), 'folder_add_id', "hide");
316 // Load the available Templates
317 $Res=$repo->exec_sql("select mod_id,mod_name,mod_desc from
318 modeledef order by mod_name");
320
321 if ( $count == 0 )
322 {
323 echo _("pas de modèle disponible");
324 }
325 else
326 {
327 $template='<SELECT NAME=FMOD_ID>';
328
329 for ($i=0;$i<$count;$i++)
330 {
332 $template.='<OPTION VALUE="'.$mod['mod_id'].'"> '.h($mod['mod_name']." - ".mb_substr($mod['mod_desc'],0,30));
333 }// for
334 $template.='<option value="0" > ** '._('Aucun modèle (dossier vide, devant être restauré manuellement)').' ** ';
335 $template.="</SELECT>";
336 }// if count = 0
337 $m_date=date('Y');
338
339 ?>
340
341 </TABLE>
342
343 <FORM ACTION="admin-noalyss.php?action=dossier_mgt" METHOD="POST" onsubmit="waiting_box();return true;">
344 <TABLE>
345 <TR>
346 <TD><?php echo _('Nom du dossier');
347 ?></td><td> <INPUT TYPE="TEXT" class="input_text" NAME="DATABASE"> </TD>
348 </TR><TR>
349 <TD><?php echo _('Description');
350 ?></td><td> <TEXTAREA class="input_text" COLS="60" ROWS="2" NAME="DESCRIPTION" ></TEXTAREA> </TD>
351 </TR>
352<tr>
353 <td>
354 <?php echo _('Max. email / jour (-1 = illimité)') ;?>
355 </td>
356 <td>
357 <?php
358 $max_email_input=new INum('max_email');
361 echo $max_email_input->input();
362 ?>
363 </td>
364</tr>
365 <TR> <TD><?php echo _('Modèle');
366 ?></td><td> <?php echo $template;
367 ?> </TD></TR>
368 <TR><TD><?php echo _('Année')?> </TD><TD><input class="input_text" type="text" size=4 name="YEAR" value=<?php echo '"'.$m_date.'"'; ?>></TD></TR>
369 <TR>
370 <TD> <INPUT TYPE=SUBMIT class="button" VALUE="<?php echo _('Creation Dossier'); ?>"> </TD>
371 <td>
372 </td>
373 </TR>
374 </TABLE>
375 </FORM>
376 <?php
377
378?>
379</div>
380<?php
381//---------------------------------------------------------------------------
382// action = del
383//---------------------------------------------------------------------------
384if ( $sa == 'remove' && isNumber($dossier_id) == 1 && $dossier_id != -1 )
385{
386 $ctl=$http->request("fld_drop");
387 $ctl_code=$http->request("ctlcode");
388 if ( $ctl != $ctl_code)
389 {
390 echo _('Désolé, le code est invalide');
391 echo HtmlInput::button_anchor(_('Retour'),'?action=dossier_mgt');
392 return;
393 }
394
395 $cn=new Database();
396 $msg="dossier";
397 $name=$cn->get_value("select dos_name from ac_dossier where dos_id=$1",array($dossier_id));
398 if ( noalyss_strlentrim($name) == 0 )
399 {
400 echo "<h2 class=\"error\"> $msg "._('inexistant')."</h2>";
401 return;
402 }
403 /**
404 * Check if db exists
405 */
407
408 $database_exist=$cn->exist_database($str_name);
409
410 // if db exists for postgres then drop it
411 if ( $database_exist == 1)
412 {
413 $sql="drop database ".$str_name;
414 ob_start();
415 if ( $cn->exec_sql($sql)==false)
416 {
417 ob_end_clean();
418
419 echo "<h2 class=\"error\"> ";
420 echo _('Base de donnée ').domaine."dossier".$_REQUEST['d'].
421 _("est accèdée, déconnectez-vous d'abord")."</h2>";
422 exit;
423 }
424 ob_flush();
425 }
426
427 // clean tables about this dossier
428 $sql="delete from jnt_use_dos where dos_id=$1";
429 $cn->exec_sql($sql,array($dossier_id));
430 $sql="delete from ac_dossier where dos_id=$1";
431 $cn->exec_sql($sql,array($dossier_id));
432 print '<h2 class="error">';
433 printf (_("Le dossier %s est effacé").'</h2>',h($name));
434 Noalyss_user::audit_admin(sprintf('DROP DATABASE %s %s',$dossier_id,$name));
435 echo HtmlInput::button_anchor(_('Retour'),'?action=dossier_mgt');
436}
437?>
438</div>
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
isNumber($p_int)
Definition: ac_common.php:215
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
tr($p_string, $p_extra='')
Definition: ac_common.php:88
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
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:137
alert($p_msg, $buffer=false)
alert in javascript
Definition: ac_common.php:738
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
$url
$opd_description style
$name size
$_REQUEST['ac']
$from_poste name
$ex
Definition: balance.inc.php:45
$input_from type
Definition: balance.inc.php:65
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
contains the class for connecting to Noalyss
manage the current dossier, everywhere we need to know to which folder we are connected,...
static synchro_admin($p_id)
connect to folder and give to admin.
static filter_table($p_table_id, $p_col, $start_row)
filter the rows in a table and keep the colored row in alternance
static button($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
static anchor($p_text, $p_url="", $p_js="", $p_style=' class="line" ', $p_title="click", array $p_attribute=[])
Return a simple anchor with a url or a javascript if $p_js is not null then p_url will be javascript:...
static title_box($p_name, $p_div, $p_mod="close", $p_js="", $p_draggable="n", $p_enlarge='n')
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
static button_anchor($p_label, $p_value, $p_name="", $p_javascript="", $p_class="smallbutton")
create a button with a ref
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: inum.class.php:42
static echo_file($msg, $print=true)
display the file
Definition: dbg.php:88
Description of class_syn_sort_table.
const ACTION
Definition: constant.php:196
$_POST['ac']
Definition: do.php:310
$max_email_input
$Res
$repo
global $http
Definition: dossier.inc.php:26
$sa
Definition: dossier.inc.php:28
$m_date
for($i=0;$i< $count;$i++) $template
$max_email_input value
$dossier_id
Definition: dossier.inc.php:31
$count
for($e=0; $e< count($afiche); $e++) exit
if(count($array)==0) $size
if(count($a_accounting)==0) $header
$p_end
$p_start
print
Type of printing.
domaine
Definition: install.php:370
$ord
Definition: menu.inc.php:115
$sql_order
Definition: modele.inc.php:247