Location: PHPKode > projects > TEMS -Time and Expense Management System > tems/lookup.php
<?php

/*********************************************************************************
 * TES is a Time and Expense Management program developed by
 * Initechs, LLC. Copyright (C) 2009 - 2010 Initechs LLC.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY INITECHS, INITECHS DISCLAIMS THE WARRANTY
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 *
 * You can contact Initechs headquarters at 1841 Piedmont Road, Suite 301,
 * Marietta, GA, USA. or at email address hide@address.com
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU General Public License version 3,
 * these Appropriate Legal Notices must retain the display od the "Initechs" logo.
 * If the display of the logo is not reasonably feasible for technical reasons,
 * the Appropriate Legal Notices must display the words "Powered by Initechs".

 ********************************************************************************/

$basedir = dirname(__FILE__);
require_once("$basedir/initialize.php");
require_once("$basedir/baseclass/PageController.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<link rel="stylesheet" type="text/css" media="all"
	href="css/tesglobal.css">

<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico">

<script type="text/javascript" language="JavaScript"
	src="tesbean/CalenderPopup.js"></script>

<title>Time and Expense Management System</title>

<?php

function buildJavaScript($formName, $formField)
{
	$javaCode = '';
	$javaCode .= "<script language='JavaScript'>";
	$javaCode .= "\n function pick(symbol)";
	$javaCode .= "\n {";
	$javaCode .= "\n	if (window.opener && !window.opener.closed)";
	$javaCode .= "\n		window.opener.document.{$formName}.{$formField}.value = symbol;";
	$javaCode .= "\n	window.close();";
	$javaCode .= "\n }";
	$javaCode .= "\n</script>";

	return $javaCode;
}

$formName = $_GET['form'];
$formField = $_GET['formfield'];
echo buildJavaScript($formName, $formField);

?>


<?php

class LookupPage extends PageController
{

	public function lookupRec($module, $table, $lookupField)
	{
		global $ini_array;
		global $strtime;

		$recs_per_page = $ini_array['display']['records_per_page'];
		$dateFormat = getUserDateFormat();

		$ControlDS = new ControlStructure($module, 'List');
		$DisplayControlDS = new DisplayControlStructure($ControlDS->folder, $ControlDS->searchLayout);

		$layoutArray = $DisplayControlDS->layoutArray;

		$where = '';
//		$where = $this->buildWhereClause($ControlDS, $layoutArray);
		if ($where <> '')
			$where .= " and ";
		$where .= " status < '90'";
		$start = $this->setRecordOffset();
		$sortBy = $this->buildSortBy();
		$ascdec = $this->buildAscDec();

		$Data = new dbObj();
		$TotalRecs = $Data->countRows($table, $where);
		$DataSet = $Data->listRows($table, $where, $sortBy, $ascdec, $start, $recs_per_page);
		foreach ($DataSet as $dataIndex => $dataRow)
		{
			if (array_key_exists($lookupField, $DataSet[$dataIndex]))
				$DataSet[$dataIndex]['browserec'] = "<a href=\"javascript:pick('{$dataRow[$lookupField]}')\"><img border=0 src='images/select.png'></a>";

			foreach ($dataRow as $field => $value)
			{
				if (!isset($layoutArray[$field]))
					continue;

				if (($layoutArray[$field]['fieldType'] == 'optionField')
				or ($layoutArray[$field]['fieldType'] == 'radioField'))
					$value = $layoutArray[$field]['validValues'][$value];

				if ($layoutArray[$field]['fieldType'] == 'dateField')
					$value = cvtDateIso2Dsp($value, $dateFormat);

				$DataSet[$dataIndex][$field] = $value;
			}
		}

		$navigation = $this->buildNavigation($start, $TotalRecs);
		
		$str = '';
		$str .= "\n<table id='frame' style='position:absolute; left:0px; top:0px;'>";
		$str .= "\n<tr>";
		$str .= "\n<td class='right_body'>";
		$heading = ucfirst($module) . ' :: List';
		$str .= $this->buildSearchForm($ControlDS, $layoutArray, $heading);
		$str .= "\n<div style='text-align:right'>$navigation</div>";
		$ControlDS->action = 'lookup';
		$str .= $this->showTable($ControlDS, $layoutArray, $DataSet);
		$str .= "\n<div style='text-align:right'>$navigation</div>";
		$str .= "\n</td>";
		$str .= "\n</tr>";

		$str .= "\n<tr>";
		$str .= "\n<td>";
		$timeTaken = time() - $strtime;
		settype($timeTaken, "string");

		$str .= "\n<table id='frame'  style='border:none;'>\n<tr>";
		$str .= "\n<td class='footer'>Copyright 2009-2011 Initechs, LLC.</td>";
		$str .= "\n<td class='footer'>Server response time: $timeTaken seconds.</td>";
		$str .= "\n</tr>\n</table>";

		$str .= "\n</td>";
		$str .= "\n</tr>";

		$str .= "\n</table>";

		return $str;
	}

}


?>

</head>

<body>

<?php

$strtime = time();
$module = $_GET['module'];
$table = $_GET['table'];
$field = $_GET['field'];

$page = new LookupPage();
echo $page->lookupRec($module, $table, $field);

?>

</body>
</html>
Return current item: TEMS -Time and Expense Management System