-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewresource.php
More file actions
140 lines (105 loc) · 3.84 KB
/
viewresource.php
File metadata and controls
140 lines (105 loc) · 3.84 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
<?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
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 = $_REQUEST['key'];
#echo '<pre>';print_r($_GET);
#Get the key, send it to check validity
include_once('core.header.php');
//if($key)
// $user_id = get_entry('access_keys', 'account_id', 'key_id', $key, $db);
// else
// $user_id = $_SESSION['user']['account_id'];
#Universal variables
$class_id = ($_REQUEST['collection_id']=='')?$_REQUEST['class_id']:$_REQUEST['collection_id'];
$collection_info = URIinfo('C'.$class_id,$user_id, $key, $db);
include('webActions.php');
if($class_id=='')
{
echo "Please provide a collection_id";
exit;
}
elseif(!$collection_info['view'])
{
echo "User does not have access to this resource";
exit;
}
else
{
##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
#will needs rules and items
if ($_SESSION['queryresult']=='') {
$s3ql=compact('user_id','db');
$s3ql['select']='*';
$s3ql['from']='items';
$s3ql['where']['collection_id']=$class_id;
$items = S3QLaction($s3ql);
}
else {
$items = $_SESSION['queryresult'];
}
if($_REQUEST['num_per_page']!='' && $_REQUEST['current_page']!='')
{
$start = (($_REQUEST['current_page']-1)*$_REQUEST['num_per_page']);
$end=($_REQUEST['num_per_page']*$_REQUEST['current_page']);
}
else {
$start = 0;
$end= count($items);
}
$end=(count($items)<$end)?count($items):$end;
if(is_array($items))
{
for ($i=$start; $i < $end; $i++) {
if(!is_array($items[$i]['stats'])){
$s3ql=compact('user_id','db');
$s3ql['from']='statements';
$s3ql['where']['item_id']=$items[$i]['item_id'];
$items[$i]['stats'] = S3QLaction($s3ql);
$_SESSION['queryresult'][$i]['stats'] = $items[$i]['stats'];
}
}
}
#echo '<pre>';print_r($items);exit;
$s3ql=compact('user_id','db');
$s3ql['select']='*';
$s3ql['from']='rules';
$s3ql['where']['subject_id']=$class_id;
$s3ql['where']['object'] = "!='UID'";
$rules = S3QLaction($s3ql);
##Find the values that are to be sent to datamatrix.php, both header and data
if(!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'=>$items,'format'=>strval($s3ql['format']), 'color'=>strval($s3ql['color']),'start'=>$start,'end'=>$end);
$display .= create_datamatrix_header($head);
if(is_array($items))
{$display .= render_datamatrix_values($head);}
else echo '<table><tr><td>Your query returned no results.</td></tr></table>';
echo $display;
exit;
}
?>