dwh/headerFile.php

136 lines
3.7 KiB
PHP
Raw Permalink Normal View History

2023-10-02 10:26:17 +00:00
<?php
include_once 'init/initialisation_parameter.php';
function checkLogin(){
if ($_SESSION['LAST_LOGIN']+SESSION_LENGTH >= mktime() && $_SESSION['KD_APPS'] === APPSID) {
$_SESSION['LAST_LOGIN'] = mktime();
$valid = 1;
} else {
if ($_SESSION['KD_USER']) {
session_destroy();
}
$valid = 0;
}
return $valid;
}
function check_session() {
$result = false;
if (!is_null($_SESSION['LAST_LOGIN'])) {
if ($_SESSION['KD_APPS'] === APPSID) {
$non_active_timelength = SESSION_LENGTH;
if ($_SESSION['LAST_LOGIN']+$non_active_timelength < mktime() ) {
session_unset();
try {
session_destroy();
} catch (Exception $e){
}
$result = false;
} else {
$_SESSION['LAST_LOGIN'] = mktime(); //updating last active
$result = true;
}
} else {
session_unset();
try {
session_destroy();
} catch (Exception $e){
}
}
}
return $result;
}
/*******************************************************************************
Function Name : format_serial
Author : Kusman Suryadi Hioe
Description : array format_serial (string $serialize_value)
Parameter : string of serialiaze value
Return : array derived from serialize value
*******************************************************************************/
function format_serial($serialize_value){
$serialize_array_value = unserialize($serialize_value);
if (is_array($serialize_array_value) && !is_null($serialize_array_value)) {
foreach ($serialize_array_value as $key => $val) {
$unserialize_array_value[$key] = $val;
}
}
return $unserialize_array_value;
}
/*******************************************************************************
Function Name : make_serial
Author : Kusman Suryadi Hioe
Description : string make_serial (array $array_value)
Parameter : array of key and value
Return : string of serialize value
*******************************************************************************/
function make_serial ($array_value) {
return serialize($array_value);
}
/*******************************************************************************
Function Name : redirect
Author : Kusman Suryadi Hioe
Description : void redirect (string $url)
Parameter : string of url address
Return : none
*******************************************************************************/
function redirect($url) {
if (!headers_sent()) {
header("Location: $url") ;
} else {
die("Headers already sent.");
}
}
function format_html_option (&$hash_table,$selected_key=null) {
include_once 'class/PregReplaceCallbackClass.php';
include_once 'init/initialisation_parameter.php';
$result = null;
//save the array address of template array addrs
$temp_template_array_addr = $_SESSION['TEMPLATE_ARRAY_ADDR'];
// assigning address of the template from include file
initOption();
$PregClass = new PregReplaceCallbackClass('');
$PregClass->SetTemplateArray('TEMPLATE_ARRAY_ADDR');
if (!empty($hash_table)) {
$PregClass->SetFormatName('OPTION_STATUS');
//assigning global variable session
$_SESSION['ARRAY_ADDR_VAR'] = &$variable_array;
foreach ($hash_table as $key => $val) {
if ($selected_key == $key) {
$variable_array['OPTION_SELECTED'] = 'SELECTED';
} else {
$variable_array['OPTION_SELECTED'] = '';
}
$variable_array['OPTION_VALUE'] = $key;
$variable_array['OPTION_NAME'] = $val;
$result .= $PregClass->PregReplaceCallback();
}
}
//restoring the session array address
$_SESSION['TEMPLATE_ARRAY_ADDR'] = $temp_template_array_addr;
return $result;
}
function initOption () {
$option_template['OPTION_STATUS'] = <<< HTML
<OPTION VALUE="<<OPTION_VALUE>>" <<OPTION_SELECTED>>><<OPTION_NAME>></OPTION>
HTML;
$_SESSION['TEMPLATE_ARRAY_ADDR'] = &$option_template;
}
?>