<?php
$response = $this->response;
?>
<h1>Výpis úkolů</h1>
<h2>Zadat úkol</h2>
<form action="/plan/post/" method="post" onsubmit="this.action += this['task[for_user_id]'].value + '.html'">
	<p>
		Identifikační číslo projektu: <?php echo $this->formText("task[project_id]"); ?>
	</p>
	<p>
		Identifikační číslo cílového uživatele: <?php echo $this->formText("task[for_user_id]"); ?>
	</p>
	<p>
		Zadání úkolu: <br />
		<textarea rows="5" cols="100" name="task[task_content]"></textarea>
	</p>
	<p>
		Výchozí stav úkolu: <select name='task[current_status]'>
			<option value="NOTSTARTED">Nezapočat</option>
			<option value="INPROGRESS">Započat</option>
			<option value="PUTOFF">Odložen</option>
			<option value="DELAY">Zpožděn</option>
			<option value="NEVER">Vypovězen</option>
			<option value="Done">Dokončen</option>
		</select>
	</p>
	<p>
		Komentář k výchozímu stavu: <br />
		<textarea rows="5" cols="100" name="task[current_comment]"></textarea>
	</p>
	<p>
		<?php echo $this->formSubmit("submit", "Vytvořit")?>
	</p>
</form>
<h2>Úkoly které jsem zadal</h2>
<table>
	<thead>
		<tr>
			<th>
			#
			</th>
			<th>
			Zadání
			</th>
			<th>
			Cílový uživatel
			</th>
			<th>
			Projekt
			</th>
			<th>
			Stav
			</th>
			<th>
			Komentář ke stavu
			</th>
			<th>
			Vytvořeno
			</th>
			<th>
			Změněno
			</th>
			<th>
			Deadline
			</th>
			<th>
			Akce
			</th>
		</tr>
	</thead>
	<tbody>
	<?php 
	//priprava cache
	$users = array();
	$projects = array();
	
	//vypis dat
	foreach ($response["sent"] as $task) {
		//kontrola cache
		if (!isset($users[$task->for_user_id])) {
			$users[$task->for_user_id] = $task->findParentRow("Application_Model_Users", "target");
		}
		
		if (!isset($projects[$task->project_id])) {
			$projects[$task->project_id] = $task->findParentRow("Application_Model_Projects", "project");
		}
		?>
		<tr>
			<td>
			<a href="/plan/get/<?php echo $task->id; ?>.html"><?php echo $task->id; ?></a>
			</td>
			<td>
			<?php echo $task->task_content; ?>
			</td>
			<td>
			<?php echo $users[$task->for_user_id]->username; ?>
			</td>
			<td>
			<?php echo $projects[$task->project_id]->project_name; ?>
			</td>
			<td>
			<?php echo $task->current_status; ?>
			</td>
			<td>
			<?php echo $task->current_comment; ?>
			</td>
			<td>
			<?php echo $task->created_at; ?>
			</td>
			<td>
			<?php echo $task->modified_at; ?>
			</td>
			<td>
			<?php echo $task->deadline_at; ?>
			</td>
			<td>
			<a href="/plan/delete/<?php echo $task->id; ?>.html">smazat</a>
			</td>
		</tr>
		<?php 
	}
	?>
	</tbody>
</table>
<h2>Úkoly které mi byly zadány</h2>
<table>
	<thead>
		<tr>
			<th>
			#
			</th>
			<th>
			Zadání
			</th>
			<th>
			Cílový uživatel
			</th>
			<th>
			Projekt
			</th>
			<th>
			Stav
			</th>
			<th>
			Komentář ke stavu
			</th>
			<th>
			Vytvořeno
			</th>
			<th>
			Změněno
			</th>
			<th>
			Deadline
			</th>
		</tr>
	</thead>
	<tbody>
	<?php 
	//vypis dat
	foreach ($response["recieved"] as $task) {
		//kontrola cache
		if (!isset($users[$task->user_id])) {
			$users[$task->for_user_id] = $task->findParentRow("Application_Model_Users", "target");
		}
		
		if (!isset($projects[$task->project_id])) {
			$projects[$task->project_id] = $task->findParentRow("Application_Model_Projects", "project");
		}
		?>
		<tr>
			<td>
			<a href="/plan/get/<?php echo $task->id; ?>.html"><?php echo $task->id; ?></a>
			</td>
			<td>
			<?php echo $task->task_content; ?>
			</td>
			<td>
			<?php echo $users[$task->user_id]->username; ?>
			</td>
			<td>
			<?php echo $projects[$task->project_id]->project_name; ?>
			</td>
			<td>
			<?php echo $task->current_status; ?>
			</td>
			<td>
			<?php echo $task->current_comment; ?>
			</td>
			<td>
			<?php echo $task->created_at; ?>
			</td>
			<td>
			<?php echo $task->modified_at; ?>
			</td>
			<td>
			<?php echo $task->deadline_at; ?>
			</td>
		</tr>
		<?php 
	}
	?>
	</tbody>
</table>