-
Notifications
You must be signed in to change notification settings - Fork 5
/
ajax.json.list.php
50 lines (44 loc) · 1.31 KB
/
ajax.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
<?php // Ajax intake for JSON data requests
include 'core/Page.php';
if ( Session::logged_in() ) {
global $database;
$getpost=getpost();
if ( isset($getpost['F']) ) {
$Field=$getpost['F'];
$parts=words($Field);
if ( count(parts) > 1 ) $Field=$parts;
}
if ( isset($getpost['T'])
&& class_exists($getpost['T'])
&& matches(get_parent_class($getpost['T']),'Model') ) {
$Table=$getpost['T'];
$Model=new $Table($database);
$result=array();
if ( isset($getpost['L']) ) {
$list=$getpost['L'];
$list=ints($list);/////////////////
// if ( matches($Table,'Item') ){
// foreach ( $list as $e ) {
// $e=$Model->Get($e);
// $result[]=array(
// 0=>intval($e['ID']),
// 1=>$e['Name'],
// );
// }
// } else if ( matches($Table,'Part') ){ ...
} else foreach ( $list as $e ) { ////////////////
$piece=array();
$piece[]=$e;
$r=$Model->Get($e);
if ( !is_array($Field) ) $piece[]=$r[$Field]; else foreach ( $Field as $g ) $piece[]=$r[$g];
$result[]=$piece;
}
echo json_encode($result);
exit;
}
}
}
echo '{"result":"error"}';
// This kind of AJAX requires a high level of trust
// Use user permissions on writes, and per-user-group databasing to secure this
// Assume they have your data schema and are not being friendly