<?php
ob_start();
////////////////////////////////////////////////////

////////////////////////////////////////////////////
function app_redirect_adv2_blog($url_location){

$finded=$url_location;

$url_location=BLOG_PATH.$finded;

$url=$url_location;

	
    if (!headers_sent())
    {    
        header('Location: '.$url);
        exit;
        }
    else
        {  
        echo '<script type="text/javascript">';
        echo 'window.location.href="'.$url.'";';
        echo '</script>';
        echo '<noscript>';
        echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
        echo '</noscript>'; exit;
    }

	

}
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////// FUNCTION | MODULE FUNCTION (c) i2d Technologies //////////////////////////////////

if (!function_exists('admin_alerts')) {
	function admin_alerts($msg){
   ?>
   <!-- PAGE FUNCTION ADMIN ALERT STARTS (c) i2d Technologies Website Engine -->
  <div class="container">
  <div class="row">
                                        <div class="col-md-12 col-sm-12 m-t-60">
                                    
  <div class="alert alert-info alert-dismissible fade in">
                                                <button type="button" class="close" data-dismiss="alert"
                                                        aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
<?php echo $msg; ?>                              
							  </div>
                                            </div>
                                            </div>
                                            </div>
 <!-- PAGE FUNCTION ADMIN ALERT ENDS (c) i2d Technologies Website Engine -->   
<?php   
}
}
//////////////////////////// HTML FUNCTION ENDS (c) i2d Technologies ///////////////////////////////////////

////////////////////// CORE FUNCTION | MODULE FUNCTION (c) i2d Technologies //////////////////////////////////
if (!function_exists('check_pass_blog')) {
function check_pass_blog($user,$pass,$ref) { 

$user=i2d_secured_input($user);
$pass=i2d_secured_input($pass);

$link=uplink();
	$sql=("SELECT * FROM master WHERE col13='$user' AND col14='$pass' AND alias='$ref'");
	$query=mysqli_query($link, $sql);
    
if($query){
$deal_count=mysqli_num_rows($query);
return $deal_count;
// close connection 
$link->close();
}
else{
$deal_count=0;
return $deal_count;	
}

// close connection 
$link->close();


} 
}
/////////////////////////// function ends /////////////////////////////////
////////////////////////// "Security" Functions Start ////////////////////////////////////
function login_user_blog($username,$password,$ref,$addr) { 

$link= uplink();

$checking=check_pass_blog($username,$password,$ref);

	if($checking>0){
		
		$randomString = substr(str_shuffle("0123456789abhijklmnopqvwxyzABCDEFNOPVWXYZ"), 0, 5);
		
if (!isset($_SESSION)){ session_start();}
if (!isset($_SESSION['user'])){
$_SESSION['user'] = $username;
}
if (!isset($_SESSION['token'])){
$_SESSION['token'] = $randomString;
}
$_SESSION['auth'] = "10";

$name=db_ref('master','col13',$username,'col15');
if (!isset($_SESSION['name'])){
$_SESSION['name'] = $name;
}
$uid=db_ref('master','col13',$username,'id');
if (!isset($_SESSION['id'])){
$_SESSION['id'] = $uid;
}
if (!isset($_SESSION['ttl'])){
$_SESSION['ttl'] = time();
}
app_redirect_adv2_blog($addr);	
}
else{
$msg="Password Error";	
	}
return $msg;
	
}
/////////////////////////// function ends /////////////////////////////////
/////////////////////////////// Function starts

if (!function_exists('check_session_blog')) {
function check_session_blog($addr) { 
if (!isset($_SESSION)){ session_start();}
if (isset($_SESSION["ttl"])){ 
$var=$_SESSION["ttl"];
if (!empty($var)){ 
$inactive=10800;
$sessionTTL = time() - $var;
    if ($sessionTTL > $inactive) {
session_destroy();      
	 app_redirect_adv2_blog($addr);
	 }
	else{
$msg="TTL IS NOT EXPIRED -".$var."PLEASE WORK ON";	
	//admin_alerts($msg);
	$_SESSION['ttl']++;
	}
}

}

else{
app_redirect_adv2_blog($addr);
} 
  
return $msg;  
}
} 

/////////////////////////// function ends /////////////////////////////////
/////////////////////////////// Function starts

if (!function_exists('check_session_login_blog')) {
function check_session_login_blog($addr) { 

if (!isset($_SESSION)){ session_start();}
if (isset($_SESSION["ttl"])){ 
$var=$_SESSION["ttl"];
if (!empty($var)){ 
$inactive=3600;
$sessionTTL = time() - $var;
    if ($sessionTTL > $inactive) {
session_destroy();      
	 
	 }
	else{
	$msg="logged in";	
	app_redirect_adv2_blog($addr);
	}
}

}

else{
 $msg="Please Log in again";
} 
  
return $msg;  
 	    
   
}
} 

/////////////////////////// function ends /////////////////////////////////
/////////////////////////////// Function starts

if (!function_exists('logout_user_blog')) {
function logout_user_blog($addr) { 
if(!isset($_SESSION)){
session_start(); 
}
$_SESSION = array(); 

if (ini_get("session.use_cookies")) { 
    $params = session_get_cookie_params(); 
    setcookie(session_name(), '', time() - 42000, 
        $params["path"], $params["domain"], 
        $params["secure"], $params["httponly"] 
    ); 
} 

session_destroy(); 
app_redirect_adv2_blog($addr);



} 
}
/////////////////////////// function ends /////////////////////////////////
////////////////////// FUNCTION | MODULE FUNCTION (c) i2d Technologies //////////////////////////////////

if (!function_exists('login_screen_blog')) {
	function login_screen_blog($settings){
	if (array_key_exists('msg', $settings)) {
	$default_msg=$settings['msg'];}
   if (array_key_exists('img', $settings)) {
   $img=$settings['img'];}
   
   if (array_key_exists('f_user_label', $settings)) {
   $user_label=$settings['f_user_label'];}
   if (array_key_exists('f_user_name', $settings)) {
   $user_name=$settings['f_user_name'];}
   
   if (array_key_exists('f_pass_label', $settings)) {
   $pass_label=$settings['f_pass_label'];}
   if (array_key_exists('f_pass_name', $settings)) {
   $pass_name=$settings['f_pass_name'];}
   
   if (array_key_exists('f_hidden_name', $settings)) {
   $hidden_name=$settings['f_hidden_name'];
   }
   
if (array_key_exists('logo', $settings)) {
   $logo=$settings['logo'];
   }
   if (array_key_exists('bg_folder', $settings)) {
   $bg_folder=$settings['bg_folder'];
   }
   
$goko=rand(1,3);   

if(isset($bg_folder) && !empty($bg_folder)){
$bg_cover1=MAIN_SITE_PATH."images/bgs"."/".$bg_folder."/";   
$bg_cover=MAIN_SITE_PATH."images/bgs"."/".$bg_folder."/".$goko.".jpg";   

} else {
$bg_cover1=MAIN_SITE_PATH."images"."/bgs/";   
$bg_cover=MAIN_SITE_PATH."images"."/bgs/".$goko.".jpg";   
}   
   ?>
   <!-- PAGE FUNCTION LOGIN SCREEN STARTS (c) i2d Technologies Website Engine -->
   <style>
   body
{
    background: url('<?php echo $bg_cover; ?>') fixed; 
	background-size: cover;
    padding: 0;
    margin: 0;
	border : 0;
}
   </style>
  <section>
            <div class="container" style="padding:0;margin:0;">
                <div class="row">
                    <div class="col-sm-12" style="background: url('<?php echo $bg_cover; ?>') fixed; 
	background-size: cover;
    padding: 0;
    margin: 0;"
					
					>

                        <div class="wrapper-page">

                            <div class="m-t-40 card-box">
                                <div class="text-center">
<?php
if(isset($logo) && !empty($logo)){
?>	
                                <span><img src="<?php echo MAIN_SITE_PATH."/images/logos"; ?>/<?php echo $logo; ?>" alt="" height="70"></span>
<?php } else { ?>
						        <span><img src="<?php echo MAIN_SITE_PATH."/images"; ?>/blog_logo.png" alt="" height="70"></span>
                         
						 <?php } ?>

						 
                                    <h5 class="font-bold" id="response" style="color:black;"><?php echo $default_msg; ?></h5>
                                   </div>
								   <br />
                                <div class="account-content">
                                    <form class="form-horizontal" enctype="multipart/form-data" method="post">

                                        <div class="form-group m-b-20">
                                            <div class="col-xs-12">
                                                <label for="emailaddress"><?php echo $user_label; ?></label>
                                                <input class="form-control" name="<?php echo $user_name; ?>" type="text" required>
                                            </div>
                                        </div>
                                        
                                        <div class="form-group m-b-20">
                                            <div class="col-xs-12">
                                                <label for="password"><?php echo $pass_label; ?></label>
                                                <input class="form-control" type="password" required placeholder="Enter your password" name="<?php echo $pass_name; ?>">
                                            </div>
                                        </div>

                                        
                                        <div class="form-group account-btn text-center m-t-10">
                                            <div class="col-xs-12">
                                                <button class="btn btn-lg btn-primary btn-block" type="submit">Sign In</button>
                                            <input type="hidden" name="<?php echo $hidden_name; ?>" value="login" />
											</div>
                                        </div>

                                    </form>

                                    <div class="clearfix"></div>

                                </div>
								<p>&nbsp;</p>
								<div class="text-center" style="position:relative !IMPORTANT; margin-top:20px;">
                            <strong>MMH Blogger V 1.0</strong> <br />i2d Technologies Pakistan , CWE &copy; 2021
                        </div>
								
                            </div>
                            <!-- end card-box-->


                           
                        </div>
                        <!-- end wrapper -->

                    </div>
                </div>
            </div>
            
            
        </section>
   
		
 <!-- PAGE FUNCTION LOGIN SCREEN ENDS (c) i2d Technologies Website Engine -->   
<?php   
}
}
//////////////////////////// HTML FUNCTION ENDS (c) i2d Technologies ///////////////////////////////////////

ob_flush();
?>