public function __construct()
 {
     parent::__construct();
     $this->checkLogin();
     if (!empty($this->loginUserInfo) && RootCommonInterface::allowed(array('user_id' => $this->loginUserInfo['id'], 'path' => '/hqoj/admin'))) {
         $this->isOjAdmin = true;
     }
     $this->view->assign(array('isOjAdmin' => $this->isOjAdmin));
 }
 public function __construct()
 {
     parent::__construct();
     // 校验登陆
     if (empty($this->loginUserInfo)) {
         $this->login();
     }
     // 获取$contestId
     $contestId = (int) Request::getREQUEST('contest-id', 0);
     if (empty($contestId)) {
         $this->render404('比赛ID不存在!');
     }
     // 获取$contestInfo
     $this->contestInfo = OjContestInterface::getDetail(array('id' => $contestId));
     if (empty($this->contestInfo) || $this->contestInfo['hidden']) {
         $this->render404('比赛不存在!');
     }
     if ($this->contestInfo['type'] == ContestVars::TYPE_APPLY) {
         $this->applyInfo = OjContestApplyInterface::getDetail(array('contest_id' => $contestId, 'user_id' => $this->loginUserInfo['id']));
     }
     // 管理员
     $isOjAdmin = RootCommonInterface::allowed(array('user_id' => $this->loginUserInfo['id'], 'path' => '/hqoj/admin'));
     if ($isOjAdmin || $this->contestInfo['user_id'] == $this->loginUserInfo['id']) {
         $this->isContestAdmin = true;
     }
     // 如果未注册,未输入密码,比赛未开始,那么跳转到比赛首页
     if (Router::$CONTROLLER != 'index') {
         if ($this->contestInfo['type'] == ContestVars::TYPE_APPLY) {
             if (empty($this->applyInfo) || $this->applyInfo['status'] != ContestVars::APPLY_ACCEPTED) {
                 $this->setNotice('error', '您未通过报名!');
                 $url = '/?contest-id=' . $contestId;
                 Url::redirect($url);
             }
         } else {
             if ($this->contestInfo['type'] == ContestVars::TYPE_PASSWORD) {
                 if ($this->password != $this->contestInfo['password']) {
                     $this->setNotice('error', '请输入密码!');
                     $url = '/?contest-id=' . $contestId;
                     Url::redirect($url);
                 }
             }
         }
         if (time() < $this->contestInfo['begin_time']) {
             $this->setNotice('error', '比赛未开始!');
             $url = '/?contest-id=' . $contestId;
             Url::redirect($url);
         }
     }
     $this->view->assign(array('contestInfo' => $this->contestInfo, 'applyInfo' => $this->applyInfo, 'password' => $this->password, 'isContestAdmin' => $this->isContestAdmin));
 }
 private function checkMenu()
 {
     $menuFile = __DIR__ . '/menu/' . $this->backendProjectInfo['menu'];
     if (!is_file($menuFile)) {
         $this->backendMenuList = array();
         $this->backendMenuInfo = array();
         // assign
         $this->view->assign(array('backendMenuList' => $this->backendMenuList, 'backendMenuInfo' => $this->backendMenuInfo));
         return;
     }
     $this->backendMenuList = (include $menuFile);
     // 计算当前菜单
     $currentPath = Url::getPath();
     foreach ($this->backendMenuList as $menuInfo) {
         foreach ($menuInfo['menu'] as $menuItem) {
             if ($currentPath == $menuItem['url']) {
                 $this->backendMenuInfo = $menuItem;
                 $this->backendMenuInfo['parent_title'] = $menuInfo['title'];
                 $this->backendMenuInfo['parent_code'] = Arr::get('code', $menuInfo, '');
                 break;
             }
         }
         if (!empty($this->backendMenuInfo)) {
             break;
         }
     }
     // 当前一级菜单和二级菜单权限判断
     if (!empty($this->backendMenuInfo)) {
         // 一级菜单权限
         $code = Arr::get('parent_code', $this->backendMenuInfo, '');
         if (!empty($code)) {
             $allowed = RootCommonInterface::allowed(array('user_id' => $this->loginUserInfo['id'], 'path' => $code));
             if (!$allowed) {
                 $this->render404('你没有权限访问!');
             }
         }
         // 二级菜单权限
         $code = Arr::get('code', $this->backendMenuInfo, '');
         if (!empty($code)) {
             $allowed = RootCommonInterface::allowed(array('user_id' => $this->loginUserInfo['id'], 'path' => $code));
             if (!$allowed) {
                 $this->render404('你没有权限访问!');
             }
         }
     }
     // 过滤没有权限的菜单
     foreach ($this->backendMenuList as $i => $menuInfo) {
         $code = Arr::get('code', $menuInfo, '');
         if (!empty($code)) {
             $allowed = RootCommonInterface::allowed(array('user_id' => $this->loginUserInfo['id'], 'path' => $code));
             if (!$allowed) {
                 unset($this->backendMenuList[$i]);
                 continue;
             }
         }
         foreach ($menuInfo['menu'] as $j => $menuItem) {
             $code = Arr::get('code', $menuItem, '');
             if (!empty($code)) {
                 $allowed = RootCommonInterface::allowed(array('user_id' => $this->loginUserInfo['id'], 'path' => $code));
                 if (!$allowed) {
                     unset($this->backendMenuList[$i]['menu'][$j]);
                     if (empty($this->backendMenuList[$i]['menu'])) {
                         unset($this->backendMenuList[$i]);
                     }
                     continue;
                 }
             }
         }
     }
     // assign
     $this->view->assign(array('backendMenuList' => $this->backendMenuList, 'backendMenuInfo' => $this->backendMenuInfo));
 }