aboutsummaryrefslogtreecommitdiff
path: root/boca-1.5.0
diff options
context:
space:
mode:
authorcassiopc <cassiopc@gmail.com>2012-08-22 14:39:03 +0000
committercassiopc <cassiopc@gmail.com>2012-08-22 14:39:03 +0000
commitfc7990c62d85fdebef4a438a1fbc9d69a3710d55 (patch)
treeba6e1a305b0e63fbeb719e1a682c8e5e578b726e /boca-1.5.0
parent059e2fdcf0cef7e3594a66e21b3fd682ac736856 (diff)
downloadboca-fc7990c62d85fdebef4a438a1fbc9d69a3710d55.tar.gz
boca-fc7990c62d85fdebef4a438a1fbc9d69a3710d55.zip
small bug fixes, inclusion of file size limit configurable
Diffstat (limited to 'boca-1.5.0')
-rw-r--r--boca-1.5.0/doc/INSTALL.txt17
-rw-r--r--boca-1.5.0/doc/problemexamples/problemtemplate/compile/c2
-rw-r--r--boca-1.5.0/doc/problemexamples/problemtemplate/limits/c2
-rw-r--r--boca-1.5.0/doc/problemexamples/problemtemplate/limits/cpp2
-rw-r--r--boca-1.5.0/doc/problemexamples/problemtemplate/limits/java2
-rwxr-xr-xboca-1.5.0/doc/problemexamples/problemtemplate/run/c13
-rwxr-xr-xboca-1.5.0/doc/problemexamples/problemtemplate/run/cpp17
-rwxr-xr-xboca-1.5.0/doc/problemexamples/problemtemplate/run/java19
-rw-r--r--boca-1.5.0/src/admin/problem.php20
-rw-r--r--boca-1.5.0/src/admin/report/piechart.php10
-rw-r--r--boca-1.5.0/src/admin/report/stat.php12
-rw-r--r--boca-1.5.0/src/admin/task.php2
-rw-r--r--boca-1.5.0/src/admin/user.php44
-rw-r--r--boca-1.5.0/src/db.php8
-rw-r--r--boca-1.5.0/src/fcontest.php67
-rw-r--r--boca-1.5.0/src/fproblem.php52
-rw-r--r--boca-1.5.0/src/freport.php39
-rw-r--r--boca-1.5.0/src/frun.php4
-rw-r--r--boca-1.5.0/src/ftask.php5
-rw-r--r--boca-1.5.0/src/hex.php49
-rw-r--r--boca-1.5.0/src/judge/team.php1
-rw-r--r--boca-1.5.0/src/optionlower.php20
-rwxr-xr-xboca-1.5.0/src/private/autojudging.php44
-rwxr-xr-xboca-1.5.0/src/private/createproblemzip.php15
-rw-r--r--boca-1.5.0/src/scoretable.php8
-rw-r--r--boca-1.5.0/src/staff/task.php2
-rw-r--r--boca-1.5.0/src/team/header.php4
-rw-r--r--boca-1.5.0/src/webcast.zipbin2813 -> 0 bytes
-rw-r--r--boca-1.5.0/src/webcast/contest/index.php15
-rw-r--r--boca-1.5.0/tools/fcontest.php1278
-rw-r--r--boca-1.5.0/tools/icpc.etc.tgzbin8648 -> 8648 bytes
31 files changed, 1639 insertions, 134 deletions
diff --git a/boca-1.5.0/doc/INSTALL.txt b/boca-1.5.0/doc/INSTALL.txt
index a9d3bc3..6319c82 100644
--- a/boca-1.5.0/doc/INSTALL.txt
+++ b/boca-1.5.0/doc/INSTALL.txt
@@ -121,6 +121,23 @@ setting up the correct values. Ex:
5) It's all done. Now you have to manage the contest with a
browser and boca. Proceed to the ADMIN.TXT file.
+
+----------
+==> DETAIL ABOUT MOVING FROM POSTGRES 8.x TO 9.1
+LARGE OBJECTS GET WRONG OWNERSHIP. TO FIX, RUN WITHIN psql:
+# su - postgres
+# psql -d bocadb
+
+do $$
+declare r record;
+begin
+for r in select loid from pg_catalog.pg_largeobject loop
+execute 'ALTER LARGE OBJECT ' || r.loid || ' OWNER TO bocauser';
+end loop;
+end$$;
+\q
+
+
Security Issues
---------------
It is strongly recommended that BOCA be installed on a computer
diff --git a/boca-1.5.0/doc/problemexamples/problemtemplate/compile/c b/boca-1.5.0/doc/problemexamples/problemtemplate/compile/c
index 4cb7ea8..5376708 100644
--- a/boca-1.5.0/doc/problemexamples/problemtemplate/compile/c
+++ b/boca-1.5.0/doc/problemexamples/problemtemplate/compile/c
@@ -21,7 +21,7 @@
# $1 source_file
# $2 exe_file (default run.exe)
# $3 timelimit (optional, limit to run all the repetitions, by default only one repetition)
-# $4 maximum allowed memory (in MBytes)
+# $4 maximum allowed memory (in MBytes, default 512M)
#
# the output of the submission should be directed to the standard output
#
diff --git a/boca-1.5.0/doc/problemexamples/problemtemplate/limits/c b/boca-1.5.0/doc/problemexamples/problemtemplate/limits/c
index b48a3b7..b5aec73 100644
--- a/boca-1.5.0/doc/problemexamples/problemtemplate/limits/c
+++ b/boca-1.5.0/doc/problemexamples/problemtemplate/limits/c
@@ -5,6 +5,8 @@ echo 4
echo 10
# and the maximum amount of memory per repetition in the third line (in Mbytes)
echo 512
+# and the maximum file size in the fourth line (in kbytes)
+echo 1024
# and shall return zero to indicate no failure
exit 0
# the idea is that this file will be executed by the autojudge in the first time the autojudge downloads a problem, so as it will be
diff --git a/boca-1.5.0/doc/problemexamples/problemtemplate/limits/cpp b/boca-1.5.0/doc/problemexamples/problemtemplate/limits/cpp
index b48a3b7..b5aec73 100644
--- a/boca-1.5.0/doc/problemexamples/problemtemplate/limits/cpp
+++ b/boca-1.5.0/doc/problemexamples/problemtemplate/limits/cpp
@@ -5,6 +5,8 @@ echo 4
echo 10
# and the maximum amount of memory per repetition in the third line (in Mbytes)
echo 512
+# and the maximum file size in the fourth line (in kbytes)
+echo 1024
# and shall return zero to indicate no failure
exit 0
# the idea is that this file will be executed by the autojudge in the first time the autojudge downloads a problem, so as it will be
diff --git a/boca-1.5.0/doc/problemexamples/problemtemplate/limits/java b/boca-1.5.0/doc/problemexamples/problemtemplate/limits/java
index b48a3b7..b5aec73 100644
--- a/boca-1.5.0/doc/problemexamples/problemtemplate/limits/java
+++ b/boca-1.5.0/doc/problemexamples/problemtemplate/limits/java
@@ -5,6 +5,8 @@ echo 4
echo 10
# and the maximum amount of memory per repetition in the third line (in Mbytes)
echo 512
+# and the maximum file size in the fourth line (in kbytes)
+echo 1024
# and shall return zero to indicate no failure
exit 0
# the idea is that this file will be executed by the autojudge in the first time the autojudge downloads a problem, so as it will be
diff --git a/boca-1.5.0/doc/problemexamples/problemtemplate/run/c b/boca-1.5.0/doc/problemexamples/problemtemplate/run/c
index 75720ee..b46e5f9 100755
--- a/boca-1.5.0/doc/problemexamples/problemtemplate/run/c
+++ b/boca-1.5.0/doc/problemexamples/problemtemplate/run/c
@@ -15,14 +15,15 @@
# // You should have received a copy of the GNU General Public License
# // along with this program. If not, see <http://www.gnu.org/licenses/>.
# ////////////////////////////////////////////////////////////////////////////////
-#Last modified: 21/july/2012 by cassio@ime.usp.br
+#Last modified: 22/aug/2012 by cassio@ime.usp.br
#
# parameters are:
# $1 exe_file
# $2 input_file
# $3 timelimit (limit to run all the repetitions, by default only one repetition)
# $4 number_of_repetitions_to_run (optional, can be used for better tuning the timelimit)
-# $5 maximum allowed memory (in KBytes)
+# $5 maximum allowed memory (in MBytes)
+# $6 maximum allowed output size (in KBytes)
#
# the output of the submission should be directed to the standard output
#
@@ -98,6 +99,12 @@ if [ "$5" != "" ]; then
maxm=${5}000
fi
fi
+maxf=1024
+if [ "$6" != "" ]; then
+ if [ "$6" -gt "0" ]; then
+ maxf=${6}
+ fi
+fi
cp "$2" stdin0 2>/dev/null
cp "$1" run.exe 2>/dev/null
@@ -110,7 +117,7 @@ fi
cdir=`pwd`
echo "Current directory is $cdir -- chrooting on it" >&2
-$sf -F10 -r$nruns -n1 -R$cdir -C. -U$bocau -G$bocag -ostdout0 -estderr0 -d$maxm -m$maxm -t$time -T$ttime -istdin0 ./run.exe
+$sf -F10 -f$maxf -r$nruns -n1 -R$cdir -C. -U$bocau -G$bocag -ostdout0 -estderr0 -d$maxm -m$maxm -t$time -T$ttime -istdin0 ./run.exe
ret=$?
if [ $ret -gt 10 ]; then
ret=0
diff --git a/boca-1.5.0/doc/problemexamples/problemtemplate/run/cpp b/boca-1.5.0/doc/problemexamples/problemtemplate/run/cpp
index e5c7620..b46e5f9 100755
--- a/boca-1.5.0/doc/problemexamples/problemtemplate/run/cpp
+++ b/boca-1.5.0/doc/problemexamples/problemtemplate/run/cpp
@@ -15,14 +15,15 @@
# // You should have received a copy of the GNU General Public License
# // along with this program. If not, see <http://www.gnu.org/licenses/>.
# ////////////////////////////////////////////////////////////////////////////////
-#Last modified: 21/july/2012 by cassio@ime.usp.br
+#Last modified: 22/aug/2012 by cassio@ime.usp.br
#
# parameters are:
# $1 exe_file
# $2 input_file
# $3 timelimit (limit to run all the repetitions, by default only one repetition)
# $4 number_of_repetitions_to_run (optional, can be used for better tuning the timelimit)
-# $5 maximum allowed memory (in KBytes)
+# $5 maximum allowed memory (in MBytes)
+# $6 maximum allowed output size (in KBytes)
#
# the output of the submission should be directed to the standard output
#
@@ -66,11 +67,11 @@ if [ "$1" == "" -o "$2" == "" -o "$3" == "" ]; then
exit 43
fi
if [ ! -x "$1" ]; then
- echo "$1 not found or it's not executable"
+ echo "$1 not found (or is not in the current dir) or it's not executable"
exit 44
fi
if [ ! -r "$2" ]; then
- echo "$2 not found or it's not readable"
+ echo "$2 not found (or is not in the current dir) or it's not readable"
exit 45
fi
if [ ! -x $sf ]; then
@@ -98,6 +99,12 @@ if [ "$5" != "" ]; then
maxm=${5}000
fi
fi
+maxf=1024
+if [ "$6" != "" ]; then
+ if [ "$6" -gt "0" ]; then
+ maxf=${6}
+ fi
+fi
cp "$2" stdin0 2>/dev/null
cp "$1" run.exe 2>/dev/null
@@ -110,7 +117,7 @@ fi
cdir=`pwd`
echo "Current directory is $cdir -- chrooting on it" >&2
-$sf -F10 -r$nruns -n1 -R$cdir -C. -U$bocau -G$bocag -ostdout0 -estderr0 -d$maxm -m$maxm -t$time -T$ttime -istdin0 ./run.exe
+$sf -F10 -f$maxf -r$nruns -n1 -R$cdir -C. -U$bocau -G$bocag -ostdout0 -estderr0 -d$maxm -m$maxm -t$time -T$ttime -istdin0 ./run.exe
ret=$?
if [ $ret -gt 10 ]; then
ret=0
diff --git a/boca-1.5.0/doc/problemexamples/problemtemplate/run/java b/boca-1.5.0/doc/problemexamples/problemtemplate/run/java
index c24d842..d35818f 100755
--- a/boca-1.5.0/doc/problemexamples/problemtemplate/run/java
+++ b/boca-1.5.0/doc/problemexamples/problemtemplate/run/java
@@ -15,14 +15,15 @@
# // You should have received a copy of the GNU General Public License
# // along with this program. If not, see <http://www.gnu.org/licenses/>.
# ////////////////////////////////////////////////////////////////////////////////
-#Last modified: 21/july/2012 by cassio@ime.usp.br
+#Last modified: 22/aug/2012 by cassio@ime.usp.br
#
# parameters are:
# $1 main_class
# $2 input_file
# $3 timelimit (limit to run all the repetitions, by default only one repetition)
# $4 number_of_repetitions_to_run (optional, can be used for better tuning the timelimit)
-# $5 maximum allowed memory (in KBytes)
+# $5 maximum allowed memory (in MBytes)
+# $6 maximum allowed output size (in KBytes)
#
# the output of the submission should be directed to the standard output
#
@@ -108,10 +109,16 @@ if [ "$4" != "" ]; then
nruns=$4
fi
fi
-maxm=512
+maxm=512000
if [ "$5" != "" ]; then
if [ "$5" -gt "0" ]; then
- maxm=${5}
+ maxm=${5}000
+ fi
+fi
+maxf=1024
+if [ "$6" != "" ]; then
+ if [ "$6" -gt "0" ]; then
+ maxf=${6}
fi
fi
@@ -136,7 +143,7 @@ if [ ! -x \$java ]; then
exit 47
fi
export CLASSPATH=.:./run.jar:$CLASSPATH
-$sf -r$nruns -t$time -T$ttime -istdin0 -F256 -u256 -ostdout0 -estderr0 -U$bocau -G$bocag -n0 -C. -f20000 -d20000000 -m20000000 -- \$java -Xmx${maxm}M -Xms${maxm}M "$name"
+$sf -r$nruns -t$time -T$ttime -istdin0 -F256 -u256 -ostdout0 -estderr0 -U$bocau -G$bocag -n0 -C. -f20000 -d20000000 -m20000000 -- \$java -Xmx${maxm}K -Xms${maxm}K "$name"
echo \$? > runit.retcode
if [ ! -d /bocajail ]; then
/bin/umount /proc 2>/dev/null
@@ -157,7 +164,7 @@ else
echo "CODE NOT BEING CHROOTED. DO NOT RUN THIS ON THE MAIN SERVER" >&2
echo "CODE NOT BEING CHROOTED. DO NOT RUN THIS ON THE MAIN SERVER" >&2
echo "CODE NOT BEING CHROOTED. DO NOT RUN THIS ON THE MAIN SERVER" >&2
- $sf -r$nruns -t$time -T$ttime -istdin0 -F256 -u256 -U$bocau -G$bocag -ostdout0 -estderr0 -n0 -C. -d20000000 -m20000000 -- $java -cp run.jar -Xmx${maxm}M -Xms${maxm}M "$name"
+ $sf -r$nruns -t$time -T$ttime -istdin0 -F256 -u256 -U$bocau -G$bocag -ostdout0 -estderr0 -n0 -C. -d20000000 -m20000000 -- $java -cp run.jar -Xmx${maxm}K -Xms${maxm}K "$name"
ret=$?
fi
if [ $ret -gt 10 ]; then
diff --git a/boca-1.5.0/src/admin/problem.php b/boca-1.5.0/src/admin/problem.php
index 0b055b6..365d059 100644
--- a/boca-1.5.0/src/admin/problem.php
+++ b/boca-1.5.0/src/admin/problem.php
@@ -61,7 +61,7 @@ if (isset($_POST["Submit3"]) && isset($_POST["problemnumber"]) && is_numeric($_P
<br>
<script language="javascript">
function conf2(url) {
- if (confirm("Confirm the DELETION of the PROBLEM and ALL data associated to it (including the SUBMISSIONS)?")) {
+ if (confirm("Confirm the DELETION of the PROBLEM and ALL data associated to it?")) {
if (confirm("Are you REALLY sure about what you are doing? DATA CANNOT BE RECOVERED!")) {
document.location=url;
} else {
@@ -71,6 +71,13 @@ if (isset($_POST["Submit3"]) && isset($_POST["problemnumber"]) && is_numeric($_P
document.location='problem.php';
}
}
+ function conf3(url) {
+ if (confirm("Confirm the UNDELETION of the PROBLEM?")) {
+ document.location=url;
+ } else {
+ document.location='problem.php';
+ }
+ }
</script>
<table width="100%" border=1>
<tr>
@@ -89,8 +96,15 @@ if (isset($_POST["Submit3"]) && isset($_POST["problemnumber"]) && is_numeric($_P
for ($i=0; $i<count($prob); $i++) {
echo " <tr>\n";
if($prob[$i]["fake"]!='t') {
- echo " <td nowrap><a href=\"javascript: conf2('problem.php?delete=" . $prob[$i]["number"] . "&input=" . rawurlencode($prob[$i]["inputfilename"]) .
- "')\">" . $prob[$i]["number"] . "</a></td>\n";
+ if(strpos($prob[$i]["fullname"],"(DEL)") !== false) {
+ echo " <td nowrap><a href=\"javascript: conf3('problem.php?delete=" . $prob[$i]["number"] . "&input=" . rawurlencode($prob[$i]["inputfilename"]) .
+ "')\">" . $prob[$i]["number"];
+ echo "(deleted)";
+ } else {
+ echo " <td nowrap><a href=\"javascript: conf2('problem.php?delete=" . $prob[$i]["number"] . "&input=" . rawurlencode($prob[$i]["inputfilename"]) .
+ "')\">" . $prob[$i]["number"];
+ }
+ echo "</a></td>\n";
} else {
echo " <td nowrap>" . $prob[$i]["number"] . " (fake)</td>\n";
}
diff --git a/boca-1.5.0/src/admin/report/piechart.php b/boca-1.5.0/src/admin/report/piechart.php
index 18d8d04..e6dbf95 100644
--- a/boca-1.5.0/src/admin/report/piechart.php
+++ b/boca-1.5.0/src/admin/report/piechart.php
@@ -41,7 +41,12 @@ else
$chart = new PieChart(400, 250);
if(isset($_GET['order'])) $chart->order=true;
+else $chart->order=false;
+$tot=0;
+for($i=1;$i<count($v); $i+=2) {
+ $tot += $v[$i+1];
+}
for($i=1;$i<count($v); $i+=2) {
$color = null;
if($cor != null) {
@@ -50,7 +55,10 @@ for($i=1;$i<count($v); $i+=2) {
$b = hexdec( substr($cor[($i-1)/2], 4, 2) );
$color = array($r, $g, $b);
}
- $chart->addPoint(new Point($v[$i], $v[$i+1], $color));
+ if($v[$i+1] > $tot/100)
+ $chart->addPoint(new Point($v[$i], $v[$i+1], $color));
+ else
+ $chart->addPoint(new Point($v[$i], $tot/100, $color));
}
$chart->setTitle($v[0]);
diff --git a/boca-1.5.0/src/admin/report/stat.php b/boca-1.5.0/src/admin/report/stat.php
index 7d99cb3..1abfa71 100644
--- a/boca-1.5.0/src/admin/report/stat.php
+++ b/boca-1.5.0/src/admin/report/stat.php
@@ -233,7 +233,9 @@ echo "<td>Total</td><td>Accepted</td></tr>\n";
reset($d['username']);
while (list($keya, $vala) = each($d['username'])) {
$keya = $d['username'][$keya];
- $vala = $d['user'][$keya];
+ if(isset($d['user'][$keya]))
+ $vala = $d['user'][$keya];
+ else $vala=0;
echo "<tr><td>".$d['userfull'][$keya]."</td>";
reset($d['problem']);
while (list($key, $val) = each($d['problem'])) {
@@ -289,7 +291,9 @@ while (list($keya, $val) = each($d['timestamp'])) {
$atual += $passo;
$pos++;
}
- $res[$pos]++;
+ if(isset($res[$pos]))
+ $res[$pos]++;
+ else $res[$pos]=1;
if($res[$pos] > $m) $m=$res[$pos];
}
@@ -318,7 +322,9 @@ while (list($keya, $val) = each($d['timestampyes'])) {
$atual += $passo;
$pos++;
}
- $res[$pos]++;
+ if(isset($res[$pos]))
+ $res[$pos]++;
+ else $res[$pos]=1;
}
$str="Accepted Runs by Time Period" . chr(1) . $m;
diff --git a/boca-1.5.0/src/admin/task.php b/boca-1.5.0/src/admin/task.php
index 95aca10..a7a5339 100644
--- a/boca-1.5.0/src/admin/task.php
+++ b/boca-1.5.0/src/admin/task.php
@@ -101,7 +101,7 @@ for ($i=0; $i<count($task); $i++) {
}
echo "</td>\n";
if ($task[$i]["oid"] != null) {
- $msg = $task[$i]["username"]." ".$task[$i]["username"]." ".$task[$i]["username"]." ".
+ $msg = "///// " . $task[$i]["username"]." ".$task[$i]["username"]." ".$task[$i]["username"]." ".
$task[$i]["username"]." ".$task[$i]["username"]." ".$task[$i]["username"];
echo " <td nowrap><a href=\"../filedownload.php?" . filedownload($task[$i]["oid"], $task[$i]["filename"]) . "\">" . $task[$i]["filename"] . "</a>";
echo " <a href=\"#\" class=menu style=\"font-weight:bold\" onClick=\"window.open('../filewindow.php?".
diff --git a/boca-1.5.0/src/admin/user.php b/boca-1.5.0/src/admin/user.php
index 88cc148..5e07930 100644
--- a/boca-1.5.0/src/admin/user.php
+++ b/boca-1.5.0/src/admin/user.php
@@ -37,7 +37,7 @@ if($ct["contestlocalsite"]==$ct["contestmainsite"]) $main=true; else $main=false
if (isset($_POST["username"]) && isset($_POST["userfullname"]) && isset($_POST["userdesc"]) && isset($_POST["userip"]) &&
isset($_POST["usernumber"]) && isset($_POST["usersitenumber"]) && isset($_POST["userenabled"]) && isset($_POST["usericpcid"]) &&
isset($_POST["usermultilogin"]) && isset($_POST["usertype"]) && isset($_POST["confirmation"]) &&
- isset($_POST["passwordn1"]) && isset($_POST["passwordn2"]) && $_POST["confirmation"] == "confirm") {
+ isset($_POST["passwordn1"]) && isset($_POST["passwordn2"]) && isset($_POST["passwordo"]) && $_POST["confirmation"] == "confirm") {
$param['user'] = htmlspecialchars($_POST["usernumber"]);
$param['site'] = htmlspecialchars($_POST["usersitenumber"]);
$param['username'] = htmlspecialchars($_POST["username"]);
@@ -47,13 +47,20 @@ if (isset($_POST["username"]) && isset($_POST["userfullname"]) && isset($_POST["
$param['userfull'] = htmlspecialchars($_POST["userfullname"]);
$param['userdesc'] = htmlspecialchars($_POST["userdesc"]);
$param['type'] = htmlspecialchars($_POST["usertype"]);
- $param['pass'] = htmlspecialchars($_POST["passwordn1"]);
$param['permitip'] = htmlspecialchars($_POST["userip"]);
$param['contest'] = $_SESSION["usertable"]["contestnumber"];
- if ($_POST["passwordn1"] == $_POST["passwordn2"]) {
- DBNewUser($param);
+
+ $passcheck = htmlspecialchars($_POST["passwordo"]);
+ $a = DBUserInfo($_SESSION["usertable"]["contestnumber"], $_SESSION["usertable"]["usersitenumber"], $_SESSION["usertable"]["usernumber"], null, false);
+ if(myhash($a['userpassword'] . session_id()) != $passcheck) {
+ MSGError('Admin password is incorrect');
+ } else {
+ if ($_POST["passwordn1"] == $_POST["passwordn2"]) {
+ $param['pass'] = bighexsub(htmlspecialchars($_POST["passwordn1"]),$a['userpassword']);
+ DBNewUser($param);
+ }
+ else MSGError ("Passwords don't match.");
}
- else MSGError ("Passwords don't match.");
ForceLoad("user.php");
}
else if (isset($_FILES["importfile"]) && isset($_POST["Submit"]) && $_FILES["importfile"]["name"]!="") {
@@ -73,10 +80,10 @@ else if (isset($_FILES["importfile"]) && isset($_POST["Submit"]) && $_FILES["imp
}
$userlist=array();
if(strtolower(substr($name,-4))==".tsv") {
- for ($i=0; $i<count($ar) && strpos($ar[$i], "File_Version\t1") === false; $i++) ;
- if($i >= $count($ar)) MSGError('File format not recognized');
+ for ($i=0; $i < count($ar) && strpos($ar[$i], "File_Version\t1") === false; $i++) ;
+ if($i >= count($ar)) MSGError('File format not recognized');
$oklines=0;
- for ($i++; $i<count($ar); $i++) {
+ for ($i++; $i < count($ar); $i++) {
$x = explode("\t",trim($ar[$i]));
if(count($x)==7) {
$param['site']=trim($x[2]);
@@ -129,9 +136,9 @@ else if (isset($_FILES["importfile"]) && isset($_POST["Submit"]) && $_FILES["imp
}
MSGError($oklines . ' users included/updated successfully');
} else {
- for ($i=0; $i<count($ar) && strpos($ar[$i], "[user]") === false; $i++) ;
- if($i >= $count($ar)) MSGError('File format not recognized');
- for ($i++; $i<count($ar) && $ar[$i][0] != "["; $i++) {
+ for ($i=0; $i < count($ar) && strpos($ar[$i], "[user]") === false; $i++) ;
+ if($i >= count($ar)) MSGError('File format not recognized');
+ for ($i++; $i < count($ar) && $ar[$i][0] != "["; $i++) {
$x = trim($ar[$i]);
if (strpos($x, "user") !== false && strpos($x, "user") == 0) {
$param = array();
@@ -215,7 +222,7 @@ else
<td><b>Description</b></td>
</tr>
<?php
-for ($i=0; $i<count($usr); $i++) {
+for ($i=0; $i < count($usr); $i++) {
echo " <tr>\n";
if(($usr[$i]["usersitenumber"] == $_SESSION["usertable"]["usersitenumber"] || $main==true) &&
//$usr[$i]["usertype"] != 'site' &&
@@ -271,8 +278,11 @@ if (isset($_GET["site"]) && isset($_GET["user"]) && is_numeric($_GET["site"]) &&
<script language="JavaScript">
function computeHASH()
{
- document.form3.passwordn1.value = js_myhash(document.form3.passwordn1.value);
- document.form3.passwordn2.value = js_myhash(document.form3.passwordn2.value);
+ document.form3.passwordn1.value = bighexsoma(js_myhash(document.form3.passwordn1.value),js_myhash(document.form3.passwordo.value));
+ document.form3.passwordn2.value = bighexsoma(js_myhash(document.form3.passwordn2.value),js_myhash(document.form3.passwordo.value));
+ document.form3.passwordo.value = js_myhash(js_myhash(document.form3.passwordo.value)+'<?php echo session_id(); ?>');
+// document.form3.passwordn1.value = js_myhash(document.form3.passwordn1.value);
+// document.form3.passwordn2.value = js_myhash(document.form3.passwordn2.value);
}
</script>
@@ -426,6 +436,12 @@ if (isset($u)) {
<input type="password" name="passwordn2" value="" size="20" maxlength="200" />
</td>
</tr>
+ <tr>
+ <td width="35%" align=right>Admin (this user) Password:</td>
+ <td width="65%">
+ <input type="password" name="passwordo" value="" size="20" maxlength="200" />
+ </td>
+ </tr>
</table>
</center>
<center>
diff --git a/boca-1.5.0/src/db.php b/boca-1.5.0/src/db.php
index da83707..6d437dc 100644
--- a/boca-1.5.0/src/db.php
+++ b/boca-1.5.0/src/db.php
@@ -163,7 +163,8 @@ function DBConnect($forcenew=false) {
"Is it running? Is the DB password in conf.php correct?");
exit;
}
- DBExecNonStop($conn,"SET NAMES '${conf["dbclientenc"]}'","set client encoding");
+ if(isset($conf["dbclientenc"]))
+ DBExecNonStop($conn,"SET NAMES '${conf["dbclientenc"]}'","set client encoding");
return $conn;
}
//fecha a conexao com o banco (isso nao eh realmente necessario, ja que o php/apache cuidam do servico)
@@ -267,7 +268,10 @@ function DBCreateDatabase() {
MSGError("Unable to connect to template1 as ".$conf["dbsuperuser"]);
exit;
}
- $r = DBExec($conn, "create database ${conf["dbname"]} with encoding = '${conf["dbencoding"]}'", "DBCreateDatabase(create)");
+ if(isset($conf["dbencoding"]))
+ $r = DBExec($conn, "create database ${conf["dbname"]} with encoding = '${conf["dbencoding"]}'", "DBCreateDatabase(create)");
+ else
+ $r = DBExec($conn, "create database ${conf["dbname"]} with encoding = 'UTF8'", "DBCreateDatabase(create)");
}
function DBcrc($contest,$id, $c=null) {
diff --git a/boca-1.5.0/src/fcontest.php b/boca-1.5.0/src/fcontest.php
index 9390a31..23ce241 100644
--- a/boca-1.5.0/src/fcontest.php
+++ b/boca-1.5.0/src/fcontest.php
@@ -139,7 +139,7 @@ CREATE TABLE \"usertable\" (
\"usersitenumber\" int4 NOT NULL, -- (id do local do time)
\"usernumber\" int4 NOT NULL, -- (id do usuario)
\"username\" varchar(20) NOT NULL, -- (nome do usuario)
- \"userfullname\" varchar(200) NOT NULL, -- (nome completo do usuario)
+ \"userfullname\" varchar(200) NOT NULL, -- (nome completo do usuario)
\"userdesc\" varchar(300), -- (descricao: escola ou integrantes ou etc)
\"usertype\" varchar(20) NOT NULL, -- (judge, team, admin, system)
\"userenabled\" bool DEFAULT 't' NOT NULL, -- (usuario ativo)
@@ -216,6 +216,11 @@ function DBAllUserInfo($contest,$site=-1) {
$a = array();
for ($i=0;$i<$n;$i++) {
$a[$i] = DBRow($r,$i);
+ $a[$i]['changepassword']=true;
+ if(substr($a[$i]['userpassword'],0,1)=='!') {
+ $a[$i]['userpassword'] = substr($a[$i]['userpassword'],1);
+ $a[$i]['changepassword']=false;
+ }
$a[$i]['userpassword'] = myhash($a[$i]['userpassword'] . $a[$i]['usersessionextra']);
}
return $a;
@@ -245,8 +250,35 @@ function DBUserInfo($contest, $site, $user, $c=null,$hashpass=true) {
LOGError("Unable to find the user in the database. SQL=(" . $sql . ")");
MSGError("Unable to find the user in the database. Contact an admin now!");
}
+ $a['changepassword']=true;
+ if(substr($a['userpassword'],0,1)=='!') {
+ $a['userpassword'] = substr($a['userpassword'],1);
+ $a['changepassword']=false;
+ }
if($hashpass)
$a['userpassword'] = myhash($a['userpassword'] . $a['usersessionextra']);
+ $inst = explode(']',$a['userfullname']);
+ if(isset($inst[1])) {
+ $a['userfullname'] = trim($inst[1]);
+ $inst = explode('[',$inst[0]);
+ if(isset($inst[1]))
+ $a['usershortname'] = trim($inst[1]);
+ }
+ $inst = explode(']',$a['userdesc']);
+ if(isset($inst[1])) {
+ $inst2 = explode('[',$inst[0]);
+ if(isset($inst2[1]))
+ $a['usershortinstitution'] = trim($inst2[0]);
+ if(isset($inst[2])) {
+ $a['userdesc']=trim($inst[2]);
+ $inst = explode('[',$inst[1]);
+ if(isset($inst[1])) {
+ $a['userinstitution'] = trim($inst[1]);
+ }
+ } else {
+ $a['userdesc']=trim($inst[1]);
+ }
+ }
return $a;
}
function DBDeleteUser($contest, $site, $user) {
@@ -322,9 +354,10 @@ function DBSiteLogoffAll($contest, $site) {
LOGLevel("Logoff all (contest=$contest,site=$site).",2);
}
-function DBAllSiteInfo($contest) {
+function DBAllSiteInfo($contest, $c=null) {
$sql = "select * from sitetable where contestnumber=$contest";
- $c = DBConnect();
+ if($c==null)
+ $c = DBConnect();
$r = DBExec ($c, $sql);
$n = DBnlines($r);
if ($n == 0) {
@@ -415,6 +448,7 @@ function DBSiteLogins ($contest, $site, $logins) {
$param['contestnumber']=$contest;
$param['sitenumber']=$site;
$param['sitepermitlogins']=$logins;
+ unset($param['updatetime']);
DBUpdateSite ($param);
LOGLevel("Site logins=$logins (contest=$contest)",2);
}
@@ -634,10 +668,11 @@ function DBUpdateSite ($param,$c=null) {
$sql .= " sitescorelevel=$sitescorelevel where contestnumber=$contestnumber and sitenumber=$sitenumber " .
"and updatetime < $updatetime";
DBExec($c,$sql, "DBUpdateSite(update site)");
- if($docommit)
+ if($docommit) {
DBExec($c, "commit work", "DBUpdateSite(commit-update)");
- LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] .
- " changed the site $sitenumber (contest=$contestnumber) settings.",2);
+ LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] .
+ " changed the site $sitenumber (contest=$contestnumber) settings.",2);
+ }
} else {
if($docommit)
DBExec($c, "commit work", "DBUpdateSite(commit-noupdate)");
@@ -648,7 +683,7 @@ function DBUpdateContest ($param, $c=null) {
if(isset($param['contestnumber']) && !isset($param['number'])) $param['number']=$param['contestnumber'];
$ac=array('number');
- $ac1=array('updatetime','atualizasites','scorelevel','mainsite','localsite','mainsiteurl','keys','unlockkey',
+ $ac1=array('updatetime','atualizasites','scorelevel','mainsite','localsite','mainsiteurl','keys','unlockkey','name',
'active','lastmileanswer','lastmilescore','penalty','startdate', 'duration', 'maxfilesize');
$type['number']=1;
$type['scorelevel']=1;
@@ -721,6 +756,7 @@ function DBUpdateContest ($param, $c=null) {
"DBUpdateContest(active)");
LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] . " activated contest $number.",2);
}
+ $chd=false;
if($updatetime > $a['updatetime']) {
$ret=2;
$sql = "update contesttable set updatetime=".$updatetime;
@@ -769,7 +805,7 @@ function DBUpdateContest ($param, $c=null) {
}
if($atualizasites) {
- $s = DBAllSiteInfo($number);
+ $s = DBAllSiteInfo($number,$c);
for($i=0; $i<count($s); $i++) {
$param = $s[$i];
$param['contestnumber']=$number;
@@ -781,7 +817,7 @@ function DBUpdateContest ($param, $c=null) {
$param['sitelastmileanswer']=$lastmileanswer;
if($lastmilescore > 0)
$param['sitelastmilescore']=$lastmilescore;
-
+ unset($param['updatetime']);
DBUpdateSite ($param,$c);
if($startdate > 0) {
@@ -793,11 +829,13 @@ function DBUpdateContest ($param, $c=null) {
}
}
}
- LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] . " changed the contest $number settings.",2);
+ $chd=true;
}
if($cw) {
DBExec($c, "commit work", "DBUpdateContest(commit)");
}
+ if($chd)
+ LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] . " changed the contest $number settings.",2);
return $ret;
}
function DBRenewSiteTime($param, $c=null) {
@@ -1042,11 +1080,15 @@ function DBUserUpdate($contest, $site, $user, $username, $userfull, $userdesc, $
"tried to change settings, but password was incorrect.",2);
MSGError ("Incorrect password.");
}
- else {
+ else {
+ if(!$a['changepassword']) {
+ MSGError('Password change is DISABLED'); return;
+ }
if ($a["userpassword"] == "") $temp = myhash("");
else $temp = $a["userpassword"];
+ $lentmp = strlen($temp);
$temp = bighexsub($passn, $temp);
- $newpass = substr($temp, strlen($temp)-strlen($myhash), strlen($myhash));
+ $newpass = substr($temp, strlen($temp)-$lentmp);
$c = DBConnect();
DBExec($c, "begin work");
@@ -1163,6 +1205,7 @@ function DBNewUser($param, $c=null) {
MSGError("Site $site does not exist");
return false;
}
+ if($type=='team') $pass='!'.$pass;
$sql = "insert into usertable (contestnumber, usersitenumber, usernumber, username, usericpcid, userfullname, " .
"userdesc, usertype, userenabled, usermultilogin, userpassword, userpermitip) values " .
"($contest, $site, $user, '$username', '$usericpcid', '$userfull', '$userdesc', '$type', '$enabled', " .
diff --git a/boca-1.5.0/src/fproblem.php b/boca-1.5.0/src/fproblem.php
index 42346cb..bbf5758 100644
--- a/boca-1.5.0/src/fproblem.php
+++ b/boca-1.5.0/src/fproblem.php
@@ -111,8 +111,9 @@ function DBGetFullProblemData($contestnumber,$freeproblems=false) {
"p.problemcolor as color, p.problemcolorname as colorname, " .
"p.probleminputfilename as inputfilename, p.probleminputfile as inputoid, p.probleminputfilehash as inputhash " .
" from problemtable as p " .
- "where p.contestnumber=$contestnumber and p.problemfullname !~ '(DEL)' order by p.problemnumber",
+ "where p.contestnumber=$contestnumber order by p.problemnumber",
"DBGetFullProblemData(get problem)");
+ // and p.problemfullname !~ '(DEL)'
$n = DBnlines($r);
if ($n == 0) {
LOGLevel("No problems defined in the database ($contestnumber)",1);
@@ -122,7 +123,10 @@ function DBGetFullProblemData($contestnumber,$freeproblems=false) {
$ds = DIRECTORY_SEPARATOR;
if($ds=="") $ds = "/";
for ($i=0;$i<$n;$i++) {
- $a[$i] = array_merge(array(),DBRow($r,$i));
+ $a[$i] = array_merge(array(),DBRow($r,$i));
+
+ if(strpos($a[$i]['fullname'],'(DEL)') !== false) continue;
+
$nn=$a[$i]['number'];
$ptmp = $_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds . "contest" . $contestnumber ."-problem" . $nn;
$ck = myshorthash('');
@@ -161,7 +165,9 @@ function DBGetFullProblemData($contestnumber,$freeproblems=false) {
$failed=2;
}
if(!$failed) {
- $descfile=trim(sanitizeText($info['descfile']));
+ $descfile='';
+ if(isset($info['descfile']))
+ $descfile=trim(sanitizeText($info['descfile']));
$basename=trim(sanitizeText($info['basename']));
$fullname=trim(sanitizeText($info['fullname']));
if($basename=='' || $fullname=='')
@@ -170,17 +176,23 @@ function DBGetFullProblemData($contestnumber,$freeproblems=false) {
} else $failed=4;
if(!$failed) {
@mkdir($ptmp);
- if($descfile != '')
+ if($descfile != '') {
if(file_put_contents($ptmp . $ds . $descfile, encryptData(file_get_contents($dir . $ds . "description" . $ds . $descfile),$cf['key']),LOCK_EX)===FALSE)
$failed=5;
- if(!$failed) {
- file_put_contents($ptmp . ".name",$ptmp . $ds . $descfile);
- file_put_contents($ptmp . ".hash",$a[$i]['inputhash']);
- if(is_readable($ptmp . ".name")) {
- $a[$i]['descfilename']=trim(file_get_contents($ptmp . ".name"));
- if($a[$i]['descfilename'] != '')
- $a[$i]['descoid']=-1;
+ if(!$failed) {
+ file_put_contents($ptmp . ".name",$ptmp . $ds . $descfile);
+ file_put_contents($ptmp . ".hash",$a[$i]['inputhash']);
+ if(is_readable($ptmp . ".name")) {
+ $a[$i]['descfilename']=trim(file_get_contents($ptmp . ".name"));
+ if($a[$i]['descfilename'] != '')
+ $a[$i]['descoid']=-1;
+ }
}
+ } else {
+ @unlink($ptmp . ".name");
+ @unlink($ptmp . ".hash");
+ }
+ if(!$failed) {
DBExec($c,"update problemtable set problemfullname='$fullname', problembasefilename='$basename' where problemnumber=$nn and contestnumber=$contestnumber",
"DBGetFullProblemData(free problem)");
$a[$i]['basefilename']=$basename;
@@ -233,11 +245,15 @@ function DBDeleteProblem($contestnumber, $param, $c=null) {
$r = DBExec($c, $sql . " for update", "DBDeleteProblem(get for update)");
if(DBnlines($r)>0) {
$a = DBRow($r,0);
- $sql="update problemtable set problemfullname='".$a["problemfullname"] ."(DEL)', updatetime=".time().
- " where contestnumber=$contestnumber and problemnumber=$number ";
+ if(($pos=strpos($a["problemfullname"],"(DEL)")) !== false) {
+ $sql="update problemtable set problemfullname='".substr($a["problemfullname"],0,$pos) ."', updatetime=".time().
+ " where contestnumber=$contestnumber and problemnumber=$number ";
+ } else {
+ $sql="update problemtable set problemfullname='".$a["problemfullname"] ."(DEL)', updatetime=".time().
+ " where contestnumber=$contestnumber and problemnumber=$number ";
+ }
if ($inputfilename != "")
$sql .= " and probleminputfilename='$inputfilename'";
-
$r = DBExec($c, $sql, "DBDeleteLanguage(update)");
$r = DBExec($c,"select runnumber as number, runsitenumber as site from runtable where contestnumber=$contestnumber and runproblem=$number for update");
$n = DBnlines($r);
@@ -248,7 +264,13 @@ function DBDeleteProblem($contestnumber, $param, $c=null) {
}
if($cw)
DBExec($c, "commit", "DBDeleteProblem(commit)");
+ $ds = DIRECTORY_SEPARATOR;
+ if($ds=="") $ds = "/";
+ $ptmp = $_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds . "contest" . $contestnumber ."-problem" . $number;
+ @unlink($ptmp . ".name");
+ @unlink($ptmp . ".hash");
+
LOGLevel("Problem $number (inputfile=$inputfilename) deleted (user=".
$_SESSION["usertable"]["username"]."/".$_SESSION["usertable"]["usersitenumber"] . ")",2);
return true;
@@ -438,7 +460,7 @@ function DBGetProblems($contest,$showanyway=false) {
$ds = DIRECTORY_SEPARATOR;
if($ds=="") $ds = "/";
$nn = $a[$i]['number'];
- $ptmp = $_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds . "contest" . $contestnumber ."-problem" . $nn;
+ $ptmp = $_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds . "contest" . $contest ."-problem" . $nn;
if(is_readable($ptmp . ".name")) {
$a[$i]['descfilename']=trim(file_get_contents($ptmp . ".name"));
if($a[$i]['descfilename'] != '')
diff --git a/boca-1.5.0/src/freport.php b/boca-1.5.0/src/freport.php
index e25bd16..6182d42 100644
--- a/boca-1.5.0/src/freport.php
+++ b/boca-1.5.0/src/freport.php
@@ -69,32 +69,53 @@ function DBRunReport($contest,$site) {
$a = DBRow($r,$i);
$xdados[$i] = $a;
// # of runs by team
- $xuser[$a['user']]++;
+ if(isset($xuser[$a['user']]))
+ $xuser[$a['user']]++;
+ else $xuser[$a['user']]=1;
// # of runs by problem
- $xproblem[$a['problem']]++;
+ if(isset($xproblem[$a['problem']]))
+ $xproblem[$a['problem']]++;
+ else $xproblem[$a['problem']]=1;
if($a['yes'] == 't') {
+ if(isset($xuseryes[$a['user']]))
$xuseryes[$a['user']]++;
+ else $xuseryes[$a['user']]=1;
$xproblemyes[$a['problem']]++;
}
// # of runs by language
- $xlanguage[$a['language']]++;
- if($a['yes'] == 't')
- $xlanguageyes[$a['language']]++;
+ if(isset($xlanguage[$a['language']]))
+ $xlanguage[$a['language']]++;
+ else $xlanguage[$a['language']]=1;
+ if($a['yes'] == 't') {
+ if(isset($xlanguageyes[$a['language']]))
+ $xlanguageyes[$a['language']]++;
+ else $xlanguageyes[$a['language']]=1;
+ }
// # of runs by answer
- $xanswer[$a['answer']]++;
+ if(isset( $xanswer[$a['answer']]))
+ $xanswer[$a['answer']]++;
+ else $xanswer[$a['answer']]=1;
// time of the runs
array_push($xtimestamp, $a['timestamp']);
if($a['yes'] == 't')
array_push($xtimestampyes, $a['timestamp']);
// # of runs by answer by problem
- $xpa[$a['problem']][$a['answer']]++;
+ if(isset($xpa[$a['problem']][$a['answer']]))
+ $xpa[$a['problem']][$a['answer']]++;
+ else $xpa[$a['problem']][$a['answer']]=1;
// # of runs by language by problem
- $xpl[$a['problem']][$a['language']]++;
+ if(isset($xpl[$a['problem']][$a['language']]))
+ $xpl[$a['problem']][$a['language']]++;
+ else $xpl[$a['problem']][$a['language']]=1;
// # of runs by answer by language
- $xla[$a['language']][$a['answer']]++;
+ if(isset($xla[$a['language']][$a['answer']]))
+ $xla[$a['language']][$a['answer']]++;
+ else $xla[$a['language']][$a['answer']]=1;
// # of runs by problem by user
// negative sign means team got an yes for the problem
+ if(!isset($xup[$a['user']][$a['problem']]))
+ $xup[$a['user']][$a['problem']]=0;
if($xup[$a['user']][$a['problem']] < 0)
$xup[$a['user']][$a['problem']]--;
else {
diff --git a/boca-1.5.0/src/frun.php b/boca-1.5.0/src/frun.php
index 3ea398a..97abd1d 100644
--- a/boca-1.5.0/src/frun.php
+++ b/boca-1.5.0/src/frun.php
@@ -727,12 +727,12 @@ function DBNewRun($param,$c=null) {
$b = DBSiteInfo($contest, $site, $c);
$dif = $b["currenttime"];
$rundatediff = $dif;
- if ($dif < 0) {
+ if ($dif < 0) { if(!isset($param['allowneg'])) {
DBExec($c, "rollback work", "DBNewRun(rollback-started)");
LOGError("Tried to submit a run but the contest is not started. SQL=(" . $sql . ")");
MSGError("The contest is not started yet!");
return false;
- }
+ } }
if (!$b["siterunning"]) {
DBExec($c, "rollback work", "DBNewRun(rollback-over)");
LOGError("Tried to submit a run but the contest is over. SQL=(" . $sql . ")");
diff --git a/boca-1.5.0/src/ftask.php b/boca-1.5.0/src/ftask.php
index 8265cc4..86417b2 100644
--- a/boca-1.5.0/src/ftask.php
+++ b/boca-1.5.0/src/ftask.php
@@ -419,13 +419,14 @@ function DBNewTask($param, $c=null) {
"VALUES ($contest, $site, $tasknumber, $user, $taskdate, $taskdatediff, $taskdatediffans, '$filename', $oid, '$status', " .
"'$desc', '$sys', '$color', '$colorname', $updatetime)",
"DBNewTask(insert task)");
+ if($sys=="t") $u="System";
+ else $u = "User $user";
+
if($cw) {
DBExec($c, "commit work", "DBNewTask(commit-insert)");
LOGLevel("$u submitted a task (#$tasknumber) on site #$site " .
"(filename=$filename, contest=$contest).",2);
}
- if($sys=="t") $u="System";
- else $u = "User $user";
$ret=2;
} else {
if($updatetime > $t) {
diff --git a/boca-1.5.0/src/hex.php b/boca-1.5.0/src/hex.php
index ec80230..0d80b1d 100644
--- a/boca-1.5.0/src/hex.php
+++ b/boca-1.5.0/src/hex.php
@@ -104,40 +104,39 @@ function bighexsoma ($hex1, $hex2){
return $resultado;
}
//hex1 e hex2 sao strings hexa
-//devolve a string que representa hex2 - hex1
+//devolve a string que representa hex1 - hex2
function bighexsub ($hex1, $hex2) {
- if (strlen($hex1) == strlen($hex2)) {
- $i=0;
- while ($hex1[$i] == $hex2[$i] && $i<strlen($hex1)) $i++;
-
- if ($i>=strlen($hex1)) return 0;
- if ($hex1[$i] > $hex2[$i]) {
- $sinal='';
- $a = $hex2;
- $hex2 = $hex1;
- $hex1 = $a;
- } else $sinal = '-';
+ $h1 = strlen($hex1);
+ $h2 = strlen($hex2);
+ while ($h1 < $h2) {
+ $hex1 = '0' . $hex1;
+ $h1++;
+ }
+ while ($h2 < $h1) {
+ $hex2 = '0' . $hex2;
+ $h2++;
}
- else {
- if (strlen($hex1) < strlen($hex2)) $sinal='-';
- else {
- $sinal='';
- $a = $hex2;
- $hex2 = $hex1;
- $hex1 = $a;
- }
- while (strlen($hex1) < strlen($hex2))
- $hex1 = '0' . $hex1;
+
+ $i=0;
+ while ($hex1[$i] == $hex2[$i] && $i<$h1) $i++;
+ if ($i>=$h1) return '0';
+
+ if ($hex1[$i] > $hex2[$i]) {
+ $sinal='';
+ } else {
+ $sinal = '-';
+ $a = $hex2;
+ $hex2 = $hex1;
+ $hex1 = $a;
}
$sobra = 0;
$resultado = '';
- for($x = strlen($hex1)-1; $x>=0; $x--){
-
+ for($x = $h1-1; $x>=0; $x--) {
$op1 = (int) hexdec(substr($hex1,$x,1));
$op2 = (int) hexdec(substr($hex2,$x,1));
- $r = $op2 - $op1 - $sobra;
+ $r = $op1 - $op2 - $sobra;
if ($r < 0) {
$r += 16;
$sobra = 1;
diff --git a/boca-1.5.0/src/judge/team.php b/boca-1.5.0/src/judge/team.php
index f00adac..7c204f0 100644
--- a/boca-1.5.0/src/judge/team.php
+++ b/boca-1.5.0/src/judge/team.php
@@ -55,6 +55,7 @@ if (isset($_FILES["sourcefile"]) && isset($_POST["problem"]) && isset($_POST["Su
'lang'=>$lang,
'filename'=>$name,
'filepath'=>$temp);
+ if($runteam=='team.php') $param['allowneg']=1;
DBNewRun ($param);
$_SESSION['forceredo']=true;
}
diff --git a/boca-1.5.0/src/optionlower.php b/boca-1.5.0/src/optionlower.php
index 9c997e3..3bca5f9 100644
--- a/boca-1.5.0/src/optionlower.php
+++ b/boca-1.5.0/src/optionlower.php
@@ -35,13 +35,13 @@ if (isset($_GET["username"]) && isset($_GET["userfullname"]) && isset($_GET["use
$passwordo = myhtmlspecialchars($_GET["passwordo"]);
$passwordn = myhtmlspecialchars($_GET["passwordn"]);
DBUserUpdate($_SESSION["usertable"]["contestnumber"],
- $_SESSION["usertable"]["usersitenumber"],
- $_SESSION["usertable"]["usernumber"],
- $username,
- $userfullname,
- $userdesc,
- $passwordo,
- $passwordn);
+ $_SESSION["usertable"]["usersitenumber"],
+ $_SESSION["usertable"]["usernumber"],
+ $username,
+ $userfullname,
+ $userdesc,
+ $passwordo,
+ $passwordn);
ForceLoad("option.php");
}
@@ -64,9 +64,9 @@ function computeHASH()
passMDo = js_myhash(js_myhash(document.form1.passwordo.value)+'<?php echo session_id(); ?>');
passMDn = bighexsoma(js_myhash(document.form1.passwordn2.value),js_myhash(document.form1.passwordo.value));
- document.form1.passwordo.value = '';
- document.form1.passwordn1.value = '';
- document.form1.passwordn2.value = '';
+ document.form1.passwordo.value = ' ';
+ document.form1.passwordn1.value = ' ';
+ document.form1.passwordn2.value = ' ';
document.location='option.php?username='+username+'&userdesc='+userdesc+'&userfullname='+userfull+'&passwordo='+passMDo+'&passwordn='+passMDn;
}
</script>
diff --git a/boca-1.5.0/src/private/autojudging.php b/boca-1.5.0/src/private/autojudging.php
index d5c49df..79c7079 100755
--- a/boca-1.5.0/src/private/autojudging.php
+++ b/boca-1.5.0/src/private/autojudging.php
@@ -82,12 +82,8 @@ $cf = globalconf();
$ip = $cf["ip"];
$activecontest=DBGetActiveContest();
$prevsleep=0;
-$dodebug=1;
+//$dodebug=1;
while(42) {
-if(!isset($dodebug)) {
- if(isset($dir)) cleardir($dir);
- if(isset($name)) unlink($name);
-}
if(($run = DBGetRunToAutojudging($activecontest["contestnumber"], $ip)) === false) {
if($prevsleep==0)
@@ -99,6 +95,10 @@ if(($run = DBGetRunToAutojudging($activecontest["contestnumber"], $ip)) === fals
$prevsleep=1;
continue;
}
+if(!isset($dodebug)) {
+ if(isset($dir)) cleardir($dir);
+ if(isset($name)) unlink($name);
+}
echo "\n";
flush();
$prevsleep=0;
@@ -162,6 +162,7 @@ if(is_readable($cache . $ds . $run["inputoid"] . "." . $run["inputname"])) {
echo "Getting problem package file from local cache: " . $cache . $ds . $run["inputoid"] . "." . $run["inputname"] . "\n";
$s = file_get_contents($cache . $ds . $run["inputoid"] . "." . $run["inputname"]);
file_put_contents($dir . $ds . $run["inputname"], decryptData($s,$key));
+ $basename=$basenames[$run['inputoid']. "." . $run["inputname"]];
} else {
echo "Downloading problem package file from db into: " . $dir . $ds . $run["inputname"] . "\n";
if(DB_lo_export($contest,$c, $run["inputoid"], $dir . $ds . $run["inputname"]) === false) {
@@ -200,6 +201,7 @@ if(is_readable($cache . $ds . $run["inputoid"] . "." . $run["inputname"])) {
cleardir($dir . $ds . "problemdata");
continue;
}
+ $basenames[$run['inputoid']. "." . $run["inputname"]]=$basename;
if(!is_dir($dir . $ds . "problemdata" . $ds . "limits")) {
echo "Problem content missing (limits) -- please check the problem package\n";
DBGiveUpRunAutojudging($contest, $site, $number, $ip, "Autojuging error: problem package file is invalid");
@@ -247,7 +249,8 @@ if(is_readable($cache . $ds . $run["inputoid"] . "." . $run["inputname"])) {
if(!isset($limits[$basename][$run["extension"]][0]) || !is_numeric($limits[$basename][$run["extension"]][0]) ||
!isset($limits[$basename][$run["extension"]][1]) || !is_numeric($limits[$basename][$run["extension"]][1]) ||
- !isset($limits[$basename][$run["extension"]][2]) || !is_numeric($limits[$basename][$run["extension"]][2]) ) {
+ !isset($limits[$basename][$run["extension"]][2]) || !is_numeric($limits[$basename][$run["extension"]][2]) ||
+ !isset($limits[$basename][$run["extension"]][3]) || !is_numeric($limits[$basename][$run["extension"]][3]) ) {
echo "Failed to find proper limits information for the problem -- please check the problem package\n";
DBGiveUpRunAutojudging($contest, $site, $number, $ip, "Autojuging error: problem package file is invalid");
continue;
@@ -311,7 +314,8 @@ if($retval != 0) {
//# $2 input_file
//# $3 timelimit (limit to run all the repetitions, by default only one repetition)
//# $4 number_of_repetitions_to_run (optional, can be used for better tuning the timelimit)
-//# $5 maximum allowed memory (in KBytes)
+//# $5 maximum allowed memory (in MBytes)
+//# $6 maximum allowed output size (in KBytes)
$zip = new ZipArchive;
$inputlist = array();
@@ -324,7 +328,7 @@ if($retval != 0) {
$pos = strrpos(dirname($filename),"input");
if($pos !== false && $pos==strlen(dirname($filename))-5) {
$inputlist[$ninputlist++] = 'input' . $ds . basename($filename);
- $outputlist[$noutputlist++] = 'output' . $ds . basename($filename);
+ $outputlist[$noutputlist++] = 'output' . $ds . basename($filename,'.link');
}
}
$zip->extractTo($dir, array_merge(array("run" . $ds . $run["extension"]),$inputlist));
@@ -348,15 +352,32 @@ if($retval != 0) {
DBGiveUpRunAutojudging($contest, $site, $number, $ip, "Autojuging error: problem package file is invalid");
continue;
} else {
+ $errp=0;
foreach($inputlist as $file) {
$file = basename($file);
if(is_file($dir . $ds . "input" . $ds . $file)) {
+ $file1=basename($file,'.link');
+ if($file != $file1) {
+ $fnam = trim(file_get_contents($dir . $ds . "input" . $ds . $file));
+ echo "Input file $file is a link. Trying to read the linked file: ($fnam)\n";
+ if(is_readable($fnam)) {
+ @unlink($dir . $ds . "input" . $ds . $file);
+ $file = basename($file,".link");
+ @copy($fnam,$dir . $ds . "input" . $ds . $file);
+ } else {
+ echo "Failed to read input files from link indicated in the ZIP -- please check the problem package\n";
+ DBGiveUpRunAutojudging($contest, $site, $number, $ip, "Autojuging error: problem package file is invalid or missing files on the autojudge");
+ $errp=1; break;
+ }
+ }
+
$ex = escapeshellcmd($script) ." ".
escapeshellarg($basename) . " ".
escapeshellarg($dir . $ds . "input" . $ds . $file)." ".
escapeshellarg(trim($limits[$basename][$run["extension"]][0]))." ".
escapeshellarg(trim($limits[$basename][$run["extension"]][1]))." ".
- escapeshellarg(trim($limits[$basename][$run["extension"]][2]));
+ escapeshellarg(trim($limits[$basename][$run["extension"]][2]))." ".
+ escapeshellarg(trim($limits[$basename][$run["extension"]][3]));
$ex .= " >stdout 2>stderr";
echo "Executing " . $ex . " at " . getcwd() . " for input " . $file . "\n";
if(system($ex, $retval)===false) $retval=-1;
@@ -380,6 +401,7 @@ if($retval != 0) {
echo "==> ERROR reading input file " . $dir . $ds . "input" . $ds . $file . " - skipping it!\n";
}
}
+ if($errp==1) continue;
}
if($retval==0) {
echo "Processing results\n";
@@ -458,8 +480,8 @@ if($retval > 9) {
}
echo "Sending results to server...\n";
-echo "out==> "; system("tail -n1 ". $dir.$ds.'allout');
-echo "err==> "; system("tail -n1 ". $dir.$ds.'allerr');
+//echo "out==> "; system("tail -n1 ". $dir.$ds.'allout');
+//echo "err==> "; system("tail -n1 ". $dir.$ds.'allerr');
DBUpdateRunAutojudging($contest, $site, $number, $ip, $answer, $dir.$ds.'allout', $dir.$ds.'allerr', $retval);
LogLevel("Autojudging: answered '$answer' (run=$number, site=$site, contest=$contest)",3);
echo "Autojudging answered '$answer' (contest=$contest, site=$site, run=$number)\n";
diff --git a/boca-1.5.0/src/private/createproblemzip.php b/boca-1.5.0/src/private/createproblemzip.php
index bbcacf9..a78c30f 100755
--- a/boca-1.5.0/src/private/createproblemzip.php
+++ b/boca-1.5.0/src/private/createproblemzip.php
@@ -24,6 +24,11 @@ if(is_readable('/etc/boca.conf')) {
$pif=parse_ini_file('/etc/boca.conf');
$bocadir = trim($pif['bocadir']) . $ds . 'src';
} else {
+ if(is_readable('boca.conf')) {
+ $pif=parse_ini_file('boca.conf');
+ $bocadir = trim($pif['bocadir']) . $ds . 'src';
+ }
+ else
$bocadir = getcwd();
}
@@ -44,11 +49,12 @@ ini_set('memory_limit','600M');
ini_set('output_buffering','off');
ini_set('implicit_flush','on');
@ob_end_flush();
-
+/*
if(system('test "`id -u`" -eq "0"',$retval)===false || $retval!=0) {
echo "Must be run as root\n";
exit;
}
+*/
if(count($argv) < 3 || !is_readable($argv[1])) {
echo "Usage: createproblemzip.php <problem_directory> <problem_zipfile> [<password>]\n";
exit;
@@ -85,8 +91,13 @@ if(is_dir(trim($argv[1]))) {
else
echo "ZIP Error $ret\n";
$encdata=encryptData(file_get_contents(trim($argv[2])),'#####'.$password1,false);
-} else
+ if($encdata=='')
+ $encdata=file_get_contents(trim($argv[2]));
+} else {
$encdata=encryptData(file_get_contents(trim($argv[1])),'#####'.$password1,true);
+ if($encdata=='')
+ $encdata=file_get_contents(trim($argv[1]));
+}
file_put_contents(trim($argv[2]),$encdata);
echo "Output file generated in " . $argv[2] . "\n";
diff --git a/boca-1.5.0/src/scoretable.php b/boca-1.5.0/src/scoretable.php
index 05b9280..0233e99 100644
--- a/boca-1.5.0/src/scoretable.php
+++ b/boca-1.5.0/src/scoretable.php
@@ -223,6 +223,14 @@ if($redo) {
$score[$e]['classingroup'][$rfi]=$class;
$class++;
}
+ else if(strpos($grname[$k],'/') >= 1) {
+ $u1 = explode('/',$grname[$k]);
+ if(isset($u1[1]) && $score[$e]['user'] >= $u1[0] && $score[$e]['user'] <= $u1[1]) {
+ $score[$e]['classingroup'][$rfi]=$class;
+ $class++;
+ }
+ }
+
}
}
if($class>1)
diff --git a/boca-1.5.0/src/staff/task.php b/boca-1.5.0/src/staff/task.php
index 283b9bb..640eae1 100644
--- a/boca-1.5.0/src/staff/task.php
+++ b/boca-1.5.0/src/staff/task.php
@@ -86,7 +86,7 @@ for ($i=0; $i<count($task); $i++) {
}
echo "</td>\n";
if ($task[$i]["oid"] != null) {
- $msg = $task[$i]["username"]." ".$task[$i]["username"]." ".$task[$i]["username"]." ".
+ $msg = "///// " . $task[$i]["username"]." ".$task[$i]["username"]." ".$task[$i]["username"]." ".
$task[$i]["username"]." ".$task[$i]["username"]." ".$task[$i]["username"];
echo " <td nowrap><a href=\"../filedownload.php?" . filedownload($task[$i]["oid"],$task[$i]["filename"]) .
"\">" . $task[$i]["filename"] . "</a>";
diff --git a/boca-1.5.0/src/team/header.php b/boca-1.5.0/src/team/header.php
index 2690766..ec7352a 100644
--- a/boca-1.5.0/src/team/header.php
+++ b/boca-1.5.0/src/team/header.php
@@ -96,7 +96,7 @@ if(!isset($_SESSION["popuptime"]) || $_SESSION["popuptime"] < time()-120) {
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"]] = "Clarification for problem ".$clar[$i]["problem"]." answered\n";
+ $_SESSION["popups"]['clar' . $i . '-' . $clar[$i]["anstime"]] = "(Clar for problem ".$clar[$i]["problem"]." answered)\n";
}
}
$run = DBUserRuns($_SESSION["usertable"]["contestnumber"],
@@ -106,7 +106,7 @@ if(!isset($_SESSION["popuptime"]) || $_SESSION["popuptime"] < time()-120) {
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';
+ $_SESSION["popups"]['run' . $i . '-' . $run[$i]["anstime"]] = "(Run ".$run[$i]["number"]." result: ".$run[$i]["answer"] . ')\n';
}
}
}
diff --git a/boca-1.5.0/src/webcast.zip b/boca-1.5.0/src/webcast.zip
deleted file mode 100644
index 577ba23..0000000
--- a/boca-1.5.0/src/webcast.zip
+++ /dev/null
Binary files differ
diff --git a/boca-1.5.0/src/webcast/contest/index.php b/boca-1.5.0/src/webcast/contest/index.php
index 8d68f34..3efc719 100644
--- a/boca-1.5.0/src/webcast/contest/index.php
+++ b/boca-1.5.0/src/webcast/contest/index.php
@@ -40,10 +40,14 @@ echo
for ($i = 0; $i < $numTeams; $i++) {
$a = DBRow($r, $i);
$teamID = $a['username'];
- $pieces = explode('</b>', $a['userfullname']);
- $teamName = trim($pieces[1]);
- $pieces = explode('<b>', $pieces[0]);
- $teamUni = trim($pieces[1]);
+ if(isset($a['usershortname']))
+ $teamName = $a['usershortname'];
+ else
+ $teamName = $a['userfullname'];
+ if(isset($a['usershortinstitution']))
+ $teamUni = $a['usershortinstitution'];
+ else
+ $teamUni = $teamName;
echo
$teamID . '' .
@@ -51,4 +55,7 @@ for ($i = 0; $i < $numTeams; $i++) {
$teamName . "\n";
}
+echo '1' . '' . '1' . "\n";
+echo $numProblems . '' . 'Y' . "\n";
+
?>
diff --git a/boca-1.5.0/tools/fcontest.php b/boca-1.5.0/tools/fcontest.php
new file mode 100644
index 0000000..b8f59ca
--- /dev/null
+++ b/boca-1.5.0/tools/fcontest.php
@@ -0,0 +1,1278 @@
+<?php
+////////////////////////////////////////////////////////////////////////////////
+//BOCA Online Contest Administrator
+// Copyright (C) 2003-2012 by BOCA System (bocasystem@gmail.com)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+////////////////////////////////////////////////////////////////////////////////
+//Last updated 10/jul/2012 by cassio@ime.usp.br
+
+function DBDropContestTable() {
+ $c = DBConnect();
+ $r = DBExec($c, "drop table \"contesttable\"", "DBDropContestTable(drop table)");
+}
+function DBCreateContestTable() {
+ $c = DBConnect();
+ $conf = globalconf();
+ if($conf["dbuser"]=="") $conf["dbuser"]="bocauser";
+ $r = DBExec($c, "
+CREATE TABLE \"contesttable\" (
+ \"contestnumber\" int4 NOT NULL, -- (id do concurso)
+ \"contestname\" varchar(100) NOT NULL, -- (nome do concurso)
+ \"conteststartdate\" int4 NOT NULL, -- (dia/horario de inicio)
+ \"contestduration\" int4 NOT NULL, -- (duracao em segundos do contest)
+ \"contestlastmileanswer\" int4, -- (qtd segundos a partir do inicio para nao responder aos times)
+ \"contestlastmilescore\" int4, -- (qtd segundos a partir do inicio para nao atualizar placar)
+ \"contestlocalsite\" int4 NOT NULL, -- (id do site local com relacao a este servidor)
+ \"contestpenalty\" int4 NOT NULL, -- (qtd de segundos perdidos para cada run errada)
+ \"contestmaxfilesize\" int4 NOT NULL, -- (tamanho max em bytes dos codigos que podem ser submetidos)
+ \"contestactive\" bool NOT NULL, -- (indica se o contest esta ativo)
+ \"contestmainsite\" int4 NOT NULL, -- (id do site principal com relacao ao contest)
+ \"contestkeys\" text NOT NULL, -- (list of keys relevant to the contest)
+ \"contestunlockkey\" varchar(100) NOT NULL, -- (key to decrypt problem files)
+ \"contestmainsiteurl\" varchar(200) NOT NULL, -- (id do site principal com relacao ao contest)
+ \"updatetime\" int4 DEFAULT EXTRACT(EPOCH FROM now()) NOT NULL, -- (indica a ultima atualizacao no registro)
+-- (esta tabela eh igual em todos os sites, com excecao do campo contestlocalsite,
+-- que guarda qual o site local. Na verdade a ideia eh que todas as tabelas sejam
+-- iguais em todos os sites.)
+ CONSTRAINT \"contest_pkey\" PRIMARY KEY (\"contestnumber\")
+)", "DBCreateContestTable(create table)");
+ $r = DBExec($c, "REVOKE ALL ON \"contesttable\" FROM PUBLIC", "DBCreateContestTable(revoke public)");
+ $r = DBExec($c, "GRANT ALL ON \"contesttable\" TO \"".$conf["dbuser"]."\"", "DBCreateContestTable(grant bocauser)");
+ $r = DBExec($c, "CREATE UNIQUE INDEX \"contestnumber_index\" ON \"contesttable\" USING btree ".
+ "(\"contestnumber\" int4_ops)", "DBCreateContestTable(create index)");
+}
+function DBDropSiteTable() {
+ $c = DBConnect();
+ $r = DBExec($c, "drop table \"sitetable\"", "DBDropSiteTable(drop table)");
+}
+function DBCreateSiteTable() {
+ $c = DBConnect();
+ $conf = globalconf();
+ if($conf["dbuser"]=="") $conf["dbuser"]="bocauser";
+ $r = DBExec($c, "
+CREATE TABLE \"sitetable\" (
+ \"contestnumber\" int4 NOT NULL, -- (id do concurso)
+ \"sitenumber\" int4 NOT NULL, -- (id do local)
+ \"siteip\" varchar(200) NOT NULL, -- (ip publico do servidor do site)
+ \"sitename\" varchar(50) NOT NULL, -- (nome do local)
+ \"siteactive\" bool NOT NULL, -- (site ativo?)
+ \"sitepermitlogins\" bool NOT NULL, -- (logins estao aceitos?)
+ \"sitelastmileanswer\" int4, -- (hora (em seg do inicio) que este site para de responder aos times)
+ \"sitelastmilescore\" int4, -- (hora (em seg do inicio) que o placar eh congelado neste site)
+ \"siteduration\" int4, -- (tamanho da competicao em segundos)
+ \"siteautoend\" bool, -- (?)
+ \"sitejudging\" text, -- (indica quais sites sao julgados neste site)
+ \"sitetasking\" text, -- (indica quais sites sao processadas as tasks neste site)
+ \"siteglobalscore\" varchar(50) DEFAULT '' NOT NULL, -- (indica se este site deve mostrar placar global)
+ \"sitescorelevel\" int4 DEFAULT 0 NOT NULL, -- (indica o nivel de detalhes do placar exibido aos times)
+ \"sitenextuser\" int4 DEFAULT 0 NOT NULL,
+ \"sitenextclar\" int4 DEFAULT 0 NOT NULL,
+ \"sitenextrun\" int4 DEFAULT 0 NOT NULL,
+ \"sitenexttask\" int4 DEFAULT 0 NOT NULL,
+ \"sitemaxtask\" int4 DEFAULT 8 NOT NULL,
+ \"updatetime\" int4 DEFAULT EXTRACT(EPOCH FROM now()) NOT NULL, -- (indica a ultima atualizacao no registro)
+ \"sitechiefname\" varchar(20) DEFAULT '' NOT NULL, -- (username do juiz chefe, se existir)
+-- (esta tabela contem uma linha para cada site do contest)
+ \"siteautojudge\" bool DEFAULT 'f',
+ \"sitemaxruntime\" int4 DEFAULT 600 NOT NULL,
+ \"sitemaxjudgewaittime\" int4 DEFAULT 900 NOT NULL,
+ CONSTRAINT \"site_pkey\" PRIMARY KEY (\"contestnumber\", \"sitenumber\"),
+ CONSTRAINT \"contest_fk\" FOREIGN KEY (\"contestnumber\") REFERENCES \"contesttable\" (\"contestnumber\")
+ ON DELETE CASCADE ON UPDATE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE
+)", "DBCreateSiteTable(create table)");
+ $r = DBExec($c, "REVOKE ALL ON \"sitetable\" FROM PUBLIC", "DBCreateSiteTable(revoke public)");
+ $r = DBExec($c, "GRANT ALL ON \"sitetable\" TO \"".$conf["dbuser"]."\"", "DBCreateSiteTable(grant bocauser)");
+ $r = DBexec($c, "CREATE UNIQUE INDEX \"site_index\" ON \"sitetable\" USING btree ".
+ "(\"contestnumber\" int4_ops, \"sitenumber\" int4_ops)", "DBCreateSiteTable(create index)");
+}
+function DBDropSiteTimeTable() {
+ $c = DBConnect();
+ $r = DBExec($c, "drop table \"sitetimetable\"", "DBDropSiteTimeTable(drop table)");
+}
+function DBCreateSiteTimeTable() {
+ $c = DBConnect();
+ $conf = globalconf();
+ if($conf["dbuser"]=="") $conf["dbuser"]="bocauser";
+ $r = DBExec($c, "
+CREATE TABLE \"sitetimetable\" (
+ \"contestnumber\" int4 NOT NULL, -- (id do concurso)
+ \"sitenumber\" int4 NOT NULL, -- (id do local)
+ \"sitestartdate\" int4 NOT NULL, -- (hora que o local comecou)
+ \"siteenddate\" int4 NOT NULL, -- (hora que o local deve terminar, zero nao terminado)
+ \"updatetime\" int4 DEFAULT EXTRACT(EPOCH FROM now()) NOT NULL, -- (indica a ultima atualizacao no registro)
+-- (esta tabela contem uma linha para cada reinicio de um site do contest)
+ CONSTRAINT \"sitetime_pkey\" PRIMARY KEY (\"contestnumber\", \"sitenumber\", \"sitestartdate\"),
+ CONSTRAINT \"site_fk\" FOREIGN KEY (\"contestnumber\", \"sitenumber\")
+ REFERENCES \"sitetable\" (\"contestnumber\", \"sitenumber\")
+ ON DELETE CASCADE ON UPDATE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE
+)", "DBCreateSiteTimeTable(create table)");
+ $r = DBExec($c, "REVOKE ALL ON \"sitetimetable\" FROM PUBLIC", "DBCreateSiteTimeTable(revoke public)");
+ $r = DBExec($c, "GRANT ALL ON \"sitetimetable\" TO \"".$conf["dbuser"]."\"", "DBCreateSiteTimeTable(grant bocauser)");
+ $r = DBExec($c, "CREATE UNIQUE INDEX \"sitetime_index\" ON \"sitetimetable\" USING btree ".
+ "(\"contestnumber\" int4_ops, \"sitenumber\" int4_ops, \"sitestartdate\" int4_ops)",
+ "DBCreateSiteTimeTable(create index)");
+ $r = DBexec($c, "CREATE INDEX \"sitetimesite_index\" ON \"sitetimetable\" USING btree ".
+ "(\"contestnumber\" int4_ops, \"sitenumber\" int4_ops)", "DBCreateSiteTimeTable(create site_index)");
+}
+function DBDropUserTable() {
+ $c = DBConnect();
+ $r = DBExec($c, "drop table \"usertable\"", "DBDropUserTable(drop table)");
+}
+function DBCreateUserTable() {
+ $c = DBConnect();
+ $conf = globalconf();
+ if($conf["dbuser"]=="") $conf["dbuser"]="bocauser";
+ $r = DBExec($c, "
+CREATE TABLE \"usertable\" (
+ \"contestnumber\" int4 NOT NULL, -- (id do concurso)
+ \"usersitenumber\" int4 NOT NULL, -- (id do local do time)
+ \"usernumber\" int4 NOT NULL, -- (id do usuario)
+ \"username\" varchar(20) NOT NULL, -- (nome do usuario)
+ \"userfullname\" varchar(200) NOT NULL, -- (nome completo do usuario)
+ \"userdesc\" varchar(300), -- (descricao: escola ou integrantes ou etc)
+ \"usertype\" varchar(20) NOT NULL, -- (judge, team, admin, system)
+ \"userenabled\" bool DEFAULT 't' NOT NULL, -- (usuario ativo)
+ \"usermultilogin\" bool DEFAULT 'f' NOT NULL, -- (usuario pode se logar multiplas vezes)
+ \"userpassword\" varchar(200) DEFAULT '', -- (senha)
+ \"userip\" varchar(300), -- (ip do ult acesso)
+ \"userlastlogin\" int4, -- (data em seg desde epoch do ult login)
+ \"usersession\" varchar(50) DEFAULT '', -- (sessao do usuario)
+ \"usersessionextra\" varchar(50) DEFAULT '', -- (sessao do usuario)
+ \"userlastlogout\" int4, -- (data em seg desde epoch do ult logout)
+ \"userpermitip\" varchar(300), -- (ip permitido para acesso)
+ \"userinfo\" varchar(300) DEFAULT '',
+ \"updatetime\" int4 DEFAULT EXTRACT(EPOCH FROM now()) NOT NULL, -- (indica a ultima atualizacao no registro)
+-- (esta tabela contem uma linha para cada usuario, seja ele administrador, juiz ou time. )
+ \"usericpcid\" varchar(50) DEFAULT '', -- (compatibilidade com dados do ICPC)
+ CONSTRAINT \"user_pkey\" PRIMARY KEY (\"contestnumber\", \"usersitenumber\", \"usernumber\"),
+ CONSTRAINT \"site_fk\" FOREIGN KEY (\"contestnumber\", \"usersitenumber\")
+ REFERENCES \"sitetable\" (\"contestnumber\", \"sitenumber\")
+ ON DELETE CASCADE ON UPDATE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE
+)", "DBCreateUserTable(create table)");
+ $r = DBExec($c, "REVOKE ALL ON \"usertable\" FROM PUBLIC", "DBCreateUserTable(revoke public)");
+ $r = DBExec($c, "GRANT ALL ON \"usertable\" TO \"".$conf["dbuser"]."\"", "DBCreateUserTable(grant bocauser)");
+ $r = DBExec($c, "CREATE UNIQUE INDEX \"user_index\" ON \"usertable\" USING btree ".
+ "(\"contestnumber\" int4_ops, \"usersitenumber\" int4_ops, \"usernumber\" int4_ops)",
+ "DBCreateUserTable(create user_index)");
+ $r = DBExec($c, "CREATE UNIQUE INDEX \"user_index2\" ON \"usertable\" USING btree ".
+ "(\"contestnumber\" int4_ops, \"usersitenumber\" int4_ops, \"username\" varchar_ops)",
+ "DBCreateUserTable(create user_index2)");
+}
+
+//////////////////////////////funcoes de usuarios/sites/contests///////////////////////////////////////
+function DBFakeContest() {
+ $c = DBConnect();
+ DBExec($c, "begin work");
+ DBExec($c, "insert into contesttable (contestnumber, contestname, conteststartdate, contestduration, ".
+ "contestlastmileanswer, contestlastmilescore, contestlocalsite, contestpenalty, contestmaxfilesize, ".
+ "contestactive, contestmainsite, contestmainsiteurl,contestkeys,contestunlockkey) " .
+ "values (0, 'Fake contest (just for initial purposes)', ".
+ "EXTRACT(EPOCH FROM now()), ".
+ "0, 0, 0, 1, 20*60, 100000, 't', 1, '', '', '')", "DBFakeContest(insert contest)");
+
+ DBExec($c, "insert into sitetable (contestnumber, sitenumber, siteip, sitename, siteactive, sitepermitlogins, ".
+ "sitelastmileanswer, sitelastmilescore, siteduration, siteautoend, sitejudging, sitetasking, ".
+ "siteglobalscore, sitescorelevel) ".
+ "values (0, 1, '', 'Fake Site (just for initial purposes)', ".
+ "'t', 't', 0, 0, 1, 't', '1', ".
+ "'1', '0', 4)", "DBFakeContest(insert site)");
+
+ $param['contest']=0;
+ $param['site']=1;
+ $param['start']=1;
+ DBRenewSiteTime($param, $c);
+ $cf = globalconf();
+ $pass = myhash($cf["basepass"]);
+ DBExec($c, "insert into usertable (contestnumber, usersitenumber, usernumber, username, userfullname, ".
+ "userdesc, usertype, userenabled, usermultilogin, userpassword, userip, userlastlogin, usersession, ".
+ "userlastlogout, userpermitip) ".
+ "values (0, 1, 1, 'system', 'Systems', NULL, 'system', 't', ".
+ "'t', '$pass', NULL, NULL, '', NULL, NULL)", "DBFakeContest(insert system user)");
+ DBExec($c, "commit work");
+}
+function DBAllUserInfo($contest,$site=-1) {
+ $sql = "select * from usertable where contestnumber=$contest ";
+ if($site > 0) $sql .= "and usersitenumber=$site ";
+ $sql .= "order by usersitenumber, usernumber";
+ $c = DBConnect();
+ $r = DBExec ($c, $sql, "DBAllUserInfo(get users)");
+ $n = DBnlines($r);
+ if ($n == 0) {
+ LOGError("Unable to find users in the database. SQL=(" . $sql . ")");
+ MSGError("Unable to find users in the database!");
+ }
+
+ $a = array();
+ for ($i=0;$i<$n;$i++) {
+ $a[$i] = DBRow($r,$i);
+ $a[$i]['userpassword'] = myhash($a[$i]['userpassword'] . $a[$i]['usersessionextra']);
+ }
+ return $a;
+}
+function DBAllSiteTime($contest, $site) {
+ $sql = "select * from sitetimetable where contestnumber=$contest and sitenumber=$site order by sitestartdate";
+ $c = DBConnect();
+ $r = DBExec ($c, $sql, "DBAllSiteTime(get times)");
+ $n = DBnlines($r);
+ if ($n == 0) {
+ LOGError("Unable to find Site times in the database. SQL=(" . $sql . ")");
+ MSGError("Unable to find site times in the database!");
+ }
+
+ $a = array();
+ for ($i=0;$i<$n;$i++) {
+ $a[$i] = DBRow($r,$i);
+ }
+
+ return $a;
+}
+function DBUserInfo($contest, $site, $user, $c=null,$hashpass=true) {
+ $sql = "select * from usertable where usernumber=$user and usersitenumber=$site and " .
+ "contestnumber=$contest";
+ $a = DBGetRow ($sql, 0, $c);
+ if ($a == null) {
+ LOGError("Unable to find the user in the database. SQL=(" . $sql . ")");
+ MSGError("Unable to find the user in the database. Contact an admin now!");
+ }
+ $a['changepassword']=true;
+ if(substr($a['userpassword'],0,1)=='!') {
+ $a['userpassword'] = substr($a['userpassword'],1);
+ $a['changepassword']=false;
+ }
+ if($hashpass)
+ $a['userpassword'] = myhash($a['userpassword'] . $a['usersessionextra']);
+ $inst = explode(']',$a['userfullname']);
+ if(isset($inst[1])) {
+ $a['userfullname'] = trim($inst[1]);
+ $inst = explode('[',$inst[0]);
+ if(isset($inst[1]))
+ $a['usershortname'] = trim($inst[1]);
+ }
+ $inst = explode(']',$a['userdesc']);
+ if(isset($inst[1])) {
+ $inst2 = explode('[',$inst[0]);
+ if(isset($inst2[1]))
+ $a['usershortinstitution'] = trim($inst2[0]);
+ if(isset($inst[2])) {
+ $a['userdesc']=trim($inst[2]);
+ $inst = explode('[',$inst[1]);
+ if(isset($inst[1])) {
+ $a['userinstitution'] = trim($inst[1]);
+ }
+ } else {
+ $a['userdesc']=trim($inst[1]);
+ }
+ }
+ return $a;
+}
+function DBDeleteUser($contest, $site, $user) {
+ if ($contest==$_SESSION["usertable"]["contestnumber"] &&
+ $site==$_SESSION["usertable"]["usersitenumber"] &&
+ $user==$_SESSION["usertable"]["usernumber"]) return false;
+ $c = DBConnect();
+ DBExec($c, "begin work");
+ DBExec($c, "lock table usertable");
+ $sql = "select * from usertable where usernumber=$user and usersitenumber=$site and " .
+ "contestnumber=$contest";
+ $a = DBGetRow ($sql, 0);
+ if ($a != null) {
+ $sql = "delete from usertable where usernumber=$user and usersitenumber=$site and " .
+ "contestnumber=$contest";
+ DBExec ($c, $sql);
+ DBExec($c, "commit work");
+ LOGLevel("User $user (site=$site,contest=$contest) removed.", 1);
+ return true;
+ } else {
+ DBExec($c, "rollback work");
+ LOGLevel("User $user (site=$site,contest=$contest) could not be removed.", 1);
+ return false;
+ }
+}
+function DBSiteInfo($contest, $site, $c=null, $msg=true) {
+ $sql = "select * from sitetable where sitenumber=$site and contestnumber=$contest";
+ if($c == null) $c = DBConnect();
+ $r = DBExec($c, $sql);
+ if(DBnLines($r) < 1) {
+ if($msg) {
+ LOGError("Unable to find the site in the database (site=$site, contest=$contest). SQL=(" . $sql . ")");
+ MSGError("Unable to find the site in the database. Contact an admin now!");
+ } else return null;
+ }
+ $a = DBRow($r, 0);
+
+ $sql = "select sitestartdate as s, siteenddate as e from sitetimetable ".
+ "where sitenumber=$site and contestnumber=$contest order by sitestartdate";
+ $r = DBExec($c, $sql);
+ $n = DBnLines($r);
+ $a["currenttime"] = 0;
+ $a["siterunning"] = false;
+ $ti = time();
+ for($i = 0; $i < $n; $i++) {
+ $b = DBRow($r, $i);
+ if($i == 0) $a["sitestartdate"] = $b["s"];
+ if($b["e"] == 0) {
+ $a["siterunning"] = true;
+ $a["currenttime"] += $ti - $b["s"];
+ } else
+ $a["currenttime"] += $b["e"] - $b["s"];
+ $a["siteendeddate"] = $b["e"];
+ }
+ if($a["siteendeddate"] == 0) $a["siteendeddate"] = $ti + $a["siteduration"] - $a["currenttime"];
+ $a["siteautoended"] = false;
+ if($a["siteautoend"] == "t" && $a["currenttime"] >= $a["siteduration"]) {
+ $a["siterunning"] = false;
+ $a["siteautoended"] = true;
+ }
+ return $a;
+}
+function DBSiteLogoffAll($contest, $site) {
+ $c = DBConnect();
+ DBExec($c, "begin work");
+ $r = DBExec($c,"update usertable set usersessionextra='', usersession='', updatetime=".time()." where usertype!='admin' and " .
+ "contestnumber=$contest and usersitenumber=$site");
+ $r = DBExec($c,"update usertable set userlastlogout=".time()." where usertype!='admin' and " .
+ "contestnumber=$contest and usersitenumber=$site and (userlastlogin>userlastlogout or " .
+ "(userlastlogout is null and userlastlogin is not null))");
+ DBExec($c, "commit work");
+
+ LOGLevel("Logoff all (contest=$contest,site=$site).",2);
+}
+
+function DBAllSiteInfo($contest) {
+ $sql = "select * from sitetable where contestnumber=$contest";
+ $c = DBConnect();
+ $r = DBExec ($c, $sql);
+ $n = DBnlines($r);
+ if ($n == 0) {
+ LOGError("Unable to find sites in the database. SQL=(" . $sql . ")");
+ MSGError("Unable to find sites in the database!");
+ }
+ $a = array();
+ for ($i=0;$i<$n;$i++) {
+ $a[$i] = DBRow($r,$i);
+ }
+ return $a;
+}
+function DBAllContestInfo() {
+ $sql = "select * from contesttable";
+ $c = DBConnect();
+ $r = DBExec ($c, $sql);
+ $n = DBnlines($r);
+ if ($n == 0) {
+ LOGError("Unable to find contests in the database. SQL=(" . $sql . ")");
+ MSGError("Unable to find contests in the database!");
+ }
+ $a = array();
+ for ($i=0;$i<$n;$i++) {
+ $a[$i] = DBRow($r,$i);
+ }
+ return $a;
+}
+function DBContestInfo($contest, $c=null) {
+ $sql = "select * from contesttable where contestnumber=$contest";
+ $a = DBGetRow ($sql, 0, $c);
+ if ($a == null) {
+ LOGError("Unable to find the contest $contest in the database. SQL=(" . $sql . ")");
+ MSGError("Unable to find the contest $contest in the database. Contact an admin now!");
+ return null;
+ }
+ return $a;
+}
+function DBGetActiveContest() {
+ $sql = "select * from contesttable where contestactive='t'";
+ $a = DBGetRow ($sql, 0);
+ if ($a == null) {
+ LOGError("Unable to find active contests in the database. SQL=(" . $sql . ")");
+ MSGError("Unable to find active contests in the database.");
+ }
+ return $a;
+}
+function DBSiteStartNow ($contest, $site) {
+ $s = DBSiteInfo($contest, $site);
+ if($s["siterunning"]) return false;
+ $t = time();
+ $c = DBConnect();
+ DBExec($c, "begin work");
+ DBExec($c, "lock table sitetable");
+ DBExec($c, "lock table sitetimetable");
+ DBExec($c, "update sitetimetable set siteenddate=".$s['siteendeddate']." where ".
+ "siteenddate=0 and sitenumber=$site and contestnumber=$contest");
+ DBExec($c, "insert into sitetimetable (contestnumber, sitenumber, sitestartdate, siteenddate) ".
+ "values ($contest, $site, $t, 0)");
+ DBExec($c, "commit work");
+ LOGLevel("Site $site (contest=$contest) started at ".dateconv($t),2);
+ return true;
+}
+function DBSiteEndNow ($contest, $site, $w=0) {
+ $s = DBSiteInfo($contest, $site);
+ if(!$s["siterunning"]) return false;
+ if($w == 0) $t = time();
+ else $t = $w;
+ $c = DBConnect();
+ DBExec($c, "begin work");
+ DBExec($c, "lock table runtable");
+ $a = DBGetRow("select max(rundate) as t from runtable where contestnumber=$contest and ".
+ "runsitenumber=$site and not runstatus ~ 'deleted'", 0);
+ if($a["t"] >= $t) {
+ LOGLevel("Unable to stop a contest before an existing run",2);
+ MSGError("Impossible to stop a contest before an existing run");
+ DBExec($c, "commit work");
+ return false;
+ }
+ DBExec($c, "update sitetimetable set siteenddate=$t, updatetime=".time()." " .
+ "where contestnumber=$contest and sitenumber=$site and siteenddate=0");
+ DBExec($c, "commit work");
+ LOGLevel("Site $site (contest=$contest) stopped at ".dateconv(time()),2);
+ return true;
+}
+function DBSiteLogins ($contest, $site, $logins) {
+ $s = DBSiteInfo($contest, $site);
+ $param = $s;
+ $param['contestnumber']=$contest;
+ $param['sitenumber']=$site;
+ $param['sitepermitlogins']=$logins;
+ DBUpdateSite ($param);
+ LOGLevel("Site logins=$logins (contest=$contest)",2);
+}
+function DBSiteDeleteAllClars ($contest, $site, $user, $usersite, $c=null) {
+ $cw=false;
+ if($c==null) {
+ $cw=true;
+ $c = DBConnect();
+ DBExec($c, "begin work");
+ }
+ DBExec($c, "lock table sitetable");
+ DBExec($c, "lock table clartable");
+ DBExec($c, "select * from sitetable where contestnumber=$contest and sitenumber=$site for update");
+ $r = DBExec($c, "select * from clartable as c where c.contestnumber=$contest and " .
+ "c.clarsitenumber=$site for update");
+ DBExec($c, "delete from clartable where contestnumber=$contest and clarsitenumber=$site");
+ DBExec($c, "update sitetable set sitenextclar=0, updatetime=".time()." " .
+ "where contestnumber=$contest and sitenumber=$site");
+ if($cw) {
+ DBExec($c, "commit work");
+ LOGLevel("All Clarifications deleted (site=$site, contest=$contest, user=$user(site=$usersite)).", 3);
+ }
+ return true;
+}
+function DBSiteDeleteAllTasks ($contest, $site, $user, $usersite,$c=null) {
+ $cw=false;
+ if($c==null) {
+ $cw=true;
+ $c = DBConnect();
+ DBExec($c, "begin work");
+ }
+ DBExec($c, "lock table sitetable");
+ DBExec($c, "lock table tasktable");
+ DBExec($c, "select * from sitetable where contestnumber=$contest and sitenumber=$site for update");
+ $r = DBExec($c, "select * from tasktable as t where t.contestnumber=$contest and " .
+ "t.sitenumber=$site for update");
+ DBExec($c, "delete from tasktable where contestnumber=$contest and sitenumber=$site");
+ DBExec($c, "update sitetable set sitenexttask=0, updatetime=".time()." " .
+ "where contestnumber=$contest and sitenumber=$site");
+ if($cw) {
+ DBExec($c, "commit work");
+ LOGLevel("All Tasks deleted (site=$site, contest=$contest, user=$user(site=$usersite)).", 3);
+ }
+ return true;
+}
+function DBSiteDeleteAllBkps ($contest, $site, $user, $usersite,$c=null) {
+ $cw=false;
+ if($c==null) {
+ $cw=true;
+ $c = DBConnect();
+ DBExec($c, "begin work");
+ }
+ DBExec($c, "lock table bkptable");
+ $r = DBExec($c, "select bkpdata from bkptable where contestnumber=$contest and sitenumber=$site and bkpstatus='active'");
+ $n = DBnlines($r);
+ for ($i=0;$i<$n;$i++) {
+ $a = DBRow($r,$i);
+ DB_lo_unlink($c,$a["bkpdata"]);
+ }
+ DBExec($c, "delete from bkptable where contestnumber=$contest and sitenumber=$site");
+ if($cw) {
+ DBExec($c, "commit work");
+ LOGLevel("All Bkps deleted (site=$site, contest=$contest, user=$user(site=$usersite)).", 3);
+ }
+ return true;
+}
+function DBSiteDeleteAllRuns ($contest, $site, $user, $usersite,$c=null) {
+ $cw=false;
+ if($c==null) {
+ $cw=true;
+ $c = DBConnect();
+ DBExec($c, "begin work");
+ }
+ DBExec($c, "lock table sitetable");
+ DBExec($c, "lock table runtable");
+ DBExec($c, "select * from sitetable where contestnumber=$contest and sitenumber=$site for update");
+ $sql = "select * from runtable as r where r.contestnumber=$contest and " .
+ "r.runsitenumber=$site";
+ $r = DBExec ($c, $sql . " for update");
+ DBExec($c, "delete from runtable where contestnumber=$contest and runsitenumber=$site");
+ DBExec($c, "update sitetable set sitenextrun=0, updatetime=".time()." " .
+ "where contestnumber=$contest and sitenumber=$site");
+ if($cw) {
+ DBExec($c, "commit work");
+ LOGLevel("All Runs deleted (site=$site, contest=$contest, user=$user(site=$usersite)).", 3);
+ }
+ return true;
+}
+function DBUpdateSite ($param,$c=null) {
+ $ac=array('contestnumber','sitenumber','sitename','sitepermitlogins','sitescorelevel');
+ $ac1=array('updatetime','siteautoend','siteglobalscore','siteip','siteactive','siteduration','sitelastmileanswer','sitelastmilescore',
+ 'siteautojudge','sitenextuser','sitenextclar','sitenextrun','sitenexttask','sitemaxtask','sitechiefname','sitejudging','sitetasking');
+
+ if(isset($param['number']) && !isset($param['sitenumber'])) $param['sitenumber']=$param['number'];
+ $type['contestnumber']=1;
+ $type['sitenumber']=1;
+ $type['updatetime']=1;
+ $type['siteduration']=1;
+ $type['sitelastmilescore']=1;
+ $type['sitelastmileanswer']=1;
+ $type['sitenextuser']=1;
+ $type['sitenextclar']=1;
+ $type['sitenextrun']=1;
+ $type['sitenexttask']=1;
+ $type['sitemaxtask']=1;
+ foreach($ac as $key) {
+ if(!isset($param[$key])) {
+ MSGError("DBUpdateSite param error: $key is not set");
+ return false;
+ }
+ $$key = sanitizeText($param[$key]);
+ if(isset($type[$key]) && !is_numeric($param[$key])) {
+ MSGError("DBUpdateSite param error: $key is not numeric");
+ return false;
+ }
+ }
+ $siteduration=-1;
+ $sitelastmileanswer=-1;
+ $sitelastmilescore=-1;
+ $sitenextuser = -1;
+ $sitenextclar = -1;
+ $sitenextrun = -1;
+ $sitenexttask = -1;
+ $sitemaxtask = -1;
+ $sitejudging = '';
+ $sitetasking = '';
+ $sitechiefname = '';
+ $siteip='';
+ $updatetime = -1;
+ $siteautojudge = 'f';
+ $siteautoend='f';
+ $siteglobalscore='';
+ $siteactive='f';
+ foreach($ac1 as $key) {
+ if(isset($param[$key])) {
+ $$key = sanitizeText($param[$key]);
+ if(isset($type[$key]) && !is_numeric($param[$key])) {
+ MSGError("DBUpdateSite param error: $key is not numeric");
+ return false;
+ }
+ }
+ }
+ $t = time();
+ if($updatetime <= 0)
+ $updatetime=$t;
+
+ if ($siteautoend != "t" && $siteautoend != "") $siteautoend = "f";
+ if ($siteactive != "t" && $siteactive != "") $siteactive = "f";
+ if ($siteautojudge != "t" && $siteautojudge != "") $siteautojudge = "f";
+ if ($sitescorelevel == "" || !is_numeric($sitescorelevel)) $sitescorelevel = 0;
+ if ($sitescorelevel < -3) $sitescorelevel = -4;
+ if ($sitescorelevel > 3) $sitescorelevel = 4;
+
+ $docommit=false;
+ if($c==null) {
+ $c = DBConnect();
+ DBExec($c, "begin work", "DBUpdateSite(begin)");
+ $docommit=true;
+ }
+ $a = DBGetRow ("select * from sitetable where contestnumber=$contestnumber and sitenumber=$sitenumber", 0, $c);
+ $ret=1;
+ if ($a == null) {
+ $ret=2;
+ $param['number']=$sitenumber;
+ DBNewSite($contestnumber,$c,$param);
+ $a = DBGetRow ("select * from sitetable where contestnumber=$contestnumber and sitenumber=$sitenumber", 0, $c);
+ if ($a == null) {
+ DBExec($c, "rollback work", "DBUpdateSite(rollback-errorsite)");
+ MSGError("DBUpdateSite update error: impossible to create a site in the DB");
+ LOGLevel("DBUpdateSite update error: impossible to create a site in the DB",0);
+ return false;
+ }
+ }
+ if($updatetime > $a['updatetime']) {
+ $ret=2;
+ if($sitenextrun==0)
+ DBSiteDeleteAllRuns($contestnumber,$sitenumber,$_SESSION["usertable"]["usernumber"],$_SESSION["usertable"]["usersitenumber"],$c);
+ if($sitenextclar==0)
+ DBSiteDeleteAllClars($contestnumber,$sitenumber,$_SESSION["usertable"]["usernumber"],$_SESSION["usertable"]["usersitenumber"],$c);
+ if($sitenexttask==0)
+ DBSiteDeleteAllTasks($contestnumber,$sitenumber,$_SESSION["usertable"]["usernumber"],$_SESSION["usertable"]["usersitenumber"],$c);
+
+ $sql = "update sitetable set sitename='$sitename', updatetime=".$updatetime.", ";
+ if ($sitepermitlogins!="") $sql .= "sitepermitlogins='$sitepermitlogins', ";
+ if ($siteduration > 0)
+ $sql .= "siteduration=$siteduration, ";
+ if($siteip != '')
+ $sql .= "siteip='$siteip',";
+ if($siteautoend != "")
+ $sql .= "siteautoend='$siteautoend', ";
+ if($siteactive != "")
+ $sql .= "siteactive='$siteactive', ";
+ if($siteglobalscore != "")
+ $sql .= "siteglobalscore='$siteglobalscore', ";
+ if($sitenextuser >= 0)
+ $sql .= "sitenextuser=$sitenextuser, ";
+ if($sitenextclar >= 0)
+ $sql .= "sitenextclar=$sitenextclar, ";
+ if($sitenextrun >= 0)
+ $sql .= "sitenextrun=$sitenextrun, ";
+ if($sitenexttask >= 0)
+ $sql .= "sitenexttask=$sitenexttask, ";
+ if($sitemaxtask >= 0)
+ $sql .= "sitemaxtask=$sitemaxtask, ";
+ if($sitechiefname != '')
+ $sql .= "sitechiefname='$sitechiefname', ";
+ if($siteautojudge != '')
+ $sql .= "siteautojudge='$siteautojudge', ";
+ if($sitejudging != '')
+ $sql .= "sitejudging='$sitejudging', ";
+ if($sitetasking != '')
+ $sql .= "sitetasking='$sitetasking', ";
+ if($sitelastmileanswer > 0)
+ $sql .= " sitelastmileanswer=$sitelastmileanswer, ";
+ if($sitelastmilescore > 0)
+ $sql .= " sitelastmilescore=$sitelastmilescore, ";
+ $sql .= " sitescorelevel=$sitescorelevel where contestnumber=$contestnumber and sitenumber=$sitenumber " .
+ "and updatetime < $updatetime";
+ DBExec($c,$sql, "DBUpdateSite(update site)");
+ if($docommit)
+ DBExec($c, "commit work", "DBUpdateSite(commit-update)");
+ LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] .
+ " changed the site $sitenumber (contest=$contestnumber) settings.",2);
+ } else {
+ if($docommit)
+ DBExec($c, "commit work", "DBUpdateSite(commit-noupdate)");
+ }
+ return $ret;
+}
+function DBUpdateContest ($param, $c=null) {
+ if(isset($param['contestnumber']) && !isset($param['number'])) $param['number']=$param['contestnumber'];
+
+ $ac=array('number');
+ $ac1=array('updatetime','atualizasites','scorelevel','mainsite','localsite','mainsiteurl','keys','unlockkey',
+ 'active','lastmileanswer','lastmilescore','penalty','startdate', 'duration', 'maxfilesize');
+ $type['number']=1;
+ $type['scorelevel']=1;
+ $type['startdate']=1;
+ $type['updatetime']=1;
+ $type['duration']=1;
+ $type['penalty']=1;
+ $type['maxfilesize']=1;
+ $type['active']=1;
+ $type['lastmilescore']=1;
+ $type['lastmileanswer']=1;
+ $type['mainsite']=1;
+ $type['localsite']=1;
+ foreach($ac as $key) {
+ if(!isset($param[$key])) {
+ MSGError("DBUpdateContest param error: $key is not set");
+ return false;
+ }
+ $$key = sanitizeText($param[$key]);
+ if(isset($type[$key]) && !is_numeric($param[$key])) {
+ MSGError("DBUpdateContest param error: $key is not numeric");
+ return false;
+ }
+ }
+ $name='';
+ $atualizasites = false;
+ $mainsiteurl='';
+ $keys='';
+ $unlockkey='';
+ $mainsite=-1;
+ $duration=-1;
+ $lastmilescore=-1;
+ $lastmileanswer=-1;
+ $penalty=-1;
+ $maxfilesize=-1;
+ $active=0;
+ $startdate=-1;
+ $localsite=-1;
+ $updatetime=-1;
+ foreach($ac1 as $key) {
+ if(isset($param[$key])) {
+ $$key = sanitizeText($param[$key]);
+ if(isset($type[$key]) && !is_numeric($param[$key])) {
+ MSGError("DBUpdateContest param error: $key is not numeric");
+ return false;
+ }
+ }
+ }
+ $t = time();
+ if($updatetime <= 0)
+ $updatetime=$t;
+
+ $cw = false;
+ if($c == null) {
+ $cw = true;
+ $c = DBConnect();
+ DBExec($c, "begin work", "DBUpdateContest(begin)");
+ }
+ $a = DBGetRow("select * from contesttable where contestnumber=$number for update", 0, $c, "DBUpdateContest(get for update)");
+ if($a == null) {
+ MSGError("Error updating contest $number -- not found");
+ LOGError("DBUpdateContest contest $number not found");
+ return false;
+ }
+ $ret=1;
+ if ($active == 1) {
+ $ret=2;
+ DBExec($c, "update contesttable set contestactive='f'", "DBUpdateContest(deactivate)");
+ DBExec($c, "update contesttable set contestactive='t' where contestnumber=$number",
+ "DBUpdateContest(active)");
+ LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] . " activated contest $number.",2);
+ }
+ if($updatetime > $a['updatetime']) {
+ $ret=2;
+ $sql = "update contesttable set updatetime=".$updatetime;
+ if($name != '') $sql .= ", contestname='$name'";
+ if($maxfilesize > 0) $sql .= ", contestmaxfilesize=$maxfilesize";
+ if($penalty > 0) $sql .= ", contestpenalty=$penalty";
+ if($lastmileanswer > 0) $sql .= ", contestlastmileanswer=$lastmileanswer";
+ if($lastmilescore > 0) $sql .= ", contestlastmilescore=$lastmilescore";
+ if($startdate > 0) $sql .= ", conteststartdate=$startdate";
+ if($duration > 0) $sql .= ", contestduration=$duration";
+ if ($mainsite > 0) $sql .= ", contestmainsite=$mainsite";
+ if ($mainsiteurl != '') $sql .= ", contestmainsiteurl='$mainsiteurl'";
+ if ($unlockkey != '') $sql .= ", contestunlockkey='$unlockkey'";
+ if ($keys != '') $sql .= ", contestkeys='$keys'";
+ if ($localsite > 0) $sql .= ", contestlocalsite=$localsite";
+ $sql .= " where contestnumber=$number";
+ DBExec($c, $sql, "DBUpdateContest(update contest)");
+
+ if($localsite > 0) {
+ $param['contestnumber']=$number;
+ $param['sitename']='Local site';
+ if($duration > 0)
+ $param['siteduration']=$duration;
+ if(isset($param['scorelevel']))
+ $param['sitescorelevel']=$scorelevel;
+ if($lastmileanswer > 0)
+ $param['sitelastmileanswer']=$lastmileanswer;
+ if($lastmilescore > 0)
+ $param['sitelastmilescore']=$lastmilescore;
+ $param['number']=$localsite;
+ DBNewSite ($number,$c,$param);
+ }
+ if($mainsite > 0) {
+ $param['contestnumber']=$number;
+ $param['sitename']='Main site';
+ if($duration > 0)
+ $param['siteduration']=$duration;
+ if(isset($param['scorelevel']))
+ $param['sitescorelevel']=$scorelevel;
+ if($lastmileanswer > 0)
+ $param['sitelastmileanswer']=$lastmileanswer;
+ if($lastmilescore > 0)
+ $param['sitelastmilescore']=$lastmilescore;
+ $param['number']=$mainsite;
+ DBNewSite ($number,$c,$param);
+ }
+
+ if($atualizasites) {
+ $s = DBAllSiteInfo($number);
+ for($i=0; $i<count($s); $i++) {
+ $param = $s[$i];
+ $param['contestnumber']=$number;
+ if($duration > 0)
+ $param['siteduration']=$duration;
+ if(isset($param['scorelevel']))
+ $param['sitescorelevel']=$scorelevel;
+ if($lastmileanswer > 0)
+ $param['sitelastmileanswer']=$lastmileanswer;
+ if($lastmilescore > 0)
+ $param['sitelastmilescore']=$lastmilescore;
+
+ DBUpdateSite ($param,$c);
+
+ if($startdate > 0) {
+ $p=array();
+ $p['contest']=$number;
+ $p['site']=$s[$i]["sitenumber"];
+ $p['start']=$startdate;
+ DBRenewSiteTime($p, $c);
+ }
+ }
+ }
+ LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] . " changed the contest $number settings.",2);
+ }
+ if($cw) {
+ DBExec($c, "commit work", "DBUpdateContest(commit)");
+ }
+ return $ret;
+}
+function DBRenewSiteTime($param, $c=null) {
+ if(!isset($param[0])) {
+ $tmp = $param;
+ $param = array();
+ $param[0] = $tmp;
+ }
+ $ac=array('contest','site','start');
+ $ac1=array('enddate','updatetime');
+ $type['contest']=1;
+ $type['site']=1;
+ $type['start']=1;
+ $type['enddate']=1;
+
+ $t = time();
+ $maxtime = 0;
+ for($i=0; isset($param[$i]); $i++) {
+// LOGLevel(implode(" ",array_keys($param[$i])),2);
+// LOGLevel(implode(" ",$param[$i]),2);
+ if(isset($param[$i]['contestnumber']) && !isset($param[$i]['contest'])) $param[$i]['contest']=$param[$i]['contestnumber'];
+ if(isset($param[$i]['sitenumber']) && !isset($param[$i]['site'])) $param[$i]['site']=$param[$i]['sitenumber'];
+ foreach($ac as $key) {
+ if(!isset($param[$i][$key])) {
+ MSGError("DBRenewSiteTime param error: $key is not set");
+ return false;
+ }
+ if(isset($type[$key]) && !is_numeric($param[$i][$key])) {
+ MSGError("DBRenewSiteTime param error: $key is not numeric");
+ return false;
+ }
+ }
+ foreach($ac1 as $key) {
+ if(isset($param[$i][$key])) {
+ if(isset($type[$key]) && !is_numeric($param[$i][$key])) {
+ MSGError("DBRenewSiteTime param error: $key is not numeric");
+ return false;
+ }
+ }
+ }
+ if(!isset($param[$i]['updatetime'])) $param[$i]['updatetime']=$t;
+ if($param[$i]['updatetime'] > $maxtime) $maxtime = $param[$i]['updatetime'];
+ if(!isset($param[$i]['enddate'])) $param[$i]['enddate']=0;
+
+ if($param[$i]['contest'] != $param[0]['contest'] || $param[$i]['site'] != $param[0]['site']) {
+ MSGError("DBRenewSiteTime param error: contest and site have to match over all instances");
+ return false;
+ }
+ }
+ $cw = false;
+ if($c == null) {
+ $cw = true;
+ $c = DBConnect();
+ DBExec($c, "begin work", "DBRenewSiteTime(begin)");
+ }
+ DBExec($c,"lock table sitetimetable","DBRenewSiteTime(lock)");
+
+ $a = DBGetRow ("select max(updatetime) as maxtime from sitetimetable where contestnumber=". $param[0]['contest'].
+ " and sitenumber=". $param[0]['site'], 0, $c);
+ $ret = 1;
+ if ($a == null || $a['maxtime'] < $maxtime) {
+ DBExec($c, "delete from sitetimetable where contestnumber=" . $param[0]['contest'].
+ " and sitenumber=". $param[0]['site'], "DBRenewSiteTime(delete)");
+ for($i=0; isset($param[$i]); $i++) {
+ DBExec($c, "insert into sitetimetable (contestnumber, sitenumber, sitestartdate, siteenddate, updatetime) ".
+ "values (". $param[0]['contest'].", ". $param[0]['site'].", ".$param[$i]['start'].", ".
+ $param[$i]['enddate'].", ".$param[$i]['updatetime'].")", "DBRenewSiteTime(insert)");
+ }
+ $ret = 2;
+ }
+ if($cw) DBExec($c, "commit work", "DBRenewSiteTime(commit)");
+ return $ret;
+}
+function DBNewContest ($param=array(), $c=null) {
+ $cw = false;
+ if($c == null) {
+ $cw = true;
+ $c = DBConnect();
+ DBExec($c, "begin work", "DBNewContest(begin)");
+ }
+ $a = DBGetRow ("select max(contestnumber) as contest from contesttable", 0, $c,
+ "DBNewContest(max(contest))");
+ if ($a == null) $n=1;
+ else $n = $a["contest"]+1;
+
+ $ac=array('name','startdate','duration','lastmileanswer','lastmilescore','penalty','updatetime','localsite','mainsite','mainsiteurl','keys','unlockkey'); //'active'
+ $type['startdate']=1;
+ $type['duration']=1;
+ $type['lastmileanswer']=1;
+ $type['lastmilescore']=1;
+ $type['penalty']=1;
+ $type['updatetime']=1;
+ $type['mainsite']=1;
+ $type['localsite']=1;
+ $mainsiteurl='';
+ $keys='';
+ $unlockkey='';
+ foreach($ac as $key) {
+ if(isset($param[$key]) && (!isset($type[$key]) || is_numeric($param[$key])))
+ $$key = sanitizeText($param[$key]);
+ else
+ $$key = "";
+ }
+ if($mainsite=="") $mainsite=1;
+ if($localsite=="") $localsite=1;
+ if($name=="") $name="Contest";
+ if($startdate=="") $startdate="EXTRACT(EPOCH FROM now())+600";
+ if($duration=="") $duration=300*60;
+ if($lastmileanswer=="") $lastmileanswer=285*60;
+ if($lastmilescore=="") $lastmilescore=240*60;
+ if($penalty=="") $penalty=20*60;
+ //if($active=="")
+ $active="f";
+ if($updatetime=="") $updatetime=time();
+
+ DBExec($c, "insert into contesttable (contestnumber, contestname, conteststartdate, contestduration, ".
+ "contestlastmileanswer, contestlastmilescore, contestlocalsite, contestpenalty, ".
+ "contestmaxfilesize, contestactive, contestmainsite, contestmainsiteurl,contestkeys,contestunlockkey, updatetime) values ($n, '$name', ".
+ "$startdate, $duration, $lastmileanswer, " .
+ "$lastmilescore, $localsite, $penalty, 100000, '$active', $mainsite, '$mainsiteurl', '$keys','$unlockkey',$updatetime)", "DBNewContest(insert contest)");
+
+ DBNewSite($n, $c, $param);
+
+ insertanswers($n,$c);
+ insertlanguages($n,$c);
+ DBinsertfakeproblem($n,$c);
+
+ if($cw) {
+ DBExec($c, "commit work", "DBNewContest(commit)");
+ }
+ LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] . " created a new contest ($n).",2);
+ return $n;
+}
+function insertlanguages($n,$c=null) {
+ $ok=false;
+ $param=null;
+ $param['number']=1;
+ $param['name']='C';
+ $param['extension']='c';
+ DBNewLanguage($n, $param, $c);
+ $param['number']=2;
+ $param['name']='C++';
+ $param['extension']='cpp';
+ DBNewLanguage($n, $param, $c);
+ $param['number']=3;
+ $param['name']='Java';
+ $param['extension']='java';
+ DBNewLanguage($n, $param, $c);
+}
+function insertanswers($n,$c) {
+ DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, fake) values ".
+ "($n, 0, 'Not answered yet', 'f', 't')", "DBNewContest(insert fake answer)");
+ DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, fake) values ".
+ "($n, 1, 'YES', 't', 'f')", "DBNewContest(insert YES answer)");
+ DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, fake) values ".
+ "($n, 2, 'NO - Compilation error', 'f', 'f')", "DBNewContest(insert CE answer)");
+ DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, fake) values ".
+ "($n, 3, 'NO - Runtime error', 'f', 'f')", "DBNewContest(insert RE answer)");
+ DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, fake) values ".
+ "($n, 4, 'NO - Time limit exceeded', 'f', 'f')", "DBNewContest(insert TLE answer)");
+ DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, fake) values ".
+ "($n, 5, 'NO - Presentation error', 'f', 'f')", "DBNewContest(insert PE answer)");
+ DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, fake) values ".
+ "($n, 6, 'NO - Wrong answer', 'f', 'f')", "DBNewContest(insert WA answer)");
+ DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, fake) values ".
+ "($n, 7, 'NO - If possible, contact staff', 'f', 'f')", "DBNewContest(insert CS answer)");
+}
+function DBNewSite ($contest, $c=null, $param=array()) {
+ $cw = false;
+ if($c == null) {
+ $cw = true;
+ $c = DBConnect();
+ DBExec($c, "begin work");
+ }
+ $ct = DBContestInfo ($contest, $c);
+ if($ct==null) return false;
+
+ if(isset($param['sitenumber']) && !isset($param['number'])) $param['number']=$param['sitenumber'];
+ $ac=array('number','siteip','sitename','sitescorelevel','updatetime','startdate','duration');
+ $type=array();
+ $type['startdate']=1;
+ $type['duration']=1;
+ $type['number']=1;
+ $type['sitescorelevel']=1;
+ $type['updatetime']=1;
+ foreach($ac as $key) {
+ if(isset($param[$key]) && (!isset($type[$key]) || is_numeric($param[$key])))
+ $$key = sanitizeText($param[$key]);
+ else
+ $$key = "";
+ }
+
+ if($number=="") {
+ $a = DBGetRow ("select max(sitenumber) as site from sitetable where contestnumber=$contest", 0, $c);
+ if ($a == null) $n=1;
+ else $n = $a["site"]+1;
+ $number=$n;
+ } else {
+ $a = DBGetRow ("select * from sitetable where contestnumber=$contest and sitenumber=$number", 0, $c);
+ if($a != null) return 1;
+ }
+ if($duration=='') $duration = $ct["contestduration"];
+ if($startdate=='') $startdate=$ct["conteststartdate"];
+ if($siteip=="") $siteip="127.0.0.1/boca";
+ if($sitename=="") $sitename="Site";
+ if($sitescorelevel=="") $sitescorelevel=3;
+ $t=time();
+ if($updatetime=="") $updatetime=$t;
+ DBExec($c, "insert into sitetable (contestnumber, sitenumber, siteip, sitename, siteactive, sitepermitlogins, ".
+ "sitelastmileanswer, sitelastmilescore, siteduration, siteautoend, sitejudging, sitetasking, ".
+ "siteglobalscore, sitescorelevel, ".
+ "sitenextuser, sitenextclar, sitenextrun, sitenexttask, sitemaxtask, updatetime) values ".
+ "($contest, $number, '$siteip', '$sitename', 't', 't', ".
+ $ct["contestlastmileanswer"].",".$ct["contestlastmilescore"].
+ ", $duration, 't', '$number', '$number', '$number', $sitescorelevel, 0, 0, 0, 0, 10, $updatetime)");
+
+ $cf=globalconf();
+ $admpass = myhash($cf["basepass"]);
+
+ DBExec($c, "insert into usertable ".
+ "(contestnumber, usersitenumber, usernumber, username, userfullname, " .
+ "userdesc, usertype, userenabled, usermultilogin, userpassword, userip, userlastlogin, ".
+ "usersession, usersessionextra, userlastlogout, userpermitip, updatetime) values " .
+ "($contest, $number, 1000, 'admin', 'Administrator', NULL, 'admin', ".
+ "'t', 't', '$admpass', NULL, NULL, '', '', NULL, NULL, $updatetime)");
+ $param=array();
+ $param['contest']=$contest;
+ $param['site']=$number;
+ $param['start']=$startdate;
+ DBRenewSiteTime($param, $c);
+ if($cw) DBExec($c, "commit work");
+ LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] .
+ " created site $number on contest $contest.",2);
+ return 2;
+}
+
+function DBUserUpdate($contest, $site, $user, $username, $userfull, $userdesc, $passo, $passn) {
+ $a = DBUserInfo($contest, $site, $user, null, false);
+ $p = myhash($a["userpassword"] . session_id());
+ if ($a["userpassword"] != "" && $p != $passo) {
+ LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] . " (contest=$contest, site=$site) " .
+ "tried to change settings, but password was incorrect.",2);
+ MSGError ("Incorrect password.");
+ }
+ else {
+ if($a['userpassword']
+ MSGError('Password change is DISABLED'); return;
+
+ if ($a["userpassword"] == "") $temp = myhash("");
+ else $temp = $a["userpassword"];
+ $lentmp = strlen($temp);
+ $temp = bighexsub($passn, $temp);
+ $newpass = substr($temp, strlen($temp)-$lentmp);
+
+ $c = DBConnect();
+ DBExec($c, "begin work");
+ DBExec($c, "lock table usertable");
+ $r = DBExec($c, "select * from usertable where username='$username' and usernumber!=$user and ".
+ "usersitenumber=$site and contestnumber=$contest");
+ $n = DBnlines ($r);
+ if ($n == 0) {
+ $sql = "update usertable set username='$username', userdesc='$userdesc', userfullname='$userfull', updatetime=".time();
+ if ($newpass != myhash("")) $sql .= ", userpassword='$newpass'";
+ $sql .= " where usernumber=$user and usersitenumber=$site and contestnumber=$contest";
+ $r = DBExec ($c, $sql);
+ DBExec ($c, "commit work");
+ LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] . " changed his settings (newname=$username) ".
+ "(user=$user,site=$site,contest=$contest)",2);
+ MSGError("Data updated.");
+ ForceLoad("index.php");
+ } else {
+ DBExec ($c, "rollback work");
+ LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] . " couldn't change his settings " .
+ "(user=$user,site=$site,contest=$contest)",2);
+ MSGError ("Update problem (maybe username already in use). No data was changed.");
+ }
+ }
+}
+
+function DBNewUser($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['user'])) $param['user']=$param['number'];
+
+ $ac=array('contest','site','user');
+ $ac1=array('updatetime','username','usericpcid','userfull','userdesc','type','enabled','multilogin','pass','permitip',
+ 'userip','userlastlogin','userlastlogout','usersession','usersessionextra');
+
+ $typei['contest']=1;
+ $typei['updatetime']=1;
+ $typei['site']=1;
+ $typei['user']=1;
+ foreach($ac as $key) {
+ if(!isset($param[$key]) || $param[$key]=="") {
+ MSGError("DBNewUser param error: $key not found");
+ return false;
+ }
+ if(isset($typei[$key]) && !is_numeric($param[$key])) {
+ MSGError("DBNewUser param error: $key is not numeric");
+ return false;
+ }
+ $$key = sanitizeText($param[$key]);
+ }
+ $username= "team" . $user;
+ $updatetime=-1;
+ $pass = null;
+ $usericpcid='';
+ $userfull='';
+ $userdesc='';
+ $type='team';
+ $enabled='f';
+ $multilogin='f';
+ $permitip='';
+ $usersession=null;
+ $usersessionextra=null;
+ $userip=null;
+ $userlastlogin=null;
+ $userlastlogout=null;
+ foreach($ac1 as $key) {
+ if(isset($param[$key])) {
+ $$key = sanitizeText($param[$key]);
+ if(isset($typei[$key]) && !is_numeric($param[$key])) {
+ MSGError("DBNewUser param error: $key is not numeric");
+ return false;
+ }
+ }
+ }
+ $t = time();
+ if($updatetime <= 0)
+ $updatetime=$t;
+
+ if ($type != "chief" && $type != "judge" && $type != "admin" &&
+ $type != "score" && $type != "staff" && $type != "site")
+ $type = "team";
+ if ($enabled != "f") $enabled = "t";
+ if ($multilogin != "t") $multilogin = "f";
+
+ $cw = false;
+ if($c == null) {
+ $cw = true;
+ $c = DBConnect();
+ DBExec($c, "begin work", "DBNewUser(begin)");
+ }
+ DBExec($c, "lock table usertable", "DBNewUser(lock)");
+ $r = DBExec($c, "select * from sitetable where sitenumber=$site and contestnumber=$contest", "DBNewUser(get site)");
+ $n = DBnlines ($r);
+ if($n == 0) {
+ DBExec ($c, "rollback work","DBNewUser(no-site)");
+ MSGError("DBNewUser param error: site $site does not exist");
+ return false;
+ }
+ $r = DBExec($c, "select * from usertable where username='$username' and usernumber!=$user and ".
+ "usersitenumber=$site and contestnumber=$contest", "DBNewUser(get user)");
+ $n = DBnlines ($r);
+ $ret=1;
+ if ($n == 0) {
+ $sql = "select * from usertable where usernumber=$user and usersitenumber=$site and " .
+ "contestnumber=$contest";
+ $a = DBGetRow ($sql, 0, $c);
+ if ($a == null) {
+ $ret=2;
+ $sql = "select * from sitetable where sitenumber=$site and contestnumber=$contest";
+ $aa = DBGetRow ($sql, 0);
+ if($aa==null) {
+ DBExec ($c, "rollback work");
+ MSGError("Site $site does not exist");
+ return false;
+ }
+ $sql = "insert into usertable (contestnumber, usersitenumber, usernumber, username, usericpcid, userfullname, " .
+ "userdesc, usertype, userenabled, usermultilogin, userpassword, userpermitip) values " .
+ "($contest, $site, $user, '$username', '$usericpcid', '$userfull', '$userdesc', '$type', '$enabled', " .
+ "'$multilogin', '$pass', '$permitip')";
+ DBExec ($c, $sql, "DBNewUser(insert)");
+ if($cw) {
+ DBExec ($c, "commit work");
+ }
+ LOGLevel ("User $user (site=$site,contest=$contest) included.",2);
+ } else {
+ if($updatetime > $a['updatetime']) {
+ $ret=2;
+ $sql = "update usertable set username='$username', usericpcid='$usericpcid', userdesc='$userdesc', updatetime=$updatetime, " .
+ "userfullname='$userfull', usertype='$type', userpermitip='$permitip', ";
+ if($pass != null && $pass != myhash("")) $sql .= "userpassword='$pass', ";
+ if($usersession != null) $sql .= "usersession='$usersession', ";
+ if($usersessionextra != null) $sql .= "usersessionextra='$usersessionextra', ";
+ if($userip != null) $sql .= "userip='$userip', ";
+ if($userlastlogin != null) $sql .= "userlastlogin='$userlastlogin', ";
+ if($userlastlogout != null) $sql .= "userlastlogout='$userlastlogout', ";
+ $sql .= "userenabled='$enabled', usermultilogin='$multilogin'";
+ $sql .= " where usernumber=$user and usersitenumber=$site and contestnumber=$contest";
+ $r = DBExec ($c, $sql, "DBNewUser(update)");
+ if($cw) {
+ DBExec ($c, "commit work");
+ }
+ LOGLevel("User $user (username=$username,site=$site,contest=$contest) updated.",2);
+ }
+ }
+ } else {
+ DBExec ($c, "rollback work");
+ LOGLevel ("Update problem for user $user (site=$site,contest=$contest) (maybe username already in use).",1);
+ MSGError ("Update problem for user $user, site $site (maybe username already in use).");
+ return false;
+ }
+ return $ret;
+}
+
+function siteclock() {
+ if (($s=DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null)
+ ForceLoad("../index.php");
+
+ 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("&gt; ". $t . " hour(s) to start",$s["currenttime"]);
+ }
+ if ($t>60) {
+ $t = (int) ($t/60);
+ return array("&gt; ". $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);
+}
+// eof
+?>
diff --git a/boca-1.5.0/tools/icpc.etc.tgz b/boca-1.5.0/tools/icpc.etc.tgz
index 5c57681..39a0ab9 100644
--- a/boca-1.5.0/tools/icpc.etc.tgz
+++ b/boca-1.5.0/tools/icpc.etc.tgz
Binary files differ