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