<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Room extends MY_BackendController {

     public function __construct() {
        parent::__construct();
        $this->load->model('Room_model');
    }
    
    public function index() {        
        $this->view('backend/room/index', ['items'=>$this->Room_model->listing_in_datatables()]);
    }

    public function add() {
        $input = $this->input->post();
        if (!empty($input)) {           
            $newid = $this->Room_model->insert($input);
            header('location: /room');
        }
        $default = ['status' => 1];
        $this->view('backend/room/add', ['status' => $this->Room_model->status, 'default' => $default]);
    }

    public function edit() {
        $request = $this->input->post();
        $result = $this->Room_model->one($request['id']);
        $this->view('backend/room/edit', ['status' => $this->Room_model->status, 'room' => $result]);
    }

    // Insert / Update
    public function save() {
        $request = $this->input->post();
        $data = ['name' => trim($request['name']),'capacity'=>trim($request['capacity']),'description'=>trim($request['description']), 'status' => trim($request['status']), 'remark' => trim($request['remark'])];
        $this->Room_model->save($data, $request['id']);
        header('location:/room');
    }

    public function delete() {
        $request = $this->input->post();
        $ids = explode(',', $request['ids']);
//       log_message('debug','is ids array?'.is_array($ids));//true
        $this->Room_model->deleteMultiple($ids);
        header("location:/room");
    }

    public function deleteall() {
        $this->Room_model->deleteAll();
        header("location:/room");
    }

}
