| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- <?php
- requirePHPLib('form');
- requirePHPLib('judger');
- requirePHPLib('data');
-
- if ($_POST['migrate_problem_submit'] == 'submit') {
- $group = queryUser(DB::escape($_POST['target_group']));
- $start = $_POST['start_pid'];
- $end = $_POST['end_pid'];
- if (!validateUInt($start) || !validateUInt($end)) {
- $errmsg = 'Error: 不合法起始终止题号';
- becomeMsgPage('<div>' . $errmsg . '</div><a href="/problems">返回</a>');
- }
- if (!group) {
- $errmsg = "Error: 未找到组 {$_POST['target_group']}";
- becomeMsgPage('<div>' . $errmsg . '</div><a href="/problems">返回</a>');
- }
- if (!hasGroupCtrlPermission($myUser, $group)) {
- $errmsg = "Error: 你对组 {$group['username']} 没有控制权";
- becomeMsgPage('<div>' . $errmsg . '</div><a href="/problems">返回</a>');
- }
- for ($i = $start; $i <= $end; $i++) {
- if (!hasProblemCtrlPermission($myUser, queryProblemBrief($i))) {
- $errmsg = "Error: 你对题目 $i 没有控制权";
- becomeMsgPage('<div>' . $errmsg . '</div><a href="/problems">返回</a>');
- }
- }
- for ($i = $start; $i <= $end; $i++) {
- attachProblemToGroup(queryProblemBrief($i), $group);
- DB::update("update problems set ctrl = '{$group['username']}' where id = $i");
- }
- }
- if ($_POST['copy_problem_submit'] == 'submit') {
- $problems = explode(',', $_POST['copy_problem_list']);
- if (count($problems) > 10) {
- $errmsg = "Error: 你不能一次复制超过 10 个题目";
- becomeMsgPage('<div>' . $errmsg . '</div><a href="/problems">返回</a>');
- }
- foreach ($problems as $pid)
- if (!hasProblemCtrlPermission($myUser, queryProblemBrief($pid))) {
- $errmsg = "Error: 你对题目 $i 没有控制权";
- becomeMsgPage('<div>' . $errmsg . '</div><a href="/problems">返回</a>');
- }
- foreach ($problems as $pid) {
- $p = queryProblemBrief($pid);
- $title = DB::escape($p['title']);
- $q = queryProblemContent($pid);
- $stat = DB::escape($q['statement']);
- $statmd = DB::escape($q['statement_md']);
- DB::query("insert into problems (title, is_hidden, submission_requirement, ctrl) values ('$title', {$p['is_hidden']}, '{$p['submission_requirement']}', '{$p['ctrl']}')");
- $id = DB::insert_id();
- DB::query("insert into problems_contents (id, statement, statement_md) values ($id, '$stat', '$statmd')");
- dataCopyProblemData($pid, $id);
- attachProblemToGroup(queryProblemBrief($id), queryUser($p['ctrl']));
- }
- }
- function echoProblem($problem) {
- global $myUser;
- if (isProblemVisibleToUser($problem, $myUser)) {
- echo '<tr class="text-center">';
- if ($problem['submission_id']) {
- echo '<td class="table-success">';
- } else {
- echo '<td>';
- }
- echo '#', $problem['id'], '</td>';
- echo '<td class="text-left">';
- if ($problem['is_hidden']) {
- echo ' <span class="text-danger">[隐藏]</span> ';
- }
- echo '<a href="/problem/', $problem['id'], '">', $problem['title'], '</a>';
- if (isset($_COOKIE['show_tags_mode'])) {
- foreach (queryProblemTags($problem['id']) as $tag) {
- echo '<a class="uoj-problem-tag">', '<span class="badge badge-pill badge-secondary">', HTML::escape($tag), '</span>', '</a>';
- }
- }
- echo '</td>';
- if (isset($_COOKIE['show_submit_mode'])) {
- $perc = $problem['submit_num'] > 0 ? round(100 * $problem['ac_num'] / $problem['submit_num']) : 0;
- echo <<<EOD
- <td><a href="/submissions?problem_id={$problem['id']}&min_score=100&max_score=100">×{$problem['ac_num']}</a></td>
- <td><a href="/submissions?problem_id={$problem['id']}">×{$problem['submit_num']}</a></td>
- <td>
- <div class="progress bot-buffer-no">
- <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="$perc" aria-valuemin="0" aria-valuemax="100" style="width: $perc%; min-width: 20px;">{$perc}%</div>
- </div>
- </td>
- EOD;
- }
- echo '<td class="text-middle">', getClickZanBlock('P', $problem['id'], $problem['zan']), '</td>';
- echo '</tr>';
- }
- }
-
- $cond = array();
-
- $search_tag = null;
-
- $cur_tab = isset($_GET['tab']) ? $_GET['tab'] : 'all';
- if ($cur_tab == 'template') {
- $search_tag = "模板题";
- }
- if (isset($_GET['tag'])) {
- $search_tag = $_GET['tag'];
- }
- if ($search_tag) {
- $cond[] = "'".DB::escape($search_tag)."' in (select tag from problems_tags where problems_tags.problem_id = problems.id)";
- }
- if (isset($_GET["search"])) {
- $cond[]="title like '%".DB::escape($_GET["search"])."%' or id like '%".DB::escape($_GET["search"])."%'";
- }
- if (isset($_GET['group'])) {
- $groupname = $_GET['group'];
- $cur_tab = $groupname;
- $group = queryUser($groupname);
- if ($group == null) become404Page();
- if (!in_array($groupname, queryUserExtgroups($myUser))) become403Page();
- $cond[] = "find_in_set(id, (select privs from user_info where username = '$groupname'))";
- }
- else {
- $group = queryUser('group_default');
- $groupname = 'group_default';
- }
- if ($cond) {
- $cond = join($cond, ' and ');
- } else {
- $cond = '1';
- }
- $print_new_problem_form = false;
- $print_mig_problem_form = false;
- $print_copy_problem_form = false;
- $print_datum_button = false;
- /*
- if (($cur_tab == 'all' || $cur_tab == 'template') and isSuperUser($myUser)) {
- $print_new_problem_form = true;
- $new_problem_form = new UOJForm('new_problem');
- $new_problem_form->handle = function() {
- global $group;
- DB::query("insert into problems (title, is_hidden, submission_requirement, ctrl) values ('New Problem', 1, '{}', 'group_default')");
- $id = DB::insert_id();
- DB::query("insert into problems_contents (id, statement, statement_md) values ($id, '', '')");
- dataNewProblem($id);
- attachProblemToGroup(queryProblemBrief($id), $group);
- };
- $new_problem_form->submit_button_config['align'] = 'right';
- $new_problem_form->submit_button_config['class_str'] = 'btn btn-primary';
- $new_problem_form->submit_button_config['text'] = UOJLocale::get('problems::add new');
- $new_problem_form->submit_button_config['smart_confirm'] = '';
-
- $new_problem_form->runAtServer();
- }
- */
- if (isSuperUser($myUser))
- $print_datum_button = true;
- if ($group != null and hasGroupCtrlPermission($myUser, $group)) {
- $print_new_problem_form = true;
- $print_copy_problem_form = true;
- $new_problem_form = new UOJForm('new_problem');
- $new_problem_form->handle = function() {
- global $groupname;
- global $group;
- DB::query("insert into problems (title, is_hidden, submission_requirement, ctrl) values ('New Problem', 1, '{}', '" . $groupname . "')");
- $id = DB::insert_id();
- DB::query("insert into problems_contents (id, statement, statement_md) values ($id, '', '')");
- dataNewProblem($id);
- attachProblemToGroup(queryProblemBrief($id), $group);
- };
- $new_problem_form->submit_button_config['align'] = 'right';
- $new_problem_form->submit_button_config['class_str'] = 'btn btn-primary';
- $new_problem_form->submit_button_config['text'] = UOJLocale::get('problems::add new');
- $new_problem_form->submit_button_config['smart_confirm'] = '';
- $new_problem_form->runAtServer();
- $print_mig_problem_form = true;
- }
-
- $header = '<tr>';
- $header .= '<th class="text-center" style="width:5em;">ID</th>';
- $header .= '<th>'.UOJLocale::get('problems::problem').'</th>';
- if (isset($_COOKIE['show_submit_mode'])) {
- $header .= '<th class="text-center" style="width:5em;">'.UOJLocale::get('problems::ac').'</th>';
- $header .= '<th class="text-center" style="width:5em;">'.UOJLocale::get('problems::submit').'</th>';
- $header .= '<th class="text-center" style="width:150px;">'.UOJLocale::get('problems::ac rate').'</th>';
- }
- $header .= '<th class="text-center" style="width:220px;">'.UOJLocale::get('appraisal').'</th>';
- $header .= '</tr>';
-
- $tabs_info = array(
- 'all' => array(
- 'name' => UOJLocale::get('problems::all problems'),
- 'url' => "/problems"
- ),
- 'template' => array(
- 'name' => UOJLocale::get('problems::template problems'),
- 'url' => "/problems/template"
- )
- );
- foreach (queryUserExtgroups($myUser) as $i => $grp)
- if ($grp != '')
- $tabs_info[$grp] = array(
- 'name' => '团队 ' . $grp .' 题目',
- 'url' => "/problems/group/" . $grp
- );
-
- $pag_config = array('page_len' => 100);
- $pag_config['col_names'] = array('*');
- $pag_config['table_name'] = "problems left join best_ac_submissions on best_ac_submissions.submitter = '{$myUser['username']}' and problems.id = best_ac_submissions.problem_id";
- $pag_config['cond'] = $cond;
- $pag_config['tail'] = "order by id asc";
- $pag = new Paginator($pag_config);
- $div_classes = array('table-responsive', 'shadow');
- $table_classes = array('table', 'table-bordered', 'table-hover', 'table-striped');
- ?>
- <?php echoUOJPageHeader(UOJLocale::get('problems')) ?>
- <div class="row my-4">
- <div class="col-sm-9">
- <?= HTML::tablist($tabs_info, $cur_tab, 'nav-pills') ?>
- </div>
- <div class="col-sm-3 order-sm-9 checkbox text-right">
- <label class="checkbox-inline" for="input-show_tags_mode"><input type="checkbox" id="input-show_tags_mode" <?= isset($_COOKIE['show_tags_mode']) ? 'checked="checked" ': ''?>/> <?= UOJLocale::get('problems::show tags') ?></label>
- <label class="checkbox-inline" for="input-show_submit_mode"><input type="checkbox" id="input-show_submit_mode" <?= isset($_COOKIE['show_submit_mode']) ? 'checked="checked" ': ''?>/> <?= UOJLocale::get('problems::show statistics') ?></label>
- </div>
- </div>
- <div class="top-buffer-sm"></div>
- <script type="text/javascript">
- $('#input-show_tags_mode').click(function() {
- if (this.checked) {
- $.cookie('show_tags_mode', '', {path: '/problems'});
- } else {
- $.removeCookie('show_tags_mode', {path: '/problems'});
- }
- location.reload();
- });
- $('#input-show_submit_mode').click(function() {
- if (this.checked) {
- $.cookie('show_submit_mode', '', {path: '/problems'});
- } else {
- $.removeCookie('show_submit_mode', {path: '/problems'});
- }
- location.reload();
- });
- </script>
- <?php
- echo '<div class="', join($div_classes, ' '), '">';
- echo '<table class="', join($table_classes, ' '), '">';
- echo '<thead>';
- echo $header;
- echo '</thead>';
- echo '<tbody>';
-
- foreach ($pag->get() as $idx => $row) {
- echoProblem($row);
- echo "\n";
- }
- if ($pag->isEmpty()) {
- echo '<tr><td class="text-center" colspan="233">'.UOJLocale::get('none').'</td></tr>';
- }
-
- echo '</tbody>';
- echo '</table>';
- echo '</div>';
-
- if ($print_new_problem_form)
- $new_problem_form->printHTML();
- if ($print_mig_problem_form) {
- echo <<<EOF
- <div class="text-right">
- <button type="button" class="mt-2 btn btn-secondary" data-toggle="modal" data-target="#MigrateProblemModal">迁移题目</button>
- </div>
- <div class="modal fade" id="MigrateProblemModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
- <div class="modal-dialog">
- <div class="modal-content">
- <div class="modal-header">
- <h4 class="modal-title" id="myModalLabel">迁移题目</h4>
- <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
- </div>
- <div class="modal-body">
- <form class="form-horizontal" action="" method="post" role="form">
- <div class="form-group row">
- <input type="hidden" name="migrate_problem_submit" value="submit">
- <label for="target_group" class="col-sm-5 control-label">目标组</label>
- <div class="col-sm-7">
- <input type="text" class="form-control" id="target_group" name="target_group" placeholder="group_default">
- </div>
- <label for="start_pid" class="col-sm-5 control-label">起始题号</label>
- <div class="col-sm-7">
- <input type="text" class="form-control" id="start_pid" name="start_pid" placeholder="您必须对范围内的">
- </div>
- <label for="end_pid" class="col-sm-5 control-label">终止题号</label>
- <div class="col-sm-7">
- <input type="text" class="form-control" id="end_pid" name="end_pid" placeholder="所有题目都有控制权">
- </div>
- </div>
- </div>
- <div class="modal-footer">
- <button type="submit" class="btn btn-success">确定</button>
- </form>
- <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
- </div>
- </div>
- </div>
- </div>
- EOF;
- }
- if ($print_copy_problem_form) {
- echo <<<EOF
- <div class="text-right">
- <button type="button" class="mt-2 btn btn-secondary" data-toggle="modal" data-target="#CopyProblemModal">复制题目</button>
- </div>
- <div class="modal fade" id="CopyProblemModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
- <div class="modal-dialog">
- <div class="modal-content">
- <div class="modal-header">
- <h4 class="modal-title" id="myModalLabel">复制题目</h4>
- <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
- </div>
- <div class="modal-body">
- <form class="form-horizontal" action="" method="post" role="form">
- <div class="form-group row">
- <input type="hidden" name="copy_problem_submit" value="submit">
- <label for="copy_problem_list" class="col-sm-5 control-label">题目列表</label>
- <div class="col-sm-7">
- <input type="text" class="form-control" id="copy_problem_list" name="copy_problem_list" placeholder="逗号分隔,复制后将连续">
- </div>
- </div>
- </div>
- <div class="modal-footer">
- <button type="submit" class="btn btn-success">确定</button>
- </form>
- <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
- </div>
- </div>
- </div>
- </div>
- EOF;
- }
- if ($print_datum_button) {
- echo <<<EOF
- <div class="text-right">
- <a type="button" class="mt-2 btn btn-secondary" href="/datums">自动生成数据</a>
- </div>
- EOF;
- }
- echo "<div class='mt-4'>";
- echo $pag->pagination();
- echo "</div>";
- ?>
- <?php echoUOJPageFooter() ?>
|