2016-07-18 16:39:37 +00:00
|
|
|
|
<?php
|
2022-03-17 04:00:03 +00:00
|
|
|
|
if (!Auth::check()) {
|
2022-10-06 12:28:43 +00:00
|
|
|
|
redirectToLogin();
|
2022-03-17 04:00:03 +00:00
|
|
|
|
}
|
2022-10-07 09:29:26 +00:00
|
|
|
|
|
|
|
|
|
requirePHPLib('form');
|
2022-04-03 10:18:17 +00:00
|
|
|
|
|
2016-07-18 16:39:37 +00:00
|
|
|
|
if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) {
|
|
|
|
|
become404Page();
|
|
|
|
|
}
|
|
|
|
|
genMoreContestInfo($contest);
|
|
|
|
|
|
|
|
|
|
if (!isSuperUser($myUser)) {
|
|
|
|
|
become403Page();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$time_form = new UOJForm('time');
|
|
|
|
|
$time_form->addInput(
|
|
|
|
|
'name', 'text', '比赛标题', $contest['name'],
|
|
|
|
|
function($str) {
|
|
|
|
|
return '';
|
|
|
|
|
},
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
$time_form->addInput(
|
|
|
|
|
'start_time', 'text', '开始时间', $contest['start_time_str'],
|
|
|
|
|
function($str, &$vdata) {
|
|
|
|
|
try {
|
|
|
|
|
$vdata['start_time'] = new DateTime($str);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
return '无效时间格式';
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
},
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
$time_form->addInput(
|
|
|
|
|
'last_min', 'text', '时长(单位:分钟)', $contest['last_min'],
|
|
|
|
|
function($str) {
|
|
|
|
|
return !validateUInt($str) ? '必须为一个整数' : '';
|
|
|
|
|
},
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
$time_form->handle = function(&$vdata) {
|
|
|
|
|
global $contest;
|
|
|
|
|
$start_time_str = $vdata['start_time']->format('Y-m-d H:i:s');
|
|
|
|
|
|
2022-10-09 13:33:13 +00:00
|
|
|
|
$purifier = HTML::purifier_inline();
|
2016-07-18 16:39:37 +00:00
|
|
|
|
|
|
|
|
|
$esc_name = $_POST['name'];
|
|
|
|
|
$esc_name = $purifier->purify($esc_name);
|
|
|
|
|
$esc_name = DB::escape($esc_name);
|
|
|
|
|
|
|
|
|
|
DB::update("update contests set start_time = '$start_time_str', last_min = {$_POST['last_min']}, name = '$esc_name' where id = {$contest['id']}");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$managers_form = newAddDelCmdForm('managers',
|
|
|
|
|
function($username) {
|
|
|
|
|
if (!validateUsername($username) || !queryUser($username)) {
|
|
|
|
|
return "不存在名为{$username}的用户";
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
},
|
|
|
|
|
function($type, $username) {
|
|
|
|
|
global $contest;
|
2022-09-19 11:06:16 +00:00
|
|
|
|
|
2016-07-18 16:39:37 +00:00
|
|
|
|
if ($type == '+') {
|
2017-11-25 15:29:18 +00:00
|
|
|
|
DB::query("insert into contests_permissions (contest_id, username) values (${contest['id']}, '$username')");
|
2020-06-25 12:41:16 +00:00
|
|
|
|
} elseif ($type == '-') {
|
2017-11-25 15:29:18 +00:00
|
|
|
|
DB::query("delete from contests_permissions where contest_id = ${contest['id']} and username = '$username'");
|
2016-07-18 16:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$problems_form = newAddDelCmdForm('problems',
|
|
|
|
|
function($cmd) {
|
|
|
|
|
if (!preg_match('/^(\d+)\s*(\[\S+\])?$/', $cmd, $matches)) {
|
|
|
|
|
return "无效题号";
|
|
|
|
|
}
|
|
|
|
|
$problem_id = $matches[1];
|
|
|
|
|
if (!validateUInt($problem_id) || !($problem = queryProblemBrief($problem_id))) {
|
|
|
|
|
return "不存在题号为{$problem_id}的题";
|
|
|
|
|
}
|
|
|
|
|
if (!hasProblemPermission(Auth::user(), $problem)) {
|
|
|
|
|
return "无权添加题号为{$problem_id}的题";
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
},
|
|
|
|
|
function($type, $cmd) {
|
|
|
|
|
global $contest;
|
|
|
|
|
|
|
|
|
|
if (!preg_match('/^(\d+)\s*(\[\S+\])?$/', $cmd, $matches)) {
|
|
|
|
|
return "无效题号";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$problem_id = $matches[1];
|
|
|
|
|
|
|
|
|
|
if ($type == '+') {
|
2022-09-19 11:06:16 +00:00
|
|
|
|
$dfn = DB::selectFirst("select max(dfn) from contests_problems where contest_id = {$contest['id']}")['max(dfn)'] + 1;
|
|
|
|
|
DB::insert("insert into contests_problems (contest_id, problem_id, dfn) values ({$contest['id']}, '$problem_id', $dfn)");
|
2020-06-25 12:41:16 +00:00
|
|
|
|
} elseif ($type == '-') {
|
2016-07-18 16:39:37 +00:00
|
|
|
|
DB::delete("delete from contests_problems where contest_id = {$contest['id']} and problem_id = '$problem_id'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($matches[2])) {
|
|
|
|
|
switch ($matches[2]) {
|
|
|
|
|
case '[sample]':
|
|
|
|
|
unset($contest['extra_config']["problem_$problem_id"]);
|
|
|
|
|
break;
|
|
|
|
|
case '[full]':
|
|
|
|
|
$contest['extra_config']["problem_$problem_id"] = 'full';
|
|
|
|
|
break;
|
|
|
|
|
case '[no-details]':
|
|
|
|
|
$contest['extra_config']["problem_$problem_id"] = 'no-details';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
$esc_extra_config = json_encode($contest['extra_config']);
|
|
|
|
|
$esc_extra_config = DB::escape($esc_extra_config);
|
|
|
|
|
DB::update("update contests set extra_config = '$esc_extra_config' where id = {$contest['id']}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (isSuperUser($myUser)) {
|
|
|
|
|
$version_form = new UOJForm('version');
|
|
|
|
|
$version_form->addInput('standings_version', 'text', '排名版本', $contest['extra_config']['standings_version'],
|
|
|
|
|
function ($x) {
|
|
|
|
|
if (!validateUInt($x) || $x < 1 || $x > 2) {
|
|
|
|
|
return '不是合法的版本号';
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
},
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
$version_form->handle = function() {
|
|
|
|
|
global $contest;
|
|
|
|
|
$contest['extra_config']['standings_version'] = $_POST['standings_version'];
|
|
|
|
|
$esc_extra_config = json_encode($contest['extra_config']);
|
|
|
|
|
$esc_extra_config = DB::escape($esc_extra_config);
|
|
|
|
|
DB::update("update contests set extra_config = '$esc_extra_config' where id = {$contest['id']}");
|
|
|
|
|
};
|
|
|
|
|
$version_form->runAtServer();
|
2019-06-11 03:03:53 +00:00
|
|
|
|
|
|
|
|
|
$contest_type_form = new UOJForm('contest_type');
|
|
|
|
|
$contest_type_form->addInput('contest_type', 'text', '赛制', $contest['extra_config']['contest_type'],
|
|
|
|
|
function ($x) {
|
|
|
|
|
if ($x != 'OI' && $x != 'ACM' && $x != 'IOI') {
|
|
|
|
|
return '不是合法的赛制名';
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
},
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
$contest_type_form->handle = function() {
|
|
|
|
|
global $contest;
|
|
|
|
|
$contest['extra_config']['contest_type'] = $_POST['contest_type'];
|
|
|
|
|
$esc_extra_config = json_encode($contest['extra_config']);
|
|
|
|
|
$esc_extra_config = DB::escape($esc_extra_config);
|
|
|
|
|
DB::update("update contests set extra_config = '$esc_extra_config' where id = {$contest['id']}");
|
|
|
|
|
};
|
|
|
|
|
$contest_type_form->runAtServer();
|
2016-07-18 16:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$time_form->runAtServer();
|
|
|
|
|
$managers_form->runAtServer();
|
|
|
|
|
$problems_form->runAtServer();
|
2022-09-21 10:12:58 +00:00
|
|
|
|
|
|
|
|
|
$blog_link_contests = new UOJForm('blog_link_contests');
|
|
|
|
|
$blog_link_contests->addInput('blog_link_contests__blog_id', 'text', '博客ID', '',
|
|
|
|
|
function ($x) {
|
|
|
|
|
if (!validateUInt($x)) {
|
|
|
|
|
return 'ID不合法';
|
|
|
|
|
}
|
|
|
|
|
if (!queryBlog($x)) {
|
|
|
|
|
return '博客不存在';
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
},
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
$blog_link_contests->addInput('blog_link_contests__title', 'text', '标题', '',
|
|
|
|
|
function ($x) {
|
|
|
|
|
return '';
|
|
|
|
|
},
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
$options = array(
|
|
|
|
|
'add' => '添加',
|
|
|
|
|
'del' => '删除'
|
|
|
|
|
);
|
|
|
|
|
$blog_link_contests->addSelect('blog_link_contests__op-type', $options, '操作类型', '');
|
|
|
|
|
$blog_link_contests->handle = function() {
|
|
|
|
|
global $contest;
|
|
|
|
|
|
|
|
|
|
$blog_id = $_POST['blog_link_contests__blog_id'];
|
|
|
|
|
$contest_id = $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['blog_link_contests__op-type'] == 'add') {
|
|
|
|
|
$row = array();
|
|
|
|
|
$row[0] = $_POST['blog_link_contests__title'];
|
|
|
|
|
$row[1] = $blog_id;
|
|
|
|
|
$config[$n] = $row;
|
|
|
|
|
}
|
|
|
|
|
if ($_POST['blog_link_contests__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();
|
|
|
|
|
|
2022-09-18 04:58:35 +00:00
|
|
|
|
?>
|
2016-07-18 16:39:37 +00:00
|
|
|
|
<?php echoUOJPageHeader(HTML::stripTags($contest['name']) . ' - 比赛管理') ?>
|
|
|
|
|
<h1 class="page-header" align="center"><?=$contest['name']?> 管理</h1>
|
2019-09-10 02:15:20 +00:00
|
|
|
|
<ul class="nav nav-tabs mb-3" role="tablist">
|
|
|
|
|
<li class="nav-item"><a class="nav-link active" href="#tab-time" role="tab" data-toggle="tab">比赛时间</a></li>
|
|
|
|
|
<li class="nav-item"><a class="nav-link" href="#tab-managers" role="tab" data-toggle="tab">管理者</a></li>
|
|
|
|
|
<li class="nav-item"><a class="nav-link" href="#tab-problems" role="tab" data-toggle="tab">试题</a></li>
|
2022-09-21 10:12:58 +00:00
|
|
|
|
<li class="nav-item"><a class="nav-link" href="#tab-blogs" role="tab" data-toggle="tab">比赛资料</a></li>
|
2016-07-18 16:39:37 +00:00
|
|
|
|
<?php if (isSuperUser($myUser)): ?>
|
2019-09-10 02:15:20 +00:00
|
|
|
|
<li class="nav-item"><a class="nav-link" href="#tab-others" role="tab" data-toggle="tab">其它</a></li>
|
2016-07-18 16:39:37 +00:00
|
|
|
|
<?php endif ?>
|
2019-09-10 02:15:20 +00:00
|
|
|
|
<li class="nav-item"><a class="nav-link" href="/contest/<?=$contest['id']?>" role="tab">返回</a></li>
|
2016-07-18 16:39:37 +00:00
|
|
|
|
</ul>
|
|
|
|
|
<div class="tab-content top-buffer-sm">
|
|
|
|
|
<div class="tab-pane active" id="tab-time">
|
|
|
|
|
<?php $time_form->printHTML(); ?>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="tab-pane" id="tab-managers">
|
|
|
|
|
<table class="table table-hover">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>#</th>
|
|
|
|
|
<th>用户名</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
<?php
|
2022-09-18 04:58:35 +00:00
|
|
|
|
$row_id = 0;
|
2016-07-18 16:39:37 +00:00
|
|
|
|
$result = DB::query("select username from contests_permissions where contest_id = {$contest['id']}");
|
2017-11-25 15:29:18 +00:00
|
|
|
|
while ($row = DB::fetch($result, MYSQLI_ASSOC)) {
|
2016-07-18 16:39:37 +00:00
|
|
|
|
$row_id++;
|
|
|
|
|
echo '<tr>', '<td>', $row_id, '</td>', '<td>', getUserLink($row['username']), '</td>', '</tr>';
|
|
|
|
|
}
|
2022-09-18 04:58:35 +00:00
|
|
|
|
?>
|
2016-07-18 16:39:37 +00:00
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
<p class="text-center">命令格式:命令一行一个,+mike表示把mike加入管理者,-mike表示把mike从管理者中移除</p>
|
|
|
|
|
<?php $managers_form->printHTML(); ?>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="tab-pane" id="tab-problems">
|
|
|
|
|
<table class="table table-hover">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>#</th>
|
|
|
|
|
<th>试题名</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
<?php
|
2022-09-19 11:06:16 +00:00
|
|
|
|
$result = DB::query("select problem_id from contests_problems where contest_id = ${contest['id']} order by dfn, problem_id");
|
2017-11-25 15:29:18 +00:00
|
|
|
|
while ($row = DB::fetch($result, MYSQLI_ASSOC)) {
|
2016-07-18 16:39:37 +00:00
|
|
|
|
$problem = queryProblemBrief($row['problem_id']);
|
|
|
|
|
$problem_config_str = isset($contest['extra_config']["problem_{$problem['id']}"]) ? $contest['extra_config']["problem_{$problem['id']}"] : 'sample';
|
|
|
|
|
echo '<tr>', '<td>', $problem['id'], '</td>', '<td>', getProblemLink($problem), ' ', "[$problem_config_str]", '</td>', '</tr>';
|
|
|
|
|
}
|
2022-09-18 04:58:35 +00:00
|
|
|
|
?>
|
2016-07-18 16:39:37 +00:00
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
<p class="text-center">命令格式:命令一行一个,+233表示把题号为233的试题加入比赛,-233表示把题号为233的试题从比赛中移除</p>
|
|
|
|
|
<?php $problems_form->printHTML(); ?>
|
|
|
|
|
</div>
|
2022-09-21 10:12:58 +00:00
|
|
|
|
<div class="tab-pane" id="tab-blogs">
|
|
|
|
|
<?php $blog_link_contests->printHTML(); ?>
|
|
|
|
|
</div>
|
2016-07-18 16:39:37 +00:00
|
|
|
|
<?php if (isSuperUser($myUser)): ?>
|
|
|
|
|
<div class="tab-pane" id="tab-others">
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="col-sm-12 top-buffer-sm">
|
|
|
|
|
<h3>版本控制</h3>
|
|
|
|
|
<?php $version_form->printHTML(); ?>
|
|
|
|
|
</div>
|
2019-06-11 03:03:53 +00:00
|
|
|
|
<div class="col-sm-12 top-buffer-sm">
|
|
|
|
|
<h3>赛制</h3>
|
|
|
|
|
<?php $contest_type_form->printHTML(); ?>
|
|
|
|
|
</div>
|
2016-07-18 16:39:37 +00:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<?php endif ?>
|
|
|
|
|
</div>
|
2022-03-17 03:02:44 +00:00
|
|
|
|
<?php echoUOJPageFooter() ?>
|