<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class ADMIN_Controller extends Controller {
    function ADMIN_Controller()
    {
        parent::Controller();
        
        $this->load->helper('url');
        
        // 共通の処理をここに書く
        // ...
        
        $this->load->library('phpsession');
        
        $admin = $this->phpsession->get('admin');
        if (is_null($admin))
        {
            // 管理者ログインページへ
            redirect('admin/login');
        }
        
        $base_url = base_url();
        $current_url = current_url();
        //log_message('debug', 'base_url=' . $base_url);
        //log_message('debug', 'current_url=' . $current_url);
        
        $url = substr($current_url, strlen($base_url));
        //log_message('debug', 'url=' . $url);
        $a = explode('/', $url);
        $hotelid = $a[3];
        //log_message('debug', 'hotelid=' . $hotelid);
        
        if ($admin['hotelid'] != $hotelid)
        {
            die('oops! invalid hotelid');
        }
        
        $this->db->where('hotelid', $hotelid);
        $query = $this->db->get('hotels', 1);
        if ($query->num_rows() > 0)
        {
            $data['hotel_spec'] = $query->row_array();
            $this->load->vars($data);
        }
        
        $data['hotelid'] = $hotelid;
        
        $this->load->vars($data);
        
        $box['loginbox'][1] = '<a href="' . site_url('admin/login/logout/') . '">ログアウト</a>';
        $this->load->vars($box);
    }
    
    public function logout()
    {
        $this->load->helper(array('form', 'url'));
        $this->load->library('phpsession');
        
        $this->phpsession->clear('admin');
        redirect('admin/index/index/');
    }
}
?>