A
download horaires.php
Language: PHP
License: GPL
Copyright: (C) 2001, 2002 Loc Dayot Mairie de Pierrefitte(93)
LOC: 539
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
<?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/
*/

require_once("header.inc.php"); // C'est dans header.inc.php que sont retrouvs les droits issus de la table droits
if (!defined("FCT_HORAIRES"))
{
  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("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=$shoraires;
$titr = $shortitre;
$datemaj="27 mars 2003";
define("COULEUR", COULEUR_HORAIRES);
require("entete.inc.php");


function AfficheCalendrier($id_localisation, $date)
{
global $unitehoraire, $PHP_SELF, $id_structure,
  $shorlegende,$shoraccesindiv,$shoractivcoll,
  $shorsemainedu;

// 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
  echo cadre_debut($shorlegende);
  echo "<table>
          <tr><td bgcolor=\"grey\">F</td><td>= ferm</td>
            <td> </td>
            <td bgcolor=\"".COULEUR_UTILISATIONS."\">I</td><td>= $shoraccesindiv</td>
            <td> </td>
            <td bgcolor=\"".COULEUR_SESSIONS."\">C</td><td>= $shoractivcoll</td>
          </tr>
        </table>\n";
  echo cadre_fin();

  echo "<hr>\n";
  echo cadre_debut("<h3>".localisation($id_localisation, 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_localisation=$id_localisation&operation=1&date=$datemoisprec\"><<<</a> - "
    ."<a href=\"$PHP_SELF?id_localisation=$id_localisation&operation=1&date=$datesemaineprec\"><<</a> - "
    ."<b>$shorsemainedu ".datetodate($date)."</b> - "
    ."<a href=\"$PHP_SELF?id_localisation=$id_localisation&operation=1&date=$datesemainesuiv\">>></a> - "
    ."<a href=\"$PHP_SELF?id_localisation=$id_localisation&operation=1&date=$datemoissuiv\">>>>></a></p>\n";
  echo $lignechoixdate;

  // on construit le tableau des horaires

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

  // Ligne des horaires
  $lignehoraires="<tr bgcolor=\"".COULEUR_HORAIRES."\"><td></td>";//<th>".datetodate($date)."</th>";
  $nbcolparheure = 60/$unitehoraire;

  for ($heure=MINHORAIRE;
       $heure<MAXHORAIRE;
       $heure=additionHeure("01:00", $heure)
       )
  {
      $lignehoraires.="<td colspan=\"".$nbcolparheure."\">";
      $lignehoraires.=sprintf("%sh - %sh", date("H", strtotime($heure)), date("H", strtotime("+1 hour", strtotime($heure))));
      $lignehoraires.="</td>\n";
  }
  $lignehoraires.="</tr>\n";

  echo $lignehoraires;

  $datecur=$date;
  while ($datecur<date("Y-m-d", strtotime("+7 days", strtotime($date))))
  {
     echo "<tr><td bgcolor=\"lightgrey\">".datetodate($datecur)."</td>";

     // Il va falloir construire la ligne des horaires en tenant compte des horaires et des rservations
     $heure=MINHORAIRE;
     $nbcol=1;
     while ($heure<MAXHORAIRE)
     {
       // On regarde si c'est dj ouvert ou pas.
       $req3 = "SELECT * FROM calendrier
                         LEFT JOIN localisations ON localisations.id=calendrier.id_localisation
                         WHERE date=\"$datecur\"
                           AND id_localisation=\"$id_localisation\"
                           AND debut<=\"$heure\" AND \"$heure\"<fin";
       $res3 = executeRequete($req3);
       $tranchehoraire = fetch_object($res3);

       $nbcol++;
       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==$tranchehoraire->id_structure))
       elseif (verifiedroits("w", FALSE))
         echo "<a href=\"$PHP_SELF?operation=11&id_localisation=$id_localisation&date=$datecur&debut=$heure\">f</a> \n";

       if ($tranchehoraire->ouverture=="accs individuels")
         echo "I ";
       //elseif (HORAIRES_AUTRES>="w" || (HORAIRES_MOI>="w" && $id_structure==$tranchehoraire->id_structure))
       elseif (verifiedroits("w", FALSE))
         echo "<a href=\"$PHP_SELF?operation=12&id_localisation=$id_localisation&date=$datecur&debut=$heure\">i</a> ";

       if ($tranchehoraire->ouverture=="activits collectives")
         echo "C ";
       //elseif (HORAIRES_AUTRES>="w" || (HORAIRES_MOI>="w" && $id_structure==$tranchehoraire->id_structure))
       elseif (verifiedroits("w", FALSE))
         echo "<a href=\"$PHP_SELF?operation=13&id_localisation=$id_localisation&date=$datecur&debut=$heure\">c</a>";

       echo "</td>\n";

       $heure=additionHeure($heure,"00:".$unitehoraire);
       free_result($res3);
     } // while $heure

     $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))
  if (verifiedroits("w", FALSE))
    echo "<tr><td colspan=\"$nbcol\" align=\"center\">
        <a href=\"$PHP_SELF?operation=2&id_localisation=$id_localisation&date=$date\">Appliquer le modle</a>
        - <a href=\"$PHP_SELF?operation=4&id_localisation=$id_localisation&date=$date\">Appliquer pour 4 semaines</a>
        - <a href=\"$PHP_SELF?operation=3&id_localisation=$id_localisation&date=$date\">Vider</a></td>
        </tr>";

  echo "</table>\n";

  echo $lignechoixdate;

  echo cadre_fin();
}

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

  // 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);*/

  // Affichage de la lgende
  echo cadre_debut($shorlegende);
  echo "<table>
          <tr><td bgcolor=\"grey\">F</td><td>= ferm</td>
            <td> </td>
            <td bgcolor=\"".COULEUR_UTILISATIONS."\">I</td><td>= $shoraccesindiv</td>
            <td> </td>
            <td bgcolor=\"".COULEUR_SESSIONS."\">C</td><td>= $shoractivcoll</td>
          </tr>
        </table>\n";
  echo cadre_fin();
  
  $unlieu=false;

  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=additionHeure("01:00", $heure)
       ) 
  {
    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 modeles_horaires
                         WHERE jour=\"$nomjour\"
                           AND id_localisation=\"$id_localisation\"
                           AND debut<=\"$heure\" AND \"$heure\"<fin";
       $res3 = executeRequete($req3);
       $tranchehoraire = fetch_object($res3);

       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=additionHeure($heure, "00:".$unitehoraire);
       free_result($res3);
     } // while $heure

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

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

// Dbut du contenu de la page

if(defined("HORAIRES") && HORAIRES>="~")
{
  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=date("H:i:00", strtotime("+".$unitehoraire." minutes", strtotime($heure)));
      //debug("$heure  $heurefin");

      // On commence par retirer le crneau ancien s'il existe
      $req = "SELECT * FROM modeles_horaires
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND debut<=\"$heure\" AND \"$heurefin\"<=fin";
      $res = executeRequete($req);
      if ($tranche=fetch_object($res))
      {  // 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 modeles_horaires
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND debut=\"$heure\" AND \"$heurefin\"=fin";
           $res1 = executeRequete($req1);
           //debug("tranche supprimee");
         }
         elseif ($heure==$tranche->debut)
         { // la tranche dbute le crneau, il faut le reculer
           $req1 = "UPDATE modeles_horaires SET debut=\"$heurefin\"
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND debut=\"$heure\"";
           $res1 = executeRequete($req1);
           //debug ("tranche rduite par le dbut");
         }
         elseif ($heurefin==$tranche->fin)
         { // la tranche termine le crneau, il faut la rduire
           $req1 = "UPDATE modeles_horaires SET fin=\"$heure\"
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND fin=\"$heurefin\"";
           $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 modeles_horaires (id_localisation, jour, debut, fin, ouverture)
                      VALUES (\"$id_localisation\", \"$nomjour\", \"$heurefin\", \"$tranche->fin\", \"$tranche->ouverture\")";
           $res1 = executeRequete($req1);
           $req1 = "UPDATE modeles_horaires SET fin=\"$heure\"
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND debut<=\"$heure\" AND \"$heure\"<=fin";
           $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 modeles_horaires
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND fin=\"$heure\"
                  AND ouverture=\"$ouverture\"";
        $res = executeRequete($req);
        $commeprecedent = fetch_object($res);

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

        if ($commeprecedent AND $commesuivant)
        { // runir les deux crneaux
           $req1 = "UPDATE modeles_horaires SET fin=\"$commesuivant->fin\"
                WHERE jour=\"$nomjour\" AND id_localisation=\"$id_localisation\"
                  AND fin=\"$heure\"";
           $res1 = executeRequete($req1);
           $req1 = "DELETE FROM modeles_horaires
                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 modeles_horaires 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 modeles_horaires 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 modeles_horaires (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
      $ouverture="";
    case 12 : // ouvrir accs individuel d'un crneau
      if (!$ouverture)
        $ouverture="accs individuels";
    case 13 : // ouvrir activit collective d'un crneau
      if (! verifiedroits("w"))
        break;
      if (!$ouverture)
        $ouverture="activits collectives";

      // calcul de la fin du crneau
      $heure=$debut;
      $heurefin=date("H:i:00", strtotime("+".$unitehoraire." minutes", strtotime($heure)));
      //debug("$heure  $heurefin");

      // On commence par retirer le crneau ancien s'il existe
      $req = "SELECT * FROM calendrier
                WHERE date=\"$date\" AND id_localisation=\"$id_localisation\"
                  AND debut<=\"$heure\" AND \"$heurefin\"<=fin";
      $res = executeRequete($req);
      if ($tranche=fetch_object($res))
      {  // 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 calendrier
                WHERE date=\"$date\" AND id_localisation=\"$id_localisation\"
                  AND debut=\"$heure\" AND \"$heurefin\"=fin";
           $res1 = executeRequete($req1);
           //debug("tranche supprimee");
         }
         elseif ($heure==$tranche->debut)
         { // la tranche dbute le crneau, il faut le reculer
           $req1 = "UPDATE calendrier SET debut=\"$heurefin\"
                WHERE date=\"$date\" AND id_localisation=\"$id_localisation\"
                  AND debut=\"$heure\"";
           $res1 = executeRequete($req1);
           //debug ("tranche rduite par le dbut");
         }
         elseif ($heurefin==$tranche->fin)
         { // la tranche termine le crneau, il faut la rduire
           $req1 = "UPDATE calendrier SET fin=\"$heure\"
                WHERE date=\"$date\" AND id_localisation=\"$id_localisation\"
                  AND fin=\"$heurefin\"";
           $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 calendrier (id_localisation, date, debut, fin, ouverture)
                      VALUES (\"$id_localisation\", \"$date\", \"$heurefin\", \"$tranche->fin\", \"$tranche->ouverture\")";
           $res1 = executeRequete($req1);
           $req1 = "UPDATE calendrier SET fin=\"$heure\"
                WHERE date=\"$date\" AND id_localisation=\"$id_localisation\"
                  AND debut<=\"$heure\" AND \"$heure\"<=fin";
           $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!=11)
      {
        // On regarde si l'horaire prcdent est du mme genre que celui qu'on veut
        $req = "SELECT * FROM calendrier
                WHERE date=\"$date\" AND id_localisation=\"$id_localisation\"
                  AND fin=\"$heure\" AND ouverture=\"$ouverture\"";
        $res = executeRequete($req);
        $commeprecedent = fetch_object($res);

        // On regarde si l'horaire suivant est du mme genre que celui qu'on veut
        $req = "SELECT * FROM calendrier
                WHERE date=\"$date\" AND id_localisation=\"$id_localisation\"
                  AND debut=\"$heurefin\" AND ouverture=\"$ouverture\"";
        $res = executeRequete($req);
        $commesuivant = fetch_object($res);

        if ($commeprecedent AND $commesuivant)
        { // runir les deux crneaux
           $req1 = "UPDATE calendrier SET fin=\"$commesuivant->fin\"
                WHERE date=\"$date\" AND id_localisation=\"$id_localisation\"
                  AND fin=\"$heure\"";
           $res1 = executeRequete($req1);
           $req1 = "DELETE FROM calendrier
                WHERE date=\"$date\" 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 calendrier SET fin=\"$heurefin\"
                WHERE date=\"$date\" AND id_localisation=\"$id_localisation\"
                  AND fin=\"$heure\"";
           $res1 = executeRequete($req1);
           //debug ("crneau allong");
        }
        elseif (!$commeprecedent AND $commesuivant)
        { // avancer le crnau suivant
           $req1 = "UPDATE calendrier SET debut=\"$heure\"
                    WHERE date=\"$date\" 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 calendrier (id_localisation, date, debut, fin, ouverture)
                      VALUES (\"$id_localisation\", \"$date\", \"$heure\", \"$heurefin\", \"$ouverture\")";
           $res1 = executeRequete($req1);
           //debug("crneau ajout");
        }
      } // if $operation!=11

    case 1 :  // Affichage du calendrier d'une salle pour un moi correpondant  une date (courante)
      if (! verifiedroits("r"))
        break;
      afficheCalendrier($id_localisation, $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 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 modeles_horaires
             WHERE id_localisation=\"$id_localisation\"
             ORDER BY jour, debut";
      $res=executeRequete($req);
      while ($horaire=fetch_object($res))
      {
        $datejour = $date;
        while (jourSemaine(date("w", strtotime($datejour))) != $horaire->jour)
          $datejour = date("Y-m-d", strtotime("+1 days", strtotime($datejour)));
        $req2="INSERT INTO calendrier (id_localisation, date, debut, fin, ouverture)
               VALUES (\"$id_localisation\", \"$datejour\", \"$horaire->debut\", \"$horaire->fin\", \"$horaire->ouverture\")";
        $res2=executeRequete($req2);
      }
      free_result($res);
      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 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;

    case 4 :  // Appliquer le modle de calendrier pour 4 semaines
      if (! verifiedroits("w"))
        break;
      // On commence par vider compltement le calendrier pour la semaine donne.
      echo "<p>Vider le calendrier pour les <b>quatre semaines</b> concernes...";
      $datefin=date("Y-m-d", strtotime("+28 days", strtotime($date)));
      $req="DELETE FROM 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 les <b>quatre semaines</b> concernes...";
      $wee=0;
      while ($wee!=4)
      {
        $req="SELECT * FROM modeles_horaires
              WHERE id_localisation=\"$id_localisation\"
              ORDER BY jour, debut";
        $res=executeRequete($req);
        while ($horaire=fetch_object($res))
        {
          $datejour = $date;
          while (jourSemaine(date("w", strtotime($datejour))) != $horaire->jour)
            $datejour = date("Y-m-d", strtotime("+1 days", strtotime($datejour)));
          $req2="INSERT INTO calendrier (id_localisation, date, debut, fin, ouverture)
                VALUES (\"$id_localisation\", \"$datejour\", \"$horaire->debut\", \"$horaire->fin\", \"$horaire->ouverture\")";
          $res2=executeRequete($req2);
        }
        $wee+=1;
        $date = date("Y-m-d", strtotime("+7 days", strtotime($date)));
      }
      free_result($res);
      echo " fait !</p>";
      echo "<p><b>Attention, le calendrier passe automatiquement quatre semaines dans le futur.</b></p>\n";
      // enfin, on n'affiche pas le rsultat, mais le calendrier quatre semaines plus loin.
      // $date = date("Y-m-d", strtotime("-6 days", strtotime($date)));
      afficheCalendrier($id_localisation, $date);
      break;

    default : // liste des localisations
      echo cadre_debut($slistelocalisations);
      if (LOCALISATIONS<="~")
      {
        echo $pasledroit;
        echo cadre_fin();
        break;
      }
      $req = "SELECT ville, localisations.id AS id_localisation, structure, salle, id_structure
                        FROM localisations
                        LEFT JOIN structures ON localisations.id_structure=structures.id ";
      if (HORAIRES_AUTRES<"r" && $is_ident=="structure")
        $req.= "WHERE id_structure=$id_structure ";
      $req.= "ORDER BY ville, structure, salle";
      $res = executeRequete($req);
      echo "<table align=center border=1>
            <tr><th align=center>$sVille</th><th align=center>$sStructure</th><th align=center>$sSalle</th><th colspan=2></th></tr>\n";
      while ($local= fetch_object($res))
      {
        echo "<tr><td>$local->ville</td>
                  <td>$local->structure</td>
                  <td>$local->salle</td>\n";
        if (HORAIRES_AUTRES>="r" || (HORAIRES_MOI>="r" && $id_structure==$local->id_structure))
          echo "<td><a href=\"$PHP_SELF?operation=1&id_localisation=$local->id_localisation\">$shorcalendrier</a></td>\n";
        else
          echo "<td></td>\n";
        if (HORAIRES_AUTRES>="w" || (HORAIRES_MOI>="w" && $id_structure==$local->id_structure))
          echo "<td><a href=\"$PHP_SELF?operation=5&id_localisation=$local->id_localisation\">$shormodelehebdo</a></td>\n";
        else
          echo "<td></td>\n";
        echo "</tr>\n";
      }
      echo "</table>\n";   
      echo cadre_fin();
      break;
    }  // switch
    printf($shorvoirlistelocalisations, $PHP_SELF);
} // 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