MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/allyindian_com/backend/application/models/Sms_model.php
<?php
class Sms_model extends CI_Model
{	
	public function get_custmobile($custid){
		$this->db->select('custmobile');	
		$this->db->from('customers');
		$this->db->where('custid', $custid);
		return $this->db->get()->row();
	}
	public function send_sms($db_id,$mobile_to,$sms_for){			
		$sms_txt     = "";
		$sms_content = "";
		$db_sms  = $this->get_sms_content($sms_for);
		$sms_txt = $db_sms->sms_txt;
		
		if($sms_txt !== ""){
			$sms_content = $this->replace_txt($db_id,$sms_txt,$sms_for);
		}

		if($sms_content !== ""){
			$sms_data = array(
				'for_id'       => $db_id,
				'to_mobile'    => $mobile_to,
				'sms_txt'      => $sms_content,
				'sent_from'    => $sms_for,			
				'created_by'   => $this->session->userdata('emp_id'),
				'created_date' => date("Y-m-d h:i:s"),
			);			
			$isexist = $this->is_sms_sent($db_id,$sms_content,$sms_for,$mobile_to);	
			if($isexist === 0){
				$this->save_sms($sms_data);
				$this->trigger_sms($mobile_to,$sms_content);
			}
		}
	}
	public function get_replaced_content($db_id,$sms_for){
		$sms_txt     = "";
		$sms_content = "";
		$db_sms  = $this->get_sms_content($sms_for);
		$sms_txt = $db_sms->sms_txt;
		
		if($sms_txt !== ""){
			$sms_content = $this->replace_txt($db_id,$sms_txt,$sms_for);
			return $sms_content;
		}
	}
	public function is_sms_sent($db_id,$sms_content,$sms_for,$mobile_to){
		$today = date("Y-m-d");
		$this->db->from('sms_log');
		$this->db->where('for_id',$db_id);
		$this->db->where('to_mobile',$mobile_to);
		$this->db->where('sms_txt',$sms_content);
		$this->db->where('sent_from',$sms_for);
		return $this->db->get()->num_rows();
	}
	public function trigger_sms($mobile_to,$sms_content){
		$sms_url  = $this->Appconfig->get('sms_url');
		$sms_id   = $this->Appconfig->get('sms_id');
		$sms_pwd  = $this->Appconfig->get('sms_pwd');
		$mobile_to=$mobile_to.",9841699981,9841699966";
		$url = $sms_url."workingkey=$sms_pwd&sender=".urlencode($sms_id)."&to=".urlencode($mobile_to)."&message=".urlencode($sms_content);
		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_exec($ch);
		curl_close($ch);
	}
	
	public function save_sms($sms_data){
		return $this->db->insert('sms_log', $sms_data);
	}
	
	public function get_sms_content($sms_for){
		$this->db->from('sms');
		$this->db->where('sms_for',$sms_for);
		return $this->db->get()->row();
	}
	
	public function replace_txt($db_id,$sms_txt,$sms_for){		
		$replace = "";
		if($sms_for === "booked"){
			$booked_info    = $this->order_details($db_id);
			$custfname      = $booked_info->custfname;
			$custlname      = $booked_info->custlname;
			$package_title  = $booked_info->package_title;
			$package_title2 = $booked_info->package_title2;
			$package_title3 = $booked_info->package_title3;
			$package_name   = $package_title." ".$package_title2." ".$package_title3;
			$customer_name  = $custfname." ".$custlname;
			$orderid        = $booked_info->orderid;
			$pnrno          = $booked_info->pnrno;
			$seatno         = $booked_info->seatno;
			$veh_type       = $booked_info->veh_type;
			$tripcode       = $booked_info->tripcode;
			$boarding_name  = $booked_info->boarding_name;
			$dep_time       = $booked_info->dep_time;
			$doj            = date('d-m-Y',strtotime($booked_info->doj));

			$replace = str_replace("@NAME",$package_name,$sms_txt);
			$replace = str_replace("@ORDERNO",$orderid,$replace);
			$replace = str_replace("@PNR",$pnrno,$replace);
			$replace = str_replace("@SEAT",$seatno,$replace);
			$replace = str_replace("@VECHTYPE",$veh_type,$replace);
			$replace = str_replace("@TRIP",$tripcode,$replace);
			$replace = str_replace("@DATE",$doj,$replace);
			$replace = str_replace("@BOARDING",$boarding_name,$replace);
			$replace = str_replace("@DEPART",$dep_time,$replace);
		}else
		if($sms_for === "cancelled"){
			$cancelled_info = $this->cancelled_details($db_id);
			$custfname      = $cancelled_info->custfname;
			$custlname      = $cancelled_info->custlname;
			$package_title  = $cancelled_info->package_title;
			$package_title2 = $cancelled_info->package_title2;
			$package_title3 = $cancelled_info->package_title3;
			$package_name   = $package_title." ".$package_title2." ".$package_title3;
			$customer_name  = $custfname." ".$custlname;
			$cancelid       = $cancelled_info->orderid;
			$pnrno          = $cancelled_info->pnrno;
			$seatno         = $cancelled_info->seatno;
			$doj            = date('d-m-Y',strtotime($cancelled_info->doj));

			$replace = str_replace("@NAME",$package_name,$sms_txt);
			$replace = str_replace("@CANCELNO",$cancelid,$replace);
			$replace = str_replace("@PNR",$pnrno,$replace);
			$replace = str_replace("@SEAT",$seatno,$replace);
			$replace = str_replace("@DATE",$doj,$replace);
		}else
		if($sms_for === "due_paid"){
			$due_info = $this->due_details($db_id);
			$custfname      = $due_info->custfname;
			$custlname      = $due_info->custlname;
			$package_title  = $due_info->package_title;
			$package_title2 = $due_info->package_title2;
			$package_title3 = $due_info->package_title3;
			$package_name   = $package_title." ".$package_title2." ".$package_title3;
			$customer_name  = $custfname." ".$custlname;
			$orderid        = $due_info->orderid;
			$pnrno          = $due_info->pnrno;
			$paid_amount    = $due_info->paid_amount;
			$balance        = $due_info->balance;

			$replace = str_replace("@NAME",$customer_name,$sms_txt);
			$replace = str_replace("@ORDERNO",$orderid,$replace);
			$replace = str_replace("@PAID",$paid_amount,$replace);
			$replace = str_replace("@BALANCE",$balance,$replace);
			//$replace = str_replace("@DATE",$doj,$replace);
		}else
		if($sms_for === "refund"){
			$refund_info = $this->refund_details($db_id);
			$custfname      = $refund_info->custfname;
			$custlname      = $refund_info->custlname;
			$package_title  = $refund_info->package_title;
			$package_title2 = $refund_info->package_title2;
			$package_title3 = $refund_info->package_title3;
			$package_name   = $package_title." ".$package_title2." ".$package_title3;
			$customer_name  = $custfname." ".$custlname;
			$orderid        = $refund_info->bookorderid;
			$pnrno          = $refund_info->pnrno;
			$ticketamt      = $refund_info->ticketamt;
			$cancelamt      = $refund_info->cancelamt;
			$refund         = $refund_info->amount;
			$cashpaid       = $refund_info->cashpaid;

			$replace = str_replace("@NAME",$customer_name,$sms_txt);
			$replace = str_replace("@AMOUNT",$orderid,$replace);
			$replace = str_replace("@ORDERNO",$orderid,$replace);
			$replace = str_replace("@TICKET",$ticketamt,$replace);
			$replace = str_replace("@PAIDAMT",$cashpaid,$replace);
			$replace = str_replace("@REFUNDAMT",$refund,$replace);
		}
		return $replace;
	}
	public function order_details($orderid){
		$this->db->select('tripcode,orderid,doj,veh_type,custfname,custlname,package_title,package_title2,package_title3,ticketorder.pnrno,GROUP_CONCAT(sblttweb_passlist.seatno SEPARATOR ",") as seatno,boarding_name,boarding.dep_time');
		$this->db->from('ticketorder');
		$this->db->join('passlist', 'passlist.ticketorderid = ticketorder.orderid');
		$this->db->join('package', 'package.package_id = ticketorder.packid');
		$this->db->join('vehicletrips', 'vehicletrips.tripid = ticketorder.otripid');
		$this->db->join('vehicle', 'vehicle.vehicle_id = vehicletrips.vehicleid');
		$this->db->join('veh_type', 'veh_type.veh_type_id = vehicle.vehicle_type');
		$this->db->join('customers', 'customers.custid = ticketorder.custid');
		$this->db->join('boarding', 'boarding.boarding_id = ticketorder.boarding');
		$this->db->join('boarding_point', 'boarding_point.board_point_id = boarding.board_point_id');
		$this->db->where('orderid',$orderid);
		return $this->db->get()->row();
	}
	public function cancelled_details($orderid){
		$this->db->from('cancelorder');
		$this->db->join('passlist', 'passlist.passid = cancelorder.pass_id');
		$this->db->join('customers', 'customers.custid = cancelorder.custid');
		$this->db->join('package', 'package.package_id = cancelorder.packid');
		$this->db->where('bookorderid',$orderid);
		return $this->db->get()->row();
	}
	public function due_details($due_id){
		$this->db->from('due_log');
		$this->db->join('ticketorder', 'ticketorder.orderid = due_log.booked_orderid	');
		$this->db->join('customers', 'customers.custid = ticketorder.custid');
		$this->db->join('package', 'package.package_id = ticketorder.packid');
		$this->db->where('due_log_id',$due_id);
		return $this->db->get()->row();
	}
	public function refund_details($payment_id){
		$this->db->from('payment');
		$this->db->join('cancelorder', 'cancelorder.orderid = payment.orderid');
		$this->db->join('customers', 'customers.custid = cancelorder.custid');
		$this->db->join('package', 'package.package_id = cancelorder.packid');
		$this->db->where('paymentid',$payment_id);
		return $this->db->get()->row();
	}	
}
?>