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

Contents of /trunk/obj/consultation.class.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 925 - (show annotations)
Thu Nov 29 23:28:01 2012 UTC (12 years, 2 months ago) by fmichon
File size: 17428 byte(s)
Revert des commits 918 et 919

1 <?php
2 //$Id$
3 //gen openMairie le 10/02/2011 20:32
4 require_once ("../gen/obj/consultation.class.php");
5 require_once("../services/outgoing/messageenqueuer.php");
6
7 class consultation extends consultation_gen {
8
9 function consultation($id,&$db,$debug) {
10 $this->constructeur($id,$db,$debug);
11 }// fin constructeur
12
13 function setValsousformulaire(&$form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire){
14 if ($validation==0) {
15 if ($maj == 0){
16 $form->setVal("dossier", $idxformulaire);
17 $form->setVal("date_envoi",date('d/m/Y'));
18 }
19 if($maj == 1) {
20 if($this->f->isAccredited('consultation_retour_avis_suivi') OR
21 $this->f->isAccredited('consultation_retour_avis_service')) {
22 $form->setVal("date_retour",date('d/m/Y'));
23 }
24 }
25 }
26 }
27
28 function setVal(&$form, $maj, $validation, &$db) {
29 if($maj == 1) {
30 $form->setVal("date_retour",date('d/m/Y'));
31 }
32 }
33
34 function setvalF($val) {
35 parent::setValF($val);
36 if($this->getParameter('maj')==0) {
37 $this->valF["date_reception"]=$this->valF["date_envoi"];
38 }
39
40 // Si un retour d'avis est modifie on passe "lu" a false
41 if($this->getParameter('maj')==1 AND (
42 $this->val[array_search("avis_consultation",$this->champs)] != $val["avis_consultation"] OR
43 $this->val[array_search("date_retour",$this->champs)] != $val["date_retour"] OR
44 $this->val[array_search("motivation",$this->champs)] != $val["motivation"] OR
45 $this->val[array_search("fichier",$this->champs)] != $val["fichier"])
46 ) {
47 $this->valF["lu"]=false;
48 }
49 }
50
51 function verifier($val, &$db, $DEBUG) {
52 parent::verifier($val, $db, $DEBUG);
53 // Si le fichier envoye est different de l'existant
54 if (isset($this->val[array_search("fichier",$this->champs)])
55 && $this->val[array_search("fichier",$this->champs)] != $val["fichier"]
56 && $this->valF['fichier']!="") {
57 // Si le fichier existe dans tmp
58 if(file_exists("../tmp/".$this->valF['fichier'])) {
59 $contents=file_get_contents("../tmp/".$this->valF['fichier']);
60 // On essaye de l'enregistrer
61 $res = $this->f->storeDecisionFile($contents, $this->valF['fichier'],
62 $this->valF['dossier'],
63 'consultation_'.$this->valF['consultation']."_");
64 // Si l'enregistrement s'est bien deroule
65 // on supprime le fichier dans tmp
66 // on met a jour valF avec le nouveau nom du fichier
67 if($res===true){
68 $this->addToMessage(_("Sauvegarde du fichier reussi"));
69 unlink("../tmp/".$this->valF['fichier']);
70 $this->valF['fichier']='consultation_'.$this->valF['consultation']."_".$this->valF['fichier'];
71 // Sinon on supprime le fichier dans tmp
72 // on reinitialise le nom du fichier a l'ancienne valeur
73 } else {
74 $this->correct = false;
75 $this->addToMessage($res);
76 unlink("../tmp/".$this->valF['fichier']);
77 $this->valF['fichier']=$this->val[array_search("fichier",$this->champs)];
78 }
79 }
80 }
81 }
82
83 function setType(&$form,$maj) {
84 // Appel du parent
85 parent::setType($form,$maj);
86 // MODE - AJOUTER
87 if ($maj == 0) {
88 // On cache alors tous les champs que nous ne voulons pas voir
89 // apparaître dans le formulaire d'ajout (principalement les
90 // informations sur le retour d'avis)
91 $form->setType('date_retour', 'hidden');
92 $form->setType('date_reception', 'hidden');
93 $form->setType('date_limite', 'hidden');
94 $form->setType('avis_consultation', 'hidden');
95 $form->setType('motivation', 'hidden');
96 $form->setType('fichier', 'hidden');
97 $form->setType('lu', 'hidden');
98 // On permet la modification de certains champs
99 $form->setType('dossier', 'hiddenstatic');
100 $form->setType('service', 'select');
101 $form->setType('date_envoi', 'date2');
102 }
103 // MODE - MODIFIER
104 if ($maj == 1) {
105
106 // On affiche en statique les informations qui ne sont plus
107 // modifiables
108 $form->setType('dossier', 'hiddenstatic');
109 $form->setType('date_envoi', 'hiddenstaticdate');
110 $form->setType('date_limite', 'hiddenstaticdate');
111 $form->setType('service', 'selecthiddenstatic');
112
113 // La date de réception ne peut être modifiée que par un
114 // utilisateur en ayant spécifiquement la permission
115 if($this->f->isAccredited('consultation_modifier_date_reception')) {
116 $form->setType('date_reception', 'date2');
117 } else {
118 $form->setType('date_reception', 'hiddenstaticdate');
119 }
120
121 // Le marqueur lu/non lu ne peut être modifié que par un
122 // utilisateur en ayant spécifiquement la permission
123 if ($this->f->isAccredited('consultation_modifier_lu')) {
124 $form->setType('lu', 'checkbox');
125 } else {
126 $form->setType('lu', 'hidden');
127 }
128
129 // Gestion du type du widget sur le champ fichier
130 if($this->val[array_search("fichier",$this->champs)]=="" OR
131 $this->f->isAccredited('consultation_modifier_fichier')) {
132 // Si il n'y a jamais eu de fichier enregistré ou que
133 // l'utilisateur a spécifiquement les droits pour modifier
134 // un fichier déjà enregistré alors on positionne un type
135 // de widget modifiable
136 $form->setType('fichier', 'tmpUpload');
137 } else {
138 // Si non on affiche uniquement le nom du fichier
139 $form->setType('fichier', 'tmpUploadStatic');
140 }
141
142 // Modification layout : écran de retour d'avis permettant
143 // uniquement la saisie des trois champs : avis, motivation et fichier
144 if (!$this->f->isAccredited('consultation_consulter_autre_que_retour_avis')) {
145
146 // On cache alors tous les champs que nous ne voulons pas voir
147 $form->setType('dossier', 'hidden');
148 $form->setType('service', 'hidden');
149 $form->setType('date_envoi', 'hidden');
150 $form->setType('date_retour', 'hidden');
151 $form->setType('date_reception', 'hidden');
152 $form->setType('date_limite', 'hidden');
153 $form->setType('lu', 'hidden');
154
155 }
156
157 }
158 // MODE - CONSULTER
159 if ( $maj == 3 ) {
160 $form->setType('fichier', 'tmpUploadStatic');
161 }
162 //// On cache la clé primaire
163 //$form->setType('consultation', 'hidden');
164 }
165
166 // TRIGGER AVANT MODIFICATION DE DONNEES
167 // trigger before modification data
168 function triggerajouter($id,&$db,$val,$DEBUG) {
169 // mise a jour instruction avec evenement [return delay]
170 if ($this->valF['date_envoi']!=""){
171 $sql= "select delai from ".DB_PREFIXE."service where service ='".$this->valF['service']."'";
172 $delai = $db->getOne($sql);
173 $this->valF['date_limite'] = $this->moisdate($this->valF['date_envoi'],$delai);
174 $this->addToMessage(_("delai")." ".
175 _("retour")." ".$delai." "._("mois")." -> ".
176 _("retour")." ".$this->valF['date_limite']."<br>");
177 $this->valF['lu'] = true;
178 }
179
180 }
181
182 function triggerajouterapres($id,&$db,$val,$DEBUG) {
183
184 // Verification de la demande de notif par mail
185 $sql= "SELECT abrege, notification_email, email FROM ".DB_PREFIXE.
186 "service WHERE service ='".$this->valF['service']."'";
187 $res=$db->query($sql);
188 $notif = $res->fetchrow(DB_FETCHMODE_ASSOC);
189 if (database :: isError($sql))die($res->getMessage()."erreur ".$sql);
190 if ($notif['notification_email']=='t') {
191
192 // Recuperation des infos du dossier
193 $sql= "SELECT dossier, terrain_adresse, terrain_adresse_complement, terrain_cp, terrain_ville
194 FROM ".DB_PREFIXE."dossier WHERE dossier ='".$this->valF['dossier']."'";
195 $res=$db->query($sql);
196 $dossier = $res->fetchrow(DB_FETCHMODE_ASSOC);
197
198 // Definition des parametres d'envoi du mail
199 $title=_("Consultation de services : dossier no")." ".$dossier['dossier'];
200 $corps=_("Votre service est consulte concernant le dossier no")." ".$dossier['dossier']."<br/>".
201 _("Il concerne le terrain situe a l'adresse :")." ".utf8_decode($dossier['terrain_adresse']).
202 " ".utf8_decode($dossier['terrain_adresse_complement'])." ".utf8_decode($dossier['terrain_cp'])." ".$dossier['terrain_ville']."<br/>".
203 _("Vous pouvez y acceder et rendre votre avis a l'adresse")." <a href='".$this->f->getParameter('services_consultes_lien_interne').
204 "scr/form.php?obj=consultation&action=3&idx=".$this->valF['consultation']."' >".
205 _("Lien interne (services VDM)")."</a> "._("ou")." <a href='".$this->f->getParameter('services_consultes_lien_externe').
206 "scr/form.php?obj=consultation&action=3&idx=".$this->valF['consultation']."' >".
207 _("Lien externe (hors VDM)")."</a>";
208 // Envoi du mail avec message de retour
209 if($this->f->sendMail($title, $corps, $notif['email'])) {
210 $this->addToMessage(_("Envoi d'un mail de notification au service")." ".$notif['abrege']);
211 } else {
212 $this->addToMessage(_("L'envoi du mail de notification a echoue"));
213 }
214 }
215
216 // s'il s'agit de la consultation ERP Secu ou ERP Accessibilite envoie un
217 // message a ERP
218 if ($this->getDossierNature($this->valF['dossier']) == 'PC'
219 && ($this->valF['service'] == $this->f->getParameter('erp_service_accessibilite')
220 || $this->valF['service'] == $this->f->getParameter('erp_service_securite'))) {
221 $msgenque = new MessageEnqueuer();
222 $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
223 $msgenque->setConsultationIdentifier($this->valF['consultation']);
224 $msgenque->enqueueMessage($msgenque::$ERP_DEMANDE_INSTRUCTION_PC);
225 }
226
227 }
228
229
230 /**
231 * Returne la nature du dossier auquel la consultation appartient.
232 * @param string $dossier L'identifiant du dossier
233 * @return La nature du dossier si elle existe, sinon NULL. En cas
234 * d'erreur de la BD, l'execution se termine.
235 */
236 function getDossierNature($dossier) {
237 $sql = "SELECT nature FROM ".DB_PREFIXE."dossier WHERE dossier = '" . $dossier . "'";
238 $res = $this->db->limitquery($sql, 0, 1);
239 $this->addToLog("getDossierNature(): db->limitquery(\"".str_replace(",",", ",$sql)."\", 0, 1);", VERBOSE_MODE);
240 // Si une erreur survient on die
241 if (database::isError($res, true)) {
242 // Appel de la methode de recuperation des erreurs
243 $this->erreur_db($res->getDebugInfo(), $res->getMessage(), 'dossier');
244 }
245 // retourne la nature du dossier
246 while ($row =& $res->fetchRow()) {
247 return $row[0];
248 }
249 // la nature n'etait pas trouve, ce qui ne devrait pas se passer
250 return NULL;
251 }
252
253 // =============================================
254 // calcul de date avec ajout de mois (delais)
255 // [add months (delay) and calculation final date]
256 // limite ? => voir fonction instruction
257 // =============================================
258 function moisdate($date,$delaimois) {
259 // rajout de mois à une date (moins de 12)
260 $temp = explode("-" , $date);
261 $jour = (int) $temp[2];
262 $mois = (int) $temp[1];
263 $annee = (int) $temp[0];
264 $mois=$mois+$delaimois;
265 // calcul mois annee
266 if($mois>12){
267 $mois=$mois-12;
268 $annee=$annee+1;
269 }
270 // Calcul du nombre de jours dans le mois sélectionné
271 switch($mois) {
272 case "2":
273 if ($annee % 4 == 0 && $annee % 100 != 0 || $annee % 400 == 0)
274 $jourmax = 29;
275 else
276 $jourmax = 28;
277 break;
278 case "4":
279 case "6":
280 case "9":
281 case "11":
282 $jourmax = 30;
283 break;
284 default:
285 $jourmax = 31;
286 }
287 if ($jour > $jourmax)
288 $jour = $jourmax;
289 return $annee."-".$mois."-".$jour ;
290 }
291
292 // =============================================
293 // Ajout du fielset
294 // Add fieldset
295 // =============================================
296 function setLayout(&$form, $maj){
297
298 // Modification layout : écran de retour d'avis permettant
299 // uniquement la saisie des trois champs : avis, motivation et fichier
300 if ($this->f->isAccredited('consultation_consulter_autre_que_retour_avis')) {
301
302 //Champs sur lequel s'ouvre le fieldset
303 $form->setBloc('dossier','D',"");
304 $form->setFieldset('dossier','D',_('Consultation'));
305
306 //Champs sur lequel se ferme le fieldset
307 $form->setFieldset('date_envoi','F','');
308 $form->setBloc('date_envoi','F');
309
310 }
311
312 // MODE - autre que AJOUTER alors on affiche un fieldset retour
313 // d'avis
314 if ($maj != 0) {
315
316 //Champs sur lequel s'ouvre le fieldset
317 $form->setBloc('date_reception','D',"");
318 $form->setFieldset('date_reception','D',_('Retour d\'avis'));
319
320 //Champs sur lequel se ferme le fieldset
321 $form->setFieldset('lu','F','');
322 $form->setBloc('lu','F');
323
324 }
325 }
326
327 /** Surcharge de la methode retour afin de retourner sur la page de saisie de
328 * code barre si besoin
329 **/
330 function retour($premier = 0, $recherche = "", $tricol = "") {
331 $params ="obj=".get_class($this);
332 if($this->getParameter("retour")=="form") {
333 $params .= "&amp;idx=".$this->getParameter("idx");
334 $params .= "&amp;action=3";
335 }
336 $params .= "&amp;premier=".$this->getParameter("premier");
337 $params .= "&amp;tricol=".$this->getParameter("tricol");
338 $params .= "&amp;recherche=".$this->getParameter("recherche");
339 $params .= "&amp;selectioncol=".$this->getParameter("selectioncol");
340 $params .= "&amp;advs_id=".$this->getParameter("advs_id");
341 $params .= "&amp;valide=".$this->getParameter("valide");
342 echo "\n<a class=\"retour\" ";
343 echo "href=\"";
344 //
345
346 if($this->getParameter("retour")=="form" AND !($this->getParameter("validation")>0 AND $this->getParameter("maj")==2 AND $this->correct)) {
347 echo "form.php?".$params;
348 } elseif($this->getParameter("retour")=="avis_code_barre") {
349 echo "../app/avis_code_barre.php";
350 } else {
351 echo "tab.php?".$params;
352 }
353 //
354 echo "\"";
355 echo ">";
356 //
357 echo _("Retour");
358 //
359 echo "</a>\n";
360 }
361
362 /**
363 * Méthode de verification d'accèssibilité de la consultation
364 * à l'utilisateur connecté
365 */
366 function canAccess() {
367 parent::canAccess();
368 if($this->f->isUserServiceExt()) {
369 // On compare l'id du service de la consultation
370 // aux id des services de utilisateur connecté
371 foreach($this->f->om_utilisateur['service'] as $service) {
372 if($this->val[array_search("service",$this->champs)]===$service['service']) {
373 return true;
374 }
375 }
376 return false;
377 } else{
378 return true;
379 }
380 }
381
382 /**
383 * Surcharge du bouton retour pour popup
384 */
385 function retoursousformulaire($idxformulaire, $retourformulaire, $val,
386 $objsf, $premiersf, $tricolsf, $validation,
387 $idx, $maj, $retour) {
388 if($retourformulaire === "demande_avis_encours") {
389 echo "\n<a class=\"retour\" ";
390 echo "href=\"";
391 echo "#";
392 echo "\" ";
393 echo ">";
394 //
395 echo _("Retour");
396 //
397 echo "</a>\n";
398 } else {
399 parent::retoursousformulaire($idxformulaire, $retourformulaire, $val,
400 $objsf, $premiersf, $tricolsf, $validation,
401 $idx, $maj, $retour);
402 }
403 }
404 }// fin classe
405 ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26