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