<?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 restore
 *
 * @author zmq163
 */
class Restore extends CI_Controller {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->library('session');
        $this->load->helper('url');
        $this->load->model('restore_house_women_child_model');
    }
    /**
     * 
     * 
     * 
     * 
     */
    public function updateAncJquery(){
        $tempIdCode=explode(':',$_POST['pregnant_id_anc_code']);
        $postData=array(
            'anc_date'=>  date('Y-m-d',strtotime($_POST['anc_date'])),
            'pregnant_id'=>$tempIdCode[0],
            'anc_code'=>$tempIdCode[1],
            'critical_status'=>$_POST['critical_status']
            );
        print_r(json_encode(array('status'=>  $this->restore_house_women_child_model->updateAncJqueryModel($postData))));
        //print_r(json_encode(array('status'=>TRUE)));
    }

    /**
     * 
     * 
     * 
     * 
     * 
     */
    public function getRestoreChildList(){
        $return = NULL;
        switch ($this->returnMiraAnm($this->session->userdata('level'), $this->session->userdata('app_total_level'))) {
            case 1:
                $_per_page_row = 10;
                $return['activePage'] = $this->uri->segment(2);
                $return['totalPage'] = $this->getTotaoPage(count($this->restore_house_women_child_model->getChildListByRegionCodeModel($this->session->userdata('create_region_id'))), $_per_page_row);
                $return['childList'] = $this->restore_house_women_child_model->getChildListByRegionCodeModel($this->session->userdata('create_region_id'), $this->uri->segment(2), $_per_page_row);
                break;
//            case 2:
//                $_per_page_row = 8;
//                $return['miraList'] = $this->Registration_house_women_child_model->getAshaListWithRegionCode($this->session->userdata('app_id'), $this->session->userdata('create_region_id'));
//                $return['activePage'] = $this->uri->segment(2);
//                $return['regionCode'] = $this->uri->segment(3);
//                if ($return['activePage'] != ''and $return['regionCode'] != '') {
//                    $return['totalPage'] = $this->getTotaoPage(count($this->Registration_house_women_child_model->getChildListByRegionCodeModel($return['regionCode'])), $_per_page_row);
//                    $return['childList'] = $this->Registration_house_women_child_model->getChildListByRegionCodeModel($return['regionCode'], $return['activePage'], $_per_page_row);
//                }
//                break;
        }
        $this->session->set_userdata('page_name', 'restore/child_list');
        //print_r($return);
        $this->load->view('mira_welcome_page', $return);
    }

    /**
     * 
     * 
     * 
     * 
     * 
     */
    public function getRestoreHouseList() {
        $return['activePage'] = '';
        $return['regionCode'] = '';
        switch ($this->returnMiraAnm($this->session->userdata('level'), $this->session->userdata('app_total_level'))) {
            case 1:
                $per_page_row = 10;
                $return['activePage'] = $this->uri->segment(2);
                $return['houseList'] = $this->restore_house_women_child_model->getHouseListByRegionCodeModel($this->session->userdata('create_region_id'), $return['activePage'], $per_page_row);
                $return['totalPage'] = $this->getTotaoPage(count($this->restore_house_women_child_model->getHouseListByRegionCodeModel($this->session->userdata('create_region_id'))), $per_page_row);
                break;
//            case 2:
//                $per_page_row = 8;
//                $return['miraList'] = $this->Registration_house_women_child_model->getAshaListWithRegionCode($this->session->userdata('app_id'), $this->session->userdata('create_region_id'));
//                $return['activePage'] = $this->uri->segment(2);
//                $return['regionCode'] = $this->uri->segment(3);
//                if ($return['activePage'] != ''and $return['regionCode'] != '') {
//                    $return['houseList'] = $this->Registration_house_women_child_model->getHouseListByRegionCodeModel($return['regionCode'], $return['activePage'], $per_page_row);
//                    $return['totalPage'] = $this->getTotaoPage(count($this->Registration_house_women_child_model->getHouseListByRegionCodeModel($return['regionCode'])), $per_page_row);
//                }
//                break;
        }

        $this->session->set_userdata('page_name', 'restore/house_list');
        $this->load->view('mira_welcome_page', $return);
    }
    /**
     * 
     * 
     * 
     * 
     * 
     * 
     */
    public function getRestoreWomenList(){
        $return = NULL;
        switch ($this->returnMiraAnm($this->session->userdata('level'), $this->session->userdata('app_total_level'))) {
            case 1:
                $_per_page_row = 10;
                $return['totalPage'] = $this->getTotaoPage(count($this->restore_house_women_child_model->getWomenListByRegionCodeModel($this->session->userdata('create_region_id'))), $_per_page_row);
                $return['activePage'] = $this->uri->segment(2);
                $return['womenList'] = $this->restore_house_women_child_model->getWomenListByRegionCodeModel($this->session->userdata('create_region_id'), $return['activePage'], $_per_page_row);
                break;
//            case 2:
//                $per_page_row = 8;
//                $return['miraList'] = $this->Registration_house_women_child_model->getAshaListWithRegionCode($this->session->userdata('app_id'), $this->session->userdata('create_region_id'));
//                $return['activePage'] = $this->uri->segment(2);
//                $return['regionCode'] = $this->uri->segment(3);
//                if ($return['activePage'] != ''and $return['regionCode'] != '') {
//                    $return['womenList'] = $this->Registration_house_women_child_model->getWomenListByRegionCodeModel($return['regionCode'], $return['activePage'], $per_page_row);
//                    $return['totalPage'] = $this->getTotaoPage(count($this->Registration_house_women_child_model->getWomenListByRegionCodeModel($return['regionCode'])), $per_page_row);
//                }
//                break;
        }
        $this->session->set_userdata('page_name', 'restore/women_list');
        $this->load->view('mira_welcome_page', $return);
    }
    /**
     * 
     * 
     * 
     * 
     * 
     */
    public function updateRestoreWomen(){
         print_r(json_encode(array('status'=>$this->restore_house_women_child_model->updateRestoreWomenModel( $_POST['women_id']))));
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function updateRestoreHouse() {
 
        print_r(json_encode(array('status'=>$this->restore_house_women_child_model->updateRestoreHouseModel( $_POST['auto_id']))));
  
    }
    /**
     * 
     * 
     * 
     */
    public function updateRestoreChild(){
        print_r(json_encode(array('status'=>$this->restore_house_women_child_model->updateRestoreChildModel( $_POST['child_id']))));
    }

    /**
     * 
     * 
     * 
     * 
     * 
     */
    public function returnMiraAnm($_user_level = NULL, $_total_app_level = NULL) {
        $data_return = NULL;
        if ($_user_level == $_total_app_level) {
            $data_return = 1;
        } else if (($_user_level + 1) == $_total_app_level) {
            $data_return = 2;
        }
        return $data_return;
    }
    /**
     * 
     * 
     * 
     * 
     */
    private function getTotaoPage($_total_row = NULL, $_per_page_row = NULL) {
        if (!($_total_row % $_per_page_row)) {
            return (int) ($_total_row / $_per_page_row);
        } else {
            return ((int) ($_total_row / $_per_page_row) + 1);
        }
    }

}
