<DOCTYPE html>

<head>
<meta http-equiv = "content-type" charset = utf-8" > 

<meta name = "description" content = "task_add" >

<meta name = "keywords" content = "task_add">

<title>php1</title>

<link rel="stylesheet" type="text/css" href="style.css">
</head>
<?php
session_start();
$a=0;
include_once('tables_in.php');
$main=new tables_in();
$a=$main->create_table($_SESSION['id']);
$b=$main->check_values($_POST);
$a[0]['date_time_start']=substr($a[0]['date_time_start'],0,-3);
$a[0]['date_time_end']=substr($a[0]['date_time_end'],0,-3);
$_POST['id']=1;
if($b==0 || $b==4)
  if(isset($_POST))
  	$main->save_edits($_POST,$_SESSION['id']);
 
?>
<html style="height:100%;">

<body style="background-color: #AAAAAA; min-height:100%;">
<div style="background-color:#FFFFFF; margin-left:10%; margin-right:10%; padding:3%; height:100%;">                                                       
<a href="calender.php"> Вернуться к списку </a>
<form action = "<?php $_PHP_SELF ?>" method="post">
<table style="border: solid-black 1px;">
<th>Редактировать задачу</th>
<tr>
<td><label for="theme"> Тема: </label></td>
<td><input type="text" name ="theme" id="theme" value="<?php if (isset($_POST['theme']) and $_POST['theme']!='') echo $_POST['theme']; else echo $a[0]['theme']; ?>"></td>
</tr>
<tr>
<td><label for="type"> Тип:</label></td>
<td><input type="text" name ="type" id="type" value="<?php if (isset($_POST['type']) and $_POST['type']!='') echo $_POST['type']; else echo $a[0]['type']; ?>"></td>
</tr>
<tr>
<td><label for="place"> Место:</label></td>
<td><input type="text" name ="place" id="place" value="<?php if (isset($_POST['place']) and $_POST['place']!='') echo $_POST['place']; else echo $a[0]['place']; ?>"></td>
</tr>
<tr>
<td><label for="date_start"> Дата начала:</label></td>
<td><input type="date" name ="date_start" id="date_start" value="<?php if (isset($_POST['date_start']) and $_POST['date_start']!='') echo $_POST['date_start']; else echo substr($a[0]['date_time_start'],0,10); ?>"></td>
</tr>
<tr>
<td><label for="time_start"> Время начала:</label></td>
<td><input type="time" name ="time_start" id="time_start" value="<?php if (isset($_POST['time_start']) and $_POST['time_start']!='') echo $_POST['time_start']; else echo substr($a[0]['date_time_start'],11,8); ?>"></td>
</tr>
<tr>
<td><label for="date_end"> Дата начала:</label></td>
<td><input type="date" name ="date_end" id="date_end" value="<?php if (isset($_POST['date_end']) and $_POST['date_end']!='') echo $_POST['date_end']; else echo substr($a[0]['date_time_end'],0,10); ?>"></td>
</tr>
<tr>
<td><label for="time_end"> Время начала:</label></td>
<td><input type="time" name ="time_end" id="time_end" value="<?php if (isset($_POST['time_end']) and $_POST['time_end']!='') echo $_POST['time_end']; else echo substr($a[0]['date_time_end'],11,8); ?>"></td>
</tr>
<tr>
<td>Направление</td><td><select name="status" value="<?php if (isset($_POST['status']) and $_POST['status']!='') echo $_POST['status']; else echo $a[0]['status']; ?>">
<option value="done">done</option>
<option value="undone">undone</option>
</select>
</tr>
<tr>
<td>Удалить?</td><td><select name="delete" value="<?php if (isset($_POST['delete']) and $_POST['delete']!='') echo $_POST['delete']; else echo $a[0]['delete']; ?>">
<option value="no">ни в коем случае!</option>
<option value="yes">обязательно!</option>
</select>
</tr>
<tr>
<td><label for="comment"> Комментарий:</label></td>
<td><textarea rows="4" name ="comment" id="comment"><?php if (isset($_POST['comment']) and $_POST['comment']!='') echo $_POST['comment']; else echo $a[0]['comment']; ?></textarea></td>
</tr>
<tr>
<td text-align:center colspan="2"><input type="submit" value="применить изменения" name="send"></td>
</tr>
<?php
if($b==1)
  echo('Буффер пустой');
if($b==2)
  echo('Заполните все поля');
if($b==3)
  echo('Неверный формат даты');

?>
</tr></td>
                                                                               
</tr>
</table>
</form>
</div>
</body>

</html>