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

Annotation of /trunk/app/consultation_multiple.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 576 - (hide annotations)
Fri Nov 2 10:09:06 2012 UTC (12 years, 3 months ago) by vpihour
File size: 26575 byte(s)
Correction du formulaire d'ajout de consultations multiple

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     <script>
89     $.download('../app/pdfetat.php','obj=$obj$textIdsConsultations', 'POST', $obj);
90     </script>
91     ";
92     }
93 vpihour 534 /*Affichage du message d'information*/
94 vpihour 555 $f->displayMessage("valid", count($donnees)._(' service(s) s&eacute;lectionn&eacute;(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 536 class="liste_gauche_service '.$name.'"
135 vpihour 534 id="'.$name.'" >
136     '.$row['ser_lib'].'
137 vpihour 536 <input id="'.$name.'" type="checkbox" '.(($row['consultation_papier'] == '' || $row['consultation_papier'] == FALSE ) ? '' : '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 536 class="liste_gauche_service '.$name.'"
148     id="'.$name.'" >
149 vpihour 534 '.$row['ser_lib'].'
150 vpihour 536 <input id="'.$name.'" type="checkbox" '.(($row['consultation_papier'] == '' || $row['consultation_papier'] == FALSE ) ? '' : '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 536 class="liste_gauche_service '.$name.'"
188 vpihour 534 id="'.$name.'" >
189     '.$row['libelle'].'&nbsp;
190 vpihour 536 <input id="'.$name.'" type="checkbox" '.(($row['consultation_papier'] == '' || $row['consultation_papier'] == FALSE ) ? '' : '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     echo "<div id='form-content'>";
208     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     _("Consultation par th&eacute;matique ")."</legend>";
212     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     echo '<input id="dossier" class="champFormulaire" type="hidden" value="'.$idx.'" name="dossier">';
222     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     echo '<div class=\'cell1 liste_gauche_them\' id=\'list-sel-ser-them-title\'>'._('Service à consulter').'</div>';
243     echo '<div class=\'cell2 liste_gauche_them\' id=\'list-sel-ser-them-title\'>'._('Version papier').'</div>';
244     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     role="button" aria-disabled="false" 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     <script>
282     $(function(){
283     /*
284     Sélectionne tous les services d'un thème au clique sur celui ci.
285     */
286     $('.liste_gauche_them').click(
287     function(){
288    
289     var id = $(this).attr('id').split('_')[1];
290 vpihour 576 var numSer = 0;
291     var numSerWithClass = 0;
292    
293 vpihour 534 $('.list-ser-them div').each(
294     function() {
295 vpihour 576
296     if ( $(this).attr('id').indexOf('them') == -1 &&
297     $(this).attr('id').indexOf(id) == 0 &&
298     $(this).hasClass('liste_gauche_service_selected') )
299    
300     numSerWithClass++;
301 vpihour 534
302     if ( $(this).attr('id').indexOf('them') == -1 &&
303 vpihour 576 $(this).attr('id').indexOf(id) == 0 )
304    
305     numSer++;
306 vpihour 534 }
307     );
308 vpihour 576
309     if ( numSerWithClass < numSer && numSerWithClass >= 0 ){
310    
311     $('.list-ser-them div').each(
312     function() {
313    
314     if ( $(this).attr('id').indexOf('them') == -1 &&
315     $(this).attr('id').indexOf(id) == 0 &&
316     !$(this).hasClass('liste_gauche_service_selected') )
317    
318     $(this).addClass('liste_gauche_service_selected');
319     }
320     );
321     }
322    
323     else {
324    
325     $('.list-ser-them div').each(
326     function() {
327    
328     if ( $(this).attr('id').indexOf('them') == -1 &&
329     $(this).attr('id').indexOf(id) == 0 &&
330     $(this).hasClass('liste_gauche_service_selected') )
331    
332     $(this).removeClass('liste_gauche_service_selected');
333     }
334     );
335     }
336 vpihour 534 }
337     );
338    
339     /*
340     Change la class CSS d'un service sur lequel on clique dans la liste de gauche.
341     */
342     $('.liste_gauche_service').click(
343     function(){
344     $(this).toggleClass('liste_gauche_service_selected');
345     }
346     );
347    
348     /*
349     Change la class CSS d'un service sur lequel on clique dans la liste de droite.
350     */
351 nhaye 548 $('.field-ser-them').on(
352 vpihour 534 'click',
353 vpihour 576 '.cell1',
354 vpihour 534 function(){
355 vpihour 576 $(this).parent().toggleClass('liste_droite_service_selected');
356 vpihour 534 }
357     );
358    
359     $('.liste_droite_service input[type=checkbox]').live(
360     'click',
361 nhaye 548 'input[type=checkbox]',
362 vpihour 534 function(){
363 vpihour 536
364     old_id = $(this).attr('id');
365    
366     tab_don = old_id.split('_');
367    
368     new_id = tab_don[0] + '_' + tab_don[1] + '_' + ((tab_don[2] == 0 ) ? 1 : 0 ) + '_';
369    
370     changeOneData( ';' + tab_don[1] + '_' + tab_don[2], ';' + tab_don[1] + '_' + ((tab_don[2] == 0) ? 1 : 0) );
371     $('div[name=\"' + $(this).attr('class') + '\"]').attr('id', new_id);
372     $(this).attr('id', new_id);
373    
374 vpihour 534 }
375     );
376    
377     $('#date_envoi').change(
378     function (){
379    
380     var listServ = new Array();
381     var data = '';
382    
383     $('.liste_gauche_service_selected').each(
384     function(i) {
385    
386     var id = $(this).attr('id');
387    
388     if ( listServ.length > 0 && listServ.indexOf(id.split('_')[1]) != -1 )
389     return;
390     listServ[i] = id.split('_')[1];
391 vpihour 536 data += ';' + id.split('_')[1] + '_' + id.split('_')[2] ;
392 vpihour 534
393     }
394     );
395    
396     changeActionVal(data);
397     }
398     );
399    
400     /*
401     Passe les services sélectionnés dans la liste de gauche dans celle de droite.
402     */
403     $('#add-ser-them').click(
404     function() {
405    
406     changeDataLeftColumn();
407     }
408     );
409    
410     /*
411     Passe les services sélectionnés dans la liste de droite dans celle de gauche.
412     */
413     $('#del-ser-them').click(
414     function() {
415    
416     var data = '';
417    
418     $('.liste_droite_service_selected').each(
419     function() {
420    
421     var id = $('#'+ $(this).attr('id') + ' .cell1 div').attr('id');
422    
423     manageListServ('.list-ser-them div', id, 1);
424 vpihour 536 data += ';' + id.split('_')[1] + '_' + id.split('_')[2] ;
425 vpihour 534
426     $(this).remove();
427     }
428     );
429    
430     changeActionVal(data);
431     }
432     );
433     });
434    
435     /*
436     Vérifie que l'objet n'est pas une thématique et que son identifiant correspond.
437     */
438     function isNotthemIsOneServ( objet, id ){
439     return ( $(objet).attr('id').indexOf('them') == -1 &&
440     $(objet).attr('id').indexOf('_' + id.split('_')[1] + '_') != -1 );
441     }
442    
443     /*
444     Affiche ou cache un élément qui n'est pas une thématique et dont son identifiant correspond.
445     */
446     function manageListServ( objet ,id, type){
447 nhaye 528
448 vpihour 534 $(objet).each(
449     function() {
450    
451     if ( isNotthemIsOneServ(this, id) ){
452     if ( type == 0 )
453 vpihour 530
454 vpihour 534 $(this).hide() ;
455    
456     else {
457    
458     if ( $(this).hasClass('liste_gauche_service_selected') )
459    
460     $(this).toggleClass('liste_gauche_service_selected');
461    
462     $(this).show() ;
463    
464 vpihour 530 }
465     }
466 vpihour 534 }
467     );
468     }
469 vpihour 530
470 vpihour 576 /*
471     Change les actions qui sont réalisées lors de la soumission du formulaire
472     */
473 vpihour 534 function changeActionVal(data){
474     date = $('#date_envoi').val();
475    
476     $('#form_val').attr(
477     'onsubmit',
478 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;' +
479 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\');'
480 vpihour 530
481 vpihour 534 );
482     $('#button_val').attr(
483     'onclick',
484 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);' +
485 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\');'
486 vpihour 530
487 vpihour 534 );
488     }
489 vpihour 576
490     /*
491     Change les actions qui sont réalisées lors de la soumission du formulaire
492     */
493 vpihour 536 function changeOneData( oldData, newData) {
494    
495     date = $('#date_envoi').val();
496    
497     $('#form_val').attr(
498     'onsubmit',
499     $('#form_val').attr('onsubmit').replace(oldData,newData)
500     );
501     $('#button_val').attr(
502     'onclick',
503     $('#button_val').attr('onclick').replace(oldData,newData)
504     );
505     }
506 vpihour 534
507     function changeDataLeftColumn(){
508 vpihour 536
509 vpihour 534 var listServ = new Array();
510     var data = '';
511    
512 vpihour 536 if ( $('.liste_droite_service').length == 0 ){
513     $('.list-sel-ser-them').empty();
514     $('.list-sel-ser-them').append(''+
515     '<div class=\'row\'>'+
516 vpihour 575 '<div class=\'cell1 liste_gauche_them\' id=\'list-sel-ser-them-title\'>"._('Service à consulter')."</div>'+
517     '<div class=\'cell2 liste_gauche_them\' id=\'list-sel-ser-them-title\'>"._('Version papier')."</div>'+
518 vpihour 536 '</div>') ;
519     }
520    
521 vpihour 534 $('.liste_gauche_service_selected').each(
522     function(i) {
523    
524 vpihour 536 if ( !$(this).is(':visible') )
525     return;
526    
527 vpihour 534 var id = $(this).attr('id');
528    
529     if ( listServ.length > 0 && listServ.indexOf(id.split('_')[1]) != -1 )
530     return;
531     listServ[i] = id.split('_')[1];
532 vpihour 536 data += ';' + id.split('_')[1] + '_' + id.split('_')[2] ;
533 vpihour 534
534     $('.list-sel-ser-them').append(
535     '<div class=\'row liste_droite_service\' id=\'' + i + '\'>'+
536     '<div class=\'cell1\'>'+
537 vpihour 536 '<div name=\'' + $(this).attr('id') + '\' id=\'' + $(this).attr('id') + '\'>'+
538 vpihour 534 $(this).html().split('<')[0]+
539 vpihour 530 '</div>'+
540 vpihour 534 '</div>' +
541     '<div class=\'cell2\'>'+
542     '<div>'+
543 vpihour 536 '<input class=\'' + $(this).attr('id') + '\''+$(this).html().split('<input')[1]+
544 vpihour 534 '</div>'+
545     '</div>'+
546     '</div>'
547     );
548    
549     $(this).hide();
550    
551     manageListServ('.list-ser-them div', id, 0);
552    
553     }
554     );
555 nhaye 528
556 vpihour 534 changeActionVal(data);
557     }
558     </script>";
559     }
560 vpihour 555 ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26