<?php  if (! defined('BASEPATH')) exit('No direct script access allowed');
 
if ( ! function_exists('send_otp'))
{
    function send_otp($mobile_number = NULL) 
    {
        $CI =& get_instance(); 
        require_once APPPATH.'third_party/textlocal.class.php';
		$textlocal = new Textlocal('subhash.prajapati@webmatriks.com', 'fadfb0cbe0df0cefe84a4c112dc3f9f5b97fe1a0d1736cfbe50cc877d08caaf6','/72eUQgGrRY-DzqKd8nbwR0avp4bB57SJeI729rYpf');
		$numbers = array($mobile_number);
		$sender = 'TXTBLB';
		$genOTP = rand(100000, 999999);
		$message = 'Your OTP is '.$genOTP;
		try {
			$result = $textlocal->sendSms($numbers, $message, $sender);
			
		}catch (Exception $e) {
			error_log('Error: ' . $e->getMessage());
		}
		//print_r($result);exit;
		if($result->status=='success'){		
			$user_id = $CI->session->userdata('user_id');
			$row = array(
				'user_id'       => $user_id, 
				'mobile_number' => $mobile_number, 
				'otp'           => $genOTP, 
				'created_at'    => date("Y-m-d H:i:s")		
			);
		    $CI->db->insert('otp', $row);
		    return $id = $CI->db->insert_id();		
		}else{
			return false; 
		}
	    
    }

}