aboutsummaryrefslogtreecommitdiffstats
path: root/toj/php
diff options
context:
space:
mode:
authorpzread <netfirewall@gmail.com>2013-04-21 15:33:11 +0800
committerpzread <netfirewall@gmail.com>2013-04-21 15:33:11 +0800
commitd8ba93f32ca6bf5f412a07756b6443595c7bfda8 (patch)
tree113591dd33a88331eab038b76e05fee4cca804c7 /toj/php
parent567ecd63584b5fac473e23502f0747aa1f7e97d8 (diff)
downloadtaiwan-online-judge-d8ba93f32ca6bf5f412a07756b6443595c7bfda8.tar
taiwan-online-judge-d8ba93f32ca6bf5f412a07756b6443595c7bfda8.tar.gz
taiwan-online-judge-d8ba93f32ca6bf5f412a07756b6443595c7bfda8.tar.bz2
taiwan-online-judge-d8ba93f32ca6bf5f412a07756b6443595c7bfda8.tar.lz
taiwan-online-judge-d8ba93f32ca6bf5f412a07756b6443595c7bfda8.tar.xz
taiwan-online-judge-d8ba93f32ca6bf5f412a07756b6443595c7bfda8.tar.zst
taiwan-online-judge-d8ba93f32ca6bf5f412a07756b6443595c7bfda8.zip
Use php.ini define include path. Add base personal statistic. Fix some bugs. Improve square event. Add contest sqmod
Diffstat (limited to 'toj/php')
-rwxr-xr-xtoj/php/common.inc.php3
-rwxr-xr-xtoj/php/sqlib_scoreboard.inc.php6
-rwxr-xr-xtoj/php/square.inc.php14
-rwxr-xr-xtoj/php/square.php24
-rwxr-xr-xtoj/php/status.inc.php10
-rwxr-xr-xtoj/php/user.inc.php51
-rwxr-xr-xtoj/php/user.php7
7 files changed, 102 insertions, 13 deletions
diff --git a/toj/php/common.inc.php b/toj/php/common.inc.php
index 0922c91..18786e9 100755
--- a/toj/php/common.inc.php
+++ b/toj/php/common.inc.php
@@ -2,7 +2,10 @@
date_default_timezone_set('Asia/Taipei');
//error_reporting(E_ALL ^ E_NOTICE);
+//ini_set("display_errors", "On");
+
//error_reporting(0);
+//
require('connect.inc.php');
diff --git a/toj/php/sqlib_scoreboard.inc.php b/toj/php/sqlib_scoreboard.inc.php
index e5e7d66..32bec44 100755
--- a/toj/php/sqlib_scoreboard.inc.php
+++ b/toj/php/sqlib_scoreboard.inc.php
@@ -71,14 +71,14 @@
sqlib_scoreboard::update($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time);
//display
- $sqlstr = 'SELECT "a1"."uid", "a1"."rank_score", COUNT(*) AS "rank" FROM "sqlib_scoreboard_main" "a1", "sqlib_scoreboard_main" "a2" WHERE "a1"."sqid"=$1 AND "a1"."sboard_id"=$2 AND "a2"."sqid"=$1 AND "a2"."sboard_id"=$2 AND ("a2"."rank_score">"a1"."rank_score" OR "a2"."uid"="a1"."uid") GROUP BY "a1"."uid", "a1"."rank_score" ORDER BY "a1"."rank_score" DESC, "a1"."uid" LIMIT $4 OFFSET $3;';
- $sqlarr = array($sqid, $sboard_id, $start_offset-1, $number);
+ $sqlstr = 'SELECT "a1"."uid", "a1"."rank_score", COUNT(*) AS "rank" FROM "sqlib_scoreboard_main" "a1", "sqlib_scoreboard_main" "a2" WHERE "a1"."sqid"=$1 AND "a1"."sboard_id"=$2 AND "a2"."sqid"=$1 AND "a2"."sboard_id"=$2 AND ("a2"."rank_score">"a1"."rank_score" OR "a2"."uid"="a1"."uid") GROUP BY "a1"."uid", "a1"."rank_score" ORDER BY "a1"."rank_score" DESC, "a1"."uid" LIMIT $4 OFFSET $3;';
+ $sqlarr = array($sqid, $sboard_id, $start_offset, $number);
if($uid)
{
$sqlstr = 'SELECT "a1"."uid", "a1"."rank_score", COUNT(*) AS "rank" FROM "sqlib_scoreboard_main" "a1", "sqlib_scoreboard_main" "a2" WHERE "a1"."sqid"=$1 AND "a1"."sboard_id"=$2 AND "a1"."uid"=$3 AND "a2"."sqid"=$1 AND "a2"."sboard_id"=$2 AND ("a2"."rank_score">"a1"."rank_score" OR "a2"."uid"="a1"."uid") GROUP BY "a1"."uid", "a1"."rank_score";';
$sqlarr = array($sqid, $sboard_id, $uid);
}
-
+
$res = pg_query_params($msqlc, $sqlstr, $sqlarr);
$arr = pg_fetch_all($res);
diff --git a/toj/php/square.inc.php b/toj/php/square.inc.php
index 4a4b52f..99f0d2e 100755
--- a/toj/php/square.inc.php
+++ b/toj/php/square.inc.php
@@ -226,6 +226,20 @@ class square
}
return $ret;
}
+ public static function get_user_list($sqlc, $sqid)
+ {
+ //get problem list of square $sqid.
+ $sqlstr = 'SELECT "user"."uid", "user"."nickname" FROM "user" INNER JOIN "us_sq" ON "user"."uid"="us_sq"."uid" WHERE "us_sq"."sqid"=$1 ORDER BY "user"."uid";';
+ $sqlarr = array($sqid);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = array();
+ while($obj = pg_fetch_object($sqlr))
+ {
+ $obj->uid = intval($obj->uid);
+ array_push($ret, $obj);
+ }
+ return $ret;
+ }
}
?>
diff --git a/toj/php/square.php b/toj/php/square.php
index c95c584..fb87741 100755
--- a/toj/php/square.php
+++ b/toj/php/square.php
@@ -2,6 +2,7 @@
//ini_set("display_errors", "On");
require_once('square.inc.php');
+require_once('event.inc.php');
$sqlc = db_connect();
@@ -44,6 +45,9 @@ if($action == 'add_sq')
if(!$res2)
die('Eadd_admin_failed');
+ if(event::exec_func('../sqmod/'.$sq->sqmodname.'/'.$sq->sqmodname.'.inc.php','event_create',[$res->sqid]) === false)
+ die('Eevent_error');
+
echo('S');
}
if($action == 'delete_sq')
@@ -59,13 +63,17 @@ if($action == 'delete_sq')
die('Epermission_denied');
$sqid = intval($sq->sqid);
- if(!square::get($sqlc, $sqid))
- die('Eno_such_sq');
+ $sq = square::get($sqlc, $sqid);
+ if(!$sq)
+ die('Ewrong_sqid');
$res = square::del($sqlc, $sqid);
if(!$res)
die('Edelete_failed');
+ if(event::exec_func('../sqmod/'.$sq->sqmodname.'/'.$sq->sqmodname.'.inc.php','event_destroy',[$sq->sqid]) === false)
+ die('Eevent_error');
+
echo('S');
}
if($action == 'edit_sq')
@@ -313,7 +321,8 @@ if($action == 'add_pro_into_sq')
if(!problem::is_available($sqlc, $dt->proid))
die('Ewrong_proid');
- if(!square::get($sqlc, $dt->sqid))
+ $sq = square::get($sqlc, $dt->sqid);
+ if(!$sq)
die('Ewrong_sqid');
$adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) || square::get_user_relationship($sqlc, $uid, $dt->sqid) >= SQUARE_USER_ADMIN;
@@ -328,6 +337,9 @@ if($action == 'add_pro_into_sq')
if(!$ret)
die('Eadd_problem_into_square_failed');
+ if(event::exec_func('../sqmod/'.$sq->sqmodname.'/'.$sq->sqmodname.'.inc.php','event_add_pro',[$sq->sqid, $dt->proid]) === false)
+ die('Eevent_error');
+
echo('S');
}
if($action == 'delete_pro_from_sq')
@@ -343,7 +355,8 @@ if($action == 'delete_pro_from_sq')
$dt = json_decode($data);
- if(!square::get($sqlc, $dt->sqid))
+ $sq = square::get($sqlc, $dt->sqid);
+ if(!$sq)
die('Ewrong_sqid');
$adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) || square::get_user_relationship($sqlc, $uid, $dt->sqid) >= SQUARE_USER_ADMIN;
@@ -358,6 +371,9 @@ if($action == 'delete_pro_from_sq')
if(!$ret)
die('Edelete_problem_from_square_failed');
+ if(event::exec_func('../sqmod/'.$sq->sqmodname.'/'.$sq->sqmodname.'.inc.php','event_del_pro',[$sq->sqid, $dt->proid]) === false)
+ die('Eevent_error');
+
echo('S');
}
diff --git a/toj/php/status.inc.php b/toj/php/status.inc.php
index adc749f..f0ad3da 100755
--- a/toj/php/status.inc.php
+++ b/toj/php/status.inc.php
@@ -33,31 +33,31 @@ class status
{
$condstr = $condstr.'"submit"."uid"='.pg_escape_string($filter->uid).' AND ';
}
- if($filter->result != null)
+ if($filter->result !== null)
{
$condstr = $condstr.'"result"='.pg_escape_string($filter->result).' AND ';
}
if($filter->proid != null)
{
- $condstr = $condstr.'"proid"='.pg_escape_string($filter->proid).' AND ';
+ $condstr = $condstr.'"submit"."proid"='.pg_escape_string($filter->proid).' AND ';
}
if($filter->lang != null)
{
$condstr = $condstr.'"lang"='.pg_escape_string($filter->lang).' AND ';
}
- if($sort->score != null)
+ if($sort->score !== null)
{
$relstr = $sort->score[0]==0 ? '<=' : '>=';
$condstr = $condstr.'"score"'.$relstr.pg_escape_string($sort->score[1]).' AND ';
$ordstr = $ordstr.'"score" '.($sort->score[0]==0 ? 'DESC' : 'ASC').' ,';
}
- if($sort->runtime != null)
+ if($sort->runtime !== null)
{
$relstr = $sort->runtime[0]==0 ? '<=' : '>=';
$condstr = $condstr.'"runtime"'.$relstr.pg_escape_string($sort->runtime[1]).' AND ';
$ordstr = $ordstr.'"runtime" '.($sort->runtime[0]==0 ? 'DESC' : 'ASC').' ,';
}
- if($sort->maxmem != null)
+ if($sort->maxmem !== null)
{
$relstr = $sort->maxmem[0]==0 ? '<=' : '>=';
$condstr = $condstr.'"memory"'.$relstr.pg_escape_string($sort->maxmem[1]).' AND ';
diff --git a/toj/php/user.inc.php b/toj/php/user.inc.php
index 8b3bb61..46205d7 100755
--- a/toj/php/user.inc.php
+++ b/toj/php/user.inc.php
@@ -192,6 +192,57 @@ class user
return true;
}
+
+ public static function statistic($sqlc, $uid){
+ $sqlstr = 'SELECT "proid",MIN("result") AS "result" FROM "submit" WHERE "uid"=$1 GROUP BY "proid" ORDER BY "proid" ASC;';
+ $sqlarr = array(intval($uid));
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $trylist = array();
+ while($obj = pg_fetch_object($sqlr)){
+ $obj->proid = intval($obj->proid);
+ $obj->result = intval($obj->result);
+ array_push($trylist, $obj);
+ }
+ pg_free_result($sqlr);
+
+ $sqlstr = 'SELECT "result",COUNT("result") AS "count" FROM "submit" WHERE "uid"=$1 GROUP BY "result" ORDER BY "result";';
+ $sqlarr = array(intval($uid));
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $substatis = array();
+ while($obj = pg_fetch_object($sqlr)){
+ $obj->result = intval($obj->result);
+ $obj->count = intval($obj->count);
+ array_push($substatis, $obj);
+ }
+ pg_free_result($sqlr);
+
+ $sqlstr = 'SELECT "result",COUNT("result") AS "count" FROM "submit" WHERE "uid"=$1 GROUP BY "result" ORDER BY "result";';
+ $sqlarr = array(intval($uid));
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $substatis = array();
+ while($obj = pg_fetch_object($sqlr)){
+ $obj->result = intval($obj->result);
+ $obj->count = intval($obj->count);
+ array_push($substatis, $obj);
+ }
+ pg_free_result($sqlr);
+
+ $sqlstr = 'SELECT TO_CHAR("submit_time",\'YYYY-MM\') AS "time",COUNT("submit_time") AS "count" FROM "submit" WHERE uid=$1 GROUP BY TO_CHAR("submit_time",\'YYYY-MM\');';
+ $sqlarr = array(intval($uid));
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $timesub = array();
+ while($obj = pg_fetch_object($sqlr)){
+ $obj->count = intval($obj->count);
+ array_push($timesub, $obj);
+ }
+ pg_free_result($sqlr);
+
+ return array(
+ 'trylist' => $trylist,
+ 'substatis' => $substatis,
+ 'timesub' => $timesub
+ );
+ }
}
function sec_check_level($sqlc, $lv, $uid = null)
diff --git a/toj/php/user.php b/toj/php/user.php
index 4570700..23a15e6 100755
--- a/toj/php/user.php
+++ b/toj/php/user.php
@@ -125,7 +125,12 @@ if($action == 'view')
if(intval($_COOKIE['uid']) != $user->uid)
unset($user->email);
- echo(json_encode($user));
+ $statis = user::statistic($sqlc, $user->uid);
+
+ echo(json_encode(array(
+ 'user' => $user,
+ 'statis' => $statis
+ )));
}
if($action == 'login')
{