/[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 808 by nhaye, Thu Nov 22 16:37:35 2012 UTC revision 1282 by vpihour, Thu Feb 21 17:48:26 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;      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
# Line 18  class demande extends demande_gen { Line 45  class demande extends demande_gen {
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         * Méthode de verification du contenu
63         */
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      * Ajout du fielset
74      * Add fieldset      * Add fieldset
# Line 29  class demande extends demande_gen { Line 76  class demande extends demande_gen {
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 col_8");              $form->setBloc('dossier_autorisation_type_detaille','D',"","dossier_type col_8");
81                
82                  $form->setFieldset('dossier_autorisation_type_detaille','D'                  $form->setFieldset('dossier_autorisation_type_detaille','D'
83                                     ,_('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                            
89                /*Champ sur lequel s'ouvre le bloc 2 */
90              $form->setBloc('date_demande','D',"","col_4 demande_hidden_bloc");              $form->setBloc('date_demande','D',"","col_4 demande_hidden_bloc");
91                  $form->setFieldset('date_demande','D',_('Date de la demande'));                  $form->setFieldset('date_demande','D',_('Date de la demande'));
92                  $form->setFieldset('date_demande','F','');                  $form->setFieldset('date_demande','F','');
93              $form->setBloc('date_demande','F');              $form->setBloc('date_demande','F');
94                /*Fin bloc 2*/
95                            
96                /*Champ sur lequel s'ouvre le bloc 3 */
97              $form->setBloc('terrain_references_cadastrales','D',"",              $form->setBloc('terrain_references_cadastrales','D',"",
98                             "localisation col_12 demande_hidden_bloc");                             "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 demande_hidden_bloc");  
                 $form->setFieldset('nombre_lots','D',_('Nombre de lots'));  
                 $form->setFieldset('nombre_lots','F','');  
             $form->setBloc('nombre_lots','F');  
104          }          }
105      }      }
106    
# Line 75  class demande extends demande_gen { Line 123  class demande extends demande_gen {
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']=1;
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        function getCodeDemandeType($demande_type){
191            
192            $sql = "SELECT
193                        code
194                    FROM
195                        ".DB_PREFIXE."demande_type
196                    WHERE
197                        demande_type = ".$demande_type;
198            $codeDemandeType = $this->db->getOne($sql);
199            $this->addToLog("db->getone(\"".$sql."\");", VERBOSE_MODE);
200            
201            return $codeDemandeType;
202        }
203    
204        /**
205         * Méthode permettant d'ajouter un dossier d'instruction
206         */
207        function ajoutDossierInstruction($id, &$db, $val, $DEBUG, $dossier_instruction_type){
208            require_once '../obj/dossier.class.php';
209            $dossier = new dossier("]",$db,$DEBUG);
210            foreach($dossier->champs as $value) {
211                $valInstr[$value] = NULL;
212            }
213            require_once '../obj/dossier_autorisation_type_detaille.class.php';
214            $datd = new dossier_autorisation_type_detaille(
215                    $this->valF['dossier_autorisation_type_detaille'],$db,$DEBUG);
216                    
217            /*Ajout de la variable dossier_instruction_type à l'objet dossier pour le
218             * versionning
219             */
220            $dossier->setDossierInstructionType($dossier_instruction_type);
221            
222            // Définition des valeurs à entrée dans la table
223            $valInstr['dossier_instruction_type']=$dossier_instruction_type;
224            $valInstr['date_depot']=$this->dateDBToForm($this->valF['date_demande']);
225            $valInstr['date_demande']=$this->dateDBToForm($this->valF['date_demande']);
226            $valInstr['depot_initial']=$this->dateDBToForm($this->valF['date_demande']);
227            $valInstr['terrain_references_cadastrales']=$this->valF['terrain_references_cadastrales'];
228            $valInstr['terrain_adresse_voie_numero']=$this->valF['terrain_adresse_voie_numero'];
229            $valInstr['complement']=$this->valF['complement'];
230            $valInstr['terrain_adresse_lieu_dit']=$this->valF['terrain_adresse_lieu_dit'];
231            $valInstr['terrain_adresse_localite']=$this->valF['terrain_adresse_localite'];
232            $valInstr['terrain_adresse_code_postal']=$this->valF['terrain_adresse_code_postal'];
233            $valInstr['terrain_adresse_bp']=$this->valF['terrain_adresse_bp'];
234            $valInstr['terrain_adresse_cedex']=$this->valF['terrain_adresse_cedex'];
235            $valInstr['terrain_superficie']=$this->valF['terrain_superficie'];
236            $valInstr['description']="";
237            $valInstr['dossier_autorisation']=$this->valF['dossier_autorisation'];
238    
239            /*
240             * Gestion de la qualification
241             * */
242             //Récupérer le code du type de la demande
243             $codeDemandeType = $this->getCodeDemandeType($val['demande_type']);
244            
245            //Marque le dossier comme à qualifier selon le type de dossier d'instruction
246            if ( strcasecmp($codeDemandeType, "DI") == 0 ||
247                 strcasecmp($codeDemandeType, "DT") == 0 ||
248                 strcasecmp($codeDemandeType, "DM") == 0 ||
249                 strcasecmp($codeDemandeType, "DP") == 0 ||
250                 strcasecmp($codeDemandeType, "DTP") == 0 ||
251                 strcasecmp($codeDemandeType, "DACT") == 0 ||
252                 strcasecmp($codeDemandeType, "DOC") == 0 ){
253                
254                $valInstr['a_qualifier'] = TRUE;
255            }
256    
257            // Récupération du cerfa pour le type d'instruction sélectionnée et valide
258            $sql = "SELECT
259                        dossier_instruction_type.cerfa
260                    FROM
261                        ".DB_PREFIXE."dossier_instruction_type
262                    JOIN
263                        ".DB_PREFIXE."cerfa
264                    ON
265                        dossier_instruction_type.cerfa = cerfa.cerfa
266                    WHERE
267                        now()<=om_validite_fin
268                        AND now()>=om_validite_debut
269                        AND dossier_instruction_type=".$dossier_instruction_type;
270            $valInstr['cerfa'] = $db->getOne($sql);
271            $this->addToLog("db->getone(\"".$sql."\");", VERBOSE_MODE);
272    
273            $dossier->ajouter($valInstr, $db, $DEBUG);
274            $this->f->isDatabaseError();
275            // Liaison du dossier ajouter à la demande
276            $this->valF['dossier_instruction'] = $dossier->valF['dossier'];
277      }      }
278    
279      /**      /**
280       * Méthode permettant de récupérer les id des demandeur lié à la demande       * Ajout des liens demandeurs / dossier d'autorisation
281       **/       **/
282      function getValIdDemandeur() {      function ajoutLiensDossierAutorisation($id, &$db, $val, $DEBUG) {
283          if( $validation > 0 ) {          // Création des liens entre le dossier autorisation et les demandeurs
284              foreach($_POST as $champ => $val) {          include '../sql/pgsql/demande.form.inc.php';
285                  if(!in_array($champ, $this->champs)) {          require_once '../obj/lien_dossier_autorisation_demandeur.class.php';
286                      $this->valIdDemandeur[$champ]=$val;          $ldad = new lien_dossier_autorisation_demandeur("]",$db,$DEBUG);
287            // Recupération des demandeurs liés à la demande
288            $sql = str_replace("<demande>",$this->valF['demande'],$sql_lien_demande_demandeur);
289            $res = $db->query($sql);
290            $this->f->addToLog("demande.class.php: db->query(\"".$sql."\");", VERBOSE_MODE);
291            $this->f->isDatabaseError();
292            while($row = &$res->fetchRow(DB_FETCHMODE_ASSOC)) {
293                $row['lien_dossier_autorisation_demandeur'] = NULL;
294                $row['dossier_autorisation'] = $this->valF['dossier_autorisation'];
295                $ldad->ajouter($row, $db, $DEBUG);
296            }
297        }
298    
299        /**
300         * Ajout des liens demandeurs / dossier d'autorisation
301         **/
302        function ajoutLiensDossierInstruction($id, &$db, $val, $DEBUG) {
303            // Création des liens entre le dossier instruction et les demandeurs
304            include '../sql/pgsql/demande.form.inc.php';
305            require_once '../obj/lien_dossier_demandeur.class.php';
306            $ldd = new lien_dossier_demandeur("]",$db,$DEBUG);
307            // Recupération des demandeurs liés à la demande
308            $sql = str_replace("<demande>",$this->valF['demande'],$sql_lien_demande_demandeur);
309            $res = $db->query($sql);
310            $this->f->addToLog("demande.class.php: db->query(\"".$sql."\");", VERBOSE_MODE);
311            $this->f->isDatabaseError();
312            while($row = &$res->fetchRow(DB_FETCHMODE_ASSOC)) {
313                $row['lien_dossier_demandeur'] = NULL;
314                $row['dossier'] = $this->valF['dossier_instruction'];
315                $ldd->ajouter($row, $db, $DEBUG);
316            }
317        }
318    
319        /*
320         * Récupère l'identifiant d'un arrondissement à partir d'un code postal
321         */
322        function getArrondissement($terrain_adresse_code_postal){
323            
324            $arrondissement = NULL;
325            
326            $sql = "SELECT
327                        arrondissement
328                    FROM
329                        ".DB_PREFIXE."arrondissement
330                    WHERE
331                        code_postal = '$terrain_adresse_code_postal' ";
332            $this->addToLog("demande.class.php : ".$sql." execute <br>", EXTRA_VERBOSE_MODE);
333            
334            $res = $this->db->query($sql);
335            $this->f->isDatabaseError($res);
336            
337            if( $res->numrows() > 0 ) {
338                
339                $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);
340                $arrondissement = $row['arrondissement'];
341            }
342            
343            return $arrondissement;
344        }
345        
346        /*
347         * Récupère l'évènement lié à un type de demande
348         */
349         function getEvenement($demande_type){
350            
351             $evenement = NULL;
352            
353             $sql =
354                "SELECT
355                    evenement
356                FROM
357                    ".DB_PREFIXE."demande_type
358                WHERE
359                    demande_type = $demande_type";
360                
361            $res = $this->db->query($sql);
362            $this->f->isDatabaseError($res);
363            
364            if ( $res->numrows() > 0 ){
365                    
366                $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);
367                $evenement = $row['evenement'];
368            }
369            
370            return $evenement;
371         }
372        
373         /*
374         * Récupère la lettre type lié à un événement
375         */
376         function getLettreType($evenement){
377            
378             $lettretype = NULL;
379            
380             $sql =
381                "SELECT
382                    lettretype
383                FROM
384                    ".DB_PREFIXE."evenement
385                WHERE
386                    evenement = $evenement";
387                
388            $res = $this->db->query($sql);
389            $this->f->isDatabaseError($res);
390            
391            if ( $res->numrows() > 0 ){
392                    
393                $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);
394                $lettretype = $row['lettretype'];
395            }
396            
397            return $lettretype;
398         }
399        
400        /**
401         * Ajout des dossiers
402         **/
403        function triggerAjouter($id, &$db, $val, $DEBUG){
404            include '../sql/pgsql/demande.form.inc.php';
405            if($this->valF["demande_type"] != NULL) {
406                $res = $db->query(str_replace('<idx>', $this->valF['demande_type'], $sql_demande_type_details_by_id));
407                $this->f->isDatabaseError();
408                $dossier_type = $res->fetchRow(DB_FETCHMODE_ASSOC);
409                // Création du dossier_autorisation
410                if($this->valF['dossier_autorisation'] == "") {
411                    $this->ajoutDossierAutorisation($id, $db, $val, $DEBUG);
412                    $this -> addToMessage(_("Creation du dossier d'autorisation no").$this->valF['dossier_autorisation']);
413                }
414                // Création du dossier d'instruction
415                if($dossier_type['dossier_instruction_type'] != NULL) {
416                    $this->ajoutDossierInstruction($id, $db, $val, $DEBUG, $dossier_type['dossier_instruction_type']);
417                    $this -> addToMessage(_("Creation du dossier d'instruction no").$this->valF['dossier_instruction']);
418                }
419                
420                /*Création du lien de téléchargement de récépissé de demande*/
421                if ( $this->valF['demande_type'] != "" && is_numeric($this->valF['demande_type'])
422                    && isset($this->valF['dossier_instruction']) && $this->valF['dossier_instruction'] !== "" ){
423                
424                    /*Récupérer l'événement lié à ce type de demande*/
425                    $evenement = $this->getEvenement($this->valF['demande_type']);
426                                    
427                    /*Récupération de la lettre type de l'événement*/
428                    $lettretype = $this->getLettreType($evenement);
429                    
430                    /*Création d'une nouvelle instruction avec cet événement*/
431                    /*Données*/
432                    $valInstr['instruction']=NULL;
433                    
434                    $valInstr['destinataire']=$this->valF['dossier_instruction'];
435                    $valInstr['dossier']=$this->valF['dossier_instruction'];
436                    
437                    $valInstr['date_evenement']=date("d/m/Y");
438                    $valInstr['evenement']=$evenement;
439                    $valInstr['lettretype']=$lettretype;
440                    $valInstr['complement']="";
441                    $valInstr['complement2']="";
442                    
443                    $valInstr['action']="initialisation";
444                    $valInstr['delai']="2";
445                    $valInstr['etat']="notifier";
446                    $valInstr['accord_tacite']="Oui";
447                    $valInstr['delai_notification']="1";
448                    $valInstr['archive_delai']="0";
449                    $valInstr['archive_date_complet']=NULL;
450                    $valInstr['archive_date_rejet']=NULL;
451                    $valInstr['archive_date_limite']=NULL;
452                    $valInstr['archive_date_notification_delai']=NULL;
453                    $valInstr['archive_accord_tacite']="Non";
454                    $valInstr['archive_etat']="initialiser";
455                    $valInstr['archive_date_decision']=NULL;
456                    $valInstr['archive_avis']="";
457                    $valInstr['archive_date_validite']=NULL;
458                    $valInstr['archive_date_achevement']=NULL;
459                    $valInstr['archive_date_chantier']=NULL;
460                    $valInstr['archive_date_conformite']=NULL;
461                    $valInstr['complement3']="";
462                    $valInstr['complement4']="";
463                    $valInstr['complement5']="";
464                    $valInstr['complement6']="";
465                    $valInstr['complement7']="";
466                    $valInstr['complement8']="";
467                    $valInstr['complement9']="";
468                    $valInstr['complement10']="";
469                    $valInstr['complement11']="";
470                    $valInstr['complement12']="";
471                    $valInstr['complement13']="";
472                    $valInstr['complement14']="";
473                    $valInstr['complement15']="";
474                    $valInstr['avis_decision']=NULL;
475                    $valInstr['date_finalisation_courrier']=NULL;
476                    $valInstr['date_envoi_signature']=NULL;
477                    $valInstr['date_retour_signature']=NULL;
478                    $valInstr['date_envoi_rar']=NULL;
479                    $valInstr['date_retour_rar']=NULL;
480                    $valInstr['date_envoi_controle_legalite']=NULL;
481                    $valInstr['date_retour_controle_legalite']=NULL;
482                    $valInstr['signataire_arrete']=NULL;
483                                    
484                    /*Fichier requis*/
485                    require_once '../obj/instruction.class.php';
486                    
487                    /*Création d'un nouveau dossier*/
488                    $instruction = new instruction("]",$db,$DEBUG);
489                    $instruction->valF = "";
490                    $instruction->ajouter($valInstr, $db, $DEBUG);
491                    
492                    /*Si la création a réussie*/
493                    if ( $instruction->valF['instruction'] != "" ){
494                        
495                        /*Affichage du récépissé de la demande*/
496                        $this->valF['instruction_recepisse'] = $instruction->valF['instruction'];
497                        $this -> addToMessage("<br/><a
498                            class='lien'
499                            href='../pdf/pdflettretype.php?obj=".$lettretype."&amp;idx=".$this->valF['dossier_instruction']."'
500                            target='_blank'>
501                                <span
502                                class=\"om-icon om-icon-16 om-icon-fix pdf-16\"
503                                title=\""._("Telecharger le recepisse de la demande")."\">".
504                                    _("Telecharger le recepisse de la demande").
505                                "</span>
506                                &nbsp;&nbsp;&nbsp;&nbsp;".
507                                _("Telecharger le recepisse de la demande")."
508                            </a><br/>");
509                  }                  }
510                    /*Sinon affiche un message d'erreur*/
511                    else {
512                        
513                        $this -> addToMessage(_("Une erreur s'est produite lors de la creation du recepisse"));
514                    }
515                }
516    
517                /*Ajout de l'arrondissement à partir du code postal*/
518                if ( !is_null($this->valF["terrain_adresse_code_postal"]) && is_numeric($this->valF["terrain_adresse_code_postal"]) ){
519                    
520                    $this->valF["arrondissement"] = $this->getArrondissement($this->valF["terrain_adresse_code_postal"]);
521              }              }
522          } elseif( $maj > 0 ) {          }
523              $sql = "SELECT demandeur, petitionnaire_principal      }
524                  FROM lien_demande_demandeur  
525                  WHERE demande = ".$this->val[array_search('demande', $this->champs)];      /**
526              $res = $f->db->query($sql);       * Ajout des délégataires et pétitionnaires
527              $f->isDatabaseError($res);       **/
528        function triggerAjouterApres($id, &$db, $val, $DEBUG){
529            $this->insertLinkDemandeDemandeur($db, $DEBUG);
530            
531            // Ajout des lliens entre dossier_autorisation et demandeur
532            if(!empty($this->valF['dossier_autorisation']) AND $val['dossier_autorisation'] == "" ) {
533                $this->ajoutLiensDossierAutorisation($id, $db, $val, $DEBUG);
534            }
535            // Ajout des lliens entre dossier et demandeur
536            if(!empty($this->valF['dossier_instruction'])) {
537                $this->ajoutLiensDossierInstruction($id, $db, $val, $DEBUG);
538            }
539    
540            // Duplication des lots et liaison au nouveau dossier_d'instruction
541            if(!empty($this->valF['dossier_autorisation']) AND $val['dossier_autorisation'] != "" ) {
542                $this->lienLotDossierInstruction($id, $db, $val, $DEBUG);
543            }
544        }
545        
546        /*Ajout du lien demande / demandeur(s)*/
547        function triggerModifierApres($id, &$db, $val, $DEBUG){
548            $this->listeDemandeur("demande",$this->val[array_search('demande', $this->champs)]);
549            $this->insertLinkDemandeDemandeur($db, $DEBUG);
550            $this->valIdDemandeur=$this->postedIdDemandeur;
551    
552        }
553    
554        /**
555         * Gestion des liens entre les lots du DA et le nouveau dossier
556         **/
557        function lienLotDossierInstruction($id, $db, $val, $DEBUG) {
558            require_once ("../obj/lot.class.php");
559            $lot = new lot("]", $db, $DEBUG);
560            require_once ("../obj/lien_dossier_lot.class.php");
561            $ldl = new lien_dossier_lot("]", $db, $DEBUG);
562            require_once ("../obj/lien_lot_demandeur.class.php");
563            $lld = new lien_lot_demandeur("]", $db, $DEBUG);
564    
565    
566            $sqlLots = "SELECT * FROM ".DB_PREFIXE."lot
567            WHERE dossier_autorisation = '".$this->valF['dossier_autorisation']."'";
568            $resLot = $db -> query($sqlLots);
569            $this->f->addToLog("db->query(\"".$sqlLots."\");", VERBOSE_MODE);
570            $this->f->isDatabaseError($resLot);
571            while ($rowLot=& $resLot->fetchRow(DB_FETCHMODE_ASSOC)){
572                // Insertion du nouveau lot
573                $valLot['lot'] = "";
574                $valLot['libelle'] = $rowLot['libelle'];
575                $valLot['dossier_autorisation'] = NULL;
576                $lot -> ajouter($valLot, $db, $DEBUG);
577    
578                //Insertion du lien entre le lot et le dossier d'instruction
579                $valLdl['lien_dossier_lot'] = "";
580                $valLdl['dossier'] = $this->valF['dossier_instruction'];
581                $valLdl['lot'] = $lot->valF['lot'];
582                $ldl->ajouter($valLdl, $db, $DEBUG);
583    
584                //Insertion des liens entre dossier et les lots
585                $sqlDemandeurs = "SELECT * FROM ".DB_PREFIXE."lien_lot_demandeur
586                WHERE lot = ".$rowLot['lot'];
587                $res = $db -> query($sqlDemandeurs);
588                $this->f->addToLog("db->query(\"".$sqlDemandeurs."\");", VERBOSE_MODE);
589                $this->f->isDatabaseError($res);
590                
591              while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){              while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
592                  $this->valIdDemandeur[$row['demande']]=$row['petitionnaire_principal'];                  $valLld["lien_lot_demandeur"] = "";
593                    $valLld["lot"]=$lot->valF['lot'];
594                    $valLld["demandeur"] = $row['demandeur'];
595                    $valLld["petitionnaire_principal"] = $row['petitionnaire_principal'];
596                    $lld->ajouter($valLld, $db, $DEBUG);
597                }
598            }
599        }
600    
601        /**
602         * Gestion des liens entre la demande et les demandeurs recemment ajoutés
603         **/
604        function insertLinkDemandeDemandeur($db, $DEBUG) {
605            //
606            require_once "../obj/lien_demande_demandeur.class.php";
607            // Comparaison de l'id petitionnaire principal
608            if(isset($this->postedIdDemandeur['petitionnaire_principal']) AND
609               !empty($this->postedIdDemandeur['petitionnaire_principal']) AND
610               $this->valIdDemandeur['petitionnaire_principal'] !=
611                            $this->postedIdDemandeur['petitionnaire_principal']) {
612                // Ajout du nouveau lien
613                $this->addLinkDemandeDemandeur($this->postedIdDemandeur['petitionnaire_principal'], true, $db, $DEBUG);
614                if(!empty($this->valIdDemandeur['petitionnaire_principal'])) {
615                    $this->deleteLinkDemandeDemandeur($this->valIdDemandeur['petitionnaire_principal'], $db, $DEBUG);
616                }
617            }
618    
619            // Comparaison du delegataire
620            if(isset($this->postedIdDemandeur['delegataire']) AND
621               !empty($this->postedIdDemandeur['delegataire']) AND
622               $this->valIdDemandeur['delegataire'] !=
623                            $this->postedIdDemandeur['delegataire']) {
624                // Ajout du nouveau lien
625                $this->addLinkDemandeDemandeur($this->postedIdDemandeur['delegataire'], false, $db, $DEBUG);
626                if(!empty($this->valIdDemandeur['delegataire'])) {
627                    $this->deleteLinkDemandeDemandeur($this->valIdDemandeur['delegataire'], $db, $DEBUG);
628                }
629            }
630    
631            // Comparaison des different petitionnaires
632            if(isset($this->postedIdDemandeur['petitionnaire'])) {
633                // Suppression des liens non valides
634                foreach ($this->valIdDemandeur['petitionnaire'] as $petitionnaire) {
635                    if(!in_array($petitionnaire, $this->postedIdDemandeur['petitionnaire'])) {
636                        $this->deleteLinkDemandeDemandeur($petitionnaire, $db, $DEBUG);
637                    }
638                }
639                // Ajout des nouveaux liens
640                foreach ($this->postedIdDemandeur['petitionnaire'] as $petitionnaire) {
641                    if(!in_array($petitionnaire, $this->valIdDemandeur['petitionnaire'])) {
642                        $this->addLinkDemandeDemandeur($petitionnaire, false, $db, $DEBUG);
643                    }
644                }
645            }
646        }
647    
648    
649        /**
650         * Fonction permettant d'ajouter un lien
651         * entre la table demande et demandeur
652         **/
653        function addLinkDemandeDemandeur($id, $principal, $db, $DEBUG) {
654            $lienAjout = new lien_demande_demandeur(
655                                            "]",
656                                            $db,
657                                            $DEBUG);
658            $lien = array('lien_demande_demandeur' => "",
659                               'petitionnaire_principal' => (($principal)?"t":"f"),
660                               'demande' => $this->valF['demande'],
661                               'demandeur' => $id);
662            $lienAjout->ajouter($lien, $db, $DEBUG);
663            $lienAjout->__destruct();
664        }
665    
666        /**
667         * Fonction permettant de supprimer un lien
668         * entre la table demande et demandeur
669         **/
670        function deleteLinkDemandeDemandeur($id, $db, $DEBUG) {
671            // Suppression
672            $sql = "DELETE FROM ".DB_PREFIXE."lien_demande_demandeur ".
673                    "WHERE demande=".$this->valF['demande'].
674                    " AND demandeur=".$id;
675            // Execution de la requete de suppression de l'objet
676            $res = $db->query($sql);
677            // Logger
678            $this->f->addToLog("supprimer(): db->query(\"".$sql."\");", VERBOSE_MODE);
679            $this->f->isDatabaseError();
680    
681        }
682    
683        /*
684         * Teste si le lien entre une demande et un demandeur existe
685         * */
686        function isLinkDemandeDemandeurExist($idDemandeur) {
687            $sql = "SELECT count(*)
688                    FROM ".DB_PREFIXE."lien_demande_demandeur
689                    WHERE demande = ".$this->valF['demande'].
690                    "AND demandeur = ".$idDemandeur;
691            $count = $this->f->db->getOne($sql);
692            $this->f->addToLog("db->getone(\"".$sql."\");", VERBOSE_MODE);
693            $this->f->isDatabaseError($count);
694            if ($count === 0) {
695                return false;
696            } else {
697                return true;
698            }
699    
700        }
701    
702        /**
703         * Methode de recupération des valeurs postées
704         **/
705        function getPostedValues() {
706            // Récupération des demandeurs dans POST
707            if (isset($_POST['petitionnaire_principal']) OR
708                    isset($_POST['delegataire']) OR
709                        isset($_POST['petitionnaire'])) {
710                if( isset($_POST['petitionnaire_principal']) AND
711                        !empty($_POST['petitionnaire_principal'])) {
712                    $this->postedIdDemandeur['petitionnaire_principal'] = $_POST['petitionnaire_principal'];
713                }
714                if( isset($_POST['delegataire']) AND
715                        !empty($_POST['delegataire'])) {
716                    $this->postedIdDemandeur['delegataire'] = $_POST['delegataire'];
717                }
718                if( isset($_POST['petitionnaire']) AND
719                        !empty($_POST['petitionnaire'])) {
720                    $this->postedIdDemandeur['petitionnaire'] = $_POST['petitionnaire'];
721              }              }
722          }          }
723      }      }
724        /**
725         * Méthode permettant de récupérer les id des demandeur liés à la demande ou
726         * liés au dossier d'autorisation
727         **/
728        function listeDemandeur($from, $id) {
729            // Récupération des demandeurs de la base
730            $sql = "SELECT demandeur.demandeur,
731                            demandeur.type_demandeur,
732                            lien_".$from."_demandeur.petitionnaire_principal
733                FROM ".DB_PREFIXE."lien_".$from."_demandeur
734                INNER JOIN ".DB_PREFIXE."demandeur
735                ON demandeur.demandeur=lien_".$from."_demandeur.demandeur
736                WHERE ".$from." = '".$id."'";
737            $res = $this->f->db->query($sql);
738            $this->f->addToLog("listeDemandeur() : ".$sql);
739            $this->f->isDatabaseError($res);
740            // Stoquage du résultat dans un tableau
741            while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
742                if ($row['petitionnaire_principal'] == 't' AND
743                    $row['type_demandeur']=="petitionnaire") {
744                    $this->valIdDemandeur['petitionnaire_principal']=$row['demandeur'];
745                } elseif ($row['petitionnaire_principal'] == 'f' AND
746                    $row['type_demandeur']=="petitionnaire"){
747                    $this->valIdDemandeur['petitionnaire'][]=$row['demandeur'];
748                } elseif ($row['type_demandeur']=="delegataire"){
749                    $this->valIdDemandeur['delegataire']=$row['demandeur'];
750                }
751            }
752        }
753    
754    
755        /**
756         * Surcharge du bouton retour afin de retourner sur la recherche de dossiers
757         * d'instruction existant
758         */
759        function retour($premier = 0, $recherche = "", $tricol = "") {
760    
761            echo "\n<a class=\"retour\" ";
762            echo "href=\"";
763            //
764            if($this->getParameter("idx_dossier") != "") {
765                echo "tab.php?";
766                echo "obj=recherche_dossier";
767    
768            } else {
769                if($this->getParameter("retour")=="form" AND !($this->getParameter("validation")>0 AND $this->getParameter("maj")==2 AND $this->correct)) {
770                    echo "form.php?";
771                } else {
772                    echo "tab.php?";
773                }
774                echo "obj=".get_class($this);
775                if($this->getParameter("retour")=="form") {
776                    echo "&amp;idx=".$this->getParameter("idx");
777                    echo "&amp;action=3";
778                }
779            }
780            echo "&amp;premier=".$this->getParameter("premier");
781            echo "&amp;tricol=".$this->getParameter("tricol");
782            echo "&amp;recherche=".$this->getParameter("recherche");
783            echo "&amp;selectioncol=".$this->getParameter("selectioncol");
784            echo "&amp;advs_id=".$this->getParameter("advs_id");
785            echo "&amp;valide=".$this->getParameter("valide");
786            //
787            echo "\"";
788            echo ">";
789            //
790            echo _("Retour");
791            //
792            echo "</a>\n";
793    
794        }
795    
796    
797      /**      /**
798       * Ajout de la liste des demandeurs       * Ajout de la liste des demandeurs
799       */       */
800      function formSpecificContent($maj) {      function formSpecificContent($maj) {
801            if(!$this->correct AND $maj != 0) {
802                $this->listeDemandeur("demande", $this->val[array_search('demande', $this->champs)]);
803            }
804            // Si le paramètre idx_dossier est défini on récupère les demandeurs liés au dossier d'instruction
805            if($this->getParameter("idx_dossier") != "") {
806                $this->listeDemandeur("dossier", $this->getParameter("idx_dossier"));
807            }
808            if($maj < 2 AND !$this->correct) {
809                $linkable = true;
810            } else {
811                $linkable = false;
812            }
813    
814          // Conteneur de la listes des demandeurs          // Conteneur de la listes des demandeurs
815          echo "<div class=\"demande_hidden_bloc col_12\">";          echo "<div id=\"liste_demandeur\" class=\"demande_hidden_bloc col_12\">";
816          echo "<fieldset class=\"cadre ui-corner-all ui-widget-content\">";          echo "<fieldset class=\"cadre ui-corner-all ui-widget-content\">";
817          echo "  <legend class=\"ui-corner-all ui-widget-content ui-state-active\">"          echo "  <legend class=\"ui-corner-all ui-widget-content ui-state-active\">"
818                  ._("Petitionnaire")."</legend>";                  ._("Petitionnaire")."</legend>";
819          // Si des demandeurs sont liés à la demande          // Si des demandeurs sont liés à la demande
820          if( count($this->valIdDemandeur) > 0 ) {          require_once "../obj/petitionnaire.class.php";
821            require_once "../obj/delegataire.class.php";
822          } else {          // Affichage du bloc pétitionnaire principal / délégataire
823            // L'ID DU DIV SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
824            echo "<div id=\"petitionnaire_principal_delegataire col_12\">";
825            // Affichage de la synthèse
826            if (isset ($this->valIdDemandeur["petitionnaire_principal"]) AND
827                !empty($this->valIdDemandeur["petitionnaire_principal"])) {
828                $demandeur = new petitionnaire(
829                                    $this->valIdDemandeur["petitionnaire_principal"],
830                                    $this->f->db,false);
831                $demandeur -> afficherSynthese("petitionnaire_principal", $linkable);
832                $demandeur -> __destruct();
833            } elseif ( isset ($this->postedIdDemandeur["petitionnaire_principal"]) AND
834                !empty($this->postedIdDemandeur["petitionnaire_principal"]) ) {
835                $demandeur = new petitionnaire(
836                                    $this->postedIdDemandeur["petitionnaire_principal"],
837                                    $this->f->db,false);
838                $demandeur -> afficherSynthese("petitionnaire_principal", $linkable);
839                $demandeur -> __destruct();
840            }
841            // Si en édition de formulaire
842            if($maj < 2) {
843              // Bouton d'ajout du pétitionnaire principal              // Bouton d'ajout du pétitionnaire principal
844              echo "<input id=\"add_petitionnaire_principal\"              // L'ID DE L'INPUT SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
845                  class=\"ui-button ui-widget ui-state-default ui-corner-all\"              echo "<span id=\"add_petitionnaire_principal\"
846                  type=\"button\" value=\""._("Saisir le petitionnaire principal")."\"/>";                  class=\"om-form-button add-16\">".
847                    _("Saisir le petitionnaire principal").
848                "</span>";
849            }
850            // Bouton d'ajout du delegataire
851            // L'ID DU DIV ET DE L'INPUT SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
852            echo "<div id=\"delegataire\">";
853            // Affichage de la synthèse
854            if (isset ($this->valIdDemandeur["delegataire"]) AND
855                !empty($this->valIdDemandeur["delegataire"])) {
856                $demandeur = new delegataire($this->valIdDemandeur["delegataire"],
857                                           $this->f->db,false);
858                $demandeur -> afficherSynthese("delegataire", $linkable);
859                $demandeur -> __destruct();
860            } elseif ( isset ($this->postedIdDemandeur["delegataire"]) AND
861            !empty($this->postedIdDemandeur["delegataire"]) ) {
862    
863                $demandeur = new delegataire($this->postedIdDemandeur["delegataire"],
864                                           $this->f->db,false);
865                $demandeur -> afficherSynthese("delegataire", $linkable);
866                $demandeur -> __destruct();
867            }
868            if($maj < 2) {
869                echo "<span id=\"add_delegataire\"
870                        class=\"om-form-button add-16\">".
871                        _("Saisir le delegataire").
872                    "</span>";
873          }          }
874            echo "</div>";
875            echo "<div class=\"both\"></div>";
876            echo "</div>";
877            // Bloc des pétitionnaires secondaires
878            // L'ID DU DIV SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
879            echo "<div id=\"listePetitionnaires col_12\">";
880    
881             // Affichage de la synthèse
882            if (isset ($this->valIdDemandeur["petitionnaire"]) AND
883                !empty($this->valIdDemandeur["petitionnaire"])) {
884                
885                foreach ($this->valIdDemandeur["petitionnaire"] as $petitionnaire) {
886                    $demandeur = new petitionnaire($petitionnaire,
887                                           $this->f->db,false);
888                    $demandeur -> afficherSynthese("petitionnaire", $linkable);
889                    $demandeur -> __destruct();
890                }
891                
892            } elseif ( isset ($this->postedIdDemandeur["petitionnaire"]) AND
893                !empty($this->postedIdDemandeur["petitionnaire"]) )  {
894                foreach ($this->postedIdDemandeur["petitionnaire"] as $petitionnaire) {
895                    $demandeur = new petitionnaire($petitionnaire,
896                                           $this->f->db,false);
897                    $demandeur -> afficherSynthese("petitionnaire", $linkable);
898                    $demandeur -> __destruct();
899                }
900            }
901            if ($maj < 2) {
902                // L'ID DE L'INPUT SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
903                echo "<span id=\"add_petitionnaire\"
904                        class=\"om-form-button add-16\">".
905                        _("Ajouter un petitionnaire")
906                    ."</span>";
907            }
908            echo "</div>";
909          echo "</fieldset>";          echo "</fieldset>";
910          echo "</div>";          echo "</div>";
911      }      }
912    
913        // {{{
914    
915        // getter
916        function getValIdDemandeur() {
917            return $this->valIdDemandeur;
918        }
919        // setter
920        function setValIdDemandeur($valIdDemandeur) {
921            $this->valIdDemandeur = $valIdDemandeur;
922        }
923        
924        //Supression du lien entre la demandeur et le(s) demandeur(s)
925        function triggerSupprimer($id, &$db, $val, $DEBUG){
926            
927            //Création de la requête
928            $sql = "DELETE FROM
929                        ".DB_PREFIXE."lien_demande_demandeur
930                    WHERE
931                        demande = $id";
932                  
933            $res = $this->f->db->query($sql);
934            $this->f->addToLog("triggerSupprimer() : ".$sql);
935            $this->f->isDatabaseError($res);
936        }
937        
938        // }}}
939  }// fin classe  }// fin classe
 ?>  
940    ?>

Legend:
Removed from v.808  
changed lines
  Added in v.1282

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26