|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* PHPPgAdmin v6.0.0-beta.30 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\Controller; |
|
8
|
|
|
|
|
9
|
|
|
use PHPPgAdmin\Decorators\Decorator; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Base controller class. |
|
13
|
|
|
*/ |
|
|
|
|
|
|
14
|
|
|
class MaterializedviewpropertiesController extends BaseController |
|
15
|
|
|
{ |
|
16
|
|
|
public $controller_name = 'MaterializedviewpropertiesController'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Default method to render the controller according to the action parameter. |
|
20
|
|
|
*/ |
|
21
|
|
|
public function render() |
|
22
|
|
|
{ |
|
23
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
$lang = $this->lang; |
|
26
|
|
|
|
|
27
|
|
|
$action = $this->action; |
|
28
|
|
|
if ('tree' == $action) { |
|
29
|
|
|
return $this->doTree(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$this->printHeader($lang['strviews'].' - '.$_REQUEST['matview']); |
|
33
|
|
|
$this->printBody(); |
|
34
|
|
|
|
|
35
|
|
|
switch ($action) { |
|
36
|
|
|
case 'save_edit': |
|
37
|
|
|
if (isset($_POST['cancel'])) { |
|
38
|
|
|
$this->doDefinition(); |
|
39
|
|
|
} else { |
|
40
|
|
|
$this->doSaveEdit(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
break; |
|
44
|
|
|
case 'edit': |
|
45
|
|
|
$this->doEdit(); |
|
46
|
|
|
|
|
47
|
|
|
break; |
|
48
|
|
|
case 'export': |
|
49
|
|
|
$this->doExport(); |
|
50
|
|
|
|
|
51
|
|
|
break; |
|
52
|
|
|
case 'definition': |
|
53
|
|
|
$this->doDefinition(); |
|
54
|
|
|
|
|
55
|
|
|
break; |
|
56
|
|
|
case 'properties': |
|
57
|
|
|
if (isset($_POST['cancel'])) { |
|
58
|
|
|
$this->doDefault(); |
|
59
|
|
|
} else { |
|
60
|
|
|
$this->doProperties(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
break; |
|
64
|
|
|
case 'alter': |
|
65
|
|
|
if (isset($_POST['alter'])) { |
|
66
|
|
|
$this->doAlter(false); |
|
67
|
|
|
} else { |
|
68
|
|
|
$this->doDefault(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
break; |
|
72
|
|
|
case 'confirm_alter': |
|
73
|
|
|
doAlter(true); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
break; |
|
76
|
|
|
case 'drop': |
|
77
|
|
|
if (isset($_POST['drop'])) { |
|
78
|
|
|
$this->doDrop(false); |
|
|
|
|
|
|
79
|
|
|
} else { |
|
80
|
|
|
$this->doDefault(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
break; |
|
84
|
|
|
case 'confirm_drop': |
|
85
|
|
|
$this->doDrop(true); |
|
86
|
|
|
|
|
87
|
|
|
break; |
|
88
|
|
|
default: |
|
89
|
|
|
$this->doDefault(); |
|
90
|
|
|
|
|
91
|
|
|
break; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$this->printFooter(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Show view definition and virtual columns. |
|
99
|
|
|
* |
|
100
|
|
|
* @param mixed $msg |
|
|
|
|
|
|
101
|
|
|
*/ |
|
102
|
|
|
public function doDefault($msg = '') |
|
103
|
|
|
{ |
|
104
|
|
|
$conf = $this->conf; |
|
105
|
|
|
|
|
106
|
|
|
$lang = $this->lang; |
|
107
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
108
|
|
|
|
|
109
|
|
|
$attPre = function (&$rowdata) use ($data) { |
|
110
|
|
|
$rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']); |
|
111
|
|
|
}; |
|
112
|
|
|
|
|
113
|
|
|
$this->printTrail('matview'); |
|
114
|
|
|
$this->printTabs('matview', 'columns'); |
|
115
|
|
|
$this->printMsg($msg); |
|
116
|
|
|
|
|
117
|
|
|
// Get view |
|
118
|
|
|
$vdata = $data->getView($_REQUEST['matview']); |
|
119
|
|
|
// Get columns (using same method for getting a view) |
|
120
|
|
|
$attrs = $data->getTableAttributes($_REQUEST['matview']); |
|
121
|
|
|
|
|
122
|
|
|
// Show comment if any |
|
123
|
|
|
if (null !== $vdata->fields['relcomment']) { |
|
124
|
|
|
echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), "</p>\n"; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
$columns = [ |
|
128
|
|
|
'column' => [ |
|
129
|
|
|
'title' => $lang['strcolumn'], |
|
130
|
|
|
'field' => Decorator::field('attname'), |
|
131
|
|
|
'url' => "colproperties.php?subject=column&{$this->misc->href}&view=".urlencode($_REQUEST['matview']).'&', |
|
132
|
|
|
'vars' => ['column' => 'attname'], |
|
133
|
|
|
], |
|
134
|
|
|
'type' => [ |
|
135
|
|
|
'title' => $lang['strtype'], |
|
136
|
|
|
'field' => Decorator::field('+type'), |
|
137
|
|
|
], |
|
138
|
|
|
'default' => [ |
|
139
|
|
|
'title' => $lang['strdefault'], |
|
140
|
|
|
'field' => Decorator::field('adsrc'), |
|
141
|
|
|
], |
|
142
|
|
|
'actions' => [ |
|
143
|
|
|
'title' => $lang['stractions'], |
|
144
|
|
|
], |
|
145
|
|
|
'comment' => [ |
|
146
|
|
|
'title' => $lang['strcomment'], |
|
147
|
|
|
'field' => Decorator::field('comment'), |
|
148
|
|
|
], |
|
149
|
|
|
]; |
|
150
|
|
|
|
|
151
|
|
|
$actions = [ |
|
152
|
|
|
'alter' => [ |
|
153
|
|
|
'content' => $lang['stralter'], |
|
154
|
|
|
'attr' => [ |
|
155
|
|
|
'href' => [ |
|
156
|
|
|
'url' => 'materializedviewproperties.php', |
|
157
|
|
|
'urlvars' => [ |
|
158
|
|
|
'action' => 'properties', |
|
159
|
|
|
'view' => $_REQUEST['matview'], |
|
160
|
|
|
'column' => Decorator::field('attname'), |
|
161
|
|
|
], |
|
162
|
|
|
], |
|
163
|
|
|
], |
|
164
|
|
|
], |
|
165
|
|
|
]; |
|
166
|
|
|
|
|
167
|
|
|
echo $this->printTable($attrs, $columns, $actions, 'materializedviewproperties-materializedviewproperties', null, $attPre); |
|
168
|
|
|
|
|
169
|
|
|
echo "<br />\n"; |
|
170
|
|
|
|
|
171
|
|
|
$navlinks = [ |
|
172
|
|
|
'browse' => [ |
|
173
|
|
|
'attr' => [ |
|
174
|
|
|
'href' => [ |
|
175
|
|
|
'url' => 'display.php', |
|
176
|
|
|
'urlvars' => [ |
|
177
|
|
|
'server' => $_REQUEST['server'], |
|
178
|
|
|
'database' => $_REQUEST['database'], |
|
179
|
|
|
'schema' => $_REQUEST['schema'], |
|
180
|
|
|
'matview' => $_REQUEST['matview'], |
|
181
|
|
|
'subject' => 'matview', |
|
182
|
|
|
'return' => 'matview', |
|
183
|
|
|
], |
|
184
|
|
|
], |
|
185
|
|
|
], |
|
186
|
|
|
'content' => $lang['strbrowse'], |
|
187
|
|
|
], |
|
188
|
|
|
'select' => [ |
|
189
|
|
|
'attr' => [ |
|
190
|
|
|
'href' => [ |
|
191
|
|
|
'url' => 'materializedviews.php', |
|
192
|
|
|
'urlvars' => [ |
|
193
|
|
|
'action' => 'confselectrows', |
|
194
|
|
|
'server' => $_REQUEST['server'], |
|
195
|
|
|
'database' => $_REQUEST['database'], |
|
196
|
|
|
'schema' => $_REQUEST['schema'], |
|
197
|
|
|
'matview' => $_REQUEST['matview'], |
|
198
|
|
|
], |
|
199
|
|
|
], |
|
200
|
|
|
], |
|
201
|
|
|
'content' => $lang['strselect'], |
|
202
|
|
|
], |
|
203
|
|
|
'drop' => [ |
|
204
|
|
|
'attr' => [ |
|
205
|
|
|
'href' => [ |
|
206
|
|
|
'url' => 'materializedviews.php', |
|
207
|
|
|
'urlvars' => [ |
|
208
|
|
|
'action' => 'confirm_drop', |
|
209
|
|
|
'server' => $_REQUEST['server'], |
|
210
|
|
|
'database' => $_REQUEST['database'], |
|
211
|
|
|
'schema' => $_REQUEST['schema'], |
|
212
|
|
|
'matview' => $_REQUEST['matview'], |
|
213
|
|
|
], |
|
214
|
|
|
], |
|
215
|
|
|
], |
|
216
|
|
|
'content' => $lang['strdrop'], |
|
217
|
|
|
], |
|
218
|
|
|
'alter' => [ |
|
219
|
|
|
'attr' => [ |
|
220
|
|
|
'href' => [ |
|
221
|
|
|
'url' => 'materializedviewproperties.php', |
|
222
|
|
|
'urlvars' => [ |
|
223
|
|
|
'action' => 'confirm_alter', |
|
224
|
|
|
'server' => $_REQUEST['server'], |
|
225
|
|
|
'database' => $_REQUEST['database'], |
|
226
|
|
|
'schema' => $_REQUEST['schema'], |
|
227
|
|
|
'matview' => $_REQUEST['matview'], |
|
228
|
|
|
], |
|
229
|
|
|
], |
|
230
|
|
|
], |
|
231
|
|
|
'content' => $lang['stralter'], |
|
232
|
|
|
], |
|
233
|
|
|
]; |
|
234
|
|
|
|
|
235
|
|
|
$this->printNavLinks($navlinks, 'materializedviewproperties-materializedviewproperties', get_defined_vars()); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
public function doTree() |
|
|
|
|
|
|
239
|
|
|
{ |
|
240
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
241
|
|
|
|
|
242
|
|
|
$lang = $this->lang; |
|
|
|
|
|
|
243
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
244
|
|
|
|
|
245
|
|
|
$reqvars = $this->misc->getRequestVars('column'); |
|
246
|
|
|
$columns = $data->getTableAttributes($_REQUEST['matview']); |
|
247
|
|
|
|
|
248
|
|
|
$attrs = [ |
|
249
|
|
|
'text' => Decorator::field('attname'), |
|
250
|
|
|
'action' => Decorator::actionurl( |
|
251
|
|
|
'colproperties.php', |
|
252
|
|
|
$reqvars, |
|
253
|
|
|
[ |
|
254
|
|
|
'view' => $_REQUEST['matview'], |
|
255
|
|
|
'column' => Decorator::field('attname'), |
|
256
|
|
|
] |
|
257
|
|
|
), |
|
258
|
|
|
'icon' => 'Column', |
|
259
|
|
|
'iconAction' => Decorator::url( |
|
260
|
|
|
'display.php', |
|
261
|
|
|
$reqvars, |
|
262
|
|
|
[ |
|
263
|
|
|
'view' => $_REQUEST['matview'], |
|
264
|
|
|
'column' => Decorator::field('attname'), |
|
265
|
|
|
'query' => Decorator::replace( |
|
266
|
|
|
'SELECT "%column%", count(*) AS "count" FROM %view% GROUP BY "%column%" ORDER BY "%column%"', |
|
267
|
|
|
[ |
|
268
|
|
|
'%column%' => Decorator::field('attname'), |
|
269
|
|
|
'%view%' => $_REQUEST['matview'], |
|
270
|
|
|
] |
|
271
|
|
|
), |
|
272
|
|
|
] |
|
273
|
|
|
), |
|
274
|
|
|
'toolTip' => Decorator::field('comment'), |
|
275
|
|
|
]; |
|
276
|
|
|
|
|
277
|
|
|
return $this->printTree($columns, $attrs, 'viewcolumns'); |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* Function to save after editing a view. |
|
282
|
|
|
*/ |
|
283
|
|
|
public function doSaveEdit() |
|
284
|
|
|
{ |
|
285
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
286
|
|
|
|
|
287
|
|
|
$lang = $this->lang; |
|
288
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
289
|
|
|
|
|
290
|
|
|
$status = $data->setView($_POST['view'], $_POST['formDefinition'], $_POST['formComment']); |
|
291
|
|
|
if (0 == $status) { |
|
292
|
|
|
$this->doDefinition($lang['strviewupdated']); |
|
293
|
|
|
} else { |
|
294
|
|
|
$this->doEdit($lang['strviewupdatedbad']); |
|
295
|
|
|
} |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Function to allow editing of a view. |
|
300
|
|
|
* |
|
301
|
|
|
* @param mixed $msg |
|
|
|
|
|
|
302
|
|
|
*/ |
|
303
|
|
|
public function doEdit($msg = '') |
|
304
|
|
|
{ |
|
305
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
306
|
|
|
|
|
307
|
|
|
$lang = $this->lang; |
|
308
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
309
|
|
|
|
|
310
|
|
|
$this->printTrail('view'); |
|
311
|
|
|
$this->printTitle($lang['stredit'], 'pg.matview.alter'); |
|
312
|
|
|
$this->printMsg($msg); |
|
313
|
|
|
|
|
314
|
|
|
$viewdata = $data->getView($_REQUEST['matview']); |
|
315
|
|
|
|
|
316
|
|
|
if ($viewdata->recordCount() > 0) { |
|
317
|
|
|
if (!isset($_POST['formDefinition'])) { |
|
318
|
|
|
$_POST['formDefinition'] = $viewdata->fields['vwdefinition']; |
|
319
|
|
|
$_POST['formComment'] = $viewdata->fields['relcomment']; |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
echo '<form action="'.\SUBFOLDER."/src/views/materializedviewproperties.php\" method=\"post\">\n"; |
|
323
|
|
|
echo "<table style=\"width: 100%\">\n"; |
|
324
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strdefinition']}</th>\n"; |
|
325
|
|
|
echo "\t\t<td class=\"data1\"><textarea style=\"width: 100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\">", |
|
326
|
|
|
htmlspecialchars($_POST['formDefinition']), "</textarea></td>\n\t</tr>\n"; |
|
327
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n"; |
|
328
|
|
|
echo "\t\t<td class=\"data1\"><textarea rows=\"3\" cols=\"32\" name=\"formComment\">", |
|
329
|
|
|
htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n"; |
|
330
|
|
|
echo "</table>\n"; |
|
331
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n"; |
|
332
|
|
|
echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n"; |
|
333
|
|
|
echo $this->misc->form; |
|
334
|
|
|
echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n"; |
|
335
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
|
336
|
|
|
echo "</form>\n"; |
|
337
|
|
|
} else { |
|
338
|
|
|
echo "<p>{$lang['strnodata']}</p>\n"; |
|
339
|
|
|
} |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
/** |
|
343
|
|
|
* Allow the dumping of the data "in" a view |
|
344
|
|
|
* NOTE:: PostgreSQL doesn't currently support dumping the data in a view |
|
345
|
|
|
* so I have disabled the data related parts for now. In the future |
|
346
|
|
|
* we should allow it conditionally if it becomes supported. This is |
|
347
|
|
|
* a SMOP since it is based on pg_dump version not backend version. |
|
348
|
|
|
* |
|
349
|
|
|
* @param mixed $msg |
|
|
|
|
|
|
350
|
|
|
*/ |
|
351
|
|
|
public function doExport($msg = '') |
|
352
|
|
|
{ |
|
353
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
354
|
|
|
|
|
355
|
|
|
$lang = $this->lang; |
|
356
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
|
|
|
|
|
357
|
|
|
|
|
358
|
|
|
$this->printTrail('view'); |
|
359
|
|
|
$this->printTabs('view', 'export'); |
|
360
|
|
|
$this->printMsg($msg); |
|
361
|
|
|
|
|
362
|
|
|
echo '<form action="'.\SUBFOLDER."/src/views/dataexport.php\" method=\"post\">\n"; |
|
363
|
|
|
echo "<table>\n"; |
|
364
|
|
|
echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n"; |
|
365
|
|
|
// Data only |
|
366
|
|
|
echo "<!--\n"; |
|
367
|
|
|
echo '<tr><th class="data left">'; |
|
368
|
|
|
echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n"; |
|
369
|
|
|
echo "<td>{$lang['strformat']}</td>\n"; |
|
370
|
|
|
echo "<td><select name=\"d_format\" >\n"; |
|
371
|
|
|
echo "<option value=\"copy\">COPY</option>\n"; |
|
372
|
|
|
echo "<option value=\"sql\">SQL</option>\n"; |
|
373
|
|
|
echo "<option value=\"csv\">CSV</option>\n"; |
|
374
|
|
|
echo "<option value=\"tab\">{$lang['strtabbed']}</option>\n"; |
|
375
|
|
|
echo "<option value=\"html\">XHTML</option>\n"; |
|
376
|
|
|
echo "<option value=\"xml\">XML</option>\n"; |
|
377
|
|
|
echo "</select>\n</td>\n</tr>\n"; |
|
378
|
|
|
echo "-->\n"; |
|
379
|
|
|
|
|
380
|
|
|
// Structure only |
|
381
|
|
|
echo "<tr><th class=\"data left\"><input type=\"radio\" id=\"what2\" name=\"what\" value=\"structureonly\" checked=\"checked\" /><label for=\"what2\">{$lang['strstructureonly']}</label></th>\n"; |
|
382
|
|
|
echo "<td><label for=\"s_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /></td>\n</tr>\n"; |
|
383
|
|
|
// Structure and data |
|
384
|
|
|
echo "<!--\n"; |
|
385
|
|
|
echo '<tr><th class="data left" rowspan="2">'; |
|
386
|
|
|
echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n"; |
|
387
|
|
|
echo "<td>{$lang['strformat']}</td>\n"; |
|
388
|
|
|
echo "<td><select name=\"sd_format\">\n"; |
|
389
|
|
|
echo "<option value=\"copy\">COPY</option>\n"; |
|
390
|
|
|
echo "<option value=\"sql\">SQL</option>\n"; |
|
391
|
|
|
echo "</select>\n</td>\n</tr>\n"; |
|
392
|
|
|
echo "<td><label for=\"sd_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"sd_clean\" name=\"sd_clean\" /></td>\n</tr>\n"; |
|
393
|
|
|
echo "-->\n"; |
|
394
|
|
|
echo "</table>\n"; |
|
395
|
|
|
|
|
396
|
|
|
echo "<h3>{$lang['stroptions']}</h3>\n"; |
|
397
|
|
|
echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n"; |
|
398
|
|
|
echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label></p>\n"; |
|
399
|
|
|
|
|
400
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n"; |
|
401
|
|
|
echo $this->misc->form; |
|
402
|
|
|
echo "<input type=\"hidden\" name=\"subject\" value=\"view\" />\n"; |
|
403
|
|
|
echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n"; |
|
404
|
|
|
echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n"; |
|
405
|
|
|
echo "</form>\n"; |
|
406
|
|
|
} |
|
407
|
|
|
|
|
408
|
|
|
/** |
|
409
|
|
|
* Show definition for a view. |
|
410
|
|
|
* |
|
411
|
|
|
* @param mixed $msg |
|
|
|
|
|
|
412
|
|
|
*/ |
|
413
|
|
|
public function doDefinition($msg = '') |
|
414
|
|
|
{ |
|
415
|
|
|
$conf = $this->conf; |
|
416
|
|
|
|
|
417
|
|
|
$lang = $this->lang; |
|
418
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
419
|
|
|
|
|
420
|
|
|
// Get view |
|
421
|
|
|
$vdata = $data->getView($_REQUEST['matview']); |
|
422
|
|
|
|
|
423
|
|
|
$this->printTrail('view'); |
|
424
|
|
|
$this->printTabs('view', 'definition'); |
|
425
|
|
|
$this->printMsg($msg); |
|
426
|
|
|
|
|
427
|
|
|
if ($vdata->recordCount() > 0) { |
|
428
|
|
|
// Show comment if any |
|
429
|
|
|
if (null !== $vdata->fields['relcomment']) { |
|
430
|
|
|
echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), "</p>\n"; |
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
echo "<table style=\"width: 100%\">\n"; |
|
434
|
|
|
echo "<tr><th class=\"data\">{$lang['strdefinition']}</th></tr>\n"; |
|
435
|
|
|
echo '<tr><td class="data1">', $this->misc->printVal($vdata->fields['vwdefinition']), "</td></tr>\n"; |
|
436
|
|
|
echo "</table>\n"; |
|
437
|
|
|
} else { |
|
438
|
|
|
echo "<p>{$lang['strnodata']}</p>\n"; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
$this->printNavLinks(['alter' => [ |
|
|
|
|
|
|
442
|
|
|
'attr' => [ |
|
443
|
|
|
'href' => [ |
|
444
|
|
|
'url' => 'materializedviewproperties.php', |
|
445
|
|
|
'urlvars' => [ |
|
446
|
|
|
'action' => 'edit', |
|
447
|
|
|
'server' => $_REQUEST['server'], |
|
448
|
|
|
'database' => $_REQUEST['database'], |
|
449
|
|
|
'schema' => $_REQUEST['schema'], |
|
450
|
|
|
'view' => $_REQUEST['matview'], |
|
451
|
|
|
], |
|
452
|
|
|
], |
|
453
|
|
|
], |
|
454
|
|
|
'content' => $lang['stralter'], |
|
455
|
|
|
]], 'materializedviewproperties-definition', get_defined_vars()); |
|
|
|
|
|
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
/** |
|
459
|
|
|
* Displays a screen where they can alter a column in a view. |
|
460
|
|
|
* |
|
461
|
|
|
* @param mixed $msg |
|
|
|
|
|
|
462
|
|
|
*/ |
|
463
|
|
|
public function doProperties($msg = '') |
|
464
|
|
|
{ |
|
465
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
466
|
|
|
|
|
467
|
|
|
$lang = $this->lang; |
|
468
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
469
|
|
|
|
|
470
|
|
|
if (!isset($_REQUEST['stage'])) { |
|
471
|
|
|
$_REQUEST['stage'] = 1; |
|
472
|
|
|
} |
|
473
|
|
|
|
|
474
|
|
|
switch ($_REQUEST['stage']) { |
|
475
|
|
|
case 1: |
|
476
|
|
|
|
|
477
|
|
|
$this->printTrail('column'); |
|
478
|
|
|
$this->printTitle($lang['stralter'], 'pg.column.alter'); |
|
479
|
|
|
$this->printMsg($msg); |
|
480
|
|
|
|
|
481
|
|
|
echo '<form action="'.\SUBFOLDER."/src/views/materializedviewproperties.php\" method=\"post\">\n"; |
|
482
|
|
|
|
|
483
|
|
|
// Output view header |
|
484
|
|
|
echo "<table>\n"; |
|
485
|
|
|
echo "<tr><th class=\"data required\">{$lang['strname']}</th><th class=\"data required\">{$lang['strtype']}</th>"; |
|
486
|
|
|
echo "<th class=\"data\">{$lang['strdefault']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>"; |
|
487
|
|
|
|
|
488
|
|
|
$column = $data->getTableAttributes($_REQUEST['matview'], $_REQUEST['column']); |
|
489
|
|
|
|
|
490
|
|
|
if (!isset($_REQUEST['default'])) { |
|
491
|
|
|
$_REQUEST['field'] = $column->fields['attname']; |
|
492
|
|
|
$_REQUEST['default'] = $_REQUEST['olddefault'] = $column->fields['adsrc']; |
|
493
|
|
|
$_REQUEST['comment'] = $column->fields['comment']; |
|
494
|
|
|
} |
|
495
|
|
|
|
|
496
|
|
|
echo '<tr><td><input name="field" size="32" value="', |
|
497
|
|
|
htmlspecialchars($_REQUEST['field']), '" /></td>'; |
|
498
|
|
|
|
|
499
|
|
|
echo '<td>', $this->misc->printVal($data->formatType($column->fields['type'], $column->fields['atttypmod'])), '</td>'; |
|
500
|
|
|
echo '<td><input name="default" size="20" value="', |
|
501
|
|
|
htmlspecialchars($_REQUEST['default']), '" /></td>'; |
|
502
|
|
|
echo '<td><input name="comment" size="32" value="', |
|
503
|
|
|
htmlspecialchars($_REQUEST['comment']), '" /></td>'; |
|
504
|
|
|
|
|
505
|
|
|
echo "</table>\n"; |
|
506
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"properties\" />\n"; |
|
507
|
|
|
echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n"; |
|
508
|
|
|
echo $this->misc->form; |
|
509
|
|
|
echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n"; |
|
510
|
|
|
echo '<input type="hidden" name="column" value="', htmlspecialchars($_REQUEST['column']), "\" />\n"; |
|
511
|
|
|
echo '<input type="hidden" name="olddefault" value="', htmlspecialchars($_REQUEST['olddefault']), "\" />\n"; |
|
512
|
|
|
echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n"; |
|
513
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
|
514
|
|
|
echo "</form>\n"; |
|
515
|
|
|
|
|
516
|
|
|
break; |
|
517
|
|
|
case 2: |
|
518
|
|
|
|
|
519
|
|
|
// Check inputs |
|
520
|
|
|
if ('' == trim($_REQUEST['field'])) { |
|
521
|
|
|
$_REQUEST['stage'] = 1; |
|
522
|
|
|
$this->doProperties($lang['strcolneedsname']); |
|
523
|
|
|
|
|
524
|
|
|
return; |
|
525
|
|
|
} |
|
526
|
|
|
|
|
527
|
|
|
// Alter the view column |
|
528
|
|
|
list($status, $sql) = $data->alterColumn( |
|
529
|
|
|
$_REQUEST['matview'], |
|
530
|
|
|
$_REQUEST['column'], |
|
531
|
|
|
$_REQUEST['field'], |
|
532
|
|
|
false, |
|
533
|
|
|
false, |
|
534
|
|
|
$_REQUEST['default'], |
|
535
|
|
|
$_REQUEST['olddefault'], |
|
536
|
|
|
'', |
|
537
|
|
|
'', |
|
538
|
|
|
'', |
|
539
|
|
|
'', |
|
540
|
|
|
$_REQUEST['comment'] |
|
541
|
|
|
); |
|
542
|
|
|
if (0 == $status) { |
|
543
|
|
|
$this->doDefault($lang['strcolumnaltered']); |
|
544
|
|
|
} else { |
|
545
|
|
|
$_REQUEST['stage'] = 1; |
|
546
|
|
|
$this->doProperties($lang['strcolumnalteredbad']); |
|
547
|
|
|
|
|
548
|
|
|
return; |
|
549
|
|
|
} |
|
550
|
|
|
|
|
551
|
|
|
break; |
|
552
|
|
|
default: |
|
553
|
|
|
echo "<p>{$lang['strinvalidparam']}</p>\n"; |
|
554
|
|
|
} |
|
555
|
|
|
} |
|
556
|
|
|
|
|
557
|
|
|
public function doAlter($confirm = false, $msg = '') |
|
|
|
|
|
|
558
|
|
|
{ |
|
559
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
560
|
|
|
|
|
561
|
|
|
$lang = $this->lang; |
|
562
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
563
|
|
|
|
|
564
|
|
|
if ($confirm) { |
|
565
|
|
|
$this->printTrail('view'); |
|
566
|
|
|
$this->printTitle($lang['stralter'], 'pg.matview.alter'); |
|
567
|
|
|
$this->printMsg($msg); |
|
568
|
|
|
|
|
569
|
|
|
// Fetch view info |
|
570
|
|
|
$view = $data->getView($_REQUEST['matview']); |
|
571
|
|
|
|
|
572
|
|
|
if ($view->recordCount() > 0) { |
|
573
|
|
|
if (!isset($_POST['name'])) { |
|
574
|
|
|
$_POST['name'] = $view->fields['relname']; |
|
575
|
|
|
} |
|
576
|
|
|
|
|
577
|
|
|
if (!isset($_POST['owner'])) { |
|
578
|
|
|
$_POST['owner'] = $view->fields['relowner']; |
|
579
|
|
|
} |
|
580
|
|
|
|
|
581
|
|
|
if (!isset($_POST['newschema'])) { |
|
582
|
|
|
$_POST['newschema'] = $view->fields['nspname']; |
|
583
|
|
|
} |
|
584
|
|
|
|
|
585
|
|
|
if (!isset($_POST['comment'])) { |
|
586
|
|
|
$_POST['comment'] = $view->fields['relcomment']; |
|
587
|
|
|
} |
|
588
|
|
|
|
|
589
|
|
|
echo '<form action="'.\SUBFOLDER."/src/views/materializedviewproperties.php\" method=\"post\">\n"; |
|
590
|
|
|
echo "<table>\n"; |
|
591
|
|
|
echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n"; |
|
592
|
|
|
echo '<td class="data1">'; |
|
593
|
|
|
echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
|
594
|
|
|
htmlspecialchars($_POST['name']), "\" /></td></tr>\n"; |
|
595
|
|
|
|
|
596
|
|
|
if ($data->isSuperUser()) { |
|
597
|
|
|
// Fetch all users |
|
598
|
|
|
$users = $data->getUsers(); |
|
599
|
|
|
|
|
600
|
|
|
echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n"; |
|
601
|
|
|
echo '<td class="data1"><select name="owner">'; |
|
602
|
|
|
while (!$users->EOF) { |
|
603
|
|
|
$uname = $users->fields['usename']; |
|
604
|
|
|
echo '<option value="', htmlspecialchars($uname), '"', |
|
605
|
|
|
($uname == $_POST['owner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n"; |
|
606
|
|
|
$users->moveNext(); |
|
607
|
|
|
} |
|
608
|
|
|
echo "</select></td></tr>\n"; |
|
609
|
|
|
} |
|
610
|
|
|
|
|
611
|
|
|
if ($data->hasAlterTableSchema()) { |
|
612
|
|
|
$schemas = $data->getSchemas(); |
|
613
|
|
|
echo "<tr><th class=\"data left required\">{$lang['strschema']}</th>\n"; |
|
614
|
|
|
echo '<td class="data1"><select name="newschema">'; |
|
615
|
|
|
while (!$schemas->EOF) { |
|
616
|
|
|
$schema = $schemas->fields['nspname']; |
|
617
|
|
|
echo '<option value="', htmlspecialchars($schema), '"', |
|
618
|
|
|
($schema == $_POST['newschema']) ? ' selected="selected"' : '', '>', htmlspecialchars($schema), "</option>\n"; |
|
619
|
|
|
$schemas->moveNext(); |
|
620
|
|
|
} |
|
621
|
|
|
echo "</select></td></tr>\n"; |
|
622
|
|
|
} |
|
623
|
|
|
|
|
624
|
|
|
echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n"; |
|
625
|
|
|
echo '<td class="data1">'; |
|
626
|
|
|
echo '<textarea rows="3" cols="32" name="comment">', |
|
627
|
|
|
htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n"; |
|
628
|
|
|
echo "</table>\n"; |
|
629
|
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"alter\" />\n"; |
|
630
|
|
|
echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n"; |
|
631
|
|
|
echo $this->misc->form; |
|
632
|
|
|
echo "<p><input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n"; |
|
633
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
|
634
|
|
|
echo "</form>\n"; |
|
635
|
|
|
} else { |
|
636
|
|
|
echo "<p>{$lang['strnodata']}</p>\n"; |
|
637
|
|
|
} |
|
638
|
|
|
} else { |
|
639
|
|
|
// For databases that don't allow owner change |
|
640
|
|
|
if (!isset($_POST['owner'])) { |
|
641
|
|
|
$_POST['owner'] = ''; |
|
642
|
|
|
} |
|
643
|
|
|
|
|
644
|
|
|
if (!isset($_POST['newschema'])) { |
|
645
|
|
|
$_POST['newschema'] = null; |
|
646
|
|
|
} |
|
647
|
|
|
|
|
648
|
|
|
$status = $data->alterView($_POST['view'], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment']); |
|
649
|
|
|
if (0 == $status) { |
|
650
|
|
|
// If view has been renamed, need to change to the new name and |
|
651
|
|
|
// reload the browser frame. |
|
652
|
|
|
if ($_POST['view'] != $_POST['name']) { |
|
653
|
|
|
// Jump them to the new view name |
|
654
|
|
|
$_REQUEST['matview'] = $_POST['name']; |
|
655
|
|
|
// Force a browser reload |
|
656
|
|
|
$this->misc->setReloadBrowser(true); |
|
657
|
|
|
} |
|
658
|
|
|
// If schema has changed, need to change to the new schema and reload the browser |
|
659
|
|
|
if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) { |
|
660
|
|
|
// Jump them to the new sequence schema |
|
661
|
|
|
$this->misc->setCurrentSchema($_POST['newschema']); |
|
662
|
|
|
$this->misc->setReloadBrowser(true); |
|
663
|
|
|
} |
|
664
|
|
|
$this->doDefault($lang['strviewaltered']); |
|
665
|
|
|
} else { |
|
666
|
|
|
$this->doAlter(true, $lang['strviewalteredbad']); |
|
667
|
|
|
} |
|
668
|
|
|
} |
|
669
|
|
|
} |
|
670
|
|
|
} |
|
671
|
|
|
|