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_patroniss_com/application/controllers/Custom_approval_bk21dec2020.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Custom_base_controller.php");
require('./phpmailer/class.phpmailer.php');
class Custom_approval extends Custom_base_controller{
	public function __construct(){
		parent::__construct('custom_approval');
		if(!$this->Appconfig->isAppvalid()){
			redirect('config');
		}
		$this->collect_base_info();
	}
	
	// LOAD PAGE WITH TABLE DATA
	public function index(){
		$data['table_head']  = $this->table_head;
		$data['master_pick'] = $this->master_pick;
		$data['fliter_list'] = $this->fliter_list;
		$this->load->view("custom_approval/manage",$data);
	}
	
	//LOAD TABEL WITH FILTERS
	public function search(){
		$draw           = $this->input->post('draw');
		$start          = $this->input->post('start');
		$per_page       = $this->input->post('length');
		$order          = $this->input->post('order');
		$order_col      = $this->input->post('columns');
		$search         = $this->input->post('search');
		$column         = $order[0]['column'];
		$order_sor      = $order[0]['dir'];
		$order_col      = $order_col[$column]['data'];
		$search         = trim($search['value']);
		$manager_reason = $this->input->post('manager_reason_arr');
		$search_query   = str_replace("@SELECT@",$this->select_query,$this->base_query);
		
		//ADDED BASIC,FILTER,COMMON QUERY HERE 		
		$this->prime_table ="cw_custom_employees";
		$fliter_query = "";
		$filter_data = FALSE;
		foreach($this->fliter_list as $fliter){
			$label_id         = $fliter['label_id'];
			$label_name       = $fliter['label_name'];
			$field_isdefault  = (int)$fliter['field_isdefault'];
			$array_list       = $fliter['array_list'];
			$field_type       = (int)$fliter['field_type'];			
			if($field_isdefault === 1){
				$column_name = $this->prime_table .".$label_id";				
				$search_val  = $this->input->post("$label_id");
				if($search_val){
					$filter_data = TRUE;
					if($field_type === 4){
						$search_val = date('Y-m-d',strtotime($search_val));
						$fliter_query .= " and $column_name = '$search_val'";
					}else
					if(($field_type === 5) || ($field_type === 7)){
						$search_val = trim(implode('","',$search_val));
						$fliter_query .= ' and '.$column_name.' in ("'.$search_val.'")';  
					}else
					if($field_type === 13){
						$search_val = date('Y-m-d H:i:s',strtotime($search_val));
						$fliter_query .= " and $column_name = '$search_val'";
					}else{
						$fliter_query .= " and $column_name LIKE '$search_val%'";
					}
				}
			}
		}
		
		$common_search = "";
		if($search){
			foreach($this->form_info as $setting){
				$prime_form_id   = $setting->prime_form_id;
				$field_type      = (int)$setting->field_type;
				$pick_list       = $setting->pick_list;
				$pick_table      = $setting->pick_table;
				$pick_list_type  = $setting->pick_list_type;
				$input_view_type = (int)$setting->input_view_type;
				$auto_prime_id      = $setting->auto_prime_id;
				$auto_dispaly_value = $setting->auto_dispaly_value;
				$label_id        = strtolower(str_replace(" ","_",$setting->label_name));
				$field_isdefault    = (int)$setting->field_isdefault;
				if($field_isdefault === 1){					
					if(($input_view_type === 1) || ($input_view_type === 2)){
						$search_label = "$this->prime_table.$label_id";
						$search_val   = "";
						if($field_type === 4){ // having issues in date search
							if(strtotime($search)){
								$search_val = date('Y-m-d',strtotime($search));
								$common_search .= ' or '. $search_label .' like "'.$search_val.'%"';
							}
						}else
						if(($field_type === 5) || ($field_type === 7) || ($field_type === 9)){							
							$result = array_filter($this->master_pick[$label_id], function ($item) use ($search) {
								if (stripos($item, $search) !== false) {
									return true;
								}
								return false;
							});
							if($result){
								$pick_key = implode('", "', array_keys($result));
								$common_search .= ' or '. $search_label .' in("'.$pick_key.'")';
							}
						}else{
							$common_search .= ' or '. $search_label .' like "'.$search.'%"';
						}
					}
				}
			}
			if($common_search){
				$common_search = ltrim($common_search,' or ');
				$common_search = " and ($common_search)";
				$common_search = str_replace("(,","(",$common_search);
				$common_search = str_replace("()","(0)",$common_search);
			}
		}
		$role_condition = "";
		if(!$filter_data && (int)$this->logged_user_role !== 2){
			if($this->role_condition){
				$role_condition = $this->role_condition;
			}			
		}
		if($common_search){
			$common_search = rtrim($common_search,' and ');
		}
		
		$count_all_query    = str_replace("@SELECT@","count(*) as allcount",$this->base_query);		
		$search_total       = $this->db->query($count_all_query);
		$search_total_info  = $search_total->result();
		$total_count        = $search_total_info[0]->allcount;
		
		$count_query        = str_replace("@SELECT@","count(*) as allcount",$this->base_query);
		$count_query       .= " where $this->prime_table.trans_status = 1  and (employee_code = '' or employee_code is null) $role_condition $fliter_query $common_search";
		$search_count       = $this->db->query($count_query);
		$search_info        = $search_count->result();
		$filtered_count     = $search_info[0]->allcount;
		
		$search_query      .= " where $this->prime_table.trans_status = 1 and (employee_code = '' or employee_code is null) $role_condition $fliter_query $common_search";
		$search_query      .= " ORDER BY  $order_col $order_sor";
		if((int)$per_page !== -1){
			$search_query  .= " LIMIT  $start,$per_page";
		}
		$search_data        = $this->db->query($search_query);
		$search_result      = $search_data->result();
		echo json_encode(array("draw" => intval($draw),"recordsTotal" => $total_count,"recordsFiltered" => $filtered_count,"data" => $search_result));		
	}
	
	
	//LOAD MODEL PAGE VIEW WITH DATA
	public function view($form_view_id=-1){
		//VIEW, FORM INPUT
		$data['view_info']              = $this->view_info;
		$data['form_info']              = $this->form_info;	
		$data['formula_result']         = $this->formula_result;//for label color change
		$data['role_based_condition']   = $this->role_based_condition;//for label name readonly options	
		
		//VIEW DATA
		$base_query  = str_replace("@SELECT@",$this->view_select,$this->base_query);
		$view_query  = $base_query ." where $this->prime_table.$this->prime_id = $form_view_id and $this->prime_table.trans_status = 1";
		$view_data   = $this->db->query("CALL sp_a_run ('SELECT','$view_query')");
		$view_result = $view_data->result();
		$view_data->next_result();
		$data['form_view']   = $view_result[0];
		
		//AUTO COMPLTE,PICK LIST AND CONDITION
		foreach($this->form_info as $from){
			$prime_form_id      = (int)$from->prime_form_id;
			$field_type         = (int)$from->field_type;
			$pick_table         = $from->pick_table;
			$auto_prime_id      = $from->auto_prime_id;
			$auto_dispaly_value = $from->auto_dispaly_value;
			$label_id           = $from->label_name;
			if($field_type === 9){
				if($view_result[0]){
					$get_value = $view_result[0]->$label_id;
					if($get_value){
						$pick_query = 'select '.$auto_dispaly_value.' from '.$pick_table.' where '.$auto_prime_id.' = "'.$get_value.'" and trans_status = 1';
						$pick_data   = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
						$pick_result = $pick_data->result();
						$pick_data->next_result();
						$this->all_pick[$prime_form_id] = $pick_result[0]->$auto_dispaly_value;
					}					
				}
			}
		}
		$data['all_pick']       = $this->all_pick;
		$data['condition_list'] = $this->condition_list;
		
		$view_qry    = 'select * from cw_form_view_setting where  prime_view_module_id = "'.$this->control_name.'" and  form_view_type = "3" and trans_status = 1';
		$view_data   = $this->db->query("CALL sp_a_run ('SELECT','$view_qry')");
		$view_result = $view_data->result();
		$view_data->next_result();
		$row_view_list = array();
		foreach($view_result as $view){
			$prime_form_view_id   = $view->prime_form_view_id;
			$row_set_data = $this->get_row_set_data($prime_form_view_id,$form_view_id);
			$row_view_list[$prime_form_view_id] = $row_set_data;
		}
		$data['row_view_list']   = $row_view_list;
		$this->load->view("custom_approval/form",$data);
	}
	
	//SAVE MODEL DATA TO DATA BASE
	public function save(){
		$prime_qry_key   = "";
		$prime_qry_value = "";
		$prime_upd_query = "";
		$form_id         = (int)$this->input->post($this->prime_id);
		$form_post_data  = array();	
		foreach($this->form_info as $setting){
			$field_type      = $setting->field_type;
			$input_view_type = (int)$setting->input_view_type;
			$label_id        = strtolower(str_replace(" ","_",$setting->label_name));
			$field_isdefault = $setting->field_isdefault;
			$unique_field    = (int)$setting->unique_field;
			$view_name       = $setting->view_name;
			if((int)$field_type === 7){
				$multi_name = $label_id."[]";
				$value = trim(implode(",",$this->input->post($multi_name)));
			}else{
				$value = trim($this->input->post($label_id));
			}
			
			if((int)$field_type === 4){
				if($value){
					$value = date('Y-m-d',strtotime($value));
				}
			}else
			if((int)$field_type === 13){
				if($value){
					$value = date('Y-m-d H:i:s',strtotime($value));
				}
			}
			if(($input_view_type === 1) || ($input_view_type === 2)){
				if((int)$field_isdefault === 1){
					$prime_qry_key     .= $label_id.",";
					$prime_qry_value   .= '"'.$value.'",';
					$prime_upd_query   .= $label_id.' = "'.$value.'",';
				}
			}
			if($label_id === "hr_status"){
				$hr_status = $value;
			}else
			if($label_id === "manager_status"){ 
				$manager_status = $value;
			}else
			if($label_id === "manager_reason"){ //manager_reason
				$manager_reason = $value;
			}else
			if($label_id === "employee_code"){
				$user_name = $value;
				$employee_code = $value;
			}else
			if($label_id === "rms_code"){
				$rms_code = $value;
			}else
			if($label_id === "date_of_joining"){
				$doj = date('Y-m-d',strtotime($value));
			}else
			if($label_id === "role"){
				$category = $value;
			}else
			if($label_id === "personal_email_id"){
				$emp_email_id = $value;
			}else
			if($label_id === "emp_name"){
				$emp_name = $value;
			}else
			if($label_id === "current_address"){
				$current_address = $value;
			}else
			if($label_id === "designation"){
				$designation  = $value;
			}else
			if($label_id === "manager_reason_date"){
				$manager_reason_date  = date('Y-m-d',strtotime($value));
			}
		}
		if($this->check_emp_code($user_name,$form_id)){
			$created_on = date("Y-m-d h:i:s");
			if((int)$form_id === 0){
				$prime_qry_key     .= "trans_created_by,trans_created_date";
				$prime_qry_value   .= '"'.$this->logged_id.'",'.'"'.$created_on.'"';
				$prime_insert_query = "insert into $this->prime_table ($prime_qry_key) values ($prime_qry_value)";
				$insert_info        = $this->db->query("CALL sp_a_run ('INSERT','$prime_insert_query')");
				$insert_result      = $insert_info->result();
				$insert_info->next_result();
				$insert_id = $insert_result[0]->ins_id;
				echo json_encode(array('success' => TRUE, 'message' => "Successfully added", 'insert_id' => $insert_id));
			}else{
				$prime_upd_query    .= 'trans_updated_by = "'. $this->logged_id .'",trans_updated_date = "'.$created_on.'"';
				$prime_update_query  = 'UPDATE '. $this->prime_table .' SET '. $prime_upd_query .' WHERE '. $this->prime_id .' = "'. $form_id .'"';
				$this->db->query("CALL sp_a_run ('UPDATE','$prime_update_query')");
				//custom log table insert
				$prime_custom_key   = $prime_qry_key;
				$prime_custom_val   = $prime_qry_value;
				$prime_custom_key  .= "custom_employees_id,trans_created_by,trans_created_date";
				$prime_custom_val  .= '"'.$form_id.'","'.$this->logged_id.'",'.'"'.$created_on.'"';
				$prime_log_insert_query = "insert into cw_custom_employees_log ($prime_custom_key) values ($prime_custom_val)";
				$insert_log_info        = $this->db->query("CALL sp_a_run ('INSERT','$prime_log_insert_query')");
				$insert_log_result      = $insert_log_info->result();
				$insert_log_info->next_result();
				
				if(((int)$manager_status === 2) && ((int)$hr_status === 3) && ($user_name !== "") && ((int)$category > 0)){//username updated in employee master
					$prime_qry_key     .= "user_name,trans_created_by,trans_created_date";
					$prime_qry_value   .= '"'.$user_name.'","'.$this->logged_id.'",'.'"'.$created_on.'"';
					$prime_insert_query = "insert into cw_employees ($prime_qry_key) values ($prime_qry_value)";
					$insert_info        = $this->db->query("CALL sp_a_run ('INSERT','$prime_insert_query')");
					$insert_result      = $insert_info->result();
					$insert_info->next_result();
					$insert_id = $insert_result[0]->ins_id;
					if($insert_id){
						$view_qry    = 'select * from cw_form_view_setting where  prime_view_module_id = "'.$this->control_name.'" and  form_view_type = "3" and trans_status = 1';
						$view_data   = $this->db->query("CALL sp_a_run ('SELECT','$view_qry')");
						$view_result = $view_data->result();
						$view_data->next_result();
						$row_view_list = array();
						foreach($view_result as $view){
							$prime_form_view_id   = $view->prime_form_view_id;
							$form_view_label_name = $view->form_view_label_name;
							$this->custom_rowset_save($prime_form_view_id,$form_view_label_name,$form_id,$insert_id);
						}
					}
				}
				if((int)$manager_reason === 1){
					$post_data = array('source'=>'custom','rms_code'=>$rms_code,'candidate_status'=>$manager_reason,'act_join_date'=>$doj);
					$this->rms_save($post_data);
				}else
				if((int)$hr_status === 4){
					$post_data = array('source'=>'custom','rms_code'=>$rms_code,'candidate_status'=>$hr_status,'act_join_date'=>$doj);
					$this->rms_save($post_data);
				}else
				if((int)$manager_reason === 4 || (int)$manager_reason === 5 || (int)$manager_reason === 6){
					$post_data = array('source'=>'custom_resigned','rms_code'=>$rms_code,'candidate_status'=>$manager_reason,'manager_reason_date'=>$manager_reason_date);
					$this->rms_save($post_data);
				}
				$mail ="";
				if($category && $emp_email_id !== '' && (int)$hr_status === 3){
					$mail_rslt = $this->send_email_directly($category,$employee_code,$emp_email_id,$emp_name,$form_id);
					$mail = " and $mail_rslt";
				}
				echo json_encode(array('success' => TRUE, 'message' => "Successfully updated $mail",'insert_id' => $form_id));
			}
		}else{
			echo json_encode(array('success' => FALSE, 'message' => "Employee Code Already Exists",'category_status'=>TRUE));
		}
	}
	
	//employee code exit or not
	public function employee_code_exit(){
		$emp_code  = $this->input->post('emp_code');
		$category  = $this->input->post('category');
		$emp_code_check_qry    = 'select count(employee_code) as rslt_count from cw_employees where employee_code = "'.$emp_code.'"';
		$emp_code_check_info   = $this->db->query("CALL sp_a_run ('RUN','$emp_code_check_qry')");
		$emp_code_check_result = $emp_code_check_info->result();
		$emp_code_check_info->next_result();
		$rslt_count = $emp_code_check_result[0]->rslt_count;
		if((int)$rslt_count > 0){
			$last_emp_code_check_qry    = 'select MAX(employee_code) as employee_code from cw_employees where role = "'.$category.'"  order by employee_code desc';
			$last_emp_code_check_info   = $this->db->query("CALL sp_a_run ('SELECT','$last_emp_code_check_qry')");
			$last_emp_code_check_result = $last_emp_code_check_info->result();
			$last_emp_code_check_info->next_result();
			$last_emp_code = $last_emp_code_check_result[0]->employee_code;
			echo json_encode(array('success' => FALSE, 'message' => "Employee code is already exit! this is your last employee code: $last_emp_code enter after this number"));
		}else{
			echo json_encode(array('success' => TRUE, 'message' => "Continue to update employee status"));
		}
	}
	
	//rowset data saved based on primary form id
	public function custom_rowset_save($prime_form_view_id,$form_view_label_name,$form_id,$insert_id){
		$module_id        = $this->control_name;
		$cust_table_name  = "cw_custom_".$module_id."_".$form_view_label_name;
		$prime_table_name = "cw_".$module_id."_".$form_view_label_name;
		$prime_tab_id     = "prime_custom_".$module_id."_id";
		$find_data_qry    = 'select * from '.$cust_table_name.' where trans_status = 1 and '.$prime_tab_id.' = '.$form_id;
		$find_data_info   = $this->db->query("CALL sp_a_run ('SELECT','$find_data_qry')");
		$find_data_result = $find_data_info->result();
		$find_data_info->next_result();
		$form_qry  = 'select * from cw_form_setting where prime_module_id = "'.$module_id.'" and  input_for = "'.$prime_form_view_id.'" and  field_show = "1" and trans_status = 1';
		$form_data   = $this->db->query("CALL sp_a_run ('SELECT','$form_qry')");
		$form_result = $form_data->result();
		$form_data->next_result();
		$prime_qry_key   = "";
		$prime_qry_value = "";
		foreach($find_data_result as $find_rslt){
			$prime_qry_key   = "prime_".$module_id."_id,";
			$prime_qry_value = '"'.$insert_id.'",';
			foreach($form_result as $setting){
				$label_id           = strtolower(str_replace(" ","_",$setting->label_name));
				$value              = $find_rslt->$label_id;			
				$prime_qry_key     .= $label_id.",";
				$prime_qry_value   .= '"'.$value.'",';
			}
			$prime_qry_key     .= "trans_created_by,trans_created_date";
			$prime_qry_value   .= '"'.$this->logged_id.'",'.'"'.$created_on.'"';
			$prime_insert_query = "insert into $prime_table_name ($prime_qry_key) values ($prime_qry_value)";
			$insert_info        = $this->db->query("CALL sp_a_run ('INSERT','$prime_insert_query')");
			$insert_result      = $insert_info->result();
			$insert_info->next_result();
		}
		return true;
	}
	
	public function get_employee_code(){
		$role                  = $this->input->post('role');
		$check_code_gen_qry    = 'select code_type from cw_employee_code_auto where trans_status = 1';
		$check_code_gen_data   = $this->db->query("CALL sp_a_run ('SELECT','$check_code_gen_qry')");
		$check_code_gen_result = $check_code_gen_data->result();
		$check_code_gen_data->next_result();
		$code_gen_mode   = $check_code_gen_result[0]->code_type;
		$sts = 0;
		if((int)$code_gen_mode === 1){
			$sts    = 1;
			$result = $this->get_digits($role);
			if($result){
				echo json_encode(array('success' => TRUE, 'sts' => $sts, 'digits' => $result));
			}else{
				echo json_encode(array('success' => FALSE, 'sts' => $sts, 'message' => "Employee Code Auto Not Updated for this role"));
				}
		}else{
			echo json_encode(array('sts' => $sts,'message' => "Manually enter the  Employee code"));
		}
	}
	
	public function get_digits($role){
		$select_qry    = 'select * from cw_employee_code_auto where (category = "'.$role.'" or category = "All") and trans_status = 1';

		$select_data   = $this->db->query("CALL sp_a_run ('SELECT','$select_qry')");
		$select_result = $select_data->result();
		$select_data->next_result();
		$num_rows      = $select_data->num_rows();
		$prefix        = $select_result[0]->prefix;
		$start_value   = $select_result[0]->start_value;
		$category      = $select_result[0]->category;
		$prefix_count  = 0;
		$prefix_qry = "";
		if($prefix){
			$prefix = strtoupper($prefix);
			$prefix_count = strlen($prefix);
			$prefix_qry = ' and employee_code like "%'.$prefix.'%"';
		}
		if($category === "All"){
			$emp_count_qry = 'select MAX(employee_code) as employee_code from cw_employees where prime_employees_id != 1 '.$prefix_qry;
		}else{
			$emp_count_qry = 'select MAX(employee_code) as employee_code from cw_employees where role = "'.$role.'" and prime_employees_id != 1 and employee_code != ""'.$prefix_qry;
		}		
		//echo $emp_count_qry; die;
		$emp_count_data    = $this->db->query("CALL sp_a_run ('SELECT','$emp_count_qry')");
		$emp_count_result  = $emp_count_data->result();
		$emp_count_data->next_result();
		//$emp_count       = $emp_count_data->num_rows();
		$max_count         = $emp_count_result[0]->employee_code;	
		if($max_count){
			if((int)$num_rows > 0){
				/*$digits        = $this->digit_check($prefix,$start_value,$max_count);*/
				$max_count = substr($max_count,$prefix_count);
				$digits    = $max_count +1;
				return $prefix."".$digits;
			}else{
				return false;
			}
		}else{
			return $prefix.$start_value;
		}
	}
	
	//get tl list
	public function get_tl_list(){
		$manager_report      = $this->input->post('manager_report');
		$select_tl_qry    = 'select employee_code,emp_name from cw_employees where manager_report = "'.$manager_report.'" and trans_status = 1';
		$select_tl_data   = $this->db->query("CALL sp_a_run ('SELECT','$select_tl_qry')");
		$select_tl_result = $select_tl_data->result();
		$select_tl_data->next_result();
		echo json_encode(array('tl_list' =>$select_tl_result));
	}
	
	public function check_emp_code($emp_code,$form_id = -1){
		if($emp_code){
			$select_tl_qry    = 'select * from cw_employees where employee_code = "'.$emp_code.'" and trans_status = 1';
			if((int)$form_id > 0){
				$select_tl_qry    .= " and prime_employees_id != $form_id";
			}
			$select_tl_data   = $this->db->query("CALL sp_a_run ('SELECT','$select_tl_qry')");
			$count = $select_tl_data->num_rows();
			$select_tl_data->next_result();
			if((int)$count > 0){
				return FALSE;
			}else{
				return TRUE;
			}
		}else{
			return TRUE;
		}
	}
	//Make Not Joined
	public function not_joined(){
		$not_joined_ids    = implode(",",$this->input->post('not_joined_ids'));
		$created_on = date("Y-m-d h:i:s");
		$prime_upd_query    .= 'trans_deleted_by = "'. $this->logged_id .'",trans_deleted_date = "'.$created_on.'"';
		$prime_update_query  = 'UPDATE '. $this->prime_table .' SET hr_status = 4 WHERE '. $this->prime_id .' in ('. $not_joined_ids .')';
		if($this->db->query("CALL sp_a_run ('UPDATE','$prime_update_query')")){
			echo json_encode(array('success' => TRUE, 'message' => "Successfully Deleted"));
		}else{
			echo json_encode(array('success' => FALSE, 'message' => "Unable to delete"));
		}
	}
	
	//candidate status to rms
	public function rms_save($post_data){
		$post_url  = "https://rms.cafsjobs.com/app/api_rms_update.php";
		$post_data['frm'] = "update_data";
		$post_data['source'] = "custom";
		$response  = $this->curl($post_url,$post_data);
		$response  = json_decode($response);
		echo $response;
	}
	public function curl($post_url,$post_data=null){
		$curl = curl_init();
		curl_setopt_array($curl, array(
		  CURLOPT_URL => $post_url,
		  CURLOPT_RETURNTRANSFER => true,
		  CURLOPT_ENCODING => "",
		  CURLOPT_MAXREDIRS => 10,
		  CURLOPT_TIMEOUT => 0,
		  CURLOPT_FOLLOWLOCATION => true,
		  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		  CURLOPT_CUSTOMREQUEST => "POST",
		  CURLOPT_POSTFIELDS => $post_data,
		));
		$response = curl_exec($curl);
		curl_close($curl);
		return $response;
	}
	public function send_email_directly($category,$employee_code,$emp_email_id,$emp_name,$view_id){
		$config_query  = 'SELECT smtp_server,sender_name,bcc,port_no,sender_email,mail_username,mail_password FROM cw_mail_configurations WHERE trans_status = 1';
		$config_info   = $this->db->query("CALL sp_a_run ('SELECT','$config_query')");
		$config_result = $config_info->result();
		$config_info->next_result();
		if($config_result){
			$smtp_server    = $config_result[0]->smtp_server;
			$sender_name    = $config_result[0]->sender_name;
			$port_no        = $config_result[0]->port_no;
			$sender_email   = $config_result[0]->sender_email;
			$user_name      = $config_result[0]->mail_username;
			$user_password  = $config_result[0]->mail_password;
		}
		
		//email template and subject and body content
		$email_temp_query  = 'select prime_print_info_id,email_design,print_info_for,print_info_module_id,print_type,email_subject from cw_email_design inner join cw_print_info on cw_print_info.prime_print_info_id = cw_email_design.email_design_for where find_in_set("'.$category.'",print_info_for) and print_info_module_id = "custom_approval" and cw_print_info.trans_status = 1';
		$email_temp_info   = $this->db->query("CALL sp_a_run ('SELECT','$email_temp_query')");
		$email_temp_result = $email_temp_info->result();
		$email_temp_info->next_result();
		if($email_temp_result){
			$print_doc_id   = $email_temp_result[0]->prime_print_info_id;
			$email_subject  = $email_temp_result[0]->email_subject;
			$email_data     = $this->load_email_data($print_doc_id,$view_id);
			$body_content   = "<!DOCTYPE html><html> <body>".$email_data['print_design']."</body></html>";
		}
		
		$design_query  = 'SELECT prime_print_info_id,print_design,print_info_for,print_info_module_id,print_type FROM cw_print_design inner join cw_print_info on cw_print_info.prime_print_info_id = cw_print_design.print_design_for WHERE FIND_IN_SET("'.$category.'",print_info_for) and print_info_module_id = "custom_approval" and cw_print_design.trans_status = 1';
		$design_info   = $this->db->query("CALL sp_a_run ('SELECT','$design_query')");
		$design_result = $design_info->result();
		$design_info->next_result();
		$print_doc_id  = $design_result[0]->prime_print_info_id;
		$data          = $this->load_print_data($print_doc_id,$view_id);
		$table_data = "<!DOCTYPE html><html> <body>".$data['print_design']."</body></html>";
		$folder_name = "custom_approval";
		$pdf_file   = $this->generate_pdf($table_data,$category,$employee_code,$folder_name);
		if($emp_email_id){
			$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       = $sender_email;
			$mail->FromName   = $sender_name;
			$mail->AddAddress($emp_email_id);
			$mail->IsHTML(true);
			$mail->Subject = $email_subject;//dynamic subject for custom approval
			$mail->Body    = $body_content;//dynamic body content for custom approval
			//Attachment
			$folder = $pdf_file;
			if(file_exists($folder)){
				$mail->addAttachment($folder); // Add attachments
				$mail= $mail->Send();
				if($mail){
					$message = "Mail Sent Successfully";
				}			
			}else{
				$message = "File Not Exist";
			}
		}else{
			$message = 'Server timeout';
		}
		return $message;
	}
}
?>