Location: PHPKode > projects > O - OpenSource GroupWare > osgw/tasklist/index.php
<?php
/**************************************************************************
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   @Author:	Ryan Thompson(hide@address.com)
***************************************************************************/
/*$Id: index.php,v 1.30 2003/12/10 20:42:29 rthomp Exp $*/

//Just getting things started
include("./data.php");
$service['add_header'] = TRUE;
include("../config.inc.php");

//Tasklist specific functions for managing tasks, etc.
include($here. "/class.tasklist.php");
$tasks = new tasklist;

//Generic header and service header
echo $layout->page_header;
echo $layout->service_header($text['service_name'], $tasks->nav_buttons());

//Filtering selection box
echo $html->create_filter($user->user_id, 'tl', 'index', $_GET['category']);


if(isset($_POST['confirm_delete']))
{
	//If confirmed delete all selected tasks
	//They were serialized to pass to the script on POST
	$O->delete_items('tl', 'o_tasklist', 'task_id', $_POST['delete_values'], $user->user_id);	
}

if(isset($_POST['delete_tasks']))
{
	//If user chose to delete some tasks we want to make sure he wants to delete them	
	echo $html->delete_confirm($_SERVER['PHP_SELF'], 'tl', $_POST['delete']);
	
} else {
	//If none of the above we search database for tasks
	unset($sort_order);
	
	if(isset($_GET['sort']))
	{
		//Sets a sort order if there is one. Otherwise we use the default sort of database. I believe most are FIFO
		$sort_order = " ORDER BY {$_GET['sort']}";	
	}
	if(isset($_GET['category']) && $_GET['category'] != '*')
	{
		//If there is a category set the we have to filter out by category.
		$sql = "SELECT o_tasklist.* FROM o_tasklist 
			LEFT JOIN o_categorize ON o_tasklist.task_id=o_categorize.id WHERE o_categorize.service='tl'
			AND o_tasklist.user_id='{$user->user_id}' AND o_categorize.category='{$_GET['category']}'$sort_order";
		$db->query($sql);
		while($db->fetch_results())
		{
			$results[] = $db->record;
		}
	} else {
		$results = $share->run_share_query('tl', $user->user_id, 'o_tasklist', 'task_id', $sort_order);

	}
	

	if(count($results) == 0)
	{
		echo $html->message_box($text['no_tasks']);
	} else {

		echo $html->create_list(
			array("STYLE"=>"list_header",
				"PHP_SELF"=> $_SERVER['PHP_SELF'],
				"COMPLETE"=>$O->create_link("{$_SERVER['PHP_SELF']}?sort=complete", $text['complete'], 'list_header'),
				"PRIORITY"=>$O->create_link("{$_SERVER['PHP_SELF']}?sort=priority", $text['priority'], 'list_header'),
				"SUBJECT"=>$O->create_link("{$_SERVER['PHP_SELF']}?sort=subject", $text['subject'], 'list_header'),
				"DUEDATE"=>$O->create_link("{$_SERVER['PHP_SELF']}?sort=task_due", $text['due_date'], 'list_header'),
				"STATUS"=>$O->create_link("{$_SERVER['PHP_SELF']}?sort=status", $text['status'], 'list_header')),
			$layout->service_theme ."/header.html");

		$db->query($sql);
		$task_ids = array();
		$i = 0;
		foreach($results AS $task_values)
		{
			unset($task_owner);
			unset($shared);
			unset($disabled);
			if($task_values['user_id'] != $user->user_id)
			{
				
				$task_owner = "({$task_values['username']})";
				$shared = '&s=TRUE';
				$disabled = " disabled=\"disabled\"";
			}
			
			if(!in_array($task_values['task_id'], $task_ids))
			{
			$status = explode(':', $text['status_list']);
			$class = $html->list_class($class);
			if($tasks->is_overdue($task_values['task_due']))
			{
				$class = 'overdue';	
			}
			if($tasks->is_complete($task_values['status']))
			{
				$class = 'complete';
			}
			
			echo $html->create_list(
				array("TASKID"=>$task_values['task_id'],
					"STYLE"=> $class,
					"COMPLETE"=>$task_values['complete'] ."%",
					"PRIORITY"=>$task_values['priority'],
					"SUBJECT"=>$O->create_link("/tasklist/view_task.php?tid={$task_values['task_id']}$shared", $task_values['subject'], $class),
					"OWNER"=>$task_owner,
					"DISABLED"=>$disabled,
					"DUEDATE"=>date($date->long_date, $task_values['task_due']),
					"STATUS"=>$status[$db->record['status']]),
				"{$layout->service_theme}/list.html");
			}
			$task_ids[] = $db->record['task_id'];
			$i++;
		}
		
		echo $html->create_list(
			array("DELETE"=>$text['delete']),
			"{$layout->service_theme}/footer.html");
	}
}
echo $layout->create_footer();
?>
Return current item: O - OpenSource GroupWare