<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Cities_controller extends CI_Controller {

    public function __construct() {
        parent::__construct();
        // Your own constructor code
        $this->load->model('cities_model');      
       
    }

    public function cities_list($cityid=null){
                
        if ($this->session->userdata('role') == '' || $this->session->userdata('role') == 'Sh-Users') {
            $this->load->view('login_view');
            
        } else {            
            
            $data['nav'] = 'business_cities';
            $data['subnav'] = 'business_cities';
            
            
            if(null != $this->input->post('city_id')){
                $cityid=$this->input->post('city_id');
            }
            
            $data['cities']=$this->cities_model->get_all_cities($cityid);
            
            
//            print_r($data['staffs']);
//            exit();
            $this->load->view('includes/header',$data);
            $this->load->view('cities/cities_list');
            $this->load->view('includes/footer');
        }

    }
    
    public function get_a_city($id_cities=null){
        //echo $floorid ;
        if(null == $id_cities){
            $id_cities = $this->input->post('id_cities');
        }
       
        $data=$this->cities_model->get_all_cities($id_cities);
        
        echo (json_encode($data));
        die;
    }
    
    
    public function update_city(){
        
        
        $result=$this->cities_model->update_city();
        
        echo 'success|'.$result;
        die;
        
    }
    
    public function add_city(){
        
        $result=$this->cities_model->add_city();
        
        echo 'success|'.$result;
        die;
        
    }
    
     public function city_areas($cityid=null){
                
        if ($this->session->userdata('role') == '' || $this->session->userdata('role') == 'Sh-Users') {
            $this->load->view('login_view');
            
        } else {            
            
            $data['nav'] = 'business_cities';
            $data['subnav'] = 'business_cities';
            
            
            if(null != $this->input->post('city_id')){
                $cityid=$this->input->post('city_id');
            }
            
            $data['city_areas']=$this->cities_model->get_all_city_areas($cityid,null);
            
            $data['cities']=$this->cities_model->get_all_cities();
                    
//            print_r($data['staffs']);
//            exit();
            $this->load->view('includes/header',$data);
            $this->load->view('cities/city_areas');
            $this->load->view('includes/footer');
        }

    }
    
     public function get_a_city_area($id_city_areas=null){
        //echo $floorid ;
        if(null == $id_city_areas){
            $id_city_areas = $this->input->post('id_city_areas');
        }
       
        $data=$this->cities_model->get_all_city_areas(null, $id_city_areas);
        
        echo (json_encode($data));
        die;
    }
    
    public function update_city_area(){
        
        
        $result=$this->cities_model->update_city_area();
        
        echo 'success|'.$result;
        die;
        
    }
    
    public function add_city_area(){
        
        $result=$this->cities_model->add_city_area();
        
        echo 'success|'.$result;
        die;
        
    }
}