aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCassio de Campos <cassiopc@gmail.com>2017-11-01 17:35:22 +0000
committerCassio de Campos <cassiopc@gmail.com>2017-11-01 17:35:22 +0000
commit689ca417a57f7d3e7ba2836b09e493a61a13aac1 (patch)
tree8d97492e81f453a97c00c3e560864f586321b296
parent9583d6ea7bb503fb0094751c5a871b3fb65de84a (diff)
parent6c7db3cfb3e72e6bf7bb8b5c530ec41fa03ec666 (diff)
downloadboca-689ca417a57f7d3e7ba2836b09e493a61a13aac1.tar.gz
boca-689ca417a57f7d3e7ba2836b09e493a61a13aac1.zip
Merge branch 'devel'
-rw-r--r--src/db.php18
-rw-r--r--src/fcontest.php2
-rw-r--r--src/fextdata.php68
-rw-r--r--src/filedownload.php2
-rw-r--r--src/filewindow.php2
-rw-r--r--src/fproblem.php2
-rw-r--r--src/site/getsite.php2
7 files changed, 61 insertions, 35 deletions
diff --git a/src/db.php b/src/db.php
index 2f6dd57..5948186 100644
--- a/src/db.php
+++ b/src/db.php
@@ -33,28 +33,28 @@ function DB_lo_open($conn, $file, $mode) {
else
return pg_lo_open ($conn, $file, $mode);
}
-function DB_lo_read_tobrowser($contest,$id) {
- $str = DB_lo_read($contest,$id);
- echo $str;
- return true;
+function DB_lo_read_tobrowser($contest,$id,$c=null) {
+ $str = DB_lo_read($contest,$id,-1,$c);
+ echo $str;
+ return true;
}
-function DB_lo_read($contest,$id,$s=-1) {
+function DB_lo_read($contest,$id,$s=-1,$c=null) {
if (strcmp(phpversion(),'4.2.0')<0) {
if($s<0) {
$str='';
- while (($buf = pg_loread ($id, 100000)) != false) $str .= $buf;
+ while (($buf = pg_loread ($id, 1000000)) != false) $str .= $buf;
} else
$str = pg_loread ($id, $s);
}
else {
if($s<0) {
$str='';
- while (($buf = pg_lo_read ($id, 100000)) != false) $str .= $buf;
+ while (($buf = pg_lo_read ($id, 1000000)) != false) $str .= $buf;
} else
$str = pg_lo_read ($id, $s);
}
- if(($str2 = DB_unlock($contest,$str))===false) return $str;
+ if(($str2 = DB_unlock($contest,$str,$c))===false) return $str;
return $str2;
}
function DB_unlock($contest,$str,$c=null) {
@@ -296,7 +296,7 @@ function DBcrc($contest,$id, $c=null) {
// just to return a unique string that will not match any other...
return "no-HASH-" . rand() . "-" . rand() . "-" . time();
}
- $str = DB_lo_read($contest,$f);
+ $str = DB_lo_read($contest,$f,-1,$c);
DB_lo_close($f);
if($docommit)
DBExec($c, "commit work", "DBcrc(commit)");
diff --git a/src/fcontest.php b/src/fcontest.php
index d00ce68..2af9ed4 100644
--- a/src/fcontest.php
+++ b/src/fcontest.php
@@ -327,7 +327,7 @@ function DBDeleteUser($contest, $site, $user) {
$n = DBnlines($r);
for ($i=0;$i<$n;$i++) {
$a = DBRow($r,$i);
- DBRunDelete($a["number"],$a["site"],$contestnumber,$_SESSION["usertable"]["usernumber"],$_SESSION["usertable"]["usersitenumber"]);
+ DBRunDelete($a["number"],$a["site"],$contest,$_SESSION["usertable"]["usernumber"],$_SESSION["usertable"]["usersitenumber"]);
}
DBExec($c, "commit work");
LOGLevel("User $user (site=$site,contest=$contest) marked as inactive.", 1);
diff --git a/src/fextdata.php b/src/fextdata.php
index 1046f29..4673fb4 100644
--- a/src/fextdata.php
+++ b/src/fextdata.php
@@ -246,7 +246,7 @@ function scoretransfer($putname, $localsite, $timeo=20) {
}
-function getMainXML($contest,$timeo=20,$upd=false) {
+function getMainXML($contest,$timeo=30,$upd=false) {
$ds = DIRECTORY_SEPARATOR;
if($ds=="") $ds = "/";
$logstr = '';
@@ -354,7 +354,7 @@ function getMainXML($contest,$timeo=20,$upd=false) {
$data = generateSiteXML($contest, $localsite, $updatetime-30, $localsite);
$logstr .= $data[1];
// $logstr .= $s;
- $data = encryptData($data[0], myhash(trim($sitedata[2])));
+ $data = encryptData($data[0], myhash(trim($sitedata[2])),false);
// $logstr .= "AB: " . now() . "\n"
$data_url = http_build_query(array('xml' => $data, 'updatetime' => ($updatetime-30)
@@ -444,7 +444,7 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0,$mainsite=-1)
// print_r($values);
$conn = DBConnect();
if ($conn==null) return array(false, $logstr);
- DBExec($conn,"begin work","importFromXML(begin)");
+ //DBExec($conn,"begin work","importFromXML(begin)");
// DBExec($conn,"lock","importFromXML(lock)");
$r = DBExec($conn, "select * from contesttable where contestnumber=$contest");
if (DBnLines($r)==0) {
@@ -663,23 +663,46 @@ function genSQLs($contest, $site, $updatetime, $mainsite=1) {
$sql['contesttable']="select contestnumber, contestname, conteststartdate, contestduration, contestlastmileanswer," .
"contestlastmilescore, contestpenalty, contestmaxfilesize, contestmainsite, contestkeys " .
"from contesttable where contestnumber=$contest"; // and updatetime >= $updatetime";
- $sql['sitetable']="select * from sitetable where contestnumber=$contest and sitenumber=$site and updatetime >= $updatetime";
- $sql['answertable']="select * from answertable where contestnumber=$contest and fake='f' and updatetime >= $updatetime";
- $sql['langtable']="select * from langtable where contestnumber=$contest and updatetime >= $updatetime";
- $sql['problemtable']="select " .
- "contestnumber, " .
- "problemnumber, " .
- "problemname, " .
- "problemfullname, " .
- "problembasefilename, " .
- "probleminputfilename, " .
- "probleminputfile, " .
- "probleminputfilehash, " .
- "fake, " .
- //"problemcolorname, " .
- //"problemcolor, " .
- "updatetime" .
- " from problemtable where contestnumber=$contest and fake='f' and updatetime >= $updatetime";
+ $sql['sitetable']="select " .
+ "contestnumber, " .
+ "sitenumber, " .
+ "siteip, " .
+ "sitename, " .
+ "siteactive, " .
+ "sitepermitlogins, " .
+ "sitelastmileanswer, " .
+ "sitelastmilescore, " .
+ "siteduration, " .
+ "siteautoend, " .
+ "sitejudging, " .
+ "sitetasking, " .
+ "siteglobalscore, " .
+ "sitescorelevel, " .
+ "sitemaxtask, " .
+ "sitechiefname, " .
+ "siteautojudge, " .
+ "sitemaxruntime, " .
+ "sitemaxjudgewaittime, " .
+ "updatetime " .
+ " from sitetable where contestnumber=$contest and sitenumber=$site and updatetime >= $updatetime";
+ if($site != $mainsite) {
+ $sql['answertable']="select * from answertable where contestnumber=$contest and fake='f' and updatetime >= $updatetime";
+ $sql['langtable']="select * from langtable where contestnumber=$contest and updatetime >= $updatetime";
+ $sql['problemtable']="select " .
+ "contestnumber, " .
+ "problemnumber, " .
+ "problemname, " .
+ "problemfullname, " .
+ "problembasefilename, " .
+ "probleminputfilename, " .
+ "probleminputfile, " .
+ "probleminputfilehash, " .
+ "fake, " .
+ //"problemcolorname, " .
+ //"problemcolor, " .
+ "updatetime" .
+ " from problemtable where contestnumber=$contest and fake='f' and updatetime >= $updatetime";
+ }
$sql['sitetimetable']="select * from sitetimetable where contestnumber=$contest and sitenumber=$site and updatetime >= $updatetime";
$sql['usertable']="select * from usertable where contestnumber=$contest and (usersitenumber=$site or usersitenumber=$mainsite) and updatetime >= $updatetime";
$sql['clartable']="select * from clartable where contestnumber=$contest and clarsitenumber=$site and updatetime >= $updatetime";
@@ -700,14 +723,15 @@ function generateSiteXML($contest,$site,$updatetime, $mainsite=1) {
if (!is_array($meta)) return null;
$r = DBExec ($c, $vv, "generateSiteXML($kk)");
$n = DBnLines ($r);
- $logstr .= "$kk has $n records to update\n";
+ if($n > 0)
+ $logstr .= "$kk has $n records to update\n";
for($i=0; $i<$n; $i++) {
$atual = DBRow($r,$i);
$str .= "<" . $kk . ">\n";
foreach($atual as $key => $val) {
if($meta[$key]['type'] == 'oid' && $val != '') {
if (($lo = DB_lo_open ($c, $val, "r")) !== false) {
- $str .= " <" . $key . ">" . base64_encode("base64:" . base64_encode(DB_lo_read($contest,$lo))) . "</" . $key . ">\n";
+ $str .= " <" . $key . ">" . base64_encode("base64:" . base64_encode(DB_lo_read($contest,$lo,-1,$c))) . "</" . $key . ">\n";
DB_lo_close($lo);
} else {
LOGError("large object ($key,$val) not readable");
diff --git a/src/filedownload.php b/src/filedownload.php
index 92de694..6b56ca9 100644
--- a/src/filedownload.php
+++ b/src/filedownload.php
@@ -74,7 +74,7 @@ if ($_GET["oid"]>=0) {
header ("Content-Disposition: attachment; filename=" . basename($fname));
ob_end_flush();
- if (DB_lo_read_tobrowser ($_SESSION["usertable"]["contestnumber"],$lo) === false) {
+ if (DB_lo_read_tobrowser ($_SESSION["usertable"]["contestnumber"],$lo,$c) === false) {
echo "<html><head><title>Download Page</title>";
DBExec($c, "rollback work");
LOGError ("Unable to download file (" . basename($fname) . ")");
diff --git a/src/filewindow.php b/src/filewindow.php
index 594e483..64bd1ec 100644
--- a/src/filewindow.php
+++ b/src/filewindow.php
@@ -79,7 +79,7 @@ if ($_GET["oid"]>=0) {
echo $msg ."\n\n\n";
}
// echo "<pre>\n";
- if (DB_lo_read_tobrowser ($_SESSION["usertable"]["contestnumber"],$lo) === false) {
+ if (DB_lo_read_tobrowser ($_SESSION["usertable"]["contestnumber"],$lo,$c) === false) {
header ("Content-type: text/html");
echo "<html><head><title>View Page</title>";
DBExec($c, "rollback work");
diff --git a/src/fproblem.php b/src/fproblem.php
index a66f62c..c14a61b 100644
--- a/src/fproblem.php
+++ b/src/fproblem.php
@@ -457,6 +457,8 @@ function DBGetProblems($contest,$showanyway=false) {
if ($b["currenttime"] < 0 && !$showanyway)
return array();
+ if(($c = DBContestInfo($contest)) == null) return array();
+ if (time() < $c['conteststartdate'] && !$showanyway) return array();
$c = DBConnect();
$sql = "select distinct p.problemnumber as number, p.problemname as problem, " .
diff --git a/src/site/getsite.php b/src/site/getsite.php
index f31f607..c29581c 100644
--- a/src/site/getsite.php
+++ b/src/site/getsite.php
@@ -49,7 +49,7 @@ if($ct["contestlocalsite"]==$ct["contestmainsite"]) {
}
if(isset($_POST['updatetime']) && is_numeric($_POST['updatetime'])) {
$xml = generateSiteXML($_SESSION["usertable"]["contestnumber"],$fromsite,$_POST['updatetime'],$ct["contestmainsite"]);
- echo "<!-- " . encryptData($xml[0],$u["userpassword"]) . " -->";
+ echo "<!-- " . encryptData($xml[0],$u["userpassword"],false) . " -->";
// echo "MAIN\n" . $xml[1];
}
} else {