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_allyindian_com/application_bk/controllers/Password_reset.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Password_reset  extends Action_controller{	
	public function __construct(){
		parent::__construct('password_reset');
		if(!$this->Appconfig->isAppvalid()){
			redirect('config');
		}
	}	
	
	// LOAD PAGE WITH TABLE DATA
	public function index(){
		$data['table_headers'] = '';
		
		$role_info   = $this->db->query("CALL sp_a_run ('SELECT','SELECT * FROM `cw_category` where trans_status = 1 and prime_category_id !=1')");
		$role_result = $role_info->result();
		$role_info->next_result();
		$category_list[""] = "---- Select Category ----";
		foreach($role_result as $for){
			$role_id   = $for->prime_category_id;
			$category_name = $for->category_name;
			$category_list[$role_id] = $category_name;
		}
		$data['category_list'] = $category_list;
		$config_info   = $this->db->query("CALL sp_a_run ('SELECT','SELECT * FROM `cw_mail_configurations` where trans_status = 1 and mail_status = 1')");
		$config_result = $config_info->result();
		$config_info->next_result();
		$configuration[""] = "---- Select Configuration ----";
		foreach($config_result as $config){
			$prime_mail_configurations_id   = $config->prime_mail_configurations_id;
			$configuration_name = $config->configuration_name;
			$configuration[$prime_mail_configurations_id] = $configuration_name;
		}
		$data['configuration'] = $configuration;

		$from_query = 'select * from cw_form_setting where prime_module_id = "employees" and field_show = "1" and label_name != "role" ORDER BY input_for,field_sort asc';
		$form_data   = $this->db->query("CALL sp_a_run ('SELECT','$from_query')");
		$form_result = $form_data->result();
		$form_data->next_result();
		$this->fliter_list    = $this->get_filter_data($form_result);
		$data['fliter_list']  = $this->fliter_list;
		$data['key']          = $this->generateKey();
		$this->load->view("$this->control_name/manage",$data);
	}
	
	//Get All the Employees by Category
	public function get_employee_list(){
		$encString         = file_get_contents('php://input');
		$_POST             = $this->cryptoDecrypt($encString);
		if(!$_POST){
			echo json_encode(array('success' => false,'message' => 'Url Expired.. Please refresh the page and try again....','table_data' => ""));
			exit(0);
		}
		$category        = implode(",",$this->input->post('category'));      
		$emp_query  = 'select employee_code,emp_name from cw_employees where role in ('.$category.') and trans_status =1 and first_time_login = 1';
		$emp_info   = $this->db->query("CALL sp_a_run ('SELECT','$emp_query')");
		$emp_result = $emp_info->result();
		$emp_info->next_result();
		$emp_list   = "<option value=''>---- Select Employee ----</option>";
		foreach($emp_result as $result){
			$id        = $result->employee_code;
			$name      = ucwords($result->emp_name);
			$emp_code  = $result->employee_code;
			$emp_list .= "<option value='$id'>$emp_code - $name</option>";
		}
		echo $emp_list;
	}
	//PROVIDE QUERY AND DROPDOWN VALUES 
	public function get_filter_data($form_result){
		$filter = array();
		foreach($form_result as $setting){
			$prime_form_id      = (int)$setting->prime_form_id;
			$prime_module_id    = $setting->prime_module_id;
			$input_view_type    = (int)$setting->input_view_type;
			$input_for          = (int)$setting->input_for;
			$field_type         = (int)$setting->field_type;
			$label_id           = $setting->label_name;
			$label_name         = ucwords($setting->view_name);
			$field_length       = $setting->field_length;
			$field_decimals     = $setting->field_decimals;
			$pick_list_type     = (int)$setting->pick_list_type;
			$pick_list          = $setting->pick_list;
			$pick_table         = $setting->pick_table;
			$auto_prime_id      = $setting->auto_prime_id;
			$auto_dispaly_value = $setting->auto_dispaly_value;
			$field_isdefault    = (int)$setting->field_isdefault;
			$file_type          = (int)$setting->file_type;
			$mandatory_field    = (int)$setting->mandatory_field;
			$unique_field       = (int)$setting->unique_field;
			$search_show        = (int)$setting->search_show;
			$array_list = array();
			if( $label_id != 'employee_code' && $label_id != 'emp_name'){
				if(($field_type === 5) || ($field_type === 7)){
					if($pick_list_type === 1){
						$pick_list_val   = explode(",",$pick_list);
						$pick_list_val_1 = $pick_list_val[0];
						$pick_list_val_2 = $pick_list_val[1];
						if($pick_table == "cw_category"){
							$qry = " and prime_category_id != 1";
							}else{
							$qry = "";
						}
						if($pick_table == "cw_payroll_formula"){
							$pick_query = "select $pick_list from $pick_table where trans_status = 1";
							$pick_data   = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
							$pick_result = $pick_data->result();
							$pick_data->next_result();
							$array_list[""] = "---- $label_name ----";
							foreach($pick_result as $pick){
								$pick_key = $pick->$pick_list_val_1;
								$pick_val = ucwords(str_replace("_"," ",$pick->$pick_list_val_2));
								$array_list[$pick_key] = $pick_val;
							}
						}else{
							if($label_id === "excemption_component"){
								$pick_query = "select $pick_list from $pick_table where trans_status = 1 and tax_section = 1 $qry";
								}else{
								$pick_query = "select $pick_list from $pick_table where trans_status = 1 $qry";
							}
							$pick_data   = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
							$pick_result = $pick_data->result();
							$pick_data->next_result();
							
							$array_list[""] = "---- $label_name ----";
							foreach($pick_result as $pick){
								$pick_key = $pick->$pick_list_val_1;
								$pick_val = $pick->$pick_list_val_2;
								$array_list[$pick_key] = $pick_val;
							}
						}
					}else
					if($pick_list_type === 2){ 
						$pick_list_val_1 = $pick_table."_id";
						$pick_list_val_2 = $pick_table."_value";
						$pick_list_val_3 = $pick_table."_status";
						
						$pick_query = "select $pick_list_val_1,$pick_list_val_2 from $pick_table where $pick_list_val_3 = 1";
						$pick_data   = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
						$pick_result = $pick_data->result();
						$pick_data->next_result();
						
						$array_list[""] = "---- $label_name ----";
						foreach($pick_result as $pick){
							$pick_key = $pick->$pick_list_val_1;
							$pick_val = $pick->$pick_list_val_2;
							$array_list[$pick_key] = $pick_val;
						}
					}
				}		
				if(($input_view_type === 1) || ($input_view_type === 2)){
					$filter[] = array('label_id'=> $label_id, 'field_isdefault'=> $field_isdefault, 'array_list'=> $array_list, 'field_type'=> $field_type);
				}
			}
		}
		return $filter;
	}
	//send email for only employee modules data...
	public function send_email(){
		$encString         = file_get_contents('php://input');
		$_POST             = $this->cryptoDecrypt($encString);
		if(!$_POST){
			echo json_encode(array('success' => false,'message' => 'Url Expired.. Please refresh the page and try again....','table_data' => ""));
			exit(0);
		}
		// $email_for      = $this->input->post('email_for');
		$configuration     = $this->input->post('configuration');
		$category          = implode(",",$this->input->post('category')); 
		$employee_type     = (int)$this->input->post('employee_type');
		$employee_code     = $this->input->post('employee_code');
		$email             = $this->input->post('email');
		$process_month     = $this->input->post('process_month');
		$subject           = $this->input->post('subject');
		$password          = $this->input->post('password');
		$created_on        = date("Y-m-d H:i:s");
		$fliter_query      = "";

		if((int)$email === 1){
			$email = "company_email_id";
		}else{
			$email = "personal_email_id";
		}
		if($employee_type === 1){
			$fliter_query = ' and employee_code = "'.$employee_code.'"';
		}else
		if($employee_type === 2){
			$fliter_label      = $this->input->post('fliter_label');
			$fliter_type       = $this->input->post('fliter_type');
			$filter_cond       = $this->input->post('filter_cond');
			$fliter_val        = $this->input->post('fliter_val');
			$filter_count      = count($fliter_label ?? []);
			$search_count      = 0;

			for($i=0;$i<=(int)$filter_count;$i++){
				$db_name     = $fliter_label[$i];
				$table_name  = $fliter_type[$i];
				$db_cond     = $filter_cond[$i];
				$db_value    = $fliter_val[$i];
				$field_type  = $field_type[$i];
				if(($db_cond) && ($db_value)){
					$search_count++;
					if((int)$field_type === 4){
						$search_val = date("Y-m-d",strtotime($db_value));
					}else{
						$search_val = $db_value;
					}
					if($db_cond === "LIKE"){ $search_val = "$db_value%"; }
					if((int)$table_name === 1){
						$this->prime_table = "cw_employees";
						$fliter_query .= ' and '. $this->prime_table .".". $db_name ." ". $db_cond .' "'.$search_val.'"'; 
					}
				}			
			}
		}
		//Get Email Configuration data
		$config_query  = 'select smtp_server,sender_name,bcc,port_no,sender_email,mail_username,mail_password from cw_mail_configurations where prime_mail_configurations_id ="'.$configuration.'" and trans_status = 1  and mail_status = 1';
		$config_info   = $this->db->query("CALL sp_a_run ('SELECT','$config_query')");
		$config_result = $config_info->result();
		$config_info->next_result();
		$smtp_server     = $config_result[0]->smtp_server;
		$sender_name     = $config_result[0]->sender_name;
		$bcc             = explode(",",$config_result[0]->bcc);
		$port_no         = $config_result[0]->port_no;
		$sender_email    = $config_result[0]->sender_email;
		$username        = $config_result[0]->mail_username;
		$mail_password   = $config_result[0]->mail_password;
		if($mail_password === $password){
			$mail_staus = True;
		}else{
			$mail_staus = False;
		}
		
		$bcc_mail = "";
		foreach ($bcc as $bcc_key => $bcc_mails){
			$bcc_mail .= "\$mail->AddCC(".$bcc_mails.");<br/>";
		}

		if($mail_staus){
			//GET FIRST TIME LOGIN EMPLOYESS DETAILS FROM EMPLOYEE MASTER TABLE
			$emp_detail_qry 	= 'SELECT '.$email.',prime_employees_id,cw_employees.role,cw_employees.employee_code,cw_employees.emp_name FROM `cw_employees` where cw_employees.trans_status = 1 and cw_employees.termination_status = 0 and cw_employees.prime_employees_id != 1 and first_time_login = 1 and cw_employees.role in ('.$category.')'.$fliter_query;
			 
			$emp_detail_info    = $this->db->query("CALL sp_a_run ('SELECT','$emp_detail_qry')");
			$emp_detail_rslt    = $emp_detail_info->result_array();
			$emp_detail_info->next_result();
			
			$emp_details_arr    = array_reduce($emp_detail_rslt, function($result, $arr){			
		    	$result[$arr['employee_code']] = $arr;
		    	return $result;
			}, array());
			if(count($emp_details_arr)){
				$emp_upd_value      = "";
				foreach($emp_details_arr as $key => $emp_codes){
					$emp_code       = $emp_codes['employee_code'];
					$emp_name       = $emp_codes['emp_name'];
					$to_email       = $emp_codes[$email];
					$category       = strtolower(str_replace(" ", "_", $emp_codes['role']));
					$prime_id       = $emp_codes['prime_employees_id'];
					$rand_str       = chr(rand(65,90)).chr(rand(65,90)).chr(rand(65,90));
					$rand_no        = str_pad($prime_id, 3, '0', STR_PAD_LEFT);
					// $mem_name       = "SPA";
					$rand_otp       = $rand_str.$rand_no.chr(rand(65,90)).chr(rand(65,90));

					if($to_email !== ""){
						try{
							$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 = $username; // Your Email Address
							$mail->Password = $password; // Your Password
							$mail->SMTPSecure = 'SSL'; // Check Your Server's Connections for TLS or SSL
							$mail->From     = $sender_email;
							$mail->FromName = $sender_name;

							if($to_email){		
								$mail->AddAddress($to_email);
							}	
							if((int)count($bcc) > 0){
								foreach ($bcc as $bcc_key => $bcc_mails){
									$mail->AddCC($bcc_mails);
								}
							}
							$mail->IsHTML(true);
							$mail->Subject = $subject;
							$con_content   = "<!DOCTYPE html><html><body>Dear $emp_name,&nbsp;<p Style = ' margin-left: 30px;'>Please Find the Below Username and Password to Enter into HRMS Application. </p><p Style = 'margin-left: 30px;'>Username :<span Style = 'color:blue;'> $emp_code </span>&nbsp;</br>Password : <span Style = 'color:blue;'>$rand_otp</span></p><p Style = ' margin-left: 30px;'>Click Here to Login..! &nbsp;<a href = '".site_url('login')."'>Login Link</a></p><br/><p><b>Note: Please use Chrome Browser for Better UI Experience.. </b></P></body></html>";
							$mail->Body    = $con_content;
								$mail= $mail->Send();
							if($mail){
								//UPD QUERY VALUE
								$emp_upd_value .= '("'.$prime_id.'","'.md5($rand_otp).'","1","'.$this->logged_id.'","'.$created_on.'"),';
								$status = 1;
								$msg = "Mail Sent Successfully";
								$tr_line .= "<tr><td>$emp_code</td><td>$emp_name</td><td style='color:green !important;'>$msg</td></tr>";
							}else{
								$status = 0;
								$msg = "Mail Not Sent";
								$tr_line .= "<tr><td>$emp_code</td><td>$emp_name</td><td style='color:#ff0303 !important;'>$msg</td></tr>";
							}
						}catch(phpmailerException $e){
							$status = 0;
							$msg = "Mail Not Sent";
							$tr_line .= "<tr><td>$emp_code</td><td>$emp_name</td><td style='color:#ff0303 !important;'>$msg</td></tr>";
						}catch(Exception $e){
							$status = 0;
							$msg = "Mail Not Sent";
							$tr_line .= "<tr><td>$emp_code</td><td>$emp_name</td><td style='color:#ff0303 !important;'>$msg</td></tr>";
						}
					}else{
						$status = 0;
						$msg = "Email ID is empty, so mail is not send";
						$tr_line .= "<tr><td>$emp_code</td><td>$emp_name</td><td style='color:#ff0303 !important;'>$msg</td></tr>";
					} 	
					
				}
				//EMPLOYEES PASSWORD MULTI UPD FORMAT QUERY
				$emp_upd_value      = rtrim($emp_upd_value,",");
				if($emp_upd_value){
					$emp_pass_upd_qry   = 'INSERT INTO cw_employees (prime_employees_id,password,first_time_login,trans_updated_by,trans_updated_date) VALUES '.$emp_upd_value.' ON DUPLICATE KEY UPDATE password = VALUES(password),first_time_login = VALUES(first_time_login),trans_updated_by = VALUES(trans_updated_by),trans_updated_date = VALUES(trans_updated_date)';
					$emp_pass_upd_info  = $this->db->query("CALL sp_a_run ('RUN','$emp_pass_upd_qry')");
				}

				$table_info = "<table class='table table-bordered'>
								<thead>
									<tr>
										<th>Employee Code</th>
										<th>Employee Name</th>
										<th>Mail Status</th>
									</tr>
								</thead>
								<tbody>$tr_line</tbody>
								</table>";
				echo json_encode(array('success'=>true,'message'=>$msg,"table_data"=>$table_info,"email_sts"=>$status));
			}else{
				echo json_encode(array('success'=>false,'message'=>"No Data Avilable..!"));
			}
		}else{
			echo json_encode(array('success'=>false,'message'=>"Please Enter the Valid Credentials..."));
		}
	}
}
?>