<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
<link href="../styles/style2.css" rel="stylesheet" type="text/css" />
<title>Code gauge</title>
</head>
<!-- You are free to copy and use this sample in accordance with the terms of the
Apache license (http://www.apache.org/licenses/LICENSE-2.0.html)
https://code.google.com/apis/ajax/playground/?type=visualization&hl=fr#gauge_interaction
-->
<body style="font-family: Arial;border: 0 none;">
<?php
//bts2m.free.fr/PH/sql_gauge.php
$link = mysql_connect('sql.free.fr','tpil.projet','motDePasse');
if(!$link) {echo"Impossible de se connecter au serveur".mysql_error();exit;}
//--Connexion à la table piscine1
mysql_select_db(piscine1,$link);
$requete="SELECT COUNT(*) FROM piscine "; // Requete 1 ; compter les lignes
$reponse=mysql_query($requete, $link); // Execution de la requete
$nbligne=mysql_result($reponse,0); // valable pour un resultat unique
$requete= "SELECT * FROM piscine ORDER BY id"; // Requete 2 : explorer piscine1 dans l'ordre
$reponse=mysql_query($requete, $link);
mysql_data_seek($reponse,$nbligne-1); // Placement du pointeur interne à la fin
$ligne=mysql_fetch_row($reponse); // Lecture de la derniere ligne
if(!$reponse) {echo"Echec de lecture de la base de données <br>".mysql_error();exit;}
$date =$ligne[1]; // Derniere ligne colonne 1 -> date
$Tpiscine =$ligne[2];
$Text = $ligne[3];
$pH= $ligne[4];
$pile=$ligne[5];
if ($nbligne>500) {mysql_data_seek($reponse,$nbligne-500);}// Placer pointeur 500 lignes avant la fin
else {mysql_data_seek($reponse,0);}
while($ligne=mysql_fetch_row($reponse)) // lecture d'une ligne (ou une entrée) de la base de données puis auto incrémentation
{ $dateUnix= 1000*strtotime ($ligne[1]);
$TableTpiscine.='['.$dateUnix.','.$ligne[2].'],'; // Pour tracer graphe T(date)
}
$requete= "SELECT * FROM consignes"; // Requete 3 : explorer mesures
$reponse=mysql_query($requete, $link);
$ligne=mysql_fetch_row($reponse);$Cb = $ligne[2];
$ligne=mysql_fetch_row($reponse);$Ch = $ligne[2];
$ligne=mysql_fetch_row($reponse);$pH_B = $ligne[2];
$ligne=mysql_fetch_row($reponse);$pH_H = $ligne[2];
if (isset($_POST['Cb'])&&($_POST['Cb']<$Ch)) {
$Cb = $_POST['Cb'];
$requete= "UPDATE consignes SET consigne =".$Cb." WHERE id=1;";
$reponse=mysql_query($requete, $link); }
if (isset($_POST['Ch'])&&($_POST['Ch']>$Cb)) {
$Ch = $_POST['Ch'];
$requete= "UPDATE consignes SET consigne =".$Ch." WHERE id=2;";
$reponse=mysql_query($requete, $link); }
if (isset($_POST['pH_B'])&&($_POST['pH_B']<$pH_H)) {
$pH_B = $_POST['pH_B'];
$requete= "UPDATE consignes SET consigne =".$pH_B." WHERE id=3;";
$reponse=mysql_query($requete, $link); }
if (isset($_POST['pH_H'])&&($_POST['pH_H']>$pH_B)) {
$pH_H = $_POST['pH_H'];
$requete= "UPDATE consignes SET consigne =".$pH_H." WHERE id=4;";
$reponse=mysql_query($requete, $link); }
mysql_close($link);
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-47469387-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script src="//www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['gauge']});
function FP_swapImg() {//v1.0
var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
elm.$src=elm.src; elm.src=args[n+1]; } }
}
function FP_getObjectByID(id,o) {//v1.0
var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
return null;
}
</script>
<?php echo "<p>Température relevée le ".$date; ?>
<a href="../PH/Pres_gauge.php" target="_blank">Code gauge.php</a></p>
<script type="text/javascript">
function drawVisualization() {
// Create and populate the data table.
var Tpiscine = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Piscine C',<?php echo $Tpiscine;?>]
]);
var pH = google.visualization.arrayToDataTable([
['Label', 'Value'],
['pH', <?php echo $pH;?>]
]);
var pile = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Volt', <?php echo $pile;?>]
]);
gaugeOptions1 = {
min: 15,
max:30,
greenFrom:<?php echo $Cb ?> , greenTo: <?php echo $Ch ?>,
minorTicks: 1,
};
gaugeOptions2 = {
min: 6,
max:9,
greenFrom:<?php echo $pH_B ?> , greenTo: <?php echo $pH_H ?> ,
minorTicks: 0.1,
};
gaugeOptions3 = {
min: 3.4,
max:4.2,
greenFrom: 3.7, greenTo:4.1,
yellowFrom: 3.43, yellowTo:3.7,
minorTicks: 5,
};
// Create and draw the visualization.
new google.visualization.Gauge(document.getElementById('gaugePiscine')).
draw(Tpiscine ,gaugeOptions1);
new google.visualization.Gauge(document.getElementById('gaugepH')).
draw(pH ,gaugeOptions2);
new google.visualization.Gauge(document.getElementById('gaugeVolt')).
draw(pile ,gaugeOptions3);
}
google.setOnLoadCallback(drawVisualization);
</script>
<table style="width: 100%">
<tr>
<td id="gaugePiscine" style="width: 250px; height: 250px; float: left;">
</td>
<td id="gaugepH" style="width: 250px; height: 200px; float: left;">
</td>
<td id="gaugeVolt" style="width: 250px; height: 250px; float: left;">
</td>
<td style="width: 394px; height: 250px; float: left;">
<a href="../PH/Pres_graphe.php" onclick="window.open(this.href); return false;">
Voir le graphe + code php</a> </a>
<p>Consigne haute :
<span style="font-weight: bold; color: red;"><?php echo $Ch ?>
°C </span></p>
<form action="sql_gauge.php" method="post">
<span style="color: red;">Consigne Haute </span>
<input name="Ch" style="color: red;" type="text" /><span style="color: red;">
°C</span> <input type="submit" value="Valider" /></form>
<p>Consigne basse :
<span style="font-weight: bold; color: blue;"><?php echo $Cb ?>
°C </span></p>
<form action="sql_gauge.php" method="post">
<span style="color: rgb(51, 102, 255);">Consigne Basse
</span>
<input name="Cb" style="color: rgb(51, 102, 255);" type="text" /><span style="color: rgb(51, 102, 255);">
°C</span> <input type="submit" value="Valider" /></form>
</td>
<td style="width: 394px; height: 250px; float: left;">
<a href="../PH/Pres_graphe.php" onclick="window.open(this.href); return false;">
Voir le graphe + code php</a> </a>
<p>Consigne pH haut : <span style="font-weight: bold; color: red;"><?php echo $pH_H ?></span>
</p>
<form action="sql_gauge.php" method="post">
<span style="color: red;">Consigne pH haut : </span>
<input name="pH_H" style="color: red;" type="text" /><input type="submit" value="Valider" /></form>
<p>Consigne pH basse :
<span style="font-weight: bold; color: blue;"><?php echo $pH_B ?></span></p>
<form action="sql_gauge.php" method="post"> <span style="color: rgb(51, 102, 255);">Consigne pH
basse :</span>
<input name="pH_B" style="color: rgb(51, 102, 255);" type="text" /><input type="submit" value="Valider" />
</form>
</td>
</tr>
</table>
</body>