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/lifemaze_in/lp_lib/lp_sms.php
<?php
/**********************************************************
	   Filename: lp_sms.php
	Description: SMS related operations
		 Author: uday
	 Created on: AUG, 18 2018
	Approved on: 
	Reviewed on: 
	------------------------------------------------------------
	Modification Details
	Changed by:
	------------------------------------------------------------
	//http://alerts.net.in/httpapi/smsapi?uname=&password=&sender=&receiver=&group={group Ids}&route=TA&msgtype=1&sms={SMS content}
**********************************************************/
class lp_sms {	

	private $dbObj = null;

	function __construct() {
		$this->dbConnection();
	}
	
	function __destruct() {
		unset($this->dbObj);
	}
	
	function dbConnection()	{
		$this->dbObj = lpObject::newObject('lp_db');
		$this->dbObj->open_db();
	}
	
	//TRIGGER SMS
	public function trigger_sms($mobile_no,$sms_content){
		$sms_url    = "http://sms.cafsinfotech.com/httpapi/smsapi?";
		$sms_id     = "CAFSINFOTECH";
		$sms_pwd    = "cafs123";
		$sender_id  = "CAFSLP";
		
		$url = $sms_url."uname=$sms_id&password=$sms_pwd&sender=".urlencode($sender_id)."&receiver=".urlencode($mobile_no)."&route=TA&msgtype=1&sms=".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);
	}
	
	// SEND SMS
	function send_sms($mobile_no,$sms_for,$send_data){
		$db_content  = $this->get_sms_content($sms_for);
		$db_txt      = $db_content[0]->sms_txt;
		if($db_txt){
			$sms_content = $this->get_replaced_content($db_txt,$sms_for,$send_data);
			$sms_data = array(
				'to_mobile'    => $mobile_no,
				'sms_txt'      => $sms_content,
				'sent_for'     => $sms_for,
				'created_date' => date("Y-m-d h:i:s"),
			);
			if($this->save_sms($sms_data)){
				$this->trigger_sms($mobile_no,$sms_content);
			}
		}
	}
	
	// GET SMS CONTENT
	function get_sms_content($sms_for){
		$sms_info = $this->dbObj->query('sms',"sms_for='$sms_for'",'sms_txt');
		return $this->dbObj->result($sms_info);
	}
	
	//REPLACE SMS CONTENT
	function get_replaced_content($sms_txt,$sms_for,$send_data){
		$replace = "";
		foreach ($send_data as $key => $value){
			$replace = str_replace($key,$value,$sms_txt);
		}
		return $replace;
	}
	
	//SAVE SMS
	function save_sms($sms_data){
		if($sms_data){
			$qry_key     = "";
			$qry_value   = "";
			foreach ($sms_data as $key => $value){
				$qry_key     .= "$key,";
				$qry_value   .= "'$value',";
			}
			$qry_key    = rtrim($qry_key,',');
			$qry_value  = rtrim($qry_value,',');
			return $this->dbObj->runQuery("insert into lp_sms_log ($qry_key) values ($qry_value)");
		}else{
			return false;
		}
	}
}
?>