<?php
if (file_exists("embedded/functions/site_functions.php"))
	{
	include_once("embedded/functions/site_functions.php");
	}
else
	{
include_once("../../embedded/functions/site_functions.php");
	}
$device_id=$_SESSION['device_id'];
$language=$_SESSION['language'];
if ($language==1)
	{
	$title1="Τελευταία ενημέρωση μετρήσεων";
	$title2="θερμοκρασία";
	$title3="υγρασία";
	$title4="έδαφος";
	$title5="φωτισμός";
	$head1="Θερμοκρασία:";
	$head2="Υγρασία:";
	$head3="Έδαφος:";
	$head4="Φωτισμός:";
	$head5="Αέρας:";
	$head6="Φώς:";
	$head7="Νερό:";
	$head8="Πατήστε maual για αλλαγή των συσκευών και εκκίνηση λειτουργίας!";
	$headdd="Τελευταία ενημέρωση:";
	
	}
else	
	{
	$title1="Last Measurements";
	$title2="temperature";
	$title3="humidity";
	$title4="soil moisture";
	$title5="indoor light";
	$head1="Temperature";
	$head2="Humidity:";
	$head3="Soil Moisture:";
	$head4="Indoor Light:";
	$head5="Fan:";
	$head6="Light:";
	$head7="Water";
	$head8="Press manual in order to change your devices!";
	$headdd="Latest update:";
	}
	
db_open();
$a=last_data($device_id);
db_close();
//inputs
$T= $a[0];
$H= $a[1];
$M= $a[2];
$IL= $a[3];
$time = $a[7];
//function for the control panel
$F=$a[4];
$L=$a[5];
$V=$a[6];

if ($F == '1') 
{
$classf1 = "class='button_on'";
$statusf ="<img src='css/images/on.png' alt='image_on' class='image_on' title='fan is activated'></img>";
}
else if ($F == '0')
{
$classf1= "class='button_off'";
$statusf="<img src='css/images/off.png' alt='image_on' class='image_status' title='fan is de-activated'></img>";
}

if ($L == '1') 
{
$classl1 = "class='button_on'";
$statusl ="<img src='css/images/on.png' alt='image_on' class='image_on' title='lighting is activated'></img>";
}
else if ($L == '0')
{
$classl1= "class='button_off'";
$statusl="<img src='css/images/off.png' alt='image_on' class='image_status' title='lighiting is de-activated'></img>";
}

if ($V == '1') 
{
$classw1 = "class='button_on'";
$statusw ="<img src='css/images/on.png' alt='image_on' class='image_on' title='watering is activated'></img>";
}
else if ($V == '0')
{
$classw1= "class='button_off'";
$statusw= "<img src='css/images/off.png' alt='image_on' class='image_status' title='watering is de-activated'></img>";
}

echo<<<CP
<div id="d0" class="time" title="$title1"><span class="timehead">$headdd</span> $time </div>
<div id ="d1" class="sensor" title="$title2">$head1<br/><a class="sensor_result">$T C</a></div>
<div id ="d2" class="sensor"  title="$title3">$head2<br /><a class="sensor_result">$H%</a></div>
<div id ="d3" class="sensor" title="$title4">$head3<br /><a class="sensor_result">$M</a></div>
<div id ="d4" class="sensor" title="$title5">$head4<br /><a class="sensor_result">$IL</a></div>
<table id="table_index" class="control_panel" onmouseover="popup(1);" onmouseout="popup(2);">
<tr><td><img src='css/images/button.png' alt='button' $classf1 />$statusf</td>
<td><img src='css/images/button.png' alt='button' $classl1 />$statusl</td>
<td><img src='css/images/button.png' alt='button' $classw1 />$statusw</td></tr>
<tr><th>$head5</th><th>$head6</th><th>$head7</th></tr> 
</table>
<div id="s_msg" >$head8</div>
CP;

?>