Exemple #1
0
 public function submit($problem_id)
 {
     try {
         $problem = new Problem($problem_id);
         $language = fRequest::get('language', 'integer');
         if (!array_key_exists($language, static::$languages)) {
             throw new fValidationException('Invalid language.');
         }
         fSession::set('last_language', $language);
         $code = trim(fRequest::get('code', 'string'));
         if (strlen($code) == 0) {
             throw new fValidationException('Code cannot be empty.');
         }
         if ($problem->isSecretNow()) {
             if (!User::can('view-any-problem')) {
                 throw new fAuthorizationException('Problem is secret now. You are not allowed to submit this problem.');
             }
         }
         $record = new Record();
         $record->setOwner(fAuthorization::getUserToken());
         $record->setProblemId($problem->getId());
         $record->setSubmitCode($code);
         $record->setCodeLanguage($language);
         $record->setSubmitDatetime(Util::currentTime());
         $record->setJudgeStatus(JudgeStatus::PENDING);
         $record->setJudgeMessage('Judging... PROB=' . $problem->getId() . ' LANG=' . static::$languages[$language]);
         $record->setVerdict(Verdict::UNKNOWN);
         $record->store();
         Util::redirect('/status');
     } catch (fException $e) {
         fMessaging::create('error', $e->getMessage());
         fMessaging::create('code', '/submit', fRequest::get('code', 'string'));
         Util::redirect("/submit?problem={$problem_id}");
     }
 }
 public function rejudge($id)
 {
     try {
         if (!User::can('rejudge-record')) {
             throw new fAuthorizationException('You are not allowed to rejudge records.');
         }
         $old_record = new Record($id);
         $new_record = new Record();
         $new_record->setOwner($old_record->getOwner());
         $new_record->setProblemId($old_record->getProblemId());
         $new_record->setSubmitCode($old_record->getSubmitCode());
         $new_record->setCodeLanguage($old_record->getCodeLanguage());
         $new_record->setSubmitDatetime($old_record->getSubmitDatetime());
         $new_record->setJudgeStatus(JudgeStatus::PENDING);
         $new_record->setJudgeMessage('Rejudging... PROB=' . $old_record->getProblemId() . ' LANG=' . $old_record->getLanguageName());
         $new_record->setVerdict(Verdict::UNKNOWN);
         $new_record->store();
         fMessaging::create('success', "Record {$id} rejudged.");
     } catch (fException $e) {
         fMessaging::create('error', $e->getMessage());
     }
     fURL::redirect(Util::getReferer());
 }