<?php
# ************** LICENCE ****************  
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# 
#			Tasks Widget
# 
# ***************************************

$id = parser($variables, 'taskid=');
$page = isset($_GET["taskpage".$id])        ?       ($_GET["taskpage".$id])         :        0;
$pageStart=$page*5;

if (isset($_GET["updtask".$id])) {
	$updatedTask = $_GET["updtask".$id];
	$DB->getResults($widTask_getOneTask, $DB->escape($updatedTask),$DB->escape($_SESSION["user_id"]));
	$row = $DB->fetch(0);
	echo '<a name="tasks'.$id.'"></a>
		<div id="widget_options">
		<form method="post" action="../widgets/scr_widget_295.inc.php?act=upd&tab='.$selectedTab.'">
			<input type="hidden" name="id" value="'.$updatedTask.'"/>
			<input type="hidden" name="uniq" value="'.$uniq.'"/>
			<input type="hidden" name="mod_id" value="'.$mod_id.'"/>
			<table cellpadding="0">
				<tr>
				<td>'.lg("title").' </td>
				<td><input type="text" name="titre" value="'.$row['name'].'" /></td>
				</tr>
				<tr>
				<td>'.lg("comments").' </td>
				<td><input type="text" name="comment" value="'.$row['comments'].'" /></td>
				</tr>
				<tr>
				<td></td>
				<td><input type="submit" value="'.lg("apply").'"/></td>
			</table>
		</form>
		</div>';
}
else {
	$DB->getResults($widTask_getTasks,$DB->escape($id),$DB->escape($_SESSION['user_id']),$DB->escape($pageStart));
	$nbTask=$DB->nbResults();
	$inc=0;

	echo '<a name="tasks'.$id.'"></a>
		<div class="widget">';

	while (($row = $DB->fetch(0)) && $inc<5) {
		$taskid=$row['task_id'];
		$done=$row['done'];

		echo '
			'.($done == 'Y'?'<del>':'').'
			<a href="../widgets/scr_widget_295.inc.php?act=status&mod_id='.$mod_id.'&tab='.$selectedTab.'&task_id='.$taskid.'&status='.($done == 'Y'?'N':'Y').'">
			'.$row['name'].'</a>'.($done == 'Y'?'</del>':'').'
			<a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&updtask'.$id.'='.$taskid.'#tasks'.$id.'"><img src="../../../../images/ico_edit.gif"></a>
			<a href="../widgets/del_widget_295.inc.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&act=del&id='.$taskid.'"><img src="../../../../images/ico_close.gif"></a>
			<br />';
		$inc++;
	}
	echo '</div>';
    
	echo '<div class="widget_options">
		'.lg("add_task").' :
		<form method="post" action="../widgets/scr_widget_295.inc.php?act=add&tab='.$selectedTab.'">
			<input type="hidden" name="id" value="'.$id.'">
			<input type="hidden" name="uniq" value="'.$uniq.'"/>
			<input type="hidden" name="mod_id" value="'.$mod_id.'"/>
			<table cellpadding="0">
				<tr>
				<td>'.lg("title").' </td>
				<td><input type="text" name="titre" size="20" /></td>
				</tr>
				<tr>
				<td>'.lg("comments").' </td>
				<td><input type="text" name="comment" size="20" /></td>
				</tr>
				<tr>
				<td></td>
				<td><input type="submit" value="'.lg("apply").'" /></td>
				</tr>
			</table>
		</form>
		</div>';

	if ($page!=0) {
		echo ' <a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&taskpage'.$id.'='.($page-1).'#tasks'.$id.'"><img src="../../../../images/ico_next2.gif" /> '.lg('previous').'</a>';
	}
	if($nbTask==6) {
		echo ' <a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&taskpage'.$id.'='.($page+1).'#tasks'.$id.'">'.lg('next').' <img src="../../../../images/ico_next2.gif" /></a>';
	}
}
?>