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




if (!function_exists('send_text_msg_new')) {
    
   function send_text_msg_new($msg)
    {
        
        $url=$msg;
       
    
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $send_details = curl_exec($ch);
            curl_close($ch);
            
           

                    if(!empty($send_details)){
                        //   if(!empty($send_details)){
                        $status = json_decode($send_details) ;
                        // return $status->status ;
                        return $status ;
                        // return $url ; 
                    }else{
            $json_data = file_get_contents($url);

            $response_data = json_decode($json_data);

            if(!empty($response_data)){
                // $status = $response_data->status ;
                
                        return $response_data; 
                
            }
            else{
            return $url ;

            }

                    }


         return $ddddddd ;  

    }

}





if (!function_exists('send_text_msg')) {
    function send_text_msg($msg)
    {
       
    
            $before = substr($msg, 0, strpos($msg, "message="));
                
            $after = substr($msg, strpos($msg, "&message=") + 1); 

            $string = $after ;

            $remove = 'message=' ;
            $now = trim(str_replace($remove,'',$string));

            // $url = $before. $remove . urlencode($now) ;
            $url = $before.$remove.urlencode($now) ;
          echo $url ;
          return ;
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $send_details = curl_exec($ch);
            curl_close($ch);
            
           

                    if(!empty($send_details)){
                        //   if(!empty($send_details)){
                        $status = json_decode($send_details) ;
                        // return $status->status ;
                        return $status ;
                        // return $url ; 
                    }else{
            $json_data = file_get_contents($url);

            $response_data = json_decode($json_data);

            if(!empty($response_data)){
                // $status = $response_data->status ;
                
                        return $response_data; 
                
            }
            else{
            return $url ;

            }

                    }


         return $ddddddd ;  

    }
}








if (!function_exists('Forget_Mail_stud')) {
    function Forget_Mail_stud($email, $status)
    {
       
        $to_email = $email;
       
        $from_email = 'shop@icrcc.org';
         $user = array('Uid' =>  $status, 'otp' => $status);
      
        $from_name = 'ICRCC.ORG';

        $config = array(

           'protocol' => 'smtp',
            'smtp_host' => 'secure##.inmotionhosting.com',
            'smtp_port' => 'POP3 995',
            'smtp_user' => 'shop@icrcc.org',
            'smtp_pass' => 'Kanpur@78',
            'mailtype'  => 'html',
            'charset'   => 'iso-8859-1'
        );
        $CI = &get_instance();
        $CI->load->library('email', $config);
        $CI->email->set_newline("\r\n");
        $CI->email->from($from_email, $from_name);
        $CI->email->to($to_email);  // replace it with receiver mail id
        $CI->email->subject('Order Received |'  . $to_email); // replace it with relevant subject
        $CI->email->message( $status );
        if ($CI->email->send()) {
        $CI->session->set_flashdata('Success', 'Paid Successfully');
        // redirect(base_url('/frontend/homepage/'));
        return true ;
        } else {
            return false;
            // return false;}
        }
    }
    
    
    
if (!function_exists('hide_string')) {
    function hide_string($string)
    {
        
$number = $string;
     $middle_string ="";
     $length = strlen($number);

     if( $length < 3 ){

       echo $length == 1 ? "*" : "*". substr($number,  - 1);

     }
     else{
        $part_size = floor( $length / 3 ) ; 
        $middle_part_size = $length - ( $part_size * 2 );
        for( $i=0; $i < $middle_part_size ; $i ++ ){
           $middle_string .= "*";
        }

        return  substr($number, 0, $part_size ) . $middle_string  . substr($number,  - $part_size );
    
    
     }
    }
}

    
    if (!function_exists('v_shopNow')) {
    function v_shopNow()
    {
         $CI = &get_instance();
	$condition = array(
		'id' => 1,	);
	$CI->db->select('status');
	$CI->db->from('v_shopNow');
	$CI->db->where($condition);
	//return $CI->db->get()->row();
	$queryResult = $CI->db->get()->row_array();
	return $queryResult['status'] ;
    }}
    
   
    
}
  
    
if (!function_exists('send_mail')) {
    function send_mail($email, $data)
    {
       
        $to_email = $email;
       
        $from_email = 'shop@icrcc.org';
         $user = array('Uid' =>  $status, 'otp' => $status);
    //  $data['data'] = $data ;
        $from_name = ' ICRCC.ORG';

        $config = array(

           'protocol' => 'smtp',
            'smtp_host' => 'secure##.inmotionhosting.com',
            'smtp_port' => 'POP3 995',
            'smtp_user' => 'shop@icrcc.org',
            'smtp_pass' => 'Kanpur@78',
            'mailtype'  => 'html',
            'charset'   => 'iso-8859-1'
        );
       
        $CI = &get_instance();
        $CI->load->library('email', $config);

        $CI->email->set_newline("\r\n");
        $CI->email->set_mailtype("html");
        $CI->email->set_newline("\r\n");
        $CI->email->set_crlf("\r\n");
        $CI->email->from($from_email, $from_name);
        $CI->email->to($to_email);  // replace it with receiver mail id
        $CI->email->subject('Shop Details |' . $from_name); // replace it with relevant subject

        $body = $CI->load->view('email_templates/shopNow_mail.php', ['data' => $data], true);

        $CI->email->message($body);

        if ($CI->email->send()) {
        $CI->session->set_flashdata('Success', 'Paid Successfully');
        // redirect(base_url('/frontend/homepage/'));
        return true ;
        } else {
            return false;
            // return false;}
        }
    }
}

    
    
      
if (!function_exists('emai_api')) {
    function emai_api($email, $data)
    {
       
        $to_email = $email;
        $subject = $data['subject'];
       $from_email = $data['from_email'];
        $from_name = $data['from_name'];
        
    //  $data['data'] = $data ;

        $config = array(

           'protocol' => 'smtp',
            'smtp_host' => 'secure##.inmotionhosting.com',
            'smtp_port' => 'POP3 995',
            'smtp_user' => 'shop@icrcc.org',
            'smtp_pass' => 'Kanpur@78',
            'mailtype'  => 'html',
            'charset'   => 'iso-8859-1'
        );
       
        $CI = &get_instance();
        $CI->load->library('email', $config);

        $CI->email->set_newline("\r\n");
        $CI->email->set_mailtype("html");
        $CI->email->set_newline("\r\n");
        $CI->email->set_crlf("\r\n");
        $CI->email->from($from_email, $from_name);
        $CI->email->to($to_email);  // replace it with receiver mail id
        $CI->email->subject($subject .' | '. $from_name); // replace it with relevant subject

        $body = $CI->load->view('email_templates/emai_api.php', ['data' => $data], true);

        $CI->email->message($body);

        if ($CI->email->send()) {
        $CI->session->set_flashdata('Success', 'Paid Successfully');
        // redirect(base_url('/frontend/homepage/'));
        return true ;
        } else {
            return false;
            // return false;}
        }
    }
}

    
    
if (!function_exists('uDetail')) {
    function uDetail($uId)
    {
       
       $CI = &get_instance();
	$CI->db->select('name , lastname , sname , slname,mobile ,  address , city ,state , zip');
	$CI->db->from('m_subscriber');
// 	$CI->db->join('address', 'ur_course.c_programe_type = ur_programs.pr_id');
	$CI->db->where('id', $uId);
	$return = $CI->db->get()->row();
	if (!empty($return)) {
	    

		return $return;
	} else {
		return "";
	}
       

        
    }
}
  
  
  
if (!function_exists('vRates')) {
    function vRates()
    {
       
       $CI = &get_instance();
	$CI->db->select('*');
	$CI->db->from('v_shopNow');
// 	$CI->db->join('address', 'ur_course.c_programe_type = ur_programs.pr_id');
	$CI->db->where('id', '1');
	$return = $CI->db->get()->row();
	if (!empty($return)) {
	    

		return $return;
	} else {
		return "";
	}
       

        
    }
}

if (!function_exists('reservation_mail')) {
    function reservation_mail($email, $data)
    {
       
        $to_email = $email;
       
        $from_email = 'webadmin@icrcc.org';
         $user = array('Uid' =>  $status, 'otp' => $status);
    //  $data['data'] = $data ;
        $from_name = ' ICRCC.ORG';

        $config = array(

           'protocol' => 'smtp',
            'smtp_host' => 'secure##.inmotionhosting.com',
            'smtp_port' => 'POP3 995',
            'smtp_user' => 'shop@icrcc.org',
            'smtp_pass' => 'Kanpur@78',
            'mailtype'  => 'html',
            'charset'   => 'iso-8859-1'
        );
       
        $CI = &get_instance();
        $CI->load->library('email', $config);

        $CI->email->set_newline("\r\n");
        $CI->email->set_mailtype("html");
        $CI->email->set_newline("\r\n");
        $CI->email->set_crlf("\r\n");
        $CI->email->from($from_email, $from_name);
        $CI->email->to($to_email);  // replace it with receiver mail id
        $CI->email->subject('Reservation Details |' . $from_name); // replace it with relevant subject

        $body = $CI->load->view('email_templates/reservation_mail.php', ['data' => $data], true);

        $CI->email->message($body);

        if ($CI->email->send()) {
        // $CI->session->set_flashdata('Success', 'Paid Successfully');
        // redirect(base_url('/frontend/homepage/'));
        return true ;
        } else {
            return false;
            // return false;}
        }
    }
}
 
if (!function_exists('send_mail_bits')) {
    function send_mail_bits($to_email, $from , $data  , $type)
    {
       
        $CI = &get_instance();
        $CI->db->select('status');
        $CI->db->from('services_status');
        $CI->db->where('service_type', 'php_mailer');
        $return = $CI->db->get()->row();
        $mailer = $return->status ;

        // print_r($data['user_id']) ; exit ;

        $user_id = $data['user_id'] ; 

        $subjectotp = $data['subjectotp'] ; 
        $messageotp = $data['messageotp'] ; 

        $d_t = date("l, d-M-Y h:i:s a"); 

        // if($mailer <> 1 ){
            if($mailer == 1 ){

    //   $from = 'abcd@xyz.com' ;
      $headers = "MIME-Version: 1.0" . "\r\n";
      $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
      
     $link =  $_SERVER['HTTP_HOST'] ;
     $cnameotp = 'noreply' ;

                    $otp=rand(1000,9999);

                    if($type == 'forget_pass_link'){

//                     $link11 = 'link here' ;

//                     $subjectotp = "Your Forgot Password Link!";

// $messageotp = 'Dear User ('.$user_id.'), <br> <br>You can change the password by clicking on below link:- <a href="'.$link11 .'" </a> <br><br>
//                 <br> Above link will be valid for 30 minutes only or for one time use.
//                 Mail Sent at '.$d_t.'<br><br>
//                 <button class="btn btn-secondary"  >This is an auto-generated mail. Please do not reply.</button>';

                    }

                    $tootp = $to_email ; //'animeshsoni0102@gmail.com' ;

    
        $headers .= 'From: <'.$cnameotp.'@'.$link.'>' . "\r\n";
               
     $mre= mail($tootp,$subjectotp,$messageotp,$headers);
     print_r('ok_mail');
     return true ;

        }else{

        $to_email = $to_email ; //'animeshsoni0102@gmail.com';         
       
        $from_email = 'noreply@msgseva.in';
        
        $from_name = 'noreply-' . $_SERVER['HTTP_HOST'] ; //'pan india';

        $config = array(
           'protocol' => 'smtp',
           'smtp_host' => 'dedi.Server2.bitspanindia.com',
           'smtp_port' => '25',
           'smtp_user' => 'noreply@msgseva.in',
           'smtp_pass' => 'Ramramji@4321',
           'mailtype'  => 'html',
           'charset'   => 'iso-8859-1'
                   );
       
        $CI = &get_instance();
        $CI->load->library('email', $config);

        $CI->email->set_newline("\r\n");
        $CI->email->set_mailtype("html");
        $CI->email->set_newline("\r\n");
        $CI->email->set_crlf("\r\n");
        $CI->email->from($from_email, $from_name);
        $CI->email->to($to_email);  // replace it with receiver mail id

        $CI->email->subject($from_name); // replace it with relevant subject

        // $body = $CI->load->view('email_templates/shopNow_mail.php', ['data' => $data], true);

        // if($type == 'forgot_pass_link'){

        $body = $CI->load->view('email_templates/'.$type.'.php', ['data' => $data], true);

        // }

        $CI->email->message($body);

        if ($CI->email->send()) {
       
        // redirect(base_url('/frontend/homepage/'));
        print_r('ok1122');
        return true ;
        
        } else {
            print_r('no1122');
            // show_error($CI->email->print_debugger());
            return false;
            // return false;}
        }
    }

}

}


if (!function_exists('send_mail_bits_11')) {
    function send_mail_bits_11($to_email, $from , $data  , $type)
    {
       
        $CI = &get_instance();
        $CI->db->select('status');
        $CI->db->from('services_status');
        $CI->db->where('service_type', 'php_mailer');
        $return = $CI->db->get()->row();
        $mailer = $return->status ;

        // print_r($data['user_id']) ; exit ;

        $user_id = $data['user_id'] ; 

        $subjectotp = $data['subjectotp'] ; 
        $messageotp = $data['messageotp'] ; 

        $d_t = date("l, d-M-Y h:i:s a"); 

            $mailer = 1 ;
        // if($mailer <> 1 ){
           
        // else{
        if($mailer == 1 ){

        $to_email = $to_email ; //'animeshsoni0102@gmail.com';         
       
        $from_email = 'noreply@msgseva.in';
        
        $from_name = 'noreply-' . $_SERVER['HTTP_HOST'] ; //'pan india';

        $config = array(
           'protocol' => 'smtp',
          'smtp_host' => 'dedi.Server2.bitspanindia.com',
        // 'smtp_host' => 'http://bitspanindia.com:2095',
        
           'smtp_port' => '25',
           'smtp_user' => 'noreply@msgseva.in',
           'smtp_pass' => 'Ramramji@4321',
           'mailtype'  => 'html',
           'charset'   => 'iso-8859-1'
                   );
    //   print_r($config) ;
      
        $CI = &get_instance();
        $CI->load->library('email', $config);

        $CI->email->set_newline("\r\n");
        $CI->email->set_mailtype("html");
        $CI->email->set_newline("\r\n");
        $CI->email->set_crlf("\r\n");
        $CI->email->from($from_email, $from_name);
        $CI->email->to($to_email);  // replace it with receiver mail id

        $CI->email->subject($from_name); // replace it with relevant subject

        // $body = $CI->load->view('email_templates/shopNow_mail.php', ['data' => $data], true);

        // if($type == 'forgot_pass_link'){

        $body = $CI->load->view('email_templates/'.$type.'.php', ['data' => $data], true);

// $body = $CI->load->view('email_templates/'.'forget_pass_link'.'.php', ['data' => $data], true);
        // }

        $CI->email->message($body);

        if ($CI->email->send()) {
       
        // redirect(base_url('/frontend/homepage/'));
        // print_r('ok1122');
        // return true ;
        
    } 
    
    // else if($mailer == 1 ){
    if($mailer == 1){

    //   $from = 'abcd@xyz.com' ;
      $headers = "MIME-Version: 1.0" . "\r\n";
      $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
      
     $link =  $_SERVER['HTTP_HOST'] ;
     $cnameotp = 'noreply' ;

                    $otp=rand(1000,9999);

                    $tootp = $to_email ; //'animeshsoni0102@gmail.com' ;

    
        $headers .= 'From: <'.$cnameotp.'@'.$link.'>' . "\r\n";
               
     $mre= mail($tootp,$subjectotp,$messageotp,$headers);
    //  print_r($headers);
    
    
     return true ;

        }
        
    // else {
        //     print_r('no1122');
        //     // show_error($CI->email->print_debugger());
        //     return false;
        //     // return false;}
        // }
    }

}

}


if (!function_exists('send_mail_bits_new_otp')) {
    function send_mail_bits_new_otp($to_email, $from , $data  , $type)
    {
       
        $CI = &get_instance();
        $CI->db->select('status');
        $CI->db->from('services_status');
        $CI->db->where('service_type', 'php_mailer');
        $return = $CI->db->get()->row();
        $mailer = $return->status ;

        // print_r($data['user_id']) ; exit ;

        $user_id = $data['user_id'] ; 

        $subjectotp = $data['subjectotp'] ; 
        $messageotp = $data['messageotp'] ; 

        $d_t = date("l, d-M-Y h:i:s a"); 

            $mailer = 1 ;
        // if($mailer <> 1 ){
           
        // else{
        if($mailer == 1 ){

        $to_email = $to_email ; //'animeshsoni0102@gmail.com';         
       
        $from_email = 'noreply@msgseva.in';
        
        $from_name = 'noreply-' . $_SERVER['HTTP_HOST'] ; //'pan india';

        $config = array(
           'protocol' => 'smtp',
          'smtp_host' => 'dedi.Server2.bitspanindia.com',
        // 'smtp_host' => 'http://bitspanindia.com:2095',
        
           'smtp_port' => '25',
           'smtp_user' => 'noreply@msgseva.in',
           'smtp_pass' => 'Ramramji@4321',
           'mailtype'  => 'html',
           'charset'   => 'iso-8859-1'
                   );
    //   print_r($config) ;
      
        $CI = &get_instance();
        $CI->load->library('email', $config);

        $CI->email->set_newline("\r\n");
        $CI->email->set_mailtype("html");
        $CI->email->set_newline("\r\n");
        $CI->email->set_crlf("\r\n");
        $CI->email->from($from_email, $from_name);
        $CI->email->to($to_email);  // replace it with receiver mail id

        $CI->email->subject($from_name); // replace it with relevant subject

        // $body = $CI->load->view('email_templates/shopNow_mail.php', ['data' => $data], true);

        // if($type == 'forgot_pass_link'){

        $body = $CI->load->view('email_templates/'.$type.'.php', ['data' => $data], true);

// $body = $CI->load->view('email_templates/'.'forget_pass_link'.'.php', ['data' => $data], true);
        // }

        $CI->email->message($body);

        if ($CI->email->send()) {
       
        // redirect(base_url('/frontend/homepage/'));
        // print_r('ok1122');
        // return true ;
        
    } 
    
    // else if($mailer == 1 ){
    if($mailer == 1){

    //   $from = 'abcd@xyz.com' ;
      $headers = "MIME-Version: 1.0" . "\r\n";
      $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
      
     $link =  $_SERVER['HTTP_HOST'] ;
     $cnameotp = 'noreply' ;

                    $otp=rand(1000,9999);

                    $tootp = $to_email ; //'animeshsoni0102@gmail.com' ;

    
        $headers .= 'From: <'.$cnameotp.'@'.$link.'>' . "\r\n";
               
     $mre= mail($tootp,$subjectotp,$messageotp,$headers);
    //  print_r($headers);
    
    
     return true ;

        }
        
    // else {
        //     print_r('no1122');
        //     // show_error($CI->email->print_debugger());
        //     return false;
        //     // return false;}
        // }
    }

}

}

if (!function_exists('send_mail_bits_1122')) {
    function send_mail_bits_1122($to_email, $from , $data  , $type)
    {
       
        $CI = &get_instance();
        $CI->db->select('status');
        $CI->db->from('services_status');
        $CI->db->where('service_type', 'php_mailer');
        $return = $CI->db->get()->row();
        $mailer = $return->status ;

        // print_r($data['user_id']) ; exit ;

        $user_id = $data['user_id'] ; 

        $subjectotp = $data['subjectotp'] ; 
        $messageotp = $data['messageotp'] ; 

        $d_t = date("l, d-M-Y h:i:s a"); 

            $mailer = 1 ;
       
      
        if($mailer == 1 ){

        $to_email = $to_email ; //'animeshsoni0102@gmail.com';         
       
        $from_email = 'noreply@msgseva.in';
        
        $from_name = 'noreply-' . $_SERVER['HTTP_HOST'] ; //'pan india';

        $config = array(
           'protocol' => 'smtp',
          'smtp_host' => 'dedi.Server2.bitspanindia.com',
        // 'smtp_host' => 'http://bitspanindia.com:2095',
        
           'smtp_port' => '25',
           'smtp_user' => 'noreply@msgseva.in',
           'smtp_pass' => 'Ramramji@4321',
           'mailtype'  => 'html',
           'charset'   => 'iso-8859-1'
                   );
      print_r($config) ;
      
        $CI = &get_instance();
        $CI->load->library('email', $config);

        $CI->email->set_newline("\r\n");
        $CI->email->set_mailtype("html");
        $CI->email->set_newline("\r\n");
        $CI->email->set_crlf("\r\n");
        $CI->email->from($from_email, $from_name);
        $CI->email->to($to_email);  // replace it with receiver mail id

        $CI->email->subject($from_name); // replace it with relevant subject

        // $body = $CI->load->view('email_templates/shopNow_mail.php', ['data' => $data], true);

        // if($type == 'forgot_pass_link'){

        $body = $CI->load->view('email_templates/'.$type.'.php', ['data' => $data], true);

// $body = $CI->load->view('email_templates/'.'forget_pass_link'.'.php', ['data' => $data], true);
        // }

        $CI->email->message($body);

        if ($CI->email->send()) {
       
       
        
    } 
    
    if($mailer == 1){

    //   $from = 'abcd@xyz.com' ;
      $headers = "MIME-Version: 1.0" . "\r\n";
      $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
      
     $link =  $_SERVER['HTTP_HOST'] ;
     $cnameotp = 'noreply' ;

                    $otp=rand(1000,9999);

                    $tootp = $to_email ; //'animeshsoni0102@gmail.com' ;

    
        $headers .= 'From: <'.$cnameotp.'@'.$link.'>' . "\r\n";
               
     $mre= mail($tootp,$subjectotp,$messageotp,$headers);
     print_r($headers);
    
    show_error($CI->email->print_debugger()) ;
     return true ;

        }
        
    // else {
        //     print_r('no1122');
        //     // show_error($CI->email->print_debugger());
        //     return false;
        //     // return false;}
        // }
    }

}

}






if (!function_exists('send_app_mail')) {



    function send_app_mail($to, $subject, $message)

    {

        // $to = 'animeshsoni0102@gmail.com' ;
        $to = 'animesh@bitspanindia.com' ;
        $subject = 'thnx for join' ;
        $message = 'support us' ;

        $ci =&get_instance();

        // $res=$ci->db->query("SELECT usesmtp,smtphost,smtpuser,smtppassword,smtpport,emailfromaddress,emailfromname,securitytype FROM tblsetting WHERE id=1");

        // $row=$res->row_array();

        

        /* $email_config = array(
            'mailtype' => 'html',
            'charset' => 'utf-8',
            'priority' => '1'
        ); */
        $email_config = Array(
            'charset' => 'utf-8',
            'priority' => '1'
        );
         

        //check mail sending method from settings

        // 'protocol' => 'SMTP',
        //    'smtp_host' => 'dedi.bitspanindia.com',
        //    'smtp_port' => '25',
        //    'smtp_user' => 'kapil@bitspanindia.com',
        //    'smtp_pass' => 'Kapil@123',
        //    'mailtype'  => 'html',

        if (1 == 1) {
            $email_config["protocol"] = "smtp";
            $email_config["smtp_host"] = 'dedi.bitspanindia.com';
            $email_config["smtp_port"] = '25';
            $email_config["smtp_user"] = 'kapil@bitspanindia.com';
            $email_config["smtp_pass"] = 'Kapil@123' ;
            // $email_config["smtp_crypto"] = $row['securitytype'];

            if (!$email_config["smtp_crypto"]) {
                $email_config["smtp_crypto"] = "tls"; //for old clients, we have to set this by defaultsssssssss
            }

            if ($email_config["smtp_crypto"] === "none") {
                $email_config["smtp_crypto"] = "";
            }

 
            $ci->load->library('email', $email_config);
            $ci->email->clear(true); //clear previous message and attachment
            $ci->email->set_newline("\r\n");
            $ci->email->set_mailtype("html");
            $ci->email->set_crlf("\r\n");
            $ci->email->from('kapil@bitspanindia.com', 'kapil@bitspanindia.com');
            $ci->email->to($to);
            $ci->email->subject($subject);
            $ci->email->message($message);
           

            //send email

            if ($ci->email->send()) {

                echo 'send';

                // return true;

            } else {

                //show error message in none production version

                

                    show_error($ci->email->print_debugger());

                

                // return false;

            }

        }



       

    }

}
  


  
if (!function_exists('encode_param')) {
    function encode_param($string)
    {
        $privateKey 	= 'AA74CDCC2BBRT935136HH7B63C27'; // user define key
        $secretKey      = '5fgf5HJ5g27'; // user define secret key
        $encryptMethod  = "AES-256-CBC";
        // $string 	= 'bits_pan_india_pay24'; // user define value
        
        $key     = hash('sha256', $privateKey);
        $ivalue  = substr(hash('sha256', $secretKey), 0, 16); // sha256 is hash_hmac_algo
        $result      = openssl_encrypt($string, $encryptMethod, $key, 0, $ivalue);
         $output = base64_encode($result);
         return $output ;  

    }}


    
if (!function_exists('decode_param')) {
    function decode_param($stringEncrypt)
    {
       
    $privateKey 	= 'AA74CDCC2BBRT935136HH7B63C27'; // user define key
    $secretKey 	= '5fgf5HJ5g27'; // user define secret key
    $encryptMethod  = "AES-256-CBC";
    // $stringEncrypt  = 'S0NKRWpWYlpybGdYREtTNlByVU10bmRlVThQU0FxbEpHUjZTMnd1RGY5UT0'; // user encrypt value
    $key    = hash('sha256', $privateKey);
    $ivalue = substr(hash('sha256', $secretKey), 0, 16); // sha256 is hash_hmac_algo
     $ddddddd = openssl_decrypt(base64_decode($stringEncrypt), $encryptMethod, $key, 0, $ivalue);
    
    // $response['endc'] = $output.'~' . $ddddddd ;
         return $ddddddd ;  

    }}
    
    if (!function_exists('send_gmail')) {
    function send_gmail($tomail, $mail_subject, $REPLACE_MGS,$file = '')
	{
		$CI = & get_instance();
		$tomail = strtolower($tomail);
		$CI->load->library(['email']);
		$mail_from = config_item('mail_from');
		$mail_from_name = config_item('mail_from_name');
		$config['protocol'] = config_item('mailer');
		$config['smtp_host'] = config_item('smtp_host');
		$config['smtp_port'] = config_item('smtp_port');
		$config['smtp_timeout'] = '7';
		$config['smtp_user'] = config_item('smtp_username');
		$config['smtp_pass'] = trim(config_item('smtp_password'));
		$config['charset'] = 'utf-8';
		$config['newline'] = "\r\n";
		$config['mailtype'] = 'html';
		$config['validation'] = TRUE;
		$CI->email->initialize($config);
		$CI->email->from($mail_from, $mail_from_name);
		$CI->email->to($tomail);
		$CI->email->subject($mail_subject);
		$CI->email->message($REPLACE_MGS);
		if($file != '')
		{
			$CI->email->attach($file);
		}
		$ree = $CI->email->print_debugger();
		//prx($ree);
		$res = $CI->email->send();
		//prx($res);
		return $res;
		
	}
    }
    
    
    if (!function_exists('send_gmail_new')) {
    function send_gmail_new($from_email = '',$from_name ='', $server = '', $port ='' , $Username,$Password = '' , $data , $type ='')
	{
		$CI = & get_instance();
		
		$ci =&get_instance();

        $res=$ci->db->query("SELECT smtp_user,smtp_detail,from_detail FROM smtp_setting WHERE id=1");
        $row=$res->row_array();
        
        $server = '' ;
        $port =  '465' ;
        
        $Username =  $row['smtp_user'];
        
        $Password = base64_decode($row['smtp_detail']);
        
        $type = 
	 $config = array(
            'protocol' => 'SMTP',
            'smtp_host' => $server,
            'smtp_port' => $port,
            'smtp_user' => $Username,
            'smtp_pass' => $Password,
            'mailtype'  => 'html',
            'charset'   => 'iso-8859-1',
            'smtp_crypto' => 'tls',
        );
        
        // $config['smtp_crypto'] = 'tls';
        $CI = &get_instance();
        $CI->load->library('email', $config);

        $CI->email->set_newline("\r\n");

        $CI->email->from($from_email, $from_name);
        // $CI->email->to($data['email']);  // replace it with receiver mail id
         $CI->email->to('animeshsoni0102@gmail.com');
        //  $CI->email->to('bitspan2008@gmail.com'); 
        $CI->email->subject('Your otp'); // replace it with relevant subject

        // $body = $CI->load->view('email_templates/demo_mail_page', ['data' => $data], true);

        $type = 'reset_pss_otp' ;
            $body= $ci->load->view('email_templates/'.$type.'.php', ['data' => $data], true);
            
        $CI->email->message($body);
        // $status = $CI->email->send();
        print_r($body);
        //Send mail
        if ($CI->email->send()) {
            return true;
        } else {
            	$ree = $CI->email->print_debugger();
		//prx($ree);
            return $ree;
        }
	}
    }
     
if (!function_exists('send_text_msg')) {
    function send_text_msg($msg)
    {
       
    
$before = substr($msg, 0, strpos($msg, "message="));
    
$after = substr($msg, strpos($msg, "&message=") + 1); 

$string = $after ;

$remove = 'message=' ;
$now = trim(str_replace($remove,'',$string));

// $url = $before. $remove . urlencode($now) ;
$url = $before.$remove.($now) ;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$send_details = curl_exec($ch);
curl_close($ch);

        if(!empty($send_details)){
            //   if(!empty($send_details)){
            $status = json_decode($send_details) ;
            // return $status->status ;
            return $status ;
            // return $url ; 
        }else{
$json_data = file_get_contents($url);

$response_data = json_decode($json_data);

if(!empty($response_data)){
    // $status = $response_data->status ;
    
            return $response_data; 
    
}
else{
return $url ;

}

        }


         return $ddddddd ;  

    }}





//send mail using smtp

if (!function_exists('send_mail_bits_gmail_smtp')) {
    function send_mail_bits_gmail_smtp($to_email, $from , $data  , $type)
    {
        $ci =&get_instance();

        $res=$ci->db->query("SELECT smtp_user,smtp_detail,from_detail FROM smtp_setting WHERE id=1");
        $row=$res->row_array();
        
        if(!empty($row))
        {
            $email_config["protocol"] = "smtp";
            $email_config["smtp_host"] = 'ssl://smtp.googlemail.com';
            $email_config["smtp_port"] = 465;
            $email_config["smtp_user"] = $row['smtp_user'];
            $email_config["smtp_pass"] = base64_decode($row['smtp_detail']);
              $email_config["charset"] = "iso-8859-1";
            $ci->load->library('email', $email_config);
            $ci->email->clear(true); //clear previous message and attachment
            $ci->email->set_newline("\r\n");
            $ci->email->set_mailtype("html");
            $ci->email->set_crlf("\r\n");
            $ci->email->from($row['from_detail']);
            $ci->email->to($to_email);
            $ci->email->subject($data['subjectotp']);
            
            // prx($data);
            
            $message= $ci->load->view('email_templates/'.$type.'.php', ['data' => $data], true);
            $ci->email->message($message);
            
            // print_r($message) ;
             if ($ci->email->send()) {

             
                return true;
                

            } else {


                //show error message in none production version

                // if (ENVIRONMENT !== 'production') {

                    show_error($ci->email->print_debugger());

                // }

                return false;

            }
        }
        
        
    }
}


