-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtuplesView.php
More file actions
146 lines (102 loc) · 4.1 KB
/
tuplesView.php
File metadata and controls
146 lines (102 loc) · 4.1 KB
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
141
142
143
144
145
146
<?php
#viewresource.php is a special join of rules, resource instances and statements, provides an excel-like struture for each resource class;
#Syntax: viewresource.php?key=xxx&collection_id=yyy
#Helena F Deus, April 20, 2007
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 = $_REQUEST['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['class_id']:$_REQUEST['collection_id'];
$class_info = URIinfo('C'.$class_id,$user_id, $key, $db);
include('webActions.php');
if($class_id==''){
echo "Plase specify the collection_id from the tuples you are trying to retrieve";
exit;
}
if(!$class_info['view'])
{
echo "User does not have access to this resource";
exit;
}
else
{
#Parse the inputs: are there attr/value pair patterns to be queried?
if($argv!='')
{
for ($i=1; $i <count($argv) ; $i++) {
list($keyWord, $val) = explode('=',$argv[$i]);
if(!ereg('collection_id|class_id|key|su3d',$keyWord));
$inputs[$keyWord] = $val;
}
}
else {
$inputs = array_filter(array_diff_key($_GET, array('collection_id'=>'','class_id'=>'','key'=>'','su3d'=>'')));
}
##For viewing statments as a table will need to have a slighly different sintax for diaplay because one combination of row/col can have more than 1 value, in that case a complete new line will need to be repeated
$cols = array('resource_id', 'resource_class_id','entity', 'notes', 'project_id','created_on', 'created_by' ,'iid');
if(empty($inputs))
{
if (is_array($_SESSION[$user_id]['instances'][$class_id])) {
$instances = $_SESSION[$user_id]['instances'][$class_id];
}
else {
$s3ql = compact('db', 'user_id');
$s3ql['select'] = '*';
$s3ql['from'] = 'items';
$s3ql['where']['collection_id'] = $class_id;
#$s3ql['where']['project_id'] = $project_id;
$instances = S3QLaction($s3ql);
}
#echo '<pre>';print_r($instances);
#For finding all the rules that this resource involves, change S a little bit
$s3ql = compact('db', 'user_id');
$s3ql['select'] = '*';
$s3ql['from'] = 'rules';
$s3ql['where']['subject_id'] = $class_id;
$s3ql['where']['object'] = "!='UID'";
$rules = S3QLaction($s3ql);
#$rules = include_all_class_id(compact('rules', 'project_id', 'db'));
}
else
{
#Building the query
$ruleScope=array();
foreach ($inputs as $key=>$value) {
$ruleScope[ereg_replace('^R', '',$key)]=stripslashes($value);
}
$q = array('rules'=>array_keys($ruleScope), 'logical'=>array_fill(0, count($inputs), 'and'), 'RuleValuePair'=>$ruleScope, 'db'=>$db);
$instances = query_statements($q);
}
##Find the values that are to be sent to datamatrix.php, both header and data
if(is_array($rules) && !empty($rules)){
$verbs = array_map('grab_verb', $rules);
foreach($verbs as $i=>$value)
{
$objects = array_map('grab_object', $rules, $verbs);
}
}
#echo '<pre>';print_r($objects);
#A matrix will need to be built that has rules on top, resource_id as rows and statements in the middle
#Create the header, which will not differ for listall or query
$head = array('key'=>$key, 'user_id'=>$user_id,'db'=>$db, 'resource_class_id'=>$class_info['resource_id'],'class_info'=>$class_info, 'project_id'=>$project_id, 'rules'=>$rules, 'objects'=>$objects, 'verbs'=>$verbs, 'instances'=>$instances,'format'=>strval($s3ql['format']), 'color'=>strval($s3ql['color']));
$display .= create_datamatrix_header($head);
if(is_array($instances))
{$display .= render_datamatrix_values($head);}
else echo '<table><tr><td>Your query returned no results.</td></tr></table>';
echo $display;
}
?>