-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitem.php
More file actions
223 lines (156 loc) · 7.47 KB
/
item.php
File metadata and controls
223 lines (156 loc) · 7.47 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
#instance.php displays all statements in a certain instance and links to create more
#Helena F Deus (helenadeus@gmail.com)
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;
}
#just to know where we are...
$thisScript = end(explode('/', $_SERVER['SCRIPT_FILENAME'])).'?'.$_SERVER['argv'][0];
$key = $_GET['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
$instance_id = ($_REQUEST['item_id']!='')?$_REQUEST['item_id']:$_REQUEST['instance_id'];
if($instance_id)
$instance_info = URIinfo('I'.$instance_id, $user_id, $key, $db);
$class_id = ($_REQUEST['class_id']!='')?$_REQUEST['class_id']:(($_REQUEST['collection_id']!='')?$_REQUEST['collection_id']:$instance_info['class_id']);
if($instance_id=='')
{
echo "Please provide an item_id";
exit;
}
elseif(!$instance_info['view'])
{echo ('User does not have permission in this instance');
exit;
}
else
{
include('action.header.php'); #add the instance header and the insertall
echo '<table width="100%">';
echo '<tr><td class="nav_menu">';
if($instance_info['add_data'])
echo '<br /><br />[ <a href="#" onClick="window.location=\''.$action['instanceform'].'\'"> Add Statements </a>]';
}
#include the header for the instance
include('resource/instance.header.php');
#if there are any rules, print a grid with the rules header and the button to add a statement
#if (ereg('(1|2|3)', $projectAcl)) {#users that do not have access on the project and do not provide a project_id cannot see rules. Otherwise, there is no way of knowing which rules they were given access to
$s3ql=compact('user_id','db');
$s3ql['from'] = 'rules';
$s3ql['where']['subject_id'] = $instance_info['class_id'];
#$s3ql['where']['object'] = "!='UID'";
$rules = S3QLaction($s3ql);
#echo 'ola<pre>';print_r($rules);exit;
$I = compact('instance_info', 'db', 'user_id', 'rules','project_id');
#}
if(is_array($rules))
echo render_statements($I); #print the statements together with the rules.
function render_statements($I)
{$action = $GLOBALS['action']; #all the possible links were separated ina script that gets always included
extract($I);
$_SESSION['current_color']='0';
$_SESSION['previous_verb']='';
#display all the rules in this class where the user has permission
$s3ql=compact('user_id','db');
$s3ql['select']='*';
$s3ql['from']='statements';
$s3ql['where']['instance_id']=$instance_info['instance_id'];
$statements = S3QLaction($s3ql);
#echo '<pre>';print_r($statements);exit;
#divide them by rules
if(is_array($statements)){
foreach ($statements as $stat_info) {
$stats_per_rule[$stat_info['rule_id']][$stat_info['statement_id']] = $stat_info;
}
if(is_array($rules))
{$rule_ids = array_map('grab_rule_id', $rules);
$tRules = array_combine($rule_ids, $rules);
}
#echo '<pre>';print_r($stats_per_rule);exit;
if(is_array($stats_per_rule) && is_array($tRules))
{
$stats ='';
$index = 1;
foreach($stats_per_rule as $rule_id=>$exist_stats)
{
if($tRules[$rule_id]['object']!='UID' && $tRules[$rule_id]['verb']!='has UID'){
$subject = $tRules[$rule_id]['subject'];
$verb = $tRules[$rule_id]['verb'];
$object = $tRules[$rule_id]['object'];
$rule_id = $tRules[$rule_id]['rule_id'];
#$rule_notes = preg_replace('/\(.*\)/', '', $rules[$i]['notes']);
$rule_notes = $tRules[$rule_id]['notes'];
$stats .= sprintf("\n%s\n", '<table width="100%" border="0"><tr bgcolor="lightyellow"><td colspan="2">');
$stats .= sprintf("%s\n", ($index++).'. '.printVerbinColor($verb).' | <font size=4><b>'.$object.'</b></font> (R'.$rule_id.') </td></tr><tr><td> <font size-=2>'.$rule_notes.'</font></td><td align="right">');
if($tRules[$rule_id]['add_data'])
$stats .= sprintf("%s\n",'<input type="button" value="Add" onClick="window.open(\''.$action['insertstatement'].'&rule_id='.$rule_id.'\', \'_blank\', \'width=600, height=500, location=no, titlebar=no, scrollbars=yes, resizable=yes\')">');
$stats .= sprintf("%s\n", ' </td></tr>');
$stat ='';
$stat .= sprintf("%s\n", ' <tr><td colspan="2" style="color: navy; font-size: normal">');
if(is_array($exist_stats))
$stat .= render_substatements_without_grid($exist_stats, $db);
//$stat .= render_substatements($exist_stats, 'value', 'DESC');
$stat .= sprintf("%s\n", ' </td></tr>');
$stats .= $stat;
$stats .= sprintf("%s\n", ' <tr><td colspan="2"><br>');
$stats .= sprintf("%s\n", ' </td></tr>');
$stats .= sprintf("%s\n", '</table>');
}
}
}
}
return $stats;
}
function render_substatements_without_grid($exist_stats, $db)
{$action=$GLOBALS['action'];
$substats = '<table width="100%" border="0">';
if(is_array($exist_stats))
{
#echo '<pre>';print_r($exist_stats);exit;
foreach($exist_stats as $i => $value)
{
#if(object_is_resource())
if($exist_stats[$i]['file_name']=='') {
if($exist_stats[$i]['object_id']!='')
{#if the value is not a file, put a button
$substats .= '<tr><td colspan="6"><input type="button" size="10" value="'.$exist_stats[$i]['object_notes'].'" onClick="window.open(\''.$action['item'].'&item_id='.$exist_stats[$i]['value'].'\', \'_blank\', \'width=700, height=600, location=no, titlebar=no, scrollbars=yes, resizable=yes\')"> <font size=1 color=navy> (Id '.str_pad($exist_stats[$i]['value'], 6, '0', STR_PAD_LEFT).')</font></td></tr>';
}
else
{
$substats .= "<tr><td colspan=6><font color=dodgerblue size=3><b>".html_entity_decode($exist_stats[$i]['value'])."</b></font></td></tr>";
}
}
else {
$substats .= "<tr><td colspan=6><font color=dodgerblue size=3><b>File: <a href=".$action['download']."&statement_id=".$exist_stats[$i]['statement_id'].">".$exist_stats[$i]['file_name'].(($exist_stats[$i]['file_size']!='')?'('.ceil($exist_stats[$i]['file_size']/1024).' kb)':'')."<a/></b></font></td></tr>";
}
$substats .= "<tr><td width=50%> </td><td width=15%><font color=gray size=1>".substr($exist_stats[$i]['created_on'], 0, 19)."</font></td><td width=15%>";
if($exist_stats[$i]['change'])
{
$action_link = printStatementActionLink($exist_stats[$i]['statement_id']);
$substats .= "<font color=gray size=1>".find_user_loginID(array('account_id'=>$exist_stats[$i]['created_by'], 'db'=>$db))."</font></td><td width=10%><font color=gray size=1>".$exist_stats[$i]['notes']."</font></td><td width=10% align=right>".$action_link."</td></tr>";
}
}
$substats .= '</table>';
//echo $substats;
return $substats;
}
}
?>