Refactor code for improved readability and consistency across multiple files
This commit is contained in:
238
temperatures.php
238
temperatures.php
@ -1,147 +1,139 @@
|
||||
<?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']))
|
||||
{
|
||||
$date1 = date('Y-m-d', strtotime($_GET['du']));
|
||||
$date2 = date('Y-m-d', strtotime($_GET['au']));
|
||||
}
|
||||
else
|
||||
{
|
||||
$date1 = date('Y-m-d', strtotime("-1 month", strtotime(date('Y-m-d'))));
|
||||
$date2 = date('Y-m-d');
|
||||
}
|
||||
<?php
|
||||
if (isset($_GET['du'], $_GET['au']) && strtotime($_GET['du']) && strtotime($_GET['au'])) {
|
||||
$date1 = date('Y-m-d', strtotime($_GET['du']));
|
||||
$date2 = date('Y-m-d', strtotime($_GET['au']));
|
||||
} else {
|
||||
$date1 = date('Y-m-d', strtotime("-1 month", strtotime(date('Y-m-d'))));
|
||||
$date2 = date('Y-m-d');
|
||||
}
|
||||
|
||||
$result_temp = $connexion->query("SELECT * FROM chateau WHERE heure='06:00:00' and date >= '".$date1."' and date <= '".$date2."' ORDER BY date, heure ASC");
|
||||
$result_temp = $connexion->query("SELECT * FROM chateau WHERE heure='06:00:00' and date >= '" . $date1 . "' and date <= '" . $date2 . "' ORDER BY date, heure ASC");
|
||||
|
||||
$while_date = $date1;
|
||||
$while_date = $date1;
|
||||
|
||||
$s_date = '';
|
||||
$s_date = '';
|
||||
|
||||
while(strtotime($while_date) <= strtotime($date2))
|
||||
{
|
||||
$tab_amb[$while_date] = 'null';
|
||||
$tab_col[$while_date] = 'null';
|
||||
|
||||
$s_date = $s_date.'"'.date("d/m/y", strtotime($while_date)).'",';
|
||||
$while_date = date("Y-m-d", strtotime("+1 day", strtotime($while_date)));
|
||||
}
|
||||
while (strtotime($while_date) <= strtotime($date2)) {
|
||||
$tab_amb[$while_date] = 'null';
|
||||
$tab_col[$while_date] = 'null';
|
||||
|
||||
while($fetch = $result_temp->fetch())
|
||||
{
|
||||
$tab_amb[$fetch['date']] = $fetch['temp_ambiante'];
|
||||
$tab_col[$fetch['date']] = $fetch['temp_colonne'];
|
||||
}
|
||||
$s_date = $s_date . '"' . date("d/m/y", strtotime($while_date)) . '",';
|
||||
$while_date = date("Y-m-d", strtotime("+1 day", strtotime($while_date)));
|
||||
}
|
||||
|
||||
$s_temp_amb = '';
|
||||
$s_temp_col= '';
|
||||
$temp_ambmin = 100;
|
||||
$temp_ambmax = 0;
|
||||
$temp_ambtot = 0;
|
||||
$temp_colmin = 100;
|
||||
$temp_colmax = 0;
|
||||
$temp_coltot = 0;
|
||||
while ($fetch = $result_temp->fetch()) {
|
||||
$tab_amb[$fetch['date']] = $fetch['temp_ambiante'];
|
||||
$tab_col[$fetch['date']] = $fetch['temp_colonne'];
|
||||
}
|
||||
|
||||
$while_date = $date1;
|
||||
$s_temp_amb = '';
|
||||
$s_temp_col = '';
|
||||
$temp_ambmin = 100;
|
||||
$temp_ambmax = 0;
|
||||
$temp_ambtot = 0;
|
||||
$temp_colmin = 100;
|
||||
$temp_colmax = 0;
|
||||
$temp_coltot = 0;
|
||||
|
||||
for($i = 0; $i < count($tab_amb); $i++)
|
||||
{
|
||||
// recherche mini et Maxi calcul total
|
||||
$temp_amb = $tab_amb[$while_date];
|
||||
$temp_col = $tab_col[$while_date];
|
||||
if ($temp_amb<$temp_ambmin) $temp_ambmin = $temp_amb;
|
||||
if ($temp_amb>$temp_ambmax) $temp_ambmax = $temp_amb;
|
||||
if ($temp_col<$temp_colmin) $temp_colmin = $temp_col;
|
||||
if ($temp_col>$temp_colmax) $temp_colmax = $temp_col;
|
||||
$temp_ambtot = $temp_ambtot + $temp_amb;
|
||||
$temp_coltot = $temp_coltot + $temp_col;
|
||||
|
||||
$s_temp_amb = $s_temp_amb.$temp_amb.',';
|
||||
$s_temp_col = $s_temp_col.$temp_col.',';
|
||||
$while_date = date("Y-m-d", strtotime("+1 day", strtotime($while_date)));
|
||||
}
|
||||
$while_date = $date1;
|
||||
|
||||
for ($i = 0; $i < count($tab_amb); $i++) {
|
||||
// recherche mini et Maxi calcul total
|
||||
$temp_amb = $tab_amb[$while_date];
|
||||
$temp_col = $tab_col[$while_date];
|
||||
if ($temp_amb < $temp_ambmin) $temp_ambmin = $temp_amb;
|
||||
if ($temp_amb > $temp_ambmax) $temp_ambmax = $temp_amb;
|
||||
if ($temp_col < $temp_colmin) $temp_colmin = $temp_col;
|
||||
if ($temp_col > $temp_colmax) $temp_colmax = $temp_col;
|
||||
$temp_ambtot = $temp_ambtot + $temp_amb;
|
||||
$temp_coltot = $temp_coltot + $temp_col;
|
||||
|
||||
$s_temp_amb = $s_temp_amb . $temp_amb . ',';
|
||||
$s_temp_col = $s_temp_col . $temp_col . ',';
|
||||
$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_amb = $temp_ambtot/($Nbjours); // moyenne par jour
|
||||
$vmoy_col = $temp_coltot/($Nbjours); // moyenne par jour
|
||||
?>
|
||||
$vmoy_amb = $temp_ambtot / ($Nbjours); // moyenne par jour
|
||||
$vmoy_col = $temp_coltot / ($Nbjours); // moyenne par jour
|
||||
?>
|
||||
|
||||
<form method="get">Du <input name="du" type="text" value="<?php echo $date1;?>" 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 $date1; ?>" 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: {
|
||||
zoomType: 'x'
|
||||
},
|
||||
title: {
|
||||
text: 'Températures du château d\'eau 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: 'Température ambiante";
|
||||
if($temp_ambtot == 0) $temp_ambmin = 0;
|
||||
echo " --- T total = <b>".$temp_ambtot."</b> m³ -- Tmoy/jour = <b>".round($vmoy_amb, 2)."</b> m³ -- Tmin = <b>".$temp_ambmin."</b> m³ -- TMax = <b>".$temp_ambmax."</b> m³<br/>Température de la colonne";
|
||||
if($temp_coltot == 0) $temp_colmin = 0;
|
||||
echo " --- T total = <b>".$temp_coltot."</b> m³ -- Tmoy/jour = <b>".round($vmoy_col, 2)."</b> m³ -- Tmin = <b>".$temp_colmin."</b> m³ -- TMax = <b>".$temp_colmax."</b> m³'";
|
||||
?>
|
||||
},
|
||||
xAxis: {
|
||||
labels: {
|
||||
rotation: -60
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$('#container').highcharts({
|
||||
chart: {
|
||||
zoomType: 'x'
|
||||
},
|
||||
categories: [<?php echo $s_date;?>]
|
||||
},
|
||||
yAxis: {
|
||||
title: {
|
||||
text: 'Temperature (°C)'
|
||||
},
|
||||
plotLines: [{
|
||||
value: 0,
|
||||
width: 1,
|
||||
color: '#808080'
|
||||
}]
|
||||
},
|
||||
tooltip: {
|
||||
valueSuffix: '°C'
|
||||
},
|
||||
legend: {
|
||||
layout: 'vertical',
|
||||
align: 'center',
|
||||
verticalAlign: 'bottom',
|
||||
borderWidth: 0
|
||||
},
|
||||
series: [{
|
||||
name: 'Temp. ambiante',
|
||||
data: [<?php echo $s_temp_amb;?>]
|
||||
}, {
|
||||
name: 'Temp. de la colonne',
|
||||
data: [<?php echo $s_temp_col;?>]
|
||||
}]
|
||||
});
|
||||
});
|
||||
</script>
|
||||
title: {
|
||||
text: 'Températures du château d\'eau 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: 'Température ambiante";
|
||||
if ($temp_ambtot == 0) $temp_ambmin = 0;
|
||||
echo " --- T total = <b>" . $temp_ambtot . "</b> m³ -- Tmoy/jour = <b>" . round($vmoy_amb, 2) . "</b> m³ -- Tmin = <b>" . $temp_ambmin . "</b> m³ -- TMax = <b>" . $temp_ambmax . "</b> m³<br/>Température de la colonne";
|
||||
if ($temp_coltot == 0) $temp_colmin = 0;
|
||||
echo " --- T total = <b>" . $temp_coltot . "</b> m³ -- Tmoy/jour = <b>" . round($vmoy_col, 2) . "</b> m³ -- Tmin = <b>" . $temp_colmin . "</b> m³ -- TMax = <b>" . $temp_colmax . "</b> m³'";
|
||||
?>
|
||||
},
|
||||
xAxis: {
|
||||
labels: {
|
||||
rotation: -60
|
||||
},
|
||||
categories: [<?php echo $s_date; ?>]
|
||||
},
|
||||
yAxis: {
|
||||
title: {
|
||||
text: 'Temperature (°C)'
|
||||
},
|
||||
plotLines: [{
|
||||
value: 0,
|
||||
width: 1,
|
||||
color: '#808080'
|
||||
}]
|
||||
},
|
||||
tooltip: {
|
||||
valueSuffix: '°C'
|
||||
},
|
||||
legend: {
|
||||
layout: 'vertical',
|
||||
align: 'center',
|
||||
verticalAlign: 'bottom',
|
||||
borderWidth: 0
|
||||
},
|
||||
series: [{
|
||||
name: 'Temp. ambiante',
|
||||
data: [<?php echo $s_temp_amb; ?>]
|
||||
}, {
|
||||
name: 'Temp. de la colonne',
|
||||
data: [<?php echo $s_temp_col; ?>]
|
||||
}]
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
|
||||
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
|
||||
<?php
|
||||
}
|
||||
else echo 'Vous n\'êtes pas autorisé/connecté!';
|
||||
} else echo 'Vous n\'êtes pas autorisé/connecté!';
|
||||
include('foot.php'); ?>
|
Reference in New Issue
Block a user