File: //home/cafsindia/cloud_cafsinfotech_in/application/controllers/Employee_enrolment.php
<?php
/**********************************************************
Filename: Employee Enrolment
Description: Employee enrolment for adding new module and form to sent to user.
Author: Jaffer Sathik
Created on: 23 December 2019
Reviewed by:
Reviewed on:
Approved by:
Approved on:
-------------------------------------------------------
Modification Details
Changed by:
Change Info:
-------------------------------------------------------
***********************************************************/
if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Secure_Controller.php");
class Employee_enrolment extends Secure_Controller{
public function __construct(){
parent::__construct('employee_enrolment');
}
public function index(){
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$data['table_headers']=$this->xss_clean(get_custom_form_setting_headers());
$this->load->view('employee_enrolment/manage',$data);
}
/* ==============================================================*/
/* ================== COMMON OPEARTION - START ==================*/
/* ==============================================================*/
//MODULE SEARCH OPEARTION
public function search(){
$search = $this->input->get('search');
$limit = $this->input->get('limit');
$offset = $this->input->get('offset');
$sort = $this->input->get('sort');
$order = $this->input->get('order');
if(!$sort){
$sort = "abs(menu_sort)";
}
if(!$order){
$order = "asc";
}
// Fetch Records
$info = $this->db->query("CALL sp_custom_form_search ('SEARCH')");
$result = $info->result();
$info->next_result();
$data_rows = array();
foreach ($result as $custom_setting){
$prime_module_id = $custom_setting->module_id;
$data_rows[]=get_custom_form_setting_datarows($custom_setting,$this);
}
$data_rows=$this->xss_clean($data_rows);
// Fetch Records Count
$count_info = $this->db->query("CALL sp_custom_form_search ('COUNT')");
$count_result = $count_info->result();
$count_info->next_result();
$num_rows = $count_result[0]->data_count;
echo json_encode(array('total'=>$num_rows,'rows'=>$data_rows));
}
//MODULE VIEW OPEARTION
public function view($prime_module_id =-1){
if($prime_module_id){
$data['prime_module_id'] = $prime_module_id;
}
$find_form_name_qry = 'select * from cw_form_view_setting where prime_view_module_id="'.$prime_module_id.'" and form_view_show = 1 order by form_view_sort asc';
$find_form_name_data = $this->db->query("CALL sp_a_run ('SELECT','$find_form_name_qry')");
$find_form_name_result = $find_form_name_data->result();
$find_form_name_data->next_result();
$form_name_list[""] = "---- Form Name For ----";
foreach($find_form_name_result as $form_rslt){
$prime_form_view_id = $form_rslt->prime_form_view_id;
$label_name = $form_rslt->form_view_label_name;
$form_view_heading = $form_rslt->form_view_heading;
$form_name_list[$prime_form_view_id] = $form_view_heading;
}
$data['form_name_list'] = $form_name_list;
$this->load->view("employee_enrolment/enroll_setting",$data);
}
public function form_name_field_list(){
$module_id = $this->input->post('module_id');
$form_name = $this->input->post('form_name');
$field_name_qry = 'select * from cw_form_setting inner join cw_form_view_setting on cw_form_view_setting.prime_form_view_id=input_for where prime_module_id="'.$module_id.'" and input_for = "'.$form_name.'" and field_show =1 order by field_sort asc';
$field_name_data = $this->db->query("CALL sp_a_run ('SELECT','$field_name_qry')");
$field_name_result = $field_name_data->result();
$field_name_data->next_result();
$input_li = "";
foreach($field_name_result as $field_name){
$label_name = $field_name->label_name;
$input_view_type = $field_name->input_view_type;
$check_name_qry ='select field_show from cw_custom_design where prime_module_id="'.$module_id.'" and input_for = "'.$form_name.'" and label_name = "'.$label_name.'" and trans_status = 1';
$check_name_data = $this->db->query("CALL sp_a_run ('SELECT','$check_name_qry')");
$check_name_result = $check_name_data->result();
$check_name_data->next_result();
$field_show = $check_name_result[0]->field_show;
if($field_show){
$checked = "checked";
}else{
$checked = "";
}
$view_name = $field_name->view_name;
$input_li .= "<li class='ui-state-default'>
<table style='width:100%;'>
<tr>
<td style='font-weight:bold'>
<label>$view_name</label>
</td>
<td style='text-align:right;'>
<input name='$label_name' id='$label_name' type='checkbox' class='check_all' value='1' $checked/>
</td>
</tr>
</table>
</li>";
}
$ul_li = "<ul class='sortable'>$input_li</ul>";
$view_content = "<div style='font-size: inherit; box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2); background-color: #FFFFFF; border: 0px; border-radius: 2px;padding:8px;margin-bottom:10px;'>
<h4>Filed Name List</h4>
<input name='input_view_type' id='input_view_type' type='hidden' value='$input_view_type'/>
<p><input id='form_label_$form_name' type='checkbox'> All</p>
$ul_li
</div>";
echo json_encode(array('view_content' => $view_content));
}
public function save_form(){
$save_data = json_decode($this->input->post('save_data'));
$created_on = date("Y-m-d H:i:s");
$logged_id = $this->session->userdata('logged_id');
$module_name = $save_data[0]->name;
$module_val = $save_data[0]->value;
$form_name = $save_data[1]->name;
$form_val = $save_data[1]->value;
$input_view_name = $save_data[2]->name;
$input_view_val = $save_data[2]->value;
$count_data = count($save_data);
$exit_name_qry ='select count(prime_custom_design_id) as design_count from cw_custom_design where prime_module_id="'.$module_val.'" and input_for = "'.$form_val.'" and trans_status = 1 limit 1';
$exit_name_data = $this->db->query("CALL sp_a_run ('SELECT','$exit_name_qry')");
$exit_name_result = $exit_name_data->result();
$exit_name_data->next_result();
$design_count = $exit_name_result[0]->design_count;
$prime_qry_key = '';
$prime_qry_value = '';
if((int)$design_count === 0){
for($i = 3; $i < $count_data; $i++){
$column_name = $save_data[$i]->name;
$column_value = $save_data[$i]->value;
$prime_qry_key = "prime_module_id,input_for,input_view,label_name,field_show,trans_created_by,trans_created_date";
$prime_qry_value = '"'.$module_val.'","'.$form_val.'","'.$input_view_val.'","'.$column_name.'","'.$column_value.'","'.$logged_id.'",'.'"'.$created_on.'"';
$custom_design_qry = "insert into cw_custom_design ($prime_qry_key) values ($prime_qry_value)";
$custom_design_info = $this->db->query("CALL sp_a_run ('INSERT','$custom_design_qry')");
$custom_design_result = $custom_design_info->result();
$custom_design_info->next_result();
}
$message = "Sucessfully field name is selected!!!";
}else{//update label name
$set_query = 'trans_updated_by = "'. $logged_id .'",trans_updated_date = "'.$created_on.'"';
$update_query = 'UPDATE cw_custom_design SET trans_status = 0, '. $set_query .' WHERE prime_module_id = "'. $module_val .'" and input_for = "'.$form_val.'"';
if($this->db->query("CALL sp_a_run ('UPDATE','$update_query')")){
for($i = 3; $i < $count_data; $i++){
$column_name = $save_data[$i]->name;
$column_value = $save_data[$i]->value;
$prime_qry_key = "prime_module_id,input_for,input_view,label_name,field_show,trans_created_by,trans_created_date";
$prime_qry_value = '"'.$module_val.'","'.$form_val.'","'.$input_view_val.'","'.$column_name.'","'.$column_value.'","'.$logged_id.'",'.'"'.$created_on.'"';
$custom_design_qry = "insert into cw_custom_design ($prime_qry_key) values ($prime_qry_value)";
$custom_design_info = $this->db->query("CALL sp_a_run ('INSERT','$custom_design_qry')");
$custom_design_result = $custom_design_info->result();
$custom_design_info->next_result();
}
}
$delete_query = 'delete from cw_custom_design WHERE trans_status = 0';
$this->db->query("CALL sp_a_run ('RUN','$delete_query')");
$message = "Updated successfully filed name in the form!!!";
}
echo json_encode(array('success' => TRUE, 'message' => $message));
}
}
?>