?
Current File : /home2/slickdealsnews/public_html/application/libraries/Sms_lib.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 *
 * @package     Library
 * @category    Sms lib
 * @author      Pradeep
 * @website     http://www.techbuddiesit.com
 * @company     Techbuddies IT Inc 
 * @since       Version 3.0
 */

class Sms_lib {  

    protected $api_url;
    protected $username;
    protected $sender;
    protected $password;

    function __construct() {

        /*KYI sms Gateway*/
        $this->api_url      = API_URL;
        $this->apikey       = API_KEY;
        $this->senderid     = SENDERID;
        $this->format        = FORMAT;
   }
    
    public function send_order_confirm_sms($user_name, $number, $order_no, $amount = NULL, $order_type = 2) 
    {

        $CI             = & get_instance();
        $delivery_date  = 'Not set';
        $timeslot       = 'Not set';
        if(!isset($number) || empty($number))
        {
            $user_preference        = $CI->session->userdata('user_preference');
            if(isset($user_preference) && !empty($user_preference))
            {
                $delivery_address_id    = $user_preference->order_preference_address;
                $user_address_record    = userAddressbyid($delivery_address_id);
                $number                 = $user_address_record[0]->mobile_number;
            }
            else
            {
                return FALSE;
            }
        }
        
        if (isset($order_no) && !empty($order_no)) {
            
            $sql = "SELECT selectdeliverydate, selectdeliverytime FROM `tbl_order` WHERE `tbl_order`.`order_number` = '" . $order_no . "'";
            $query = $CI->db->query($sql);
            if ($query->num_rows() > 0) {
                $data = $query->row();
                $delivery_date = date('d-m-Y',strtotime($data->selectdeliverydate));
                $timeslot = $data->selectdeliverytime;
            }
        }
        if(isset($order_type) && $order_type == 1)
        {

            $template = sms_templates("ORDER_SUCCESS_PICKUP");
        }
        else
        {
            $template = sms_templates("ORDER_SUCCESS");

        }
        if(isset($template) && !empty($template))
        {
            $template = str_replace('$user_name', ucwords(strtolower($user_name)), $template);
            $template = str_replace('$order_no', $order_no, $template);
            $template = str_replace('$delivery_date', $delivery_date, $template);
            $template = str_replace('$timeslot', $timeslot, $template);
            $message = $template;
        }

        if ($number && $message) {

            $url = $this->api_url."?apikey=" . $this->apikey . "&senderid=" . $this->senderid ."&number=" . $number . "&message=" . urlencode($message) ."&format=".$this->format;

            if(isset($url) && !empty($url))
            {
                return file_get_contents($url);
            }
        }
    }

    public function send_order_status_sms($user_name, $number, $order_no, $type, $smstype = 'NOT_SET') 
    {

        $template = sms_templates($smstype);
        if(isset($template) && !empty($template))
        {
            $template = str_replace('$order_no', $order_no, $template);
            $template = str_replace('$user_name', ucwords(strtolower($user_name)), $template);
            $template = str_replace('$type', $type, $template);
            $message = $template;
        }

        if (isset($number) && !empty($number) && strlen($number) >= 10 && isset($message) && !empty($message)) 
        {

             $url = $this->api_url."?apikey=" . $this->apikey . "&senderid=" . $this->senderid ."&number=" . $number . "&message=" . urlencode($message) ."&format=".$this->format;

            
            if(isset($url) && !empty($url))
            {
                return file_get_contents($url);
            }
        }
    }

    public function send_wallet_pin($pin=NULL,$number=NULL,$templte=NULL){
        $template = sms_templates($templte);

        if(isset($template) && !empty($template))
        {
            $template = str_replace('$pin', $pin, $template);
            $message = $template;
        }
        if($number !='' )
        {
             $url = $this->api_url."?apikey=" . $this->apikey . "&senderid=" . $this->senderid ."&number=" . $number . "&message=" . urlencode($message) ."&format=".$this->format;
        }
        if(isset($url) && !empty($url))
            {
                return file_get_contents($url);
            }
    }

    public function send_order_rescheduled_sms($user_name, $number, $order_no, $type, $smstype = 'NOT_SET', $order_date = NULL, $time_slot = NULL) 
    {

        $template = sms_templates($smstype);
        if(isset($template) && !empty($template))
        {
            $template = str_replace('$order_no', $order_no, $template);
            $template = str_replace('$user_name', ucwords(strtolower($user_name)), $template);
            $template = str_replace('$type', $type, $template);
            $template = str_replace('$order_date', $order_date, $template);
            $template = str_replace('$time_slot', $time_slot, $template);
            $message = $template;
        }

        if (isset($number) && !empty($number) && strlen($number) >= 10 && isset($message) && !empty($message)) 
        {

             $url = $this->api_url."?apikey=" . $this->apikey . "&senderid=" . $this->senderid ."&number=" . $number . "&message=" . urlencode($message) ."&format=".$this->format;

            // $url = $this->api_url."?username=" . urlencode($this->username) . "&password=" . urlencode($this->password) . "&to=" . urlencode($number) . "&sender=" . urlencode($this->sender) . "&message=" . urlencode($message) . "&type=" . urlencode('3')."&priority=1&dnd=1&unicode=0";

            if(isset($url) && !empty($url))
            {
                return file_get_contents($url);
            }
        }
    }

    public function send_order_sms_payment_failed($user_name, $number, $order_no) 
    {

        $template = sms_templates('ORDER_FAILED');
        if(isset($template) && !empty($template))
        {
            $template = str_replace('$user_name', ucwords(strtolower($user_name)), $template);
            $template = str_replace('$order_no', $order_no, $template);
            $message = $template;
        }

        if (isset($number) && !empty($number) && strlen($number) >= 10 && isset($message) && !empty($message)) 
        {

             $url = $this->api_url."?apikey=" . $this->apikey . "&senderid=" . $this->senderid ."&number=" . $number . "&message=" . urlencode($message) ."&format=".$this->format;
            
            // $url = $this->api_url."?username=" . urlencode($this->username) . "&password=" . urlencode($this->password) . "&to=" . urlencode($number) . "&sender=" . urlencode($this->sender) . "&message=" . urlencode($message) . "&type=" . urlencode('3')."&priority=1&dnd=1&unicode=0";

            if(isset($url) && !empty($url))
            {
                return file_get_contents($url);
            }
        }
    }

    public function send_forgot_sms( $number, $resetlink, $smstype = 'NOT_SET') 
    {
        $template = sms_templates($smstype);
        if(isset($template) && !empty($template))
        {
            $template = str_replace('$resetlink', $resetlink, $template);
            $message = $template;
        }
        else
        {
            $message = "Click the below Link to reset the Password :- ".$resetlink;
        }

         $url = $this->api_url."?apikey=" . $this->apikey . "&senderid=" . $this->senderid ."&number=" . $number . "&message=" . urlencode($message) ."&format=".$this->format;

        // $url = $this->api_url."?username=" . urlencode($this->username) . "&password=" . urlencode($this->password) . "&to=" . urlencode($number) . "&sender=" . urlencode($this->sender) . "&message=" . urlencode($message) . "&type=" . urlencode('3')."&priority=1&dnd=1&unicode=0";

        if(isset($url) && !empty($url))
        {
            return file_get_contents($url);
        }
    }

    public function send_singup_sms( $number, $password, $smstype = 'NOT_SET') 
    {
        $template = sms_templates($smstype);
        if(isset($template) && !empty($template))
        {
            $template = str_replace('$password', $password, $template);
            $message = $template;
        }
        else
        {
            $message = "Your password is - ".$password.". Please login using this password";
        }

         $url = $this->api_url."?apikey=" . $this->apikey . "&senderid=" . $this->senderid ."&number=" . $number . "&message=" . urlencode($message) ."&format=".$this->format;

        // $url = $this->api_url."?username=" . urlencode($this->username) . "&password=" . urlencode($this->password) . "&to=" . urlencode($number) . "&sender=" . urlencode($this->sender) . "&message=" . urlencode($message) . "&type=" . urlencode('3')."&priority=1&dnd=1&unicode=0";

        if(isset($url) && !empty($url))
        {
            return file_get_contents($url);
        }
    }

    
    public function send_otp( $number, $otp, $smstype = 'NOT_SET') 
    {
        $template = sms_templates($smstype);
        if(isset($template) && !empty($template))
        {
            $template = str_replace('$otp', $otp, $template);
            $message = $template;
        }

        $url = $this->api_url."?apikey=" . $this->apikey . "&senderid=" . $this->senderid ."&number=" . $number . "&message=" . urlencode($message) ."&format=".$this->format;

        // $url = $this->api_url."?username=" . urlencode($this->username) . "&password=" . urlencode($this->password) . "&to=" . urlencode($number) . "&sender=" . urlencode($this->sender) . "&message=" . urlencode($message) . "&type=" . urlencode('3')."&priority=1&dnd=1&unicode=0";

        if(isset($url) && !empty($url))
        {
            return file_get_contents($url);
        }
    }
    
    public function send_wallet_pin_sms( $number, $pin, $smstype = 'NOT_SET')
    {
        $template = sms_templates($smstype);
        if(isset($template) && !empty($template))
        {
            $template = str_replace('$pin', $pin, $template);
            $message = $template;
        }

         $url = $this->api_url."?apikey=" . $this->apikey . "&senderid=" . $this->senderid ."&number=" . $number . "&message=" . urlencode($message) ."&format=".$this->format;

        // $url = $this->api_url."?username=" . urlencode($this->username) . "&password=" . urlencode($this->password) . "&to=" . urlencode($number) . "&sender=" . urlencode($this->sender) . "&message=" . urlencode($message) . "&type=" . urlencode('3')."&priority=1&dnd=1&unicode=0";

        if(isset($url) && !empty($url))
        {
            return file_get_contents($url);
        }
    }

    public function send_wallet_otp_sms( $number, $otp, $smstype = 'NOT_SET')
    {
        $template = sms_templates($smstype);
        if(isset($template) && !empty($template))
        {
            $template = str_replace('$otp', $otp, $template);
            $message = $template;
        }

         $url = $this->api_url."?apikey=" . $this->apikey . "&senderid=" . $this->senderid ."&number=" . $number . "&message=" . urlencode($message) ."&format=".$this->format;

        // $url = $this->api_url."?username=" . urlencode($this->username) . "&password=" . urlencode($this->password) . "&to=" . urlencode($number) . "&sender=" . urlencode($this->sender) . "&message=" . urlencode($message) . "&type=" . urlencode('3')."&priority=1&dnd=1&unicode=0";

        if(isset($url) && !empty($url))
        {
            return file_get_contents($url);
        }
    }

    public function send_addmoneyinwallet_sms( $number, $amount, $smstype = 'NOT_SET', $customer_name = NULL, $total_amount = 0)
    {
        $template = sms_templates($smstype);
        if(isset($template) && !empty($template))
        {
            $template = str_replace('$amount', $amount, $template);
            $template = str_replace('$customer_name', $customer_name, $template);
            $template = str_replace('$total_amount', $total_amount, $template);
            $message = $template;
        }

         $url = $this->api_url."?apikey=" . $this->apikey . "&senderid=" . $this->senderid ."&number=" . $number . "&message=" . urlencode($message) ."&format=".$this->format;
        
        if(isset($url) && !empty($url))
        {
            return file_get_contents($url);
        }
    }
    
}