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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:keywords Id

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26