/[openfoncier]/trunk/obj/instruction.class.php
ViewVC logotype

Annotation of /trunk/obj/instruction.class.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1183 - (hide annotations)
Tue Jan 8 15:21:06 2013 UTC (12 years ago) by nhaye
File size: 40202 byte(s)
Affichage des liens vers la bible dans le formulaire d'ajout et modification d'instruction

1 fraynaud 3 <?php
2     //$Id$
3 fraynaud 20 //gen openMairie le 10/02/2011 20:34
4     /*
5     $Id: instruction.class.php,v 1.29 2010-10-27 10:52:20 fraynaud Exp $
6     specific :
7     - cle secondaire
8     destruction autorisée que pour le dernier evenement
9     [delete the last event ]
10     - variable globale [global variables]
11     var $archive_date_depot;
12     var $retourformulaire;
13     var $idxformulaire;
14     - modification des données dans dossier trigger avant
15     [modify dossier data with trigger function]
16     - function moisdate : pour ajouter des mois a une date
17     [add months (delay) and calculation final date]
18     - voir script_lang.js : bible ...
19     */
20 fraynaud 3 require_once ("../gen/obj/instruction.class.php");
21 mlimic 910 require_once("../services/outgoing/messageenqueuer.php");
22 fraynaud 3
23     class instruction extends instruction_gen {
24    
25 fraynaud 20 var $archive_date_depot; // specific
26     var $retourformulaire; // specific
27     var $idxformulaire; // specific
28 fraynaud 3
29 fraynaud 20 function instruction($id,&$db,$debug) {
30     $this->constructeur($id,$db,$debug);
31     }// fin constructeur
32    
33 fmichon 944 // {{{ Gestion de la confidentialité des données spécifiques
34    
35     /**
36     * Surcharge pour gérer les actions disponibles dans le portlet
37     */
38     function checkAccessibility() {
39     //
40     parent::checkAccessibility();
41     // Si l'utilisateur est un intructeur qui en correspond pas à la
42     // division du dossier
43     if ($this->f->isUserInstructeur()
44     && isset($this->f->om_utilisateur["division"])
45     && $this->f->om_utilisateur["division"] != $this->getDivisionFromDossier()) {
46     //
47     $this->actions_sup = array();
48     $this->setParameter("actions", array());
49     }
50     // Si une action 'lu' est présente et que le champ lu est à true
51     // on supprime l'action
52     if (isset($this->actions_sup["lu"])
53     && isset($this->val[array_search("lu", $this->champs)])
54     && $this->val[array_search("lu", $this->champs)]== "t") {
55     unset($this->actions_sup["lu"]);
56     }
57     }
58    
59     /**
60     * Cette methode est à surcharger elle permet de tester dans chaque classe
61     * des droits des droits spécifiques en fonction des données
62     */
63     function canAccess() {
64     // Si l'utilisateur est un intructeur qui ne correspond pas à la
65     // division du dossier
66     if ($this->f->isUserInstructeur()
67     && $this->f->om_utilisateur["division"] != $this->getDivisionFromDossier()
68     && $this->getParameter("maj") != 3) {
69     //
70     return false;
71     }
72     //
73     return true;
74     }
75    
76     /**
77     * Cette méthode permet de récupérer la division d'un dossier
78     */
79     function getDivisionFromDossier() {
80     //
81     if (!isset($this->val[array_search("dossier", $this->champs)])) {
82     return NULL;
83     }
84     //
85     $sql = "select division from ".DB_PREFIXE."dossier ";
86     $sql .= " where dossier='".$this->val[array_search("dossier", $this->champs)]."'";
87     //
88     $division = $this->db->getOne($sql);
89     $this->addToLog("getDivisionFromDossier(): db->getone(\"".$sql."\")", VERBOSE_MODE);
90     database::isError($division);
91     //
92     return $division;
93     }
94    
95     // }}}
96    
97 fraynaud 20 function cleSecondaire($id,&$db,$val,$DEBUG) {
98 fraynaud 129 parent::cleSecondaire($id,$db,$val,$DEBUG);
99     // controle suppression cle secondaire [secondary key delete control]
100     // ------------------------------------------------------------------------------------
101     // specifique detruire que le dernier [specific instruction : delete the last event ]
102     // ------------------------------------------------------------------------------------
103 fraynaud 20 $dernierevenement='';
104 fraynaud 242 $sql="select max(instruction) from ".DB_PREFIXE."instruction where dossier ='".
105 fraynaud 20 $this->idxformulaire."'";
106     $dernierevenement = $db->getOne($sql);
107     if($dernierevenement==$id){
108     $this->correct=true;
109 nhaye 460 $this->addToMessage(_('Destruction_chronologique'));
110 fraynaud 20 }else{
111 nhaye 460 $this->addToMessage(_('Destruction_evenement')." : ".$dernierevenement);
112     $this->addToMessage(_('Destruction_chronologique'));
113 fraynaud 20 $this->correct=false;
114     }
115     }
116    
117 vpihour 1058 /*Met des valeurs par défaut dans certains des sous-formulaire*/
118 fraynaud 20 function setValsousformulaire(&$form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire){
119 nhaye 428 if ($validation==0 and $maj<2) {
120 fraynaud 20 if ($maj == 0){
121     $form->setVal("destinataire", $idxformulaire);
122     $form->setVal("dossier", $idxformulaire);
123 vpihour 1127 $form->setVal("date_evenement", date('Y-m-d'));
124 fraynaud 20 }
125     $form->setVal("bible_auto","bible_auto()");
126     $form->setVal("bible","bible()");
127     $form->setVal("bible2","bible2()");
128     }
129     $this->retourformulaire=$retourformulaire;
130     $this->idxformulaire=$idxformulaire;
131     }
132    
133 vpihour 1058 /*Affecte un type à certains champs*/
134 fraynaud 20 function setType(&$form,$maj) {
135 nhaye 428 parent::setType($form,$maj);
136     if ($maj < 2) { //ajouter et modifier
137     $form->setType('destinataire', 'hidden');
138     $form->setType('lettretype', 'hiddenstatic');
139     $form->setType('complement', 'textarea');
140     $form->setType('complement2', 'textarea');
141     $form->setType('bible_auto', 'httpclick');
142     $form->setType('bible', 'httpclick');
143     $form->setType('bible2', 'httpclick');
144     $form->setType('dossier', 'hiddenstatic');
145     $form->setType('libelle', 'hiddenstatic');
146     if($maj==0){ // add
147     $form->setType('instruction', 'hiddenstatic');
148     $form->setType('evenement', 'select');
149 vpihour 1127 $form->setType('date_evenement', 'date2');
150 nhaye 428 }else{ // modify
151     $form->setType('instruction', 'hiddenstatic');
152     $form->setType('evenement', 'hiddenstatic');
153 vpihour 1127 //$form->setType('date_evenement', 'hiddenstaticdate');
154     $form->setType('date_evenement', 'date2');
155 nhaye 428 // necessaire pour calcul de date en modification
156     $form->setType('delai', 'hiddenstatic');
157     }
158 nhaye 460 } elseif($maj==2){
159     $form->setType('dossier', 'hiddenstatic');
160 nhaye 1183 $form->setType('bible_auto', 'hidden');
161     $form->setType('bible', 'hidden');
162     $form->setType('bible2', 'hidden');
163 nhaye 460 }else {
164     $form->setType('destinataire', 'hidden');
165     $form->setType('dossier', 'static');
166 nhaye 1183 $form->setType('bible_auto', 'hidden');
167     $form->setType('bible', 'hidden');
168     $form->setType('bible2', 'hidden');
169 nhaye 428 }
170 fraynaud 20 $form->setType('complement3', 'hidden');
171     $form->setType('bible3', 'hidden');
172     $form->setType('complement4', 'hidden');
173     $form->setType('bible4', 'hidden');
174     $form->setType('complement5', 'hidden');
175     $form->setType('bible5', 'hidden');
176     $form->setType('complement6', 'hidden');
177     $form->setType('bible6', 'hidden');
178     $form->setType('complement7', 'hidden');
179     $form->setType('bible7', 'hidden');
180     $form->setType('complement8', 'hidden');
181     $form->setType('bible8', 'hidden');
182     $form->setType('complement9', 'hidden');
183     $form->setType('bible9', 'hidden');
184     $form->setType('complement10', 'hidden');
185     $form->setType('bible10', 'hidden');
186     $form->setType('complement11', 'hidden');
187     $form->setType('bible11', 'hidden');
188     $form->setType('complement12', 'hidden');
189     $form->setType('bible12', 'hidden');
190     $form->setType('complement13', 'hidden');
191     $form->setType('bible13', 'hidden');
192     $form->setType('complement14', 'hidden');
193     $form->setType('bible14', 'hidden');
194     $form->setType('complement15', 'hidden');
195     $form->setType('bible15', 'hidden');
196     $form->setType('delai', 'hidden');
197     $form->setType('etat', 'hidden');
198     $form->setType('accord_tacite', 'hidden');
199     $form->setType('action', 'hidden');
200     $form->setType('delai_notification', 'hidden');
201 vpihour 489 $form->setType('avis_decision', 'hidden');
202 fraynaud 20 $form->setType('archive_delai', 'hidden');
203     $form->setType('archive_etat', 'hidden');
204     $form->setType('archive_accord_tacite', 'hidden');
205     $form->setType('archive_avis', 'hidden');
206     $form->setType('archive_date_complet', 'hidden');
207     $form->setType('archive_date_rejet', 'hidden');
208     $form->setType('archive_date_limite', 'hidden');
209     $form->setType('archive_date_notification_delai', 'hidden');
210     $form->setType('archive_date_decision', 'hidden');
211     $form->setType('archive_date_validite', 'hidden');
212     $form->setType('archive_date_achevement', 'hidden');
213     $form->setType('archive_date_conformite', 'hidden');
214 nhaye 428 $form->setType('archive_date_chantier', 'hidden');
215 fraynaud 20 }
216 fraynaud 265
217 vpihour 1058 /*Met des valeurs choisies dans certains select du formulaire*/
218 fraynaud 20 function setSelect(&$form, $maj,&$db,$DEBUG) {
219 atreal 312 if(file_exists ("../sql/".$db->phptype."/".$this->table.".form.inc.php"))
220     include ("../sql/".$db->phptype."/".$this->table.".form.inc.php");
221 nhaye 428
222     // *** evenement ***
223     $contenu=array();
224     // etat du dossier
225     $sql="select etat from ".DB_PREFIXE."dossier where dossier ='".
226     $this->idxformulaire."'";
227     $etat_dossier = $db->getOne($sql);
228 nhaye 1140 // nature du dossier d'autorisation
229     $sql="select code from ".DB_PREFIXE."dossier
230     INNER JOIN ".DB_PREFIXE."dossier_autorisation ON
231     dossier.dossier_autorisation = dossier_autorisation.dossier_autorisation
232     INNER JOIN ".DB_PREFIXE."dossier_autorisation_type_detaille ON
233     dossier_autorisation.dossier_autorisation_type_detaille =
234     dossier_autorisation_type_detaille.dossier_autorisation_type_detaille
235     WHERE dossier ='".
236     $this->idxformulaire."'";
237     $nature_dossier = $db->getOne($sql);
238    
239 nhaye 428 // recherche des evenement de transition
240 nhaye 1140 // XXX modifier la requète après la modification de structure du workflow
241     $sql= $sql_transition." where transition.etat ='".$etat_dossier."' and (dossier_autorisation_type_detaille.code ='".
242     $nature_dossier."' or (dossier_autorisation_type_detaille.code ='T'
243     and dossier_autorisation_type_detaille.code !='CU')) order by evenement.action";
244 nhaye 428
245     // *** attention en dur le CU
246 vpihour 1124 $this->addToLog("setSelect(): db->query(\"".$sql."\");", VERBOSE_MODE);
247 nhaye 428
248     $res = $db->query($sql);
249     if (database::isError($res))
250     die($res->getMessage());
251     $contenu[0][0]="";
252     $contenu[1][0]=_('choisir')." "._('evenement');
253     $k=1;
254     while ($row=& $res->fetchRow()){
255     if($maj==0){ // ajouter
256     $contenu[0][$k]=$row[0];
257     $contenu[1][$k]=$row[1];
258     $k++;
259     }else{
260     // select hiddenstatic
261     $contenu[0][$k]=$row[0];
262     $contenu[1][$k]=$row[1];
263     $k++;
264 fraynaud 20 }
265     }
266 nhaye 428 $form->setSelect("evenement",$contenu);
267     // lien bible_auto [link]
268     $contenu=array();
269     $contenu[0]=" automatique ";
270     $form->setSelect("bible_auto",$contenu);
271     // lien bible1
272     $contenu=array();
273     $contenu[0]=" Bible ";
274     $form->setSelect("bible",$contenu);
275     // lien bible2
276     $contenu=array();
277     $contenu[0]=" Bible ";
278     $form->setSelect("bible2",$contenu);
279 fraynaud 20 } // function select
280    
281     function setGroupe(&$form,$maj){
282     $form->setGroupe('evenement','D');
283     $form->setGroupe('libelle','G');
284 vpihour 1127 $form->setGroupe('date_evenement','G');
285 fraynaud 20 $form->setGroupe('lettretype','F');
286     }
287    
288     function setRegroupe(&$form,$maj){
289     $form->setRegroupe('evenement','D',_('evenement'), "collapsible");
290     $form->setRegroupe('libelle','G','');
291 vpihour 1127 $form->setRegroupe('date_evenement','G','');
292 fraynaud 20 $form->setRegroupe('lettretype','F','');
293 fraynaud 196 $form->setRegroupe('complement','D',_('complement'), "collapsible");
294 fraynaud 20 $form->setRegroupe('bible_auto','G','');
295     $form->setRegroupe('bible','F','');
296     $form->setRegroupe('complement2','D',_('complement2'), "startClosed");
297     $form->setRegroupe('bible2','F','');
298     }
299    
300 vpihour 1058 /*Change le libellé de certains champs*/
301 fraynaud 20 function setLib(&$form,$maj) {
302     parent :: setLib($form,$maj);
303     $form->setLib('libelle',' ');
304     $form->setLib('bible_auto',"");
305     $form->setLib('bible',"");
306     $form->setLib('bible2',"");
307     $form->setLib('lettretype',"->"._(" courrier "));
308 vpihour 1127 $form->setLib('date_evenement',_(" du "));
309 fraynaud 20 }
310    
311     // ==================================================================
312 vpihour 1058 // trigger avant modification des données [trigger before modify data]
313 fraynaud 20 // ==================================================================
314     function triggerajouter($id,&$db,$val,$DEBUG) {
315     // mise a jour instruction avec evenement
316     // [modify instruction with evenement]
317 fraynaud 242 $sql= "select * from ".DB_PREFIXE."evenement where evenement =".$this->valF['evenement'];
318 vpihour 1137
319 fraynaud 20 $res = $db->query($sql);
320 fraynaud 129 if (database::isError($res)) die($res->getMessage());
321 vpihour 1137
322 fraynaud 20 if ($DEBUG == 1)
323     echo " la requete ".$sql." est exécutée<br>";
324 vpihour 1137
325 fraynaud 20 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
326 vpihour 1137
327 nhaye 460 if(isset($row['action']) and !empty($row['action'])) {
328     $this->valF['action']=$row['action'];
329     } else {
330     $this->valF['action']=NULL;
331     }
332 fraynaud 20 $this->valF['delai']=$row['delai'];
333 nhaye 460 if(isset($row['etat']) and !empty($row['etat'])) {
334     $this->valF['etat']=$row['etat'];
335     } else {
336     $this->valF['etat']=NULL;
337     }
338 fraynaud 20 $this->valF['accord_tacite']=$row['accord_tacite'];
339     $this->valF['delai_notification']=$row['delai_notification'];
340 vpihour 489 if(isset($row['avis_decision']) and !empty($row['avis_decision'])) {
341     $this->valF['avis_decision']=$row['avis_decision'];
342 nhaye 460 } else {
343 vpihour 489 $this->valF['avis_decision']=NULL;
344 nhaye 460 }
345 fraynaud 20 if($row['lettretype']!="")
346     $this->valF['lettretype']=$row['lettretype'];
347     else
348     $this->valF['lettretype']="standard";
349 vpihour 1137
350 fraynaud 20 }
351 fraynaud 242 $sql= "select * from ".DB_PREFIXE."dossier where dossier = '".$this->valF['dossier']."'";
352 fraynaud 20 $res = $db->query($sql);
353     if (database::isError($res))
354     die($res->getMessage());
355     if ($DEBUG == 1)
356     echo " la requete ".$sql." est exécutée<br>";
357     while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
358     //
359     $this->archive_date_depot = $row['date_depot'];
360     // archive en instruction (si suppression)
361     $this->valF['archive_delai']=$row['delai'];
362     $this->valF['archive_accord_tacite']=$row['accord_tacite'];
363     $this->valF['archive_etat']=$row['etat'];
364 vpihour 489 $this->valF['archive_avis']=$row['avis_decision'];
365 fraynaud 20 // compatibilite pgsql
366     if($row['date_complet']!='')
367     $this->valF['archive_date_complet']=$row['date_complet'];
368     if($row['date_rejet']!='')
369     $this->valF['archive_date_rejet']= $row['date_rejet'];
370     if($row['date_limite']!='')
371     $this->valF['archive_date_limite']= $row['date_limite'];
372     if($row['date_notification_delai']!='')
373     $this->valF['archive_date_notification_delai']= $row['date_notification_delai'];
374     if($row['date_decision']!='')
375     $this->valF['archive_date_decision']= $row['date_decision'];
376     if($row['date_validite']!='')
377     $this->valF['archive_date_validite']= $row['date_validite'];
378     if($row['date_achevement']!='')
379     $this->valF['archive_date_achevement']= $row['date_achevement'];
380     if($row['date_chantier']!='')
381     $this->valF['archive_date_chantier']= $row['date_chantier'];
382     if($row['date_conformite']!='')
383     $this->valF['archive_date_conformite']= $row['date_conformite'];
384     }
385     }
386    
387 vpihour 1137 // Test si une restriction est valide
388     // return boolean
389     function restrictionIsValid($restriction){
390    
391     /* Met des espace avant et après les opérateurs puis transforme la chaine en
392     * un tableau */
393     $tabRestriction = str_replace(">="," >= ",
394     str_replace("<="," <= ",
395     str_replace("-"," - ",
396     str_replace("+"," + ",$restriction))));
397     $tabRestriction = explode( " ", $tabRestriction);
398    
399     //Variables de résultat
400     $res = array();
401     $i = 0;
402     $comp = "";
403    
404    
405     //Test que le tableau n'est pas vide
406     if ( count($tabRestriction) > 0 ){
407    
408     $res[0] = $this->getRestrictionValue($tabRestriction[0]);
409    
410     //Calcul des variables
411     for ( $j = 1 ; $j < count($tabRestriction) ; $j += 2 ) {
412    
413     //Variable de comparaison
414     if ( strcmp( ">=", $tabRestriction[$j] ) == 0 ||
415     strcmp( "<=", $tabRestriction[$j]) ==0 ){
416    
417     $comp = $tabRestriction[$j];
418     $res[++$i] = $this->getRestrictionValue($tabRestriction[$j+1]);
419     }
420     // Fait l'addition
421     elseif ( strcmp( "+", $tabRestriction[$j]) == 0 ){
422    
423     $res[$i] = $this->moisdate( $res[$i], $this->getRestrictionValue($tabRestriction[$j+1]) );
424     }
425     }
426     }
427    
428     // Effectue le test
429     if ( strcmp($comp, ">=") == 0 ){
430    
431     if ( $res[0] >= $res[1] || $res[0] == "" ){
432    
433     return true;
434     }
435     else {
436    
437     return false;
438     }
439     }
440     elseif ( strcmp($comp, "<=") == 0 ){
441    
442     if ( $res[0] <= $res[1] || $res[1] == "" ){
443    
444     return true;
445     }
446     else {
447    
448     return false;
449     }
450     }
451    
452     return true;
453     }
454    
455     //Retourne la valeur de valF si $restrictionValue n'est pas un chiffre, le chiffre sinon
456     function getRestrictionValue($restrictionValue){
457    
458     return ( is_numeric($restrictionValue) ) ?
459     $restrictionValue :
460     $this->valF[$restrictionValue];
461     }
462    
463 fraynaud 123 function regle($regle){
464     $temp = explode ("+",$regle);
465 atreal 208 //echo '|'.$regle;
466 fraynaud 124 // cas rejet
467 fraynaud 129 if($regle=="null") // 1 dimension -> null
468 fraynaud 124 return null;
469     if(sizeof($temp)==1) // 1 dimension
470     if($temp[0]=="archive_date_depot") // initialisation avec le depot
471 fraynaud 123 return $this->$regle;
472 fraynaud 124 else // cas general
473 fraynaud 123 return $this->valF[$regle];
474 fraynaud 124 if(sizeof($temp)==2){ // 2 dimensions
475     if($temp[0]=="archive_date_depot") //initialisation avec le depot
476 fraynaud 123 if(is_numeric($temp[1]))
477     return $this->moisdate($this->$temp[0], $temp[1]);
478     else
479     return $this->moisdate($this->$temp[0], $this->valF[$temp[1]]);
480 fraynaud 124 if($temp[0]=="archive_delai") // majoration de delai
481     return $this->valF[$temp[0]]+$this->valF[$temp[1]];
482     // cas general 2 dimensions
483 fraynaud 123 if(is_numeric($temp[1]))
484     return $this->moisdate($this->valF[$temp[0]], $temp[1]);
485     else
486     return $this->moisdate($this->valF[$temp[0]], $this->valF[$temp[1]]);
487     }
488 fraynaud 124 if(sizeof($temp)==3){ // 3 dimensions
489     // cas date de validite de sursis
490     if(is_numeric($temp[1]))
491     $temp1 = $this->moisdate($this->valF[$temp[0]], $temp[1]);
492     else
493     $temp1 = $this->moisdate($this->valF[$temp[0]], $this->valF[$temp[1]]);
494     if(is_numeric($temp[2]))
495     return $this->moisdate($temp1, $temp[2]);
496     else
497     return $this->moisdate($temp1, $this->valF[$temp[2]]);
498     }
499 fraynaud 123 }
500    
501    
502    
503 fraynaud 20 // ==================================================================
504     // valeur dossier apres modification [values dossier after action]
505     // ==================================================================
506     function triggerajouterapres($id,&$db,$val,$DEBUG) {
507 fraynaud 47 // mise a null au lieu de "" / voir compatibilite mysql
508     // voir parametrage CU en dur
509     // voir parametrage des actions en dur
510 fraynaud 123 $param=1;
511 fraynaud 121 if($param==1){
512 fraynaud 242 $sql="select * from ".DB_PREFIXE."action where action = '".$this->valF['action']."'";
513 fraynaud 121 $res = $db->query($sql);
514     if (database::isError($res))
515     die($res->getMessage());
516     while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
517     if($row['regle_etat']!=''){
518 fraynaud 123 $valF['etat']= $this->regle($row['regle_etat']);
519 fraynaud 121 }
520     if($row['regle_delai']!=''){
521 fraynaud 123 $valF['delai']= $this->regle($row['regle_delai']);
522 fraynaud 121 }
523     if($row['regle_accord_tacite']!=''){
524 fraynaud 123 $valF['accord_tacite']= $this->regle($row['regle_accord_tacite']);
525 fraynaud 121 }
526 fraynaud 124 if($row['regle_avis']!=''){
527 vpihour 489 $valF['avis_decision']= $this->regle($row['regle_avis']);
528 fraynaud 124 }
529 fraynaud 121 if($row['regle_date_limite']!=''){
530 fraynaud 123 $valF['date_limite']= $this->regle($row['regle_date_limite']);
531     }
532     if($row['regle_date_complet']!=''){
533     $valF['date_complet']= $this->regle($row['regle_date_complet']);
534     }
535     if($row['regle_date_notification_delai']!=''){
536     $valF['date_notification_delai']= $this->regle($row['regle_date_notification_delai']);
537     }
538 fraynaud 124 if($row['regle_date_decision']!=''){
539     $valF['date_decision']= $this->regle($row['regle_date_decision']);
540     }
541     if($row['regle_date_rejet']!=''){
542     $valF['date_rejet']= $this->regle($row['regle_date_rejet']);
543     }
544     if($row['regle_date_validite']!=''){
545     $valF['date_validite']= $this->regle($row['regle_date_validite']);
546     }
547     if($row['regle_date_chantier']!=''){
548     $valF['date_chantier']= $this->regle($row['regle_date_chantier']);
549     }
550     if($row['regle_date_achevement']!=''){
551     $valF['date_achevement']= $this->regle($row['regle_date_achevement']);
552     }
553     if($row['regle_date_conformite']!=''){
554     $valF['date_conformite']= $this->regle($row['regle_date_conformite']);
555     }
556 fraynaud 121 }
557     }else{
558 fraynaud 242 switch ($this->valF['action']) {
559     case "initialisation" :
560     $valF['delai']= $this->valF['delai'];
561     $valF['etat']= $this->valF['etat'];
562     $valF['accord_tacite']= $this->valF['accord_tacite'];
563     // la date_complet est la date de depot
564     $valF['date_complet']= $this->archive_date_depot; // ****
565     $valF['date_limite'] = $this->moisdate($valF['date_complet'],$valF['delai']);
566     $valF['date_notification_delai'] = $this->moisdate($valF['date_complet'],1);
567     break;
568     case "notification" :
569     $valF['delai']= $this->valF['delai'];
570     $valF['etat']= $this->valF['etat'];
571     $valF['accord_tacite']= $this->valF['accord_tacite'];
572     // la date_complet est celle precedemment saisie
573     $valF['date_complet']=$this->valF['archive_date_complet'];
574     $valF['date_limite'] = $this->moisdate($valF['date_complet'],$valF['delai']);
575     $valF['date_notification_delai'] = $this->moisdate($valF['date_complet'],1);
576     // la date du courrier ne doit pas etre depasse par rapport au delai de
577     // notification [verify notification date]
578 vpihour 1127 if($this->valF['archive_date_notification_delai']<$this->valF['date_evenement'])
579 fraynaud 242 $this->msg=$this->msg."<br><img src='../img/erreur.gif'> "._("date_notification_delai")." ".
580 vpihour 1127 $this->valF['archive_date_notification_delai']." < "._('date_evenement');
581 fraynaud 242 //
582     break;
583     case "retour" :
584     $valF['delai']= $this->valF['delai'];
585     $valF['etat']= $this->valF['etat'];
586     $valF['accord_tacite']= $this->valF['accord_tacite'];
587     // la date_complet est celle de l evenement
588 vpihour 1127 $valF['date_complet']= $this->valF['date_evenement'];
589 fraynaud 242 $valF['date_limite'] = $this->moisdate($valF['date_complet'],$valF['delai']);
590     $valF['date_notification_delai'] = $this->moisdate($valF['date_complet'],1);
591     break;
592     case "rejet" :
593     //$valF['delai']=0; // *** delai a garder pour etat dpc
594     $valF['etat']= $this->valF['etat'];
595     $valF['accord_tacite']= $this->valF['accord_tacite'];
596     // la date rejet est initialisee
597 vpihour 1127 $valF['date_rejet']= $this->valF['date_evenement'];
598 fraynaud 242 // les dates de depart et fin d instruction sont annulées
599     $valF['date_limite'] =null;
600     $valF['date_notification_delai'] =null;
601     $valF['date_complet']=null;
602     break;
603     case "majoration" :
604     $valF['delai']= $this->valF['archive_delai']+$this->valF['delai'];
605     $valF['etat']= $this->valF['etat'];
606     $valF['accord_tacite']= $this->valF['accord_tacite'];
607     $valF['date_complet']=$this->valF['archive_date_complet'];
608     // majoration de la date limite
609     $valF['date_limite'] = $this->moisdate($valF['date_complet'],$valF['delai']);
610     $valF['date_notification_delai'] = $this->moisdate($valF['date_complet'],1);
611     // la date du courrier ne doit pas etre depasse par rapport au delai de
612     // notification
613 vpihour 1127 if($this->valF['archive_date_notification_delai']<$this->valF['date_evenement'])
614 fraynaud 242 $this->msg=$this->msg."<br><img src='../img/erreur.gif'>"._("date_notification_delai").
615 vpihour 1127 $this->valF['archive_date_notification_delai']." < "._('date_evenement');
616 fraynaud 242 break;
617     case "acceptation" :
618     $valF['etat']= $this->valF['etat'];
619 vpihour 1127 $valF['date_decision']= $this->valF['date_evenement'];
620 vpihour 489 $valF['avis_decision']= $this->valF['avis_decision'];
621 fraynaud 242 // date de validite = date de l evenement + delai
622 vpihour 1127 $valF['date_validite'] = $this->moisdate($this->valF['date_evenement'],$this->valF['delai']);
623 fraynaud 242 break;
624     case "refus" :
625     $valF['etat']= $this->valF['etat'];
626 vpihour 1127 $valF['date_decision']= $this->valF['date_evenement'];
627 vpihour 489 $valF['avis_decision']= $this->valF['avis_decision'];
628 fraynaud 242 break;
629     case "prolongation" :
630     $valF['date_validite'] = $this->moisdate($this->valF['archive_date_validite'],$this->valF['delai']);
631     break;
632     case "sursis" :
633 vpihour 1127 $valF['date_limite'] = $this->moisdate($this->valF['date_evenement'],$this->valF['delai']);
634 fraynaud 242 $valF['etat']= $this->valF['etat'];
635     $valF['accord_tacite']= $this->valF['accord_tacite'];
636 vpihour 489 $valF['avis_decision']= $this->valF['avis_decision'];
637 vpihour 1127 $valF['date_decision']= $this->valF['date_evenement'];
638 fraynaud 242 $temp = $valF['date_limite'];
639     $valF['date_validite']= $this->moisdate($temp,2);
640     break;
641     case "execution" :
642     $valF['etat']= $this->valF['etat'];
643 vpihour 1127 $valF['date_chantier'] = $this->valF['date_evenement'];
644 fraynaud 242 //echo $this->msg=$this->msg.$valF['date_chantier']."";
645     break;
646     case "achevement" :
647     $valF['etat']= $this->valF['etat'];
648 vpihour 1127 $valF['date_achevement'] = $this->valF['date_evenement'];
649 fraynaud 242 break;
650     case "archivage" :
651     $valF['etat']= $this->valF['etat'];
652 vpihour 1127 $valF['date_conformite'] = $this->valF['date_evenement'];
653 fraynaud 242 break;
654    
655     default:
656     if ($this->valF['etat']!="")
657     $valF['etat']= $this->valF['etat'];
658     }// end switch
659 fraynaud 121 } // end param
660 fraynaud 20 if($valF!=""){
661     $cle= " dossier = '".$this->valF['dossier']."'";
662 fraynaud 242 $res1= $db->autoExecute(DB_PREFIXE.'dossier',$valF,DB_AUTOQUERY_UPDATE,$cle);
663 fraynaud 20 if (database::isError($res1))
664     die($res->getMessage());
665     if ($DEBUG == 1)
666     echo "La requête de mise à jour est effectuée.<br>";
667     $this->msg=$this->msg."<br>"._('enregistrement')." ".
668     $this->valF['dossier']." "._('table')." dossier [".
669     $db->affectedRows()." "._('enregistrement').
670     " "._('mis_a_jour')."]" ;
671     }
672 fmichon 1005 // verification si envoi vers ERP est active
673     if ($this->f->getParameter('option_erp') != "") {
674     // la nature du dossier
675     $nature_dossier = substr($this->idxformulaire,0,2);
676     $dossier_erp = $this->getFromDB("SELECT erp FROM ".DB_PREFIXE."dossier WHERE dossier = '" .
677     $this->valF['dossier'] . "'");
678     $evenement_libelle = $this->getFromDB(
679     "SELECT libelle FROM ".DB_PREFIXE."evenement WHERE evenement = '" .
680     $this->valF['evenement'] . "'");
681     if ($dossier_erp == 't') {
682     // envoi du message en cas d'un PC qui est ERP et sur lequel un evenement
683     // d'acceptation etait fait
684     if ($nature_dossier ==
685     $this->f->getParameter('erp_evenement_accepter_dossier_PC')
686     && $this->valF['evenement'] ==
687     $this->f->getParameter('erp_evenement_accepter_sans_reserve')) {
688     $msgenque = new MessageEnqueuer();
689     $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
690     $msgenque->setDecision($evenement_libelle);
691     $msgenque->enqueueMessage($msgenque::$ERP_ARRETE_PC_EFFECTUE);
692     }
693     if ($this->valF['evenement'] ==
694     $this->f->getParameter('erp_evenement_refuser_dossier')) {
695     $msgenque = new MessageEnqueuer();
696     $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
697     $msgenque->enqueueMessage($msgenque::$ERP_DECISION_CONFORMITE_EFFECTUE);
698     }
699 mlimic 936 }
700 fmichon 1005 } // fin de if ($this->f->getParameter('option_erp') != "")
701 fraynaud 20 }
702 mlimic 910
703    
704     /**
705     * Fait une requette sql pour extraire la valeur d'un champ, et retourne
706     * cette valeur
707     * @param string $sql La requete sql a executer
708     * @return La valeur du champs cherche, sinon NULL. En cas d'erreur de la BD
709     * l'execution s'arrete.
710     */
711     function getFromDB($sql) {
712 fmichon 926 //$sql = "SELECT libelle FROM ".DB_PREFIXE."dossier WHERE dossier = '" . $dossier . "'";
713 mlimic 910 $res = $this->db->limitquery($sql, 0, 1);
714     $this->addToLog("getDossierERPSpecification(): db->limitquery(\"".
715     str_replace(",",", ",$sql)."\", 0, 1);", VERBOSE_MODE);
716     // Si une erreur survient on die
717     if (database::isError($res, true)) {
718     // Appel de la methode de recuperation des erreurs
719     $this->erreur_db($res->getDebugInfo(), $res->getMessage(), 'instruction');
720     }
721     // retourne la nature du dossier
722     while ($row =& $res->fetchRow()) {
723     return $row[0];
724     }
725     // la nature n'etait pas trouve, ce qui ne devrait pas se passer
726     return NULL;
727 fraynaud 129
728 mlimic 910 }
729    
730    
731 fraynaud 129 function triggermodifierapres($id,&$db,$val,$DEBUG) {
732     /*
733 vpihour 1058 * cette fonction a pour objet de permettre de modifier la date courrier
734 fraynaud 129 */
735     $valF=array();
736 fraynaud 242 $sql= "select action from ".DB_PREFIXE."evenement where evenement =".$this->valF['evenement'];
737 fraynaud 129 $action = $db->getOne($sql);
738     if (database::isError($action)) die($action->getMessage().$sql);
739 fraynaud 242 $sql="select * from ".DB_PREFIXE."action where action = '".$action."'";
740 fraynaud 129 $res = $db->query($sql);
741     if (database::isError($res)) die($res->getMessage().$sql);
742     while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
743     // application des regles sur le courrier + delai
744 vpihour 1127 if(preg_match("/date_evenement/",$row['regle_date_limite'])){
745 fraynaud 129 $valF['date_limite']= $this->regle($row['regle_date_limite']);
746     }
747 vpihour 1127 if(preg_match("/date_evenement/",$row['regle_date_complet'])){
748 fraynaud 129 $valF['date_complet']= $this->regle($row['regle_date_complet']);
749     }
750 vpihour 1127 if(preg_match("/date_evenement/",$row['regle_date_notification_delai'])){
751 fraynaud 129 $valF['date_notification_delai']= $this->regle($row['regle_date_notification_delai']);
752     }
753 vpihour 1127 if(preg_match("/date_evenement/",$row['regle_date_decision'])){
754 fraynaud 129 $valF['date_decision']= $this->regle($row['regle_date_decision']);
755     }
756 vpihour 1127 if(preg_match("/date_evenement/",$row['regle_date_rejet'])){
757 fraynaud 129 $valF['date_rejet']= $this->regle($row['regle_date_rejet']);
758     }
759 vpihour 1127 if(preg_match("/date_evenement/",$row['regle_date_validite'])){
760 fraynaud 129 $valF['date_validite']= $this->regle($row['regle_date_validite']);
761     }
762 vpihour 1127 if(preg_match("/date_evenement/",$row['regle_date_chantier'])){
763 fraynaud 129 $valF['date_chantier']= $this->regle($row['regle_date_chantier']);
764     }
765 vpihour 1127 if(preg_match("/date_evenement/",$row['regle_date_achevement'])){
766 fraynaud 129 $valF['date_achevement']= $this->regle($row['regle_date_achevement']);
767     }
768 vpihour 1127 if(preg_match("/date_evenement/",$row['regle_date_conformite'])){
769 fraynaud 129 $valF['date_conformite']= $this->regle($row['regle_date_conformite']);
770     }
771     } // while
772     if($valF!=array()){
773     $cle= " dossier = '".$this->valF['dossier']."'";
774 fraynaud 242 $res1= $db->autoExecute(DB_PREFIXE.'dossier',$valF,DB_AUTOQUERY_UPDATE,$cle);
775 fraynaud 129 if (database::isError($res1))
776     die($res->getMessage());
777     if ($DEBUG == 1)
778     echo "La requête de mise à jour est effectuée.<br>";
779     $this->msg=$this->msg."<br>"._('enregistrement')." ".
780     $this->valF['dossier']." "._('table')." dossier [".
781     $db->affectedRows()." "._('enregistrement').
782     " "._('mis_a_jour')."]" ;
783     }
784     }
785    
786    
787 fraynaud 20
788     // trigger before delete
789     function triggersupprimer($id,&$db,$val,$DEBUG) {
790     // archive en instruction (si suppression) [archive if delete instruction]
791     $valF['delai']=$val['archive_delai'];
792     $valF['accord_tacite']=$val['archive_accord_tacite'];
793     $valF['etat']=$val['archive_etat'];
794 fraynaud 80 if($val['archive_avis']=='')
795 vpihour 489 $valF['avis_decision']= null;
796 fraynaud 80 else
797 vpihour 489 $valF['avis_decision']=$val['archive_avis'];
798 fraynaud 20 // if= compatibilite pgsql
799     if($val['archive_date_complet']!='')
800     $valF['date_complet']=$val['archive_date_complet'];
801     if($val['archive_date_rejet']!='')
802     $valF['date_rejet']= $val['archive_date_rejet'];
803     if($val['archive_date_limite']!='')
804     $valF['date_limite']= $val['archive_date_limite'];
805     if($val['archive_date_notification_delai']!='')
806     $valF['date_notification_delai']= $val['archive_date_notification_delai'];
807     if($val['archive_date_decision']!='')
808     $valF['date_decision']= $val['archive_date_decision'];
809     if($val['archive_date_validite']!='')
810     $valF['date_validite']= $val['archive_date_validite'];
811     if($val['archive_date_achevement']!='')
812     $valF['date_achevement']= $val['archive_date_achevement'];
813     if($val['archive_date_chantier']!='')
814     $valF['date_chantier']= $val['archive_date_chantier'];
815     if($val['archive_date_conformite']!='')
816     $valF['date_conformite']= $val['archive_date_conformite'];
817 fraynaud 80
818 fraynaud 20 $cle= " dossier = '".$val['dossier']."'";
819 fraynaud 242 $res= $db->autoExecute(DB_PREFIXE.'dossier',$valF,DB_AUTOQUERY_UPDATE,$cle);
820 fraynaud 20 if (database::isError($res))
821     die($res->getMessage());
822     else{
823     if ($DEBUG == 1)
824     echo "La requête de mise à jour est effectuée.<br>";
825     }
826     }
827     // =============================================
828     // calcul de date avec ajout de mois (delais)
829     // [add months (delay) and calculation final date]
830     // LIMITE DE LA FONCTION si delai >24 MOIS
831     // [limit : delay < 24 month]
832     // =============================================
833     function moisdate($date,$delaimois) {
834     $temp = explode("-" , $date);
835     $jour = (int) $temp[2];
836     $mois = (int) $temp[1];
837     $annee = (int) $temp[0];
838     // calcul si delai superieur à 12 (limite 24) [delay > 24 month]
839     if($delaimois>=12){
840     $delaimois=$delaimois-12;
841     $annee=$annee+1;
842     }
843     if($delaimois>=12){
844     $delaimois=$delaimois-12;
845     $annee=$annee+1;
846     }
847     // mois
848     $mois=$mois+$delaimois;
849     // calcul mois annee [calculation number of years if > 12 month]
850     // nb de mois > à 12
851     if ($mois>12){
852     $mois=$mois-12;
853     $annee=$annee+1;
854     }
855     // Calcul du nombre de jours dans le mois sélectionné [calculation number of days]
856     switch($mois) {
857     case "2":
858     if ($annee % 4 == 0 && $annee % 100 != 0 || $annee % 400 == 0)
859     $jourmax = 29;
860     else
861     $jourmax = 28;
862     break;
863     case "4":
864     case "6":
865     case "9":
866     case "11":
867     $jourmax = 30;
868     break;
869     default:
870     $jourmax = 31;
871     }
872     if ($jour > $jourmax)
873     $jour = $jourmax;
874     //$dateretour=$annee."-".$mois."-".$jour;
875     return $annee."-".$mois."-".$jour ;
876     }
877    
878 vpihour 1137 // Vérifie la restriction sur l'événement
879     function verifier($val = array(), &$db, $DEBUG){
880    
881     //Récupère la restriction
882     $sql= "SELECT
883     restriction
884     FROM
885     ".DB_PREFIXE."evenement
886     WHERE
887     evenement =".$this->valF['evenement'];
888    
889     $res = $db->query($sql);
890     $this->f->addToLog("verifier(): db->query(\"".$sql."\");", VERBOSE_MODE);
891     $this->f->isDatabaseError();
892    
893     $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);
894    
895     //Test qu'une restriction est présente
896     if ( isset($row['restriction']) && $row['restriction'] != "" ){
897    
898     //Test si la restriction est valide
899     if ( !$this->restrictionIsValid($row['restriction']) ){
900    
901     $this->correct=false;
902     $this->addToMessage(_("Restriction non valide"));
903     }
904     else {
905    
906     $this->correct = true;
907     }
908     }
909     }
910    
911 fraynaud 3 }// fin classe
912 atreal 208 ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26