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

//! add second menu's items
function web_ContactCreateSLvlMenu(&$oIn, &$oOut)
{
	if ( !is_array($oOut) )
		$oOut = array();
	if ( isset($oIn['menu_flvl']) && $oIn['menu_flvl'] == "Contacts" )
	{
		$oOut[5][_LW('View contacts')] = "contact/contact_main.php";
		
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>0, 'type'=>ID_SEMA_CONTACT, 'mask'=>'W');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
		if ( isset($_oOut['result']) && $_oOut['result'] )
			$oOut[5][_LW('New contact')] = "contact/contact_form.php";
	}
	return true;
}

//! validate user's data and transmit it to kernel
function web_ContactCreate(&$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 )
	{
		// validate data 
		if ( isset($oIn['post']['first_name']) && !strlen($oIn['post']['first_name']) )
			web_AddErrorMsg($oOut, _LW("You must input 'Contact first name'!"));
			
		if ( isset($oIn['post']['last_name']) && !strlen($oIn['post']['last_name']) )
			web_AddErrorMsg($oOut, _LW("You must input 'Contact last name'!"));
			
		if ( isset($oIn['post']['login1']) && !strlen($oIn['post']['login1']) )
			web_AddErrorMsg($oOut, _LW("You must input 'Contact login'!"));
			
		if ( isset($oIn['post']['password1']) && !strlen($oIn['post']['password1']) )
			web_AddErrorMsg($oOut, _LW("You must input 'Contact password'!"));
			
		if ( isset($oIn['post']['password2']) && !strlen($oIn['post']['password2']) )
			web_AddErrorMsg($oOut, _LW("Confirm password!"));
			
		if ( isset($oIn['post']['password1']) && strlen($oIn['post']['password1']) &&
			isset($oIn['post']['password2']) && strlen($oIn['post']['password2']) &&
			$oIn['post']['password1'] != $oIn['post']['password2'] )
			web_AddErrorMsg($oOut, _LW("Retype password and its confirmation!"));
			
		if ( isset($oIn['post']['flags']) && !strlen($oIn['post']['flags']) )
			web_AddErrorMsg($oOut, _LW("You must input 'Flags'!"));
		else if (!((strpos($oIn['post']['flags'],"I")!==FALSE) || (strpos($oIn['post']['flags'],"E")!==FALSE)))
			web_AddErrorMsg($oOut, _LW("Flags must contain at least 'I'nternal or 'E'xternal falgs."));
		else if ((strpos($oIn['post']['flags'],"I")!==FALSE) && (strpos($oIn['post']['flags'],"E")!==FALSE))
			web_AddErrorMsg($oOut, _LW("Flags cannot contain both I and E flags."));
		else 
		{
			$nCount = strlen($oIn['post']['flags']);
			for ($i=0; $i<$nCount; $i++)
			{
				$c = $oIn['post']['flags'][$i];
				if (!($c == 'I' || $c =='E' || $c=='R'))
				{
					web_AddErrorMsg($oOut, _LW("Wrong flags used, can be [R][I|E]"));
					break;
				}
			}
		}

		return true;
	}
	elseif ( $oIn['step'] == 2 )
	{
		$oIn['post']['idcontact_current'] = $_SESSION['iduser'];

		if ( isset($oIn['post']['idcontact']) && $oIn['post']['idcontact']>0 )
			return $GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_MODIFY", $oIn['post'], $oOut);
		else
			return $GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_CREATE", $oIn['post'], $oTemp);
	}
	return PEAR::raiseError("FILE: \"".__FILE__."\" LINE: \"".__LINE__."\" MSG: \""._LW("Bad params!")."\"", E_USER_ERROR);
}

//! validate user's data and transmit it to kernel
function web_ContactAddInfoCreate(&$oIn, &$oOut)
{
	if ( !is_array($oIn) )
		return false;

	if ( $oIn['step'] == 1 )
	{
		if ( isset($oIn['post']['phone']) && !strlen($oIn['post']['phone']) )
			web_AddErrorMsg($oOut, _LW("You must input 'Phone' field!"));
			
		if ( isset($oIn['post']['address']) && !strlen($oIn['post']['address']) )
			web_AddErrorMsg($oOut, _LW("You must input 'Address' field!"));
			
		if ( isset($oIn['post']['email']) && !strlen($oIn['post']['email']) )
			web_AddErrorMsg($oOut, _LW("You must input 'E-mail' field!"));
	}
	elseif ( $oIn['step'] == 2 )
	{
		$oIn['post']['idcontact_current'] = $_SESSION['iduser'];
		// add contact addition info
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_ADDINFO_CREATE", $oIn['post'], $oTemp);
	}
	return true;
}

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

	if ( $oIn['type'] != ID_SEMA_CONTACT )
		return true;
		
	// check is this contact is root
	$_oIn = array('idcontact'=>$_SESSION['iduser']);
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_ISROOT", $_oIn, $oResult);
	if ( isset($oResult['result']) && $oResult['result'] )
		$oOut[9][_LW('Global rights')] = "?page=/web/contact/contact_rules.php&idcontact=".$oIn['idobject'];

	if ($_SESSION['iduser'] == $oIn['idobject']) {	
		$oOut[5][_LW('Notifications')] = "?page=/web/contact/contact_notifications.php";
		$oOut[5][_LW('Preferences')] = "?page=/web/contact/contact_prefs.php";
	}
		
	$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_CONTACT, 'mask'=>'W');
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut=array());
	if ( isset($_oOut['result']) && $_oOut['result'] )
		$oOut[10][_LW("Modify")] = "?page=/web/contact/contact_form.php&idcontact=".$oIn['idobject'];
			
	return true;
}

function web_ContactRuleCreate(&$oIn, &$oOut)
{
	if ( !is_array($oIn) )
		return false;

	if ( $oIn['step'] == 1 )
	{
		if ( isset($oIn['post']['mask']) && !strlen($oIn['post']['mask']) )
			web_AddErrorMsg($oOut, _LW("You must input 'Mask' field!"));
		else if (strpos($oIn['post']['mask'],"R")===FALSE)
			web_AddErrorMsg($oOut, _LW("You must at least grant 'R'read right"));
		else if (!((strpos($oIn['post']['mask'],"I")!==FALSE) || (strpos($oIn['post']['mask'],"E")!==FALSE)))
			web_AddErrorMsg($oOut, _LW("Mask must contain at least 'I'nternal or 'E'xternal falgs."));
		else 
		{
			$nCount = strlen($oIn['post']['mask']);
			for ($i=0; $i<$nCount; $i++)
			{
				$c = $oIn['post']['mask'][$i];
				if (!($c == 'R' || $c =='W' || $c=='1' || $c=='2' || $c=='3' || $c=='4' || $c=='5' || $c=='I' || $c=='E'))
				{
					web_AddErrorMsg($oOut, _LW("Wrong mask used, can be RW12345IE"));
					break;
				}
			}
		}
	}
	elseif ( $oIn['step'] == 2 )
	{
		$oIn['post']['idcontact_current'] = $_SESSION['iduser'];
		// add contact addition info
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_RULE_CREATE", $oIn['post'], $oTemp);
	}
	return true;
}

function web_ContactNotificationModify(&$oIn, &$oOut)
{
	if ( !is_array($oIn) )
		return false;

	if ( $oIn['step'] == 2 )
	{
		$oIn['post']['idcontact_current'] = $_SESSION['iduser'];
		// add contact addition info
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_NOTIFICATION_MODIFY", $oIn['post'], $oTemp);
	}
	return true;
}

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

	if ( isset($oIn['form_name']) )
	{
		if ($oIn['form_name'] == "GT_CONTACT_WEBLINKS") {
			$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_CONTACT, 'mask'=>'W');
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
			if ( isset($_oOut['result']) && $_oOut['result'] || $_SESSION['iduser']==$oIn['idobject'] )	
				$oOut[5][_LW("Remove")] =  array('href'=>"?action=remove&idform=".$oIn['form_name']."&id=".$oIn['id']."&redirect=page@@/web/contact/contact_prefs.php", 'onclick'=>'if (!confirm("'._LW("Are you sure?").'")) return false;');
		}
		else {
			$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_CONTACT, 'mask'=>'W');
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
			if ( isset($_oOut['result']) && $_oOut['result'] || $_SESSION['iduser']==$oIn['idobject'] )	
				$oOut[5][_LW("Remove")] =  array('href'=>"?action=remove&idform=".$oIn['form_name']."&id=".$oIn['id']."&redirect=page@@/web/contact/hide@address.com@@".$oIn['idobject'], 'onclick'=>'if (!confirm("'._LW("Are you sure?").'")) return false;');
		}
	}
	else 
	{
		$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idobject'], 'type'=>ID_SEMA_CONTACT, 'mask'=>'W');
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut=array());
		if ( isset($_oOut['result']) && $_oOut['result'] )
			$oOut[10][_LW("Modify")] = array('href'=>"?page=/web/contact/contact_form.php&idcontact=".$oIn['idobject']);
	}
	return true;
}

function web_ContactPrefsWLinksCreate(&$oIn, &$oOut) {
	if ( !is_array($oIn) )
		return false;

	if ( $oIn['step'] == 1 ) {
		if ( isset($oIn['post']['name']) && !strlen($oIn['post']['name']) )
			web_AddErrorMsg($oOut, _LW("You must input 'Name' field!"));
		if ( isset($oIn['post']['link']) && !strlen($oIn['post']['link']) )
			web_AddErrorMsg($oOut, _LW("You must input 'Link' field!"));
		if ( !isset($oIn['post']['priority']) || $oIn['post']['priority']<0 )
			web_AddErrorMsg($oOut, _LW("Value of 'Name' field must be greater or equal '0'!"));
	}
	elseif ( $oIn['step'] == 2 ) {
		$oIn['post']['idcontact_current'] = $_SESSION['iduser'];
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_PREFS_WLINKS", $oIn['post'], $oTemp);
	}
	
	return true;
}

function web_ContactPrefsEmailEncodeCreate(&$oIn, &$oOut) {
	if ( !is_array($oIn) )
		return false;
		
	if ($oIn['step']==2) {
		$oIn['post']['idcontact_current'] = $_SESSION['iduser'];
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_PREFS_EMAILENCODE", $oIn['post'], $oTemp);
	}
}

function web_ContactPrefsClientEncodeCreate(&$oIn, &$oOut) {
	if ( !is_array($oIn) )
		return false;
		
	if ($oIn['step']==2) {
		$oIn['post']['idcontact_current'] = $_SESSION['iduser'];
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_PREFS_CLIENTENCODE", $oIn['post'], $oTemp);
	}
}

function web_ContactPrefsSemaLangCreate(&$oIn, &$oOut) {
	if ( !is_array($oIn) )
		return false;
		
	if ($oIn['step']==2) {
		$oIn['post']['idcontact_current'] = $_SESSION['iduser'];
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_PREFS_SEMALANG", $oIn['post'], $oTemp);
	}
}
?>
Return current item: PushOk SEMA