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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
<?php
require_once('common.php');
function square_list($sqlc,$paramo){
$userid = $_COOKIE['userid'];
$usersec = $_COOKIE['usersec'];
if(!sec_checkuser($userid,$usersec)){
return null;
}
$userid = pg_escape_string($userid);
$sqlr = pg_query_params($sqlc,'SELECT array_to_string("squarelist",\',\') AS "squarelist" FROM "user" WHERE "userid"=$1 LIMIT 1;',
array($userid));
if(($sqlo = pg_fetch_object($sqlr)) == null){
pg_free_result($sqlr);
return null;
}
$squarelist = $sqlo->squarelist;
pg_free_result($sqlr);
$sqlr = pg_query($sqlc,'SELECT *,array_to_string("flag",\',\') AS "flag","starttime"<=now() AS "start","endtime"<=now() AS "end" FROM "square" WHERE "squareid" IN ('.$squarelist.') ORDER BY "squareid" ASC;');
$inlist = array();
while($squareo = pg_fetch_object($sqlr)){
if($squareo->end == 't'){
$status = 'inactive';
}else if($squareo->start == 't'){
$status = 'active';
}else{
$status = 'upcoming';
}
$flaglist = explode(',',$squareo->flag);
$flag = array();
for($idx = 0;$idx < count($flaglist);$idx++){
$flag[$flaglist[$idx]] = true;
}
$inlist[] = array(
'squareid' => $squareo->squareid,
'squarename' => $squareo->squarename,
'starttime' => $squareo->starttime,
'endtime' => $squareo->endtime,
'status' => $status,
'flag' => $flag
);
}
pg_free_result($sqlr);
$sqlr = pg_query($sqlc,'SELECT *,array_to_string("flag",\',\') AS "flag","starttime"<=now() AS "start","endtime"<=now() AS "end" FROM "square" WHERE "squareid" NOT IN ('.$squarelist.') ORDER BY "squareid" ASC;');
$outlist = array();
while($squareo = pg_fetch_object($sqlr)){
if($squareo->end == 't'){
$status = 'inactive';
}else if($squareo->start == 't'){
$status = 'active';
}else{
$status = 'upcoming';
}
$flaglist = explode(',',$squareo->flag);
$flag = array();
for($idx = 0;$idx < count($flaglist);$idx++){
$flag[$flaglist[$idx]] = true;
}
$outlist[] = array(
'squareid' => $squareo->squareid,
'squarename' => $squareo->squarename,
'starttime' => $squareo->starttime,
'endtime' => $squareo->endtime,
'status' => $status,
'flag' => $flag
);
}
pg_free_result($sqlr);
return array(
'inlist' => $inlist,
'outlist' => $outlist
);
}
?>
|