S2OJ/web/app/controllers/contest_members.php

264 lines
7.5 KiB
PHP
Raw Permalink 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();
UOJContest::init(UOJRequest::get('id')) || UOJResponse::page404();
2022-03-17 04:00:03 +00:00
2022-11-06 02:26:21 +00:00
$contest = UOJContest::info();
2022-04-03 10:18:17 +00:00
2022-11-06 02:26:21 +00:00
$is_manager = UOJContest::cur()->userCanManage(Auth::user());
$show_ip = isSuperUser(Auth::user());
2022-11-06 02:26:21 +00:00
if ($is_manager) {
$add_new_contestant_form = new UOJForm('add_new_contestant_form');
2022-11-06 02:26:21 +00:00
$add_new_contestant_form->addInput(
'new_username',
[
'placeholder' => '用户名',
'validator_php' => function ($username, &$vdata) {
$user = UOJUser::query($username);
2022-11-06 02:26:21 +00:00
if (!$user) {
return '用户不存在';
}
2022-03-20 00:07:46 +00:00
if (UOJContest::cur()->userHasRegistered($user)) {
return '该用户已经报名';
}
2022-11-06 02:26:21 +00:00
$vdata['user'] = $user;
2022-11-06 02:26:21 +00:00
return '';
},
]
2022-11-06 02:26:21 +00:00
);
$add_new_contestant_form->config['submit_container']['class'] = 'mt-3 text-center';
$add_new_contestant_form->config['submit_button']['class'] = 'btn btn-secondary';
$add_new_contestant_form->config['submit_button']['text'] = '注册该用户';
2022-11-06 02:26:21 +00:00
$add_new_contestant_form->handle = function (&$vdata) {
UOJContest::cur()->userRegister($vdata['user']);
};
$add_new_contestant_form->runAtServer();
$add_group_to_contest_form = new UOJForm('add_group_to_contest');
2022-11-06 02:26:21 +00:00
$add_group_to_contest_form->addInput(
'group_id',
[
'placeholder' => '小组 ID',
'validator_php' => function ($group_id, &$vdata) {
$group = UOJGroup::query($group_id);
if (!$group) {
return '小组不存在';
}
$vdata['group'] = $group;
return '';
},
]
2022-11-06 02:26:21 +00:00
);
$add_group_to_contest_form->config['submit_container']['class'] = 'mt-3 text-center';
$add_group_to_contest_form->config['submit_button']['class'] = 'btn btn-secondary';
$add_group_to_contest_form->config['submit_button']['text'] = '注册该小组中的用户';
2022-11-06 02:26:21 +00:00
$add_group_to_contest_form->handle = function (&$vdata) {
2022-11-11 00:20:33 +00:00
$usernames = $vdata['group']->getUsernames();
foreach ($usernames as $username) {
$user = UOJUser::query($username);
2022-11-06 02:26:21 +00:00
UOJContest::cur()->userRegister($user);
}
};
$add_group_to_contest_form->runAtServer();
$remove_user_from_contest_form = new UOJForm('remove_user_from_contest');
2022-11-06 02:26:21 +00:00
$remove_user_from_contest_form->addInput(
'remove_username',
[
'placeholder' => '用户名',
'validator_php' => function ($username, &$vdata) {
$user = UOJUser::query($username);
2022-11-06 02:26:21 +00:00
if (!$user) {
return '用户不存在';
}
2022-11-06 02:26:21 +00:00
if (!UOJContest::cur()->userHasRegistered($user)) {
return '该用户未报名';
}
2022-11-06 02:26:21 +00:00
$vdata['user'] = $user;
2022-03-20 00:07:46 +00:00
return '';
},
]
2022-11-06 02:26:21 +00:00
);
$remove_user_from_contest_form->config['submit_container']['class'] = 'mt-3 text-center';
$remove_user_from_contest_form->config['submit_button']['class'] = 'btn btn-danger';
$remove_user_from_contest_form->config['submit_button']['text'] = '移除该用户';
2022-11-06 02:26:21 +00:00
$remove_user_from_contest_form->handle = function (&$vdata) {
UOJContest::cur()->userUnregister($vdata['user']);
};
$remove_user_from_contest_form->runAtServer();
$force_set_user_participated_form = new UOJForm('force_set_user_participated');
2022-11-06 02:26:21 +00:00
$force_set_user_participated_form->addInput(
'force_set_username',
[
'placeholder' => '用户名',
'validator_php' => function ($username, &$vdata) {
$user = UOJUser::query($username);
2022-11-06 02:26:21 +00:00
if (!$user) {
return '用户不存在';
}
2022-11-06 02:26:21 +00:00
if (!UOJContest::cur()->userHasRegistered($user)) {
return '该用户未报名';
}
2022-11-06 02:26:21 +00:00
$vdata['user'] = $user;
2022-11-06 02:26:21 +00:00
return '';
},
]
2022-11-06 02:26:21 +00:00
);
$force_set_user_participated_form->config['submit_container']['class'] = 'mt-3 text-center';
$force_set_user_participated_form->config['submit_button']['class'] = 'btn btn-warning';
$force_set_user_participated_form->config['submit_button']['text'] = '强制参赛';
2022-11-06 02:26:21 +00:00
$force_set_user_participated_form->handle = function (&$vdata) {
UOJContest::cur()->markUserAsParticipated($vdata['user']);
};
$force_set_user_participated_form->runAtServer();
}
if ($contest['cur_progress'] == CONTEST_NOT_STARTED) {
$iHasRegistered = UOJContest::cur()->userHasRegistered(Auth::user());
if ($iHasRegistered) {
if ($iHasRegistered && UOJContest::cur()->freeRegistration()) {
$unregister_form = new UOJForm('unregister');
2022-11-06 02:26:21 +00:00
$unregister_form->handle = function () {
UOJContest::cur()->userUnregister(Auth::user());
2016-07-18 16:39:37 +00:00
};
$unregister_form->config['submit_container']['class'] = 'text-end';
$unregister_form->config['submit_button']['class'] = 'btn btn-danger btn-xs';
$unregister_form->config['submit_button']['text'] = '取消报名';
2016-07-18 16:39:37 +00:00
$unregister_form->succ_href = "/contests";
$unregister_form->runAtServer();
}
}
2022-11-06 02:26:21 +00:00
}
?>
<?php echoUOJPageHeader(HTML::stripTags(UOJContest::info('name')) . ' - ' . UOJLocale::get('contests::contest registrants')) ?>
2016-07-18 16:39:37 +00:00
2022-11-06 02:26:21 +00:00
<h1 class="text-center">
<?= UOJContest::info('name') ?>
2022-10-22 13:12:13 +00:00
</h1>
<?php if (UOJContest::cur()->progress() == CONTEST_NOT_STARTED) : ?>
2022-11-06 02:26:21 +00:00
<?php if ($iHasRegistered) : ?>
<div class="row mb-3">
2022-10-02 12:54:25 +00:00
<div class="col-6">
<a class="text-decoration-none text-success">已报名</a>
2022-10-02 12:54:25 +00:00
</div>
<div class="col-6">
<?php $unregister_form->printHTML() ?>
2022-10-02 12:54:25 +00:00
</div>
2016-07-18 16:39:37 +00:00
</div>
2022-11-06 02:26:21 +00:00
<?php else : ?>
<div class="mb-3">
当前尚未报名,您可以 <a class="text-decoration-none text-danger" href="/contest/<?= UOJContest::info('id') ?>/register">报名</a>
</div>
2016-07-18 16:39:37 +00:00
<?php endif ?>
<?php endif ?>
<?php
2022-11-11 00:20:33 +00:00
$header_row = '<tr>';
$header_row .= '<th>#</th><th>' . UOJLocale::get('username') . '</th>';
2022-11-06 02:26:21 +00:00
if ($show_ip) {
$header_row .= '<th>remote_addr</th><th>http_x_forwarded_for</th>';
}
if ($is_manager) {
$header_row .= '<th>是否参赛</th>';
}
$header_row .= '</tr>';
echoLongTable(
['*'],
'contests_registrants',
['contest_id' => $contest['id']],
'order by username desc',
$header_row,
function ($contestant, $num) use ($is_manager, $show_ip) {
$user = UOJUser::query($contestant['username']);
echo '<tr>';
echo '<td>' . $num . '</td>';
echo '<td>' . UOJUser::getLink($user) . '</td>';
2022-11-06 02:26:21 +00:00
if ($show_ip) {
echo '<td>' . $user['remote_addr'] . '</td>';
echo '<td>' . $user['http_x_forwarded_for'] . '</td>';
}
if ($is_manager) {
echo '<td>' . ($contestant['has_participated'] ? 'Yes' : 'No') . '</td>';
}
echo '</tr>';
},
[
'page_len' => 50,
'get_row_index' => '',
'div_classes' => ['table-responsive', 'card', 'mb-3'],
'table_classes' => ['table', 'uoj-table', 'mb-0', 'text-center'],
]
);
?>
2022-10-22 13:12:13 +00:00
<div class="row gy-2 gx-3 align-items-center">
<?php if (isset($add_new_contestant_form)) : ?>
<div class="col-auto">
<div class="card">
<div class="card-header fw-bold">添加参赛者</div>
<div class="card-body">
<?php $add_new_contestant_form->printHTML() ?>
</div>
</div>
</div>
<?php endif ?>
<?php if (isset($add_group_to_contest_form)) : ?>
<div class="col-auto">
<div class="card">
<div class="card-header fw-bold">小组报名</div>
<div class="card-body">
<?php $add_group_to_contest_form->printHTML() ?>
</div>
</div>
</div>
<?php endif ?>
<?php if (isset($remove_user_from_contest_form)) : ?>
<div class="col-auto">
<div class="card border-danger">
<div class="card-header fw-bold text-bg-danger">移除选手</div>
<div class="card-body">
<?php $remove_user_from_contest_form->printHTML() ?>
</div>
</div>
</div>
<?php endif ?>
<?php if (isset($force_set_user_participated_form)) : ?>
<div class="col-auto">
<div class="card">
<div class="card-header fw-bold">强制参赛</div>
<div class="card-body">
<?php $force_set_user_participated_form->printHTML() ?>
</div>
</div>
</div>
<?php endif ?>
</div>
2022-03-17 03:02:44 +00:00
<?php echoUOJPageFooter() ?>