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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1400 - (show annotations)
Thu Mar 14 11:21:55 2013 UTC (11 years, 10 months ago) by nhaye
File size: 50608 byte(s)
Correction des requêtes appelant demandeurs et travaux

1 <?php
2 //$Id$
3 //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 require_once ("../gen/obj/instruction.class.php");
21 require_once("../services/outgoing/messageenqueuer.php");
22
23 class instruction extends instruction_gen {
24
25 var $archive_date_depot; // specific
26 var $retourformulaire; // specific
27 var $idxformulaire; // specific
28
29 function instruction($id,&$db,$debug) {
30 $this->constructeur($id,$db,$debug);
31 }// fin constructeur
32
33 // {{{ 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 function cleSecondaire($id,&$db,$val,$DEBUG) {
98 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 $dernierevenement='';
104 $sql="select max(instruction) from ".DB_PREFIXE."instruction where dossier ='".
105 $this->idxformulaire."'";
106 $dernierevenement = $db->getOne($sql);
107 if($dernierevenement==$id){
108 $this->correct=true;
109 $this->addToMessage(_('Destruction_chronologique'));
110 }else{
111 $this->addToMessage(_('Destruction_evenement')." : ".$dernierevenement);
112 $this->addToMessage(_('Destruction_chronologique'));
113 $this->correct=false;
114 }
115 }
116
117 // Sélectionne le signataire_arrete par défaut
118 function setVal(&$form,$maj,$validation){
119
120 // Ajout
121 if($maj == 0) {
122
123 // Création de la requête
124 $sql = "SELECT signataire_arrete
125 FROM ".DB_PREFIXE."signataire_arrete
126 WHERE defaut IS TRUE";
127
128 // Exécution de la requête
129 $this->f->addToLog("deleteAllLienDossierInstructionTypeEvenementEvenement(): db->query(\"".$sql."\");", VERBOSE_MODE);
130 $res = $this->f->db->query($sql);
131 $this->f->isDatabaseError();
132
133 $row = $res->fetchrow(DB_FETCHMODE_ASSOC);
134
135 if ( isset($row['signataire_arrete']) && is_numeric($row['signataire_arrete'])){
136
137 $form->setVal("signataire_arrete",$row['signataire_arrete']);
138 }
139 }
140 }
141
142 /*Met des valeurs par défaut dans certains des sous-formulaire*/
143 function setValsousformulaire(&$form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire){
144 if ($validation==0 and $maj<2) {
145 if ($maj == 0){
146 $form->setVal("destinataire", $idxformulaire);
147 $form->setVal("dossier", $idxformulaire);
148 $form->setVal("date_evenement", date('Y-m-d'));
149 }
150 $form->setVal("bible_auto","bible_auto()");
151 $form->setVal("bible","bible()");
152 $form->setVal("bible2","bible2()");
153 }
154 $this->retourformulaire=$retourformulaire;
155 $this->idxformulaire=$idxformulaire;
156 }
157
158 /*Affecte un type à certains champs*/
159 function setType(&$form,$maj) {
160 parent::setType($form,$maj);
161 if ($maj < 2) { //ajouter et modifier
162 $form->setType('destinataire', 'hidden');
163 $form->setType('lettretype', 'hiddenstatic');
164 $form->setType('complement', 'textarea');
165 $form->setType('complement2', 'textarea');
166 $form->setType('bible_auto', 'httpclick');
167 $form->setType('bible', 'httpclick');
168 $form->setType('bible2', 'httpclick');
169 $form->setType('dossier', 'hiddenstatic');
170 $form->setType('libelle', 'hiddenstatic');
171 $form->setType('signataire_arrete','select');
172 if($maj==0){ // add
173 $form->setType('instruction', 'hiddenstatic');
174 $form->setType('evenement', 'select');
175 $form->setType('date_evenement', 'date2');
176 }else{ // modify
177 $form->setType('instruction', 'hiddenstatic');
178 $form->setType('evenement', 'hiddenstatic');
179 //$form->setType('date_evenement', 'hiddenstaticdate');
180 $form->setType('date_evenement', 'date2');
181 // necessaire pour calcul de date en modification
182 $form->setType('delai', 'hiddenstatic');
183 }
184 } elseif($maj==2){
185 $form->setType('dossier', 'hiddenstatic');
186 $form->setType('bible_auto', 'hidden');
187 $form->setType('bible', 'hidden');
188 $form->setType('bible2', 'hidden');
189 }else {
190 $form->setType('destinataire', 'hidden');
191 $form->setType('dossier', 'static');
192 $form->setType('bible_auto', 'hidden');
193 $form->setType('bible', 'hidden');
194 $form->setType('bible2', 'hidden');
195 }
196 $form->setType('complement3', 'hidden');
197 $form->setType('bible3', 'hidden');
198 $form->setType('complement4', 'hidden');
199 $form->setType('bible4', 'hidden');
200 $form->setType('complement5', 'hidden');
201 $form->setType('bible5', 'hidden');
202 $form->setType('complement6', 'hidden');
203 $form->setType('bible6', 'hidden');
204 $form->setType('complement7', 'hidden');
205 $form->setType('bible7', 'hidden');
206 $form->setType('complement8', 'hidden');
207 $form->setType('bible8', 'hidden');
208 $form->setType('complement9', 'hidden');
209 $form->setType('bible9', 'hidden');
210 $form->setType('complement10', 'hidden');
211 $form->setType('bible10', 'hidden');
212 $form->setType('complement11', 'hidden');
213 $form->setType('bible11', 'hidden');
214 $form->setType('complement12', 'hidden');
215 $form->setType('bible12', 'hidden');
216 $form->setType('complement13', 'hidden');
217 $form->setType('bible13', 'hidden');
218 $form->setType('complement14', 'hidden');
219 $form->setType('bible14', 'hidden');
220 $form->setType('complement15', 'hidden');
221 $form->setType('bible15', 'hidden');
222 $form->setType('delai', 'hidden');
223 $form->setType('etat', 'hidden');
224 $form->setType('accord_tacite', 'hidden');
225 $form->setType('action', 'hidden');
226 $form->setType('delai_notification', 'hidden');
227 $form->setType('avis_decision', 'hidden');
228 $form->setType('archive_delai', 'hidden');
229 $form->setType('archive_etat', 'hidden');
230 $form->setType('archive_accord_tacite', 'hidden');
231 $form->setType('archive_avis', 'hidden');
232 $form->setType('archive_date_complet', 'hidden');
233 $form->setType('archive_date_rejet', 'hidden');
234 $form->setType('archive_date_limite', 'hidden');
235 $form->setType('archive_date_notification_delai', 'hidden');
236 $form->setType('archive_date_decision', 'hidden');
237 $form->setType('archive_date_validite', 'hidden');
238 $form->setType('archive_date_achevement', 'hidden');
239 $form->setType('archive_date_conformite', 'hidden');
240 $form->setType('archive_date_chantier', 'hidden');
241 $form->setType('numero_arrete', 'hidden');
242 }
243
244 /*Met des valeurs choisies dans certains select du formulaire*/
245 function setSelect(&$form, $maj,&$db,$DEBUG) {
246 if(file_exists ("../sql/".$db->phptype."/".$this->table.".form.inc.php"))
247 include ("../sql/".$db->phptype."/".$this->table.".form.inc.php");
248
249 parent::setSelect($form, $maj, $db, $DEBUG);
250
251 // *** evenement ***
252 $contenu=array();
253 // etat du dossier
254 $sql="select etat from ".DB_PREFIXE."dossier where dossier ='".
255 $this->idxformulaire."'";
256 $etat_dossier = $db->getOne($sql);
257 // nature du dossier d'autorisation
258 $sql="select code from ".DB_PREFIXE."dossier
259 INNER JOIN ".DB_PREFIXE."dossier_autorisation ON
260 dossier.dossier_autorisation = dossier_autorisation.dossier_autorisation
261 INNER JOIN ".DB_PREFIXE."dossier_autorisation_type_detaille ON
262 dossier_autorisation.dossier_autorisation_type_detaille =
263 dossier_autorisation_type_detaille.dossier_autorisation_type_detaille
264 WHERE dossier ='".
265 $this->idxformulaire."'";
266 $nature_dossier = $db->getOne($sql);
267
268 // recherche des evenement de transition
269 // XXX modifier la requète après la modification de structure du workflow
270 $sql= $sql_transition." where transition.etat ='".$etat_dossier."' and dossier='".
271 $this->idxformulaire."' order by evenement.action";
272
273 // *** attention en dur le CU
274 $this->addToLog("setSelect(): db->query(\"".$sql."\");", VERBOSE_MODE);
275
276 $res = $db->query($sql);
277 if (database::isError($res))
278 die($res->getMessage());
279 $contenu[0][0]="";
280 $contenu[1][0]=_('choisir')." "._('evenement');
281 $k=1;
282 while ($row=& $res->fetchRow()){
283 if($maj==0){ // ajouter
284 $contenu[0][$k]=$row[0];
285 $contenu[1][$k]=$row[1];
286 $k++;
287 }else{
288 // select hiddenstatic
289 $contenu[0][$k]=$row[0];
290 $contenu[1][$k]=$row[1];
291 $k++;
292 }
293 }
294 $form->setSelect("evenement",$contenu);
295 // lien bible_auto [link]
296 $contenu=array();
297 $contenu[0]=" automatique ";
298 $form->setSelect("bible_auto",$contenu);
299 // lien bible1
300 $contenu=array();
301 $contenu[0]=" Bible ";
302 $form->setSelect("bible",$contenu);
303 // lien bible2
304 $contenu=array();
305 $contenu[0]=" Bible ";
306 $form->setSelect("bible2",$contenu);
307 } // function select
308
309 function setGroupe(&$form,$maj){
310 $form->setGroupe('evenement','D');
311 $form->setGroupe('libelle','G');
312 $form->setGroupe('date_evenement','G');
313 $form->setGroupe('lettretype','F');
314 }
315
316 function setRegroupe(&$form,$maj){
317 $form->setRegroupe('evenement','D',_('evenement'), "collapsible");
318 $form->setRegroupe('libelle','G','');
319 $form->setRegroupe('date_evenement','G','');
320 $form->setRegroupe('lettretype','F','');
321 $form->setRegroupe('complement','D',_('complement'), "collapsible");
322 $form->setRegroupe('bible_auto','G','');
323 $form->setRegroupe('bible','F','');
324 $form->setRegroupe('complement2','D',_('complement2'), "startClosed");
325 $form->setRegroupe('bible2','F','');
326 }
327
328 /*Change le libellé de certains champs*/
329 function setLib(&$form,$maj) {
330 parent :: setLib($form,$maj);
331 $form->setLib('libelle',' ');
332 $form->setLib('bible_auto',"");
333 $form->setLib('bible',"");
334 $form->setLib('bible2',"");
335 $form->setLib('lettretype',"->"._(" courrier "));
336 $form->setLib('date_evenement',_(" du "));
337 }
338
339 // ==================================================================
340 // trigger avant modification des données [trigger before modify data]
341 // ==================================================================
342 function triggerajouter($id,&$db,$val,$DEBUG) {
343 // mise a jour instruction avec evenement
344 // [modify instruction with evenement]
345 $sql= "select * from ".DB_PREFIXE."evenement where evenement =".$this->valF['evenement'];
346
347 $res = $db->query($sql);
348 if (database::isError($res)) die($res->getMessage());
349
350 if ($DEBUG == 1)
351 echo " la requete ".$sql." est exécutée<br>";
352
353 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
354
355 if(isset($row['action']) and !empty($row['action'])) {
356 $this->valF['action']=$row['action'];
357 } else {
358 $this->valF['action']=NULL;
359 }
360 $this->valF['delai']=$row['delai'];
361 if(isset($row['etat']) and !empty($row['etat'])) {
362 $this->valF['etat']=$row['etat'];
363 } else {
364 $this->valF['etat']=NULL;
365 }
366 $this->valF['accord_tacite']=$row['accord_tacite'];
367 $this->valF['delai_notification']=$row['delai_notification'];
368 if(isset($row['avis_decision']) and !empty($row['avis_decision'])) {
369 $this->valF['avis_decision']=$row['avis_decision'];
370 } else {
371 $this->valF['avis_decision']=NULL;
372 }
373 if($row['lettretype']!="")
374 $this->valF['lettretype']=$row['lettretype'];
375 else
376 $this->valF['lettretype']="standard";
377
378 }
379 $sql= "select * from ".DB_PREFIXE."dossier where dossier = '".$this->valF['dossier']."'";
380 $res = $db->query($sql);
381 if (database::isError($res))
382 die($res->getMessage());
383 if ($DEBUG == 1)
384 echo " la requete ".$sql." est exécutée<br>";
385 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
386 //
387 $this->archive_date_depot = $row['date_depot'];
388 // archive en instruction (si suppression)
389 $this->valF['archive_delai']=$row['delai'];
390 $this->valF['archive_accord_tacite']=$row['accord_tacite'];
391 $this->valF['archive_etat']=$row['etat'];
392 $this->valF['archive_avis']=$row['avis_decision'];
393 // compatibilite pgsql
394 if($row['date_complet']!='')
395 $this->valF['archive_date_complet']=$row['date_complet'];
396 if($row['date_rejet']!='')
397 $this->valF['archive_date_rejet']= $row['date_rejet'];
398 if($row['date_limite']!='')
399 $this->valF['archive_date_limite']= $row['date_limite'];
400 if($row['date_notification_delai']!='')
401 $this->valF['archive_date_notification_delai']= $row['date_notification_delai'];
402 if($row['date_decision']!='')
403 $this->valF['archive_date_decision']= $row['date_decision'];
404 if($row['date_validite']!='')
405 $this->valF['archive_date_validite']= $row['date_validite'];
406 if($row['date_achevement']!='')
407 $this->valF['archive_date_achevement']= $row['date_achevement'];
408 if($row['date_chantier']!='')
409 $this->valF['archive_date_chantier']= $row['date_chantier'];
410 if($row['date_conformite']!='')
411 $this->valF['archive_date_conformite']= $row['date_conformite'];
412 }
413 }
414
415 // Test si une restriction est valide
416 // return boolean
417 function restrictionIsValid($restriction){
418
419 /* Met des espace avant et après les opérateurs puis transforme la chaine en
420 * un tableau */
421 $tabRestriction = str_replace(">="," >= ",
422 str_replace("<="," <= ",
423 str_replace("-"," - ",
424 str_replace("+"," + ",$restriction))));
425 $tabRestriction = explode( " ", $tabRestriction);
426
427 //Variables de résultat
428 $res = array();
429 $i = 0;
430 $comp = "";
431
432
433 //Test que le tableau n'est pas vide
434 if ( count($tabRestriction) > 0 ){
435
436 $res[0] = $this->getRestrictionValue($tabRestriction[0]);
437
438 //Calcul des variables
439 for ( $j = 1 ; $j < count($tabRestriction) ; $j += 2 ) {
440
441 //Variable de comparaison
442 if ( strcmp( ">=", $tabRestriction[$j] ) == 0 ||
443 strcmp( "<=", $tabRestriction[$j]) ==0 ){
444
445 $comp = $tabRestriction[$j];
446 $res[++$i] = $this->getRestrictionValue($tabRestriction[$j+1]);
447 }
448 // Fait l'addition
449 elseif ( strcmp( "+", $tabRestriction[$j]) == 0 ){
450
451 $res[$i] = $this->moisdate( $res[$i], $this->getRestrictionValue($tabRestriction[$j+1]) );
452 }
453 }
454 }
455
456 // Effectue le test
457 if ( strcmp($comp, ">=") == 0 ){
458
459 if ( $res[0] >= $res[1] || $res[0] == "" ){
460
461 return true;
462 }
463 else {
464
465 return false;
466 }
467 }
468 elseif ( strcmp($comp, "<=") == 0 ){
469
470 if ( $res[0] <= $res[1] || $res[1] == "" ){
471
472 return true;
473 }
474 else {
475
476 return false;
477 }
478 }
479
480 return true;
481 }
482
483 //Retourne la valeur de valF si $restrictionValue n'est pas un chiffre, le chiffre sinon
484 function getRestrictionValue($restrictionValue){
485
486 return ( is_numeric($restrictionValue) ) ?
487 $restrictionValue :
488 $this->valF[$restrictionValue];
489 }
490
491 function regle($regle){
492 $temp = explode ("+",$regle);
493 //echo '|'.$regle;
494 // cas rejet
495 if($regle=="null") // 1 dimension -> null
496 return null;
497 if(sizeof($temp)==1) // 1 dimension
498 if($temp[0]=="archive_date_depot") // initialisation avec le depot
499 return $this->$regle;
500 else // cas general
501 return $this->valF[$regle];
502 if(sizeof($temp)==2){ // 2 dimensions
503 if($temp[0]=="archive_date_depot") //initialisation avec le depot
504 if(is_numeric($temp[1]))
505 return $this->moisdate($this->$temp[0], $temp[1]);
506 else
507 return $this->moisdate($this->$temp[0], $this->valF[$temp[1]]);
508 if($temp[0]=="archive_delai") // majoration de delai
509 return $this->valF[$temp[0]]+$this->valF[$temp[1]];
510 // cas general 2 dimensions
511 if(is_numeric($temp[1]))
512 return $this->moisdate($this->valF[$temp[0]], $temp[1]);
513 else
514 return $this->moisdate($this->valF[$temp[0]], $this->valF[$temp[1]]);
515 }
516 if(sizeof($temp)==3){ // 3 dimensions
517 // cas date de validite de sursis
518 if(is_numeric($temp[1]))
519 $temp1 = $this->moisdate($this->valF[$temp[0]], $temp[1]);
520 else
521 $temp1 = $this->moisdate($this->valF[$temp[0]], $this->valF[$temp[1]]);
522 if(is_numeric($temp[2]))
523 return $this->moisdate($temp1, $temp[2]);
524 else
525 return $this->moisdate($temp1, $this->valF[$temp[2]]);
526 }
527 }
528
529
530
531 // ==================================================================
532 // valeur dossier apres modification [values dossier after action]
533 // ==================================================================
534 function triggerajouterapres($id,&$db,$val,$DEBUG) {
535 // mise a null au lieu de "" / voir compatibilite mysql
536 // voir parametrage CU en dur
537 // voir parametrage des actions en dur
538 $param=1;
539 if($param==1){
540 $sql="select * from ".DB_PREFIXE."action where action = '".$this->valF['action']."'";
541 $res = $db->query($sql);
542 if (database::isError($res))
543 die($res->getMessage());
544 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
545 if($row['regle_etat']!=''){
546 $valF['etat']= $this->regle($row['regle_etat']);
547 }
548 if($row['regle_delai']!=''){
549 $valF['delai']= $this->regle($row['regle_delai']);
550 }
551 if($row['regle_accord_tacite']!=''){
552 $valF['accord_tacite']= $this->regle($row['regle_accord_tacite']);
553 }
554 if($row['regle_avis']!=''){
555 $valF['avis_decision']= $this->regle($row['regle_avis']);
556 }
557 if($row['regle_date_limite']!=''){
558 $valF['date_limite']= $this->regle($row['regle_date_limite']);
559 }
560 if($row['regle_date_complet']!=''){
561 $valF['date_complet']= $this->regle($row['regle_date_complet']);
562 }
563 if($row['regle_date_notification_delai']!=''){
564 $valF['date_notification_delai']= $this->regle($row['regle_date_notification_delai']);
565 }
566 if($row['regle_date_decision']!=''){
567 $valF['date_decision']= $this->regle($row['regle_date_decision']);
568 }
569 if($row['regle_date_rejet']!=''){
570 $valF['date_rejet']= $this->regle($row['regle_date_rejet']);
571 }
572 if($row['regle_date_validite']!=''){
573 $valF['date_validite']= $this->regle($row['regle_date_validite']);
574 }
575 if($row['regle_date_chantier']!=''){
576 $valF['date_chantier']= $this->regle($row['regle_date_chantier']);
577 }
578 if($row['regle_date_achevement']!=''){
579 $valF['date_achevement']= $this->regle($row['regle_date_achevement']);
580 }
581 if($row['regle_date_conformite']!=''){
582 $valF['date_conformite']= $this->regle($row['regle_date_conformite']);
583 }
584
585 // Appel des méthode stockées dans le champ methode_trigger
586 if($row['methode_trigger'] != "") {
587 foreach (explode(";", $row['methode_trigger']) as $methode) {
588 if(method_exists($this, $methode)) {
589 $this->$methode();
590 }
591
592 }
593 }
594 }
595 }else{
596 switch ($this->valF['action']) {
597 case "initialisation" :
598 $valF['delai']= $this->valF['delai'];
599 $valF['etat']= $this->valF['etat'];
600 $valF['accord_tacite']= $this->valF['accord_tacite'];
601 // la date_complet est la date de depot
602 $valF['date_complet']= $this->archive_date_depot; // ****
603 $valF['date_limite'] = $this->moisdate($valF['date_complet'],$valF['delai']);
604 $valF['date_notification_delai'] = $this->moisdate($valF['date_complet'],1);
605 break;
606 case "notification" :
607 $valF['delai']= $this->valF['delai'];
608 $valF['etat']= $this->valF['etat'];
609 $valF['accord_tacite']= $this->valF['accord_tacite'];
610 // la date_complet est celle precedemment saisie
611 $valF['date_complet']=$this->valF['archive_date_complet'];
612 $valF['date_limite'] = $this->moisdate($valF['date_complet'],$valF['delai']);
613 $valF['date_notification_delai'] = $this->moisdate($valF['date_complet'],1);
614 // la date du courrier ne doit pas etre depasse par rapport au delai de
615 // notification [verify notification date]
616 if($this->valF['archive_date_notification_delai']<$this->valF['date_evenement'])
617 $this->msg=$this->msg."<br><img src='../img/erreur.gif'> "._("date_notification_delai")." ".
618 $this->valF['archive_date_notification_delai']." < "._('date_evenement');
619 //
620 break;
621 case "retour" :
622 $valF['delai']= $this->valF['delai'];
623 $valF['etat']= $this->valF['etat'];
624 $valF['accord_tacite']= $this->valF['accord_tacite'];
625 // la date_complet est celle de l evenement
626 $valF['date_complet']= $this->valF['date_evenement'];
627 $valF['date_limite'] = $this->moisdate($valF['date_complet'],$valF['delai']);
628 $valF['date_notification_delai'] = $this->moisdate($valF['date_complet'],1);
629 break;
630 case "rejet" :
631 //$valF['delai']=0; // *** delai a garder pour etat dpc
632 $valF['etat']= $this->valF['etat'];
633 $valF['accord_tacite']= $this->valF['accord_tacite'];
634 // la date rejet est initialisee
635 $valF['date_rejet']= $this->valF['date_evenement'];
636 // les dates de depart et fin d instruction sont annulées
637 $valF['date_limite'] =null;
638 $valF['date_notification_delai'] =null;
639 $valF['date_complet']=null;
640 break;
641 case "majoration" :
642 $valF['delai']= $this->valF['archive_delai']+$this->valF['delai'];
643 $valF['etat']= $this->valF['etat'];
644 $valF['accord_tacite']= $this->valF['accord_tacite'];
645 $valF['date_complet']=$this->valF['archive_date_complet'];
646 // majoration de la date limite
647 $valF['date_limite'] = $this->moisdate($valF['date_complet'],$valF['delai']);
648 $valF['date_notification_delai'] = $this->moisdate($valF['date_complet'],1);
649 // la date du courrier ne doit pas etre depasse par rapport au delai de
650 // notification
651 if($this->valF['archive_date_notification_delai']<$this->valF['date_evenement'])
652 $this->msg=$this->msg."<br><img src='../img/erreur.gif'>"._("date_notification_delai").
653 $this->valF['archive_date_notification_delai']." < "._('date_evenement');
654 break;
655 case "acceptation" :
656 $valF['etat']= $this->valF['etat'];
657 $valF['date_decision']= $this->valF['date_evenement'];
658 $valF['avis_decision']= $this->valF['avis_decision'];
659 // date de validite = date de l evenement + delai
660 $valF['date_validite'] = $this->moisdate($this->valF['date_evenement'],$this->valF['delai']);
661 break;
662 case "refus" :
663 $valF['etat']= $this->valF['etat'];
664 $valF['date_decision']= $this->valF['date_evenement'];
665 $valF['avis_decision']= $this->valF['avis_decision'];
666 break;
667 case "prolongation" :
668 $valF['date_validite'] = $this->moisdate($this->valF['archive_date_validite'],$this->valF['delai']);
669 break;
670 case "sursis" :
671 $valF['date_limite'] = $this->moisdate($this->valF['date_evenement'],$this->valF['delai']);
672 $valF['etat']= $this->valF['etat'];
673 $valF['accord_tacite']= $this->valF['accord_tacite'];
674 $valF['avis_decision']= $this->valF['avis_decision'];
675 $valF['date_decision']= $this->valF['date_evenement'];
676 $temp = $valF['date_limite'];
677 $valF['date_validite']= $this->moisdate($temp,2);
678 break;
679 case "execution" :
680 $valF['etat']= $this->valF['etat'];
681 $valF['date_chantier'] = $this->valF['date_evenement'];
682 //echo $this->msg=$this->msg.$valF['date_chantier']."";
683 break;
684 case "achevement" :
685 $valF['etat']= $this->valF['etat'];
686 $valF['date_achevement'] = $this->valF['date_evenement'];
687 break;
688 case "archivage" :
689 $valF['etat']= $this->valF['etat'];
690 $valF['date_conformite'] = $this->valF['date_evenement'];
691 break;
692
693 default:
694 if ($this->valF['etat']!="")
695 $valF['etat']= $this->valF['etat'];
696 }// end switch
697 } // end param
698 if($valF!=""){
699 $cle= " dossier = '".$this->valF['dossier']."'";
700 $res1= $db->autoExecute(DB_PREFIXE.'dossier',$valF,DB_AUTOQUERY_UPDATE,$cle);
701 if (database::isError($res1))
702 die($res->getMessage());
703 if ($DEBUG == 1)
704 echo "La requête de mise à jour est effectuée.<br>";
705 $this->msg=$this->msg."<br>"._('enregistrement')." ".
706 $this->valF['dossier']." "._('table')." dossier [".
707 $db->affectedRows()." "._('enregistrement').
708 " "._('mis_a_jour')."]" ;
709 }
710 // verification si envoi vers ERP est active
711 if ($this->f->getParameter('option_erp') != "") {
712 // la nature du dossier
713 $nature_dossier = substr($this->idxformulaire,0,2);
714 $dossier_erp = $this->getFromDB("SELECT erp FROM ".DB_PREFIXE."dossier WHERE dossier = '" .
715 $this->valF['dossier'] . "'");
716 $evenement_libelle = $this->getFromDB(
717 "SELECT libelle FROM ".DB_PREFIXE."evenement WHERE evenement = '" .
718 $this->valF['evenement'] . "'");
719 if ($dossier_erp == 't') {
720 // envoi du message en cas d'un PC qui est ERP et sur lequel un evenement
721 // d'acceptation etait fait
722 if ($nature_dossier ==
723 $this->f->getParameter('erp_evenement_accepter_dossier_PC')
724 && $this->valF['evenement'] ==
725 $this->f->getParameter('erp_evenement_accepter_sans_reserve')) {
726 $msgenque = new MessageEnqueuer();
727 $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
728 $msgenque->setDecision($evenement_libelle);
729 $msgenque->enqueueMessage($msgenque::$ERP_ARRETE_PC_EFFECTUE);
730 }
731 if ($this->valF['evenement'] ==
732 $this->f->getParameter('erp_evenement_refuser_dossier')) {
733 $msgenque = new MessageEnqueuer();
734 $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
735 $msgenque->enqueueMessage($msgenque::$ERP_DECISION_CONFORMITE_EFFECTUE);
736 }
737 }
738 } // fin de if ($this->f->getParameter('option_erp') != "")
739 }
740
741
742 /**
743 * Fait une requette sql pour extraire la valeur d'un champ, et retourne
744 * cette valeur
745 * @param string $sql La requete sql a executer
746 * @return La valeur du champs cherche, sinon NULL. En cas d'erreur de la BD
747 * l'execution s'arrete.
748 */
749 function getFromDB($sql) {
750 //$sql = "SELECT libelle FROM ".DB_PREFIXE."dossier WHERE dossier = '" . $dossier . "'";
751 $res = $this->db->limitquery($sql, 0, 1);
752 $this->addToLog("getDossierERPSpecification(): db->limitquery(\"".
753 str_replace(",",", ",$sql)."\", 0, 1);", VERBOSE_MODE);
754 // Si une erreur survient on die
755 if (database::isError($res, true)) {
756 // Appel de la methode de recuperation des erreurs
757 $this->erreur_db($res->getDebugInfo(), $res->getMessage(), 'instruction');
758 }
759 // retourne la nature du dossier
760 while ($row =& $res->fetchRow()) {
761 return $row[0];
762 }
763 // la nature n'etait pas trouve, ce qui ne devrait pas se passer
764 return NULL;
765
766 }
767
768
769 function triggermodifierapres($id,&$db,$val,$DEBUG) {
770 /*
771 * cette fonction a pour objet de permettre de modifier la date courrier
772 */
773 $valF=array();
774 $sql= "select action from ".DB_PREFIXE."evenement where evenement =".$this->valF['evenement'];
775 $action = $db->getOne($sql);
776 if (database::isError($action)) die($action->getMessage().$sql);
777 $sql="select * from ".DB_PREFIXE."action where action = '".$action."'";
778 $res = $db->query($sql);
779 if (database::isError($res)) die($res->getMessage().$sql);
780 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
781 // application des regles sur le courrier + delai
782 if(preg_match("/date_evenement/",$row['regle_date_limite'])){
783 $valF['date_limite']= $this->regle($row['regle_date_limite']);
784 }
785 if(preg_match("/date_evenement/",$row['regle_date_complet'])){
786 $valF['date_complet']= $this->regle($row['regle_date_complet']);
787 }
788 if(preg_match("/date_evenement/",$row['regle_date_notification_delai'])){
789 $valF['date_notification_delai']= $this->regle($row['regle_date_notification_delai']);
790 }
791 if(preg_match("/date_evenement/",$row['regle_date_decision'])){
792 $valF['date_decision']= $this->regle($row['regle_date_decision']);
793 }
794 if(preg_match("/date_evenement/",$row['regle_date_rejet'])){
795 $valF['date_rejet']= $this->regle($row['regle_date_rejet']);
796 }
797 if(preg_match("/date_evenement/",$row['regle_date_validite'])){
798 $valF['date_validite']= $this->regle($row['regle_date_validite']);
799 }
800 if(preg_match("/date_evenement/",$row['regle_date_chantier'])){
801 $valF['date_chantier']= $this->regle($row['regle_date_chantier']);
802 }
803 if(preg_match("/date_evenement/",$row['regle_date_achevement'])){
804 $valF['date_achevement']= $this->regle($row['regle_date_achevement']);
805 }
806 if(preg_match("/date_evenement/",$row['regle_date_conformite'])){
807 $valF['date_conformite']= $this->regle($row['regle_date_conformite']);
808 }
809 } // while
810 if($valF!=array()){
811 $cle= " dossier = '".$this->valF['dossier']."'";
812 $res1= $db->autoExecute(DB_PREFIXE.'dossier',$valF,DB_AUTOQUERY_UPDATE,$cle);
813 if (database::isError($res1))
814 die($res->getMessage());
815 if ($DEBUG == 1)
816 echo "La requête de mise à jour est effectuée.<br>";
817 $this->msg=$this->msg."<br>"._('enregistrement')." ".
818 $this->valF['dossier']." "._('table')." dossier [".
819 $db->affectedRows()." "._('enregistrement').
820 " "._('mis_a_jour')."]" ;
821 }
822
823 // Envoi des infos au
824 if ($this->valF['date_retour_signature'] != $this->getVal('date_retour_signature')) {
825 $msgenque = new MessageEnqueuer();
826 $sqlArrete = "SELECT instruction.signataire_arrete as \"ws_DA_In_Signataire\",
827 signataire_arrete.nom as \"ws_DA_In_Sign_Nom\",
828 signataire_arrete.prenom as \"ws_DA_In_Sign_Prenom\",
829 signataire_arrete.qualite as \"ws_DA_In_Sign_Qualite\",
830 instruction.date_evenement as \"ws_DA_In_Dte_Redac\",
831 '' as \"ws_DA_In_lieu_Redac\",
832 instruction.dossier as \"ws_DA_In_N_Doss_DAS\",
833 '' as \"ws_DA_In_Sigle\",
834 instruction.etat as \"ws_DA_In_Decision\",
835 dossier.date_depot as \"ws_DA_In_Dte_Depot_Dem\",
836 dossier.terrain_numero as \"ws_DA_In_N_Voie\",
837 '' as \"ws_DA_In_Type_Voie\",
838 dossier.complement as \"ws_DA_In_Adresse1\",
839 dossier.terrain_adresse_lieu_dit as \"ws_DA_In_Adresse2\",
840 dossier.terrain_adresse_code_postal as \"ws_DA_In_CP\",
841 dossier.terrain_adresse_localite as \"ws_DA_In_Ville\",
842 dossier.terrain_references_cadastrales as \"ws_DA_In_Nb_Parcelle\",
843 '' as \"ws_DA_In_Detail_Parcelle\",
844 CONCAT(donnees_techniques.am_projet_desc,' ',donnees_techniques.co_projet_desc) as \"ws_DA_In_Nature_Trvx\",
845 '' as \"ws_DA_In_Destination_Trvx\",
846 dossier_autorisation_type_detaille.code as \"ws_DA_In_Type_Dos_Autoris\",
847 COALESCE(particulier_nom,personne_morale_raison_sociale) as \"ws_DA_In_Nom_Petition\",
848 COALESCE(particulier_prenom, personne_morale_denomination) as \"ws_DA_In_Prenom_Petition\",
849 '' as \"ws_DA_In_Piece_GED\",
850 instruction.date_retour_signature as \"ws_DA_In_Dte_Signature\"
851 FROM ".DB_PREFIXE."instruction
852 LEFT JOIN ".DB_PREFIXE."signataire_arrete ON
853 instruction.signataire_arrete = signataire_arrete.signataire_arrete
854 LEFT JOIN ".DB_PREFIXE."dossier ON
855 instruction.dossier = dossier.dossier
856 LEFT JOIN ".DB_PREFIXE."lien_dossier_demandeur ON
857 lien_dossier_demandeur.dossier = dossier.dossier
858 LEFT JOIN ".DB_PREFIXE."demandeur ON
859 lien_dossier_demandeur.demandeur = demandeur.demandeur
860 LEFT JOIN ".DB_PREFIXE."dossier_instruction_type ON
861 dossier.dossier_instruction_type = dossier_instruction_type.dossier_instruction_type
862 LEFT JOIN ".DB_PREFIXE."dossier_autorisation_type_detaille ON
863 dossier_instruction_type.dossier_autorisation_type_detaille =
864 dossier_autorisation_type_detaille.dossier_autorisation_type_detaille
865 LEFT JOIN ".DB_PREFIXE."donnees_techniques ON
866 donnees_techniques.dossier_instruction = dossier.dossier
867 WHERE instruction.instruction = ".$this->valF['instruction'];
868 $resArrete = $this->db->query($sqlArrete);
869 $this->f->addToLog("triggerModifierApres(): db->query(\"".$sqlArrete."\");", VERBOSE_MODE);
870 $this->f->isDatabaseError();
871
872 $rowArrete = $resArrete->fetchRow(DB_FETCHMODE_ASSOC);
873 $msgenque->setArreteInfo($rowArrete);
874 $msgenque->enqueueMessage($msgenque::$ARRETE_ENVOI);
875 }
876 }
877
878
879
880 // trigger before delete
881 function triggersupprimer($id,&$db,$val,$DEBUG) {
882 // archive en instruction (si suppression) [archive if delete instruction]
883 $valF['delai']=$val['archive_delai'];
884 $valF['accord_tacite']=$val['archive_accord_tacite'];
885 $valF['etat']=$val['archive_etat'];
886 if($val['archive_avis']=='')
887 $valF['avis_decision']= null;
888 else
889 $valF['avis_decision']=$val['archive_avis'];
890 // if= compatibilite pgsql
891 if($val['archive_date_complet']!='')
892 $valF['date_complet']=$val['archive_date_complet'];
893 if($val['archive_date_rejet']!='')
894 $valF['date_rejet']= $val['archive_date_rejet'];
895 if($val['archive_date_limite']!='')
896 $valF['date_limite']= $val['archive_date_limite'];
897 if($val['archive_date_notification_delai']!='')
898 $valF['date_notification_delai']= $val['archive_date_notification_delai'];
899 if($val['archive_date_decision']!='')
900 $valF['date_decision']= $val['archive_date_decision'];
901 if($val['archive_date_validite']!='')
902 $valF['date_validite']= $val['archive_date_validite'];
903 if($val['archive_date_achevement']!='')
904 $valF['date_achevement']= $val['archive_date_achevement'];
905 if($val['archive_date_chantier']!='')
906 $valF['date_chantier']= $val['archive_date_chantier'];
907 if($val['archive_date_conformite']!='')
908 $valF['date_conformite']= $val['archive_date_conformite'];
909
910 $cle= " dossier = '".$val['dossier']."'";
911 $res= $db->autoExecute(DB_PREFIXE.'dossier',$valF,DB_AUTOQUERY_UPDATE,$cle);
912 if (database::isError($res))
913 die($res->getMessage());
914 else{
915 if ($DEBUG == 1)
916 echo "La requête de mise à jour est effectuée.<br>";
917 }
918 }
919 // =============================================
920 // calcul de date avec ajout de mois (delais)
921 // [add months (delay) and calculation final date]
922 // LIMITE DE LA FONCTION si delai >24 MOIS
923 // [limit : delay < 24 month]
924 // =============================================
925 function moisdate($date,$delaimois) {
926 $temp = explode("-" , $date);
927 $jour = (int) $temp[2];
928 $mois = (int) $temp[1];
929 $annee = (int) $temp[0];
930 // calcul si delai superieur à 12 (limite 24) [delay > 24 month]
931 if($delaimois>=12){
932 $delaimois=$delaimois-12;
933 $annee=$annee+1;
934 }
935 if($delaimois>=12){
936 $delaimois=$delaimois-12;
937 $annee=$annee+1;
938 }
939 // mois
940 $mois=$mois+$delaimois;
941 // calcul mois annee [calculation number of years if > 12 month]
942 // nb de mois > à 12
943 if ($mois>12){
944 $mois=$mois-12;
945 $annee=$annee+1;
946 }
947 // Calcul du nombre de jours dans le mois sélectionné [calculation number of days]
948 switch($mois) {
949 case "2":
950 if ($annee % 4 == 0 && $annee % 100 != 0 || $annee % 400 == 0)
951 $jourmax = 29;
952 else
953 $jourmax = 28;
954 break;
955 case "4":
956 case "6":
957 case "9":
958 case "11":
959 $jourmax = 30;
960 break;
961 default:
962 $jourmax = 31;
963 }
964 if ($jour > $jourmax)
965 $jour = $jourmax;
966 //$dateretour=$annee."-".$mois."-".$jour;
967 return $annee."-".$mois."-".$jour ;
968 }
969
970 // Vérifie la restriction sur l'événement
971 function verifier($val = array(), &$db, $DEBUG){
972 parent::verifier($val, $db, $DEBUG);
973 //Récupère la restriction
974 $sql= "SELECT
975 restriction
976 FROM
977 ".DB_PREFIXE."evenement
978 WHERE
979 evenement =".$this->valF['evenement'];
980
981 $res = $db->query($sql);
982 $this->f->addToLog("verifier(): db->query(\"".$sql."\");", VERBOSE_MODE);
983 $this->f->isDatabaseError();
984
985 $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);
986
987 //Test qu'une restriction est présente
988 if ( isset($row['restriction']) && $row['restriction'] != "" ){
989
990 //Test si la restriction est valide
991 if ( !$this->restrictionIsValid($row['restriction']) ){
992
993 $this->correct=false;
994 $this->addToMessage(_("Restriction non valide"));
995 }
996 else {
997
998 $this->correct = true;
999 }
1000 }
1001 }
1002
1003 /**
1004 * Méthode permettant de mettre à jour l'état d'un DA
1005 */
1006 function majEtatDA() {
1007 if($this->valF['action'] == 'accepter' AND $this->valF['avis_decision'] == 8) {
1008 $val['etat_dossier_autorisation']=5;
1009 } elseif($this->valF['action'] == 'accepter' AND $this->valF['avis_decision'] == 15) {
1010 $val['etat_dossier_autorisation']=3;
1011 } elseif($this->valF['action'] == 'accepter') {
1012 $val['etat_dossier_autorisation']=2;
1013 } elseif($this->valF['action'] == 'rejeter') {
1014 $val['etat_dossier_autorisation']=4;
1015 } elseif($this->valF['action'] == 'terminer') {
1016 $val['etat_dossier_autorisation']=8;
1017 } elseif($this->valF['action'] == 'majorer') {
1018 $val['etat_dossier_autorisation']=6;
1019 } else {
1020 $val['etat_dossier_autorisation']=7;
1021 }
1022
1023 //Récupération du numéro de dossier d'autorisation lié au dossier d'instruction
1024 $IDdossier_autorisation = $this->getDossierAutorisation($this->valF['dossier']);
1025
1026 // Mis à jour de l'état du dossier d'autorisation
1027 require_once '../obj/dossier_autorisation.class.php';
1028 $dossier_autorisation = new dossier_autorisation($IDdossier_autorisation,$this->db,DEBUG);
1029
1030 $dossier_autorisation->val[array_search("etat_dossier_autorisation", $dossier_autorisation->champs)] = $val['etat_dossier_autorisation'];
1031
1032 //Récupération des données
1033 $valDossierAutorisation = array();
1034 for ( $i=0 ; $i<count($dossier_autorisation->champs); $i++){
1035
1036 $valDossierAutorisation[$dossier_autorisation->champs[$i]]=
1037 $dossier_autorisation->val[$i];
1038 }
1039
1040 $dossier_autorisation->modifier($valDossierAutorisation, $this->db, DEBUG);
1041 }
1042
1043 /**
1044 * Méthode permettant de mettre à jour les données d'un DA
1045 */
1046 function majDataDA() {
1047
1048 //Récupération du numéro de dossier d'autorisation lié au dossier d'instruction
1049 $IDdossier_autorisation = $this->getDossierAutorisation($this->valF['dossier']);
1050 require_once '../obj/dossier_autorisation.class.php';
1051 $dossier_autorisation = new dossier_autorisation($IDdossier_autorisation,$this->db,DEBUG);
1052
1053 require_once '../obj/dossier.class.php';
1054 $dossier = new dossier($this->valF['dossier'],$this->db,DEBUG);
1055
1056 //Récupération des données
1057 $valDossierAutorisation = array();
1058 for ( $i=0 ; $i<count($dossier_autorisation->champs); $i++){
1059
1060 if ( array_search($dossier_autorisation->champs[$i], $dossier->champs) ){
1061
1062 $valDossierAutorisation[$dossier_autorisation->champs[$i]]=$dossier->getVal($dossier_autorisation->champs[$i]);
1063 }
1064 else {
1065 $valDossierAutorisation[$dossier_autorisation->champs[$i]]=
1066 $dossier_autorisation->val[$i];
1067 }
1068 }
1069
1070 $dossier_autorisation->modifier($valDossierAutorisation, $this->db, DEBUG);
1071
1072 // Suppression du liens entre les lots et le DA
1073 $valLot['dossier_autorisation'] = NULL;
1074 $this->db->autoExecute(DB_PREFIXE."lot", $valLot, DB_AUTOQUERY_UPDATE, "dossier_autorisation='".$IDdossier_autorisation."'");
1075
1076 // Liaison des lots du DI avec le DA
1077 $sqlLot = "SELECT lot FROM ".DB_PREFIXE."lien_dossier_lot WHERE dossier='".$this->valF['dossier']."'";
1078 $res = $this->db->query($sqlLot);
1079 $this->addToLog($sqlLot);
1080 $this->f->isDatabaseError();
1081 while($rowLot = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
1082 $valLot['dossier_autorisation'] = $IDdossier_autorisation;
1083 $this->db->autoExecute(DB_PREFIXE."lot", $valLot, DB_AUTOQUERY_UPDATE, "lot=".$rowLot['lot']);
1084 }
1085 }
1086
1087 // Récupération de l'identifiant du dossier d'autorisation lié au dossier d'instruction
1088 function getDossierAutorisation($dossier_instruction){
1089
1090 $sql = "SELECT
1091 dossier_autorisation.dossier_autorisation
1092 FROM
1093 ".DB_PREFIXE."dossier_autorisation
1094 LEFT JOIN
1095 ".DB_PREFIXE."dossier
1096 ON
1097 dossier_autorisation.dossier_autorisation = dossier.dossier_autorisation
1098 WHERE
1099 dossier.dossier = '".$dossier_instruction."'";
1100
1101 $IDdossier_autorisation = $this->db->getOne($sql);
1102 $this->addToLog("getDossierAutorisation(): db->getone(\"".$sql."\")", VERBOSE_MODE);
1103 database::isError($IDdossier_autorisation);
1104
1105 return $IDdossier_autorisation;
1106 }
1107 }// fin classe
1108 ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26