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/hrms_cafsindia_com/app/api_model.php
<?php
include('./dbconnect.php');
class api_model extends dbconnect{
	Protected $smtp_server;  
	Protected $port_no;       
	Protected $user_name;     
	Protected $user_password; 
	Protected $hr_mail;      
	Protected $cc_mail;
	Protected $sender_name;
	
	public function __construct() {
		$this->open_db();
		$get_email_qry       = 'select * from cw_mail_configurations where trans_status = 1 and mail_status = 1';
		$email_info          = $this->runQuery("$get_email_qry");
		$email_result        = $this->result($email_info);
		if($email_result){
			$this->smtp_server   = $email_result[0]->smtp_server;
			$this->port_no       = $email_result[0]->port_no;
			$this->user_name     = $email_result[0]->mail_username;
			$this->user_password = $email_result[0]->mail_password;
			$this->hr_mail       = $email_result[0]->sender_email;
			$this->cc_mail       = $email_result[0]->bcc;
			$this->sender_name   = $email_result[0]->sender_name;
		}
    }
	
	//check data
	public function is_exit_data($exit_qry){
		$exit_info     = $this->runQuery("$exit_qry");
		$exit_result   = $this->result($exit_info);
		return $exit_result;
	}
	
	//inserted data
	public function offer_insert($prime_query){
		$rms_user_id     = $this->runQuery_insert_id("$prime_query");
		if($rms_user_id){
			$user_info_qry       = 'select employee_name,employee_email_id,offer_reference_number from cw_offer_letter where trans_status = 1 and prime_offer_letter_id = '.$rms_user_id;
			$user_info          = $this->runQuery("$user_info_qry");
			$user_result        = $this->result($user_info);
			$offer_name         = $user_result[0]->employee_name;
			$rms_mail_id        = $user_result[0]->employee_email_id;
			$offer_no           = $user_result[0]->offer_reference_number;
			$msg = $this->call_email($rms_mail_id,$offer_no,$offer_name);
			$msg = " and $msg";
			return json_encode(array('status' => true,'data' => "Successfully added our offer $msg!!!"));
		}else{
			return json_encode(array('status' => false,'data' => 'Failed to add and update information'));
		}	
	}
	
	//updated data
	public function offer_update($prime_update_query,$rms_code,$resend_mail){
		$update_info     = $this->runQuery("$prime_update_query");
		if($update_info){
			$update_info_qry       = 'select employee_name,employee_email_id,offer_reference_number from cw_offer_letter where trans_status = 1 and rms_code = "'.$rms_code.'"';
			$update_info          = $this->runQuery("$update_info_qry");
			$update_result        = $this->result($update_info);
			$offer_name           = $update_result[0]->employee_name;
			$rms_mail_id          = $update_result[0]->employee_email_id;
			$offer_no             = $update_result[0]->offer_reference_number;
			$msg ="";
			if((int)$resend_mail === 1){
				$msg = $this->call_email($rms_mail_id,$offer_no,$offer_name);
				$msg = " and $msg";
			}
			return json_encode(array('status' => true,'data' => "Successfully update our offer $msg!!!"));
		}else{
			return json_encode(array('status' => false,'data' => 'Failed to add and update information'));
		}	
	}
	public function call_email($rms_mail_id,$offer_no,$offer_name){
		require('../phpmailer/class.phpmailer.php');
		$base_url = "http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["REQUEST_URI"].'?');
		$base_url =  str_replace("/app","/offer","$base_url");
		$content  = "Dear $offer_name,<br/>
					This is your offer reference number: $offer_no. <br/>	
					Please find the following link to upload your documents ".$base_url."<br/>";
		$content  .= "With Regards<br/>
					HR Team"; 
		$hr_mail   = '';
		if($rms_mail_id){
			$smtp_server      = $this->smtp_server;  
			$port_no          = $this->port_no; 
			$user_name        = $this->user_name;  
			$user_password    = $this->user_password;  
			$hr_mail          = $this->hr_mail;  	
			$sender_name      = $this->sender_name;
			$mail             = new PHPMailer();
			$mail->SMTPDebug  = 3;
			$mail->IsSMTP();
			$mail->Host       = $smtp_server; // Your SMTP PArameter
			$mail->Port       = $port_no; // Your Outgoing Port
			$mail->SMTPAuth   = true; // This Must Be True
			$mail->Username   = $user_name; // Your Email Address
			$mail->Password   = $user_password; // Your Password
			$mail->SMTPSecure = 'tls'; // Check Your Server's Connections for TLS or SSL
			$mail->From       = $hr_mail;
			$mail->FromName   = $sender_name;
			$mail->AddAddress($rms_mail_id);
			$mail->IsHTML(true);
			$mail->Subject="Document Upload link";
			$mail->Body = $content;
			if($mail=$mail->Send()){ 
				$message = 'Mail Send Successfully';
			}else{
				$message = 'Mail Not Send';
			}
		}else{
			$message = 'Server timeout';
		}
		return $message;
	}
	
	public function generate_number(){
		$max_val = 200000;
		$max_no_qry = 'select IFNULL(MAX(offer_reference_number),0)as max_offer_number from cw_offer_letter where trans_status = 1 and offer_reference_number >= '.$max_val;
		$max_no_info     = $this->runQuery("$max_no_qry");
		$max_no_result   = $this->result($max_no_info);
		$max_count       = $max_no_result[0]->max_offer_number;
		if((int)$max_count === 0){
			$offer_reference_number = $max_val + 1;
		}else{
			$offer_reference_number = $max_count + 1;
		}
		return 	$offer_reference_number;
	}
}
?>