<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AreaAdd
 *
 * @author zmq163
 */
class AreaAdd extends CI_Controller {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->library('session');
        $this->load->helper('url');
        $this->load->model('Add_area_model');
         if (!$this->session->userdata('is_user_loged')) {
            redirect('login');
        }
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function addCountryView() {
        $this->session->set_userdata('page_name', 'mira_add_country');
        $this->load->view('mira_welcome_page');
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function addCountry() {
        $this->session->set_userdata('page_name', 'mira_success_page');
        if ($this->Add_area_model->addCountryModel(array('country_id' => $_POST['country_code'], 'country_name' => $_POST['country']))) {
            $return['status'] = TRUE;
            $return['message'] = "Your Coutry add Successfully";
        } else {
            $return['status'] = FALSE;
            $return['message'] = "Your Coutry already add.";
        }

        $this->session->set_userdata('alert_message_info', 'add_country_message');
        $this->load->view('mira_welcome_page', $return);
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function addStateView() {
        $return['country'] = $this->Add_area_model->getCountryModel(1);
        $this->session->set_userdata('page_name', 'mira_add_state');

        $this->load->view('mira_welcome_page', $return);
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function addState() {
        $this->session->set_userdata('page_name', 'mira_success_page');
        $return['status'] = $this->Add_area_model->addStateModel(array('country_code' => $_POST['country_code'], 'state_name' => $_POST['state'], 'state_code' => $_POST['state_code'], 'state_actvation_status' => 1));
        $return['message'] = "Your State add Successfully";
        $this->session->set_userdata('alert_message_info', 'add_state_message');
        $this->load->view('mira_welcome_page', $return);
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function getState() {
        $return['state'] = $this->Add_area_model->getStateByCountryCodeModel($_POST['country_code']);
        print_r(json_encode($return));
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function addDistrictView() {
        $return['country'] = $this->Add_area_model->getCountryModel(1);
        $this->session->set_userdata('page_name', 'mira_add_district');
        $this->load->view('mira_welcome_page', $return);
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function addDistrict() {

        $this->session->set_userdata('page_name', 'mira_success_page');
        $return['status'] = $this->Add_area_model->addDistrictModel(array('district_activation_status' => 1, 'district_name' => $_POST['district'], 'state_code' => $_POST['state_code'], 'district_code' => $_POST['district_code']));
        $return['message'] = "Your district add Successfully";
        $this->session->set_userdata('alert_message_info', 'add_district_message');
        $this->load->view('mira_welcome_page', $return);
    }

    public function getDistrict() {
        $return['district'] = $this->Add_area_model->getDistrictByStateCodeModel($_POST['state_code']);
        print_r(json_encode($return));
    }

}
