File: /home/barbeatleanalyti/www/manage.beatleanalytics.com/dispatcher.php 6-9-2018
<?php
/*
Project Name : Staffing Management System
@Summary: Main loading file. Execution of all pages starts here except index page
@version: 1.0
*/
//if(!ob_start("ob_gzhandler")) ob_start();
#Initialize session data
//flush();
//ob_start();
session_destroy();
error_reporting(0);
session_start();
$LOADDISPATCHER = YES;
include_once("site/include/config.php");
include_once("site/include/dbClass.php");
require_once("site/include/storeconfig.php");
$objDB = new MySQLCN;
MySQLCN::$objDB = $objDB;
$storeconfig = new storeconfig;
$storeconfigdata = $storeconfig->find_storeid();
if(count($storeconfigdata) > 0)
{
$StoreName = $storeconfigdata[0]['StoreName'];
$StoreDisplayName = $storeconfigdata[0]['StoreDisplayName'];
}
require_once("site/include/functions.php"); # Function file
$objDB->ClientID = FetchClientID();
$objDB->MasterAdminID = FetchMasterAdminID();
$blockedIP = check_blocked_visit_ip();
$request_uri_info = @parse_url(stripslashes(func_get_request_uri()));
$dispatched_request = preg_replace('/^'.preg_quote(DIRECTORY."/", '/').'/', '', $request_uri_info['path']);
$dispatched_request = rtrim($dispatched_request, "/");
// REMOVE IF NOT WORKING
$dispatched_request = ltrim($dispatched_request, "/");
if(!strstr($dispatched_request, ".php") && !strstr($dispatched_request, ".html"))
$errorcount = 1;
else
$errorcount = 0;
$dispatched_request = preg_replace("/\.html$/i", '', $dispatched_request);
$accesspath = str_replace(DIRECTORY, "", $dispatched_request);
$query = $request_uri_info['query'];
$query = explode("&", $query); //echo "<pre>"; print_r($query); echo "</pre>";exit;
for($i=0; $i < count($query); $i++)
{
if($query[$i] != "")
{
$args = explode("=",$query[$i]);
${$args[0]} = urldecode($args[1]);
}
}
if($errorcount == 1)
{
//$pg="error";
include("index.php");
exit;
}
if(isPartUppercase($accesspath))
{
header ('HTTP/1.1 301 Moved Permanently');
if(strstr($accesspath, ".php"))
$RURL = strtolower($accesspath);
else
$RURL = strtolower($accesspath).".html";
header("Location:".SERVER_ROOT.$RURL);
exit;
}
$SQL = "SELECT NewURL, RedirectType, Comments FROM url_redirect WHERE URL = '".$accesspath.".html' AND Status = 'Y'";
$res = $objDB->select($SQL);
if(count($res) > 0)
{
$comment = $res[0]['Comments'];
$referer = $_SERVER['HTTP_REFERER'];
if (strpos($comment, $referer) === false)
{
$comment .= "\n";
$comment .= trim(addslashes($referer));
}
$RURL = $res[0]['NewURL'];
if($res[0]['RedirectType'] == "301")
header ('HTTP/1.1 301 Moved Permanently');
else if($res[0]['RedirectType'] == "302")
header ('HTTP/1.1 302 Moved Temporarily');
$SQL = "UPDATE url_redirect SET LastVisit = now(), Comments = '".$comment."', TotalCount = TotalCount + 1 WHERE URL = '".$accesspath.".html'";
$res = $objDB->sql_query($SQL);
header("Location:".SERVER_ROOT.$RURL);
exit;
}
if($accesspath == "index.php" || $accesspath == "index" || $accesspath == "")
{
if(!isset($pg))
$pg = "login";
include("index.php");
exit;
}
if($accesspath == 'price-range' && (isset($StartPrice) && isset($EndPrice))){
$_SESSION['StartPrice'] = $StartPrice;
$_SESSION['EndPrice'] = $EndPrice;
header('Location: '.SERVER_ROOT.'price-range.html');
}
if(file_exists("site/template/".$accesspath.".php") && $accesspath != "index")
{
$pg = $accesspath;
$SQL = "SELECT * FROM content WHERE SEName = '".$accesspath."' AND Status = 'Yes'";
$res = $objDB->select($SQL);
if(count($res) > 0)
{
if($res[0]['SEName'] != $accesspath && $res[0]['SEName'] != $accesspath.".html")
{
header ('HTTP/1.1 301 Moved Permanently');
$RURL = $res[0]['SEName'];
header("Location:".SERVER_ROOT.$RURL);
exit;
}
if($blockedIP == false)
{
$SQL = "UPDATE content SET TotalVisit = TotalVisit + 1 WHERE ContentID = ".$res[0]['ContentID'];
$res = $objDB->sql_query($SQL);
}
$MetaKeywords = $res[0]['SEKeywords'];
$PageTitle = $res[0]['SETitle'];
$MetaDescription = $res[0]['SEDescription'];
}
$PageName = str_replace("_", " ", $accesspath);
include("index.php");
exit;
}
$SQL = "SELECT * FROM content WHERE SEName = '".$accesspath."' AND Status = 'Yes'";
$res = $objDB->select($SQL);
if(count($res) > 0)
{
if($res[0]['SEName'] != $accesspath && $res[0]['SEName'] != $accesspath.".html")
{
header ('HTTP/1.1 301 Moved Permanently');
$RURL = $res[0]['SEName'];
header("Location:".SERVER_ROOT.$RURL);
exit;
}
else
{
$PageName = $res[0]['TopicName'];
$PageSEName = $res[0]['SEName'];
$Description = $res[0]['Description'];
$MetaKeywords = $res[0]['SEKeywords'];
$PageTitle = $res[0]['SETitle'];
$MetaDescription = $res[0]['SEDescription'];
}
if($blockedIP == false)
{
$SQL = "UPDATE content SET TotalVisit = TotalVisit + 1 WHERE ContentID = ".$res[0]['ContentID'];
$res = $objDB->sql_query($SQL);
}
$pg = "cms";
include("index.php");
exit;
}
if($accesspath == "index" && !isset($pg))
{
$pg = "home";
include(SERVER_ROOT."index.php");
exit;
}
//$pg = "error";
include("index.php");
exit;
function func_get_request_uri() {
if (isset($_SERVER['REQUEST_URI'])) {
return $_SERVER['REQUEST_URI'];
}
if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
return $_SERVER['HTTP_X_ORIGINAL_URL'];
} else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
return $_SERVER['HTTP_X_REWRITE_URL'];
}
if (isset($_SERVER['PATH_INFO']) && !zerolen($_SERVER['PATH_INFO'])) {
if ($_SERVER['PATH_INFO'] == $_SERVER['PHP_SELF']) {
$request_uri = $_SERVER['PHP_SELF'];
} else {
$request_uri = $_SERVER['PHP_SELF'] . $_SERVER['PATH_INFO'];
}
} else {
$request_uri = $_SERVER['PHP_SELF'];
}
# Append query string
if (isset($_SERVER['argv']) && isset($_SERVER['argv'][0]) && !zerolen($_SERVER['argv'][0])) {
$request_uri .= '?' . $_SERVER['argv'][0];
} else if (isset($_SERVER['QUERY_STRING']) && !zerolen($_SERVER['QUERY_STRING'])) {
$request_uri .= '?' . $_SERVER['QUERY_STRING'];
}
return $request_uri;
}
function zerolen() {
foreach (func_get_args() as $arg) {
if (strlen($arg) == 0) return true;
}
return false;
}
function isPartUppercase($string) {
return (bool) preg_match('/[A-Z]/', $string);
}
?>