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

// preapre to run
session_start();
function getmicrotime()
{ 
    list($usec, $sec) = explode(" ",microtime()); 
    return ((float)$usec + (float)$sec); 
} 
$sema_execstart = getmicrotime();

// include kernel code
require_once("lib/lib.pinc");

// initialize dispatchers
$GLOBALS['LIB_DISPATCHER'] = new lib_Dispatcher;
$GLOBALS['LIB_DISPATCHER']->Init("/lib/lib_messages.ini");

$GLOBALS['WEB_DISPATCHER'] = new lib_Dispatcher;
$GLOBALS['WEB_DISPATCHER']->Init("/web/web_messages.ini");

// initialize locale
require_once 'Translation2.php';
require_once 'I18Nv2.php';
require_once 'I18Nv2/Negotiator.php';

$neg = &new I18Nv2_Negotiator;
$params = array(
    'langs_avail_file'  => 'langs.ini',
    'domains_path_file' => 'domains.ini',
    'file_type'         => 'po',
);
$g_tr =& Translation2::factory('gettext', $params, $params);

// retrieve what we support
$ret = $g_tr->getLangs('array');
$locale_codes = array();
$locale_subs  = array();
foreach ($ret as $key => $val)
{
    array_push($locale_codes,$key);
	if (!isset($val['use']))
	    $locale_charsets[$key] = $val['meta'];
}
foreach ($ret as $key => $val)
{
	if (isset($val['use']))
	    $locale_charsets[$key] = $locale_charsets[$val['use']];
}

// check what wants explorer
$g_lang = $neg->GetLanguageMatch($locale_codes);
$g_charset = $locale_charsets[$g_lang];

// check what select user
if (isset($_SESSION['iduser']))
{
    $_oIn = array('idcontact'=>$_SESSION['iduser'], 'key'=>'web_client_encode');
    $GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_PREFERENCE_SEARCH", $_oIn, $arPrefs);
    if (isset($arPrefs['id']) && $arPrefs['id']>0)
        $g_charset = $arPrefs['value'];

    $_oIn = array('idcontact'=>$_SESSION['iduser'], 'key'=>'web_sema_lang');
    $GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_PREFERENCE_SEARCH", $_oIn, $arPrefs);
    if (isset($arPrefs['id']) && $arPrefs['id']>0)
        $g_lang = $arPrefs['value'];
}

I18Nv2::setLocale($g_lang);
$g_tr->setLang($g_lang); 
I18Nv2::autoConv($g_charset,'utf-8',true);

// well continue
require_once("./lib/enums.pinc");
require_once("./web/web.pinc");

// process get request if it is exists
if ( count($_GET) )
{
	if ( isset($_GET['action']) )
	{
		$_GET['idcontact_current'] = $_SESSION['iduser'];
		
		if ( isset($_GET['redirect']) && strlen($_GET['redirect']) )
			$_SESSION['active_page'] = str_replace("@","&",str_replace("@@","=",$_GET['redirect']));
	        
		if ( $_GET['action'] == "remove" )
		{
			if (isset($_GET['idform'])) 
				$GLOBALS['LIB_DISPATCHER']->ProcessMessage($_GET['idform'], $_GET, $oResult);
			else {
				$_GET['idcontact_current'] = $_SESSION['iduser'];
				$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_OBJECT_DELETE", $_GET, $oResult);	
			}
			web_RedirectRelative("sema.php?".$_SESSION['active_page']);
		}
		elseif ( $_GET['action'] == "filter" )
		{
			$_SESSION['last_filter'] = $_GET;
			$oIn = $_GET;
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage($_GET['idform'], $oIn, $oResult);
			// create get params for page
			web_RedirectRelative("sema.php?".$_SESSION['active_page']);
		}
		elseif ( $_GET['action'] == "modify" )
		{
			$oIn = $_GET;
			$GLOBALS['LIB_DISPATCHER']->ProcessMessage($_GET['idform'], $oIn, $oResult);
			// create get params for page
			web_RedirectRelative("sema.php?".$_SESSION['active_page']);
		}
	}
	elseif ( isset($_GET['logout']) )
	{
		$_SESSION = array();
		web_RedirectRelative("sema.php");
	}
	else
    {
        $get_url = "";
        foreach ($_GET as $key => $value)
            $get_url = $get_url.$key."=".$value."&";
		$_SESSION['active_page'] = $get_url;
    }
}	

// process post request
if ( count($_POST) )
{
	$oIn = array('step' => 1, 'post' => $_POST);
	$rc = $GLOBALS['WEB_DISPATCHER']->ProcessMessage($_POST['idform'], $oIn, $oResult);
	if ( PEAR::isError($rc) || count($oResult['error']) )
	{
		// was some error (or errors)
		$_SESSION['last_post']['data'] = $_POST;
		$_SESSION['last_post']['error'] = $oResult['error'];
		if (PEAR::isError($rc))
			web_AddErrorMsg($_SESSION['last_post'], $rc->getMessage());
		if ( isset($_POST['onerror']) && strlen($_POST['onerror']) )
			web_RedirectRelative("sema.php".$_POST['onerror']);
		else 
			web_RedirectRelative("sema.php");
	}
	else 
	{
		$oIn = array('step' => 2, 'post' => $_POST);
		$rc = $GLOBALS['WEB_DISPATCHER']->ProcessMessage($_POST['idform'], $oIn, $oResult);
		if ( (isset($rc) && PEAR::isError($rc)) || (isset($oResult['error']) && count($oResult['error'])) )
		{
			// was some error (or errors)
			$_SESSION['last_post']['data'] = $_POST;
			$_SESSION['last_post']['error'] = $oResult['error'];
			if (PEAR::isError($rc))
				web_AddErrorMsg($_SESSION['last_post'], $rc->getMessage());
			if ( isset($_POST['onerror']) && strlen($_POST['onerror']) )
				web_RedirectRelative("sema.php".$_POST['onerror']);
			else 
				web_RedirectRelative("sema.php");
		}
		else
		{
			unset($_SESSION['last_post']);
			if ( isset($_POST['onsuccess']) && strlen($_POST['onsuccess']) )
				web_RedirectRelative("sema.php".$_POST['onsuccess']);
			else 
				web_RedirectRelative("sema.php");
		}
	}
}

// not time to include layout obj (can be any)
require_once 'web/layouts/default/default.pinc';

// user _should_ be authorized
if ( isset($_SESSION['iduser']) )
{
	if ( isset($_GET['page']) && strlen($_GET['page']) )
	{
		// get page param from url
		require_once(realpath('.')."".$_GET['page']); 
	}
	else
		web_RedirectRelative("sema.php?page=/web/default.php");
}
else
{
	require_once("web/authentification.php");
}


// finalize 
if (isset($_SESSION['last_post']))
    unset ($_SESSION['last_post']);

$sema_execstoretime = isset($_SESSION['sema_execstoretime'])?$_SESSION['sema_execstoretime']:0;
$sema_exectime = $sema_execstoretime + getmicrotime() - $sema_execstart;
$sema_exectime = floor($sema_exectime*1000)/1000;

unset($_SESSION['sema_execstoretime']);

echo "<BR><FONT color=gray><CENTER>__________________________________<BR>Pushok SEMA v0.2 (C) Pushok Software 2005<BR>Page generation time is: ".$sema_exectime." s</CENTER></FONT>";
  
?>
Return current item: PushOk SEMA