Refactor code for improved readability and consistency across multiple files

This commit is contained in:
Le Stagiaire
2024-11-08 16:08:06 +01:00
parent 0cfc5938bd
commit 6aa7fea79c
19 changed files with 1677 additions and 1794 deletions

View File

@ -1,178 +1,162 @@
<?php require('head.php');
if(@$infos_user['droit'] > 0)
{
if (@$infos_user['droit'] > 0) {
?>
<script src="js/highcharts.js"></script>
<script src="js/modules/exporting.js"></script>
<script type="text/javascript" src="calendrier.js"></script>
<script src="js/highcharts.js"></script>
<script src="js/modules/exporting.js"></script>
<script type="text/javascript" src="calendrier.js"></script>
<table class="ds_box" cellpadding="0" cellspacing="0" id="ds_conclass" style="display: none;">
<tr>
<td id="ds_calclass"></td>
</tr>
</table>
<table class="ds_box" cellpadding="0" cellspacing="0" id="ds_conclass" style="display: none;">
<tr>
<td id="ds_calclass"></td>
</tr>
</table>
<?php
if(isset($_GET['du'], $_GET['au']) && strtotime($_GET['du']) && strtotime($_GET['au'])) //On vérifie les dates reçues
{
$date1 = date("Y-m-d", strtotime("-1 day", strtotime($_GET['du'])));
$date1bis = date('Y-m-d', strtotime($_GET['du']));
$date2 = date('Y-m-d', strtotime($_GET['au']));
}
else //Sinon on prend les valeurs du dernier mois
{
$date1bis = $date1 = date('Y-m-d', strtotime("-1 month", strtotime(date('Y-m-d'))));
$date2 = date('Y-m-d', strtotime("+1 day", strtotime(date('Y-m-d'))));
}
$result_vol_6 = $connexion->query("SELECT * FROM chateau WHERE heure='06:00:00' and date >= '".$date1."' and date <= '".$date2."' ORDER BY date, heure ASC");
$result_vol_22 = $connexion->query("SELECT * FROM chateau WHERE heure='22:00:00' and date >= '".$date1."' and date <= '".$date2."' ORDER BY date, heure ASC");
$while_date = $date1;
$s_date = '';
while(strtotime($while_date) <= strtotime($date2))
{
$tab_vol_6[$while_date] = 'null';
$tab_vol_22[$while_date] = 'null';
$while_date = date("Y-m-d", strtotime("+1 day", strtotime($while_date)));
}
$while_datebis = $date1bis;
while(strtotime($while_datebis) <= strtotime($date2))
{
$s_date = $s_date.'"'.date("d/m/y", strtotime($while_datebis)).'",';
$while_datebis = date("Y-m-d", strtotime("+1 day", strtotime($while_datebis)));
}
while($fetch = $result_vol_6->fetch()) //On remplie tab_vol_6 avec les valeurs de la bdd
{
$tab_vol_6[$fetch['date']] = $fetch['compteur_impulsion'];
}
while($fetch = $result_vol_22->fetch()) //On remplie tab_vol_22 avec les valeurs de la bdd
{
$tab_vol_22[$fetch['date']] = $fetch['compteur_impulsion'];
}
$s_vol_6 = '';
$s_vol_22= '';
$volmin = 100;
$volmax = 0;
$voltot = 0;
$Nbjours_V1=0;
$while_date = $date1;
for($i = 0; $i < count($tab_vol_6); $i++)//On remplie s_vol_6 des valeurs de la bdd pour highchart
{
if(isset($tab_vol_22[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))]) && $tab_vol_22[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))] != 'null' && $tab_vol_6[$while_date] != 'null')
<?php
if (isset($_GET['du'], $_GET['au']) && strtotime($_GET['du']) && strtotime($_GET['au'])) //On vérifie les dates reçues
{
$vol = ($tab_vol_6[$while_date]-$tab_vol_22[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))]);
$Nbjours_V1++;
$vol = round($vol, 2);
if ($vol<$volmin) $volmin = $vol;
if ($vol>$volmax) $volmax = $vol;
$voltot = $voltot + $vol;
$s_vol_6 = $s_vol_6.$vol.','; //On ajoute la valeur au tableau
$date1 = date("Y-m-d", strtotime("-1 day", strtotime($_GET['du'])));
$date1bis = date('Y-m-d', strtotime($_GET['du']));
$date2 = date('Y-m-d', strtotime($_GET['au']));
} else //Sinon on prend les valeurs du dernier mois
{
$date1bis = $date1 = date('Y-m-d', strtotime("-1 month", strtotime(date('Y-m-d'))));
$date2 = date('Y-m-d', strtotime("+1 day", strtotime(date('Y-m-d'))));
}
else if ($i != 0) $s_vol_6 = $s_vol_6.'null,'; //Si aucune valeur on met null dans le tableau
$while_date = date("Y-m-d", strtotime("+1 day", strtotime($while_date)));
}
// calcul du nombre de jours sur l'intervalle
$result_vol_6 = $connexion->query("SELECT * FROM chateau WHERE heure='06:00:00' and date >= '" . $date1 . "' and date <= '" . $date2 . "' ORDER BY date, heure ASC");
$result_vol_22 = $connexion->query("SELECT * FROM chateau WHERE heure='22:00:00' and date >= '" . $date1 . "' and date <= '" . $date2 . "' ORDER BY date, heure ASC");
$while_date = $date1;
$s_date = '';
while (strtotime($while_date) <= strtotime($date2)) {
$tab_vol_6[$while_date] = 'null';
$tab_vol_22[$while_date] = 'null';
$while_date = date("Y-m-d", strtotime("+1 day", strtotime($while_date)));
}
$while_datebis = $date1bis;
while (strtotime($while_datebis) <= strtotime($date2)) {
$s_date = $s_date . '"' . date("d/m/y", strtotime($while_datebis)) . '",';
$while_datebis = date("Y-m-d", strtotime("+1 day", strtotime($while_datebis)));
}
while ($fetch = $result_vol_6->fetch()) //On remplie tab_vol_6 avec les valeurs de la bdd
{
$tab_vol_6[$fetch['date']] = $fetch['compteur_impulsion'];
}
while ($fetch = $result_vol_22->fetch()) //On remplie tab_vol_22 avec les valeurs de la bdd
{
$tab_vol_22[$fetch['date']] = $fetch['compteur_impulsion'];
}
$s_vol_6 = '';
$s_vol_22 = '';
$volmin = 100;
$volmax = 0;
$voltot = 0;
$Nbjours_V1 = 0;
$while_date = $date1;
for ($i = 0; $i < count($tab_vol_6); $i++) //On remplie s_vol_6 des valeurs de la bdd pour highchart
{
if (isset($tab_vol_22[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))]) && $tab_vol_22[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))] != 'null' && $tab_vol_6[$while_date] != 'null') {
$vol = ($tab_vol_6[$while_date] - $tab_vol_22[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))]);
$Nbjours_V1++;
$vol = round($vol, 2);
if ($vol < $volmin) $volmin = $vol;
if ($vol > $volmax) $volmax = $vol;
$voltot = $voltot + $vol;
$s_vol_6 = $s_vol_6 . $vol . ','; //On ajoute la valeur au tableau
} else if ($i != 0) $s_vol_6 = $s_vol_6 . 'null,'; //Si aucune valeur on met null dans le tableau
$while_date = date("Y-m-d", strtotime("+1 day", strtotime($while_date)));
}
// calcul du nombre de jours sur l'intervalle
$TDfin = strtotime($date2); // conversion timestamp
$TDDeb = strtotime($date1);
$Nbjours = round(($TDfin-$TDDeb)/(60*60*24)); //division des secondes pour avoir les jours
$Nbjours = round(($TDfin - $TDDeb) / (60 * 60 * 24)); //division des secondes pour avoir les jours
//$Nbjours = 31;
// Affichage des données bilan sur la période;
$vmoy=$voltot/($Nbjours); // moyenne par jour
$vmoy = $voltot / ($Nbjours); // moyenne par jour
$result_pomp = $connexion->query("SELECT * FROM relevage WHERE heure='00:15:00' and date >= '".$date1."' and date <= '".$date2."' ORDER BY date, heure ASC");
$result_pomp = $connexion->query("SELECT * FROM relevage WHERE heure='00:15:00' and date >= '" . $date1 . "' and date <= '" . $date2 . "' ORDER BY date, heure ASC");
$i = 0;
$i = 0;
while($fetch = $result_pomp->fetch()) //On remplie tab_pomp1 et tab_pomp2 avec les valeurs de la bdd
{
$tab_pomp1[$fetch['date']] = $fetch['temp_marche_pp1'];
$tab_pomp2[$fetch['date']] = $fetch['temp_marche_pp2'];
}
$s_pomp1 = '';
$s_pomp2= '';
$vol_maxp1 = 0;
$vol_minp1 = 100;
$vol_totp1 = 0;
$Nbjours_P1 = 0;
$while_date = $date1;
for($i = 0; $i < $Nbjours+1;$i++)//On remplie s_pomp1 des valeurs de la bdd pour highchart
{
if(isset($tab_pomp1[$while_date]) && $tab_pomp1[$while_date] != 'null' and $i != 0)
while ($fetch = $result_pomp->fetch()) //On remplie tab_pomp1 et tab_pomp2 avec les valeurs de la bdd
{
if(!isset($tab_pomp1[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))])) //On vérifie que la valeur précédente éxiste
if(isset($tab_pomp1[date("Y-m-d", strtotime("-2 day", strtotime($while_date)))]))
{
$vol = $tab_pomp1[$while_date]-$tab_pomp1[date("Y-m-d", strtotime("-2 day", strtotime($while_date)))];
$tab_pomp1[$fetch['date']] = $fetch['temp_marche_pp1'];
$tab_pomp2[$fetch['date']] = $fetch['temp_marche_pp2'];
}
$s_pomp1 = '';
$s_pomp2 = '';
$vol_maxp1 = 0;
$vol_minp1 = 100;
$vol_totp1 = 0;
$Nbjours_P1 = 0;
$while_date = $date1;
for ($i = 0; $i < $Nbjours + 1; $i++) //On remplie s_pomp1 des valeurs de la bdd pour highchart
{
if (isset($tab_pomp1[$while_date]) && $tab_pomp1[$while_date] != 'null' and $i != 0) {
if (!isset($tab_pomp1[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))])) //On vérifie que la valeur précédente éxiste
if (isset($tab_pomp1[date("Y-m-d", strtotime("-2 day", strtotime($while_date)))])) {
$vol = $tab_pomp1[$while_date] - $tab_pomp1[date("Y-m-d", strtotime("-2 day", strtotime($while_date)))];
$Nbjours_P1++;
} else
$vol = '0';
else {
$vol = $tab_pomp1[$while_date] - $tab_pomp1[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))];
$Nbjours_P1++;
}
else
$vol ='0';
else
{
$vol = $tab_pomp1[$while_date]-$tab_pomp1[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))];
$Nbjours_P1++;
}
$vol = round($vol, 2);
if ($vol<$vol_minp1) $vol_minp1 = $vol;
if ($vol>$vol_maxp1) $vol_maxp1 = $vol;
$vol_totp1 = $vol_totp1 + $vol;
$s_pomp1 = $s_pomp1.$vol.','; //On ajoute la valeur au tableau
}
else if ($i != 0) $s_pomp1 = $s_pomp1.'null,'; //Si aucune valeur on met null dans le tableau
$while_date = date("Y-m-d", strtotime("+1 day", strtotime($while_date)));
}
$vol_maxp2 = 0;
$vol_minp2 = 100;
$vol_totp2 = 0;
$Nbjours_P2=0;
$vol = round($vol, 2);
if ($vol < $vol_minp1) $vol_minp1 = $vol;
if ($vol > $vol_maxp1) $vol_maxp1 = $vol;
$vol_totp1 = $vol_totp1 + $vol;
$while_date = $date1;
for($i = 0; $i < $Nbjours+1; $i++)//On remplie s_pomp2 des valeurs de la bdd pour highchart
{
if(isset($tab_pomp2[$while_date]) && $tab_pomp2[$while_date] != 'null' and $i != 0)
$s_pomp1 = $s_pomp1 . $vol . ','; //On ajoute la valeur au tableau
} else if ($i != 0) $s_pomp1 = $s_pomp1 . 'null,'; //Si aucune valeur on met null dans le tableau
$while_date = date("Y-m-d", strtotime("+1 day", strtotime($while_date)));
}
$vol_maxp2 = 0;
$vol_minp2 = 100;
$vol_totp2 = 0;
$Nbjours_P2 = 0;
$while_date = $date1;
for ($i = 0; $i < $Nbjours + 1; $i++) //On remplie s_pomp2 des valeurs de la bdd pour highchart
{
if(!isset($tab_pomp2[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))])) //On vérifie que la valeur précédente éxiste
if(isset($tab_pomp2[date("Y-m-d", strtotime("-2 day", strtotime($while_date)))]))
{
$vol = $tab_pomp2[$while_date]-$tab_pomp2[date("Y-m-d", strtotime("-2 day", strtotime($while_date)))];
if (isset($tab_pomp2[$while_date]) && $tab_pomp2[$while_date] != 'null' and $i != 0) {
if (!isset($tab_pomp2[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))])) //On vérifie que la valeur précédente éxiste
if (isset($tab_pomp2[date("Y-m-d", strtotime("-2 day", strtotime($while_date)))])) {
$vol = $tab_pomp2[$while_date] - $tab_pomp2[date("Y-m-d", strtotime("-2 day", strtotime($while_date)))];
$Nbjours_P2++;
} else
$vol = '0';
else {
$vol = $tab_pomp2[$while_date] - $tab_pomp2[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))];
$Nbjours_P2++;
}
else
$vol='0';
else
{
$vol = $tab_pomp2[$while_date]-$tab_pomp2[date("Y-m-d", strtotime("-1 day", strtotime($while_date)))];
$Nbjours_P2++;
}
$vol = round($vol, 2);
if ($vol<$vol_minp2) $vol_minp2 = $vol;
if ($vol>$vol_maxp2) $vol_maxp2 = $vol;
$vol_totp2 = $vol_totp2 + $vol;
$s_pomp2 = $s_pomp2.$vol.','; //On ajoute la valeur au tableau
}
else if ($i != 0) $s_pomp2 = $s_pomp2.'null,'; //Si aucune valeur on met null dans le tableau
$while_date = date("Y-m-d", strtotime("+1 day", strtotime($while_date)));
}
$vol = round($vol, 2);
if ($vol < $vol_minp2) $vol_minp2 = $vol;
if ($vol > $vol_maxp2) $vol_maxp2 = $vol;
$vol_totp2 = $vol_totp2 + $vol;
$s_pomp2 = $s_pomp2 . $vol . ','; //On ajoute la valeur au tableau
} else if ($i != 0) $s_pomp2 = $s_pomp2 . 'null,'; //Si aucune valeur on met null dans le tableau
$while_date = date("Y-m-d", strtotime("+1 day", strtotime($while_date)));
}
// calcul du nombre de jours sur l'intervalle
$TDfin = strtotime($date2); // conversion timestamp
@ -180,118 +164,117 @@ for($i = 0; $i < $Nbjours+1; $i++)//On remplie s_pomp2 des valeurs de la bdd pou
//$Nbjours = round(($TDfin-$TDDeb)/(60*60*24)); //division des secondes pour avoir les jours
//$Nbjours = 31;
// Affichage des données bilan sur la période;
$vmoyp1=$vol_totp1/($Nbjours_P1); // moyenne par jour
$vmoyp2=$vol_totp2/($Nbjours_P2); // moyenne par jour
$vmoy=$voltot/($Nbjours_V1); // moyenne par jour
?>
$vmoyp1 = $vol_totp1 / ($Nbjours_P1); // moyenne par jour
$vmoyp2 = $vol_totp2 / ($Nbjours_P2); // moyenne par jour
$vmoy = $voltot / ($Nbjours_V1); // moyenne par jour
?>
<form method="get">Du <input name="du" type="text" value="<?php echo $date1bis;?>" onclick="ds_sh(this);"> au <input name="au" type="text" value="<?php echo $date2;?>" onclick="ds_sh(this);"><input type="submit" value="Afficher le graphique"><em style="font-size:12px;">(format ex.: 2014-05-27)</em></form>
<form method="get">Du <input name="du" type="text" value="<?php echo $date1bis; ?>" onclick="ds_sh(this);"> au <input name="au" type="text" value="<?php echo $date2; ?>" onclick="ds_sh(this);"><input type="submit" value="Afficher le graphique"><em style="font-size:12px;">(format ex.: 2014-05-27)</em></form>
<script type="text/javascript">
$(function () {
$('#container').highcharts({
chart: {
alignTicks: false,
type: 'column',
zoomType: 'x'
},
title: {
text: 'Temps de fonctionnement des pompes de la station de relavage<br/>du <?php echo "<b>".date("d/m/Y", strtotime($date1))."</b> au <b>".date("d/m/Y", strtotime($date2))."</b>";?>',
x: -20 //center
},
subtitle: {
<?php
echo " text: 'T.F. pompe1 ";
if($vol_totp1 == 0) $vol_minp1 = 0;
echo " --- T total = <b>".round($vol_totp1, 2)."</b> H -- Tmoy/jour = <b>".round($vmoyp1, 2)."</b> H (".$Nbjours_P1."J) -- Tmin = <b>".round($vol_minp1, 2)."</b> H -- TMax = <b>".round($vol_maxp1, 2)."</b> H<br/>T.F. pompe2 ";
if($vol_totp2 == 0) $vol_minp2 = 0;
echo " --- T total = <b>".round($vol_totp2, 2)."</b> H -- Tmoy/jour = <b>".round($vmoyp2, 2)."</b> H (".$Nbjours_P2."J) -- Tmin = <b>".round($vol_minp2, 2)."</b> H -- TMax = <b>".round($vol_maxp2, 2)."</b> H'";
?>
},
xAxis: {
labels: {
rotation: -60
<script type="text/javascript">
$(function() {
$('#container').highcharts({
chart: {
alignTicks: false,
type: 'column',
zoomType: 'x'
},
title: {
text: 'Temps de fonctionnement des pompes de la station de relavage<br/>du <?php echo "<b>" . date("d/m/Y", strtotime($date1)) . "</b> au <b>" . date("d/m/Y", strtotime($date2)) . "</b>"; ?>',
x: -20 //center
},
subtitle: {
<?php
echo " text: 'T.F. pompe1 ";
if ($vol_totp1 == 0) $vol_minp1 = 0;
echo " --- T total = <b>" . round($vol_totp1, 2) . "</b> H -- Tmoy/jour = <b>" . round($vmoyp1, 2) . "</b> H (" . $Nbjours_P1 . "J) -- Tmin = <b>" . round($vol_minp1, 2) . "</b> H -- TMax = <b>" . round($vol_maxp1, 2) . "</b> H<br/>T.F. pompe2 ";
if ($vol_totp2 == 0) $vol_minp2 = 0;
echo " --- T total = <b>" . round($vol_totp2, 2) . "</b> H -- Tmoy/jour = <b>" . round($vmoyp2, 2) . "</b> H (" . $Nbjours_P2 . "J) -- Tmin = <b>" . round($vol_minp2, 2) . "</b> H -- TMax = <b>" . round($vol_maxp2, 2) . "</b> H'";
?>
},
xAxis: {
labels: {
rotation: -60
},
categories: [<?php echo $s_date; ?>]
},
yAxis: {
title: {
text: 'Heure (H)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
categories: [<?php echo $s_date;?>]
},
yAxis: {
title: {
text: 'Heure (H)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
yAxis: [{ // Primary yAxis
title: {
text: 'Volume',
style: {
color: Highcharts.getOptions().colors[0]
}
},
opposite: true
yAxis: [{ // Primary yAxis
title: {
text: 'Volume',
style: {
color: Highcharts.getOptions().colors[0]
}
},
opposite: true
}, { // Secondary yAxis
gridLineWidth: 0,
title: {
text: 'Heure (H)',
style: {
color: Highcharts.getOptions().colors[2]
}
},
}, { // Secondary yAxis
gridLineWidth: 0,
title: {
text: 'Heure (H)',
style: {
color: Highcharts.getOptions().colors[2]
}
},
}],
}],
tooltip: {
valueSuffix: 'H'
},
plotOptions: {
column: {
stacking: 'normal'
}
},
legend: {
layout: 'vertical',
align: 'center',
verticalAlign: 'bottom',
borderWidth: 0
},
series: [{
name: 'Temps de fonctionnement pompe 1',
data: [<?php echo $s_pomp1;?>],
stack: 'heure_pompe',
yAxis: 1,
color: '#32CD32'
}, {
name: 'Temps de fonctionnement pompe 2',
data: [<?php echo $s_pomp2;?>],
stack: 'heure_pompe',
yAxis: 1,
color: '#008000'
}, {
name: 'Volume pompé Chateau d\'eau',
data: [<?php echo $s_vol_6;?>],
stack: 'volume',
yAxis: 0,
color: '#00BFFF',
tooltip: {
valueSuffix: ''
}
}]
});
});
</script>
valueSuffix: 'H'
},
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
plotOptions: {
column: {
stacking: 'normal'
}
},
legend: {
layout: 'vertical',
align: 'center',
verticalAlign: 'bottom',
borderWidth: 0
},
series: [{
name: 'Temps de fonctionnement pompe 1',
data: [<?php echo $s_pomp1; ?>],
stack: 'heure_pompe',
yAxis: 1,
color: '#32CD32'
}, {
name: 'Temps de fonctionnement pompe 2',
data: [<?php echo $s_pomp2; ?>],
stack: 'heure_pompe',
yAxis: 1,
color: '#008000'
}, {
name: 'Volume pompé Chateau d\'eau',
data: [<?php echo $s_vol_6; ?>],
stack: 'volume',
yAxis: 0,
color: '#00BFFF',
tooltip: {
valueSuffix: 'm³'
}
}]
});
});
</script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<?php
if($voltot == 0) $volmin = 0;
echo "Volume pompé --- V total = <b>".round($voltot, 2)."</b> m³ -- Tmoy/jour = <b>".round($vmoy, 2)."</b> m³ (".$Nbjours_V1."J) -- Tmin = <b>".round($volmin, 2)."</b> m³ -- TMax = <b>".round($volmax, 2)."</b> m³ --- ";
}
else echo 'Vous n\'êtes pas autorisé/connecté!';
if ($voltot == 0) $volmin = 0;
echo "Volume pompé --- V total = <b>" . round($voltot, 2) . "</b> m³ -- Tmoy/jour = <b>" . round($vmoy, 2) . "</b> m³ (" . $Nbjours_V1 . "J) -- Tmin = <b>" . round($volmin, 2) . "</b> m³ -- TMax = <b>" . round($volmax, 2) . "</b> m³ --- ";
} else echo 'Vous n\'êtes pas autorisé/connecté!';
include('foot.php'); ?>