Location: PHPKode > projects > PushOk SEMA > html/web/contact/contact_view.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 more information about some contact.
*/
$nIdContact = 0;
if ( isset($_GET['idcontact']) && $_GET['idcontact']>0 )
	$nIdContact = $_GET['idcontact'];
else 
	web_RedirectRelative("sema.php");

class web_Contact extends web_Layout 
{
	function Info()
	{
		global $nIdContact;
		
		$oIn = array('id' => $nIdContact, 'idcontact_current'=>$_SESSION['iduser']);
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_SEARCH", $oIn, $arContacts);
		$arContactInfo = $arContacts['contacts'];
		
		// contact data
		$this->formStart($arContactInfo[$nIdContact]['title']);
        $this->formSection("General");
		$this->formItem(_LW("First name"),"string",$arContactInfo[$nIdContact]['first_name']);
		$this->formItem(_LW("Middle name"),"string",$arContactInfo[$nIdContact]['middle_name']);
		$this->formItem(_LW("Last name"),"string",$arContactInfo[$nIdContact]['last_name']);
		$this->formItem(_LW("Nick name"),"string",$arContactInfo[$nIdContact]['nick_name']);
		$this->formItem(_LW("Work place"),"string",$arContactInfo[$nIdContact]['work_place']);
		$oIn = array('idcontact' => $nIdContact, 'idcontact_current' => $_SESSION['iduser'], 'layout' => &$this);
		$GLOBALS['WEB_DISPATCHER']->ProcessMessage("WM_CONTACT_VIEW_SHOW", $oIn, $oOut);
        $this->formSection("Phones");
        $this->formItem("","subitem");
        $this->InfoKind("1",$nIdContact);
        $this->formSection("Address");
        $this->formItem("","subitem");
        $this->InfoKind("2",$nIdContact);
        $this->formSection("Emails");
        $this->formItem("","subitem");
        $this->InfoKind("3",$nIdContact);
        $this->formEnd();
		?>
		<?PHP
	}
	function InfoKind($nIdInfo,$nIdContact)
	{
		global  $arPhoneType, $arAddressType, $arEmailType;
		
		$oIn = array('idcontact' => $nIdContact);
		$oIn['info_kind'] = $nIdInfo;
		$sFieldName = "";
		$sFormName = "";
		$arTypeValues = null;

		switch ( $oIn['info_kind'] )
		{
		case 1:
			$sFieldName = "phone";
			$sName = _LW("Phone");
			$sFormName = "GT_CONTACT_PHONE";
			$arTypeValues = $arPhoneType;
			break;
		case 2:
			$sFieldName = "address";
			$sName = _LW("Address");
			$sFormName = "GT_CONTACT_ADDRESS";
			$arTypeValues = $arAddressType;
			break;
		case 3:
			$sFieldName = "email";
			$sName = _LW("E-mail");
			$sFormName = "GT_CONTACT_EMAIL";
			$arTypeValues = $arEmailType;
			break;
		default:
			{
				$nIdInfo = 0;
				PEAR::raiseError(_LW("Unknown 'info_kind'!"), E_USER_WARNING);
			}
		}

		if ( $nIdInfo )
		{
			$_oIn = array('idcontact_current'=>$_SESSION['iduser'], 'info_kind'=>$nIdInfo, 'idcontact'=>$nIdContact);
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_SEARCH_ADDINFO", $_oIn, $arContact);
		}
				
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$nIdContact, 'type'=>ID_SEMA_CONTACT, 'mask'=>'W');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
		$bHasMask = false;
		if ( isset($_oOut['result']) && $_oOut['result'] )
			$bHasMask = true;
			
		$this->tableStart("default_sub");
		$arHeader = array( 
			array('value'=>$sName, 'colspan'=>0, 'align'=>'left'),
			array('value'=>_LW('Type'), 'colspan'=>0, 'align'=>'left'),
			array('value'=>_LW('Action'), 'colspan'=>0, 'align'=>'left'),
							);
		$this->tableHeader($arHeader);
		
		if ( count($arContact['contact_addinfo']) )
		{
			foreach ( $arContact['contact_addinfo'] as $nId => $arInfo )
			{
				$this->tableRow();
				$this->tableCol($arInfo[$sFieldName]);
				$this->tableCol($arTypeValues[$arInfo['type']]);
				
				$_oIn=array('idobject'=>$nIdContact, 'type'=>ID_SEMA_CONTACT, 'form_name'=>$sFormName, 'id'=>$nId);
				$GLOBALS['WEB_DISPATCHER']->ProcessMessage("WM_ACTION_MENU_CREATE", $_oIn, $_oOut=array());
				
				$this->tableCol();
				if ( count($_oOut) )
				{
					krsort($_oOut);
					foreach (  $_oOut as $nPriority=>$arMenues) 
						foreach ( $arMenues as $sName => $arData )
        	            	echo $this->singleItem("action",$sName,$arData);
				}
			}
		}
        if ( $bHasMask || $nIdContact == $_SESSION['iduser'] )
        {
            echo "<FORM method=\"POST\">\n";
            $this->tableRow();
            echo "<INPUT type=\"hidden\" name=\"idform\" value=\"FM_CONTACT_ADDINFO_CREATE\"></INPUT>\n";
            echo "<INPUT type=\"hidden\" name=\"onsuccess\" value=\"?".web_GetPageGetParams()."\"></INPUT>\n";
            echo "<INPUT type=\"hidden\" name=\"onerror\" value=\"?".web_GetPageGetParams()."\"></INPUT>\n";
            echo "<INPUT type=\"hidden\" name=\"idcontact\" value=\"$nIdContact\"></INPUT>\n";
            echo "<INPUT type=\"hidden\" name=\"info_kind\" value=\"$nIdInfo\"></INPUT>\n";
            $this->tableCol($this->singleInputItem(false, "edit", $sFieldName));
            $this->tableCol($this->singleInputItem(false, "select", "type", "", $arTypeValues));
            // type column
            $this->tableCol($this->singleInputItem(_LW("Add"), "submit"));
            echo "</FORM>\n";
        }

		$this->tableEnd();
	}
}

$oPage = new web_Contact;
$oPage->m_windowHeader = _LW("Contact info");
$oPage->WebStack("contact_view.php", $oPage->m_windowHeader, $oPage->m_windowHeader, web_GetPageGetParams());

if ( !isset($_SESSION['iduser']) )
	web_RedirectRelative("sema.php");

$oPage->idobject = $nIdContact;
$oPage->object_type = ID_SEMA_CONTACT;
$oPage->m_menuFLvl = "Contacts";
$oPage->RenderPage();

?>
Return current item: PushOk SEMA