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, ERP Accessibilite, ou |
217 |
// deenvoie un |
218 |
// message a ERP |
219 |
$dossier_erp = $this->getFromDB("SELECT erp FROM ".DB_PREFIXE. |
220 |
"dossier WHERE dossier = '" .$this->valF['dossier'] . "'"); |
221 |
$dossier_nature = $this->getFromDB("SELECT nature FROM ".DB_PREFIXE. |
222 |
"dossier WHERE dossier = '" . $this->valF['dossier'] . "'"); |
223 |
if ($dossier_erp == 't' |
224 |
&& substr($dossier_nature, 0, 2) == $this->f->getParameter('erp_dossier_nature_pc')) { |
225 |
// envoi du message "Demande d'instruction d'un dossier PC pour un ERP" |
226 |
if (($this->valF['service'] == $this->f->getParameter('erp_service_accessibilite') |
227 |
|| $this->valF['service'] == $this->f->getParameter('erp_service_securite'))) { |
228 |
$msgenque = new MessageEnqueuer(); |
229 |
$msgenque->setDossierInstructionIdentifier($this->valF['dossier']); |
230 |
$msgenque->setConsultationIdentifier($this->valF['consultation']); |
231 |
$msgenque->enqueueMessage($msgenque::$ERP_DEMANDE_INSTRUCTION_PC); |
232 |
} |
233 |
|
234 |
// envoi du message "Consultation ERP pour conformite" en cas de creation de la |
235 |
// consultation du service ERP Conformite |
236 |
if ($this->valF['service'] == $this->f->getParameter('erp_service_conformite')) { |
237 |
$msgenque = new MessageEnqueuer(); |
238 |
$msgenque->setDossierInstructionIdentifier($this->valF['dossier']); |
239 |
$msgenque->setConsultationIdentifier($this->valF['consultation']); |
240 |
$msgenque->enqueueMessage($msgenque::$ERP_CONSULTATION_CONFORMITE); |
241 |
} |
242 |
} |
243 |
|
244 |
} |
245 |
|
246 |
/** |
247 |
* Fait une requette sql pour extraire la valeur d'un champ, et retourne |
248 |
* cette valeur |
249 |
* @param string $sql La requete sql a executer |
250 |
* @return La valeur du champs cherche, sinon NULL. En cas d'erreur de la BD |
251 |
* l'execution s'arrete. |
252 |
*/ |
253 |
function getFromDB($sql) { |
254 |
//$sql = "SELECT libelle FROM ".DB_PREFIXE."dossier WHERE dossier = '" . $dossier . "'"; |
255 |
$res = $this->db->limitquery($sql, 0, 1); |
256 |
$this->addToLog("getDossierERPSpecification(): db->limitquery(\"". |
257 |
str_replace(",",", ",$sql)."\", 0, 1);", VERBOSE_MODE); |
258 |
// Si une erreur survient on die |
259 |
if (database::isError($res, true)) { |
260 |
// Appel de la methode de recuperation des erreurs |
261 |
$this->erreur_db($res->getDebugInfo(), $res->getMessage(), 'instruction'); |
262 |
} |
263 |
// retourne la nature du dossier |
264 |
while ($row =& $res->fetchRow()) { |
265 |
return $row[0]; |
266 |
} |
267 |
// la nature n'etait pas trouve, ce qui ne devrait pas se passer |
268 |
return NULL; |
269 |
|
270 |
} |
271 |
|
272 |
|
273 |
/** |
274 |
* Returne la nature du dossier auquel la consultation appartient. |
275 |
* @param string $dossier L'identifiant du dossier |
276 |
* @return La nature du dossier si elle existe, sinon NULL. En cas |
277 |
* d'erreur de la BD, l'execution se termine. |
278 |
*/ |
279 |
function getDossierNature($dossier) { |
280 |
$sql = "SELECT nature FROM ".DB_PREFIXE."dossier WHERE dossier = '" . $dossier . "'"; |
281 |
$res = $this->db->limitquery($sql, 0, 1); |
282 |
$this->addToLog("getDossierNature(): db->limitquery(\"".str_replace(",",", ",$sql)."\", 0, 1);", VERBOSE_MODE); |
283 |
// Si une erreur survient on die |
284 |
if (database::isError($res, true)) { |
285 |
// Appel de la methode de recuperation des erreurs |
286 |
$this->erreur_db($res->getDebugInfo(), $res->getMessage(), 'dossier'); |
287 |
} |
288 |
// retourne la nature du dossier |
289 |
while ($row =& $res->fetchRow()) { |
290 |
return $row[0]; |
291 |
} |
292 |
// la nature n'etait pas trouve, ce qui ne devrait pas se passer |
293 |
return NULL; |
294 |
} |
295 |
|
296 |
// ============================================= |
297 |
// calcul de date avec ajout de mois (delais) |
298 |
// [add months (delay) and calculation final date] |
299 |
// limite ? => voir fonction instruction |
300 |
// ============================================= |
301 |
function moisdate($date,$delaimois) { |
302 |
// rajout de mois à une date (moins de 12) |
303 |
$temp = explode("-" , $date); |
304 |
$jour = (int) $temp[2]; |
305 |
$mois = (int) $temp[1]; |
306 |
$annee = (int) $temp[0]; |
307 |
$mois=$mois+$delaimois; |
308 |
// calcul mois annee |
309 |
if($mois>12){ |
310 |
$mois=$mois-12; |
311 |
$annee=$annee+1; |
312 |
} |
313 |
// Calcul du nombre de jours dans le mois sélectionné |
314 |
switch($mois) { |
315 |
case "2": |
316 |
if ($annee % 4 == 0 && $annee % 100 != 0 || $annee % 400 == 0) |
317 |
$jourmax = 29; |
318 |
else |
319 |
$jourmax = 28; |
320 |
break; |
321 |
case "4": |
322 |
case "6": |
323 |
case "9": |
324 |
case "11": |
325 |
$jourmax = 30; |
326 |
break; |
327 |
default: |
328 |
$jourmax = 31; |
329 |
} |
330 |
if ($jour > $jourmax) |
331 |
$jour = $jourmax; |
332 |
return $annee."-".$mois."-".$jour ; |
333 |
} |
334 |
|
335 |
// ============================================= |
336 |
// Ajout du fielset |
337 |
// Add fieldset |
338 |
// ============================================= |
339 |
function setLayout(&$form, $maj){ |
340 |
|
341 |
// Modification layout : écran de retour d'avis permettant |
342 |
// uniquement la saisie des trois champs : avis, motivation et fichier |
343 |
if ($this->f->isAccredited('consultation_consulter_autre_que_retour_avis')) { |
344 |
|
345 |
//Champs sur lequel s'ouvre le fieldset |
346 |
$form->setBloc('dossier','D',""); |
347 |
$form->setFieldset('dossier','D',_('Consultation')); |
348 |
|
349 |
//Champs sur lequel se ferme le fieldset |
350 |
$form->setFieldset('date_envoi','F',''); |
351 |
$form->setBloc('date_envoi','F'); |
352 |
|
353 |
} |
354 |
|
355 |
// MODE - autre que AJOUTER alors on affiche un fieldset retour |
356 |
// d'avis |
357 |
if ($maj != 0) { |
358 |
|
359 |
//Champs sur lequel s'ouvre le fieldset |
360 |
$form->setBloc('date_reception','D',""); |
361 |
$form->setFieldset('date_reception','D',_('Retour d\'avis')); |
362 |
|
363 |
//Champs sur lequel se ferme le fieldset |
364 |
$form->setFieldset('lu','F',''); |
365 |
$form->setBloc('lu','F'); |
366 |
|
367 |
} |
368 |
} |
369 |
|
370 |
/** Surcharge de la methode retour afin de retourner sur la page de saisie de |
371 |
* code barre si besoin |
372 |
**/ |
373 |
function retour($premier = 0, $recherche = "", $tricol = "") { |
374 |
$params ="obj=".get_class($this); |
375 |
if($this->getParameter("retour")=="form") { |
376 |
$params .= "&idx=".$this->getParameter("idx"); |
377 |
$params .= "&action=3"; |
378 |
} |
379 |
$params .= "&premier=".$this->getParameter("premier"); |
380 |
$params .= "&tricol=".$this->getParameter("tricol"); |
381 |
$params .= "&recherche=".$this->getParameter("recherche"); |
382 |
$params .= "&selectioncol=".$this->getParameter("selectioncol"); |
383 |
$params .= "&advs_id=".$this->getParameter("advs_id"); |
384 |
$params .= "&valide=".$this->getParameter("valide"); |
385 |
echo "\n<a class=\"retour\" "; |
386 |
echo "href=\""; |
387 |
// |
388 |
|
389 |
if($this->getParameter("retour")=="form" AND !($this->getParameter("validation")>0 AND $this->getParameter("maj")==2 AND $this->correct)) { |
390 |
echo "form.php?".$params; |
391 |
} elseif($this->getParameter("retour")=="avis_code_barre") { |
392 |
echo "../app/avis_code_barre.php"; |
393 |
} else { |
394 |
echo "tab.php?".$params; |
395 |
} |
396 |
// |
397 |
echo "\""; |
398 |
echo ">"; |
399 |
// |
400 |
echo _("Retour"); |
401 |
// |
402 |
echo "</a>\n"; |
403 |
} |
404 |
|
405 |
/** |
406 |
* Surcharge pour gérer les actions disponibles dans le portlet |
407 |
*/ |
408 |
function checkAccessibility() { |
409 |
// Si une action 'lu' est présente et que le champ lu est à true |
410 |
// on supprime l'action |
411 |
if (isset($this->actions_sup["lu"]) |
412 |
&& isset($this->val[array_search("lu", $this->champs)]) |
413 |
&& $this->val[array_search("lu", $this->champs)]== "t") { |
414 |
unset($this->actions_sup["lu"]); |
415 |
} |
416 |
// |
417 |
parent::checkAccessibility(); |
418 |
} |
419 |
|
420 |
/** |
421 |
* Méthode de verification d'accèssibilité de la consultation |
422 |
* à l'utilisateur connecté |
423 |
*/ |
424 |
function canAccess() { |
425 |
parent::canAccess(); |
426 |
if($this->f->isUserServiceExt()) { |
427 |
// On compare l'id du service de la consultation |
428 |
// aux id des services de utilisateur connecté |
429 |
foreach($this->f->om_utilisateur['service'] as $service) { |
430 |
if($this->val[array_search("service",$this->champs)]===$service['service']) { |
431 |
return true; |
432 |
} |
433 |
} |
434 |
return false; |
435 |
} else{ |
436 |
return true; |
437 |
} |
438 |
} |
439 |
|
440 |
/** |
441 |
* Surcharge du bouton retour pour popup |
442 |
*/ |
443 |
function retoursousformulaire($idxformulaire, $retourformulaire, $val, |
444 |
$objsf, $premiersf, $tricolsf, $validation, |
445 |
$idx, $maj, $retour) { |
446 |
if($retourformulaire === "demande_avis_encours") { |
447 |
echo "\n<a class=\"retour\" "; |
448 |
echo "href=\""; |
449 |
echo "#"; |
450 |
echo "\" "; |
451 |
echo ">"; |
452 |
// |
453 |
echo _("Retour"); |
454 |
// |
455 |
echo "</a>\n"; |
456 |
} else { |
457 |
parent::retoursousformulaire($idxformulaire, $retourformulaire, $val, |
458 |
$objsf, $premiersf, $tricolsf, $validation, |
459 |
$idx, $maj, $retour); |
460 |
} |
461 |
} |
462 |
}// fin classe |
463 |
?> |