<?php
session_start();
$wdt=date("Ymd");

if ($_SERVER['HTTP_HOST'] == "localhost") {

    define('LOCAL_MODE', true);

}

else {

 	define('LOCAL_MODE', false);

}



// File system path

$tmp = dirname(__FILE__);

$tmp = str_replace('\\' ,'/',$tmp);

$tmp = substr($tmp, 0, strrpos($tmp, '/'));



define('SITE_DIR_PATH', $tmp);



// include all the library files needed here

require_once(SITE_DIR_PATH."/include/config.php");

require_once(SITE_DIR_PATH."/include/crypt.php");

require_once(SITE_DIR_PATH."/include/db_class.php");
require_once(SITE_DIR_PATH."/smtp/PHPMailerAutoload.php");

require_once(SITE_DIR_PATH."/include/common_functions.php");

require_once(SITE_DIR_PATH."/include/include_functions.php");

require_once(SITE_DIR_PATH."/include/arrays.inc.php");

require_once(SITE_DIR_PATH."/include/return_functions.php");

if(strstr($_SERVER['PHP_SELF'],"/".ADMIN_DIR)){

	require_once(SITE_DIR_PATH."/".ADMIN_DIR."/admin-function.php");

}



$adminRes=getResult("admin_details"," where 1");

if (strlen($adminRes['email'])) {

	$admin_email=$adminRes['email'];

}

else {

	$admin_email="admin@yahoo.com";

}



if (strlen($adminRes['companyName'])) {

	$website_name=$adminRes['companyName'];

}

else {

	$website_name="Coupon Ming";

}



if (strlen($adminRes['name'])) {

	$admin_name=$adminRes['name'];

}

else {

	$admin_name="Admin";

}



if (strlen($adminRes['address'])) {

	$admin_address=$adminRes['address'];

}

else {

	$admin_address="";

}



define('WEBSITE_NAME',$website_name);

define('ADMINHEAD',"Admin Panel Of ".WEBSITE_NAME);

define('SCRIPT_START_TIME', getmicrotime());

define('SITE_EMAIL',$admin_email);

define('ADMIN_EMAIL',$admin_email);

define('ADMIN_NAME',$admin_name);

define('ADMIN_ADDRESS',$admin_address);

define('CURRENCY', "USD");

define('CURRENCY_SYMBOL', "$");



$_GET = ms_htmlentities(ms_trim($_GET));

$_POST = ms_htmlentities(ms_trim($_POST));

$_COOKIE = ms_htmlentities(ms_trim($_COOKIE));

$_REQUEST = ms_htmlentities(ms_trim($_REQUEST));

@extract($_GET);

@extract($_POST);



// magic_quotes_runtime needs to be "off"

if(get_magic_quotes_runtime()) {

	set_magic_quotes_runtime(0);

}



if ($handle = opendir(SITE_DIR_PATH.'/'.PLUGINS_DIR)) {

	while (false !== ($file = readdir($handle))) { 

		if ($file != "." && $file != "..") { 

			$curr_dir = SITE_DIR_PATH.'/'.PLUGINS_DIR.'/'.$file;

			if(is_dir($curr_dir)) {

				if(file_exists($curr_dir.'/plugin.php')) {

					require_once($curr_dir.'/plugin.php');

				}

			}

		}

	}

	closedir($handle);

}



$PHP_SELF=$_SERVER['PHP_SELF'];

$cur_page = basename($_SERVER['PHP_SELF']);

$admin_pos  = strpos($PHP_SELF, '/'.ADMIN_DIR.'/');


 $link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$ee=explode('/',$link);
$mm=$ee[3];
$ss=explode('.',$mm);
$cc=$ss[0]; 
$cat=str_replace("-", " ", $cc);
$cats=ucfirst($cat);
$loc_s="select * from location_tbl where locationName='$cats'";
$loc_q=mysqli_query($GLOBALS['dbcon'],$loc_s);

if(mysqli_num_rows($loc_q) > 0){

	// echo "subdomain";
	// exit;
	define('DOM_URL_PATH',SITE_URL_PATH.'/'.$cc);
	define('IS_SUB_DOMAIN', true);
	
	$last_segment = $ee[4];
	$category=explode('.',$last_segment);
	$catname=$category[0];
	$category_name=str_replace("-", " ", $catname);
	$category_name=ucfirst($category_name);
	$cat_s=mysqli_query($GLOBALS['dbcon'],"select * from category_tbl where catName='$category_name'");
	$num=mysqli_num_rows($cat_s);
}
else{
	// echo "main";
	// exit;
	define('DOM_URL_PATH',SITE_URL_PATH);
	define('IS_SUB_DOMAIN', false);
	$cat_s=mysqli_query($GLOBALS['dbcon'],"select * from category_tbl where catName='$cats'");
	$num=mysqli_num_rows($cat_s);
}

?>