S2OJ/web/app/controllers/add_contest.php

102 lines
2.0 KiB
PHP
Raw Normal View History

2016-07-18 16:39:37 +00:00
<?php
2022-03-17 04:00:03 +00:00
if (!Auth::check()) {
redirectToLogin();
2022-03-17 04:00:03 +00:00
}
2022-04-03 10:18:17 +00:00
if (!isNormalUser($myUser)) {
become403Page();
}
2022-10-19 03:57:06 +00:00
requireLib('bootstrap5');
2016-07-18 16:39:37 +00:00
requirePHPLib('form');
2020-06-25 12:41:16 +00:00
if (!isSuperUser($myUser)) {
2016-07-18 16:39:37 +00:00
become403Page();
}
$time_form = new UOJForm('time');
2022-10-02 06:41:26 +00:00
$time_form->addVInput(
2016-07-18 16:39:37 +00:00
'name', 'text', '比赛标题', 'New Contest',
function($name, &$vdata) {
if ($name == '') {
return '标题不能为空';
}
if (strlen($name) > 100) {
return '标题过长';
}
$name = HTML::escape($name);
if ($name === '') {
return '无效编码';
}
$vdata['name'] = $name;
2016-07-18 16:39:37 +00:00
return '';
},
null
);
2022-10-02 06:41:26 +00:00
$time_form->addVInput(
2016-07-18 16:39:37 +00:00
'start_time', 'text', '开始时间', date("Y-m-d H:i:s"),
function($str, &$vdata) {
try {
$vdata['start_time'] = new DateTime($str);
} catch (Exception $e) {
return '无效时间格式';
}
return '';
},
null
);
2022-10-02 06:41:26 +00:00
$time_form->addVInput(
2016-07-18 16:39:37 +00:00
'last_min', 'text', '时长(单位:分钟)', 180,
function($str, &$vdata) {
if (!validateUInt($str)) {
return '必须为一个整数';
}
$vdata['last_min'] = $str;
return '';
2016-07-18 16:39:37 +00:00
},
null
);
$time_form->handle = function(&$vdata) {
$start_time_str = $vdata['start_time']->format('Y-m-d H:i:s');
$esc_name = DB::escape($vdata['name']);
$esc_last_min = DB::escape($vdata['last_min']);
2016-07-18 16:39:37 +00:00
DB::query("insert into contests (name, start_time, last_min, status) values ('$esc_name', '$start_time_str', $esc_last_min, 'unfinished')");
2016-07-18 16:39:37 +00:00
};
$time_form->succ_href = "/contests";
2016-07-18 16:39:37 +00:00
$time_form->runAtServer();
2022-09-18 04:58:35 +00:00
?>
2016-07-18 16:39:37 +00:00
<?php echoUOJPageHeader('添加比赛') ?>
2022-10-02 06:41:26 +00:00
<div class="row">
<div class="col-lg-9">
<div class="card card-default mb-2">
<div class="card-body">
2022-10-19 03:57:06 +00:00
<h1 class="h2 card-title">添加比赛</h1>
2022-10-02 06:41:26 +00:00
<div class="w-full" style="max-width: 400px">
<?php $time_form->printHTML(); ?>
2016-07-18 16:39:37 +00:00
</div>
2022-10-02 06:41:26 +00:00
</div>
</div>
</div>
2022-10-19 03:57:06 +00:00
<!-- right col -->
<aside class="col-lg-3 mt-3 mt-lg-0">
2022-10-02 06:41:26 +00:00
<?php uojIncludeView('sidebar', array()) ?>
</aside>
</div>
2022-03-17 04:00:03 +00:00
<?php echoUOJPageFooter() ?>