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