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

//! add second menu's items
function web_TBoardCreateSLvlMenu(&$oIn, &$oOut)
{
	if ( !is_array($oOut) )
		$oOut = array();
	$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$_SESSION['iduser'], 'type'=>ID_SEMA_CONTACT, 'mask'=>'3');
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
	if ( isset($oIn['menu_flvl']) && $oIn['menu_flvl'] == "Time board" && isset($_oOut['result']) && $_oOut['result']) 
		$oOut[5][_LW("Mark my time")] = "time_board/time_board_form.php";
	return true;
}

function web_TBoardGlobalMenuCreate(&$oIn, &$oOut)
{
	$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$_SESSION['iduser'], 'type'=>ID_SEMA_CONTACT, 'mask'=>'1');
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
	if ( isset($_oOut['result']) && $_oOut['result'] ) {
		// check has user opened time record for current day
		$_oIn = array("idcontact_current"=>$_SESSION['iduser'], "idworker"=>$_SESSION['iduser'], "end"=>"00:00:00", "date"=>date("Y-m-d"));
		$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TBOARD_SEARCH", $_oIn, $_oOut = array());
		if (isset($_oOut['tbt']) && count($_oOut['tbt'])) {
		// user already has some non closed record
			$keys = array_keys($_oOut['tbt']);
			$oOut[7][_LW("Mark TB")." ".$_oOut['tbt'][$keys[0]]['start']] = "time_board/time_board.php&action=finish";
		}
		else
			$oOut[7][_LW('Mark my arrival')] = "time_board/time_board.php&action=start";
	}
}

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

	$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$oIn['idworker'], 'type'=>ID_SEMA_TBOARD, 'mask'=>'3');
	$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut=array());
	if ( isset($_oOut['result']) && $_oOut['result'] ) {
		$oOut[10][_LW("edit")] = array('href'=>"?page=/web/time_board/time_board_form.php&id=".$oIn['idobject']);
		$oOut[10][_LW("del")] =  array('href'=>"?action=remove&idobject=".$oIn['idobject']."&type=".constant("ID_SEMA_TBOARD")."&redirect=page@@/web/time_board/time_board_main.php", 'onclick'=>'if (!confirm("'._LW("Are you sure?").'")) return false;');
	}
	return true;
}

function web_TBoardCreate(&$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']['date']) && !strlen($oIn['post']['date']) )
			web_AddErrorMsg($oOut, _LW("You must input 'Date'!"));
			
		if ( isset($oIn['post']['start']) && !strlen($oIn['post']['start']) )
			web_AddErrorMsg($oOut, _LW("You must input 'Start'!"));
			
		if ( isset($oIn['post']['end']) && !strlen($oIn['post']['end']) )
			web_AddErrorMsg($oOut, _LW("You must input 'End'!"));
			
		if ( isset($oIn['post']['idworker']) && !strlen($oIn['post']['idworker']) )
			web_AddErrorMsg($oOut, _LW("You must input 'Worker'!"));
		return true;
	}
	elseif ( $oIn['step'] == 2 )
	{
		$oIn['post']['idcontact_current'] = $_SESSION['iduser'];

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

function web_TBoardWorkDayUpdate(&$oIn, &$oOut) {
	if ( $oIn['step'] == 1 )
		return true;
	elseif ( $oIn['step'] == 2 )
	{
		$oIn['post']['idcontact_current'] = $_SESSION['iduser'];
		return $GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TBOARD_UPDATEWORKDAY", $oIn['post'], $oOut);
	}
	return PEAR::raiseError("FILE: \"".__FILE__."\" LINE: \"".__LINE__."\" MSG: \""._LW("Bad params!")."\"", E_USER_ERROR);
}
//================================================================================================================
// process some get params
if (isset($_GET) && count($_GET)) {
	if (isset($_GET['action']) && $_GET['action'] != "") {
		// switch what to do
		switch ($_GET['action']) {
			case "start":
				$_oIn = array('idcontact_current' => $_SESSION['iduser']);
 				$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TBOARD_START", $_oIn, $_oOut = array());
				break;
			case "finish":
				$_oIn = array('idcontact_current' => $_SESSION['iduser']);
 				$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TBOARD_FINISH", $_oIn, $_oOut = array());
				break;
		}
		web_RedirectRelative("sema.php");
	}
}
?>
Return current item: PushOk SEMA