/[openfoncier]/trunk/app/consultation_multiple.php
ViewVC logotype

Annotation of /trunk/app/consultation_multiple.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 606 - (hide annotations)
Tue Nov 6 09:57:46 2012 UTC (12 years, 3 months ago) by vpihour
File size: 26739 byte(s)
Correction mineur

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26