userCanView(Auth::user(), ['ensure' => true]); if (!UOJProblem::cur()->userCanManage(Auth::user())) { UOJProblem::cur()->userPermissionCodeCheck(Auth::user(), UOJProblem::cur()->getExtraConfig('view_solution_type')) || UOJResponse::page403(); foreach (UOJProblem::cur()->findInContests() as $cp) { if ($cp->contest->progress() == CONTEST_IN_PROGRESS && $cp->contest->userHasRegistered(Auth::user())) { UOJResponse::page403(); } } } if (UOJRequest::post('submit-remove_solution') === 'remove_solution') { crsf_defend(); $blog = UOJBlog::query(UOJRequest::post('blog_id')); if (!$blog || !$blog->userCanView(Auth::user())) { dieWithAlert('博客不存在。'); } if (!UOJProblem::cur()->userCanManage(Auth::user()) && $blog->info['poster'] != Auth::id()) { dieWithAlert('您没有权限移除该题解。'); } if ($blog->info['poster'] != Auth::id()) { sendSystemMsg( $blog->info['poster'], '题解移除通知', "
" . UOJUser::getLink($blog->info['poster']) . " 您好:
" . "您为问题 " . UOJProblem::cur()->getLink(['with' => 'id']) . " 提交的题解 " . $blog->getLink() . " 已被" . (isSuperUser(Auth::user()) ? "管理员" : " " . UOJUser::getLink(Auth::user()) . " ") . "移除。
" ); } DB::delete([ "delete from problems_solutions", "where", [ "problem_id" => UOJProblem::info('id'), "blog_id" => $blog->info['id'], ], ]); dieWithAlert('移除成功!'); } if (UOJProblem::cur()->userCanManage(Auth::user()) || UOJProblem::cur()->userPermissionCodeCheck(Auth::user(), UOJProblem::cur()->getExtraConfig('submit_solution_type'))) { $add_new_solution_form = new UOJForm('add_new_solution'); $add_new_solution_form->addInput( 'blog_id_2', [ 'placeholder' => '博客 ID', 'validator_php' => function ($blog_id, &$vdata) { $blog = UOJBlog::query($blog_id); if (!$blog) { return '博客不存在'; } if (!$blog->userCanManage(Auth::user())) { if ($blog->info['poster'] != Auth::id()) { if ($blog->info['is_hidden']) { return '博客不存在'; } return '只能提交本人撰写的博客'; } } if (!UOJProblem::cur()->userCanManage(Auth::user())) { if ($blog->info['is_hidden']) { return '只能提交公开的博客'; } } if ($problem_id = $blog->getSolutionProblemId()) { return "该博客已经是题目 #$problem_id 的题解"; } $vdata['blog'] = $blog; return ''; }, ] ); $add_new_solution_form->config['submit_button']['text'] = '发布'; $add_new_solution_form->config['submit_button']['class'] = 'btn btn-secondary'; $add_new_solution_form->handle = function (&$vdata) { DB::insert([ "insert into problems_solutions", DB::bracketed_fields(["problem_id", "blog_id"]), "values", DB::tuple([UOJProblem::info('id'), $vdata['blog']->info['id']]), ]); }; $add_new_solution_form->runAtServer(); } $pag_config = [ 'page_len' => 5, 'col_names' => ['blog_id', 'zan'], 'table_name' => 'problems_solutions inner join blogs on blogs.id = problems_solutions.blog_id', 'cond' => ["problem_id" => UOJProblem::info('id')], 'post_filter' => function ($row) { $blog = UOJBlog::query($row['blog_id']); // 根据实际使用需要,题目管理员可以通过题解页面看到其他用户提交的题解,并且即使该题解对应的博客是隐藏状态也会照常显示 // 如需仅允许超级管理员查看,请将下一行改为 return $blog->userCanView(Auth::user()); return $blog->userCanView(Auth::user()) || UOJProblem::cur()->userCanManage(Auth::user()); }, ]; $pag_config['tail'] = "order by zan desc, post_time desc, id asc"; $pag = new Paginator($pag_config); ?> getTitle(['with' => 'id']))) ?>