Location: PHPKode > projects > PushOk SEMA > html/web/issue/issue_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 issue or modify existing.
*/
$nIdParent = 0;// if this variable isset then we here to add new issue to object
if ( isset($_GET['idparent']) && $_GET['idparent']>0 )
	$nIdParent = $_GET['idparent'];
	
$nIdIssue = 0;// if this variable isset then we here to modify existing issue
if ( isset($_GET['idissue']) && $_GET['idissue']>0 )
	$nIdIssue = $_GET['idissue'];

class web_Issue extends web_Layout 
{
	function Info()
	{
		global $nIdParent, $nIdIssue, $arIssueStatus, $arIssueStatusInt, $arIssuePriority;
		
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_SHORTINFO", $oIn = array('idcontact_current'=>$_SESSION['iduser']), $arContacts);
		$bIssueHasParent = false;
		if ($nIdIssue) {
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_OBJECT_INFO", $oIn = array('idobject'=>$nIdIssue), $oOut=array());
			if (isset($oOut['object']) && count($oOut['object']) && $oOut['object']['parent_object'])
				$bIssueHasParent = true;
		}
		
		if ( $nIdParent || $bIssueHasParent ) {
			$nIdObject = $nIdIssue?$nIdIssue:$nIdParent;
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_OBJECT_ROOT_PARENT", $oIn = array('idcontact_current'=>$_SESSION['iduser'], 'idobject'=>$nIdObject), $arObject);
			if ( isset($arObject['object']) && count($arObject['object']) )
			{
				$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 ( $nIdIssue ) 
		{
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_ISSUE_SEARCH", $oIn = array('id' => $nIdIssue, 'idcontact_current' => $_SESSION['iduser']), $arIssueInfo);
			if (count($arIssueInfo)==0)
			{
				web_PageError(_LW("Access denied, or object deleted !"));
				return;
			}
		}
		
		if ( $nIdIssue )
			$this->formStart($arIssueInfo['issues'][$nIdIssue]['title']);
		else 	
			$this->formStart(_LW("New issue"));
        echo "<FORM method=post enctype=\"multipart/form-data\">";
		echo "<INPUT type=\"hidden\" name=\"idform\" value=\"FM_ISSUE_CREATE\"></INPUT>\n";
		$sLink = web_GetPrevPage();
		if (!strlen($sLink))
			$sLink = "?page=/web/issue/issue_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=\"idissue\" value=\"$nIdIssue\"></INPUT>\n";
		
		// if was some error then show the message about
		$bError = isset($_SESSION['last_post']);

		// title column 
		$sFieldValue = "";
		if ( $nIdIssue && isset($arIssueInfo['issues'][$nIdIssue]['title']) ) 
			$sFieldValue = $arIssueInfo['issues'][$nIdIssue]['title'];
		if ( $bError )
			$sFieldValue = $_SESSION['last_post']['data']['title'];
		$this->formInputItem(_LW("Title"),"edit","title",$sFieldValue);

		// change responsible and status of issue can user with mask 4
		$bHasMask = false;
		$_oOut = array();
		if ($nIdParent) {
			$_oIn = array('idobject'=>$nIdParent);
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_OBJECT_INFO", $_oIn, $_oOut);
			$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$nIdParent, 'type'=>$_oOut['object']['type'], 'mask'=>'4');
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut=array());
		}
		else {
			$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$nIdIssue, 'type'=>ID_SEMA_ISSUE, 'mask'=>'4');
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
		}
		if ( isset($_oOut['result']) && $_oOut['result'] )
		{
			$bHasMask = true;
			// idresponsible column 
			$sFieldValue = $_SESSION['iduser'];
			if ( $nIdIssue && isset($arIssueInfo['issues'][$nIdIssue]['idresponsible']) ) 
				$sFieldValue = $arIssueInfo['issues'][$nIdIssue]['idresponsible'];
			if ( $bError )
				$sFieldValue = $_SESSION['last_post']['data']['idresponsible'];
			$this->formInputItem(_LW("Responsible"),"select","idresponsible",$sFieldValue, $arContacts['contacts']);
			
			// idworker column 
			$sFieldValue = $_SESSION['iduser'];
			if ( $nIdIssue && isset($arIssueInfo['issues'][$nIdIssue]['idworker']) ) 
				$sFieldValue = $arIssueInfo['issues'][$nIdIssue]['idworker'];
			if ( $bError )
				$sFieldValue = $_SESSION['last_post']['data']['idworker'];
			$this->formInputItem(_LW("Worker"),"select","idworker",$sFieldValue, $arContacts['contacts']);
		}
		else 
		{
			// get owner of parent object
			$_oIn = array('idcontact_current'=>$_SESSION['iduser'], 'idobject'=>$nIdParent);
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_OBJECT_INFO", $_oIn, $_oOut=array());
			
			if ( isset($_oOut['object']) && count($_oOut['object']) )
				$nIdContact = $_oOut['object']['idcreator'];
			else				
				$nIdContact = $_SESSION['iduser'];
			
			echo "<INPUT type=\"hidden\" name=\"idresponsible\" value=\"$nIdContact\"></INPUT>\n";
			echo "<INPUT type=\"hidden\" name=\"idworker\" value=\"$nIdContact\"></INPUT>\n";
		}
			
		// priority column 
		$sFieldValue = "";
		if ( $nIdIssue && isset($arIssueInfo['issues'][$nIdIssue]['priority']) ) 
			$sFieldValue = $arIssueInfo['issues'][$nIdIssue]['priority'];
		if ( $bError )
			$sFieldValue = $_SESSION['last_post']['data']['priority'];
		$this->formInputItem(_LW("Priority"),"select","priority",$sFieldValue, $arIssuePriority);

		if ( $bHasMask )
		{	
			// status column 
			$sFieldValue = 0;
			if ( $nIdIssue && isset($arIssueInfo['issues'][$nIdIssue]['status']) ) 
				$sFieldValue = $arIssueInfo['issues'][$nIdIssue]['status']; 
			if ( $bError )
				$sFieldValue = $_SESSION['last_post']['data']['status'];
			$this->formInputItem(_LW("Status"),"select","status",$sFieldValue, $arIssueStatus);
			
			// internal status column 
			$sFieldValue = 0;
			if ( $nIdIssue && isset($arIssueInfo['issues'][$nIdIssue]['status2']) ) 
				$sFieldValue = $arIssueInfo['issues'][$nIdIssue]['status2']; 
			if ( $bError )
				$sFieldValue = $_SESSION['last_post']['data']['status2'];
			$this->formInputItem(_LW("Internal"),"select","status2",$sFieldValue, $arIssueStatusInt);
		}
		else 
		{
			echo "<INPUT type=\"hidden\" name=\"status\" value=\"1\"></INPUT>\n";
			echo "<INPUT type=\"hidden\" name=\"status2\" value=\"1\"></INPUT>\n";
		}
		
		// new comment can add only user with mask 3
		$bCanAdd = true;
		if ( $nIdIssue )
		{
			$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$nIdIssue, 'type'=>ID_SEMA_ISSUE, 'mask'=>'3');
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut=array());
			if ( !(isset($_oOut['result']) && $_oOut['result']) )
				$bCanAdd = false;
		}
		if ( $bCanAdd )
		{
			// text column (issue_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));
			
			$this->formInputItem(_LW("Attach"), "file", "attach[]");
			$this->formInputItem(_LW("Attach"), "file", "attach[]");
			$this->formInputItem(_LW("Attach"), "file", "attach[]");
		}
			
		$sFieldValue = $nIdIssue?_LW("Modify"):_LW("Create");
		$this->formInputItem($sFieldValue,"submit","","");						
        echo "</FORM>";
		
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_ISSUE_CONTENT_GET", $oIn=array('idcontact_current'=>$_SESSION['iduser'], 'idissue'=>$nIdIssue), $arIssueContent);
		if ( isset($arIssueContent['issue_content']) && count($arIssueContent['issue_content']) )
		{
            $this->formSection(_LW("Description"));
			foreach ( $arIssueContent['issue_content'] as $key => $arInfo )
			{
				$this->formItem(_LW("Author"), "string", $arContacts['contacts'][$arInfo['idcreator']]);
				$text = web_ChangeObject2Link($arInfo['text']);
				$this->formItem("", "subitem",$this->singleItem("memo",$text));
				$sFilesIds = $arInfo['files'];
				if ( strlen($sFilesIds) )
				{
					$arFilesIds = split(',', $sFilesIds);
					// show links to files
					$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_FILE_INFO_GET", $_oIn=array('idcontact_current'=>$_SESSION['iduser'], 'idfile'=>$arFilesIds), $_oOut=array());
					if ( isset($_oOut['files']) && count($_oOut['files']) )
					{
						foreach ( $_oOut['files'] as $nId => $sName )
							$this->formItem("", "subitem", $this->singleItem("link", $sName, array('href'=>"?page=/web/attach_download.php&id=$nId")));
					}
				}
			}
		}
		$this->formEnd();
		?>
		<?PHP
	}
}

$oPage = new web_Issue;
if ( $nIdIssue ) 
	$oPage->m_windowHeader = _LW("Modify issue");
else 
	$oPage->m_windowHeader = _LW("Create issue");
$oPage->WebStack("issue_form.php", $oPage->m_windowHeader, $oPage->m_windowHeader, web_GetPageGetParams());

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

?>
Return current item: PushOk SEMA