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_db.php
<?php
/**********************************************************
	   Filename: lp_db.php
	Description: life planner specific database operations
		 Author: uday
	 Created on: AUG, 01 2018
	Approved on: 
	Reviewed on: 
	------------------------------------------------------------
	Modification Details
	Changed by:
	------------------------------------------------------------
**********************************************************/

class lp_db extends DBObject{
	
	private $dbObj = null;
	private $created_date;
	private $valid_cust = false;
	
	public $cust_id;
	public $cust_name;
	public $cust_mobile;
	public $cust_email;
	public $cust_address;
	public $city;
	public $pin;
	public $country;
	
	function __construct(){
		$this->open_db();
		$this->cust_id      = 0;
		$this->cust_name    = '';
		$this->cust_mobile  = '';
		$this->cust_email   = '';
		$this->cust_address = '';
		$this->city         = '';
		$this->state        = '';
		$this->pin          = '';
		$this->country      = '';
		$this->created_date = '';	
		$this->valid_cust   = false;
	}
	
	function getDBObject(){
		$this->dbObj = $this->get_db();
		return $this->dbObj;
	}
	
	function is_customer(){
		return $this->valid_cust;
	}
	
	function forgot_password($mobile_no){
		$cust_info  = $this->query("customers","cust_mobile='$mobile_no'");
		$cust_rows  = $this->num_rows($cust_info);
		if((int)$cust_rows === 1){
			$sign_info  = $this->query("signup","reg_mob='$mobile_no'");
			$sign_rows  = $this->num_rows($sign_info);
			$otp        = mt_rand(100000,999999);
			$lp_sms     = lpObject::newObject('lp_sms');
			$send_data = array('@OTP'=>$otp); 
			if((int)$sign_rows === 1){
				$sign_rslt = $this->result($sign_info);
				$signup_id = $sign_rslt[0]->signup_id;
				$this->runQuery("UPDATE lp_signup SET otp = '$otp' WHERE signup_id = '$signup_id'");
			}else{
				$created_on = date("Y-m-d h:i:s");
				$this->runQuery("insert into lp_signup (reg_mob,otp,created_date) values ('$mobile_no','$otp','$created_on')");	
			}
			$lp_sms->send_sms($mobile_no,'signup_otp',$send_data);
			return json_encode(array('sts' => TRUE, 'mode' =>"reset_pwd"));
		}else{
			return json_encode(array('sts' => TRUE, 'mode' =>"reset_invalid_mob"));
		}
	}
	
	function resend_otp($mobile_no){
		$sign_info  = $this->query("signup","reg_mob='$mobile_no'");
		$sign_rows  = $this->num_rows($sign_info);
		$sign_rslt  = $this->result($sign_info);
		$otp        = $sign_rslt[0]->otp;
		$lp_sms     = lpObject::newObject('lp_sms');
		$send_data = array('@OTP'=>$otp);
		$lp_sms->send_sms($mobile_no,'signup_otp',$send_data);
		return json_encode(array('sts' => TRUE, 'mode' =>"sent"));
	}
	
	//CHECK IS CUSTOMER EXIST
	function is_mobile_no_exist($mobile_no){
		$cust_info  = $this->query("customers","cust_mobile='$mobile_no'");
		$cust_rows  = $this->num_rows($cust_info);
		if((int)$cust_rows === 1){
			return json_encode(array('sts' => TRUE, 'mode' =>"sign_in"));
		}else{
			return json_encode(array('sts' => TRUE, 'mode' =>"sign_up"));
		}
	}
	
	// CHECK BOTH CUSTOMER AND SIGNUP TABLE
	function validate_signup($mobile_no){
		$cust_info  = $this->query("customers","cust_mobile='$mobile_no'");
		$cust_rows  = $this->num_rows($cust_info);
		if((int)$cust_rows === 0){
			$sign_info  = $this->query("signup","reg_mob='$mobile_no'");
			$sign_rows  = $this->num_rows($sign_info);
			$otp        = mt_rand(100000,999999);
			$lp_sms     = lpObject::newObject('lp_sms');
			$send_data = array('@OTP'=>$otp); 
			if((int)$sign_rows === 1){
				$sign_rslt = $this->result($sign_info);
				$signup_id = $sign_rslt[0]->signup_id;
				$this->runQuery("UPDATE lp_signup SET otp = '$otp' WHERE signup_id = '$signup_id'");
			}else{
				$created_on = date("Y-m-d h:i:s");
				$this->runQuery("insert into lp_signup (reg_mob,otp,created_date) values ('$mobile_no','$otp','$created_on')");
			}
			$lp_sms->send_sms($mobile_no,'signup_otp',$send_data);
			return json_encode(array('sts' => TRUE, 'mode' =>"sign_up"));
		}
		
	}
	
	// PROVIDE SIGNUP INFORMATION
	function get_signup_info($mobile_no){
		$sign_info  = $this->query("signup","reg_mob='$mobile_no'");
		$sign_rows  = $this->num_rows($sign_info);
		if((int)$sign_rows === 1){
			$sign_info  = $this->query("signup","reg_mob='$mobile_no'");
			$sign_rslt = $this->result($sign_info);
			$signup_id = $sign_rslt[0]->signup_id;
			$otp       = $sign_rslt[0]->otp;
			return json_encode(array('sts' => TRUE, 'signup_id' =>$signup_id, 'otp' =>$otp));
		}else{
			return json_encode(array('sts' => false));
		}
	}
	
	// CREATE ACCOUNT
	function create_account($mobile_no,$pwd,$signup_id){
		$created_on = date("Y-m-d h:i:s");
		$this->runQuery("insert into lp_customers (cust_mobile,pwd,created_date) values ('$mobile_no','$pwd','$created_on')");
		$this->runQuery("UPDATE lp_signup SET otp_sts = '1' WHERE signup_id = '$signup_id'");		
		return $this->core_login($mobile_no,$pwd);
	}
	
	function update_pwd($mobile_no,$pwd){
		return $this->runQuery("UPDATE lp_customers SET pwd = '$pwd' WHERE cust_mobile = '$mobile_no'");
	}
	//CORE LOGIN FOR BOTH SIGNIN AND SIGNUP
	function core_login($mobile_no,$pwd){
		$cust_info  = $this->query("customers","cust_mobile='$mobile_no' and pwd='$pwd'");
		$cust_rows  = $this->num_rows($cust_info);
		if((int)$cust_rows === 1){
			$cust_rslt = $this->result($cust_info);
			$cust_id   = $cust_rslt[0]->cust_id;
			
			$libObject = lpObject::newObject('lp_customer');
			$libObject->get_cust_info($cust_id);
			$obj_id = urlencode(base64_encode(serialize($libObject)));
			
			$lp_session = lpObject::newObject('lp_session');
			if($lp_session->clear_session($cust_id)){				
				$lp_session->save_session($cust_id, $obj_id);
			}	
			return json_encode(array('sts' => true, 'info'=>'Login Success'));			
		}else{
			return json_encode(array('sts' => false,'info'=>'Invalid login'));
		}
	}
	
	//FEEDBACK INSERT
	function feedback_save($query){
		$feedback_info  = $this->runQuery($query);
		if($feedback_info){
			return json_encode(array('sts' => TRUE,'info'=>'Feedback Added Successfully'));
		}else{
			return json_encode(array('sts' => FALSE,'info'=>'Invalid login'));
		}		
	}
}
?>