<?php error_reporting(E_ALL & ~E_NOTICE); 
error_reporting(E_ALL ^ E_WARNING); 
ob_start(); 
$links = $_SERVER['PHP_SELF'];
$pattern = "/admin/";
$match = preg_match($pattern, $links);

set_time_limit(5625); 
	$timezone = "Asia/Kolkata"; 
	date_default_timezone_set ($timezone);
	$domain=$_SERVER['HTTP_HOST'];
$_SESSION['ProJectNa']='ADM'; 
define('DEBUG', '0');
define('PRJ_HEADING', 'NEW PROJECT');
define('PRJ_SESSION_ID_PREF', 'TRUINFBk_');
$sess_mast=$_SESSION['SalTSeSSId'];
if($sess_mast==''){
	$salt="Y";
	$Allowed_Chars ='ABCDEFGHKMNPQSTUZ';
	$Chars_Len = 12;
	$Salt_Length = 6;
	$mysql_date = date( 'Y-m-d' );

	for($i=0; $i<$Salt_Length; $i++)
		{
			$salt .= $Allowed_Chars[mt_rand(0,$Chars_Len)];
		}
	$_SESSION['SalTSeSSId']=$salt;
	define('SESS_MASTER', $salt);
	}else{
		define('SESS_MASTER', $_SESSION['SalTSeSSId']);
     }

$praums=SESS_MASTER."".$_SESSION['ProJectNa'];
define('ADD_TAG', $praums);
include("coredb.php");

  if(DB_NAME ==""){
	if($match == 1){
		header("Location:../installation/theme-activate-panel.php");
   }else{
		 header("Location:./installation/theme-activate-panel.php");
   }
	
  }else{
  	try {
    $conn = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8', DB_USER, DB_PASS);
 		$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
		$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
		$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
		$conn->setAttribute( PDO::MYSQL_ATTR_INIT_COMMAND , "SET NAMES utf8" );
		//$conn->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'");
		$conn->query('SET NAMES utf8');
		 
	 
    }
catch(PDOException $e)
    {
    echo $e->getMessage();
    }
  }

function getNamRandomStringe($n) { 
    $characters = 'abcefgkmnpqrstuvwxyz'; 
    $randomString = ''; 
  
    for ($i = 0; $i < $n; $i++) { 
        $index = rand(0, strlen($characters) - 1); 
        $randomString .= $characters[$index]; 
    } 
  
    return $randomString; 
} 
  
  
 function interpolateQuery($sql_string, array $params = null){
     if (!empty($params)) {
        $indexed = $params == array_values($params);
        foreach($params as $k=>$v) {
            if (is_object($v)) {
                if ($v instanceof \DateTime) $v = $v->format('Y-m-d H:i:s');
                else continue;
            }
            elseif (is_string($v)) $v="'$v'";
            elseif ($v === null) $v='NULL';
            elseif (is_array($v)) $v = implode(',', $v);

            if ($indexed) {
                $sql_string = preg_replace('/\?/', $v, $sql_string, 1);
            }
            else {
                if ($k[0] != ':') $k = ':'.$k; //add leading colon if it was left out
                $sql_string = str_replace($k,$v,$sql_string);
            }
        }
    }
    return $sql_string;
}
  
 function secureSuperGlobalPOST($key)
    {  
	if(is_array($key)){
		$valrets= $value;
		}else{
			$return = '';
			for($i = 0; $i < strlen($key ); ++$i) {
				$char = htmlspecialchars($key[$i], ENT_QUOTES, 'UTF-8');
				$ord = ord($char);
				if($char !== "'" && $char !== "\"" && $char !== '\\' && $ord >= 32 && $ord <= 126)
					$return .= $char;
				else
					$return .= '';
			}
   $valrets= $return;  
		}
		
		return $valrets;
    }


function ipCheck() {
	$domain=$_SERVER['HTTP_HOST'];
if($domain!='localhost'){ 	
		if (getenv('HTTP_CLIENT_IP')) {
			$ip = getenv('HTTP_CLIENT_IP');
		}
		elseif (getenv('HTTP_X_FORWARDED_FOR')) {
			$ip = getenv('HTTP_X_FORWARDED_FOR');
		}
		elseif (getenv('HTTP_X_FORWARDED')) {
			$ip = getenv('HTTP_X_FORWARDED');
		}
		elseif (getenv('HTTP_FORWARDED_FOR')) {
			$ip = getenv('HTTP_FORWARDED_FOR');
		}
		elseif (getenv('HTTP_FORWARDED')) {
			$ip = getenv('HTTP_FORWARDED');
		}
		else {
			$ip = $_SERVER['REMOTE_ADDR'];
		}
}else{
	$ip ='127.0.0.1';
	}
		return $ip;
	}



function rand_string( $length ) {
	$chars = "ADEFGHRSTUXYZ";	// IJKLMNOPQ VW BC NOT INCLUDED

	$size = strlen( $chars );
	for( $i = 0; $i < $length; $i++ ) {
		$str .= $chars[ rand( 0, $size - 1 ) ];
	}

	return $str;
}

function total_coupan($brand_name){
    global $conn;
    

	$sqlcon = "SELECT * FROM coupon ";

	if($brand_name != "All"){

		$sqlcon = $sqlcon." WHERE from_site = '$brand_name'";

	}
	 
   	$myquerycon=$conn->query($sqlcon);
	$mydaracon= $myquerycon->fetchAll()  ;
	
	$rows_foundcon = $myquerycon->rowCount();


	return $rows_foundcon ;
	

}

function total_company(){
    global $conn;
    

	$sqlcon = "SELECT DISTINCT from_site FROM coupon";


	 
   	$myquerycon=$conn->query($sqlcon);
	$mydaracon= $myquerycon->fetchAll()  ;
	
	$rows_foundcon = $myquerycon->rowCount();


	return $rows_foundcon ;

}


function total_brand($brand_name){
    global $conn;
    
    
	$sqlcon = "SELECT DISTINCT brand_name FROM brand_master";

	if($brand_name != "All"){
		$brand_name = secureSuperGlobalPOST($brand_name);

		$sqlcon = $sqlcon." WHERE brand_name = '$brand_name'";

	}
	 
   	$myquerycon=$conn->query($sqlcon);
	$mydaracon= $myquerycon->fetchAll()  ;
	
	$rows_foundcon = $myquerycon->rowCount();


	return $rows_foundcon ;

}

function total_products(){
     global $conn;
    

	$sqlcon = "SELECT * FROM product_master ";

	
	 
   	$myquerycon=$conn->query($sqlcon);
	$mydaracon= $myquerycon->fetchAll()  ;
	
	$rows_foundcon = $myquerycon->rowCount();


	return $rows_foundcon ;

}

function products_count($company_name){
     global $conn;
    

	$sqlcon = "SELECT company_name FROM product_master";

	if($brand_name != "All"){
		$product_name = secureSuperGlobalPOST($product_name);

		$sqlcon = $sqlcon." WHERE company_name = '$company_name'";

	}
	 
   	$myquerycon=$conn->query($sqlcon);
	$mydaracon= $myquerycon->fetchAll()  ;
	
	$rows_foundcon = $myquerycon->rowCount();


	return $rows_foundcon ;
}


function total_merchant(){
     global $conn;
    

	$sqlcon = "SELECT * FROM vendor_master ";

	
	 
   	$myquerycon=$conn->query($sqlcon);
	$mydaracon= $myquerycon->fetchAll()  ;
	
	$rows_foundcon = $myquerycon->rowCount();


	return $rows_foundcon ;

}

function total_store(){
    global $conn;
    
    
	$sqlcon = "SELECT DISTINCT store_name FROM store_master";

	
	 
   	$myquerycon=$conn->query($sqlcon);
	$mydaracon= $myquerycon->fetchAll()  ;
	
	$rows_foundcon = $myquerycon->rowCount();


	return $rows_foundcon ;

}

function affiliate_company(){
    global $conn;
    

	$sqlcon = "SELECT DISTINCT from_site  FROM coupon";
	 
   	$myquerycon=$conn->query($sqlcon);
	$mydaracon= $myquerycon->fetchAll()  ;
	
	$rows_foundcon = $myquerycon->rowCount();


	return $mydaracon ;

}


function affiliate_brand(){
    global $conn;
    

	$sqlcon = "SELECT DISTINCT company_name  FROM coupon";
	 
   	$myquerycon=$conn->query($sqlcon);
	$mydaracon= $myquerycon->fetchAll()  ;
	
	$rows_foundcon = $myquerycon->rowCount();


	return $mydaracon ;

}

function affiliate_product(){
    global $conn;
    

	$sqlcon = "SELECT DISTINCT company_name  FROM product_master";
	 
   	$myquerycon=$conn->query($sqlcon);
	$mydaracon= $myquerycon->fetchAll()  ;
	
	$rows_foundcon = $myquerycon->rowCount();


	return $mydaracon ;

}


function total_categories(){
	 global $conn;
	$sqlcatno = "SELECT category FROM  category_master";
$myquerycatno=$conn->query($sqlcatno);
$mydaracatno= $myquerycatno->fetchAll()  ;
$rows_foundcatno = $myquerycatno->rowCount();
return $rows_foundcatno ;
}


$sqlcon = "SELECT * FROM google_code";
    
      $myquerycon=$conn->query($sqlcon);
   $mydaracon= $myquerycon->fetchAll()  ;
   
   $rows_foundcon = $myquerycon->rowCount();
    if($rows_foundcon==0){
        $stat='0';
    }else{
         $stat='1';
    }

      foreach( $mydaracon as $rowcon ) {
            $gog_id  = $rowcon['rowId'];
            $google_addis  = $rowcon['google_addis'];
            $google_adfeed = $rowcon['google_adfeed'];
            $google_adar   = $rowcon['google_adar'];
            $google_ad4 = $rowcon['google_ad4'];
            $google_ana = $rowcon['google_ana'];
             $adimg1  = $rowcon['adimg1'];
            $adimg2  = $rowcon['adimg2'];
            $adimg3  = $rowcon['adimg3'];
            $adimg4  = $rowcon['adimg4'];
         
      }
 
  $sql = "SELECT * FROM admin_master ";
   
    $myquery=$conn->query($sql);
  $mydara= $myquery->fetchAll()  ;
  
  $rows_found = $myquery->rowCount();
  foreach ($mydara as $key ) {
     $emailid= $key['emailid'];
     $full_name= $key['full_name'];
     $mobileno= $key['mobileno'];
     $city = $key['location_city'];
     $state= $key['location_state'];
     $country= $key['location_country'];
     $profile_pic = $key['profile_pic'];
     $company_name = $key['company_name'];
     $company_logo = $key['company_logo'];
     $copyright = $key['copyright'];
      $freshdesk_url  = $key['freshdesk_url'];
      $purchase_code  = $key['purchase_code'];
         
  }


$actual_link = "https://".$_SERVER['HTTP_HOST'];
	

 $base_link = "https://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
//echo $base_link;
/*##################ALL BASIC FUNCIONS OF ##contactus## STARTS ####################*/
/*########################################################*/
        

/*##################ALL BASIC FUNCIONS OF ##blogcomment## ENDS ####################*/

/*##################ALL BASIC FUNCIONS OF ##filemaster## STARTS ####################*/



?>
 