-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_item.php
109 lines (90 loc) · 2.91 KB
/
query_item.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
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
<?php
ini_set('display_errors',0);
if($_REQUEST['su3d'])
ini_set('display_errors',1);
if($_SERVER['HTTP_X_FORWARDED_HOST']!='')
$def = $_SERVER['HTTP_X_FORWARDED_HOST'];
else
$def = $_SERVER['HTTP_HOST'];
if(file_exists('config.inc.php'))
{
include('config.inc.php');
}
else
{
Header('Location: http://'.$def.'/s3db/');
exit;
}
$key = $_GET['key'];
#echo '<pre>';print_r($_GET);
#Get the key, send it to check validity
include_once('core.header.php');
#Universal variables
$class_id = ($_REQUEST['collection_id']!='')?$_REQUEST['collection_id']:$_REQUEST['class_id'];
$uid = 'C'.$class_id;
if($class_id)
{
$pl = permission4Resource(array('uid'=>'C'.$class_id, 'shared_with'=>'U'.$user_id, 'db'=>$db, 'user_id'=>$user_id));
#$info['C'.$class_id] = URIinfo('C'.$class_id, $user_id, $key, $db);
$pl = permission_level($pl,'C'.$class_id, $user_id, $db);
if(!$pl['view'] && !$pl['propagate'])
{echo "User does not have access to view or query this collection";
exit;
}
}
#What are the rules tah use this collection as subject?
if($_SESSION[$uid]['rules']==''){
$s3ql=compact('user_id','db');
$s3ql['from'] = 'rules';
if($class_id!='')
$s3ql['where']['subject_id'] = $class_id;
#if($_REQUEST['project_id']!='')
#$s3ql['where']['project_id'] = $_REQUEST['project_id'];
$s3ql['where']['object']='!="UID"';
if($_REQUEST['orderBy'])
$s3ql['order_by'] = $_REQUEST['orderBy'].' '.$_REQUEST['direction'];
$rules = S3QLaction($s3ql);
#echo '<pre>';print_r($rules);exit;
}
else {
$rules = $_SESSION[$uid]['rules'];
}
#is there a query?
foreach ($_REQUEST as $key=>$value) {
if (ereg('R(.*)', $key, $rule_id)) {
$rule_value_pairs['rule_1_'.$rule_id[1]] = $value;
#$rules[] = $rule_id[1];
#$where['rule_id'] = $rule_id[1];
#$where['value']=$value;
}
}
$orderBy = $_REQUEST['orderBy'].' '.$_REQUEST['direction'];
$format = ($_REQUEST['format']!='')?$_REQUEST['format']:'html.pretty';
if(!is_array($rule_value_pairs))
{
#query everything
$s3ql=compact('user_id','db');
$s3ql['from'] = 'items';
$s3ql['where']['collection_id'] = $class_id;
if($_REQUEST['orderBy']!='')
$s3ql['order_by'] = $orderBy;
$items =S3QLaction($s3ql);
}
else {
$data = search_resource(compact('rules', 'db', 'orderBy', 'rule_value_pairs'));
$letter = 'I';
$include_all=0;
$data = fillSlotACL(compact('letter', 'user_id','db', 'data', 'include_all'));
$instances = $data;
$cols = array('resource_id','notes');
$D = compact('data','format', 'select','returnFields', 'letter','cols', 'db');
echo array2str($D);
#
#$omit_button_notes=1;
#echo '<pre>';print_r($rules);
#$data = include_statements(compact('rules', 'instances', 'user_id', 'db', 'project_id', 'omit_button_notes'));
#echo '<pre>';print_r($data);exit;
#$D = compact('data','format', 'select','returnFields', 'letter','cols', 'db')
#echo array2str($D);
}
?>