<?php

class Equip extends MY_Controller {
    public $page_title = 'อุปกรณ์ห้องประชุม';

    function __construct() {
        parent::__construct();
        $this->load->model('db_m');
        $this->load->model('script_m');
        $this->load->model('equip_m');
        
        $s_imeeting['activemenu'] = '002';
        $this->session->set_userdata('s_imeeting',$s_imeeting);
    }

    function index() {
        $data['extraHeadContent'] = $this->script_m->bootstrap_modal();
        $data['page_title'] = $this->page_title;
        $data['content'] = 'equip/equip_v';
        $this->load->view('template_v', $data);
    }

    function ajax_get_grid($offset = 0) {
        $txtsearch = $this->input->post('txtsearch');

        $array = $this->equip_m->get_all($txtsearch, $offset);
        $data['query'] = $array['query'];
        $data['pagination'] = $array['pagination'];
        $this->load->view('equip/equip_grid_v', $data);
    }

    function ajax_get_data() {
        $id = $this->input->post('id');
        $this->db->where('id', $id);
        $row = $this->db->get('tbequip')->row_array();

        echo json_encode($row);
    }

    function ajax_save() {
        $id = $this->input->post('id');

        $data = array(
            'name' => $this->input->post('name'),
            'detail' => $this->input->post('detail')
        );

        $result = $this->db_m->validate_save('tbequip', $id, 'name', $this->input->post('name'), $data);

        echo json_encode($result);
    }

    function ajax_delete() {
        $this->db->where('id', $this->input->post('id'));
        $this->db->delete('tbequip');
        echo true;
    }

}

?>
