';
$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}";
if (!$this->styler->shouldFadeDetails($test_info)) {
echo '';
} elseif ($node->nodeName == 'custom-test') {
$test_info = $node->getAttribute('info');
$test_time = $this->_get_attr($node, 'time', -1);
$test_memory = $this->_get_attr($node, 'memory', -1);
echo '
';
$accordion_parent = "{$this->name}_details_accordion";
$accordion_collapse = "{$accordion_parent}_collapse_custom_test";
if (!$this->styler->shouldFadeDetails($test_info)) {
echo '';
}
} elseif ($node->nodeName == 'in') {
echo '
input:
';
echo '
', "\n";
$this->_print_c($node);
echo "\n
";
} elseif ($node->nodeName == 'out') {
echo '
output:
';
echo '
', "\n";
$this->_print_c($node);
echo "\n
";
} elseif ($node->nodeName == 'res') {
echo '
result:
';
echo '
', "\n";
if ($node->hasChildNodes()) {
$this->_print_c($node);
} else {
echo "\n";
}
echo "
";
} elseif ($node->nodeName == "info-block") {
echo '
';
if ($node->hasAttribute("title")) {
if ($node->hasAttribute("size")) {
echo '
';
if ($node->getAttribute("size") <= 1) {
echo '(', $node->getAttribute("size"), ' byte)';
} else {
echo '(', $node->getAttribute("size"), ' bytes)';
}
echo '
';
}
echo '
', $node->getAttribute("title"), ":
";
}
echo '
', "\n";
$this->_print_c($node);
echo "\n
";
echo '
';
} 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) {
$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() {
$this->subtask_num = null;
$this->_print($this->dom->documentElement);
}
}
function echoJudgementDetails($raw_details, $styler, $name) {
try {
$printer = new JudgmentDetailsPrinter($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') {
return 'card-uoj-accepted';
} elseif ($info == 'Time Limit Exceeded') {
return 'card-uoj-tle';
} elseif ($info == 'Acceptable Answer') {
return 'card-uoj-acceptable-answer';
} else {
return 'card-uoj-wrong';
}
}
public function getTestInfoIcon($test_info) {
if ($test_info == 'Accepted' || $test_info == 'Extra Test Passed') {
return '
';
} elseif ($test_info == 'Time Limit Exceeded') {
return '
';
} elseif ($test_info == 'Acceptable Answer') {
return '
';
} elseif ($test_info == 'Wrong Answer') {
return '
';
} else {
return '
';
}
}
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;
public $ioi_contest_is_running = false;
public function getTestInfoClass($info) {
if ($info == 'Success') {
return 'card-uoj-accepted';
} elseif ($info == 'Time Limit Exceeded') {
return 'card-uoj-tle';
} elseif ($info == 'Acceptable Answer') {
return 'card-uoj-acceptable-answer';
} else {
return 'card-uoj-wrong';
}
}
public function getTestInfoIcon($test_info) {
if ($test_info == 'Success') {
return '
';
} elseif ($test_info == 'Time Limit Exceeded') {
return '
';
} elseif ($test_info == 'Acceptable Answer') {
return '
';
} elseif ($test_info == 'Wrong Answer') {
return '
';
} else {
return '
';
}
}
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') {
return 'card-uoj-accepted';
} elseif ($info == 'Time Limit Exceeded') {
return 'card-uoj-tle';
} elseif ($info == 'Acceptable Answer') {
return 'card-uoj-acceptable-answer';
} else {
return 'card-uoj-wrong';
}
}
public function getTestInfoIcon($test_info) {
if ($test_info == 'Accepted' || $test_info == 'Extra Test Passed') {
return '
';
} elseif ($test_info == 'Time Limit Exceeded') {
return '
';
} elseif ($test_info == 'Acceptable Answer') {
return '
';
} elseif ($test_info == 'Wrong Answer') {
return '
';
} else {
return '
';
}
}
public function shouldFadeDetails($info) {
return $this->fade_all_details;
}
}
function echoSubmissionDetails($submission_details, $name) {
echoJudgementDetails($submission_details, new SubmissionDetailsStyler(), $name);
}
function echoCustomTestSubmissionDetails($submission_details, $name) {
echoJudgementDetails($submission_details, new CustomTestSubmissionDetailsStyler(), $name);
}
function echoHackDetails($hack_details, $name) {
echoJudgementDetails($hack_details, new HackDetailsStyler(), $name);
}
function echoHack($hack, $config, $user) {
$problem = queryProblemBrief($hack['problem_id']);
echo '
';
if (!isset($config['id_hidden'])) {
echo '#', $hack['id'], ' | ';
}
if (!isset($config['submission_hidden'])) {
echo '#', $hack['submission_id'], ' | ';
}
if (!isset($config['problem_hidden'])) {
if ($hack['contest_id']) {
echo '', getContestProblemLink($problem, $hack['contest_id'], '!id_and_title'), ' | ';
} else {
echo '', getProblemLink($problem, '!id_and_title'), ' | ';
}
}
if (!isset($config['hacker_hidden'])) {
echo '', getUserLink($hack['hacker']), ' | ';
}
if (!isset($config['owner_hidden'])) {
echo '', getUserLink($hack['owner']), ' | ';
}
if (!isset($config['result_hidden'])) {
if ($hack['judge_time'] == null) {
echo 'Waiting | ';
} elseif ($hack['success'] == null) {
echo 'Judging | ';
} elseif ($hack['success']) {
echo 'Success! | ';
} else {
echo 'Failed. | ';
}
} else {
echo 'Hidden | ';
}
if (!isset($config['submit_time_hidden'])) {
echo '', $hack['submit_time'], ' | ';
}
if (!isset($config['judge_time_hidden'])) {
echo '', $hack['judge_time'], ' | ';
}
echo '
';
}
function echoHackListOnlyOne($hack, $config, $user) {
echo '
';
echo '
';
echo '';
echo '';
if (!isset($config['id_hidden'])) {
echo 'ID | ';
}
if (!isset($config['submission_id_hidden'])) {
echo '' . UOJLocale::get('problems::submission id') . ' | ';
}
if (!isset($config['problem_hidden'])) {
echo '' . UOJLocale::get('problems::problem') . ' | ';
}
if (!isset($config['hacker_hidden'])) {
echo '' . UOJLocale::get('problems::hacker') . ' | ';
}
if (!isset($config['owner_hidden'])) {
echo '' . UOJLocale::get('problems::owner') . ' | ';
}
if (!isset($config['result_hidden'])) {
echo '' . UOJLocale::get('problems::result') . ' | ';
}
if (!isset($config['submit_time_hidden'])) {
echo '' . UOJLocale::get('problems::submit time') . ' | ';
}
if (!isset($config['judge_time_hidden'])) {
echo '' . UOJLocale::get('problems::judge time') . ' | ';
}
echo '
';
echo '';
echo '';
echoHack($hack, $config, $user);
echo '';
echo '
';
echo '
';
}
function echoHacksList($cond, $tail, $config, $user) {
$header_row = '
';
$col_names = [];
$col_names[] = 'id';
$col_names[] = 'success';
$col_names[] = 'status';
$col_names[] = 'judge_time';
if (!isset($config['id_hidden'])) {
$header_row .= 'ID | ';
}
if (!isset($config['submission_id_hidden'])) {
$header_row .= '' . UOJLocale::get('problems::submission id') . ' | ';
$col_names[] = 'submission_id';
}
if (!isset($config['problem_hidden'])) {
$header_row .= '' . UOJLocale::get('problems::problem') . ' | ';
$col_names[] = 'problem_id';
}
if (!isset($config['hacker_hidden'])) {
$header_row .= '' . UOJLocale::get('problems::hacker') . ' | ';
$col_names[] = 'hacker';
}
if (!isset($config['owner_hidden'])) {
$header_row .= '' . UOJLocale::get('problems::owner') . ' | ';
$col_names[] = 'owner';
}
if (!isset($config['result_hidden'])) {
$header_row .= '' . UOJLocale::get('problems::result') . ' | ';
}
if (!isset($config['submit_time_hidden'])) {
$header_row .= '' . UOJLocale::get('problems::submit time') . ' | ';
$col_names[] = 'submit_time';
}
if (!isset($config['judge_time_hidden'])) {
$header_row .= '' . UOJLocale::get('problems::judge time') . ' | ';
}
$header_row .= '
';
if (!isSuperUser($user)) {
if ($user != null) {
$permission_cond = DB::lor([
'is_hidden' => false,
DB::land([
'is_hidden' => true,
DB::lor([
[
'problem_id', 'in', DB::rawbracket([
'select problem_id from problems_permissions',
'where', ['username' => $user['username']]
])
],
[
'problem_id', 'in', DB::rawbracket([
'select problem_id from problems',
'where', ['uploader' => $user['username']]
])
]
])
])
]);
} else {
$permission_cond = ['is_hidden' => false];
}
if ($cond !== '1') {
$cond = [
DB::conds($cond),
DB::conds($permission_cond)
];
} else {
$cond = $permission_cond;
}
}
$table_config = isset($config['table_config']) ? $config['table_config'] : null;
echoLongTable(
$col_names,
'hacks',
$cond,
$tail,
$header_row,
function ($hacks) use ($config, $user) {
echoHack($hacks, $config, $user);
},
$table_config
);
}
function echoBlog($blog, $config = array()) {
global $REQUIRE_LIB;
$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;
}
}
$config['REQUIRE_LIB'] = $REQUIRE_LIB;
uojIncludeView('blog-preview', $config);
}
function echoBlogTag($tag) {
echo '
', '', HTML::escape($tag), ' ';
}
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()) {
global $REQUIRE_LIB;
$config['REQUIRE_LIB'] = $REQUIRE_LIB;
uojIncludeView('page-footer', $config);
}
function echoRanklist($config = []) {
$header_row = '';
$header_row .= '
';
$header_row .= '# | ';
$header_row .= '' . UOJLocale::get('username') . ' | ';
$header_row .= '' . UOJLocale::get('motto') . ' | ';
$header_row .= '' . UOJLocale::get('solved') . ' | ';
$header_row .= '
';
$parsedown = HTML::parsedown();
$purifier = HTML::purifier_inline();
$users = [];
$print_row = function ($user, $now_cnt) use (&$users, $config, $purifier, $parsedown) {
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 '
';
echo '' . $user['rank'] . ' | ';
echo '' . getUserLink($user['username']) . ' | ';
echo "";
echo $purifier->purify($parsedown->line($user['motto']));
echo " | ";
echo '' . $user['ac_num'] . ' | ';
echo '
';
$users[] = $user;
};
$from = 'user_info';
$col_names = ['user_info.username as username', 'ac_num', 'motto'];
$cond = '1';
$tail = 'group by user_info.username order by ac_num desc, user_info.username asc';
if (isset($config['group_id'])) {
$group_id = $config['group_id'];
$from = "user_info inner join groups_users on (user_info.username = groups_users.username and groups_users.group_id = {$group_id})";
$config['pagination_cond'] = "group_id = {$group_id}";
}
if (isset($config['top10'])) {
$tail .= ' limit 10';
}
$config['get_row_index'] = '';
echoLongTable($col_names, $from, $cond, $tail, $header_row, $print_row, $config);
}
// ===== uoj.ac =====
function echoJudgmentDetails($raw_details, $styler, $name) {
try {
$printer = new JudgmentDetailsPrinter($raw_details, $styler, $name);
$printer->printHTML();
} catch (Exception $e) {
echo 'Failed to show details';
}
}