1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
<?php
require_once('common.php');
function square_problem_list($sqlc,$paramo){
$userid = $_COOKIE['userid'];
$usersec = $_COOKIE['usersec'];
$squareid = $paramo->squareid;
$prooff = $paramo->prooff;
if(!sec_checkuser($userid,$usersec)){
$userid = null;
}
if(gettype($squareid) != 'integer' || $squareid < 1){
return null;
}
if(gettype($prooff) != 'integer' || $prooff < 0){
return null;
}
$squaireid = pg_escape_string($squareid);
$prooff = pg_escape_string($prooff);
$sqlr = pg_query_params($sqlc,'SELECT * FROM "problem" WHERE $1 = ANY ("squarelist") ORDER BY "proid" LIMIT 20 OFFSET $2;',
array($squareid,$prooff));
$prolist = array();
$proidlist = array();
while($proo = pg_fetch_object($sqlr)){
$prolist[] = array(
'proid' => $proo->proid,
'proname' => $proo->proname,
'acceptcount' => $proo->acceptcount,
'submitcount' => $proo->submitcount,
'sumscore' => null,
'summaxscore' => null);
$proidlist[$proo->proid] = count($prolist) - 1;
}
pg_free_result($sqlr);
$sqlr = pg_query_params($sqlc,'SELECT COUNT(*) FROM "problem" WHERE $1 = ANY ("squarelist");',
array($squareid));
$procount = pg_fetch_row($sqlr)[0];
pg_free_result($sqlr);
if($userid){
$userid = pg_escape_string($userid);
$sqlr = pg_query_params($sqlc,'SELECT "proid","sumscore","summaxscore" FROM "submit" WHERE "userid"=$1 AND "proid" IN ('.implode(',',array_keys($proidlist)).') ORDER BY "sumscore" DESC;',
array($userid));
while($sqlo = pg_fetch_object($sqlr)){
if($prolist[$proidlist[$sqlo->proid]]['sumscore'] == null){
$prolist[$proidlist[$sqlo->proid]]['sumscore'] = $sqlo->sumscore;
$prolist[$proidlist[$sqlo->proid]]['summaxscore'] = $sqlo->summaxscore;
}
}
pg_free_result($sqlr);
}
return array(
'procount' => $procount,
'prolist' => $prolist
);
}
?>
|