PageRenderTime 52ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/boca-1.5.1/src/system/contest.php

https://bitbucket.org/jorgenio/boca
PHP | 214 lines | 185 code | 9 blank | 20 comment | 67 complexity | efc08f1425105538dbaf47e7e90bdfd3 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. //BOCA Online Contest Administrator
  4. // Copyright (C) 2003-2012 by BOCA Development Team (bocasystem@gmail.com)
  5. //
  6. // This program is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ////////////////////////////////////////////////////////////////////////////////
  18. // Last modified 05/aug/2012 by cassio@ime.usp.br
  19. //Change list:
  20. // 02/jul/2006 by cassio@ime.usp.br
  21. // 25/aug/2007 by cassio@ime.usp.br: php initial tag changed to complete form
  22. require 'header.php';
  23. if (isset($_GET["new"]) && $_GET["new"]=="1") {
  24. $n = DBNewContest();
  25. ForceLoad("contest.php?contest=$n");
  26. }
  27. if (isset($_GET["contest"]) && is_numeric($_GET["contest"]))
  28. $contest=$_GET["contest"];
  29. else
  30. $contest=$_SESSION["usertable"]["contestnumber"];
  31. if(($ct = DBContestInfo($contest)) == null)
  32. ForceLoad("../index.php");
  33. if ($ct["contestlocalsite"]==$ct["contestmainsite"]) $main=true; else $main=false;
  34. if (isset($_POST["Submit3"]) && isset($_POST["penalty"]) && is_numeric($_POST["penalty"]) &&
  35. isset($_POST["maxfilesize"]) && isset($_POST["mainsite"]) && isset($_POST['localsite']) &&
  36. isset($_POST["name"]) && $_POST["name"] != "" && isset($_POST["lastmileanswer"]) &&
  37. is_numeric($_POST["lastmileanswer"]) && is_numeric($_POST["mainsite"]) && is_numeric($_POST['localsite']) &&
  38. isset($_POST["lastmilescore"]) && is_numeric($_POST["lastmilescore"]) && isset($_POST["duration"]) &&
  39. is_numeric($_POST["duration"]) &&
  40. isset($_POST["startdateh"]) && $_POST["startdateh"] >= 0 && $_POST["startdateh"] <= 23 &&
  41. isset($_POST["contest"]) && is_numeric($_POST["contest"]) &&
  42. isset($_POST["startdatemin"]) && $_POST["startdatemin"] >= 0 && $_POST["startdatemin"] <= 59 &&
  43. isset($_POST["startdated"]) && isset($_POST["startdatem"]) && isset($_POST["startdatey"]) &&
  44. checkdate($_POST["startdatem"], $_POST["startdated"], $_POST["startdatey"])) {
  45. if ($_POST["confirmation"] == "confirm") {
  46. $t = mktime ($_POST["startdateh"], $_POST["startdatemin"], 0, $_POST["startdatem"],
  47. $_POST["startdated"], $_POST["startdatey"]);
  48. if ($_POST["Submit3"] == "Activate") $ac=1;
  49. else $ac=0;
  50. $param['number']=$_POST["contest"];
  51. $param['name']=$_POST["name"];
  52. $param['startdate']=$t;
  53. $param['duration']=$_POST["duration"]*60;
  54. $param['lastmileanswer']=$_POST["lastmileanswer"]*60;
  55. $param['lastmilescore']= $_POST["lastmilescore"]*60;
  56. $param['penalty']=$_POST["penalty"]*60;
  57. $param['maxfilesize']=$_POST["maxfilesize"]*1000;
  58. $param['active']=$ac;
  59. $param['mainsite']=$_POST["mainsite"];
  60. $param['localsite']=$_POST["localsite"];
  61. $param['mainsiteurl']=$_POST["mainsiteurl"];
  62. DBUpdateContest ($param);
  63. if ($ac == 1 && $_POST["contest"] != $_SESSION["usertable"]["contestnumber"]) {
  64. $cf = globalconf();
  65. if($cf["basepass"] == "")
  66. MSGError("You must log in the new contest. The standard admin password is empty (if not changed yet).");
  67. else
  68. MSGError("You must log in the new contest. The standard admin password is " . $cf["basepass"] . " (if not changed yet).");
  69. ForceLoad("../index.php");
  70. }
  71. }
  72. ForceLoad("contest.php?contest=".$_POST["contest"]);
  73. }
  74. ?>
  75. <br>
  76. <form name="form1" enctype="multipart/form-data" method="post" action="contest.php">
  77. <input type=hidden name="confirmation" value="noconfirm" />
  78. <script language="javascript">
  79. function conf() {
  80. if (confirm("Confirm?")) {
  81. document.form1.confirmation.value='confirm';
  82. }
  83. }
  84. function newcontest() {
  85. document.location='contest.php?new=1';
  86. }
  87. function contestch(n) {
  88. if(n==null) {
  89. k=document.form1.contest[document.form1.contest.selectedIndex].value;
  90. if(k=='new') newcontest();
  91. else document.location='contest.php?contest='+k;
  92. } else {
  93. document.location='contest.php?contest='+n;
  94. }
  95. }
  96. </script>
  97. <br><br>
  98. <center>
  99. <table border="0">
  100. <tr>
  101. <td width="35%" align=right>Contest number:</td>
  102. <td width="65%">
  103. <select onChange="contestch()" name="contest">
  104. <?php
  105. $cs = DBAllContestInfo();
  106. $isfake=false;
  107. for ($i=0; $i<count($cs); $i++) {
  108. echo "<option value=\"" . $cs[$i]["contestnumber"] . "\" ";
  109. if ($contest == $cs[$i]["contestnumber"]) {
  110. echo "selected";
  111. if($cs[$i]["contestnumber"] == 0) $isfake=true;
  112. }
  113. echo ">" . $cs[$i]["contestnumber"] . ($cs[$i]["contestactive"]=="t"?"*":"") ."</option>\n";
  114. }
  115. ?>
  116. <option value="new">new</option>
  117. </select>
  118. </td>
  119. </tr>
  120. <?php if(!$isfake) { ?>
  121. <tr>
  122. <td width="35%" align=right>Name:</td>
  123. <td width="65%">
  124. <input type="text" <?php if(!$main) echo "readonly"; ?> name="name" value="<?php echo $ct["contestname"]; ?>" size="50" maxlength="50" />
  125. </td>
  126. </tr>
  127. <tr>
  128. <td width="35%" align=right>Start date:</td>
  129. <td width="65%"> hh:mm
  130. <input type="text" <?php if(!$main) echo "readonly"; ?> name="startdateh" value="<?php echo date("H", $ct["conteststartdate"]); ?>" size="2" maxlength="2" />
  131. :
  132. <input type="text" <?php if(!$main) echo "readonly"; ?> name="startdatemin" value="<?php echo date("i", $ct["conteststartdate"]); ?>" size="2" maxlength="2" />
  133. &nbsp; &nbsp; dd/mm/yyyy
  134. <input type="text" <?php if(!$main) echo "readonly"; ?> name="startdated" value="<?php echo date("d", $ct["conteststartdate"]); ?>" size="2" maxlength="2" />
  135. /
  136. <input type="text" <?php if(!$main) echo "readonly"; ?> name="startdatem" value="<?php echo date("m", $ct["conteststartdate"]); ?>" size="2" maxlength="2" />
  137. /
  138. <input type="text" <?php if(!$main) echo "readonly"; ?> name="startdatey" value="<?php echo date("Y", $ct["conteststartdate"]); ?>" size="4" maxlength="4" />
  139. </td>
  140. </tr>
  141. <tr>
  142. <td width="35%" align=right>Duration (in minutes):</td>
  143. <td width="65%">
  144. <input type="text" name="duration" <?php if(!$main) echo "readonly"; ?> value="<?php echo $ct["contestduration"]/60; ?>" size="20" maxlength="20" />
  145. </td>
  146. </tr>
  147. <tr>
  148. <td width="35%" align=right>Stop answering (in minutes):</td>
  149. <td width="65%">
  150. <input type="text" name="lastmileanswer" <?php if(!$main) echo "readonly"; ?> value="<?php echo $ct["contestlastmileanswer"]/60; ?>" size="20" maxlength="20" />
  151. </td>
  152. </tr>
  153. <tr>
  154. <td width="35%" align=right>Stop scoreboard (in minutes):</td>
  155. <td width="65%">
  156. <input type="text" name="lastmilescore" <?php if(!$main) echo "readonly"; ?> value="<?php echo $ct["contestlastmilescore"]/60; ?>" size="20" maxlength="20" />
  157. </td>
  158. </tr>
  159. <tr>
  160. <td width="35%" align=right>Penalty (in minutes):</td>
  161. <td width="65%">
  162. <input type="text" name="penalty" <?php if(!$main) echo "readonly"; ?> value="<?php echo $ct["contestpenalty"]/60; ?>" size="20" maxlength="20" />
  163. </td>
  164. </tr>
  165. <tr>
  166. <td width="35%" align=right>Max file size allowed for teams (in KB):</td>
  167. <td width="65%">
  168. <input type="text" name="maxfilesize" <?php if(!$main) echo "readonly"; ?>
  169. value="<?php echo $ct["contestmaxfilesize"]/1000; ?>" size="20" maxlength="20" />
  170. </td>
  171. </tr>
  172. <tr><td width="35%" align=right>
  173. Your PHP config. allows at most:</td>
  174. <td width="65%">
  175. <?php echo ini_get('post_max_size').'B(max. post) and '.ini_get('upload_max_filesize').'B(max. filesize)'; ?>
  176. </td></tr>
  177. <tr>
  178. <td width="35%" align=right>Contest main site URL (IP/bocafolder):</td>
  179. <td width="65%">
  180. <input type="text" name="mainsiteurl" value="<?php echo $ct["contestmainsiteurl"]; ?>" size="40" maxlength="200" />
  181. </td>
  182. </tr>
  183. <tr>
  184. <td width="35%" align=right>Contest main site number:</td>
  185. <td width="65%">
  186. <input type="text" name="mainsite" value="<?php echo $ct["contestmainsite"]; ?>" size="4" maxlength="4" />
  187. </td>
  188. </tr>
  189. <tr>
  190. <td width="35%" align=right>Contest local site number:</td>
  191. <td width="65%">
  192. <input type="text" name="localsite" value="<?php echo $ct["contestlocalsite"]; ?>" size="4" maxlength="4" />
  193. </td>
  194. </tr>
  195. </table>
  196. </center>
  197. <center>
  198. <input type="submit" name="Submit3" value="Send" onClick="conf()">
  199. <input type="submit" name="Submit3" value="Activate" onClick="conf()">
  200. <input type="reset" name="Submit4" value="Clear">
  201. </center>
  202. <?php } else { echo "<br><br><center>Select a contest or create a new one.</center><br><br>"; } ?>
  203. </form>
  204. </body>
  205. </html>