| Server IP : 162.214.74.102 / Your IP : 216.73.217.80 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/public_html/lrsys_projetos/sopizzas/application/controllers/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class City extends MY_Controller {
function __construct()
{
parent::__construct();
$this->load->helper("url");
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->library('javascript');
$this->load->library('Ajax_pagination');
$this->perPage = ROW_PER_PAGE;
$this->load->model('location_model');
$session_data = $this->session->userdata('logged_in');
}
function index($SearchBy = '')
{
if ($this->input->server('REQUEST_METHOD') == 'POST') {
if ($this->input->post('EditId') == '') {
$this->addCity();
}
else {
$this->editCity();
}
}
else {
$this->showCityList($SearchBy);
}
}
function showCityList($SearchBy = '') {
//total rows count
$totalRec = count($this->location_model->get_city_list());
//pagination configuration
$config['target'] = '#postList';
$config['base_url'] = base_url().'city/ajaxPaginationData/'.$SearchBy;
$config['total_rows'] = $totalRec;
$config['per_page'] = $this->perPage;
$this->ajax_pagination->initialize($config);
//get the posts data
$data['CityList'] = $this->location_model->get_city_list(array('limit'=>$this->perPage), $SearchBy);
$data['StateList'] = $this->location_model->get_state_list($params = array(), $action = '1');
$data['title']="City";
$data['page']="city";
$this->load->view('superadmin/header',$data);
$this->load->view('superadmin/main-sidebar');
$this->load->view('superadmin/city');
$this->load->view('superadmin/footer');
}
function ajaxPaginationData(){
$action = $this->input->post('action');
$page = $this->input->post('page');
if(!$page){
$offset = 0;
}else{
$offset = $page;
}
$perpage = $this->input->post('per_page');
if(!$perpage){
$perpage = $this->perPage;
}else{
$perpage = $perpage;
}
//total rows count
$totalRec = count($this->location_model->get_city_list());
//pagination configuration
$config['target'] = '#postList';
$config['base_url'] = base_url().'city/ajaxPaginationData';
$config['total_rows'] = $totalRec;
$config['per_page'] = $perpage;
$this->ajax_pagination->initialize($config);
//get the posts data
$data['CityList'] = $this->location_model->get_city_list(array('start'=>$offset,'limit'=>$perpage), $action);
$data['title']="City";
$data['page']="city";
$data['perPageCount'] = $page;
/*** Remember what was the last page start ***/
if ($this->input->post('pagination') != '') {
$myPage = $this->input->post('page');
$myAction = $this->input->post('action');
$myPerPage = $this->input->post('per_page');
$myAction2 = $this->input->post('action2');
$paginationArray = array('page' => $myPage, 'action' => $myAction, 'per_page' => $myPerPage, 'action2' => $myAction2, 'page_name' => $data['page'], 'pagination' => $this->input->post('pagination'));
if ($this->session->userdata('paginationArray')) {
$this->session->unset_userdata('paginationArray');
}
$this->session->set_userdata('paginationArray', $paginationArray);
}
/*** Remember what was the last page end ***/
$this->load->view('superadmin/city-list-ajax', $data, false);
}
function addCity() {
$now = date('Y-m-d H:i:s');
$this->form_validation->set_rules('statecode', 'State Code', 'trim|required|xss_clean');
$this->form_validation->set_rules('cityname', 'City Name', 'trim|required|xss_clean|is_unique[rt_city.cityname]');
if ($this->form_validation->run() == FALSE) {
$this->showCityList();
}
else {
$this->db->trans_start();
$data_in = array(
'statecode' => $this->input->post('statecode'),
'cityname' => $this->input->post('cityname'),
'addeddate' => $now
);
$this->db->insert('rt_city', $data_in);
$this->db->trans_complete();
$this->session->set_flashdata('success_msg', $this->input->post('cityname').' is successfully saved');
redirect('superadmin/city');
}
}
function editCity() {
$EditId = $this->input->post('EditId');
$this->form_validation->set_rules('statecode', 'State Code', 'trim|required|xss_clean');
$this->form_validation->set_rules('cityname', 'City Name', 'trim|required|xss_clean|callback_isCityNameExist');
if ($this->form_validation->run() == FALSE) {
$this->showCityList();
}
else {
$this->db->trans_start();
$data_up = array(
'statecode' => $this->input->post('statecode'),
'cityname' => $this->input->post('cityname')
);
$this->db->where('city_id', $EditId);
$this->db->update('rt_city', $data_up);
$this->db->trans_complete();
$this->session->set_flashdata('success_msg', $this->input->post('cityname').' is successfully updated');
redirect('superadmin/city');
}
}
function isCityNameExist() {
$cityname = $this->input->post('cityname');
$city_id = $this->input->post('EditId');
$is_exist = $this->location_model->isCityNameExist
($city_id, $cityname);
if ($is_exist) {
$this->form_validation->set_message('isCityNameExist', 'City Name already exist');
return false;
}
else {
return true;
}
}
}