Location: PHPKode > projects > PushOk SEMA > html/web/task/task.php
<?PHP
// Pushok's SEMA (Small Enterprise Management Application)
//
// Copyright (C) 2004 Pushok Software http://www.pushok.com
//
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html

//! add menu item to main menu
function web_TaskCreateFLvlMenu(&$oIn, &$oOut)
{
	if ( !is_array($oOut) )
		$oOut = array();
	$oOut[5][_LW('Tasks')]= "task/task_main.php";
	return true;
}

//! add second menu's items
function web_TaskCreateSLvlMenu(&$oIn, &$oOut)
{
	if ( !is_array($oOut) )
		$oOut = array();
	if ( isset($oIn['menu_flvl']) && $oIn['menu_flvl'] == "Tasks" )
	{
		$oOut[5][_LW('Search tasks')] = "task/task_main.php";
		
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>0, 'type'=>ID_SEMA_TASK, 'mask'=>'W');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
		if ( isset($_oOut['result']) && $_oOut['result'] )
			$oOut[5][_LW('Create new task')] = "task/task_form.php";
	}
	return true;
}

//! validate user's data and transmit it to kernel 
function web_TaskCreate(&$oIn, &$oOut)
{
	if ( !is_array($oIn) )
		return PEAR::raiseError("FILE: \"".__FILE__."\" LINE: \"".__LINE__."\" MSG: \""._LW("Not enough params!")."\"", E_USER_ERROR);
		
	if ( $oIn['step'] == 1 )
	{
		if ( !isset($oIn['post']['title']) || !strlen($oIn['post']['title']) )
			web_AddErrorMsg($oOut, "You must specify 'Title'!");
			
		if ( !(isset($oIn['post']['time_type']) && $oIn['post']['time_type']==2))
			if ( !isset($oIn['post']['work_time']) || !strlen($oIn['post']['work_time']) )
				web_AddErrorMsg($oOut, "You must specify 'Work time'!");
		return true;
	}
	elseif ( $oIn['step'] == 2 )
	{
		$oIn['post']['idcontact_current'] = $_SESSION['iduser'];
		
		if ( isset($oIn['post']['idtask']) && $oIn['post']['idtask']>0 )
			return $GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TASK_MODIFY", $oIn['post'], $oOut);
		else
			return $GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TASK_CREATE", $oIn['post'], $oOut);
	}
	return PEAR::raiseError("FILE: \"".__FILE__."\" LINE: \"".__LINE__."\" MSG: \""._LW("Bad params!")."\"", E_USER_ERROR);
}

function web_TaskViewShow(&$oIn, &$oOut)
{
	global $arTaskStatus;
	// tasks' data
	$_oIn = array('idcontact_current'=>$_SESSION['iduser'], 'status'=>-1/* active */, 'idparent'=>$oIn['idparent']);
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TASK_SEARCH", $_oIn, $arTasks);
	$this = $oIn['layout'];
	
	if ( count($arTasks['tasks']) )
	{
		$nTasksCount = count($arTasks['tasks']);
		$nTasksWorkHours = 0;
		foreach ( $arTasks['tasks'] as $nIdTask => $arTaskInfo )
			$nTasksWorkHours += $arTaskInfo['work_time'];
		
		$this->formSection(_LW("Tasks"));
        $this->formItem(_LW("Count"),"string",$nTasksCount);
        $this->formItem(_LW("Work hours"),"string",$nTasksWorkHours);
        $this->formItem(_LW("Project resources"),"link", _LW("View"), array('href'=>"?page=/web/task/task_gant.php&idparent=".$oIn['idparent']));
		
        $this->formSection(_LW("Tasks"));
        $this->formItem("","subitem");
        $this->tableStart("default_sub");
        $arHeader = array( 
        	array('value'=>_LW('ID'), 'colspan'=>0, 'align'=>'left'),
			array('value'=>_LW('Title'), 'colspan'=>0, 'align'=>'left'),
			array('value'=>_LW('Responsible'), 'colspan'=>0, 'align'=>'left'),
			array('value'=>_LW('Status'), 'colspan'=>0, 'align'=>'left'),
							);
		$this->tableHeader($arHeader);
		
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_SHORTINFO", $_oIn = array('idcontact_current'=>$_SESSION['iduser']), $arContacts=array());
        foreach ( $arTasks['tasks'] as $nIdTask => $arTaskInfo )
        {
			$this->tableRow();
			$this->tableCol($this->singleItem("string",$nIdTask));
			$this->tableCol($this->singleItem("string",$arTaskInfo['title']));
			$this->tableCol($this->singleItem("string",$arContacts['contacts'][$arTaskInfo['idresponsible']]));
			$this->tableCol($this->singleItem("string",$arTaskStatus[$arTaskInfo['status']]));
        }
        $this->tableEnd();
	}
}

function web_TaskMenuCreate(&$oIn, &$oOut)
{
	if ( !is_array($oIn) || !isset($oIn['idobject']) || !isset($oIn['type']) )
		return false;

	if ( $oIn['type'] == ID_SEMA_TASK )
	{	
		// check is this user responsible for current task
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idtask'=>$oIn['idobject']);
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_ISRESPONSIBLE", $_oIn, $arResponsible = array());
		
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_TASK, 'mask'=>'2');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut=array());
		if ( (isset($_oOut['result']) && $_oOut['result']) && (isset($arResponsible['result']) && $arResponsible['result']) )
			$oOut[5][_LW('Deed task')] = "?action=modify&idform=GT_TASK_CHAIN_DEED&idtask=".$oIn['idobject'];
	
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_TASK, 'mask'=>'34', 'operation'=>'|');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut=array());
		if ( (isset($_oOut['result']) && $_oOut['result']) && (isset($arResponsible['result']) && $arResponsible['result']) )
			$oOut[5][_LW('Alter task')] = "?action=modify&idform=GT_TASK_CHAIN_ALTER&idtask=".$oIn['idobject'];
			
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_PROJECT, 'mask'=>'4');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut=array());
		if ( isset($_oOut['result']) && $_oOut['result'] )	
			$oOut[10][_LW("Create task")] = "?page=/web/task/task_form.php&idparent=".$oIn['idobject'];
			
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_TASK, 'mask'=>'W');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
		if ( isset($_oOut['result']) && $_oOut['result'] ) 
			$oOut[10][_LW("Modify")] = "?page=/web/task/task_form.php&idtask=".$oIn['idobject'];
	}
	elseif ( $oIn['type'] == ID_SEMA_PROJECT )
	{
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_PROJECT, 'mask'=>'4');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut=array());
		if ( isset($_oOut['result']) && $_oOut['result'] )	
			$oOut[10][_LW("Create task")] = "?page=/web/task/task_form.php&idparent=".$oIn['idobject'];
		
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_PROJECT, 'mask'=>'R');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut=array());
		if ( isset($_oOut['result']) && $_oOut['result'] )
		{
			$oOut[5][_LW('View tasks')] = "?page=/web/task/task_main.php&idproject=".$oIn['idobject'];
			$oOut[5][_LW('View gant')] = "?page=/web/task/task_gant.php&idparent=".$oIn['idobject'];
		}
	}
	return true;
}

function web_TaskActionMenuCreate(&$oIn, &$oOut)
{
	if ( !is_array($oIn) || !isset($oIn['idobject']) || !isset($oIn['type']) )
		return false;

	$level = 0;
	if (isset($oIn['level'])) $level =$oIn['level'];
	
	if ( $oIn['type'] != ID_SEMA_TASK && $oIn['type'] != ID_SEMA_PROJECT)
		return true;
			
	if ($oIn['type'] == ID_SEMA_TASK)
	{
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_TASK, 'mask'=>'W');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
		if ( isset($_oOut['result']) && $_oOut['result'] ) {
			$oOut[10][_LW("edit")] = array('href'=>"?page=/web/task/task_form.php&idtask=".$oIn['idobject']);
			if ($level==0) $oOut[10][_LW("del")] =  array('href'=>"?action=remove&idobject=".$oIn['idobject']."&type=".constant("ID_SEMA_TASK")."&redirect=page@@/web/task/task_main.php", 'onclick'=>'if (!confirm("'._LW("Are you sure?").'")) return false;');
		}
	}
		
	$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_TASK, 'mask'=>'34', 'operation'=>'|');
	$_oOut = array();
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
	if ( isset($_oOut['result']) && $_oOut['result'] )	
		$oOut[5][_LW("+task")] = array('href'=>"?page=/web/task/task_form.php&idparent=".$oIn['idobject']);
			
	return true;
}

function web_TaskDefaultViewShow(&$oIn, &$oOut)
{
	if ( !is_array($oIn) || !isset($oIn['layout']) )
		return false;
		
	global $arTaskStatus, $arTaskPriority;
	$this = &$oIn['layout'];
	
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_SHORTINFO", $_oIn=array(), $arContacts=array());

	// section "My Tasks"
	$_oIn = array('idcontact_current'=>$_SESSION['iduser'], 'type'=>'myown');
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TASK_SEARCH_DEFVIEW", $_oIn, $arTasks=array());
	
	if ( isset($arTasks['tasks']) && count($arTasks['tasks']) )
	{
		$this->formSection(_LW("My tasks"));
		$this->formItem("" ,"subitem");
		$this->tableStart("default_sub");
		$arHeader = array( 
			array('value'=>_LW('ID'), 'colspan'=>0, 'align'=>'left'),
			array('value'=>_LW('Title'), 'colspan'=>0, 'align'=>'left'),
			array('value'=>_LW('Info'), 'colspan'=>0, 'align'=>'left'),
			array('value'=>_LW('Action'), 'colspan'=>0, 'align'=>'left')
							);
		$this->tableHeader($arHeader);

	    foreach ( $arTasks['tasks'] as $nIdTask => $arTaskInfo )
	    {
			$this->tableRow();
			$this->tableCol($this->singleItem("string",$nIdTask));
			$this->tableCol($this->singleItem("link", $arTaskInfo['title'], array('href'=>"?page=/web/task/task_view.php&idtask=$nIdTask")));
			$this->tableCol($arTaskStatus[$arTaskInfo['status']]." / ".$arTaskPriority[$arTaskInfo['priority']]);

			$this->tableCol();

			// prepare actions for current task
			$_oIn=array('idobject'=>$nIdTask, 'type'=>ID_SEMA_TASK, 'level'=>1);
			$GLOBALS['WEB_DISPATCHER']->ProcessMessage("WM_ACTION_MENU_CREATE", $_oIn, $_oOut=array());
			if ( count($_oOut) )
			{
				krsort($_oOut);
				foreach ($_oOut as $nPriority=>$arMenues) 
					foreach ($arMenues as $sName => $arData) 
						echo $this->singleItem("action",$sName,$arData);
			}
	    }
		$this->tableEnd();
		$this->formSectionEnd();
	}

	$_oIn = array('idcontact_current'=>$_SESSION['iduser'], 'type'=>'active');
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TASK_SEARCH_DEFVIEW", $_oIn, $arTasks=array());
	
	if ( isset($arTasks['tasks']) && count($arTasks['tasks']) )
	{
		// section
		$this->formSection(_LW("Active Tasks"));
		$this->formItem("" ,"subitem");
		$this->tableStart("default_sub");
		$arHeader = array( 
			array('value'=>_LW('ID'), 'colspan'=>0, 'align'=>'left'),
			array('value'=>_LW('Title'), 'colspan'=>0, 'align'=>'left'),
			array('value'=>_LW('Info'), 'colspan'=>0, 'align'=>'left'),
			array('value'=>_LW('Action'), 'colspan'=>0, 'align'=>'left')
							);
		$this->tableHeader($arHeader);

	    foreach ( $arTasks['tasks'] as $nIdTask => $arTaskInfo )
	    {
			$this->tableRow();
			$this->tableCol($this->singleItem("string",$nIdTask));
			$this->tableCol($this->singleItem("link", $arTaskInfo['title'], array('href'=>"?page=/web/task/task_view.php&idtask=$nIdTask")));
			$this->tableCol($arTaskStatus[$arTaskInfo['status']]." / ".$arContacts['contacts'][$arTaskInfo['idworker']]." / ".$arTaskPriority[$arTaskInfo['priority']]);
			
			$this->tableCol();

			// prepare actions for current task
			$_oIn=array('idobject'=>$nIdTask, 'type'=>ID_SEMA_TASK, 'level'=>1);
			$GLOBALS['WEB_DISPATCHER']->ProcessMessage("WM_ACTION_MENU_CREATE", $_oIn, $_oOut=array());
			if ( count($_oOut) )
			{
				krsort($_oOut);
				foreach ($_oOut as $nPriority=>$arMenues) 
					foreach ($arMenues as $sName => $arData) 
						echo $this->singleItem("action",$sName,$arData);
			}
	    }

		$this->tableEnd();
		$this->formSectionEnd();
	}
	
	return true;
}

function web_TaskGlobalMenuCreate(&$oIn, &$oOut)
{
	$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>0, 'type'=>ID_SEMA_TASK, 'mask'=>'W');
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
	if ( isset($_oOut['result']) && $_oOut['result'] )
		$oOut[6][_LW('Create my task')] = "task/task_form.php";
}
?>
Return current item: PushOk SEMA