<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * 访问权限管理
 */

class Permission {

    var $CI;

    public function __construct() {
        $this->CI = & get_instance();
        log_message('debug', "Access permission Class Initialized");
    }

    function is_admin($auto_redirect = true) {
        if ($this->CI->session->userdata('session_admin') === FALSE) {
            if ($auto_redirect) {
                redirect(site_url('login'));
            } else {
                return false;
            }
        } else {
            $site_item = $this->CI->session->userdata('session_site');
            $this->CI->config->set_item('site_code', $site_item['site_code']);
            $this->CI->config->set_item('site_lgc', $site_item['site_lgc']);
            $this->CI->config->set_item('site_url', $site_item['site_url']);
            $this->CI->config->set_item('site_id', $site_item['site_id']);
            $this->CI->config->set_item('site_image_url', $site_item['site_image_url']);
            /*
              //国际站和子网站自动跳转到欧洲的信息平台，其它站点不变
              if ((is_series_site() || is_sub_site()) && stripos(site_url(),  'http://europe.chtcdn.com/' ) === FALSE )
              {
              redirect('http://europe.chtcdn.com/info.php/login/change_site/'.$site_item['site_code']);
              }
              else if (!is_series_site() && !is_sub_site() && stripos(site_url(),  'http://i.chtcdn.com/' ) === FALSE)
              {
              redirect('http://i.chtcdn.com/info.php/login/change_site/'.$site_item['site_code']);
              }
             */
            return true;
        }
    }

}
