Files

242 lines
7.1 KiB
PHP
Executable File

<?php
$id_club=$_GET['id_club'];
$jour=$_GET['jour'];
$mois=$_GET['mois'];
$annee=$_GET['annee'];
include("conf.php");
if($jour!= 'vide' and $mois!='vide') {
$res=checkdate($mois, $jour, $annee);
if($res==TRUE) {
$date_ok=1;
}
else {
$date_ok=-1;
}
}
else {
$date_ok=0;
}
/* Journée */
if($date_ok==1) {
$ts=mktime(0,0,0,$mois,$jour,$annee);
$debut=Date("Y-m-d", $ts);
$fin=Date("Y-m-d", $ts);
$titre=date("d/m/Y", $ts);
$type='jour';
}
/* Sur un mois ou une année */
else if($date_ok==0) {
/* Année */
if($mois=='vide') {
$debut="$annee-01-01";
$fin="$annee-12-31";
$titre="Annee $annee";
$type='annee';
}
/* Mois */
else {
$ts=mktime(0,0,0,$mois,1,$annee);
$debut=Date("Y-m-d", $ts);
/* dernier jour du mois */
$ts=mktime(0,0,0,$mois,1,$annee);
$locales = array('fr_FR.UTF-8', 'fr_FR');
setlocale(LC_ALL,$locales);
$dernier_jour=date("t",$ts);
$ts=mktime(0,0,0,$mois,$dernier_jour,$annee);
$fin=Date("Y-m-d", $ts);
$titre="Mois de ".nom_mois($mois)." $annee";
$type='mois';
}
}
/**********************************************************************************/
/* Date de comparaison */
$jour_cmp=$_GET['jour_cmp'];
$mois_cmp=$_GET['mois_cmp'];
$annee_cmp=$_GET['annee_cmp'];
if($jour_cmp != 'vide' and $mois_cmp !='vide') {
$res=checkdate($mois_cmp, $jour_cmp, $annee_cmp);
if($res==TRUE) {
$date_cmp_ok=1;
}
else {
$date_cmp_ok=-1;
}
}
else {
$date_cmp_ok=0;
}
/* Journée */
if($date_cmp_ok==1) {
$ts=mktime(0,0,0,$mois_cmp,$jour_cmp,$annee_cmp);
$debut_cmp=Date("Y-m-d", $ts);
$fin_cmp=Date("Y-m-d", $ts);
$titre_cmp=date("d/m/Y", $ts);
$type_cmp='jour';
}
/* Sur un mois ou une année */
else if($date_cmp_ok==0) {
/* Année */
if($mois_cmp == 'vide') {
$debut_cmp ="$annee_cmp-01-01";
$fin_cmp ="$annee_cmp-12-31";
$titre_cmp="Annee $annee_cmp";
$type_cmp='annee';
}
/* Mois */
else {
$ts=mktime(0,0,0,$mois_cmp,1,$annee_cmp);
$debut_cmp=Date("Y-m-d", $ts);
/* dernier jour du mois */
$ts=mktime(0,0,0,$mois_cmp,1,$annee_cmp);
$locales = array('fr_FR.UTF-8', 'fr_FR');
setlocale(LC_ALL,$locales);
$dernier_jour=date("t",$ts);
$ts=mktime(0,0,0,$mois_cmp,$dernier_jour,$annee_cmp);
$fin_cmp=Date("Y-m-d", $ts);
$titre_cmp="Mois de ".nom_mois($mois_cmp)." $annee_cmp";
$type_cmp='mois';
}
}
/********************************/
/* Requetes */
$rub=array('Loisir','Cours','Championnat','Tournoi','Entretien','Autre');
$res=array();
$res_cmp=array();
$evol=array();
for($i=0;$i<count($rub);$i++) {
/* Date en cours */
$requete="SELECT r.id_reservation FROM reservation r, reservable t WHERE ";
$requete.="t.id_reservable=r.id_reservable AND t.id_club='$id_club' AND date_resa <='$fin' AND date_resa>='$debut' AND r.type='$rub[$i]'";
$reponse=mysqli_query( $db_connection, $requete) or die("Erreur lors de l'execution de la requete<br />");
$res[$i]=mysqli_num_rows($reponse);
/* Comparaison */
$requete="SELECT r.id_reservation FROM reservation r, reservable t WHERE ";
$requete.="t.id_reservable=r.id_reservable AND t.id_club='$id_club' AND date_resa <='$fin_cmp' AND date_resa>='$debut_cmp' AND r.type='$rub[$i]'";
$reponse=mysqli_query( $db_connection, $requete) or die("Erreur lors de l'execution de la requete<br />");
$res_cmp[$i]=mysqli_num_rows($reponse);
}
/* Total */
$requete="SELECT r.id_reservation FROM reservation r, reservable t WHERE ";
$requete.="t.id_reservable=r.id_reservable AND t.id_club='$id_club' AND date_resa <='$fin' AND date_resa>='$debut'";
$reponse=mysqli_query( $db_connection, $requete) or die("Erreur lors de l'execution de la requete<br />");
$nb_resas_total=mysqli_num_rows($reponse);
$requete="SELECT r.id_reservation FROM reservation r, reservable t WHERE ";
$requete.="t.id_reservable=r.id_reservable AND t.id_club='$id_club' AND date_resa <='$fin_cmp' AND date_resa>='$debut_cmp'";
$reponse=mysqli_query( $db_connection, $requete) or die("Erreur lors de l'execution de la requete<br />");
$nb_resas_total_cmp=mysqli_num_rows($reponse);
/* Graphique */
include ("jpgraph/jpgraph.php");
include ("jpgraph/jpgraph_bar.php");
/* Donnees */
$abs=array($titre, $titre_cmp);
$loisir=array($res[0], $res_cmp[0]);
$cours=array($res[1], $res_cmp[1]);
$champ=array($res[2], $res_cmp[2]);
$tournoi=array($res[3], $res_cmp[3]);
$entretien=array($res[4], $res_cmp[4]);
$autre=array($res[5], $res_cmp[5]);
$total=array($nb_resas_total, $nb_resas_total_cmp);
/* Graphique */
$graph = new Graph(800,600,"auto");
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->img->SetMargin(60,40,50,40);
$graph->SetMarginColor('#CCCCFF');
$graph->title->Set("Comparaison des reservation entre 2 periodes");
$graph->title->SetMargin(20);
// Loisir
$histo_loisir = new BarPlot($loisir);
$histo_loisir->SetFillColor('orange');
$histo_loisir->SetLegend('Loisir');
$histo_loisir->value->Show();
$histo_loisir->value->SetColor('black');
$histo_loisir->value->SetFormat('%d');
// Cours
$histo_cours = new BarPlot($cours);
$histo_cours->SetFillColor('blue');
$histo_cours->SetLegend('Cours');
$histo_cours->value->Show();
$histo_cours->value->SetColor('black');
$histo_cours->value->SetFormat('%d');
// Championnat
$histo_champ = new BarPlot($champ);
$histo_champ->SetFillColor('red');
$histo_champ->SetLegend('Championnat');
$histo_champ->value->Show();
$histo_champ->value->SetColor('black');
$histo_champ->value->SetFormat('%d');
// Tournoi
$histo_tournoi = new BarPlot($tournoi);
$histo_tournoi->SetFillColor('green');
$histo_tournoi->SetLegend('Tournoi');
$histo_tournoi->value->Show();
$histo_tournoi->value->SetColor('black');
$histo_tournoi->value->SetFormat('%d');
// Autre
$histo_autre = new BarPlot($autre);
$histo_autre->SetFillColor('lightblue');
$histo_autre->SetLegend('Autre');
$histo_autre->value->Show();
$histo_autre->value->SetColor('black');
$histo_autre->value->SetFormat('%d');
// Entretien
$histo_entret = new BarPlot($entretien);
$histo_entret->SetFillColor('pink');
$histo_entret->SetLegend('Entretien');
$histo_entret->value->Show();
$histo_entret->value->SetColor('black');
$histo_entret->value->SetFormat('%d');
// Total
$histo_total = new BarPlot($total);
$histo_total->SetFillColor('brown');
$histo_total->SetLegend('Total');
$histo_total->value->Show();
$histo_total->value->SetColor('black');
$histo_total->value->SetFormat('%d');
$gbplot = new AccBarPlot(array($histo_loisir, $histo_cours, $histo_champ,$histo_entret, $histo_autre,$histo_tournoi,$histo_total));
// Position de la légende
$graph->legend->Pos(0.85,0.1,"left","top");
// Ajouter l'ensemble accumulé
$graph->Add($gbplot);
// Paramétrer les axes X et Y
$graph->yaxis->title->Set("Nombre reservations");
$graph->yaxis->title->SetMargin(20);
$graph->xaxis->title->Set("Periode");
$graph->xaxis->SetTickLabels($abs);
$graph->xaxis->title->SetMargin(4);
// Afficher l'image générée
$graph->Stroke();
function nom_mois($mois) {
$noms=array("Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Decembre");
$mois_tab=$mois-1;
return $noms[$mois_tab];
}
?>