<?php
/*
Copyright (C) 2001, 2002 Bertand Pallie, Loc Dayot - Mairie Pierrefitte-sur-Seine
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");
if (!defined("FCT_SESSIONS"))
{
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=$stablehorairesession;
$titr = $stitreplanningsession;
$datemaj="4 mai 2003";
define("COULEUR", COULEUR_SESSIONS);
require("entete.inc.php");
// affiche de courtes informations concernant une session
function infoReservation($reservation)
{ // $reservation est un objet enregistrement de la table session
global $id_structure;
if ($reservation->nom_session>"")
{ // il s'agit d'une session exceptionnelle
$rep="";
if ($reservation->etat=="pr-rservation")
$rep.="<i>pr-rservation</i> ";
// rcuprer les informations sur l'organisateur
$res1=recherche("structures", "id", $reservation->id_structure);
$structure=fetch_object($res1);
// rcuprer la structure de la localisation
$res2=recherche("localisations", "id", $reservation->id_localisation);
$localisation=fetch_object($res2);
// N'a le droit d'diter la session que le super-administrateur
// ou bien si la structure identifie hberge la session
// ou encore si c'est la structure identifie qui organise
if (SESSIONS_AUTRES>="r" || (SESSIONS_MOI>="r" &&
($localisation->id_structure==$id_structure || $id_structure==$reservation->id_structure)
))
$rep.="<a href=\"session.php?operation=2&id_session=$reservation->id\">$reservation->nom_session</a> ($structure->structure)
<a href=\"inscription_session.php?id_session=$reservation->id\">bilan</a>";
else
$rep.="$reservation->nom_session ($structure->structure)";
}
else
{ // Il s'agit d'une initiation connue, sur inscription...
$rep="";
if ($reservation->etat=="pr-rservation")
$rep.="<i>pr-rservation</i> ";
// rcuprer les informations sur l'organisateur
$res1=recherche("structures", "id", $reservation->id_structure);
$structure=fetch_object($res1);
// rcuprer la structure de la localisation
$res2=recherche("localisations", "id", $reservation->id_localisation);
$localisation=fetch_object($res2);
// on recherche l'intitul de l'initiation
$res3=recherche("initiations", "id", $reservation->id_initiation);
$initiation=fetch_object($res3);
// N'a le droit d'diter la session que le super-administrateur
// ou bien si la structure identifie hberge la session
// ou encore si c'est la structure identifie qui organise
if (SESSIONS_AUTRES>="r" || (SESSIONS_MOI>="r" &&
($localisation->id_structure==$id_structure || $id_structure==$reservation->id_structure)
))
{
// on regarde si le bilan quantitatif a t fait.
$req1 = "SELECT COUNT(*) as nb
FROM parcours
WHERE id_session='$reservation->id'
GROUP BY id_session";
$res1 = executeRequete($req1);
$parc = fetch_object($res1);
$nb = 0 + $parc->nb;
$bilan= "<table><tr><td";
if ($nb<2) $bilan.= " bgcolor=\"#88000\"";
elseif ($nb<3) $bilan.= " bgcolor=\"#888811\"";
// recherche du nombre maximum de participants la session selon l'initiation et la localisation
$nbmax=nbmaxparticipants($reservation->id);
$bilan.="><a href=\"inscription_session.php?id_session=$reservation->id\">$nb/$nbmax</a>";
$bilan.="</td></tr></table>";
$rep.="<a href=\"session.php?operation=2&id_session=$reservation->id\">
$initiation->initiation</a>
$bilan ($structure->structure)";
}
else
$rep.="$initiation->initiation ($structure->structure)";
}
return $rep;
}
function AfficheDisponibilitsSalle($lieuv, $datev, $sens)
{
global $info, $programmer, $deprogrammer, $modifier, $ajouter,
$unitehoraire, $id_structure,
$spasdesalleselectionnee;
while(date("w", strtotime($datev))!=1)
$datev=date("Y-m-d",strtotime("-1 day",strtotime($datev)));
$datef=date("Y-m-d", strtotime("+6 days", strtotime($datev)));
// Construction de la requte pour le lieu et la date
$req = "SELECT DISTINCT structures.ville AS ville,
structures.structure AS structure,
structures.id AS id_structure, ";
$req.=" localisations.id AS id_localisation ";
// localisations.salle AS salle, // plus besoin car utilisation de
// localisations.id AS id_localisation, // fonction localisation();
// localisations.image AS image
$req.=" FROM localisations
LEFT JOIN structures ON structures.id=localisations.id_structure ";
if (defined("FCT_HORAIRES"))
$req.=" LEFT JOIN calendrier ON calendrier.id_localisation=localisations.id ";
$req.=" WHERE ((\"$lieuv\"=\"*\") OR
(CONCAT(\"V\",ville)=\"$lieuv\") OR
(CONCAT(\"S\",id_structure)=\"$lieuv\") OR
(CONCAT(\"L\",localisations.id)=\"$lieuv\")) ";
//if (defined("FCT_HORAIRES"))
// $req.=" AND (calendrier.date>=\"$datev\") AND (calendrier.date<=\"$datef\") ";
$req.=" ORDER BY structures.ville, structures.structure, localisations.salle";
// retir le 16 juillet 2002 AND (ouverture=\"activits collectives\")
// parce que le planning est celui de la salle et pas seulement celui des sessions collectives.
// LD : Ajout du 14 mai 2003
// Affichage des liens vers chaque salle
$res = executeRequete($req);
echo "<p>";
while ($reponse=fetch_object($res))
{
if ($ville!=$reponse->ville)
{
echo "<br><b>$reponse->ville</b>";
$ville=$reponse->ville;
}
if ($structure!=$reponse->structure)
{
echo "<br>$reponse->structure ";
$structure=$reponse->structure;
}
echo " - <a href=\"#$reponse->id_localisation\">".localisation($reponse->id_localisation)."</a>";
}
echo "</p>";
// Affichage de chaque salle
$res = executeRequete($req);
$unlieu=false;
// On a un tableau par ville, structure, salle ou groupe d'ordinateurs
while ($reponse = fetch_object($res))
{ // Il y a sans doute une ouverture de la salle.
$unlieu=true;
//echo "<hr>\n";
echo "<a name=\"$reponse->id_localisation\">";
echo cadre_debut(localisation($reponse->id_localisation,
TRUE, // image
TRUE) // lien vers le parc
);
// ."</h3>\n";
//echo "<img src=\"$reponse->image\" alt=\"$reponse->salle\" align=\"left\" width=\"80\">";
//echo "<h3>$reponse->salle de $reponse->structure $reponse->ville</h3>\n";
// Affichage des disponibilits en fonction du calendrier et des rservations
// L, il faudrait afficher le planning de la salle concerne.
// on a id_localisation et on sait qu'il y a une ouverture. Vrifier disponibilit.
// on regarde les horaires d'ouverture
if (defined("FCT_HORAIRES"))
{
$minhoraire="23:59";
$maxhoraire="00:01";
$req1 = "SELECT * FROM calendrier
WHERE (calendrier.date>=\"$datev\") AND (calendrier.date<=\"$datef\")
AND (id_localisation=\"$reponse->id_localisation\")
ORDER BY date, debut";
$res1 = executeRequete($req1);
$ntranche=0;
while ($tranchehoraireouverture = fetch_object($res1))
{ // il y a des crneaux d'ouverture, alors on regarde l'amplitude maxi
$tranche[$ntranche]=array( "debut" => $tranchehoraireouverture->debut,
"fin" => $tranchehoraireouverture->fin);
if ($tranche[$ntranche]["debut"]<$minhoraire)
$minhoraire=date("H:00:00", strtotime($tranche[$ntranche]["debut"]));
if ($tranche[$ntranche]["fin"]>$maxhoraire)
$maxhoraire=$tranche[$ntranche]["fin"];
$ntranche++;
}
free_result($res1);
// On ajoute une heure avant et aprs ce qui a t trouv dans les horaires d'ouverture
$minhoraire=differenceheure($minhoraire, "01:00");
$maxhoraire=additionheure($maxhoraire, "01:00");
} // id defined
//else // Mais en fait, on ne tient pas compte des horaires d'ouverture, on prend large.
{
$minhoraire=MINHORAIRE;
$maxhoraire=MAXHORAIRE;
}
// On peut commencer le tableau.
echo "<table align=center border=1>\n";
// On stocke dans un tableau plutt que d'afficher de suite,
// en esprant trouver un moyen de faire le transpos d'un tableau HTML.
$i=0; // indice des lignes
$j=0; // indicie des colonnes
// Ligne des horaires
$tableau[$i][$j]["contenu"]="";
$j++;
//echo "<tr><td></td>";
$nbcolparheure = 60/$unitehoraire;
for ($heure=$minhoraire;
$heure<$maxhoraire;
//$heure=date("H:i:00", strtotime("+ 1 hour", strtotime($heure)))
$heure=additionHeure($heure, "01:00")
)
{
$tableau[$i][$j]["param"]= " colspan=$nbcolparheure";
$tableau[$i][$j]["contenu"]= date("H", strtotime($heure))."h"." - ".
date("H", strtotime("+ 1 hour", strtotime($heure)))."h";
$j++;
} // fin du for $heure
$i++; $j=0;
//echo "</tr>\n";
// Ensuite, on fait une ligne par jour...
for($datecur=$datev;
$datecur<=$datef;
$datecur=date("Y-m-d",strtotime("+1 day",strtotime($datecur))))
{
$tableau[$i][$j]["param"]=""; // width=\"110\"";
$tableau[$i][$j]["contenu"]="<b>".datetodate($datecur)."</b>";
$j++;
// Une colonne par horaire
$heure=$minhoraire;
while ($heure<$maxhoraire)
{
// On regarde tout d'abord si on est dans les horaires d'ouverture
unset($tranchehoraireouverture);
if (defined("FCT_HORAIRES"))
{
$req3 = "SELECT * FROM calendrier
WHERE date=\"$datecur\"
AND id_localisation=\"$reponse->id_localisation\"
AND debut<=\"$heure\" AND \"$heure\"<fin";
$res3 = executeRequete($req3);
$tranchehoraireouverture = fetch_object($res3);
}
if (! $tranchehoraireouverture)
{ // on n'est pas ouvert
$tableau[$i][$j]["param"]=" bgcolor=\"#C0C0C0\" align=center"; // gris
// Il faut quand meme regarder s'il n'y a pas une session programme
$req4 = "SELECT * FROM sessions
WHERE date=\"$datecur\" AND id_localisation=\"$reponse->id_localisation\"
AND (debut<=\"$heure\" AND \"$heure\"<fin)
AND (etat<>\"annule\" AND etat<>\"non tenue\")";
$res4 = executeRequete($req4);
if (! ($reservation = fetch_object($res4))) // pas de rservation
{
$tableau[$i][$j]["contenu"]="<a href=\"session.php?operation=1&datev=$datecur&debutv=$heure&id_localisation=$reponse->id_localisation\">
$programmer</a>";
// on passe au crneau suivant
$heure=additionHeure($heure, "00:".$unitehoraire);
}
else // il y a bien une session prvue sur ce crneau l.
{
$tableau[$i][$j]["param"]=" bgcolor=\"#C0E0C0\" align=center"; // gris
$tableau[$i][$j]["contenu"]=infoReservation($reservation);
$nbminres=60*(date("H",strtotime($reservation->fin))-date("H",strtotime($reservation->debut)))
+ (date("i",strtotime($reservation->fin))-date("i",strtotime($reservation->debut)));
$nbuniteres = $nbminres / $unitehoraire;
$tableau[$i][$j]["param"].=" colspan=$nbuniteres";
// on passe au crneau suivant (duree variable)
$heure=additionHeure($heure, "00:".$nbminres);
free_result($res4);
}
$j++;
}
else
{ // C'est ouvert...
// on regarde quel type d'ouverture
// on regarde si ce n'est pas de l'accs individuel
if ($tranchehoraireouverture->ouverture=="accs individuels")
{
$nbminres=60*(date("H",strtotime($tranchehoraireouverture->fin))-date("H",strtotime($tranchehoraireouverture->debut)))
+ (date("i",strtotime($tranchehoraireouverture->fin))-date("i",strtotime($tranchehoraireouverture->debut)));
$nbuniteres = $nbminres / $unitehoraire;
$tableau[$i][$j]["param"]=" colspan=$nbuniteres align=center bgcolor=\"".COULEUR_UTILISATIONS."\""; // vert
if ( UTILISATIONS_AUTRES>="r" || (UTILISATIONS_MOI>="r" && $id_structure==$reponse->id_structure) )
$tableau[$i][$j]["contenu"]="<a href=\"table_horaire.php?datev=$tranchehoraireouverture->date&lieuv=S$reponse->id_structure\">Accs individuel</a>";
else
$tableau[$i][$j]["contenu"]="Accs individuel";
$j++;
$heure=additionHeure($heure, "00:".$nbminres);
}
else
{ // c'est une activit collective
// on regarde si la salle n'est pas dj rserve
$req5 = "SELECT * FROM sessions
WHERE date=\"$datecur\" AND id_localisation=\"$reponse->id_localisation\"
AND (debut<=\"$heure\" AND \"$heure\"<fin)
AND (etat<>\"annule\" AND etat<>\"non tenue\")";
$res5 = executeRequete($req5);
if (! ($reservation = fetch_object($res5)))
{ // pas de rservation
$tableau[$i][$j]["param"]=" align=center bgcolor=\"".COULEUR_SESSIONS."\""; // bleu
$tableau[$i][$j]["contenu"]="<a href=\"session.php?operation=1&datev=$datecur&debutv=$heure&id_localisation=$reponse->id_localisation\">
$programmer</a>";
// on passe au crneau suivant
$heure=additionHeure($heure, "00:".$unitehoraire);
}
else
{ // il y a bien une session prvue sur ce crneau l.
$tableau[$i][$j]["param"]=" bgcolor=\"".COULEUR_SESSIONS."\" align=center";
$tableau[$i][$j]["contenu"]=infoReservation($reservation);
$nbminres=60*(date("H",strtotime($reservation->fin))-date("H",strtotime($reservation->debut)))
+ (date("i",strtotime($reservation->fin))-date("i",strtotime($reservation->debut)));
$nbuniteres = $nbminres / $unitehoraire;
$tableau[$i][$j]["param"].=" colspan=$nbuniteres";
// on passe au crneau suivant (duree variable)
$heure=additionHeure($heure, "00:".$nbminres);
$tableau[$i][$j]["contenu"]=infoReservation($reservation);
free_result($res5);
}
$j++;
} // fin du else
} // fin de if c'est ouvert
if (defined("FCT_HORAIRES"))
free_result($res3);
} // while $heure
$i++; $j=0;
//echo "</tr>\n";
} // for $datecur, pour les jours
Affiche_tableau($tableau, $sens);
unset($tableau);
echo "</table>\n";
echo cadre_fin();
} // for pour les salles ou groupes d'ordinateurs
if (!$unlieu)
echo "<p>$spasdesalleselectionnee</p>\n";
} // function AfficheDisponibilitsSalle($lieuv, $datev, $sens)
function ChoixSemaine($datev)
{
while (date("w", strtotime($datev))!="1")
$datev=date("Y-m-d", strtotime("-1 day", strtotime($datev)));
echo "<td><select name=\"datev\">";
for ($nd=10 ; $nd>0; $nd--)
{
$ndate=date("Y-m-d", strtotime("-".$nd." weeks", strtotime($datev)));
echo "<option value=\"$ndate\"";
if ($datev==$ndate) echo " selected";
echo ">".jourSemaine(date("w",strtotime($ndate))).
" ".date("d",strtotime($ndate)).
" ".nomMois(date("m",strtotime($ndate))).
" ".date("Y",strtotime($ndate)).
"</option>\n";
}
for ($nd=0 ; $nd<=30; $nd++)
{
$ndate=date("Y-m-d", strtotime("+".$nd." weeks", strtotime($datev)));
echo "<option value=\"$ndate\"";
if ($datev==$ndate) echo " selected";
echo ">".jourSemaine(date("w",strtotime($ndate))).
" ".date("d",strtotime($ndate)).
" ".nomMois(date("m",strtotime($ndate))).
" ".date("Y",strtotime($ndate)).
"</option>\n";
}
echo "</select>
</td>\n";
}
function formChoixLieuDate($lieuv, $datev, $sens, $operation)
{
global $PHP_SELF;
echo "<form name=\"formlieudate\" method=\"post\" action=\"$PHP_SELF\">
<input type=\"hidden\" name=\"operation\" value=\"$operation\">
<table border=1 align=center>";
echo " <tr>
<td>Lieu</td>
<td>"; choix_Lieu($lieuv); echo "</td>";
echo " <td rowspan=\"2\">
<table>
<tr>
<td>Disposition</td>
<td>"; choixSensTableau($sens);
echo " </td>
</tr>
</table>
</td>
</tr>
<tr><td>Date</td>
<td>
<table>
<tr>
<td>
<a href=\"$PHP_SELF?operation=$operation&datev=".date("Y-m-d",strtotime("-7 day",strtotime($datev)))."&lieuv=$lieuv&sens=$sens\"><<</a>
</td>";
choixSemaine($datev);
echo " <td>
<a href=\"$PHP_SELF?operation=$operation&datev=".date("Y-m-d",strtotime("+7 day",strtotime($datev)))."&lieuv=$lieuv&sens=$sens\">>></a>
</td>
</tr>
</table>
</td>\n";
echo " </tr>
<tr>
<td align=center colspan=3>
<input type=\"submit\" name=\"Recherche disponibilits\" value=\"Recherche disponibilits\">
</td>
</tr>
</table>
</form>\n";
}
if (SESSIONS<="~")
{
echo $pasledroit;
exit();
}
// Dbut du contenu de la page
switch ($operation)
{
case 1 : // pr-rservation d'une salle par une structure
default :
if($datev=="")
if($day=="" | $month=="" | $year=="")
$datev = date("Y-m-d");
else
$datev = date("Y-m-d",strtotime($month."/".$day."/".$year));
if ($lieuv=="" || !$lieuv)
$lieuv="S$id_structure";
// formulaire de slection du lieu et de la semaine
echo cadre_debut($sselectionplanningsession);
formChoixLieuDate($lieuv, $datev, $sens, $operation);
echo cadre_fin();
// affichage du tableau des plannings des salles
AfficheDisponibilitsSalle($lieuv, $datev, $sens);
// rptition du formulaire
/*echo "<hr>\n";
formChoixLieuDate($lieuv, $datev, $sens, $operation); */
break;
} // fin du switch operation
include("basdepage.inc.php");
echo "</body></html>\n";
require("footer.inc.php");
?>