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

/boca-1.5.1/src/fproblem.php

https://bitbucket.org/jorgenio/boca
PHP | 495 lines | 443 code | 21 blank | 31 comment | 141 complexity | f73a6f572c864d6a964a8a7b34c3f46d 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. function DBDropProblemTable() {
  20. $c = DBConnect();
  21. $r = DBExec($c, "drop table \"problemtable\"", "DBDropProblemTable(drop table)");
  22. }
  23. function DBCreateProblemTable() {
  24. $c = DBConnect();
  25. $conf = globalconf();
  26. if($conf["dbuser"]=="") $conf["dbuser"]="bocauser";
  27. $r = DBExec($c, "
  28. CREATE TABLE \"problemtable\" (
  29. \"contestnumber\" int4 NOT NULL, -- (id do concurso)
  30. \"problemnumber\" int4 NOT NULL, -- (id do problema)
  31. \"problemname\" varchar(20) NOT NULL, -- (nome do problema)
  32. \"problemfullname\" varchar(100) DEFAULT '', -- (nome completo do problema)
  33. \"problembasefilename\" varchar(100), -- (nome base dos arquivos do problema)
  34. \"probleminputfilename\" varchar(100) DEFAULT '', -- (nome do arquivo de entrada)
  35. \"probleminputfile\" oid, -- (apontador para o arquivo de entrada)
  36. \"probleminputfilehash\" varchar(50), -- (apontador para o arquivo de entrada)
  37. \"fake\" bool DEFAULT 'f' NOT NULL, -- (indica se o problema eh valido para submissoes. Util para
  38. -- clarification em General, por exemplo)
  39. \"problemcolorname\" varchar(100) DEFAULT '', -- nome da cor do problema
  40. \"problemcolor\" varchar(6) DEFAULT '', -- cor do problema, formato html (RGB hexadecimal)
  41. \"updatetime\" int4 DEFAULT EXTRACT(EPOCH FROM now()) NOT NULL, -- (indica a ultima atualizacao no registro)
  42. -- (tabela com os problemas. Se um problema tiver mais que par de arquivos
  43. -- entrada/solucao, entao colocamos mais que uma linha para ele aqui.)
  44. CONSTRAINT \"problem_pkey\" PRIMARY KEY (\"contestnumber\", \"problemnumber\"),
  45. CONSTRAINT \"contest_fk\" FOREIGN KEY (\"contestnumber\") REFERENCES \"contesttable\" (\"contestnumber\")
  46. ON DELETE CASCADE ON UPDATE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE
  47. )", "DBCreateProblemTable(create table)");
  48. $r = DBExec($c, "REVOKE ALL ON \"problemtable\" FROM PUBLIC", "DBCreateProblemTable(revoke public)");
  49. $r = DBExec($c, "GRANT ALL ON \"problemtable\" TO \"".$conf["dbuser"]."\"", "DBCreateProblemTable(grant bocauser)");
  50. $r = DBExec($c, "CREATE UNIQUE INDEX \"problem_index\" ON \"problemtable\" USING btree ".
  51. "(\"contestnumber\" int4_ops, \"problemnumber\" int4_ops)", "DBCreateProblemTable(create problem_index)");
  52. $r = DBExec($c, "CREATE INDEX \"problem_index2\" ON \"problemtable\" USING btree ".
  53. "(\"contestnumber\" int4_ops, \"problemname\" varchar_ops)", "DBCreateProblemTable(create problem_index2)");
  54. }
  55. function DBinsertfakeproblem($n,$c) {
  56. DBExec($c, "insert into problemtable (contestnumber, problemnumber, problemname, problemfullname, ".
  57. "problembasefilename, probleminputfilename, probleminputfile, fake) values ($n, 0, 'General', 'General', NULL, NULL, ".
  58. "NULL, 't')", "DBNewContest(insert problem)");
  59. }
  60. //////////////////////funcoes de problemas//////////////////////////////////////////////////////////////
  61. //recebe um numero de contest e numero de problema
  62. //devolve todos os dados relativos ao problema em cada linha do array, sendo que cada linha representa o fato
  63. //que existe mais que um arquivo de entrada/sol. Nao retorna dados sobre problemas fake, ja que eles nao devem ter.
  64. function DBGetProblemData($contestnumber, $problemnumber, $c=null) {
  65. if($c==null)
  66. $c = DBConnect();
  67. $r = DBExec($c, "select p.problemname as problemname, p.problemfullname as fullname, p.problembasefilename " .
  68. "as basefilename, p.problemnumber as number, " .
  69. "p.problemcolor as color, p.problemcolorname as colorname, " .
  70. "p.probleminputfilename as inputfilename, p.probleminputfile as inputoid, p.probleminputfilehash as inputhash " .
  71. " from problemtable as p where p.contestnumber=$contestnumber and p.problemnumber=$problemnumber and p.fake!='t'",
  72. "DBGetProblemData(get problem)");
  73. $n = DBnlines($r);
  74. if ($n == 0) {
  75. LOGError("Unable to find problem data in the database ($contestnumber, $problemnumber)");
  76. MSGError("Unable to find problem data in the database. Contact an admin now!");
  77. exit;
  78. }
  79. $a = array();
  80. for ($i=0;$i<$n;$i++) {
  81. $a[$i] = DBRow($r,$i);
  82. $ds = DIRECTORY_SEPARATOR;
  83. if($ds=="") $ds = "/";
  84. $nn = $a[$i]['number'];
  85. $ptmp = $_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds . "contest" . $contestnumber ."-problem" . $nn;
  86. if(is_readable($ptmp . ".name")) {
  87. $a[$i]['descfilename']=trim(file_get_contents($ptmp . ".name"));
  88. if($a[$i]['descfilename'] != '')
  89. $a[$i]['descoid']=-1;
  90. }
  91. }
  92. return $a;
  93. }
  94. function DBClearProblemTmp($contestnumber) {
  95. $ds = DIRECTORY_SEPARATOR;
  96. if($ds=="") $ds = "/";
  97. $ptmp = $_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds . "contest" . $contestnumber . "-*.name";
  98. foreach(glob($ptmp) as $file) @unlink($file);
  99. $ptmp = $_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds . "contest" . $contestnumber . "-*.hash";
  100. foreach(glob($ptmp) as $file) @unlink($file);
  101. }
  102. function DBGetFullProblemData($contestnumber,$freeproblems=false) {
  103. $c = DBConnect();
  104. DBExec($c, "begin work", "GetFullProblemData");
  105. $r = DBExec($c, "select p.problemnumber as number, p.problemname as name, p.problemfullname as fullname, " .
  106. "p.problembasefilename as basefilename, p.fake as fake, " .
  107. "p.problemcolor as color, p.problemcolorname as colorname, " .
  108. "p.probleminputfilename as inputfilename, p.probleminputfile as inputoid, p.probleminputfilehash as inputhash " .
  109. " from problemtable as p " .
  110. "where p.contestnumber=$contestnumber order by p.problemnumber",
  111. "DBGetFullProblemData(get problem)");
  112. // and p.problemfullname !~ '(DEL)'
  113. $n = DBnlines($r);
  114. if ($n == 0) {
  115. LOGLevel("No problems defined in the database ($contestnumber)",1);
  116. }
  117. $cf = globalconf();
  118. $a = array();
  119. $ds = DIRECTORY_SEPARATOR;
  120. if($ds=="") $ds = "/";
  121. for ($i=0;$i<$n;$i++) {
  122. $a[$i] = array_merge(array(),DBRow($r,$i));
  123. if(strpos($a[$i]['fullname'],'(DEL)') !== false) continue;
  124. $nn=$a[$i]['number'];
  125. $ptmp = $_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds . "contest" . $contestnumber ."-problem" . $nn;
  126. $ck = myshorthash('');
  127. if(is_readable($ptmp . ".hash")) {
  128. $ck = trim(file_get_contents($ptmp . ".hash"));
  129. }
  130. if($ck != $a[$i]['inputhash']) {
  131. @unlink($ptmp . ".name");
  132. @unlink($ptmp . ".hash");
  133. $a[$i]['basefilename']='';
  134. $a[$i]['descfilename']='';
  135. $a[$i]['fullname']='';
  136. }
  137. if($freeproblems && $a[$i]['fake'] != 't') {
  138. if(is_readable($ptmp . ".name")) {
  139. $a[$i]['descfilename']=trim(file_get_contents($ptmp . ".name"));
  140. if($a[$i]['descfilename'] != '')
  141. $a[$i]['descoid']=-1;
  142. } else {
  143. @unlink($ptmp . ".name");
  144. @unlink($ptmp . ".hash");
  145. $randnum = session_id() . "_" . rand();
  146. $dir = $ptmp . '-' . $randnum;
  147. @mkdir($dir,0770,true);
  148. $failed=0;
  149. if(($ret=DB_lo_export($contestnumber, $c, $a[$i]["inputoid"], $dir . $ds . "tmp.zip")) === false) {
  150. LogError("FreeProblems: Unable to read problem package from database (problem=$nn, contest=$contestnumber)");
  151. $failed=1;
  152. }
  153. if(!$failed) {
  154. $zip = new ZipArchive;
  155. if ($zip->open($dir . $ds . "tmp.zip") === true) {
  156. $zip->extractTo($dir);
  157. $zip->close();
  158. if(($info=@parse_ini_file($dir . $ds . "description" . $ds . 'problem.info'))===false) {
  159. $failed=2;
  160. }
  161. if(!$failed) {
  162. $descfile='';
  163. if(isset($info['descfile']))
  164. $descfile=trim(sanitizeText($info['descfile']));
  165. $basename=trim(sanitizeText($info['basename']));
  166. $fullname=trim(sanitizeText($info['fullname']));
  167. if($basename=='' || $fullname=='')
  168. $failed=3;
  169. }
  170. } else $failed=4;
  171. if(!$failed) {
  172. @mkdir($ptmp);
  173. if($descfile != '') {
  174. if(file_put_contents($ptmp . $ds . $descfile, encryptData(file_get_contents($dir . $ds . "description" . $ds . $descfile),$cf['key']),LOCK_EX)===FALSE)
  175. $failed=5;
  176. if(!$failed) {
  177. file_put_contents($ptmp . ".name",$ptmp . $ds . $descfile);
  178. file_put_contents($ptmp . ".hash",$a[$i]['inputhash']);
  179. if(is_readable($ptmp . ".name")) {
  180. $a[$i]['descfilename']=trim(file_get_contents($ptmp . ".name"));
  181. if($a[$i]['descfilename'] != '')
  182. $a[$i]['descoid']=-1;
  183. }
  184. }
  185. } else {
  186. @unlink($ptmp . ".name");
  187. @unlink($ptmp . ".hash");
  188. }
  189. if(!$failed) {
  190. DBExec($c,"update problemtable set problemfullname='$fullname', problembasefilename='$basename' where problemnumber=$nn and contestnumber=$contestnumber",
  191. "DBGetFullProblemData(free problem)");
  192. $a[$i]['basefilename']=$basename;
  193. $a[$i]['fullname']=$fullname;
  194. }
  195. }
  196. }
  197. if($failed) {
  198. $a[$i]['basefilename']='';
  199. $a[$i]['descfilename']='';
  200. @unlink($ptmp . ".name");
  201. @unlink($ptmp . ".hash");
  202. DBExec($c,"update problemtable set problemfullname='', problembasefilename='' where problemnumber=$nn and contestnumber=$contestnumber",
  203. "DBGetFullProblemData(unfree problem)");
  204. if($failed!=4) {
  205. LogError("Failed to unzip problem package (failcode=$failed, problem=$nn, contest=$contestnumber)");
  206. if($failed==1) $a[$i]['fullname']='(ERROR READING FROM DATABASE, OR DIRECTORY PERMISSION PROBLEM)';
  207. else $a[$i]['fullname']='(PROBLEM PACKAGE SEEMS INVALID)';
  208. } else {
  209. if($ret==1) $a[$i]['fullname']='(PROBABLY ENCRYPTED FILE)';
  210. if($ret==2) $a[$i]['fullname']='(FILE IS NOT A ZIP)';
  211. }
  212. }
  213. cleardir($dir,false,true);
  214. }
  215. }
  216. }
  217. DBExec($c, "commit", "GetFullProblemData");
  218. return $a;
  219. }
  220. function DBDeleteProblem($contestnumber, $param, $c=null) {
  221. $ac=array('number','inputfilename');
  222. foreach($ac as $key) {
  223. if(!isset($param[$key])) return false;
  224. $$key = sanitizeText($param[$key]);
  225. }
  226. $sql = "select * from problemtable where problemnumber=$number and contestnumber=$contestnumber and fake='f'";
  227. if ($inputfilename != "")
  228. $sql .= " and probleminputfilename='$inputfilename'";
  229. $cw = false;
  230. if($c == null) {
  231. $cw = true;
  232. $c = DBConnect();
  233. DBExec($c, "begin work", "DBDeleteProblem(transaction)");
  234. }
  235. $r = DBExec($c, $sql . " for update", "DBDeleteProblem(get for update)");
  236. if(DBnlines($r)>0) {
  237. $a = DBRow($r,0);
  238. if(($pos=strpos($a["problemfullname"],"(DEL)")) !== false) {
  239. $sql="update problemtable set problemfullname='".substr($a["problemfullname"],0,$pos) ."', updatetime=".time().
  240. " where contestnumber=$contestnumber and problemnumber=$number ";
  241. } else {
  242. $sql="update problemtable set problemfullname='".$a["problemfullname"] ."(DEL)', updatetime=".time().
  243. " where contestnumber=$contestnumber and problemnumber=$number ";
  244. }
  245. if ($inputfilename != "")
  246. $sql .= " and probleminputfilename='$inputfilename'";
  247. $r = DBExec($c, $sql, "DBDeleteLanguage(update)");
  248. $r = DBExec($c,"select runnumber as number, runsitenumber as site from runtable where contestnumber=$contestnumber and runproblem=$number for update");
  249. $n = DBnlines($r);
  250. for ($i=0;$i<$n;$i++) {
  251. $a = DBRow($r,$i);
  252. DBRunDelete($a["number"],$a["site"],$contestnumber,$_SESSION["usertable"]["usernumber"],$_SESSION["usertable"]["usersitenumber"]);
  253. }
  254. }
  255. if($cw)
  256. DBExec($c, "commit", "DBDeleteProblem(commit)");
  257. $ds = DIRECTORY_SEPARATOR;
  258. if($ds=="") $ds = "/";
  259. $ptmp = $_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds . "contest" . $contestnumber ."-problem" . $number;
  260. @unlink($ptmp . ".name");
  261. @unlink($ptmp . ".hash");
  262. LOGLevel("Problem $number (inputfile=$inputfilename) deleted (user=".
  263. $_SESSION["usertable"]["username"]."/".$_SESSION["usertable"]["usersitenumber"] . ")",2);
  264. return true;
  265. }
  266. function DBNewProblem($contestnumber, $param, $c=null) {
  267. if(isset($param["action"]) && $param["action"]=="delete") {
  268. return DBDeleteProblem($contestnumber, $param);
  269. }
  270. $ac=array('number','name');
  271. $type['number']=1;
  272. $type['updatetime']=1;
  273. $ac1=array('colorname','fake','color','updatetime','fullname',
  274. 'basename','inputfilename','inputfilepath');
  275. $colorname='';
  276. $color='';
  277. $fake='f';
  278. foreach($ac as $key) {
  279. if(!isset($param[$key])) {
  280. MSGError("DBNewProblem param error: $key is not set");
  281. return false;
  282. }
  283. if(isset($type[$key]) && !is_numeric($param[$key])) {
  284. MSGError("DBNewProblem param error: $key is not numeric");
  285. return false;
  286. }
  287. $$key = sanitizeText($param[$key]);
  288. }
  289. $basename='';
  290. $inputfilename='';
  291. $inputfilepath='';
  292. $fullname='';
  293. $updatetime=-1;
  294. foreach($ac1 as $key) {
  295. if(isset($param[$key])) {
  296. if(isset($type[$key]) && !is_numeric($param[$key])) {
  297. MSGError("DBNewProblem param error: $key is not numeric");
  298. return false;
  299. }
  300. $$key = sanitizeText($param[$key]);
  301. }
  302. }
  303. $t = time();
  304. if($updatetime <= 0)
  305. $updatetime=$t;
  306. $inputhash = '';
  307. $sql2 = "select * from problemtable where contestnumber=$contestnumber and problemnumber=$number for update";
  308. // "select * from problemtable where contestnumber=$contestnumber and problemnumber=$number " .
  309. // "and probleminputfilename='$inputfilename'";
  310. $cw = false;
  311. if($c == null) {
  312. $cw = true;
  313. $c = DBConnect();
  314. DBExec($c, "begin work", "DBNewProblem(transaction)");
  315. }
  316. $r = DBExec ($c, $sql2, "DBNewProblem(get problem for update)");
  317. $n = DBnlines($r);
  318. $ret=1;
  319. $oldfullname='';
  320. $deservesupdatetime=false;
  321. if ($n == 0) {
  322. DBExec ($c, "insert into problemtable (contestnumber, problemnumber, problemname, problemcolor) values " .
  323. "($contestnumber, $number, '$name','-1')", "DBNewProblem(insert problem)");
  324. $deservesupdatetime=true;
  325. $s = "created";
  326. }
  327. else {
  328. $lr = DBRow($r,0);
  329. $t = $lr['updatetime'];
  330. $oldfullname=$lr['problemfullname'];
  331. $s = "updated";
  332. $inputhash = $lr['probleminputfilehash'];
  333. }
  334. if($s=="created" || $updatetime > $t) {
  335. if(substr($inputfilepath,0,7)!="base64:") {
  336. if ($inputfilepath != "") {
  337. $hash = myshorthash(file_get_contents($inputfilepath));
  338. if($hash != $inputhash) {
  339. $oldoid='';
  340. if(isset($lr))
  341. $oldoid = $lr['probleminputfile'];
  342. if (($oid1 = DB_lo_import($c, $inputfilepath)) === false) {
  343. DBExec($c, "rollback work", "DBNewProblem(rollback-input)");
  344. LOGError("Unable to create a large object for file $inputfilename.");
  345. MSGError("problem importing file to database. See log for details!");
  346. exit;
  347. }
  348. if($oldoid != '') DB_lo_unlink($c,$oldoid);
  349. $inputhash = DBcrc($contestnumber, $oid1, $c);
  350. } else
  351. $oid1 = $lr['probleminputfile'];
  352. }
  353. } else {
  354. $inputfilepath = base64_decode(substr($inputfilepath,7));
  355. $hash = myshorthash($inputfilepath);
  356. if($hash != $inputhash) {
  357. $oldoid='';
  358. if(isset($lr))
  359. $oldoid = $lr['probleminputfile'];
  360. if (($oid1 = DB_lo_import_text($c, $inputfilepath)) == null) {
  361. DBExec($c, "rollback work", "DBNewProblem(rollback-i-import)");
  362. LOGError("Unable to import the large object for file $inputfilename.");
  363. MSGError("problem importing file to database. See log for details!");
  364. exit;
  365. }
  366. if($oldoid != '') DB_lo_unlink($c,$oldoid);
  367. $inputhash = DBcrc($contestnumber, $oid1, $c);
  368. } else
  369. $oid1 = $lr['probleminputfile'];
  370. }
  371. if ($name != "")
  372. DBExec ($c, "update problemtable set problemname='$name' where contestnumber=$contestnumber ".
  373. "and problemnumber=$number", "DBNewProblem(update name)");
  374. if ($fullname != "" || strpos($oldfullname,'(DEL)')!==false) {
  375. $deservesupdatetime=true;
  376. DBExec ($c, "update problemtable set problemfullname='$fullname' where contestnumber=$contestnumber ".
  377. "and problemnumber=$number", "DBNewProblem(update fullname)");
  378. }
  379. if ($basename != "") {
  380. $deservesupdatetime=true;
  381. DBExec ($c, "update problemtable set problembasefilename='$basename' where contestnumber=$contestnumber ".
  382. "and problemnumber=$number", "DBNewProblem(update basename)");
  383. }
  384. if ($colorname != "")
  385. DBExec ($c, "update problemtable set problemcolorname='$colorname' where contestnumber=$contestnumber ".
  386. "and problemnumber=$number", "DBNewProblem(update colorname)");
  387. if ($color != "")
  388. DBExec ($c, "update problemtable set problemcolor='$color' where contestnumber=$contestnumber ".
  389. "and problemnumber=$number", "DBNewProblem(update color)");
  390. if ($inputfilename != "") {
  391. $deservesupdatetime=true;
  392. DBExec ($c, "update problemtable set probleminputfilename='$inputfilename' where ".
  393. "contestnumber=$contestnumber and problemnumber=$number ", "DBNewProblem(update inputfilename)");
  394. }
  395. if ($inputfilepath != "") {
  396. $deservesupdatetime=true;
  397. DBExec ($c, "update problemtable set probleminputfile=$oid1,probleminputfilehash='$inputhash' where contestnumber=$contestnumber and ".
  398. "problemnumber=$number ", "DBNewProblem(update inputfile)");
  399. }
  400. if ($fake == "t") {
  401. $deservesupdatetime=true;
  402. DBExec ($c, "update problemtable set fake='$fake' where contestnumber=$contestnumber and ".
  403. "problemnumber=$number", "DBNewProblem(update fake)");
  404. }
  405. if($deservesupdatetime) {
  406. $ds = DIRECTORY_SEPARATOR;
  407. if($ds=="") $ds = "/";
  408. @unlink($_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds . "contest" . $contestnumber ."-problem" . $number . '.name');
  409. DBExec ($c, "update problemtable set updatetime=" . $updatetime .
  410. " where contestnumber=$contestnumber and problemnumber=$number", "DBNewProblem(time)");
  411. }
  412. if($cw)
  413. DBExec($c, "commit work", "DBNewProblem(commit)");
  414. LOGLevel ("Problem $number (inputfile=$inputfilename) $s (user=".$_SESSION["usertable"]["usernumber"].
  415. ",site=".$_SESSION["usertable"]["usersitenumber"].",contest=$contestnumber)", 2);
  416. $ret=2;
  417. } else {
  418. if($cw)
  419. DBExec($c, "commit work", "DBNewProblem(commit)");
  420. }
  421. return $ret;
  422. }
  423. //recebe o numero do contest
  424. //devolve um array, onde cada linha tem os atributos number (numero do problema), problem (nome do problema),
  425. //descfilename (nome do arquivo com a descricao do problema) e descoid (large object com a descricao)
  426. function DBGetProblems($contest,$showanyway=false) {
  427. if (($b = DBSiteInfo($contest,$_SESSION["usertable"]["usersitenumber"])) == null)
  428. return array();
  429. if ($b["currenttime"] < 0 && !$showanyway)
  430. return array();
  431. $c = DBConnect();
  432. $sql = "select distinct p.problemnumber as number, p.problemname as problem, " .
  433. "p.problemfullname as fullname, p.problembasefilename as basefilename, " .
  434. "p.problemcolor as color, p.problemcolorname as colorname " .
  435. "from problemtable as p where p.fake!='t' and p.contestnumber=$contest and p.problemfullname !~ '(DEL)' order by p.problemnumber";
  436. $r = DBExec($c, $sql, "DBGetProblems(get problems)");
  437. $n = DBnlines($r);
  438. $a = array();
  439. for ($i=0;$i<$n;$i++) {
  440. $a[$i] = DBRow($r,$i);
  441. $ds = DIRECTORY_SEPARATOR;
  442. if($ds=="") $ds = "/";
  443. $nn = $a[$i]['number'];
  444. $ptmp = $_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds . "contest" . $contest ."-problem" . $nn;
  445. if(is_readable($ptmp . ".name")) {
  446. $a[$i]['descfilename']=trim(file_get_contents($ptmp . ".name"));
  447. if($a[$i]['descfilename'] != '')
  448. $a[$i]['descoid']=-1;
  449. }
  450. }
  451. return $a;
  452. }
  453. //recebe o numero do contest
  454. //devolve um array, onde cada linha tem os atributos number (numero do problema) e problem (nome do problema)
  455. //para todos os problemas, inclusive os fakes
  456. function DBGetAllProblems($contest) {
  457. if (($b = DBSiteInfo($contest,$_SESSION["usertable"]["usersitenumber"])) == null)
  458. return array();
  459. $c = DBConnect();
  460. $sql = "select distinct p.problemnumber as number, p.problemname as problem, " .
  461. "p.problemcolor as color, p.problemcolorname as colorname " .
  462. "from problemtable as p " .
  463. "where p.contestnumber=$contest and p.problemfullname !~ '(DEL)' ";
  464. if ($b["currenttime"] < 0) $sql .= "and p.fake='t' ";
  465. $sql .= " order by p.problemnumber";
  466. $r = DBExec($c, $sql, "DBGetAllProblems(get problems)");
  467. $n = DBnlines($r);
  468. $a = array();
  469. for ($i=0;$i<$n;$i++)
  470. $a[$i] = DBRow($r,$i);
  471. return $a;
  472. }
  473. // eof
  474. ?>