PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/boca-1.5.0/src/judge/team.php

https://bitbucket.org/jorgenio/boca
PHP | 191 lines | 159 code | 14 blank | 18 comment | 40 complexity | f7d23af4f4236484491e0bce7c2b7eef 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 21/jul/2012 by cassio@ime.usp.br
  19. require('header.php');
  20. if (isset($_FILES["sourcefile"]) && isset($_POST["problem"]) && isset($_POST["Submit"]) && isset($_POST["language"]) &&
  21. is_numeric($_POST["problem"]) && is_numeric($_POST["language"]) && $_FILES["sourcefile"]["name"]!="") {
  22. if ($_POST["confirmation"] == "confirm") {
  23. if(($ct = DBContestInfo($_SESSION["usertable"]["contestnumber"])) == null)
  24. ForceLoad("../index.php");
  25. $prob = myhtmlspecialchars($_POST["problem"]);
  26. $lang = myhtmlspecialchars($_POST["language"]);
  27. $type=myhtmlspecialchars($_FILES["sourcefile"]["type"]);
  28. $size=myhtmlspecialchars($_FILES["sourcefile"]["size"]);
  29. $name=myhtmlspecialchars($_FILES["sourcefile"]["name"]);
  30. $temp=myhtmlspecialchars($_FILES["sourcefile"]["tmp_name"]);
  31. if ($size > $ct["contestmaxfilesize"]) {
  32. LOGLevel("User {$_SESSION["usertable"]["username"]} tried to submit file " .
  33. "$name with $size bytes ({$ct["contestmaxfilesize"]} max allowed).", 1);
  34. MSGError("File size exceeds the limit allowed.");
  35. ForceLoad($runteam);
  36. }
  37. if (!is_uploaded_file($temp) || strlen($name)>100) {
  38. IntrusionNotify("file upload problem.");
  39. ForceLoad("../index.php");
  40. }
  41. $ac=array('contest','site','user','problem','lang','filename','filepath');
  42. $ac1=array('runnumber','rundate','rundatediff','rundatediffans','runanswer','runstatus','runjudge','runjudgesite',
  43. 'runjudge1','runjudgesite1','runanswer1','runjudge2','runjudgesite2','runanswer2',
  44. 'autoip','autobegindate','autoenddate','autoanswer','autostdout','autostderr','updatetime');
  45. $param = array('contest'=>$_SESSION["usertable"]["contestnumber"],
  46. 'site'=>$_SESSION["usertable"]["usersitenumber"],
  47. 'user'=> $_SESSION["usertable"]["usernumber"],
  48. 'problem'=>$prob,
  49. 'lang'=>$lang,
  50. 'filename'=>$name,
  51. 'filepath'=>$temp);
  52. if($runteam=='team.php') $param['allowneg']=1;
  53. DBNewRun ($param);
  54. $_SESSION['forceredo']=true;
  55. }
  56. ForceLoad($runteam);
  57. }
  58. $ds = DIRECTORY_SEPARATOR;
  59. if($ds=="") $ds = "/";
  60. $runtmp = $_SESSION["locr"] . $ds . "private" . $ds . "runtmp" . $ds . "run-contest" . $_SESSION["usertable"]["contestnumber"] .
  61. "-site". $_SESSION["usertable"]["usersitenumber"] . "-user" . $_SESSION["usertable"]["usernumber"] . ".php";
  62. $redo = TRUE;
  63. if(!isset($_SESSION['forceredo']) || $_SESSION['forceredo']==false) {
  64. $actualdelay = 30;
  65. if(file_exists($runtmp)) {
  66. if(isset($strtmp) || (($strtmp = file_get_contents($runtmp,FALSE,NULL,-1,1000000)) !== FALSE)) {
  67. list($d) = sscanf($strtmp,"%*s %d");
  68. if($d > time() - $actualdelay) {
  69. $conf=globalconf();
  70. $strtmp = decryptData(substr($strtmp,strpos($strtmp,"\n")+1),$conf["key"],'runtmp');
  71. if($strtmp !== false)
  72. $redo = FALSE;
  73. }
  74. }
  75. }
  76. }
  77. if($redo) {
  78. $_SESSION['forceredo']=false;
  79. if(($st = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null)
  80. ForceLoad("../index.php");
  81. $strtmp="<br>\n<table width=\"100%\" border=1>\n <tr>\n <td><b>Run #</b></td>\n<td><b>Time</b></td>\n".
  82. " <td><b>Problem</b></td>\n <td><b>Language</b></td>\n <td><b>Answer</b></td>\n <td><b>File</b></td>\n </tr>\n";
  83. $strcolors = "0";
  84. $run = DBUserRuns($_SESSION["usertable"]["contestnumber"],
  85. $_SESSION["usertable"]["usersitenumber"],
  86. $_SESSION["usertable"]["usernumber"]);
  87. for ($i=0; $i<count($run); $i++) {
  88. $strtmp .= " <tr>\n";
  89. $strtmp .= " <td nowrap>" . $run[$i]["number"] . "</td>\n";
  90. $strtmp .= " <td nowrap>" . dateconvminutes($run[$i]["timestamp"]) . "</td>\n";
  91. $strtmp .= " <td nowrap>" . $run[$i]["problem"] . "</td>\n";
  92. $strtmp .= " <td nowrap>" . $run[$i]["language"] . "</td>\n";
  93. // $strtmp .= " <td nowrap>" . $run[$i]["status"] . "</td>\n";
  94. if (trim($run[$i]["answer"]) == "") {
  95. $run[$i]["answer"] = "Not answered yet";
  96. $strtmp .= " <td>Not answered yet";
  97. }
  98. else {
  99. $strtmp .= " <td>" . $run[$i]["answer"];
  100. if($run[$i]['yes']=='t') {
  101. $strtmp .= " <img alt=\"".$run[$i]["colorname"]."\" width=\"15\" ".
  102. "src=\"" . balloonurl($run[$i]["color"]) ."\" />";
  103. $strcolors .= "\t" . $run[$i]["colorname"] . "\t" . $run[$i]["color"];
  104. }
  105. }
  106. $strtmp .= "</td>\n";
  107. $strtmp .= "<td nowrap><a href=\"../filedownload.php?" . filedownload($run[$i]["oid"],$run[$i]["filename"]) . "\">";
  108. $strtmp .= $run[$i]["filename"] . "</a>";
  109. $strtmp .= "</td>\n";
  110. $strtmp .= " </tr>\n";
  111. if ($run[$i]["anstime"]>$_SESSION["usertable"]["userlastlogin"]-$st["sitestartdate"] && $run[$i]["anstime"] < $st['sitelastmileanswer'] &&
  112. $run[$i]["ansfake"]!="t" && !isset($_SESSION["popups"]['run' . $i . '-' . $run[$i]["anstime"]])) {
  113. $_SESSION["popups"]['run' . $i . '-' . $run[$i]["anstime"]] = "Run ".$run[$i]["number"]." result: ".$run[$i]["answer"]. "<br>";
  114. }
  115. }
  116. $strtmp .= "</table>";
  117. if (count($run) == 0) $strtmp .= "<br><center><b><font color=\"#ff0000\">NO RUNS AVAILABLE</font></b></center>";
  118. $strtmp .= "<br><br><center><b>To submit a program, just fill in the following fields:</b></center>\n".
  119. "<form name=\"form1\" enctype=\"multipart/form-data\" method=\"post\" action=\"". $runteam ."\">\n".
  120. " <input type=hidden name=\"confirmation\" value=\"noconfirm\" />\n".
  121. " <center>\n".
  122. " <table border=\"0\">\n".
  123. " <tr> \n".
  124. " <td width=\"25%\" align=right>Problem:</td>\n".
  125. " <td width=\"75%\">\n".
  126. " <select name=\"problem\" onclick=\"Arquivo()\">\n";
  127. $prob = DBGetProblems($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usertype"]=='judge');
  128. for ($i=0;$i<count($prob);$i++)
  129. $strtmp .= "<option value=\"" . $prob[$i]["number"] . "\">" . $prob[$i]["problem"] . "</option>\n";
  130. $strtmp .= " </select>\n".
  131. " </td>\n".
  132. " </tr>\n".
  133. " <tr> \n".
  134. " <td width=\"25%\" align=right>Language:</td>\n".
  135. " <td width=\"75%\"> \n".
  136. " <select name=\"language\" onclick=\"Arquivo()\">\n";
  137. $lang = DBGetLanguages($_SESSION["usertable"]["contestnumber"]);
  138. for ($i=0;$i<count($lang);$i++)
  139. $strtmp .= "<option value=\"" . $lang[$i]["number"] . "\">" . $lang[$i]["name"] . "</option>\n";
  140. $strtmp .= " </select>\n".
  141. " </td>\n".
  142. " </tr>\n".
  143. " <tr> \n".
  144. " <td width=\"25%\" align=right>Source code:</td>\n".
  145. " <td width=\"75%\">\n".
  146. " <input type=\"file\" name=\"sourcefile\" size=\"40\" onclick=\"Arquivo()\">\n".
  147. " </td>\n".
  148. " </tr>\n".
  149. " </table>\n".
  150. " </center>\n".
  151. " <script language=\"javascript\">\n".
  152. " function conf() {\n".
  153. " if (confirm(\"Confirm submission?\")) {\n".
  154. " document.form1.confirmation.value='confirm';\n".
  155. " }\n".
  156. " }\n".
  157. " </script>\n".
  158. " <center>\n".
  159. " <input type=\"submit\" name=\"Submit\" value=\"Send\" onClick=\"conf()\">\n".
  160. " <input type=\"reset\" name=\"Submit2\" value=\"Clear\">\n".
  161. " </center>\n".
  162. "</form>\n";
  163. $conf=globalconf();
  164. $strtmp1 = "<!-- " . time() . " --> <?php exit; ?>\t" . encryptData($strcolors,$conf["key"],false) . "\n" . encryptData($strtmp,$conf["key"],false);
  165. $randnum = session_id() . "_" . rand();
  166. if(file_put_contents($runtmp . "_" . $randnum, $strtmp1,LOCK_EX)===FALSE) {
  167. if(!isset($_SESSION['writewarn'])) {
  168. LOGError("Cannot write to the user-run cache file $runtmp -- performance might be compromised");
  169. $_SESSION['writewarn']=true;
  170. }
  171. }
  172. @rename($runtmp . "_" . $randnum, $runtmp);
  173. }
  174. echo $strtmp;
  175. ?>
  176. </body>
  177. </html>