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/sbltt/application/models/Sms_model.php
<?php
class Sms_model extends CI_Model
{
	public function resend_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;
		$template_id = $db_sms->template_id;
		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"),
			);
			$this->save_sms($sms_data);
			$this->trigger_sms($mobile_to,$sms_content,$template_id);
			return $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 send_traking_url($op_line_id){
		$opetation_info = $this->operation_confirm($op_line_id);
		$mobile_to  = $opetation_info->phone_number;
		$vehicle_no    = $opetation_info->vehicle_no;
		$tracking_link = $opetation_info->tracking_link;
		$trip_days     = $opetation_info->trip_days;
		if($tracking_link){
			$url = "http://gpsvts.net/mobile/getVehicleExpForSblt?vehicleId=".urlencode($tracking_link)."&userId=manisblt&days=".urlencode($trip_days);
			$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);
			$tracking_url = curl_exec($ch);
			curl_close($ch);
			echo "BSK $tracking_url"; die;
			$sms_data = array(
				'for_id'       => $op_line_id,
				'to_mobile'    => $mobile_to,
				'sms_txt'      => $tracking_url,
				'sent_from'    => "tracking_url",			
				'created_by'   => $this->session->userdata('emp_id'),
				'created_date' => date("Y-m-d h:i:s"),
			);			
			$isexist = $this->is_sms_sent($op_line_id,$tracking_url,'tracking_url',$mobile_to);
			if($isexist === 0){
				$this->save_sms($sms_data);
				$this->trigger_sms($mobile_to,$tracking_url);		
			}
		}
	}
	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;
		$template_id = $db_sms->template_id;
		
		if($sms_txt !== ""){
			$sms_content = $this->replace_txt($db_id,$sms_txt,$sms_for);
		}
		//echo "sms_content :: $sms_content";
		//exit(0);
		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,$template_id);
				/* TO all -Ragu asked to remove
					Add For Managers only
					1.Ragu Admin       - 9841699956
					2.Vasu Operation   - 9841698503 / 9841699981
					3.Murali Operation - 9710764865										
					4.Karthi Accounts  - 9841699974
					5.CRM Team         - 9841699966
					6.elango - 9841587512
					if(($sms_for === "enquiry_confirm") || ($sms_for === "booking_confirm") || ($sms_for === "operation_confirm") || ($sms_for === "booking_cancelled")){
						$this->trigger_sms("9841699956,9841698503,9710764865,9841699974,9841699966,9841587512",$sms_content);
					}
				*/
				//$this->trigger_sms("9841699956,9841699981,9710764865,9841699974,9841699966,9841587512",$sms_content);	
				/* only to managers - Ragu asked to remove Activated requested by viji and raghu 10sep2018*/
				if(($sms_for === "catering_confirm") || ($sms_for === "catering_cancelled")){
					$this->trigger_sms("9841698549",$sms_content,$template_id);
				}else{
					/*$this->trigger_sms("9841699956,9841699981,9841587512",$sms_content);	*/
				}
				
				if($sms_for === "operation_confirm"){
					$this->trigger_sms("9841698503",$sms_content,$template_id);
				}
			}
		}
	}
	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);
		//$this->db->where('created_date',$today);
		return $this->db->get()->num_rows();
	}
	public function trigger_sms($mobile_to,$sms_content,$template_id){
		$sms_url   = $this->Appconfig->get('sms_url');
		$sms_id    = $this->Appconfig->get('sms_id');
		$sms_pwd   = $this->Appconfig->get('sms_pwd');	
		$client_id = '514a8b75-44cf-491d-bb2d-2e5a1ca31b00';	
		$url = $sms_url."SenderId=".urlencode($sms_id)."&Message=".urlencode($sms_content)."&MobileNumbers=".urlencode($mobile_to)."&TemplateId=".urlencode($template_id)."&ApiKey=$sms_pwd&ClientId=$client_id";
		//echo $url; die;
		$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 === "enquiry_confirm"){
			$enquiry_info   = $this->enquiry_confirm($db_id);
			$customer_name  = $enquiry_info->customer_name;
			$enquiry_id     = $enquiry_info->enquiry_id;
			$veh_type       = $enquiry_info->veh_type;
			$trip_type      = $enquiry_info->trip_type_name;
			$from_date      = date('d-m-Y',strtotime($enquiry_info->from_date));
			$enquiry_id     = "INQ".str_pad($enquiry_id, 4, '0', STR_PAD_LEFT);
			
			$replace = str_replace("@NAME",$customer_name,$sms_txt);
			$replace = str_replace("@TOURNO",$enquiry_id,$replace);
			$replace = str_replace("@VECHTYPE",$veh_type,$replace);
			$replace = str_replace("@DATE",$from_date,$replace);
			$replace = str_replace("@TRIP",$trip_type,$replace);
		}else
		if(($sms_for === "booking_confirm") || ($sms_for === "booking_cancelled")){
			$booking_info   = $this->booking_confirm($db_id);
			$customer_name  = $booking_info->customer_name;
			$tour_no        = $booking_info->tour_no;
			$veh_type       = $booking_info->veh_type;
			$reporting_time = $booking_info->reporting_time;
			$trip_type      = $booking_info->trip_type_name;
			$reporting_time = date("G:i", strtotime($reporting_time));
			$from_date      = date('d-m-Y',strtotime($booking_info->from_date));
						
			$replace = str_replace("@NAME",$customer_name,$sms_txt);
			$replace = str_replace("@TOURNO",$tour_no,$replace);
			$replace = str_replace("@VECHTYPE",$veh_type,$replace);
			$replace = str_replace("@TIME",$reporting_time,$replace);
			$replace = str_replace("@DATE",$from_date,$replace);
			$replace = str_replace("@TRIP",$trip_type,$replace);
		}else
		if($sms_for === "operation_confirm"){
			$operation_info   = $this->operation_confirm($db_id);
			$customer_name        = $operation_info->customer_name;
			$tour_no              = $operation_info->tour_no;
			$veh_type             = $operation_info->veh_type;
			$vehicle_no           = $operation_info->vehicle_no;
			$reporting_time       = $operation_info->reporting_time;
			$trip_type            = $operation_info->trip_type_name;
			$op_driver_name       = $operation_info->op_driver_name;
			$op_driver_number     = $operation_info->op_driver_number;
			$second_driver_name   = $operation_info->second_driver_name;
			$second_driver_number = $operation_info->second_driver_number;
			$reporting_time       = date("G:i", strtotime($reporting_time));
			$from_date            = date('d-m-Y',strtotime($operation_info->from_date));
						
			$replace = str_replace("@NAME",$customer_name,$sms_txt);
			$replace = str_replace("@TOURNO",$tour_no,$replace);
			$replace = str_replace("@VECHTYPE",$veh_type,$replace);
			$replace = str_replace("@REPTIME",$reporting_time,$replace);
			$replace = str_replace("@DATE",$from_date,$replace);
			$replace = str_replace("@TRIP",$trip_type,$replace);
			$replace = str_replace("@VECHNO",$vehicle_no,$replace);
			$driver_name = $op_driver_name;
			if($driver_name){
				$driver_name = $driver_name ."/".$second_driver_name;
			}
			$driver_mob = $op_driver_number;
			if($driver_mob){
				$driver_mob = $driver_mob ."/".$second_driver_number;
			}
			$replace = str_replace("@DRIVER",$driver_name,$replace);
			$replace = str_replace("@MOBDRIVER",$driver_mob,$replace);
		}else
		if($sms_for === "driver_duty"){
			$operation_info   = $this->operation_confirm($db_id);
			$customer_name        = $operation_info->customer_name;
			$tour_no              = $operation_info->tour_no;;
			$reporting_time       = $operation_info->reporting_time;
			$shed_out_time        = $operation_info->shed_out_time;
			$phone_number         = $operation_info->phone_number;
			$alt_number           = $operation_info->alt_number;
			$report_address       = $operation_info->report_address;
			$city                 = $operation_info->city;
			$state_name           = $operation_info->state_name;
			$landmark             = $operation_info->landmark;
			$shed_out_time        = date("G:i", strtotime($shed_out_time));
			$reporting_time       = date("G:i", strtotime($reporting_time));
			$from_date            = date('d-m-Y',strtotime($operation_info->from_date));
			
			$cust_mob = $phone_number ."/".$alt_number;
			$cust_address1 = $report_address;
			$cust_address2 = $city.",".$state_name.",".$landmark;
			
			$replace = str_replace("@CUSTNAME",$customer_name,$sms_txt);
			$replace = str_replace("@TOURNO",$tour_no,$replace);
			$replace = str_replace("@CUSTMOB",$cust_mob,$replace);
			$replace = str_replace("@ADDRESS",$cust_address1,$replace);
			$replace = str_replace("@LANDMARK",$cust_address2,$replace);
			$replace = str_replace("@REPTIME",$reporting_time,$replace);
			$replace = str_replace("@DATE",$from_date,$replace);
		}else
		if(($sms_for === "catering_enquiry") || ($sms_for === "catering_confirm") || ($sms_for === "catering_cancelled")){
			$catering_info   = $this->catering_info($db_id);
			$customer_name   = $catering_info->customer_name;
			$cat_out_id      = $catering_info->cat_out_id;
			$fucntion_name   = $catering_info->fucntion_name;
			$fucntion_place  = $catering_info->fucntion_place;
			$reporting_time  = $catering_info->reporting_time;
			$pax             = $catering_info->pax;
			$reporting_time  = date("G:i", strtotime($reporting_time));
			$from_date       = date('d-m-Y',strtotime($catering_info->from_date));
			$cat_out_id      = "CAT".str_pad($cat_out_id, 4, '0', STR_PAD_LEFT);
			
			$replace = str_replace("@NAME",$customer_name,$sms_txt);
			$replace = str_replace("@CATID",$cat_out_id,$replace);
			$replace = str_replace("@FUNNAME",$fucntion_name,$replace);
			$replace = str_replace("@PLACE",$fucntion_place,$replace);
			$replace = str_replace("@FUNDATE",$from_date,$replace);
			$replace = str_replace("@PAX",$pax,$replace);
			$replace = str_replace("@REPTIME",$reporting_time,$replace);
		}else
		if($sms_for === "trip_completed"){
			$trip_info   = $this->booking_confirm($db_id);
			$customer_name   = $trip_info->customer_name;			
			$tour_no         = $trip_info->tour_no;			
			$replace = str_replace("@NAME",$customer_name,$sms_txt);
			$replace = str_replace("@TOURNO",$tour_no,$replace);
			$encode = base64_encode($tour_no);
			$url = "http://sbltt.cafsinfotech.com/app/feedback.php?feed_id=$encode";
			$replace = $replace."\n".$url;
		}else
		if($sms_for === "pkgenquiry_confirm"){
			$package_info      = $this->pkgenquiry_confirm($db_id);
			$customer_name     = $package_info->customer_name;			
			$temple_enquiry_id = $package_info->temple_enquiry_id;
			$package_name      = $package_info->package_name;
			$trip_days         = $package_info->trip_days;
			$from_date       = date('d-m-Y',strtotime($package_info->from_date));
			$temple_enquiry_id = "PKGINQ".str_pad($temple_enquiry_id, 4, '0', STR_PAD_LEFT);
			
			
			$replace = str_replace("@NAME",$customer_name,$sms_txt);
			$replace = str_replace("@PAKNAME",$package_name,$replace);
			$replace = str_replace("@ENQID",$temple_enquiry_id,$replace);
			$replace = str_replace("@DATE",$from_date,$replace);
		}else
		if($sms_for === "package_enquiry"){
			$package_info      = $this->package_enquiry($db_id);
			$customer_name     = $package_info->customer_name;	
			$package_name      = $package_info->package_name;
			$from_date         = date('d-m-Y',strtotime($package_info->from_date));
			$pnr               = $package_info->pnr;
			$seat_no           = $package_info->seat_no;
			
			$replace = str_replace("@NAME",$customer_name,$sms_txt);
			$replace = str_replace("@PAKNAME",$package_name,$replace);
			$replace = str_replace("@PNR",$pnr,$replace);
			$replace = str_replace("@SEAT",$seat_no,$replace);
			$replace = str_replace("@DATE",$from_date,$replace);
		}
		return $replace;
	}
	public function enquiry_confirm($enquiry_id){
		$this->db->select('*,frm.city_name as frm_city_name, to.city_name as to_city_name');
		$this->db->from('enquiry');
		$this->db->join('customers', 'customers.cust_id = enquiry.cust_id','left');
		$this->db->join('trip_type', 'trip_type.trip_type_id = enquiry.trip_type','left');
		$this->db->join('veh_type', 'veh_type.veh_type_id = enquiry.vehicle_type','left');
		$this->db->join('booking_type', 'booking_type.booking_type_id = enquiry.cust_type','left');
		$this->db->join('city frm', 'frm.city_id = enquiry.orgin','left');
		$this->db->join('city to', 'to.city_id = enquiry.destination','left');
		$this->db->join('state', 'state_code = customers.state','left');
		$this->db->where('enquiry_id',$enquiry_id);
		return $this->db->get()->row();
	}
	public function booking_confirm($booking_id){		
		$this->db->select('*,frm.city_name as frm_city_name, to.city_name as to_city_name');
		$this->db->from('booking');
		$this->db->join('customers', 'customers.cust_id = booking.cust_id','left');
		$this->db->join('trip_type', 'trip_type.trip_type_id = booking.trip_type','left');
		$this->db->join('veh_type', 'veh_type.veh_type_id = booking.vehicle_type','left');
		$this->db->join('booking_type', 'booking_type.booking_type_id = booking.cust_type','left');
		$this->db->join('city frm', 'frm.city_id = booking.orgin','left');
		$this->db->join('city to', 'to.city_id = booking.destination','left');
		$this->db->join('state', 'state_code = customers.state','left');
		$this->db->where('booking_id',$booking_id);
		return $this->db->get()->row();
	}
	public function operation_confirm($op_line_id){		
		$this->db->select('*,frm.city_name as frm_city_name, to.city_name as to_city_name,operation_line.tp_info as rout_info,operation_line.remarks as op_remarks');
		$this->db->from('operation_line');
		$this->db->join('operation', 'operation.operation_id = operation_line.operation_id','left');
		$this->db->join('customers', 'customers.cust_id = operation.cust_id','left');
		$this->db->join('trip_type', 'trip_type.trip_type_id = operation.trip_type','left');
		$this->db->join('veh_type', 'veh_type.veh_type_id = operation.vehicle_type','left');
		$this->db->join('booking_type', 'booking_type.booking_type_id = operation.cust_type','left');
		$this->db->join('city frm', 'frm.city_id = operation.orgin','left');
		$this->db->join('city to', 'to.city_id = operation.destination','left');
		$this->db->join('state', 'state_code = customers.state','left');
		$this->db->join('vehicle', 'vehicle.vehicle_id = operation_line.op_vehicle_id','left');
		$this->db->where('op_line_id',$op_line_id);
		$this->db->where('operation_line.status',1);
		return $this->db->get()->row();
	}
	public function catering_info($cat_out_id){		
		$this->db->from('catering_outside');
		$this->db->join('customers', 'customers.cust_id = catering_outside.cust_id','left');
		$this->db->join('booking_type', 'booking_type.booking_type_id = catering_outside.cust_type','left');
		$this->db->join('state', 'state_code = customers.state','left');
		$this->db->where('catering_outside.status',1);
		$this->db->where('cat_out_id',$cat_out_id);
		return $this->db->get()->row();
	}
	public function pkgenquiry_confirm($temple_enquiry_id){		
		$this->db->from('temple_enquiry');
		$this->db->join('customers', 'customers.cust_id = temple_enquiry.cust_id','left');
		$this->db->join('package_management', 'package_management.package_id = temple_enquiry.package_id','left');
		$this->db->where('temple_enquiry_id',$temple_enquiry_id);
		return $this->db->get()->row();
	}
	public function package_enquiry($package_line_id){		
		$this->db->from('package_line');
		$this->db->join('customers', 'customers.cust_id = package_line.cust_id','left');
		$this->db->join('package_management', 'package_management.package_id = package_line.package_id','left');
		$this->db->where('package_line_id',$package_line_id);
		return $this->db->get()->row();
	}
}
?>