<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	

	/**
	  ** Time zone
	**/
    if (!function_exists('time_zone')) {

	    function time_zone() {
	        $ci =& get_instance();
	        $set_time_zone = get_setting()['time_zone']; //Asia/Dhaka
	        $date = new DateTime();
      		$timeZone = $date->getTimezone();
      		!empty($set_time_zone)?$get_zone = $set_time_zone:$get_zone = $timeZone->getName();
	        return $get_zone;
	        
	    }

	}
	if(!function_exists('full_date')){
	    function full_date($date){       
	        
	        if($date != ''){
	            $date_new = get_date_format($date);
	            return $date_new;
	        }else{
	            return '';
	        }
	    }
	}

	if(!function_exists('get_date_format')){
	    function get_date_format($date){       
	        $type=8;
	        if($date != ''){
	            $dates = [
		            1 => date("d-m-Y",strtotime($date)),
		            2 => date("Y-m-d",strtotime($date)),
		            3 => date("d/m/Y",strtotime($date)),
		            4 => date("Y/m/d",strtotime($date)),
		            5 => date("d.m.Y",strtotime($date)),
		            6 => date("Y.m.d",strtotime($date)),
		            7 => date("d M, Y",strtotime($date)),
		            8 => date("d M Y",strtotime($date)),
	            ];
	            return $dates[$type];
	        }else{
	            return '';
	        }
	    }
	}

	if(!function_exists('time_format')){
	    function time_format($date){       
	        $type=1;
	        if($date != ''){ 
	            $dates = [
		            1 => date('h:i a', strtotime($date)),
		            2 => date("H:i",strtotime($date)),
	            ];
	            return $dates[$type];
	        }else{
	            return '';
	        }
	    }
	}

	if(!function_exists('full_time')){
	    function full_time($date){       
	        
	        if($date != '' && $date !='0000-00-00 00:00:00'){
	            $date2 = date_create($date);
	            $fdate = get_date_format($date);
	            $ftime = time_format($date);
	            $date_new = $fdate.' - '.$ftime;
	            return $date_new;
	        }else{
	            return '';
	        }
	    }
	}

	if(!function_exists('resize_img')){
    function resize_img($fullname, $width, $height){         
        
        $dir = 'uploads/pwa/';
        $url = base_url() . 'uploads/pwa/';
        // Get the CodeIgniter super object
        $CI = &get_instance();
        // get src file's extension and file name
        $extension = pathinfo($fullname, PATHINFO_EXTENSION);
        $filename = pathinfo($fullname, PATHINFO_FILENAME);
        $image_org = $dir . $filename . "." . $extension;
        $image_thumb = $dir . $filename . "-" . $height . '_' . $width . "." . $extension;
        $image_returned = $url . $filename . "-" . $height . '_' . $width . "." . $extension;

        if (!file_exists($image_thumb)) {
            // LOAD LIBRARY
            $CI->load->library('image_lib');
            // CONFIGURE IMAGE LIBRARY
            $config['source_image'] = $image_org;
            $config['new_image'] = $image_thumb;
            $config['width'] = $width;
            $config['height'] = $height;
            $config['create_thumb'] = FALSE;
            $config['maintain_ratio'] = FALSE;
            $CI->image_lib->initialize($config);
            $CI->image_lib->resize();
            $CI->image_lib->clear();
        }
        return $image_returned;
    }
}




	if (!function_exists('get_vcard_by_slug')) {

	    function get_vcard_by_slug($slug){        
	        $ci = get_instance();
	        $ci->load->model('common_m');
	        $data = $ci->common_m->get_vcard_by_slug($slug);        
	        return 'card_layouts/vcard_'.$data;
		}	
	}
	if (!function_exists('admin')) {

		function admin(){        
			$ci = get_instance();
			$ci->load->model('common_m');
			$data = $ci->common_m->get_admin();        
			return $data;
		}	
	}

	if (!function_exists('bg_loader')) {

		function bg_loader(){        
			$ci = get_instance();
			return base_url('assets/images/background.gif');
			// return 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
		}	
	}

	if (!function_exists('check_login_user')) {

	    function check_login_user() {
	        $ci = get_instance();
	        if ($ci->session->userdata('user_login') != TRUE) {
	            $ci->session->sess_destroy();
	            redirect(base_url('login'));
	        }else if(empty(user_info())){
	        	$ci->session->sess_destroy();
	            redirect(base_url('login'));
	        }
	        
	    }

	}

	// check valid auth/admin
	if (!function_exists('check_valid_auth')) {

	    function check_valid_auth() {
	        $ci = get_instance();
	        if(auth('user_login')==TRUE){
		        if (auth('user_type') != 1) {
		            redirect(base_url('dashboard'));
		        }  
		    }else{
		    	$ci->session->sess_destroy();
	            redirect(base_url('login'));
		    }
	    }

	}

	// check valid user

	if (!function_exists('check_valid_user')) {

		    function check_valid_user() {
		        $ci = get_instance();
		        if(auth('user_login')==TRUE){
			        if (auth('user_type') == 1) {
			            redirect(base_url('dashboard'));
			        }  
			    }else{
			    	$ci->session->sess_destroy();
		            redirect(base_url('login'));
			    }
		    }

		}

	

	if (!function_exists('str_slug')) {

	    function str_slug($string, $separator = '-') {
	        $ci = get_instance();
	        $re = "/(\\s|\\".$separator.")+/mu";
	        $str = @trim($string);
	        $subst = $separator;
	        $result = preg_replace($re, $subst, $str);
	        return mb_strtolower($result, mb_detect_encoding($result));
	    }

	}

	if (!function_exists('user_info')) {

	    function user_info(){        
        $ci = get_instance();
        $ci->load->model('admin_m');
        $data = $ci->admin_m->get_user_info();        
        return $data;
  		}	
	}

	
	if (!function_exists('get_setting')) {

	    function get_setting(){        
	        $ci = get_instance();
	        $ci->load->model('admin_m');
	        $data = $ci->admin_m->get_setting();        
	        return $data;
  		}	
	}


	if (!function_exists('get_user_settings')) {

	    function get_user_settings($id){        
	        $ci = get_instance();
	        $ci->load->model('common_m');
	        $data = $ci->common_m->get_user_settings($id);        
	        return $data;
  		}	
	}

	
	if(!function_exists('c_time')){
	    function c_time(){        

	        $dt = new DateTime('now',new DateTimezone(time_zone()));
	        $date_time = $dt->format('d-m-Y');      
	        
	        return $date_time;
	    }
	}



	if(!function_exists('d_time')){
	    function d_time(){    
	        $dt = new DateTime('now',new DateTimezone(time_zone()));
	        if($dt){
	        	$date_time = $dt->format('Y-m-d H:i:s'); 
	        }else{
	            $dt = new DateTime('now',new DateTimezone('Asia/Dhaka'));
	       		$date_time = $dt->format('Y-m-d H:i:s'); 
	        }
	         return $date_time;
	    }
	}


	if(!function_exists('today')){
		function today(){    
			$dt = new DateTime('now',new DateTimezone(time_zone()));
			if($dt){
				$date_time = $dt->format('Y-m-d'); 
			}else{
				$dt = new DateTime('now',new DateTimezone('Asia/Dhaka'));
				$date_time = $dt->format('Y-m-d'); 
			}
			return $date_time;
		}
	}


	
	if (!function_exists('cl_format')) {

	    function cl_format($date) {
	        $ci = get_instance();
	        if($date != '' && $date !='0000-00-00 00:00:00'){
			    return get_date_format($date);
			}else{
				return '';
			}
	        
	    }
	}

	
	if (!function_exists('get_percent')) 
	{
	    function get_percent($amount,$percent)
	    {
	        $ci =& get_instance();
	       	return ($amount*$percent)/100;
	        
	    }
	}

	if(!function_exists('add_year')){
	    function add_year($type){        
	    	$current_date = strtotime(d_time());
	    	if($type=='yearly' || $type=='year'){
				$date = strtotime("+ 1 year", $current_date);
				$date = date('Y-m-d', $date);	  
				$end_date = $date." 23:59:59";
			}else if($type=='monthly' || $type=='trial' || $type=='month'){
				$date = strtotime("+ 1 month", $current_date);
				$date = date('Y-m-d', $date);	  
				$end_date = $date." 23:59:59";
			}else{
				$end_date = '0000-00-00 00:00:00';
			}
	        return $end_date;
	    }
	}

	if(!function_exists('add_date')){
		//duration = 1,2 and type= days,month,year
	    function add_date($duration,$type){        
	    	$current_date = strtotime(d_time());
			$date = strtotime("+ ".$duration.' '.$type, $current_date);
			$date = date('Y-m-d', $date);	  
			$end_date = $date." 23:59:59";
	        return $end_date;
	    }
	}

	if(!function_exists('get_interval')){
		//duration = 1,2 and type= days,month,year and sign== +-
	    function get_interval($sign,$duration,$type){        
	    	$current_date = strtotime(d_time());
			$date = strtotime($sign." ".$duration.' '.$type, $current_date);
			$date = date('Y-m-d', $date);	  
			// $end_date = $date." 23:59:59";
	        return $date;
	    }
	}


	
if (!function_exists('get_package_type')) 
{
    function get_package_type($value)
    {

        $ci =& get_instance();
        if(strtolower($value)=="yearly"):
        	$url = 'Year';
        elseif(strtolower($value)=="monthly"):
        	$url ='Month';
        else:
        	$url= '';
        endif;
       	return $url ;
        
    }
}

	if(!function_exists('day_left')){
	    function day_left($start,$end){ 
	        $datetime1 = date_create($start);
	        $datetime2 = date_create($end);
	        $interval = date_diff($datetime1, $datetime2);
	        $date_differ =  $interval->format('%a');

	        if($datetime1 <= $datetime2):
	        	if($date_differ == "0"){
					$date =  "Tonight";
					$left =  0;
				}else{
					$left =  $date_differ." Days left";
					$date =  $date_differ;
				}
	        else:
	        	$date = '-'.$date_differ;
	        	$left =  '-'.$date_differ." Days ago";
	        endif;
			
			return ['day_left'=>$left,'date'=>$date];
	    }
	}



	if(!function_exists('count_days')){
	    function count_days($start,$end){ 
	        $datetime1 = date_create($start);
	        $datetime2 = date_create($end);
	        $interval = date_diff($datetime1, $datetime2);
	        $date_differ =  $interval->format('%a');

			
			return $date_differ;
	    }
	}



	
	
	
//session  data
    if (!function_exists('auth')) 
    {
        function auth($string)
        {
            $ci =& get_instance();
            return $ci->session->userdata($string);
        }
    }


    if (!function_exists('d_auth')) 
    {
        function d_auth($string)
        {
            $ci =& get_instance();
            if(!empty($ci->session->userdata('discount_ss'))){
            	return $ci->session->userdata('discount_ss')[$string];
            }else{
            	return '';
            }
            
        }
    }



// get user info by slug
if (!function_exists('get_user_info_by_slug')) {

	    function get_user_info_by_slug($slug){        
	        $ci = get_instance();
	        $ci->load->model('common_m');
	        $data = $ci->common_m->get_user_info_by_slug($slug);        
	        return $data;
  		}	
	}
// get user info by slug
if (!function_exists('users')) {

	    function users($slug){        
	        $ci = get_instance();
	        $ci->load->model('common_m');
	        $data = $ci->common_m->get_user_info_by_slug($slug);        
	        return $data;
  		}	
	}

// get user layout by slug
if (!function_exists('get_layouts_by_slug')) {

	    function get_layouts_by_slug($slug){        
	        $ci = get_instance();
	        $ci->load->model('common_m');
	        $data = $ci->common_m->get_layouts_by_slug($slug);        
	        return $data;
  		}	
	}

// get user layout by slug
	if (!function_exists('get_view_layouts_by_slug')) {

		    function get_view_layouts_by_slug($slug){        
		        $ci = get_instance();
		        $ci->load->model('common_m');
		        $data = $ci->common_m->get_layouts_by_slug($slug);        
		        return 'style'.$data;
	  		}	
		}

// get user info by id
if (!function_exists('get_user_info_by_id')) {

	    function get_user_info_by_id($id){        
	        $ci = get_instance();
	        $ci->load->model('admin_m');
	        $data = $ci->admin_m->get_user_info_by_id($id);        
	        return $data;
  		}	
	}

if (!function_exists('get_id_by_slug')) {
	function get_id_by_slug($name){        
		$ci = get_instance();
		$ci->load->model('common_m');
		$data = $ci->common_m->get_id_by_slug($name);        
		return $data;
	}	
}


if (!function_exists('get_id_by_package_slug')) {
	function get_id_by_package_slug($slug){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->get_id_by_package_slug($slug);        
		return $data;
	}	
}
if (!function_exists('get_payment_type')) {
    function get_payment_type($type)
    {
    	$ci =& get_instance();
       	if($type=='0'){
       		$payment = 'offline';
       	}elseif($type=='1'){
       		$payment = 'paypal';
       	}elseif($type=='2'){
       		$payment = 'stripe';
       	}elseif($type=='3'){
       		$payment = 'razorpay';
       	}elseif($type=='4'){
       		$payment = 'paytm';
       	}elseif($type=='5'){
       		$payment = 'flutterwave';
       	}else{
       		$payment = $type;
       	}

     	return $payment;
    }
}


if (!function_exists('single_select_by_user')) {
	function single_select_by_user($id,$table){        
		$ci = get_instance();
		$ci->load->model('common_m');
		$data = $ci->common_m->single_select_by_user($id,$table);        
		return $data;
	}	
}
if (!function_exists('single_select_by_user_id')) {
	function single_select_by_user_id($id,$table){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->single_select_by_user($id,$table);        
		return $data;
	}	
}

if (!function_exists('single_select_by_id')) {
	function single_select_by_id($id,$table){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->single_select_by_id($id,$table);        
		return $data;
	}	
}


if (!function_exists('select_all')) {
	function select_all($table){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->select($table);        
		return $data;
	}	
}

if (!function_exists('select_all_by_status')) {
	function select_all_by_status($table){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->select_all_by_status($table);        
		return $data;
	}	
}


if (!function_exists('single_select_by_user_slug')) {
	function single_select_by_user_slug($slug,$table){        
		$ci = get_instance();
		$ci->load->model('common_m');
		$data = $ci->common_m->single_select_by_user_slug($slug,$table);        
		return $data;
	}	
}

if (!function_exists('get_auth_info')) {
	function get_auth_info(){        
		$ci = get_instance();
		$ci->load->model('common_m');
		$data = $ci->common_m->get_auth_info();        
		return $data;
	}	
}

if (!function_exists('get_user_social_sites')) {
	function get_user_social_sites($id){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->get_user_social_sites($id);        
		return $data;
	}	
}

if (!function_exists('get_feature_id')) {
	function get_feature_id($id){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->get_feature_id($id);        
		return $data;
	}	
}

if (!function_exists('get_price_feature_id')) {
	function get_price_feature_id($id,$type_id){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->get_price_feature_id($id,$type_id);        
		return $data;
	}	
}


if (!function_exists('get_active_package_features')) {
	function get_active_package_features($id,$type_id){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->get_active_package_features($id,$type_id);        
		return $data;
	}	
}


if (!function_exists('limit')) {
	function limit($id){        
		$ci = get_instance();
		$ci->load->model('common_m');
		$data = $ci->common_m->get_user_limit($id);        
		return $data;
	}	
}

/**
  ** get freatures for user package
**/
if (!function_exists('get_user_pricing_by_id')) {
	function get_user_pricing_by_id($id,$type_slug){        
		$ci = get_instance();
		$ci->load->model('common_m');
		$data = $ci->common_m->get_user_pricing_by_id($id,$type_slug);        
		return $data['check'];
	}	
}


/**
  ** get freatures for user package
**/
if (!function_exists('get_all_user_info_id')) {
	function get_all_user_info_id($id){        
		$ci = get_instance();
		$ci->load->model('common_m');
		$data = $ci->common_m->get_all_user_info_id($id);        
		return $data;
	}	
}


/**
  ** get freatures for user package
**/
if (!function_exists('get_all_user_info_slug')) {
	function get_all_user_info_slug($slug){        
		$ci = get_instance();
		$ci->load->model('common_m');
		$data = $ci->common_m->get_all_user_info_slug($slug);        
		return $data;
	}	
}

/**
  ** get package_info by id
**/
if (!function_exists('get_package_info_by_id')) {
	function get_package_info_by_id($id){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->get_package_info_by_id($id);        
		return $data;
	}	
}

if (!function_exists('get_package_info_by_slug')) {
	function get_package_info_by_slug($id){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->get_package_info_by_slug($id);        
		return $data;
	}	
}

if (!function_exists('get_layouts')) {
	function get_layouts($id,$type){        
		$ci = get_instance();
		$ci->load->model('common_m');
		$data = $ci->common_m->get_layouts($id,$type);        
		return $data;
	}	
}


if (!function_exists('single_appoinment')) {
	function single_appoinment($id){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->single_appoinment($id);        
		return $data;
	}	
}

if (!function_exists('check_layouts')) {
	function check_layouts($type,$value){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->check_layouts($type,$value);        
		return $data;
	}	
}


if (!function_exists('get_single_appoinment')) {
	function get_single_appoinment($id,$user_id){        
		$ci = get_instance();
		$ci->load->model('common_m');
		$data = $ci->common_m->get_single_appoinment($id,$user_id);        
		return $data;
	}	
}


if (!function_exists('get_portfolio_type_name')) {
	function get_portfolio_type_name($id){        
		$ci = get_instance();
		$ci->load->model('common_m');
		$data = $ci->common_m->get_portfolio_type_name($id);        
		return $data;
	}	
}

if (!function_exists('get_total_income')) {
	function get_total_income(){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->get_total_income();        
		return $data;
	}	
}


if (!function_exists('income')) {
	function income($month,$type){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->get_total_income_by_month($month,$type);        
		return $data;
	}	
}


if (!function_exists('check_setting_value')) {
	function check_setting_value($type){        
		$ci = get_instance();
		$ci->load->model('admin_m');
		$data = $ci->admin_m->check_setting_value($type);        
		return $data;
	}	
}


if(!function_exists('get_layout_img')){
    function get_layout_img($img){   
       if(!empty($img)){
       	$image = $img;
       }else{
       	$image = 'assets/images/home_banner.jpg';
       }
        return base_url($image);
    }
}

if(!function_exists('lang')){
    function lang($data){  
    $ci = get_instance(); 
      return $ci->lang->line($data);
    }
}

if (!function_exists('get_lang')) 
{
    function get_lang()
    {
        $ci =& get_instance();
        if ($ci->session->userdata('site_lang') == '') {
        	$settings = $ci->admin_m->get_setting();
        	return $settings['language'];
        } else {
        	$name = $ci->session->userdata('site_lang');
        	return $name;
        }
        
    }
}

if (!function_exists('direction')) 
{
    function direction()
    {
        $ci =& get_instance();
        $ci->load->model('admin_m');
       	$data = $ci->admin_m->get_languages_by_slug(get_lang());
       	return $data['direction'] ;
        
    }
}


if (!function_exists('get_features_name')) 
{
    function get_features_name($slug)
    {
        $ci =& get_instance();
        $ci->load->model('admin_m');
       	$data = $ci->admin_m->get_features_name($slug);
       	return $data ;
        
    }
}

if (!function_exists('get_currency')) 
{
    function get_currency($type)
    {
        $ci =& get_instance();
        $ci->load->model('admin_m');
        $setting = get_setting();
        if(isset($setting['currency']) && ($setting['currency'] != 0 || $setting['currency'] != '')):
       		$data = $ci->admin_m->get_currencies($setting['currency'],'countries');
       	else:
       		$data = array(
       			'currency_code'=>'USD',
       			'icon'=>'&#36;',
       		);
       endif;
       	return isset($data[$type])?$data[$type]:0 ;
        
    }
}


if (!function_exists('my_currency')) 
{
    function my_currency($id,$type='')
    {
        $ci =& get_instance();
        $ci->load->model('admin_m');
        $info = $ci->admin_m->single_select_by_id($id,'countries');
        if(isset($info) && !empty($info)):
       		$data = $info;
       	else:
       		$data = array(
       			'currency_code'=>'USD',
       			'currency_symbol'=>'&#36;',
       		);
       endif;
       	return isset($data[$type])?$data[$type]:0 ;
        
    }
}


if (!function_exists('count_all')) 
{
    function count_all($table)
    {
        $ci =& get_instance();
        $ci->load->model('admin_m');
       	$data = $ci->admin_m->select($table);
       	return count($data) ;
        
    }
}

if (!function_exists('valid_user')) {
    function valid_user($id) {
        $ci = get_instance();
        if(auth('id')!=$id){
	       redirect(base_url('dashboard'));
	     } 
    }
}

if (!function_exists('check_update')) 
{
    function check_update()
    {
        $ci =& get_instance();
        $ci->load->model('admin_m');
       	$data = $ci->admin_m->check_update();
       	return $data ;
        
    }
}


if (!function_exists('is_active')) 
{
    function is_active($id,$slug)
    {
        $ci =& get_instance();
        $ci->load->model('admin_m');
       	$data = $ci->admin_m->check_active_features($id,$slug);
       	return $data['check'] ;
        
    }
}

if (!function_exists('is_free')) 
{
    function is_free($slug)
    {
        $ci =& get_instance();
        $ci->load->model('admin_m');
        $info = get_user_info_by_slug($slug);
       	$data = $ci->admin_m->get_price_type_by_id($info['account_type']);
       	if(isset($data['type']) && $data['type']=='free'):
       		return TRUE ;
       	else:
       		return false;
       	endif;
        
    }
}


if (!function_exists('ads')) 
{
    function ads($type)
    {
        $ci =& get_instance();
        $ci->load->model('admin_m');
       	$data = $ci->admin_m->single_select('ads_images');
       	if(!empty($data)):
       	return ['big' =>$data['ads_'.$type],'thumb'=>$data['ads_thumb_'.$type]] ;
       else:
       	return ['big' =>'','thumb'=>''] ;
       endif;
        
    }
}


if (!function_exists('delete_image_from_server')) {
    function delete_image_from_server($path)
    {
        $full_path = FCPATH . $path;
        if (strlen($path) > 15 && file_exists($full_path)) {
            unlink($full_path);
        }
    }
}



if(!function_exists('get_user_layout_img')){
    function get_user_layout_img($id,$feature_name){  
    	$ci = get_instance();
		$ci->load->model('admin_m');
    	$user_img = $ci->admin_m->single_select_by_user($id,'features_images');
    	if(isset($user_img)):
    	 $img = $user_img[$feature_name];
	       if(isset($img) && !empty($img)){
	       		$image = $img;
	       }else{
	       		$image = '';
	       }
	   else:
	   	$image = '';
	   endif;
        return base_url($image);
    }
}

if(!function_exists('get_theme7_layout_img')){
    function get_theme7_layout_img($id,$feature_name){  
    	$ci = get_instance();
		$ci->load->model('admin_m');
    	$user_img = $ci->admin_m->single_select_by_user($id,'features_images');
    	if(isset($user_img)):
    	 $img = $user_img[$feature_name];
	       if(isset($img) && !empty($img)){
	       		$image = $img;
	       }else{
	       		$image = 'assets/images/user_banner.jpg';
	       }
	   else:
	   	$image = '';
	   endif;
        return base_url($image);
    }
}


if(!function_exists('get_days')){
    function get_days(){   
        $days = array(
            '1' => 'Monday',
            '2' => 'Tuesday',
            '3' => 'Wednesday',
            '4' => 'Thursday',
            '5' => 'Friday',
            '6' => 'Saturday',
            '0' => 'Sunday',
        );
        return $days;
    }
}

if(!function_exists('is_valid')){
    function is_valid(){  
    	$ci = get_instance(); 
    	$settings =  get_setting();
	    	if(isset($settings['site_id']) && !empty($settings['site_id']) && !empty($settings['active_code']) && !empty($settings['active_key']) && $settings['created_at']!='0000-00-00 00:00:00'):
	    		return true;
	    else:
	    	base_url('admin/dashboard/check_valid_purchases');
	    endif;
    	
    }
}

if(!function_exists('check_code')){
    function check_code(){  
    	if(CHECK=='allow'):
	    	$ci = get_instance(); 
	    	$settings =  get_setting();
	    	if(isset($settings['site_id']) && !empty($settings['site_id']) && !empty($settings['active_key']) && !empty($settings['active_code']) && $settings['created_at']!='0000-00-00 00:00:00'):
	    		
				if($ci->security->get_key() == $settings['active_key']){
					return 1;
				}else{
					return 0;
				}
			    
	    	else:
	    		return 0;
	    	endif;

    	elseif(CHECK=='exit'):
			return 1;
		else:
			return 0;
		endif;
  		
    }
}

if(!function_exists('is_test')){
    function is_test(){  
    	$ci =& get_instance();
    	$settings = get_setting();
    	if(isset($settings['environment']) && $settings['environment'] =='demo'):
    		$ci->session->set_flashdata('error', 'Sorry Not available in demo');
    		redirect($_SERVER['HTTP_REFERER']);
    		exit();
    	else:

    	endif;   		
    }
}



if(!function_exists('is_demo')){
	function is_demo(){  
		$ci =& get_instance();
		$settings = get_setting();
		if(isset($settings['environment']) && $settings['environment'] =='demo'):
			return 1;
		else:
			return 0;
		endif;  		
	}
}


if(!function_exists('is_update')){
    function is_update(){  
    	$ci =& get_instance();
    	$settings = get_setting();
    	if($settings['is_update']==1):
    		return 1;
    	else:
    		return 0;
    	endif;  		
    }
}


if(!function_exists('is_allow')){
    function is_allow(){  
    	$ci =& get_instance();
    	$settings = get_setting();
    	if($settings['license_code']==LICENSE):
    		return 1;
    	else:
    		return 0;
    	endif;  		
    }
}



if(!function_exists('my_features')){
    function my_features(){  
      $features = ['home','about','services','resume','skills','portfolio','blog','appointment','contacts','teams','facts'];
       return $features;     
    }
}

if(!function_exists('my_menu_features')){
    function my_menu_features(){  
      $features = ['home','about','services','resume','portfolio','blog','appointment','contacts'];
       return $features;     
    }
}

if(!function_exists('page_title')){
    function page_title(){  
      $features = ['home','about','services','resume','skills','portfolio','blog','appointment','contacts'];
       return $features;     
    }
}


if(!function_exists('check_active_features')){
    function check_active_features($user_id,$slug){  
       if(get_user_pricing_by_id($user_id,$slug)==1 && is_active($user_id,$slug)==1){
          $status = 1;
        }else{
          $status = 0;
        }
      return $status;     
    }
}

if(!function_exists('profile_status')){
    function profile_status(){  
      $features = my_features();
      $status = [];
      foreach($features as $key => $value){
        if(get_user_pricing_by_id(auth('id'),$value)==1){
          $status = 1;
        }else{
          $status = 0;
        }
      }
      return $status;     
    }
}

if(!function_exists('is_active_profile')){
    function is_active_profile(){  
      $features = my_features();
      $status = [];
      foreach($features as $key => $value){
        if(is_active(auth('id'),$value)==1){
          $status = 1;
        }else{
          $status = 0;
        }
      }
      return $status;     
    }
}

if (!function_exists('redirect_url')) 
{
    function redirect_url($slug='',$value='',$dial_code='',$text='')
    {
    	
        $ci =& get_instance();
        if($slug=="whatsapp"):
        	$url = 'https://api.whatsapp.com/send?phone='.$dial_code.$value.'&text='.urlencode($text);
        elseif($slug=="phone"):
        	$url ='tel:'.$dial_code.$value;
        elseif($slug=="email"):
        	$url ='mailto:'.$value;
        elseif($slug=="sms"):
        	$url ='sms:'.$dial_code.$value.'?body='.urlencode($text);
        else:
        	$url= prep_url($value);
        endif;
       	return $url ;
        
    }
}

if (!function_exists('contact_url')) 
{
    function contact_url($slug,$value)
    {
    $ci =& get_instance();
	    if (($pos = strtok($value, ",")) !== FALSE) { 
		   $whatIWant = strtok($value, ',');; 
		}else {
			$whatIWant = $value;
		} 
		
       if($slug=="phone"):
        	$url ='tel:'.$whatIWant;
        elseif($slug=="email"):
        	$url ='mailto:'.$whatIWant;
        else:
        	$url= prep_url($whatIWant);
        endif;
       	return $url ;
        
    }
}

if (!function_exists('get_embeded')) {
    function get_embeded($url)
    {
    	$ci =& get_instance();
	     $shortUrlRegex = '/youtu.be\/([a-zA-Z0-9_-]+)\??/i';
	     $longUrlRegex = '/youtube.com\/((?:embed)|(?:watch))((?:\?v\=)|(?:\/))([a-zA-Z0-9_-]+)/i';

	    if (preg_match($longUrlRegex, $url, $matches)) {
	        $youtube_id = $matches[count($matches) - 1];
	    }

	    if (preg_match($shortUrlRegex, $url, $matches)) {
	        $youtube_id = $matches[count($matches) - 1];
	    }
	    return 'https://www.youtube.com/embed/' . $youtube_id ;
    }
}


 //youtube thumbnail
    if (!function_exists('get_youtube_thumb')) 
    {
        function get_youtube_thumb($link)
        {
            $video_id = explode("?v=", $link);
            if (!isset($video_id[1])) {
                $video_id = explode("youtu.be/", $link);
            }
            $youtubeID = $video_id[1];
            if (empty($video_id[1])) $video_id = explode("/v/", $link);
            $video_id = explode("&", $video_id[1]);
            $youtubeVideoID = $video_id[0];

            $img_name= md5('youtube'.time());
            if ($youtubeVideoID) {
                return $thumbURL = 'https://img.youtube.com/vi/'.$youtubeVideoID.'/mqdefault.jpg';
            } else {
                return false;
            }
        }
    }

if(!function_exists('get_time_ago')){
	    function get_time_ago($time_ago){        
	        $ci = get_instance();
	        
	        $dt = new DateTime('now', new DateTimezone('Asia/Dhaka'));
	        $date_time = strtotime($dt->format('Y-m-d H:i:s')); 

	        $time_ago = strtotime($time_ago);
	        $cur_time   = $date_time;
	        $time_elapsed   = $cur_time - $time_ago;
	        $seconds    = $time_elapsed ;
	        $minutes    = round($time_elapsed / 60 );
	        $hours      = round($time_elapsed / 3600);
	        $days       = round($time_elapsed / 86400 );
	        $weeks      = round($time_elapsed / 604800);
	        $months     = round($time_elapsed / 2600640 );
	        $years      = round($time_elapsed / 31207680 );
	        // Seconds

	        //return $seconds;

	        if($seconds <= 60){
	            return "just now";
	        }
	        //Minutes
	        else if($minutes <=60){
	            if($minutes==1){
	                return "one minute ago";
	            }
	            else{
	                return "$minutes minutes ago";
	            }
	        }
	        //Hours
	        else if($hours <=24){
	            if($hours==1){
	                return "an hour ago";
	            }else{
	                return "$hours hrs ago";
	            }
	        }
	        //Days
	        else if($days <= 7){
	            if($days==1){
	                return "yesterday";
	            }else{
	                return "$days days ago";
	            }
	        }
	        //Weeks
	        else if($weeks <= 4.3){
	            if($weeks==1){
	                return "a week ago";
	            }else{
	                return "$weeks weeks ago";
	            }
	        }
	        //Months
	        else if($months <=12){
	            if($months==1){
	                return "a month ago";
	            }else{
	                return "$months months ago";
	            }
	        }
	        //Years
	        else{
	            if($years==1){
	                return "one year ago";
	            }else{
	                return "$years years ago";
	            }
	        }


	        
	    }
	}


	if(!function_exists('get_icon')){
		function get_icon($icon){  
			if(!empty($icon)):
				$icon = explode('"', $icon);
				return $icon = $icon[1];
			else:
				return $icon = '';
			endif;
		}
	}

	if (!function_exists('payment_methods')) {

		function payment_methods() {
			$ci = get_instance();
			$data = $ci->common_m->select_with_status('payment_method_list');
			return $data;
			
		}
	}

	if (!function_exists('type_limit')) {

		function type_limit($type) {
			$ci = get_instance();
			if($type==0){
				return lang('unlimited');
			}else{
				return $type;
			}
			
		}
	}

	if (!function_exists('active')) {

		function active($type) {
			$ci = get_instance();
			$data = [];
			$settings = get_setting();
			if(isset($settings[$type]) && $settings[$type]==1){
				return 1;
			}else{
				return 0;
			}
		}
	}
if (!function_exists('get_domain')) {

		function get_domain($siteUrl) {
			$ci = get_instance();
			$siteUrl = preg_replace('#(^https?:\/\/(w{3}\.)?)|(\/$)#', '', $siteUrl);
			$siteUrl = str_replace('www.','',$siteUrl);
			$siteUrl = str_replace('/.','',$siteUrl);
			return $siteUrl.'/';
		}
	}