2016-07-18 16:39:37 +00:00
< ? php
2022-09-20 01:50:37 +00:00
define ( 'DOM_SANITIZE_CONFIG' , " { ALLOWED_TAGS: ['a', 'b', 'i', 'u', 'em', 'strong', 'sub', 'sup', 'small', 'del', 'br'], ALLOWED_ATTR: ['href']} " );
2022-09-18 13:38:57 +00:00
2016-07-18 16:39:37 +00:00
function uojHandleAtSign ( $str , $uri ) {
$referrers = array ();
2020-06-25 12:41:16 +00:00
$res = preg_replace_callback ( '/@(@|[a-zA-Z0-9_]{1,20})/' , function ( $matches ) use ( & $referrers ) {
2016-07-18 16:39:37 +00:00
if ( $matches [ 1 ] === '@' ) {
return '@' ;
} else {
$user = queryUser ( $matches [ 1 ]);
if ( $user == null ) {
return $matches [ 0 ];
} else {
$referrers [ $user [ 'username' ]] = '' ;
2022-03-17 03:02:44 +00:00
return '<span class="uoj-username">@' . $user [ 'username' ] . '</span>' ;
2016-07-18 16:39:37 +00:00
}
}
}, $str );
$referrers_list = array ();
foreach ( $referrers as $referrer => $val ) {
$referrers_list [] = $referrer ;
}
return array ( $res , $referrers_list );
}
2018-10-11 15:01:50 +00:00
function uojFilePreview ( $file_name , $output_limit , $file_type = 'text' ) {
switch ( $file_type ) {
case 'text' :
return strOmit ( file_get_contents ( $file_name , false , null , 0 , $output_limit + 4 ), $output_limit );
default :
return strOmit ( shell_exec ( 'xxd -g 4 -l 5000 ' . escapeshellarg ( $file_name ) . ' | head -c ' . ( $output_limit + 4 )), $output_limit );
}
2016-07-18 16:39:37 +00:00
}
function uojIncludeView ( $name , $view_params = array ()) {
2022-10-04 06:06:03 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
extract ( $view_params );
include $_SERVER [ 'DOCUMENT_ROOT' ] . '/app/views/' . $name . '.php' ;
}
function redirectTo ( $url ) {
header ( 'Location: ' . $url );
die ();
}
function permanentlyRedirectTo ( $url ) {
header ( " HTTP/1.1 301 Moved Permanently " );
header ( 'Location: ' . $url );
die ();
}
function redirectToLogin () {
if ( UOJContext :: isAjax ()) {
die ( 'please <a href="' . HTML :: url ( '/login' ) . '">login</a>' );
} else {
header ( 'Location: ' . HTML :: url ( '/login' ));
die ();
}
}
function becomeMsgPage ( $msg , $title = '消息' ) {
2022-09-23 22:25:27 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
if ( UOJContext :: isAjax ()) {
die ( $msg );
} else {
2022-09-24 02:18:55 +00:00
if ( ! isset ( $_COOKIE [ 'bootstrap4' ])) {
2022-09-24 00:26:39 +00:00
$REQUIRE_LIB [ 'bootstrap5' ] = '' ;
}
2022-09-23 22:25:27 +00:00
2016-07-18 16:39:37 +00:00
echoUOJPageHeader ( $title );
echo $msg ;
echoUOJPageFooter ();
die ();
}
}
2022-04-02 10:01:26 +00:00
function become404Page ( $message = '未找到页面。' ) {
2016-07-18 16:39:37 +00:00
header ( $_SERVER [ 'SERVER_PROTOCOL' ] . " 404 Not Found " , true , 404 );
2022-04-02 10:01:26 +00:00
becomeMsgPage ( '<div class="text-center"><div style="font-size:150px">404</div><p>' . $message . '</p></div>' , '404' );
2016-07-18 16:39:37 +00:00
}
2022-04-02 10:01:26 +00:00
function become403Page ( $message = '访问被拒绝,您可能需要适当的权限以访问此页面。' ) {
2016-07-18 16:39:37 +00:00
header ( $_SERVER [ 'SERVER_PROTOCOL' ] . " 403 Forbidden " , true , 403 );
2022-04-02 10:01:26 +00:00
becomeMsgPage ( '<div class="text-center"><div style="font-size:150px">403</div><p>' . $message . '</p></div>' , '403' );
2016-07-18 16:39:37 +00:00
}
2022-03-17 03:02:44 +00:00
function getUserLink ( $username ) {
2022-10-01 10:00:42 +00:00
if ( validateUsername ( $username ) && ( $user = queryUser ( $username )) && $user [ 'usergroup' ] != 'B' ) {
2022-03-17 10:26:29 +00:00
$realname = $user [ 'realname' ];
if ( $realname == " " ) {
return '<span class="uoj-username">' . $username . '</span>' ;
} else {
return '<span class="uoj-username" data-realname="' . $realname . '">' . $username . '</span>' ;
}
2016-07-18 16:39:37 +00:00
} else {
$esc_username = HTML :: escape ( $username );
return '<span>' . $esc_username . '</span>' ;
}
}
2022-03-17 10:26:29 +00:00
function getUserName ( $username , $realname = null ) {
if ( $realname == null ) {
if ( validateUsername ( $username ) && ( $user = queryUser ( $username ))) {
$realname = $user [ 'realname' ];
}
}
if ( $realname == " " ) {
return " $username " ;
} else {
return " $username ( $realname ) " ;
}
}
2016-07-18 16:39:37 +00:00
function getProblemLink ( $problem , $problem_title = '!title_only' ) {
2022-09-24 00:13:39 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
if ( $problem_title == '!title_only' ) {
$problem_title = $problem [ 'title' ];
2020-06-25 12:41:16 +00:00
} elseif ( $problem_title == '!id_and_title' ) {
2016-07-18 16:39:37 +00:00
$problem_title = " # ${ problem['id'] } . ${ problem['title'] } " ;
}
2022-09-24 00:13:39 +00:00
$result = '<a ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
$result .= ' class="text-decoration-none" ' ;
}
$result .= ' href="/problem/' . $problem [ 'id' ] . '">' . $problem_title . '</a>' ;
return $result ;
2016-07-18 16:39:37 +00:00
}
function getContestProblemLink ( $problem , $contest_id , $problem_title = '!title_only' ) {
2022-09-24 00:13:39 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
if ( $problem_title == '!title_only' ) {
$problem_title = $problem [ 'title' ];
2020-06-25 12:41:16 +00:00
} elseif ( $problem_title == '!id_and_title' ) {
2016-07-18 16:39:37 +00:00
$problem_title = " # { $problem [ 'id' ] } . { $problem [ 'title' ] } " ;
}
2022-09-24 00:13:39 +00:00
$result = '<a ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
$result .= ' class="text-decoration-none" ' ;
}
$result .= ' href="/contest/' . $contest_id . '/problem/' . $problem [ 'id' ] . '">' . $problem_title . '</a>' ;
return $result ;
2016-07-18 16:39:37 +00:00
}
function getBlogLink ( $id ) {
2022-09-26 12:55:56 +00:00
global $REQUIRE_LIB ;
$result = '' ;
2016-07-18 16:39:37 +00:00
if ( validateUInt ( $id ) && $blog = queryBlog ( $id )) {
2022-09-26 12:55:56 +00:00
$result = '<a ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
$result .= ' class="text-decoration-none" ' ;
}
$result .= ' href="/blogs/' . $id . '">' . $blog [ 'title' ] . '</a>' ;
2016-07-18 16:39:37 +00:00
}
2022-09-26 12:55:56 +00:00
return $result ;
2016-07-18 16:39:37 +00:00
}
2022-10-03 12:47:32 +00:00
function getClickZanBlock ( $type , $id , $cnt , $val = null , $show_text = true ) {
2016-07-18 16:39:37 +00:00
if ( $val == null ) {
$val = queryZanVal ( $id , $type , Auth :: user ());
}
2022-10-03 12:47:32 +00:00
return '<div class="uoj-click-zan-block" data-id="' . $id . '" data-type="' . $type . '" data-val="' . $val . '" data-cnt="' . $cnt . '" ' . ( $show_text ? ' data-show-text="1" ' : '' ) . '></div>' ;
2016-07-18 16:39:37 +00:00
}
function getLongTablePageRawUri ( $page ) {
2020-06-25 12:41:16 +00:00
$path = strtok ( UOJContext :: requestURI (), '?' );
$query_string = strtok ( '?' );
parse_str ( $query_string , $param );
2016-07-18 16:39:37 +00:00
2020-06-25 12:41:16 +00:00
$param [ 'page' ] = $page ;
if ( $page == 1 ) {
unset ( $param [ 'page' ]);
}
2016-07-18 16:39:37 +00:00
2020-06-25 12:41:16 +00:00
if ( $param ) {
return $path . '?' . http_build_query ( $param );
} else {
return $path ;
2016-07-18 16:39:37 +00:00
}
2020-06-25 12:41:16 +00:00
}
2016-07-18 16:39:37 +00:00
function getLongTablePageUri ( $page ) {
return HTML :: escape ( getLongTablePageRawUri ( $page ));
}
function echoLongTable ( $col_names , $table_name , $cond , $tail , $header_row , $print_row , $config ) {
2022-09-23 13:00:17 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
$pag_config = $config ;
$pag_config [ 'col_names' ] = $col_names ;
$pag_config [ 'table_name' ] = $table_name ;
$pag_config [ 'cond' ] = $cond ;
$pag_config [ 'tail' ] = $tail ;
$pag = new Paginator ( $pag_config );
$div_classes = isset ( $config [ 'div_classes' ]) ? $config [ 'div_classes' ] : array ( 'table-responsive' );
2022-09-23 13:00:17 +00:00
$table_classes = isset ( $config [ 'table_classes' ])
? $config [ 'table_classes' ]
2022-09-23 14:02:40 +00:00
: ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])
2022-09-23 13:00:17 +00:00
? array ( 'table' , 'table-bordered' , 'table-striped' , 'text-center' )
2022-09-23 14:02:40 +00:00
: array ( 'table' , 'table-bordered' , 'table-hover' , 'table-striped' , 'table-text-center' ));
2022-09-20 09:19:51 +00:00
if ( isset ( $config [ 'head_pagination' ]) && $config [ 'head_pagination' ]) {
echo $pag -> pagination ();
}
2016-07-18 16:39:37 +00:00
echo '<div class="' , join ( $div_classes , ' ' ), '">' ;
echo '<table class="' , join ( $table_classes , ' ' ), '">' ;
echo '<thead>' ;
echo $header_row ;
echo '</thead>' ;
echo '<tbody>' ;
foreach ( $pag -> get () as $idx => $row ) {
if ( isset ( $config [ 'get_row_index' ])) {
$print_row ( $row , $idx );
} else {
$print_row ( $row );
}
}
if ( $pag -> isEmpty ()) {
echo '<tr><td colspan="233">' . UOJLocale :: get ( 'none' ) . '</td></tr>' ;
}
echo '</tbody>' ;
echo '</table>' ;
echo '</div>' ;
if ( isset ( $config [ 'print_after_table' ])) {
$fun = $config [ 'print_after_table' ];
$fun ();
}
echo $pag -> pagination ();
}
function getSubmissionStatusDetails ( $submission ) {
$html = '<td colspan="233" style="vertical-align: middle">' ;
$out_status = explode ( ', ' , $submission [ 'status' ])[ 0 ];
2019-09-10 02:20:30 +00:00
$fly = '<img src="/images/utility/qpx_n/b37.gif" alt="小熊像超人一样飞" class="img-rounded" />' ;
$think = '<img src="/images/utility/qpx_n/b29.gif" alt="小熊像在思考" class="img-rounded" />' ;
2016-07-18 16:39:37 +00:00
if ( $out_status == 'Judged' ) {
$status_text = '<strong>Judged!</strong>' ;
$status_img = $fly ;
} else {
if ( $submission [ 'status_details' ] !== '' ) {
$status_img = $fly ;
$status_text = HTML :: escape ( $submission [ 'status_details' ]);
2020-06-25 12:41:16 +00:00
} else {
2016-07-18 16:39:37 +00:00
$status_img = $think ;
$status_text = $out_status ;
}
}
$html .= '<div class="uoj-status-details-img-div">' . $status_img . '</div>' ;
$html .= '<div class="uoj-status-details-text-div">' . $status_text . '</div>' ;
$html .= '</td>' ;
return $html ;
}
function echoSubmission ( $submission , $config , $user ) {
2022-09-24 00:13:39 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
$problem = queryProblemBrief ( $submission [ 'problem_id' ]);
$submitterLink = getUserLink ( $submission [ 'submitter' ]);
if ( $submission [ 'score' ] == null ) {
$used_time_str = " / " ;
$used_memory_str = " / " ;
} else {
$used_time_str = $submission [ 'used_time' ] . 'ms' ;
$used_memory_str = $submission [ 'used_memory' ] . 'kb' ;
}
$status = explode ( ', ' , $submission [ 'status' ])[ 0 ];
$show_status_details = Auth :: check () && $submission [ 'submitter' ] === Auth :: id () && $status !== 'Judged' ;
if ( ! $show_status_details ) {
echo '<tr>' ;
} else {
echo '<tr class="warning">' ;
}
if ( ! isset ( $config [ 'id_hidden' ])) {
2022-09-24 00:13:39 +00:00
echo '<td><a ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' class="text-decoration-none" ' ;
}
echo ' href="/submission/' , $submission [ 'id' ], '">#' , $submission [ 'id' ], '</a></td>' ;
2016-07-18 16:39:37 +00:00
}
if ( ! isset ( $config [ 'problem_hidden' ])) {
if ( $submission [ 'contest_id' ]) {
echo '<td>' , getContestProblemLink ( $problem , $submission [ 'contest_id' ], '!id_and_title' ), '</td>' ;
} else {
echo '<td>' , getProblemLink ( $problem , '!id_and_title' ), '</td>' ;
}
}
if ( ! isset ( $config [ 'submitter_hidden' ])) {
echo '<td>' , $submitterLink , '</td>' ;
}
if ( ! isset ( $config [ 'result_hidden' ])) {
echo '<td>' ;
if ( $status == 'Judged' ) {
if ( $submission [ 'score' ] == null ) {
2022-09-25 02:44:33 +00:00
echo '<a ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' class="text-decoration-none small" ' ;
} else {
echo ' class="small" ' ;
}
echo ' href="/submission/' , $submission [ 'id' ], '">' , $submission [ 'result_error' ], '</a>' ;
2016-07-18 16:39:37 +00:00
} else {
echo '<a href="/submission/' , $submission [ 'id' ], '" class="uoj-score">' , $submission [ 'score' ], '</a>' ;
}
} else {
2022-09-25 02:44:33 +00:00
echo '<a ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' class="text-decoration-none small" ' ;
} else {
echo ' class="small" ' ;
}
echo ' href="/submission/' , $submission [ 'id' ], '">' , $status , '</a>' ;
2016-07-18 16:39:37 +00:00
}
echo '</td>' ;
}
2020-06-25 12:41:16 +00:00
if ( ! isset ( $config [ 'used_time_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<td>' , $used_time_str , '</td>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'used_memory_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<td>' , $used_memory_str , '</td>' ;
2020-06-25 12:41:16 +00:00
}
2016-07-18 16:39:37 +00:00
2022-09-24 00:13:39 +00:00
echo '<td>' , '<a ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' class="text-decoration-none" ' ;
}
echo ' href="/submission/' , $submission [ 'id' ], '">' , $submission [ 'language' ], '</a>' , '</td>' ;
2016-07-18 16:39:37 +00:00
if ( $submission [ 'tot_size' ] < 1024 ) {
$size_str = $submission [ 'tot_size' ] . 'b' ;
} else {
$size_str = sprintf ( " %.1f " , $submission [ 'tot_size' ] / 1024 ) . 'kb' ;
}
echo '<td>' , $size_str , '</td>' ;
2020-06-25 12:41:16 +00:00
if ( ! isset ( $config [ 'submit_time_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<td><small>' , $submission [ 'submit_time' ], '</small></td>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'judge_time_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<td><small>' , $submission [ 'judge_time' ], '</small></td>' ;
2020-06-25 12:41:16 +00:00
}
2016-07-18 16:39:37 +00:00
echo '</tr>' ;
if ( $show_status_details ) {
echo '<tr id="' , " status_details_ { $submission [ 'id' ] } " , '" class="info">' ;
echo getSubmissionStatusDetails ( $submission );
echo '</tr>' ;
echo '<script type="text/javascript">update_judgement_status_details(' . $submission [ 'id' ] . ')</script>' ;
}
}
function echoSubmissionsListOnlyOne ( $submission , $config , $user ) {
2022-09-24 13:19:48 +00:00
global $REQUIRE_LIB ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<div class="card mb-3">' ;
echo '<table class="table text-center uoj-table mb-0">' ;
} else {
echo '<div class="table-responsive">' ;
echo '<table class="table table-bordered table-text-center">' ;
}
2016-07-18 16:39:37 +00:00
echo '<thead>' ;
echo '<tr>' ;
2020-06-25 12:41:16 +00:00
if ( ! isset ( $config [ 'id_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>ID</th>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'problem_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::problem' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'submitter_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::submitter' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'result_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::result' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'used_time_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::used time' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'used_memory_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::used memory' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::language' ) . '</th>' ;
echo '<th>' . UOJLocale :: get ( 'problems::file size' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
if ( ! isset ( $config [ 'submit_time_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::submit time' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'judge_time_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::judge time' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
2016-07-18 16:39:37 +00:00
echo '</tr>' ;
echo '</thead>' ;
echo '<tbody>' ;
echoSubmission ( $submission , $config , $user );
echo '</tbody>' ;
echo '</table>' ;
echo '</div>' ;
}
function echoSubmissionsList ( $cond , $tail , $config , $user ) {
2022-09-24 00:13:39 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
$header_row = '<tr>' ;
$col_names = array ();
$col_names [] = 'submissions.status_details' ;
$col_names [] = 'submissions.status' ;
$col_names [] = 'submissions.result_error' ;
$col_names [] = 'submissions.score' ;
if ( ! isset ( $config [ 'id_hidden' ])) {
$header_row .= '<th>ID</th>' ;
$col_names [] = 'submissions.id' ;
}
if ( ! isset ( $config [ 'problem_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::problem' ) . '</th>' ;
$col_names [] = 'submissions.problem_id' ;
$col_names [] = 'submissions.contest_id' ;
}
if ( ! isset ( $config [ 'submitter_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::submitter' ) . '</th>' ;
$col_names [] = 'submissions.submitter' ;
}
if ( ! isset ( $config [ 'result_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::result' ) . '</th>' ;
}
if ( ! isset ( $config [ 'used_time_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::used time' ) . '</th>' ;
$col_names [] = 'submissions.used_time' ;
}
if ( ! isset ( $config [ 'used_memory_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::used memory' ) . '</th>' ;
$col_names [] = 'submissions.used_memory' ;
}
$header_row .= '<th>' . UOJLocale :: get ( 'problems::language' ) . '</th>' ;
$col_names [] = 'submissions.language' ;
$header_row .= '<th>' . UOJLocale :: get ( 'problems::file size' ) . '</th>' ;
$col_names [] = 'submissions.tot_size' ;
if ( ! isset ( $config [ 'submit_time_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::submit time' ) . '</th>' ;
$col_names [] = 'submissions.submit_time' ;
}
if ( ! isset ( $config [ 'judge_time_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::judge time' ) . '</th>' ;
$col_names [] = 'submissions.judge_time' ;
}
$header_row .= '</tr>' ;
$table_name = isset ( $config [ 'table_name' ]) ? $config [ 'table_name' ] : 'submissions' ;
if ( ! isSuperUser ( $user )) {
if ( $user != null ) {
$permission_cond = " submissions.is_hidden = false or (submissions.is_hidden = true and submissions.problem_id in (select problem_id from problems_permissions where username = ' { $user [ 'username' ] } ')) " ;
} else {
$permission_cond = " submissions.is_hidden = false " ;
}
if ( $cond !== '1' ) {
$cond = " ( $cond ) and ( $permission_cond ) " ;
} else {
$cond = $permission_cond ;
}
}
$table_config = isset ( $config [ 'table_config' ]) ? $config [ 'table_config' ] : null ;
echoLongTable ( $col_names , $table_name , $cond , $tail , $header_row ,
2020-06-25 12:41:16 +00:00
function ( $submission ) use ( $config , $user ) {
2016-07-18 16:39:37 +00:00
echoSubmission ( $submission , $config , $user );
}, $table_config );
}
function echoSubmissionContent ( $submission , $requirement ) {
2022-09-24 13:19:48 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
$zip_file = new ZipArchive ();
$submission_content = json_decode ( $submission [ 'content' ], true );
$zip_file -> open ( UOJContext :: storagePath () . $submission_content [ 'file_name' ]);
$config = array ();
foreach ( $submission_content [ 'config' ] as $config_key => $config_val ) {
$config [ $config_val [ 0 ]] = $config_val [ 1 ];
}
foreach ( $requirement as $req ) {
if ( $req [ 'type' ] == " source code " ) {
$file_content = $zip_file -> getFromName ( " { $req [ 'name' ] } .code " );
$file_content = uojTextEncode ( $file_content , array ( 'allow_CR' => true , 'html_escape' => true ));
$file_language = htmlspecialchars ( $config [ " { $req [ 'name' ] } _language " ]);
$footer_text = UOJLocale :: get ( 'problems::source code' ) . ', ' . UOJLocale :: get ( 'problems::language' ) . ': ' . $file_language ;
switch ( $file_language ) {
case 'C++' :
case 'C++11' :
2022-09-18 02:54:13 +00:00
case 'C++17' :
2022-10-04 13:31:28 +00:00
case 'C++20' :
2022-09-18 02:54:13 +00:00
case 'C++98' :
2022-10-04 13:31:28 +00:00
case 'C++03' :
2022-10-04 23:47:56 +00:00
$sh_class = 'sh_cpp language-cpp' ;
2016-07-18 16:39:37 +00:00
break ;
2019-06-28 08:40:41 +00:00
case 'Python2' :
2022-10-04 13:31:28 +00:00
case 'Python2.7' :
2016-07-18 16:39:37 +00:00
case 'Python3' :
2022-10-04 23:47:56 +00:00
$sh_class = 'sh_python language-python' ;
break ;
case 'Java8' :
case 'Java11' :
case 'Java17' :
$sh_class = 'sh_java language-java' ;
2016-07-18 16:39:37 +00:00
break ;
case 'C' :
2022-10-04 23:47:56 +00:00
$sh_class = 'sh_c language-c' ;
2016-07-18 16:39:37 +00:00
break ;
case 'Pascal' :
2022-10-04 23:47:56 +00:00
$sh_class = 'sh_pascal language-pascal' ;
2016-07-18 16:39:37 +00:00
break ;
default :
$sh_class = '' ;
break ;
}
2019-09-10 02:15:20 +00:00
echo '<div class="card border-info mb-3">' ;
echo '<div class="card-header bg-info">' ;
echo '<h4 class="card-title">' . $req [ 'name' ] . '</h4>' ;
2016-07-18 16:39:37 +00:00
echo '</div>' ;
2019-09-10 02:15:20 +00:00
echo '<div class="card-body">' ;
2022-09-24 13:19:48 +00:00
echo '<pre><code class="' . $sh_class ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
2022-09-29 03:03:51 +00:00
echo ' bg-light rounded p-3 ' ;
2022-09-24 13:19:48 +00:00
}
echo '">' . $file_content . " \n " . '</code></pre>' ;
2016-07-18 16:39:37 +00:00
echo '</div>' ;
2019-09-10 02:15:20 +00:00
echo '<div class="card-footer">' . $footer_text . '</div>' ;
2016-07-18 16:39:37 +00:00
echo '</div>' ;
2020-06-25 12:41:16 +00:00
} elseif ( $req [ 'type' ] == " text " ) {
2016-07-18 16:39:37 +00:00
$file_content = $zip_file -> getFromName ( " { $req [ 'file_name' ] } " , 504 );
$file_content = strOmit ( $file_content , 500 );
$file_content = uojTextEncode ( $file_content , array ( 'allow_CR' => true , 'html_escape' => true ));
$footer_text = UOJLocale :: get ( 'problems::text file' );
2019-09-10 02:15:20 +00:00
echo '<div class="card border-info mb-3">' ;
echo '<div class="card-header bg-info">' ;
echo '<h4 class="card-title">' . $req [ 'file_name' ] . '</h4>' ;
2016-07-18 16:39:37 +00:00
echo '</div>' ;
2019-09-10 02:15:20 +00:00
echo '<div class="card-body">' ;
2022-09-29 03:03:51 +00:00
echo '<pre class=" ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' bg-light rounded p-3 ' ;
}
echo " \" > \n " . $file_content . " \n " . '</pre>' ;
2016-07-18 16:39:37 +00:00
echo '</div>' ;
2019-09-10 02:15:20 +00:00
echo '<div class="card-footer">' . $footer_text . '</div>' ;
2016-07-18 16:39:37 +00:00
echo '</div>' ;
}
}
$zip_file -> close ();
}
class JudgementDetailsPrinter {
private $name ;
private $styler ;
private $dom ;
private $subtask_num ;
private function _print_c ( $node ) {
foreach ( $node -> childNodes as $child ) {
if ( $child -> nodeName == '#text' ) {
echo htmlspecialchars ( $child -> nodeValue );
} else {
$this -> _print ( $child );
}
}
}
private function _print ( $node ) {
2022-09-24 13:19:48 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
if ( $node -> nodeName == 'error' ) {
2022-09-29 03:03:51 +00:00
echo '<pre class=" ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' bg-light rounded p-3 ' ;
}
echo " \" > \n " ;
2016-07-18 16:39:37 +00:00
$this -> _print_c ( $node );
echo " \n </pre> " ;
} elseif ( $node -> nodeName == 'tests' ) {
2019-09-10 02:15:20 +00:00
echo '<div id="' , $this -> name , '_details_accordion">' ;
2022-09-24 13:50:59 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
$this -> _print_c ( $node );
}
2016-07-18 16:39:37 +00:00
if ( $this -> styler -> show_small_tip ) {
2022-09-24 13:19:48 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<div class="my-2 px-2 text-end text-muted">' ;
} else {
echo '<div class="text-right text-muted">' ;
}
echo '小提示:点击横条可展开更详细的信息' , '</div>' ;
2020-06-25 12:41:16 +00:00
} elseif ( $this -> styler -> ioi_contest_is_running ) {
2022-09-24 13:19:48 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<div class="my-2 px-2 text-end text-muted">' ;
} else {
echo '<div class="text-right text-muted">' ;
}
echo 'IOI赛制比赛中不支持显示详细信息' , '</div>' ;
2019-06-11 03:03:53 +00:00
}
2022-09-24 13:50:59 +00:00
if ( ! isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
$this -> _print_c ( $node );
}
2016-07-18 16:39:37 +00:00
echo '</div>' ;
} elseif ( $node -> nodeName == 'subtask' ) {
$subtask_num = $node -> getAttribute ( 'num' );
$subtask_score = $node -> getAttribute ( 'score' );
$subtask_info = $node -> getAttribute ( 'info' );
2022-09-24 13:19:48 +00:00
echo '<div class="card ' , $this -> styler -> getTestInfoClass ( $subtask_info );
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
2022-09-24 13:50:59 +00:00
echo ' border-0 rounded-0 border-bottom ' ;
2022-09-24 13:19:48 +00:00
} else {
echo ' mb-3 ' ;
}
echo '">' ;
2016-07-18 16:39:37 +00:00
$accordion_parent = " { $this -> name } _details_accordion " ;
$accordion_collapse = " { $accordion_parent } _collapse_subtask_ { $subtask_num } " ;
$accordion_collapse_accordion = " { $accordion_collapse } _accordion " ;
2022-09-24 13:50:59 +00:00
echo '<div class="card-header ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' uoj-submission-result-item bg-transparent rounded-0 border-0 ' ;
}
echo '" ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' data-bs-toggle="collapse" data-bs-parent="#' , $accordion_parent , '" data-bs-target="#' , $accordion_collapse , '" ' ;
} else {
echo ' data-toggle="collapse" data-parent="#' , $accordion_parent , '" data-target="#' , $accordion_collapse , '" ' ;
}
echo ' >' ;
2016-07-18 16:39:37 +00:00
echo '<div class="row">' ;
2022-09-24 13:50:59 +00:00
echo '<div class="col-sm-4">' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<h3 class="fs-5">' ;
} else {
echo '<h3 class="card-title">' ;
}
echo 'Subtask #' , $subtask_num , ': ' , '</h3>' ;
2016-07-18 16:39:37 +00:00
echo '</div>' ;
if ( $this -> styler -> show_score ) {
echo '<div class="col-sm-2">' ;
2022-09-24 13:50:59 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<i class="bi bi-clipboard-check"></i> ' ;
} else {
echo 'score: ' ;
}
echo $subtask_score ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' pts' ;
}
2016-07-18 16:39:37 +00:00
echo '</div>' ;
2022-09-24 14:01:38 +00:00
echo '<div class="col-sm-2 uoj-status-text">' ;
2022-09-24 13:50:59 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo $this -> styler -> getTestInfoIcon ( $subtask_info );
}
2016-07-18 16:39:37 +00:00
echo htmlspecialchars ( $subtask_info );
echo '</div>' ;
} else {
echo '<div class="col-sm-4">' ;
2022-09-24 13:50:59 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo $this -> styler -> getTestInfoIcon ( $subtask_info );
}
2016-07-18 16:39:37 +00:00
echo htmlspecialchars ( $subtask_info );
echo '</div>' ;
}
echo '</div>' ;
echo '</div>' ;
2019-09-10 02:15:20 +00:00
echo '<div id="' , $accordion_collapse , '" class="card-collapse collapse">' ;
2022-09-24 13:50:59 +00:00
echo '<div class="card-body ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' pt-0 ' ;
}
echo '">' ;
2016-07-18 16:39:37 +00:00
2022-09-24 13:50:59 +00:00
echo '<div id="' , $accordion_collapse_accordion , '" ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' class="border rounded overflow-hidden" ' ;
}
echo ' >' ;
2016-07-18 16:39:37 +00:00
$this -> subtask_num = $subtask_num ;
$this -> _print_c ( $node );
$this -> subtask_num = null ;
echo '</div>' ;
echo '</div>' ;
echo '</div>' ;
echo '</div>' ;
} elseif ( $node -> nodeName == 'test' ) {
$test_info = $node -> getAttribute ( 'info' );
$test_num = $node -> getAttribute ( 'num' );
$test_score = $node -> getAttribute ( 'score' );
$test_time = $node -> getAttribute ( 'time' );
$test_memory = $node -> getAttribute ( 'memory' );
2022-09-24 13:19:48 +00:00
echo '<div class="card ' , $this -> styler -> getTestInfoClass ( $test_info );
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
2022-09-24 13:50:59 +00:00
echo ' border-0 rounded-0 border-bottom ' ;
2022-09-24 13:19:48 +00:00
} else {
echo ' mb-3 ' ;
}
echo '">' ;
2016-07-18 16:39:37 +00:00
$accordion_parent = " { $this -> name } _details_accordion " ;
if ( $this -> subtask_num != null ) {
$accordion_parent .= " _collapse_subtask_ { $this -> subtask_num } _accordion " ;
}
$accordion_collapse = " { $accordion_parent } _collapse_test_ { $test_num } " ;
2022-09-24 13:19:48 +00:00
echo '<div class="card-header ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' uoj-submission-result-item bg-transparent rounded-0 border-0 ' ;
}
echo '" ' ;
2016-07-18 16:39:37 +00:00
if ( ! $this -> styler -> shouldFadeDetails ( $test_info )) {
2022-09-24 13:19:48 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' data-bs-toggle="collapse" data-bs-parent="#' , $accordion_parent , '" data-bs-target="#' , $accordion_collapse , '" ' ;
} else {
echo ' data-toggle="collapse" data-parent="#' , $accordion_parent , '" data-target="#' , $accordion_collapse , '" ' ;
}
2016-07-18 16:39:37 +00:00
}
2022-09-24 13:19:48 +00:00
echo '>' ;
2016-07-18 16:39:37 +00:00
echo '<div class="row">' ;
2022-09-24 13:19:48 +00:00
echo '<div class="col-sm-4">' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<h4 class="fs-5">' ;
} else {
echo '<h4 class="card-title">' ;
}
2016-07-18 16:39:37 +00:00
if ( $test_num > 0 ) {
2022-09-24 13:19:48 +00:00
echo 'Test #' , $test_num , ': ' ;
2016-07-18 16:39:37 +00:00
} else {
2022-09-24 13:19:48 +00:00
echo 'Extra Test:' ;
2016-07-18 16:39:37 +00:00
}
2022-09-24 13:19:48 +00:00
echo '</h4>' ;
2016-07-18 16:39:37 +00:00
echo '</div>' ;
if ( $this -> styler -> show_score ) {
echo '<div class="col-sm-2">' ;
2022-09-24 13:19:48 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<i class="bi bi-clipboard-check"></i> ' ;
} else {
echo 'score: ' ;
}
echo $test_score ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' pts' ;
}
2016-07-18 16:39:37 +00:00
echo '</div>' ;
2022-09-24 13:19:48 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<div class="col-sm-2 uoj-status-text">' ;
2022-09-24 13:50:59 +00:00
echo $this -> styler -> getTestInfoIcon ( $test_info );
2022-09-24 13:19:48 +00:00
} else {
echo '<div class="col-sm-2">' ;
}
2016-07-18 16:39:37 +00:00
echo htmlspecialchars ( $test_info );
echo '</div>' ;
} else {
2022-09-25 02:44:33 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<div class="col-sm-4 uoj-status-text">' ;
echo $this -> styler -> getTestInfoIcon ( $test_info );
} else {
echo '<div class="col-sm-4">' ;
}
2016-07-18 16:39:37 +00:00
echo htmlspecialchars ( $test_info );
echo '</div>' ;
}
2022-09-24 13:19:48 +00:00
echo '<div class="col-sm-2">' ;
2016-07-18 16:39:37 +00:00
if ( $test_time >= 0 ) {
2022-09-24 13:19:48 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<i class="bi bi-hourglass-split"></i> ' ;
} else {
echo 'time: ' ;
}
echo $test_time , ' ms' ;
2016-07-18 16:39:37 +00:00
}
echo '</div>' ;
2022-09-24 13:19:48 +00:00
echo '<div class="col-sm-2">' ;
2016-07-18 16:39:37 +00:00
if ( $test_memory >= 0 ) {
2022-09-24 13:19:48 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<i class="bi bi-memory"></i> ' ;
} else {
echo 'memory: ' ;
}
echo $test_memory , ' kB' ;
2016-07-18 16:39:37 +00:00
}
echo '</div>' ;
echo '</div>' ;
echo '</div>' ;
if ( ! $this -> styler -> shouldFadeDetails ( $test_info )) {
2019-09-10 02:15:20 +00:00
$accordion_collapse_class = 'card-collapse collapse' ;
2016-07-18 16:39:37 +00:00
if ( $this -> styler -> collapse_in ) {
$accordion_collapse_class .= ' in' ;
}
2022-09-20 05:10:25 +00:00
echo '<div id="' , $accordion_collapse , '" class="uoj-testcase ' , $accordion_collapse_class , '" data-test=' . $test_num . '>' ;
2019-09-10 02:15:20 +00:00
echo '<div class="card-body">' ;
2016-07-18 16:39:37 +00:00
$this -> _print_c ( $node );
echo '</div>' ;
echo '</div>' ;
}
echo '</div>' ;
} elseif ( $node -> nodeName == 'custom-test' ) {
$test_info = $node -> getAttribute ( 'info' );
$test_time = $node -> getAttribute ( 'time' );
$test_memory = $node -> getAttribute ( 'memory' );
2022-09-25 10:28:43 +00:00
echo '<div class="card ' , $this -> styler -> getTestInfoClass ( $test_info );
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
} else {
}
echo ' mb-3">' ;
2016-07-18 16:39:37 +00:00
$accordion_parent = " { $this -> name } _details_accordion " ;
$accordion_collapse = " { $accordion_parent } _collapse_custom_test " ;
2022-09-25 10:28:43 +00:00
echo '<div class="card-header ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' uoj-submission-result-item bg-transparent rounded-0 border-0 ' ;
}
echo '" ' ;
2016-07-18 16:39:37 +00:00
if ( ! $this -> styler -> shouldFadeDetails ( $test_info )) {
2022-09-25 10:28:43 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' data-bs-toggle="collapse" data-bs-parent="#' , $accordion_parent , '" data-bs-target="#' , $accordion_collapse , '" ' ;
} else {
echo ' data-toggle="collapse" data-parent="#' , $accordion_parent , '" data-target="#' , $accordion_collapse , '" ' ;
}
2016-07-18 16:39:37 +00:00
}
2022-09-25 10:28:43 +00:00
echo '>' ;
2016-07-18 16:39:37 +00:00
echo '<div class="row">' ;
2022-09-27 08:53:39 +00:00
echo '<div class="col-sm-4">' ;
2019-09-10 02:15:20 +00:00
echo '<h4 class="card-title">' , 'Custom Test: ' , '</h4>' ;
2016-07-18 16:39:37 +00:00
echo '</div>' ;
2022-09-27 08:53:39 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<div class="col-sm-4 uoj-status-text">' ;
echo $this -> styler -> getTestInfoIcon ( $test_info );
} else {
echo '<div class="col-sm-4">' ;
}
2016-07-18 16:39:37 +00:00
echo htmlspecialchars ( $test_info );
echo '</div>' ;
2022-09-27 08:53:39 +00:00
echo '<div class="col-sm-2">' ;
2016-07-18 16:39:37 +00:00
if ( $test_time >= 0 ) {
2022-09-27 08:53:39 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<i class="bi bi-hourglass-split"></i> ' ;
} else {
echo 'time: ' ;
}
echo $test_time , ' ms' ;
2016-07-18 16:39:37 +00:00
}
echo '</div>' ;
2022-09-27 08:53:39 +00:00
echo '<div class="col-sm-2">' ;
2016-07-18 16:39:37 +00:00
if ( $test_memory >= 0 ) {
2022-09-27 08:53:39 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<i class="bi bi-memory"></i> ' ;
} else {
echo 'memory: ' ;
}
echo $test_memory , ' kB' ;
2016-07-18 16:39:37 +00:00
}
echo '</div>' ;
echo '</div>' ;
echo '</div>' ;
if ( ! $this -> styler -> shouldFadeDetails ( $test_info )) {
2019-09-10 02:15:20 +00:00
$accordion_collapse_class = 'card-collapse collapse' ;
2016-07-18 16:39:37 +00:00
if ( $this -> styler -> collapse_in ) {
$accordion_collapse_class .= ' in' ;
}
echo '<div id="' , $accordion_collapse , '" class="' , $accordion_collapse_class , '">' ;
2019-09-10 02:15:20 +00:00
echo '<div class="card-body">' ;
2016-07-18 16:39:37 +00:00
$this -> _print_c ( $node );
echo '</div>' ;
echo '</div>' ;
echo '</div>' ;
}
} elseif ( $node -> nodeName == 'in' ) {
2022-09-24 13:19:48 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<h4 class="fs-6 d-flex justify-content-between"><span>input: </span><a class="uoj-testcase-download-input"></a></h4>' ;
} else {
echo '<h4>input: <a class="uoj-testcase-download-input"></a></h4>' ;
}
echo " <pre class= \" bg-light p-3 rounded \" > \n " ;
2016-07-18 16:39:37 +00:00
$this -> _print_c ( $node );
echo " \n </pre> " ;
} elseif ( $node -> nodeName == 'out' ) {
2022-09-24 13:19:48 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<h4 class="fs-6 d-flex justify-content-between"><span>output: </span><a class="uoj-testcase-download-output"></a></h4>' ;
} else {
echo '<h4>output: <a class="uoj-testcase-download-output"></a></h4>' ;
}
echo " <pre class= \" bg-light p-3 rounded \" > \n " ;
2016-07-18 16:39:37 +00:00
$this -> _print_c ( $node );
echo " \n </pre> " ;
} elseif ( $node -> nodeName == 'res' ) {
2022-09-24 13:19:48 +00:00
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<h4 class="fs-6 d-flex justify-content-between"><span>result: </span><a class="uoj-testcase-download-result"></a></h4>' ;
} else {
echo '<h4>result: <a class="uoj-testcase-download-result"></a></h4>' ;
}
echo " <pre class= \" bg-light p-3 rounded \" > \n " ;
2016-07-18 16:39:37 +00:00
$this -> _print_c ( $node );
echo " \n </pre> " ;
} else {
echo '<' , $node -> nodeName ;
foreach ( $node -> attributes as $attr ) {
echo ' ' , $attr -> name , '="' , htmlspecialchars ( $attr -> value ), '"' ;
}
echo '>' ;
$this -> _print_c ( $node );
echo '</' , $node -> nodeName , '>' ;
}
}
public function __construct ( $details , $styler , $name ) {
2022-09-24 13:19:48 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
$this -> name = $name ;
$this -> styler = $styler ;
$this -> details = $details ;
$this -> dom = new DOMDocument ();
if ( ! $this -> dom -> loadXML ( $this -> details )) {
throw new Exception ( " XML syntax error " );
}
$this -> details = '' ;
}
public function printHTML () {
2022-09-24 13:19:48 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
$this -> subtask_num = null ;
$this -> _print ( $this -> dom -> documentElement );
}
}
function echoJudgementDetails ( $raw_details , $styler , $name ) {
2022-09-24 13:19:48 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
try {
$printer = new JudgementDetailsPrinter ( $raw_details , $styler , $name );
$printer -> printHTML ();
} catch ( Exception $e ) {
echo 'Failed to show details' ;
}
}
class SubmissionDetailsStyler {
public $show_score = true ;
public $show_small_tip = true ;
public $collapse_in = false ;
public $fade_all_details = false ;
public function getTestInfoClass ( $info ) {
if ( $info == 'Accepted' || $info == 'Extra Test Passed' ) {
2019-09-10 02:15:20 +00:00
return 'card-uoj-accepted' ;
2016-07-18 16:39:37 +00:00
} elseif ( $info == 'Time Limit Exceeded' ) {
2019-09-10 02:15:20 +00:00
return 'card-uoj-tle' ;
2016-07-18 16:39:37 +00:00
} elseif ( $info == 'Acceptable Answer' ) {
2019-09-10 02:15:20 +00:00
return 'card-uoj-acceptable-answer' ;
2016-07-18 16:39:37 +00:00
} else {
2019-09-10 02:15:20 +00:00
return 'card-uoj-wrong' ;
2016-07-18 16:39:37 +00:00
}
}
2022-09-24 13:50:59 +00:00
public function getTestInfoIcon ( $test_info ) {
if ( $test_info == 'Accepted' || $test_info == 'Extra Test Passed' ) {
return '<i class="bi bi-check-lg"></i> ' ;
} elseif ( $test_info == 'Time Limit Exceeded' ) {
return '<i class="bi bi-clock"></i> ' ;
} elseif ( $test_info == 'Acceptable Answer' ) {
return '<i class="bi bi-dash-square"></i> ' ;
} elseif ( $test_info == 'Wrong Answer' ) {
return '<i class="bi bi-x-lg"></i> ' ;
} else {
return '<i class="bi bi-slash-circle"></i> ' ;
}
}
2016-07-18 16:39:37 +00:00
public function shouldFadeDetails ( $info ) {
return $this -> fade_all_details || $info == 'Extra Test Passed' ;
}
}
class CustomTestSubmissionDetailsStyler {
public $show_score = true ;
public $show_small_tip = false ;
public $collapse_in = true ;
public $fade_all_details = false ;
2019-06-11 03:03:53 +00:00
public $ioi_contest_is_running = false ;
2016-07-18 16:39:37 +00:00
public function getTestInfoClass ( $info ) {
if ( $info == 'Success' ) {
2019-09-10 02:15:20 +00:00
return 'card-uoj-accepted' ;
2016-07-18 16:39:37 +00:00
} elseif ( $info == 'Time Limit Exceeded' ) {
2019-09-10 02:15:20 +00:00
return 'card-uoj-tle' ;
2016-07-18 16:39:37 +00:00
} elseif ( $info == 'Acceptable Answer' ) {
2019-09-10 02:15:20 +00:00
return 'card-uoj-acceptable-answer' ;
2016-07-18 16:39:37 +00:00
} else {
2019-09-10 02:15:20 +00:00
return 'card-uoj-wrong' ;
2016-07-18 16:39:37 +00:00
}
}
2022-09-27 08:53:39 +00:00
public function getTestInfoIcon ( $test_info ) {
if ( $test_info == 'Success' ) {
return '<i class="bi bi-check-lg"></i> ' ;
} elseif ( $test_info == 'Time Limit Exceeded' ) {
return '<i class="bi bi-clock"></i> ' ;
} elseif ( $test_info == 'Acceptable Answer' ) {
return '<i class="bi bi-dash-square"></i> ' ;
} elseif ( $test_info == 'Wrong Answer' ) {
return '<i class="bi bi-x-lg"></i> ' ;
} else {
return '<i class="bi bi-slash-circle"></i> ' ;
}
}
2016-07-18 16:39:37 +00:00
public function shouldFadeDetails ( $info ) {
return $this -> fade_all_details ;
}
}
class HackDetailsStyler {
public $show_score = false ;
public $show_small_tip = false ;
public $collapse_in = true ;
public $fade_all_details = false ;
public function getTestInfoClass ( $info ) {
if ( $info == 'Accepted' || $info == 'Extra Test Passed' ) {
2019-09-10 02:15:20 +00:00
return 'card-uoj-accepted' ;
2016-07-18 16:39:37 +00:00
} elseif ( $info == 'Time Limit Exceeded' ) {
2019-09-10 02:15:20 +00:00
return 'card-uoj-tle' ;
2016-07-18 16:39:37 +00:00
} elseif ( $info == 'Acceptable Answer' ) {
2019-09-10 02:15:20 +00:00
return 'card-uoj-acceptable-answer' ;
2016-07-18 16:39:37 +00:00
} else {
2019-09-10 02:15:20 +00:00
return 'card-uoj-wrong' ;
2016-07-18 16:39:37 +00:00
}
}
2022-09-25 02:44:33 +00:00
public function getTestInfoIcon ( $test_info ) {
if ( $test_info == 'Accepted' || $test_info == 'Extra Test Passed' ) {
return '<i class="bi bi-check-lg"></i> ' ;
} elseif ( $test_info == 'Time Limit Exceeded' ) {
return '<i class="bi bi-clock"></i> ' ;
} elseif ( $test_info == 'Acceptable Answer' ) {
return '<i class="bi bi-dash-square"></i> ' ;
} elseif ( $test_info == 'Wrong Answer' ) {
return '<i class="bi bi-x-lg"></i> ' ;
} else {
return '<i class="bi bi-slash-circle"></i> ' ;
}
}
2016-07-18 16:39:37 +00:00
public function shouldFadeDetails ( $info ) {
return $this -> fade_all_details ;
}
}
function echoSubmissionDetails ( $submission_details , $name ) {
2022-09-24 13:19:48 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
echoJudgementDetails ( $submission_details , new SubmissionDetailsStyler (), $name );
}
function echoCustomTestSubmissionDetails ( $submission_details , $name ) {
echoJudgementDetails ( $submission_details , new CustomTestSubmissionDetailsStyler (), $name );
}
function echoHackDetails ( $hack_details , $name ) {
2022-09-25 02:44:33 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
echoJudgementDetails ( $hack_details , new HackDetailsStyler (), $name );
}
function echoHack ( $hack , $config , $user ) {
2022-09-26 12:42:46 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
$problem = queryProblemBrief ( $hack [ 'problem_id' ]);
echo '<tr>' ;
2020-06-25 12:41:16 +00:00
if ( ! isset ( $config [ 'id_hidden' ])) {
2022-09-25 02:44:33 +00:00
echo '<td><a ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' class="text-decoration-none" ' ;
}
echo ' href="/hack/' , $hack [ 'id' ], '">#' , $hack [ 'id' ], '</a></td>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'submission_hidden' ])) {
2022-09-25 02:44:33 +00:00
echo '<td><a ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' class="text-decoration-none" ' ;
}
echo ' href="/submission/' , $hack [ 'submission_id' ], '">#' , $hack [ 'submission_id' ], '</a></td>' ;
2020-06-25 12:41:16 +00:00
}
2016-07-18 16:39:37 +00:00
if ( ! isset ( $config [ 'problem_hidden' ])) {
if ( $hack [ 'contest_id' ]) {
echo '<td>' , getContestProblemLink ( $problem , $hack [ 'contest_id' ], '!id_and_title' ), '</td>' ;
} else {
echo '<td>' , getProblemLink ( $problem , '!id_and_title' ), '</td>' ;
}
}
2020-06-25 12:41:16 +00:00
if ( ! isset ( $config [ 'hacker_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<td>' , getUserLink ( $hack [ 'hacker' ]), '</td>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'owner_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<td>' , getUserLink ( $hack [ 'owner' ]), '</td>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'result_hidden' ])) {
if ( $hack [ 'judge_time' ] == null ) {
2022-09-25 02:44:33 +00:00
echo '<td><a ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' class="text-decoration-none" ' ;
}
echo ' href="/hack/' , $hack [ 'id' ], '">Waiting</a></td>' ;
2016-07-18 16:39:37 +00:00
} elseif ( $hack [ 'success' ] == null ) {
2022-09-25 02:44:33 +00:00
echo '<td><a ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' class="text-decoration-none" ' ;
}
echo ' href="/hack/' , $hack [ 'id' ], '">Judging</a></td>' ;
2016-07-18 16:39:37 +00:00
} elseif ( $hack [ 'success' ]) {
2022-09-25 02:44:33 +00:00
echo '<td><a href="/hack/' , $hack [ 'id' ], '" class="uoj-status ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' text-decoration-none ' ;
}
echo ' " data-success="1"><strong>Success!</strong></a></td>' ;
2016-07-18 16:39:37 +00:00
} else {
2022-09-25 02:44:33 +00:00
echo '<td><a href="/hack/' , $hack [ 'id' ], '" class="uoj-status ' ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo ' text-decoration-none ' ;
}
echo ' " data-success="0"><strong>Failed.</strong></a></td>' ;
2016-07-18 16:39:37 +00:00
}
2020-06-25 12:41:16 +00:00
} else {
2016-07-18 16:39:37 +00:00
echo '<td>Hidden</td>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'submit_time_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<td>' , $hack [ 'submit_time' ], '</td>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'judge_time_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<td>' , $hack [ 'judge_time' ], '</td>' ;
2020-06-25 12:41:16 +00:00
}
2016-07-18 16:39:37 +00:00
echo '</tr>' ;
}
function echoHackListOnlyOne ( $hack , $config , $user ) {
2022-09-25 02:44:33 +00:00
global $REQUIRE_LIB ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
echo '<div class="card mb-3">' ;
echo '<table class="table text-center uoj-table mb-0">' ;
} else {
echo '<div class="table-responsive">' ;
echo '<table class="table table-bordered table-text-center">' ;
}
2016-07-18 16:39:37 +00:00
echo '<thead>' ;
echo '<tr>' ;
2020-06-25 12:41:16 +00:00
if ( ! isset ( $config [ 'id_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>ID</th>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'submission_id_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::submission id' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'problem_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::problem' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'hacker_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::hacker' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'owner_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::owner' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'result_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::result' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'submit_time_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::submit time' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
if ( ! isset ( $config [ 'judge_time_hidden' ])) {
2016-07-18 16:39:37 +00:00
echo '<th>' . UOJLocale :: get ( 'problems::judge time' ) . '</th>' ;
2020-06-25 12:41:16 +00:00
}
2016-07-18 16:39:37 +00:00
echo '</tr>' ;
echo '</thead>' ;
echo '<tbody>' ;
echoHack ( $hack , $config , $user );
echo '</tbody>' ;
echo '</table>' ;
echo '</div>' ;
}
function echoHacksList ( $cond , $tail , $config , $user ) {
$header_row = '<tr>' ;
$col_names = array ();
$col_names [] = 'id' ;
$col_names [] = 'success' ;
$col_names [] = 'judge_time' ;
if ( ! isset ( $config [ 'id_hidden' ])) {
$header_row .= '<th>ID</th>' ;
}
if ( ! isset ( $config [ 'submission_id_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::submission id' ) . '</th>' ;
$col_names [] = 'submission_id' ;
}
if ( ! isset ( $config [ 'problem_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::problem' ) . '</th>' ;
$col_names [] = 'problem_id' ;
}
if ( ! isset ( $config [ 'hacker_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::hacker' ) . '</th>' ;
$col_names [] = 'hacker' ;
}
if ( ! isset ( $config [ 'owner_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::owner' ) . '</th>' ;
$col_names [] = 'owner' ;
}
if ( ! isset ( $config [ 'result_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::result' ) . '</th>' ;
}
if ( ! isset ( $config [ 'submit_time_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::submit time' ) . '</th>' ;
$col_names [] = 'submit_time' ;
}
if ( ! isset ( $config [ 'judge_time_hidden' ])) {
$header_row .= '<th>' . UOJLocale :: get ( 'problems::judge time' ) . '</th>' ;
}
$header_row .= '</tr>' ;
if ( ! isSuperUser ( $user )) {
if ( $user != null ) {
$permission_cond = " is_hidden = false or (is_hidden = true and problem_id in (select problem_id from problems_permissions where username = ' { $user [ 'username' ] } ')) " ;
} else {
$permission_cond = " is_hidden = false " ;
}
if ( $cond !== '1' ) {
$cond = " ( $cond ) and ( $permission_cond ) " ;
} else {
$cond = $permission_cond ;
}
}
2022-09-26 12:42:46 +00:00
$table_config = isset ( $config [ 'table_config' ]) ? $config [ 'table_config' ] : null ;
2016-07-18 16:39:37 +00:00
echoLongTable ( $col_names , 'hacks' , $cond , $tail , $header_row ,
2020-06-25 12:41:16 +00:00
function ( $hacks ) use ( $config , $user ) {
2016-07-18 16:39:37 +00:00
echoHack ( $hacks , $config , $user );
2022-09-26 12:42:46 +00:00
}, $table_config );
2016-07-18 16:39:37 +00:00
}
function echoBlog ( $blog , $config = array ()) {
2022-09-29 14:02:56 +00:00
global $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
$default_config = array (
'blog' => $blog ,
'show_title_only' => false ,
'is_preview' => false
);
foreach ( $default_config as $key => $val ) {
if ( ! isset ( $config [ $key ])) {
$config [ $key ] = $val ;
}
}
2022-09-29 14:02:56 +00:00
$config [ 'REQUIRE_LIB' ] = $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
uojIncludeView ( 'blog-preview' , $config );
}
function echoBlogTag ( $tag ) {
2022-10-01 11:34:03 +00:00
global $REQUIRE_LIB ;
if ( isset ( $REQUIRE_LIB [ 'bootstrap5' ])) {
2022-10-02 09:02:17 +00:00
echo '<a class="uoj-blog-tag my-1">' ;
2022-10-01 11:34:03 +00:00
echo '<span class="badge bg-secondary">' ;
} else {
2022-10-02 09:02:17 +00:00
echo '<a class="uoj-blog-tag">' ;
2022-10-01 11:34:03 +00:00
echo '<span class="badge badge-pill badge-secondary">' ;
}
echo HTML :: escape ( $tag ), '</span></a>' ;
2016-07-18 16:39:37 +00:00
}
function echoUOJPageHeader ( $page_title , $extra_config = array ()) {
global $REQUIRE_LIB ;
$config = UOJContext :: pageConfig ();
$config [ 'REQUIRE_LIB' ] = $REQUIRE_LIB ;
$config [ 'PageTitle' ] = $page_title ;
$config = array_merge ( $config , $extra_config );
uojIncludeView ( 'page-header' , $config );
}
function echoUOJPageFooter ( $config = array ()) {
2022-09-23 13:00:17 +00:00
global $REQUIRE_LIB ;
$config [ 'REQUIRE_LIB' ] = $REQUIRE_LIB ;
2016-07-18 16:39:37 +00:00
uojIncludeView ( 'page-footer' , $config );
}
2022-03-21 02:51:31 +00:00
function echoRanklist ( $config = array ()) {
2022-09-23 13:00:17 +00:00
global $REQUIRE_LIB ;
2022-03-21 02:51:31 +00:00
$header_row = '' ;
$header_row .= '<tr>' ;
$header_row .= '<th style="width: 5em;">#</th>' ;
$header_row .= '<th style="width: 14em;">' . UOJLocale :: get ( 'username' ) . '</th>' ;
$header_row .= '<th style="width: 50em;">' . UOJLocale :: get ( 'motto' ) . '</th>' ;
$header_row .= '<th style="width: 5em;">' . UOJLocale :: get ( 'solved' ) . '</th>' ;
$header_row .= '</tr>' ;
$users = array ();
$print_row = function ( $user , $now_cnt ) use ( & $users , $config ) {
if ( ! $users ) {
if ( $now_cnt == 1 ) {
$rank = 1 ;
} else {
$rank = DB :: selectCount ( " select count(*) from (select b.username as username, count(*) as accepted from best_ac_submissions a inner join user_info b on a.submitter = b.username group by username) as derived where accepted > { $user [ 'ac_num' ] } " ) + 1 ;
}
} else {
$rank = $now_cnt ;
}
$user [ 'rank' ] = $rank ;
echo '<tr>' ;
echo '<td>' . $user [ 'rank' ] . '</td>' ;
echo '<td>' . getUserLink ( $user [ 'username' ]) . '</td>' ;
2022-09-18 13:38:57 +00:00
$motto_id = uniqid ( " motto- { $user [ 'username' ] } - " );
echo " <td id= \" $motto_id\ " ></ td > " ;
2022-09-28 23:41:45 +00:00
$motto = rawurlencode ( $user [ 'motto' ]);
2022-09-18 13:38:57 +00:00
$dom_sanitize_config = DOM_SANITIZE_CONFIG ;
echo '<script type="text/javascript">' ;
2022-09-28 23:41:45 +00:00
echo " $ (function() { $ ('# $motto_id ').html(DOMPurify.sanitize(decodeURIComponent( \" { $motto } \" ), $dom_sanitize_config )); }); " ;
2022-09-18 13:38:57 +00:00
echo '</script>' ;
2022-03-21 02:51:31 +00:00
echo '<td>' . $user [ 'ac_num' ] . '</td>' ;
echo '</tr>' ;
$users [] = $user ;
};
$from = 'best_ac_submissions a inner join user_info b on a.submitter = b.username' ;
$col_names = array ( 'b.username as username' , 'count(*) as ac_num' , 'b.motto as motto' );
$cond = '1' ;
$tail = 'group by username order by ac_num desc, username asc' ;
if ( isset ( $config [ 'group_id' ])) {
$group_id = $config [ 'group_id' ];
$from = " best_ac_submissions a inner join user_info b on a.submitter = b.username inner join groups_users c on (a.submitter = c.username and c.group_id = { $group_id } ) " ;
}
if ( isset ( $config [ 'top10' ])) {
$tail .= ' limit 10' ;
}
$config [ 'get_row_index' ] = '' ;
2022-09-21 06:08:14 +00:00
$config [ 'pagination_table' ] = 'user_info' ;
2022-03-21 02:51:31 +00:00
echoLongTable ( $col_names , $from , $cond , $tail , $header_row , $print_row , $config );
}