-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_list.php
66 lines (55 loc) · 2.13 KB
/
json_list.php
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
<?php
//$flagNoAuth = true;
require ('common/auth.php');
$id = $_GET['id']?urldecode($_GET['id']):'';
$q = urldecode($_GET["term"]);
$table = urldecode($_GET["table"]);
$limit = $_GET['limit']?(integer)$_GET['limit']:10;
//$prefix = urldecode($_GET["prefix"]);
if (strlen($q)>1 || $id){
$sql = "SHOW TABLES LIKE '$table'";
//$rs = $oSQL->q($sql);
if ($rw = $oSQL->d($sql)){
$sql = "SHOW COLUMNS FROM `$rw`";
$id_col = $oSQL->d($sql);
$prefix = substr($id_col,0,3);
$fldTitle = Array("Title"=>"{$prefix}Title","TitleLocal"=>"{$prefix}TitleLocal");
switch($table){
case "stbl_user":
$fldTitle=Array("Title"=>"{$prefix}Name","TitleLocal"=>"{$prefix}NameLocal");
break;
case 'tbl_port':
$fldTitle=Array("Title"=>"CONCAT('[',prtID,']',prtTitle)","TitleLocal"=>"CONCAT('[',prtID,']',prtTitleLocal)",'icon'=>"LCASE(LEFT(prtID,2))");
break;
}
if ($id) {
$sql = "SELECT `{$prefix}ID` as value, `{$fldTitle["Title$strLocal"]}` as label
FROM `$table`
WHERE `{$prefix}ID` = '$id'
LIMIT 1;";
} else {
$sql = "SELECT `{$prefix}ID` as value, {$fldTitle["Title$strLocal"]} as label".($fldTitle["desc"]?", {$fldTitle["desc"]} as desc,":"").($fldTitle["icon"]?",{$fldTitle["icon"]} as icon":"")."
FROM `$table`
WHERE ({$fldTitle["Title"]} LIKE '%".addslashes($q)."%'
OR {$fldTitle["TitleLocal"]} LIKE '%".addslashes($q)."%'
OR {$fldTitle["TitleLocal"]} LIKE '%".addslashes(mb_convert_case($q, MB_CASE_TITLE, "UTF-8"))."%'
OR {$fldTitle["TitleLocal"]} LIKE '%".addslashes(mb_convert_case($q, MB_CASE_UPPER, "UTF-8"))."%')
AND `{$prefix}FlagDeleted`<>1
ORDER BY {$fldTitle["Title"]}, {$fldTitle["TitleLocal"]}
LIMIT $limit;";
}
$rs = $oSQL->q($sql);
//if (mysql_num_rows($rs)==0) echo $sql;
while ($rw=$oSQL->f($rs)){
$arrOutput[] = $rw;
}
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header('Content-type:application/json; charset=UTF-8');
echo json_encode($arrOutput);
} else {
echo "ERROR: Table '$table' doesn't exist";
}
echo $strOutput;
}
?>