Location: PHPKode > projects > PushOk SEMA > html/web/issue/issue.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_IssueCreateFLvlMenu(&$oIn, &$oOut)
{
	if ( !is_array($oOut) )
		$oOut = array();
	$oOut[5][_LW('Issues')]= "issue/issue_main.php";
	return true;
}

//! add second menu's items
function web_IssueCreateSLvlMenu(&$oIn, &$oOut)
{
	if ( !is_array($oOut) )
		$oOut = array();
	if ( isset($oIn['menu_flvl']) && $oIn['menu_flvl'] == "Issues" )
	{
		$oOut[5][_LW('Search issues')] = "issue/issue_main.php";
		
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>0, 'type'=>ID_SEMA_ISSUE, 'mask'=>'W');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
		if ( isset($_oOut['result']) && $_oOut['result'] )
			$oOut[5][_LW('Create new issue')] = "issue/issue_form.php";
	}
	return true;
}

//! validate user's data and transmit it to kernel 
function web_IssueCreate(&$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'!");
		return true;
	}
	elseif ( $oIn['step'] == 2 )
	{
		$oIn['post']['idcontact_current'] = $_SESSION['iduser'];
		
		if ( isset($oIn['post']['idissue']) && $oIn['post']['idissue']>0 )
			return $GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_ISSUE_MODIFY", $oIn['post'], $oOut);
		else
			return $GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_ISSUE_CREATE", $oIn['post'], $oOut);
	}
	return PEAR::raiseError("FILE: \"".__FILE__."\" LINE: \"".__LINE__."\" MSG: \""._LW("Bad params!")."\"", E_USER_ERROR);

}

function web_IssueViewShow(&$oIn, &$oOut)
{
	global $arIssueStatus;
	// issues' data
	$_oIn = array('idcontact_current'=>$_SESSION['iduser'], 'status'=>-1/* active */, 'idparent'=>$oIn['idparent']);
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_ISSUE_SEARCH", $_oIn, $arIssues);
	$this = $oIn['layout'];
	
	if ( count($arIssues['issues']) )
	{
        $this->formSection(_LW("Issues"));
        $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('Worker'), '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'], 'status'=>-1/*active*/), $arContacts=array());
        foreach ( $arIssues['issues'] as $nIdIssue => $arIssueInfo )
        {
			$this->tableRow();
			$this->tableCol($this->singleItem("string",$nIdIssue));
			$this->tableCol($arIssueInfo['title']);
			$this->tableCol($arContacts['contacts'][$arIssueInfo['idresponsible']]);
			$this->tableCol($arContacts['contacts'][$arIssueInfo['idworker']]);
			$this->tableCol($arIssueStatus[$arIssueInfo['status']]);
        }
        $this->tableEnd();
	}
}

function web_IssueMenuCreate(&$oIn, &$oOut)
{
	if ( !is_array($oIn) || !isset($oIn['idobject']) || !isset($oIn['type']) )
		return false;
	
	if ( $oIn['type'] == ID_SEMA_PROJECT || $oIn['type'] == ID_SEMA_TASK )
	{	
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>$oIn['type'], 'mask'=>'R');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
		if ( isset($_oOut['result']) && $_oOut['result'] )
			$oOut[5][_LW('View issues')] = "?page=/web/issue/issue_main.php&idparent=".$oIn['idobject'];
	
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>$oIn['type'], 'mask'=>'1');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
		if ( isset($_oOut['result']) && $_oOut['result'] )
			$oOut[10][_LW('Create issue')] = "?page=/web/issue/issue_form.php&idparent=".$oIn['idobject'];
	}
	elseif ( $oIn['type'] == ID_SEMA_ISSUE )
	{
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_ISSUE, 'mask'=>'W');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
		if ( isset($_oOut['result']) && $_oOut['result'] )
			$oOut[10][_LW("Modify")] = "?page=/web/issue/issue_form.php&idissue=".$oIn['idobject'];
	}

	return true;
}

function web_IssueActionMenuCreate(&$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 && $oIn['type'] != ID_SEMA_ISSUE)
		return true;

	if ($oIn['type'] == ID_SEMA_ISSUE)
	{
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_ISSUE, '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/issue/issue_form.php&idissue=".$oIn['idobject']);
			if ($level==0)	$oOut[10][_LW("del")] = array('href'=>"?action=remove&idobject=".$oIn['idobject']."&type=".constant("ID_SEMA_ISSUE")."&redirect=page@@/web/issue/issue_main.php", 'onclick'=>'if (!confirm("'._LW("Are you sure?").'")) return false;');
		}
	}
	else
	{
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>$oIn['type'], 'mask'=>'1');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
		if ( isset($_oOut['result']) && $_oOut['result'] )
			$oOut[10][_LW('+bug')] = array('href'=>"?page=/web/issue/issue_form.php&idparent=".$oIn['idobject']);
	}

	return true;
}

function web_IssueDefaultViewShow(&$oIn, &$oOut) {
	if ( !is_array($oIn) || !isset($oIn['layout']) )
		return false;
		
	global $arIssueStatus, $arIssueStatusInt, $arIssuePriority;
	$this = &$oIn['layout'];
	
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_SHORTINFO", $_oIn=array(), $arContacts=array());
	
	$_oIn = array('idcontact_current'=>$_SESSION['iduser'], 'idresponsible'=>$_SESSION['iduser'], 
	'idworker'=>$_SESSION['iduser'], 'idcreator'=>$_SESSION['iduser']);
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_ISSUE_SEARCH_DEFVIEW", $_oIn, $arIssues);
	
	if (isset($arIssues['issues']) && count($arIssues['issues'])) {
		$this->formSection(_LW("Active issues"));
		$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 ($arIssues['issues'] as $nIdIssue => $arIssueInfo) {
			$this->tableRow();
			$this->tableCol($this->singleItem("string",$nIdIssue));
			$this->tableCol($this->singleItem("link", $arIssueInfo['title'], array('href'=>"?page=/web/issue/issue_view.php&idissue=$nIdIssue")));
			if ($_SESSION['iduser']==$arIssueInfo['idresponsible'])
				$nametoshow = $arContacts['contacts'][$arIssueInfo['idworker']];
			else
				$nametoshow = $arContacts['contacts'][$arIssueInfo['idresponsible']];
			$this->tableCol($arIssueStatus[$arIssueInfo['status']]."-".$arIssueStatusInt[$arIssueInfo['status2']]." / ".$arIssuePriority[$arIssueInfo['priority']]." / ".$nametoshow);
			
			$this->tableCol();

			// prepare actions for current task
			$_oIn=array('idobject'=>$nIdIssue, 'type'=>ID_SEMA_ISSUE, '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_IssueGlobalMenuCreate(&$oIn, &$oOut) {
	$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>0, 'type'=>ID_SEMA_ISSUE, 'mask'=>'W');
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
	if ( isset($_oOut['result']) && $_oOut['result'] )
		$oOut[5][_LW('Create my issue')] = "issue/issue_form.php";
}

function web_IssueDescriptionNew(&$oIn, &$oOut) {
	if ( !is_array($oIn) )
		return false;
		
	if ( $oIn['step'] == 1 )
	{
		if ( !isset($oIn['post']['text']) || !strlen($oIn['post']['text']) )
			web_AddErrorMsg($oOut, "You need to write some message in 'Text'!");
	}
	elseif ( $oIn['step'] == 2 )
	{
		$oIn['post']['idcontact_current'] = $_SESSION['iduser'];
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_ISSUE_DESCRIPTION_NEW", $oIn['post'], $oOut);
	}
	return true;
}

?>
Return current item: PushOk SEMA