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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26