2016-07-18 16:39:37 +00:00
< ? php
2022-10-22 13:12:13 +00:00
requireLib ( 'bootstrap5' );
2016-07-18 16:39:37 +00:00
requirePHPLib ( 'form' );
2022-03-17 04:00:03 +00:00
2022-10-07 09:29:26 +00:00
if ( ! Auth :: check () && UOJConfig :: $data [ 'switch' ][ 'force-login' ]) {
2022-10-06 12:28:43 +00:00
redirectToLogin ();
2022-03-17 04:00:03 +00:00
}
2022-10-07 09:29:26 +00:00
if ( ! isNormalUser ( $myUser ) && UOJConfig :: $data [ 'switch' ][ 'force-login' ]) {
2022-04-03 10:18:17 +00:00
become403Page ();
}
2016-07-18 16:39:37 +00:00
if ( ! validateUInt ( $_GET [ 'id' ]) || ! ( $contest = queryContest ( $_GET [ 'id' ]))) {
become404Page ();
}
2022-10-01 13:26:01 +00:00
2016-07-18 16:39:37 +00:00
genMoreContestInfo ( $contest );
2022-03-17 03:02:44 +00:00
2022-03-20 00:07:46 +00:00
if ( isSuperUser ( $myUser )) {
$add_new_contestant_form = new UOJForm ( 'add_new_contestant_form' );
$add_new_contestant_form -> addInput ( 'new_username' , 'text' , '用户名' , '' ,
function ( $x ) {
global $contest ;
2022-03-20 09:19:07 +00:00
if ( ! validateUsername ( $x )) {
return '用户名不合法' ;
}
2022-03-20 00:07:46 +00:00
$user = queryUser ( $x );
2022-03-20 09:19:07 +00:00
if ( ! $user ) {
return '用户不存在' ;
}
2022-03-20 00:07:46 +00:00
if ( hasRegistered ( $user , $contest )) {
return '该用户已经报名' ;
}
return '' ;
},
null
);
$add_new_contestant_form -> submit_button_config [ 'align' ] = 'compressed' ;
$add_new_contestant_form -> submit_button_config [ 'text' ] = '注册该用户' ;
$add_new_contestant_form -> handle = function () {
global $contest ;
2022-09-21 04:41:29 +00:00
$username = $_POST [ 'new_username' ];
2022-03-20 00:07:46 +00:00
2022-09-21 04:41:29 +00:00
DB :: query ( " replace into contests_registrants (username, contest_id, has_participated) values (' { $username } ', { $contest [ 'id' ] } , 0) " );
2022-03-20 00:07:46 +00:00
updateContestPlayerNum ( $contest );
};
$add_new_contestant_form -> runAtServer ();
$add_group_to_contest_form = new UOJForm ( 'add_group_to_contest' );
$add_group_to_contest_form -> addInput ( 'group_id' , 'text' , '小组 ID' , '' ,
function ( $x ) {
global $contest ;
2022-03-20 09:19:07 +00:00
if ( ! validateUInt ( $x )) {
return '小组 ID 不合法' ;
}
2022-03-20 00:07:46 +00:00
$group = queryGroup ( $x );
2022-03-20 09:19:07 +00:00
if ( ! $group ) {
return '小组不存在' ;
}
2022-03-20 00:07:46 +00:00
return '' ;
},
null
);
$add_group_to_contest_form -> submit_button_config [ 'align' ] = 'compressed' ;
$add_group_to_contest_form -> submit_button_config [ 'text' ] = '注册该小组中的用户' ;
$add_group_to_contest_form -> handle = function () {
global $contest ;
$group_id = $_POST [ 'group_id' ];
2022-03-24 04:48:37 +00:00
$users = DB :: selectAll ( " select b.username as username from groups_users a inner join user_info b on a.username = b.username where a.group_id = $group_id " );
2022-03-20 00:07:46 +00:00
foreach ( $users as $user ) {
2022-03-21 03:10:54 +00:00
DB :: query ( " replace into contests_registrants (username, contest_id, has_participated) values (' { $user [ 'username' ] } ', { $contest [ 'id' ] } , 0) " );
2022-03-20 00:07:46 +00:00
}
updateContestPlayerNum ( $contest );
};
$add_group_to_contest_form -> runAtServer ();
2022-09-20 03:02:37 +00:00
$remove_user_from_contest_form = new UOJForm ( 'remove_user_from_contest' );
$remove_user_from_contest_form -> addInput ( 'remove_username' , 'text' , '用户名' , '' ,
function ( $x ) {
global $contest ;
if ( ! validateUsername ( $x )) {
return '用户名不合法' ;
}
2022-09-21 04:41:29 +00:00
$user = queryUser ( $x );
if ( ! $user ) {
2022-09-20 03:02:37 +00:00
return '用户不存在' ;
}
2022-09-21 04:41:29 +00:00
if ( ! hasRegistered ( $user , $contest )) {
return '该用户未报名' ;
}
2022-09-20 03:02:37 +00:00
return '' ;
},
null
);
$remove_user_from_contest_form -> submit_button_config [ 'align' ] = 'compressed' ;
$remove_user_from_contest_form -> submit_button_config [ 'text' ] = '移除该用户' ;
$remove_user_from_contest_form -> submit_button_config [ 'class_str' ] = 'mt-2 btn btn-danger' ;
$remove_user_from_contest_form -> handle = function () {
global $contest ;
2022-09-21 04:41:29 +00:00
$username = $_POST [ 'remove_username' ];
DB :: query ( " delete from contests_registrants where username = ' { $username } ' and contest_id = { $contest [ 'id' ] } " );
2022-09-20 03:02:37 +00:00
updateContestPlayerNum ( $contest );
};
$remove_user_from_contest_form -> runAtServer ();
2022-09-21 06:34:16 +00:00
$force_set_user_participated_form = new UOJForm ( 'force_set_user_participated' );
$force_set_user_participated_form -> addInput ( 'force_set_username' , 'text' , '用户名' , '' ,
function ( $x ) {
global $contest ;
if ( ! validateUsername ( $x )) {
return '用户名不合法' ;
}
$user = queryUser ( $x );
if ( ! $user ) {
return '用户不存在' ;
}
if ( ! hasRegistered ( $user , $contest )) {
return '该用户未报名' ;
}
return '' ;
},
null
);
$force_set_user_participated_form -> submit_button_config [ 'align' ] = 'compressed' ;
$force_set_user_participated_form -> submit_button_config [ 'text' ] = '强制参赛' ;
$force_set_user_participated_form -> submit_button_config [ 'class_str' ] = 'mt-2 btn btn-warning' ;
$force_set_user_participated_form -> handle = function () {
global $contest ;
$username = $_POST [ 'force_set_username' ];
DB :: query ( " update contests_registrants set has_participated = 1 where username = ' { $username } ' and contest_id = { $contest [ 'id' ] } " );
updateContestPlayerNum ( $contest );
};
$force_set_user_participated_form -> runAtServer ();
2022-03-20 00:07:46 +00:00
}
2016-07-18 16:39:37 +00:00
$has_contest_permission = hasContestPermission ( $myUser , $contest );
$show_ip = $has_contest_permission ;
if ( $contest [ 'cur_progress' ] == CONTEST_NOT_STARTED ) {
$iHasRegistered = $myUser != null && hasRegistered ( $myUser , $contest );
if ( $iHasRegistered ) {
$unregister_form = new UOJForm ( 'unregister' );
$unregister_form -> handle = function () {
global $myUser , $contest ;
2017-11-25 15:29:18 +00:00
DB :: query ( " delete from contests_registrants where username = ' { $myUser [ 'username' ] } ' and contest_id = { $contest [ 'id' ] } " );
2016-07-18 16:39:37 +00:00
updateContestPlayerNum ( $contest );
};
2022-10-02 12:54:25 +00:00
$unregister_form -> submit_button_config [ 'align' ] = 'right' ;
2016-07-18 16:39:37 +00:00
$unregister_form -> submit_button_config [ 'class_str' ] = 'btn btn-danger btn-xs' ;
$unregister_form -> submit_button_config [ 'text' ] = '取消报名' ;
$unregister_form -> succ_href = " /contests " ;
$unregister_form -> runAtServer ();
}
}
2022-09-18 04:58:35 +00:00
?>
2016-07-18 16:39:37 +00:00
< ? php echoUOJPageHeader ( HTML :: stripTags ( $contest [ 'name' ]) . ' - ' . UOJLocale :: get ( 'contests::contest registrants' )) ?>
2022-10-22 13:12:13 +00:00
< h1 class = " h2 text-center " >
< ? = $contest [ 'name' ] ?>
</ h1 >
2016-07-18 16:39:37 +00:00
< ? php if ( $contest [ 'cur_progress' ] == CONTEST_NOT_STARTED ) : ?>
< ? php if ( $iHasRegistered ) : ?>
2022-10-02 12:54:25 +00:00
< div class = " row " >
< div class = " col-6 " >
2022-10-23 12:39:11 +00:00
< a class = " text-decoration-none text-success " > 已报名 </ a >
2022-10-02 12:54:25 +00:00
</ div >
2022-10-22 13:12:13 +00:00
< div class = " col-6 text-end " >
2022-10-02 12:54:25 +00:00
< ? php $unregister_form -> printHTML (); ?>
</ div >
2016-07-18 16:39:37 +00:00
</ div >
< ? php else : ?>
2022-10-22 13:12:13 +00:00
< div > 当前尚未报名,您可以 < a class = " text-decoration-none text-danger " href = " /contest/<?= $contest['id'] ?>/register " > 报名 </ a > 。 </ div >
2016-07-18 16:39:37 +00:00
< ? php endif ?>
2022-10-22 13:12:13 +00:00
< div class = " mt-2 " ></ div >
2016-07-18 16:39:37 +00:00
< ? php endif ?>
< ? php
2022-10-01 13:26:01 +00:00
$header_row = '<tr><th>#</th><th>' . UOJLocale :: get ( 'username' ) . '</th>' ;
if ( $show_ip ) {
$header_row .= '<th>remote_addr</th><th>http_x_forwarded_for</th>' ;
}
if ( $has_contest_permission ) {
$header_row .= '<th>是否参赛</th>' ;
}
$header_row .= '</tr>' ;
2022-10-22 13:12:13 +00:00
echoLongTable (
[ '*' ],
'contests_registrants' ,
" contest_id = { $contest [ 'id' ] } " ,
'order by username desc' ,
2022-10-01 13:26:01 +00:00
$header_row ,
2022-10-23 12:39:11 +00:00
function ( $contestant , $num ) use ( $myUser , $has_contest_permission , $show_ip , $has_participated ) {
2022-10-22 13:12:13 +00:00
$user = queryUser ( $contestant [ 'username' ]);
2022-10-23 12:39:11 +00:00
echo '<tr>' ;
2022-10-01 13:26:01 +00:00
echo '<td>' . $num . '</td>' ;
2022-10-22 13:12:13 +00:00
echo '<td>' . getUserLink ( $contestant [ 'username' ]) . '</td>' ;
2022-10-01 13:26:01 +00:00
if ( $show_ip ) {
echo '<td>' . $user [ 'remote_addr' ] . '</td>' ;
echo '<td>' . $user [ 'http_x_forwarded_for' ] . '</td>' ;
}
if ( $has_contest_permission ) {
2022-10-22 13:12:13 +00:00
echo '<td>' . ( $contestant [ 'has_participated' ] ? 'Yes' : 'No' ) . '</td>' ;
2022-10-01 13:26:01 +00:00
}
echo '</tr>' ;
},
2022-10-22 13:12:13 +00:00
[
'page_len' => 50 ,
'get_row_index' => '' ,
'div_classes' => [ 'table-responsive' , 'card' , 'mb-3' ],
'table_classes' => [ 'table' , 'uoj-table' , 'mb-0' , 'text-center' ],
]
2022-10-01 13:26:01 +00:00
);
2022-09-18 04:58:35 +00:00
?>
2022-10-22 13:12:13 +00:00
< ? php
if ( isset ( $add_new_contestant_form )) {
$add_new_contestant_form -> printHTML ();
}
if ( isset ( $add_group_to_contest_form )) {
$add_group_to_contest_form -> printHTML ();
}
if ( isset ( $remove_user_from_contest_form )) {
$remove_user_from_contest_form -> printHTML ();
}
if ( isset ( $force_set_user_participated_form )) {
$force_set_user_participated_form -> printHTML ();
}
?>
2022-03-17 03:02:44 +00:00
< ? php echoUOJPageFooter () ?>