|
@@ -89,12 +89,16 @@ function processKeyParameter($key,$table,$database,$mysqli) {
|
89
|
89
|
return $key;
|
90
|
90
|
}
|
91
|
91
|
|
92
|
|
-function processFilterParameter($filter,$mysqli) {
|
|
92
|
+function processFilterParameter($filter,$match,$mysqli) {
|
93
|
93
|
if ($filter) {
|
94
|
94
|
$filter = explode(':',$filter,2);
|
95
|
95
|
if (count($filter)==2) {
|
96
|
96
|
$filter[0] = preg_replace('/[^a-zA-Z0-9\-_]/','',$filter[0]);
|
97
|
|
- $filter[1] = $mysqli->real_escape_string($filter[1]);
|
|
97
|
+ if ($match=='in') {
|
|
98
|
+ $filter[1] = implode("','",array_map(function($v){ return preg_replace('/[^a-zA-Z0-9\-]/','',$v); },explode(',',$filter[1])));
|
|
99
|
+ } else {
|
|
100
|
+ $filter[1] = $mysqli->real_escape_string($filter[1]);
|
|
101
|
+ }
|
98
|
102
|
$filter[2] = 'LIKE';
|
99
|
103
|
if ($match=='any'||$match=='start') $filter[1] .= '%';
|
100
|
104
|
if ($match=='any'||$match=='end') $filter[1] = '%'.$filter[1];
|
|
@@ -103,6 +107,9 @@ function processFilterParameter($filter,$mysqli) {
|
103
|
107
|
if ($match=='upto') $filter[2] = '<=';
|
104
|
108
|
if ($match=='from') $filter[2] = '>=';
|
105
|
109
|
if ($match=='higher') $filter[2] = '>';
|
|
110
|
+ if ($match=='in') $filter[2] = 'IN';
|
|
111
|
+ $filter[1]="'$filter[1]'";
|
|
112
|
+ if ($filter[2]=='IN') $filter[1]="($filter[1])";
|
106
|
113
|
} else {
|
107
|
114
|
$filter = false;
|
108
|
115
|
}
|
|
@@ -166,7 +173,7 @@ $mysqli = connectDatabase($config["hostname"], $config["username"], $config["pas
|
166
|
173
|
|
167
|
174
|
$table = processTableParameter($table,$config["database"],$mysqli);
|
168
|
175
|
$key = processKeyParameter($key,$table,$config["database"],$mysqli);
|
169
|
|
-$filter = processFilterParameter($filter,$mysqli);
|
|
176
|
+$filter = processFilterParameter($filter,$match,$mysqli);
|
170
|
177
|
$page = processPageParameter($page);
|
171
|
178
|
|
172
|
179
|
$table = applyWhitelistAndBlacklist($table,$action,$config['whitelist'],$config['blacklist']);
|
|
@@ -185,7 +192,7 @@ switch($action){
|
185
|
192
|
echo '"'.$table.'":{';
|
186
|
193
|
if ($t==0 && is_array($page)) {
|
187
|
194
|
$sql = "SELECT COUNT(*) FROM `$table`";
|
188
|
|
- if (is_array($filter)) $sql .= " WHERE `$filter[0]` $filter[2] '$filter[1]'";
|
|
195
|
+ if (is_array($filter)) $sql .= " WHERE `$filter[0]` $filter[2] $filter[1]";
|
189
|
196
|
if ($result = $mysqli->query($sql)) {
|
190
|
197
|
$pages = $result->fetch_row();
|
191
|
198
|
$count = $pages[0];
|
|
@@ -193,7 +200,7 @@ switch($action){
|
193
|
200
|
}
|
194
|
201
|
echo '"columns":';
|
195
|
202
|
$sql = "SELECT * FROM `$table`";
|
196
|
|
- if ($t==0 && is_array($filter)) $sql .= " WHERE `$filter[0]` $filter[2] '$filter[1]'";
|
|
203
|
+ if ($t==0 && is_array($filter)) $sql .= " WHERE `$filter[0]` $filter[2] $filter[1]";
|
197
|
204
|
if ($t==0 && is_array($page)) $sql .= " LIMIT $page[1] OFFSET $page[0]";
|
198
|
205
|
if ($result = $mysqli->query($sql)) {
|
199
|
206
|
$fields = array();
|