<?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");
?>