1 |
<?php |
2 |
//$Id$ |
3 |
//gen openMairie le 03/05/2018 09:18 |
4 |
|
5 |
require_once "../obj/om_dbform.class.php"; |
6 |
|
7 |
class contrainte_gen extends om_dbform { |
8 |
|
9 |
protected $_absolute_class_name = "contrainte"; |
10 |
|
11 |
var $table = "contrainte"; |
12 |
var $clePrimaire = "contrainte"; |
13 |
var $typeCle = "N"; |
14 |
var $required_field = array( |
15 |
"contrainte", |
16 |
"libelle", |
17 |
"nature", |
18 |
"om_collectivite" |
19 |
); |
20 |
|
21 |
var $foreign_keys_extended = array( |
22 |
"om_collectivite" => array("om_collectivite", ), |
23 |
); |
24 |
|
25 |
/** |
26 |
* |
27 |
* @return string |
28 |
*/ |
29 |
function get_default_libelle() { |
30 |
return $this->getVal($this->clePrimaire)." ".$this->getVal("libelle"); |
31 |
} |
32 |
|
33 |
/** |
34 |
* |
35 |
* @return array |
36 |
*/ |
37 |
function get_var_sql_forminc__champs() { |
38 |
return array( |
39 |
"contrainte", |
40 |
"numero", |
41 |
"nature", |
42 |
"groupe", |
43 |
"sousgroupe", |
44 |
"libelle", |
45 |
"texte", |
46 |
"no_ordre", |
47 |
"reference", |
48 |
"service_consulte", |
49 |
"om_validite_debut", |
50 |
"om_validite_fin", |
51 |
"om_collectivite", |
52 |
); |
53 |
} |
54 |
|
55 |
/** |
56 |
* |
57 |
* @return string |
58 |
*/ |
59 |
function get_var_sql_forminc__sql_om_collectivite() { |
60 |
return "SELECT om_collectivite.om_collectivite, om_collectivite.libelle FROM ".DB_PREFIXE."om_collectivite ORDER BY om_collectivite.libelle ASC"; |
61 |
} |
62 |
|
63 |
/** |
64 |
* |
65 |
* @return string |
66 |
*/ |
67 |
function get_var_sql_forminc__sql_om_collectivite_by_id() { |
68 |
return "SELECT om_collectivite.om_collectivite, om_collectivite.libelle FROM ".DB_PREFIXE."om_collectivite WHERE om_collectivite = <idx>"; |
69 |
} |
70 |
|
71 |
|
72 |
|
73 |
|
74 |
function setvalF($val = array()) { |
75 |
//affectation valeur formulaire |
76 |
if (!is_numeric($val['contrainte'])) { |
77 |
$this->valF['contrainte'] = ""; // -> requis |
78 |
} else { |
79 |
$this->valF['contrainte'] = $val['contrainte']; |
80 |
} |
81 |
if ($val['numero'] == "") { |
82 |
$this->valF['numero'] = NULL; |
83 |
} else { |
84 |
$this->valF['numero'] = $val['numero']; |
85 |
} |
86 |
$this->valF['nature'] = $val['nature']; |
87 |
if ($val['groupe'] == "") { |
88 |
$this->valF['groupe'] = NULL; |
89 |
} else { |
90 |
$this->valF['groupe'] = $val['groupe']; |
91 |
} |
92 |
if ($val['sousgroupe'] == "") { |
93 |
$this->valF['sousgroupe'] = NULL; |
94 |
} else { |
95 |
$this->valF['sousgroupe'] = $val['sousgroupe']; |
96 |
} |
97 |
$this->valF['libelle'] = $val['libelle']; |
98 |
$this->valF['texte'] = $val['texte']; |
99 |
if (!is_numeric($val['no_ordre'])) { |
100 |
$this->valF['no_ordre'] = NULL; |
101 |
} else { |
102 |
$this->valF['no_ordre'] = $val['no_ordre']; |
103 |
} |
104 |
if ($val['reference'] == 1 || $val['reference'] == "t" || $val['reference'] == "Oui") { |
105 |
$this->valF['reference'] = true; |
106 |
} else { |
107 |
$this->valF['reference'] = false; |
108 |
} |
109 |
if ($val['service_consulte'] == 1 || $val['service_consulte'] == "t" || $val['service_consulte'] == "Oui") { |
110 |
$this->valF['service_consulte'] = true; |
111 |
} else { |
112 |
$this->valF['service_consulte'] = false; |
113 |
} |
114 |
if ($val['om_validite_debut'] != "") { |
115 |
$this->valF['om_validite_debut'] = $this->dateDB($val['om_validite_debut']); |
116 |
} else { |
117 |
$this->valF['om_validite_debut'] = NULL; |
118 |
} |
119 |
if ($val['om_validite_fin'] != "") { |
120 |
$this->valF['om_validite_fin'] = $this->dateDB($val['om_validite_fin']); |
121 |
} else { |
122 |
$this->valF['om_validite_fin'] = NULL; |
123 |
} |
124 |
if (!is_numeric($val['om_collectivite'])) { |
125 |
$this->valF['om_collectivite'] = ""; // -> requis |
126 |
} else { |
127 |
if($_SESSION['niveau']==1) { |
128 |
$this->valF['om_collectivite'] = $_SESSION['collectivite']; |
129 |
} else { |
130 |
$this->valF['om_collectivite'] = $val['om_collectivite']; |
131 |
} |
132 |
} |
133 |
} |
134 |
|
135 |
//================================================= |
136 |
//cle primaire automatique [automatic primary key] |
137 |
//================================================== |
138 |
|
139 |
function setId(&$dnu1 = null) { |
140 |
//numero automatique |
141 |
$this->valF[$this->clePrimaire] = $this->f->db->nextId(DB_PREFIXE.$this->table); |
142 |
} |
143 |
|
144 |
function setValFAjout($val = array()) { |
145 |
//numero automatique -> pas de controle ajout cle primaire |
146 |
} |
147 |
|
148 |
function verifierAjout($val = array(), &$dnu1 = null) { |
149 |
//numero automatique -> pas de verfication de cle primaire |
150 |
} |
151 |
/** |
152 |
* Methode verifier |
153 |
*/ |
154 |
function verifier($val = array(), &$dnu1 = null, $dnu2 = null) { |
155 |
// On appelle la methode de la classe parent |
156 |
parent::verifier($val, $this->f->db, null); |
157 |
|
158 |
// gestion des dates de validites |
159 |
$date_debut = $this->valF['om_validite_debut']; |
160 |
$date_fin = $this->valF['om_validite_fin']; |
161 |
|
162 |
if ($date_debut != '' and $date_fin != '') { |
163 |
|
164 |
$date_debut = explode('-', $this->valF['om_validite_debut']); |
165 |
$date_fin = explode('-', $this->valF['om_validite_fin']); |
166 |
|
167 |
$time_debut = mktime(0, 0, 0, $date_debut[1], $date_debut[2], |
168 |
$date_debut[0]); |
169 |
$time_fin = mktime(0, 0, 0, $date_fin[1], $date_fin[2], |
170 |
$date_fin[0]); |
171 |
|
172 |
if ($time_debut > $time_fin or $time_debut == $time_fin) { |
173 |
$this->correct = false; |
174 |
$this->addToMessage(__('La date de fin de validite doit etre future a la de debut de validite.')); |
175 |
} |
176 |
} |
177 |
} |
178 |
|
179 |
|
180 |
//========================== |
181 |
// Formulaire [form] |
182 |
//========================== |
183 |
/** |
184 |
* |
185 |
*/ |
186 |
function setType(&$form, $maj) { |
187 |
// Récupération du mode de l'action |
188 |
$crud = $this->get_action_crud($maj); |
189 |
|
190 |
// MODE AJOUTER |
191 |
if ($maj == 0 || $crud == 'create') { |
192 |
$form->setType("contrainte", "hidden"); |
193 |
$form->setType("numero", "text"); |
194 |
$form->setType("nature", "text"); |
195 |
$form->setType("groupe", "text"); |
196 |
$form->setType("sousgroupe", "text"); |
197 |
$form->setType("libelle", "text"); |
198 |
$form->setType("texte", "textarea"); |
199 |
$form->setType("no_ordre", "text"); |
200 |
$form->setType("reference", "checkbox"); |
201 |
$form->setType("service_consulte", "checkbox"); |
202 |
if ($this->f->isAccredited(array($this->table."_modifier_validite", $this->table, ))) { |
203 |
$form->setType("om_validite_debut", "date"); |
204 |
} else { |
205 |
$form->setType("om_validite_debut", "hiddenstaticdate"); |
206 |
} |
207 |
if ($this->f->isAccredited(array($this->table."_modifier_validite", $this->table, ))) { |
208 |
$form->setType("om_validite_fin", "date"); |
209 |
} else { |
210 |
$form->setType("om_validite_fin", "hiddenstaticdate"); |
211 |
} |
212 |
if ($this->is_in_context_of_foreign_key("om_collectivite", $this->retourformulaire)) { |
213 |
if($_SESSION["niveau"] == 2) { |
214 |
$form->setType("om_collectivite", "selecthiddenstatic"); |
215 |
} else { |
216 |
$form->setType("om_collectivite", "hidden"); |
217 |
} |
218 |
} else { |
219 |
if($_SESSION["niveau"] == 2) { |
220 |
$form->setType("om_collectivite", "select"); |
221 |
} else { |
222 |
$form->setType("om_collectivite", "hidden"); |
223 |
} |
224 |
} |
225 |
} |
226 |
|
227 |
// MDOE MODIFIER |
228 |
if ($maj == 1 || $crud == 'update') { |
229 |
$form->setType("contrainte", "hiddenstatic"); |
230 |
$form->setType("numero", "text"); |
231 |
$form->setType("nature", "text"); |
232 |
$form->setType("groupe", "text"); |
233 |
$form->setType("sousgroupe", "text"); |
234 |
$form->setType("libelle", "text"); |
235 |
$form->setType("texte", "textarea"); |
236 |
$form->setType("no_ordre", "text"); |
237 |
$form->setType("reference", "checkbox"); |
238 |
$form->setType("service_consulte", "checkbox"); |
239 |
if ($this->f->isAccredited(array($this->table."_modifier_validite", $this->table, ))) { |
240 |
$form->setType("om_validite_debut", "date"); |
241 |
} else { |
242 |
$form->setType("om_validite_debut", "hiddenstaticdate"); |
243 |
} |
244 |
if ($this->f->isAccredited(array($this->table."_modifier_validite", $this->table, ))) { |
245 |
$form->setType("om_validite_fin", "date"); |
246 |
} else { |
247 |
$form->setType("om_validite_fin", "hiddenstaticdate"); |
248 |
} |
249 |
if ($this->is_in_context_of_foreign_key("om_collectivite", $this->retourformulaire)) { |
250 |
if($_SESSION["niveau"] == 2) { |
251 |
$form->setType("om_collectivite", "selecthiddenstatic"); |
252 |
} else { |
253 |
$form->setType("om_collectivite", "hidden"); |
254 |
} |
255 |
} else { |
256 |
if($_SESSION["niveau"] == 2) { |
257 |
$form->setType("om_collectivite", "select"); |
258 |
} else { |
259 |
$form->setType("om_collectivite", "hidden"); |
260 |
} |
261 |
} |
262 |
} |
263 |
|
264 |
// MODE SUPPRIMER |
265 |
if ($maj == 2 || $crud == 'delete') { |
266 |
$form->setType("contrainte", "hiddenstatic"); |
267 |
$form->setType("numero", "hiddenstatic"); |
268 |
$form->setType("nature", "hiddenstatic"); |
269 |
$form->setType("groupe", "hiddenstatic"); |
270 |
$form->setType("sousgroupe", "hiddenstatic"); |
271 |
$form->setType("libelle", "hiddenstatic"); |
272 |
$form->setType("texte", "hiddenstatic"); |
273 |
$form->setType("no_ordre", "hiddenstatic"); |
274 |
$form->setType("reference", "hiddenstatic"); |
275 |
$form->setType("service_consulte", "hiddenstatic"); |
276 |
$form->setType("om_validite_debut", "hiddenstatic"); |
277 |
$form->setType("om_validite_fin", "hiddenstatic"); |
278 |
if ($_SESSION["niveau"] == 2) { |
279 |
$form->setType("om_collectivite", "selectstatic"); |
280 |
} else { |
281 |
$form->setType("om_collectivite", "hidden"); |
282 |
} |
283 |
} |
284 |
|
285 |
// MODE CONSULTER |
286 |
if ($maj == 3 || $crud == 'read') { |
287 |
$form->setType("contrainte", "static"); |
288 |
$form->setType("numero", "static"); |
289 |
$form->setType("nature", "static"); |
290 |
$form->setType("groupe", "static"); |
291 |
$form->setType("sousgroupe", "static"); |
292 |
$form->setType("libelle", "static"); |
293 |
$form->setType("texte", "textareastatic"); |
294 |
$form->setType("no_ordre", "static"); |
295 |
$form->setType("reference", "checkboxstatic"); |
296 |
$form->setType("service_consulte", "checkboxstatic"); |
297 |
$form->setType("om_validite_debut", "datestatic"); |
298 |
$form->setType("om_validite_fin", "datestatic"); |
299 |
if ($this->is_in_context_of_foreign_key("om_collectivite", $this->retourformulaire)) { |
300 |
if($_SESSION["niveau"] == 2) { |
301 |
$form->setType("om_collectivite", "selectstatic"); |
302 |
} else { |
303 |
$form->setType("om_collectivite", "hidden"); |
304 |
} |
305 |
} else { |
306 |
if($_SESSION["niveau"] == 2) { |
307 |
$form->setType("om_collectivite", "selectstatic"); |
308 |
} else { |
309 |
$form->setType("om_collectivite", "hidden"); |
310 |
} |
311 |
} |
312 |
} |
313 |
|
314 |
} |
315 |
|
316 |
|
317 |
function setOnchange(&$form, $maj) { |
318 |
//javascript controle client |
319 |
$form->setOnchange('contrainte','VerifNum(this)'); |
320 |
$form->setOnchange('no_ordre','VerifNum(this)'); |
321 |
$form->setOnchange('om_validite_debut','fdate(this)'); |
322 |
$form->setOnchange('om_validite_fin','fdate(this)'); |
323 |
$form->setOnchange('om_collectivite','VerifNum(this)'); |
324 |
} |
325 |
/** |
326 |
* Methode setTaille |
327 |
*/ |
328 |
function setTaille(&$form, $maj) { |
329 |
$form->setTaille("contrainte", 11); |
330 |
$form->setTaille("numero", 30); |
331 |
$form->setTaille("nature", 10); |
332 |
$form->setTaille("groupe", 30); |
333 |
$form->setTaille("sousgroupe", 30); |
334 |
$form->setTaille("libelle", 30); |
335 |
$form->setTaille("texte", 80); |
336 |
$form->setTaille("no_ordre", 11); |
337 |
$form->setTaille("reference", 1); |
338 |
$form->setTaille("service_consulte", 1); |
339 |
$form->setTaille("om_validite_debut", 12); |
340 |
$form->setTaille("om_validite_fin", 12); |
341 |
$form->setTaille("om_collectivite", 11); |
342 |
} |
343 |
|
344 |
/** |
345 |
* Methode setMax |
346 |
*/ |
347 |
function setMax(&$form, $maj) { |
348 |
$form->setMax("contrainte", 11); |
349 |
$form->setMax("numero", 250); |
350 |
$form->setMax("nature", 10); |
351 |
$form->setMax("groupe", 250); |
352 |
$form->setMax("sousgroupe", 250); |
353 |
$form->setMax("libelle", 250); |
354 |
$form->setMax("texte", 6); |
355 |
$form->setMax("no_ordre", 11); |
356 |
$form->setMax("reference", 1); |
357 |
$form->setMax("service_consulte", 1); |
358 |
$form->setMax("om_validite_debut", 12); |
359 |
$form->setMax("om_validite_fin", 12); |
360 |
$form->setMax("om_collectivite", 11); |
361 |
} |
362 |
|
363 |
|
364 |
function setLib(&$form, $maj) { |
365 |
//libelle des champs |
366 |
$form->setLib('contrainte', __('contrainte')); |
367 |
$form->setLib('numero', __('numero')); |
368 |
$form->setLib('nature', __('nature')); |
369 |
$form->setLib('groupe', __('groupe')); |
370 |
$form->setLib('sousgroupe', __('sousgroupe')); |
371 |
$form->setLib('libelle', __('libelle')); |
372 |
$form->setLib('texte', __('texte')); |
373 |
$form->setLib('no_ordre', __('no_ordre')); |
374 |
$form->setLib('reference', __('reference')); |
375 |
$form->setLib('service_consulte', __('service_consulte')); |
376 |
$form->setLib('om_validite_debut', __('om_validite_debut')); |
377 |
$form->setLib('om_validite_fin', __('om_validite_fin')); |
378 |
$form->setLib('om_collectivite', __('om_collectivite')); |
379 |
} |
380 |
/** |
381 |
* |
382 |
*/ |
383 |
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
384 |
|
385 |
// om_collectivite |
386 |
$this->init_select( |
387 |
$form, |
388 |
$this->f->db, |
389 |
$maj, |
390 |
null, |
391 |
"om_collectivite", |
392 |
$this->get_var_sql_forminc__sql("om_collectivite"), |
393 |
$this->get_var_sql_forminc__sql("om_collectivite_by_id"), |
394 |
false |
395 |
); |
396 |
} |
397 |
|
398 |
|
399 |
function setVal(&$form, $maj, $validation, &$dnu1 = null, $dnu2 = null) { |
400 |
if($validation==0 and $maj==0 and $_SESSION['niveau']==1) { |
401 |
$form->setVal('om_collectivite', $_SESSION['collectivite']); |
402 |
}// fin validation |
403 |
$this->set_form_default_values($form, $maj, $validation); |
404 |
}// fin setVal |
405 |
|
406 |
//================================== |
407 |
// sous Formulaire |
408 |
//================================== |
409 |
|
410 |
|
411 |
function setValsousformulaire(&$form, $maj, $validation, $idxformulaire, $retourformulaire, $typeformulaire, &$dnu1 = null, $dnu2 = null) { |
412 |
$this->retourformulaire = $retourformulaire; |
413 |
if($validation==0 and $maj==0 and $_SESSION['niveau']==1) { |
414 |
$form->setVal('om_collectivite', $_SESSION['collectivite']); |
415 |
}// fin validation |
416 |
if($validation == 0) { |
417 |
if($this->is_in_context_of_foreign_key('om_collectivite', $this->retourformulaire)) |
418 |
$form->setVal('om_collectivite', $idxformulaire); |
419 |
}// fin validation |
420 |
$this->set_form_default_values($form, $maj, $validation); |
421 |
}// fin setValsousformulaire |
422 |
|
423 |
//================================== |
424 |
// cle secondaire |
425 |
//================================== |
426 |
|
427 |
/** |
428 |
* Methode clesecondaire |
429 |
*/ |
430 |
function cleSecondaire($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
431 |
// On appelle la methode de la classe parent |
432 |
parent::cleSecondaire($id); |
433 |
// Verification de la cle secondaire : dossier_contrainte |
434 |
$this->rechercheTable($this->f->db, "dossier_contrainte", "contrainte", $id); |
435 |
} |
436 |
|
437 |
|
438 |
} |