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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
<?php
ini_set("display_errors", "On");
error_reporting(E_ALL & ~E_NOTICE);
require_once('problem.inc.php');
require_once('user.inc.php');
$sqlc = db_connect();
$action = $_POST['action'];
$data = $_POST['data'];
if(strlen($action)==0)
die('Eno_action');
if($action == 'get_pro')
{
//get problem data: proid, modid, name, pmodname, smodname, jmodname
//only USER_LEVEL_SUPERADMIN or is_available
//data : proid
$dt = json_decode($data);
$proid = intval($dt->proid);
$ret = problem::get($sqlc, $proid);
if(!$ret)
die('Eget_problem');
if(!problem::is_available($sqlc, $proid))
die('Epermission_denied');
unset($ret->proid);
//unset($ret->hidden);
echo(json_encode($ret));
}
if($action == 'add_pro')
{
//Add problem
//need SUPERADMIN
//data: modid, proname, [hidden]
if(!sec_is_login())
die('Enot_login');
if(!sec_check_level($sqlc, USER_PER_PROCREATOR))
die('Epermission_denied');
$dt = json_decode($data);
if(strlen($dt->proname) == 0)
die('Eproname_too_short');
if(strlen($dt->proname) > PRONAME_LEN_MAX)
die('Eproname_too_long');
if(!problem::getmod($sqlc, $dt->modid))
die('Ewrong_modid');
if($dt->hidden != 't' && $dt->hidden != 'f')
die('Ewrong_hidden_value');
/*CHECK OTHER DATA, TESTDATA ETC*/
$dt->admin_uid = intval($_COOKIE['uid']);
$pro = problem::add($sqlc, $dt);
if(!$pro)
die('Eadd_problem');
echo(json_encode($pro));
}
if($action == 'submit_code')
{
//Submit code
//Need problem available
//data: proid, lang, code
if(!sec_is_login())
die('Enot_login');
$uid = intval($_COOKIE['uid']);
$dt = json_decode($data);
$proid = intval($dt->proid);
if(!problem::is_available($sqlc, $proid)){
die('Epermission_denied');
}
$obj = problem::get($sqlc, $proid);
$lang = intval($dt->lang);
$oklang = problem::mod_get_lang($sqlc, $obj->modid);
if($LANGUAGE[$lang] == null || (($lang & $oklang) == 0))
die('Ewrong_language');
if(strlen($dt->code) < CODE_LEN_MIN)
die('Ecode_too_short');
if(strlen($dt->code) > CODE_LEN_MAX)
die('Ecode_too_long');
//if(problem::recent_submit($sqlc, $uid, SUBMIT_MIN_INTERVAL) > 0)
// die('Esubmit_too_frequently');
$subid = problem::submit($sqlc, $proid, $uid, $lang, $dt->code);
if(!$subid)
die('Esubmit_code_failed');
/*ASSOCIATED SQUARE : CALL SQUARE MODULE TO GET EXTRA JUDGE OPTION*/
if(!problem::send_socket($subid, $proid))
die('Esend_socket_failed');
echo(json_encode($subid));
}
if($action == 'get_pro_stat')
{
//Get score and is_ac for specified proid.
//Need login and problem available.
//data : proid
if(!sec_is_login())
die('Enot_login');
$uid = intval($_COOKIE['uid']);
$dt = json_decode($data);
$proid = intval($dt->proid);
if(!problem::is_available($sqlc, $proid)){
die('Epermission_denied');
}
$ret = problem::get_pro_stat($sqlc, $proid, $uid);
if(!$ret)
die('Eerror_get_pro_stat');
echo(json_encode($ret));
}
db_close($sqlc);
?>
|