uoj-html-lib.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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 . '">' . $rp['title'] . '</a>';
  87. }
  88. function getProblemLink($problem, $problem_title = '!title_only') {
  89. if ($problem_title == '!title_only') {
  90. $problem_title = $problem['title'];
  91. } elseif ($problem_title == '!id_and_title') {
  92. $problem_title = "#${problem['id']}. ${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 = $problem['title'];
  99. } elseif ($problem_title == '!id_and_title') {
  100. $problem_title = "#{$problem['id']}. {$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 = $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 = $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 = $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 = $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. $col = explode('#', $certs)[0];
  483. $text = explode('#', $certs)[1];
  484. $cert = '<span class="uoj-certs uoj-certs-' . $col . '">' . $text . '</span>';
  485. echo <<<HTML
  486. <tr>
  487. <td>$cert</td>
  488. <td>
  489. <form action="/certs-manage" method="post">
  490. <input type="hidden" name="certs" value="$certs">
  491. <button type="submit" class="btn btn-primary">展示这个</button>
  492. </form>
  493. </td>
  494. </tr>
  495. HTML;
  496. });
  497. }
  498. function echoPastesList() {
  499. $header_row = '<tr>';
  500. $col_names = ['`index`','creator','created_at'];
  501. $header_row .= '<th>ID</th>';
  502. $header_row .= '<th>'.UOJLocale::get("problems::submitter").'</th>';
  503. $header_row .= '<th>'.UOJLocale::get('problems::submit time').'</th>';
  504. $header_row .= '<th> 操作 </th>';
  505. $header_row .= '</tr>';
  506. $table_name = 'pastes';
  507. echoLongTable($col_names, $table_name, "1", 'order by created_at desc', $header_row,
  508. function($paste) {
  509. $user = getUserLink($paste['creator']);
  510. $token = HTML::hiddenToken();
  511. echo <<<HTML
  512. <tr>
  513. <td>
  514. <a href="/pastes/{$paste['index']}">{$paste['index']}</a>
  515. </td>
  516. <td>
  517. {$user}
  518. </td>
  519. <td>
  520. {$paste['created_at']}
  521. </td>
  522. <td>
  523. <form action="/super-manage/paste" method="post" class="form-horizontal">
  524. {$token}
  525. <input type="text" class="form-control" name="paste_deleter_name" id="input-paste_deleter_name" value="{$paste['index']}" style="display: none;">
  526. <button type="submit" name="submit-paste_deleter" value="paste_deleter" class="btn btn-sm btn-danger" style="margin: 0">删除</button>
  527. </form>
  528. </td>
  529. </tr>
  530. HTML;
  531. }, []);
  532. }
  533. function echoPasteContent($paste) {
  534. $zip_file = new ZipArchive();
  535. $submission_content = json_decode($paste['content'], true);
  536. $zip_file->open(UOJContext::storagePath().$submission_content['file_name']);
  537. $config = array();
  538. foreach ($submission_content['config'] as $config_key => $config_val) {
  539. $config[$config_val[0]] = $config_val[1];
  540. }
  541. $file_content = $zip_file->getFromName("paste.code");
  542. $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
  543. $file_language = htmlspecialchars($config["paste_language"]);
  544. $footer_text = UOJLocale::get('problems::source code').', '.UOJLocale::get('problems::language').': '.$file_language;
  545. $footer_text .= ", ".UOJLocale::get("problems::submitter") . <<<HTML
  546. : <a href="/user/profile/${paste['creator']}">${paste['creator']}</a>
  547. HTML;
  548. $footer_text .= ", ".UOJLocale::get("problems::submit time").": ".$paste['created_at'];
  549. switch ($file_language) {
  550. case 'C++14':
  551. case 'C++17':
  552. case 'C++17ubsan':
  553. $sh_class = 'sh_cpp';
  554. break;
  555. case 'Python2':
  556. case 'Python3':
  557. $sh_class = 'sh_python';
  558. break;
  559. case 'Java8':
  560. case 'Java11':
  561. $sh_class = 'sh_java';
  562. break;
  563. case 'C':
  564. $sh_class = 'sh_c';
  565. break;
  566. case 'Pascal':
  567. $sh_class = 'sh_pascal';
  568. break;
  569. default:
  570. $sh_class = '';
  571. break;
  572. }
  573. echo '<div class="card border-info mb-3">';
  574. echo '<div class="card-header bg-info">';
  575. echo '<h4 class="card-title">Paste!</h4>';
  576. echo '</div>';
  577. echo '<div class="card-body">';
  578. echo '<pre><code class="'.$sh_class.'">'.$file_content."\n".'</code></pre>';
  579. echo '</div>';
  580. echo '<div class="card-footer">'.$footer_text.'</div>';
  581. echo '</div>';
  582. $zip_file->close();
  583. }
  584. function echoSubmissionContent($submission, $requirement) {
  585. $zip_file = new ZipArchive();
  586. $submission_content = json_decode($submission['content'], true);
  587. $zip_file->open(UOJContext::storagePath().$submission_content['file_name']);
  588. $config = array();
  589. foreach ($submission_content['config'] as $config_key => $config_val) {
  590. $config[$config_val[0]] = $config_val[1];
  591. }
  592. foreach ($requirement as $req) {
  593. if ($req['type'] == "source code") {
  594. $file_content = $zip_file->getFromName("{$req['name']}.code");
  595. $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
  596. $file_language = htmlspecialchars($config["{$req['name']}_language"]);
  597. $footer_text = UOJLocale::get('problems::source code').', '.UOJLocale::get('problems::language').': '.$file_language;
  598. switch ($file_language) {
  599. case 'C++14':
  600. case 'C++17':
  601. case 'C++17ubsan':
  602. $sh_class = 'sh_cpp';
  603. break;
  604. case 'Python2':
  605. case 'Python3':
  606. $sh_class = 'sh_python';
  607. break;
  608. case 'Java8':
  609. case 'Java11':
  610. $sh_class = 'sh_java';
  611. break;
  612. case 'C':
  613. $sh_class = 'sh_c';
  614. break;
  615. case 'Pascal':
  616. $sh_class = 'sh_pascal';
  617. break;
  618. default:
  619. $sh_class = '';
  620. break;
  621. }
  622. echo '<div class="card border-info mb-3">';
  623. echo '<div class="card-header bg-info">';
  624. echo '<h4 class="card-title">'.$req['name'].'</h4>';
  625. echo '</div>';
  626. echo '<div class="card-body">';
  627. echo '<pre><code class="'.$sh_class.'">'.$file_content."\n".'</code></pre>';
  628. echo '</div>';
  629. echo '<div class="card-footer">'.$footer_text.'</div>';
  630. echo '</div>';
  631. } elseif ($req['type'] == "text") {
  632. $file_content = $zip_file->getFromName("{$req['file_name']}", 504);
  633. $file_content = strOmit($file_content, 500);
  634. $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
  635. $footer_text = UOJLocale::get('problems::text file');
  636. echo '<div class="card border-info mb-3">';
  637. echo '<div class="card-header bg-info">';
  638. echo '<h4 class="card-title">'.$req['file_name'].'</h4>';
  639. echo '</div>';
  640. echo '<div class="card-body">';
  641. echo '<pre>'."\n".$file_content."\n".'</pre>';
  642. echo '</div>';
  643. echo '<div class="card-footer">'.$footer_text.'</div>';
  644. echo '</div>';
  645. }
  646. }
  647. $zip_file->close();
  648. }
  649. class JudgementDetailsPrinter {
  650. private $name;
  651. private $styler;
  652. private $dom;
  653. private $subtask_num;
  654. private function _print_c($node) {
  655. foreach ($node->childNodes as $child) {
  656. if ($child->nodeName == '#text') {
  657. echo htmlspecialchars($child->nodeValue);
  658. } else {
  659. $this->_print($child);
  660. }
  661. }
  662. }
  663. private function _print($node) {
  664. if ($node->nodeName == 'error') {
  665. echo "<pre>\n";
  666. $this->_print_c($node);
  667. echo "\n</pre>";
  668. } elseif ($node->nodeName == 'tests') {
  669. echo '<div id="', $this->name, '_details_accordion">';
  670. if ($this->styler->show_small_tip) {
  671. echo '<div class="text-right text-muted">', '小提示:点击横条可展开更详细的信息', '</div>';
  672. } elseif ($this->styler->ioi_contest_is_running) {
  673. echo '<div class="text-right text-muted">', 'IOI 赛制比赛中不支持显示详细信息', '</div>';
  674. }
  675. $this->_print_c($node);
  676. echo '</div>';
  677. } elseif ($node->nodeName == 'subtask') {
  678. $subtask_num = $node->getAttribute('num');
  679. $subtask_score = $node->getAttribute('score');
  680. $subtask_info = $node->getAttribute('info');
  681. echo '<div class="card ', $this->styler->getTestInfoClass($subtask_info), ' mb-3">';
  682. $accordion_parent = "{$this->name}_details_accordion";
  683. $accordion_collapse = "{$accordion_parent}_collapse_subtask_{$subtask_num}";
  684. $accordion_collapse_accordion = "{$accordion_collapse}_accordion";
  685. echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
  686. echo '<div class="row">';
  687. echo '<div class="col-sm-4">';
  688. echo '<h3 class="card-title">', 'Subtask #', $subtask_num, ': ', '</h3>';
  689. echo '</div>';
  690. if ($this->styler->show_score) {
  691. echo '<div class="col-sm-4">';
  692. echo '得分:', $subtask_score;
  693. echo '</div>';
  694. echo '<div class="col-sm-4">';
  695. echo htmlspecialchars($subtask_info);
  696. echo '</div>';
  697. } else {
  698. echo '<div class="col-sm-8">';
  699. echo htmlspecialchars($subtask_info);
  700. echo '</div>';
  701. }
  702. echo '</div>';
  703. echo '</div>';
  704. echo '<div id="', $accordion_collapse, '" class="card-collapse collapse">';
  705. echo '<div class="card-body">';
  706. echo '<div id="', $accordion_collapse_accordion, '">';
  707. $this->subtask_num = $subtask_num;
  708. $this->_print_c($node);
  709. $this->subtask_num = null;
  710. echo '</div>';
  711. echo '</div>';
  712. echo '</div>';
  713. echo '</div>';
  714. } elseif ($node->nodeName == 'test') {
  715. $test_info = $node->getAttribute('info');
  716. $test_num = $node->getAttribute('num');
  717. $test_score = $node->getAttribute('score');
  718. $test_time = $node->getAttribute('time');
  719. $test_memory = $node->getAttribute('memory');
  720. echo '<div class="card ', $this->styler->getTestInfoClass($test_info), ' mb-3">';
  721. $accordion_parent = "{$this->name}_details_accordion";
  722. if ($this->subtask_num != null) {
  723. $accordion_parent .= "_collapse_subtask_{$this->subtask_num}_accordion";
  724. }
  725. $accordion_collapse = "{$accordion_parent}_collapse_test_{$test_num}";
  726. if (!$this->styler->shouldFadeDetails($test_info)) {
  727. echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
  728. } else {
  729. echo '<div class="card-header">';
  730. }
  731. echo '<div class="row">';
  732. echo '<div class="col-sm-4">';
  733. if ($test_num > 0) {
  734. echo '<h4 class="card-title">', 'Test #', $test_num, ': ', '</h4>';
  735. } else {
  736. echo '<h4 class="card-title">', 'Extra Test:', '</h4>';
  737. }
  738. echo '</div>';
  739. if ($this->styler->show_score) {
  740. echo '<div class="col-sm-4">';
  741. echo '得分:', $test_score;
  742. echo '</div>';
  743. echo '<div class="col-sm-4">';
  744. echo htmlspecialchars($test_info);
  745. echo '</div>';
  746. } else {
  747. echo '<div class="col-sm-8">';
  748. echo htmlspecialchars($test_info);
  749. echo '</div>';
  750. }
  751. echo '<div class="col-sm-4">';
  752. if ($test_time >= 0) {
  753. echo '时间:', $test_time, 'ms';
  754. }
  755. echo '</div>';
  756. echo '<div class="col-sm-4">';
  757. if ($test_memory >= 0) {
  758. echo '内存:', $test_memory, 'kb';
  759. }
  760. echo '</div>';
  761. echo '</div>';
  762. echo '</div>';
  763. if (!$this->styler->shouldFadeDetails($test_info)) {
  764. $accordion_collapse_class = 'card-collapse collapse';
  765. if ($this->styler->collapse_in) {
  766. $accordion_collapse_class .= ' in';
  767. }
  768. echo '<div id="', $accordion_collapse, '" class="', $accordion_collapse_class, '">';
  769. echo '<div class="card-body">';
  770. $this->_print_c($node);
  771. echo '</div>';
  772. echo '</div>';
  773. }
  774. echo '</div>';
  775. } elseif ($node->nodeName == 'custom-test') {
  776. $test_info = $node->getAttribute('info');
  777. $test_time = $node->getAttribute('time');
  778. $test_memory = $node->getAttribute('memory');
  779. echo '<div class="card ', $this->styler->getTestInfoClass($test_info), ' mb-3">';
  780. $accordion_parent = "{$this->name}_details_accordion";
  781. $accordion_collapse = "{$accordion_parent}_collapse_custom_test";
  782. if (!$this->styler->shouldFadeDetails($test_info)) {
  783. echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
  784. } else {
  785. echo '<div class="card-header">';
  786. }
  787. echo '<div class="row">';
  788. echo '<div class="col-sm-2">';
  789. echo '<h4 class="card-title">', '自定义测试:', '</h4>';
  790. echo '</div>';
  791. echo '<div class="col-sm-4">';
  792. echo htmlspecialchars($test_info);
  793. echo '</div>';
  794. echo '<div class="col-sm-3">';
  795. if ($test_time >= 0) {
  796. echo '时间:', $test_time, 'ms';
  797. }
  798. echo '</div>';
  799. echo '<div class="col-sm-3">';
  800. if ($test_memory >= 0) {
  801. echo '空间:', $test_memory, 'kb';
  802. }
  803. echo '</div>';
  804. echo '</div>';
  805. echo '</div>';
  806. if (!$this->styler->shouldFadeDetails($test_info)) {
  807. $accordion_collapse_class = 'card-collapse collapse';
  808. if ($this->styler->collapse_in) {
  809. $accordion_collapse_class .= ' in';
  810. }
  811. echo '<div id="', $accordion_collapse, '" class="', $accordion_collapse_class, '">';
  812. echo '<div class="card-body">';
  813. $this->_print_c($node);
  814. echo '</div>';
  815. echo '</div>';
  816. echo '</div>';
  817. }
  818. } elseif ($node->nodeName == 'in') {
  819. echo "<h4>标准输入:</h4><pre>\n";
  820. $this->_print_c($node);
  821. echo "\n</pre>";
  822. } elseif ($node->nodeName == 'out') {
  823. echo "<h4>标准输出:</h4><pre>\n";
  824. $this->_print_c($node);
  825. echo "\n</pre>";
  826. } elseif ($node->nodeName == 'res') {
  827. echo "<h4>检验结果:</h4><pre>\n";
  828. $this->_print_c($node);
  829. echo "\n</pre>";
  830. } else {
  831. echo '<', $node->nodeName;
  832. foreach ($node->attributes as $attr) {
  833. echo ' ', $attr->name, '="', htmlspecialchars($attr->value), '"';
  834. }
  835. echo '>';
  836. $this->_print_c($node);
  837. echo '</', $node->nodeName, '>';
  838. }
  839. }
  840. public function __construct($details, $styler, $name) {
  841. $this->name = $name;
  842. $this->styler = $styler;
  843. $this->details = $details;
  844. $this->dom = new DOMDocument();
  845. if (!$this->dom->loadXML($this->details)) {
  846. throw new Exception("XML syntax error");
  847. }
  848. $this->details = '';
  849. }
  850. public function printHTML() {
  851. $this->subtask_num = null;
  852. $this->_print($this->dom->documentElement);
  853. }
  854. }
  855. function echoJudgementDetails($raw_details, $styler, $name) {
  856. try {
  857. $printer = new JudgementDetailsPrinter($raw_details, $styler, $name);
  858. $printer->printHTML();
  859. } catch (Exception $e) {
  860. echo 'Failed to show details';
  861. }
  862. }
  863. class SubmissionDetailsStyler {
  864. public $show_score = true;
  865. public $show_small_tip = true;
  866. public $collapse_in = false;
  867. public $fade_all_details = false;
  868. public function getTestInfoClass($info) {
  869. if ($info == 'Accepted' || $info == 'Extra Test Passed') {
  870. return 'card-uoj-accepted';
  871. } elseif ($info == 'Time Limit Exceeded') {
  872. return 'card-uoj-tle';
  873. } elseif ($info == 'Acceptable Answer') {
  874. return 'card-uoj-acceptable-answer';
  875. } else {
  876. return 'card-uoj-wrong';
  877. }
  878. }
  879. public function shouldFadeDetails($info) {
  880. return $this->fade_all_details || $info == 'Extra Test Passed';
  881. }
  882. }
  883. class CustomTestSubmissionDetailsStyler {
  884. public $show_score = true;
  885. public $show_small_tip = false;
  886. public $collapse_in = true;
  887. public $fade_all_details = false;
  888. public $ioi_contest_is_running = false;
  889. public function getTestInfoClass($info) {
  890. if ($info == 'Success') {
  891. return 'card-uoj-accepted';
  892. } elseif ($info == 'Time Limit Exceeded') {
  893. return 'card-uoj-tle';
  894. } elseif ($info == 'Acceptable Answer') {
  895. return 'card-uoj-acceptable-answer';
  896. } else {
  897. return 'card-uoj-wrong';
  898. }
  899. }
  900. public function shouldFadeDetails($info) {
  901. return $this->fade_all_details;
  902. }
  903. }
  904. class HackDetailsStyler {
  905. public $show_score = false;
  906. public $show_small_tip = false;
  907. public $collapse_in = true;
  908. public $fade_all_details = false;
  909. public function getTestInfoClass($info) {
  910. if ($info == 'Accepted' || $info == 'Extra Test Passed') {
  911. return 'card-uoj-accepted';
  912. } elseif ($info == 'Time Limit Exceeded') {
  913. return 'card-uoj-tle';
  914. } elseif ($info == 'Acceptable Answer') {
  915. return 'card-uoj-acceptable-answer';
  916. } else {
  917. return 'card-uoj-wrong';
  918. }
  919. }
  920. public function shouldFadeDetails($info) {
  921. return $this->fade_all_details;
  922. }
  923. }
  924. function echoSubmissionDetails($submission_details, $name) {
  925. echoJudgementDetails($submission_details, new SubmissionDetailsStyler(), $name);
  926. }
  927. function echoCustomTestSubmissionDetails($submission_details, $name) {
  928. echoJudgementDetails($submission_details, new CustomTestSubmissionDetailsStyler(), $name);
  929. }
  930. function echoHackDetails($hack_details, $name) {
  931. echoJudgementDetails($hack_details, new HackDetailsStyler(), $name);
  932. }
  933. function echoHack($hack, $config, $user) {
  934. $problem = queryProblemBrief($hack['problem_id']);
  935. echo '<tr>';
  936. if (!isset($config['id_hidden'])) {
  937. echo '<td><a href="/hack/', $hack['id'], '">#', $hack['id'], '</a></td>';
  938. }
  939. if (!isset($config['submission_hidden'])) {
  940. echo '<td><a href="/submission/', $hack['submission_id'], '">#', $hack['submission_id'], '</a></td>';
  941. }
  942. if (!isset($config['problem_hidden'])) {
  943. if ($hack['contest_id']) {
  944. echo '<td>', getContestProblemLink($problem, $hack['contest_id'], '!id_and_title'), '</td>';
  945. } else {
  946. echo '<td>', getProblemLink($problem, '!id_and_title'), '</td>';
  947. }
  948. }
  949. if (!isset($config['hacker_hidden'])) {
  950. echo '<td>', getUserLink($hack['hacker']), '</td>';
  951. }
  952. if (!isset($config['owner_hidden'])) {
  953. echo '<td>', getUserLink($hack['owner']), '</td>';
  954. }
  955. if (!isset($config['result_hidden'])) {
  956. if ($hack['judge_time'] == null) {
  957. echo '<td><a href="/hack/', $hack['id'], '">Waiting</a></td>';
  958. } elseif ($hack['success'] == null) {
  959. echo '<td><a href="/hack/', $hack['id'], '">Judging</a></td>';
  960. } elseif ($hack['success']) {
  961. echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status" data-success="1"><strong>Success!</strong></a></td>';
  962. } else {
  963. echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status" data-success="0"><strong>Failed.</strong></a></td>';
  964. }
  965. } else {
  966. echo '<td>Hidden</td>';
  967. }
  968. if (!isset($config['submit_time_hidden'])) {
  969. echo '<td>', $hack['submit_time'], '</td>';
  970. }
  971. if (!isset($config['judge_time_hidden'])) {
  972. echo '<td>', $hack['judge_time'], '</td>';
  973. }
  974. echo '</tr>';
  975. }
  976. function echoHackListOnlyOne($hack, $config, $user) {
  977. echo '<div class="table-responsive shadow my-4">';
  978. echo '<table class="table table-bordered table-text-center">';
  979. echo '<thead>';
  980. echo '<tr>';
  981. if (!isset($config['id_hidden'])) {
  982. echo '<th>ID</th>';
  983. }
  984. if (!isset($config['submission_id_hidden'])) {
  985. echo '<th>'.UOJLocale::get('problems::submission id').'</th>';
  986. }
  987. if (!isset($config['problem_hidden'])) {
  988. echo '<th>'.UOJLocale::get('problems::problem').'</th>';
  989. }
  990. if (!isset($config['hacker_hidden'])) {
  991. echo '<th>'.UOJLocale::get('problems::hacker').'</th>';
  992. }
  993. if (!isset($config['owner_hidden'])) {
  994. echo '<th>'.UOJLocale::get('problems::owner').'</th>';
  995. }
  996. if (!isset($config['result_hidden'])) {
  997. echo '<th>'.UOJLocale::get('problems::result').'</th>';
  998. }
  999. if (!isset($config['submit_time_hidden'])) {
  1000. echo '<th>'.UOJLocale::get('problems::submit time').'</th>';
  1001. }
  1002. if (!isset($config['judge_time_hidden'])) {
  1003. echo '<th>'.UOJLocale::get('problems::judge time').'</th>';
  1004. }
  1005. echo '</tr>';
  1006. echo '</thead>';
  1007. echo '<tbody>';
  1008. echoHack($hack, $config, $user);
  1009. echo '</tbody>';
  1010. echo '</table>';
  1011. echo '</div>';
  1012. }
  1013. function echoHacksList($cond, $tail, $config, $user) {
  1014. $header_row = '<tr>';
  1015. $col_names = array();
  1016. $col_names[] = 'id';
  1017. $col_names[] = 'success';
  1018. $col_names[] = 'judge_time';
  1019. if (!isset($config['id_hidden'])) {
  1020. $header_row .= '<th>ID</th>';
  1021. }
  1022. if (!isset($config['submission_id_hidden'])) {
  1023. $header_row .= '<th>'.UOJLocale::get('problems::submission id').'</th>';
  1024. $col_names[] = 'submission_id';
  1025. }
  1026. if (!isset($config['problem_hidden'])) {
  1027. $header_row .= '<th>'.UOJLocale::get('problems::problem').'</th>';
  1028. $col_names[] = 'problem_id';
  1029. }
  1030. if (!isset($config['hacker_hidden'])) {
  1031. $header_row .= '<th>'.UOJLocale::get('problems::hacker').'</th>';
  1032. $col_names[] = 'hacker';
  1033. }
  1034. if (!isset($config['owner_hidden'])) {
  1035. $header_row .= '<th>'.UOJLocale::get('problems::owner').'</th>';
  1036. $col_names[] = 'owner';
  1037. }
  1038. if (!isset($config['result_hidden'])) {
  1039. $header_row .= '<th>'.UOJLocale::get('problems::result').'</th>';
  1040. }
  1041. if (!isset($config['submit_time_hidden'])) {
  1042. $header_row .= '<th>'.UOJLocale::get('problems::submit time').'</th>';
  1043. $col_names[] = 'submit_time';
  1044. }
  1045. if (!isset($config['judge_time_hidden'])) {
  1046. $header_row .= '<th>'.UOJLocale::get('problems::judge time').'</th>';
  1047. }
  1048. $header_row .= '</tr>';
  1049. if (!isSuperUser($user)) {
  1050. if ($user != null) {
  1051. $permission_cond = "is_hidden = false or (is_hidden = true and problem_id in (select problem_id from problems_permissions where username = '{$user['username']}'))";
  1052. } else {
  1053. $permission_cond = "is_hidden = false";
  1054. }
  1055. if ($cond !== '1') {
  1056. $cond = "($cond) and ($permission_cond)";
  1057. } else {
  1058. $cond = $permission_cond;
  1059. }
  1060. }
  1061. echoLongTable($col_names, 'hacks', $cond, $tail, $header_row,
  1062. function($hacks) use ($config, $user) {
  1063. echoHack($hacks, $config, $user);
  1064. }, null);
  1065. }
  1066. function echoDatum($datum) {
  1067. $pid = $datum['pid'];
  1068. $title = queryProblemBrief($pid)['title'];
  1069. echo '<tr>';
  1070. echo '<td>' . $datum['id'] . '</td>';
  1071. echo '<td>', getProblemLink(queryProblemBrief($pid), '!id_and_title'), '</td>';
  1072. if ($datum['status'] == 'Done')
  1073. echo '<td><a href="/datum/' . $datum['id'] . '" class="uoj-status" data-success="1"><strong>Done</strong></a></td>';
  1074. else if ($datum['status'] == 'Failed')
  1075. echo '<td><a href="/datum/' . $datum['id'] . '" class="uoj-status" data-success="0"><strong>Failed</strong></a></td>';
  1076. else echo '<td><a href="/datum/' . $datum['id'] . '">' . $datum['status'] . '</a></td>';
  1077. echo '<td>' . $datum['request_time'] . '</td>';
  1078. echo '<td>' . $datum['finish_time'] . '</td>';
  1079. echo '<td>' . $datum['timelimit'] . ' s</td>';
  1080. echo '<td>' . $datum['memlimit'] . ' MB</td>';
  1081. echo '</tr>';
  1082. }
  1083. function echoDatumlistOnlyOne($datum) {
  1084. $header_row = '<tr><th>ID</th><th>题目</th><th>状态</th><th>请求时间</th><th>完成时间</th><th>时间限制</th><th>空间限制</th></tr>';
  1085. echo '<div class="table-responsive shadow my-4">';
  1086. echo '<table class="table table-bordered table-text-center">';
  1087. echo '<thead>';
  1088. echo $header_row;
  1089. echo '</thead>';
  1090. echo '<tbody>';
  1091. echoDatum($datum);
  1092. echo '</tbody>';
  1093. echo '</table></div>';
  1094. }
  1095. function echoDatumList() {
  1096. $col_names = array('id', 'pid', 'request_time', 'status', 'finish_time', 'timelimit', 'memlimit');
  1097. $header_row = '<tr><th>ID</th><th>题目</th><th>状态</th><th>请求时间</th><th>完成时间</th><th>时间限制</th><th>空间限制</th></tr>';
  1098. echoLongTable($col_names, 'datum_requests', '1', '', $header_row,
  1099. function($datum) { echoDatum($datum); }, null);
  1100. }
  1101. function getBlogPreview($str) {
  1102. return '';
  1103. }
  1104. function echoBlogCard($blog) {
  1105. if ($blog == null)
  1106. return;
  1107. $bloghref = "/blogs/" . $blog['id'];
  1108. $blogtitle = $blog['title'];
  1109. $poster = queryUser($blog['poster']);
  1110. $blogpreview = getBlogPreview($blog['content']);
  1111. $userlink = getUserLink($blog['poster']);
  1112. $posttime = $blog['post_time'];
  1113. $usermotto = $poster['motto'];
  1114. $zanblock = getClickZanBlock('B', $blog['id'], $blog['zan']);
  1115. return <<<EOF
  1116. <div class="col-12 mb-4">
  1117. <div class="card d-flex p-3 shadow mx-4">
  1118. <div class="align-items-start">
  1119. <a href="$bloghref"><h5>$blogtitle</h5></a>
  1120. <p>$blogpreview</p>
  1121. </div>
  1122. <div class="d-flex align-items-end justify-content-between">
  1123. <div>
  1124. <span class="mb-2">$userlink</span>
  1125. <span class="text-muted">$posttime</span>
  1126. <span class="ml-4">$usermotto</span>
  1127. </div>
  1128. $zanblock
  1129. </div>
  1130. </div>
  1131. </div>
  1132. EOF;
  1133. }
  1134. function echoRecommendProblem($pid, $link, $name, $descr) {
  1135. return <<<EOF
  1136. <div class="col-md-3 mb-4">
  1137. <div class="card h-100 p-3 text-center">
  1138. <a class="mb-2" href="$link"><h4>$pid</h4></a>
  1139. <h4 class="mb-2">$name</h4>
  1140. <span class="text-bottom">$descr</span>
  1141. </div>
  1142. </div>
  1143. EOF;
  1144. }
  1145. function echoBlog($blog, $config = array()) {
  1146. $default_config = array(
  1147. 'blog' => $blog,
  1148. 'show_title_only' => false,
  1149. 'show_content_only' => false,
  1150. 'is_preview' => false,
  1151. 'outside_blog_domain' => false,
  1152. );
  1153. foreach ($default_config as $key => $val) {
  1154. if (!isset($config[$key])) {
  1155. $config[$key] = $val;
  1156. }
  1157. }
  1158. uojIncludeView('blog-preview', $config);
  1159. }
  1160. function echoBlogTag($tag) {
  1161. echo '<a class="uoj-blog-tag"><span class="badge badge-pill badge-secondary">', HTML::escape($tag), '</span></a>';
  1162. }
  1163. function echoUOJPageHeader($page_title, $extra_config = array()) {
  1164. global $REQUIRE_LIB;
  1165. $config = UOJContext::pageConfig();
  1166. $config['REQUIRE_LIB'] = $REQUIRE_LIB;
  1167. $config['PageTitle'] = $page_title;
  1168. $config = array_merge($config, $extra_config);
  1169. uojIncludeView('page-header', $config);
  1170. }
  1171. function echoUOJPageFooter($config = array()) {
  1172. uojIncludeView('page-footer', $config);
  1173. }
  1174. function getAvatar($user) {
  1175. return '<img class="media-object img-rounded" height="50" width="50" src="' . HTML::avatar_addr($user, 50) . '">';
  1176. }
  1177. function echoRanklist($config = array()) {
  1178. $header_row = '';
  1179. $header_row .= '<tr>';
  1180. $header_row .= '<th style="width: 5em;">#</th>';
  1181. $header_row .= '<th style="width: 14em";>'.'头像'.'</th>';
  1182. $header_row .= '<th style="width: 14em;">'.UOJLocale::get('username').'</th>';
  1183. $header_row .= '<th style="width: 50em;">'.UOJLocale::get('motto').'</th>';
  1184. $header_row .= '<th style="width: 5em;">'.UOJLocale::get('rating').'</th>';
  1185. $header_row .= '</tr>';
  1186. $users = array();
  1187. $relcnt = 0;
  1188. $print_row = function($user, $now_cnt) use (&$users, &$relcnt) {
  1189. #if (!$users) {
  1190. $rank = DB::selectCount("select count(*) from user_info where rating > {$user['rating']}") + 1;
  1191. # } elseif ($user['rating'] == $users[count($users) - 1]['rating']) {
  1192. # $rank = $users[count($users) - 1]['rank'];
  1193. # } else {
  1194. # $rank = $now_cnt;
  1195. # }
  1196. $user['rank'] = $rank;
  1197. $relcnt++;
  1198. echo '<tr>';
  1199. echo '<td>' . $user['rank'] . ' (' . $relcnt . ')</td>';
  1200. echo '<td>' . getAvatar($user) . '</td>';
  1201. echo '<td>' . getUserLink($user['username']) . '</td>';
  1202. echo '<td>' . HTML::escape($user['motto']) . '</td>';
  1203. echo '<td>' . $user['rating'] . '</td>';
  1204. echo '</tr>';
  1205. $users[] = $user;
  1206. };
  1207. $col_names = array('username', 'email', 'qq', 'rating', 'motto');
  1208. $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';
  1209. # $tail = 'order by rating desc, username asc';
  1210. #
  1211. $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';
  1212. if (isset($config['top10'])) {
  1213. $tail .= ' limit 10';
  1214. }
  1215. $config['get_row_index'] = '';
  1216. echoLongTable($col_names, 'user_info', '1', $tail, $header_row, $print_row, $config);
  1217. }