2016-07-18 16:39:37 +00:00
< ? php
2022-10-22 11:24:48 +00:00
requireLib ( 'bootstrap5' );
2016-07-18 16:39:37 +00:00
requirePHPLib ( 'form' );
requirePHPLib ( 'judger' );
2019-06-14 15:30:02 +00:00
requirePHPLib ( 'data' );
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-04-03 10:18:17 +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 ();
}
2022-09-24 02:18:55 +00:00
2016-07-18 16:39:37 +00:00
2022-03-17 13:52:10 +00:00
if ( isSuperUser ( $myUser ) || isProblemManager ( $myUser ) || isProblemUploader ( $myUser )) {
2016-07-18 16:39:37 +00:00
$new_problem_form = new UOJForm ( 'new_problem' );
$new_problem_form -> handle = function () {
2022-09-19 08:02:44 +00:00
global $myUser ;
2022-03-17 13:52:10 +00:00
DB :: query ( " insert into problems (title, uploader, is_hidden, submission_requirement) values ('New Problem', ' { $myUser [ 'username' ] } ', 1, ' { }') " );
2017-11-25 15:29:18 +00:00
$id = DB :: insert_id ();
DB :: query ( " insert into problems_contents (id, statement, statement_md) values ( $id , '', '') " );
2019-06-14 15:30:02 +00:00
dataNewProblem ( $id );
2016-07-18 16:39:37 +00:00
};
$new_problem_form -> submit_button_config [ 'align' ] = 'right' ;
$new_problem_form -> submit_button_config [ 'class_str' ] = 'btn btn-primary' ;
$new_problem_form -> submit_button_config [ 'text' ] = UOJLocale :: get ( 'problems::add new' );
$new_problem_form -> submit_button_config [ 'smart_confirm' ] = '' ;
$new_problem_form -> runAtServer ();
}
function echoProblem ( $problem ) {
2022-10-11 02:31:54 +00:00
global $myUser ;
2022-09-24 02:18:55 +00:00
2016-07-18 16:39:37 +00:00
if ( isProblemVisibleToUser ( $problem , $myUser )) {
echo '<tr class="text-center">' ;
if ( $problem [ 'submission_id' ]) {
2020-08-29 06:48:54 +00:00
echo '<td class="table-success">' ;
2016-07-18 16:39:37 +00:00
} else {
echo '<td>' ;
}
echo '#' , $problem [ 'id' ], '</td>' ;
2022-10-10 00:18:55 +00:00
echo '<td class="text-start">' ;
echo '<a class="text-decoration-none" href="/problem/' , $problem [ 'id' ], '">' , $problem [ 'title' ], '</a>' ;
2022-10-08 04:07:49 +00:00
if ( $problem [ 'uploader' ] == $myUser [ 'username' ]) {
echo ' <span class="badge text-white bg-info">' , UOJLocale :: get ( 'problems::my problem' ) , '</span> ' ;
}
2022-10-08 04:04:54 +00:00
if ( $problem [ 'is_hidden' ]) {
echo ' <span class="badge text-bg-danger"><i class="bi bi-eye-slash-fill"></i> ' , UOJLocale :: get ( 'hidden' ), '</span> ' ;
}
2016-07-18 16:39:37 +00:00
if ( isset ( $_COOKIE [ 'show_tags_mode' ])) {
foreach ( queryProblemTags ( $problem [ 'id' ]) as $tag ) {
2022-10-10 00:18:55 +00:00
echo ' <a class="uoj-problem-tag my-1">' ;
echo '<span class="badge bg-secondary">' ;
2022-09-24 02:18:55 +00:00
echo HTML :: escape ( $tag ), '</span>' ;
echo '</a> ' ;
2016-07-18 16:39:37 +00:00
}
}
echo '</td>' ;
if ( isset ( $_COOKIE [ 'show_submit_mode' ])) {
$perc = $problem [ 'submit_num' ] > 0 ? round ( 100 * $problem [ 'ac_num' ] / $problem [ 'submit_num' ]) : 0 ;
echo <<< EOD
2022-10-10 00:18:55 +00:00
< td >< a class = " text-decoration-none " href = " /submissions?problem_id= { $problem [ 'id' ] } &min_score=100&max_score=100 " >& times ;{ $problem [ 'ac_num' ]} </ a ></ td >
< td >< a class = " text-decoration-none " href = " /submissions?problem_id= { $problem [ 'id' ] } " >& times ;{ $problem [ 'submit_num' ]} </ a ></ td >
2016-07-18 16:39:37 +00:00
< td >
< div class = " progress bot-buffer-no " >
< div class = " progress-bar progress-bar-success " role = " progressbar " aria - valuenow = " $perc " aria - valuemin = " 0 " aria - valuemax = " 100 " style = " width: $perc %; min-width: 20px; " > { $perc } %</ div >
</ div >
</ td >
EOD ;
}
2022-09-29 02:10:24 +00:00
if ( isset ( $_COOKIE [ 'show_difficulty' ])) {
$extra_config = getProblemExtraConfig ( $problem );
if ( $extra_config [ 'difficulty' ] == 0 ) {
echo " <td></td> " ;
} else {
echo " <td> { $extra_config [ 'difficulty' ] } </td> " ;
}
}
2022-10-22 11:24:48 +00:00
echo '<td class="text-start">' , getClickZanBlock ( 'P' , $problem [ 'id' ], $problem [ 'zan' ], null , false ), '</td>' ;
2016-07-18 16:39:37 +00:00
echo '</tr>' ;
}
}
$cond = array ();
$search_tag = null ;
$cur_tab = isset ( $_GET [ 'tab' ]) ? $_GET [ 'tab' ] : 'all' ;
if ( $cur_tab == 'template' ) {
$search_tag = " 模板题 " ;
}
if ( isset ( $_GET [ 'tag' ])) {
$search_tag = $_GET [ 'tag' ];
}
if ( $search_tag ) {
$cond [] = " ' " . DB :: escape ( $search_tag ) . " ' in (select tag from problems_tags where problems_tags.problem_id = problems.id) " ;
}
2020-06-25 12:41:16 +00:00
if ( isset ( $_GET [ " search " ])) {
2022-10-11 02:31:54 +00:00
$cond [] = " (title like '% " . DB :: escape ( $_GET [ " search " ]) . " %' or id like '% " . DB :: escape ( $_GET [ " search " ]) . " %') " ;
}
if ( isset ( $_GET [ 'is_hidden' ])) {
$cond [] = 'is_hidden = 1' ;
}
if ( Auth :: check () && isset ( $_GET [ 'my' ])) {
$cond [] = " uploader = ' { $myUser [ 'username' ] } ' " ;
2017-11-25 04:00:00 +00:00
}
2016-07-18 16:39:37 +00:00
if ( $cond ) {
$cond = join ( $cond , ' and ' );
} else {
$cond = '1' ;
}
$header = '<tr>' ;
$header .= '<th class="text-center" style="width:5em;">ID</th>' ;
$header .= '<th>' . UOJLocale :: get ( 'problems::problem' ) . '</th>' ;
if ( isset ( $_COOKIE [ 'show_submit_mode' ])) {
2022-10-10 00:18:55 +00:00
$header .= '<th class="text-center" style="width:4em;">' . UOJLocale :: get ( 'problems::ac' ) . '</th>' ;
$header .= '<th class="text-center" style="width:4em;">' . UOJLocale :: get ( 'problems::submit' ) . '</th>' ;
$header .= '<th class="text-center" style="width:125px;">' . UOJLocale :: get ( 'problems::ac ratio' ) . '</th>' ;
2016-07-18 16:39:37 +00:00
}
2022-09-29 02:10:24 +00:00
if ( isset ( $_COOKIE [ 'show_difficulty' ])) {
$header .= '<th class="text-center" style="width:3em;">' . UOJLocale :: get ( 'problems::difficulty' ) . '</th>' ;
}
2022-10-03 12:47:32 +00:00
$header .= '<th class="text-center" style="width:100px;">' . UOJLocale :: get ( 'appraisal' ) . '</th>' ;
2016-07-18 16:39:37 +00:00
$header .= '</tr>' ;
$tabs_info = array (
'all' => array (
'name' => UOJLocale :: get ( 'problems::all problems' ),
'url' => " /problems "
),
'template' => array (
'name' => UOJLocale :: get ( 'problems::template problems' ),
'url' => " /problems/template "
)
);
2022-09-18 13:06:18 +00:00
$pag_config = array ( 'page_len' => 40 );
2022-09-29 02:10:24 +00:00
$pag_config [ 'col_names' ] = array ( 'best_ac_submissions.submission_id as submission_id' , 'problems.id as id' , 'problems.is_hidden as is_hidden' , 'problems.title as title' , 'problems.submit_num as submit_num' , 'problems.ac_num as ac_num' , 'problems.zan as zan' , 'problems.extra_config as extra_config' , 'problems.uploader as uploader' , 'problems.extra_config as extra_config' );
2016-07-18 16:39:37 +00:00
$pag_config [ 'table_name' ] = " problems left join best_ac_submissions on best_ac_submissions.submitter = ' { $myUser [ 'username' ] } ' and problems.id = best_ac_submissions.problem_id " ;
$pag_config [ 'cond' ] = $cond ;
$pag_config [ 'tail' ] = " order by id asc " ;
$pag = new Paginator ( $pag_config );
2022-10-10 00:18:55 +00:00
$div_classes = [ 'card' , 'my-3' , 'table-responsive' ];
$table_classes = [ 'table' , 'uoj-table' , 'mb-0' ];
2022-09-18 04:58:35 +00:00
?>
2016-07-18 16:39:37 +00:00
< ? php echoUOJPageHeader ( UOJLocale :: get ( 'problems' )) ?>
2022-09-24 05:39:55 +00:00
2022-09-25 06:16:36 +00:00
< div class = " row " >
2022-10-10 00:18:55 +00:00
<!-- left col -->
2022-09-26 23:57:01 +00:00
< div class = " col-lg-9 " >
2022-10-10 00:18:55 +00:00
<!-- title -->
2022-09-24 05:39:55 +00:00
< div class = " d-flex justify-content-between " >
2022-10-10 00:18:55 +00:00
2022-09-24 05:39:55 +00:00
< h1 class = " h2 " >
< ? = UOJLocale :: get ( 'problems' ) ?>
</ h1 >
2022-09-24 02:18:55 +00:00
< ? php if ( isSuperUser ( $myUser ) || isProblemManager ( $myUser ) || isProblemUploader ( $myUser )) : ?>
< div class = " text-end " >
< ? php $new_problem_form -> printHTML (); ?>
</ div >
< ? php endif ?>
2022-09-24 06:19:28 +00:00
</ div >
2022-10-10 00:18:55 +00:00
<!-- end title -->
2022-09-25 06:16:36 +00:00
2016-07-18 16:39:37 +00:00
< div class = " row " >
2022-10-10 00:18:55 +00:00
< div class = " col-sm-4 col-12 " >
2016-07-18 16:39:37 +00:00
< ? = HTML :: tablist ( $tabs_info , $cur_tab , 'nav-pills' ) ?>
</ div >
2022-10-10 00:18:55 +00:00
< div class = " text-end p-2 col-12 col-sm-8 " >
2022-09-24 02:18:55 +00:00
< div class = " form-check d-inline-block me-2 " >
2022-10-10 00:18:55 +00:00
< input
type = " checkbox " id = " input-show_tags_mode "
class = " form-check-input "
< ? = isset ( $_COOKIE [ 'show_tags_mode' ]) ? 'checked="checked" ' : '' ?>
/>
2022-09-24 02:18:55 +00:00
< label class = " form-check-label " for = " input-show_tags_mode " >
2022-10-10 00:18:55 +00:00
< ? = UOJLocale :: get ( 'problems::show tags' ) ?>
</ label >
2022-09-24 02:18:55 +00:00
</ div >
< div class = " form-check d-inline-block " >
2022-10-10 00:18:55 +00:00
< input
type = " checkbox " id = " input-show_submit_mode "
2022-09-24 02:18:55 +00:00
class = " form-check-input "
< ? = isset ( $_COOKIE [ 'show_submit_mode' ]) ? 'checked="checked" ' : '' ?>
/>
< label class = " form-check-label " for = " input-show_submit_mode " >
2022-10-10 00:18:55 +00:00
< ? = UOJLocale :: get ( 'problems::show statistics' ) ?>
</ label >
2022-09-24 02:18:55 +00:00
</ div >
2022-09-29 02:10:24 +00:00
< div class = " form-check d-inline-block " >
2022-10-10 00:18:55 +00:00
< input
type = " checkbox " id = " input-show_difficulty "
2022-09-29 02:10:24 +00:00
class = " form-check-input "
2022-10-10 00:18:55 +00:00
< ? = isset ( $_COOKIE [ 'show_difficulty' ]) ? 'checked="checked" ' : '' ?>
/>
2022-09-29 02:10:24 +00:00
< label class = " form-check-label " for = " input-show_difficulty " >
2022-10-10 00:18:55 +00:00
< ? = UOJLocale :: get ( 'problems::show difficulty' ) ?>
</ label >
2022-09-29 02:10:24 +00:00
</ div >
2016-07-18 16:39:37 +00:00
</ div >
</ div >
2022-09-25 06:16:36 +00:00
2022-09-26 23:57:01 +00:00
< div class = " text-center " >
2022-10-10 00:18:55 +00:00
< ? = $pag -> pagination () ?>
2022-09-26 23:57:01 +00:00
</ div >
2016-07-18 16:39:37 +00:00
< script type = " text/javascript " >
$ ( '#input-show_tags_mode' ) . click ( function () {
if ( this . checked ) {
$ . cookie ( 'show_tags_mode' , '' , { path : '/problems' });
} else {
$ . removeCookie ( 'show_tags_mode' , { path : '/problems' });
}
location . reload ();
});
$ ( '#input-show_submit_mode' ) . click ( function () {
if ( this . checked ) {
$ . cookie ( 'show_submit_mode' , '' , { path : '/problems' });
} else {
$ . removeCookie ( 'show_submit_mode' , { path : '/problems' });
}
location . reload ();
});
2022-09-29 02:10:24 +00:00
$ ( '#input-show_difficulty' ) . click ( function () {
if ( this . checked ) {
$ . cookie ( 'show_difficulty' , '' , { path : '/' });
} else {
$ . removeCookie ( 'show_difficulty' , { path : '/' });
}
location . reload ();
});
2016-07-18 16:39:37 +00:00
</ script >
2022-09-20 09:20:23 +00:00
< div class = " <?= join( $div_classes , ' ') ?> " >
< table class = " <?= join( $table_classes , ' ') ?> " >
< thead >< ? = $header ?> </thead>
< tbody >
2016-07-18 16:39:37 +00:00
< ? php
2022-09-20 09:20:23 +00:00
foreach ( $pag -> get () as $idx => $row ) {
echoProblem ( $row );
echo " \n " ;
}
if ( $pag -> isEmpty ()) {
echo '<tr><td class="text-center" colspan="233">' . UOJLocale :: get ( 'none' ) . '</td></tr>' ;
}
2022-09-18 04:58:35 +00:00
?>
2022-09-20 09:20:23 +00:00
</ tbody >
</ table >
</ div >
2022-09-25 06:16:36 +00:00
2022-10-10 00:18:55 +00:00
< div class = " text-center " >
< ? = $pag -> pagination () ?>
</ div >
2022-09-25 06:16:36 +00:00
</ div >
2022-10-10 00:18:55 +00:00
<!-- end left col -->
2022-09-25 06:16:36 +00:00
2022-10-10 00:18:55 +00:00
<!-- right col -->
2022-10-19 03:57:06 +00:00
< aside class = " col-lg-3 mt-3 mt-lg-0 " >
2022-09-25 10:38:19 +00:00
2022-10-10 00:18:55 +00:00
<!-- search bar -->
2022-10-11 02:31:54 +00:00
< form method = " get " class = " mb-3 " id = " form-problem_search " >
2022-09-25 10:38:19 +00:00
< div class = " input-group mb-3 " >
< input id = " search-input " name = " search " type = " text " class = " form-control " placeholder = " 搜索 " >
< button class = " btn btn-outline-secondary " type = " submit " >
< i class = " bi bi-search " ></ i >
</ button >
</ div >
2022-10-11 02:31:54 +00:00
< ? php if ( Auth :: check ()) : ?>
< div class = " form-check d-inline-block " >
< input
type = " checkbox " name = " my "
< ? = isset ( $_GET [ 'my' ]) ? 'checked="checked"' : '' ?>
class = " form-check-input " id = " input-my " >
< label class = " form-check-label " for = " input-my " >
我的题目
</ label >
</ div >
< ? php endif ?>
< ? php if ( isProblemManager ( Auth :: user ())) : ?>
< div class = " form-check d-inline-block ms-2 " >
< input
type = " checkbox " name = " is_hidden "
< ? = isset ( $_GET [ 'is_hidden' ]) ? 'checked="checked"' : '' ?>
class = " form-check-input " id = " input-is_hidden " >
< label class = " form-check-label " for = " input-is_hidden " >
隐藏题目
</ label >
</ div >
< ? php endif ?>
2022-09-25 10:38:19 +00:00
</ form >
2022-10-11 02:31:54 +00:00
< script >
$ ( '#search-input' ) . val ( new URLSearchParams ( location . search ) . get ( 'search' ));
$ ( '#input-my, #input-is_hidden' ) . click ( function () {
$ ( '#form-problem_search' ) . submit ();
});
</ script >
2022-09-25 10:38:19 +00:00
2022-10-10 00:18:55 +00:00
<!-- sidebar -->
< ? php uojIncludeView ( 'sidebar' , []) ?>
2022-09-25 06:16:36 +00:00
</ aside >
</ div >
2016-07-18 16:39:37 +00:00
< ? php echoUOJPageFooter () ?>