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

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

   
    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);
        }
    }


    private function getNumberOfPages($_total_number = NULL, $_per_page_row = NULL) {
        if ($_total_number != NULL and $_per_page_row != NULL) {
            if (!($_total_number % $_per_page_row)) {
                return (int) ($_total_number / $_per_page_row);
            } else {
                return((int) ($_total_number / $_per_page_row) + 1);
            }
        } else {
            return FALSE;
        }
    }


    public function getChildListByRegionID() {
       $return = NULL;
        switch (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->Registration_house_women_child_model->getChildListByRegionCodeModel($this->session->userdata('create_region_id'))), $_per_page_row);
                $return['childList'] = $this->Registration_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;
                
            case 3:
                $per_page_row = 8;
                $return['anmList'] = $this->Registration_house_women_child_model->getANMListWithAppId($this->session->userdata('app_id'), $this->session->userdata('create_region_id'));
                $return['flag'] = false;
               
                break;
        }
        $this->session->set_userdata('page_name', 'mira_wise_data_by_anm');
        //print_r($return);
        $this->load->view('mira_welcome_page', $return);
    }

    

}
