/
views.php
343 lines (295 loc) · 12.9 KB
/
views.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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?php
/**
* Manage views in a database
*
* $Id: views.php,v 1.15 2003/06/05 20:05:45 xzilla Exp $
*/
// Include application functions
include_once('libraries/lib.inc.php');
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
if (!isset($msg)) $msg = '';
$PHP_SELF = $_SERVER['PHP_SELF'];
/**
* Ask for select parameters and perform select
*/
function doSelectRows($confirm, $msg = '') {
global $localData, $database, $misc;
global $lang;
global $PHP_SELF;
if ($confirm) {
echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: ", $misc->printVal($_REQUEST['view']), ": {$lang['strselect']}</h2>\n";
$misc->printMsg($msg);
$attrs = &$localData->getTableAttributes($_REQUEST['view']);
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
if ($attrs->recordCount() > 0) {
echo "<table>\n<tr>";
// Output table header
echo "<tr><th class=\"data\">{$lang['strshow']}</th><th class=\"data\">{$lang['strfield']}</th>";
echo "<th class=\"data\">{$lang['strtype']}</th><th class=\"data\">{$lang['strnull']}</th>";
echo "<th class=\"data\">{$lang['strvalue']}</th></tr>";
$i = 0;
while (!$attrs->EOF) {
$attrs->f['attnotnull'] = $localData->phpBool($attrs->f['attnotnull']);
// Set up default value if there isn't one already
if (!isset($_REQUEST['values'][$attrs->f['attname']]))
$_REQUEST['values'][$attrs->f['attname']] = null;
// Continue drawing row
$id = (($i % 2) == 0 ? '1' : '2');
echo "<tr>\n";
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">";
echo "<input type=\"checkbox\" name=\"show[", htmlspecialchars($attrs->f['attname']), "]\"",
isset($_REQUEST['show'][$attrs->f['attname']]) ? ' checked="checked"' : '', " /></td>";
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($attrs->f['attname']), "</td>";
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($attrs->f['type']), "</td>";
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">";
// Output null box if the column allows nulls (doesn't look at CHECKs or ASSERTIONS)
if (!$attrs->f['attnotnull'])
echo "<input type=\"checkbox\" name=\"nulls[{$attrs->f['attname']}]\"",
isset($_REQUEST['nulls'][$attrs->f['attname']]) ? ' checked="checked"' : '', " /></td>";
else
echo " </td>";
echo "<td class=\"data{$id}\" nowrap>", $localData->printField("values[{$attrs->f['attname']}]",
$_REQUEST['values'][$attrs->f['attname']], $attrs->f['type']), "</td>";
echo "</tr>\n";
$i++;
$attrs->moveNext();
}
echo "</table></p>\n";
}
else echo "<p>{$lang['strinvalidparam']}</p>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"selectrows\" />\n";
echo "<input type=\"hidden\" name=\"view\" value=\"", htmlspecialchars($_REQUEST['view']), "\" />\n";
echo $misc->form;
echo "<input type=\"submit\" name=\"select\" value=\"{$lang['strselect']}\" />\n";
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
echo "</form>\n";
}
else {
if (!isset($_POST['show'])) $_POST['show'] = array();
if (!isset($_POST['values'])) $_POST['values'] = array();
if (!isset($_POST['nulls'])) $_POST['nulls'] = array();
if (sizeof($_POST['show']) == 0)
doSelectRows(true, $lang['strselectneedscol']);
else {
// Generate query SQL
$query = $localData->getSelectSQL($_REQUEST['view'], array_keys($_POST['show']),
$_POST['values'], array_keys($_POST['nulls']));
$_REQUEST['query'] = $query;
$_REQUEST['return_url'] = "views.php?action=confselectrows&{$misc->href}&view={$_REQUEST['view']}";
$_REQUEST['return_desc'] = $lang['strback'];
include('display.php');
exit;
}
}
}
/**
* Function to save after editing a view
*/
function doSaveEdit() {
global $localData, $lang;
$status = $localData->setView($_POST['view'], $_POST['formDefinition']);
if ($status == 0)
doProperties($lang['strviewupdated']);
else
doEdit($lang['strviewupdatedbad']);
}
/**
* Function to allow editing of a view
*/
function doEdit($msg = '') {
global $data, $localData, $misc;
global $PHP_SELF, $lang;
echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: ", $misc->printVal($_REQUEST['view']), ": {$lang['stredit']}</h2>\n";
$misc->printMsg($msg);
$viewdata = &$localData->getView($_REQUEST['view']);
if ($viewdata->recordCount() > 0) {
if (!isset($_POST['formDefinition'])) $_POST['formDefinition'] = $viewdata->f[$data->vwFields['vwdef']];
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
echo "<table width=\"100%\">\n";
echo "<tr><th class=\"data\">{$lang['strname']}</th></tr>\n";
echo "<tr><td class=\"data1\">", $misc->printVal($viewdata->f[$data->vwFields['vwname']]), "</td></tr>\n";
echo "<tr><th class=\"data\">{$lang['strdefinition']}</th></tr>\n";
echo "<tr><td class=\"data1\"><textarea style=\"width:100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\" wrap=\"virtual\">",
htmlspecialchars($_POST['formDefinition']), "</textarea></td></tr>\n";
echo "</table>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n";
echo "<input type=\"hidden\" name=\"view\" value=\"", htmlspecialchars($_REQUEST['view']), "\" />\n";
echo $misc->form;
echo "<input type=\"submit\" value=\"{$lang['strsave']}\" />\n";
echo "<input type=\"reset\" value=\"{$lang['strreset']}\" />\n";
echo "</form>\n";
}
else echo "<p>{$lang['strnodata']}</p>\n";
echo "<p><a class=\"navlink\" href=\"$PHP_SELF?{$misc->href}\">{$lang['strshowallviews']}</a> |\n";
echo "<a class=\"navlink\" href=\"$PHP_SELF?action=properties&{$misc->href}&view=",
urlencode($_REQUEST['view']), "\">{$lang['strproperties']}</a></p>\n";
}
/**
* Show read only properties for a view
*/
function doProperties($msg = '') {
global $data, $localData, $misc;
global $PHP_SELF, $lang;
echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: ", $misc->printVal($_REQUEST['view']), ": {$lang['strproperties']}</h2>\n";
$misc->printMsg($msg);
$viewdata = &$localData->getView($_REQUEST['view']);
if ($viewdata->recordCount() > 0) {
echo "<table width=\"100%\">\n";
echo "<tr><th class=\"data\">{$lang['strname']}</th></tr>\n";
echo "<tr><td class=\"data1\">", $misc->printVal($viewdata->f[$data->vwFields['vwname']]), "</td></tr>\n";
echo "<tr><th class=\"data\">{$lang['strdefinition']}</th></tr>\n";
echo "<tr><td class=\"data1\">", $misc->printVal($viewdata->f[$data->vwFields['vwdef']]), "</td></tr>\n";
echo "</table>\n";
}
else echo "<p>{$lang['strnodata']}</p>\n";
echo "<p><a class=\"navlink\" href=\"$PHP_SELF?{$misc->href}\">{$lang['strshowallviews']}</a> |\n";
echo "<a class=\"navlink\" href=\"$PHP_SELF?action=edit&{$misc->href}&view=",
urlencode($_REQUEST['view']), "\">{$lang['stredit']}</a></p>\n";
}
/**
* Show confirmation of drop and perform actual drop
*/
function doDrop($confirm) {
global $localData, $misc;
global $PHP_SELF, $lang;
if ($confirm) {
echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: ", $misc->printVal($_REQUEST['view']), ": {$lang['strdrop']}</h2>\n";
echo "<p>", sprintf($lang['strconfdropview'], $misc->printVal($_REQUEST['view'])), "</p>\n";
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"drop\">\n";
echo "<input type=\"hidden\" name=\"view\" value=\"", htmlspecialchars($_REQUEST['view']), "\">\n";
echo $misc->form;
// Show cascade drop option if supportd
if ($localData->hasDropBehavior()) {
echo "<p><input type=\"checkbox\" name=\"cascade\"> {$lang['strcascade']}</p>\n";
}
echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\"> <input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\">\n";
echo "</form>\n";
}
else {
$status = $localData->dropView($_POST['view'], isset($_POST['cascade']));
if ($status == 0)
doDefault($lang['strviewdropped']);
else
doDefault($lang['strviewdroppedbad']);
}
}
/**
* Displays a screen where they can enter a new view
*/
function doCreate($msg = '') {
global $data, $localData, $misc;
global $PHP_SELF, $lang;
if (!isset($_POST['formView'])) $_POST['formView'] = '';
if (!isset($_POST['formDefinition'])) $_POST['formDefinition'] = '';
echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: {$lang['strcreateview']}</h2>\n";
$misc->printMsg($msg);
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
echo "<table width=\"100%\">\n";
echo "<tr><th class=\"data\">{$lang['strname']}</th></tr>\n";
echo "<tr><td class=\"data1\"><input name=\"formView\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
htmlspecialchars($_POST['formView']), "\"></td></tr>\n";
echo "<tr><th class=\"data\">{$lang['strdefinition']}</th></tr>\n";
echo "<tr><td class=\"data1\"><textarea style=\"width:100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\" wrap=\"virtual\">",
htmlspecialchars($_POST['formDefinition']), "</textarea></td></tr>\n";
echo "</table>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"save_create\">\n";
echo $misc->form;
echo "<input type=\"submit\" value=\"{$lang['strcreate']}\"> <input type=\"reset\" value=\"{$lang['strreset']}\">\n";
echo "</form>\n";
echo "<p><a class=\"navlink\" href=\"$PHP_SELF?{$misc->href}\">{$lang['strshowallviews']}</a></p>\n";
}
/**
* Actually creates the new view in the database
*/
function doSaveCreate() {
global $localData, $lang;
// Check that they've given a name and a definition
if ($_POST['formView'] == '') doCreate($lang['strviewneedsname']);
elseif ($_POST['formDefinition'] == '') doCreate($lang['strviewneedsdef']);
else {
$status = $localData->createView($_POST['formView'], $_POST['formDefinition'], false);
if ($status == 0)
doDefault($lang['strviewcreated']);
else
doCreate($lang['strviewcreatedbad']);
}
}
/**
* Show default list of views in the database
*/
function doDefault($msg = '') {
global $data, $localData, $misc;
global $PHP_SELF, $lang;
echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}</h2>\n";
$misc->printMsg($msg);
$views = &$localData->getViews();
if ($views->recordCount() > 0) {
echo "<table>\n";
echo "<tr><th class=\"data\">{$lang['strview']}</th><th class=\"data\">{$lang['strowner']}</th>";
echo "<th colspan=\"5\" class=\"data\">{$lang['stractions']}</th></tr>\n";
$i = 0;
while (!$views->EOF) {
// @@@@@@@@@ FIX THIS!!!!!
$query = urlencode("SELECT * FROM \"{$views->f[$data->vwFields['vwname']]}\"");
$count = urlencode("SELECT COUNT(*) AS total FROM \"{$views->f[$data->vwFields['vwname']]}\"");
$return_url = urlencode("views.php?{$misc->href}");
$id = (($i % 2) == 0 ? '1' : '2');
echo "<tr><td class=\"data{$id}\">", $misc->printVal($views->f[$data->vwFields['vwname']]), "</td>\n";
echo "<td class=\"data{$id}\">", $misc->printVal($views->f[$data->vwFields['vwowner']]), "</td>\n";
echo "<td class=\"opbutton{$id}\"><a href=\"display.php?{$misc->href}&query={$query}&count={$count}&return_url={$return_url}&return_desc=",
urlencode($lang['strback']), "\">{$lang['strbrowse']}</a></td>\n";
echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confselectrows&{$misc->href}&view=", urlencode($views->f[$data->vwFields['vwname']]), "\">{$lang['strselect']}</a></td>\n";
echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=properties&{$misc->href}&view=", urlencode($views->f[$data->vwFields['vwname']]), "\">{$lang['strproperties']}</a></td>\n";
echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&view=", urlencode($views->f[$data->vwFields['vwname']]), "\">{$lang['strdrop']}</a></td>\n";
echo "<td class=\"opbutton{$id}\"><a href=\"privileges.php?{$misc->href}&object=", urlencode($views->f[$data->vwFields['vwname']]),
"&type=view\">{$lang['strprivileges']}</a></td>\n";
echo "</tr>\n";
$views->moveNext();
$i++;
}
echo "</table>\n";
}
else {
echo "<p>{$lang['strnoviews']}</p>\n";
}
echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&{$misc->href}\">{$lang['strcreateview']}</a></p>\n";
}
$misc->printHeader($lang['strviews']);
$misc->printBody();
switch ($action) {
case 'selectrows':
if (!isset($_POST['cancel'])) doSelectRows(false);
else doDefault();
break;
case 'confselectrows':
doSelectRows(true);
break;
case 'save_create':
doSaveCreate();
break;
case 'create':
doCreate();
break;
case 'drop':
if (isset($_POST['yes'])) doDrop(false);
else doDefault();
break;
case 'confirm_drop':
doDrop(true);
break;
case 'save_edit':
doSaveEdit();
break;
case 'edit':
doEdit();
break;
case 'properties':
doProperties();
break;
default:
doDefault();
break;
}
$misc->printFooter();
?>