public function ajaxSubmitAction() { // 获取参数 $language = (int) Request::getPOST('language'); $code = Request::getPOST('code', '', true); $problemHash = Request::getPOST('problem-hash'); $userId = $this->loginUserInfo['id']; $globalId = array_search($problemHash, $this->contestInfo['problem_hash']); if (empty($globalId)) { $this->renderError('竞赛中无此题!'); } // 校验 if (strlen($code) < 50 || strlen($code) > 65535) { $this->renderError('代码长度超出范围,请限制为50-65535(BYTE)!'); } $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); if (empty($problemInfo) || $problemInfo['hidden']) { $this->renderError('题目不存在!'); } if (!array_key_exists($language, StatusVars::$LANGUAGE_SUPPORT[$problemInfo['remote']])) { $this->renderError('编译器不支持!'); } if (OjSolutionInterface::submitAlready(array('user_id' => $userId))) { $this->renderError('提交频繁!'); } // 非法字符判断 if ($problemInfo['remote'] == StatusVars::REMOTE_HDU) { if (false === iconv('UTF-8', 'GBK', $code)) { $this->renderError('代码中存在非法字符!'); } } OjSolutionInterface::save(array('global_id' => $globalId, 'user_id' => $userId, 'language' => $language, 'source' => $code, 'contest_id' => $this->contestInfo['id'])); $this->renderAjax(0); }
public function defaultAction() { // 获取参数 $globalId = (int) Request::getGET('global-id'); $problemId = Request::getGET('problem-id'); $problemInfo = array(); if (!empty($globalId)) { $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); } else { if (!empty($problemId)) { $problemInfo = OjProblemInterface::getDetail(array('remote' => StatusVars::REMOTE_HQU, 'problem_id' => $problemId)); } } if (empty($problemInfo)) { $this->renderError('题目不存在!'); } // 权限校验 if ($problemInfo['user_id'] != $this->loginUserInfo['id']) { $this->renderError('你没有权限查看!'); } if ($problemInfo['remote'] != StatusVars::REMOTE_HQU) { $this->renderError('你没有权限查看!'); } $this->renderFramework(array('problemInfo' => $problemInfo), 'setup/problem/detail.php'); }
public function ajaxSubmitAction() { // 获取参数 $globalId = Request::getPOST('global-id'); $language = Request::getPOST('language'); $code = Request::getPOST('code', '', true); // 校验 if (strlen($code) < 50 || strlen($code) > 65535) { $this->renderError('代码长度超出范围,请限制为50-65535(BYTE)!'); } $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); if (empty($problemInfo)) { $this->renderError('题目不存在!'); } if (!array_key_exists($language, StatusVars::$LANGUAGE_SUPPORT[$problemInfo['remote']])) { $this->renderError('编译器不支持!'); } // 非法字符判断 if ($problemInfo['remote'] == StatusVars::REMOTE_HDU) { if (false === iconv('UTF-8', 'GBK', $code)) { $this->renderError('代码中存在非法字符!'); } } OjJudgeInterface::save(array('problem_id' => $problemInfo['problem_id'], 'language' => $language, 'source' => $code, 'user_id' => $this->loginUserInfo['id'])); // judge $this->renderAjax(0); }
public function defaultAction() { $setId = (int) Request::getGET('set-id'); if (empty($setId)) { $this->renderError('参数错误'); } $setInfo = OjProblemSetInterface::getById(array('id' => $setId)); if (empty($setInfo)) { $this->renderError(); } $globalIds = (array) json_decode($setInfo['problem_set'], true); $problemHash = OjProblemInterface::getById(array('id' => $globalIds)); $this->renderFramework(array('setInfo' => $setInfo, 'problemHash' => $problemHash), 'setup/set/set_problem.php'); }
public function ajaxRemoveProblemAction() { $contestId = (int) Request::getPOST('contest-id'); $globalId = (int) Request::getPOST('global-id'); $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); if (empty($problemInfo)) { $this->renderError('题目不存在!'); } $contestInfo = OjContestInterface::getById(array('id' => $contestId)); if (empty($contestInfo)) { $this->renderError('竞赛不存在!'); } // 更新数据 OjContestInterface::removeProblem(array('id' => $contestId, 'global_id' => $globalId)); $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '移除成功!'); $this->renderAjax(0); }
public function defaultAction() { // 获取参数 $id = Request::getGET('global-id'); // 校验题目 $problemInfo = OjProblemInterface::getById(array('id' => $id)); if (empty($problemInfo) || $problemInfo['hidden']) { $this->renderError('题目不存在!'); } $remote = $problemInfo['remote']; $problemId = $problemInfo['problem_id']; $problemCode = $problemInfo['problem_code']; if ($remote) { $srcUrl = OjCommonHelper::getSrcUrl($remote, $problemId, $problemCode); $this->renderFramework(array('srcUrl' => $srcUrl, 'problemInfo' => $problemInfo), 'problem/detail_remote.php'); } else { $this->renderFramework(array('problemInfo' => $problemInfo), 'problem/detail.php'); } }
public function ajaxSubmitAction() { // 获取参数 $globalId = (int) Request::getPOST('global-id'); $title = trim(Request::getPOST('title')); $source = trim(Request::getPOST('source')); $timeLimit = max(1, Request::getPOST('time-limit')); $memoryLimit = max(32, Request::getPOST('memory-limit')); $description = Request::getPOST('description', '', true); $input = Request::getPOST('input', '', true); $output = Request::getPOST('output', '', true); $sampleInput = Request::getPOST('sample-input', '', true); $sampleOutput = Request::getPOST('sample-output', '', true); $hint = Request::getPOST('hint', '', true); if (!in_array($timeLimit, StatusVars::$TIME_LIMIT) || !in_array($memoryLimit, StatusVars::$MEMORY_LIMIT)) { $this->renderError('参数错误!'); } // 校验 if (mb_strlen($title, 'utf8') > 50) { $this->renderError('标题限制50个字以内!'); } if (mb_strlen($source, 'utf8') > 50) { $this->renderError('来源限制50个字以内!'); } // 校验problem $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); if (empty($problemInfo) || !$problemInfo['hidden'] || $problemInfo['user_id'] != $this->loginUserInfo['id']) { $this->renderError('你没有操作权限!'); } // 更新 $data = array('id' => $globalId, 'title' => $title, 'source' => str_replace(',', ',', $source), 'time_limit' => $timeLimit * 1000, 'memory_limit' => $memoryLimit * 1024, 'description' => $description, 'input' => $input, 'output' => $output, 'sample_input' => $sampleInput, 'sample_output' => $sampleOutput, 'hint' => $hint); OjProblemInterface::save($data); // 记录编辑历史 if ($problemInfo['remote'] == StatusVars::REMOTE_HQU) { $dateTime = date('Y-m-d H:i:s', time()); $history = "<p>{$dateTime} 用户{$this->loginUserInfo['username']}编辑了题目</p>"; OjProblemInterface::auditHistory(array('problem_id' => $problemInfo['problem_id'], 'append_history' => $history)); } $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '编辑成功!'); $this->renderAjax(0); }
public function defaultAction() { // 获取参数 $problemHash = Request::getGET('problem-hash'); $globalId = array_search($problemHash, $this->contestInfo['problem_hash']); if (empty($globalId)) { $this->renderError('竞赛中无此题!'); } // 获取题目 $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); if (empty($problemInfo)) { $this->renderError('题目不存在!'); } $remote = $problemInfo['remote']; $problemId = $problemInfo['problem_id']; $problemCode = $problemInfo['problem_code']; if ($remote) { $srcUrl = OjCommonHelper::getSrcUrl($remote, $problemId, $problemCode); $this->renderFramework(array('srcUrl' => $srcUrl, 'problemInfo' => $problemInfo), 'problem/detail_remote.php'); } else { $this->renderFramework(array('problemInfo' => $problemInfo), 'problem/detail.php'); } }
public function defaultAction() { $setId = (int) Request::getGET('set-id'); if (empty($setId)) { $this->renderError(); } $setInfo = OjProblemSetInterface::getById(array('id' => $setId)); if (empty($setInfo)) { $this->renderError(); } if (!$this->isOjAdmin && $setInfo['hidden'] && $this->loginUserInfo['id'] != $setInfo['user_id']) { Cookie::delete('current_set'); $this->renderError('您没有权限查看!'); } // 设置当前的set Cookie::set('current_set', $setId); $problemJson = $setInfo['problem_set']; $globalIds = (array) json_decode($problemJson, true); // 按照$globalIds顺序 $problemList = OjProblemInterface::getById(array('id' => $globalIds)); // 获取用户解决的题目 $userSolution = array(); if ($this->loginUserInfo) { $where = array(array('problem_global_id', 'IN', $globalIds), array('user_id', '=', $this->loginUserInfo['id'])); $solutionList = OjSolutionInterface::getList(array('where' => $where)); foreach ($solutionList as $solutionInfo) { $globalId = $solutionInfo['problem_global_id']; if (!array_key_exists($globalId, $userSolution) || $solutionInfo['result'] == StatusVars::ACCEPTED) { $userSolution[$globalId] = $solutionInfo; } } } // userInfo $userInfo = UserCommonInterface::getById(array('id' => $setInfo['user_id'])); $this->renderFramework(array('setInfo' => $setInfo, 'problemList' => $problemList, 'userSolution' => $userSolution, 'userInfo' => $userInfo), 'set/set_problem.php'); }
public static function getProblemHash($id) { $contestInfo = self::getDetail($id); if (empty($contestInfo)) { throw new InterfaceException('比赛不存在!'); } // 获取problemList $globalIds = $contestInfo['global_ids']; $problemHash = OjProblemInterface::getById(array('id' => $globalIds)); // 重置solved, submit foreach ($problemHash as &$problemInfo) { $problemInfo['contest_solved'] = $problemInfo['contest_submit'] = 0; } // 获取solutionList $field = 'id,user_id,problem_global_id,result'; $where = array(array('contest_id', '=', $id), array('problem_global_id', 'IN', $globalIds)); $order = array('id' => 'ASC'); $solutionList = OjSolutionInterface::getList(array('field' => $field, 'where' => $where, 'order' => $order, 'include_contest' => true)); // 计算solved, submit $userAccept = array(); // 标记 foreach ($solutionList as $solutionInfo) { $globalId = $solutionInfo['problem_global_id']; $userId = $solutionInfo['user_id']; $result = $solutionInfo['result']; $problemHash[$globalId]['contest_submit']++; if (!isset($userAccept[$userId])) { $userAccept[$userId] = array(); } if (!isset($userAccept[$userId][$globalId]) && $result == StatusVars::ACCEPTED) { $userAccept[$userId][$globalId] = 1; $problemHash[$globalId]['contest_solved']++; } } return $problemHash; }
public function ajaxSetUserAction() { // 获取参数 $globalId = Request::getPOST('global-id'); $username = trim(Request::getPOST('username', '')); // 校验用户 $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username)); if (empty($userInfo)) { $this->renderError('用户不存在!'); } // 校验problem $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); if (empty($problemInfo)) { $this->renderError('题目不存在!'); } OjProblemInterface::setUser(array('id' => $globalId, 'username' => $username)); $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '设置成功!'); $this->renderAjax(0); }
private static function updateResult($id, $result, $trans = null) { $solutionInfo = self::getById($id); if (empty($solutionInfo)) { throw new InterfaceException('solution不存在!'); } $innerTrans = $trans; if (null == $trans) { $innerTrans = new Trans(DbConfig::$SERVER_TRANS); $innerTrans->begin(); } $solutionModel = new OjSolutionModel($innerTrans); $remote = $solutionInfo['remote']; $globalId = $solutionInfo['problem_global_id']; $userId = $solutionInfo['user_id']; $contestId = $solutionInfo['contest_id']; // 如果状态从 非AC -> AC,那么修改user表和problem表,竞赛状态下不改变 if (0 == $contestId && $result == StatusVars::ACCEPTED && $solutionInfo['result'] != StatusVars::ACCEPTED) { // 判断是否没有AC过 $where = array(array('problem_global_id', '=', $globalId), array('user_id', '=', $userId), array('result', '=', StatusVars::ACCEPTED), array('contest_id', '=', 0)); $count = self::getCount($where); if (0 == $count) { $userInfo = UserCommonInterface::getById(array('id' => $userId)); $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); $remoteStr = strtolower(StatusVars::$REMOTE_SCHOOL[$remote]); UserCommonInterface::save(array('trans' => $innerTrans, 'id' => $userId, 'solved_all' => $userInfo['solved_all'] + 1, "solved_{$remoteStr}" => $userInfo["solved_{$remoteStr}"] + 1)); OjProblemInterface::save(array('trans' => $innerTrans, 'id' => $globalId, 'solved' => $problemInfo['solved'] + 1)); } } // 如果状态从 AC -> 非AC,那么修改user表和problem表,竞赛状态下不改变 if (0 == $contestId && $result != StatusVars::ACCEPTED && $solutionInfo['result'] == StatusVars::ACCEPTED) { // 判断是否只AC过一次 $where = array(array('problem_global_id', '=', $globalId), array('user_id', '=', $userId), array('result', '=', StatusVars::ACCEPTED), array('contest_id', '=', 0)); $count = self::getCount($where); if (1 == $count) { $userInfo = UserCommonInterface::getById(array('id' => $userId)); $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); $remoteStr = strtolower(StatusVars::$REMOTE_SCHOOL[$remote]); UserCommonInterface::save(array('trans' => $innerTrans, 'id' => $userId, 'solved_all' => $userInfo['solved_all'] - 1, "solved_{$remoteStr}" => $userInfo["solved_{$remoteStr}"] - 1)); OjProblemInterface::save(array('trans' => $innerTrans, 'id' => $globalId, 'solved' => $problemInfo['solved'] - 1)); } } // 更新solution $affects = $solutionModel->updateById($id, array('result' => $result)); if (null == $trans && null != $innerTrans) { // 没有外部事务,并且存在内部事务 $innerTrans->commit(); } return $affects; }