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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1262 - (hide annotations)
Thu Feb 14 17:54:53 2013 UTC (11 years, 11 months ago) by nhaye
File size: 38933 byte(s)
- obj/cerfa.class.php : surcharge de la méthode verifier afin qu'on ne puisse pas ajouter 2 cerfa avec la même période de validité et le même type de dossier d'instruction
- obj/demande.class.php : ajout du n° de cerfa au dossier d'instruction lors de sa création
- sql/pgsql/dossier.inc.php : ajout de l'onglet "donnees_techniques"
- sql/pgsql/donnees_techniques.form.inc.php : remise en ordre des champs, définition du tableau des surfaces
- obj/donnees_techniques.class.php : configuration du tableau des surfaces et affichage ou non des champs selon le cerfa

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26