mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-12-25 13:11:52 +00:00
feat(web/index): add countdown
This commit is contained in:
parent
27c1eee037
commit
69404b4376
@ -332,6 +332,29 @@ LOCK TABLES `contests_submissions` WRITE;
|
||||
/*!40000 ALTER TABLE `contests_submissions` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `countdowns`
|
||||
--
|
||||
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `countdowns` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`title` text NOT NULL,
|
||||
`endtime` datetime NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `countdowns`
|
||||
--
|
||||
|
||||
LOCK TABLES `countdowns` WRITE;
|
||||
/*!40000 ALTER TABLE `countdowns` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `countdowns` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `custom_test_submissions`
|
||||
--
|
||||
|
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
$blogs = DB::selectAll("select blogs.id, title, poster, post_time from important_blogs, blogs where is_hidden = 0 and important_blogs.blog_id = blogs.id order by level desc, important_blogs.blog_id desc limit 5");
|
||||
$countdowns = DB::selectAll("select * from countdowns order by endtime asc limit 5")
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJConfig::$data['profile']['oj-name-short']) ?>
|
||||
<div class="card card-default">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-9">
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-9">
|
||||
<div class="card card-default">
|
||||
<div class="card-body">
|
||||
<table class="table table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -14,7 +15,7 @@
|
||||
<th style="width:20%"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody>
|
||||
<?php $now_cnt = 0; ?>
|
||||
<?php foreach ($blogs as $blog): ?>
|
||||
<?php
|
||||
@ -37,23 +38,44 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-xs-6 col-sm-4 col-md-3">
|
||||
<img class="media-object img-thumbnail" src="/images/logo.png" alt="Logo" />
|
||||
</div>
|
||||
<?php if (Auth::check() && isNormalUser($myUser)): ?>
|
||||
<div class="mt-4">
|
||||
<h3><?= UOJLocale::get('top solver') ?></h3>
|
||||
<?php echoRanklist(array('echo_full' => true, 'top10' => true, 'by_accepted' => true)) ?>
|
||||
<div class="text-center">
|
||||
<a href="/solverlist"><?= UOJLocale::get('view all') ?></a>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<div class="col-xs-6 col-sm-4 col-md-3">
|
||||
<div class="d-none d-md-block">
|
||||
<img class="media-object img-thumbnail" src="/images/logo.png" alt="Logo" />
|
||||
</div>
|
||||
<div class="card card-default mt-4">
|
||||
<div class="card-body">
|
||||
<h3 class="card-title">倒计时</h3>
|
||||
<div>
|
||||
<?php foreach ($countdowns as $countdown): ?>
|
||||
<?php
|
||||
$enddate = strtotime($countdown['endtime']);
|
||||
$nowdate = time();
|
||||
$diff = floor(($enddate - $nowdate) / (24 * 60 * 60));
|
||||
?>
|
||||
<p class="card-text">
|
||||
<?php if ($diff > 0): ?>
|
||||
距离 <b><?= $countdown['title'] ?></b> 还有 <b><?= $diff ?></b> 天。
|
||||
<?php else: ?>
|
||||
<b><?= $countdown['title'] ?></b> 已开始。
|
||||
<?php endif ?>
|
||||
</p>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (Auth::check() && isNormalUser($myUser)): ?>
|
||||
<div class="row">
|
||||
<div class="col-sm-12 mt-4">
|
||||
<h3><?= UOJLocale::get('top solver') ?></h3>
|
||||
<?php echoRanklist(array('echo_full' => true, 'top10' => true, 'by_accepted' => true)) ?>
|
||||
<div class="text-center">
|
||||
<a href="/solverlist"><?= UOJLocale::get('view all') ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -298,6 +298,67 @@
|
||||
};
|
||||
$blog_deleter->runAtServer();
|
||||
|
||||
$countdown_adder = new UOJForm('new_countdown');
|
||||
$countdown_adder->submit_button_config['align'] = 'compressed';
|
||||
$countdown_adder->addInput('new_countdown_title', 'text', '标题', '',
|
||||
function ($new_countdown_title) {
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$countdown_adder->addInput('new_countdown_endtime', 'text', '截止日期', date("Y-m-d H:i:s"),
|
||||
function($str, &$vdata) {
|
||||
try {
|
||||
$vdata['new_countdown_endtime'] = new DateTime($str);
|
||||
} catch (Exception $e) {
|
||||
return '无效时间格式';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$countdown_adder->handle = function() {
|
||||
$new_countdown_title = $_POST['new_countdown_title'];
|
||||
$new_countdown_endtime = $_POST['new_countdown_endtime'];
|
||||
$new_countdown_title = DB::escape($new_countdown_title);
|
||||
|
||||
DB::query("insert into countdowns (title, endtime) values ('$new_countdown_title', '$new_countdown_endtime')");
|
||||
};
|
||||
$countdown_adder->runAtServer();
|
||||
|
||||
$countdown_deleter = new UOJForm('delete_countdown');
|
||||
$countdown_deleter->submit_button_config['align'] = 'compressed';
|
||||
$countdown_deleter->addInput('delete_countdown_id', 'text', 'ID', '',
|
||||
function ($delete_countdown_id) {
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$countdown_deleter->handle = function() {
|
||||
$delete_countdown_id = $_POST['delete_countdown_id'];
|
||||
$delete_countdown_id = DB::escape($delete_countdown_id);
|
||||
|
||||
DB::query("delete from countdowns where id = '$delete_countdown_id'");
|
||||
};
|
||||
$countdown_deleter->runAtServer();
|
||||
|
||||
$countdowns_header_row = <<<EOD
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>标题</th>
|
||||
<th>时间</th>
|
||||
</tr>
|
||||
EOD;
|
||||
$countdowns_print_row = function($row) {
|
||||
echo <<<EOD
|
||||
<tr>
|
||||
<td>{$row['id']}</td>
|
||||
<td>{$row['title']}</td>
|
||||
<td>{$row['endtime']}</td>
|
||||
</tr>
|
||||
EOD;
|
||||
};
|
||||
|
||||
$contest_submissions_deleter = new UOJForm('contest_submissions');
|
||||
$contest_submissions_deleter->addInput('contest_id', 'text', '比赛ID', '',
|
||||
function ($x) {
|
||||
@ -453,6 +514,10 @@ EOD;
|
||||
'name' => '博客管理',
|
||||
'url' => "/super-manage/blogs"
|
||||
),
|
||||
'index' => array(
|
||||
'name' => '首页管理',
|
||||
'url' => '/super-manage/index'
|
||||
),
|
||||
'submissions' => array(
|
||||
'name' => '提交记录',
|
||||
'url' => "/super-manage/submissions"
|
||||
@ -529,6 +594,15 @@ EOD;
|
||||
<h4>删除博客</h4>
|
||||
<?php $blog_deleter->printHTML(); ?>
|
||||
</div>
|
||||
<?php elseif ($cur_tab === 'index'): ?>
|
||||
<div>
|
||||
<h4>倒计时管理</h4>
|
||||
<?php echoLongTable(array('id', 'title', 'endtime'), 'countdowns', '1', 'order by endtime asc', $countdowns_header_row, $countdowns_print_row, $userlist_config) ?>
|
||||
<h5>添加倒计时</h5>
|
||||
<?php $countdown_adder->printHTML(); ?>
|
||||
<h5>删除倒计时</h5>
|
||||
<?php $countdown_deleter->printHTML(); ?>
|
||||
</div>
|
||||
<?php elseif ($cur_tab === 'submissions'): ?>
|
||||
<div>
|
||||
<h4>删除赛前提交记录</h4>
|
||||
|
Loading…
Reference in New Issue
Block a user