<?php
/**
 * Plantouestypes Management
 * @package     ci-hotel
 * @author      Teruki Hosokawa <hosotk@gmail.com>
 * @license     New BSD License
 */
require_once (dirname(__FILE__) . "/ADMIN_Controller.php");

/**
 */
class Plantoguesttypes extends ADMIN_Controller {
    
    function Plantoguesttypes()
    {
        parent::ADMIN_Controller();
        $this->load->model('User_model');
        $this->load->model('Hotel_model');
    }
    
    /**
     * 客タイプ一覧
     */
    public function index($hotelid, $planid)
    {
        $this->load->library('session');
        $this->load->helper(array('form', 'url'));
        
        $this->db->where('hotelid', $hotelid);
        $query = $this->db->get('guesttypes');
        $data['hotelid'] = $hotelid;
        $data['planid'] = $planid;
        $data['guesttypes'] = $query->result_array();
        $this->load->vars($data);
        
        if (isset($_POST['submit']))
        {
            // 一旦削除する。
            $this->db->where('hotelid', $hotelid);
            $this->db->where('planid', $planid);
            $this->db->delete('plan_to_guesttypes');
            //$this->db->where('hotelid', $hotelid);
            //$this->db->where('planid', $planid);
            //$this->db->delete('plan_prices');
            
            if (isset($_POST['guesttypes']) != null)
            {
                $guesttypids = $_POST['guesttypes'];
                foreach ($guesttypids as $guesttypeid)
                {
                    //var_dump($guesttypeid);
                    $data = array(
                       'hotelid' => $hotelid,
                       'planid' => $planid,
                       'guesttypeid' => $guesttypeid
                    );
                    $this->db->insert('plan_to_guesttypes', $data); 
                }
            }
        }
        
        $options = array();
        $this->db->where('hotelid', $hotelid);
        $this->db->where('planid', $planid);
        $query = $this->db->get('plan_to_guesttypes');
        foreach ($query->result() as $row)
        {
            $options[] = $row->guesttypeid;
        }
        $data['options'] = $options;
        $this->load->vars($data);
        
        $this->load->view('admin/plantoguesttypes/index');
    }
    
}
/* End of file plantoguesttypes.php */
