| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619 |
- <?php
- requirePHPLib('form');
- requirePHPLib('judger');
-
- if ($myUser == null || !isSuperUser($myUser)) {
- become403Page();
- }
-
- $user_form = new UOJForm('user');
- $user_form->addInput('username', 'text', '用户名', '',
- function ($username) {
- if (!validateUsername($username)) {
- return '用户名不合法';
- }
- if (!queryUser($username)) {
- return '用户不存在';
- }
- return '';
- },
- null
- );
- $options = array(
- 'banneduser' => '设为封禁用户',
- 'normaluser' => '设为普通用户',
- 'superuser' => '设为超级用户'
- );
- $user_form->addSelect('op-type', $options, '操作类型', '');
- $user_form->handle = function() {
- global $user_form;
-
- $username = $_POST['username'];
- switch ($_POST['op-type']) {
- case 'banneduser':
- DB::update("update user_info set usergroup = 'B' where username = '{$username}'");
- break;
- case 'normaluser':
- DB::update("update user_info set usergroup = 'U' where username = '{$username}'");
- break;
- case 'superuser':
- DB::update("update user_info set usergroup = 'S' where username = '{$username}'");
- break;
- }
- };
- $user_form->runAtServer();
- $assign_certs_form = new UOJForm('assign_certs_form');
- $color_options = array('red' => '红色', 'blue' => '蓝色', 'green' => '绿色', 'purple' => '紫色', 'pink' => '粉色', 'olive' => '屎黄色', 'deepblue' => '深蓝');
- $assign_certs_form->addSelect('color-type', $color_options, '勋章颜色', '');
- $assign_certs_form->addInput('certs_user', 'text', '用户名', '',
- function ($username) {
- if (!validateUsername($username))
- return '用户名不合法';
- if (!queryUser($username))
- return '用户不存在';
- return '';
- }, null
- );
-
- $assign_certs_form->addInput('certs_name', 'text', '称号', '',
- function ($text) {
- if (strpos($text, '#') != false || strpos($text, ',') != false)
- return '不能含有井号或逗号';
- if (mb_strlen($text) > 8) return '称号过长' . $text;
- return '';
- }, null
- );
- $assign_certs_form->handle = function() {
- $username = $_POST['certs_user'];
- $text = $_POST['certs_name'];
- $color = $_POST['color-type'];
- $user = queryUser($username);
- $newcerts = $user['certslist'];
- if ($user['certslist'] != '') $newcerts = $newcerts . ',' . $color . '#' . $text;
- else $newcerts = $color . '#' . $text;
- DB::update("update user_info set certslist = '{$newcerts}' where username = '{$username}'");
- if ($user['certs'] == '') DB::update("update user_info set certs = '{$newcerts}' where username = '{$username}'");
- };
- $assign_certs_form->runAtServer();
- $user_attach_form = new UOJForm('user_attach_form');
- $user_attach_form->addInput('username', 'text', '用户名', '',
- function ($username) {
- if (!validateUsername($username)) {
- return '用户名不合法';
- }
- if (!queryUser($username)) {
- return '用户不存在';
- }
- return '';
- },
- null
- );
- $user_attach_form->addInput('group', 'text', '组名', '',
- function ($username) {
- if (!validateUsername($username))
- return '组名不合法';
- if (!queryUser($username))
- return '组不存在';
- if (substr($username, 0, 6) != 'group_')
- return '不是合法组(前缀非 group_)';
- return '';
- },
- null
- );
- $user_attach_form->handle = function() {
- $username = $_POST['username'];
- $group = $_POST['group'];
- attachUserToGroup (queryUser($username), queryUser($group));
- };
- $user_attach_form->runAtServer();
- $problem_attach_form = new UOJForm('problem_attach_form');
- $problem_attach_form->addInput('pid', 'text', '题号', '',
- function ($pid) {
- if (!validateUInt($pid)) {
- return '题号不合法';
- }
- if (!queryProblemBrief($pid)) {
- return '题目不存在';
- }
- return '';
- },
- null
- );
- $problem_attach_form->addInput('problem_group', 'text', '组名', '',
- function ($username) {
- if (!validateUsername($username))
- return '组名不合法';
- if (!queryUser($username))
- return '组不存在';
- if (substr($username, 0, 6) != 'group_')
- return '不是合法组(前缀非 group_)';
- return '';
- },
- null
- );
- $problem_attach_form->handle = function() {
- $pid = $_POST['pid'];
- $group = $_POST['problem_group'];
- attachProblemToGroup (queryProblemBrief ($pid), queryUser($group));
- };
- $problem_attach_form->runAtServer();
- $blog_link_contests = new UOJForm('blog_link_contests');
- $blog_link_contests->addInput('blog_id', 'text', '博客ID', '',
- function ($x) {
- if (!validateUInt($x)) {
- return 'ID不合法';
- }
- if (!queryBlog($x)) {
- return '博客不存在';
- }
- return '';
- },
- null
- );
- $blog_link_contests->addInput('contest_id', 'text', '比赛ID', '',
- function ($x) {
- if (!validateUInt($x)) {
- return 'ID不合法';
- }
- if (!queryContest($x)) {
- return '比赛不存在';
- }
- return '';
- },
- null
- );
- $blog_link_contests->addInput('title', 'text', '标题', '',
- function ($x) {
- return '';
- },
- null
- );
- $options = array(
- 'add' => '添加',
- 'del' => '删除'
- );
- $blog_link_contests->addSelect('op-type', $options, '操作类型', '');
- $blog_link_contests->handle = function() {
- $blog_id = $_POST['blog_id'];
- $contest_id = $_POST['contest_id'];
- $str = DB::selectFirst(("select * from contests where id='${contest_id}'"));
- $all_config = json_decode($str['extra_config'], true);
- $config = $all_config['links'];
- $n = count($config);
-
- if ($_POST['op-type'] == 'add') {
- $row = array();
- $row[0] = $_POST['title'];
- $row[1] = $blog_id;
- $config[$n] = $row;
- }
- if ($_POST['op-type'] == 'del') {
- for ($i = 0; $i < $n; $i++) {
- if ($config[$i][1] == $blog_id) {
- $config[$i] = $config[$n - 1];
- unset($config[$n - 1]);
- break;
- }
- }
- }
- $all_config['links'] = $config;
- $str = json_encode($all_config);
- $str = DB::escape($str);
- DB::query("update contests set extra_config='${str}' where id='${contest_id}'");
- };
- $blog_link_contests->runAtServer();
-
- $blog_link_index = new UOJForm('blog_link_index');
- $blog_link_index->addInput('blog_id2', 'text', '博客ID', '',
- function ($x) {
- if (!validateUInt($x)) {
- return 'ID不合法';
- }
- if (!queryBlog($x)) {
- return '博客不存在';
- }
- return '';
- },
- null
- );
- $blog_link_index->addInput('blog_level', 'text', '置顶级别(删除不用填)', '0',
- function ($x) {
- if (!validateUInt($x)) {
- return '数字不合法';
- }
- if ($x > 3) {
- return '该级别不存在';
- }
- return '';
- },
- null
- );
- $options = array(
- 'add' => '添加',
- 'del' => '删除'
- );
- $blog_link_index->addSelect('op-type2', $options, '操作类型', '');
- $blog_link_index->handle = function() {
- $blog_id = $_POST['blog_id2'];
- $blog_level = $_POST['blog_level'];
- if ($_POST['op-type2'] == 'add') {
- if (DB::selectFirst("select * from important_blogs where blog_id = {$blog_id}")) {
- DB::update("update important_blogs set level = {$blog_level} where blog_id = {$blog_id}");
- } else {
- DB::insert("insert into important_blogs (blog_id, level) values ({$blog_id}, {$blog_level})");
- }
- }
- if ($_POST['op-type2'] == 'del') {
- DB::delete("delete from important_blogs where blog_id = {$blog_id}");
- }
- };
- $blog_link_index->runAtServer();
-
- $blog_deleter = new UOJForm('blog_deleter');
- $blog_deleter->addInput('blog_del_id', 'text', '博客ID', '',
- function ($x) {
- if (!validateUInt($x)) {
- return 'ID不合法';
- }
- if (!queryBlog($x)) {
- return '博客不存在';
- }
- return '';
- },
- null
- );
- $blog_deleter->handle = function() {
- deleteBlog($_POST['blog_del_id']);
- };
- $blog_deleter->runAtServer();
- $contest_submissions_deleter = new UOJForm('contest_submissions');
- $contest_submissions_deleter->addInput('contest_id', 'text', '比赛ID', '',
- function ($x) {
- if (!validateUInt($x)) {
- return 'ID不合法';
- }
- if (!queryContest($x)) {
- return '博客不存在';
- }
- return '';
- },
- null
- );
- $contest_submissions_deleter->handle = function() {
- $contest = queryContest($_POST['contest_id']);
- genMoreContestInfo($contest);
-
- $contest_problems = DB::selectAll("select problem_id from contests_problems where contest_id = {$contest['id']}");
- foreach ($contest_problems as $problem) {
- $submissions = DB::selectAll("select * from submissions where problem_id = {$problem['problem_id']} and submit_time < '{$contest['start_time_str']}'");
- foreach ($submissions as $submission) {
- $content = json_decode($submission['content'], true);
- unlink(UOJContext::storagePath().$content['file_name']);
- DB::delete("delete from submissions where id = {$submission['id']}");
- updateBestACSubmissions($submission['submitter'], $submission['problem_id']);
- }
- }
- };
- $contest_submissions_deleter->runAtServer();
- $custom_test_deleter = new UOJForm('custom_test_deleter');
- $custom_test_deleter->addInput('last', 'text', '删除末尾记录', '5',
- function ($x, &$vdata) {
- if (!validateUInt($x)) {
- return '不合法';
- }
- $vdata['last'] = $x;
- return '';
- },
- null
- );
- $custom_test_deleter->handle = function(&$vdata) {
- $all = DB::selectAll("select * from custom_test_submissions order by id asc limit {$vdata['last']}");
- foreach ($all as $submission) {
- $content = json_decode($submission['content'], true);
- unlink(UOJContext::storagePath().$content['file_name']);
- }
- DB::delete("delete from custom_test_submissions order by id asc limit {$vdata['last']}");
- };
- $custom_test_deleter->runAtServer();
- $judger_adder = new UOJForm('judger_adder');
- $judger_adder->addInput('judger_adder_name', 'text', '评测机名称', '',
- function ($x, &$vdata) {
- if (!validateUsername($x)) {
- return '不合法';
- }
- if (DB::selectCount("select count(*) from judger_info where judger_name='$x'")!=0) {
- return '不合法';
- }
- $vdata['name'] = $x;
- return '';
- },
- null
- );
- $judger_adder->handle = function(&$vdata) {
- $password=uojRandString(32);
- DB::insert("insert into judger_info (judger_name,password) values('{$vdata['name']}','{$password}')");
- };
- $judger_adder->runAtServer();
-
- $judger_deleter = new UOJForm('judger_deleter');
- $judger_deleter->addInput('judger_deleter_name', 'text', '评测机名称', '',
- function ($x, &$vdata) {
- if (!validateUsername($x)) {
- return '不合法';
- }
- if (DB::selectCount("select count(*) from judger_info where judger_name='$x'")!=1) {
- return '不合法';
- }
- $vdata['name'] = $x;
- return '';
- },
- null
- );
- $judger_deleter->handle = function(&$vdata) {
- DB::delete("delete from judger_info where judger_name='{$vdata['name']}'");
- };
- $judger_deleter->runAtServer();
- $paste_deleter = new UOJForm('paste_deleter');
- $paste_deleter->addInput('paste_deleter_name', 'text', 'Paste ID', '',
- function ($x, &$vdata) {
- if (DB::selectCount("select count(*) from pastes where `index`='$x'")==0) {
- return '不合法';
- }
- $vdata['name'] = $x;
- return '';
- },
- null
- );
- $paste_deleter->handle = function(&$vdata) {
- DB::delete("delete from pastes where `index` = '${vdata['name']}'");
- };
- $paste_deleter->runAtServer();
-
- $judgerlist_cols = array('judger_name', 'password');
- $judgerlist_config = array();
- $judgerlist_header_row = <<<EOD
- <tr>
- <th>评测机名称</th>
- <th>密码</th>
- </tr>
- EOD;
- $judgerlist_print_row = function($row) {
- echo <<<EOD
- <tr>
- <td>{$row['judger_name']}</td>
- <td>{$row['password']}</td>
- </tr>
- EOD;
- };
-
- $banlist_cols = array('username', 'usergroup');
- $banlist_config = array();
- $banlist_header_row = <<<EOD
- <tr>
- <th>用户名</th>
- </tr>
- EOD;
- $banlist_print_row = function($row) {
- $hislink = getUserLink($row['username']);
- echo <<<EOD
- <tr>
- <td>${hislink}</td>
- </tr>
- EOD;
- };
-
- $cur_tab = isset($_GET['tab']) ? $_GET['tab'] : 'users';
-
- $tabs_info = array(
- 'users' => array(
- 'name' => '用户操作',
- 'url' => "/super-manage/users"
- ),
- 'blogs' => array(
- 'name' => '博客管理',
- 'url' => "/super-manage/blogs"
- ),
- 'submissions' => array(
- 'name' => '提交记录',
- 'url' => "/super-manage/submissions"
- ),
- 'custom-test' => array(
- 'name' => '自定义测试',
- 'url' => '/super-manage/custom-test'
- ),
- 'click-zan' => array(
- 'name' => '点赞管理',
- 'url' => '/super-manage/click-zan'
- ),
- 'search' => array(
- 'name' => '搜索管理',
- 'url' => '/super-manage/search'
- ),
- 'judger' => array(
- 'name' => '评测机管理',
- 'url' => '/super-manage/judger'
- ),
- 'paste' => array(
- 'name' => 'Paste管理',
- 'url' => '/super-manage/paste'
- ),
- 'groups' => array(
- 'name' => '用户组管理',
- 'url' => '/super-manage/groups'
- ),
- 'certs' => array(
- 'name' => '勋章管理',
- 'url' => '/super-manage/certs'
- )
- );
-
- if (!isset($tabs_info[$cur_tab])) {
- become404Page();
- }
- ?>
- <?php
- requireLib('hljs');
- requireLib('morris');
- ?>
- <?php echoUOJPageHeader('系统管理') ?>
- <div class="row">
- <div class="col-sm-3">
- <?= HTML::tablist($tabs_info, $cur_tab, 'nav-pills flex-column') ?>
- </div>
-
- <div class="col-sm-9">
- <?php if ($cur_tab === 'users'): ?>
- <?php $user_form->printHTML(); ?>
- <h3>封禁名单</h3>
- <?php echoLongTable($banlist_cols, 'user_info', "usergroup='B'", '', $banlist_header_row, $banlist_print_row, $banlist_config) ?>
- <?php elseif ($cur_tab === 'blogs'): ?>
- <div>
- <h4>添加到比赛链接</h4>
- <?php $blog_link_contests->printHTML(); ?>
- </div>
- <div>
- <h4>添加到公告</h4>
- <?php $blog_link_index->printHTML(); ?>
- </div>
-
- <div>
- <h4>删除博客</h4>
- <?php $blog_deleter->printHTML(); ?>
- </div>
- <?php elseif ($cur_tab === 'submissions'): ?>
- <div>
- <h4>删除赛前提交记录</h4>
- <?php $contest_submissions_deleter->printHTML(); ?>
- </div>
- <div>
- <h4>测评失败的提交记录</h4>
- <?php echoSubmissionsList("result_error = 'Judgement Failed'", 'order by id desc', array('result_hidden' => ''), $myUser); ?>
- </div>
- <?php elseif ($cur_tab === 'custom-test'): ?>
- <?php $custom_test_deleter->printHTML() ?>
- <?php
- $submissions_pag = new Paginator(array(
- 'col_names' => array('*'),
- 'table_name' => 'custom_test_submissions',
- 'cond' => '1',
- 'tail' => 'order by id asc',
- 'page_len' => 5
- ));
- foreach ($submissions_pag->get() as $submission) {
- $problem = queryProblemBrief($submission['problem_id']);
- $submission_result = json_decode($submission['result'], true);
- echo '<dl class="dl-horizontal">';
- echo '<dt>id</dt>';
- echo '<dd>', "#{$submission['id']}", '</dd>';
- echo '<dt>problem_id</dt>';
- echo '<dd>', "#{$submission['problem_id']}", '</dd>';
- echo '<dt>submit time</dt>';
- echo '<dd>', $submission['submit_time'], '</dd>';
- echo '<dt>submitter</dt>';
- echo '<dd>', $submission['submitter'], '</dd>';
- echo '<dt>judge_time</dt>';
- echo '<dd>', $submission['judge_time'], '</dd>';
- echo '</dl>';
- echoSubmissionContent($submission, getProblemCustomTestRequirement($problem));
- echoCustomTestSubmissionDetails($submission_result['details'], "submission-{$submission['id']}-details");
- }
- ?>
- <?= $submissions_pag->pagination() ?>
- <?php elseif ($cur_tab === 'click-zan'): ?>
- 没写好QAQ
- <?php elseif ($cur_tab === 'search'): ?>
- <h2 class="text-center">一周搜索情况</h2>
- <div id="search-distribution-chart-week" style="height: 250px;"></div>
- <script type="text/javascript">
- new Morris.Line({
- element: 'search-distribution-chart-week',
- data: <?= json_encode(DB::selectAll("select DATE_FORMAT(created_at, '%Y-%m-%d %h:00'), count(*) from search_requests where created_at > now() - interval 1 week group by DATE_FORMAT(created_at, '%Y-%m-%d %h:00')")) ?>,
- xkey: "DATE_FORMAT(created_at, '%Y-%m-%d %h:00')",
- ykeys: ["count(*)"],
- labels: ['number'],
- resize: true
- });
- </script>
-
- <h2 class="text-center">一月搜索情况</h2>
- <div id="search-distribution-chart-month" style="height: 250px;"></div>
- <script type="text/javascript">
- new Morris.Line({
- element: 'search-distribution-chart-month',
- data: <?= json_encode(DB::selectAll("select DATE_FORMAT(created_at, '%Y-%m-%d'), count(*) from search_requests where created_at > now() - interval 1 week group by DATE_FORMAT(created_at, '%Y-%m-%d')")) ?>,
- xkey: "DATE_FORMAT(created_at, '%Y-%m-%d')",
- ykeys: ["count(*)"],
- labels: ['number'],
- resize: true
- });
- </script>
-
- <?php echoLongTable(array('*'), 'search_requests', "1", 'order by id desc',
- '<tr><th>id</th><th>created_at</th><th>remote_addr</th><th>type</th><th>q</th><tr>',
- function($row) {
- echo '<tr>';
- echo '<td>', $row['id'], '</td>';
- echo '<td>', $row['created_at'], '</td>';
- echo '<td>', $row['remote_addr'], '</td>';
- echo '<td>', $row['type'], '</td>';
- echo '<td>', HTML::escape($row['q']), '</td>';
- echo '</tr>';
- }, array(
- 'page_len' => 1000
- ))
- ?>
- <?php elseif ($cur_tab === 'judger'): ?>
- <div>
- <h4>添加评测机</h4>
- <?php $judger_adder->printHTML(); ?>
- </div>
- <div>
- <h4>删除评测机</h4>
- <?php $judger_deleter->printHTML(); ?>
- </div>
- <h3>评测机列表</h3>
- <?php echoLongTable($judgerlist_cols, 'judger_info', "1=1", '', $judgerlist_header_row, $judgerlist_print_row, $judgerlist_config) ?>
- <?php elseif ($cur_tab === 'paste'): ?>
- <div>
- <h4>Paste管理</h4>
- <?php echoPastesList() ?>
- </div>
- <?php elseif ($cur_tab == 'groups'): ?>
- <div>
- <h4>用户组管理</h4>
- <?php echoGroupsList() ?>
- </div>
- <div>
- <h4>添加用户到组</h4>
- <?php $user_attach_form->printHTML(); ?>
- </div>
- <div>
- <h4>添加题目到组</h4>
- <?php $problem_attach_form->printHTML(); ?>
- </div>
- <?php elseif ($cur_tab == 'certs'): ?>
- <div>
- <h4>将勋章授予某人</h4>
- <?php $assign_certs_form->printHTML(); ?>
- </div>
- <?php endif ?>
- </div>
- </div>
- <?php echoUOJPageFooter() ?>
|