S2OJ/web/app/controllers/contests.php

139 lines
5.3 KiB
PHP
Raw Normal View History

2016-07-18 16:39:37 +00:00
<?php
requirePHPLib('form');
2022-03-17 04:00:03 +00:00
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin();
2022-03-17 04:00:03 +00:00
}
2022-09-24 04:10:30 +00:00
if (!isset($_COOKIE['bootstrap4'])) {
$REQUIRE_LIB['bootstrap5'] = '';
}
2016-07-18 16:39:37 +00:00
$upcoming_contest_name = null;
$upcoming_contest_href = null;
$rest_second = 1000000;
function echoContest($contest) {
2022-09-24 04:10:30 +00:00
global $myUser, $upcoming_contest_name, $upcoming_contest_href, $rest_second, $REQUIRE_LIB;
$a_class = ' ';
if (isset($REQUIRE_LIB['bootstrap5'])) {
$a_class = ' class="text-decoration-none" ';
}
2016-07-18 16:39:37 +00:00
$contest_name_link = <<<EOD
2022-09-24 04:10:30 +00:00
<a $a_class href="/contest/{$contest['id']}">{$contest['name']}</a>
2016-07-18 16:39:37 +00:00
EOD;
genMoreContestInfo($contest);
if ($contest['cur_progress'] == CONTEST_NOT_STARTED) {
$cur_rest_second = $contest['start_time']->getTimestamp() - UOJTime::$time_now->getTimestamp();
if ($cur_rest_second < $rest_second) {
$upcoming_contest_name = $contest['name'];
$upcoming_contest_href = "/contest/{$contest['id']}";
$rest_second = $cur_rest_second;
}
if ($myUser != null && hasRegistered($myUser, $contest)) {
2022-09-24 04:10:30 +00:00
$contest_name_link .= '<sup><a '.$a_class.' style="color:green">'.UOJLocale::get('contests::registered').'</a></sup>';
2016-07-18 16:39:37 +00:00
} else {
2022-09-24 04:10:30 +00:00
$contest_name_link .= '<sup><a '.$a_class.' style="color:red" href="/contest/'.$contest['id'].'/register">'.UOJLocale::get('contests::register').'</a></sup>';
2016-07-18 16:39:37 +00:00
}
} elseif ($contest['cur_progress'] == CONTEST_IN_PROGRESS) {
2022-09-24 04:10:30 +00:00
$contest_name_link .= '<sup><a '.$a_class.' style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::in progress').'</a></sup>';
2016-07-18 16:39:37 +00:00
} elseif ($contest['cur_progress'] == CONTEST_PENDING_FINAL_TEST) {
2022-09-24 04:10:30 +00:00
$contest_name_link .= '<sup><a '.$a_class.' style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::pending final test').'</a></sup>';
2016-07-18 16:39:37 +00:00
} elseif ($contest['cur_progress'] == CONTEST_TESTING) {
2022-09-24 04:10:30 +00:00
$contest_name_link .= '<sup><a '.$a_class.' style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::final testing').'</a></sup>';
2016-07-18 16:39:37 +00:00
} elseif ($contest['cur_progress'] == CONTEST_FINISHED) {
2022-09-24 04:10:30 +00:00
$contest_name_link .= '<sup><a '.$a_class.'style="color:grey" href="/contest/'.$contest['id'].'/standings">'.UOJLocale::get('contests::ended').'</a></sup>';
2016-07-18 16:39:37 +00:00
}
$last_hour = round($contest['last_min'] / 60, 2);
$click_zan_block = getClickZanBlock('C', $contest['id'], $contest['zan']);
echo '<tr>';
echo '<td>', $contest_name_link, '</td>';
2022-09-24 04:10:30 +00:00
echo '<td>', '<a'.$a_class.'href="'.HTML::timeanddate_url($contest['start_time'], array('duration' => $contest['last_min'])).'">'.$contest['start_time_str'].'</a>', '</td>';
2016-07-18 16:39:37 +00:00
echo '<td>', UOJLocale::get('hours', $last_hour), '</td>';
echo '<td>', '<a'.$a_class.'href="/contest/'.$contest['id'].'/registrants">';
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo '<i class="bi bi-person-fill"></i>';
} else {
echo '<span class="glyphicon glyphicon-user"></span>';
}
echo ' &times;'.$contest['player_num'].'</a>', '</td>';
2016-07-18 16:39:37 +00:00
echo '<td>', '<div class="text-left">'.$click_zan_block.'</div>', '</td>';
echo '</tr>';
}
2022-09-18 04:58:35 +00:00
?>
2016-07-18 16:39:37 +00:00
<?php echoUOJPageHeader(UOJLocale::get('contests')) ?>
2022-09-24 05:39:55 +00:00
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="d-flex justify-content-between">
<?php endif ?>
<h1 class="h2">
<?= UOJLocale::get('contests') ?>
</h1>
2022-09-24 04:10:30 +00:00
<?php
if (isSuperUser($myUser)) {
if (isset($REQUIRE_LIB['bootstrap5'])) {
echo '<div class="text-end">';
} else {
echo '<div class="text-right">';
}
echo '<a href="/contest/new" class="btn btn-primary">'.UOJLocale::get('contests::add new contest').'</a>';
echo '</div>';
}
?>
2022-09-24 05:39:55 +00:00
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div>
<?php endif ?>
2016-07-18 16:39:37 +00:00
<h4><?= UOJLocale::get('contests::current or upcoming contests') ?></h4>
<?php
2022-09-24 04:10:30 +00:00
$table_header = '';
2016-07-18 16:39:37 +00:00
$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>';
2022-09-24 04:10:30 +00:00
$table_config = array('page_len' => 40);
if (isset($REQUIRE_LIB['bootstrap5'])) {
$table_config['div_classes'] = array('card', 'mb-3');
$table_config['table_classes'] = array('table', 'uoj-table', 'mb-0', 'text-center');
2022-09-24 04:10:30 +00:00
}
echoLongTable(array('*'), 'contests', "status != 'finished'", 'order by start_time asc, id asc', $table_header,
2016-07-18 16:39:37 +00:00
echoContest,
2022-09-24 04:10:30 +00:00
$table_config
2016-07-18 16:39:37 +00:00
);
if ($rest_second <= 86400) {
$notification = json_encode($upcoming_contest_name . " 已经开始了。是否要跳转到比赛页面?");
2016-07-18 16:39:37 +00:00
echo <<<EOD
<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-09-18 04:58:35 +00:00
?>
2016-07-18 16:39:37 +00:00
<h4><?= UOJLocale::get('contests::ended contests') ?></h4>
<?php
2022-09-24 04:10:30 +00:00
echoLongTable(array('*'), 'contests', "status = 'finished'", 'order by start_time desc, id desc', $table_header,
echoContest,
$table_config
);
2022-09-18 04:58:35 +00:00
?>
2016-07-18 16:39:37 +00:00
<?php echoUOJPageFooter() ?>