Location: PHPKode > projects > O - OpenSource GroupWare > osgw/tasklist/class.tasklist.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.

   @Authors:	Ryan Thompson(hide@address.com)
***************************************************************************/
/*$Id: class.tasklist.php,v 1.21 2003/12/11 21:24:57 rthomp Exp $*/
class tasklist 
{

	var $months;

	function nav_buttons()
	{
		GLOBAL $lang;
		$navigation = "<input type=\"submit\" name=\"tasklist\" value=\"". $lang->msgs['list_tasks'] ."\"
			class=\"button1\" onClick=\"window.location='index.php'\">";
		$navigation .= "<input type=\"submit\" name=\"add_task\" value=\"". $lang->msgs['add_task'] ."\" 
			class=\"button1\" onClick=\"window.location='create_task.php'\">";
	
	
		return $navigation;
	}
	
	
	function verify_fields($summary, $description)
	{
		GLOBAL $error;
		if(empty($summary))
		{
			$error->get_message('11000');
			return FALSE;
		}
		
		return TRUE;
		
	}
	
	function create($data)
	{
		GLOBAL $O, $db, $user, $category, $share;
		
		$due_date = mktime (0, 0, 0, $data['due_month'], $data['due_day'], $data['due_year']);
		$priority = $data['priority'];
		
		$description = $data['description'];
		$status = $data['status'];
		
		$uid = $user->user_id;
		if(!isset($data['complete']))
		{
			$complete = '0';
		} else {
			$complete = $data['complete'];
		}
		
		$sql = "INSERT INTO o_tasklist (user_id,subject,description, task_due, status, complete, priority) 
			VALUES
			('{$user->user_id}','{$data['summary']}','$description','$due_date','{$data['status']}',
			'$complete','$priority')";
	
		$db->query($sql);
		
		$insert_id = $db->insert_id;
		$category->categorize($insert_id, 'tl', $_POST['category']);
		
		$share->add_share($insert_id, 'tl', $data['share_users']);
		
	}
	
	function delete($delete_tasks)
	{
		GLOBAL $db, $category, $share, $user;
		
		foreach($delete_tasks AS $key => $value)
		{
			$sql = "SELECT user_id FROM o_tasklist WHERE task_id='$value'";
			$db->query($sql);
			$db->fetch_results();
			if($db->record['user_id'] == $user->user_id)
			{
				$sql = "DELETE FROM o_tasklist WHERE task_id='$value'";
				$db->query($sql);
				$category->delete($value, 'tl');
				$share->delete($value, 'tl');
			}
		}

	}
	
	/*!
		@function update()
		@author Ryan Thompson
		@abstract Updates task in database
		@version 0.1
		@params $task_id
		@params $data[]
		@return TRUE/FALSE
		@since 09-12-2003
	*/		
	function update($task_id, $data)
	{
		GLOBAL $O, $db, $user, $category, $share;
		
		$uid = $user->user_id;

		
		$subject = $data['summary'];
		$description = $data['description'];
		$status = $data['status'];
		
		$due_date = mktime (0, 0, 0, $data['due_month'], $data['due_day'], $data['due_year']);
		$complete = $data['complete'];
		$priority = $data['priority'];
		$sql = "UPDATE o_tasklist SET subject='$subject',description='$description',task_due='$due_date',status='$status',
			complete='$complete',priority='$priority' WHERE task_id='$task_id' AND user_id='{$user->user_id}'";
		$db->query($sql);
		$task_id = $_GET['tid'];
		
		$category->edit_category($task_id, 'tl', $data['category']);
		
		$share->update_share($data['enable_sharing'], $task_id, 'tl', $data['share_users']);
		//Add Update Category and update data sharing
		return;	
	}
	
	/*!
		@function is_overdue()
		@author Ryan Thompson
		@abstract Checks to see if task has past it's due date
		@version 0.1
		@params $due_date
		@return TRUE/FALSE
		@since 09-12-2003
	*/	
	function is_overdue($due_date)
	{
		if($due_date < time())
		{
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	/*!
		@function is_complete()
		@author Ryan Thompson
		@abstract Checks to see if task has been completed or cancelled
		@version 0.1
		@params $status
		@return TRUE/FALSE
		@since 09-12-2003
	*/	
	function is_complete($status)
	{
		if($status >= 3)
		{
			return TRUE;
		} else {
			return FALSE;
		}
	}	
	
}
Return current item: O - OpenSource GroupWare