A
download animateurs-horaires.php
Language: PHP
License: GPL
Copyright: (C) 2001, 2002 Loc Dayot Mairie de Pierrefitte(93)
LOC: 584
Project Info
epnadmin
Server: Savannah NonGNU
Type: cvs
...epnadmin\epnadmin\epnadmin\
   6cartes.inc.php
   add_message.sh
   add_message_file.sh
   animateur.php
   ...eurs-disponibilites.php
   animateurs-horaires.php
   animateurs.inc.php
   autoeval.js
   barcode.inc.php
   basdepage.inc.php
   camembert.inc.php
   cartes.inc.php
   common.initial.sql
   config.php
   configuration.php
   constantes.inc.php
   courriel.php
   dateheure.inc.php
   debug.inc.php
   domaines.php
   en.lang.inc.php
   entete.inc.php
   epnadmin.css
   epnadminv.css
   exemple.sql
   fonctions.inc.php
   footer.inc.php
   fr.initial.sql
   fr.lang.inc.php
   header.inc.php
   horaires.php
   i25object.inc.php
   image.inc.php
   index.php
   initial.sql
   initiations.inc.php
   initiations.php
   inscription_session.php
   localisations.php
   logiciels.php
   materiels.php
   menu2.js
   mysql.inc.php
   parcours.inc.php
   parcours.php
   positionnement.php
   prets.php
   print.php
   questions.php
   remove_message.sh
   reservations.inc.php
   reservations.php
   session.php
   sessions.inc.php
   siteweb.inc.php
   siteweb.php
   stats.php
   structure.sql
   structures.inc.php
   structures.php
   table_horaire.php
   table_horaire_session.php
   tableaux.inc.php
   tarifs.php
   themes.php
   usagers.inc.php
   usagers.php
   usages.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
<?php
/*
    Copyright (C) 2001, 2002 Loc Dayot Mairie de Pierrefitte(93)

    EPNadmin - Version 0.6

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    http://epnadmin.pierrefitte93.fr/
*/
//phpinfo();
require_once("header.inc.php"); // C'est dans header.inc.php que sont retrouvs les droits issus de la table droits
if (!defined("FCT_ANIMATEURS"))
{
  echo $fctnonactive;
  exit;
}

require_once("constantes.inc.php");             // dfinition des constantes
//require_once("fonctions.inc.php");              // concernant des fonctions transversales inclassables
require_once("mysql.inc.php");                  // concernant mysql
//require_once("sessions.inc.php");             // concernant les sessions et initiations
//require_once("usagers.inc.php");              // concernant la gestion des usagers
//require_once("reservations.inc.php");         // concernant les rservations des postes en accs individuel par des usagers
//require_once("tableaux.inc.php");             // Concernant l'affichage transpos d'un tableau
require_once("animateurs.inc.php");	// concernant les animateurs
require_once("siteweb.inc.php");              // concernant les pages perso des usagers et les sites web des structures
require_once("dateheure.inc.php");            // concernant la manipulation des heures et des dates, formulaire, conversion...
require_once("structures.inc.php");           // concernant les structures
//require_once("initiations.inc.php");          // concernant les initiations et les thmes
//require_once("parcours.inc.php");             // concernant les parcours des usagers et leur positionnement

$ptitr=$shorairesani;
$titr = $shortitre;
$datemaj="30 avril 2003";
define("COULEUR", COULEUR_HORAIRES);
require("entete.inc.php");

function AfficheCalendrier($id_localisation, $date)
{
	global $unitehoraire, $PHP_SELF,$shorlegende,$shoraccesindiv,$shoractivcoll,$shorsemainedu,$id_animateur;
// On retrouve le lundi
	while (date("w", strtotime($date))!=1)        // 1 pour commencer le lundi, 0 pour commencer le dimanche
		$date=date("Y-m-d", strtotime("-1 days", strtotime($date)));

// on initialise  faux. Si  la fin du script il est encore faux,
// c'est qu'on n'a trouv aucune salle.
	$unlieu=false;

// Affichage de la lgende total d'heure par animateur par la suite

// On n'a ncessairement qu'une ligne
	
	echo "<hr>\n";
	$fini=true;
	$lheure=MINHORAIRE;
	$indtable=0;
	$indi=0;
	$heuretmp=MINHORAIRE;
	$heure=MINHORAIRE;
	$heure=min2h(h2min($heure) - 4*$unitehoraire);
	while($fini)
	{
	$indtable++;
	echo"<A NAME=\"[$indtable]\"></A>";
	if(h2min($lheure)>=h2min(MAXHORAIRE))
		break;
	echo cadre_debut("<h3>".animateur($id_animateur, TRUE)."</h3>");
	
	$datesemaineprec=date("Y-m-d", strtotime("-7 days", strtotime($date)));
	$datesemainesuiv=date("Y-m-d", strtotime("+7 days", strtotime($date)));
	$datemoisprec=date("Y-m-d", strtotime("-1 month", strtotime($date)));
	$datemoissuiv=date("Y-m-d", strtotime("+1 month", strtotime($date)));

	$lignechoixdate=
    "<p align=center><a href=\"$PHP_SELF?id_animateur=$id_animateur&operation=1&date=$datemoisprec\"><<<</a> - "
    ."<a href=\"$PHP_SELF?id_animateur=$id_animateur&operation=1&date=$datesemaineprec\"><<</a> - "
    ."<b>$shorsemainedu ".datetodate($date)."</b> - "
    ."<a href=\"$PHP_SELF?id_animateur=$id_animateur&operation=1&date=$datesemainesuiv\">>></a> - "
    ."<a href=\"$PHP_SELF?id_animateur=$id_animateur&operation=1&date=$datemoissuiv\">>>>></a></p>\n";
	echo $lignechoixdate;

  // on construit le tableau des horaires
	echo "<table align=center border=1 name=$indtable>\n";
	
	// Ligne des horaires
	$lignehoraires="<tr bgcolor=\"".COULEUR_HORAIRES."\"><td></td>";//<th>".datetodate($date)."</th>";
	$nbcolparheure = 60/$unitehoraire;
	////////$heure=$lheure;
	//die($heure. " ". $lheure . " " .h2min($heure) . " " .(h2min($lheure)+240));
	
	for ($heuretmp=$lheure;h2min($heuretmp)<(h2min($lheure)+240);$heuretmp=min2h(h2min($heuretmp) + 60))
	{
		$lignehoraires.="<td colspan=\"".$nbcolparheure."\">";
		$lignehoraires.=sprintf("%sh - %sh", date("H", strtotime($heuretmp)), date("H", strtotime("+1 hour", strtotime($heuretmp))));
		$lignehoraires.="</td>\n";
	}
	$lignehoraires.="</tr>\n";
	$lheure=$heuretmp;
	echo $lignehoraires;
	$datecur=$date;
	$heureencours=0;
	$heure=min2h(h2min($heure) + 4*$unitehoraire);
	$datecur=date("Y-m-d", strtotime("+0 days", strtotime($datecur)));
	while ($datecur<date("Y-m-d", strtotime("+7 days", strtotime($date))))
	{
		if(!($datecur<date("Y-m-d", strtotime("+7 days", strtotime($date)))))
		{
			$fini=false;
			break;
		}
		if($heureencours==4)
		{
			break;
		}
		
		echo "<tr><td bgcolor=\"lightgrey\">".datetodate($datecur)."</td>";
		// Il va falloir construire la ligne des horaires en tenant compte des horaires et des rservations
		$nbcol=1;
		//while (min2h($heure)<min2h(MAXHORAIRE))
		while ($heureencours!=4)
		{
			$indi++;
			$heureencours++;
			// On regarde si c'est dj ouvert ou pas.
/*			$req3 = "SELECT * FROM calendrier WHERE date=\"$datecur\" AND calendrier.debut<=\"$heure\" AND \"$heure\"<fin";
			$res3 = executeRequete($req3);
			if(DB::iserror($res3))
				break;
			$tranchehoraire = $res3->fetchrow(DB_FETCHMODE_OBJECT);*/
			
			$nbcol++;
			echo "<td bgcolor=\"grey\">\n";
			
			$reqvv2="select * from animateurs_horaires where id_animateur=$id_animateur and date=\"$datecur\" and debut<=\"$heure\"";
			$resvv2=executerequete($reqvv2);
			if(num_rows($resvv2)>=1)
			{
				echo "<form action=$PHP_SELF#[$indtable] name=\"localisateur$indi\">";
				echo "<select name=\"id_localisation\" onchange=\"document.localisateur$indi.submit();\"";
				
				$req="select *,localisations.id as id_localisation from localisations,structures where structures.id=localisations.id_structure";
				$res=executerequete($req);
				$reqvv="select * from animateurs_calendrier where id_animateur=$id_animateur and date=\"$datecur\" and debut<=\"$heure\" and fin>\"$heure\"";
				//die($reqvv);
				$resvv=executerequete($reqvv);
				$pardefaut=0;
				if($resvv)
				{
					$dejaprevu=fetch_object($resvv);
					$pardefaut=1;
				}
				echo "<option value=0></option>";
				while($listloc=fetch_object($res))
				{
					$req3 = "SELECT * FROM calendrier WHERE date=\"$datecur\" AND debut<=\"$heure\" AND fin>=\"$heure\" AND id_localisation=\"$listloc->id_localisation\"";
					//die($req3);
					$res3 = executeRequete($req3);
					if(! $res3)
					{
						$etat="F:";
					}
					else
					{
						$rien=num_rows($res3);
						if ($rien!=0)
							$etat="O:";
						else
							$etat="F:";
					}
					if ($pardefaut==1)
					{
						/*while ($dejaprevu=$resvv->fetchrow(DB_FETCHMODE_OBJECT) || ($dejaprevu->id_localisation==$listloc->id_localisation))
						{}*/
						if ($dejaprevu->id_localisation==$listloc->id_localisation)
						{
							echo "<option selected value=\"$listloc->id_localisation\">$etat $listloc->structure:$listloc->salle</option>";
							$pardefaut=0;
						}
						else
							echo "<option value=\"$listloc->id_localisation\">$etat $listloc->structure:$listloc->salle</option>";
					}
					else
						echo "<option value=\"$listloc->id_localisation\">$etat $listloc->structure:$listloc->salle</option>";
					
				}
					echo "</select>";
					echo "<input type=\"hidden\" name=\"id_animateur\" value=\"$id_animateur\"></input>";
					echo "<input type=\"hidden\" name=\"operation\" value=\"11\"></input>";
					echo "<input type=\"hidden\" name=\"heure\" value=\"" . h2min($heure) ."\"></input>";
					echo "<input type=\"hidden\" name=\"date\" value=\"$datecur\"></input>";
					echo "</form>";
					echo "</TD>";
				
					free_result($res3);
				}	
					$heure=min2h(h2min($heure) + $unitehoraire);
					
				} // while $heure
		$heure=min2h(h2min($heure) - 4*$unitehoraire);
		$heureencours=0;
		
		$datecur=date("Y-m-d", strtotime("+1 days", strtotime($datecur)));
	} // while

	echo "</tr>\n";
		
	if (HORAIRES_AUTRES>="w" || (HORAIRES_MOI>="w" && id_structure==$tranchehoraire->id_structure))
    echo "<tr><td colspan=\"$nbcol\" align=\"center\">
        <a href=\"$PHP_SELF?operation=2&id_animateur=$id_animateur&date=$date\">Appliquer le modle</a>
        - <a href=\"$PHP_SELF?operation=3&id_animateur=$id_animateur&date=$date\">Vider</a></td>
        </tr>";

	echo "</table>\n";

	echo $lignechoixdate;

	echo cadre_fin();
}
}

function AfficheModle($id_localisation)
{
global $unitehoraire, $PHP_SELF;

  // Construction de la requte.
/*  $req = "SELECT DISTINCT structures.ville AS ville,
                          structures.structure AS structure,
                          localisations.salle AS salle,
                          id_structure
          FROM localisations
            LEFT JOIN structures ON structures.id=localisations.id_structure
          WHERE localisations.id=\"$id_localisation\"";
  $res = executeRequete($req);*/

  $unlieu=false;

  // On n'a qu'une ligne
  //$reponse = $res->fetchrow(DB_FETCHMODE_OBJECT);

  echo cadre_debut("<h3>".localisation($id_localisation)."</h3>");

  // Affichage des disponibilits en fonction du calendrier et des rservations
  // L, il faudrait afficher le planning de la salle concerne.
  // on a id_localisation

  // on construit le tableau des horaires

  echo "<table align=center border=1>\n";

  // Ligne des horaires
  echo "<tr><td></td>";
  $nbcolparheure = 60/$unitehoraire;

  for ($heure=MINHORAIRE;$heure<MAXHORAIRE;$heure=min2h(h2min($heure) + 60)
       ) 
  {
    echo "<td colspan=\"".$nbcolparheure."\">";
    printf("%sh - %sh", date("H", strtotime($heure)), date("H", strtotime("+1 hour", strtotime($heure))));
    echo "</td>\n";
  }
  echo "</tr>\n";

  for ($jour=1; $jour<8; $jour++)
  {
     $nomjour=jourSemaine($jour!=8 ? $jour : 0);
     echo "<tr><td>".$nomjour."</td>";

     // Il va falloir construire la ligne des horaires en tenant compte des horaires et des rservations
     $heure=MINHORAIRE;
     while ($heure<MAXHORAIRE)
     {
       // On regarde si c'est dj ouvert ou pas.
       $req3 = "SELECT * FROM animateurs_calendrier
                         WHERE jour=\"$nomjour\"
                           AND id_localisation=\"$id_localisation\"
                           AND debut<=\"$heure\" AND \"$heure\"<fin";
       $res3 = executeRequete($req3);
       $tranchehoraire = $res3->fetchrow(DB_FETCHMODE_OBJECT);

       echo "<td";
       switch ($tranchehoraire->ouverture)
       {
       case "accs individuels" :
         echo " bgcolor=\"".COULEUR_UTILISATIONS."\">\n";
         break;
       case "activits collectives" :
         echo " bgcolor=\"".COULEUR_SESSIONS."\">\n";
         break;
       default :
         echo " bgcolor=\"grey\">\n";
         break;
       } // switch

       if (!$tranchehoraire->ouverture)
         echo "F ";
       elseif (HORAIRES_AUTRES>="w" || (HORAIRES_MOI>="w" && $id_structure==$reponse->id_structure))
         echo "<a href=\"$PHP_SELF?operation=51&id_localisation=$id_localisation&nomjour=$nomjour&debut=$heure\">f</a> \n";

       if ($tranchehoraire->ouverture=="accs individuels")
         echo "I ";
       elseif (HORAIRES_AUTRES>="w" || (HORAIRES_MOI>="w" && $id_structure==$reponse->id_structure))
         echo "<a href=\"$PHP_SELF?operation=52&id_localisation=$id_localisation&nomjour=$nomjour&debut=$heure\">i</a> ";

       if ($tranchehoraire->ouverture=="activits collectives")
         echo "C ";
       elseif (HORAIRES_AUTRES>="w" || (HORAIRES_MOI>="w" && $id_structure==$reponse->id_structure))
         echo "<a href=\"$PHP_SELF?operation=53&id_localisation=$id_localisation&nomjour=$nomjour&debut=$heure\">c</a>";

       echo "</td>\n";

       $heure=min2h(h2min($heure)+$unitehoraire);
       $res3->free();
     } // while $heure

     echo "</tr>";
  } // for jour
  echo "</table>\n";
  echo cadre_fin();
}

function verifiedroits($droit="r")
{
global $id_animateur, $id_structure,
  $manqueinfosalle, $salleintrouvable, $pasledroit;
  // retrouver la localisation
   if (! $id_animateur)
  {
    echo $manqueinfosalle;
    return FALSE;
  }
  $res=recherche("animateurs", "id", $id_animateur);
  if (! $localisation=fetch_object($res))
  {
    echo $salleintrouvable;
    return FALSE;
  }
  // On regarde si on a les droits
  if ( !(ANIMATEURS_AUTRES>=$droit || (ANIMATEURS_MOI>=$droit && $id_structure==$reponse->id_structure)))
  {
    echo $pasledroit;
    return FALSE;
  }
  return TRUE;
}

// Dbut du contenu de la page
//fonction de choix d'animateurs		
echo cadre_debut("calendrier de l'animateur");
echo "<form action=\"$PHPSELF?operation=1\" method=\"post\" name=\"choixanim\">
	<select name=\"id_animateur\" onchange=\"document.choixanim.submit();\">";
$req="select * from animateurs";
$res=executerequete($req);
echo "<option value=0></option>";
while($listanim=fetch_object($res))
{
	if($listanim->id==$id_animateur)
		echo "<option selected value=\"$listanim->id\">$listanim->prenom,$listanim->nom</option>";
	else
		echo "<option value=\"$listanim->id\">$listanim->prenom,$listanim->nom</option>";
}
echo "</select>";
//choix_animateur($id, "id", "");
echo "</form>";

echo cadre_fin();


if(defined("ANIMATEURS") && ANIMATEURS>="~")
{
  switch($operation)
  {
    case 51 : // fermer un crneau
      $ouverture="";
    case 52 : // ouvrir accs individuel d'un crneau
      if (!$ouverture)
        $ouverture="accs individuels";
    case 53 : // ouvrir activit collective d'un crneau
      if (! verifiedroits("w"))
        break;
      if (!$ouverture)
        $ouverture="activits collectives";

      // calcul de la fin du crneau
//      $heure=$debut;
      $heurefin=min2h(h2min($heure)+60);
      //debug("$heure  $heurefin");

      // On commence par retirer le crneau ancien s'il existe
      $req = "SELECT * FROM animateurs_calendrier
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND debut<=\"$heure\" AND fin=>\"$heurefin\"
				  AND id_animateur=\"$id_animateur\"";
      $res = executeRequete($req);
      if ($tranche=$res->fetchrow(DB_FETCHMODE_OBJECT))
      {  // oui, a fait partie d'une tranche horaire
         if (($heure==$tranche->debut) & ($heurefin==$tranche->fin))
         { // a correspond exactement  une tranche, alors on la dtruit
           $req1 = "DELETE FROM animateurs_calendrier
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND debut=\"$heure\" AND \"$heurefin\"=fin
				  AND id_animateur=\"$id_animateur\"";
           $res1 = executeRequete($req1);
           //debug("tranche supprimee");
         }
         elseif ($heure==$tranche->debut)
         { // la tranche dbute le crneau, il faut le reculer
           $req1 = "UPDATE animateurs_calendrier SET debut=\"$heurefin\"
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND debut=\"$heure\"
				  AND id_animateur=\"$id_animateur\"";
           $res1 = executeRequete($req1);
           //debug ("tranche rduite par le dbut");
         }
         elseif ($heurefin==$tranche->fin)
         { // la tranche termine le crneau, il faut la rduire
           $req1 = "UPDATE animateurs_calendrier SET fin=\"$heure\"
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND fin=\"$heurefin\"
				  AND id_animateur=\"$id_animateur\"";
           $res1 = executeRequete($req1);
           //debug ("tranche rduite par la fin");
         }
         else
         {  // on se trouve au milieu d'un crneau, il faut le cinder en deux
           // celui du dbut
           $heurefinorigine=$tranche->fin;
           $req1 = "INSERT INTO animateurs_calendrier (id_animateur,id_localisation, jour, debut, fin)
                      VALUES (\"$id_animateur\",\"$id_localisation\", \"$nomjour\", \"$heurefin\", \"$tranche->fin\")";
           $res1 = executeRequete($req1);
           $req1 = "UPDATE animateurs_calendrier SET fin=\"$heure\"
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND debut<=\"$heure\" AND fin=>\"$heure\"
				  AND id_animateur=\"$id_animateur\"";
           $res1 = executeRequete($req1);
           //debug ("tranche coupe en deux");
         }
      }
      // ouf, a y est, on est sur qu'il n'y a plus de crneau qu'on veut configurer.

      //debug("$heure  $heurefin");

      // Maintenant, il faut l'ajouter si besoin.
      if ($operation!=51)
      {
        // On regarde si l'horaire prcdent est du mme genre que celui qu'on veut
        $req = "SELECT * FROM animateurs_calendrier
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND fin=\"$heure\"
                  AND ouverture=\"$ouverture\"";
        $res = executeRequete($req);
        $commeprecedent = $res->fetchrow(DB_FETCHMODE_OBJECT);

        // On regarde si l'horaire suivant est du mme genre que celui qu'on veut
        $req = "SELECT * FROM animateurs_calendrier
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND debut=\"$heurefin\"
                  AND ouverture=\"$ouverture\"";
        $res = executeRequete($req);
        $commesuivant = $res->fetchrow(DB_FETCHMODE_OBJECT);

        if ($commeprecedent AND $commesuivant)
        { // runir les deux crneaux
           $req1 = "UPDATE animateurs_calendrier SET fin=\"$commesuivant->fin\"
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND fin=\"$heure\"";
           $res1 = executeRequete($req1);
           $req1 = "DELETE FROM animateurs_calendrier
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND debut=\"$heurefin\"";
           $res1 = executeRequete($req1);
           //debug ("deux tranches runies");
        }
        elseif ($commeprecedent AND !$commesuivant)
        { // allonger le crnau prcdent
           $req1 = "UPDATE animateurs_calendrier SET fin=\"$heurefin\"
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND fin=\"$heure\"";
           $res1 = executeRequete($req1);
           //debug ("crneau allong");
        }
        elseif (!$commeprecedent AND $commesuivant)
        { // avancer le crnau suivant
           $req1 = "UPDATE animateurs_calendrier SET debut=\"$heure\"
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND debut=\"$heurefin\"";
           $res1 = executeRequete($req1);
           //debug ("crneau avanc");
        }
        else // en dehors de tout crneau identique
        { // ajouter le crneau
           $req1 = "INSERT INTO animateurs_calendrier (id_localisation, jour, debut, fin, ouverture)
                      VALUES (\"$id_localisation\", \"$nomjour\", \"$heure\", \"$heurefin\", \"$ouverture\")";
           $res1 = executeRequete($req1);
           //debug("crneau ajout");
        }
      } // if $operation!=51

    case 5 :  // Affichage des modles hebdomadaires
      if (! verifiedroits("r"))
        break;
      afficheModle($id_localisation);
      break;

    case 11 : // fermer un crneau
      // calcul de la fin du crneau
//	  $heure=$debut;
	$heurefin=min2h($heure + $unitehoraire);
	$heure=min2h($heure);
	
	
	
	$req = "SELECT * FROM animateurs_calendrier
		WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
        AND debut<=\"$heure\" AND fin>=\"$heurefin\"";
	$res = executeRequete($req);

	//Supression d'un crenau
	$tranche=$res->fetchrow(DB_FETCHMODE_OBJECT);
	//die($res->numrows(). "  " . $presence);
	if ($res->numrows()>=1 & $id_localisation==0)
	{
		//die((h2min($heure) . "  " .h2min($tranche->debut)) . "  " . (h2min($heurefin). "  " . h2min($tranche->fin)));
		if ((h2min($heure)==h2min($tranche->debut)) & (h2min($heurefin)==h2min($tranche->fin)))
		{
			$req1 = "DELETE FROM animateurs_calendrier
				WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
				AND debut<=\"$heure\" AND fin>=\"$heurefin\"";
			$res1 = executeRequete($req1);
		}
		else
		{
			$req1 = "UPDATE animateurs_calendrier SET id_localisation=\"$tranche->id_localisation\",fin=\"$heure\"
				WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
				AND debut=\"$tranche->debut\"";
			$res1 = executeRequete($req1);
			 
			if(h2min($heurefin)!=h2min($tranche->fin))
			{
				$req1 = "insert into animateurs_calendrier (id_animateur, date, debut, fin,id_localisation) 
					VALUES (\"$id_animateur\",\"$date\",\"$heurefin\",\"$tranche->fin\",\"$tranche->id_localisation\")";
				$res1 = executeRequete($req1);
			}
		}
		afficheCalendrier($id_animateur,$date);
		break;

	}
	elseif ($id_localisation==0)
		break;

//remplacement d'un crenau	
	if ($res->numrows()>=1)
    {  
		
		if ((h2min($heure)==h2min($tranche->debut)) & (h2min($heurefin)==h2min($tranche->fin)))
        { 
	   
			$i=0;
			$req4 = "SELECT * FROM animateurs_calendrier
                WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
                  AND fin=\"$heure\" AND id_localisation=\"$id_localisation\"";
			$res4 = executeRequete($req4);
			if ($trancheav=$res4->fetchrow(DB_FETCHMODE_OBJECT))
			{
				$req1 = "UPDATE animateurs_calendrier SET id_localisation=\"$id_localisation\",fin=\"$heurefin\"
					WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
					AND fin=\"$heure\"";
				$res1 = executeRequete($req1);
				
				$req = "DELETE FROM animateurs_calendrier
                WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
                  AND debut=\"$heure\" AND fin=\"$heurefin\"";
				
				$res = executeRequete($req);
				$i=1;
			}
		
			$req5 = "SELECT * FROM animateurs_calendrier
                WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
                  AND debut=\"$heurefin\" AND id_localisation=\"$id_localisation\"";
			$res5 = executeRequete($req5);
			if ($trancheap=$res5->fetchrow(DB_FETCHMODE_OBJECT))
			{
				$req1 = "UPDATE animateurs_calendrier SET id_localisation=\"$id_localisation\",fin=\"$trancheap->fin\"
					WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"";
				if($trancheav->debut)
					$req1 .=" AND debut=\"$trancheav->debut\"";
				else
					$req1 .=" AND debut=\"$heure\"";
				$res1 = executeRequete($req1);

				$req = "DELETE FROM animateurs_calendrier
					WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
					AND debut=\"$heurefin\"";
				$res = executeRequete($req);
				$i=1;
			}
			if ($i==1)
			{
				afficheCalendrier($id_animateur,$date);
				break;
			}
			
		   $req1 = "UPDATE animateurs_calendrier SET id_localisation=\"$id_localisation\"
                WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
                  AND debut=\"$heure\" AND fin=\"$heurefin\"";
           $res1 = executeRequete($req1);
           //debug("tranche supprimee");
			afficheCalendrier($id_animateur,$date);
			break;
		 }
		 else
		{
			$req1 = "UPDATE animateurs_calendrier SET id_localisation=\"$tranche->id_localisation\",fin=\"$heure\"
                WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
                  AND debut=\"$tranche->debut\"";
			$res1 = executeRequete($req1);
			 
			$req1 = "INSERT INTO animateurs_calendrier (id_animateur, date, debut, fin,id_localisation) 
			VALUES (\"$id_animateur\", \"$date\" , \"$heure\", \"$heurefin\", \"$id_localisation\")";
            $res1 = executeRequete($req1);
			
			if(h2min($heurefin)!=h2min($tranche->fin))
			{
				$req1 = "insert into animateurs_calendrier (id_animateur, date, debut, fin,id_localisation) 
					VALUES (\"$id_animateur\",\"$date\",\"$heurefin\",\"$tranche->fin\",\"$tranche->id_localisation\")";
				$res1 = executeRequete($req1);
			}
			afficheCalendrier($id_animateur,$date);
			break;
		}
	}
	else
    { //ajout ou mix d'un crenau
		$req1 = "INSERT INTO animateurs_calendrier (id_animateur, date, debut, fin, id_localisation)
				VALUES (\"$id_animateur\", \"$date\", \"$heure\", \"$heurefin\", \"$id_localisation\")";
		$res1 = executeRequete($req1);
		$i=0;
		$req4 = "SELECT * FROM animateurs_calendrier
			WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
            AND fin=\"$heure\" AND id_localisation=\"$id_localisation\"";

		$res4 = executeRequete($req4);
		if ($trancheav=$res4->fetchrow(DB_FETCHMODE_OBJECT))
		{
			$req1 = "UPDATE animateurs_calendrier SET id_localisation=\"$id_localisation\",fin=\"$heurefin\"
				WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
				AND fin=\"$heure\"";
			$res1 = executeRequete($req1);
				
			$req = "DELETE FROM animateurs_calendrier
				WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
				AND debut=\"$heure\" AND fin=\"$heurefin\"";
				
			$res = executeRequete($req);
			$i=1;
		}
		
		$req5 = "SELECT * FROM animateurs_calendrier
			WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
			AND debut=\"$heurefin\" AND id_localisation=\"$id_localisation\"";
		$res5 = executeRequete($req5);
		if ($trancheap=$res5->fetchrow(DB_FETCHMODE_OBJECT))
		{
			$req1 = "UPDATE animateurs_calendrier SET id_localisation=\"$id_localisation\",fin=\"$trancheap->fin\"
				WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"";
			if($trancheav->debut)
				$req1 .=" AND debut=\"$trancheav->debut\"";
			else
				$req1 .=" AND debut=\"$heure\"";
			$res1 = executeRequete($req1);

			$req = "DELETE FROM animateurs_calendrier
				WHERE date=\"$date\" AND id_animateur=\"$id_animateur\"
				AND debut=\"$heurefin\"";
			$res = executeRequete($req);
			$i=1;
		}
		if ($i==1)
		{
			$req1 = "DELETE FROM animateurs_calendrier 
			WHERE id_animateur=\"$id_animateur\" AND date=\"$date\" AND debut=\"$heure\" AND fin=\"$heurefin\" AND id_localisation=\"$id_localisation\"";
			$res1 = executeRequete($req1);
			afficheCalendrier($id_animateur,$date);
			break;
		}
    }
	afficheCalendrier($id_animateur,$date);
	break;
	
	
	
	
	
	
	
	
	
	
	
	
	

/*	$req = "SELECT * FROM animateurs_calendrier
		WHERE date=\"$date\" AND debut=\"$heure\" 
		AND id_animateur=\"$id_animateur\"";
	$res = executeRequete($req);
	if ($tranche=$res->fetchrow(DB_FETCHMODE_OBJECT))
	{  // oui, a fait partie d'une tranche horaire
		$req1 = "DELETE FROM animateurs_calendrier
			WHERE date=\"$date\" AND debut=\"$heure\" 
			AND id_animateur=\"$id_animateur\"";
		$res1 = executeRequete($req1);
	}
	if ($id_localisation!=0)
	{
		$req1 = "INSERT INTO animateurs_calendrier (id_animateur,id_localisation, date, debut, fin)
			VALUES (\"$id_animateur\",\"$id_localisation\", \"$date\", \"$heure\", \"$heurefin\")";
		$res1 = executeRequete($req1);
	} // if $operation!=11*/

    case 1 :  // Affichage du animateurs_calendrier d'une salle pour un moi correpondant  une date (courante)
      if (! verifiedroits("r"))
        break;
      afficheCalendrier($id_animateur, $date);
      break;

    case 2 :  // Appliquer le modle de calendrier pour une semaine donne
      if (! verifiedroits("w"))
        break;
      // On commence par vider compltement le calendrier pour la semaine donne.
      echo "<p>Vider le calendrier pour la semaine concerne...";
      $datefin=date("Y-m-d", strtotime("+6 days", strtotime($date)));
      $req="DELETE FROM animateurs_calendrier WHERE date>=\"$date\" AND date<=\"$datefin\"
                    AND id_localisation=\"$id_localisation\"";
      $res = executeRequete($req);
      echo " fait !</p>";
      // Ensuite, on applique le modle sur la semain concerne
      echo "<p>Appliquer le modle au calendrier pour la semaine concerne...";
      $req="SELECT * FROM animateurs_calendrier
             WHERE id_localisation=\"$id_localisation\"
             ORDER BY jour, debut";
      $res=executeRequete($req);
      while ($horaire=$res->fetchrow(DB_FETCHMODE_OBJECT))
      {
        $datejour = $date;
        while (jourSemaine(date("w", strtotime($datejour))) != $horaire->jour)
          $datejour = date("Y-m-d", strtotime("+1 days", strtotime($datejour)));
        $req2="INSERT INTO animateurs_calendrier (id_localisation, date, debut, fin, ouverture)
               VALUES (\"$id_localisation\", \"$datejour\", \"$horaire->debut\", \"$horaire->fin\", \"$horaire->ouverture\")";
        $res2=executeRequete($req2);
      }
      $res3->free();
      echo " fait !</p>";
      // enfin, on affiche le rsultat
      afficheCalendrier($id_localisation, $date);
      break;

    case 3 :  // Vider le calendrier pour une semaine donne
      if (! verifiedroits("w"))
        break;
      // On commence par vider compltement le calendrier pour la semaine donne.
      echo "<p>Vider le calendrier pour la semaine concerne...";
      $datefin=date("Y-m-d", strtotime("+6 days", strtotime($date)));
      $req="DELETE FROM animateurs_calendrier WHERE date>=\"$date\" AND date<=\"$datefin\"
                    AND id_localisation=\"$id_localisation\"";
      $res = executeRequete($req);
      // et on affiche le rsultat
      afficheCalendrier($id_localisation, $date);
      break;

    default : // liste des localisations
      echo cadre_debut($slistelocalisations);
      if (ANIMATEURS<="~")
      {
        echo $pasledroit;   
        echo cadre_fin();
        break;
      }
    }  // switch
} // if
else
  echo $pasledroit;

include("basdepage.inc.php");
echo "</body></html>\n";
require("footer.inc.php");
?>

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us