alpha_full/admin/stats/graphDate.php
2026-04-06 22:58:51 +02:00

164 lines
3.9 KiB
PHP
Executable File

<?php
$nomFicAppelant = basename(__FILE__);
require_once("jpgraph/src/jpgraph.php");
require_once ("jpgraph/src/jpgraph_line.php");
require_once("jpgraph/src/jpgraph_bar.php");
if(file_exists("../../_include/dataBaseConnect.php")) {$includePathConf="../../_conf";include ("../../_include/dataBaseConnect.php");}
if (isset($debug[2]) && $debug[2] == '1' ) {$includePathConf="../../../_conf"; if(file_exists("../../../_include/dataBaseConnect.php")) include ("../../../_include/dataBaseConnect.php");}
// -----------------------------------------------------
// Init
// -----------------------------------------------------
$year="Toutes";
$tbML=array();
$lib=array();
$data=array();
$resConn='';
// -----------------------------------------------------
// Init value
// -----------------------------------------------------
$lib[0]="Jan. ";
$lib[1]="Fev. ";
$lib[2]="Mars";
$lib[3]="Avril";
$lib[4]="Mai";
$lib[5]="Juin";
$lib[6]="Juil. ";
$lib[7]="Aout";
$lib[8]="Sept";
$lib[9]="Oct. ";
$lib[10]="Nov. ";
$lib[11]="Dec. ";
$data[0]="0";
$data[1]="0";
$data[2]="0";
$data[3]="0";
$data[4]="0";
$data[5]="0";
$data[6]="0";
$data[7]="0";
$data[8]="0";
$data[9]="0";
$data[10]="0";
$data[11]="0";
if (isset($_SESSION['modeTest'])) $modeTest=$_SESSION['modeTest']; else $modeTest=1;
if ($modeTest==2) {
// prendre la BDD prod
include ($includePathConf. "/prod.dbConnect.php");
// pour affichage environnement
$bdd=$bddProd;
$idPdo=$idPdoProd;
}
if (isset($_SESSION['year'])) $year=$_SESSION['year'];
if (isset($_GET['year'])) $year=$_GET['year'];
if( $year=="Toutes" )
{ $reqSelect="SELECT substr(timestamp,6,2) as period , count(timestamp)+0 as `nb` FROM `stats` group by substr(timestamp,6,2 ) order by period;"; }
else
{ $reqSelect="SELECT substr(timestamp,6,2) as period , count(timestamp)+0 as `nb` FROM `stats` WHERE substr(timestamp,1,4)=" .$year. " group by substr(timestamp,6,2 ) order by period;"; }
if (isset($debug[2]) && $debug[2] == '1' ) { $debugMsg .=monDebug(2, ['reqSelect' => $reqSelect],'graphPays');}
$resConn=$idPdo->query($reqSelect);
if ($resConn) {
$l=-1;
while ($tbML=$resConn->fetch(PDO::FETCH_ASSOC)) {
$l++;
$lib[$l]=$tbML['period'];
$data[$l]=intval($tbML['nb']);
$data[$l]=intval($data[$l]);
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['lib[l]' => $lib[$l]], '');}
switch ($lib[$l] ) {
case 01:
case "01":
$lib[$l]="Jan. ";
break;
case 02:
case "02":
$lib[$l]="Fev. ";
break;
case "03":
$lib[$l]="Mars";
break;
case "04":
$lib[$l]="Avril";
break;
case "05":
$lib[$l]="Mai";
break;
case "06":
$lib[$l]="Juin";
break;
case "07":
$lib[$l]="Juil. ";
break;
case "08":
$lib[$l]="Aout";
break;
case "09":
$lib[$l]="Sept";
break;
case "10":
$lib[$l]="Oct. ";
break;
case "11":
$lib[$l]="Nov. ";
break;
case "12":
$lib[$l]="Dec. ";
break;
// $l++;
}
}
}
$largeur = 700;
$hauteur = 500;
$graph = new Graph($largeur, $hauteur, "auto");
// $graph->setScale("textlin");
$graph->SetScale('textint');
$plot = new BarPlot($data);
$graph->add($plot);
$plot->value->SetColor("darkgreen","darkred");
$plot->SetFillgradient('darkgreen','#D5EAFF',GRAD_WIDE_MIDVER);
$graph->img->SetMargin(60,40,60,10);
$graph->SetShadow();
$plot->value->Show();
$plot->value->SetFormat('%d');
$lineplot=new LinePlot($data);
$graph->Add($lineplot);
// Axe des abscisses
$graph->yaxis->SetLabelAngle ( 45 ); // angle de 45 degrés
$graph->yaxis->SetTextLabelInterval(2); // interval ou on ecrit l'unité
$graph ->yaxis->scale->ticks->Set(20);
// $graph->xaxis->SetLabelAngle(90);
$graph->xaxis->SetLabelAlign('right', 'center');
$plot->SetFillColor("azure2");
$graph->SetColor('azure3');
$graph->xaxis->SetTickLabels($lib);
$graph->title->SET("Nombre de visite par mois / année : " .$year);
$graph->stroke();
?>