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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1185 - (show annotations)
Wed Jan 9 11:20:26 2013 UTC (12 years ago) by vpihour
File size: 64237 byte(s)
Ajout de la rédaction du rapprt d'instruction à partir du portlet d'action d'un dossier d'instruction

1 <?php
2 //$Id$
3 //gen openMairie le 10/02/2011 20:39
4
5 require_once ("../gen/obj/dossier.class.php");
6 require_once("../services/outgoing/messageenqueuer.php");
7
8 class dossier extends dossier_gen {
9
10 var $maj;
11 var $sig;
12 var $servitude="";
13 var $auto_pos;
14 var $auto_servitude_surfacique;
15 var $auto_servitude_ligne;
16 var $auto_servitude_point;
17 var $auto_parcelle;
18 var $auto_parcelle_lot;
19 var $aff_depot = "collapsible";
20 var $aff_travaux = "collapsible";
21 var $aff_instruction = "collapsible";
22 var $aff_demandeur = "startClosed";
23 var $aff_delegataire = "startClosed";
24 var $aff_terrain = "startClosed";
25 var $aff_localisation = "collapsible";
26 var $aff_description = "startClosed";
27 var $aff_amenagement = "startClosed";
28 var $dossier_instruction_type;
29
30 function dossier($id,&$db,$DEBUG) {
31 $this->constructeur($id,$db,$DEBUG);
32 } // fin constructeur
33
34 /*Mutateur pour ma variable dossier_instruction_type*/
35 public function getDossierInstructionType(){
36 return $this->dossier_instruction_type;
37 }
38 public function setDossierInstructionType($dossier_instruction_type){
39 $this->dossier_instruction_type = $dossier_instruction_type;
40 }
41
42 // {{{ Gestion de la confidentialité des données spécifiques
43
44 /**
45 * Surcharge pour gérer les actions disponibles dans le portlet
46 */
47 function checkAccessibility() {
48 //
49 parent::checkAccessibility();
50 // Si l'utilisateur est un intructeur qui en correspond pas à la
51 // division du dossier
52 if ($this->f->isUserInstructeur()
53 && isset($this->f->om_utilisateur["division"])
54 && $this->f->om_utilisateur["division"] != $this->getDivisionFromDossier()) {
55 //
56 $this->actions_sup = array();
57 $this->setParameter("actions", array());
58 }
59
60 /*
61 * Si une action 'rapport_instruction' est présente et
62 * que le le rapport d'instruction existe déjà, lien vers l'objet en modification
63 * sinon, lien vers un script qui va créer le nouvel objet et
64 * rediriger l'utilisateur vers l'objet en modification.
65 */
66
67 // Vérifie si un rapport d'instruction existe déjà
68 if ( isset($this->actions_sup["rapport_instruction"]) ) {
69
70 // Requête de vérification
71 $sql = "SELECT
72 rapport_instruction
73 FROM
74 ".DB_PREFIXE."rapport_instruction
75 WHERE
76 dossier_instruction = '".$this->getParameter('idx')."'";
77
78 // Ajout au log
79 $this->f->addToLog("checkAccessibility(): db->query(\"".$sql."\");", VERBOSE_MODE);
80
81 // Exécution de la requête
82 $res=$this->f->db->query($sql);
83 $this->f->isDatabaseError($res);
84
85 /*
86 * S'il n'y a pas de rapport d'instruction, redirection vers un script
87 * de création, puis vers l'objet.
88 * */
89 if ( $res->numrows() == 0 ){
90
91 $this->actions_sup["rapport_instruction"]["lien"] =
92 '../app/rapport_instruction.php?idx=';
93 }
94 // S'il a déjà été créé, lien vers l'objet en modification
95 elseif ( $res->numrows() > 0 ){
96
97 $row = & $res->fetchRow(DB_FETCHMODE_ASSOC);
98 $this->actions_sup["rapport_instruction"]["lien"] =
99 '../scr/form.php?obj=rapport_instruction&amp;action=1&amp;idx='.
100 $row['rapport_instruction'].'&amp;idD=';
101 }
102
103 }
104 }
105
106 /**
107 * Cette methode est à surcharger elle permet de tester dans chaque classe
108 * des droits des droits spécifiques en fonction des données
109 */
110 function canAccess() {
111 // Si l'utilisateur est un intructeur qui ne correspond pas à la
112 // division du dossier
113 if ($this->f->isUserInstructeur()
114 && $this->f->om_utilisateur["division"] != $this->getDivisionFromDossier()
115 && $this->getParameter("maj") != 3) {
116 //
117 return false;
118 }
119 //
120 return true;
121 }
122
123 /**
124 * Cette méthode permet de récupérer la division d'un dossier
125 */
126 function getDivisionFromDossier() {
127 //
128 if (!isset($this->val[array_search("dossier", $this->champs)])) {
129 return NULL;
130 }
131 //
132 $sql = "select division from ".DB_PREFIXE."dossier ";
133 $sql .= " where dossier='".$this->val[array_search("dossier", $this->champs)]."'";
134 //
135 $division = $this->db->getOne($sql);
136 $this->addToLog("getDivisionFromDossier(): db->getone(\"".$sql."\")", VERBOSE_MODE);
137 database::isError($division);
138 //
139 return $division;
140 }
141
142 // }}}
143 /*
144 * Ajoute un numéro au dossier
145 *
146 */
147 function setValFAjout($val = array()) {
148
149 /*Récupération de la lettre associé au type de dossier d'instruction*/
150 $code = $this->getCode($this->getDossierInstructionType());
151
152 /* Récupération de la valeur du suffixe ce dossier_instruction_type */
153 $suffixe = $this->getSuffixe($this->getDossierInstructionType());
154
155 /*S'il est à TRUE, on récupère le numéro de version du dossier d'autorisation*/
156 $numeroVersion = "";
157 if ( $suffixe == 't' ){
158
159 $numeroVersion = $this->getNumeroVersion($val['dossier_autorisation']);
160
161 /* Incrémentation du numéro de version */
162 if ( is_numeric($numeroVersion) or $numeroVersion == -1 ){
163
164 $this->incrementNumeroVersion($val['dossier_autorisation'], ++$numeroVersion);
165 }
166 }
167
168 /*Création du numéro de dossier*/
169 $this->valF['dossier'] = $val['dossier_autorisation']."$code$numeroVersion";
170 }
171
172 /*Récupère la valeur du suffixe d'un dossier_instruction_type*/
173 function getSuffixe($dossierInstructionType){
174
175 $suffixe = "";
176
177 $sql = "SELECT
178 suffixe
179 FROM
180 ".DB_PREFIXE."dossier_instruction_type
181 WHERE
182 dossier_instruction_type = $dossierInstructionType";
183
184 $this->addToLog("getSuffixe(): db->query(\"".$sql."\")", VERBOSE_MODE);
185 $res = $this->db->query($sql);
186 if (database :: isError($res))
187 die($res->getMessage()."erreur ".$sql);
188
189 if ( $res->numRows() > 0 ){
190
191 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
192 $suffixe = $row['suffixe'];
193 }
194
195 return $suffixe;
196 }
197
198 /*Récupère dans la table de paramètrage la lettre correspondant
199 * au dossier_instruction_type
200 */
201 function getCode($dossierInstructionType){
202
203 $code = "";
204
205 $sql = "SELECT
206 code
207 FROM
208 ".DB_PREFIXE."dossier_instruction_type
209 WHERE
210 dossier_instruction_type = $dossierInstructionType";
211
212 $this->addToLog("getCode(): db->query(\"".$sql."\")", VERBOSE_MODE);
213 $res = $this->db->query($sql);
214 if (database :: isError($res))
215 die($res->getMessage()."erreur ".$sql);
216
217 if ( $res->numRows() > 0 ){
218
219 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
220 $code = $row['code'];
221 }
222
223 return $code;
224 }
225
226 /*Récupère le numéro de version d'un dossier_autorisation*/
227 function getNumeroVersion($dossierAutorisation){
228
229 $numeroVersion = "";
230
231 $sql = "SELECT
232 numero_version
233 FROM
234 ".DB_PREFIXE."dossier_autorisation
235 WHERE
236 dossier_autorisation = '$dossierAutorisation'";
237
238 $this->addToLog("getNumeroVersion(): db->query(\"".$sql."\")", VERBOSE_MODE);
239 $res = $this->db->query($sql);
240 if (database :: isError($res))
241 die($res->getMessage()."erreur ".$sql);
242
243 if ( $res->numRows() > 0 ){
244
245 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
246 $numeroVersion = $row['numero_version'];
247 }
248
249 return $numeroVersion;
250 }
251
252 /*Incrémente le numéro de version du dossier*/
253 function incrementNumeroVersion($dossierAutorisation, $nouveauNumeroVersion) {
254
255 $valF = array (
256 "numero_version" => $nouveauNumeroVersion
257 );
258
259 $res = $this->db->autoExecute(DB_PREFIXE."dossier_autorisation",
260 $valF,
261 DB_AUTOQUERY_UPDATE,
262 "dossier_autorisation = '$dossierAutorisation'");
263
264 if (database :: isError($res))
265 die($res->getMessage()."erreur ".$sql);
266
267 }
268
269 function setvalF($val){
270 parent::setvalF($val);
271 // enlever les valeurs a ne pas saisir -> recherche en trigger ajouter et modifier
272 // $sig = 1
273 unset ($this->valF['geom']);
274 unset ($this->valF['geom1']);
275 // valeurs hiddenstatic (calcule)
276 if($this->maj==1){
277 // par defaut
278 unset ($this->valF['etat']);
279 unset ($this->valF['delai']);
280 unset ($this->valF['accord_tacite']);
281 unset ($this->valF['types']);
282 }
283 unset ($this->valF['avis_decision']); // avis + libelle avis
284 unset ($this->valF['terrain_surface_calcul']);
285 unset ($this->valF['shon_calcul']);
286 unset ($this->valF['parcelle_archive']);
287 unset ($this->valF['parcelle_lot_archive']);
288 unset ($this->valF['date_notification_delai']);
289 unset ($this->valF['date_decision']);
290 unset ($this->valF['date_limite']);
291 unset ($this->valF['date_validite']);
292 unset ($this->valF['date_chantier']);
293 unset ($this->valF['date_achevement']);
294 unset ($this->valF['date_conformite']);
295 }
296
297 /*Vérification des données saisies*/
298 function verifier($val,&$db,$DEBUG){
299 parent::verifier($val,$db,$DEBUG);
300 if($val['parcelle']!="" and $val['sig']!='Oui'){
301 if (!preg_match('/^[0-9]{3} [A-Z]{1,3} [0-9]{1,5}$/', $val['parcelle']) && !preg_match('/^[0-9]{3}[A-Z]{1,3}[0-9]{1,5}$/', $val['parcelle'])){
302 $this->correct=false;
303 $this->addToMessage("<br>format parcelle incorrect");
304 }
305 }
306 // regles travaux verification
307 if ($this->valF['travaux']!=""){
308 $sql= "select * from ".DB_PREFIXE."regle where id = '".$this->valF['travaux'].
309 "' and controle = 'travaux' order by ordre";
310 $res = $db->query($sql);
311 if (database :: isError($res)) die($res->getMessage().$sql);
312 $this->addToLog("requete ".$sql." execute <br>", EXTRA_VERBOSE_MODE);
313 $regle=0;
314 $msg="";
315 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
316 if(isset($this->valF[$row['champ']]))
317 $champvaleur=$this->valF[$row['champ']];
318 else
319 $champvaleur=0;
320 switch ($row['operateur']) {
321 case ">" :
322 if($row['sens']=="plus"){
323 if($champvaleur > $row['valeur'])
324 $condition = 1;
325 else
326 $condition = 0;
327 if($regle==1 or $condition == 1)
328 $regle=1;
329 else
330 $regle=0;
331 $msg=$msg."<br> + ".$row['message']." [".$row['champ']." = ".
332 $champvaleur."]";
333 }else{
334 if($champvaleur > $row['valeur']){
335 $condition = 0;
336 }else{
337 $condition = 1;
338 $regle=0;
339 }
340 $msg=$msg."<br> ou ".$row['message']." [".$row['champ']." = ".
341 $champvaleur."]";
342 }
343 break;
344 case ">=":
345 if($row['sens']=="plus"){
346 if($champvaleur >= $row['valeur'])
347 $condition = 1;
348 else
349 $condition = 0;
350 if($regle==1 or $condition == 1)
351 $regle=1;
352 else
353 $regle=0;
354 $msg=$msg."<br> + ".$row['message']." [".$row['champ']." = ".
355 $champvaleur."]";
356 }else{
357 if($champvaleur >= $row['valeur']){
358 $condition = 0;
359
360 }else{
361 $condition = 1;
362 $regle=0;
363 }
364 $msg=$msg."<br> ou ".$row['message']." [".$row['champ']." = ".
365 $champvaleur."]";
366 }
367 break;
368 case "<" :
369 if($row['sens']=="plus"){
370 if($champvaleur < $row['valeur'])
371 $condition = 1;
372 else
373 $condition = 0;
374 if($regle==1 or $condition == 1)
375 $regle=1;
376 else
377 $regle=0;
378 $msg=$msg."<br> + ".$row['message']." [".$row['champ']." = ".
379 $champvaleur."]";
380 }else{
381 if($champvaleur < $row['valeur']){
382 $condition = 0;
383 }else{
384 $condition = 1;
385 $regle=0;
386 }
387 $msg=$msg."<br> et ".$row['message']." [".$row['champ']." = ".
388 $champvaleur."]";
389 }
390 break;
391 case "==":
392 if($row['sens']=="plus"){
393 if($champvaleur == $row['valeur'])
394 $condition = 1;
395 else
396 $condition = 0;
397 if($regle==1 or $condition == 1)
398 $regle=1;
399 else
400 $regle=0;
401 $msg=$msg."<br> + ".$row['message']." [".$row['champ']." = ".
402 $champvaleur."]";
403 }else{
404 if($champvaleur == $row['valeur']){
405 $condition = 0;
406
407 }else{
408 $condition = 1;
409 $regle=0;
410 }
411 $msg=$msg."<br> ou ".$row['message']." [".$row['champ']." = ".
412 $champvaleur."]";
413 }
414 break;
415 //break;
416 } // switch
417 if($regle==0)
418 $this->addToMessage($msg." <br>");
419 } // while
420 } // travaux
421 }//verifier
422
423
424 function setType(&$form,$maj) {
425 parent::setType($form,$maj);
426 if ($maj < 2) { //ajouter et modifier
427 // cache
428 if($maj==0) $form->setType('dossier', 'hidden');
429 $form->setType('annee', 'hidden');
430 $form->setType('parcelle_archive','hidden');
431 $form->setType('parcelle_lot_archive','hidden');
432 $form->setType('objet_dossier','hidden'); // PC
433 $form->setType('amenagement','hidden'); // PC
434 $form->setType('parcelle_lot','hidden'); // PC
435 $form->setType('parcelle_lot_lotissement','hidden'); // PC
436
437 $form->setType('geom1', 'hidden');
438 $form->setType('geom', 'geom');
439 $form->setType('servitude', 'hiddenstatic');
440
441 //select
442 $form->setType('terrain_numero_complement','select');
443
444 // combo
445 $form->setType('rivoli','comboD');
446 $form->setType('terrain_adresse','comboG');
447 $form->setType('architecte_nom','comboG');
448 $form->setType('architecte','comboD');
449
450
451 // hiddenstatic
452 if($maj==1) $form->setType('dossier', 'hiddenstatic');
453 $form->setType('etat','hiddenstatic');
454 $form->setType('avis_decision','hiddenstatic');
455 $form->setType('delai','hiddenstatic');
456 $form->setType('terrain_surface_calcul','hiddenstatic');
457 $form->setType('shon_calcul','hiddenstatic');
458
459 $form->setType('accord_tacite','hiddenstatic');
460 $form->setType('types', 'hiddenstatic'); // transfert modificatif
461
462
463 // hiddenstaticdate
464 $form->setType('date_notification_delai','hiddenstaticdate');
465 $form->setType('date_decision','hiddenstaticdate');
466 $form->setType('date_limite','hiddenstaticdate');
467 $form->setType('date_rejet','hiddenstaticdate');
468 $form->setType('date_complet','hiddenstaticdate');
469 $form->setType('date_limite','hiddenstaticdate');
470 $form->setType('date_validite','hiddenstaticdate');
471 $form->setType('date_chantier','hiddenstaticdate');
472 $form->setType('date_achevement','hiddenstaticdate');
473 $form->setType('date_conformite','hiddenstaticdate');
474
475 // checkbox
476 $form->setType('sig','checkbox');
477 $form->setType('delegataire','checkbox');
478
479 // mail
480 $form->setType('delegataire_email','mail');
481 $form->setType('demandeur_email','mail');
482
483 // zones temp et strategysig
484
485
486 // temp
487 if (file_exists ("../dyn/var.inc"))
488 include ("../dyn/var.inc");
489 if(!isset($auto_pos))
490 $auto_pos=0;
491 if($auto_pos==1)
492 $form->setType('pos','hiddenstatic');
493 else
494 $form->setType('pos','select');
495 $form->setType('temp1',$temp1_type);
496 $form->setType('temp2',$temp2_type);
497 $form->setType('temp3',$temp3_type);
498 $form->setType('temp4',$temp4_type);
499 $form->setType('temp5',$temp5_type);
500 $form->setType('a_qualifier', 'checkbox');
501 }
502 if ($maj == 1) {
503 //
504 if ($this->f->isAccredited("dossier_modifier_instructeur")) {
505 $form->setType('instructeur', 'select');
506 } else {
507 $form->setType('instructeur', 'selecthiddenstatic');
508 }
509 //
510 if($this->f->getParameter('afficher_division') === 'true') {
511 //
512 if ($this->f->isAccredited("dossier_modifier_division")) {
513 $form->setType('division', 'select');
514 } else {
515 $form->setType('division', 'selecthiddenstatic');
516 }
517 } else {
518 $form->setType('division', 'hidden');
519 }
520 }
521 if($maj == 3) {
522 $form->setType('annee', 'hidden');
523 $form->setType('temp1','hidden');
524 $form->setType('temp2','hidden');
525 $form->setType('temp3','hidden');
526 $form->setType('temp4','hidden');
527 $form->setType('temp5','hidden');
528 $form->setType('parcelle_archive','hidden');
529 $form->setType('parcelle_lot_archive','hidden');
530 $form->setType('geom1','hidden');
531 $form->setType('geom','hidden');
532 $form->setType('a_qualifier', 'checkboxstatic');
533 }
534 //
535 if(!$this->f->getParameter('afficher_division') === 'true') {
536 $form->setType('division', 'hidden');
537 }
538 $form->setType('dossier_autorisation', 'hiddenstatic');
539 //
540 if ($maj == 0) {
541 $form->setType('dossier_autorisation', 'select');
542 }
543 // On cache enjeu_ERP si l'option n'est pas activée
544 if($this->f->getParameter('option_ERP') != 'true') {
545 $form->setType('erp', 'hidden');
546 $form->setType('enjeu_erp', 'hidden');
547 }
548 }
549
550 function setVal(&$form,$maj,$validation){
551 $this->maj=$maj;
552 if ($validation==0) {
553 if ($maj == 0){
554 //$dossier_cp = $this->f->collectivite["cp"];
555 //$dossier_ville = $this->f->collectivite["ville"];
556
557 $form->setVal('annee', date('y'));
558 $form->setVal('date_demande', date('Y-m-d'));
559 $form->setVal('date_depot', date('Y-m-d'));
560
561 //$form->setVal('demandeur_cp', $dossier_cp);
562 //$form->setVal('demandeur_ville', $dossier_ville);
563
564 //$form->setVal('delegataire_cp', $dossier_cp);
565 //$form->setVal('delegataire_ville', $dossier_ville);
566
567 //$form->setVal('terrain_cp', $dossier_cp);
568 //$form->setVal('terrain_ville', $dossier_ville);
569
570 $form->setVal('accord_tacite', 'Non');
571 $form->setVal('etat', 'initialiser');
572 $form->setVal('types', 'Initial');
573 }
574 }
575 }
576
577 function setSelect(&$form, $maj,&$db,$debug) {
578 parent::setSelect($form, $maj,$db,$debug);
579 //optimisation sur table importante parcelle -> pas d appel methode parent
580 if(file_exists ("../sql/".$db->phptype."/".$this->table.".form.inc.php"))
581 include ("../sql/".$db->phptype."/".$this->table.".form.inc.php");
582 if($maj<2){
583 // travaux
584 $contenu=array();
585 // prise en compte du solde en ajout
586 if($maj==0)
587 $sql_travaux = $sql_travaux.
588 " and solde = 'Non' order by libelle";
589 else
590 $sql_travaux = $sql_travaux.
591 " order by libelle";
592 $res = $db->query($sql_travaux);
593 if (database::isError($res)) die($res->getMessage()).$sql_travaux;
594 $this->addToLog(" la requete ".$sql_travaux." est executee", VERBOSE_MODE);
595 $contenu[0][0]="";
596 $contenu[1][0]=_('choisir')." "._('travaux');
597 $k=1;
598 while ($row=& $res->fetchRow()){
599 $contenu[0][$k]=$row[0];
600 $contenu[1][$k]=$row[1];
601 $k++;
602 }
603 $form->setSelect("travaux",$contenu);
604
605 // code et libelle voie
606 $contenu="";
607 $contenu[0][0]="rivoli";// table
608 $contenu[0][1]="rivoli"; // zone origine
609 $contenu[1][0]="libelle";
610 $contenu[1][1]="terrain_adresse";
611 $form->setSelect("rivoli",$contenu);
612 //terrain_adresse
613 $contenu="";
614 $contenu[0][0]="rivoli";// table
615 $contenu[0][1]="libelle"; // zone origine
616 $contenu[1][0]="rivoli";
617 $contenu[1][1]="rivoli";
618 $form->setSelect("terrain_adresse",$contenu);
619 // code et libelle architecte
620 $contenu="";
621 $contenu[0][0]="architecte";// table
622 $contenu[0][1]="architecte"; // zone origine
623 $contenu[1][0]="nom";
624 $contenu[1][1]="architecte_nom";
625 $form->setSelect("architecte",$contenu);
626 $contenu="";
627 $contenu[0][0]="architecte";// table
628 $contenu[0][1]="nom"; // zone origine
629 $contenu[1][0]="architecte";
630 $contenu[1][1]="architecte";
631 $form->setSelect("architecte_nom",$contenu);
632 // parcelle_lot
633 $contenu="";
634 $contenu[0][0]="parcelle_lot";// table
635 $contenu[0][1]="parcelle_lot"; // zone origine
636 $contenu[1][0]="lotissement";
637 $contenu[1][1]="parcelle_lot_lotissement";
638 $form->setSelect("parcelle_lot",$contenu);
639 $contenu="";
640 $contenu[0][0]="parcelle_lot";// table
641 $contenu[0][1]="lotissement"; // zone origine
642 $contenu[1][0]="parcelle_lot";
643 $contenu[1][1]="parcelle_lot";
644 $form->setSelect("parcelle_lot_lotissement",$contenu);
645 // accord tacite
646 $contenu=array();
647 $contenu[0]=array('Non','Oui');
648 $contenu[1]=array('Non','Oui');
649 $form->setSelect("accord_tacite",$contenu);
650 // terrain_numero_complement
651 $contenu=array();
652 $contenu[0]=array('','bis','ter','quater');
653 $contenu[1]=array('','bis','ter','quater');
654 $form->setSelect("terrain_numero_complement",$contenu);
655 // geom *** a voir
656 if($maj==1){ //modification
657 $contenu=array();
658 $contenu[0]=array("dossier",$this->getParameter("idx"));
659 $form->setSelect('geom',$contenu);
660 }
661 // arrondissement recherche anvancée
662 $this->init_select($form, $db, $maj, $debug, "arrondissement",
663 $sql_arrondissement, $sql_arrondissement_by_id, false);
664 // dossier_autorisation_type_detaille recherche anvancée
665 $this->init_select($form, $db, $maj, $debug, "dossier_autorisation_type_detaille",
666 $sql_dossier_autorisation_type_detaille, $sql_dossier_autorisation_type_detaille_by_id, false);
667 /*
668 * Affichage de données dans le select de la parcelle
669 * */
670 $contenu=array();
671 $sql="select parcelle from ".DB_PREFIXE."parcelle ";
672 $res = $db->query($sql);
673 if (database::isError($res))
674 die($res->getMessage());
675 $contenu[0][0]="";
676 $contenu[1][0]=_("choisir parcelle");
677 $k=1;
678 while ($row=& $res->fetchRow()){
679 $contenu[0][$k]=$row[0];
680 $contenu[1][$k]=$row[0];
681 $k++;
682 }
683 $form->setSelect("parcelle",$contenu);
684
685 }
686 if($this->f->getParameter('afficher_division')==='true') {
687 // instructeur
688 $this->init_select($form, $db, $maj, $debug, "instructeur",
689 $sql_instructeur_div, $sql_instructeur_div_by_id, false);
690 }
691 }
692
693 function setLib(&$form,$maj) {
694 parent::setLib($form,$maj);
695 $form->setLib('geom','');
696 }
697
698 function setGroupe(&$form,$maj){
699 //If ($maj==0){
700 // $form->setGroupe('date_demande','D');
701 // $form->setGroupe('date_depot','G');
702 // $form->setGroupe('division','F');
703 //}else{
704 // $form->setGroupe('dossier','D');
705 // $form->setGroupe('annee','G');
706 // $form->setGroupe('date_demande','G');
707 // $form->setGroupe('date_depot','G');
708 // $form->setGroupe('division','F');
709 //}
710 $form->setGroupe('demandeur_categorie','D');
711 $form->setGroupe('demandeur_civilite','G');
712 $form->setGroupe('demandeur_nom','F');
713
714 $form->setGroupe('demandeur_societe','D');
715 $form->setGroupe('demandeur_adresse','G');
716 $form->setGroupe('demandeur_adresse_complement','F');
717
718 $form->setGroupe('demandeur_cp','D');
719 $form->setGroupe('demandeur_ville','G');
720 $form->setGroupe('demandeur_pays','F');
721
722 $form->setGroupe('demandeur_email','D');
723 $form->setGroupe('demandeur_telephone','F');
724
725 $form->setGroupe('delegataire','D');
726 $form->setGroupe('delegataire_civilite','G');
727 $form->setGroupe('delegataire_nom','F');
728
729 $form->setGroupe('delegataire_societe','D');
730 $form->setGroupe('delegataire_adresse','G');
731 $form->setGroupe('delegataire_adresse_complement','F');
732 $form->setGroupe('delegataire_cp','D');
733 $form->setGroupe('delegataire_ville','G');
734 $form->setGroupe('delegataire_pays','F');
735
736 $form->setGroupe('delegataire_email','D');
737 $form->setGroupe('delegataire_telephone','F');
738
739 $form->setGroupe('architecte','D');
740 $form->setGroupe('architecte_nom','F');
741 //$form->setGroupe('saisie_architecte','F');
742
743 $form->setGroupe('travaux','D');
744 $form->setGroupe('travaux_complement','F');
745
746 // terrain
747 $form->setGroupe('terrain_numero','D');
748 $form->setGroupe('terrain_numero_complement','G');
749 $form->setGroupe('rivoli','F');
750 $form->setGroupe('terrain_adresse','D');
751 $form->setGroupe('terrain_adresse_complement','F');
752
753 $form->setGroupe('terrain_cp','D');
754 $form->setGroupe('terrain_ville','F');
755
756 // surface
757 $form->setGroupe('terrain_surface','D');
758 $form->setGroupe('terrain_surface_calcul','F');
759
760 // instruction
761 $form->setGroupe('date_complet','D');
762 $form->setGroupe('date_rejet','G');
763 $form->setGroupe('rejet','G');
764 $form->setGroupe('delai','F');
765
766 $form->setGroupe('date_limite','D');
767 $form->setGroupe('date_notification_delai','G');
768 $form->setGroupe('accord_tacite','G');
769 $form->setGroupe('etat','F');
770
771 $form->setGroupe('date_decision','D');
772 $form->setGroupe('avis_decision','G');
773 $form->setGroupe('date_validite','G');
774 $form->setGroupe('types','F');
775
776 $form->setGroupe('date_chantier','D');
777 $form->setGroupe('date_achevement','G');
778 $form->setGroupe('date_conformite','F');
779
780 // localisation
781 $form->setGroupe('parcelle','D');
782 $form->setGroupe('pos','G');
783 if($maj==1){
784 $form->setGroupe('sig','G');
785 $form->setGroupe('geom','F');
786 }else {
787 $form->setGroupe('sig','F');
788 }
789 if($maj==1){
790 $form->setGroupe('sig','G');
791 $form->setGroupe('geom','F');
792 }
793
794 // description
795 $form->setGroupe('batiment_nombre','D');
796 $form->setGroupe('logement_nombre','G');
797 $form->setGroupe('hauteur','G');
798 $form->setGroupe('piece_nombre','F');
799
800 $form->setGroupe('shon','D');
801 $form->setGroupe('shon_calcul','G');
802 $form->setGroupe('shob','G');
803 $form->setGroupe('lot','F');
804
805 $form->setGroupe('amenagement','D');
806 $form->setGroupe('parcelle_lot','G');
807 $form->setGroupe('parcelle_lot_lotissement','F');
808 }
809
810 function setOnchange(&$form,$maj){
811 parent::setOnchange($form,$maj);
812 // mise en majuscule
813 $form->setOnchange("demandeur_nom","this.value=this.value.toUpperCase()");
814 $form->setOnchange("demandeur_societe","this.value=this.value.toUpperCase()");
815 $form->setOnchange("delegataire_nom","this.value=this.value.toUpperCase()");
816 $form->setOnchange("delegataire_societe","this.value=this.value.toUpperCase()");
817 $form->setOnchange("architecte_nom","this.value=this.value.toUpperCase()");
818 $form->setOnchange("terrain_adresse","this.value=this.value.toUpperCase()");
819 $form->setOnchange('shon','VerifNumdec(this)');
820 $form->setOnchange('shob','VerifNumdec(this)');
821 $form->setOnchange('hauteur','VerifNumdec(this)');
822 $form->setOnchange('terrain_surface','VerifNumdec(this)');
823 }
824
825 function setLayout(&$form, $maj) {
826 //
827 $form->setBloc('dossier', 'D', '', ($maj == 3 ? 'col_9':'col_12'));
828 $form->setBloc('dossier', 'D', '', 'col_9');
829 $form->setFieldset('dossier', 'D', _("Dossier d'instruction"));
830 $form->setFieldset('autorite_competente', 'F');
831 $form->setBloc('autorite_competente', 'F');
832 $form->setBloc('date_demande', 'D', '', 'col_3');
833 $form->setFieldset('date_demande', 'D', _("Depot"));
834 $form->setFieldset('date_depot', 'F');
835 $form->setFieldset('enjeu_urba', 'D', _("Enjeu"));
836 $form->setFieldset('enjeu_erp', 'F');
837 $form->setBloc('enjeu_erp', 'F');
838 $form->setBloc('enjeu_erp', 'F');
839 //
840 $form->setBloc('objet_dossier', 'D', '', 'col_12');
841 //
842 $form->setFieldset('date_complet', 'D', _('Instruction'), 'col_12');
843 $form->setRegroupe('date_conformite','F','');
844 //
845 $form->setBloc('terrain_superficie', 'F');
846
847 }
848
849 function setRegroupe(&$form,$maj) {
850 //// depot
851 //If ($maj==0){
852 // $form->setRegroupe('date_demande','D',_("Depot"),$this->aff_depot );
853 //}
854 //If ($maj==1){
855 // $form->setRegroupe('dossier','D',_("Depot"), $this->aff_depot);
856 // $form->setRegroupe('date_demande','G','');
857 //}
858 //$form->setRegroupe('date_depot','G','');
859 //$form->setRegroupe('division','F','');
860
861 // travaux
862 $form->setRegroupe('architecte','D',_('Architecte')." / "._("Travaux"), $this->aff_travaux);
863 $form->setRegroupe('architecte_nom','G','');
864 $form->setRegroupe('travaux','G','');
865 $form->setRegroupe('travaux_complement','F','');
866
867 //// instruction
868 //$form->setRegroupe('date_complet','D',_('Instruction'), $this->aff_instruction);
869 //$form->setRegroupe('date_rejet','G','');
870 //$form->setRegroupe('date_notification_delai','G','');
871 //$form->setRegroupe('delai','G','');
872 //$form->setRegroupe('date_limite','G','Decision ');
873 //$form->setRegroupe('accord_tacite','G','');
874 //$form->setRegroupe('etat','G','');
875 //$form->setRegroupe('date_decision','G','');
876 //$form->setRegroupe('avis_decision','G','');
877 //$form->setRegroupe('date_validite','G','');
878 //$form->setRegroupe('types','G','');
879 //$form->setRegroupe('date_chantier','G','');
880 //$form->setRegroupe('date_achevement','G','');
881 //$form->setRegroupe('date_conformite','F','');
882
883 // demandeur
884 $form->setRegroupe('demandeur_categorie','D',_('Demandeur'), $this->aff_demandeur);
885 $form->setRegroupe('demandeur_civilite','G','');
886 $form->setRegroupe('demandeur_nom','G','');
887 $form->setRegroupe('demandeur_societe','G','');
888 $form->setRegroupe('demandeur_adresse','G','Decision ');
889 $form->setRegroupe('demandeur_cp','G','');
890 $form->setRegroupe('demandeur_ville','G','');
891 $form->setRegroupe('demandeur_pays','G','');
892 $form->setRegroupe('demandeur_email','G','');
893 $form->setRegroupe('demandeur_telephone','F','');
894
895
896 // delegataire
897 $form->setRegroupe('delegataire','D',_('delegataire'), $this->aff_delegataire);
898 $form->setRegroupe('delegataire_civilite','G','');
899 $form->setRegroupe('delegataire_nom','G','');
900 $form->setRegroupe('delegataire_societe','G','');
901 $form->setRegroupe('delegataire_adresse','G','Decision ');
902 $form->setRegroupe('delegataire_cp','G','');
903 $form->setRegroupe('delegataire_ville','G','');
904 $form->setRegroupe('delegataire_pays','G','');
905 $form->setRegroupe('delegataire_email','G','');
906 $form->setRegroupe('delegataire_telephone','F','');
907
908 // terrain
909 $form->setRegroupe('terrain_numero','D',_('terrain'), $this->aff_terrain);
910 $form->setRegroupe('terrain_numero_complement','G','');
911 $form->setRegroupe('rivoli','G','');
912 $form->setRegroupe('terrain_adresse','G','');
913 $form->setRegroupe('terrain_adresse_complement','G','');
914 $form->setRegroupe('terrain_cp','G','');
915 $form->setRegroupe('terrain_ville','G','');
916 $form->setRegroupe('terrain_surface','G',_('surface'),'');// $this->aff_surface);
917 $form->setRegroupe('terrain_surface_calcul','F','');
918
919 // localisation
920 $form->setRegroupe('parcelle','D',_('localisation'), $this->aff_localisation);
921 $form->setRegroupe('pos','G','');
922 $form->setRegroupe('sig','F','');
923 if($maj==1){
924 $form->setRegroupe('sig','G','');
925 $form->setRegroupe('geom','F','');
926 }
927
928 // description
929 $form->setRegroupe('batiment_nombre','D',_('statistique'), $this->aff_description);
930 $form->setRegroupe('logement_nombre','G','');
931 $form->setRegroupe('hauteur','G','');
932 $form->setRegroupe('piece_nombre','G','');
933 $form->setRegroupe('shon','G','');
934 $form->setRegroupe('shon_calcul','G','');
935 $form->setRegroupe('shob','G','');
936 $form->setRegroupe('lot','F','');
937
938 $form->setRegroupe('description','D',_('description').' '._('servitude'), $this->aff_amenagement);
939 $form->setRegroupe('servitude','F','');
940
941 // amenagement
942 $form->setRegroupe('amenagement','D',_('Amenagement'), $this->aff_amenagement);
943 $form->setRegroupe('parcelle_lot','G','');
944 $form->setRegroupe('parcelle_lot_lotissement','F','');
945
946 }
947
948 /* =============================================================
949 * fonction trigger relative a la connexion SIG
950 * $sig = 1 dans dyn/var.inc
951 * utilisé aussi pour envoyer une message au service REST d'ERP
952 * ===============================================================
953 */
954
955 function triggerajouterapres($id,&$db,$val,$DEBUG) {
956 $this->sig_parametre($db);
957 $id=$this->valF['dossier']; // id n est pas valorise en ajout
958 if($this->sig==1 and $val['sig']!='Oui'){
959 if($val['parcelle']!=''or $val['parcelle_lot']!=''){
960
961 $this->sig_interne($id,$db,$val,$DEBUG);
962 }
963 else
964 $this->addToMessage("<br>"._("Parcelle non renseignee dans dossier")." ".$id." <br>");
965
966 }
967
968
969 if ($this->f->getParameter('option_erp') != "") {
970 // envoi du message a ERP en cas d'un depot du dossier dat
971 if ($this->getDATDCode($this->valF['dossier']) ==
972 $this->f->getParameter('erp_depot_dossier_dat')) {
973 $msgenque = new MessageEnqueuer();
974 $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
975 $msgenque->enqueueMessage($msgenque::$ERP_DEPOT_DOSSIER_DAT);
976 }
977
978 // envoi du message a ERP en cas d'une demande d'ouverture DAT
979 if ($this->getDATDCode($this->valF['dossier']) ==
980 $this->f->getParameter('erp_demande_ouverture_dat')) {
981 $msgenque = new MessageEnqueuer();
982 $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
983 $msgenque->enqueueMessage($msgenque::$ERP_DEMANDE_OUVERTURE_DAT);
984 }
985
986 if ($this->valF['erp'] === true) {
987 // envoi du message a ERP en cas d'annulation d'une demande
988 if ($this->getDATDCode($this->valF['dossier']) ==
989 $this->f->getParameter('erp_annulation_demande')) {
990 $msgenque = new MessageEnqueuer();
991 $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
992 $msgenque->enqueueMessage($msgenque::$ERP_ANNULATION_DEMANDE);
993 }
994
995 // envoi du message a ERP en cas d'ouverture d'un dossier PC "rattache"
996 // au dossier DAACT
997 if ($this->getDATDCode($this->valF['dossier']) ==
998 $this->f->getParameter('erp_demande_ouverture_pc_daact')) {
999 $msgenque = new MessageEnqueuer();
1000 $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
1001 $msgenque->enqueueMessage($msgenque::$ERP_DEMANDE_OUVERTURE_PC);
1002 }
1003 }
1004 } // fin de if ($this->f->getParameter('option_erp') != "")
1005 }
1006
1007 /*
1008 * Calcul l'identifiant du quartier et d'un arrondissement d'une parcelle
1009 * */
1010 function getQuartierArrondissement($parcelle) {
1011
1012 $parcelle = trim($parcelle);
1013 $quartier = '';
1014
1015 /*Récupère le code impot du quartier dans la parcelle*/
1016 for ( $i = 0 ; $i < strlen($parcelle) ; $i++ ){
1017
1018 if (is_numeric($parcelle[$i]) ){
1019
1020 $quartier .= $parcelle[$i];
1021 }
1022 else{
1023
1024 break;
1025 }
1026 }
1027
1028 if ( $quartier !== '' ){
1029
1030 /*identifiant*/
1031 $sql = "SELECT
1032 quartier, arrondissement
1033 FROM
1034 ".DB_PREFIXE."quartier
1035 WHERE
1036 code_impots='$quartier'";
1037
1038 $this->addToLog("getQuartierArrondissement(parcelle) : db->query(\"$sql\")", VERBOSE_MODE);
1039 $res = $this->db->query($sql);
1040 if (database :: isError($res))
1041 die($res->getMessage()."erreur ".$sql);
1042
1043 if ( $res->numRows() > 0 ){
1044
1045 return $res->fetchRow(DB_FETCHMODE_ASSOC);
1046 }
1047 }
1048
1049 return NULL;
1050 }
1051
1052 /*
1053 * Retourne la section d'une parcelle
1054 * */
1055 function getSection($parcelle){
1056
1057 $parcelle = trim($parcelle);
1058 $section = NULL;
1059
1060 for ( $i = 0 ; $i < strlen($parcelle) ; $i++ )
1061 if ( !is_numeric($parcelle[$i]) && is_string($parcelle[$i]) && $parcelle[$i] !== ' ' )
1062 $section .= $parcelle[$i];
1063
1064 return $section;
1065 }
1066
1067 /*
1068 * Retourne l'intructeur correspondant le mieux à la parcelle
1069 * */
1070 function getInstructeurDivision( $quartier, $arrondissement, $section, $dossier_autorisation) {
1071
1072 $quartier = ( $quartier == NULL ) ? -1 : $quartier;
1073 $arrondissement = ( $arrondissement == NULL ) ? -1 : $arrondissement;
1074
1075 /*Récupération du dossier_autorisation_type_detaille concerné par le $dossier_autorisation*/
1076 $sql = "
1077 SELECT
1078 dossier_autorisation_type_detaille
1079 FROM
1080 ".DB_PREFIXE."dossier_autorisation
1081 WHERE
1082 dossier_autorisation = '$dossier_autorisation'";
1083
1084 $this->addToLog("getInstructeurDivision : db->query(\"$sql\")", VERBOSE_MODE);
1085 $resDATD = $this->db->query($sql);
1086 if (database :: isError($resDATD))
1087 die($resDATD->getMessage()."erreur ".$sql);
1088
1089 if ( $resDATD->numRows() > 0 ){
1090 $rowDATD = $resDATD->fetchRow(DB_FETCHMODE_ASSOC);
1091
1092 $sql = "
1093 SELECT
1094 instructeur, section, quartier, arrondissement, dossier_autorisation_type_detaille
1095 FROM
1096 ".DB_PREFIXE."affectation_automatique l
1097 WHERE
1098 ( dossier_autorisation_type_detaille IS NULL AND arrondissement IS NULL AND quartier IS NULL AND section IS NULL ) OR
1099 ( dossier_autorisation_type_detaille IS NULL AND arrondissement IS NULL AND quartier IS NULL AND section = '$section' ) OR
1100 ( dossier_autorisation_type_detaille IS NULL AND arrondissement IS NULL AND quartier = $quartier AND section IS NULL ) OR
1101 ( dossier_autorisation_type_detaille IS NULL AND arrondissement IS NULL AND quartier = $quartier AND section = '$section' ) OR
1102 ( dossier_autorisation_type_detaille IS NULL AND arrondissement = $arrondissement AND quartier IS NULL AND section IS NULL ) OR
1103 ( dossier_autorisation_type_detaille IS NULL AND arrondissement = $arrondissement AND quartier IS NULL AND section = '$section' ) OR
1104 ( dossier_autorisation_type_detaille IS NULL AND arrondissement = $arrondissement AND quartier = $quartier AND section IS NULL ) OR
1105 ( dossier_autorisation_type_detaille IS NULL AND arrondissement = $arrondissement AND quartier = $quartier AND section = '$section' ) OR
1106 ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement IS NULL AND quartier IS NULL AND section IS NULL ) OR
1107 ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement IS NULL AND quartier IS NULL AND section = '$section' ) OR
1108 ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement IS NULL AND quartier = $quartier AND section IS NULL ) OR
1109 ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement IS NULL AND quartier = $quartier AND section = '$section' ) OR
1110 ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement = $arrondissement AND quartier IS NULL AND section IS NULL ) OR
1111 ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement = $arrondissement AND quartier IS NULL AND section = '$section' ) OR
1112 ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement = $arrondissement AND quartier = $quartier AND section IS NULL ) OR
1113 ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement = $arrondissement AND quartier = $quartier AND section = '$section' )
1114 ORDER BY section, quartier, arrondissement, dossier_autorisation_type_detaille
1115 LIMIT 1
1116 ";
1117
1118 $this->addToLog("getInstructeurDivision : db->query(\"$sql\")", VERBOSE_MODE);
1119 $res = $this->db->query($sql);
1120 if (database :: isError($res))
1121 die($res->getMessage()."erreur ".$sql);
1122
1123 if ( $res->numRows() > 0 ){
1124
1125 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1126
1127 $sql = "SELECT division FROM ".DB_PREFIXE."instructeur WHERE instructeur = ".$row['instructeur'];
1128 $res = $this->db->query($sql);
1129 if (database :: isError($res))
1130 die($res->getMessage()."erreur ".$sql);
1131
1132 if ( $res->numRows() > 0 ){
1133
1134 $rowT=& $res->fetchRow(DB_FETCHMODE_ASSOC);
1135 $row['division'] = $rowT['division'];
1136 }
1137
1138 return $row;
1139 }
1140 }
1141
1142 return NULL;
1143 }
1144
1145 /* =============================================================
1146 * fonction trigger relative a la connexion SIG
1147 * $sig = 1 dans dyn/var.inc
1148 * ===============================================================
1149 */
1150
1151 function triggerajouter($id,&$db,$val,$DEBUG) {
1152 //
1153 $this->addToLog("triggerajouter() : start", EXTRA_VERBOSE_MODE);
1154
1155 // Initialisation des variables nécessaires à l'affectation automatique
1156 $quartier = NULL;
1157 $arrondissement = NULL;
1158 $section = NULL;
1159 $instructeur = NULL;
1160
1161 // Si la parcelle n'est pas vide alors on récupère la section, le
1162 // quartier et l'arrondissement
1163 if ($val['parcelle'] != '') {
1164 // Cette méthode récupère l'arrondissement et le quartier associé à une parcelle
1165 $quartierArrondissement = $this->getQuartierArrondissement($val['parcelle']);
1166 if ( $quartierArrondissement!= NULL ){
1167
1168 $quartier = $quartierArrondissement['quartier'];
1169 $arrondissement = $quartierArrondissement['arrondissement'];
1170 }
1171 // Si il n'y a pas d'arrondissement alors on vide le quartier
1172 if ( strcmp($arrondissement,'') == 0 ) {
1173
1174 $arrondissement = NULL;
1175 $quartier = NULL;
1176 }
1177 // On récupère la section
1178 $section = $this->getSection($val['parcelle']);
1179 }
1180
1181 // Si aucun instructeur n'est saisi et que la dossier_autorisation_type_detaille n'est pas vide
1182 // alors on récupère l'instructeur et la division depuis l'affectation
1183 if ( ( empty($this->valF['instructeur']) || $this->valF['instructeur'] == '' ) && $val['dossier_autorisation'] != '' ) {
1184
1185 //
1186 $instructeurDivision = $this->getInstructeurDivision($quartier, $arrondissement, $section, $val['dossier_autorisation']);
1187 if ( $instructeurDivision != NULL ){
1188
1189 $instructeur = $instructeurDivision['instructeur'];
1190 $division = $instructeurDivision['division'];
1191 }
1192
1193 if ( $instructeur != NULL ){
1194
1195 $this->valF['instructeur'] = $instructeur;
1196 $this->valF['division'] = $division;
1197 } else {
1198 if ($this->f->isAccredited("dossier_modifier_instructeur")) {
1199 $this->addToMessage("<br/> "._("Pensez a assigner un instructeur a ce dossier.")." <br/>");
1200 } else {
1201 $this->addToMessage("<br/> "._("Aucun instructeur compatible avec ce dossier trouve, contactez votre administrateur afin d'en assigner un a ce dossier.")." <br/>");
1202 }
1203 }
1204 } else {
1205 $this->addToMessage("<br/> "._("Aucun instructeur compatible avec ce dossier trouve, contactez votre administrateur afin d'en assigner un a ce dossier.")." <br/>");
1206 }
1207 //
1208 $this->addToLog("triggerajouter() : end", EXTRA_VERBOSE_MODE);
1209 }
1210
1211 function triggermodifierapres($id,&$db,$val,$DEBUG) {
1212 $this->sig_parametre($db);
1213 // si la parcelle est changée
1214 if(($this->sig==1 and $val['sig']!='Oui' and ($val['parcelle']!=$val['parcelle_archive'])
1215 or $val['parcelle_lot']!=$val['parcelle_lot_archive'])){ // parcelle_lot_archive
1216 if($val['parcelle']!='' or $val['parcelle_lot']!='')
1217 $this->sig_interne($this->valF['dossier'],$db,$val,$DEBUG);
1218 else{
1219 if($this->maj ==1){ // en maj mettre a null la geometrie si parcelle changée inexistante
1220 $sql ="update ".DB_PREFIXE."dossier set geom = null, servitude = '', pos= '' where dossier ='".$id."'";
1221 $res = $db -> query($sql);
1222 $this->addToLog("requete trigger modifier parcelle vide -> maj pos et servitude :".$sql, VERBOSE_MODE);
1223 if (database :: isError($res))
1224 die($res->getMessage()."erreur ".$sql);
1225 }
1226 $this->addToMessage("<br>"._("Parcelle ou parcelle_lot non renseignee dans dossier")." ".$id." <br>");
1227 }
1228 }
1229
1230 // verification si envoi vers ERP est active
1231 if ($this->f->getParameter('option_erp') != "") {
1232 if ($this->val[array_search('a_qualifier', $this->champs)] == 't'
1233 && $this->valF['a_qualifier'] === false) {
1234
1235 // envoi du message "ERP Qualifie" pour un dossier DAT qui a besoin
1236 // de la qualification URBA
1237 if ($this->getDATDCode($this->valF['dossier']) ==
1238 $this->f->getParameter('erp_nature_dat')) {
1239 $msgenque = new MessageEnqueuer();
1240 $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
1241 $msgenque->setCompetence($this->valF['autorite_competente']);
1242 $msgenque->setContraintePlu($this->valF['servitude']);
1243 $msgenque->setReferenceCadastrale(
1244 $this->getReferenceCadastrale($this->valF['dossier']));
1245 $msgenque->enqueueMessage($msgenque::$ERP_QUALIFIE);
1246 }
1247
1248 // envoi des messages a ERP en cas du dossier PC traite par URBA, et
1249 // qui etait classifie come ERP
1250 if ($this->getDATDCode($this->valF['dossier']) ==
1251 $this->f->getParameter('erp_dossier_nature_pc')
1252 && $this->valF['erp'] == true) {
1253 $msgenque = new MessageEnqueuer();
1254 $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
1255 $msgenque->enqueueMessage($msgenque::$ERP_DEMANDE_COMPLETUDE_PC);
1256 $msgenque->enqueueMessage($msgenque::$ERP_DEMANDE_QUALIFICATION_PC);
1257 }
1258 }
1259 } // fin de if($this->f->getParameter('option_erp'))
1260 }
1261
1262 /**
1263 * Retourne le type de dossier d'autorisation du dossier courant :
1264 * - dossier_autorisation_type_detaille.code
1265 **/
1266 function getDATDCode($idxDossier) {
1267 $sql = "SELECT dossier_autorisation_type_detaille.code
1268 FROM ".DB_PREFIXE."dossier_autorisation_type_detaille
1269 INNER JOIN ".DB_PREFIXE."dossier_autorisation
1270 ON dossier_autorisation_type_detaille.dossier_autorisation_type_detaille =
1271 dossier_autorisation.dossier_autorisation_type_detaille
1272 INNER JOIN ".DB_PREFIXE."dossier ON dossier.dossier_autorisation = dossier_autorisaiton.dossier_autorisation
1273 WHERE dossier.dossier = ".$idxDossier;
1274 $res = $db -> getOne($sql);
1275 $this->f->isDatabaseError();
1276 return $res;
1277 }
1278
1279
1280 /**
1281 * Retourne la reference cadastrale de la demande attache a un dossier ERP
1282 * specifique
1283 * @param string $dossier L'identifiant du dossier
1284 * @return string|null La reference cadastrale si elle est trouve,
1285 * sinon NULL. En cas d'erreur de la BD, l'execution s'arrete.
1286 */
1287 function getReferenceCadastrale($dossier) {
1288 $sql = "SELECT terrain_references_cadastrales FROM ".DB_PREFIXE."demande WHERE dossier_instruction = '" . $dossier . "'";
1289 $res = $this->db->limitquery($sql, 0, 1);
1290 $this->addToLog("getReferenceCadastrale(): db->limitquery(\"".
1291 str_replace(",",", ",$sql)."\", 0, 1);", VERBOSE_MODE);
1292 // Si une erreur survient on die
1293 if (database::isError($res, true)) {
1294 // Appel de la methode de recuperation des erreurs
1295 $this->erreur_db($res->getDebugInfo(), $res->getMessage(), 'demande');
1296 }
1297 // retourne la nature du dossier
1298 while ($row =& $res->fetchRow()) {
1299 return $row[0];
1300 }
1301 // la nature n'etait pas trouve, ce qui ne devrait pas se passer
1302 return NULL;
1303 }
1304
1305
1306 function sig_parametre(&$db){
1307 if (file_exists ("../dyn/var.inc"))
1308 include ("../dyn/var.inc");
1309 if(!isset($sig))
1310 $this->sig=0;
1311 else
1312 $this->sig=1;
1313 if(!isset($auto_pos))
1314 $this->auto_pos=0;
1315 else
1316 $this->auto_pos=$auto_pos;
1317 if(!isset($auto_servitude_surfacique))
1318 $this->auto_servitude_surfacique=0;
1319 else
1320 $this->auto_servitude_surfacique=$auto_servitude_surfacique;
1321 if(!isset($auto_servitude_ligne))
1322 $this->auto_servitude_ligne=0;
1323 else
1324 $this->auto_servitude_ligne=$auto_servitude_ligne;
1325 if(!isset($auto_servitude_point))
1326 $this->auto_servitude_point=0;
1327 else
1328 $this->auto_servitude_point=$auto_servitude_point;
1329 if(!isset($auto_parcelle))
1330 $this->auto_parcelle=0;
1331 else
1332 $this->auto_parcelle=$auto_parcelle;
1333 if(!isset($auto_parcelle_lot))
1334 $this->auto_parcelle_lot=0;
1335 else
1336 $this->auto_parcelle_lot=$auto_parcelle_lot;
1337 $this->addToLog("trigger valeur sig :".$this->sig, VERBOSE_MODE);
1338 $this->addToLog("trigger valeur auto_pos :". $this->auto_pos, VERBOSE_MODE);
1339 $this->addToLog("trigger valeur auto_servitude_surfacique :".$this->auto_servitude_surfacique, VERBOSE_MODE);
1340 $this->addToLog("trigger valeur auto_servitude_ligne :". $this->auto_servitude_ligne, VERBOSE_MODE);
1341 $this->addToLog("trigger valeur auto_servitude_point :".$this->auto_servitude_point, VERBOSE_MODE);
1342 $this->addToLog("trigger valeur auto_parcelle :". $this->auto_parcelle, VERBOSE_MODE);
1343 $this->addToLog("trigger valeur auto_parcelle_lot :".$this->auto_parcelle_lot, VERBOSE_MODE);
1344 }
1345
1346
1347 function sig_interne($id,&$db,$val,$DEBUG){
1348 // Strategy interne dans var.inc
1349 // si la parcelle existe, il est cree un point au milieu de la parcelle
1350 // de maniere automatique
1351 $geom='';
1352 $parcelle=$val["parcelle"];
1353 $projection = $db -> getOne("select srid from geometry_columns where f_table_name='dossier'");
1354 if($this->auto_parcelle==1 and $val["parcelle"]!=''){
1355 $sql= "select astext(centroid(geom)) from ".DB_PREFIXE."parcelle where parcelle ='".$val["parcelle"]."'";
1356 $this->addToLog("recherche centroid parcelle :".$sql, VERBOSE_MODE);
1357 $geom = $db -> getOne($sql);
1358 if (database :: isError($geom))die($res->getMessage()."erreur ".$sql);
1359 }
1360 if($geom=='' and $this->auto_parcelle_lot==1 and $val["parcelle_lot"]!=''){ // lot
1361 $sql= "select astext(centroid(geom)) from ".DB_PREFIXE."parcelle_lot where parcelle_lot ='".$val["parcelle_lot"]."'";
1362 $this->addToLog("recherche centroid parcelle lot :".$sql, VERBOSE_MODE);
1363 $geom = $db -> getOne($sql);
1364 if (database :: isError($geom))die($res->getMessage()."erreur ".$sql);
1365 $parcelle=$val["parcelle_lot"]." ".$val["parcelle_lot_lotissement"];
1366 }
1367 if($geom!=''){ // la parcelle est exitante dans la table ou vue parcelle
1368 $sql ="update ".DB_PREFIXE."dossier set geom =geometryfromtext('".$geom."', ".$projection." ) where dossier ='".$id."'";
1369 $this->addToLog("sig_interne maj geom :".$sql, VERBOSE_MODE);
1370 $res = $db -> query($sql);
1371 if (database :: isError($res)) die($res->getMessage()."erreur ".$sql);
1372 $this->addToMessage(""._("centroid de parcelle calcule")." ".$parcelle." ");
1373 if($this->auto_pos==1) // recherche du pos
1374 $this->calcul_auto_pos($id,$db,$geom,$projection);
1375 if($this->auto_servitude_surfacique==1) // recherche de servitude surfacique
1376 $this->calcul_auto_servitude_surfacique($id,$db,$geom,$projection);
1377 if($this->auto_servitude_ligne==1) // recherche de servitude ligne
1378 $this->calcul_auto_servitude_ligne($id,$db,$geom,$projection);
1379 if($this->auto_servitude_point==1) // recherche de servitude point
1380 $this->calcul_auto_servitude_point($id,$db,$geom,$projection);
1381 $temp=strtr($this->servitude,"'"," "); // enleve le '
1382 $sql1 ="update ".DB_PREFIXE."dossier set servitude = '".$temp."' where dossier = '".$id."'";
1383 $res1 = $db -> query($sql1);
1384 $this->addToLog("maj servitudes :".$sql1, VERBOSE_MODE);
1385 if (database:: isError($res1)) die($res1->getMessage()."erreur ".$sql1);
1386 }else{ // parcelle inexistante //***
1387 if($this->maj ==1){ // en maj mettre a null la geometrie si parcelle changée inexistante
1388 $sql ="update ".DB_PREFIXE."dossier set geom = null, servitude = '', pos= '' where dossier ='".$id."'";
1389 $res = $db -> query($sql);
1390 $this->addToLog("requete sig_interne maj parcelle inexistante :".$sql, VERBOSE_MODE);
1391 if (database :: isError($res))
1392 die($res->getMessage()."erreur ".$sql);
1393 }
1394 //$this->addToMessage("<br> parcelle ".$parcelle." "._("inexistante")." ".$id."");
1395 }
1396 }
1397
1398 function calcul_auto_pos($id,&$db,$geom,$projection){
1399 // recherche du pos automatique
1400 $sql="select pos from ".DB_PREFIXE."pos WHERE ST_contains(geom, geometryfromtext('".$geom."', ".$projection."))";
1401 $pos = $db -> getOne($sql);
1402 $this->addToLog("recherche auto_pos :".$sql, VERBOSE_MODE);
1403 if($pos!=''){
1404 $sql1 ="update ".DB_PREFIXE."dossier set pos = '".$pos."' where dossier = '".$id."'";
1405 $res1 = $db -> query($sql1);
1406 $this->addToLog("maj auto_pos :".$sql1, VERBOSE_MODE);
1407 if (database:: isError($res1)) die($res1->getMessage()."erreur ".$sql1);
1408 $this->addToMessage("<br>"._("POS/PLU")." : ".$pos."");
1409 }else{
1410 $this->addToMessage("<br>"._("POS/PLU non trouve")." ".$id."");
1411 }
1412 }
1413
1414 function calcul_auto_servitude_surfacique($id,&$db,$geom,$projection){
1415 // recherche servitude surfacique
1416 $sql="select * from ".DB_PREFIXE."servitude_surfacique WHERE ST_contains(geom, geometryfromtext('".$geom."', ".$projection."))";
1417 $res=$db->query($sql);
1418 if (database:: isError($res)) die($res1->getMessage()."erreur ".$sql);
1419 $this->addToLog("requete :".$sql." executee ", VERBOSE_MODE);
1420 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
1421 $this->addToMessage("<br>"._("servitude")." : ".$row['libelle']." - ".$row['observation']);
1422 $this->servitude.=" [".$row['libelle']."] ".$row['observation']." - ";
1423 }
1424 }
1425
1426 function calcul_auto_servitude_ligne($id,&$db,$geom,$projection){
1427 // recherche servitude ligne
1428 $sql="select * from ".DB_PREFIXE."servitude_ligne WHERE ST_contains(ST_buffer(geom, perimetre), geometryfromtext('".$geom."', ".$projection."))";
1429 $res=$db->query($sql);
1430 if (database:: isError($res)) die($res1->getMessage()."erreur ".$sql);
1431 $this->addToLog("requete :".$sql." executee ", VERBOSE_MODE);
1432 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
1433 $this->addToMessage("<br>"._("servitude")." : ".$row['libelle']." - ".$row['observation']);
1434 $this->servitude.=" [".$row['libelle']."] ".$row['observation']." - ";
1435 }
1436 }
1437
1438 function calcul_auto_servitude_point($id,&$db,$geom,$projection){
1439 // recherche servitude point
1440 $sql="select libelle,observation, perimetre, distance(geom, geometryfromtext('".$geom."', ".$projection.")) as distance from ".
1441 DB_PREFIXE."servitude_point WHERE distance(geom, geometryfromtext('".$geom."', ".$projection."))<perimetre";
1442 $res=$db->query($sql);
1443 if (database:: isError($res)) die($res1->getMessage()."erreur ".$sql);
1444 $this->addToLog("requete :".$sql." executee ", VERBOSE_MODE);
1445 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
1446 $this->addToMessage("<br>"._("servitude")." : ".$row['libelle']." - ".$row['observation']." a ".round($row['distance'],2)." m ");
1447 $this->servitude.=" [".$row['libelle']."] ".$row['observation']." a ".round($row['distance'],2)." m - ";
1448 }
1449 }
1450 }// fin classe
1451 ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26