contests.php 4.7 KB

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