<?php
class Datasheet extends CI_Controller {

    public function __construct() {
        parent::__construct();
       $this->load->model('datasheet_model');
        $this->load->library('session');
        $this->load->helper('url');
        if (!$this->session->userdata('is_user_loged')) {
            redirect('login');
        }
    }

    public function show_table_task($_user_level = 4) {
        $data['users'] = $this->datasheet_model->load_anm($_user_level); 
        $this->session->set_userdata('page_name', 'mira_task_table');
        $this->load->view('mira_welcome_page', $data); 
    }


   public function show_house_table_task($_user_level = 4) {
        $data['users'] = $this->datasheet_model->load_anm($_user_level);
        $this->session->set_userdata('page_name', 'mira_task_table');
        $this->load->view('mira_welcome_page', $data);
    }

     public function show_women_table_task($_user_level = 4) {
        $data['users'] = $this->datasheet_model->load_anm($_user_level);
        $this->session->set_userdata('page_name', 'mira_task_table_women');
        $this->load->view('mira_welcome_page', $data);
    } 
    public function show_child_table_task($_user_level = 4) {
        $data['users'] = $this->datasheet_model->load_anm($_user_level);
        $this->session->set_userdata('page_name', 'mira_task_table_child');
        $this->load->view('mira_welcome_page', $data);
    }



    public function show_asha_list() {
        $_region_code = $this->input->post('region_code');
        $data['anm'] = $this->datasheet_model->load_asha($_region_code);
        echo json_encode($data['anm']);
    }

    public function show_table() {
        $_region_code = $this->input->post('region_code');
        $data['data'] = $this->datasheet_model->show_data($_region_code);
        echo json_encode($data['data']);
    }

     public function show_house_table() {
        $_region_code = $this->input->post('region_code');
        $data['data'] = $this->datasheet_model->show_house_data($_region_code);
        echo json_encode($data['data']);
    }
    
     public function show_women_table() {
        $_region_code = $this->input->post('region_code');
        $data['data'] = $this->datasheet_model->show_women_data($_region_code);
        echo json_encode($data['data']);
    }
  
    public function update_date() {
        // Get the input data
        $house_id = $this->input->post('house_id');
        $child_id = $this->input->post('child_id');
        $women_id = $this->input->post('women_id');
        $date     = $this->input->post('actual_register_date');
        $formatted_date = date('Y-m-d', strtotime(str_replace('/', '-', $date)));
        $update_result = $this->datasheet_model->update_date($house_id, $child_id, $women_id, $formatted_date);
            echo json_encode(array('status' => 'success'));
      
    }
    
    }
    

