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

Diff of /trunk/obj/demande.class.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 693 by vpihour, Thu Nov 15 09:03:18 2012 UTC revision 1246 by nhaye, Wed Feb 13 10:19:51 2013 UTC
# Line 6  require_once ("../gen/obj/demande.class. Line 6  require_once ("../gen/obj/demande.class.
6    
7  class demande extends demande_gen {  class demande extends demande_gen {
8    
9        var $valIdDemandeur = array("petitionnaire_principal" => "",
10                                    "delegataire" => "",
11                                    "petitionnaire" => array());
12        var $postedIdDemandeur = array("petitionnaire_principal" => "",
13                                    "delegataire" => "",
14                                    "petitionnaire" => array());
15    
16      function demande($id,&$db,$debug) {      function demande($id,&$db,$debug) {
17          $this->constructeur($id,$db,$debug);          $this->constructeur($id,$db,$debug);
18      }// fin constructeur      }// fin constructeur
19    
20        function setValF($val) {
21            parent::setValF($val);
22            // Récupération des id demandeurs postés
23            $this->getPostedValues();
24            //$this->valIdDemandeur=$this->postedIdDemandeur;
25        }
26    
27        /**
28         * Méthode permettant de récupérer les valeurs du dossier d'autorisation
29         * correspondant à la nouvelle demande
30         */
31        function getValFromDossier($dossier_autorisation) {
32            include "../sql/pgsql/demande.form.inc.php";
33            $sql=str_replace("<idx>",$this->getParameter("idx_dossier"),
34                        $sql_infos_dossier);
35            $res = $this->db->query($sql);
36            $this->addToLog("demande -> getValFromDossier() : ".$sql);
37            $this->f->isDatabaseError();
38            $row = & $res->fetchRow(DB_FETCHMODE_ASSOC);
39            return $row;
40        }
41            
42       // =============================================       /*
43      // La date du jour par défaut dans le champs date_demande      * La date du jour par défaut dans le champs date_demande
44      // Put the date of the day by default into the field date_demande      * Put the date of the day by default into the field date_demande
45      // =============================================      */
46      function setVal(&$form, $maj, $validation, &$db) {      function setVal(&$form, $maj, $validation, &$db) {
47          if($maj == 0) {          if($maj == 0) {
48               $form->setVal("date_demande",date('d/m/Y'));              $form->setVal("date_demande",date('d/m/Y'));
49    
50                // Récupération des valeurs du dossier d'autorisation correspondant
51                if($this->getParameter("idx_dossier") != "") {
52                    $val_autorisation = $this->getValFromDossier(
53                                                $this->getParameter("idx_dossier"));
54                    foreach($val_autorisation as $champ => $value) {
55                        $form->setVal($champ,$value);
56                    }
57                }
58          }          }
59      }      }
60            
61      // =============================================      /**
62      // Ajout du fielset       * Méthode de verification du contenu
63      // Add fieldset       */
64      // =============================================      function verifier($val, &$db, $DEBUG) {
65            parent::verifier($val, $db, $DEBUG);
66            if(!isset($this->postedIdDemandeur["petitionnaire_principal"]) OR
67               empty($this->postedIdDemandeur["petitionnaire_principal"])) {
68                $this->correct = false;
69                $this->addToMessage("La saisie d'un petitionnaire principal est obligatoire.");
70            }
71        }
72        /*
73        * Ajout du fielset
74        * Add fieldset
75        */
76      function setLayout(&$form, $maj){      function setLayout(&$form, $maj){
77          if ( $maj < 2 OR $maj == 3 ) {          if ( $maj < 2 OR $maj == 3 ) {
78                            
79              //Champs sur lequel s'ouvre le fieldset              /*Champ sur lequel s'ouvre le bloc 1 */
80              $form->setBloc('dossier_autorisation_type_detaille','D',"", "dossier_type_demande_date col_9");              $form->setBloc('dossier_autorisation_type_detaille','D',"","dossier_type col_8");
81                  $form->setBloc('dossier_autorisation_type_detaille','D',"","dossier_type col_9");  
82                                    $form->setFieldset('dossier_autorisation_type_detaille','D'
83                      $form->setFieldset('dossier_autorisation_type_detaille','D',_('Type de dossier/demande'));                                     ,_('Type de dossier/demande'));
84                      $form->setFieldset('demande_type','F','');                  $form->setFieldset('demande_type','F','');
85                                
86                  $form->setBloc('demande_type','F');              $form->setBloc('demande_type','F');
87                                /*Fin bloc 1*/
88                  $form->setBloc('date_demande','D',"","col_3");              
89                      $form->setFieldset('date_demande','D',_('Date de la demande'));              /*Champ sur lequel s'ouvre le bloc 2 */
90                      $form->setFieldset('date_demande','F','');              $form->setBloc('date_demande','D',"","col_4 demande_hidden_bloc");
91                  $form->setBloc('date_demande','F');                  $form->setFieldset('date_demande','D',_('Date de la demande'));
92                    $form->setFieldset('date_demande','F','');
93              $form->setBloc('date_demande','F');              $form->setBloc('date_demande','F');
94                /*Fin bloc 2*/
95                            
96              $form->setBloc('terrain_references_cadastrales','D',"", "localisation col_12");              /*Champ sur lequel s'ouvre le bloc 3 */
97                $form->setBloc('terrain_references_cadastrales','D',"",
98                               "localisation col_12 demande_hidden_bloc");
99                  $form->setFieldset('terrain_references_cadastrales','D',_('Localisation du terrain'));                  $form->setFieldset('terrain_references_cadastrales','D',_('Localisation du terrain'));
100                  $form->setFieldset('terrain_superficie','F','');                  $form->setFieldset('terrain_superficie','F','');
101              $form->setBloc('terrain_superficie','F');              $form->setBloc('terrain_superficie','F');
102                /*Fin bloc 4*/
103                            
             $form->setBloc('nombre_lots','D',"","lots col_12");  
                 $form->setFieldset('nombre_lots','D',_('Nombre de lots'));  
                 $form->setFieldset('nombre_lots','F','');  
             $form->setBloc('nombre_lots','F');  
104          }          }
105      }      }
106    
107       // =============================================      /*
108      // Ajoute des actions sur les deux premiers select      * Ajoute des actions sur les deux premiers select
109      // Add actions on the two first select      * Add actions on the two first select
110      // =============================================      */
111      function setOnchange(&$form,$maj){      function setOnchange(&$form,$maj){
112          parent::setOnchange($form,$maj);          parent::setOnchange($form,$maj);
113          $form->setOnchange("dossier_autorisation_type_detaille","changeDemandeType();");          $form->setOnchange("dossier_autorisation_type_detaille","changeDemandeType();");
114          $form->setOnchange("demande_type","showFormsDemande();");          $form->setOnchange("demande_type","showFormsDemande();");
115      }      }
116            
117       // =============================================      /*
118      // Cache le champ terrain_references_cadastrales      * Cache le champ terrain_references_cadastrales
119      // Hide the fiels terrain_references_cadastrales      * Hide the fiels terrain_references_cadastrales
120      // =============================================      */
121      function setType(&$form,$maj) {      function setType(&$form,$maj) {
122          parent::setType($form,$maj);          parent::setType($form,$maj);
123                    
124          $form->setType('dossier_instruction', 'hidden');          $form->setType('dossier_instruction', 'hidden');
125          $form->setType('dossier_autorisation', 'hidden');          $form->setType('dossier_autorisation', 'hidden');
126    
127            $form->setType('instruction_recepisse', 'hidden');
128            $form->setType('arrondissement', 'hidden');
129    
130            // Si il s'agit d'une demande sur dossier existant on desactive tous les champs
131            // sauf demande_type
132            if(($maj == 0 AND $this-> getParameter("idx_dossier"))) {
133                $form->setType('dossier_autorisation_type_detaille', 'selecthiddenstatic');
134                $form->setType('terrain_references_cadastrales', 'hiddenstatic');
135                $form->setType('terrain_adresse_voie_numero', 'hiddenstatic');
136                $form->setType('complement', 'hiddenstatic');
137                $form->setType('terrain_adresse_lieu_dit', 'hiddenstatic');
138                $form->setType('terrain_adresse_localite', 'hiddenstatic');
139                $form->setType('terrain_adresse_code_postal', 'hiddenstatic');
140                $form->setType('terrain_adresse_bp', 'hiddenstatic');
141                $form->setType('terrain_adresse_cedex', 'hiddenstatic');
142                $form->setType('terrain_superficie', 'hiddenstatic');
143            }
144            if($maj == 1) {
145                $form->setType('dossier_autorisation_type_detaille', 'selecthiddenstatic');
146                $form->setType('demande_type', 'selecthiddenstatic');
147            }
148            if($maj == 3) {
149                $form->setType('terrain_references_cadastrales', 'referencescadastralesstatic');
150            }
151    
152        }
153    
154        /**
155         * Méthode permettant d'ajouter un dossier d'autorisation
156         */
157        function ajoutDossierAutorisation($id, &$db, $val, $DEBUG){
158            require_once '../obj/dossier_autorisation.class.php';
159            $dossier_autorisation = new dossier_autorisation("]",$db,$DEBUG);
160            // Création du dossier
161            foreach($dossier_autorisation->champs as $value) {
162                $valAuto[$value] = NULL;
163            }
164            $valAuto['dossier_autorisation']=NULL;
165            $valAuto['exercice']=NULL;
166            $valAuto['insee']=NULL;
167            $valAuto['arrondissement']=NULL;
168            $valAuto['etat']=NULL;
169            $valAuto['erp_numero_batiment']=NULL;
170            $valAuto['erp_ouvert']=NULL;
171            $valAuto['erp_arrete_decision']=NULL;
172            $valAuto['dossier_autorisation_type_detaille']=$this->valF['dossier_autorisation_type_detaille'];
173            $valAuto['depot_initial']=$this->valF['date_demande'];
174            $valAuto['terrain_references_cadastrales']=$this->valF['terrain_references_cadastrales'];
175            $valAuto['terrain_adresse_voie_numero']=$this->valF['terrain_adresse_voie_numero'];
176            $valAuto['complement']=$this->valF['complement'];
177            $valAuto['terrain_adresse_lieu_dit']=$this->valF['terrain_adresse_lieu_dit'];
178            $valAuto['terrain_adresse_localite']=$this->valF['terrain_adresse_localite'];
179            $valAuto['terrain_adresse_code_postal']=$this->valF['terrain_adresse_code_postal'];
180            $valAuto['terrain_adresse_bp']=$this->valF['terrain_adresse_bp'];
181            $valAuto['terrain_adresse_cedex']=$this->valF['terrain_adresse_cedex'];
182            $valAuto['terrain_superficie']=$this->valF['terrain_superficie'];
183            $valAuto['numero_version']=-1;
184            // Ajout du dossier dans la base
185            $dossier_autorisation->ajouter($valAuto, $db, $DEBUG);
186            // Liaison du dossier ajouter à la demande
187            $this->valF['dossier_autorisation'] = $dossier_autorisation->valF['dossier_autorisation'];
188        }
189    
190        /**
191         * Méthode permettant d'ajouter un dossier d'instruction
192         */
193        function ajoutDossierInstruction($id, &$db, $val, $DEBUG, $dossier_instruction_type){
194            require_once '../obj/dossier.class.php';
195            $dossier = new dossier("]",$db,$DEBUG);
196            foreach($dossier->champs as $value) {
197                $valInstr[$value] = NULL;
198            }
199            require_once '../obj/dossier_autorisation_type_detaille.class.php';
200            $datd = new dossier_autorisation_type_detaille(
201                    $this->valF['dossier_autorisation_type_detaille'],$db,$DEBUG);
202                    
203            /*Ajout de la variable dossier_instruction_type à l'objet dossier pour le
204             * versionning
205             */
206            $dossier->setDossierInstructionType($dossier_instruction_type);
207            
208            // Définition des valeurs à entrée dans la table
209            $valInstr['dossier_instruction_type']=$dossier_instruction_type;
210            $valInstr['date_depot']=$this->dateDBToForm($this->valF['date_demande']);
211            $valInstr['date_demande']=$this->dateDBToForm($this->valF['date_demande']);
212            $valInstr['depot_initial']=$this->dateDBToForm($this->valF['date_demande']);
213            $valInstr['terrain_references_cadastrales']=$this->valF['terrain_references_cadastrales'];
214            $valInstr['terrain_adresse_voie_numero']=$this->valF['terrain_adresse_voie_numero'];
215            $valInstr['complement']=$this->valF['complement'];
216            $valInstr['terrain_adresse_lieu_dit']=$this->valF['terrain_adresse_lieu_dit'];
217            $valInstr['terrain_adresse_localite']=$this->valF['terrain_adresse_localite'];
218            $valInstr['terrain_adresse_code_postal']=$this->valF['terrain_adresse_code_postal'];
219            $valInstr['terrain_adresse_bp']=$this->valF['terrain_adresse_bp'];
220            $valInstr['terrain_adresse_cedex']=$this->valF['terrain_adresse_cedex'];
221            $valInstr['terrain_superficie']=$this->valF['terrain_superficie'];
222            $valInstr['description']="";
223            $valInstr['dossier_autorisation']=$this->valF['dossier_autorisation'];
224            $dossier->ajouter($valInstr, $db, $DEBUG);
225            $this->f->isDatabaseError();
226            // Liaison du dossier ajouter à la demande
227            $this->valF['dossier_instruction'] = $dossier->valF['dossier'];
228        }
229    
230        /**
231         * Ajout des liens demandeurs / dossier d'autorisation
232         **/
233        function ajoutLiensDossierAutorisation($id, &$db, $val, $DEBUG) {
234            // Création des liens entre le dossier autorisation et les demandeurs
235            include '../sql/pgsql/demande.form.inc.php';
236            require_once '../obj/lien_dossier_autorisation_demandeur.class.php';
237            $ldad = new lien_dossier_autorisation_demandeur("]",$db,$DEBUG);
238            // Recupération des demandeurs liés à la demande
239            $sql = str_replace("<demande>",$this->valF['demande'],$sql_lien_demande_demandeur);
240            $res = $db->query($sql);
241            $this->f->addToLog("demande.class.php: db->query(\"".$sql."\");", VERBOSE_MODE);
242            $this->f->isDatabaseError();
243            while($row = &$res->fetchRow(DB_FETCHMODE_ASSOC)) {
244                $row['lien_dossier_autorisation_demandeur'] = NULL;
245                $row['dossier_autorisation'] = $this->valF['dossier_autorisation'];
246                $ldad->ajouter($row, $db, $DEBUG);
247            }
248        }
249    
250        /**
251         * Ajout des liens demandeurs / dossier d'autorisation
252         **/
253        function ajoutLiensDossierInstruction($id, &$db, $val, $DEBUG) {
254            // Création des liens entre le dossier instruction et les demandeurs
255            include '../sql/pgsql/demande.form.inc.php';
256            require_once '../obj/lien_dossier_demandeur.class.php';
257            $ldd = new lien_dossier_demandeur("]",$db,$DEBUG);
258            // Recupération des demandeurs liés à la demande
259            $sql = str_replace("<demande>",$this->valF['demande'],$sql_lien_demande_demandeur);
260            $res = $db->query($sql);
261            $this->f->addToLog("demande.class.php: db->query(\"".$sql."\");", VERBOSE_MODE);
262            $this->f->isDatabaseError();
263            while($row = &$res->fetchRow(DB_FETCHMODE_ASSOC)) {
264                $row['lien_dossier_demandeur'] = NULL;
265                $row['dossier'] = $this->valF['dossier_instruction'];
266                $ldd->ajouter($row, $db, $DEBUG);
267            }
268        }
269    
270        /*
271         * Récupère l'identifiant d'un arrondissement à partir d'un code postal
272         */
273        function getArrondissement($terrain_adresse_code_postal){
274            
275            $arrondissement = NULL;
276            
277            $sql = "SELECT
278                        arrondissement
279                    FROM
280                        ".DB_PREFIXE."arrondissement
281                    WHERE
282                        code_postal = '$terrain_adresse_code_postal' ";
283            $this->addToLog("demande.class.php : ".$sql." execute <br>", EXTRA_VERBOSE_MODE);
284            
285            $res = $this->db->query($sql);
286            $this->f->isDatabaseError($res);
287            
288            if( $res->numrows() > 0 ) {
289                
290                $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);
291                $arrondissement = $row['arrondissement'];
292            }
293            
294            return $arrondissement;
295      }      }
296            
297      // =============================================      /*
298      // Sous formulaire pour le pétitionnaire       * Récupère l'évènement lié à un type de demande
299      // Sub form for the 'petitionnaire'       */
300      // =============================================       function getEvenement($demande_type){
301      function sousformulaire($enteteTab, $validation, $maj, &$db, $postVar, $premiersf,          
302                  $DEBUG, $idx, $idxformulaire, $retourformulaire, $typeformulaire,           $evenement = NULL;
303                  $objsf, $tricolsf, $retour= "", $actions = array()){          
304             $sql =
305                "SELECT
306                    evenement
307                FROM
308                    ".DB_PREFIXE."demande_type
309                WHERE
310                    demande_type = $demande_type";
311                
312            $res = $this->db->query($sql);
313            $this->f->isDatabaseError($res);
314            
315            if ( $res->numrows() > 0 ){
316                    
317                $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);
318                $evenement = $row['evenement'];
319            }
320            
321            return $evenement;
322         }
323        
324         /*
325         * Récupère la lettre type lié à un événement
326         */
327         function getLettreType($evenement){
328            
329             $lettretype = NULL;
330            
331             $sql =
332                "SELECT
333                    lettretype
334                FROM
335                    ".DB_PREFIXE."evenement
336                WHERE
337                    evenement = $evenement";
338                
339            $res = $this->db->query($sql);
340            $this->f->isDatabaseError($res);
341            
342            if ( $res->numrows() > 0 ){
343                    
344                $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);
345                $lettretype = $row['lettretype'];
346            }
347            
348            return $lettretype;
349         }
350        
351        /**
352         * Ajout des dossiers
353         **/
354        function triggerAjouter($id, &$db, $val, $DEBUG){
355            include '../sql/pgsql/demande.form.inc.php';
356            if($this->valF["demande_type"] != NULL) {
357                $res = $db->query(str_replace('<idx>', $this->valF['demande_type'], $sql_demande_type_details_by_id));
358                $this->f->isDatabaseError();
359                $dossier_type = $res->fetchRow(DB_FETCHMODE_ASSOC);
360                // Création du dossier_autorisation
361                if($this->valF['dossier_autorisation'] == "") {
362                    $this->ajoutDossierAutorisation($id, $db, $val, $DEBUG);
363                    $this -> addToMessage(_("Creation du dossier d'autorisation no").$this->valF['dossier_autorisation']);
364                }
365                // Création du dossier d'instruction
366                if($dossier_type['dossier_instruction_type'] != NULL) {
367                    $this->ajoutDossierInstruction($id, $db, $val, $DEBUG, $dossier_type['dossier_instruction_type']);
368                    $this -> addToMessage(_("Creation du dossier d'instruction no").$this->valF['dossier_instruction']);
369                }
370                
371                /*Création du lien de téléchargement de récépissé de demande*/
372                if ( $this->valF['demande_type'] != "" && is_numeric($this->valF['demande_type'])
373                    && isset($this->valF['dossier_instruction']) && $this->valF['dossier_instruction'] !== "" ){
374                
375                    /*Récupérer l'événement lié à ce type de demande*/
376                    $evenement = $this->getEvenement($this->valF['demande_type']);
377                                    
378                    /*Récupération de la lettre type de l'événement*/
379                    $lettretype = $this->getLettreType($evenement);
380                    
381                    /*Création d'une nouvelle instruction avec cet événement*/
382                    /*Données*/
383                    $valInstr['instruction']=NULL;
384                    
385                    $valInstr['destinataire']=$this->valF['dossier_instruction'];
386                    $valInstr['dossier']=$this->valF['dossier_instruction'];
387                    
388                    $valInstr['date_evenement']=date("d/m/Y");
389                    $valInstr['evenement']=$evenement;
390                    $valInstr['lettretype']=$lettretype;
391                    $valInstr['complement']="";
392                    $valInstr['complement2']="";
393                    
394                    $valInstr['action']="initialisation";
395                    $valInstr['delai']="2";
396                    $valInstr['etat']="notifier";
397                    $valInstr['accord_tacite']="Oui";
398                    $valInstr['delai_notification']="1";
399                    $valInstr['archive_delai']="0";
400                    $valInstr['archive_date_complet']=NULL;
401                    $valInstr['archive_date_rejet']=NULL;
402                    $valInstr['archive_date_limite']=NULL;
403                    $valInstr['archive_date_notification_delai']=NULL;
404                    $valInstr['archive_accord_tacite']="Non";
405                    $valInstr['archive_etat']="initialiser";
406                    $valInstr['archive_date_decision']=NULL;
407                    $valInstr['archive_avis']="";
408                    $valInstr['archive_date_validite']=NULL;
409                    $valInstr['archive_date_achevement']=NULL;
410                    $valInstr['archive_date_chantier']=NULL;
411                    $valInstr['archive_date_conformite']=NULL;
412                    $valInstr['complement3']="";
413                    $valInstr['complement4']="";
414                    $valInstr['complement5']="";
415                    $valInstr['complement6']="";
416                    $valInstr['complement7']="";
417                    $valInstr['complement8']="";
418                    $valInstr['complement9']="";
419                    $valInstr['complement10']="";
420                    $valInstr['complement11']="";
421                    $valInstr['complement12']="";
422                    $valInstr['complement13']="";
423                    $valInstr['complement14']="";
424                    $valInstr['complement15']="";
425                    $valInstr['avis_decision']=NULL;
426                    $valInstr['date_finalisation_courrier']=NULL;
427                    $valInstr['date_envoi_signature']=NULL;
428                    $valInstr['date_retour_signature']=NULL;
429                    $valInstr['date_envoi_rar']=NULL;
430                    $valInstr['date_retour_rar']=NULL;
431                    $valInstr['date_envoi_controle_legalite']=NULL;
432                    $valInstr['date_retour_controle_legalite']=NULL;
433                    $valInstr['signataire_arrete']=NULL;
434                                    
435                    /*Fichier requis*/
436                    require_once '../obj/instruction.class.php';
437                    
438                    /*Création d'un nouveau dossier*/
439                    $instruction = new instruction("]",$db,$DEBUG);
440                    $instruction->valF = "";
441                    $instruction->ajouter($valInstr, $db, $DEBUG);
442                    
443                    /*Si la création a réussie*/
444                    if ( $instruction->valF['instruction'] != "" ){
445                        
446                        /*Affichage du récépissé de la demande*/
447                        $this->valF['instruction_recepisse'] = $instruction->valF['instruction'];
448                        $this -> addToMessage("<br/><a
449                            class='lien'
450                            href='../pdf/pdflettretype.php?obj=".$lettretype."&amp;idx=".$this->valF['dossier_instruction']."'
451                            target='_blank'>
452                                <span
453                                class=\"om-icon om-icon-16 om-icon-fix pdf-16\"
454                                title=\""._("Telecharger le recepisse de la demande")."\">".
455                                    _("Telecharger le recepisse de la demande").
456                                "</span>
457                                &nbsp;&nbsp;&nbsp;&nbsp;".
458                                _("Telecharger le recepisse de la demande")."
459                            </a><br/>");
460                    }
461                    /*Sinon affiche un message d'erreur*/
462                    else {
463                        
464                        $this -> addToMessage(_("Une erreur s'est produite lors de la creation du recepisse"));
465                    }
466                }
467    
468          parent::setType($form,$maj);              /*Ajout de l'arrondissement à partir du code postal*/
469                if ( !is_null($this->valF["terrain_adresse_code_postal"]) && is_numeric($this->valF["terrain_adresse_code_postal"]) ){
470                    
471                    $this->valF["arrondissement"] = $this->getArrondissement($this->valF["terrain_adresse_code_postal"]);
472                }
473            }
474        }
475    
476        /**
477         * Ajout des délégataires et pétitionnaires
478         **/
479        function triggerAjouterApres($id, &$db, $val, $DEBUG){
480            $this->insertLinkDemandeDemandeur($db, $DEBUG);
481            
482            // Ajout des lliens entre dossier_autorisation et demandeur
483            if(!empty($this->valF['dossier_autorisation']) AND $val['dossier_autorisation'] == "" ) {
484                $this->ajoutLiensDossierAutorisation($id, $db, $val, $DEBUG);
485            }
486            // Ajout des lliens entre dossier et demandeur
487            if(!empty($this->valF['dossier_instruction'])) {
488                $this->ajoutLiensDossierInstruction($id, $db, $val, $DEBUG);
489            }
490    
491            // Duplication des lots et liaison au nouveau dossier_d'instruction
492            if(!empty($this->valF['dossier_autorisation']) AND $val['dossier_autorisation'] != "" ) {
493                $this->lienLotDossierInstruction($id, $db, $val, $DEBUG);
494            }
495        }
496        
497        /*Ajout du lien demande / demandeur(s)*/
498        function triggerModifierApres($id, &$db, $val, $DEBUG){
499            $this->listeDemandeur("demande",$this->val[array_search('demande', $this->champs)]);
500            $this->insertLinkDemandeDemandeur($db, $DEBUG);
501            $this->valIdDemandeur=$this->postedIdDemandeur;
502    
503        }
504    
505        /**
506         * Gestion des liens entre les lots du DA et le nouveau dossier
507         **/
508        function lienLotDossierInstruction($id, $db, $val, $DEBUG) {
509            require_once ("../obj/lot.class.php");
510            $lot = new lot("]", $db, $DEBUG);
511            require_once ("../obj/lien_dossier_lot.class.php");
512            $ldl = new lien_dossier_lot("]", $db, $DEBUG);
513            require_once ("../obj/lien_lot_demandeur.class.php");
514            $lld = new lien_lot_demandeur("]", $db, $DEBUG);
515    
516    
517            $sqlLots = "SELECT * FROM ".DB_PREFIXE."lot
518            WHERE dossier_autorisation = '".$this->valF['dossier_autorisation']."'";
519            $resLot = $db -> query($sqlLots);
520            $this->f->addToLog("db->query(\"".$sqlLots."\");", VERBOSE_MODE);
521            $this->f->isDatabaseError($resLot);
522            while ($rowLot=& $resLot->fetchRow(DB_FETCHMODE_ASSOC)){
523                // Insertion du nouveau lot
524                $valLot['lot'] = "";
525                $valLot['libelle'] = $rowLot['libelle'];
526                $valLot['dossier_autorisation'] = NULL;
527                $lot -> ajouter($valLot, $db, $DEBUG);
528    print_r($rowLot);
529                //Insertion du lien entre le lot et le dossier d'instruction
530                $valLdl['lien_dossier_lot'] = "";
531                $valLdl['dossier'] = $this->valF['dossier_instruction'];
532                $valLdl['lot'] = $lot->valF['lot'];
533                $ldl->ajouter($valLdl, $db, $DEBUG);
534    
535                //Insertion des liens entre dossier et les lots
536                $sqlDemandeurs = "SELECT * FROM ".DB_PREFIXE."lien_lot_demandeur
537                WHERE lot = ".$rowLot['lot'];
538                $res = $db -> query($sqlDemandeurs);
539                $this->f->addToLog("db->query(\"".$sqlDemandeurs."\");", VERBOSE_MODE);
540                $this->f->isDatabaseError($res);
541                
542                while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
543                    $valLld["lien_lot_demandeur"] = "";
544                    $valLld["lot"]=$lot->valF['lot'];
545                    $valLld["demandeur"] = $row['demandeur'];
546                    $valLld["petitionnaire_principal"] = $row['petitionnaire_principal'];
547                    $lld->ajouter($valLld, $db, $DEBUG);
548                }
549            }
550        }
551    
552        /**
553         * Gestion des liens entre la demande et les demandeurs recemment ajoutés
554         **/
555        function insertLinkDemandeDemandeur($db, $DEBUG) {
556            //
557            require_once "../obj/lien_demande_demandeur.class.php";
558            // Comparaison de l'id petitionnaire principal
559            if(isset($this->postedIdDemandeur['petitionnaire_principal']) AND
560               !empty($this->postedIdDemandeur['petitionnaire_principal']) AND
561               $this->valIdDemandeur['petitionnaire_principal'] !=
562                            $this->postedIdDemandeur['petitionnaire_principal']) {
563                // Ajout du nouveau lien
564                $this->addLinkDemandeDemandeur($this->postedIdDemandeur['petitionnaire_principal'], true, $db, $DEBUG);
565                if(!empty($this->valIdDemandeur['petitionnaire_principal'])) {
566                    $this->deleteLinkDemandeDemandeur($this->valIdDemandeur['petitionnaire_principal'], $db, $DEBUG);
567                }
568            }
569    
570            // Comparaison du delegataire
571            if(isset($this->postedIdDemandeur['delegataire']) AND
572               !empty($this->postedIdDemandeur['delegataire']) AND
573               $this->valIdDemandeur['delegataire'] !=
574                            $this->postedIdDemandeur['delegataire']) {
575                // Ajout du nouveau lien
576                $this->addLinkDemandeDemandeur($this->postedIdDemandeur['delegataire'], false, $db, $DEBUG);
577                if(!empty($this->valIdDemandeur['delegataire'])) {
578                    $this->deleteLinkDemandeDemandeur($this->valIdDemandeur['delegataire'], $db, $DEBUG);
579                }
580            }
581    
582            // Comparaison des different petitionnaires
583            if(isset($this->postedIdDemandeur['petitionnaire'])) {
584                // Suppression des liens non valides
585                foreach ($this->valIdDemandeur['petitionnaire'] as $petitionnaire) {
586                    if(!in_array($petitionnaire, $this->postedIdDemandeur['petitionnaire'])) {
587                        $this->deleteLinkDemandeDemandeur($petitionnaire, $db, $DEBUG);
588                    }
589                }
590                // Ajout des nouveaux liens
591                foreach ($this->postedIdDemandeur['petitionnaire'] as $petitionnaire) {
592                    if(!in_array($petitionnaire, $this->valIdDemandeur['petitionnaire'])) {
593                        $this->addLinkDemandeDemandeur($petitionnaire, false, $db, $DEBUG);
594                    }
595                }
596            }
597        }
598    
599    
600        /**
601         * Fonction permettant d'ajouter un lien
602         * entre la table demande et demandeur
603         **/
604        function addLinkDemandeDemandeur($id, $principal, $db, $DEBUG) {
605            $lienAjout = new lien_demande_demandeur(
606                                            "]",
607                                            $db,
608                                            $DEBUG);
609            $lien = array('lien_demande_demandeur' => "",
610                               'petitionnaire_principal' => (($principal)?"t":"f"),
611                               'demande' => $this->valF['demande'],
612                               'demandeur' => $id);
613            $lienAjout->ajouter($lien, $db, $DEBUG);
614            $lienAjout->__destruct();
615        }
616    
617        /**
618         * Fonction permettant de supprimer un lien
619         * entre la table demande et demandeur
620         **/
621        function deleteLinkDemandeDemandeur($id, $db, $DEBUG) {
622            // Suppression
623            $sql = "DELETE FROM ".DB_PREFIXE."lien_demande_demandeur ".
624                    "WHERE demande=".$this->valF['demande'].
625                    " AND demandeur=".$id;
626            // Execution de la requete de suppression de l'objet
627            $res = $db->query($sql);
628            // Logger
629            $this->f->addToLog("supprimer(): db->query(\"".$sql."\");", VERBOSE_MODE);
630            $this->f->isDatabaseError();
631    
632        }
633    
634        /*
635         * Teste si le lien entre une demande et un demandeur existe
636         * */
637        function isLinkDemandeDemandeurExist($idDemandeur) {
638            $sql = "SELECT count(*)
639                    FROM ".DB_PREFIXE."lien_demande_demandeur
640                    WHERE demande = ".$this->valF['demande'].
641                    "AND demandeur = ".$idDemandeur;
642            $count = $this->f->db->getOne($sql);
643            $this->f->addToLog("db->getone(\"".$sql."\");", VERBOSE_MODE);
644            $this->f->isDatabaseError($count);
645            if ($count === 0) {
646                return false;
647            } else {
648                return true;
649            }
650    
651        }
652    
653        /**
654         * Methode de recupération des valeurs postées
655         **/
656        function getPostedValues() {
657            // Récupération des demandeurs dans POST
658            if (isset($_POST['petitionnaire_principal']) OR
659                    isset($_POST['delegataire']) OR
660                        isset($_POST['petitionnaire'])) {
661                if( isset($_POST['petitionnaire_principal']) AND
662                        !empty($_POST['petitionnaire_principal'])) {
663                    $this->postedIdDemandeur['petitionnaire_principal'] = $_POST['petitionnaire_principal'];
664                }
665                if( isset($_POST['delegataire']) AND
666                        !empty($_POST['delegataire'])) {
667                    $this->postedIdDemandeur['delegataire'] = $_POST['delegataire'];
668                }
669                if( isset($_POST['petitionnaire']) AND
670                        !empty($_POST['petitionnaire'])) {
671                    $this->postedIdDemandeur['petitionnaire'] = $_POST['petitionnaire'];
672                }
673            }
674        }
675        /**
676         * Méthode permettant de récupérer les id des demandeur liés à la demande ou
677         * liés au dossier d'autorisation
678         **/
679        function listeDemandeur($from, $id) {
680            // Récupération des demandeurs de la base
681            $sql = "SELECT demandeur.demandeur,
682                            demandeur.type_demandeur,
683                            lien_".$from."_demandeur.petitionnaire_principal
684                FROM ".DB_PREFIXE."lien_".$from."_demandeur
685                INNER JOIN ".DB_PREFIXE."demandeur
686                ON demandeur.demandeur=lien_".$from."_demandeur.demandeur
687                WHERE ".$from." = '".$id."'";
688            $res = $this->f->db->query($sql);
689            $this->f->addToLog("listeDemandeur() : ".$sql);
690            $this->f->isDatabaseError($res);
691            // Stoquage du résultat dans un tableau
692            while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
693                if ($row['petitionnaire_principal'] == 't' AND
694                    $row['type_demandeur']=="petitionnaire") {
695                    $this->valIdDemandeur['petitionnaire_principal']=$row['demandeur'];
696                } elseif ($row['petitionnaire_principal'] == 'f' AND
697                    $row['type_demandeur']=="petitionnaire"){
698                    $this->valIdDemandeur['petitionnaire'][]=$row['demandeur'];
699                } elseif ($row['type_demandeur']=="delegataire"){
700                    $this->valIdDemandeur['delegataire']=$row['demandeur'];
701                }
702            }
703        }
704    
705    
706        /**
707         * Surcharge du bouton retour afin de retourner sur la recherche de dossiers
708         * d'instruction existant
709         */
710        function retour($premier = 0, $recherche = "", $tricol = "") {
711    
712            echo "\n<a class=\"retour\" ";
713            echo "href=\"";
714            //
715            if($this->getParameter("idx_dossier") != "") {
716                echo "tab.php?";
717                echo "obj=recherche_dossier";
718    
719            } else {
720                if($this->getParameter("retour")=="form" AND !($this->getParameter("validation")>0 AND $this->getParameter("maj")==2 AND $this->correct)) {
721                    echo "form.php?";
722                } else {
723                    echo "tab.php?";
724                }
725                echo "obj=".get_class($this);
726                if($this->getParameter("retour")=="form") {
727                    echo "&amp;idx=".$this->getParameter("idx");
728                    echo "&amp;action=3";
729                }
730            }
731            echo "&amp;premier=".$this->getParameter("premier");
732            echo "&amp;tricol=".$this->getParameter("tricol");
733            echo "&amp;recherche=".$this->getParameter("recherche");
734            echo "&amp;selectioncol=".$this->getParameter("selectioncol");
735            echo "&amp;advs_id=".$this->getParameter("advs_id");
736            echo "&amp;valide=".$this->getParameter("valide");
737            //
738            echo "\"";
739            echo ">";
740            //
741            echo _("Retour");
742            //
743            echo "</a>\n";
744    
745        }
746    
747    
748        /**
749         * Ajout de la liste des demandeurs
750         */
751        function formSpecificContent($maj) {
752            if(!$this->correct AND $maj != 0) {
753                $this->listeDemandeur("demande", $this->val[array_search('demande', $this->champs)]);
754            }
755            // Si le paramètre idx_dossier est défini on récupère les demandeurs liés au dossier d'instruction
756            if($this->getParameter("idx_dossier") != "") {
757                $this->listeDemandeur("dossier", $this->getParameter("idx_dossier"));
758            }
759            if($maj < 2 AND !$this->correct) {
760                $linkable = true;
761            } else {
762                $linkable = false;
763            }
764    
765            // Conteneur de la listes des demandeurs
766            echo "<div id=\"liste_demandeur\" class=\"demande_hidden_bloc col_12\">";
767            echo "<fieldset class=\"cadre ui-corner-all ui-widget-content\">";
768            echo "  <legend class=\"ui-corner-all ui-widget-content ui-state-active\">"
769                    ._("Petitionnaire")."</legend>";
770            // Si des demandeurs sont liés à la demande
771            require_once "../obj/petitionnaire.class.php";
772            require_once "../obj/delegataire.class.php";
773            // Affichage du bloc pétitionnaire principal / délégataire
774            // L'ID DU DIV SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
775            echo "<div id=\"petitionnaire_principal_delegataire col_12\">";
776            // Affichage de la synthèse
777            if (isset ($this->valIdDemandeur["petitionnaire_principal"]) AND
778                !empty($this->valIdDemandeur["petitionnaire_principal"])) {
779                $demandeur = new petitionnaire(
780                                    $this->valIdDemandeur["petitionnaire_principal"],
781                                    $this->f->db,false);
782                $demandeur -> afficherSynthese("petitionnaire_principal", $linkable);
783                $demandeur -> __destruct();
784            } elseif ( isset ($this->postedIdDemandeur["petitionnaire_principal"]) AND
785                !empty($this->postedIdDemandeur["petitionnaire_principal"]) ) {
786                $demandeur = new petitionnaire(
787                                    $this->postedIdDemandeur["petitionnaire_principal"],
788                                    $this->f->db,false);
789                $demandeur -> afficherSynthese("petitionnaire_principal", $linkable);
790                $demandeur -> __destruct();
791            }
792            // Si en édition de formulaire
793            if($maj < 2) {
794                // Bouton d'ajout du pétitionnaire principal
795                // L'ID DE L'INPUT SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
796                echo "<span id=\"add_petitionnaire_principal\"
797                    class=\"om-form-button add-16\">".
798                    _("Saisir le petitionnaire principal").
799                "</span>";
800            }
801            // Bouton d'ajout du delegataire
802            // L'ID DU DIV ET DE L'INPUT SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
803            echo "<div id=\"delegataire\">";
804            // Affichage de la synthèse
805            if (isset ($this->valIdDemandeur["delegataire"]) AND
806                !empty($this->valIdDemandeur["delegataire"])) {
807                $demandeur = new delegataire($this->valIdDemandeur["delegataire"],
808                                           $this->f->db,false);
809                $demandeur -> afficherSynthese("delegataire", $linkable);
810                $demandeur -> __destruct();
811            } elseif ( isset ($this->postedIdDemandeur["delegataire"]) AND
812            !empty($this->postedIdDemandeur["delegataire"]) ) {
813    
814                $demandeur = new delegataire($this->postedIdDemandeur["delegataire"],
815                                           $this->f->db,false);
816                $demandeur -> afficherSynthese("delegataire", $linkable);
817                $demandeur -> __destruct();
818            }
819            if($maj < 2) {
820                echo "<span id=\"add_delegataire\"
821                        class=\"om-form-button add-16\">".
822                        _("Saisir le delegataire").
823                    "</span>";
824            }
825            echo "</div>";
826            echo "<div class=\"both\"></div>";
827            echo "</div>";
828            // Bloc des pétitionnaires secondaires
829            // L'ID DU DIV SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
830            echo "<div id=\"listePetitionnaires col_12\">";
831    
832             // Affichage de la synthèse
833            if (isset ($this->valIdDemandeur["petitionnaire"]) AND
834                !empty($this->valIdDemandeur["petitionnaire"])) {
835                
836                foreach ($this->valIdDemandeur["petitionnaire"] as $petitionnaire) {
837                    $demandeur = new petitionnaire($petitionnaire,
838                                           $this->f->db,false);
839                    $demandeur -> afficherSynthese("petitionnaire", $linkable);
840                    $demandeur -> __destruct();
841                }
842                
843            } elseif ( isset ($this->postedIdDemandeur["petitionnaire"]) AND
844                !empty($this->postedIdDemandeur["petitionnaire"]) )  {
845                foreach ($this->postedIdDemandeur["petitionnaire"] as $petitionnaire) {
846                    $demandeur = new petitionnaire($petitionnaire,
847                                           $this->f->db,false);
848                    $demandeur -> afficherSynthese("petitionnaire", $linkable);
849                    $demandeur -> __destruct();
850                }
851            }
852            if ($maj < 2) {
853                // L'ID DE L'INPUT SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
854                echo "<span id=\"add_petitionnaire\"
855                        class=\"om-form-button add-16\">".
856                        _("Ajouter un petitionnaire")
857                    ."</span>";
858            }
859            echo "</div>";
860            echo "</fieldset>";
861            echo "</div>";
862        }
863    
864        // {{{
865    
866        // getter
867        function getValIdDemandeur() {
868            return $this->valIdDemandeur;
869        }
870        // setter
871        function setValIdDemandeur($valIdDemandeur) {
872            $this->valIdDemandeur = $valIdDemandeur;
873        }
874        
875        //Supression du lien entre la demandeur et le(s) demandeur(s)
876        function triggerSupprimer($id, &$db, $val, $DEBUG){
877                    
878          //$form->setType('terrain_references_cadastrales', 'hidden');          //Création de la requête
879            $sql = "DELETE FROM
880                        ".DB_PREFIXE."lien_demande_demandeur
881                    WHERE
882                        demande = $id";
883                  
884            $res = $this->f->db->query($sql);
885            $this->f->addToLog("triggerSupprimer() : ".$sql);
886            $this->f->isDatabaseError($res);
887      }      }
888        
889        // }}}
890  }// fin classe  }// fin classe
 ?>  
891    ?>

Legend:
Removed from v.693  
changed lines
  Added in v.1246

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26