<?
include('auth.php');
include('common.php');

$do_close=0;

if (count($_POST) > 0)
{
	$notes = secure_user_input($_POST['notes']);
	$d = $_POST['year']."-".$_POST['month']."-".$_POST['day'];
	$t = $_POST['hours'].":".$_POST['minutes'].":00";
	
	$SQL="INSERT INTO learnersession (tutor_id, learner_id, stype, notes, thedate, duration )
	VALUES ('".$_POST['tid']."','".$_POST['lid']."','".$_POST['stype']."' ,'".$notes."', '".$d."', '".$t."')";
	
	//echo $SQL;
	$results = llnb_query($SQL);
	
	$do_close=1;
}
else
{
	//council- fetch council code associated with learner
	$SQL="SELECT firstname, lastname, council_id FROM tutor WHERE id=".$_GET['tid'];
	$results = llnb_query($SQL);
	$rowtutor = llnb_fetch_assoc($results);
	$c=$rowtutor['council_id'];

	$SQL="SELECT * FROM learner WHERE id IN 
		(SELECT learner_id FROM tutor_learner WHERE tutor_id = ".$_GET['tid']." AND alive=1)"; 
	$results = llnb_query($SQL);

	$options.="<select name=\"lid\" title=\"learners\">";
	
	$i=0;
	while($row = llnb_fetch_assoc($results))
	{
		$options.="<option value=\"".$row['id']."\">".$row['firstname']." ".$row['lastname']."</option>\n";
		$i++;
	}
	$options.="</select>";
	
	if ($i==0)
		$options ="No learners associated to this tutor.";

}
?>




<head>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/llnb-style.css">
</head>

<style type="text/css">

body { background-color: #fff; background-image:none; padding: 20px;}
div { font-family: sans-serif; color: #222; }

.btn	{ -moz-border-radius: 7px; -webkit-border-radius: 7px; -khtml-border-radius: 7px; border-radius: 7px; border: 1px #222 solid; background-image: url(img/btn-bg-nor.jpg) ; line-height: 25px; padding: 3px 10px 0; text-decoration: none; color: #222; }
.btn:hover	{ border-color: #33C; color: #33c;}

.btnhidden {border-color: #CCC; background-image: none; font-size: .8em;}

.btncnt	{ width: 160px; text-align:center; display: block; margin-bottom: 10px;}

.btnlrg	{width: 300px; padding-left: 20px;}
.btnsml	{ padding: 1px 10px; font-weight: bold;}
.btnpg	{ padding: 2px 4px 1px; font-size: .75em;margin-right: 4px;}

.lfr	{ float: right; margin-right: 10px;}
.lfl	{ float: left; margin-right: 10px;}
form label { display:block; margin-top: 10px; font-size: .8em; color: #555; }
.session { margin-bottom: 15px; padding-bottom: 10px;}
.talrg	{ width: 460px; height: 60px;}

</style>




<div style="width: 500px;">

<? 
if ($do_close) 
	echo "<script>parent.location.href='tutor_list.php';</script>"; 

?>

<h2>Add Session Time for:<br>
  Tutor     <? echo $rowtutor['firstname']." ".$rowtutor['lastname']; ?></h2>

<form name="addtime" action="tutor_time_m.php" method="post">

<div class="input" style="float:left;display:block;">
<label style="display:block;">Select Learner:</label>
<?= $options;?>
</div>
<div style="clear:both;"></div>

<div style="float:left; display:block;  margin-bottom: 10px;">



<label style="display:block;">Date:</label>
<select name="month" title="month">
       	<?
       	$mymon = ($_POST['month']) ? stripslashes($_POST['month']) : $month;
       	echo buildMonthDropdown($mymon, $_MONTHS_abbr); 
       	?>
</select>
<select name="day" title="date">
       	<?
       	$myday = ($_POST['day']) ? stripslashes($_POST['day']) : $day;
       	echo buildDayDropdown($myday); 
       	?>
</select>

<select name="year" title="Year">
       	<?
       	$myyear = ($_POST['year']) ? stripslashes($_POST['year']) : $year;
       	echo buildYearDropdown($myyear, "2012"); 
       	?>
</select>
</div>
<div class=" input plusleft">
<label style="display:block;">Session Type:</label>

<select name="stype" title="amount">
  <option value="1">Tutoring</option>
  <option value="2">Prep</option>
</select>
</div>
<div class=" input plusleft">
<label>Amount:</label>
<select name="hours" title="amounthr">
 <?= buildHourDropdown() ;?>
</select>

<select name="minutes" title="amountmin">
<?= buildMinDropdown() ;?>
</select>
</div>

<input type="hidden" name="tid" value="<?=$_GET['tid'];?>">


<div style="clear:both;"></div>
<label>Session notes:</label>
<textarea name="notes" cols="" rows="3"  class="talrg"></textarea>

<p class="clearfix">
<input type="submit"  class="btnlfr_m" value="Save &amp; Close">
<a href="#" onclick="parent.SqueezeBox.close();"class="btn lfr">Cancel</a>
</p>
</form>
</div>