<?php
function formatDate($dateString) {
    // Convert date string to a Unix timestamp
    $timestamp = strtotime($dateString);
    
    // Convert Unix timestamp to formatted date string
    $formattedDate = date('d M Y', $timestamp);
    
    return $formattedDate;
}
function db_variables(){
    $ci =& get_instance();
    $query=$ci->db->get('admin_files');
    $admin_data = $query->result_array();
        $admin_data2=array();
        $admin_data2['site_name']=$admin_data['0']['name'];
        $admin_data2['site_map']=$admin_data['0']['map'];
        $admin_data2['site_phone']=$admin_data['0']['phone'];
        $admin_data2['site_email']=$admin_data['0']['email'];
        $admin_data2['site_brief']=$admin_data['0']['brief'];
        $admin_data2['site_address']=$admin_data['0']['address'];
        $admin_data2['GA']=$admin_data['0']['ga'];
        $admin_data2['AD']=$admin_data['0']['ad'];
        $admin_data2['chat']=$admin_data['0']['chat'];
        $admin_data2['f']=$admin_data['0']['f'];
        $admin_data2['f2']=$admin_data['0']['f2'];

        $admin_social_media=social_media_db(); // social media links
        $admin_data2['social_fb']=$admin_social_media['0']['fb'];
        $admin_data2['social_tw']=$admin_social_media['0']['tw'];
        $admin_data2['social_yt']=$admin_social_media['0']['yt'];
        $admin_data2['social_in']=$admin_social_media['0']['insta'];
        $admin_data2['social_linkedin']=$admin_social_media['0']['linkedin'];

        $admin_data2['demo_content']="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown <br/> printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, <br/>but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset <br/>sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
    $admin_data2['demo_img']='https://via.placeholder.com/';

    return $admin_data2;
}



function check_session($case,$url){
    switch($case){
        case '1': // signup , login page
            if(isset($_SESSION['yid']) && $_SESSION['yid'] != ''){
                redirect(base_url("index.php/main/$url"));
            }
        break;

        case '2': // profile page
            if(!isset($_SESSION['yid']) || $_SESSION['yid'] == ''){
                redirect(base_url("index.php/main/$url"));
            }
        break;

        case '3':
        if(!isset($_SESSION['yid']) || $_SESSION['yid'] == ''){
             echo 'Please login to continue.'; die;
            }
        break;case 'check':
        if(!isset($_SESSION['yid']) || @$_SESSION['yid'] == ''){
             return '1';
            }
        break;

        default:
            return false();
        break;
    }
}
function emailCHECK($regmail,$ercode=null){
if (!filter_var($regmail,FILTER_VALIDATE_EMAIL)){
echo $ercode.' Sorry, '.$regmail.' is not a valid email !!!'; exit; }
}
function social_media_db(){
    $ci =& get_instance();
    $query=$ci->db->get('admin_socialm');
    $admin_data = $query->result_array();
    return $admin_data;
}

function trim_text($string, $length, $dots = ".") {
    return (strlen($string) > $length) ? substr($string, 0, $length - strlen($dots)) . $dots : $string;
}


function money_show($money){
    $len = strlen($money);
    $m = '';
    $money = strrev($money);
    for($i=0;$i<$len;$i++){
        if(( $i==3 || ($i>3 && ($i-1)%2==0) )&& $i!=$len){
            $m .=',';
        }
        $m .=$money[$i];
    }
    return 'Rs: '.strrev($m);
}

function get_captcha($addclass){ ?>
    <script src="https://www.google.com/recaptcha/api.js" async defer></script>
    <div class="g-recaptcha <?=$addclass?>" data-sitekey="6LdsJSIeAAAAABs-3vApvTTDqiFst4T28Vb9sopm"></div>
<?php }

function send_email($tos,$subject09,$messageto90,$site_name,$json_string){
$k1="e2742ce0501017d3938570e755df5fe4";
$k2="7deb9a31ec656bd9b94381a4a52759ca";
$details='{
    "Messages": [{
        "From": {
            "Email": "no-reply@ynaps-test.ml",
            "Name": "Incrive Ent"
        },
        "To": [{
            "Email": "'.$tos.'"
        }],
        "Subject": "'.$subject09.'",
        "HTMLPart": "'.$messageto90.'"
    }]
}';

// echo $details; die;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.mailjet.com/v3.1/send');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $details);
curl_setopt($ch, CURLOPT_USERPWD, $k1 . ':' . $k2);
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
// print_r($result); die;
curl_close($ch);
}
function email_template($preheader,$greet,$message,$link,$linkname,$message2,$greet2,$site_name,$site_address){
    $messageto90="<!doctype html><html> <head> <meta name='viewport' content='width=device-width'/> <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/><style>img{border: none; -ms-interpolation-mode: bicubic; max-width: 100%;}body{background-color: #f6f6f6; font-family: sans-serif; -webkit-font-smoothing: antialiased; font-size: 14px; line-height: 1.4; margin: 0; padding: 0; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;}table{border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;}table td{font-family: sans-serif; font-size: 14px; vertical-align: top;}/* ------------------------------------- BODY & CONTAINER ------------------------------------- */ .body{background-color: #f6f6f6; width: 100%;}/* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */ .container{display: block; Margin: 0 auto !important; /* makes it centered */ max-width: 580px; padding: 10px; width: 580px;}/* This should also be a block element, so that it will fill 100% of the .container */ .content{box-sizing: border-box; display: block; Margin: 0 auto; max-width: 580px; padding: 0px;border:1px solid #ddd;background: #fff;}/* ------------------------------------- HEADER, FOOTER, MAIN ------------------------------------- */ .main{padding: 30px; background: #fff; border-radius: 0px; width: 100%;}.wrapper{box-sizing: border-box; padding: 20px;}.footer{clear: both;padding: 30px 0px;text-align: center;width: 100%;background: #dfe6ec;color: #fff !important;}.footer td, .footer p, .footer span, .footer a{color: #999999; font-size: 12px; text-align: center;}/* ------------------------------------- TYPOGRAPHY ------------------------------------- */ h1, h2, h3, h4{color: #000000; font-family: sans-serif; font-weight: 400; line-height: 1.4; margin: 0; Margin-bottom: 30px;}h1{font-size: 35px; font-weight: 300; text-align: center; text-transform: capitalize;}p, ul, ol{font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;}p li, ul li, ol li{list-style-position: inside; margin-left: 5px;}a{color: #3498db; text-decoration: underline;}/* ------------------------------------- BUTTONS ------------------------------------- */ .btn{box-sizing: border-box; width: 100%;}.btn > tbody > tr > td{padding-bottom: 15px;}.btn table{width: 60%;}.btn table td{background-color: #ffffff; border-radius: 5px; text-align: center;}.btn a{background-color: #ffffff; border: solid 1px #3498db; border-radius: 5px; box-sizing: border-box; color: #3498db; cursor: pointer; display: inline-block; font-size: 14px; font-weight: bold; margin: 0; padding: 12px 25px; text-decoration: none; text-transform: capitalize;}.btn-primary table td{background-color: #3498db;}.btn-primary a{background-color: #3498db; border-color: #3498db; color: #ffffff;}/* ------------------------------------- OTHER STYLES THAT MIGHT BE USEFUL ------------------------------------- */ .last{margin-bottom: 0;}.first{margin-top: 0;}.align-center{text-align: center;}.align-right{text-align: right;}.align-left{text-align: left;}.clear{clear: both;}.mt0{margin-top: 0;}.mb0{margin-bottom: 0;}.preheader{color: transparent; display: none; height: 0; max-height: 0; max-width: 0; opacity: 0; overflow: hidden; mso-hide: all; visibility: hidden; width: 0;}.powered-by a{text-decoration: none;}hr{border: 0; border-bottom: 1px solid #f6f6f6; Margin: 20px 0;}/* ------------------------------------- RESPONSIVE AND MOBILE FRIENDLY STYLES ------------------------------------- */ @media only screen and (max-width: 620px){table[class=body] h1{font-size: 28px !important; margin-bottom: 10px !important;}table[class=body] p, table[class=body] ul, table[class=body] ol, table[class=body] td, table[class=body] span, table[class=body] a{font-size: 16px !important;}table[class=body] .wrapper, table[class=body] .article{padding: 10px !important;}table[class=body] .content{padding: 0 !important;}table[class=body] .container{padding: 0 !important; width: 100% !important;}table[class=body] .main{border-left-width: 0 !important; border-radius: 0 !important; border-right-width: 0 !important;}table[class=body] .btn table{width: 100% !important;}table[class=body] .btn a{width: 100% !important;}table[class=body] .img-responsive{height: auto !important; max-width: 100% !important; width: auto !important;}}/* ------------------------------------- PRESERVE THESE STYLES IN THE HEAD ------------------------------------- */ @media all{.ExternalClass{width: 100%;}.ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div{line-height: 100%;}.apple-link a{color: inherit !important; font-family: inherit !important; font-size: inherit !important; font-weight: inherit !important; line-height: inherit !important; text-decoration: none !important;}.btn-primary table td:hover{background-color: #34495e !important;}.btn-primary a:hover{background-color: #34495e !important; border-color: #34495e !important;}}</style> </head> <body class=''> <table border='0' cellpadding='0' cellspacing='0' class='body'> <tr> <td>&nbsp;</td><td class='container'> <div class='content'> <span class='preheader'>$preheader</span><table style='text-align: center;padding-top:40px;'><td><img src='https://pngimg.com/uploads/hello/hello_PNG46.png' style='height: 170px;'></td></table> <table class='main'> <tr> <td class='wrapper'> <table border='0' cellpadding='0' cellspacing='0'><tr><td><img src='".base_url()."assets/avator/logo.png' style='height:40px'/><hr/></td></tr><tr> <td> <h1>$greet</h1><p style='font-size:20px;'>$message</p><table border='0' cellpadding='0' cellspacing='0' class='btn btn-primary'> <tbody> <tr> <td align='left'> <table border='0' cellpadding='0' cellspacing='0'> <tbody> <tr> <td> <a href='$link' style='width:100%;background:#0E385E;border:0px;border-radius:0px !important;' target='_blank'>$linkname</a></td></tr></tbody> </table> </td></tr></tbody> </table> <hr/><p style='color:silver;'><b>About us:</b> $message2.</p><hr/><p>$greet2.</p></td></tr></table> </td></tr></table> <div class='footer'> <table border='0' cellpadding='0' cellspacing='0'> <tr> <td class='content-block'> <span class='apple-link'>$site_name, $site_address</span> <br>Don't like these emails? <a href='#'>Unsubscribe</a>. </td></tr><tr> <td class='content-block powered-by'> Website and email Powered by <a href='http://ynaps.com/'>YNAPS</a></td></tr><tr><td></td></tr></table> </div></div></td><td>&nbsp;</td></tr></table> </body></html>";
    return $messageto90;
}


function uploadonlyimage($fileNAmeis,$directory,$qual){
    if(isset($_POST))
{   $DestinationDirectory   = $directory;
    $Quality                = $qual;
 $BigImageMaxSize='1800px';
    // check $_FILES["$fileNAmeis"] not empty
    if(!isset($_FILES["$fileNAmeis"]) || !is_uploaded_file($_FILES["$fileNAmeis"]['tmp_name']))
    { die('Something wrong with uploaded file, something missing!'); exit; }
    $refrenext=explode(".", $_FILES["$fileNAmeis"]["name"]);
    $extension = end($refrenext);
    $ImageName      = str_replace(' ','',strtolower($_FILES["$fileNAmeis"]['name'])); //get image name
    $ImageName      = preg_replace('/[^A-Za-z0-9\-]/', '', $ImageName);
    $ImageSize      = $_FILES["$fileNAmeis"]['size']; // get original image size
    $TempSrc        = $_FILES["$fileNAmeis"]['tmp_name']; // Temp name of image file stored in PHP tmp folder
    $ImageType      = $_FILES["$fileNAmeis"]['type']; //get file type, returns "image/png", image/jpeg, text/plain etc.

    //Let's check allowed $ImageType, we use PHP SWITCH statement here
    switch(strtolower($ImageType))
    {
        case 'image/png':
            $CreatedImage =  imagecreatefrompng($_FILES["$fileNAmeis"]['tmp_name']);
            break;
        case 'image/gif':
            $CreatedImage =  imagecreatefromgif($_FILES["$fileNAmeis"]['tmp_name']);
            break;
        case 'image/jpeg':
        case 'image/pjpeg':
            $CreatedImage = imagecreatefromjpeg($_FILES["$fileNAmeis"]['tmp_name']);
            break;
        default:
        die('Unsupported File!');
            exit;   }

    list($CurWidth,$CurHeight)=getimagesize($TempSrc);
    $randomnumber=rand(111111111,999999999);
    $NewImageName = $randomnumber.$ImageName.'.'.$extension;
    $DestRandImageName = $DestinationDirectory.$NewImageName;
    if(resizeImage($CurWidth,$CurHeight,$BigImageMaxSize,$DestRandImageName,$CreatedImage,$Quality,$ImageType))
    {

        return 'SUCCXX'.$NewImageName; die;
exit;
    }else{
        die ('error generated'); exit; //output error
    }
}
}


function resizeImage($CurWidth,$CurHeight,$MaxSize,$DestFolder,$SrcImage,$Quality,$ImageType)
{
    //Check Image size is not 0
    if($CurWidth <= 0 || $CurHeight <= 0)
    {
        return false;
    }

    ini_set('memory_limit', '-1');
    //Construct a proportional size of new image
    $NewWidth           = ($CurWidth)*(.75);
    $NewHeight          = ($CurHeight)*(.75);
    $NewCanves          = imagecreatetruecolor($NewWidth, $NewHeight);

    // Resize Image
    if(imagecopyresampled($NewCanves, $SrcImage,0, 0, 0, 0, $NewWidth, $NewHeight, $CurWidth, $CurHeight))
    {
        switch(strtolower($ImageType))
        {
            case 'image/png':
        // $background = imagecolorallocate($NewCanves , 0, 0, 0);
        // imagecolortransparent($NewCanves, $background);
        // imagealphablending($NewCanves, false);
        // imagesavealpha($SrcImage, true);
        imagepng($NewCanves,$DestFolder);
                break;
            case 'image/gif':
                imagegif($NewCanves,$DestFolder);
                break;
            case 'image/jpeg':
            case 'image/pjpeg':
                imagejpeg($NewCanves,$DestFolder,$Quality);
                break;
            default:
                return false;
        }
    //Destroy image, frees memory
    if(is_resource($NewCanves)) {imagedestroy($NewCanves);}
    return true;
    } }

function date_format_1($datess,$style){
    if($datess =='0000-00-00 00:00:00'){return 'NA';}
    switch($style){
            case '1':
            echo date("d-M-Y", strtotime($datess));
            break;
            case '2':
            echo date("d-m-Y", strtotime($datess));
            break;
            case 't':
            echo date("d-M-y, h:i a", strtotime($datess));
            break;
            case 'sql':
            return date("Y/m/d", strtotime($datess));
            break;
            case 'dt':
            return date("m/d/Y", strtotime($datess));
            break;
            case 'Y':
            $date = new DateTime($datess);
            return $date->format('Y-m-d');
            break;
            default:
            echo date($style, strtotime($datess));
            break;
    }
}

function multiSearch(array $array, array $pairs)
// $theziprs=multiSearch($thezipr,array('ex_name' => 'zip'));
    {
        $found = array();
        foreach ($array as $aKey => $aVal) {
            $coincidences = 0;
            foreach ($pairs as $pKey => $pVal) {
                if (array_key_exists($pKey, $aVal) && $aVal[$pKey] == $pVal) {
                    $coincidences++;
                }
            }
            if ($coincidences == count($pairs)) {
                $found[$aKey] = $aVal;
            }
        }

        return $found;
    }

function replace_accents($str) {
   $str = htmlentities($str, ENT_COMPAT, "UTF-8");
   $str = preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/','$1',$str);
   return html_entity_decode($str);
}

    function url_smart($url){
        return strtolower(url_title($url));
        $url=replace_accents($url);
        $url=str_replace(' ','-',$url);
        $url=str_replace('%','-p',$url);
        $url=str_replace(':','',$url);
        return preg_replace('/\s+/s', '-',strtolower($url));
    }function unsmart_url($url){
        // return strtolower(url_title($url));
        // $url=replace_accents($url);
        // $url=str_replace('&','',$url);
        $url=str_replace('-',' ',$url);
        // $url=str_replace(':','',$url);
        return preg_replace('/\s+/s', ' ',strtolower($url));
    }


function get_id_multi_array($products, $field, $value)
{
   foreach($products as $key => $product)
   {
      if ( $product[$field] === $value )
         return $key;
   }
   return false;
}

function check_passwords($pwd,$ercode){
if (strlen($pwd) < 8) {
        echo "$ercode Password too short! (should be atleast 8 Character long and should have atleast 1 number and a chrector.)"; die;
    }
    if (!preg_match("#[0-9]+#", $pwd)) {
        echo "$ercode Password must include at least one number in password! (should be atleast 8 Character long and should have atleast 1 number and a chrector.)"; die;
    }
    if (!preg_match("#[a-zA-Z]+#", $pwd)) {
    echo "$ercode Password must include at least one letter! (should be atleast 8 Character long and should have atleast 1 number and a chrector.)"; die;
    }
}

function check_mobile($mobile)
{
    if(preg_match('/^[0-9]{10}+$/', $mobile) !='1'){
        echo 'Please check your mobile number, please do not add any extensions.'; die;
    } ;
}

function check_verify($switch,$check,$class){
    switch($switch){
        case '1':
        if($check =='1'){
        echo "<span class='fa fa-check-circle $class' data-toggle='tooltip' data-placement='bottom' title='Verified by ID'> </span>";
        }else{return false;}
        break;
        case '2':
        if($check =='1'){
        echo "<span class='fa fa-check-circle $class' data-toggle='tooltip' data-placement='bottom' title='Verified by ticket'> <span class='u_text'>This is a ticket verified listing.</span> </span>";
        }else{return false;}
        break;

        default:
        return false;
        break;
    }
}

function send_sms($mobileno,$textsms,$var1=0,$var2=0,$temp=0){
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://2factor.in/API/R1/?module=TRANS_SMS&apikey=b995c4c8-f3ac-11ea-9fa5-0200cd936042&to=$mobileno&from=THENGF&templatename=$temp&var1=$var1&var2=$var2&var3=$var3",
  // CURLOPT_URL => "https://test-2factor.in/API/R1/?module=TRANS_SMS&apikey=b995c4c8-f3ac-11ea-9fa5-0200cd936042&to=$mobileno&from=NYNAPS&templatename=$temp&var1=$var1&var2=$var2",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_POSTFIELDS => "{}",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$result=$response;
}

function get_cat($option,$limit){
    switch($option){
        case '1':
        $ci =& get_instance();
        $thereturn= $ci->db->query("select * from site_catagory where display ='1' order by sid asc limit $limit");
        return $thereturn;
        break;
         case '2':
        $ci =& get_instance();
        $thereturns= $ci->db->query("select * from site_catagory order by sid asc limit $limit");
        return $thereturns;
        break;case '3':
        $ci =& get_instance();
        $thereturns= $ci->db->query("select * from site_catagory where ctid='$limit' ");
        return $thereturns->row_array();
        break;

        default:

        break;
    }
}



function get_web_img($data=0,$toreturn=0){
    $CI = get_instance();
    
    switch($data){
        case '0':
            $getallhomedata=$CI->db->query("select * from site_img order by img_sort asc");
            $thedata=$getallhomedata->result_array();
            return $thedata;
        break;
        case 'list':
            $getallhomedata=$CI->db->query("select * from site_img where img_place='$toreturn' order by img_sort asc ");
            $thedata=$getallhomedata->result_array();
            return $thedata;
        break;
        case 'byname':
            $getallhomedata=$CI->db->query("select * from site_img where img_place='$toreturn' order by img_sort asc");
            $thedata=$getallhomedata->row_array();
            return $thedata;
        break;
        default:
            $getallhomedata=$CI->db->query("select * from site_img where img_id='$data' order by img_sort asc ");
            $thedata=$getallhomedata->row_array();
            if($toreturn !='0'){
                return $thedata[$toreturn];
            }else{
                return $thedata;
            }
        break;
    }
}

function data_convert($thecheck,$data){
    switch($thecheck){
        case 'active':
            if($data =='1'){
                return 'Active';
            }else{
                return 'Not Active';
            }
        break;
    }
}

function get_domain($url)
{
  return parse_url($url, PHP_URL_HOST);
}
function uploadanyfile($fileName,$size){
    $allowedExts = array("pdf","doc","docx","png","jpg","jpeg","gif","GIF","ppt","pptx","PNG","JPEG","JPG","psd","txt","xlsx","xls","rtf");$refrenext=explode(".", $_FILES["$fileName"]["name"]);
    $extension = end($refrenext);
    if ( (
    ($_FILES["$fileName"]["type"] == "application/pdf") ||
    ($_FILES["$fileName"]["type"] == "application/acrobat") ||
    ($_FILES["$fileName"]["type"] == "application/x-pdf") ||
    ($_FILES["$fileName"]["type"] == "application/msword") ||
    ($_FILES["$fileName"]["type"] == "application/rtf") ||
    ($_FILES["$fileName"]["type"] == "application/vnd.ms-excel") ||
    ($_FILES["$fileName"]["type"] == "application/vnd.ms-powerpoint") ||
    ($_FILES["$fileName"]["type"] == "application/vnd.openxmlformats-officedocument.presentationml.presentation") ||
    ($_FILES["$fileName"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") ||
    ($_FILES["$fileName"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") ||
    ($_FILES["$fileName"]["type"] == "image/psd") ||
    ($_FILES["$fileName"]["type"] == "application/psd") ||
    ($_FILES["$fileName"]["type"] == "text/plain") ||
    ($_FILES["$fileName"]["type"] == "application/photoshop") ||
    ($_FILES["$fileName"]["type"] == "image/photoshop") ||
    ($_FILES["$fileName"]["type"] == "image/PJPEG") ||
    ($_FILES["$fileName"]["type"] == "image/pjpeg") ||
    ($_FILES["$fileName"]["type"] == "image/PNG") ||
    ($_FILES["$fileName"]["type"] == "image/png") ||
    ($_FILES["$fileName"]["type"] == "image/GIF") ||
    ($_FILES["$fileName"]["type"] == "image/gif") ||
    ($_FILES["$fileName"]["type"] == "image/jpeg") ||
    ($_FILES["$fileName"]["type"] == "image/JPG") ||
    ($_FILES["$fileName"]["type"] == "image/jpg") ) &&
    in_array($extension, $allowedExts))
    {
      if ($_FILES["$fileName"]["error"] > 0)
      {
$retuva= 'error in uploading may be the file type is not supported.!!';
      }
      else
     {
$retuva= 'YNAPS_SUCES';
      }
} else {
$retuva= 'file not uploaded !! Invalid file type.';
}
 return $retuva;
}

function get_client_ip()
{
    $ipaddress = '';
    if (isset($_SERVER['HTTP_CLIENT_IP'])) {
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    } else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else if (isset($_SERVER['HTTP_X_FORWARDED'])) {
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    } else if (isset($_SERVER['HTTP_FORWARDED_FOR'])) {
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    } else if (isset($_SERVER['HTTP_FORWARDED'])) {
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    } else if (isset($_SERVER['REMOTE_ADDR'])) {
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    } else {
        $ipaddress = 'UNKNOWN';
    }

    return $ipaddress;
}
function code_to_country( $code ){

    $code = strtoupper($code);

    $countryList = array(
        'AF'=> 'Afghanistan', 'AX'=> 'Aland Islands', 'AL'=> 'Albania', 'DZ'=> 'Algeria', 'AS'=> 'American Samoa', 'AD'=> 'Andorra', 'AO'=> 'Angola', 'AI'=> 'Anguilla', 'AQ'=> 'Antarctica', 'AG'=> 'Antigua and Barbuda', 'AR'=> 'Argentina', 'AM'=> 'Armenia', 'AW'=> 'Aruba', 'AU'=> 'Australia', 'AT'=> 'Austria', 'AZ'=> 'Azerbaijan', 'BS'=> 'Bahamas the', 'BH'=> 'Bahrain', 'BD'=> 'Bangladesh', 'BB'=> 'Barbados', 'BY'=> 'Belarus', 'BE'=> 'Belgium', 'BZ'=> 'Belize', 'BJ'=> 'Benin', 'BM'=> 'Bermuda', 'BT'=> 'Bhutan', 'BO'=> 'Bolivia', 'BA'=> 'Bosnia and Herzegovina', 'BW'=> 'Botswana', 'BV'=> 'Bouvet Island (Bouvetoya)', 'BR'=> 'Brazil', 'IO'=> 'British Indian Ocean Territory (Chagos Archipelago)', 'VG'=> 'British Virgin Islands', 'BN'=> 'Brunei Darussalam', 'BG'=> 'Bulgaria', 'BF'=> 'Burkina Faso', 'BI'=> 'Burundi', 'KH'=> 'Cambodia', 'CM'=> 'Cameroon', 'CA'=> 'Canada', 'CV'=> 'Cape Verde', 'KY'=> 'Cayman Islands', 'CF'=> 'Central African Republic', 'TD'=> 'Chad', 'CL'=> 'Chile', 'CN'=> 'China', 'CX'=> 'Christmas Island', 'CC'=> 'Cocos (Keeling) Islands', 'CO'=> 'Colombia', 'KM'=> 'Comoros the', 'CD'=> 'Congo', 'CG'=> 'Congo the', 'CK'=> 'Cook Islands', 'CR'=> 'Costa Rica', 'CI'=> 'Cote dIvoire', 'HR'=> 'Croatia', 'CU'=> 'Cuba', 'CY'=> 'Cyprus', 'CZ'=> 'Czech Republic', 'DK'=> 'Denmark', 'DJ'=> 'Djibouti', 'DM'=> 'Dominica', 'DO'=> 'Dominican Republic', 'EC'=> 'Ecuador', 'EG'=> 'Egypt', 'SV'=> 'El Salvador', 'GQ'=> 'Equatorial Guinea', 'ER'=> 'Eritrea', 'EE'=> 'Estonia', 'ET'=> 'Ethiopia', 'FO'=> 'Faroe Islands', 'FK'=> 'Falkland Islands (Malvinas)', 'FJ'=> 'Fiji the Fiji Islands', 'FI'=> 'Finland', 'FR'=> 'France, French Republic', 'GF'=> 'French Guiana', 'PF'=> 'French Polynesia', 'TF'=> 'French Southern Territories', 'GA'=> 'Gabon', 'GM'=> 'Gambia the', 'GE'=> 'Georgia', 'DE'=> 'Germany', 'GH'=> 'Ghana', 'GI'=> 'Gibraltar', 'GR'=> 'Greece', 'GL'=> 'Greenland', 'GD'=> 'Grenada', 'GP'=> 'Guadeloupe', 'GU'=> 'Guam', 'GT'=> 'Guatemala', 'GG'=> 'Guernsey', 'GN'=> 'Guinea', 'GW'=> 'Guinea-Bissau', 'GY'=> 'Guyana', 'HT'=> 'Haiti', 'HM'=> 'Heard Island and McDonald Islands', 'VA'=> 'Holy See (Vatican City State)', 'HN'=> 'Honduras', 'HK'=> 'Hong Kong', 'HU'=> 'Hungary', 'IS'=> 'Iceland', 'IN'=> 'India', 'ID'=> 'Indonesia', 'IR'=> 'Iran', 'IQ'=> 'Iraq', 'IE'=> 'Ireland', 'IM'=> 'Isle of Man', 'IL'=> 'Israel', 'IT'=> 'Italy', 'JM'=> 'Jamaica', 'JP'=> 'Japan', 'JE'=> 'Jersey', 'JO'=> 'Jordan', 'KZ'=> 'Kazakhstan', 'KE'=> 'Kenya', 'KI'=> 'Kiribati', 'KP'=> 'Korea', 'KR'=> 'Korea', 'KW'=> 'Kuwait', 'KG'=> 'Kyrgyz Republic', 'LA'=> 'Lao', 'LV'=> 'Latvia', 'LB'=> 'Lebanon', 'LS'=> 'Lesotho', 'LR'=> 'Liberia', 'LY'=> 'Libyan Arab Jamahiriya', 'LI'=> 'Liechtenstein', 'LT'=> 'Lithuania', 'LU'=> 'Luxembourg', 'MO'=> 'Macao', 'MK'=> 'Macedonia', 'MG'=> 'Madagascar', 'MW'=> 'Malawi', 'MY'=> 'Malaysia', 'MV'=> 'Maldives', 'ML'=> 'Mali', 'MT'=> 'Malta', 'MH'=> 'Marshall Islands', 'MQ'=> 'Martinique', 'MR'=> 'Mauritania', 'MU'=> 'Mauritius', 'YT'=> 'Mayotte', 'MX'=> 'Mexico', 'FM'=> 'Micronesia', 'MD'=> 'Moldova', 'MC'=> 'Monaco', 'MN'=> 'Mongolia', 'ME'=> 'Montenegro', 'MS'=> 'Montserrat', 'MA'=> 'Morocco', 'MZ'=> 'Mozambique', 'MM'=> 'Myanmar', 'NA'=> 'Namibia', 'NR'=> 'Nauru', 'NP'=> 'Nepal', 'AN'=> 'Netherlands Antilles', 'NL'=> 'Netherlands the', 'NC'=> 'New Caledonia', 'NZ'=> 'New Zealand', 'NI'=> 'Nicaragua', 'NE'=> 'Niger', 'NG'=> 'Nigeria', 'NU'=> 'Niue', 'NF'=> 'Norfolk Island', 'MP'=> 'Northern Mariana Islands', 'NO'=> 'Norway', 'OM'=> 'Oman', 'PK'=> 'Pakistan', 'PW'=> 'Palau', 'PS'=> 'Palestinian Territory', 'PA'=> 'Panama', 'PG'=> 'Papua New Guinea', 'PY'=> 'Paraguay', 'PE'=> 'Peru', 'PH'=> 'Philippines', 'PN'=> 'Pitcairn Islands', 'PL'=> 'Poland', 'PT'=> 'Portugal, Portuguese Republic', 'PR'=> 'Puerto Rico', 'QA'=> 'Qatar', 'RE'=> 'Reunion', 'RO'=> 'Romania', 'RU'=> 'Russian Federation', 'RW'=> 'Rwanda', 'BL'=> 'Saint Barthelemy', 'SH'=> 'Saint Helena', 'KN'=> 'Saint Kitts and Nevis', 'LC'=> 'Saint Lucia', 'MF'=> 'Saint Martin', 'PM'=> 'Saint Pierre and Miquelon', 'VC'=> 'Saint Vincent and the Grenadines', 'WS'=> 'Samoa', 'SM'=> 'San Marino', 'ST'=> 'Sao Tome and Principe', 'SA'=> 'Saudi Arabia', 'SN'=> 'Senegal', 'RS'=> 'Serbia', 'SC'=> 'Seychelles', 'SL'=> 'Sierra Leone', 'SG'=> 'Singapore', 'SK'=> 'Slovakia (Slovak Republic)', 'SI'=> 'Slovenia', 'SB'=> 'Solomon Islands', 'SO'=> 'Somalia, Somali Republic', 'ZA'=> 'South Africa', 'GS'=> 'South Georgia and the South Sandwich Islands', 'ES'=> 'Spain', 'LK'=> 'Sri Lanka', 'SD'=> 'Sudan', 'SR'=> 'Suriname', 'SJ'=> 'Svalbard & Jan Mayen Islands', 'SZ'=> 'Swaziland', 'SE'=> 'Sweden', 'CH'=> 'Switzerland, Swiss Confederation', 'SY'=> 'Syrian Arab Republic', 'TW'=> 'Taiwan', 'TJ'=> 'Tajikistan', 'TZ'=> 'Tanzania', 'TH'=> 'Thailand', 'TL'=> 'Timor-Leste', 'TG'=> 'Togo', 'TK'=> 'Tokelau', 'TO'=> 'Tonga', 'TT'=> 'Trinidad and Tobago', 'TN'=> 'Tunisia', 'TR'=> 'Turkey', 'TM'=> 'Turkmenistan', 'TC'=> 'Turks and Caicos Islands', 'TV'=> 'Tuvalu', 'UG'=> 'Uganda', 'UA'=> 'Ukraine', 'AE'=> 'United Arab Emirates', 'GB'=> 'United Kingdom', 'US'=> 'United States of America', 'UM'=> 'United States Minor Outlying Islands', 'VI'=> 'United States Virgin Islands', 'UY'=> 'Uruguay, Eastern Republic of', 'UZ'=> 'Uzbekistan', 'VU'=> 'Vanuatu', 'VE'=> 'Venezuela', 'VN'=> 'Vietnam', 'WF'=> 'Wallis and Futuna', 'EH'=> 'Western Sahara', 'YE'=> 'Yemen', 'ZM'=> 'Zambia', 'ZW'=> 'Zimbabwe'
    );

    if( !$countryList[$code] ) return $code;
    else return $countryList[$code];
    }

function get_admin_rights(){
    if($_SESSION['aid'] =='' || $_SESSION['auth-rights'] !='2' ){
        redirect('index.php/logout.php');
    }
}

function get_page_data($page,$data,$series=null){
    $ci =& get_instance();

    switch($data){
        case '': case '0': case 'na':
        $get_data=$ci->db->query("select * from admin_pages where name='$page' ");
        $thedata_is=$get_data->row_array();
        return $thedata_is;
        break;

        case 'cache':
        $get_data=$ci->db->query("select * from admin_pages where name='$page' ");
        $thedata_is=$get_data->row_array();
        return $thedata_is;
        break;

        case 'series':
            $get_data=$ci->db->query("select * from admin_pages where name='$page' and type='$series' ");
            $thedata_is=$get_data->result_array();
            return $thedata_is;
        break;

        default:
            $ci =& get_instance();
            $get_data=$ci->db->query("select * from admin_pages where pid='$data' ");
            $thedata_is=$get_data->row_array();
            return $thedata_is;
        break;
    }

}

function getState($country,$style,$selected=0){
    $ci=&get_instance();
    $gettallsstates=$ci->db->query("select * from site_states where country_id ='$country' ");
    $thedetails_thedth=$gettallsstates->result_array();
    switch($style){ 
        case '1':?><option value="">Select State</option>
        <?php foreach($thedetails_thedth as $states_lisgs){?>
        <option value="<?=$states_lisgs['state_id']?>" <?php if($selected == $states_lisgs['state_id']){ echo "selected";} ?> ><?=$states_lisgs['state_name']?></option>
        <?php }
        break;
        case 'st_name':
        $gettallsstates=$ci->db->query("select * from site_states where state_id ='$country' ");
        $thedetails_thedth=$gettallsstates->row_array();
        return $thedetails_thedth['state_name'];
        break;
        default:
        return 'ok';
        break;
    }}

function getCity($state,$style,$selected=0){
    $ci=&get_instance();
    $gettallsstates=$ci->db->query("select * from site_cities where state_id ='$state' ");
    $thedetails_thedth=$gettallsstates->result_array();
    switch($style){ 
        case '1':
        foreach($thedetails_thedth as $states_lisgs){?>
        <option value="<?=$states_lisgs['city_id']?>" <?php if($selected == $states_lisgs['city_id']){ echo "selected";} ?> ><?=$states_lisgs['city_name']?></option>
        <?php }
        break;
        case 'ct_name':
        $gettallsstates=$ci->db->query("select * from site_cities where city_id ='$state' ");
        $thedetails_thedth=$gettallsstates->row_array();
        return $thedetails_thedth['city_name'];
        break;
        default:
        return 'ok';
        break;
    }}

    function get_country($selected){
        $ci=&get_instance();
        $gettallsstates=$ci->db->query("select * from site_countries");
        $thedetails_thedth=$gettallsstates->result_array();

        foreach($thedetails_thedth as $states_lisgs){ ?>
        <option value="<?=$states_lisgs['pincode']?>" <?php if($selected == $states_lisgs['pincode']){ echo "selected";} ?> ><?=$states_lisgs['country_name']?></option> 
        <?php  }
    }

    function getTags($style=null,$type=null,$limit=50){
        switch($style){
            case '1':
            $ci=&get_instance();
            $gettex_89sd=$ci->db->query("select * from site_tags_skills where stg_type ='$type' limit $limit ");
            return $atheadmins=$gettex_89sd->result_array();
            break;case 'select':
            $ci=&get_instance();
            $gettex_89sd=$ci->db->query("select * from site_tags_skills where stg_type ='$type' limit $limit ");
            $atheadmins=$gettex_89sd->result_array();
            $theselect='';
            foreach($atheadmins as $select_atheadmins){
                $theselect=$theselect."<option value='".$select_atheadmins['stg_tgid']."'>".$select_atheadmins['stg_name']."</option>";
            }
            return $theselect;
            break;
            case 'byid':
            $ci=&get_instance();
            $gettex_89sd=$ci->db->query("select * from site_tags_skills where stg_tgid ='$type' ");
            $atheadmins=$gettex_89sd->row_array();
            echo $atheadmins['stg_name'];
            break;

            default:
            $ci=&get_instance();
            $gettex_89sd=$ci->db->query("select * from site_tags_skills where stg_type ='$type' ");
            return $atheadmins=$gettex_89sd->result_array();
            break;
        }
    }

    function is_verified(){
        return("<span class='fa fa-check-circle verified_tick'> </span>");
    }

    function user_relationship($relation){
        return $relation;
    }

    function select_right_side_bar($type_user){
        switch($type_user){
            case 'd':
            return 'user_side.php';
            break;case 'p':
            return 'user_side_p.php';
            break;case 'b':
            return 'user_side_b.php';
            break;case 'u':
            return 'user_side_user.php';
            break;case 'e':
            return 'user_side_e.php';
            break;default:
            return 'user_side_user.php';
            break;
        }
    }

    function check_rights($user_type,$page_tosend){
        if($user_type != $_SESSION['user_type']){
            redirect(base_url($page_tosend));
        }
    }

    function read_me_user($what,$data1,$data2=0){
        switch($what){
            case 'blog_type':
                    switch($data1){
                        case '1':
                        return 'Blog';
                        break;case '3':
                        return 'News';
                        break;case '2':
                        return 'Offer';
                        break;
                    }
                break;
                case 'user_status':
                    switch($data1){
                        case '0':
                        return "<span class='mb-2 mr-2 badge badge-danger'>Pending <span class='fa fa-clock'></span>";
                        break;case '1':
                        return "<span class='mb-2 mr-2 badge badge-primary'>Active <span class='fa fa-check'></span>";
                        break;case '2':
                        return "<span class='mb-2 mr-2 badge badge-danger'>Suspended <span class='fa fa-ban'> </span>";
                        break;
                    }
                    case 'order_status':
                        switch($data1){
                            case '0':
                                return "<span class='mb-2 mr-2 badge badge-danger'>Ban <span class='fa fa-ban'></span>";
                            case '1':
                            return "<span class='mb-2 mr-2 badge badge-warning'>Pending <span class='fa fa-clock'></span>";
                            break;
                            case '2':
                            return "<span class='mb-2 mr-2 badge badge-primary'>Active <span class='fa fa-archive'></span>";
                            case '3':
                                return "<span class='mb-2 mr-2 badge badge-success'>Delivered <span class='fa fa-bus'></span>";
                            break;
                        }
                break;case 'gender':
                    switch($data1){
                        case 'm':
                        return "Male";
                        break;case 'f':
                        return "Female";
                        break;case 'o':
                        return "Others";
                        break;
                    }
                break;case 'cou_status':
                    switch($data1){
                        case '0':
                        return "<span class='mb-2 mr-2 badge badge-warning'>In-Active <span class='fa fa-clock'></span>";
                        break;case '1':
                        return "<span class='mb-2 mr-2 badge badge-primary'>Active <span class='fa fa-check'></span>";
                        break;
                    }
                break;
                case 'cou_feat':
                    switch($data1){
                        case '0':
                        return "<span class='mb-2 mr-2 badge badge-warning'>Non-Featured <span class='fa fa-clock'></span>";
                        break;case '1':
                        return "<span class='mb-2 mr-2 badge badge-primary'>Featured <span class='fa fa-check'></span>";
                        break;
                    }
                break;case 'yes_no':
                    switch($data1){
                        case '1':
                        return "<span class='mb-2 mr-2 badge badge-warning'>YES</span>";
                        break;case '0':
                        return "<span class='mb-2 mr-2 badge badge-primary'>NO</span>";
                        break;
                    }
                break;
                case 'test_status':
                    switch($data1){
                        case '1':
                        return "<span class='mb-2 mr-2 badge badge-warning'>Approved</span>";
                        break;case '0':
                        return "<span class='mb-2 mr-2 badge badge-primary'>Pending</span>";
                        break;
                    }
                break;
                case 'cpay':
                    switch($data1){
                        case '0':
                        return "Un-Paid";
                        break;case '1':
                        return "Paid";
                        break;
                    }
                break;
                case 'cstatus':
                    switch($data1){
                        case '0':
                        return "Pending";
                        break;case '1':
                        return "Confirmed";
                        break;case '2':
                        return "Cancelled";
                        break;case '3':
                        return "Shipped";
                        break;case '4':
                        return "Completed";
                        break;
                    }
                break;
                case 'user_type_status':
                    switch($data1){
                        case 'u':
                        return "<span class='mb-2 mr-2 badge badge-warning'>User</span>";
                        break;case 's':
                        return "<span class='mb-2 mr-2 badge badge-primary'>Seller</span>";
                        break;
                    }
                break;
        }
    }

    function get_age($dob){
        return date_diff(date_create($dob), date_create('today'))->y;
    }

    function get_profile_level($user){
        $ci =& get_instance();
        $get_basics=$ci->db->query("select * from site_mem where mid='$user' ");
        $thedetailsa_4=$get_basics->row_array();

        if($thedetailsa_4['address'] !='' && $thedetailsa_4['photo'] !='photo.jpg'){
            echo "80";
        }else{
            echo "50";
        }
    }

    function startup_thing($style,$startup){
        switch($style){
            case '1':
                echo "Self Funded - Based In Delhi - 2011";
            break;
        }
    }


    // DATA CONVERTERS
    function XMLtoArray($XML)
    {
        $xml_parser = xml_parser_create();
        xml_parse_into_struct($xml_parser, $XML, $vals);
        xml_parser_free($xml_parser);
        // wyznaczamy tablice z powtarzajacymi sie tagami na tym samym poziomie
        $_tmp='';
        foreach ($vals as $xml_elem) {
            $x_tag=$xml_elem['tag'];
            $x_level=$xml_elem['level'];
            $x_type=$xml_elem['type'];
            if ($x_level!=1 && $x_type == 'close') {
                if (isset($multi_key[$x_tag][$x_level]))
                    $multi_key[$x_tag][$x_level]=1;
                else
                    $multi_key[$x_tag][$x_level]=0;
            }
            if ($x_level!=1 && $x_type == 'complete') {
                if ($_tmp==$x_tag)
                    $multi_key[$x_tag][$x_level]=1;
                $_tmp=$x_tag;
            }
        }
        // jedziemy po tablicy
        foreach ($vals as $xml_elem) {
            $x_tag=$xml_elem['tag'];
            $x_level=$xml_elem['level'];
            $x_type=$xml_elem['type'];
            if ($x_type == 'open')
                $level[$x_level] = $x_tag;
            $start_level = 1;
            $php_stmt = '$xml_array';
            if ($x_type=='close' && $x_level!=1)
                $multi_key[$x_tag][$x_level]++;
            while ($start_level < $x_level) {
                $php_stmt .= '[$level['.$start_level.']]';
                if (isset($multi_key[$level[$start_level]][$start_level]) && $multi_key[$level[$start_level]][$start_level])
                    $php_stmt .= '['.($multi_key[$level[$start_level]][$start_level]-1).']';
                $start_level++;
            }
            $add='';
            if (isset($multi_key[$x_tag][$x_level]) && $multi_key[$x_tag][$x_level] && ($x_type=='open' || $x_type=='complete')) {
                if (!isset($multi_key2[$x_tag][$x_level]))
                    $multi_key2[$x_tag][$x_level]=0;
                else
                    $multi_key2[$x_tag][$x_level]++;
                $add='['.$multi_key2[$x_tag][$x_level].']';
            }
            if (isset($xml_elem['value']) && trim($xml_elem['value'])!='' && !array_key_exists('attributes', $xml_elem)) {
                if ($x_type == 'open')
                    $php_stmt_main=$php_stmt.'[$x_type]'.$add.'[\'content\'] = $xml_elem[\'value\'];';
                else
                    $php_stmt_main=$php_stmt.'[$x_tag]'.$add.' = $xml_elem[\'value\'];';
                eval($php_stmt_main);
            }
            if (array_key_exists('attributes', $xml_elem)) {
                if (isset($xml_elem['value'])) {
                    $php_stmt_main=$php_stmt.'[$x_tag]'.$add.'[\'content\'] = $xml_elem[\'value\'];';
                    eval($php_stmt_main);
                }
                foreach ($xml_elem['attributes'] as $key=>$value) {
                    $php_stmt_att=$php_stmt.'[$x_tag]'.$add.'[$key] = $value;';
                    eval($php_stmt_att);
                }
            }
        }
        return $xml_array;
    }

    function cookie_keyword()
    {
        $ci=&get_instance();
        $rand_on=time().rand(11111,9999);
        $check_srch_cookie=$ci->input->cookie('user_cook', TRUE);
        if (!isset($check_srch_cookie) || $check_srch_cookie =='' ) {
            // create cookie to avoid hitting this case again
            $srch_cookie = array(
                'name'   => 'user_cook',
                'value'  => $rand_on,
                'expire' => 865000,
                'secure' => false
            );
            $ci->input->set_cookie($srch_cookie);
        }
    }

    function clean_url($string) { 
        // $string = preg_replace("~\b(?:https?://(?:www\.)?|www\.)\S+|[^A-Za-z0-9 ']~", '', $string); 
        $string = url_title($string); 
        $string = preg_replace('/ +/', ' ', $string); 
        $string = str_replace('', '-', $string); 
        return ucfirst($string);
     }

     function clean($string) { 
        // $string = preg_replace("~\b(?:https?://(?:www\.)?|www\.)\S+|[^A-Za-z0-9 ']~", '', $string); 
        // $string = preg_replace('/ +/', ' ', $string); 
        // return strtolower($string);
        return preg_replace('/[^A-Za-z0-9\-]/', ' ', $string); // Removes special chars.
     }

    function set_keyword_cookie($yid){
        $ci=&get_instance();
        //Assign LoggedIn UserID to the cookie keyword
        $check_srch_cookie=$ci->input->cookie('user_cook', TRUE);
        if (isset($check_srch_cookie)) {
            $cookie_id=$_COOKIE['user_cook'];
            $updateUserID=$ci->db->query("UPDATE x_cou_keywords SET user_id='$yid' where cookie_id='$cookie_id'");
        }
    } 
////////////////////////////// THIS IS CUSTOM //////////////////////////////////////////////////////////////////////

function show_cost($price){
    @$thecurre=$_SESSION['currency'];
    // if($price =='0'){return 'free';}
    switch($thecurre){
        case 'INR':
            $thecurre2='USD';
            // $theprice=$price*77;
            $theprice=convertCurrency($price,$thecurre2,$thecurre);
            return "<span class='fa fa-rupee mr-1' ></span>".$theprice."<span data-toggle='tooltip' data-placement='top' title='* Price may slightly vary as per currency conversion rate' class='muted-text' ><small>*</small></span>";
        break;
        case 'USD':default:
            $thecurre2='INR';
            // $theprice=$price*77;
            $theprice=convertCurrency($price,$thecurre2,$thecurre);
            return "<span class='fa fa-rupee mr-1' ></span>".$theprice."<span data-toggle='tooltip' data-placement='top' title='* Price may slightly vary as per currency conversion rate' class='muted-text' ><small>*</small></span>";
            // return '$'.$price;
        break;
    }
}

function convertCurrency($amount, $from ='USD',$to = 'INR'){
    if($amount =='0' || $amount=='' ){return 'free';}

  // $curl = file_get_contents("http://data.fixer.io/api/latest?access_key=c763384a73e8bb397471f29afd9124fd&symbols=$from,$to");

  // if($curl)
  // {
  //   $arr = json_decode($curl,true);
  //   if($arr['success'])
  //   {
  //       $from = $arr['rates'][$from];
  //       $to = $arr['rates'][$to];

  //       $rate = $to / $from;
  //       $result = round($amount * $rate, 0);
  //       return $result;
  //   }else{
  //       echo $arr['error']['info'];
  //   }
  // }else{
  //   echo "Error reaching api";
  // }

    switch($from){
        case 'USD': default:
            if($to =='USD'){
                return number_format($amount).' USD'."<span data-toggle='tooltip' data-placement='top' title='* Price may slightly vary as per currency conversion rate' class='muted-text' ><small>*</small></span>";
            }else{
                return number_format($amount*80).' INR'."<span data-toggle='tooltip' data-placement='top' title='* Price may slightly vary as per currency conversion rate' class='muted-text' ><small>*</small></span>";
                // return $amount;
            }
        break;
        case 'INR':
            if($to =='INR'){
                return number_format($amount).' INR'."<span data-toggle='tooltip' data-placement='top' title='* Price may slightly vary as per currency conversion rate' class='muted-text' ><small>*</small></span>";
            }else{
                return number_format($amount/80).' USD'."<span data-toggle='tooltip' data-placement='top' title='* Price may slightly vary as per currency conversion rate' class='muted-text' ><small>*</small></span>";
            }
        break;
    }


}

function checkandset_currency(){
    if(!isset($_SESSION['currency']) || $_SESSION['currency'] =='' ){
        $_SESSION['currency']='INR';
    }
}

function ratings_star($rate,$style){
    if($rate!='' && $rate>0){
        $rate=round($rate,2);
        switch($style){
            case 'star':
                $star_rate=$rate.' ';
                for($k=$rate; $k>0; $k--){
                $star_rate=$star_rate." <span class='fa fa-star ml-1 star_colr'></span>";
                }

                for($k=5-$rate; $k>1; $k--){
                $star_rate=$star_rate." <span class='fa fa-star ml-1 no_star_colr'></span>";
                }
                echo $star_rate;
            break;
        }
    }
}


function social_login($type,$data1=null,$data2=null){
    switch($type){
        case 'google';
        include_once APPPATH . "libraries/vendor/autoload.php";
        $google_client = new Google_Client();
        $google_client->setClientId('112177324296-hf2rmbq0bpm7sg7co64rbs7utq2rrmfo.apps.googleusercontent.com'); //Define your ClientID
        $google_client->setClientSecret('yY9iT3tn9Kex_YMdkMIU2ckt'); //Define your Client Secret Key
        $google_client->setRedirectUri('https://courslyst.com/google_login/login'); //Define your Redirect Uri
        $google_client->addScope('email');
        $google_client->addScope('profile');

        // echo $login_button = '<a href="'.$google_client->createAuthUrl().'" class="sign-in-with" ><img src="'.base_url('assets/theme/').'images/icon/google.png" class="sign-in-with" style="max-height:90px;" /><span>Sign Up with Google</span></a>';

        echo "<div class='account-header'>
                    <a href='".$google_client->createAuthUrl()."' class='sign-in-with'><img src='".base_url('assets/theme/')."images/icon/google.png' alt='icon'><span>Sign Up with Google</span></a>
            </div>";

        // <a href="#0" class="sign-in-with"><img src="./assets/images/icon/google.png" alt="icon"><span>Sign Up with Google</span></a>

        // $data['login_button'] = $login_button;
        break;case 'google2';
        include_once APPPATH . "libraries/vendor/autoload.php";
        $google_client = new Google_Client();
        $google_client->setClientId('112177324296-hf2rmbq0bpm7sg7co64rbs7utq2rrmfo.apps.googleusercontent.com'); //Define your ClientID
        $google_client->setClientSecret('yY9iT3tn9Kex_YMdkMIU2ckt'); //Define your Client Secret Key
        $google_client->setRedirectUri('https://courslyst.com/google_login/login'); //Define your Redirect Uri
        $google_client->addScope('email');
        $google_client->addScope('profile');

        // echo $login_button = '<a href="'.$google_client->createAuthUrl().'" class="sign-in-with" ><img src="'.base_url('assets/theme/').'images/icon/google.png" class="sign-in-with" style="max-height:90px;" /><span>Sign Up with Google</span></a>';

        echo "<div class='account-header'>
                    <a href='".$google_client->createAuthUrl()."' class='sign-in-with'><img src='".base_url('assets/theme/')."images/icon/google.png' alt='icon'><span>Login with Google</span></a>
            </div>";

        // <a href="#0" class="sign-in-with"><img src="./assets/images/icon/google.png" alt="icon"><span>Sign Up with Google</span></a>

        // $data['login_button'] = $login_button;
        break;
    }
}

function myfav_items($id,$check=0){
    $CI = get_instance();
    if( !isset($_SESSION['myfav']) || empty($_SESSION['myfav']) || $check !='0'){
    // My favourites
    $get_myfav=$CI->db->query("select fav_id,fav_item_id from site_favourites where fav_user_id = '$id'");
    $myfav=$get_myfav->result_array();
    $_SESSION['myfav']=$myfav;    
    }else{
    return $myfav=$_SESSION['myfav'];    
    }
    // return $myfav;
}

function favourite_me($itemID){ 
    $fav_class='fas fa-heart'; 
    $the_fav_mess='Mark as favourite';
    if((isset($_SESSION['myfav']) || !empty($_SESSION['myfav']))) { 
        $fav_items=$_SESSION['myfav'];
        
        if(array_search($itemID, array_column($fav_items, 'fav_item_id')) != '' ) {
            $fav_class='fa fa-heart'; $the_fav_mess='Remove from favourite';
         }
        
        if(isset($_SESSION['yid'])){
            $fav_class.=' the_ani_btn';
        }
    } ?>
        <form id="fav<?=$itemID?>" action="<?=base_url('action/user_favourite')?>" method="post" class="fav_icons_btn the_imp_btn" onsubmit="return ajaxsubmitform('<?=base_url('action/user_favourite')?>',this,'error_div','loder_div','#','1','favourite');" onclick="$('#fav<?=$itemID?>').submit();" style='cursor: pointer;'>
            <input type="hidden" name="itemID" value="<?=$itemID?>" >
            <div class="" aria-hidden="true" data-toggle="tooltip" data-placement="right" data-original-title="<?=$the_fav_mess?>"><i class="<?=$fav_class?>" id="tehe_fav<?=$itemID?>" ></i></div>
        </form>
<?php }

function getsubCat($catID, $style='1'){
    $ci=&get_instance();
    $gettall_subcat=$ci->db->query("select * from site_sub_cat where sc_ctid ='$catID'");
    $thescat_details=$gettall_subcat->result_array();
    switch($style){ 
        case '1':
            echo '<option value="">Select SubCategory</option>';
            foreach($thescat_details as $thescat){
            echo '<option value="'.$thescat['sc_id'].'">'.$thescat['sc_name'].'</option>';
           }
        break;
        case 'sct_name':
            $gettall_subcat=$ci->db->query("select sc_name from site_sub_cat where sc_id ='$catID' ");
            $thescat_details=$gettall_subcat->row_array();
            return $thescat_details['sc_name'];
        break;
    }
}

function getsub2Cat($catID, $scatID, $style='1'){
    $ci=&get_instance();
    $gettall_variant=$ci->db->query("select * from mr_sub2 where mr_sub2_sid='$scatID' and mr_sub2_cid='$catID'");
    $thevar_details=$gettall_variant->result_array();
    switch($style){ 
        case '1':
            echo '<option value="">Select Sub2Category</option>';
            foreach($thevar_details as $thevar){
            echo '<option value="'.$thevar['mr_sub2_id'].'">'.$thevar['mr_sub2_name'].'</option>';
           }
        break;
        case 'vname':
            $gettall_subcat=$ci->db->query("select mr_sub2_name from mr_sub2 where mr_sub2_id='$catID'");
            $thescat_details=$gettall_subcat->row_array();
            return $thescat_details['mr_sub2_name'];
        break;
    }
}

function convertYoutube($string,$class=0,$height='400px') {
    return preg_replace(
        "/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
        "<iframe src=\"//www.youtube.com/embed/$2\" width='100%' height='$height' allowfullscreen></iframe>",
        $string
    );
}

function get_cou_image($cou_img, $pr_img){
    if($cou_img == ''){
        return base_url('assets/avator/upload/').$pr_img;
    }else{
        return $cou_img;
    }
}

function upload_doc($fileNAmeis,$directory,$targetFileName=''){
    if(isset($_POST))
    {   $DestinationDirectory   = $directory;
    
    if(!isset($_FILES["$fileNAmeis"]) || !is_uploaded_file($_FILES["$fileNAmeis"]['tmp_name']))
    { die('Something wrong with uploaded file, something missing!'); exit; }
    $refrenext=explode(".", $_FILES["$fileNAmeis"]["name"]);
    $extension = end($refrenext);
    $FileName      = str_replace(' ','',strtolower($_FILES["$fileNAmeis"]['name'])); //get image name
    $FileName      = preg_replace('/[^A-Za-z0-9\-]/', '', $FileName);
    $ImageSize      = $_FILES["$fileNAmeis"]['size']; // get original image size
    $TempSrc        = $_FILES["$fileNAmeis"]['tmp_name']; // Temp name of image file stored in PHP tmp folder
    $FileType      = $_FILES["$fileNAmeis"]['type']; //get file type, returns "image/png", image/jpeg, text/plain etc.

        if($targetFileName==''){
            $randomnumber=rand(111111111,999999999);
            $targetFileName=$randomnumber.$FileName.'.'.$extension;
        }
        $NewImageName = $targetFileName.'.'.$extension;
        $DestinationDirectory.=$NewImageName;
        if (move_uploaded_file($_FILES["$fileNAmeis"]['tmp_name'], $DestinationDirectory)) {            
            return 'SUCCXX'.$NewImageName; die;
          } else {
            echo "Sorry, there was an error uploading your file.";
          } 
    }
}


function con_24to12($date_tim, $min,$style, $today=0){
    switch($style){
        case '1':
            if($date_tim == 0){
                $thataretu= '12 :'.$min.' AM';
            }else
            if($date_tim < 12){
                $thataretu= $date_tim.':'.$min.' AM';
            }elseif($date_tim == 12){
                $thataretu= '12'.':'.$min.' PM';
            }else{
                $thataretu= $date_tim-12 .':'.$min.' PM';
            }
            return $thataretu;
        break;
    }
}


function redirect_path($reffer,$url,$style){
    if($reffer !=''){
        return $reffer;
    }else{
        return base_url($url);
    }
}
 ?>
