Location: PHPKode > projects > TEMS -Time and Expense Management System > tems/baseclass/PageSection.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/baseclass/PageElement.php");
require_once("$basedir/baseclass/GetAuthorization.php");
require_once("$basedir/systemconfig/controllerstructure.php"); // Needed in showAddlButtons method - Kallol.

abstract class PageSection extends PageElement {

    public function __construct() {
        if (!isUserRegistered()) {
            throw new Exception('er0006');
        }
    }
    
    public function getReportHtmlHead ()
    {
    	$str = '';
    	
    	$str .= '<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" src="../tesbean/html2pdf.js"></script>
					<title>Time and Expense Management System</title>
				</head>';
    	
    	return $str;
    }
    
    public function getScreenHtmlHead ()
    {
    	$str = '';
    	
    	$str .= '<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" src="tesbean/jquery-1.4.2.min.js"></script>
        	<script type="text/javascript" src="tesbean/OnScreenSearch.js"></script>
        	<script type="text/javascript" language="JavaScript" src="tesbean/CalenderPopup.js"></script>

        	<title>Time and Expense Management System</title>
    	</head>';
        	
    	return $str;
    }
    

    protected function showPageWithData($ControlDS, $DisplayControlDS, $heading='') {
        $str = '';
        $str .= $this->setHeading($DisplayControlDS->heading);

        $buttons = $this->showStdButtons($DisplayControlDS, $ControlDS);
        $linkButton = $this->showAddlButtons($DisplayControlDS, $ControlDS);

        if ($ControlDS->callOnSubmit <> '') {
            $str .= "\n<form name='{$ControlDS->formName}' method='{$ControlDS->method}' action='{$ControlDS->callOnSubmit}' enctype='multipart/form-data' accept-charset='UTF-8'>";
            if (strtolower($DisplayControlDS->buttonPlace) <> 'bottom')
                $str .= "\n<div class='button'> $buttons </div>";
        }

        if ((strtolower($DisplayControlDS->buttonPlace) <> 'bottom')
                and ($linkButton <> ''))
            $str .= "\n<div class='button'> $linkButton </div>";

        $str .= $this->makeFormData($ControlDS, $DisplayControlDS);
        $str .= $this->makeAddlFormData($ControlDS, $DisplayControlDS);
        $msg = $this->showMessage();
        if ($msg <> '')
            $str .= "\n<table id='form'><tr><td style='border:none;'>{$msg}</td></tr></table>";

        if ((strtolower($DisplayControlDS->buttonPlace) <> 'top')
                and ($linkButton <> ''))
            $str .= "\n<div class='button'> $linkButton </div>";

        if ($ControlDS->callOnSubmit <> '') {
            if (strtolower($DisplayControlDS->buttonPlace) <> 'top')
                $str .= "\n<div class='button'> $buttons </div>";
            $str .= "\n</form>";
        }

        if ((isset($DisplayControlDS->helptext))
                and ($DisplayControlDS->helptext != ''))
            $str .= "\n<table id='form'><tr><td style='border:none;'>{$DisplayControlDS->helptext}</td></tr></table>";

        $errorMsg = $this->fieldError('nocategory');
        if ($errorMsg <> '')
            $str .= "\n<table id='form'><tr><td style='border:none;'>{$errorMsg}</td></tr></table>";

        return $str;
    }

    protected function makeFormData($ControlDS, $DisplayControlDS) {
        $hiddenFieldArray = array();

        $str = '';

        $str .= "\n\t<table id = 'form'>";

        foreach ($DisplayControlDS->layoutArray as $fieldName => $fieldDetail) {
            $fieldType = $fieldDetail['fieldType'];
            $fieldAction = $fieldDetail['displayType'];

            if ((array_search($fieldName, $ControlDS->parent_keys) !== false)
                    and (isset($_SESSION['parentkey'][$ControlDS->module][$fieldName]))
                    and ($_SESSION['parentkey'][$ControlDS->module][$fieldName]) <> '')
                $fieldAction = 'protected';

            if ($fieldAction == 'hidden') {
                $hiddenFieldArray[] = $fieldName;
                continue;
            }

            $fieldAtrb = '';
            if (($fieldAction <> 'editable')
                    and ($fieldAction <> 'haveselect'))
                $fieldAtrb = 'disabled';

            $addlStr = '';
            if ($fieldType == 'dateField' and $fieldAction <> 'editable')
                $addlStr = 'NOCAL';
            if ($fieldType == 'optionField')
                $addlStr = $fieldDetail['validValues'];
            if ($fieldType == 'radioField')
                $addlStr = $fieldDetail['validValues'];

            $field_value = $this->postValue($fieldName);
            $str .= "\n<tr>";

            $fieldAction == 'viewonly' ? $class = 'label_display' : $class = 'label_entry';
            $fieldLabel = ucfirst($fieldDetail['label']);
            $str .= "\n<td class='{$class}'>$fieldLabel:</td>";

            $fieldAction == 'viewonly' ? $class = 'field_display' : $class = 'field_entry';
            $str .= "\n\t<td class='{$class}'>";
            $str .= "{$this->$fieldType($fieldName, $field_value, $fieldDetail['displaysize'], $fieldDetail['fieldlen'], $fieldAction, $fieldAtrb, $addlStr, $fieldDetail, $ControlDS)}";

            if ($fieldAction == 'protected')
                $str .= "\n\t{$this->hiddenField($fieldName, $fieldType)}";

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

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

        foreach ($hiddenFieldArray as $fieldName)
            $str .= "\n{$this->hiddenField($fieldName)}";

        return $str;
    }

    protected function makeAddlFormData($ControlDS, $DisplayControlDS) {
        return;
    }

    protected function showStdButtons($DisplayControlDS, $ControlDS) {
        $uid = isset($_GET['uid']) ? $_GET['uid'] : '';
        $auth = new userauthorization();

        $str = '';

        if (isset($DisplayControlDS->buttonArray)) {
            $index = 0;
            $button_array = $DisplayControlDS->buttonArray;
            while (($button_element = $button_array[$index++]) != null) {
                $heading = changeLiteral($button_element['heading']);
                if (strtolower($button_element['type']) == 'submit') {
                    if ($auth->checkauthority_for_display($ControlDS, $uid))
                        $str .= "\n<input type='submit' value='$heading'>";
                }
                else
                    $str .= "\n<input type='{$button_element['type']}' value='$heading'>";
            }
        }
        else {
            if ($auth->checkauthority_for_display($ControlDS, $uid)) {
                $buttonHeading = changeLiteral('Submit');
                $str .= "\n<input type='submit' value='$buttonHeading'>";
            }
            $buttonHeading = changeLiteral('Refresh');
            $str .= "\n<input type='reset' value='$buttonHeading'>";
            $buttonHeading = changeLiteral('Go Back');
            $str .= "\n<input type='button' value='$buttonHeading' onclick='window.history.go(-1)'>";
        }
        return $str;
    }

    protected function showAddlButtons($DisplayControlDS, $ControlDS) {
        global $config_array;

        if ($DisplayControlDS->addlButtonArray == null)
            return '';

        $dateFormat = getUserDateFormat();
        $auth = new userauthorization();
        $str = '';
        $index = 0;

        $link_array = $DisplayControlDS->addlButtonArray;
        while (($link_element = $link_array[$index++]) != null) {
            $link_module = $link_element['module'];
            $link_action = $link_element['action'];
            if (isset($link_element['conditionalValues'])) {
                $link_condition = explode("=", $link_element['conditionalValues'], 2);
                $field_value = $this->postValue(trim($link_condition[0]));
                if (strpos(trim($link_condition[1]), $field_value) === false)
                    continue;
            }
            if (!$auth->isauthorized_record_level($link_module, $link_action))
                continue;

            $parmKeyValue = "&uid={$_SESSION['postdata']['uid']}&load=Yes";
            if (isset($link_element['filter_keys'])) {
                $parmKeyValue = "";
                foreach ($link_element['filter_keys'] as $fieldName) {
                    $field_value = $this->postValue($fieldName);
                    if ($DisplayControlDS->layoutArray[$fieldName]['fieldType'] == 'dateField')
                        $field_value = cvtDateIso2Dsp($field_value, $dateFormat);
                    $parmKeyValue .= "&$fieldName=$field_value";
                }
            }

            $buttonHeading = changeLiteral($link_element['heading']);
            $pgm = "index.php";
            if (isset($config_array[$link_module]['actions'][$link_action]['callProgram']))
                $pgm = $config_array[$link_module]['actions'][$link_action]['callProgram'];
            $str .= "\n<input type='button' value='$buttonHeading' onclick=\"addlButton('$pgm', '$link_module', '$link_action', '$parmKeyValue')\">";
        }
        return $str;
    }

    protected function buildSearchForm($ControlDS, $displayLayout, $heading='') {

        $searchStr = '';
        $searchStr .= $this->setHeading($heading);

        if ($displayLayout == '')
            return $searchStr;

        $searchStr .= "\n<form name='{$ControlDS->formName}' method='get'>";
        foreach ($_GET as $key => $value) {  // To set the module and action part of the get parameters
            if ((!array_key_exists($key, $displayLayout))
                    and ($key <> 'offset'))
                $searchStr .= "\n<input type='hidden' name=$key value=$value>";
        }

        $searchStr .= "\n<table id = 'searchform'>";

        foreach ($displayLayout as $fieldName => $fieldDetail) {
            $attribute = '';
            if ((array_search($fieldName, $ControlDS->parent_keys) !== false)
                    and isset($_SESSION['parentkey'][$ControlDS->module][$fieldName])
                    and ($_SESSION['parentkey'][$ControlDS->module][$fieldName]) <> '')
                $attribute = 'disabled';

            $fieldType = $fieldDetail['fieldType'];
            $fieldAction = $fieldDetail['displayType'];

            $action = strtolower($ControlDS->action);
            $addlStr = '';
            if ($fieldType == 'dateField' and $fieldAction <> 'editable')
                $addlStr = 'NOCAL';

            if ($fieldType == 'optionField') {
                $addlStr = $fieldDetail['validValues'];
                $addlStr['*'] = '-- All --';
            }

            if ($fieldType == 'radioField') {
                $addlStr = $fieldDetail['validValues'];
                $addlStr['*'] = 'All';
            }

            $searchStr .= "\n<tr>";
            $searchStr .= "\n\t<td class='label_display'>{$fieldDetail['label']}:</td>";

            $searchStr .= $fieldDetail['fieldType'] <> 'radioField' ?  "\n\t<td>" : "\n\t<td style='padding-left: 0px;'>";

            $searchStr .= "{$this->searchField($fieldName, $fieldDetail, $fieldAction, $attribute, $addlStr, $ControlDS)}";

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

        $searchStr .= "\n<tr>";
        $searchStr .= "\n\t<td>&nbsp;</td>";
        $buttonHeading = changeLiteral('Search');
        $searchStr .= "\n\t<td><table><tr><td><input type='submit' value='$buttonHeading'></td>".$this->moreButtons($ControlDS, $displayLayout)."</tr></table></td>";
        $searchStr .= "\n</tr>";
        $searchStr .= "\n</table>";
        $searchStr .= "\n</form>";

        return $searchStr;
    }

    protected function moreButtons($ControlDS, $displayLayout) {
        return '&nbsp;';
    }

    protected function showTable($ControlDS, $displayLayout, $dataSet, $navigation='', $heading='') {
        $dateFormat = getUserDateFormat();

        $listStr = '';
        if ($navigation <> '')
            $listStr .= "\n<div style='text-align:right'>$navigation</div>";

        if ($heading <> '')
            $listStr .= $heading;
        $listStr .= "\n<table id = 'list'>";
        $listStr .= "\n<tr>";
        $listStr .= "\n\t<th>&nbsp;</th>";

        foreach ($displayLayout as $colName => $colDetail) {
            $listStr .= "\n\t<th style='text-align:{$colDetail['displayType']}'>";
            if ((isset($colDetail['sort'])
                    and strtolower($colDetail['sort'])) <> 'no')
                $listStr .= $this->showColumnHdg($colDetail['label'], $colName, $ControlDS->action);
            else
                $listStr .= "{$colDetail['label']}";
            $listStr .= "</th>";
        }

        $listStr .= "\n</tr>";

        $rowStyle = "";
        foreach ($dataSet as $key => $row) {
            $rowStyle == "alt" ? $rowStyle = "" : $rowStyle = "alt";
            if ($rowStyle == "alt")
                $listStr .= "\n<tr class=$rowStyle>";
            else
                $listStr .= "\n<tr>";

            $listStr .= "\n\t<td>{$row['browserec']}</td>";

            foreach ($displayLayout as $fieldName => $colDetail) {
                $listStr .= "\n\t<td style='text-align:{$colDetail['displayType']}'>$row[$fieldName]</td>";
            }

            $listStr .= "\n</tr>";
        }

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

        if ($navigation <> '')
            $listStr .= "\n<div style='text-align:right'>$navigation</div>";

        return $listStr;
    }

    protected function showColumnHdg($heading, $field, $action) {
        $base_uri = strtolower($action) == 'lookup' ? "lookup.php?" : "index.php?";

        foreach ($_GET as $key => $value) {
            if (($key <> 'sort')
                    and ($key <> 'ascdec')
                    and ($key <> 'offset'))
            {
                $value = urlencode($value);
                $base_uri .= $key == 'module' ? "$key=$value" : "&$key=$value";
            }
        }

        $str = "<a href=$base_uri&sort=$field";
        $sortBy = $this->buildSortBy();
        $ascdec = $this->buildAscDec();

        $offset = 0;
        if (($sortBy == $field)
                and (isset($_GET['offset'])))
            $offset = $_GET['offset'];

        if (($sortBy == $field)
                and ($ascdec == ''))
            $str .= "&ascdec=desc&offset=$offset>$heading<img border=0 src='images/up.png'>";
        else
            $str .= "&offset=$offset>$heading<img border=0 src='images/down.png'>";

        $str .= "</a>";
        return $str;
    }

    protected function buildNavigation($start, $TotalRecs) {

        global $ini_array;
        $recs_per_page = $ini_array['display']['records_per_page'];
        $next = changeLiteral('Next');
        $previous = changeLiteral('Previous');

        $navstr = '';
        $ustart = $start + 1;

        $offset = (($start + $recs_per_page) > $TotalRecs) ? $TotalRecs : $start + $recs_per_page;
        $navstr .= "($ustart - $offset) of $TotalRecs ";

        stristr($_SERVER['REQUEST_URI'], 'lookup.php') === false ? $base_uri = "index.php?" : $base_uri = "lookup.php?";

        foreach ($_GET as $key => $value) {
            if ($key <> 'offset') {
                $base_uri .= $key == 'module' ? "$key=$value" : "&$key=$value";
            }
        }

        $offset = $start - $recs_per_page;
        if ($start != 0)
            $navstr .= "<a href=$base_uri&offset=$offset>< $previous</a>&nbsp";

        $offset = $start + $recs_per_page;
        if ($offset < $TotalRecs) {
            if ($start != 0)
                $navstr .= "|&nbsp;";
            $navstr .= "<a href=$base_uri&offset=$offset>$next ></a>&nbsp;";
        }

        return $navstr;
    }

    protected function setHeading($heading='') {
        $heading = changeLiteral($heading);
        $str = "\n<div class='in_page_nav'>$heading</div>";
        return $str;
    }

}

?>
Return current item: TEMS -Time and Expense Management System