<?php
class AppBootstrap {
 public function boot() {
 include_once(CONFIG_PATH . 'local.config.php');
 include_library('Cookie');
 if(!(\Cookie::has('asset_url'))) \Cookie::set("asset_url",asset());
 if(area_name() == 'super-admin') {
 $auth = load_auth();
 if(!$auth->hasRole(\RoleGlobal::$role->enterSuperAdmin)) {
 redirect(base_url());
 }
 }
 else if(area_name() == 'master') {
 $auth = load_auth();
 if($auth->hasRole(\RoleGlobal::$role->enterSuperAdmin)) {
 redirect(base_url() . '/super-admin');
 }
 }
 }
 public function error($ex) {
 }
 }
 function showUnauthorized() {
 if(\RoleGlobal::$role->lastRoleCalled) {
 $r = \RoleGlobal::$role->getRole(\RoleGlobal::$role->lastRoleCalled);
 throw new \TCMS\TException(lang('unauthorized.authorized'). ' ' . $r->name . ' ' . $r->group, 401);
 }
 else {
 if(strpos(route_name(), 'index') !== false) throw new \TCMS\TException(lang('unauthorized.view'), 401);
 else if(strpos(route_name(), 'create') !== false) throw new \TCMS\TException(lang('unauthorized.create'), 401);
 else if(strpos(route_name(), 'update') !== false) throw new \TCMS\TException(lang('unauthorized.update'), 401);
 else if(strpos(route_name(), 'delete') !== false) throw new \TCMS\TException(lang('unauthorized.delete'), 401);
 else throw new \TCMS\TException(lang('unauthorized.unauthorized'), 401);
 }
 }
