S2OJ/web/app/controllers/contests.php

145 lines
5.6 KiB
PHP
Raw Normal View History

2016-07-18 16:39:37 +00:00
<?php
2022-11-06 02:26:21 +00:00
requirePHPLib('form');
2022-03-17 04:00:03 +00:00
2022-11-06 02:26:21 +00:00
Auth::check() || redirectToLogin();
2022-03-17 04:00:03 +00:00
2022-11-06 02:26:21 +00:00
$upcoming_contest_name = null;
$upcoming_contest_href = null;
$rest_second = 1000000;
function echoContest($info) {
global $upcoming_contest_name, $upcoming_contest_href, $rest_second;
2022-09-24 04:10:30 +00:00
2022-11-06 02:26:21 +00:00
$contest = new UOJContest($info);
$contest_name_link = '<a class="text-decoration-none" href="/contest/' . $contest->info['id'] . '">' . $contest->info['name'] . '</a>';
if ($contest->progress() == CONTEST_NOT_STARTED) {
$cur_rest_second = $contest->info['start_time']->getTimestamp() - UOJTime::$time_now->getTimestamp();
if ($cur_rest_second < $rest_second) {
$upcoming_contest_name = $contest->info['name'];
$upcoming_contest_href = '/contest/' . $contest->info['id'];
$rest_second = $cur_rest_second;
}
if ($contest->userHasRegistered(Auth::user())) {
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:green">' . UOJLocale::get('contests::registered') . '</a></sup>';
} else {
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:red" href="/contest/' . $contest->info['id'] . '/register">' . UOJLocale::get('contests::register') . '</a></sup>';
}
} elseif ($contest->progress() == CONTEST_IN_PROGRESS) {
if ($contest->allowExtraRegistration() && !$contest->userHasRegistered(Auth::user())) {
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:red" href="/contest/' . $contest->info['id'] . '/register">' . UOJLocale::get('contests::register') . ' (' . UOJLocale::get('contests::in progress') . ')' . '</a></sup>';
} else {
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:blue" href="/contest/' . $contest->info['id'] . '">' . UOJLocale::get('contests::in progress') . '</a></sup>';
}
} elseif ($contest->progress() == CONTEST_FINISHED) {
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:grey" href="/contest/' . $contest->info['id'] . '/standings">' . UOJLocale::get('contests::ended') . '</a></sup>';
} else {
if ($contest->basicRule() == 'OI') {
if ($contest->progress() == CONTEST_PENDING_FINAL_TEST) {
$contest_name_link .= '<sup><a style="color:blue" href="/contest/' . $contest->info['id'] . '">' . UOJLocale::get('contests::pending final test') . '</a></sup>';
} elseif ($contest->progress() == CONTEST_TESTING) {
$contest_name_link .= '<sup><a style="color:blue" href="/contest/' . $contest->info['id'] . '">' . UOJLocale::get('contests::final testing') . '</a></sup>';
}
2022-11-06 02:26:21 +00:00
} elseif ($contest->basicRule() == 'ACM' || $contest->basicRule() == 'IOI') {
$contest_name_link .= '<sup><a style="color:blue" href="/contest/' . $contest->info['id'] . '">' . UOJLocale::get('contests::official results to be announced') . '</a></sup>';
2016-07-18 16:39:37 +00:00
}
}
2022-11-06 02:26:21 +00:00
$last_hour = round($contest->info['last_min'] / 60, 2);
echo '<tr>';
echo '<td>', $contest_name_link, '</td>';
echo '<td>', '<a class="text-decoration-none" href="' . HTML::timeanddate_url($contest->info['start_time'], ['duration' => $contest->info['last_min']]) . '">' . $contest->info['start_time_str'] . '</a>', '</td>';
echo '<td>', UOJLocale::get('hours', $last_hour), '</td>';
echo '<td>', '<a class="text-decoration-none" href="/contest/' . $contest->info['id'] . '/registrants">', '<i class="bi bi-person-fill"></i>', ' &times;' . $contest->info['player_num'] . '</a>', '</td>';
2022-11-11 23:10:34 +00:00
echo HTML::tag('td', [], $contest->getZanBlock());
2022-11-06 02:26:21 +00:00
echo '</tr>';
}
?>
2016-07-18 16:39:37 +00:00
<?php echoUOJPageHeader(UOJLocale::get('contests')) ?>
2022-10-22 13:12:13 +00:00
<!-- title container -->
2022-09-24 05:39:55 +00:00
<div class="d-flex justify-content-between">
2022-11-06 02:26:21 +00:00
<h1>
<?= UOJLocale::get('contests') ?>
</h1>
2022-09-24 05:39:55 +00:00
2022-11-11 23:10:34 +00:00
<?php if (UOJContest::userCanCreateContest(Auth::user())) : ?>
2022-11-06 02:26:21 +00:00
<div class="text-end">
<a href="/contest/new" class="btn btn-primary"><?= UOJLocale::get('contests::add new contest') ?></a>
</div>
<?php endif ?>
2022-10-22 13:12:13 +00:00
</div>
<!-- end title container -->
2022-11-06 02:26:21 +00:00
<h2>
2022-10-22 13:12:13 +00:00
<?= UOJLocale::get('contests::current or upcoming contests') ?>
</h2>
2016-07-18 16:39:37 +00:00
<?php
2022-11-06 02:26:21 +00:00
$table_header = '';
$table_header .= '<tr>';
$table_header .= '<th>' . UOJLocale::get('contests::contest name') . '</th>';
$table_header .= '<th style="width:15em;">' . UOJLocale::get('contests::start time') . '</th>';
$table_header .= '<th style="width:100px;">' . UOJLocale::get('contests::duration') . '</th>';
$table_header .= '<th style="width:100px;">' . UOJLocale::get('contests::the number of registrants') . '</th>';
$table_header .= '<th style="width:180px;">' . UOJLocale::get('appraisal') . '</th>';
$table_header .= '</tr>';
$table_config = [
2023-02-17 13:50:04 +00:00
'page_len' => 50,
2022-11-06 02:26:21 +00:00
'div_classes' => ['card', 'mb-3'],
'table_classes' => ['table', 'uoj-table', 'mb-0', 'text-center'],
];
2022-11-11 23:10:34 +00:00
if (!UOJUser::checkPermission(Auth::user(), 'contests.view')) {
$table_config['post_filter'] = function ($info) {
return (new UOJContest($info))->userCanView(Auth::user());
};
}
2022-11-06 02:26:21 +00:00
echoLongTable(
['*'],
'contests',
[["status", "!=", 'finished']],
'order by start_time asc, id asc',
$table_header,
'echoContest',
2023-02-17 13:50:04 +00:00
$table_config + ['echo_full' => true],
2022-11-06 02:26:21 +00:00
);
if ($rest_second <= 86400) {
$notification = json_encode($upcoming_contest_name . " 已经开始了。是否要跳转到比赛页面?");
echo <<<EOD
2016-07-18 16:39:37 +00:00
<div class="text-center bot-buffer-lg">
2022-09-24 04:10:30 +00:00
<div class="text-secondary">$upcoming_contest_name 倒计时</div>
2016-07-18 16:39:37 +00:00
<div id="contest-countdown"></div>
<script type="text/javascript">
$('#contest-countdown').countdown($rest_second, function() {
2021-04-25 13:58:47 +00:00
if (confirm($notification)) {
2016-07-18 16:39:37 +00:00
window.location.href = "$upcoming_contest_href";
}
});
</script>
</div>
EOD;
2022-11-06 02:26:21 +00:00
}
?>
2016-07-18 16:39:37 +00:00
2022-11-06 02:26:21 +00:00
<h2>
2022-10-22 13:12:13 +00:00
<?= UOJLocale::get('contests::ended contests') ?>
</h2>
2022-11-06 02:26:21 +00:00
2016-07-18 16:39:37 +00:00
<?php
2022-11-06 02:26:21 +00:00
echoLongTable(
['*'],
'contests',
['status' => 'finished'],
'order by start_time desc, id desc',
$table_header,
'echoContest',
$table_config
);
?>
2016-07-18 16:39:37 +00:00
<?php echoUOJPageFooter() ?>