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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2986 - (hide annotations)
Thu Apr 24 16:15:03 2014 UTC (10 years, 9 months ago) by softime
File size: 77892 byte(s)
- Ajout d'un parametre : insee à la valeur 13055
- Code insee des dossiers d'autorisation ajouté à la création

1 vpihour 632 <?php
2     //$Id$
3     //gen openMairie le 08/11/2012 14:00
4    
5     require_once ("../gen/obj/demande.class.php");
6    
7     class demande extends demande_gen {
8    
9 nhaye 838 var $valIdDemandeur = array("petitionnaire_principal" => "",
10     "delegataire" => "",
11     "petitionnaire" => array());
12     var $postedIdDemandeur = array("petitionnaire_principal" => "",
13     "delegataire" => "",
14     "petitionnaire" => array());
15 nhaye 807
16 nhaye 1333 var $autreDossierEnCour;
17    
18 nhaye 2976 var $cerfa = null;
19    
20 vpihour 632 function demande($id,&$db,$debug) {
21     $this->constructeur($id,$db,$debug);
22     }// fin constructeur
23 fmichon 1005
24     function setValF($val) {
25     parent::setValF($val);
26     // Récupération des id demandeurs postés
27     $this->getPostedValues();
28 nhaye 1020 //$this->valIdDemandeur=$this->postedIdDemandeur;
29 fmichon 1005 }
30    
31     /**
32     * Méthode permettant de récupérer les valeurs du dossier d'autorisation
33 vpihour 1058 * correspondant à la nouvelle demande
34 fmichon 1005 */
35 nhaye 1039 function getValFromDossier($dossier_autorisation) {
36 fmichon 1005 include "../sql/pgsql/demande.form.inc.php";
37     $sql=str_replace("<idx>",$this->getParameter("idx_dossier"),
38 nhaye 1053 $sql_infos_dossier);
39 fmichon 1005 $res = $this->db->query($sql);
40 vpihour 1777 $this->f->addToLog("getValFromDossier(): db->query(\"".$sql."\")", VERBOSE_MODE);
41     if ( database::isError($res)){
42     die();
43     }
44 fmichon 1005 $row = & $res->fetchRow(DB_FETCHMODE_ASSOC);
45     return $row;
46     }
47 vpihour 651
48 vpihour 799 /*
49     * La date du jour par défaut dans le champs date_demande
50     * Put the date of the day by default into the field date_demande
51     */
52 vpihour 635 function setVal(&$form, $maj, $validation, &$db) {
53     if($maj == 0) {
54 fmichon 1005 $form->setVal("date_demande",date('d/m/Y'));
55    
56     // Récupération des valeurs du dossier d'autorisation correspondant
57     if($this->getParameter("idx_dossier") != "") {
58 nhaye 1039 $val_autorisation = $this->getValFromDossier(
59 fmichon 1005 $this->getParameter("idx_dossier"));
60     foreach($val_autorisation as $champ => $value) {
61     $form->setVal($champ,$value);
62     }
63     }
64 vpihour 635 }
65     }
66 nhaye 1404 function getDataSubmit() {
67    
68     $datasubmit = parent::getDataSubmit();
69     if($this->getParameter("idx_dossier") != "") {
70     $datasubmit .= "&idx_dossier=".$this->getParameter("idx_dossier");
71     }
72     return $datasubmit;
73     }
74 vpihour 635
75 nhaye 838 /**
76     * Méthode de verification du contenu
77     */
78     function verifier($val, &$db, $DEBUG) {
79     parent::verifier($val, $db, $DEBUG);
80 vpihour 2606
81 nhaye 838 if(!isset($this->postedIdDemandeur["petitionnaire_principal"]) OR
82 vpihour 2606 empty($this->postedIdDemandeur["petitionnaire_principal"]) AND
83     !is_null($this->form)) {
84 nhaye 838 $this->correct = false;
85 fmichon 1725 $this->addToMessage(_("La saisie d'un petitionnaire principal est obligatoire."));
86 nhaye 838 }
87     }
88 nhaye 1333
89     /**
90     * Configuration des select
91     */
92     function setSelect(&$form, $maj,&$db,$debug) {
93    
94     if(file_exists ("../sql/".$db->phptype."/".$this->table.".form.inc.php"))
95     include ("../sql/".$db->phptype."/".$this->table.".form.inc.php");
96     elseif(file_exists ("../sql/".$db->phptype."/".$this->table.".form.inc"))
97     include ("../sql/".$db->phptype."/".$this->table.".form.inc");
98 softime 2503
99     //
100     $form->setSelect('demande_type', $this->loadSelectDemandeType($form, $maj, $db, $debug, "dossier_autorisation_type_detaille"));
101 atreal 2730
102     // arrondissement
103     $this->init_select($form, $db, $maj, $debug, "arrondissement",
104     $sql_arrondissement, $sql_arrondissement_by_id, false);
105    
106     // dossier_autorisation_type_detaille
107     $this->init_select($form, $db, $maj, $debug, "dossier_autorisation_type_detaille",
108     $sql_dossier_autorisation_type_detaille, $sql_dossier_autorisation_type_detaille_by_id, false);
109    
110 softime 2503 }
111 nhaye 1333
112 softime 2503 /**
113     * Charge le select du champ type de demande
114     * @param object $form Formulaire
115     * @param int $maj Mode d'insertion
116     * @param object $db Database
117     * @param bool $debug Debug active ou pas
118     * @param string $champ champ activant le filtre
119     * @return array Contenu du select
120     */
121     function loadSelectDemandeType(&$form, $maj, &$db, $debug, $champ) {
122 nhaye 1333
123 softime 2503 //
124     if(file_exists ("../sql/".$db->phptype."/".$this->table.".form.inc.php"))
125     include ("../sql/".$db->phptype."/".$this->table.".form.inc.php");
126     elseif(file_exists ("../sql/".$db->phptype."/".$this->table.".form.inc"))
127     include ("../sql/".$db->phptype."/".$this->table.".form.inc");
128 nhaye 1333
129 softime 2503 // Contenu de la liste à choix
130     $contenu=array();
131     $contenu[0][0]='';
132     $contenu[1][0]=_('choisir')."&nbsp;"._("demande_type");
133 nhaye 1857
134 softime 2503 //Récupère l'id du type de dossier d'autorisation détaillé
135     $id_dossier_autorisation_type_detaille = "";
136     if (isset($_POST[$champ])) {
137     $id_dossier_autorisation_type_detaille = $_POST[$champ];
138     } elseif($this->getParameter($champ) != "") {
139     $id_dossier_autorisation_type_detaille = $this->getParameter($champ);
140     } elseif(isset($form->val[$champ])) {
141     $id_dossier_autorisation_type_detaille = $form->val[$champ];
142     }
143 nhaye 1580
144 softime 2503 // Récupération de paramètre pour le rechargement ajax du select
145     $idx_dossier = $this->getParameter("idx_dossier");
146 softime 1997
147 softime 2503 // Récupère l'id de la nature de la demande
148     $id_demande_nature = "1";
149     if (isset($idx_dossier) AND $idx_dossier != "") {
150     $id_demande_nature = '2';
151     }
152 nhaye 1333
153 softime 2503 // Ajout de condition pour la requête
154     $ajout_condition_requête = "";
155     if ($id_demande_nature == '2') {
156     $ajout_condition_requête = " AND dossier.dossier = '".$idx_dossier."'";
157     }
158 nhaye 1333
159 softime 2503 //
160     if ($id_dossier_autorisation_type_detaille != "") {
161     //Si l'id du type de dossier d'autorisation détaillé est renseigné
162     $sql_demande_type_by_dossier_autorisation_type_detaille = str_replace('<idx_dossier_autorisation_type_detaille>', $id_dossier_autorisation_type_detaille, $sql_demande_type_by_dossier_autorisation_type_detaille);
163     // Ajoute une condition sur la nature de la demande
164     $sql_demande_type_by_dossier_autorisation_type_detaille = str_replace('<idx_demande_nature>', $id_demande_nature, $sql_demande_type_by_dossier_autorisation_type_detaille);
165     // Permet d'ajouter une condition
166     $sql_demande_type_by_dossier_autorisation_type_detaille = str_replace('<ajout_condition_requête>', $ajout_condition_requête, $sql_demande_type_by_dossier_autorisation_type_detaille);
167     $res = $this->db->query($sql_demande_type_by_dossier_autorisation_type_detaille);
168     $this->addToLog("db->query(\"".$sql_demande_type_by_dossier_autorisation_type_detaille."\");", VERBOSE_MODE);
169     $this->f->isDatabaseError($res);
170     //Les résultats de la requête sont stocké dans le tableau contenu
171 softime 1997 $k=1;
172 softime 2503 while ($row=& $res->fetchRow()){
173     $contenu[0][$k]=$row[0];
174     $contenu[1][$k]=$row[1];
175 softime 1997 $k++;
176 softime 2503 }
177     }
178 softime 1997
179 softime 2503 // Retourne le contenu de la liste
180     return $contenu;
181 nhaye 1333 }
182 softime 2503
183 vpihour 799 /*
184     * Ajout du fielset
185     * Add fieldset
186     */
187 vpihour 635 function setLayout(&$form, $maj){
188     if ( $maj < 2 OR $maj == 3 ) {
189    
190 vpihour 1058 /*Champ sur lequel s'ouvre le bloc 1 */
191 nhaye 807 $form->setBloc('dossier_autorisation_type_detaille','D',"","dossier_type col_8");
192 vpihour 1058
193 nhaye 807 $form->setFieldset('dossier_autorisation_type_detaille','D'
194     ,_('Type de dossier/demande'));
195     $form->setFieldset('demande_type','F','');
196    
197     $form->setBloc('demande_type','F');
198 vpihour 1058 /*Fin bloc 1*/
199 nhaye 807
200 vpihour 1058 /*Champ sur lequel s'ouvre le bloc 2 */
201 nhaye 807 $form->setBloc('date_demande','D',"","col_4 demande_hidden_bloc");
202     $form->setFieldset('date_demande','D',_('Date de la demande'));
203     $form->setFieldset('date_demande','F','');
204 vpihour 635 $form->setBloc('date_demande','F');
205 vpihour 1058 /*Fin bloc 2*/
206 vpihour 635
207 vpihour 1058 /*Champ sur lequel s'ouvre le bloc 3 */
208 nhaye 807 $form->setBloc('terrain_references_cadastrales','D',"",
209     "localisation col_12 demande_hidden_bloc");
210 vpihour 693 $form->setFieldset('terrain_references_cadastrales','D',_('Localisation du terrain'));
211     $form->setFieldset('terrain_superficie','F','');
212 vpihour 635 $form->setBloc('terrain_superficie','F');
213 vpihour 1058 /*Fin bloc 4*/
214 vpihour 676
215 vpihour 635 }
216     }
217 vpihour 641
218 vpihour 799 /*
219     * Ajoute des actions sur les deux premiers select
220     * Add actions on the two first select
221     */
222 vpihour 641 function setOnchange(&$form,$maj){
223     parent::setOnchange($form,$maj);
224 softime 1997
225 vpihour 641 $form->setOnchange("dossier_autorisation_type_detaille","changeDemandeType();");
226     $form->setOnchange("demande_type","showFormsDemande();");
227     }
228 nhaye 1442
229     function setLib(&$form,$maj) {
230     parent::setLib($form,$maj);
231     //libelle des champs
232    
233 softime 2061 $form->setLib('terrain_adresse_voie',_('terrain_adresse'));
234 nhaye 1442 }
235 vpihour 799 /*
236     * Cache le champ terrain_references_cadastrales
237     * Hide the fiels terrain_references_cadastrales
238     */
239 vpihour 651 function setType(&$form,$maj) {
240     parent::setType($form,$maj);
241    
242 vpihour 689 $form->setType('dossier_instruction', 'hidden');
243     $form->setType('dossier_autorisation', 'hidden');
244 fmichon 1005
245     $form->setType('instruction_recepisse', 'hidden');
246     $form->setType('arrondissement', 'hidden');
247    
248     // Si il s'agit d'une demande sur dossier existant on desactive tous les champs
249     // sauf demande_type
250 nhaye 1100 if(($maj == 0 AND $this-> getParameter("idx_dossier"))) {
251 nhaye 1053 $form->setType('dossier_autorisation_type_detaille', 'selecthiddenstatic');
252 nhaye 1676 $form->setType('terrain_references_cadastrales', 'hiddenstatic');
253 nhaye 1053 $form->setType('terrain_adresse_voie_numero', 'hiddenstatic');
254 softime 2061 $form->setType('terrain_adresse_voie', 'hiddenstatic');
255 nhaye 1053 $form->setType('terrain_adresse_lieu_dit', 'hiddenstatic');
256     $form->setType('terrain_adresse_localite', 'hiddenstatic');
257     $form->setType('terrain_adresse_code_postal', 'hiddenstatic');
258     $form->setType('terrain_adresse_bp', 'hiddenstatic');
259     $form->setType('terrain_adresse_cedex', 'hiddenstatic');
260     $form->setType('terrain_superficie', 'hiddenstatic');
261 fmichon 1005 }
262 nhaye 1100 if($maj == 1) {
263     $form->setType('dossier_autorisation_type_detaille', 'selecthiddenstatic');
264 nhaye 1095 $form->setType('demande_type', 'selecthiddenstatic');
265     }
266 nhaye 1100 if($maj == 3) {
267 nhaye 1101 $form->setType('terrain_references_cadastrales', 'referencescadastralesstatic');
268 nhaye 1100 }
269    
270 vpihour 651 }
271 vpihour 676
272 nhaye 807 /**
273 nhaye 2976 * Permet de recupérer l'identifiant du cerfa du DATD séléctionné
274     * par l'utilisateur.
275     *
276     * @return integer identifiant du cerfa
277 nhaye 920 */
278 nhaye 2976 function getIdCerfa() {
279     if($this->cerfa != null) {
280     return $this->cerfa;
281     }
282     // Récupération du cerfa pour le type d'instruction sélectionnée et valide
283     $sql = "SELECT
284     dossier_autorisation_type_detaille.cerfa
285     FROM
286     ".DB_PREFIXE."dossier_autorisation_type_detaille
287     JOIN
288     ".DB_PREFIXE."cerfa
289     ON
290     dossier_autorisation_type_detaille.cerfa = cerfa.cerfa
291     WHERE
292     now()<=om_validite_fin
293     AND now()>=om_validite_debut
294     AND dossier_autorisation_type_detaille=".
295     $this->valF['dossier_autorisation_type_detaille'];
296     $this->cerfa = $this->db->getOne($sql);
297     $this->f->addToLog(
298     "ajoutDossierInstruction() : db->getone(\"".$sql."\");",
299     VERBOSE_MODE
300     );
301     if ( database::isError($this->cerfa)){
302     return false;
303     }
304     return $this->cerfa;
305     }
306    
307    
308     /**
309     * Méthode permettant d'ajouter un dossier d'autorisation.
310     *
311     * @param integer $id identifiant de la demande
312     * @param database &$db handler de la base de donnée
313     * @param array $val tableau de valeurs postées via le formulaire
314     * @param boolean $DEBUG debug
315     *
316     * @return boolean false si erreur
317     */
318     function ajoutDossierAutorisation($id, &$db, $val, $DEBUG) {
319 nhaye 920 require_once '../obj/dossier_autorisation.class.php';
320 nhaye 2976 $dossier_autorisation = new dossier_autorisation("]", $db, $DEBUG);
321     $id_etat_initial_da =
322     $this->f->getParameter('id_etat_initial_dossier_autorisation');
323 nhaye 1619
324 nhaye 2976 // Vérification de l'existance d'un état initial des DA dans la table
325     // om_parametre afin d'éviter d'eventuelle erreur de base de données
326 nhaye 1606 if(isset($id_etat_initial_da)) {
327     $sql = "SELECT count(*) FROM ".DB_PREFIXE."etat_dossier_autorisation
328     WHERE etat_dossier_autorisation = ".$id_etat_initial_da;
329     $count = $this->db->getOne($sql);
330 nhaye 2976 $this->f->addToLog(
331     "ajoutDossierAutorisation() : db->getOne(\"".$sql."\")",
332     VERBOSE_MODE
333     );
334 vpihour 1777 if ( database::isError($count)){
335 nhaye 2976 return false;
336 vpihour 1777 }
337 nhaye 1606 if($count != 1) {
338 nhaye 2976 return false;
339 nhaye 1606 } else {
340 nhaye 1619 // La méthode ajouter prend en paramètre un tableau associatif
341     // contenant toutes les champs de la classe instanciée,
342 nhaye 2976 // d'où l'initialisation du tableau en bouclant sur la liste des
343     // champs du DA
344 nhaye 1606 foreach($dossier_autorisation->champs as $value) {
345 nhaye 2976 $valAuto[$value] = null;
346 nhaye 1606 }
347 nhaye 1619 // Définition des valeurs à insérer
348 nhaye 1606 $valAuto['dossier_autorisation']="";
349 nhaye 2976 $valAuto['exercice']=null;
350 softime 2986 $valAuto['insee']= $this->f->getParameter("insee");
351 nhaye 2976 $valAuto['arrondissement']=null;
352     $valAuto['etat_dossier_autorisation']=
353     $this->f->getParameter('id_etat_initial_dossier_autorisation');
354     $valAuto['erp_numero_batiment']=null;
355     $valAuto['erp_ouvert']=null;
356     $valAuto['erp_arrete_decision']=null;
357     $valAuto['dossier_autorisation_type_detaille']=
358     $this->valF['dossier_autorisation_type_detaille'];
359     $valAuto['depot_initial']=
360     $this->dateDBToForm($this->valF['date_demande']);
361     $valAuto['terrain_references_cadastrales']=
362     $this->valF['terrain_references_cadastrales'];
363     $valAuto['terrain_adresse_voie_numero']=
364     $this->valF['terrain_adresse_voie_numero'];
365 softime 2061 $valAuto['terrain_adresse_voie']=$this->valF['terrain_adresse_voie'];
366 nhaye 2976 $valAuto['terrain_adresse_lieu_dit']=
367     $this->valF['terrain_adresse_lieu_dit'];
368     $valAuto['terrain_adresse_localite']=
369     $this->valF['terrain_adresse_localite'];
370     $valAuto['terrain_adresse_code_postal']=
371     $this->valF['terrain_adresse_code_postal'];
372 nhaye 1606 $valAuto['terrain_adresse_bp']=$this->valF['terrain_adresse_bp'];
373     $valAuto['terrain_adresse_cedex']=$this->valF['terrain_adresse_cedex'];
374     $valAuto['terrain_superficie']=$this->valF['terrain_superficie'];
375     $valAuto['numero_version']=-1;
376     // Ajout du dossier dans la base
377 nhaye 2976 if($dossier_autorisation->ajouter($valAuto, $db, $DEBUG) === false) {
378     return false;
379     }
380 nhaye 1606 // Liaison du dossier ajouter à la demande
381 nhaye 2976 $this->valF['dossier_autorisation'] =
382     $dossier_autorisation->valF['dossier_autorisation'];
383 nhaye 1606 }
384     } else {
385 nhaye 2976 return false;
386 nhaye 920 }
387 nhaye 1606
388 nhaye 920 }
389    
390     /**
391 nhaye 2976 * Méthode permettant d'ajouter un dossier d'instruction.
392     *
393     * @param integer $id identifiant de la demande
394     * @param database &$db handler de la base de donnée
395     * @param array $val tableau de valeurs postées via
396     * le formulaire
397     * @param boolean $DEBUG debug
398     * @param integer $dossier_instruction_type identifiant du DI type
399     *
400     * @return boolean false si erreur
401 nhaye 920 */
402 nhaye 2976 function ajoutDossierInstruction($id, &$db, $val, $DEBUG, $dossier_instruction_type) {
403 nhaye 920 require_once '../obj/dossier.class.php';
404 nhaye 2976 $dossier = new dossier("]", $db, $DEBUG);
405 nhaye 920 foreach($dossier->champs as $value) {
406 nhaye 2976 $valInstr[$value] = null;
407 nhaye 920 }
408     require_once '../obj/dossier_autorisation_type_detaille.class.php';
409     $datd = new dossier_autorisation_type_detaille(
410 nhaye 2976 $this->valF['dossier_autorisation_type_detaille'],
411     $db,
412     $DEBUG
413     );
414 fmichon 1005
415     /*Ajout de la variable dossier_instruction_type à l'objet dossier pour le
416     * versionning
417     */
418     $dossier->setDossierInstructionType($dossier_instruction_type);
419    
420 nhaye 920 // Définition des valeurs à entrée dans la table
421 nhaye 1186 $valInstr['dossier_instruction_type']=$dossier_instruction_type;
422 nhaye 920 $valInstr['date_depot']=$this->dateDBToForm($this->valF['date_demande']);
423 nhaye 1571 $valInstr['date_dernier_depot']=$this->dateDBToForm($this->valF['date_demande']);
424 nhaye 1037 $valInstr['date_demande']=$this->dateDBToForm($this->valF['date_demande']);
425 nhaye 920 $valInstr['depot_initial']=$this->dateDBToForm($this->valF['date_demande']);
426 nhaye 2976 $valInstr['terrain_references_cadastrales']=
427     $this->valF['terrain_references_cadastrales'];
428     $valInstr['terrain_adresse_voie_numero']=
429     $this->valF['terrain_adresse_voie_numero'];
430 softime 2061 $valInstr['terrain_adresse_voie']=$this->valF['terrain_adresse_voie'];
431 nhaye 920 $valInstr['terrain_adresse_lieu_dit']=$this->valF['terrain_adresse_lieu_dit'];
432     $valInstr['terrain_adresse_localite']=$this->valF['terrain_adresse_localite'];
433 nhaye 2976 $valInstr['terrain_adresse_code_postal']=
434     $this->valF['terrain_adresse_code_postal'];
435 nhaye 920 $valInstr['terrain_adresse_bp']=$this->valF['terrain_adresse_bp'];
436     $valInstr['terrain_adresse_cedex']=$this->valF['terrain_adresse_cedex'];
437     $valInstr['terrain_superficie']=$this->valF['terrain_superficie'];
438     $valInstr['description']="";
439 fmichon 927 $valInstr['dossier_autorisation']=$this->valF['dossier_autorisation'];
440 nhaye 1262
441 vpihour 1273 /*
442     * Gestion de la qualification
443     * */
444 softime 2363 // Initialise le champ à false
445     $valInstr['a_qualifier'] = false;
446    
447     // Récupère l'information depuis le type de la demande
448     $qualification = $this->get_qualification($val['demande_type']);
449    
450     // Si le dossier doit être à qualifier
451     if ($qualification === 't') {
452     // Met le champ à true
453     $valInstr['a_qualifier'] = true;
454 vpihour 1273 }
455    
456 nhaye 2976 if($dossier->ajouter($valInstr, $db, $DEBUG) === false) {
457     return false;
458 vpihour 1777 }
459 vpihour 2302
460     //Affichage de message à l'utilisateur concernant un problème lors de
461 vpihour 2303 //l'affectation de l'instructeur au dossier d'instruction
462 vpihour 2302 if ($dossier->valF['dossier_autorisation'] === '' &&
463 nhaye 2976 $dossier->valF['instructeur'] === null){
464     $this->addToMessage(
465     _("Aucun instructeur compatible avec ce dossier, contactez votre administrateur afin d'en assigner un a ce dossier.")
466     );
467 vpihour 2302 }
468 nhaye 2976 elseif ( $dossier->valF['instructeur'] === null ){
469 vpihour 2302 if ($this->f->isAccredited("dossier_modifier_instructeur")) {
470 nhaye 2976 $this->addToMessage("<br/> ".
471     _("Pensez a assigner un instructeur a ce dossier.")
472     );
473 vpihour 2302 } else {
474 nhaye 2976 $this->addToMessage(
475     _("Aucun instructeur compatible avec ce dossier, contactez votre administrateur afin d'en assigner un a ce dossier.")
476     );
477 vpihour 2302 }
478     }
479    
480 nhaye 920 // Liaison du dossier ajouter à la demande
481     $this->valF['dossier_instruction'] = $dossier->valF['dossier'];
482     }
483    
484     /**
485 nhaye 2976 * Méthode permettant d'ajouter les données techniques d'un DA.
486     *
487     * @param integer $id identifiant de la demande
488     * @param database &$db handler de la base de donnée
489     * @param array $val tableau de valeurs postées via le formulaire
490     * @param boolean $DEBUG debug
491     *
492     * @return boolean false si erreur
493 vpihour 1374 */
494 nhaye 2976 function ajoutDonneesTechniquesDA($id, &$db, $val, $DEBUG) {
495 vpihour 1374
496     require_once '../obj/donnees_techniques.class.php';
497 nhaye 2976 $this->DTDA = new donnees_techniques("]", $db, $DEBUG);
498 vpihour 1374
499 nhaye 2976 // Champs tous à NULL car seul le champ concernant le dossier
500     // d'autorisation sera rempli
501     foreach($this->DTDA->champs as $value) {
502     $val[$value] = null;
503 vpihour 1374 }
504     // Ajout du numéro de dossier d'instruction
505 nhaye 2110 $val['dossier_autorisation']=$this->valF['dossier_autorisation'];
506 nhaye 2976 // Identifiant du cerfa
507     $val['cerfa'] = $this->getIdCerfa();
508 vpihour 1374 // Ajout des données techniques
509 nhaye 2976 if($this->DTDA->ajouter($val, $db, $DEBUG) === false) {
510     return false;
511     }
512 vpihour 1374 }
513    
514     /**
515 nhaye 2976 * Méthode permettant d'ajouter les données techniques d'un DI.
516     *
517     * @param integer $id identifiant de la demande
518     * @param database &$db handler de la base de donnée
519     * @param array $val tableau de valeurs postées via le formulaire
520     * @param boolean $DEBUG debug
521     *
522     * @return boolean false si erreur
523 nhaye 2110 */
524 nhaye 2976 function ajoutDonneesTechniquesDI($id, &$db, $val, $DEBUG) {
525    
526 nhaye 2110 require_once '../obj/donnees_techniques.class.php';
527 nhaye 2976 $this->DTDI = new donnees_techniques(']', $db, $DEBUG);
528 nhaye 2110 // Ajout du numéro de dossier d'instruction
529 nhaye 2976 $this->DTDA->valF['dossier_instruction'] = $this->valF['dossier_instruction'];
530 nhaye 2110 // Suppression du numéro de dossier d'autorisation
531 nhaye 2976 $this->DTDA->valF['dossier_autorisation'] = null;
532     // Identifiant du cerfa
533     $this->DTDA->valF['cerfa'] = $this->getIdCerfa();
534 nhaye 2110 // Ajout des données techniques
535 nhaye 2976 if($this->DTDI->ajouter($this->DTDA->valF, $db, $DEBUG) === false) {
536     return false;
537     }
538 nhaye 2110 }
539    
540     /**
541 vpihour 2038 * Ajout des liens demandeurs / dossier d'autorisation s'ils n'y sont pas déjà
542 nhaye 907 **/
543 nhaye 920 function ajoutLiensDossierAutorisation($id, &$db, $val, $DEBUG) {
544     // Création des liens entre le dossier autorisation et les demandeurs
545 nhaye 907 include '../sql/pgsql/demande.form.inc.php';
546 nhaye 920 require_once '../obj/lien_dossier_autorisation_demandeur.class.php';
547     $ldad = new lien_dossier_autorisation_demandeur("]",$db,$DEBUG);
548     // Recupération des demandeurs liés à la demande
549 vpihour 2038 $sql = str_replace("<demande>",$this->valF['demande'],$sql_lien_demande_demandeur.
550     " AND lien_demande_demandeur.demandeur NOT IN (
551     SELECT lien_dossier_autorisation_demandeur.demandeur
552     FROM ".DB_PREFIXE."lien_dossier_autorisation_demandeur
553     WHERE lien_dossier_autorisation_demandeur.dossier_autorisation =
554     '".$this->valF['dossier_autorisation']."'
555     )");
556 nhaye 920 $res = $db->query($sql);
557 vpihour 1777 $this->f->addToLog("ajoutLiensDossierAutorisation() : db->query(\"".$sql."\");", VERBOSE_MODE);
558     if ( database::isError($res)){
559     die();
560     }
561 nhaye 920 while($row = &$res->fetchRow(DB_FETCHMODE_ASSOC)) {
562     $row['lien_dossier_autorisation_demandeur'] = NULL;
563     $row['dossier_autorisation'] = $this->valF['dossier_autorisation'];
564     $ldad->ajouter($row, $db, $DEBUG);
565     }
566     }
567    
568     /**
569     * Ajout des liens demandeurs / dossier d'autorisation
570     **/
571     function ajoutLiensDossierInstruction($id, &$db, $val, $DEBUG) {
572     // Création des liens entre le dossier instruction et les demandeurs
573     include '../sql/pgsql/demande.form.inc.php';
574     require_once '../obj/lien_dossier_demandeur.class.php';
575     $ldd = new lien_dossier_demandeur("]",$db,$DEBUG);
576     // Recupération des demandeurs liés à la demande
577     $sql = str_replace("<demande>",$this->valF['demande'],$sql_lien_demande_demandeur);
578     $res = $db->query($sql);
579 vpihour 1777 $this->f->addToLog("ajoutLiensDossierInstruction() : db->query(\"".$sql."\");", VERBOSE_MODE);
580     if ( database::isError($res)){
581     die();
582     }
583 nhaye 920 while($row = &$res->fetchRow(DB_FETCHMODE_ASSOC)) {
584     $row['lien_dossier_demandeur'] = NULL;
585     $row['dossier'] = $this->valF['dossier_instruction'];
586     $ldd->ajouter($row, $db, $DEBUG);
587     }
588     }
589    
590 fmichon 1005 /*
591     * Récupère l'identifiant d'un arrondissement à partir d'un code postal
592     */
593     function getArrondissement($terrain_adresse_code_postal){
594    
595     $arrondissement = NULL;
596    
597     $sql = "SELECT
598     arrondissement
599     FROM
600     ".DB_PREFIXE."arrondissement
601     WHERE
602     code_postal = '$terrain_adresse_code_postal' ";
603     $this->addToLog("demande.class.php : ".$sql." execute <br>", EXTRA_VERBOSE_MODE);
604    
605     $res = $this->db->query($sql);
606 vpihour 1777 $this->f->addToLog("getArrondissement() : db->query(\"".$sql."\")", VERBOSE_MODE);
607     if ( database::isError($res)){
608     die();
609     }
610 fmichon 1005
611     if( $res->numrows() > 0 ) {
612    
613     $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);
614     $arrondissement = $row['arrondissement'];
615     }
616    
617     return $arrondissement;
618     }
619    
620     /*
621     * Récupère l'évènement lié à un type de demande
622     */
623     function getEvenement($demande_type){
624    
625 nhaye 2977 $evenement = null;
626 fmichon 1005
627     $sql =
628     "SELECT
629     evenement
630     FROM
631     ".DB_PREFIXE."demande_type
632     WHERE
633     demande_type = $demande_type";
634    
635     $res = $this->db->query($sql);
636 vpihour 1777 $this->f->addToLog("getEvenement() : db->query(\"".$sql."\")", VERBOSE_MODE);
637     if ( database::isError($res)){
638     die();
639     }
640 fmichon 1005
641     if ( $res->numrows() > 0 ){
642    
643     $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);
644     $evenement = $row['evenement'];
645     }
646    
647     return $evenement;
648     }
649    
650 vpihour 2450
651 softime 2112
652     /**
653     * Retourne le libellé du dossier d'autorisation
654     * @param string $dossier_autorisation Identifiant du dossier d'autorisation
655     * @return string Libellé dossier d'autorisation
656     */
657     function get_dossier_autorisation_libelle($dossier_autorisation) {
658    
659     $dossier_autorisation_libelle = "";
660    
661     // Requête SQL
662     $sql = "SELECT
663     dossier_autorisation_libelle
664     FROM
665     ".DB_PREFIXE."dossier_autorisation
666     WHERE
667     dossier_autorisation = '$dossier_autorisation'";
668    
669     $dossier_autorisation_libelle = $this->db->getOne($sql);
670     $this->addToLog("get_dossier_autorisation_libelle(): db->getOne(\"".$sql."\")", VERBOSE_MODE);
671     database::isError($dossier_autorisation_libelle);
672    
673     // Retourne le résultat
674     return $dossier_autorisation_libelle;
675     }
676    
677     /**
678 nhaye 2977 * Retourne le libellé du dossier d'autorisation.
679     * @param string $dossier Identifiant du dossier d'autorisation
680     *
681 softime 2112 * @return string Libellé dossier d'autorisation
682     */
683     function get_dossier_libelle($dossier) {
684    
685     $dossier_libelle = "";
686    
687     // Requête SQL
688     $sql = "SELECT
689     dossier_libelle
690     FROM
691     ".DB_PREFIXE."dossier
692     WHERE
693     dossier = '$dossier'";
694    
695 nhaye 2977 $dossier_libelle = $this->db->getOne($sql);
696 softime 2112 $this->addToLog("get_dossier_libelle(): db->getOne(\"".$sql."\")", VERBOSE_MODE);
697     database::isError($dossier_libelle);
698    
699     // Retourne le résultat
700     return $dossier_libelle;
701     }
702 fmichon 1005
703 nhaye 920 /**
704     * Ajout des dossiers
705     **/
706     function triggerAjouter($id, &$db, $val, $DEBUG){
707 softime 2071
708 nhaye 920 include '../sql/pgsql/demande.form.inc.php';
709 softime 2071
710 nhaye 2976 if($this->valF["demande_type"] != null) {
711     $res = $db->query(
712     str_replace(
713     '<idx>',
714     $this->valF['demande_type'],
715     $sql_demande_type_details_by_id
716     )
717     );
718     $this->f->addToLog(
719     "triggerAjouter() : db->query(\"".
720     str_replace(
721     '<idx>',
722     $this->valF['demande_type'],
723     $sql_demande_type_details_by_id
724     )."\")",
725     VERBOSE_MODE
726     );
727 vpihour 1777 if ( database::isError($res)){
728     die();
729     }
730 nhaye 1808 // Attribut permettant de définir si un dossier a été créé
731 nhaye 2976 $this->ajoutDI = false;
732 nhaye 920 $dossier_type = $res->fetchRow(DB_FETCHMODE_ASSOC);
733 nhaye 907 // Création du dossier_autorisation
734 nhaye 1054 if($this->valF['dossier_autorisation'] == "") {
735 nhaye 2976 if($this->ajoutDossierAutorisation($id, $db, $val, $DEBUG) === false) {
736     $this -> addToMessage(
737     _("Erreur lors de l'enregistrement de la demande.")." ".
738     _("Contactez votre administrateur.")
739     );
740     $this->correct = false;
741     return false;
742     }
743     $this -> addToMessage(
744     _("Creation du dossier d'autorisation no").
745     $this->get_dossier_autorisation_libelle(
746     $this->valF['dossier_autorisation']
747     )
748     );
749 nhaye 2110 //Ajout des données techniques au dossier d'autorisation
750 nhaye 2976 if($this->ajoutDonneesTechniquesDA($id, $db, $val, $DEBUG) === false) {
751     $this -> addToMessage(
752     _("Erreur lors de l'enregistrement de la demande.")." ".
753     _("Contactez votre administrateur.")
754     );
755     $this->correct = false;
756     return false;
757     }
758 nhaye 2977 } else {
759     $sqlIdDTDA = "SELECT donnees_techniques
760     FROM ".DB_PREFIXE."donnees_techniques
761     WHERE dossier_autorisation='".
762     $this->valF['dossier_autorisation']."'";
763     $idDTDA = $this->db->getOne($sqlIdDTDA);
764     $this->addToLog(
765     "triggerAjouter(): db->getOne(\"".$sqlIdDTDA."\")",
766     VERBOSE_MODE
767     );
768     database::isError($idDTDA);
769     require_once '../obj/donnees_techniques.class.php';
770     $this->DTDA = new donnees_techniques(
771     $idDTDA,
772     $db,
773     $DEBUG
774     );
775     $this->DTDA->setValFFromVal();
776 nhaye 907 }
777 nhaye 2976 // Enregistrement du numéro dossier existant
778     // (il sera écrasé si un DI est créé)
779 nhaye 1808 if ($this->getParameter("idx_dossier") != "") {
780     $this->valF['dossier_instruction'] = $this->getParameter("idx_dossier");
781     }
782 nhaye 920 // Création du dossier d'instruction
783 nhaye 2976 if($dossier_type['dossier_instruction_type'] != null) {
784     if($this->ajoutDossierInstruction(
785     $id,
786     $db,
787     $val,
788     $DEBUG,
789     $dossier_type['dossier_instruction_type']
790     ) === false ) {
791     $this -> addToMessage(
792     _("Erreur lors de l'enregistrement de la demande.")." ".
793     _("Contactez votre administrateur.")
794     );
795     $this->correct = false;
796     return false;
797     }
798     $this -> addToMessage(
799     _("Creation du dossier d'instruction no").
800     $this->get_dossier_libelle($this->valF['dossier_instruction'])
801     );
802 nhaye 1808 // Attribut permettant de définir si un dossier a été créé.
803 nhaye 2976 $this->ajoutDI = true;
804 vpihour 1374
805     //Ajout des données techniques au dossier d'instruction
806 nhaye 2976 if($this->ajoutDonneesTechniquesDI($id, $db, $val, $DEBUG) === false){
807    
808     $this -> addToMessage(
809     _("Erreur lors de l'enregistrement de la demande.")." ".
810     _("Contactez votre administrateur.")
811     );
812     $this->correct = false;
813     return false;
814    
815     }
816 nhaye 907 }
817 softime 2071
818     // Si le dossier_instruction existe
819     if (isset($this->valF['dossier_instruction']) && $this->valF['dossier_instruction'] !== "" ) {
820 softime 2369
821 softime 2071 // Récupère les informations nécessaire pour créer le répertoire de numérisation
822     $getInfosForFoldername = $this->getInfosForFoldername($this->valF['dossier_instruction']);
823 softime 2369
824 softime 2071 // Création du répertoire pour la numérisation
825 softime 2369 $createFolder = $this->createFolder($getInfosForFoldername['dossier_autorisation'], $getInfosForFoldername['code'], $getInfosForFoldername['version']);
826    
827     // Si la création a échouée
828     if ($createFolder === false) {
829    
830     // Annule la validation
831 softime 2071 $this->correct = false;
832     // arrête le traitement entier
833     return false;
834 softime 2369
835     //
836     } else {
837    
838     //
839     $this->addToLog("createFolder() : Success", VERBOSE_MODE);
840 softime 2071 }
841     }
842 fmichon 1005
843     /*Ajout de l'arrondissement à partir du code postal*/
844     if ( !is_null($this->valF["terrain_adresse_code_postal"]) && is_numeric($this->valF["terrain_adresse_code_postal"]) ){
845    
846     $this->valF["arrondissement"] = $this->getArrondissement($this->valF["terrain_adresse_code_postal"]);
847     }
848 nhaye 907 }
849     }
850    
851     /**
852 nhaye 828 * Ajout des délégataires et pétitionnaires
853 nhaye 807 **/
854 nhaye 828 function triggerAjouterApres($id, &$db, $val, $DEBUG){
855 softime 2071
856 nhaye 828 $this->insertLinkDemandeDemandeur($db, $DEBUG);
857 fmichon 1005
858 nhaye 920 // Ajout des lliens entre dossier_autorisation et demandeur
859 vpihour 2038 if(!empty($this->valF['dossier_autorisation'])) {
860 nhaye 920 $this->ajoutLiensDossierAutorisation($id, $db, $val, $DEBUG);
861     }
862     // Ajout des lliens entre dossier et demandeur
863 nhaye 1808 if($this->ajoutDI === TRUE) {
864 nhaye 920 $this->ajoutLiensDossierInstruction($id, $db, $val, $DEBUG);
865     }
866 nhaye 1246
867 nhaye 2110 // Duplication des lots (et leurs données techniques) et
868     // liaison au nouveau dossier_d'instruction
869 nhaye 1246 if(!empty($this->valF['dossier_autorisation']) AND $val['dossier_autorisation'] != "" ) {
870     $this->lienLotDossierInstruction($id, $db, $val, $DEBUG);
871     }
872 nmeucci 2889
873     /*Création du lien de téléchargement de récépissé de demande*/
874     if ( $this->valF['demande_type'] != "" && is_numeric($this->valF['demande_type'])
875     && isset($this->valF['dossier_instruction']) && $this->valF['dossier_instruction'] !== "" ){
876    
877     /*Récupérer l'événement lié à ce type de demande*/
878     $evenement = $this->getEvenement($this->valF['demande_type']);
879    
880     /*Récupération de la lettre type de l'événement*/
881     $lettretype = $this->f->getLettreType($evenement);
882    
883     /*Création d'une nouvelle instruction avec cet événement*/
884     /*Données*/
885     $valInstr['instruction']=NULL;
886    
887     $valInstr['destinataire']=$this->valF['dossier_instruction'];
888     $valInstr['dossier']=$this->valF['dossier_instruction'];
889     // Récupère la date de la demande
890     $valInstr['date_evenement']=$this->dateDBToForm($this->valF['date_demande']);
891     $valInstr['evenement']=$evenement;
892     $valInstr['lettretype']=$lettretype;
893     $valInstr['complement_om_html']="";
894     $valInstr['complement2_om_html']="";
895    
896     $valInstr['action']="initialisation";
897     $valInstr['delai']="2";
898     $valInstr['etat']="notifier";
899     $valInstr['accord_tacite']="Oui";
900     $valInstr['delai_notification']="1";
901     $valInstr['archive_delai']="0";
902     $valInstr['archive_date_complet']=NULL;
903     $valInstr['archive_date_dernier_depot']=NULL;
904     $valInstr['archive_date_rejet']=NULL;
905     $valInstr['archive_date_limite']=NULL;
906     $valInstr['archive_date_notification_delai']=NULL;
907     $valInstr['archive_accord_tacite']="Non";
908     $valInstr['archive_etat']="initialiser";
909     $valInstr['archive_date_decision']=NULL;
910     $valInstr['archive_avis']="";
911     $valInstr['archive_date_validite']=NULL;
912     $valInstr['archive_date_achevement']=NULL;
913     $valInstr['archive_date_chantier']=NULL;
914     $valInstr['archive_date_conformite']=NULL;
915     $valInstr['archive_incompletude']=NULL;
916     $valInstr['archive_evenement_suivant_tacite']="";
917     $valInstr['archive_evenement_suivant_tacite_incompletude']=NULL;
918     $valInstr['archive_etat_pendant_incompletude']=NULL;
919     $valInstr['archive_date_limite_incompletude']=NULL;
920     $valInstr['archive_delai_incompletude']=NULL;
921     $valInstr['archive_autorite_competente']=NULL;
922     $valInstr['complement3_om_html']="";
923     $valInstr['complement4_om_html']="";
924     $valInstr['complement5_om_html']="";
925     $valInstr['complement6_om_html']="";
926     $valInstr['complement7_om_html']="";
927     $valInstr['complement8_om_html']="";
928     $valInstr['complement9_om_html']="";
929     $valInstr['complement10_om_html']="";
930     $valInstr['complement11_om_html']="";
931     $valInstr['complement12_om_html']="";
932     $valInstr['complement13_om_html']="";
933     $valInstr['complement14_om_html']="";
934     $valInstr['complement15_om_html']="";
935     $valInstr['avis_decision']=NULL;
936     $valInstr['date_finalisation_courrier']=NULL;
937     $valInstr['date_envoi_signature']=NULL;
938     $valInstr['date_retour_signature']=NULL;
939     $valInstr['date_envoi_rar']=NULL;
940     $valInstr['date_retour_rar']=NULL;
941     $valInstr['date_envoi_controle_legalite']=NULL;
942     $valInstr['date_retour_controle_legalite']=NULL;
943     $valInstr['signataire_arrete']=NULL;
944     $valInstr['numero_arrete']=NULL;
945     $valInstr['code_barres']=NULL;
946     $valInstr['om_fichier_instruction']=NULL;
947     $valInstr['om_final_instruction']=NULL;
948     $valInstr['document_numerise']=NULL;
949     $valInstr['autorite_competente']=NULL;
950     $valInstr['duree_validite_parametrage']="0";
951     $valInstr['duree_validite']="0";
952    
953     //Récupération des champs archive si cette demande a créée un dossier
954     //d'instruction mais pas un P0
955     if (!is_null($this->valF['dossier_instruction']) &&
956     $this->valF['dossier_instruction'] !== "" ){
957    
958     //Requête
959     $sql = "SELECT dossier_instruction_type.code
960     FROM ".DB_PREFIXE."demande_type
961     LEFT JOIN ".DB_PREFIXE."dossier_instruction_type
962     ON demande_type.dossier_instruction_type = dossier_instruction_type.dossier_instruction_type
963     WHERE demande_type.demande_type = ".$this->valF['demande_type'];
964     $res = $db->getOne($sql);
965     $this->addToLog("triggerajouter(): db->getOne(\"".$sql."\");", VERBOSE_MODE);
966     if (database::isError($res)) {
967     die($res->getMessage());
968     }
969    
970     //On vérifie que ce n'est pas un P0
971     if ( strcmp($res, "P") !== 0 ){
972    
973     $res = $this->getArchiveInstruction($this->valF['dossier_instruction']);
974    
975     if (isset($res['archive_delai'])) {
976     $valInstr['archive_delai']=$res["archive_delai"];
977     }
978     if (isset($res['archive_date_complet'])) {
979     $valInstr['archive_date_complet']=$res["archive_date_complet"];
980     }
981     if (isset($res['archive_date_dernier_depot'])) {
982     $valInstr['archive_date_dernier_depot']=$res["archive_date_dernier_depot"];
983     }
984     if (isset($res['archive_date_rejet'])) {
985     $valInstr['archive_date_rejet']=$res["archive_date_rejet"];
986     }
987     if (isset($res['archive_date_limite'])) {
988     $valInstr['archive_date_limite']=$res["archive_date_limite"];
989     }
990     if (isset($res['archive_date_notification_delai'])) {
991     $valInstr['archive_date_notification_delai']=$res["archive_date_notification_delai"];
992     }
993     if (isset($res['archive_accord_tacite'])) {
994     $valInstr['archive_accord_tacite']=$res["archive_accord_tacite"];
995     }
996     if (isset($res['archive_etat'])) {
997     $valInstr['archive_etat']=$res["archive_etat"];
998     }
999     if (isset($res['archive_date_decision'])) {
1000     $valInstr['archive_date_decision']=$res["archive_date_decision"];
1001     }
1002     if (isset($res['archive_avis'])) {
1003     $valInstr['archive_avis']=$res["archive_avis"];
1004     }
1005     if (isset($res['archive_date_validite'])) {
1006     $valInstr['archive_date_validite']=$res["archive_date_validite"];
1007     }
1008     if (isset($res['archive_date_achevement'])) {
1009     $valInstr['archive_date_achevement']=$res["archive_date_achevement"];
1010     }
1011     if (isset($res['archive_date_chantier'])) {
1012     $valInstr['archive_date_chantier']=$res["archive_date_chantier"];
1013     }
1014     if (isset($res['archive_date_conformite'])) {
1015     $valInstr['archive_date_conformite']=$res["archive_date_conformite"];
1016     }
1017     if (isset($res['archive_incompletude'])) {
1018     $valInstr['archive_incompletude']=$res["archive_incompletude"];
1019     }
1020     if (isset($res['archive_evenement_suivant_tacite'])) {
1021     $valInstr['archive_evenement_suivant_tacite']=$res["archive_evenement_suivant_tacite"];
1022     }
1023     if (isset($res['archive_evenement_suivant_tacite_incompletude'])) {
1024     $valInstr['archive_evenement_suivant_tacite_incompletude']=$res["archive_evenement_suivant_tacite_incompletude"];
1025     }
1026     if (isset($res['archive_etat_pendant_incompletude'])) {
1027     $valInstr['archive_etat_pendant_incompletude']=$res["archive_etat_pendant_incompletude"];
1028     }
1029     if (isset($res['archive_date_limite_incompletude'])) {
1030     $valInstr['archive_date_limite_incompletude']=$res["archive_date_limite_incompletude"];
1031     }
1032     if (isset($res['archive_delai_incompletude'])) {
1033     $valInstr['archive_delai_incompletude']=$res["archive_delai_incompletude"];
1034     }
1035     if (isset($res['archive_autorite_competente'])) {
1036     $valInstr['archive_autorite_competente']=$res["archive_autorite_competente"];
1037     }
1038     }
1039     }
1040    
1041     /*Fichier requis*/
1042     require_once '../obj/instruction.class.php';
1043    
1044     /*Création d'un nouveau dossier*/
1045     $instruction = new instruction("]",$db,$DEBUG);
1046     $instruction->valF = "";
1047     $instruction->ajouter($valInstr, $db, $DEBUG);
1048    
1049     //Finalisation du document
1050     $_GET['obj']='instruction';
1051     $_GET['idx']=$instruction->valF[$instruction->clePrimaire];
1052     $instruction_final = new instruction($_GET['idx'],$db,$DEBUG);
1053     if($instruction_final->getVal('lettretype') != "") {
1054     $res = $instruction_final->finaliser('', 1, '', '');
1055     }
1056    
1057     /*Si la création de l'instruction a réussie*/
1058     if ( $instruction->valF['instruction'] != "" ){
1059    
1060     /*Affichage du récépissé de la demande*/
1061     $this->valF['instruction_recepisse'] = $instruction->valF['instruction'];
1062     $this -> addToMessage("<br/><a
1063     class='lien'
1064     href='"
1065     .((isset($res['pdf'])&&$instruction->valF['om_final_instruction'])?$res['pdf']:
1066     "../pdf/pdflettretype.php?obj=".$lettretype."&amp;idx=".$instruction->valF['instruction'])."'
1067     target='_blank'>
1068     <span
1069     class=\"om-icon om-icon-16 om-icon-fix pdf-16\"
1070     title=\""._("Telecharger le recepisse de la demande")."\">".
1071     _("Telecharger le recepisse de la demande").
1072     "</span>
1073     &nbsp;&nbsp;&nbsp;&nbsp;".
1074     _("Telecharger le recepisse de la demande")."
1075     </a><br/>");
1076     }
1077     /*Sinon affiche un message d'erreur*/
1078     else {
1079    
1080     $this -> addToMessage(_("Une erreur s'est produite lors de la creation du recepisse"));
1081     }
1082     }
1083 nhaye 828 }
1084 vpihour 1058
1085     /*Ajout du lien demande / demandeur(s)*/
1086 nhaye 828 function triggerModifierApres($id, &$db, $val, $DEBUG){
1087 nhaye 1039 $this->listeDemandeur("demande",$this->val[array_search('demande', $this->champs)]);
1088 nhaye 828 $this->insertLinkDemandeDemandeur($db, $DEBUG);
1089 nhaye 838 $this->valIdDemandeur=$this->postedIdDemandeur;
1090 nhaye 828
1091     }
1092    
1093     /**
1094 nhaye 1246 * Gestion des liens entre les lots du DA et le nouveau dossier
1095     **/
1096     function lienLotDossierInstruction($id, $db, $val, $DEBUG) {
1097     require_once ("../obj/lot.class.php");
1098     $lot = new lot("]", $db, $DEBUG);
1099     require_once ("../obj/lien_lot_demandeur.class.php");
1100     $lld = new lien_lot_demandeur("]", $db, $DEBUG);
1101    
1102    
1103     $sqlLots = "SELECT * FROM ".DB_PREFIXE."lot
1104     WHERE dossier_autorisation = '".$this->valF['dossier_autorisation']."'";
1105     $resLot = $db -> query($sqlLots);
1106     $this->f->addToLog("db->query(\"".$sqlLots."\");", VERBOSE_MODE);
1107     $this->f->isDatabaseError($resLot);
1108     while ($rowLot=& $resLot->fetchRow(DB_FETCHMODE_ASSOC)){
1109     // Insertion du nouveau lot
1110     $valLot['lot'] = "";
1111     $valLot['libelle'] = $rowLot['libelle'];
1112 nhaye 2976 $valLot['dossier_autorisation'] = null;
1113 nhaye 2082 $valLot['dossier'] = $this->valF['dossier_instruction'];
1114 nhaye 1246 $lot -> ajouter($valLot, $db, $DEBUG);
1115 nhaye 1247
1116 nhaye 1246 //Insertion des liens entre dossier et les lots
1117     $sqlDemandeurs = "SELECT * FROM ".DB_PREFIXE."lien_lot_demandeur
1118     WHERE lot = ".$rowLot['lot'];
1119     $res = $db -> query($sqlDemandeurs);
1120 nhaye 2976 $this->f->addToLog(
1121     "lienLotDossierInstruction() : db->query(\"".$sqlDemandeurs."\");",
1122     VERBOSE_MODE
1123     );
1124 vpihour 1777 if ( database::isError($res)){
1125     die();
1126     }
1127 nhaye 1246
1128     while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
1129     $valLld["lien_lot_demandeur"] = "";
1130     $valLld["lot"]=$lot->valF['lot'];
1131     $valLld["demandeur"] = $row['demandeur'];
1132     $valLld["petitionnaire_principal"] = $row['petitionnaire_principal'];
1133     $lld->ajouter($valLld, $db, $DEBUG);
1134     }
1135 nhaye 2110
1136     // Récupération des données techniques du nouveau lots
1137 nhaye 2976 if($this->ajoutDonneesTechniquesLots(
1138     $id,
1139     $db,
1140     $val,
1141     $DEBUG,
1142     $rowLot['lot'],
1143     $lot->valF['lot']) === false) {
1144     $this -> addToMessage(
1145     _("Erreur lors de l'enregistrement de la demande.")." ".
1146     _("Contactez votre administrateur.")
1147     );
1148     $this->correct = false;
1149     return false;
1150     }
1151 nhaye 2110
1152 nhaye 1246 }
1153     }
1154    
1155 nhaye 2110
1156 nhaye 1246 /**
1157 nhaye 2976 * Méthode permettant d'ajouter les données techniques d'un lot.
1158     *
1159     * @param integer $id identifiant de la demande
1160     * @param database &$db handler de la base de donnée
1161     * @param array $val tableau de valeurs postées via le formulaire
1162     * @param boolean $DEBUG debug
1163     * @param integer $lotInit identifiant de lot initial
1164     * @param integer $lotDest identifiant du lot qui va recevoir les données
1165     *
1166     * @return boolean false si erreur
1167 nhaye 2110 */
1168 nhaye 2976 function ajoutDonneesTechniquesLots($id, &$db, $val, $DEBUG, $lotInit, $lotDest) {
1169     // Requete permettant de recupérer les données techniques du lot passé
1170     // en paramètre ($lotInit)
1171     $sql_get_dt = "
1172     SELECT donnees_techniques
1173     FROM ".DB_PREFIXE."donnees_techniques
1174     WHERE lot=".$lotInit;
1175 nhaye 2110 $id_dt = $this->f->db->getOne($sql_get_dt);
1176 nhaye 2976 // Si des données techniques sont liées au lots on les "copie" et
1177     // on les lies au lot passé en paramètre (lotDest)
1178     if(isset($id_dt) and !empty($id_dt)) {
1179     $this->f->addToLog(
1180     "ajoutDonneesTechniquesLots() : db->getone(\"".$sql_get_dt."\");",
1181     VERBOSE_MODE
1182     );
1183 nhaye 2110 if ( database::isError($id_dt)){
1184     // Appel de la methode de recuperation des erreurs
1185     $this->erreur_db($id_dt->getDebugInfo(), $id_dt->getMessage(), '');
1186     return false;
1187     }
1188     require_once '../obj/donnees_techniques.class.php';
1189 nhaye 2976 $donnees_techniques = new donnees_techniques($id_dt, $db, $DEBUG);
1190 nhaye 2110
1191     // Récupération des données dans le tableau des valeurs à insérer
1192     foreach($donnees_techniques->champs as $value) {
1193     $val[$value] = $donnees_techniques->getVal($value);
1194     }
1195     // Modification du lien vers le nouveau lot
1196     $val["lot"] = $lotDest;
1197 nhaye 2976 // Identifiant du cerfa
1198     $val['cerfa'] = $this->getIdCerfa();
1199 nhaye 2110 // Ajout des données techniques
1200 nhaye 2976 if($donnees_techniques->ajouter($val, $db, $DEBUG) === false) {
1201     return false;
1202     }
1203 nhaye 2110 }
1204     }
1205    
1206     /**
1207 vpihour 1058 * Gestion des liens entre la demande et les demandeurs recemment ajoutés
1208 nhaye 828 **/
1209     function insertLinkDemandeDemandeur($db, $DEBUG) {
1210     //
1211     require_once "../obj/lien_demande_demandeur.class.php";
1212 nhaye 838 // Comparaison de l'id petitionnaire principal
1213     if(isset($this->postedIdDemandeur['petitionnaire_principal']) AND
1214     !empty($this->postedIdDemandeur['petitionnaire_principal']) AND
1215     $this->valIdDemandeur['petitionnaire_principal'] !=
1216     $this->postedIdDemandeur['petitionnaire_principal']) {
1217     // Ajout du nouveau lien
1218     $this->addLinkDemandeDemandeur($this->postedIdDemandeur['petitionnaire_principal'], true, $db, $DEBUG);
1219     if(!empty($this->valIdDemandeur['petitionnaire_principal'])) {
1220     $this->deleteLinkDemandeDemandeur($this->valIdDemandeur['petitionnaire_principal'], $db, $DEBUG);
1221 nhaye 807 }
1222 nhaye 828 }
1223 nhaye 838
1224     // Comparaison du delegataire
1225     if(isset($this->postedIdDemandeur['delegataire']) AND
1226     !empty($this->postedIdDemandeur['delegataire']) AND
1227     $this->valIdDemandeur['delegataire'] !=
1228     $this->postedIdDemandeur['delegataire']) {
1229     // Ajout du nouveau lien
1230     $this->addLinkDemandeDemandeur($this->postedIdDemandeur['delegataire'], false, $db, $DEBUG);
1231     if(!empty($this->valIdDemandeur['delegataire'])) {
1232     $this->deleteLinkDemandeDemandeur($this->valIdDemandeur['delegataire'], $db, $DEBUG);
1233     }
1234     }
1235    
1236     // Comparaison des different petitionnaires
1237     if(isset($this->postedIdDemandeur['petitionnaire'])) {
1238     // Suppression des liens non valides
1239     foreach ($this->valIdDemandeur['petitionnaire'] as $petitionnaire) {
1240     if(!in_array($petitionnaire, $this->postedIdDemandeur['petitionnaire'])) {
1241     $this->deleteLinkDemandeDemandeur($petitionnaire, $db, $DEBUG);
1242     }
1243     }
1244     // Ajout des nouveaux liens
1245     foreach ($this->postedIdDemandeur['petitionnaire'] as $petitionnaire) {
1246     if(!in_array($petitionnaire, $this->valIdDemandeur['petitionnaire'])) {
1247     $this->addLinkDemandeDemandeur($petitionnaire, false, $db, $DEBUG);
1248     }
1249     }
1250     }
1251     }
1252    
1253    
1254     /**
1255     * Fonction permettant d'ajouter un lien
1256     * entre la table demande et demandeur
1257     **/
1258     function addLinkDemandeDemandeur($id, $principal, $db, $DEBUG) {
1259     $lienAjout = new lien_demande_demandeur(
1260     "]",
1261     $db,
1262     $DEBUG);
1263     $lien = array('lien_demande_demandeur' => "",
1264     'petitionnaire_principal' => (($principal)?"t":"f"),
1265     'demande' => $this->valF['demande'],
1266     'demandeur' => $id);
1267     $lienAjout->ajouter($lien, $db, $DEBUG);
1268     $lienAjout->__destruct();
1269     }
1270    
1271     /**
1272     * Fonction permettant de supprimer un lien
1273     * entre la table demande et demandeur
1274     **/
1275     function deleteLinkDemandeDemandeur($id, $db, $DEBUG) {
1276     // Suppression
1277     $sql = "DELETE FROM ".DB_PREFIXE."lien_demande_demandeur ".
1278     "WHERE demande=".$this->valF['demande'].
1279     " AND demandeur=".$id;
1280     // Execution de la requete de suppression de l'objet
1281     $res = $db->query($sql);
1282     // Logger
1283 vpihour 1777 $this->f->addToLog("deleteLinkDemandeDemandeur(): db->query(\"".$sql."\");", VERBOSE_MODE);
1284     if ( database::isError($res)){
1285     die();
1286     }
1287 nhaye 838
1288     }
1289    
1290 vpihour 1058 /*
1291     * Teste si le lien entre une demande et un demandeur existe
1292     * */
1293 nhaye 838 function isLinkDemandeDemandeurExist($idDemandeur) {
1294     $sql = "SELECT count(*)
1295     FROM ".DB_PREFIXE."lien_demande_demandeur
1296     WHERE demande = ".$this->valF['demande'].
1297     "AND demandeur = ".$idDemandeur;
1298     $count = $this->f->db->getOne($sql);
1299 vpihour 1777 $this->f->addToLog("isLinkDemandeDemandeurExist() : db->getone(\"".$sql."\");", VERBOSE_MODE);
1300     if ( database::isError($count)){
1301     die();
1302     }
1303 nhaye 838 if ($count === 0) {
1304     return false;
1305 nhaye 828 } else {
1306 nhaye 838 return true;
1307 nhaye 828 }
1308 nhaye 838
1309 nhaye 828 }
1310    
1311     /**
1312     * Methode de recupération des valeurs postées
1313     **/
1314     function getPostedValues() {
1315     // Récupération des demandeurs dans POST
1316     if (isset($_POST['petitionnaire_principal']) OR
1317     isset($_POST['delegataire']) OR
1318     isset($_POST['petitionnaire'])) {
1319     if( isset($_POST['petitionnaire_principal']) AND
1320     !empty($_POST['petitionnaire_principal'])) {
1321 nhaye 838 $this->postedIdDemandeur['petitionnaire_principal'] = $_POST['petitionnaire_principal'];
1322 nhaye 807 }
1323 nhaye 828 if( isset($_POST['delegataire']) AND
1324     !empty($_POST['delegataire'])) {
1325 nhaye 838 $this->postedIdDemandeur['delegataire'] = $_POST['delegataire'];
1326 nhaye 828 }
1327     if( isset($_POST['petitionnaire']) AND
1328     !empty($_POST['petitionnaire'])) {
1329 nhaye 838 $this->postedIdDemandeur['petitionnaire'] = $_POST['petitionnaire'];
1330 nhaye 828 }
1331 nhaye 807 }
1332 vpihour 676 }
1333 fmichon 1713
1334 nhaye 828 /**
1335 fmichon 1713 * Méthode permettant de récupérer les id des demandeurs liés à la table
1336     * liée passée en paramètre
1337     *
1338     * @param string $from Table liée : "demande", "dossier", dossier_autorisation"
1339     * @param string $id Identifiant (clé primaire de la table liée en question)
1340     */
1341 nhaye 1039 function listeDemandeur($from, $id) {
1342 nhaye 828 // Récupération des demandeurs de la base
1343 fmichon 1723 $sql = "SELECT demandeur.demandeur,
1344     demandeur.type_demandeur,
1345     lien_".$from."_demandeur.petitionnaire_principal
1346     FROM ".DB_PREFIXE."lien_".$from."_demandeur
1347     INNER JOIN ".DB_PREFIXE."demandeur
1348     ON demandeur.demandeur=lien_".$from."_demandeur.demandeur
1349     WHERE ".$from." = '".$id."'";
1350     $res = $this->f->db->query($sql);
1351     $this->f->addToLog("listeDemandeur(): db->query(\"".$sql."\")", VERBOSE_MODE);
1352 vpihour 1777 if ( database::isError($res)){
1353     die();
1354     }
1355 fmichon 1723 // Stockage du résultat dans un tableau
1356     while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
1357     if ($row['petitionnaire_principal'] == 't' AND
1358     $row['type_demandeur']=="petitionnaire") {
1359     $this->valIdDemandeur['petitionnaire_principal']=$row['demandeur'];
1360     } elseif ($row['petitionnaire_principal'] == 'f' AND
1361     $row['type_demandeur']=="petitionnaire"){
1362     $this->valIdDemandeur['petitionnaire'][]=$row['demandeur'];
1363     } elseif ($row['type_demandeur']=="delegataire"){
1364     $this->valIdDemandeur['delegataire']=$row['demandeur'];
1365 nhaye 828 }
1366     }
1367     }
1368 nhaye 807
1369 nhaye 1037
1370 nhaye 807 /**
1371 nhaye 1037 * Surcharge du bouton retour afin de retourner sur la recherche de dossiers
1372     * d'instruction existant
1373     */
1374     function retour($premier = 0, $recherche = "", $tricol = "") {
1375    
1376     echo "\n<a class=\"retour\" ";
1377     echo "href=\"";
1378     //
1379     if($this->getParameter("idx_dossier") != "") {
1380     echo "tab.php?";
1381     echo "obj=recherche_dossier";
1382    
1383     } else {
1384     if($this->getParameter("retour")=="form" AND !($this->getParameter("validation")>0 AND $this->getParameter("maj")==2 AND $this->correct)) {
1385     echo "form.php?";
1386     } else {
1387     echo "tab.php?";
1388     }
1389     echo "obj=".get_class($this);
1390     if($this->getParameter("retour")=="form") {
1391     echo "&amp;idx=".$this->getParameter("idx");
1392 softime 2093 echo "&amp;idz=".$this->getParameter("idz");
1393 nhaye 1037 echo "&amp;action=3";
1394     }
1395     }
1396     echo "&amp;premier=".$this->getParameter("premier");
1397     echo "&amp;tricol=".$this->getParameter("tricol");
1398     echo "&amp;recherche=".$this->getParameter("recherche");
1399     echo "&amp;selectioncol=".$this->getParameter("selectioncol");
1400     echo "&amp;advs_id=".$this->getParameter("advs_id");
1401     echo "&amp;valide=".$this->getParameter("valide");
1402     //
1403     echo "\"";
1404     echo ">";
1405     //
1406     echo _("Retour");
1407     //
1408     echo "</a>\n";
1409    
1410     }
1411    
1412    
1413     /**
1414 fmichon 1723 * Cette méthode permet d'afficher des informations spécifiques dans le
1415     * formulaire de l'objet
1416     *
1417     * @param integer $maj Mode de mise à jour
1418 nhaye 807 */
1419     function formSpecificContent($maj) {
1420 fmichon 1723
1421     /**
1422     * Gestion du bloc des demandeurs
1423     */
1424     // Si le mode est (modification ou suppression ou consultation) ET que
1425     // le formulaire n'est pas correct (c'est-à-dire que le formulaire est
1426     // actif)
1427     if (!$this->correct AND $maj != 0) {
1428     // Alors on récupère les demandeurs dans la table lien pour
1429     // affectation des résultats dans this->valIdDemandeur
1430 nhaye 1039 $this->listeDemandeur("demande", $this->val[array_search('demande', $this->champs)]);
1431 nhaye 838 }
1432 fmichon 1723
1433     // Si le mode est (ajout ou modification) ET que le formulaire n'est pas
1434     // correct (c'est-à-dire que le formulaire est actif)
1435     if ($maj < 2 AND !$this->correct) {
1436     // Alors on positionne le marqueur linkable a true qui permet
1437     // d'afficher ou non les actions de gestion des demandeurs
1438 nhaye 838 $linkable = true;
1439     } else {
1440 fmichon 1723 // Sinon on positionne le marqueur linkable a false qui permet
1441     // d'afficher ou non les actions de gestion des demandeurs
1442 nhaye 838 $linkable = false;
1443     }
1444 nhaye 1020
1445 fmichon 1723 // Affichage des demandeurs et des actions
1446 nhaye 807 // Conteneur de la listes des demandeurs
1447 nhaye 1097 echo "<div id=\"liste_demandeur\" class=\"demande_hidden_bloc col_12\">";
1448 nhaye 807 echo "<fieldset class=\"cadre ui-corner-all ui-widget-content\">";
1449     echo " <legend class=\"ui-corner-all ui-widget-content ui-state-active\">"
1450     ._("Petitionnaire")."</legend>";
1451     // Si des demandeurs sont liés à la demande
1452 nhaye 828 require_once "../obj/petitionnaire.class.php";
1453     require_once "../obj/delegataire.class.php";
1454 nhaye 1097 // Affichage du bloc pétitionnaire principal / délégataire
1455     // L'ID DU DIV SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
1456 nhaye 1672 echo "<div id=\"petitionnaire_principal_delegataire\">";
1457 nhaye 1097 // Affichage de la synthèse
1458     if (isset ($this->valIdDemandeur["petitionnaire_principal"]) AND
1459     !empty($this->valIdDemandeur["petitionnaire_principal"])) {
1460     $demandeur = new petitionnaire(
1461     $this->valIdDemandeur["petitionnaire_principal"],
1462     $this->f->db,false);
1463     $demandeur -> afficherSynthese("petitionnaire_principal", $linkable);
1464     $demandeur -> __destruct();
1465     } elseif ( isset ($this->postedIdDemandeur["petitionnaire_principal"]) AND
1466     !empty($this->postedIdDemandeur["petitionnaire_principal"]) ) {
1467     $demandeur = new petitionnaire(
1468     $this->postedIdDemandeur["petitionnaire_principal"],
1469     $this->f->db,false);
1470     $demandeur -> afficherSynthese("petitionnaire_principal", $linkable);
1471     $demandeur -> __destruct();
1472     }
1473     // Si en édition de formulaire
1474     if($maj < 2) {
1475     // Bouton d'ajout du pétitionnaire principal
1476     // L'ID DE L'INPUT SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
1477     echo "<span id=\"add_petitionnaire_principal\"
1478     class=\"om-form-button add-16\">".
1479     _("Saisir le petitionnaire principal").
1480     "</span>";
1481     }
1482     // Bouton d'ajout du delegataire
1483     // L'ID DU DIV ET DE L'INPUT SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
1484     echo "<div id=\"delegataire\">";
1485     // Affichage de la synthèse
1486     if (isset ($this->valIdDemandeur["delegataire"]) AND
1487     !empty($this->valIdDemandeur["delegataire"])) {
1488     $demandeur = new delegataire($this->valIdDemandeur["delegataire"],
1489     $this->f->db,false);
1490     $demandeur -> afficherSynthese("delegataire", $linkable);
1491     $demandeur -> __destruct();
1492     } elseif ( isset ($this->postedIdDemandeur["delegataire"]) AND
1493     !empty($this->postedIdDemandeur["delegataire"]) ) {
1494 nhaye 807
1495 nhaye 1097 $demandeur = new delegataire($this->postedIdDemandeur["delegataire"],
1496     $this->f->db,false);
1497     $demandeur -> afficherSynthese("delegataire", $linkable);
1498     $demandeur -> __destruct();
1499     }
1500     if($maj < 2) {
1501     echo "<span id=\"add_delegataire\"
1502 vpihour 1075 class=\"om-form-button add-16\">".
1503 nmeucci 2846 _("Saisir un autre correspondant").
1504 vpihour 1051 "</span>";
1505 nhaye 1097 }
1506     echo "</div>";
1507 nhaye 1118 echo "<div class=\"both\"></div>";
1508 nhaye 1097 echo "</div>";
1509     // Bloc des pétitionnaires secondaires
1510     // L'ID DU DIV SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
1511 nhaye 1672 echo "<div id=\"listePetitionnaires\">";
1512 fmichon 1005
1513 nhaye 1097 // Affichage de la synthèse
1514     if (isset ($this->valIdDemandeur["petitionnaire"]) AND
1515     !empty($this->valIdDemandeur["petitionnaire"])) {
1516    
1517     foreach ($this->valIdDemandeur["petitionnaire"] as $petitionnaire) {
1518     $demandeur = new petitionnaire($petitionnaire,
1519     $this->f->db,false);
1520     $demandeur -> afficherSynthese("petitionnaire", $linkable);
1521 nhaye 1065 $demandeur -> __destruct();
1522     }
1523    
1524 nhaye 1097 } elseif ( isset ($this->postedIdDemandeur["petitionnaire"]) AND
1525     !empty($this->postedIdDemandeur["petitionnaire"]) ) {
1526     foreach ($this->postedIdDemandeur["petitionnaire"] as $petitionnaire) {
1527     $demandeur = new petitionnaire($petitionnaire,
1528     $this->f->db,false);
1529     $demandeur -> afficherSynthese("petitionnaire", $linkable);
1530     $demandeur -> __destruct();
1531 nhaye 828 }
1532 nhaye 1097 }
1533     if ($maj < 2) {
1534     // L'ID DE L'INPUT SUIVANT EST NECESSAIRE AU BON FONCTIONNEMENT DU JS
1535     echo "<span id=\"add_petitionnaire\"
1536     class=\"om-form-button add-16\">".
1537     _("Ajouter un petitionnaire")
1538     ."</span>";
1539     }
1540     echo "</div>";
1541 nhaye 807 echo "</fieldset>";
1542 softime 2313 // Champ flag permettant de récupérer la valeur de l'option sig pour
1543     // l'utiliser en javascript, notamment lors du chargement de l'interface
1544     // pour les références cadastrales
1545     // XXX Si un widget pour les références cadastrales existait, il n'y
1546     // aurait pas besoin de faire cela
1547     echo "<input id='option_sig' type='hidden' value='".$this->f->getParameter("option_sig")."' name='option_sig'>";
1548 vpihour 2364 echo "</div>";
1549 nhaye 807 }
1550    
1551 nhaye 1097 // {{{
1552    
1553     // getter
1554     function getValIdDemandeur() {
1555     return $this->valIdDemandeur;
1556     }
1557     // setter
1558     function setValIdDemandeur($valIdDemandeur) {
1559     $this->valIdDemandeur = $valIdDemandeur;
1560     }
1561 vpihour 1106
1562     //Supression du lien entre la demandeur et le(s) demandeur(s)
1563     function triggerSupprimer($id, &$db, $val, $DEBUG){
1564    
1565     //Création de la requête
1566     $sql = "DELETE FROM
1567     ".DB_PREFIXE."lien_demande_demandeur
1568     WHERE
1569     demande = $id";
1570    
1571     $res = $this->f->db->query($sql);
1572 vpihour 1777 $this->f->addToLog("triggerSupprimer() : db->query(\"".$sql."\")");
1573     if ( database::isError($res)){
1574     die();
1575     }
1576 vpihour 1106 }
1577    
1578 nhaye 1097 // }}}
1579 softime 2071
1580    
1581     /**
1582     * Cette fonction permet de récupérer les informations nécessaires
1583     * à la génération du nom du répertoire
1584     * @param string $dossier Identifiant du dossier
1585     * @return array Tableau des résultats
1586     */
1587     private function getInfosForFoldername($dossier) {
1588    
1589     //Requête SQL
1590 softime 2204 $sql = "SELECT dossier.dossier_autorisation, dossier_instruction_type.code, dossier.version
1591 softime 2071 FROM ".DB_PREFIXE."dossier
1592     LEFT JOIN ".DB_PREFIXE."dossier_instruction_type
1593     ON dossier_instruction_type.dossier_instruction_type = dossier.dossier_instruction_type
1594     WHERE dossier.dossier = '".$dossier."'";
1595     $res = $this->f->db->query($sql);
1596     $this->addToLog("getInfosForFoldername() : db->query(".$sql.")", VERBOSE_MODE);
1597     database::isError($res);
1598    
1599     // tableau des résultats
1600     $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1601 vpihour 2119
1602     //Formatage du numéro de version
1603 vpihour 2131 require_once '../obj/dossier.class.php';
1604     $dossier = new dossier($dossier,$this->db,DEBUG);
1605 softime 2204 $row['version'] = $dossier->getNumeroVersionDossierInstructionType($dossier->getVal('dossier_autorisation'), $dossier->getVal('dossier_instruction_type'), $row['version'], false);
1606 vpihour 2119
1607 softime 2071 // retourne le tableau des résultats
1608     return $row;
1609     }
1610    
1611     /**
1612     * Cette fonction permet la création du répertoire dans le dossier de numérisation
1613     * @param string $dossier_autorisation Identifiant dossier d'autorisation
1614     * @param string $code Type du dossier d'instruction
1615     * @param int $version Numéro de version du dossier
1616     * @return boolean Vrai ou Faux
1617     */
1618     private function createFolder($dossier_autorisation, $code, $version) {
1619    
1620 softime 2369 // Nom du répertoire
1621 softime 2071 $foldername = $dossier_autorisation.".".$code.$version;
1622    
1623 softime 2369 // Vérifie le paramètrage du répertoire de numérisation
1624 softime 2072 if (isset($this->f->config["path_scan"])) {
1625 softime 2369
1626     // Vérifie que le répertoire existe
1627     if (is_dir($this->f->config["path_scan"])) {
1628    
1629     // Répertoire des "à traiter"
1630     $dir = $this->f->config["path_scan"]."Todo/";
1631    
1632     // Si le répertore existe déjà le répertoire n'est pas crée
1633     if (file_exists($dir.$foldername)) {
1634    
1635     //
1636     return true;
1637     }
1638    
1639     // Vérifie que le répêrtoire des "à traiter" existe
1640     if (is_dir($dir)) {
1641    
1642     // Création du répertoire
1643     mkdir($dir.$foldername, 0777);
1644     //
1645     return true;
1646     }
1647    
1648     // Message d'erreur
1649     $this->msg = "";
1650     $this->addToErrors ('', _("Le repertoire Todo n'existe pas.") . " " . _("Veuillez contacter votre administrateur."), "createFolder() : Faillure");
1651     //
1652     return false;
1653    
1654 softime 2072 }
1655 softime 2369
1656     // Message d'erreur
1657     $this->msg = "";
1658     $this->addToErrors ('', _("Le repertoire de numerisation configure n'existe pas.") . " " . _("Veuillez contacter votre administrateur."), "createFolder() : Faillure");
1659     //
1660     return false;
1661    
1662 softime 2071 }
1663    
1664 softime 2369 // Message d'erreur
1665     $this->msg = "";
1666     $this->addToErrors ('', _("Le repertoire de numerisation n'a pas ete configure.") . " " . _("Veuillez contacter votre administrateur."), "createFolder() : Faillure");
1667     //
1668 softime 2071 return false;
1669     }
1670    
1671 softime 2363 /**
1672     * Récupère le champ "qualification" du type de la demande
1673     * @param integer $demande_type Identifiant du type de la demande
1674     * @return boolean
1675     */
1676     function get_qualification($demande_type) {
1677    
1678     // Initialise le résultat
1679     $qualification = "";
1680    
1681     // Si la condition existe
1682 softime 2365 if (is_numeric($demande_type)) {
1683 softime 2363
1684     // Requête SQL
1685     $sql = "SELECT qualification
1686     FROM ".DB_PREFIXE."demande_type
1687     WHERE demande_type = $demande_type";
1688     $qualification = $this->db->getOne($sql);
1689 softime 2365 $this->f->addToLog("get_qualification() : db->getOne(\"".$sql."\")",
1690     VERBOSE_MODE);
1691 softime 2363 $this->f->isDatabaseError($qualification);
1692     }
1693    
1694     // Retourne le résultat
1695     return $qualification;
1696     }
1697    
1698 vpihour 2643 /**
1699     * Récupère les champs archive_* d'une instruction
1700     * @param string $dossier L'identifiant du dossier d'instruction
1701     */
1702     public function getArchiveInstruction($dossierID){
1703    
1704     //On récupère les données du dernier DI accordé
1705     $sql = "SELECT dossier.delai, dossier.accord_tacite, dossier.etat,
1706     dossier.avis_decision,
1707     to_char(dossier.date_complet, 'DD/MM/YYYY') as date_complet,
1708     to_char(dossier.date_dernier_depot, 'DD/MM/YYYY') as date_dernier_depot,
1709     to_char(dossier.date_rejet, 'DD/MM/YYYY') as date_rejet,
1710     to_char(dossier.date_limite, 'DD/MM/YYYY') as date_limite,
1711     to_char(dossier.date_notification_delai, 'DD/MM/YYYY') as date_notification_delai,
1712     to_char(dossier.date_decision, 'DD/MM/YYYY') as date_decision,
1713     to_char(dossier.date_validite, 'DD/MM/YYYY') as date_validite,
1714     to_char(dossier.date_achevement, 'DD/MM/YYYY') as date_achevement,
1715     to_char(dossier.date_chantier, 'DD/MM/YYYY') as date_chantier,
1716     to_char(dossier.date_conformite, 'DD/MM/YYYY') as date_conformite,
1717     dossier.incompletude,
1718     dossier.evenement_suivant_tacite, dossier.evenement_suivant_tacite_incompletude,
1719     dossier.etat_pendant_incompletude,
1720     to_char(dossier.date_limite_incompletude, 'DD/MM/YYYY') as date_limite_incompletude,
1721     dossier.delai_incompletude, dossier.autorite_competente, dossier.duree_validite
1722     ,dossier.dossier
1723     FROM ".DB_PREFIXE."dossier
1724     LEFT JOIN ".DB_PREFIXE."avis_decision
1725     ON dossier.avis_decision = avis_decision.avis_decision
1726     WHERE dossier.avis_decision IS NOT NULL AND avis_decision.typeavis = 'F'
1727     AND dossier.dossier_autorisation = (
1728     SELECT dossier_autorisation.dossier_autorisation
1729     FROM ".DB_PREFIXE."dossier_autorisation
1730     LEFT JOIN ".DB_PREFIXE."dossier
1731     ON dossier_autorisation.dossier_autorisation = dossier.dossier_autorisation
1732     WHERE dossier = '".$dossierID."')
1733     ORDER BY dossier.version DESC";
1734    
1735     $res = $this->db->query($sql);
1736     $this->addToLog("updateArchiveInstruction(): db->query(\"".$sql."\");", VERBOSE_MODE);
1737     if (database::isError($res)) {
1738     die($res->getMessage());
1739     }
1740    
1741     //Un des dosssiers d'instruction a été accordé, on récupère ses données
1742     if ( $res->numrows() != 0 ){
1743    
1744     $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);
1745     require_once "../obj/instruction.class.php";
1746     $instruction = new instruction("]",$this->db,DEBUG);
1747    
1748     $instruction->setParameter("maj", 1);
1749     $instruction->updateArchiveData($row);
1750     return $instruction->valF;
1751     }
1752     //Sinon, on prend les données du P0, si ce n'est pas un P0
1753     else {
1754     $sql = "SELECT dossier.delai, dossier.accord_tacite, dossier.etat,
1755     dossier.avis_decision, dossier.date_complet, dossier.date_dernier_depot,
1756     dossier.date_rejet, dossier.date_limite, dossier.date_notification_delai,
1757     dossier.date_decision, dossier.date_validite, dossier.date_achevement,
1758     dossier.date_chantier, dossier.date_conformite, dossier.incompletude,
1759     dossier.evenement_suivant_tacite, dossier.evenement_suivant_tacite_incompletude,
1760     dossier.etat_pendant_incompletude, dossier.date_limite_incompletude,
1761     dossier.delai_incompletude, dossier.autorite_competente, dossier.duree_validite
1762     ,dossier.dossier
1763     FROM ".DB_PREFIXE."dossier
1764     LEFT JOIN ".DB_PREFIXE."dossier_instruction_type
1765     ON dossier.dossier_instruction_type = dossier_instruction_type.dossier_instruction_type
1766     WHERE dossier.dossier_autorisation = (
1767     SELECT dossier_autorisation.dossier_autorisation
1768     FROM ".DB_PREFIXE."dossier_autorisation
1769     LEFT JOIN ".DB_PREFIXE."dossier
1770     ON dossier_autorisation.dossier_autorisation = dossier.dossier_autorisation
1771 softime 2653 WHERE dossier = '".$dossierID."')
1772 vpihour 2643 AND dossier_instruction_type.code = 'P'
1773     ORDER BY dossier.version DESC";
1774     $res = $this->db->query($sql);
1775     $this->addToLog("updateArchiveInstruction(): db->query(\"".$sql."\");", VERBOSE_MODE);
1776     if (database::isError($res)) {
1777     die($res->getMessage());
1778     }
1779    
1780     //On est pas dans le cas d'un dépôt d'un P0
1781     if ( $res->numrows() != 0 ){
1782     $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);
1783 softime 2653 require_once "../obj/instruction.class.php";
1784 vpihour 2643 $instruction = new instruction("]",$this->db,DEBUG);
1785     $instruction->setParameter("maj", 1);
1786     $instruction->updateArchiveData($row);
1787     return $instruction->valF;
1788     }
1789     }
1790     }
1791 vpihour 632 }// fin classe
1792 fmichon 1005 ?>

Properties

Name Value
svn:keywords Id

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26