1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* List views in a database
|
5
|
*
|
6
|
* $Id: viewproperties.php,v 1.16 2005/10/18 03:45:16 chriskl Exp $
|
7
|
*/
|
8
|
|
9
|
// Include application functions
|
10
|
include_once('./libraries/lib.inc.php');
|
11
|
|
12
|
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
|
13
|
$PHP_SELF = $_SERVER['PHP_SELF'];
|
14
|
|
15
|
/**
|
16
|
* Function to save after editing a view
|
17
|
*/
|
18
|
function doSaveEdit() {
|
19
|
global $data, $lang;
|
20
|
|
21
|
$status = $data->setView($_POST['view'], $_POST['formDefinition'], $_POST['formComment']);
|
22
|
if ($status == 0)
|
23
|
doDefinition($lang['strviewupdated']);
|
24
|
else
|
25
|
doEdit($lang['strviewupdatedbad']);
|
26
|
}
|
27
|
|
28
|
/**
|
29
|
* Function to allow editing of a view
|
30
|
*/
|
31
|
function doEdit($msg = '') {
|
32
|
global $data, $misc;
|
33
|
global $PHP_SELF, $lang;
|
34
|
|
35
|
$misc->printTrail('view');
|
36
|
$misc->printTitle($lang['stredit'],'pg.view.alter');
|
37
|
$misc->printMsg($msg);
|
38
|
|
39
|
$viewdata = $data->getView($_REQUEST['view']);
|
40
|
|
41
|
if ($viewdata->recordCount() > 0) {
|
42
|
|
43
|
if (!isset($_POST['formDefinition'])) {
|
44
|
$_POST['formDefinition'] = $viewdata->f['vwdefinition'];
|
45
|
$_POST['formComment'] = $viewdata->f['relcomment'];
|
46
|
}
|
47
|
|
48
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
49
|
echo "<table width=\"100%\">\n";
|
50
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strdefinition']}</th>\n";
|
51
|
echo "\t\t<td class=\"data1\"><textarea style=\"width: 100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\" wrap=\"virtual\">",
|
52
|
htmlspecialchars($_POST['formDefinition']), "</textarea></td>\n\t</tr>\n";
|
53
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
|
54
|
echo "\t\t<td class=\"data1\"><textarea rows=\"3\" cols=\"32\" name=\"formComment\" wrap=\"virtual\">",
|
55
|
htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n";
|
56
|
echo "</table>\n";
|
57
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n";
|
58
|
echo "<input type=\"hidden\" name=\"view\" value=\"", htmlspecialchars($_REQUEST['view']), "\" />\n";
|
59
|
echo $misc->form;
|
60
|
echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n";
|
61
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
62
|
echo "</form>\n";
|
63
|
}
|
64
|
else echo "<p>{$lang['strnodata']}</p>\n";
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* Allow the dumping of the data "in" a view
|
69
|
* NOTE:: PostgreSQL doesn't currently support dumping the data in a view
|
70
|
* so I have disabled the data related parts for now. In the future
|
71
|
* we should allow it conditionally if it becomes supported. This is
|
72
|
* a SMOP since it is based on pg_dump version not backend version.
|
73
|
*/
|
74
|
function doExport($msg = '') {
|
75
|
global $data, $misc;
|
76
|
global $PHP_SELF, $lang;
|
77
|
|
78
|
$misc->printTrail('view');
|
79
|
$misc->printTabs('view','export');
|
80
|
$misc->printMsg($msg);
|
81
|
|
82
|
echo "<form action=\"dataexport.php\" method=\"post\">\n";
|
83
|
echo "<table>\n";
|
84
|
echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n";
|
85
|
// Data only
|
86
|
echo "<!--\n";
|
87
|
echo "<tr><th class=\"data left\">";
|
88
|
echo "<input type=\"radio\" name=\"what\" value=\"dataonly\" />{$lang['strdataonly']}</th>\n";
|
89
|
echo "<td>{$lang['strformat']}</td>\n";
|
90
|
echo "<td><select name=\"d_format\" >\n";
|
91
|
echo "<option value=\"copy\">COPY</option>\n";
|
92
|
echo "<option value=\"sql\">SQL</option>\n";
|
93
|
echo "<option value=\"csv\">CSV</option>\n";
|
94
|
echo "<option value=\"tab\">{$lang['strtabbed']}</option>\n";
|
95
|
echo "<option value=\"html\">XHTML</option>\n";
|
96
|
echo "<option value=\"xml\">XML</option>\n";
|
97
|
echo "</select>\n</td>\n</tr>\n";
|
98
|
echo "-->\n";
|
99
|
|
100
|
// Structure only
|
101
|
echo "<tr><th class=\"data left\"><input type=\"radio\" name=\"what\" value=\"structureonly\" checked=\"checked\" />{$lang['strstructureonly']}</th>\n";
|
102
|
echo "<td>{$lang['strdrop']}</td><td><input type=\"checkbox\" name=\"s_clean\" /></td>\n</tr>\n";
|
103
|
// Structure and data
|
104
|
echo "<!--\n";
|
105
|
echo "<tr><th class=\"data left\" rowspan=\"2\">";
|
106
|
echo "<input type=\"radio\" name=\"what\" value=\"structureanddata\" />{$lang['strstructureanddata']}</th>\n";
|
107
|
echo "<td>{$lang['strformat']}</td>\n";
|
108
|
echo "<td><select name=\"sd_format\">\n";
|
109
|
echo "<option value=\"copy\">COPY</option>\n";
|
110
|
echo "<option value=\"sql\">SQL</option>\n";
|
111
|
echo "</select>\n</td>\n</tr>\n";
|
112
|
echo "<td>{$lang['strdrop']}</td><td><input type=\"checkbox\" name=\"sd_clean\" /></td>\n</tr>\n";
|
113
|
echo "-->\n";
|
114
|
echo "</table>\n";
|
115
|
|
116
|
echo "<h3>{$lang['stroptions']}</h3>\n";
|
117
|
echo "<p><input type=\"radio\" name=\"output\" value=\"show\" checked=\"checked\" />{$lang['strshow']}\n";
|
118
|
echo "<br/><input type=\"radio\" name=\"output\" value=\"download\" />{$lang['strdownload']}</p>\n";
|
119
|
|
120
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
|
121
|
echo $misc->form;
|
122
|
echo "<input type=\"hidden\" name=\"subject\" value=\"view\" />\n";
|
123
|
echo "<input type=\"hidden\" name=\"view\" value=\"", htmlspecialchars($_REQUEST['view']), "\" />\n";
|
124
|
echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
|
125
|
echo "</form>\n";
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* Show definition for a view
|
130
|
*/
|
131
|
function doDefinition($msg = '') {
|
132
|
global $data, $misc;
|
133
|
global $PHP_SELF, $lang;
|
134
|
|
135
|
// Get view
|
136
|
$vdata = $data->getView($_REQUEST['view']);
|
137
|
|
138
|
$misc->printTrail('view');
|
139
|
$misc->printTabs('view','definition');
|
140
|
$misc->printMsg($msg);
|
141
|
|
142
|
if ($vdata->recordCount() > 0) {
|
143
|
// Show comment if any
|
144
|
if ($vdata->f['relcomment'] !== null)
|
145
|
echo "<p class=\"comment\">", $misc->printVal($vdata->f['relcomment']), "</p>\n";
|
146
|
|
147
|
echo "<table width=\"100%\">\n";
|
148
|
echo "<tr><th class=\"data\">{$lang['strdefinition']}</th></tr>\n";
|
149
|
echo "<tr><td class=\"data1\">", $misc->printVal($vdata->f['vwdefinition']), "</td></tr>\n";
|
150
|
echo "</table>\n";
|
151
|
}
|
152
|
else echo "<p>{$lang['strnodata']}</p>\n";
|
153
|
|
154
|
echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?action=edit&{$misc->href}&view=",
|
155
|
urlencode($_REQUEST['view']), "\">{$lang['stralter']}</a></p>\n";
|
156
|
}
|
157
|
|
158
|
/**
|
159
|
* Displays a screen where they can alter a column in a view
|
160
|
*/
|
161
|
function doProperties($msg = '') {
|
162
|
global $data, $misc;
|
163
|
global $PHP_SELF, $lang;
|
164
|
|
165
|
if (!isset($_REQUEST['stage'])) $_REQUEST['stage'] = 1;
|
166
|
|
167
|
switch ($_REQUEST['stage']) {
|
168
|
case 1:
|
169
|
global $lang;
|
170
|
|
171
|
$misc->printTrail('column');
|
172
|
$misc->printTitle($lang['straltercolumn'],'pg.column.alter');
|
173
|
$misc->printMsg($msg);
|
174
|
|
175
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
176
|
|
177
|
// Output view header
|
178
|
echo "<table>\n<tr>";
|
179
|
echo "<tr><th class=\"data required\">{$lang['strname']}</th><th class=\"data required\">{$lang['strtype']}</th>";
|
180
|
echo "<th class=\"data\">{$lang['strdefault']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>";
|
181
|
|
182
|
$column = $data->getTableAttributes($_REQUEST['view'], $_REQUEST['column']);
|
183
|
|
184
|
if (!isset($_REQUEST['default'])) {
|
185
|
$_REQUEST['field'] = $column->f['attname'];
|
186
|
$_REQUEST['default'] = $_REQUEST['olddefault'] = $column->f['adsrc'];
|
187
|
$_REQUEST['comment'] = $column->f['comment'];
|
188
|
}
|
189
|
|
190
|
// If name of view column is editable, make it a field
|
191
|
if ($data->hasViewColumnRename()) {
|
192
|
echo "<tr><td><input name=\"field\" size=\"32\" value=\"",
|
193
|
htmlspecialchars($_REQUEST['field']), "\" /></td>";
|
194
|
}
|
195
|
else {
|
196
|
echo "<tr><td>", htmlspecialchars($column->f['attname']), "</td>";
|
197
|
}
|
198
|
echo "<td>", $misc->printVal($data->formatType($column->f['type'], $column->f['atttypmod'])), "</td>";
|
199
|
echo "<td><input name=\"default\" size=\"20\" value=\"",
|
200
|
htmlspecialchars($_REQUEST['default']), "\" /></td>";
|
201
|
echo "<td><input name=\"comment\" size=\"32\" value=\"",
|
202
|
htmlspecialchars($_REQUEST['comment']), "\" /></td>";
|
203
|
|
204
|
echo "</table>\n";
|
205
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"properties\" />\n";
|
206
|
echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n";
|
207
|
echo $misc->form;
|
208
|
echo "<input type=\"hidden\" name=\"view\" value=\"", htmlspecialchars($_REQUEST['view']), "\" />\n";
|
209
|
echo "<input type=\"hidden\" name=\"column\" value=\"", htmlspecialchars($_REQUEST['column']), "\" />\n";
|
210
|
echo "<input type=\"hidden\" name=\"olddefault\" value=\"", htmlspecialchars($_REQUEST['olddefault']), "\" />\n";
|
211
|
echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n";
|
212
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
213
|
echo "</form>\n";
|
214
|
|
215
|
break;
|
216
|
case 2:
|
217
|
global $data, $lang;
|
218
|
|
219
|
// Check inputs
|
220
|
if ($data->hasViewColumnRename() && trim($_REQUEST['field']) == '') {
|
221
|
$_REQUEST['stage'] = 1;
|
222
|
doProperties($lang['strcolneedsname']);
|
223
|
return;
|
224
|
}
|
225
|
|
226
|
// If we aren't able to rename view columns, set new name to equal old name always
|
227
|
if (!$data->hasViewColumnRename()) $_REQUEST['field'] = $_REQUEST['column'];
|
228
|
|
229
|
// Alter the view column
|
230
|
$status = $data->alterColumn($_REQUEST['view'], $_REQUEST['column'], $_REQUEST['field'],
|
231
|
false, false, $_REQUEST['default'], $_REQUEST['olddefault'],
|
232
|
'', '', '', '', $_REQUEST['comment']);
|
233
|
if ($status == 0)
|
234
|
doDefault($lang['strcolumnaltered']);
|
235
|
else {
|
236
|
$_REQUEST['stage'] = 1;
|
237
|
doProperties($lang['strcolumnalteredbad']);
|
238
|
return;
|
239
|
}
|
240
|
break;
|
241
|
default:
|
242
|
echo "<p>{$lang['strinvalidparam']}</p>\n";
|
243
|
}
|
244
|
}
|
245
|
|
246
|
/**
|
247
|
* Show view definition and virtual columns
|
248
|
*/
|
249
|
function doDefault($msg = '') {
|
250
|
global $data, $misc;
|
251
|
global $PHP_SELF, $lang;
|
252
|
|
253
|
function attPre(&$rowdata) {
|
254
|
global $data;
|
255
|
$rowdata->f['+type'] = $data->formatType($rowdata->f['type'], $rowdata->f['atttypmod']);
|
256
|
}
|
257
|
|
258
|
$misc->printTrail('view');
|
259
|
$misc->printTabs('view','columns');
|
260
|
$misc->printMsg($msg);
|
261
|
|
262
|
// Get view
|
263
|
$vdata = $data->getView($_REQUEST['view']);
|
264
|
// Get columns (using same method for getting a view)
|
265
|
$attrs = $data->getTableAttributes($_REQUEST['view']);
|
266
|
|
267
|
// Show comment if any
|
268
|
if ($vdata->f['relcomment'] !== null)
|
269
|
echo "<p class=\"comment\">", $misc->printVal($vdata->f['relcomment']), "</p>\n";
|
270
|
|
271
|
$columns = array(
|
272
|
'column' => array(
|
273
|
'title' => $lang['strcolumn'],
|
274
|
'field' => 'attname',
|
275
|
),
|
276
|
'type' => array(
|
277
|
'title' => $lang['strtype'],
|
278
|
'field' => '+type',
|
279
|
),
|
280
|
'default' => array(
|
281
|
'title' => $lang['strdefault'],
|
282
|
'field' => 'adsrc',
|
283
|
),
|
284
|
'actions' => array(
|
285
|
'title' => $lang['stractions'],
|
286
|
),
|
287
|
'comment' => array(
|
288
|
'title' => $lang['strcomment'],
|
289
|
'field' => 'comment',
|
290
|
),
|
291
|
);
|
292
|
|
293
|
$actions = array(
|
294
|
'alter' => array(
|
295
|
'title' => $lang['stralter'],
|
296
|
'url' => "{$PHP_SELF}?action=properties&{$misc->href}&view=".urlencode($_REQUEST['view'])."&",
|
297
|
'vars' => array('column' => 'attname'),
|
298
|
),
|
299
|
);
|
300
|
|
301
|
$misc->printTable($attrs, $columns, $actions, null, 'attPre');
|
302
|
|
303
|
echo "<br />\n";
|
304
|
|
305
|
echo "<ul>\n";
|
306
|
$return_url = urlencode("viewproperties.php?{$misc->href}&view=" . urlencode($_REQUEST['view']));
|
307
|
echo "\t<li><a href=\"display.php?{$misc->href}&view=", urlencode($_REQUEST['view']), "&subject=view&return_url={$return_url}&return_desc=",
|
308
|
urlencode($lang['strback']), "\">{$lang['strbrowse']}</a></li>\n";
|
309
|
echo "\t<li><a href=\"views.php?action=confselectrows&{$misc->href}&view=", urlencode($_REQUEST['view']),"\">{$lang['strselect']}</a></li>\n";
|
310
|
echo "\t<li><a href=\"views.php?action=confirm_drop&{$misc->href}&view=", urlencode($_REQUEST['view']),"\">{$lang['strdrop']}</a></li>\n";
|
311
|
echo "</ul>\n";
|
312
|
}
|
313
|
|
314
|
$misc->printHeader($lang['strviews'] . ' - ' . $_REQUEST['view']);
|
315
|
$misc->printBody();
|
316
|
|
317
|
switch ($action) {
|
318
|
case 'save_edit':
|
319
|
if (isset($_POST['cancel'])) doDefinition();
|
320
|
else doSaveEdit();
|
321
|
break;
|
322
|
case 'edit':
|
323
|
doEdit();
|
324
|
break;
|
325
|
case 'export':
|
326
|
doExport();
|
327
|
break;
|
328
|
case 'definition':
|
329
|
doDefinition();
|
330
|
break;
|
331
|
case 'properties':
|
332
|
if (isset($_POST['cancel'])) doDefault();
|
333
|
else doProperties();
|
334
|
break;
|
335
|
case 'drop':
|
336
|
if (isset($_POST['drop'])) doDrop(false);
|
337
|
else doDefault();
|
338
|
break;
|
339
|
case 'confirm_drop':
|
340
|
doDrop(true);
|
341
|
break;
|
342
|
default:
|
343
|
doDefault();
|
344
|
break;
|
345
|
}
|
346
|
|
347
|
$misc->printFooter();
|
348
|
|
349
|
?>
|