contests.php 4.9 KB

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