File: //var/www/html/pmw24/pmw_live_testing/OLD_Root_BAK/application/controllers/admin/City.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class City extends MY_Controller {
public function __construct() {
parent::__construct();
$this->redirect_guest();
$this->admin=$this->session->userdata('admin');
$this->load->model('admin/mcity');
}
public function index() {
$this->_load_list_view();
}
private function _load_list_view() {
$data['content'] = 'admin/city/list';
$this->load->view('admin/layouts/index', $data);
}
public function all_content_list(){
$list = $this->mcity->get_datatables();
$data = array();
$no = $_POST['start'];
$i=1;
foreach ($list as $person) {
$no++;
$row = array();
//$row[]=$i;
$row[] = $person->name;
$row[] = $person->date_of_creation;
$row[] = '<a class="cstm_view" href="'.base_url('admin/city/details/'.$person->city_id).'" title="Edit">Edit</a>|<a class="cstm_view" id="delete" style="padding-left:5px" href="javascript:void(0)" title="'.$person->city_id.'">Delete</a>|<a class="cstm_view" id="view" style="padding-left:5px" href="javascript:void(0)" title="'.$person->city_id.'">View</a>';
$data[] = $row;
$i++;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->mcity->count_all(),
"recordsFiltered" => $this->mcity->count_filtered(),
"data" => $data,
);
echo json_encode($output);
}
public function add(){
$this->_load_add_view();
}
private function _load_add_view(){
$data['content']='admin/city/add';
$this->load->view('admin/layouts/index',$data);
}
public function add_content(){
if($this->input->post()){
$this->form_validation->set_rules('city_name','City Name','required');
if($this->form_validation->run()==FALSE){
$this->_load_add_view();
}else{
$city_name = $this->input->post('city_name');
$check_exsits = $this->mcity->check_city_exsits($city_name);
if($check_exsits == 1){
$this->session->set_flashdata('error_msg','City already exsits');
redirect('admin/city');
}else{
$udata['name'] = $this->input->post('city_name');
$udata['date_of_creation'] = date('Y-m-d');
$city_id=$this->mcity->add($udata);
$this->session->set_flashdata('success_msg','City added successfully');
redirect('admin/city');
}
}
}else{
$this->_load_list_view();
}
}
public function all_details(){
$city_id = $this->input->post('city_id');
$result = $this->mcity->get_details($city_id);
echo json_encode($result);
}
public function edit($city_id){
$data['cms']=$this->mcity->get_details($city_id);
if(empty($data['cms'])){
$this->_load_list_view();
}else{
$this->_load_details_view($data);
}
}
private function _load_details_view($parms){
$data['cms']=$parms['cms'];
$data['content'] = 'admin/city/detail';
$this->load->view('admin/layouts/index', $data);
}
public function update(){
if($this->input->post()){
$this->form_validation->set_rules('city_name','City Name','required');
if($this->form_validation->run()==FALSE){
$city_id = $this->input->post('city_id');
$data['cms']=$this->mcity->get_details($city_id);
$this->_load_details_view($data);
}else{
$city_id = $this->input->post('city_id');
$city_name = $this->input->post('city_name');
$city_information = $this->mcity->get_details($city_id);
if($city_information['name'] == $city_name)
{
$udata['name'] = $this->input->post('city_name');
$udata['date_of_update'] = date('Y-m-d');
$condition=array('city_id'=>$city_id);
$this->mcity->update($condition,$udata);
$this->session->set_flashdata('success_msg','City updated successfully');
redirect('admin/city');
}else{
$check_exsits = $this->mcity->check_city_exsits($city_name);
if($check_exsits == 1){
$this->session->set_flashdata('error_msg','City already exsits');
redirect('admin/city');
}else{
$udata['name'] = $this->input->post('city_name');
$udata['date_of_update'] = date('Y-m-d');
$condition=array('city_id'=>$city_id);
$this->mcity->update($condition,$udata);
$this->session->set_flashdata('success_msg','City updated successfully');
redirect('admin/city');
}
}
}
}else{
$this->_load_list_view();
}
}
public function delete_content(){
$condition['city_id']=$this->input->post('city_id');
$this->mcity->delete($condition);
$response=array('status'=>1,'message'=>'Success');
echo header('Content-Type: application/json');
echo json_encode($response);
}
}