1 |
<?php |
2 |
/** |
3 |
* Script personnalisé pour les consultations multiples. |
4 |
* |
5 |
* @package openfoncier |
6 |
* @version SVN : $Id$ |
7 |
*/ |
8 |
|
9 |
require_once "../obj/utils.class.php"; |
10 |
|
11 |
// Identifiant de l'objet metier a copier |
12 |
(isset($_GET['idx']) ? $idx = $_GET['idx'] : $idx = ""); |
13 |
// Nom de l'objet metier |
14 |
(isset($_GET['obj']) ? $obj = $_GET['obj'] : $obj = ""); |
15 |
//formulaire retour |
16 |
(isset($_GET['ret']) ? $retourformulaire = $_GET['ret'] : $retourformulaire = ""); |
17 |
(isset($_GET['date_envoi']) ? $date_envoi = $_GET['date_envoi'] : $date_envoi = ""); |
18 |
|
19 |
$f = new utils("nohtml"); |
20 |
|
21 |
$liste_gauche = ""; |
22 |
|
23 |
if ( isset($_GET) && isset($_GET['data']) && !empty($_GET['data']) ){ |
24 |
$f->disableLog(); |
25 |
/*Récupération des données et formatage.*/ |
26 |
$donnees_temp = explode(';', $_GET['data']); |
27 |
for ( $i = 1 ; $i < count($donnees_temp) ; $i++ ) |
28 |
$donnees[] = explode('_', $donnees_temp[$i]); |
29 |
|
30 |
/* Nombre de consultations papier à générer */ |
31 |
$nbConsPap = 0; |
32 |
|
33 |
/* Ajout des données en base de données |
34 |
* 0 : l'ID du service |
35 |
* 1 : consultation papier {0,1} |
36 |
* */ |
37 |
if ( isset($donnees) && count($donnees) > 0 ){ |
38 |
|
39 |
require_once "../core/om_dbform.class.php"; |
40 |
$om_dbform = new dbForm(); |
41 |
require_once "../obj/consultation.class.php"; |
42 |
$consultation = new consultation("]",$f->db,DEBUG); |
43 |
|
44 |
foreach ($donnees as $value) { |
45 |
|
46 |
$sql = "SELECT delai FROM service WHERE service = $value[0]"; |
47 |
$res = $f->db->query($sql); |
48 |
$f->isDatabaseError($res); |
49 |
$row=& $res->fetchRow(); |
50 |
$delai = $row[0]; |
51 |
|
52 |
/*Calcul du delai de retour*/ |
53 |
$date_envoi_temp = $om_dbform->datePHP($date_envoi); |
54 |
$delai = $om_dbform->dateDB($consultation->moisdate($date_envoi_temp, $delai)); |
55 |
|
56 |
/*Les données à ajouter*/ |
57 |
$arrayVal = array( |
58 |
'consultation' => "]", |
59 |
'dossier' => $idx, |
60 |
'date_envoi' => $date_envoi, |
61 |
'date_retour' => NULL, |
62 |
'date_limite' => $delai, |
63 |
'service' => $value[0], |
64 |
'avis_consultation' => NULL, |
65 |
'date_reception' => NULL, |
66 |
'motivation' => "", |
67 |
'fichier' => NULL, |
68 |
'lu' => TRUE |
69 |
); |
70 |
|
71 |
$consultation->ajouter($arrayVal, $f->db, DEBUG); |
72 |
|
73 |
/*Comptage du nombre de consultations papier demandées et récupération des ids des PDFs à éditer*/ |
74 |
if ($value[1]==1){ |
75 |
$idxConsultations[] = $consultation->valF['consultation']; |
76 |
$nbConsPap++; |
77 |
} |
78 |
} |
79 |
|
80 |
/*Génération du PDF*/ |
81 |
if ( isset($idxConsultations) && count($idxConsultations) > 0 ){ |
82 |
|
83 |
$textIdsConsultations = ""; |
84 |
foreach ($idxConsultations as $value) |
85 |
$textIdsConsultations .= "&idxConsultations[]=$value"; |
86 |
|
87 |
echo " |
88 |
<script language='javascript' type='text/javascript'> |
89 |
$.download('../app/pdfetat.php','obj=$obj$textIdsConsultations', 'POST', $obj); |
90 |
</script> |
91 |
"; |
92 |
} |
93 |
/*Affichage du message d'information*/ |
94 |
$f->displayMessage("valid", count($donnees)._(' service(s) selectionne(s) dont ').$nbConsPap._(' consultation(s) papier.')); |
95 |
} |
96 |
|
97 |
} |
98 |
else { |
99 |
/*Requête qui récupère les services qui sont dans des thématiques*/ |
100 |
$sql = |
101 |
"SELECT |
102 |
ser_cat.service_categorie, ser_cat.libelle AS them_lib, |
103 |
ser.service, ser.libelle AS ser_lib, ser.consultation_papier |
104 |
FROM |
105 |
".DB_PREFIXE."lien_service_service_categorie lie, |
106 |
".DB_PREFIXE."service_categorie ser_cat, |
107 |
".DB_PREFIXE."service ser |
108 |
WHERE |
109 |
ser_cat.service_categorie = lie.service_categorie AND |
110 |
ser.service = lie.service AND |
111 |
( |
112 |
ser.om_validite_fin <= CURRENT_DATE OR |
113 |
ser.om_validite_fin IS NULL |
114 |
) |
115 |
"; |
116 |
|
117 |
$res = $f->db->query($sql); |
118 |
$f->isDatabaseError($res); |
119 |
|
120 |
$temp_ser_cat = 0; |
121 |
while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)) { |
122 |
$name = $row['service_categorie'].'_'. |
123 |
$row['service'].'_'. |
124 |
(($row['consultation_papier'] == '' || $row['consultation_papier'] == 'f' ) ? '0' : '1' ).'_'; |
125 |
/*On change de thématique, donc rajoute le nom de la thématique*/ |
126 |
if ( $temp_ser_cat != $row['service_categorie'] ){ |
127 |
|
128 |
$temp_ser_cat = $row['service_categorie']; |
129 |
$liste_gauche .= ' |
130 |
<div id="them_'.$row['service_categorie'].'" class="liste_gauche_them" >'. |
131 |
$row['them_lib']. |
132 |
'</div> |
133 |
<div |
134 |
class="liste_gauche_service t'.$name.'" |
135 |
id="t'.$name.'" > |
136 |
'.$row['ser_lib'].' |
137 |
<input class="t'.$name.'" type="checkbox" '.(($row['consultation_papier'] == '' || $row['consultation_papier'] == 'f' ) ? '' : 'checked="checked"' ).'/> |
138 |
</div> |
139 |
'; |
140 |
} |
141 |
|
142 |
/*On est dans la même thématique*/ |
143 |
else { |
144 |
|
145 |
$liste_gauche .= ' |
146 |
<div |
147 |
class="liste_gauche_service t'.$name.'" |
148 |
id="t'.$name.'" > |
149 |
'.$row['ser_lib'].' |
150 |
<input class="t'.$name.'" type="checkbox" '.(($row['consultation_papier'] == '' || $row['consultation_papier'] == 'f' ) ? '' : 'checked="checked"' ).'/> |
151 |
</div> |
152 |
'; |
153 |
} |
154 |
|
155 |
} |
156 |
|
157 |
/*Requête qui récupère les services qui ne sont pas dans une thématique*/ |
158 |
$sql = |
159 |
"SELECT service, libelle, consultation_papier |
160 |
FROM ".DB_PREFIXE."service |
161 |
WHERE service NOT IN |
162 |
( |
163 |
SELECT service |
164 |
FROM ".DB_PREFIXE."lien_service_service_categorie |
165 |
) |
166 |
AND |
167 |
( |
168 |
om_validite_fin <= CURRENT_DATE OR |
169 |
om_validite_fin IS NULL |
170 |
) |
171 |
"; |
172 |
|
173 |
$res = $f->db->query($sql); |
174 |
$f->isDatabaseError($res); |
175 |
|
176 |
if ( $res->numrows() > 0 ) |
177 |
$liste_gauche .= ' |
178 |
<div id="them_0" class="liste_gauche_them">Autres</div>'; |
179 |
|
180 |
while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)) { |
181 |
|
182 |
/*Ajout de tous les services qui n'ont pas de thématique*/ |
183 |
$name = '0_'. |
184 |
$row['service'].'_'. |
185 |
(($row['consultation_papier'] == '' || $row['consultation_papier'] == 'f' ) ? '0' : '1' ).'_'; |
186 |
$liste_gauche .= ' |
187 |
<div |
188 |
class="liste_gauche_service t'.$name.'" |
189 |
id="t'.$name.'" > |
190 |
'.$row['libelle'].' |
191 |
<input class="t'.$name.'" type="checkbox" '.(($row['consultation_papier'] == '' || $row['consultation_papier'] == 'f' ) ? '' : 'checked="checked"' ).'/> |
192 |
</div> |
193 |
'; |
194 |
} |
195 |
|
196 |
/*Affichage du formulaire*/ |
197 |
echo '<div class="subtitle">'; |
198 |
echo '<h3>'; |
199 |
echo _("Application"); |
200 |
echo '<span class="om-icon om-icon-16 om-icon-fix arrow-right-16"></span>'; |
201 |
echo _("consultation"); |
202 |
echo '</h3>'; |
203 |
echo '</div>'; |
204 |
echo '<div class="sformulaire">'; |
205 |
echo '<form onsubmit="ajaxIt(\'consultation\', \'../app/consultation_multiple.php\');return false;" |
206 |
method="get" action="" name="f2" id="form_val">'; |
207 |
echo '<div class="formEntete ui-corner-all">'; |
208 |
echo "<div>"; |
209 |
echo '<div class="bloc">'; |
210 |
echo "<fieldset class='cadre ui-corner-all ui-widget-content'>\n"; |
211 |
echo "\t<legend class='ui-corner-all ui-widget-content ui-state-active'>". |
212 |
_("Consultation par thematique ")."</legend>"; |
213 |
echo "<div class='fieldsetContent' style='width:100%'>"; |
214 |
echo '<div class="field-ser-them field-type-hiddenstatic">'; |
215 |
echo '<div class="form-libelle">'; |
216 |
echo '<label class="libelle-dossier" for="dossier">'; |
217 |
echo _('dossier'); |
218 |
echo '<span class="not-null-tag">*</span>'; |
219 |
echo '</label>'; |
220 |
echo '</div>'; |
221 |
echo '<div class="form-content">'; |
222 |
echo '<input class="champFormulaire" type="hidden" value="'.$idx.'" name="dossier"/>'; |
223 |
echo $idx; |
224 |
echo '</div>'; |
225 |
echo '</div>'; |
226 |
/*Code du nouveau champ*/ |
227 |
echo '<div class="field-ser-them ser-them">'; |
228 |
echo '<div class="list-ser-them">'; |
229 |
echo $liste_gauche; |
230 |
echo '</div>'; |
231 |
echo '<div class="button-ser-them">'; |
232 |
echo '<ul>'; |
233 |
echo '<li>'; |
234 |
echo '<input type="button" value="'._("Ajouter").' >>" id="add-ser-them"/>'; |
235 |
echo '</li>'; |
236 |
echo '<li>'; |
237 |
echo '<input type="button" value="<< '._("Supprimer").'" id="del-ser-them"/>'; |
238 |
echo '</li>'; |
239 |
echo '</ul>'; |
240 |
echo '</div>'; |
241 |
echo '<div class="list-sel-ser-them">'; |
242 |
echo '<div class=\'row\'>'; |
243 |
echo '<div class=\'cell1 liste_droite_title list-sel-ser-them-title\'>'._('Service a consulter').'</div>'; |
244 |
echo '<div class=\'cell2 liste_droite_title list-sel-ser-them-title\'>'._('Version papier').'</div>'; |
245 |
echo '</div>'; |
246 |
echo '</div>'; |
247 |
echo '</div>'; |
248 |
/* -- FIN --*/ |
249 |
echo '<div class="field-ser-them field-type-date2">'; |
250 |
echo '<div class="form-libelle">'; |
251 |
echo '<label class="libelle-date_envoi" for="date_envoi">'; |
252 |
echo _('date_envoi'); |
253 |
echo '<span class="not-null-tag">*</span>'; |
254 |
echo '</label>'; |
255 |
echo '</div>'; |
256 |
echo '<div class="form-content">'; |
257 |
echo '<input id="date_envoi" class="champFormulaire datepicker" |
258 |
type="text" onkeyup="" onchange="fdate(this)" |
259 |
maxlength="10" size="12" value="'.date("d/m/Y").'" |
260 |
name="date_envoi">'; |
261 |
echo '</div>'; |
262 |
echo '</div>'; |
263 |
echo "</div>"; |
264 |
echo "</fieldset>"; |
265 |
echo '</div>'; |
266 |
echo '</div>'; |
267 |
echo '</div>'; |
268 |
echo '<div class="formControls">'; |
269 |
echo '<input class="om-button ui-button ui-widget ui-state-default ui-corner-all" |
270 |
type="button" onclick="if ( $(\'.liste_gauche_service_selected\').length > 0 && $(\'#date_envoi\').val() != \'\' ) { ajaxIt(\'consultation\', \'../app/consultation_multiple.php\'); } else alert(\'Veuillez choisir au moins un service et une date d envoi\');" |
271 |
value="Ajouter le(s) enregistrement(s) de la table : \'Consultation\'" |
272 |
id="button_val">'; |
273 |
echo '<a class="retour" onclick="ajaxIt(\'consultation\', \'../scr/soustab.php?obj='.$obj.'&retourformulaire='.$retourformulaire.'&idxformulaire='.$idx.'&premier=0&tricol=\');" |
274 |
href="#">'; |
275 |
echo 'Retour'; |
276 |
echo '</a>'; |
277 |
echo '</div>'; |
278 |
echo '</form>'; |
279 |
echo '</div>'; |
280 |
|
281 |
echo " |
282 |
<script language='javascript' type='text/javascript'> |
283 |
$(function(){ |
284 |
|
285 |
/* |
286 |
Sélectionne tous les services d'un thème au clique sur celui ci. |
287 |
*/ |
288 |
$('.liste_gauche_them').click( |
289 |
function(){ |
290 |
|
291 |
var id = $(this).attr('id').split('_')[1]; |
292 |
var numSer = 0; |
293 |
var numSerWithClass = 0; |
294 |
|
295 |
$('.list-ser-them div').each( |
296 |
function() { |
297 |
|
298 |
if ( $(this).attr('id').indexOf('them') == -1 && |
299 |
$(this).attr('id').indexOf(id) == 1 && |
300 |
$(this).hasClass('liste_gauche_service_selected') ) |
301 |
|
302 |
numSerWithClass++; |
303 |
|
304 |
if ( $(this).attr('id').indexOf('them') == -1 && |
305 |
$(this).attr('id').indexOf(id) == 1 ) |
306 |
|
307 |
numSer++; |
308 |
} |
309 |
); |
310 |
|
311 |
if ( numSerWithClass < numSer && numSerWithClass >= 0 ){ |
312 |
|
313 |
$('.list-ser-them div').each( |
314 |
function() { |
315 |
|
316 |
if ( $(this).attr('id').indexOf('them') == -1 && |
317 |
$(this).attr('id').indexOf(id) == 1 && |
318 |
!$(this).hasClass('liste_gauche_service_selected') ) |
319 |
|
320 |
$(this).addClass('liste_gauche_service_selected'); |
321 |
} |
322 |
); |
323 |
} |
324 |
|
325 |
else { |
326 |
|
327 |
$('.list-ser-them div').each( |
328 |
function() { |
329 |
|
330 |
if ( $(this).attr('id').indexOf('them') == -1 && |
331 |
$(this).attr('id').indexOf(id) == 1 && |
332 |
$(this).hasClass('liste_gauche_service_selected') ) |
333 |
|
334 |
$(this).removeClass('liste_gauche_service_selected'); |
335 |
} |
336 |
); |
337 |
} |
338 |
} |
339 |
); |
340 |
|
341 |
/* |
342 |
Change la class CSS d'un service sur lequel on clique dans la liste de gauche. |
343 |
*/ |
344 |
$('.liste_gauche_service').click( |
345 |
function(){ |
346 |
$(this).toggleClass('liste_gauche_service_selected'); |
347 |
} |
348 |
); |
349 |
|
350 |
/* |
351 |
Change la class CSS d'un service sur lequel on clique dans la liste de droite. |
352 |
*/ |
353 |
$('.field-ser-them').on( |
354 |
'click', |
355 |
'.cell1', |
356 |
function(){ |
357 |
if ( !$(this).hasClass('liste_droite_title') ) |
358 |
$(this).parent().toggleClass('liste_droite_service_selected'); |
359 |
} |
360 |
); |
361 |
|
362 |
$('.liste_droite_service input[type=checkbox]').live( |
363 |
'click', |
364 |
'input[type=checkbox]', |
365 |
function(){ |
366 |
|
367 |
old_id = $(this).attr('class'); |
368 |
|
369 |
tab_don = old_id.split('_'); |
370 |
|
371 |
new_id = tab_don[0] + '_' + tab_don[1] + '_' + ((tab_don[2] == 0 ) ? 1 : 0 ) + '_'; |
372 |
|
373 |
changeOneData( ';' + tab_don[1] + '_' + tab_don[2], ';' + tab_don[1] + '_' + ((tab_don[2] == 0) ? 1 : 0) ); |
374 |
$('div[class=\"' + old_id + '\"]').attr('class', new_id); |
375 |
$(this).attr('class', new_id); |
376 |
|
377 |
} |
378 |
); |
379 |
|
380 |
$('#date_envoi').change( |
381 |
function (){ |
382 |
|
383 |
var listServ = new Array(); |
384 |
var data = ''; |
385 |
|
386 |
$('.liste_gauche_service_selected').each( |
387 |
function(i) { |
388 |
|
389 |
var name = $(this).attr('name'); |
390 |
|
391 |
if ( listServ.length > 0 && listServ.indexOf(name.split('_')[1]) != -1 ) |
392 |
return; |
393 |
listServ[i] = name.split('_')[1]; |
394 |
data += ';' + name.split('_')[1] + '_' + name.split('_')[2] ; |
395 |
|
396 |
} |
397 |
); |
398 |
|
399 |
changeActionVal(data); |
400 |
} |
401 |
); |
402 |
|
403 |
/* |
404 |
Passe les services sélectionnés dans la liste de gauche dans celle de droite. |
405 |
*/ |
406 |
$('#add-ser-them').click( |
407 |
function() { |
408 |
|
409 |
changeDataLeftColumn(); |
410 |
} |
411 |
); |
412 |
|
413 |
/* |
414 |
Passe les services sélectionnés dans la liste de droite dans celle de gauche. |
415 |
*/ |
416 |
$('#del-ser-them').click( |
417 |
function() { |
418 |
|
419 |
var data = ''; |
420 |
|
421 |
$('.liste_droite_service_selected').each( |
422 |
function() { |
423 |
|
424 |
var name = $('#'+ $(this).attr('id') + ' .cell1 div').attr('name'); |
425 |
|
426 |
manageListServ('.list-ser-them div', name, 1); |
427 |
data += ';' + name.split('_')[1] + '_' + name.split('_')[2] ; |
428 |
|
429 |
$(this).remove(); |
430 |
} |
431 |
); |
432 |
|
433 |
changeActionVal(data); |
434 |
} |
435 |
); |
436 |
}); |
437 |
|
438 |
/* |
439 |
Vérifie que l'objet n'est pas une thématique et que son identifiant correspond. |
440 |
*/ |
441 |
function isNotthemIsOneServ( objet, id ){ |
442 |
return ( $(objet).attr('id').indexOf('them') == -1 && |
443 |
$(objet).attr('id').indexOf('_' + id.split('_')[1] + '_') != -1 ); |
444 |
} |
445 |
|
446 |
/* |
447 |
Affiche ou cache un élément qui n'est pas une thématique et dont son identifiant correspond. |
448 |
*/ |
449 |
function manageListServ( objet , name, type){ |
450 |
|
451 |
$(objet).each( |
452 |
function() { |
453 |
|
454 |
if ( isNotthemIsOneServ(this, name) ){ |
455 |
if ( type == 0 ) |
456 |
|
457 |
$(this).hide() ; |
458 |
|
459 |
else { |
460 |
|
461 |
if ( $(this).hasClass('liste_gauche_service_selected') ) |
462 |
|
463 |
$(this).toggleClass('liste_gauche_service_selected'); |
464 |
|
465 |
$(this).show() ; |
466 |
|
467 |
} |
468 |
} |
469 |
} |
470 |
); |
471 |
} |
472 |
|
473 |
/* |
474 |
Change les actions qui sont réalisées lors de la soumission du formulaire |
475 |
*/ |
476 |
function changeActionVal(data){ |
477 |
date = $('#date_envoi').val(); |
478 |
|
479 |
$('#form_val').attr( |
480 |
'onsubmit', |
481 |
'if ( $(\'.liste_gauche_service_selected\').length > 0 && $(\'#date_envoi\').val() != \'\' ) { messageIt(\'consultation\', \'../app/consultation_multiple.php?obj=$obj&data='+data+'&idx=$idx&date_envoi='+date+'\',true);return false;' + |
482 |
'messageIt(\'consultation\', \'../scr/soustab.php?obj=$obj&retourformulaire=$retourformulaire&idxformulaire=$idx&premier=0&tricol=\',false);} else alert(\'Veuillez choisir au moins un service et une date d envoi\');' |
483 |
|
484 |
); |
485 |
$('#button_val').attr( |
486 |
'onclick', |
487 |
'if ( $(\'.liste_gauche_service_selected\').length > 0 && $(\'#date_envoi\').val() != \'\' ) { messageIt(\'consultation\', \'../app/consultation_multiple.php?obj=$obj&data='+data+'&idx=$idx&date_envoi='+date+'\',true);' + |
488 |
'messageIt(\'consultation\', \'../scr/soustab.php?obj=$obj&retourformulaire=$retourformulaire&idxformulaire=$idx&premier=0&tricol=\',false);} else alert(\'Veuillez choisir au moins un service et une date d envoi\');' |
489 |
|
490 |
); |
491 |
} |
492 |
|
493 |
/* |
494 |
Change les actions qui sont réalisées lors de la soumission du formulaire |
495 |
*/ |
496 |
function changeOneData( oldData, newData) { |
497 |
|
498 |
date = $('#date_envoi').val(); |
499 |
|
500 |
$('#form_val').attr( |
501 |
'onsubmit', |
502 |
$('#form_val').attr('onsubmit').replace(oldData,newData) |
503 |
); |
504 |
$('#button_val').attr( |
505 |
'onclick', |
506 |
$('#button_val').attr('onclick').replace(oldData,newData) |
507 |
); |
508 |
} |
509 |
|
510 |
function changeDataLeftColumn(){ |
511 |
|
512 |
$('.list-sel-ser-them').empty(); |
513 |
$('.list-sel-ser-them').html( |
514 |
'<div class=\"row\">' + |
515 |
'<div class=\"cell1 liste_droite_title list-sel-ser-them-title\">Service a consulter</div>' + |
516 |
'<div class=\"cell2 liste_droite_title list-sel-ser-them-title\">Version papier</div>' + |
517 |
'</div>' |
518 |
); |
519 |
|
520 |
var listServ = new Array(); |
521 |
var data = ''; |
522 |
|
523 |
$('.liste_gauche_service_selected').each( |
524 |
function(i) { |
525 |
|
526 |
var id = $(this).attr('id'); |
527 |
|
528 |
if ( $.inArray(id.split('_')[1], listServ) != -1 ) |
529 |
return; |
530 |
|
531 |
data += ';' + id.split('_')[1] + '_' + id.split('_')[2] ; |
532 |
listServ[i] = id.split('_')[1]; |
533 |
|
534 |
$('.list-sel-ser-them').append( |
535 |
'<div id=\'s' + i + '\' class=\'row liste_droite_service\'>'+ |
536 |
'<div class=\'cell1\'>'+ |
537 |
'<div class=\'' + $(this).attr('id') + '\' name=\'' + $(this).attr('id') + '\'>'+ |
538 |
$(this).html().split('<')[0]+ |
539 |
'</div>'+ |
540 |
'</div>' + |
541 |
'<div class=\'cell2\'>'+ |
542 |
'<div>'+ |
543 |
'<input class=\'' + $(this).attr('id') + '\''+$(this).html().split('<input')[1]+ |
544 |
'</div>'+ |
545 |
'</div>'+ |
546 |
'</div>' |
547 |
); |
548 |
|
549 |
$(this).hide(); |
550 |
|
551 |
manageListServ('.list-ser-them div', id, 0); |
552 |
|
553 |
} |
554 |
); |
555 |
changeActionVal(data); |
556 |
} |
557 |
</script>"; |
558 |
} |
559 |
?> |