public function ajaxApplyAction()
 {
     if (empty($this->loginUserInfo)) {
         $this->renderError('请登录!');
     }
     $contestId = (int) Request::getPOST('contest-id');
     $realName = trim(Request::getPOST('real-name'));
     $xuehao = trim(Request::getPOST('xuehao'));
     $xueyuan = (int) Request::getPOST('xueyuan');
     $sex = (int) Request::getPOST('sex');
     // 校验
     if (empty($realName) || empty($xuehao) || empty($xueyuan) || empty($sex) || !array_key_exists($xueyuan, ContestVars::$XUEYUAN) || !in_array($sex, array(1, 2)) || mb_strlen($realName, 'utf8') < 2 || mb_strlen($realName, 'utf8') > 4) {
         $this->renderError('参数错误!');
     }
     $contestInfo = OjContestInterface::getById(array('id' => $contestId));
     if (empty($contestInfo)) {
         $this->renderError('比赛不存在!');
     }
     if ($contestInfo['type'] != ContestVars::TYPE_APPLY) {
         $this->renderError('比赛不需要报名!');
     }
     if ($contestInfo['end_time'] < time()) {
         $this->renderError('比赛已经结束!');
     }
     $applyInfo = OjContestApplyInterface::getDetail(array('contest_id' => $contestId, 'user_id' => $this->loginUserInfo['id']));
     if (!empty($applyInfo) && $applyInfo['status'] == ContestVars::APPLY_ACCEPTED) {
         $this->renderError('报名已通过,无法修改!');
     }
     $data = array('contest_id' => $contestId, 'user_id' => $this->loginUserInfo['id'], 'real_name' => $realName, 'xuehao' => $xuehao, 'xueyuan' => $xueyuan, 'sex' => $sex);
     OjContestApplyInterface::save($data);
     $this->renderAjax(0);
 }
 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));
 }