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