contests.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. requirePHPLib('form');
  3. $upcoming_contest_name = null;
  4. $upcoming_contest_href = null;
  5. $rest_second = 1000000;
  6. function echoContest($contest) {
  7. global $myUser, $upcoming_contest_name, $upcoming_contest_href, $rest_second;
  8. $contest_name_link = <<<EOD
  9. <a href="/contest/{$contest['id']}">{$contest['name']}</a>
  10. EOD;
  11. genMoreContestInfo($contest);
  12. if ($contest['cur_progress'] == CONTEST_NOT_STARTED) {
  13. $cur_rest_second = $contest['start_time']->getTimestamp() - UOJTime::$time_now->getTimestamp();
  14. if ($cur_rest_second < $rest_second) {
  15. $upcoming_contest_name = $contest['name'];
  16. $upcoming_contest_href = "/contest/{$contest['id']}";
  17. $rest_second = $cur_rest_second;
  18. }
  19. if ($myUser != null && hasRegistered($myUser, $contest)) {
  20. $contest_name_link .= '<sup><a style="color:green">'.UOJLocale::get('contests::registered').'</a></sup>';
  21. } else {
  22. $contest_name_link .= '<sup><a style="color:red" href="/contest/'.$contest['id'].'/register">'.UOJLocale::get('contests::register').'</a></sup>';
  23. }
  24. } elseif ($contest['cur_progress'] == CONTEST_IN_PROGRESS) {
  25. $contest_name_link .= '<sup><a style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::in progress').'</a></sup>';
  26. } elseif ($contest['cur_progress'] == CONTEST_PENDING_FINAL_TEST) {
  27. $contest_name_link .= '<sup><a style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::pending final test').'</a></sup>';
  28. } elseif ($contest['cur_progress'] == CONTEST_TESTING) {
  29. $contest_name_link .= '<sup><a style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::final testing').'</a></sup>';
  30. } elseif ($contest['cur_progress'] == CONTEST_FINISHED) {
  31. $contest_name_link .= '<sup><a style="color:grey" href="/contest/'.$contest['id'].'/standings">'.UOJLocale::get('contests::ended').'</a></sup>';
  32. }
  33. $last_hour = round($contest['last_min'] / 60, 2);
  34. $click_zan_block = getClickZanBlock('C', $contest['id'], $contest['zan']);
  35. echo '<tr>';
  36. echo '<td>', $contest_name_link, '</td>';
  37. echo '<td>', '<a href="'.HTML::timeanddate_url($contest['start_time'], array('duration' => $contest['last_min'])).'">'.$contest['start_time_str'].'</a>', '</td>';
  38. echo '<td>', UOJLocale::get('hours', $last_hour), '</td>';
  39. echo '<td>', '<a href="/contest/'.$contest['id'].'/registrants"><span class="glyphicon glyphicon-user"></span> &times;'.$contest['player_num'].'</a>', '</td>';
  40. echo '<td>', '<div class="text-center">'.$click_zan_block.'</div>', '</td>';
  41. echo '</tr>';
  42. }
  43. ?>
  44. <?php echoUOJPageHeader(UOJLocale::get('contests')) ?>
  45. <div class="row">
  46. <h4><?= UOJLocale::get('contests::current or upcoming contests') ?></h4>
  47. <?php
  48. $table_header = '';
  49. $table_header .= '<tr>';
  50. $table_header .= '<th>'.UOJLocale::get('contests::contest name').'</th>';
  51. $table_header .= '<th style="width:15em;">'.UOJLocale::get('contests::start time').'</th>';
  52. $table_header .= '<th style="width:100px;">'.UOJLocale::get('contests::duration').'</th>';
  53. $table_header .= '<th style="width:100px;">'.UOJLocale::get('contests::the number of registrants').'</th>';
  54. $table_header .= '<th style="width:220px;">'.UOJLocale::get('appraisal').'</th>';
  55. $table_header .= '</tr>';
  56. echoLongTable(array('*'), 'contests', "status != 'finished'", 'order by start_time asc, id asc', $table_header,
  57. echoContest,
  58. array('page_len' => 100)
  59. );
  60. if ($rest_second <= 86400) {
  61. $notification = json_encode($upcoming_contest_name . " 已经开始了。是否要跳转到比赛页面?");
  62. echo <<<EOD
  63. <div class="w-100 text-center bot-buffer-lg">
  64. <div class="text-warning">$upcoming_contest_name 倒计时</div>
  65. <div id="contest-countdown"></div>
  66. <script type="text/javascript">
  67. $('#contest-countdown').countdown($rest_second, function() {
  68. if (confirm($notification)) {
  69. window.location.href = "$upcoming_contest_href";
  70. }
  71. });
  72. </script>
  73. </div>
  74. EOD;
  75. }
  76. ?>
  77. </div>
  78. <div class="row">
  79. <h4><?= UOJLocale::get('contests::ended contests') ?></h4>
  80. <?php
  81. echoLongTable(array('*'), 'contests', "status = 'finished'", 'order by start_time desc, id desc', $table_header,
  82. echoContest,
  83. array('page_len' => 100,
  84. 'print_after_table' => function() {
  85. global $myUser;
  86. if (isSuperUser($myUser)) {
  87. echo '<div class="text-right">';
  88. echo '<a href="/contest/new" class="btn btn-primary">'.UOJLocale::get('contests::add new contest').'</a>';
  89. echo '</div>';
  90. }
  91. }
  92. )
  93. );
  94. ?>
  95. </div>
  96. <?php echoUOJPageFooter() ?>