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

$do_close=0;
if ($_GET['tid']) 	$tid= $_GET['tid'];  else 	$tid = $_POST['tid'];
if ($_GET['tnid']) 	$tnid= $_GET['tnid']; else	$tnid = $_POST['tnid'];	
if ($_GET['mode'])	$mode= $_GET['mode']; else	$mode = $_POST['mode'];	

if (count($_POST) > 0)
{
	$note = secure_user_input($_POST['thenote']);
	$notetitle = secure_user_input($_POST['notetitle']);

	if ($_POST['tnid']) //update
	{
		$SQL="UPDATE tutornotes 
			SET 
			thenote = '".$note."',
			notetitle = '".$notetitle."'
			WHERE id=".$_POST['tnid'];
			
		//echo $SQL;
		$do_close=1;
	
	}
	else //insert new record
	{
		$SQL="INSERT INTO tutornotes ( tutor_id, thenote, notetitle)
		VALUES ('".$tid."' , '".$note."', '".$notetitle."')";

		//echo $SQL;
		$do_close=1;
	}
	$results = llnb_query($SQL);
	
}
else 
{

	if ($mode == "edit")
	{
		$SQL="SELECT *, DATE(timestamp) AS thedate
			FROM tutornotes WHERE id=".$_GET['tnid'];
		$results = llnb_query($SQL);
		$row = llnb_fetch_assoc($results);
	
	}

	
	
}
?><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; }

input.ssminp[type="text"] {width: 40px;}
input.sminp[type="text"] {width: 80px;}
input.btn { height: 30px;}


</style>

<body onLoad="document.forms.addnote.title.focus()">
<? 
if ($do_close) 
	echo "<script>parent.location.href='tutor_notes_list.php?tid=".$tid."';</script>"; 

?>
<div style="width: 525px;">
<h2>Add a Note For: <br>
  Tutor    : <?= fetchTutorName($tid); ?></H2>

<form name="addnote" action="tutor_note_add_m.php" method="post">

      <div class="input">
        <label>Title of Note:</label>
        <input name="notetitle" type="text"   value="<?=$row['notetitle'];?>" class="lrginp">
      </div>
      <div style="clear:both;"></div>
	
      <div class="input">
      	<label>Note on Tutor:</label>
        <textarea name="thenote" cols="" rows="10" class="talrg" ><?=$row['thenote'];?></textarea>
        </div>
        <div style="clear:both;"></div>
        
       
<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>

<input type="hidden" value="<?=$tnid;?>" name="tnid">
<input type="hidden" value="<?=$tid;?>" name="tid">
<input type="hidden" value="<?=$mode;?>" name="mode">
</form>
</div>
</body>