noalyss Version-9
modele.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
21
22/**
23 * \file
24 *
25 *
26 * \brief concerne only the template
27 *
28 */
29if ( !defined ('ALLOWED')) die('Forbidden');
32$sa = $http->request("sa", "string", 'list');
33if (isset($_POST['upd']) &&
34 isset($_POST['m']))
35{
36 $name=$http->post('name');
37 $desc =$http->post('desc');
38 $mod_id=$http->post("m", "number",0);
39
40 if (trim($name) != "" && $mod_id != 0 && isNumber($mod_id)==1)
41 {
42 $cn = new Database();
43 $cn->exec_sql("update modeledef set mod_name=$1, " .
44 " mod_desc=$2 where mod_id=$3 ",
45 array(trim($name), trim($desc), $mod_id));
46 }
47 $sa = "list";
48}
49
50$cn = new Database();
51
52$fmod_dbid=$http->post("FMOD_DBID","number",0);
53
54// IF FMOD_NAME is posted then must add a template
55if (isset($_POST["FMOD_NAME"]))
56{
57 $encoding = $cn->get_value("select encoding from pg_database where " .
58 " datname=$1",array(domaine . 'dossier' . $fmod_dbid));
59
60 if ($encoding != 6)
61 {
62 alert(_('Désolé vous devez migrer ce modèle en unicode'));
63 echo '<span class="error">';
64 printf (_('la base de donnée %smod%s doit être migrée en unicode'),domaine,$fmod_dbid);
65 echo "</span>";
66 echo '<span class="error"> '._("Pour le passer en unicode, faites-en un backup puis restaurez le fichier reçu").'</span>';
67
68 echo HtmlInput::button_anchor(_('Retour'), 'admin-noalyss.php?action=dossier_mgt');
69 return;
70 }
71
72 $mod_name = $http->post("FMOD_NAME");
73 $mod_desc = $http->post("FMOD_DESC");
74 if ($mod_name != null || trim ($mod_name) != "")
75 {
76 $Res = $cn->exec_sql("insert into modeledef(mod_name,mod_desc)
77 values ($1,$2)",array($mod_name,$mod_desc));
78
79 // get the mod_id
80 $l_id = $cn->get_current_seq('s_modid');
81 if ($l_id != 0)
82 {
83 $Sql = sprintf("CREATE DATABASE %sMOD%d encoding='UTF8' TEMPLATE %sDOSSIER%s", domaine, $l_id, domaine, $_POST["FMOD_DBID"]);
84 ob_start();
85 if ($cn->exec_sql($Sql) == false)
86 {
87 ob_end_clean();
88 echo "<h2 class=\"error\">";
89 printf(_('Base de donnée %sdossier%d" est accèdée, déconnectez-vous en d\'abord'),domaine,$fmod_dbid);
90 echo "</h2>";
91 $Res = $cn->exec_sql("delete from modeledef where mod_id=$1",array($l_id));
92
93 exit;
94 }
95 }
96 }// if $mod_name != null
97 else
98 {
99 alert(_('Le nom est vide'));
100 return;
101 }
102 $cn_mod = new Database($l_id, 'mod');
103
104 // Clean some tables
105
106 $Res = $cn_mod->exec_sql("select distinct jr_pj from jrn where jr_pj is not null ");
107 if (Database::num_row($Res) != 0)
108 {
109 $a_lob = Database::fetch_all($Res);
110 $nb_lob=($a_lob == FALSE)?0:count($a_lob);
111 for ($i = 0; $i < $nb_lob; $i++)
112 $cn_mod->lo_unlink($a_lob[$i]['jr_pj']);
113 }
114 $Res = $cn_mod->exec_sql("truncate table centralized");
115 $Res = $cn_mod->exec_sql("truncate table jrn cascade");
116 $Res = $cn_mod->exec_sql("delete from del_jrn");
117 $Res = $cn_mod->exec_sql("delete from del_jrnx");
118 $Res = $cn_mod->exec_sql("truncate table jrnx cascade ");
119 $Res = $cn_mod->exec_sql("truncate table todo_list cascade ");
120 $Res = $cn_mod->exec_sql("delete from del_action");
121 $Res = $cn_mod->exec_sql("delete from profile_user");
122 $Res = $cn_mod->exec_sql("delete from jnt_letter");
123
124 $Res = $cn_mod->exec_sql('delete from operation_analytique');
125 // Delete info from USERS
126 $Res = $cn_mod->exec_sql('delete from user_sec_act');
127 $Res = $cn_mod->exec_sql('delete from user_sec_action_profile');
128 $Res = $cn_mod->exec_sql('delete from user_local_pref');
129 $Res = $cn_mod->exec_sql('delete from user_sec_jrn');
130 $Res = $cn_mod->exec_sql('delete from bookmark');
131
132 // Reset the closed periode
133 $Res = $cn_mod->exec_sql("update parm_periode set p_closed='f'");
134 $Res = $cn_mod->exec_sql('delete from jrn_periode');
135 $Res = $cn_mod->exec_sql(' insert into jrn_periode(p_id,jrn_def_id,status) ' .
136 ' select p_id,jrn_def_id,\'OP\' ' .
137 ' from ' .
138 ' parm_periode cross join jrn_def');
139
140 // Reset Sequence
141 $a_seq = array('s_jrn', 's_jrn_op', 's_centralized', 's_stock_goods', 's_internal');
142 foreach ($a_seq as $seq)
143 {
144 $sql = sprintf("select setval('%s',1,false)", $seq);
145 $Res = $cn_mod->exec_sql($sql);
146 }
147 $sql = "select jrn_def_id from jrn_def ";
148 $Res = $cn_mod->exec_sql($sql);
150 for ($seq = 0; $seq < $Max; $seq++)
151 {
153 /* if seq doesn't exist create it */
154 if ($cn_mod->exist_sequence('s_jrn_' . $row['jrn_def_id']) == false)
155 {
156 $cn_mod->create_sequence('s_jrn_' . $row['jrn_def_id']);
157 }
158
159
160 $sql = sprintf("select setval('s_jrn_%d',1,false)", $row['jrn_def_id']);
161 $cn_mod->exec_sql($sql);
162
163 $sql = sprintf("select setval('s_jrn_pj%d',1,false)", $row['jrn_def_id']);
164 $cn_mod->exec_sql($sql);
165 $sql = sprintf("select setval('jnt_letter_jl_id_seq',1,false)");
166 $cn_mod->exec_sql($sql);
167 }
168 //---
169 // Cleaning Follow_Up
170 //--
171 if (isset($_POST['DOC']))
172 {
173 $Res = $cn_mod->exec_sql("delete from action_gestion_related");
174 $Res = $cn_mod->exec_sql("delete from action_gestion_comment");
175 $Res = $cn_mod->exec_sql("delete from action_gestion_related");
176 $Res = $cn_mod->exec_sql("delete from action_person");
177 $Res = $cn_mod->exec_sql("delete from action_gestion");
178 $Res = $cn_mod->exec_sql("delete from tags");
179 $Res = $cn_mod->exec_sql("delete from action_tags");
180 $Res = $cn_mod->exec_sql("delete from document");
181
182 // reset sequences for Follow-up
183 $a_seq=$cn_mod->get_array(" select sequence_name "
184 . " from information_schema.sequences "
185 . "where sequence_name like 'seq_doc_type%'"
186 );
187 $n_seq=count($a_seq);
188 for ($i = 0;$i < $n_seq;$i++) {
189 $cn_mod->alter_seq($a_seq[$i]['sequence_name'], 1);
190 }
191 }
192 if (isset($_POST['CARD']))
193 {
194 // it is necessary to remove the plugin amortissement due to a
195 // Foreign key without cascading
196 $a_schema=$cn_mod->get_array("
197 select nspname from pg_namespace
198 where
199 nspname not like 'pg_%'
200 and nspname in ('amortissement')
201 ");
202 $nb_schema=count($a_schema);
203 for ($i=0;$i < $nb_schema;$i++)
204 {
205 $cn_mod->exec_sql(" drop schema ".$a_schema[$i]['nspname']." cascade");
206 }
207 $Res = $cn_mod->exec_sql("delete from action_gestion");
208 $Res = $cn_mod->exec_sql("delete from fiche_detail");
209 $Res = $cn_mod->exec_sql("delete from fiche");
210 $Res = $cn_mod->exec_sql("delete from document");
211 $Res = $cn_mod->exec_sql("delete from document_modele");
212 $Res = $cn_mod->exec_sql("delete from op_predef");
213
214
215 }
216 if (isset($_POST['CANAL']))
217 {
218 $Res = $cn_mod->exec_sql('delete from poste_analytique');
219 $Res = $cn_mod->exec_sql('delete from plan_analytique');
220 }
221 if ( isset ($_POST['PLUGIN'])) {
222 $a_schema=$cn_mod->get_array("
223 select nspname from pg_namespace
224 where
225 nspname not like 'pg_%'
226 and nspname not in ('information_schema','public','comptaproc')
227 ");
228 $nb_schema=count($a_schema);
229 for ($i=0;$i < $nb_schema;$i++)
230 {
231 $cn_mod->exec_sql(" drop schema ".$a_schema[$i]['nspname']." cascade");
232 }
233 }
234 // Clean orphan log
235 $cn_mod->clean_orphan_lob();
236
237}
238// Show all available templates
239$url=$_SERVER['PHP_SELF']."?".http_build_query(array("sa"=>"list","action"=>$http->request('action')));
240
242$header->add(_("id"),$url," order by mod_id asc"," order by mod_id desc","ia","id");
243$header->add(_("Nom"),$url," order by mod_name asc"," order by mod_name desc","na","nd");
244$header->add(_("Description"),$url," order by mod_desc asc"," order by mod_desc desc","da","dd");
245
246$ord=(isset($_REQUEST['ord']))?$_REQUEST['ord']:'na';
247$sql_order=$header->get_sql_order($ord);
248
249$Res = $cn->exec_sql("select mod_id,mod_name,mod_desc from
250 modeledef $sql_order");
251
253echo '<div class="content">';
254echo "<H2>"._('Modèles')."</H2>";
255if ($sa == 'list')
256{
257 echo '<p>';
258 echo HtmlInput::button(_('Ajouter'),_('Ajouter un modèle')," onclick=\$('folder_add_id').show()");
259
260 echo '</p>';
261 echo "<p class=\"notice\">" . _("Si vous voulez r&eacute;cup&eacute;rer toutes les adaptations d'un dossier " .
262 " dans un autre dossier, vous pouvez en faire un modèle." .
263 " Seules les fiches, la structure des journaux, les p&eacute;riodes,... seront reprises " .
264 "et aucune donn&eacute;e du dossier sur lequel le dossier est bas&eacute;. Les données contenues dans les extensions ne sont pas effacées") . "</p>";
265 echo h2(_("Modèles locaux"));
266 if ($count == 0)
267 {
268 echo _("Aucun modèle disponible");
269 }
270 else
271 {
272
273 echo '<span style="display:block;margin-top:10">';
274 echo _('Filtre').Icon_Action::infobulle(23);
275 echo HtmlInput::filter_table("t_modele", "0,1,2","1");
276 echo '</span>';
277 echo '<table id="t_modele" class="table_large" style="border-spacing:10;border-collapse:separate" >';
278 echo "<TR>".
279 "<TH>".$header->get_header(0)."</TH>" .
280 "<TH>".$header->get_header(1)."</TH>" .
281 "<TH>".$header->get_header(2)."</TH>" .
282 "<TH>"._('Nom base de données')."</TH>" .
283 "<th> </th>" .
284 "<th> </th>" .
285 "</TR>";
286
287 for ($i = 0; $i < $count; $i++)
288 {
290 $class = ($i % 2 == 0) ? "odd" : "even";
291 $str_name=domaine.'mod'.$mod['mod_id'];
292 $valid=true;
293 $exist=true;
294 $mod_status="";
295 if ( $cn->exist_database($str_name) == 0 ) {
296 $exist=false;
297 $mod_status=_('Inexistant');
298 }
299 if ( $exist ) {
300 $mod_cn=new Database($mod['mod_id'],'mod');
301 if ( $mod_cn->exist_table("version")==0) {
302 $valid=false;
303 $mod_status=_('Invalide');
304 }
305 }
306 printf('<TR class="' . $class . '" style="vertical-align:top">' .
307 '<TD>%d </td><td><b> %s</b> </TD>' .
308 '<TD><I> %s </I></TD>' .
309 '<td>'.$str_name.'</td>'.
310 td($mod_status).
311 '<td> ' .
312 HtmlInput::anchor(_('Effacer'), '?action=modele_mgt&sa=del&m=' . $mod['mod_id']," onclick = \"modele_drop('{$mod['mod_id']}') \"") . '</td>' .
313 '</td>' .
314 '<td>' . HtmlInput::anchor(_('Modifie'), '?action=modele_mgt&sa=mod&m=' . $mod['mod_id']," onclick = \"modele_modify('{$mod['mod_id']}') \"") . '</td>' .
315 '</td>' .
316 '<td>' . HtmlInput::anchor(_('Backup'), '?action=backup&sa=b&t=m&d='
317 . $mod['mod_id']) . '</td>' .
318 '</TR>', $mod['mod_id'], $mod['mod_name'], $mod['mod_desc']);
319 }// for
320 echo "</table>";
321 }// if count = 0
322 echo h2(_("Modèles disponibles dans le dépôt"));
323
324 require NOALYSS_INCLUDE . "/upgrade-template.php";
325
326}
327?>
328<div id="folder_add_id" class="inner_box" style="display:none;top:50px">
329 <?php
330 echo HtmlInput::title_box(_("Ajout d'un modèle"), 'folder_add_id', "hide");
331
332//---------------------------------------------------------------------------
333// Add a template
334//---------------------------------------------------------------------------
335// Show All available folder
336 $Res = $cn->exec_sql("select dos_id, dos_name,dos_description from ac_dossier
337 order by dos_name");
340 if ($count != 0)
341 {
342 $available = '<SELECT NAME="FMOD_DBID">';
343 for ($i = 0; $i < $count; $i++)
344 {
346 $available.='<OPTION VALUE="' . $db['dos_id'] . '">' . $db['dos_name'] . ':' . $db['dos_description'];
347 }//for i
348 $available.='</SELECT>';
349 }//if count !=0
350 ?>
351 <form action="admin-noalyss.php?action=modele_mgt" METHOD="post" onsubmit="waiting_box();return true;">
352 <TABLE>
353 <tr>
354 <td><?php echo _('Nom')?> </TD>
355 <TD><INPUT TYPE="TEXT" class="input_text" VALUE="" NAME="FMOD_NAME"></TD>
356 </TR>
357 <TR>
358 <TD><?php echo _('Description')?></TD>
359 <TD><TEXTAREA ROWS="2" class="input_text" COLS="60" NAME="FMOD_DESC"></Textarea></TD>
360 </TR>
361 <TR>
362 <TD> <?php echo _("Bas&eacute; sur")?> </TD>
363 <TD> <?php echo $available?></TD>
364 </TR>
365 </table>
366 <ol style="list-style: none">
367 <li>
368 <input type="checkbox" class="input_text" name="DOC">
369 <?php echo _("Nettoyage des Documents et courriers (ce qui n'effacera pas les modèles de documents)")?>
370 </li>
371 <li>
372 <input type="checkbox" class="input_text" name="CARD">
373 <?php echo _("Nettoyage de toutes les fiches (ce qui effacera client,
374 op&eacute;rations pr&eacute;d&eacute;finies fournisseurs modèles de documents et documents)")?>
375 </li>
376 <li>
377 <input class="input_text" type="checkbox" name="CANAL">
378 <?php echo _("Nettoyage de la comptabilit&eacute; analytique : effacement des plans et des postes, les op&eacute;rations
379 sont de toute fa&ccedil;on effac&eacute;es")?>
380 </li>
381 <li>
382 <input class="input_text" type="checkbox" name="PLUGIN">
383 <?php echo _("Effacement de toutes les donn&eacute;es des plugins")?>
384 </li>
385 </ol>
386 <INPUT TYPE="SUBMIT" class="button" VALUE="<?php echo _("Ajout d'un modele")?>" >
387</form>
388</div>
389 <?php
390
391 //---------------------------------------------------------------------------
392 // action = del
393 //---------------------------------------------------------------------------
394 if ($sa == 'remove')
395 {
396 if (!isset($_REQUEST['p_confirm']))
397 {
398 echo _('Désolé, vous n\'avez pas coché la case');
399 echo HtmlInput::button_anchor(_('Retour'), '?action=modele_mgt');
400 return;
401 }
402 try {
403 $mod_id=$http->request('m', "number");
404
405 }
406 catch (Exception $e)
407 {
408 echo _('Donnée invalide');
409 return;
410 }
411 $cn = new Database();
412 $msg = "dossier";
413 $name = $cn->get_value("select mod_name from modeledef where mod_id=$1", array($mod_id));
414 if (noalyss_strlentrim($name) == 0)
415 {
416 echo "<h2 class=\"error\"> $msg inexistant</h2>";
417 return;
418 }
419 // Before dropping database check that database exist
420 if ( $cn->exist_database(domaine.'mod'.$mod_id) == 1)
421 {
422 $sql = "drop database " . domaine . "mod" . sql_string($mod_id);
423 ob_start();
424 if ($cn->exec_sql($sql) == false)
425 {
426 ob_end_clean();
427
428 echo "<h2 class=\"error\">";
429 printf (_("Base de donnée %s mod %s est accèdée, déconnectez-vous d'abord"),domaine,$mod_id )
430 . "</h2>";
431 exit;
432 }
433 ob_flush();
434 }
435 $sql = "delete from modeledef where mod_id=$1";
436 $cn->exec_sql($sql, array($mod_id));
437 print '<h2 class="error">';
438 printf (_("Le modèle %s est effacé")."</H2>",$name );
439 echo HtmlInput::button_anchor(_('Retour'), '?action=modele_mgt');
440 }
441 echo '</div>';
442 ?>
443
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
isNumber($p_int)
Definition: ac_common.php:215
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
alert($p_msg, $buffer=false)
alert in javascript
Definition: ac_common.php:738
$opd_description style
$_REQUEST['ac']
$from_poste name
$input_from type
Definition: balance.inc.php:65
$class
static fetch_all($ret)
wrapper for the function pg_fetch_all
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
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
manage the http input (get , post, request) and extract from an array
static echo_file($msg, $print=true)
display the file
Definition: dbg.php:88
Description of class_syn_sort_table.
$all table
$_POST['ac']
Definition: do.php:310
for($e=0; $e< count($afiche); $e++) exit
domaine
Definition: install.php:370
if(isset($_POST['upd']) &&isset($_POST['m'])) $cn
Definition: modele.inc.php:50
$Res
Definition: modele.inc.php:249
if(noalyss_strlentrim( $name)==0) if( $cn->exist_database(domaine. 'mod'. $mod_id)==1) $sql
Definition: modele.inc.php:435
$sql_order
Definition: modele.inc.php:247
print
Definition: modele.inc.php:437
$fmod_dbid
Definition: modele.inc.php:52
$header
Definition: modele.inc.php:241
vous n
Definition: modele.inc.php:398
$http
Definition: modele.inc.php:31
$sa
Definition: modele.inc.php:32
$ord
Definition: modele.inc.php:246
$msg
Definition: modele.inc.php:412
$name
Definition: modele.inc.php:413
if(isset($_POST["FMOD_NAME"])) $url
Definition: modele.inc.php:239
$available
Definition: modele.inc.php:339
$count
Definition: modele.inc.php:252
$valid
Definition: recover.php:57