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/.trash/application.1/controllers/Employee_log_report.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Employee_log_report  extends Action_controller{	
	public function __construct(){
		parent::__construct('employee_log_report');
	}
	// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
	public function index(){
		$data['key']          = $this->generateKey();
		$this->load->view("employee_log_report/manage",$data);
	}
	//AUTO COMPLETE FUNCTION -> EmpName
	public function emp_suggest_name(){
		$encString         = file_get_contents('php://input');
		$_POST             = $this->cryptoDecrypt($encString);
		if(!$_POST){
			echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
			exit(0);
		}
		$search_term  = $this->input->post_get('term');
		$final_qry = 'select employee_code,emp_name from cw_employees where trans_status = 1 and prime_employees_id !=1 and employee_code like "'.$search_term.'%"';
		$final_data   = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
		$final_result = $final_data->result();
		$final_data->next_result();
		foreach($final_result as $rslt){
			$employee_code = $rslt->employee_code;
			$emp_name      = $rslt->emp_name;
			$suggestions[] = array('value' => "$employee_code", 'label' =>"$employee_code - $emp_name");
		}
		if(empty($suggestions)){
			$suggestions[] = array('value' => "0", 'label' => "No data found for this search");
		}
		echo json_encode($suggestions);
	}
	// AUTO COMPLETE FUNCTION -> AadharNo
	public function emp_suggest(){
		$encString         = file_get_contents('php://input');
		$_POST             = $this->cryptoDecrypt($encString);
		if(!$_POST){
			echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
			exit(0);
		}
		$search_term = $this->input->post_get('term');
		$final_qry = 'SELECT aadhar_card_no FROM cw_employees WHERE trans_status = 1 AND prime_employees_id != 1 AND aadhar_card_no LIKE "'.$search_term.'%"';
		$final_data = $this->db->query("CALL sp_a_run ('SELECT', '$final_qry')");
		$final_result = $final_data->result_array();
		$final_data->next_result();
		$suggestions = array();
		foreach ($final_result as $rslt) {
			$aadhar_card_no = $rslt['aadhar_card_no'];
			$suggestions[] = array('value' => $aadhar_card_no, 'label' => $aadhar_card_no, 'display_name' => $aadhar_card_no);
		}
		if (empty($suggestions)) {
			$suggestions[] = array('value' => "0", 'label' => "No data found for this search");
		}
		echo json_encode($suggestions);
	}
	
	public function check_log_details(){
		$encString         = file_get_contents('php://input');
		$_POST             = $this->cryptoDecrypt($encString);
		if(!$_POST){
			echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
			exit(0);
		}
		//VIEW INFO FUNCTION CALL
		$this->view_info($form_view_id);
		//GET EMPLOYEE MASTER PICKLIST
		$master_pick       = $this->pick_list;//all pick result
		$process_by		   = $this->input->post('process_by');
		$log_table         = $this->input->post('log_table');
		$aadhar_card_no    = $this->input->post('aadhar_card_no');
		$employee_code     = $this->input->post('employee_code');
		$start_date        = str_replace("/","-",$this->input->post('start_date'));
		$end_date          = str_replace("/","-",$this->input->post('end_date'));
		$from_date         = date('Y-m-d',strtotime($start_date));
		$to_date           = date('Y-m-d',strtotime($end_date));
		if((int)$log_table === 1){
			$table_name         = "cw_employees_log";
			$table_column	    = "emp_name,employee_code,label_name,old_value,new_value,trans_created_by,trans_created_date";
			$separate_col_head	= "Employee Code";
		}else
		if((int)$log_table === 2){
			$separate_col_head	= "Aadhar Card No";
			$table_name         = "cw_custom_employees_log";
			$table_column	    = "emp_name,aadhar_card_no,label_name,old_value,new_value,trans_created_by,trans_created_date";
		}
		//changed by employee details
		$emp_name_qry     = 'select prime_employees_id,emp_name,employee_code from cw_employees where trans_status = 1 and termination_status=0';
		$emp_name_data    = $this->db->query("CALL sp_a_run ('SELECT','$emp_name_qry')");
		$emp_name_result  = $emp_name_data->result_array();
		$emp_name_data->next_result();
		$emp_name_rslt    = array_reduce($emp_name_result, function ($result, $arr) {
		    $result[$arr['prime_employees_id']] = $arr['employee_code']." - ".$arr['emp_name'];
		    return $result;
		}, array());
		//form setting for view name details
		$form_view_qry    = 'select label_name,view_name,field_type from cw_form_setting where prime_module_id="employees" and trans_status=1';
		$form_view_data   = $this->db->query("CALL sp_a_run ('SELECT','$form_view_qry')");
		$form_view_result = $form_view_data->result_array();
		$form_view_data->next_result();
		$form_view_rslt   = array_reduce($form_view_result, function ($result, $arr) {
		    $result[$arr['label_name']] = $arr;
		    return $result;
		}, array());	
		$qry    = "";
		if((int)$process_by === 1){
			if((int)$log_table === 1){
				$qry    = ' and employee_code="'.$employee_code.'"';
			}else
			if((int)$log_table === 2){
				$qry    = ' and aadhar_card_no="'.$aadhar_card_no.'"';
			}
		}else
		if((int)$process_by === 2){
			$qry        = ' and DATE_FORMAT(trans_created_date, "%Y-%m-%d") between "'.$from_date.'" and "'.$to_date.'"';
		}
		$emp_log_qry    = 'select '.$table_column.' from '.$table_name.' where trans_status=1' .$qry;
		$emp_log_data   = $this->db->query("CALL sp_a_run ('SELECT','$emp_log_qry')");
		$emp_log_result = $emp_log_data->result();
		$emp_log_data->next_result();
		if($emp_log_result){
			$tr_line = "";
			$i       = 1;
			foreach($emp_log_result as $emp_log_rslt){
				if((int)$log_table === 1){
					$employee_code = $emp_log_rslt->employee_code;
				}else
				if((int)$log_table === 2){
					$employee_code = $emp_log_rslt->aadhar_card_no;
				}
				$emp_name      = $emp_log_rslt->emp_name;
				$label_name    = $emp_log_rslt->label_name;
				$old_value     = $emp_log_rslt->old_value;
				$new_value     = $emp_log_rslt->new_value;
				$change_date   = date('d-m-Y H:i:s',strtotime($emp_log_rslt->trans_created_date));
				$change_by     = $emp_log_rslt->trans_created_by;
				$change_name   = $emp_name_rslt[$change_by];
				$view_name     = $form_view_rslt[$label_name]['view_name'];
				$field_type    = (int)$form_view_rslt[$label_name]['field_type'];
				if($field_type === 4){
					if($old_value){
						$old_value   = date('d-m-Y',strtotime($old_value));
					}
					if($new_value){
						$new_value   = date('d-m-Y',strtotime($new_value));
					}
				}else
				if($field_type === 13){
					if($old_value){
						$old_value   = date('d-m-Y H:i:s',strtotime($old_value));
					}
					if($new_value){
						$new_value   = date('d-m-Y H:i:s',strtotime($new_value));
					}
				}else
				if($field_type === 5 || $field_type === 7 || $field_type === 9){
					if($old_value){
						$old_value 	= $master_pick[$label_name]['array_list'][$old_value];
					}if($new_value){
						$new_value  = $master_pick[$label_name]['array_list'][$new_value];
					}
				}
				$tr_line         .="<tr><td>$i</td><td>$employee_code</td><td>$emp_name</td><td>$view_name</td><td>$old_value</td><td>$new_value</td><td>$change_date</td><td>$change_name</td></tr>";
				$i++;
			}
			$table_content = "<div style='background-color: #f2f2f2;'>
								<table class='table table-striped table-bordered' id='details_list'>
										<thead>
											<tr>
												<th>Si.No</th>
												<th>$separate_col_head</th>
												<th>Employee Name</th>
												<th>Field Name</th>
												<th>Old Value</th>
												<th>New Value</th>
												<th>Changed On</th>
												<th>Changed By</th>
											</tr>
										</thead>
										<tbody>
											$tr_line
										</tbody>
									</table>
									</div>";
			echo json_encode(array('success' => TRUE, 'message' => "See employee log list details",'table_content'=>$table_content));
		}else{
			echo json_encode(array('success' => FALSE, 'message' => "No data is available"));
		}
	}
}
?>