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/uds.cafsinfotech.in/application/controllers/Revision_letter_view.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Revision_letter_view  extends Action_controller{	
	public function __construct(){
		parent::__construct('revision_letter_view');
	}
	// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
	public function index(){
		$this->page_info();
		$data['encKey']  = $this->generateKey();
		$this->load->view("$this->control_name/manage",$data);
	}
	
	// FUNCTION FOR GET PROJECT DETAILS WHEN TYPE AUTOCOMPLETE SEARCH BOX
	public function get_project(){
		$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');
		$process_month   = $this->input->post_get('process_month');
		$project_id      = $this->input->post_get('project_id');
		$project         = str_replace(',', '","', $project_id);
		$start_date      = date('Y-m-d', strtotime("01-".$process_month));
		$final_qry       = 'select pro_personal_area_id,pro_id,CONCAT(pro_id," - ",pro_desc) as project from cw_sap_project where pro_start_date <= "'.$start_date.'" and pro_end_date >= "'.$start_date.'" and trans_status=1 and (pro_desc LIKE "%'.$search_term.'%" OR pro_id LIKE "%'.$search_term.'%") and trans_status  = 1 and pro_personal_area_id IN ("'.$project.'")';
		$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) {
			$project_area_id    = $rslt->pro_personal_area_id;
			$proj_desc      	= $rslt->project;
			$project_id			= $rslt->pro_id;
			$suggestions[]      = array(
				'value' => $project_id,
				'label' => "$proj_desc",
				'display_name'=>"$proj_desc"
			);
		}
		if (empty($suggestions)) {
			$suggestions[] = array(
				'value' => "0",
				'label' => "No data found for this search"
			);
		}
		echo json_encode($suggestions);
	}
	//FUNCTION FOR WBS ELEMENT BASED ON DATE AND PROJECT WHEN TYPE AUTOCOMPLETE BOX
	public function get_wbs_element(){
		$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');
		$process_month   = $this->input->post_get('process_month');
		$project_id      = $this->input->post_get('project_id');
		$area_access     = $this->input->post_get('area_access');
		$start_date      = date('Y-m-d', strtotime("01-".$process_month));
		$get_wbs_qry     = 'select wbs_id,CONCAT(wbs_id," - ",wbs_desc) as wbs_data from cw_sap_wbs where wbs_start_date <= "'.$start_date.'" and wbs_end_date >= "'.$start_date.'" and trans_status = 1 and (wbs_desc LIKE "%'.$search_term.'%" OR wbs_id LIKE "%'.$search_term.'%") and trans_status = 1 and wbs_project_id = "'.$project_id.'"';
		$wbs_data     = $this->db->query("CALL sp_a_run ('SELECT','$get_wbs_qry')");
		$wbs_result   = $wbs_data->result();
		$wbs_data->next_result();

		foreach ($wbs_result as $rslt) {
			$wbs_id        = $rslt->wbs_id;
			$wbs_desc      = $rslt->wbs_data;
			$suggestions[] = array(
				'value' => $wbs_id,
				'label' => "$wbs_desc",
				'display_name'=>"$wbs_desc"
			);
		}
		if (empty($suggestions)){
			$suggestions[] = array(
				'value' => "0",
				'label' => "No data found for this search"
			);
		}
		echo json_encode($suggestions);
	}
	public function check_revision_letter(){
		$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);
		}
		$user_right     	= $this->input->post('user_right');
		$emp_code       	= $this->input->post('emp_code');
		$process_month  	= $this->input->post('process_month');
		$project_id     	= $this->input->post('project_id');
		$wbs_id         	= $this->input->post('wbs_id');
		$this->logged_area_access = $this->session->userdata('logged_area_access');
		
		//WHERE CONDITION ONLY FOR BRANCH USER(3) 
		if((int)$user_right === 3){
			if($wbs_id){
				$where_cond  = ' and project_id = "'.$project_id.'" and wbs_element = "'.$wbs_id.'" and process_month = "'.$process_month.'" and personal_code in ('.$this->logged_area_access.')';
			}else{
				$where_cond   = ' and project_id = "'.$project_id.'" and process_month = "'.$process_month.'" and personal_code in ('.$this->logged_area_access.')';
			}
		}else{
			//WHERE CONDITION FOR ALL USER ROLE
			$where_cond    = ' and employee_code = "'.$emp_code.'" and process_month = "'.$process_month.'"';
		}
		$rev_letter_list_qry  = 'select wbs_element,employee_code from cw_transactions_fms where trans_status=1 '.$where_cond.' ';
		$rev_letter_info      = $this->db->query("CALL sp_a_run ('SELECT',	'$rev_letter_list_qry')");
		$rev_letter_result    = $rev_letter_info->result();
		$rev_letter_info->next_result();
		$wbs_element          = $rev_letter_result[0]->wbs_element;
	
		$start_date  	      = date('Y-m-d', strtotime("01-".$process_month));
		$start       	      = strtotime($start_date);
		$month       	      = strtotime($start_date);
		$letter_month         = date('m-Y', $month);
		$letter_month_name    = date('F Y', $month);
		$tble_line   	      = "";
		$i = 0;
		if((int)$user_right === 3){
			foreach($rev_letter_result as $folder_path){
				$wbs_code             = strtolower(str_replace(" ", "_",$folder_path->wbs_element));
				$employee_code 	      = $folder_path->employee_code;  
				$folder_name	      = strtolower($payslip_based_on."_".$file_name);
				$emp_result_arr[$i]   = $folder_path->employee_code;
				$file_path            = "emp_documents/revision_letter/$letter_month/$employee_code.pdf";
				$zip_file_path        = "emp_documents/revision_letter/$letter_month";

				if(file_exists($file_path)){
					$file_path        = base_url().$file_path;
					// $filename         = dirname(__FILE__).$file_path;
					// $filename         = str_replace("application\controllers","",$filename);
					$tble_line       .= "<tr class='gradeU'>
								<td>$letter_month_name</td>
								<td>$wbs_code</td>
								<td>$employee_code</td>
								<td>
									<a class = 'btn btn-primary btn-sm' onclick = pdf_viewer('$file_path')><span class='fa fa-eye' >&nbsp;</span> view </a>
									<a class = 'btn btn-primary btn-sm' id='download_$letter_month' href='$file_path' download '><span class='fa fa-download' download>&nbsp;</span> Download </a>
								</td>
								</tr>";
				}
				$i++;
			}	
		}else{
			$file_path = "emp_documents/revision_letter/$letter_month/$emp_code.pdf";
			if(file_exists($file_path)){
				$file_path        = base_url().$file_path;
				// $filename         = dirname(__FILE__).$file_path;
				// $filename         = str_replace("application\controllers","",$filename);
				$tble_line       .= "	<tr class='gradeU'>
							<td>$letter_month_name</td>
							<td>$wbs_element</td>
							<td>$emp_code</td>
							<td>
								<a class = 'btn btn-primary btn-sm' onclick = pdf_viewer('$file_path')><span class='fa fa-eye' >&nbsp;</span> view </a>
								<a class = 'btn btn-primary btn-sm' id='download_$letter_month' href='$file_path' download '><span class='fa fa-download' download>&nbsp;</span> Download </a>
							</td>
							</tr>";
			}
		}

		//IF ROLE IS BRANCH USER ENABLE DOWNLOAD ZIP
		if((int)$user_right  === 3 && $emp_result_arr){
			$rslt   = array_unique($emp_result_arr ?? []);
			$emp_result_arr  = '"'.implode('.pdf","', $rslt ?? []).'.pdf"';
			$tfoot_list      = "<tfoot>
				<tr class    = 'gradeU'><td></td><td style='text-align:center;'><a class='btn btn-primary btn-sm' onclick = download_zip('$zip_file_path','$emp_result_arr') ><span class='fa fa-download' >&nbsp;</span> Download All </a></td><td></td><td></td></tr>
			</tfoot>";
		}
		$tbl_body       = "";
		$tbl_body       = $tble_line;
		if($tbl_body){
			$table_data = "	<table class = 'table table-striped table-bordered' id='emp_details'>
									<thead>
										<tr>
										<th>Revision Letter Month</th>
										<th>WBS Element</th>
										<th>Employee Code</th>
										<th>Action</th>
										</tr>
									</thead>
									<tbody>
										$tbl_body
									</tbody>
										$tfoot_list
								</table>";
			echo json_encode(array('success' => true,'table_data' => $table_data,'user_right'=> $user_right));
		}else{
			echo json_encode(array('success' => false,'message' =>"Revision Letter Not Available",'user_right'=> $user_right));
		}
						
	}
				
	public function download_zip(){
		$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);
		}
		$emp_codes 		= $this->input->post("emp_codes");
		$emp_codes  	= str_replace('"', '', $emp_codes);
		$emp_code_arr  	= explode(',', $emp_codes ?? "");
		$path_name  	= strtolower($this->input->post('path_name'));
		
		$path       	= "./".$path_name."/";
		$zip        	= new ZipArchive();
		$filename   	= "./".$path_name.".zip";
		unlink($filename);
		if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
			exit("cannot open <$filename>\n");
		}
		$dir = $path;
		if (is_dir($dir)){
			if ($dh = opendir($dir)){
				while (($file = readdir($dh)) !== false){
					if($file != '' && $file != '.' && $file != '..'){
						$file_name = $path.$file.'/';
						if (is_dir($file_name)){
							if ($dhs = opendir($file_name)){
								while (($files = readdir($dhs)) !== false){
									if (in_array($files, $emp_code_arr)){
										if (is_file($file_name.$files)) {
											if($files != '' && $files != '.' && $files != '..'){
												$zip->addFile($file_name.$files);
											}
										}
									}
								}
								closedir($dhs);
							}
						}
					}
				}
				closedir($dh);
			}
		}
		$zip->close();
		$filename = str_replace("./","",$filename);
		echo json_encode(array('success' => true,'filename' => $filename));
	}
	
}
?>