<?php
if ((isset($_GET["q"]) && !empty($_GET["q"])) && (isset($_GET["r"]) && !empty($_GET["r"])))
{

if (file_exists("embedded/functions/site_functions.php"))
	{
	include_once("embedded/functions/site_functions.php");
	}
else
	{
include_once("../../embedded/functions/site_functions.php");
	}
db_open();	
$language=$_SESSION['language'];
if ($language==1)
	{
	$problem="Πρόβλημα!";
	$from="Από:";
	$to="Έως:";
	$wet="Υγρό";
	$dry="Ξηρό";
	$temp="θερμ";
	$hum="υγρ";
	$inli="φωτ";
	$head1="Έδαφος:";
	$select="Επιλογή";
	}
else
	{
	$problem="Problem!";
	$from="From:";
	$to="To:";
	$wet="Wet";
	$dry="Dry";
	$temp="temp";
	$hum="hum";
	$inli="inli";
	$head1="Soil Moisture Status:";
	$select="Select";
	}
	$msg="";
	$q= strip_tags(htmlspecialchars(mysql_real_escape_string(trim($_GET["q"]))));
	$r= strip_tags(htmlspecialchars(mysql_real_escape_string(trim($_GET["r"]))));
	
	if (!is_numeric($r) || ($r!="1" && $r!="2" && $r!="3" && $r!="4" && $r!="5"))
		{
		$msg='<span class="invalid">'.$problem.'</span>';
		}
	else
		{
	
			if (preg_match("/[^_A-Za-z0-9\' ']/", $q))
				{
				$msg='<span class="invalid">'.$problem.'</span>';
				}
			else
				{
				if ($q=="temperature")
					{
					$msg='<b>'.$from.'</b><input type="text" id="temp1" name="temp1" class="number" placeholder="'.$temp.'1" onkeyup="temp1_validator(this.value,'.$r.',1,1);"/>C 
					<b>'.$to.'</b></b><input type="text" id="temp2" name="temp2" class="number" placeholder="'.$temp.'2" onkeyup="temp1_validator(this.value,'.$r.',1,2);">C
					<a id="msg_'.$r.'" class="o_msg"> </a>';
					}
				else if ($q=="humidity")
					{
					$msg='<b>'.$from.'</b><input type="text" id="hum1" name="hum1" class="number" placeholder="'.$hum.'1" onkeyup="hum1_validator(this.value,'.$r.',1,1);"/>% 
					<b>'.$to.'</b></b><input type="text" id="hum2" name="hum2" class="number" placeholder="'.$hum.'2" onkeyup="hum1_validator(this.value,'.$r.',1,2);"/>%
					<a id="msg_'.$r.'" class="o_msg"> </a>';
					}
				else if ($q=="soil_moisture")
					{
					$msg='<b>'.$head1.'</b>
					<select id="soil_moisture" name="soil_moisture" onchange="sm_validator(this.value,'.$r.',1);">
					<option value="">'.$select.'</option>
					<option value="yes">'.$wet.'</option>
					<option value="no">'.$dry.'</option>
					</select>
					<a id="msg_'.$r.'" class="o_msg"> </a>';
					}
					
				else if ($q=="indoor_lighting")
					{
					$msg='<b>'.$from.'</b><input type="text" id="inli1" name="'.$inli.'1" class="number" placeholder="inli1" onkeyup="inli1_validator(this.value,'.$r.',1,1);"/> 
					<b>'.$to.'</b></b><input type="text" id="inli2" name="'.$inli.'2" class="number" placeholder="inli2" onkeyup="inli1_validator(this.value,'.$r.',1,2);"/>
					<a id="msg_'.$r.'" class="o_msg"> </a>';
					}
				else if ($q=="no_sensor")
					{
					$msg="";
					}	
				}
		}
db_close();		
echo $msg;	
}
?>