예제 #1
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 ajaxAddProblemAction()
 {
     $setId = Request::getPOST('set-id');
     $remote = Request::getPOST('remote');
     $problemCode = Request::getPOST('problem-code');
     // 默认题库
     Cookie::set('default_remote', $remote);
     $problemInfo = OjProblemInterface::getDetail(array('remote' => $remote, 'problem_code' => $problemCode));
     if (empty($problemInfo)) {
         $this->renderError('题目不存在!');
     }
     if ($problemInfo['hidden']) {
         $this->renderError('无法添加隐藏的题目!');
     }
     $setInfo = OjProblemSetInterface::getById(array('id' => $setId));
     if (empty($setInfo)) {
         $this->renderError('专题不存在!');
     }
     // 属主验证
     if ($this->loginUserInfo['id'] != $setInfo['user_id']) {
         $this->renderError('你没有权限操作!');
     }
     $globalIds = (array) json_decode($setInfo['problem_set'], true);
     if (in_array($problemInfo['id'], $globalIds)) {
         $this->renderError('题目已经在专题中!');
     }
     // 题目上限
     if (count($globalIds) >= ContestVars::SET_PROBLEM_LIMIT) {
         $this->renderError('题目数量达到上限,无法继续添加!');
     }
     // 更新数据
     OjProblemSetInterface::addProblem(array('id' => $setId, 'remote' => $remote, 'problem_code' => $problemCode));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '操作成功');
     $this->renderAjax(0);
 }
 public function ajaxAddProblemAction()
 {
     $contestId = (int) Request::getPOST('contest-id');
     $remote = (int) Request::getPOST('remote');
     $problemCode = Request::getPOST('problem-code');
     if (!array_key_exists($remote, StatusVars::$REMOTE_SCHOOL) || empty($problemCode) || empty($contestId)) {
         $this->renderError('缺少参数!');
     }
     // 默认题库
     Cookie::set('default_remote', $remote);
     $contestInfo = OjContestInterface::getDetail(array('id' => $contestId));
     if (empty($contestInfo)) {
         $this->renderError('竞赛不存在!');
     }
     $problemInfo = OjProblemInterface::getDetail(array('remote' => $remote, 'problem_code' => $problemCode));
     if (empty($problemInfo)) {
         $this->renderError('题目不存在!');
     }
     // 只能添加公开的题目,或者自建私有的题目
     if ($problemInfo['hidden'] && $problemInfo['user_id'] != $this->loginUserInfo['id']) {
         $this->renderError('权限不足,无法添加该题目!');
     }
     $globalIds = $contestInfo['global_ids'];
     if (in_array($problemInfo['id'], $globalIds)) {
         $this->renderError('题目已经添加!');
     }
     // 题目上限
     if (count($globalIds) >= ContestVars::CONTEST_PROBLEM_LIMIT) {
         $this->renderError('题目数量达到上限,无法继续添加!');
     }
     // 更新数据
     OjContestInterface::addProblem(array('id' => $contestId, 'remote' => $remote, 'problem_code' => $problemCode));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '添加成功!');
     $this->renderAjax(0);
 }
예제 #4
0
 public function iframeShowHistoryAction()
 {
     $problemId = Request::getGET('problem-id');
     if (empty($problemId)) {
         $this->renderError();
     }
     // 校验权限
     $problemInfo = OjProblemInterface::getDetail(array('remote' => StatusVars::REMOTE_HQU, 'problem_id' => $problemId));
     if (empty($problemInfo)) {
         $this->renderError('题目不存在!');
     }
     $this->renderIframe(array('problemInfo' => $problemInfo), 'problem/iframe/show_audit_history.php');
 }
예제 #5
0
 public static function rejudge($id, $trans = null)
 {
     if (!empty($trans)) {
         $model = new OjJudgeModel($trans);
     } else {
         $model = new OjJudgeModel();
     }
     // 校验
     $judgeInfo = self::getById($id);
     if (empty($judgeInfo)) {
         throw new InterfaceException('judgeInfo不存在!');
     }
     $problemInfo = OjProblemInterface::getDetail(array('remote' => StatusVars::REMOTE_HQU, 'problem_id' => $judgeInfo['problem_id']));
     // 更新
     $data = array('time_limit' => $problemInfo['time_limit'], 'memory_limit' => $problemInfo['memory_limit'], 'judge_time' => 0, 'result' => StatusVars::REJUDGE, 'time_cost' => 0, 'memory_cost' => 0, 'ce' => '', 're' => '', 'detail' => '');
     $affects = $model->updateById($id, $data);
     return $affects;
 }
 public function ajaxRejudgeAction()
 {
     // 获取参数
     $judgeId = Request::getPOST('judge-id');
     // 只能重判自己的solution
     $judgeInfo = OjJudgeInterface::getById(array('id' => $judgeId));
     if (empty($judgeInfo)) {
         $this->renderError('judgeInfo不存在!');
     }
     if ($judgeInfo['solution_id'] > 0 || $judgeInfo['user_id'] != $this->loginUserInfo['id']) {
         $this->renderError('你没有权限重判!');
     }
     // 获取题目
     $problemInfo = OjProblemInterface::getDetail(array('remote' => StatusVars::REMOTE_HQU, 'problem_id' => $judgeInfo['problem_id']));
     if ($problemInfo['user_id'] != $this->loginUserInfo['id']) {
         $this->renderError('你没有权限重判他人的题目!');
     }
     // rejudge
     OjJudgeInterface::rejudge(array('id' => $judgeId));
     $this->renderAjax(0);
 }
예제 #7
0
 public static function addProblem($id, $remote, $problemCode)
 {
     $contestInfo = self::getDetail($id);
     if (empty($contestInfo)) {
         throw new InterfaceException('竞赛不存在!');
     }
     $problemInfo = OjProblemInterface::getDetail(array('remote' => $remote, 'problem_code' => $problemCode));
     if (empty($problemInfo)) {
         throw new InterfaceException('题目不存在!');
     }
     $globalIds = $contestInfo['global_ids'];
     if (in_array($problemInfo['id'], $globalIds)) {
         return 0;
     }
     if (count($globalIds) >= ContestVars::CONTEST_PROBLEM_LIMIT) {
         throw new InterfaceException('题目数量达到上限!');
     }
     $globalIds[] = (int) $problemInfo['id'];
     $json = json_encode($globalIds);
     $model = new OjContestModel();
     $data = array('problem_json' => $json);
     $affects = $model->updateById($id, $data);
     // 更新排行榜,可能有人提交的题目被恢复
     // TODO
     return $affects;
 }
 public function ajaxUploadAction()
 {
     $problemId = Request::getPOST('problem-id');
     $fileList = Upload::getFileList('file');
     if (empty($fileList) || empty($problemId)) {
         $this->echoJson(1, '参数错误!');
     }
     // 校验权限
     $problemInfo = OjProblemInterface::getDetail(array('remote' => StatusVars::REMOTE_HQU, 'problem_id' => $problemId));
     if (empty($problemInfo)) {
         $this->echoJson(1, '题目不存在!');
     }
     // 获取upload所有文件,并计算大小
     $dataUploadDir = '/home/judge/data/' . $problemId . '/upload/';
     if (false == ($handle = opendir($dataUploadDir))) {
         $this->echoJson(1, '打开upload文件夹失败!');
     }
     $uploadFileSize = 0;
     while (false !== ($filename = readdir($handle))) {
         $file = $dataUploadDir . '/' . $filename;
         if ($filename[0] == '.' || is_dir($file)) {
             continue;
         }
         $uploadFileSize += filesize($file);
     }
     closedir($handle);
     foreach ($fileList as $key => $fileInfo) {
         if (!preg_match('/^[A-Za-z0-9_\\.]{1,14}$/', $fileInfo['name'])) {
             $this->echoJson(1, '文件名必须是字母数字下划线组成,并且不能超过14个字符!');
             return;
         }
         $uploadFileSize += $fileInfo['size'];
     }
     if ($uploadFileSize > 5 * 1024 * 1024) {
         $this->echoJson(1, '上传目录空间限制5M,你已经超出范围啦!');
     }
     // 移动
     foreach ($fileList as $key => $fileInfo) {
         $path = '/home/judge/data/' . $problemId . '/upload/' . $fileInfo['name'];
         move_uploaded_file($fileInfo['tmp_name'], $path);
     }
     // 重新获取upload文件夹
     if (false == ($handle = opendir($dataUploadDir))) {
         $this->echoJson(1, '打开upload文件夹失败!');
     }
     $uploadFileList = array();
     while (false !== ($filename = readdir($handle))) {
         $file = $dataUploadDir . '/' . $filename;
         if ($filename[0] == '.' || is_dir($file)) {
             continue;
         }
         $fileInfo = array();
         $fileInfo['filename'] = $filename;
         //文件名,包含扩展名
         $fileInfo['datetime'] = date('Y-m-d H:i:s', filemtime($file));
         //文件最后修改时间
         $fileInfo['filesize'] = filesize($file);
         $uploadFileList[] = $fileInfo;
     }
     closedir($handle);
     // 排序
     function cmpFunc($a, $b)
     {
         return strcmp($a['filename'], $b['filename']);
     }
     usort($uploadFileList, 'cmpFunc');
     // 计算大小,并格式化
     $uploadFileSize = 0;
     foreach ($uploadFileList as $key => $fileInfo) {
         $uploadFileList[$key]['format'] = sprintf('%-14s %10d %s', $fileInfo['filename'], $fileInfo['filesize'], $fileInfo['datetime']);
         $uploadFileList[$key]['format'] = str_replace(' ', ' ', $uploadFileList[$key]['format']);
         $uploadFileSize += $uploadFileList[$key]['filesize'];
     }
     // 记录操作
     $dateTime = date('Y-m-d H:i:s', time());
     $history = "<p>{$dateTime} 管理员{$this->loginUserInfo['username']}批量上传了文件</p>";
     OjProblemInterface::auditHistory(array('problem_id' => $problemId, 'append_history' => $history));
     $this->echoJson(0, 'success', array('uploadFileList' => $uploadFileList, 'uploadFileSize' => $uploadFileSize));
 }
 public static function addProblem($id, $remote, $problemCode)
 {
     $setInfo = self::getById($id);
     if (empty($setInfo)) {
         throw new InterfaceException('专题不存在!');
     }
     $problemInfo = OjProblemInterface::getDetail(array('remote' => $remote, 'problem_code' => $problemCode));
     if (empty($problemInfo)) {
         throw new InterfaceException('题目不存在!');
     }
     $globalIds = (array) json_decode($setInfo['problem_set'], true);
     if (in_array($problemInfo['id'], $globalIds)) {
         return 0;
     }
     if (count($globalIds) >= ContestVars::SET_PROBLEM_LIMIT) {
         throw new InterfaceException('题目数量达到上限!');
     }
     $globalIds[] = (int) $problemInfo['id'];
     $json = json_encode($globalIds);
     $model = new OjProblemSetModel();
     $data = array('problem_set' => $json);
     $affects = $model->updateById($id, $data);
     return $affects;
 }