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
|
<?php
/**
* PHPPgAdmin v6.0.0-RC1
*/
namespace PHPPgAdmin\Traits;
use PHPPgAdmin\Decorators\Decorator;
/**
* Common trait for dealing with views or materialized views.
*/
trait ViewsMatViewsPropertiesTrait
{
public $href = '';
public $misc;
public $view_name;
/**
* Show view definition and virtual columns.
*
* @param mixed $msg
*/
public function doDefault($msg = '')
{
$data = $this->misc->getDatabaseAccessor();
$attPre = function (&$rowdata) use ($data) {
$rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']);
};
$this->printTrail($this->subject);
$this->printTabs($this->subject, 'columns');
$this->printMsg($msg);
// Get view
$vdata = $data->getView($_REQUEST[$this->subject]);
// Get columns (using same method for getting a view)
$attrs = $data->getTableAttributes($_REQUEST[$this->subject]);
// Show comment if any
if (null !== $vdata->fields['relcomment']) {
echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), '</p>'.PHP_EOL;
}
$columns = [
'column' => [
'title' => $this->lang['strcolumn'],
'field' => Decorator::field('attname'),
'url' => "colproperties?subject=column&{$this->misc->href}&view=".urlencode($_REQUEST[$this->subject]).'&',
'vars' => ['column' => 'attname'],
],
'type' => [
'title' => $this->lang['strtype'],
'field' => Decorator::field('+type'),
],
'default' => [
'title' => $this->lang['strdefault'],
'field' => Decorator::field('adsrc'),
],
'actions' => [
'title' => $this->lang['stractions'],
],
'comment' => [
'title' => $this->lang['strcomment'],
'field' => Decorator::field('comment'),
],
];
$actions = [
'alter' => [
'content' => $this->lang['stralter'],
'attr' => [
'href' => [
'url' => $this->view_name,
'urlvars' => [
'action' => 'properties',
$this->subject => $_REQUEST[$this->subject],
'column' => Decorator::field('attname'),
],
],
],
],
];
echo $this->printTable($attrs, $columns, $actions, "{$this->view_name}-{$this->view_name}", $this->lang['strnodata'], $attPre);
echo '<br />'.PHP_EOL;
$navlinks = [
'browse' => [
'attr' => [
'href' => [
'url' => 'display',
'urlvars' => [
'server' => $_REQUEST['server'],
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
$this->subject => $_REQUEST[$this->subject],
'subject' => $this->subject,
'return' => $this->subject,
],
],
],
'content' => $this->lang['strbrowse'],
],
'select' => [
'attr' => [
'href' => [
'url' => str_replace('properties', 's', $this->view_name),
'urlvars' => [
'action' => 'confselectrows',
'server' => $_REQUEST['server'],
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
$this->subject => $_REQUEST[$this->subject],
],
],
],
'content' => $this->lang['strselect'],
],
'drop' => [
'attr' => [
'href' => [
'url' => str_replace('properties', 's', $this->view_name),
'urlvars' => [
'action' => 'confirm_drop',
'server' => $_REQUEST['server'],
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
$this->subject => $_REQUEST[$this->subject],
],
],
],
'content' => $this->lang['strdrop'],
],
'alter' => [
'attr' => [
'href' => [
'url' => $this->view_name,
'urlvars' => [
'action' => 'confirm_alter',
'server' => $_REQUEST['server'],
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
$this->subject => $_REQUEST[$this->subject],
],
],
],
'content' => $this->lang['stralter'],
],
];
$this->prtrace($this->view_name);
if ($this->view_name === 'materializedviewproperties') {
$navlinks['refresh'] = [
'attr' => [
'href' => [
'url' => $this->view_name,
'urlvars' => [
'action' => 'refresh',
'server' => $_REQUEST['server'],
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
$this->subject => $_REQUEST[$this->subject],
],
],
],
'content' => $this->lang['strrefresh'],
];
}
$this->printNavLinks($navlinks, "{$this->view_name}-{$this->view_name}", get_defined_vars());
}
public function doTree()
{
$data = $this->misc->getDatabaseAccessor();
$reqvars = $this->misc->getRequestVars('column');
$columns = $data->getTableAttributes($_REQUEST[$this->subject]);
$attrs = [
'text' => Decorator::field('attname'),
'action' => Decorator::actionurl(
'colproperties',
$reqvars,
[
$this->subject => $_REQUEST[$this->subject],
'column' => Decorator::field('attname'),
]
),
'icon' => 'Column',
'iconAction' => Decorator::url(
'display',
$reqvars,
[
$this->subject => $_REQUEST[$this->subject],
'column' => Decorator::field('attname'),
'query' => Decorator::replace(
'SELECT "%column%", count(*) AS "count" FROM %view% GROUP BY "%column%" ORDER BY "%column%"',
[
'%column%' => Decorator::field('attname'),
'%view%' => $_REQUEST[$this->subject],
]
),
]
),
'toolTip' => Decorator::field('comment'),
];
return $this->printTree($columns, $attrs, 'viewcolumns');
}
/**
* Allow the dumping of the data "in" a view
* NOTE:: PostgreSQL doesn't currently support dumping the data in a view
* so I have disabled the data related parts for now. In the future
* we should allow it conditionally if it becomes supported. This is
* a SMOP since it is based on pg_dump version not backend version.
*
* @param mixed $msg
*/
public function doExport($msg = '')
{
$this->printTrail($this->subject);
$this->printTabs($this->subject, 'export');
$this->printMsg($msg);
$subject = $this->subject;
$object = $_REQUEST[$this->subject];
echo $this->formHeader();
// Data only
// echo $this->dataOnly(false);
// Structure only
echo $this->structureOnly(true);
// Structure and data
// echo $this->structureAndData();
echo $this->displayOrDownload();
echo $this->formFooter($subject, $object);
}
/**
* Show definition for a view or matview.
*
* @param mixed $msg
*/
public function doDefinition($msg = '')
{
$data = $this->misc->getDatabaseAccessor();
// Get view
$vdata = $data->getView($_REQUEST[$this->subject]);
$this->printTrail($this->subject);
$this->printTabs($this->subject, 'definition');
$this->printMsg($msg);
if ($vdata->recordCount() > 0) {
// Show comment if any
if (null !== $vdata->fields['relcomment']) {
echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), '</p>'.PHP_EOL;
}
echo '<table style="width: 100%">'.PHP_EOL;
echo "<tr><th class=\"data\">{$this->lang['strdefinition']}</th></tr>".PHP_EOL;
echo '<tr><td class="data1">', $this->misc->printVal($vdata->fields['vwdefinition']), '</td></tr>'.PHP_EOL;
echo '</table>'.PHP_EOL;
} else {
echo "<p>{$this->lang['strnodata']}</p>".PHP_EOL;
}
$this->printNavLinks(['alter' => [
'attr' => [
'href' => [
'url' => $this->view_name,
'urlvars' => [
'action' => 'edit',
'server' => $_REQUEST['server'],
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
$this->subject => $_REQUEST[$this->subject],
],
],
],
'content' => $this->lang['stralter'],
]], "{$this->view_name}-definition", get_defined_vars());
}
}
|