function DBUserRunsYES($contest, $site, $user) { $b = DBSiteInfo($contest, $site); if ($b == null) { exit; } $t = $b["currenttime"]; $c = DBConnect(); $r = DBExec($c, "select distinct p.problemcolorname as colorname, p.problemcolor as color, " . "r.rundatediff as timestamp, p.problemnumber as number " . "from runtable as r, problemtable as p, answertable as a " . "where r.contestnumber={$contest} and p.contestnumber=r.contestnumber and " . "r.contestnumber=a.contestnumber and r.runproblem=p.problemnumber and " . "r.runsitenumber={$site} and r.usernumber={$user} and not r.runstatus ~ 'deleted' and " . "(r.rundatediffans<={$t} or (r.runstatus != 'judged' and r.rundatediff<={$t})) and " . "a.answernumber=r.runanswer and a.yes='t' order by r.rundatediff", "DBUserRunsYES(get run/prob/ans/lang)"); $n = DBnlines($r); $a = array(); $j = 0; $p = array(); for ($i = 0; $i < $n; $i++) { $aa = DBRow($r, $i); if ($aa["timestamp"] < $b["sitelastmileanswer"]) { if (!isset($p[$aa["number"]])) { $p[$aa["number"]] = 1; $a[$j] = $aa; $j++; } } } return $a; }
$i++; } } else { unset($strtmp); } } if ($doslow) { $run = DBUserRunsYES($_SESSION["usertable"]["contestnumber"], $_SESSION["usertable"]["usersitenumber"], $_SESSION["usertable"]["usernumber"]); $n = count($run); for ($i = 0; $i < $n; $i++) { echo "<img alt=\"" . $run[$i]["colorname"] . "\" width=\"10\" " . "src=\"" . balloonurl($run[$i]["color"]) . "\" />\n"; } } if (!isset($_SESSION["popuptime"]) || $_SESSION["popuptime"] < time() - 120) { $_SESSION["popuptime"] = time(); if (($st = DBSiteInfo($_SESSION["usertable"]["contestnumber"], $_SESSION["usertable"]["usersitenumber"])) != null) { $clar = DBUserClars($_SESSION["usertable"]["contestnumber"], $_SESSION["usertable"]["usersitenumber"], $_SESSION["usertable"]["usernumber"]); for ($i = 0; $i < count($clar); $i++) { if ($clar[$i]["anstime"] > $_SESSION["usertable"]["userlastlogin"] - $st["sitestartdate"] && $clar[$i]["anstime"] < $st['siteduration'] && trim($clar[$i]["answer"]) != '' && !isset($_SESSION["popups"]['clar' . $i . '-' . $clar[$i]["anstime"]])) { $_SESSION["popups"]['clar' . $i . '-' . $clar[$i]["anstime"]] = "(Clar for problem " . $clar[$i]["problem"] . " answered)\n"; } } $run = DBUserRuns($_SESSION["usertable"]["contestnumber"], $_SESSION["usertable"]["usersitenumber"], $_SESSION["usertable"]["usernumber"]); for ($i = 0; $i < count($run); $i++) { if ($run[$i]["anstime"] > $_SESSION["usertable"]["userlastlogin"] - $st["sitestartdate"] && $run[$i]["anstime"] < $st['sitelastmileanswer'] && $run[$i]["ansfake"] != "t" && !isset($_SESSION["popups"]['run' . $i . '-' . $run[$i]["anstime"]])) { $_SESSION["popups"]['run' . $i . '-' . $run[$i]["anstime"]] = "(Run " . $run[$i]["number"] . " result: " . $run[$i]["answer"] . ')\\n'; } } } $str = ''; if (isset($_SESSION["popups"])) {
function DBLogInContest($name, $pass, $contest, $msg = true) { $b = DBGetRow("select * from contesttable where contestnumber={$contest}", 0, null, "DBLogIn(get active contest)"); if ($b == null) { LOGLevel("There is no contest {$contest}.", 0); if ($msg) { MSGError("There is no contest {$contest}, contact an admin."); } return false; } $d = DBSiteInfo($b["contestnumber"], $b["contestlocalsite"], null, false); if ($d == null) { if ($msg) { MSGError("There is no active site, contact an admin."); } return false; } $a = DBGetRow("select * from usertable where username='******' and contestnumber=" . $b["contestnumber"] . " and " . "usersitenumber=" . $b["contestlocalsite"], 0, null, "DBLogIn(get user)"); if ($a == null) { if ($msg) { LOGLevel("User {$name} tried to log in contest {$contest} but it does not exist.", 2); MSGError("User does not exist or incorrect password."); } return false; } $a = DBUserInfo($b["contestnumber"], $b["contestlocalsite"], $a['usernumber'], null, false); $_SESSION['usertable'] = $a; $p = myhash($a["userpassword"] . session_id()); $_SESSION['usertable']['userpassword'] = $p; if ($a["userpassword"] != "" && $p != $pass) { LOGLevel("User {$name} tried to log in contest {$contest} but password was incorrect.", 2); if ($msg) { MSGError("Incorrect password."); } unset($_SESSION["usertable"]); return false; } if ($d["sitepermitlogins"] == "f" && $a["usertype"] != "admin" && $a["usertype"] != "judge" && $a["usertype"] != "site") { LOGLevel("User {$name} tried to login contest {$contest} but logins are denied.", 2); if ($msg) { MSGError("Logins are not allowed."); } unset($_SESSION["usertable"]); return false; } if ($a["userenabled"] != "t") { LOGLevel("User {$name} tried to log in contest {$contest} but it is disabled.", 2); if ($msg) { MSGError("User disabled."); } unset($_SESSION["usertable"]); return false; } $gip = getIP(); if ($a["userip"] != $gip && $a["userip"] != "" && $a["usertype"] != "score") { LOGLevel("User {$name} is using two different IPs: " . $a["userip"] . "(" . dateconv($a["userlastlogin"]) . ") and " . $gip, 1); if ($msg && $a["usertype"] != "admin") { MSGError("You are using two distinct IPs. Admin notified."); } } if ($a["userpermitip"] != "") { $ips = explode(';', $a["userpermitip"]); $gips = explode(';', $gip); if (count($gips) < count($ips)) { IntrusionNotify("Invalid IP: " . $gip); ForceLoad("index.php"); } for ($ipss = 0; $ipss < count($ips); $ipss++) { $gipi = $gips[$ipss]; $ipi = $ips[$ipss]; if (!match_network($ipi, $gipi)) { IntrusionNotify("Invalid IP: " . $gip); ForceLoad("index.php"); } } } $c = DBConnect(); $t = time(); if ($a["usertype"] == "team" && $a["usermultilogin"] != "t" && $a["userpermitip"] == "") { $r = DBExec($c, "update usertable set userip='" . $gip . "', updatetime=" . time() . ", userpermitip='" . $gip . "'," . "userlastlogin={$t}, usersession='" . session_id() . "' where username='******' and contestnumber=" . $b["contestnumber"] . " and usersitenumber=" . $b["contestlocalsite"], "DBLogIn(update session)"); } else { DBExec($c, "begin work"); $sql = "update usertable set usersessionextra='" . session_id() . "' where username='******' and contestnumber=" . $b["contestnumber"] . " and usersitenumber=" . $b["contestlocalsite"] . " and (usersessionextra='' or userip != '" . $gip . "' or userlastlogin<=" . ($t - 86400) . ")"; DBExec($c, $sql); DBExec($c, "update usertable set userip='" . $gip . "', updatetime=" . time() . ", userlastlogin={$t}, " . "usersession='" . session_id() . "' where username='******' and contestnumber=" . $b["contestnumber"] . " and usersitenumber=" . $b["contestlocalsite"], "DBLogIn(update user)"); if ($name == 'admin') { list($clockstr, $clocktime) = siteclock(); if ($clocktime < -600) { DBExec($c, "update contesttable set contestunlockkey='' where contestnumber=" . $b["contestnumber"], "DBLogInContest(update contest)"); } } DBExec($c, "commit work"); } LOGLevel("User {$name} authenticated (" . $gip . ")", 2); return $a; }
function siteclock() { if (($s = DBSiteInfo($_SESSION["usertable"]["contestnumber"], $_SESSION["usertable"]["usersitenumber"])) == null) { ForceLoad("../index.php"); } ///////CASO DE COMECAR MAIS TARDE NO CENTRALIZADO if (substr($_SESSION["usertable"]["username"], 0, 3) == 'XXX') { $s["currenttime"] = $s["currenttime"] - 60 * 10; // 10 minutos } if ($s["siteactive"] != "t") { return array("site is not active", -1000000000); } if (!$s["siterunning"]) { return array("contest not running", -1000000000); } if ($s["currenttime"] < 0) { $t = -$s["currenttime"]; if ($t > 3600) { $t = (int) ($t / 360) / 10; return array("> " . $t . " hour(s) to start", $s["currenttime"]); } if ($t > 60) { $t = (int) ($t / 60); return array("> " . $t . " min(s) to start", $s["currenttime"]); } else { return array($t . " second(s) to start", $s["currenttime"]); } } if ($s["currenttime"] >= 0) { $t = $s["siteduration"] - $s["currenttime"]; $str = ''; if ($t >= 3600) { $str .= (int) ($t / 3600) . 'h '; $t = $t % 3600; } if ($t > 60) { $t = (int) ($t / 60); return array($str . $t . " min(s) left", $s["currenttime"]); } else { if ($str == '') { if ($t > 0) { return array($t . " second(s) left", $s["currenttime"]); } else { $t = (int) (-$t / 60); return array($t . "min. of extra time", $s["currenttime"]); } } else { return array($str . " left", $s["currenttime"]); } } } else { return array("not started", -1000000000); } }
<?php require '../../db.php'; require '../config.php'; header('Content-type: text/plain; encoding=utf-8'); $s = DBSiteInfo($contest, $site); $run = DBAllRunsInSites($contest, $site, 'run'); $numRuns = count($run); for ($i = 0; $i < $numRuns; $i++) { $u = DBUserInfo($contest, $site, $run[$i]['user']); $runID = $run[$i]['number']; $runTime = dateconvminutes($run[$i]['timestamp']); $runTeam = $u['username']; $runProblem = $run[$i]['problem']; if ($runTime > $freezeTime) { continue; } echo $runID . '' . $runTime . '' . $runTeam . '' . $runProblem . ''; if ($run[$i]['yes'] == 't') { echo 'Y' . "\n"; } else { if ($run[$i]['answer'] == 'Not answered yet') { echo '?' . "\n"; } else { echo 'N' . "\n"; } } }
function DBNewClar($param, $c = null) { if (isset($param['contestnumber']) && !isset($param['contest'])) { $param['contest'] = $param['contestnumber']; } if (isset($param['sitenumber']) && !isset($param['site'])) { $param['site'] = $param['sitenumber']; } if (isset($param['usernumber']) && !isset($param['user'])) { $param['user'] = $param['usernumber']; } if (isset($param['number']) && !isset($param['clarnumber'])) { $param['clarnumber'] = $param['number']; } $ac = array('contest', 'site', 'user', 'problem', 'question'); $ac1 = array('clarnumber', 'clardate', 'clardatediff', 'clardatediffans', 'claranswer', 'clarstatus', 'clarjudge', 'clarjudgesite', 'updatetime'); $type['contest'] = 1; $type['problem'] = 1; $type['updatetime'] = 1; $type['site'] = 1; $type['user'] = 1; $type['clarnumber'] = 1; $type['clardatediffans'] = 1; $type['clardatediff'] = 1; $type['clardate'] = 1; $type['clarjudge'] = 1; $type['clarjudgesite'] = 1; foreach ($ac as $key) { if (!isset($param[$key]) || $param[$key] == "") { MSGError("DBNewClar param error: {$key} not found"); return false; } if (isset($type[$key]) && !is_numeric($param[$key])) { MSGError("DBNewClar param error: {$key} is not numeric"); return false; } ${$key} = sanitizeText($param[$key]); } $t = time(); $clarnumber = -1; $updatetime = -1; $clardatediff = -1; $clardate = $t; $claranswer = ''; $clardatediffans = 999999999; $clarjudge = 'NULL'; $clarjudgesite = 'NULL'; $clarstatus = 'openclar'; foreach ($ac1 as $key) { if (isset($param[$key])) { ${$key} = sanitizeText($param[$key]); if (isset($type[$key]) && !is_numeric($param[$key])) { MSGError("DBNewClar param error: {$key} is not numeric"); return false; } } } if ($updatetime < 0) { $updatetime = $t; } $cw = false; if ($c == null) { $cw = true; $c = DBConnect(); DBExec($c, "begin work", "DBNewClar(transaction)"); } $insert = true; if ($clarnumber < 0) { $sql = "select sitenextclar as nextclar from sitetable where sitenumber={$site} and contestnumber={$contest} for update"; $r = DBExec($c, $sql, "DBNewClar(get site for update)"); if (DBnlines($r) != 1) { DBExec($c, "rollback work", "DBNewClar(rollback-site)"); LOGError("Unable to find a unique site/contest in the database. SQL=(" . $sql . ")"); MSGError("Unable to find a unique site/contest in the database. Contact an admin now!"); exit; } $a = DBRow($r, 0); $n = $a["nextclar"] + 1; $clarnumber = $n; } else { $sql = "select * from clartable as t where t.contestnumber={$contest} and " . "t.clarsitenumber={$site} and t.clarnumber={$clarnumber}"; $r = DBExec($c, $sql . " for update", "DBNewClar(get clar for update)"); $n = DBnlines($r); if ($n > 0) { $insert = false; $lr = DBRow($r, 0); $t = $lr['updatetime']; } $n = $clarnumber; } DBExec($c, "update sitetable set sitenextclar={$clarnumber}, updatetime=" . $t . " where sitenumber={$site} and contestnumber={$contest} and sitenextclar<{$clarnumber}", "DBNewClar(update site)"); if ($clardatediff < 0) { $b = DBSiteInfo($contest, $site, $c); $dif = $b["currenttime"]; $clardatediff = $dif; if ($dif < 0) { DBExec($c, "rollback work", "DBNewClar(rollback-started)"); LOGError("Tried to submit a clarification but the contest is not started. SQL=(" . $sql . ")"); MSGError("The contest is not started yet!"); return false; } if (!$b["siterunning"]) { DBExec($c, "rollback work", "DBNewClar(rollback-over)"); LOGError("Tried to submit a clarification but the contest is over. SQL=(" . $sql . ")"); MSGError("The contest is over!"); return false; } } else { $dif = $clardatediff; } $ret = 1; if ($insert) { DBExec($c, "INSERT INTO clartable (contestnumber, clarsitenumber, clarnumber, usernumber, clardate, " . "clardatediff, clardatediffans, clarproblem, clardata, claranswer, clarjudge, clarjudgesite, clarstatus, updatetime) VALUES " . "({$contest}, {$site}, {$n}, {$user}, {$clardate}, {$clardatediff}, {$clardatediffans}, {$problem}, '{$question}', " . "'{$claranswer}', {$clarjudge}, {$clarjudgesite}, '{$clarstatus}', {$updatetime})", "DBNewClar(insert clar)"); if ($cw) { DBExec($c, "commit work", "DBNewClar(commit-insert)"); } LOGLevel("User {$user} submitted a clarification (#{$n}) on site #{$site} " . "(problem={$problem}, contest={$contest}).", 2); $ret = 2; } else { if ($updatetime > $t) { $ret = 2; DBExec($c, "update clartable set clardate={$clardate}, clardatediff={$clardatediff}, " . "clardatediffans={$clardatediffans}, claranswer='{$claranswer}', clarstatus='{$clarstatus}', " . "clarjudge={$clarjudge}, clarjudgesite={$clarjudgesite}, updatetime={$updatetime}, clardata='{$question}', clarproblem={$problem} " . "where clarnumber={$clarnumber} and contestnumber={$contest} and clarsitenumber={$site}", "DBNewClar(update clar)"); } if ($cw) { DBExec($c, "commit work", "DBNewClar(commit-update)"); } } return $ret; /* // isso gera problemas de portabilidade e de seguranca se os demais usuarios tiverem shell no servidor // por outro lado, garante que as coisas estao guardadas em arquivos fora do banco, caso haja outros problemas. umask(0077); @mkdir("/tmp/boca"); $fp = fopen("/tmp/boca/contest${contest}.site${site}.clar${n}.user${user}.problem${problem}.time${t}", "w"); if ($fp) { fwrite($fp, $question); fclose($fp); } else LOGLevel("Clarification not saved as file (clar=$n,site=$site,contest=$contest)", 1); */ }
if ($_POST["confirmation"] == "confirm" && isset($_POST['localsite']) && is_numeric($_POST['localsite']) && isset($_POST['challenge']) && isset($_POST['password'])) { $localsite = $_POST['localsite']; header("Content-transfer-encoding: binary\n"); header("Content-type: application/force-download"); //header ("Content-type: application/octet-stream"); //if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")) // header("Content-Disposition: filename=" .$_GET["filename"]); // For IE //else header("Content-Disposition: attachment; filename=export.dat"); ob_end_flush(); $reduced = false; if (isset($_POST["Submit"]) && $_POST['Submit'] == "Reduced Export") { $reduced = true; } $fromsite = $localsite; $siteinfo = DBSiteInfo($_SESSION["usertable"]["contestnumber"], $fromsite); $scores = explode(",", $siteinfo['siteglobalscore']); if (count($scores) == 0 || count($scores) == 1 && !is_numeric($scores[0])) { $scores = array($fromsite); } $judges = explode(",", $siteinfo['sitejudging']); if (count($judges) == 0 || count($judges) == 1 && !is_numeric($judges[0])) { $judges = array($fromsite); } $scores = array_unique(array_merge($scores, $judges)); if (in_array(0, $scores)) { $scores = null; } $xml = generateXML($_SESSION["usertable"]["contestnumber"], $localsite, $scores, $reduced); if (isset($_POST['nopassword']) && $_POST['nopassword'] == 'true') { echo $xml;
function DBUserTasks($contest, $site, $user) { $b = DBSiteInfo($contest, $site); if ($b == null) { exit; } $t = $b["currenttime"]; $c = DBConnect(); $r = DBExec($c, "select distinct t.sitenumber as site, t.tasknumber as number, " . "t.taskdatediff as timestamp, t.taskstatus as status, t.taskfilename as filename, " . "t.taskdesc as description, t.updatetime " . "from tasktable as t " . "where t.contestnumber={$contest} and t.sitenumber={$site} and " . "(t.taskdatediffans<={$t} or (t.taskstatus != 'done' and t.taskdatediff<={$t})) and " . "t.usernumber={$user} and t.taskstatus != 'deleted' and t.tasksystem='f' " . "order by t.updatetime", "DBUserTasks(get tasks)"); $n = DBnlines($r); $a = array(); for ($i = 0; $i < $n; $i++) { $a[$i] = DBRow($r, $i); } return $a; }
//$loc = $_SESSION['loc']; $loc = $locr = "../.."; require_once $locr . "/globals.php"; if (!ValidSession()) { InvalidSession($_SERVER['PHP_SELF']); ForceLoad($loc . "/index.php"); } if ($_SESSION["usertable"]["usertype"] != "admin") { IntrusionNotify($_SERVER['PHP_SELF']); ForceLoad($loc . "/index.php"); } require_once $locr . "/db.php"; require_once $locr . "/freport.php"; echo "<html><head><title>Report Page</title>\n"; echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"; echo "<link rel=stylesheet href=\"{$loc}/Css.php\" type=\"text/css\">\n"; $contest = $_SESSION["usertable"]["contestnumber"]; if (($ct = DBContestInfo($contest)) == null) { ForceLoad($loc . "/index.php"); } $site = $_SESSION["usertable"]["usersitenumber"]; if (($st = DBSiteInfo($contest, $site)) == null) { ForceLoad($loc . "/index.php"); } echo "</head><body><table border=1 width=\"100%\">\n"; echo "<tr><td bgcolor=\"eeee00\" nowrap align=center>"; echo "<img src=\"{$loc}/images/smallballoontransp.png\" alt=\"\">"; echo "<font color=\"#ffffff\"><a href=\"http://www.ime.usp.br/~cassio/boca/\">BOCA</a></font>"; echo "</td><td bgcolor=\"#eeee00\" width=\"99%\">\n"; echo $ct["contestname"] . " - " . $st["sitename"] . "</td>\n"; echo "</tr></table>\n";
function DBGetAllProblems($contest) { if (($b = DBSiteInfo($contest, $_SESSION["usertable"]["usersitenumber"])) == null) { return array(); } $c = DBConnect(); $sql = "select distinct p.problemnumber as number, p.problemname as problem, " . "p.problemcolor as color, p.problemcolorname as colorname " . "from problemtable as p " . "where p.contestnumber={$contest} and p.problemfullname !~ '(DEL)' "; if ($b["currenttime"] < 0) { $sql .= "and p.fake='t' "; } $sql .= " order by p.problemnumber"; $r = DBExec($c, $sql, "DBGetAllProblems(get problems)"); $n = DBnlines($r); $a = array(); for ($i = 0; $i < $n; $i++) { $a[$i] = DBRow($r, $i); } return $a; }
$param['siteautoend'] = $_POST["autoend"]; } if (isset($_POST["globalscore"])) { $param['siteglobalscore'] = $_POST["globalscore"]; } if (isset($_POST["active"])) { $param['siteactive'] = $_POST["active"]; } $param['sitescorelevel'] = $_POST["scorelevel"]; $param['sitepermitlogins'] = ''; if (isset($_POST["autojudge"])) { $param['siteautojudge'] = $_POST["autojudge"]; } $param['sitechiefname'] = $_POST["chiefname"]; DBUpdateSite($param); $st1 = DBSiteInfo($_SESSION["usertable"]["contestnumber"], $_POST["site"]); if ($t != $st1["sitestartdate"]) { $param = array('contest' => $_SESSION["usertable"]["contestnumber"], 'site' => $_POST["site"], 'start' => $t); DBRenewSiteTime($param); } } ForceLoad("site.php?site=" . $_POST["site"]); } if ($main && isset($_FILES["importfile"]) && isset($_POST["Submit"]) && $_POST["Submit"] == 'Import' && $_FILES["importfile"]["name"] != "") { if ($_POST["confirmation"] == "confirm") { $type = myhtmlspecialchars($_FILES["importfile"]["type"]); $size = myhtmlspecialchars($_FILES["importfile"]["size"]); $name = myhtmlspecialchars($_FILES["importfile"]["name"]); $temp = myhtmlspecialchars($_FILES["importfile"]["tmp_name"]); if (!is_uploaded_file($temp)) { IntrusionNotify("file upload problem.");
$teamUni = $teamName; } $contestfile = $contestfile . $teamID . '' . $teamUni . '' . $teamName . "\n"; } $contestfile = $contestfile . '1' . '' . '1' . "\n"; $contestfile = $contestfile . $numProblems . '' . 'Y' . "\n"; $score = DBScore($_SESSION["usertable"]["contestnumber"], false, -1, $ct["contestlocalsite"]); //$contestfile = $contestfile . // "<h2>ICPC Output</h2>"; //$contestfile = $contestfile . // "<pre>"; $n = 0; $class = 1; while (list($e, $c) = each($score)) { if (isset($score[$e]["site"]) && isset($score[$e]["user"])) { if (DBSiteInfo($_SESSION["usertable"]["contestnumber"], $score[$e]["site"]) != null) { $r = DBUserInfo($_SESSION["usertable"]["contestnumber"], $score[$e]["site"], $score[$e]["user"]); $contestfile = $contestfile . $r["usericpcid"] . "," . $class++ . "," . $score[$e]["totalcount"] . "," . $score[$e]["totaltime"] . ","; if ($score[$e]["first"]) { $contestfile = $contestfile . $score[$e]["first"] . "\n"; } else { $contestfile = $contestfile . "0\n"; } $n++; } } } //$contestfile = $contestfile . // "</pre>"; $timefile = $st['currenttime']; $versionfile = '1.0' . "\n";
function DBScoreSite($contest, $site, $verifylastmile, $hor = -1, $data = null) { if (($blocal = DBSiteInfo($contest, $_SESSION["usertable"]["usersitenumber"])) == null) { exit; } if (($b = DBSiteInfo($contest, $site, null, false)) == null) { $b = $blocal; } if (($ct = DBContestInfo($contest)) == null) { exit; } $t = time(); $ta = $blocal["currenttime"]; if ($hor >= 0) { $ta = $hor; } if ($verifylastmile) { $tf = $b["sitelastmilescore"]; } else { $tf = $b["siteduration"]; } if ($data != null && is_numeric($data)) { if ($data < $ta) { $ta = $data; } $data = null; } $data0 = array(); if ($data == null) { $c = DBConnect(); $resp = array(); $r = DBExec($c, "select * from usertable where contestnumber={$contest} and usersitenumber={$site} and " . "usertype='team' and userlastlogin is not null and userenabled='t'", "DBScoreSite(get users)"); $n = DBnlines($r); for ($i = 0; $i < $n; $i++) { $a = DBRow($r, $i); $resp[$a["usernumber"]]["user"] = $a["usernumber"]; $resp[$a["usernumber"]]["site"] = $a["usersitenumber"]; $resp[$a["usernumber"]]["username"] = $a["username"]; $resp[$a["usernumber"]]["usertype"] = $a["usertype"]; $resp[$a["usernumber"]]["userfullname"] = $a["userfullname"]; $resp[$a["usernumber"]]["totaltime"] = 0; $resp[$a["usernumber"]]["totalcount"] = 0; $resp[$a["usernumber"]]["problem"] = array(); } $r = DBExec($c, "select r.usernumber as user, p.problemname as problemname, r.runproblem as problem, " . "p.problemcolor as color, p.problemcolorname as colorname, " . "r.rundatediff as time, r.rundatediffans as anstime, a.yes as yes, r.runanswer as answer from " . "runtable as r, answertable as a, problemtable as p where r.runanswer=a.answernumber and " . "a.contestnumber={$contest} and p.problemnumber=r.runproblem and p.contestnumber={$contest} and " . "r.contestnumber={$contest} and r.runsitenumber={$site} and (r.runstatus ~ 'judged' or r.runstatus ~ 'judged+') and " . "r.rundatediff>=0 and r.rundatediff<={$tf} and r.rundatediffans<={$ta} " . "order by r.usernumber, r.runproblem, r.rundatediff", "DBScoreSite(get runs)"); $n = DBnlines($r); $a = array(); for ($i = 0; $i < $n; $i++) { $a[$i] = DBRow($r, $i); } $data0['n'] = $n; $data0['resp'] = $resp; $data0['a'] = $a; $data0['site'] = $site; } else { $resp = $data['resp']; $n = $data['n']; $a = $data['a']; } $i = 0; while ($i < $n) { if ($a[$i]["anstime"] > $ta) { $i++; continue; } $user = $a[$i]["user"]; $problem = $a[$i]["problem"]; $time = 0; $k = 0; if (!isset($resp[$user])) { $i++; continue; } $resp[$user]["user"] = $user; $resp[$user]["site"] = $site; $resp[$user]["problem"][$problem]["name"] = $a[$i]["problemname"]; $resp[$user]["problem"][$problem]["color"] = $a[$i]["color"]; $resp[$user]["problem"][$problem]["colorname"] = $a[$i]["colorname"]; $resp[$user]["problem"][$problem]["solved"] = false; $resp[$user]["problem"][$problem]["judging"] = false; $resp[$user]["problem"][$problem]["time"] = 0; $resp[$user]["problem"][$problem]["penalty"] = 0; $resp[$user]["problem"][$problem]["count"] = 0; while ($i < $n && $a[$i]["anstime"] <= $ta && $a[$i]["user"] == $user && $a[$i]["problem"] == $problem && $a[$i]["yes"] != 't') { $time += (int) ($ct["contestpenalty"] / 60); $k++; $i++; } $resp[$user]["problem"][$problem]["count"] = $k; if ($i >= $n) { break; } if ($a[$i]["anstime"] <= $ta && $a[$i]["user"] == $user && $a[$i]["problem"] == $problem && $a[$i]["yes"] == 't') { $timet = (int) ($a[$i]["time"] / 60); if (!isset($resp[$user]["first"]) || $timet < $resp[$user]["first"]) { $resp[$user]["first"] = $timet; } $time += $timet; $resp[$user]["problem"][$problem]["time"] = $timet; $resp[$user]["problem"][$problem]["penalty"] = $time; $resp[$user]["problem"][$problem]["solved"] = true; $resp[$user]["problem"][$problem]["count"]++; $resp[$user]["totaltime"] += $time; $resp[$user]["totalcount"]++; } while ($i < $n && $a[$i]["user"] == $user && $a[$i]["problem"] == $problem) { $i++; } } if ($data == null) { $aa = DBRecentNews($contest, $site, $verifylastmile, $ta); $data0['aa'] = $aa; } else { $aa = $data['aa']; } for ($i = 0; $i < count($aa); $i++) { if ($aa[$i]["fut"] == 't') { $resp[$aa[$i]["usernumber"]]["problem"][$aa[$i]["problemnumber"]]["judging"] = true; } } if (($result = ordena($resp)) === false) { LOGError("Error while sorting scores (contest={$contest}, site={$site})."); MSGError("Error while sorting scores. Contact an admin now!"); } return array($result, $data0); }