uoj-html-lib.php 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. <?php
  2. function uojHandleAtSign($str, $uri) {
  3. $referrers = array();
  4. $res = preg_replace_callback('/@(@|[a-zA-Z0-9_]{1,20})/', function($matches) use (&$referrers) {
  5. if ($matches[1] === '@') {
  6. return '@';
  7. } else {
  8. $user = queryUser($matches[1]);
  9. if ($user == null) {
  10. return $matches[0];
  11. } else {
  12. $referrers[$user['username']] = '';
  13. return '<span class="uoj-username" data-rating="'.$user['rating'].'">@'.$user['username'].'</span>';
  14. }
  15. }
  16. }, $str);
  17. $referrers_list = array();
  18. foreach ($referrers as $referrer => $val) {
  19. $referrers_list[] = $referrer;
  20. }
  21. return array($res, $referrers_list);
  22. }
  23. function uojFilePreview($file_name, $output_limit, $file_type = 'text') {
  24. switch ($file_type) {
  25. case 'text':
  26. return strOmit(file_get_contents($file_name, false, null, 0, $output_limit + 4), $output_limit);
  27. default:
  28. return strOmit(shell_exec('xxd -g 4 -l 5000 ' . escapeshellarg($file_name) . ' | head -c ' . ($output_limit + 4)), $output_limit);
  29. }
  30. }
  31. function uojIncludeView($name, $view_params = array()) {
  32. extract($view_params);
  33. include $_SERVER['DOCUMENT_ROOT'].'/app/views/'.$name.'.php';
  34. }
  35. function redirectTo($url) {
  36. header('Location: '.$url);
  37. die();
  38. }
  39. function permanentlyRedirectTo($url) {
  40. header("HTTP/1.1 301 Moved Permanently");
  41. header('Location: '.$url);
  42. die();
  43. }
  44. function redirectToLogin() {
  45. if (UOJContext::isAjax()) {
  46. die('please <a href="'.HTML::url('/login').'">login</a>');
  47. } else {
  48. header('Location: '.HTML::url('/login'));
  49. die();
  50. }
  51. }
  52. function becomeMsgPage($msg, $title = '消息') {
  53. if (UOJContext::isAjax()) {
  54. die($msg);
  55. } else {
  56. echoUOJPageHeader($title);
  57. echo $msg;
  58. echoUOJPageFooter();
  59. die();
  60. }
  61. }
  62. function become404Page() {
  63. header($_SERVER['SERVER_PROTOCOL'] . " 404 Not Found", true, 404);
  64. becomeMsgPage('<div class="text-center"><div style="font-size:233px">404</div><p>唔……未找到该页面……你是从哪里点进来的……&gt;_&lt;……</p></div>', '404');
  65. }
  66. function become403Page() {
  67. header($_SERVER['SERVER_PROTOCOL'] . " 403 Forbidden", true, 403);
  68. becomeMsgPage('<div class="text-center"><div style="font-size:233px">403</div><p>禁止入内! T_T</p></div>', '403');
  69. }
  70. function getUserLink($username, $rating = null, $certs = null) {
  71. if (validateUsername($username) && ($user = queryUser($username))) {
  72. if ($rating == null) {
  73. $rating = $user['rating'];
  74. }
  75. if ($cert == null) {
  76. $certs = $user['certs'];
  77. }
  78. return '<span class="uoj-username" data-rating="'.$rating.'" data-certs="'.$certs.'">'.$username.'</span>';
  79. } else {
  80. $esc_username = HTML::escape($username);
  81. return '<span>'.$esc_username.'</span>';
  82. }
  83. }
  84. function getRemoteProblemLink($rpid) {
  85. $rp = queryRemoteProblemBrief($rpid);
  86. return '<a href="/rp/' . $rpid . '">' . HTML::escape($rp['title']) . '</a>';
  87. }
  88. function getProblemLink($problem, $problem_title = '!title_only') {
  89. if ($problem_title == '!title_only') {
  90. $problem_title = HTML::escape($problem['title']);
  91. } elseif ($problem_title == '!id_and_title') {
  92. $problem_title = "#${problem['id']}. " . HTML::escape($problem['title']);
  93. }
  94. return '<a href="/problem/'.$problem['id'].'">'.$problem_title.'</a>';
  95. }
  96. function getContestProblemLink($problem, $contest_id, $problem_title = '!title_only') {
  97. if ($problem_title == '!title_only') {
  98. $problem_title = HTML::escape($problem['title']);
  99. } elseif ($problem_title == '!id_and_title') {
  100. $problem_title = "#{$problem['id']}. " . HTML::escape($problem['title']);
  101. }
  102. return '<a href="/contest/'.$contest_id.'/problem/'.$problem['id'].'">'.$problem_title.'</a>';
  103. }
  104. function getBlogLink($id) {
  105. if (validateUInt($id) && $blog = queryBlog($id)) {
  106. return '<a href="/blogs/'.$id.'">'.$blog['title'].'</a>';
  107. }
  108. }
  109. function getClickZanBlock($type, $id, $cnt, $val = null) {
  110. if ($val == null) {
  111. $val = queryZanVal($id, $type, Auth::user());
  112. }
  113. return '<div class="uoj-click-zan-block" data-id="'.$id.'" data-type="'.$type.'" data-val="'.$val.'" data-cnt="'.$cnt.'"></div>';
  114. }
  115. function getLongTablePageRawUri($page) {
  116. $path = strtok(UOJContext::requestURI(), '?');
  117. $query_string = strtok('?');
  118. parse_str($query_string, $param);
  119. $param['page'] = $page;
  120. if ($page == 1) {
  121. unset($param['page']);
  122. }
  123. if ($param) {
  124. return $path . '?' . http_build_query($param);
  125. } else {
  126. return $path;
  127. }
  128. }
  129. function getLongTablePageUri($page) {
  130. return HTML::escape(getLongTablePageRawUri($page));
  131. }
  132. function echoLongTable($col_names, $table_name, $cond, $tail, $header_row, $print_row, $config) {
  133. $pag_config = $config;
  134. $pag_config['col_names'] = $col_names;
  135. $pag_config['table_name'] = $table_name;
  136. $pag_config['cond'] = $cond;
  137. $pag_config['tail'] = $tail;
  138. $pag = new Paginator($pag_config);
  139. $div_classes = isset($config['div_classes']) ? $config['div_classes'] : array('table-responsive', 'shadow', 'my-4');
  140. $table_classes = isset($config['table_classes']) ? $config['table_classes'] : array('table', 'table-bordered', 'table-hover', 'table-striped', 'table-text-center');
  141. echo '<div class="', join($div_classes, ' '), '">';
  142. echo '<table class="', join($table_classes, ' '), '">';
  143. echo '<thead>';
  144. echo $header_row;
  145. echo '</thead>';
  146. echo '<tbody>';
  147. foreach ($pag->get() as $idx => $row) {
  148. if (isset($config['get_row_index'])) {
  149. $print_row($row, $idx);
  150. } else {
  151. $print_row($row);
  152. }
  153. }
  154. if ($pag->isEmpty()) {
  155. echo '<tr><td colspan="233">'.UOJLocale::get('none').'</td></tr>';
  156. }
  157. echo '</tbody>';
  158. echo '</table>';
  159. echo '</div>';
  160. if (isset($config['print_after_table'])) {
  161. $fun = $config['print_after_table'];
  162. $fun();
  163. }
  164. echo $pag->pagination();
  165. }
  166. function getSubmissionStatusDetails($submission) {
  167. $html = '<td colspan="233" style="vertical-align: middle">';
  168. $out_status = explode(', ', $submission['status'])[0];
  169. $fly = '<img src="/images/utility/qpx_n/b37.gif" alt="小熊像超人一样飞" class="img-rounded" />';
  170. $think = '<img src="/images/utility/qpx_n/b29.gif" alt="小熊像在思考" class="img-rounded" />';
  171. if ($out_status == 'Judged') {
  172. $status_text = '<strong>Judged!</strong>';
  173. $status_img = $fly;
  174. } else {
  175. if ($submission['status_details'] !== '') {
  176. $status_img = $fly;
  177. $status_text = HTML::escape($submission['status_details']);
  178. } else {
  179. $status_img = $think;
  180. $status_text = $out_status;
  181. }
  182. }
  183. $html .= '<div class="uoj-status-details-img-div">' . $status_img . '</div>';
  184. $html .= '<div class="uoj-status-details-text-div">' . $status_text . '</div>';
  185. $html .= '</td>';
  186. return $html;
  187. }
  188. function echoSubmission($submission, $config, $user) {
  189. $problem = queryProblemBrief($submission['problem_id']);
  190. $submitterLink = getUserLink($submission['submitter']);
  191. if ($submission['score'] == null) {
  192. $used_time_str = "/";
  193. $used_memory_str = "/";
  194. } else {
  195. $used_time_str = $submission['used_time'] . 'ms';
  196. $used_memory_str = $submission['used_memory'] . 'kb';
  197. }
  198. $status = explode(', ', $submission['status'])[0];
  199. $show_status_details = Auth::check() && ($submission['submitter'] === Auth::id() || isSuperUser(queryUser(Auth::id()))) && $status !== 'Judged';
  200. if (!$show_status_details) {
  201. echo '<tr>';
  202. } else {
  203. echo '<tr class="warning">';
  204. }
  205. if (!isset($config['id_hidden'])) {
  206. echo '<td><a href="/submission/', $submission['id'], '">#', $submission['id'], '</a></td>';
  207. }
  208. if (!isset($config['problem_hidden'])) {
  209. if ($submission['contest_id']) {
  210. echo '<td>', getContestProblemLink($problem, $submission['contest_id'], '!id_and_title'), '</td>';
  211. } else if ($submission['problem_id'] != 260328) {
  212. echo '<td>', getProblemLink($problem, '!id_and_title'), '</td>';
  213. } else {
  214. foreach (json_decode($submission['content'], true)['config'] as $row)
  215. if ($row[0] == 'rpid') {
  216. $rpid = $row[1];
  217. break;
  218. }
  219. echo '<td>' . getRemoteProblemLink($rpid) . '</td>';
  220. }
  221. }
  222. if (!isset($config['submitter_hidden'])) {
  223. echo '<td>', $submitterLink, '</td>';
  224. }
  225. if (!isset($config['result_hidden'])) {
  226. echo '<td>';
  227. if ($status == 'Judged') {
  228. if ($submission['score'] == null) {
  229. echo '<a href="/submission/', $submission['id'], '" class="small">', $submission['result_error'], '</a>';
  230. } else {
  231. echo '<a href="/submission/', $submission['id'], '" class="uoj-score">', $submission['score'], '</a>';
  232. }
  233. } else {
  234. echo '<a href="/submission/', $submission['id'], '" class="small">', $status, '</a>';
  235. }
  236. echo '</td>';
  237. }
  238. if (!isset($config['used_time_hidden'])) {
  239. echo '<td>', $used_time_str, '</td>';
  240. }
  241. if (!isset($config['used_memory_hidden'])) {
  242. echo '<td>', $used_memory_str, '</td>';
  243. }
  244. echo '<td>', '<a href="/submission/', $submission['id'], '">', $submission['language'], '</a>', '</td>';
  245. if ($submission['tot_size'] < 1024) {
  246. $size_str = $submission['tot_size'] . 'b';
  247. } else {
  248. $size_str = sprintf("%.1f", $submission['tot_size'] / 1024) . 'kb';
  249. }
  250. echo '<td>', $size_str, '</td>';
  251. if (!isset($config['submit_time_hidden'])) {
  252. echo '<td><small>', $submission['submit_time'], '</small></td>';
  253. }
  254. if (!isset($config['judge_time_hidden'])) {
  255. echo '<td><small>', $submission['judge_time'], '</small></td>';
  256. }
  257. echo '</tr>';
  258. if ($show_status_details) {
  259. echo '<tr id="', "status_details_{$submission['id']}", '" class="info">';
  260. echo getSubmissionStatusDetails($submission);
  261. echo '</tr>';
  262. echo '<script type="text/javascript">update_judgement_status_details('.$submission['id'].')</script>';
  263. }
  264. }
  265. function echoSubmissionsListOnlyOne($submission, $config, $user) {
  266. echo '<div class="table-responsive shadow my-4">';
  267. echo '<table class="table table-bordered table-text-center">';
  268. echo '<thead>';
  269. echo '<tr>';
  270. if (!isset($config['id_hidden'])) {
  271. echo '<th>ID</th>';
  272. }
  273. if (!isset($config['problem_hidden'])) {
  274. echo '<th>'.UOJLocale::get('problems::problem').'</th>';
  275. }
  276. if (!isset($config['submitter_hidden'])) {
  277. echo '<th>'.UOJLocale::get('problems::submitter').'</th>';
  278. }
  279. if (!isset($config['result_hidden'])) {
  280. echo '<th>'.UOJLocale::get('problems::result').'</th>';
  281. }
  282. if (!isset($config['used_time_hidden'])) {
  283. echo '<th>'.UOJLocale::get('problems::used time').'</th>';
  284. }
  285. if (!isset($config['used_memory_hidden'])) {
  286. echo '<th>'.UOJLocale::get('problems::used memory').'</th>';
  287. }
  288. echo '<th>'.UOJLocale::get('problems::language').'</th>';
  289. echo '<th>'.UOJLocale::get('problems::file size').'</th>';
  290. if (!isset($config['submit_time_hidden'])) {
  291. echo '<th>'.UOJLocale::get('problems::submit time').'</th>';
  292. }
  293. if (!isset($config['judge_time_hidden'])) {
  294. echo '<th>'.UOJLocale::get('problems::judge time').'</th>';
  295. }
  296. echo '</tr>';
  297. echo '</thead>';
  298. echo '<tbody>';
  299. echoSubmission($submission, $config, $user);
  300. echo '</tbody>';
  301. echo '</table>';
  302. echo '</div>';
  303. }
  304. function echoSubmissionsList($cond, $tail, $config, $user) {
  305. $header_row = '<tr>';
  306. $col_names = array();
  307. $col_names[] = 'submissions.status_details';
  308. $col_names[] = 'submissions.status';
  309. $col_names[] = 'submissions.result_error';
  310. $col_names[] = 'submissions.score';
  311. $col_names[] = 'submissions.content';
  312. if (!isset($config['id_hidden'])) {
  313. $header_row .= '<th>ID</th>';
  314. $col_names[] = 'submissions.id';
  315. }
  316. if (!isset($config['problem_hidden'])) {
  317. $header_row .= '<th>'.UOJLocale::get('problems::problem').'</th>';
  318. $col_names[] = 'submissions.problem_id';
  319. $col_names[] = 'submissions.contest_id';
  320. }
  321. if (!isset($config['submitter_hidden'])) {
  322. $header_row .= '<th>'.UOJLocale::get('problems::submitter').'</th>';
  323. $col_names[] = 'submissions.submitter';
  324. }
  325. if (!isset($config['result_hidden'])) {
  326. $header_row .= '<th>'.UOJLocale::get('problems::result').'</th>';
  327. }
  328. if (!isset($config['used_time_hidden'])) {
  329. $header_row .= '<th>'.UOJLocale::get('problems::used time').'</th>';
  330. $col_names[] = 'submissions.used_time';
  331. }
  332. if (!isset($config['used_memory_hidden'])) {
  333. $header_row .= '<th>'.UOJLocale::get('problems::used memory').'</th>';
  334. $col_names[] = 'submissions.used_memory';
  335. }
  336. $header_row .= '<th>'.UOJLocale::get('problems::language').'</th>';
  337. $col_names[] = 'submissions.language';
  338. $header_row .= '<th>'.UOJLocale::get('problems::file size').'</th>';
  339. $col_names[] = 'submissions.tot_size';
  340. if (!isset($config['submit_time_hidden'])) {
  341. $header_row .= '<th>'.UOJLocale::get('problems::submit time').'</th>';
  342. $col_names[] = 'submissions.submit_time';
  343. }
  344. if (!isset($config['judge_time_hidden'])) {
  345. $header_row .= '<th>'.UOJLocale::get('problems::judge time').'</th>';
  346. $col_names[] = 'submissions.judge_time';
  347. }
  348. $header_row .= '</tr>';
  349. $table_name = isset($config['table_name']) ? $config['table_name'] : 'submissions';
  350. if (!isSuperUser($user)) {
  351. if ($user != null) {
  352. $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']}')) or (submissions.is_hidden = 1 and (select max(find_in_set(submissions.problem_id, privs)) as nr from user_info where username like 'group_%' and find_in_set(username, '{$user['extgroups']}')))";
  353. } else {
  354. $permission_cond = "submissions.is_hidden = false";
  355. }
  356. if ($cond !== '1') {
  357. $cond = "($cond) and ($permission_cond)";
  358. } else {
  359. $cond = $permission_cond;
  360. }
  361. }
  362. $table_config = isset($config['table_config']) ? $config['table_config'] : null;
  363. echoLongTable($col_names, $table_name, $cond, $tail, $header_row,
  364. function($submission) use ($config, $user) {
  365. echoSubmission($submission, $config, $user);
  366. }, $table_config);
  367. }
  368. function echoShortList($header, $rows, $print_row) {
  369. echo '<div class="table-responsive"><table class="table table-bordered table-hover table-striped table-text-center">';
  370. echo '<thead>';
  371. echo $header;
  372. echo '</thead>';
  373. echo '<tbody>';
  374. foreach ($rows as $idx => $row)
  375. $print_row($row);
  376. if (empty($rows))
  377. echo '<tr><td colspan="233">'.UOJLocale::get('none').'</td></tr>';
  378. echo '</tbody>';
  379. echo '</table>';
  380. echo '</div>';
  381. }
  382. function echoBelongGroupList($user) {
  383. echoShortList('<tr><th>组名</th><th>显示名</th><th>题目</th></tr>', queryUserExtgroups($user), function($grp) {
  384. $qp = queryUser($grp);
  385. $link = getUserLink($qp['username']);
  386. $name = HTML::escape($qp['email']);
  387. echo <<<HTML
  388. <tr>
  389. <td>$link</td>
  390. <td>$name</td>
  391. <td><a href="/problems/group/{$grp}">题目</a></td>
  392. </tr>
  393. HTML;
  394. });
  395. }
  396. function echoGroupMemberList($grp) {
  397. echoShortList('<tr><th>用户名</th><th>管理</th></tr>', queryGroupMembers($grp),
  398. function($usern) use ($grp) {
  399. $username = $usern['username'];
  400. $user = queryUser($username);
  401. $link = getUserLink($username);
  402. if (hasGroupCtrlPermission($user, $grp)) $adminp = '<b>是</b>';
  403. else $adminp = '否';
  404. echo <<<HTML
  405. <tr>
  406. <td>$link</td>
  407. <td>$adminp</td>
  408. </tr>
  409. HTML;
  410. });
  411. }
  412. function echoGroupProblemList($grp) {
  413. echoShortList('<tr><th>题号</th><th>题名</th><th>控制</th><th>压缩包大小</th></tr>', queryGroupProblems($grp),
  414. function($pid) use ($grp) {
  415. $problem = queryProblemBrief($pid);
  416. $pid = $pid;
  417. $title = HTML::escape($problem['title']);
  418. if ($problem['ctrl'] && $problem['ctrl'] == $grp['username']) $adminp = '<b>是</b>';
  419. else $adminp = '否';
  420. $size = printSize(queryProblemSize($pid));
  421. echo <<<HTML
  422. <tr><td>$pid</td>
  423. <td><a href="/problem/{$pid}">$title</a></td>
  424. <td>$adminp</td>
  425. <td>$size</td></tr>
  426. HTML;
  427. });
  428. }
  429. function echoGroupProblemSizeList($grp) {
  430. echoShortList('<tr><th>题号</th><th>题名</th><th>压缩包大小</th></tr>', queryGroupCtrlProblems($grp),
  431. function($pid) {
  432. $problem = queryProblemBrief($pid);
  433. $pid = $pid;
  434. $title = HTML::escape($problem['title']);
  435. $size = printSize(queryProblemSize($pid));
  436. echo <<<HTML
  437. <tr><td>$pid</td>
  438. <td><a href="/problem/{$pid}">$title</a></td>
  439. <td>$size</td></tr>
  440. HTML;
  441. });
  442. }
  443. function echoControlGroupList($user) {
  444. echoShortList('<tr><th>组名</th><th>显示名</th><th>管理</th></tr>', queryUserCtrlgroups($user), function($grp) {
  445. $qp = queryUser($grp);
  446. $link = getUserLink($qp['username']);
  447. $name = HTML::escape($qp['email']);
  448. echo <<<HTML
  449. <tr>
  450. <td>$link</td>
  451. <td>$name</td>
  452. <td><a href="/group-manage/{$grp}">管理</a></td>
  453. </tr>
  454. HTML;
  455. });
  456. }
  457. function echoGroupsList() {
  458. $header_row = '<tr>';
  459. $col_names = ['username', 'privs'];
  460. $header_row .= '<th>组名</th>';
  461. $header_row .= '<th>组权限</th>';
  462. $header_row .= '</tr>';
  463. $table_name = 'user_info';
  464. echoLongTable($col_names, $table_name, "username like 'group_%'", '', $header_row,
  465. function ($group) {
  466. $link = getUserLink($group['username']);
  467. $privs = $group['privs'];
  468. echo <<<HTML
  469. <tr>
  470. <td>
  471. {$link}
  472. </td>
  473. <td>
  474. {$privs_pretty}
  475. </td>
  476. </tr>
  477. HTML;
  478. }, []);
  479. }
  480. function echoCertsList($user) {
  481. echoShortList('<tr><th>勋章</th><th>展示</th></tr>', explode(',', $user['certslist']), function($certs) {
  482. $token = HTML::hiddenToken();
  483. $col = explode('#', $certs)[0];
  484. $text = HTML::escape(explode('#', $certs)[1]);
  485. $cert = '<span class="uoj-certs uoj-certs-' . $col . '">' . $text . '</span>';
  486. echo <<<HTML
  487. <tr>
  488. <td>$cert</td>
  489. <td>
  490. <form action="/certs-manage" method="post">
  491. {$token}
  492. <input type="hidden" name="certs" value="$certs">
  493. <button type="submit" class="btn btn-primary">展示这个</button>
  494. </form>
  495. </td>
  496. </tr>
  497. HTML;
  498. });
  499. }
  500. function echoPastesList() {
  501. $header_row = '<tr>';
  502. $col_names = ['`index`','creator','created_at'];
  503. $header_row .= '<th>ID</th>';
  504. $header_row .= '<th>'.UOJLocale::get("problems::submitter").'</th>';
  505. $header_row .= '<th>'.UOJLocale::get('problems::submit time').'</th>';
  506. $header_row .= '<th> 操作 </th>';
  507. $header_row .= '</tr>';
  508. $table_name = 'pastes';
  509. echoLongTable($col_names, $table_name, "1", 'order by created_at desc', $header_row,
  510. function($paste) {
  511. $user = getUserLink($paste['creator']);
  512. $token = HTML::hiddenToken();
  513. echo <<<HTML
  514. <tr>
  515. <td>
  516. <a href="/pastes/{$paste['index']}">{$paste['index']}</a>
  517. </td>
  518. <td>
  519. {$user}
  520. </td>
  521. <td>
  522. {$paste['created_at']}
  523. </td>
  524. <td>
  525. <form action="/super-manage/paste" method="post" class="form-horizontal">
  526. {$token}
  527. <input type="text" class="form-control" name="paste_deleter_name" id="input-paste_deleter_name" value="{$paste['index']}" style="display: none;">
  528. <button type="submit" name="submit-paste_deleter" value="paste_deleter" class="btn btn-sm btn-danger" style="margin: 0">删除</button>
  529. </form>
  530. </td>
  531. </tr>
  532. HTML;
  533. }, []);
  534. }
  535. function echoPasteContent($paste) {
  536. $zip_file = new ZipArchive();
  537. $submission_content = json_decode($paste['content'], true);
  538. $zip_file->open(UOJContext::storagePath().$submission_content['file_name']);
  539. $config = array();
  540. foreach ($submission_content['config'] as $config_key => $config_val) {
  541. $config[$config_val[0]] = $config_val[1];
  542. }
  543. $file_content = $zip_file->getFromName("paste.code");
  544. $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
  545. $file_language = htmlspecialchars($config["paste_language"]);
  546. $footer_text = UOJLocale::get('problems::source code').', '.UOJLocale::get('problems::language').': '.$file_language;
  547. $footer_text .= ", ".UOJLocale::get("problems::submitter") . <<<HTML
  548. : <a href="/user/profile/${paste['creator']}">${paste['creator']}</a>
  549. HTML;
  550. $footer_text .= ", ".UOJLocale::get("problems::submit time").": ".$paste['created_at'];
  551. switch ($file_language) {
  552. case 'C++14':
  553. case 'C++17':
  554. case 'C++17ubsan':
  555. $sh_class = 'sh_cpp';
  556. break;
  557. case 'Python2':
  558. case 'Python3':
  559. $sh_class = 'sh_python';
  560. break;
  561. case 'Java8':
  562. case 'Java11':
  563. $sh_class = 'sh_java';
  564. break;
  565. case 'C':
  566. $sh_class = 'sh_c';
  567. break;
  568. case 'Pascal':
  569. $sh_class = 'sh_pascal';
  570. break;
  571. default:
  572. $sh_class = '';
  573. break;
  574. }
  575. echo '<div class="card border-info mb-3">';
  576. echo '<div class="card-header bg-info">';
  577. echo '<h4 class="card-title">Paste!</h4>';
  578. echo '</div>';
  579. echo '<div class="card-body">';
  580. echo '<pre><code class="'.$sh_class.'">'.$file_content."\n".'</code></pre>';
  581. echo '</div>';
  582. echo '<div class="card-footer">'.$footer_text.'</div>';
  583. echo '</div>';
  584. $zip_file->close();
  585. }
  586. function echoSubmissionContent($submission, $requirement) {
  587. $zip_file = new ZipArchive();
  588. $submission_content = json_decode($submission['content'], true);
  589. $zip_file->open(UOJContext::storagePath().$submission_content['file_name']);
  590. $config = array();
  591. foreach ($submission_content['config'] as $config_key => $config_val) {
  592. $config[$config_val[0]] = $config_val[1];
  593. }
  594. foreach ($requirement as $req) {
  595. if ($req['type'] == "source code") {
  596. $file_content = $zip_file->getFromName("{$req['name']}.code");
  597. $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
  598. $file_language = htmlspecialchars($config["{$req['name']}_language"]);
  599. $footer_text = UOJLocale::get('problems::source code').', '.UOJLocale::get('problems::language').': '.$file_language;
  600. switch ($file_language) {
  601. case 'C++14':
  602. case 'C++17':
  603. case 'C++17ubsan':
  604. $sh_class = 'sh_cpp';
  605. break;
  606. case 'Python2':
  607. case 'Python3':
  608. $sh_class = 'sh_python';
  609. break;
  610. case 'Java8':
  611. case 'Java11':
  612. $sh_class = 'sh_java';
  613. break;
  614. case 'C':
  615. $sh_class = 'sh_c';
  616. break;
  617. case 'Pascal':
  618. $sh_class = 'sh_pascal';
  619. break;
  620. default:
  621. $sh_class = '';
  622. break;
  623. }
  624. echo '<div class="card border-info mb-3">';
  625. echo '<div class="card-header bg-info">';
  626. echo '<h4 class="card-title">'.$req['name'].'</h4>';
  627. echo '</div>';
  628. echo '<div class="card-body">';
  629. echo '<pre><code class="'.$sh_class.'">'.$file_content."\n".'</code></pre>';
  630. echo '</div>';
  631. echo '<div class="card-footer">'.$footer_text.'</div>';
  632. echo '</div>';
  633. } elseif ($req['type'] == "text") {
  634. $file_content = $zip_file->getFromName("{$req['file_name']}", 504);
  635. $file_content = strOmit($file_content, 500);
  636. $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
  637. $footer_text = UOJLocale::get('problems::text file');
  638. echo '<div class="card border-info mb-3">';
  639. echo '<div class="card-header bg-info">';
  640. echo '<h4 class="card-title">'.$req['file_name'].'</h4>';
  641. echo '</div>';
  642. echo '<div class="card-body">';
  643. echo '<pre>'."\n".$file_content."\n".'</pre>';
  644. echo '</div>';
  645. echo '<div class="card-footer">'.$footer_text.'</div>';
  646. echo '</div>';
  647. }
  648. }
  649. $zip_file->close();
  650. }
  651. class JudgementDetailsPrinter {
  652. private $name;
  653. private $styler;
  654. private $dom;
  655. private $subtask_num;
  656. private function _print_c($node) {
  657. foreach ($node->childNodes as $child) {
  658. if ($child->nodeName == '#text') {
  659. echo htmlspecialchars($child->nodeValue);
  660. } else {
  661. $this->_print($child);
  662. }
  663. }
  664. }
  665. private function _print($node) {
  666. if ($node->nodeName == 'error') {
  667. echo "<pre>\n";
  668. $this->_print_c($node);
  669. echo "\n</pre>";
  670. } elseif ($node->nodeName == 'tests') {
  671. echo '<div id="', $this->name, '_details_accordion">';
  672. if ($this->styler->show_small_tip) {
  673. echo '<div class="text-right text-muted">', '小提示:点击横条可展开更详细的信息', '</div>';
  674. } elseif ($this->styler->ioi_contest_is_running) {
  675. echo '<div class="text-right text-muted">', 'IOI 赛制比赛中不支持显示详细信息', '</div>';
  676. }
  677. $this->_print_c($node);
  678. echo '</div>';
  679. } elseif ($node->nodeName == 'subtask') {
  680. $subtask_num = $node->getAttribute('num');
  681. $subtask_score = $node->getAttribute('score');
  682. $subtask_info = $node->getAttribute('info');
  683. echo '<div class="card ', $this->styler->getTestInfoClass($subtask_info), ' mb-3">';
  684. $accordion_parent = "{$this->name}_details_accordion";
  685. $accordion_collapse = "{$accordion_parent}_collapse_subtask_{$subtask_num}";
  686. $accordion_collapse_accordion = "{$accordion_collapse}_accordion";
  687. echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
  688. echo '<div class="row">';
  689. echo '<div class="col-sm-4">';
  690. echo '<h3 class="card-title">', 'Subtask #', $subtask_num, ': ', '</h3>';
  691. echo '</div>';
  692. if ($this->styler->show_score) {
  693. echo '<div class="col-sm-4">';
  694. echo '得分:', $subtask_score;
  695. echo '</div>';
  696. echo '<div class="col-sm-4">';
  697. echo htmlspecialchars($subtask_info);
  698. echo '</div>';
  699. } else {
  700. echo '<div class="col-sm-8">';
  701. echo htmlspecialchars($subtask_info);
  702. echo '</div>';
  703. }
  704. echo '</div>';
  705. echo '</div>';
  706. echo '<div id="', $accordion_collapse, '" class="card-collapse collapse">';
  707. echo '<div class="card-body">';
  708. echo '<div id="', $accordion_collapse_accordion, '">';
  709. $this->subtask_num = $subtask_num;
  710. $this->_print_c($node);
  711. $this->subtask_num = null;
  712. echo '</div>';
  713. echo '</div>';
  714. echo '</div>';
  715. echo '</div>';
  716. } elseif ($node->nodeName == 'test') {
  717. $test_info = $node->getAttribute('info');
  718. $test_num = $node->getAttribute('num');
  719. $test_score = $node->getAttribute('score');
  720. $test_time = $node->getAttribute('time');
  721. $test_memory = $node->getAttribute('memory');
  722. echo '<div class="card ', $this->styler->getTestInfoClass($test_info), ' mb-3">';
  723. $accordion_parent = "{$this->name}_details_accordion";
  724. if ($this->subtask_num != null) {
  725. $accordion_parent .= "_collapse_subtask_{$this->subtask_num}_accordion";
  726. }
  727. $accordion_collapse = "{$accordion_parent}_collapse_test_{$test_num}";
  728. if (!$this->styler->shouldFadeDetails($test_info)) {
  729. echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
  730. } else {
  731. echo '<div class="card-header">';
  732. }
  733. echo '<div class="row">';
  734. echo '<div class="col-sm-4">';
  735. if ($test_num > 0) {
  736. echo '<h4 class="card-title">', 'Test #', $test_num, ': ', '</h4>';
  737. } else {
  738. echo '<h4 class="card-title">', 'Extra Test:', '</h4>';
  739. }
  740. echo '</div>';
  741. if ($this->styler->show_score) {
  742. echo '<div class="col-sm-4">';
  743. echo '得分:', $test_score;
  744. echo '</div>';
  745. echo '<div class="col-sm-4">';
  746. echo htmlspecialchars($test_info);
  747. echo '</div>';
  748. } else {
  749. echo '<div class="col-sm-8">';
  750. echo htmlspecialchars($test_info);
  751. echo '</div>';
  752. }
  753. echo '<div class="col-sm-4">';
  754. if ($test_time >= 0) {
  755. echo '时间:', $test_time, 'ms';
  756. }
  757. echo '</div>';
  758. echo '<div class="col-sm-4">';
  759. if ($test_memory >= 0) {
  760. echo '内存:', $test_memory, 'kb';
  761. }
  762. echo '</div>';
  763. echo '</div>';
  764. echo '</div>';
  765. if (!$this->styler->shouldFadeDetails($test_info)) {
  766. $accordion_collapse_class = 'card-collapse collapse';
  767. if ($this->styler->collapse_in) {
  768. $accordion_collapse_class .= ' in';
  769. }
  770. echo '<div id="', $accordion_collapse, '" class="', $accordion_collapse_class, '">';
  771. echo '<div class="card-body">';
  772. $this->_print_c($node);
  773. echo '</div>';
  774. echo '</div>';
  775. }
  776. echo '</div>';
  777. } elseif ($node->nodeName == 'custom-test') {
  778. $test_info = $node->getAttribute('info');
  779. $test_time = $node->getAttribute('time');
  780. $test_memory = $node->getAttribute('memory');
  781. echo '<div class="card ', $this->styler->getTestInfoClass($test_info), ' mb-3">';
  782. $accordion_parent = "{$this->name}_details_accordion";
  783. $accordion_collapse = "{$accordion_parent}_collapse_custom_test";
  784. if (!$this->styler->shouldFadeDetails($test_info)) {
  785. echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
  786. } else {
  787. echo '<div class="card-header">';
  788. }
  789. echo '<div class="row">';
  790. echo '<div class="col-sm-2">';
  791. echo '<h4 class="card-title">', '自定义测试:', '</h4>';
  792. echo '</div>';
  793. echo '<div class="col-sm-4">';
  794. echo htmlspecialchars($test_info);
  795. echo '</div>';
  796. echo '<div class="col-sm-3">';
  797. if ($test_time >= 0) {
  798. echo '时间:', $test_time, 'ms';
  799. }
  800. echo '</div>';
  801. echo '<div class="col-sm-3">';
  802. if ($test_memory >= 0) {
  803. echo '空间:', $test_memory, 'kb';
  804. }
  805. echo '</div>';
  806. echo '</div>';
  807. echo '</div>';
  808. if (!$this->styler->shouldFadeDetails($test_info)) {
  809. $accordion_collapse_class = 'card-collapse collapse';
  810. if ($this->styler->collapse_in) {
  811. $accordion_collapse_class .= ' in';
  812. }
  813. echo '<div id="', $accordion_collapse, '" class="', $accordion_collapse_class, '">';
  814. echo '<div class="card-body">';
  815. $this->_print_c($node);
  816. echo '</div>';
  817. echo '</div>';
  818. echo '</div>';
  819. }
  820. } elseif ($node->nodeName == 'in') {
  821. echo "<h4>标准输入:</h4><pre>\n";
  822. $this->_print_c($node);
  823. echo "\n</pre>";
  824. } elseif ($node->nodeName == 'out') {
  825. echo "<h4>标准输出:</h4><pre>\n";
  826. $this->_print_c($node);
  827. echo "\n</pre>";
  828. } elseif ($node->nodeName == 'res') {
  829. echo "<h4>检验结果:</h4><pre>\n";
  830. $this->_print_c($node);
  831. echo "\n</pre>";
  832. } else {
  833. echo '<', $node->nodeName;
  834. foreach ($node->attributes as $attr) {
  835. echo ' ', $attr->name, '="', htmlspecialchars($attr->value), '"';
  836. }
  837. echo '>';
  838. $this->_print_c($node);
  839. echo '</', $node->nodeName, '>';
  840. }
  841. }
  842. public function __construct($details, $styler, $name) {
  843. $this->name = $name;
  844. $this->styler = $styler;
  845. $this->details = $details;
  846. $this->dom = new DOMDocument();
  847. if (!$this->dom->loadXML($this->details)) {
  848. throw new Exception("XML syntax error");
  849. }
  850. $this->details = '';
  851. }
  852. public function printHTML() {
  853. $this->subtask_num = null;
  854. $this->_print($this->dom->documentElement);
  855. }
  856. }
  857. function echoJudgementDetails($raw_details, $styler, $name) {
  858. try {
  859. $printer = new JudgementDetailsPrinter($raw_details, $styler, $name);
  860. $printer->printHTML();
  861. } catch (Exception $e) {
  862. echo 'Failed to show details';
  863. }
  864. }
  865. class SubmissionDetailsStyler {
  866. public $show_score = true;
  867. public $show_small_tip = true;
  868. public $collapse_in = false;
  869. public $fade_all_details = false;
  870. public function getTestInfoClass($info) {
  871. if ($info == 'Accepted' || $info == 'Extra Test Passed') {
  872. return 'card-uoj-accepted';
  873. } elseif ($info == 'Time Limit Exceeded') {
  874. return 'card-uoj-tle';
  875. } elseif ($info == 'Acceptable Answer') {
  876. return 'card-uoj-acceptable-answer';
  877. } else {
  878. return 'card-uoj-wrong';
  879. }
  880. }
  881. public function shouldFadeDetails($info) {
  882. return $this->fade_all_details || $info == 'Extra Test Passed';
  883. }
  884. }
  885. class CustomTestSubmissionDetailsStyler {
  886. public $show_score = true;
  887. public $show_small_tip = false;
  888. public $collapse_in = true;
  889. public $fade_all_details = false;
  890. public $ioi_contest_is_running = false;
  891. public function getTestInfoClass($info) {
  892. if ($info == 'Success') {
  893. return 'card-uoj-accepted';
  894. } elseif ($info == 'Time Limit Exceeded') {
  895. return 'card-uoj-tle';
  896. } elseif ($info == 'Acceptable Answer') {
  897. return 'card-uoj-acceptable-answer';
  898. } else {
  899. return 'card-uoj-wrong';
  900. }
  901. }
  902. public function shouldFadeDetails($info) {
  903. return $this->fade_all_details;
  904. }
  905. }
  906. class HackDetailsStyler {
  907. public $show_score = false;
  908. public $show_small_tip = false;
  909. public $collapse_in = true;
  910. public $fade_all_details = false;
  911. public function getTestInfoClass($info) {
  912. if ($info == 'Accepted' || $info == 'Extra Test Passed') {
  913. return 'card-uoj-accepted';
  914. } elseif ($info == 'Time Limit Exceeded') {
  915. return 'card-uoj-tle';
  916. } elseif ($info == 'Acceptable Answer') {
  917. return 'card-uoj-acceptable-answer';
  918. } else {
  919. return 'card-uoj-wrong';
  920. }
  921. }
  922. public function shouldFadeDetails($info) {
  923. return $this->fade_all_details;
  924. }
  925. }
  926. function echoSubmissionDetails($submission_details, $name) {
  927. echoJudgementDetails($submission_details, new SubmissionDetailsStyler(), $name);
  928. }
  929. function echoCustomTestSubmissionDetails($submission_details, $name) {
  930. echoJudgementDetails($submission_details, new CustomTestSubmissionDetailsStyler(), $name);
  931. }
  932. function echoHackDetails($hack_details, $name) {
  933. echoJudgementDetails($hack_details, new HackDetailsStyler(), $name);
  934. }
  935. function echoHack($hack, $config, $user) {
  936. $problem = queryProblemBrief($hack['problem_id']);
  937. echo '<tr>';
  938. if (!isset($config['id_hidden'])) {
  939. echo '<td><a href="/hack/', $hack['id'], '">#', $hack['id'], '</a></td>';
  940. }
  941. if (!isset($config['submission_hidden'])) {
  942. echo '<td><a href="/submission/', $hack['submission_id'], '">#', $hack['submission_id'], '</a></td>';
  943. }
  944. if (!isset($config['problem_hidden'])) {
  945. if ($hack['contest_id']) {
  946. echo '<td>', getContestProblemLink($problem, $hack['contest_id'], '!id_and_title'), '</td>';
  947. } else {
  948. echo '<td>', getProblemLink($problem, '!id_and_title'), '</td>';
  949. }
  950. }
  951. if (!isset($config['hacker_hidden'])) {
  952. echo '<td>', getUserLink($hack['hacker']), '</td>';
  953. }
  954. if (!isset($config['owner_hidden'])) {
  955. echo '<td>', getUserLink($hack['owner']), '</td>';
  956. }
  957. if (!isset($config['result_hidden'])) {
  958. if ($hack['judge_time'] == null) {
  959. echo '<td><a href="/hack/', $hack['id'], '">Waiting</a></td>';
  960. } elseif ($hack['success'] == null) {
  961. echo '<td><a href="/hack/', $hack['id'], '">Judging</a></td>';
  962. } elseif ($hack['success']) {
  963. echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status" data-success="1"><strong>Success!</strong></a></td>';
  964. } else {
  965. echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status" data-success="0"><strong>Failed.</strong></a></td>';
  966. }
  967. } else {
  968. echo '<td>Hidden</td>';
  969. }
  970. if (!isset($config['submit_time_hidden'])) {
  971. echo '<td>', $hack['submit_time'], '</td>';
  972. }
  973. if (!isset($config['judge_time_hidden'])) {
  974. echo '<td>', $hack['judge_time'], '</td>';
  975. }
  976. echo '</tr>';
  977. }
  978. function echoHackListOnlyOne($hack, $config, $user) {
  979. echo '<div class="table-responsive shadow my-4">';
  980. echo '<table class="table table-bordered table-text-center">';
  981. echo '<thead>';
  982. echo '<tr>';
  983. if (!isset($config['id_hidden'])) {
  984. echo '<th>ID</th>';
  985. }
  986. if (!isset($config['submission_id_hidden'])) {
  987. echo '<th>'.UOJLocale::get('problems::submission id').'</th>';
  988. }
  989. if (!isset($config['problem_hidden'])) {
  990. echo '<th>'.UOJLocale::get('problems::problem').'</th>';
  991. }
  992. if (!isset($config['hacker_hidden'])) {
  993. echo '<th>'.UOJLocale::get('problems::hacker').'</th>';
  994. }
  995. if (!isset($config['owner_hidden'])) {
  996. echo '<th>'.UOJLocale::get('problems::owner').'</th>';
  997. }
  998. if (!isset($config['result_hidden'])) {
  999. echo '<th>'.UOJLocale::get('problems::result').'</th>';
  1000. }
  1001. if (!isset($config['submit_time_hidden'])) {
  1002. echo '<th>'.UOJLocale::get('problems::submit time').'</th>';
  1003. }
  1004. if (!isset($config['judge_time_hidden'])) {
  1005. echo '<th>'.UOJLocale::get('problems::judge time').'</th>';
  1006. }
  1007. echo '</tr>';
  1008. echo '</thead>';
  1009. echo '<tbody>';
  1010. echoHack($hack, $config, $user);
  1011. echo '</tbody>';
  1012. echo '</table>';
  1013. echo '</div>';
  1014. }
  1015. function echoHacksList($cond, $tail, $config, $user) {
  1016. $header_row = '<tr>';
  1017. $col_names = array();
  1018. $col_names[] = 'id';
  1019. $col_names[] = 'success';
  1020. $col_names[] = 'judge_time';
  1021. if (!isset($config['id_hidden'])) {
  1022. $header_row .= '<th>ID</th>';
  1023. }
  1024. if (!isset($config['submission_id_hidden'])) {
  1025. $header_row .= '<th>'.UOJLocale::get('problems::submission id').'</th>';
  1026. $col_names[] = 'submission_id';
  1027. }
  1028. if (!isset($config['problem_hidden'])) {
  1029. $header_row .= '<th>'.UOJLocale::get('problems::problem').'</th>';
  1030. $col_names[] = 'problem_id';
  1031. }
  1032. if (!isset($config['hacker_hidden'])) {
  1033. $header_row .= '<th>'.UOJLocale::get('problems::hacker').'</th>';
  1034. $col_names[] = 'hacker';
  1035. }
  1036. if (!isset($config['owner_hidden'])) {
  1037. $header_row .= '<th>'.UOJLocale::get('problems::owner').'</th>';
  1038. $col_names[] = 'owner';
  1039. }
  1040. if (!isset($config['result_hidden'])) {
  1041. $header_row .= '<th>'.UOJLocale::get('problems::result').'</th>';
  1042. }
  1043. if (!isset($config['submit_time_hidden'])) {
  1044. $header_row .= '<th>'.UOJLocale::get('problems::submit time').'</th>';
  1045. $col_names[] = 'submit_time';
  1046. }
  1047. if (!isset($config['judge_time_hidden'])) {
  1048. $header_row .= '<th>'.UOJLocale::get('problems::judge time').'</th>';
  1049. }
  1050. $header_row .= '</tr>';
  1051. if (!isSuperUser($user)) {
  1052. if ($user != null) {
  1053. $permission_cond = "is_hidden = false or (is_hidden = true and problem_id in (select problem_id from problems_permissions where username = '{$user['username']}'))";
  1054. } else {
  1055. $permission_cond = "is_hidden = false";
  1056. }
  1057. if ($cond !== '1') {
  1058. $cond = "($cond) and ($permission_cond)";
  1059. } else {
  1060. $cond = $permission_cond;
  1061. }
  1062. }
  1063. echoLongTable($col_names, 'hacks', $cond, $tail, $header_row,
  1064. function($hacks) use ($config, $user) {
  1065. echoHack($hacks, $config, $user);
  1066. }, null);
  1067. }
  1068. function echoDatum($datum) {
  1069. $pid = $datum['pid'];
  1070. $title = queryProblemBrief($pid)['title'];
  1071. echo '<tr>';
  1072. echo '<td>' . $datum['id'] . '</td>';
  1073. echo '<td>', getProblemLink(queryProblemBrief($pid), '!id_and_title'), '</td>';
  1074. if ($datum['status'] == 'Done')
  1075. echo '<td><a href="/datum/' . $datum['id'] . '" class="uoj-status" data-success="1"><strong>Done</strong></a></td>';
  1076. else if ($datum['status'] == 'Failed')
  1077. echo '<td><a href="/datum/' . $datum['id'] . '" class="uoj-status" data-success="0"><strong>Failed</strong></a></td>';
  1078. else echo '<td><a href="/datum/' . $datum['id'] . '">' . $datum['status'] . '</a></td>';
  1079. echo '<td>' . $datum['request_time'] . '</td>';
  1080. echo '<td>' . $datum['finish_time'] . '</td>';
  1081. echo '<td>' . $datum['timelimit'] . ' s</td>';
  1082. echo '<td>' . $datum['memlimit'] . ' MB</td>';
  1083. echo '</tr>';
  1084. }
  1085. function echoDatumlistOnlyOne($datum) {
  1086. $header_row = '<tr><th>ID</th><th>题目</th><th>状态</th><th>请求时间</th><th>完成时间</th><th>时间限制</th><th>空间限制</th></tr>';
  1087. echo '<div class="table-responsive shadow my-4">';
  1088. echo '<table class="table table-bordered table-text-center">';
  1089. echo '<thead>';
  1090. echo $header_row;
  1091. echo '</thead>';
  1092. echo '<tbody>';
  1093. echoDatum($datum);
  1094. echo '</tbody>';
  1095. echo '</table></div>';
  1096. }
  1097. function echoDatumList() {
  1098. $col_names = array('id', 'pid', 'request_time', 'status', 'finish_time', 'timelimit', 'memlimit');
  1099. $header_row = '<tr><th>ID</th><th>题目</th><th>状态</th><th>请求时间</th><th>完成时间</th><th>时间限制</th><th>空间限制</th></tr>';
  1100. echoLongTable($col_names, 'datum_requests', '1', '', $header_row,
  1101. function($datum) { echoDatum($datum); }, null);
  1102. }
  1103. function getBlogPreview($str) {
  1104. return '';
  1105. }
  1106. function echoBlogCard($blog) {
  1107. if ($blog == null)
  1108. return;
  1109. $bloghref = "/blogs/" . $blog['id'];
  1110. $blogtitle = $blog['title'];
  1111. $poster = queryUser($blog['poster']);
  1112. $userlink = getUserLink($blog['poster']);
  1113. $posttime = $blog['post_time'];
  1114. $usermotto = HTML::escape($poster['motto']);
  1115. $zanblock = getClickZanBlock('B', $blog['id'], $blog['zan']);
  1116. $avatar = "https://q.qlogo.cn/g?b=qq&nk=" . $poster['qq'] . "&s=100";
  1117. return <<<EOF
  1118. <div class="col-12 mb-3">
  1119. <div class="card wyoj-blog-card border-0 shadow-sm">
  1120. <div class="card-body p-3">
  1121. <a href="$bloghref" class="text-decoration-none text-dark">
  1122. <h5 class="mb-3 wyoj-blog-title">$blogtitle</h5>
  1123. </a>
  1124. <div class="d-flex align-items-center justify-content-between">
  1125. <div class="d-flex align-items-center" style="min-width:0;">
  1126. <img class="uoj-avatar rounded-circle flex-shrink-0 mr-2"
  1127. style="width:28px;height:28px;object-fit:cover;"
  1128. src="$avatar" alt="...">
  1129. <span class="text-truncate">$userlink</span>
  1130. <span class="text-muted ml-2 text-nowrap" style="font-size:0.85rem;">$posttime</span>
  1131. <span class="ml-3 text-truncate" style="font-size:1rem;font-family:'SimSun','宋体','Songti SC','STSong',serif;">$usermotto</span>
  1132. </div>
  1133. <div class="flex-shrink-0 ml-2">$zanblock</div>
  1134. </div>
  1135. </div>
  1136. </div>
  1137. </div>
  1138. EOF;
  1139. }
  1140. function echoRecommendProblem($pid, $link, $name, $descr) {
  1141. return <<<EOF
  1142. <div class="col-md-3 mb-4">
  1143. <div class="card h-100 p-3 text-center">
  1144. <a class="mb-2" href="$link"><h4>$pid</h4></a>
  1145. <h4 class="mb-2">$name</h4>
  1146. <span class="text-bottom">$descr</span>
  1147. </div>
  1148. </div>
  1149. EOF;
  1150. }
  1151. function echoBlog($blog, $config = array()) {
  1152. $default_config = array(
  1153. 'blog' => $blog,
  1154. 'show_title_only' => false,
  1155. 'show_content_only' => false,
  1156. 'is_preview' => false,
  1157. 'outside_blog_domain' => false,
  1158. );
  1159. foreach ($default_config as $key => $val) {
  1160. if (!isset($config[$key])) {
  1161. $config[$key] = $val;
  1162. }
  1163. }
  1164. uojIncludeView('blog-preview', $config);
  1165. }
  1166. function echoBlogTag($tag) {
  1167. echo '<a class="uoj-blog-tag"><span class="badge badge-pill badge-secondary">', HTML::escape($tag), '</span></a>';
  1168. }
  1169. function echoUOJPageHeader($page_title, $extra_config = array()) {
  1170. global $REQUIRE_LIB;
  1171. $config = UOJContext::pageConfig();
  1172. $config['REQUIRE_LIB'] = $REQUIRE_LIB;
  1173. $config['PageTitle'] = $page_title;
  1174. $config = array_merge($config, $extra_config);
  1175. uojIncludeView('page-header', $config);
  1176. }
  1177. function echoUOJPageFooter($config = array()) {
  1178. uojIncludeView('page-footer', $config);
  1179. }
  1180. function getAvatar($user) {
  1181. return '<img class="media-object img-rounded" height="50" width="50" src="' . HTML::avatar_addr($user, 50) . '">';
  1182. }
  1183. function echoRanklist($config = array()) {
  1184. $header_row = '';
  1185. $header_row .= '<tr>';
  1186. $header_row .= '<th style="width: 5em;">#</th>';
  1187. $header_row .= '<th style="width: 14em";>'.'头像'.'</th>';
  1188. $header_row .= '<th style="width: 14em;">'.UOJLocale::get('username').'</th>';
  1189. $header_row .= '<th style="width: 50em;">'.UOJLocale::get('motto').'</th>';
  1190. $header_row .= '<th style="width: 5em;">'.UOJLocale::get('rating').'</th>';
  1191. $header_row .= '</tr>';
  1192. $users = array();
  1193. $relcnt = 0;
  1194. $print_row = function($user, $now_cnt) use (&$users, &$relcnt) {
  1195. #if (!$users) {
  1196. $rank = DB::selectCount("select count(*) from user_info where rating > {$user['rating']}") + 1;
  1197. # } elseif ($user['rating'] == $users[count($users) - 1]['rating']) {
  1198. # $rank = $users[count($users) - 1]['rank'];
  1199. # } else {
  1200. # $rank = $now_cnt;
  1201. # }
  1202. $user['rank'] = $rank;
  1203. $relcnt++;
  1204. echo '<tr>';
  1205. echo '<td>' . $user['rank'] . ' (' . $relcnt . ')</td>';
  1206. echo '<td>' . getAvatar($user) . '</td>';
  1207. echo '<td>' . getUserLink($user['username']) . '</td>';
  1208. echo '<td>' . HTML::escape($user['motto']) . '</td>';
  1209. echo '<td>' . $user['rating'] . '</td>';
  1210. echo '</tr>';
  1211. $users[] = $user;
  1212. };
  1213. $col_names = array('username', 'email', 'qq', 'rating', 'motto');
  1214. $tail = 'inner join contests_registrants c on user_info.username = c.username inner join contests s on s.id = c.contest_id where datediff(now(), s.start_time) <= 180 group by c.username having cnt >= 3 order by rating desc, username asc';
  1215. # $tail = 'order by rating desc, username asc';
  1216. #
  1217. $config['raw_sql'] = 'select u.username, u.email, u.rating, u.rating_rd, u.rating_vol, u.motto, u.qq, count(*) cnt from user_info u inner join contests_registrants c on u.username = c.username inner join contests s on s.id = c.contest_id where datediff(now(), s.start_time) <= 180 group by c.username having cnt >= 3 order by rating desc, username asc';
  1218. if (isset($config['top10'])) {
  1219. $tail .= ' limit 10';
  1220. }
  1221. $config['get_row_index'] = '';
  1222. echoLongTable($col_names, 'user_info', '1', $tail, $header_row, $print_row, $config);
  1223. }