<?php
if ((isset($_GET['m']) && !empty($_GET['m'])) && (isset($_GET['y']) && !empty($_GET['y'])) && (isset($_GET['d']) && !empty($_GET['d'])) && (is_numeric($_GET['m']) && is_numeric($_GET['y']) && is_numeric($_GET['d'])))
{
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'];
db_open();
if ($language==1)
	{
	$head1="Επιλέξτε Σενάριο:";
	$head2="Σενάρια";
	$head3="Ώρα έναρξης:";
	$head4="Ω";
	$head5="Λ";
	$title1="Επιλέξτε Ώρα";
	$title2="Επιλέξτε Λεπτά";
	$head6="Ώρα τέλους:";
	$head7="Συχνότητα:";
	$head8="Κάθε:";
	$today="σήμερα";
	$day="μέρα";
	$day1="2η μέρα";
	$day2="3η μέρα";
	$week="εβδομάδα";
	$week2="15 μέρες";
	$month="μήνα";
	$year="έτος";
	$for="Για";
	$save="Προσθήκη";
	$clear="Ακύρωση";
	$back="Πίσω";
	}
else
	{
	$head1="Select Scenario:";
	$head2="Scenarios";
	$head3="Start Time:";
	$head4="H";
	$head5="M";
	$title1="Select Hour";
	$title2="Select Minute";
	$head6="End Time:";
	$head7="Frequency:";
	$head8="Every:";
	$today="today";
	$day="day";
	$day1="2nd day";
	$day2="3rd day";
	$week="week";
	$week2="15 days";
	$month="month";
	$year="year";
	$for="For";
	$save="Save";
	$clear="Clear";
	$back="Back";
	}
$m= strip_tags(htmlspecialchars(mysql_real_escape_string(trim($_GET["m"]))));
$y= strip_tags(htmlspecialchars(mysql_real_escape_string(trim($_GET["y"]))));
$d= strip_tags(htmlspecialchars(mysql_real_escape_string(trim($_GET["d"]))));
date_default_timezone_set("Europe/Athens");
echo<<<a
<table id="p_i" class="margin6">
<tr>
<td class="p_i_title">
$head1
</td>
<td class="p_i_data6">
<select id="scenario_select">
<option value="">$head2</option>
a;

$sql1 = "SELECT * FROM scenarios WHERE device_id='$device_id'";
@ $result = mysql_query($sql1);
while($row = mysql_fetch_array($result))
	{
	$scenario_name=$row['scenario_name'];
	echo '<option value="'.$scenario_name.'">'.$scenario_name.'</option>';
	}

echo<<<a
</select>
</td></tr>
<tr>
<td class="p_i_title">
$head3
</td>
<td>
<select id="t1" title="$title1">
<option value="">$head4</option>
a;
for ($i=0; $i<=23; $i++)
	{
		if ($i<10)
		{
		$i="0".$i;
		}
	echo '<option value="'.$i.'">'.$i.'</option>';
	}
echo<<<a
</select>
:
<select id="t2" title="$title2">
<option value="">$head5</option>
<option value="90">00</option>
a;

for ($i=5; $i<=59; $i=$i+5)
	{
	if ($i<10)
		{
		$i="0".$i;
		}
	echo '<option value="'.$i.'">'.$i.'</option>';
	}
echo<<<a
</select>
<a id="m1" class="o_msg"></a>
</td> 
</tr>
<tr>
<td class="p_i_title">
$head6
</td>
<td>
<select id="t3" title="$title1">
<option value="">$head4</option>
a;
for ($i=0; $i<=23; $i++)
	{
	if ($i<10)
		{
		$i="0".$i;
		}
	echo '<option value="'.$i.'">'.$i.'</option>';
	}
echo<<<a
</select>
:
<select id="t4">
<option value="" title="$title2">$head5</option>
<option value="90">00</option>
a;
for ($i=5; $i<=59; $i=$i+5)
	{
	if ($i<10)
		{
		$i="0".$i;
		}
	echo '<option value="'.$i.'">'.$i.'</option>';
	}
echo<<<a
</select>
<a id="m2" class="o_msg"></a>
</td> 
</tr>
<tr>
<td class="p_i_title">
$head7
</td>
<td>
<select id="frequency" class="select_scenario_menu" onclick="time_validator(3,3,0,0);" >
<option value="">$head8</option>
<option value="6">$today</option>
<option value="1">$day</option>
<option value="2">$day1</option>
<option value="3">$day2</option>
<option value="4">$week</option>
<option value="5">$week2</option>
</select>
<select id="frequency_stop" class="select_scenario_menu">
<option value="" id="cc">$for</option>
<option value="1">$week</option>
<option value="2">$week2</option>
<option value="3">$month</option>
<option value="4">$year</option>
</select>
</td>
</tr>
</table>
<input type="button" class="save_scenario" value="$save" onclick="time_validator(3,1,0,$y,$m,$d);" />
<input type="button" class="clear_scenario" value="$clear" onclick="time_validator(3,2,0,0,0,0);" />
<input type="button" class="back_scenario" value="$back" onclick="time_validator(3,2,2,$y,$m,$d);" />
a;
}
db_close();

?>