Location: PHPKode > projects > PushOk SEMA > html/web/task/task_form.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

/*
subscription: contain form to create new task or modify existing.
*/
$nIdParent = 0;// if this variable isset then we here to add new task to project
if ( isset($_GET['idparent']) && $_GET['idparent']>0 )
	$nIdParent = $_GET['idparent'];
	
$nIdTask = 0;// if this variable isset then we here to modify existing task
if ( isset($_GET['idtask']) && $_GET['idtask']>0 )
	$nIdTask = $_GET['idtask'];

class web_Task extends web_Layout 
{
	function Info()
	{
		global $arTaskStatus, $nIdParent, $nIdTask, $arTaskTT, $arTaskPriority;

		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_SHORTINFO", $oIn = array('idcontact_current'=>$_SESSION['iduser']), $arContacts);
		$nId = $nIdParent?$nIdParent:$nIdTask;
		$bHasParent = false;
		if ( $nId )
		{
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_OBJECT_ROOT_PARENT", $oIn = array('idcontact_current'=>$_SESSION['iduser'], 'idobject'=>$nId), $arObject);
			if ( isset($arObject['object']) && count($arObject['object']) )
			{
				$bHasParent = true;
				$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_OBJECT_CONTACTS_GET", $oIn = array('idobject'=>$arObject['object']['id'], 'idobject_type'=>$arObject['object']['type']), $arObjectContacts);
				// rebuild data
				if ( count($arObjectContacts) )
				{
					foreach ( $arObjectContacts as $nIndex=>$_arContacts)
					{
						foreach ( $_arContacts as $nId=>$arContact )
							$arTemp[$nId] = $arContacts['contacts'][$nId];
					}
					$arContacts['contacts'] = $arTemp;
				}
			}
		}
	
		if ( $nIdTask ) 
		{
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TASK_SEARCH", $oIn = array('id' => $nIdTask, 'idcontact_current' => $_SESSION['iduser']), $arTaskInfo);
			if (count($arTaskInfo)==0)
			{
				web_PageError(_LW("Access denied, or object deleted !"));
				return;
			}
		}
		
		if ( $nIdTask )
			$this->formStart($arTaskInfo['tasks'][$nIdTask]['title']);
		else 	
			$this->formStart(_LW("New task"));
        echo "<FORM method=post>";
		echo "<INPUT type=\"hidden\" name=\"idform\" value=\"FM_TASK_CREATE\"></INPUT>\n";
		$sLink = web_GetPrevPage();
		if (!strlen($sLink))
			$sLink = "?page=/web/task/task_main.php";
		echo "<INPUT type=\"hidden\" name=\"onsuccess\" value=\"$sLink\"></INPUT>\n";
		echo "<INPUT type=\"hidden\" name=\"onerror\" value=\"?".web_GetPageGetParams()."\"></INPUT>\n";
		echo "<INPUT type=\"hidden\" name=\"idparent\" value=\"$nIdParent\"></INPUT>\n";
		echo "<INPUT type=\"hidden\" name=\"idtask\" value=\"$nIdTask\"></INPUT>\n";
		
		// if was some error then show the message about
		$bError = isset($_SESSION['last_post']);

		// title column 
		$sFieldValue = "";
		if ( $nIdTask && isset($arTaskInfo['tasks'][$nIdTask]['title']) ) 
			$sFieldValue = $arTaskInfo['tasks'][$nIdTask]['title'];
		if ( $bError )
			$sFieldValue = $_SESSION['last_post']['data']['title'];
		$this->formInputItem(_LW("Title"),"edit","title",$sFieldValue);
		
		// time_type column 
		$sFieldValue = "";
		if ( $nIdTask && isset($arTaskInfo['tasks'][$nIdTask]['time_type']) ) 
			$sFieldValue = $arTaskInfo['tasks'][$nIdTask]['time_type'];
		if ( $bError )
			$sFieldValue = $_SESSION['last_post']['data']['time_type'];
		$this->formInputItem(_LW("Time type"),"select","time_type",$sFieldValue, $arTaskTT);
			
		// bdate column 
		$sFieldValue = "";
		if ( $nIdTask && isset($arTaskInfo['tasks'][$nIdTask]['bdate']) ) 
			$sFieldValue = $arTaskInfo['tasks'][$nIdTask]['bdate'];
		if ( $bError )
			$sFieldValue = $_SESSION['last_post']['data']['bdate'];
		$this->formInputItem(_LW("Start date"),"date","bdate",$sFieldValue);
			
		// edate column 
		$sFieldValue = "";
		if ( $nIdTask && isset($arTaskInfo['tasks'][$nIdTask]['edate']) ) 
			$sFieldValue = $arTaskInfo['tasks'][$nIdTask]['edate'];
		if ( $bError )
			$sFieldValue = $_SESSION['last_post']['data']['edate'];
		$this->formInputItem(_LW("End date"),"date","edate",$sFieldValue);
			
		// work_time column 
		$sFieldValue = "";
		if ( $nIdTask && isset($arTaskInfo['tasks'][$nIdTask]['work_time']) ) 
			$sFieldValue = $arTaskInfo['tasks'][$nIdTask]['work_time'];
		if ( $bError )
			$sFieldValue = $_SESSION['last_post']['data']['work_time'];
		$this->formInputItem(_LW("Work time"),"edit","work_time",$sFieldValue);
		
		// idworker column 
		$sFieldValue = "";
		if (!$bHasParent)
			$sFieldValue = $_SESSION['iduser'];
		if ( $nIdTask && isset($arTaskInfo['tasks'][$nIdTask]['idworker']) ) 
			$sFieldValue = $arTaskInfo['tasks'][$nIdTask]['idworker'];
		if ( $bError )
			$sFieldValue = $_SESSION['last_post']['data']['idworker'];
		$this->formInputItem(_LW("Worker"),"select","idworker",$sFieldValue, $arContacts['contacts']);
			
		if ($nIdTask) {
			// idresponsible column 
			$sFieldValue = "";
			if (!$bHasParent) 
				$sFieldValue = $_SESSION['iduser'];
			if ( $nIdTask && isset($arTaskInfo['tasks'][$nIdTask]['idresponsible']) ) 
				$sFieldValue = $arTaskInfo['tasks'][$nIdTask]['idresponsible'];
			if ( $bError )
				$sFieldValue = $_SESSION['last_post']['data']['idresponsible'];
			$this->formInputItem(_LW("Responsible"),"select","idresponsible",$sFieldValue, $arContacts['contacts']);
		} 
			
		// priority column 
		$sFieldValue = 2;
		if ( $nIdTask && isset($arTaskInfo['tasks'][$nIdTask]['priority']) ) 
			$sFieldValue = $arTaskInfo['tasks'][$nIdTask]['priority'];
		if ( $bError )
			$sFieldValue = $_SESSION['last_post']['data']['priority'];
		$this->formInputItem(_LW("Priority"),"select","priority",$sFieldValue, $arTaskPriority);
				
		// status column 
		$sFieldValue = 2;
		if ( $nIdTask && isset($arTaskInfo['tasks'][$nIdTask]['status']) ) 
			$sFieldValue = $arTaskInfo['tasks'][$nIdTask]['status']; 
		if ( $bError )
			$sFieldValue = $_SESSION['last_post']['data']['status'];
		$this->formInputItem(_LW("Status"),"select","status",$sFieldValue, $arTaskStatus);
		
		// chain column 
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CHAIN_GET", $oIn=array(), $arChains=array());
		// prepare data for showing
		$arChainData = array();
		if ( isset($arChains['chains']) && count($arChains['chains']) )
			foreach ( $arChains['chains'] as $nId => $arChainInfo )
				$arChainData[$nId] = $arChainInfo['name'];
		$sFieldValue = 1;
		if ( $nIdTask && isset($arTaskInfo['tasks'][$nIdTask]['iddoc_chain']) ) 
			$sFieldValue = $arTaskInfo['tasks'][$nIdTask]['iddoc_chain']; 
		if ( $bError )
			$sFieldValue = $_SESSION['last_post']['data']['iddoc_chain'];
		$this->formInputItem(_LW("Chain"),"select","iddoc_chain",$sFieldValue, $arChainData);
		
		// text column (task_content table data)
        $this->formSection(_LW("New description"));

		$sFieldValue = "";
		if ( $bError )
			$sFieldValue = $_SESSION['last_post']['data']['text'];
		$this->formInputItem(_LW("Text"),"text","text",$sFieldValue, array('cols'=>80, 'rows'=>10));
			
		$sFieldValue = $nIdTask?_LW("Modify"):_LW("Create");
		$this->formInputItem($sFieldValue,"submit","","");						
        echo "</FORM>";
		
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TASK_CONTENT_GET", $oIn=array('idcontact_current'=>$_SESSION['iduser'], 'idtask'=>$nIdTask), $arTaskContent);
		if ( isset($arTaskContent['task_content']) && count($arTaskContent['task_content']) )
		{
            $this->formSection(_LW("Description"));
			foreach ( $arTaskContent['task_content'] as $key => $text )
			{
				$text = web_ChangeObject2Link($text);
				$this->formItem("", "subitem",$this->singleItem("memo",$text));
			}
		}
		$this->formEnd();
		?>
		<?PHP
	}
}

$oPage = new web_Task;
if ( $nIdTask ) 
	$oPage->m_windowHeader = _LW("Modify task");
else 
	$oPage->m_windowHeader = _LW("Create task");
$oPage->WebStack("task_form.php", $oPage->m_windowHeader, $oPage->m_windowHeader, web_GetPageGetParams());

if ( !isset($_SESSION['iduser']) )
	web_RedirectRelative("sema.php");
	
$oPage->idobject = $nIdTask;
$oPage->object_type = ID_SEMA_TASK;
$oPage->m_menuFLvl = "Tasks";
$oPage->RenderPage();

?>
Return current item: PushOk SEMA