|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PHPPgAdmin v6.0.0-beta.49 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\Traits; |
|
8
|
|
|
|
|
9
|
|
|
use PHPPgAdmin\Decorators\Decorator; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Common trait for dealing with views or materialized views. |
|
13
|
|
|
*/ |
|
14
|
|
|
trait ViewsMatViewsPropertiesTrait |
|
15
|
|
|
{ |
|
16
|
|
|
public $href = ''; |
|
17
|
|
|
public $misc; |
|
18
|
|
|
public $view_name; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Show view definition and virtual columns. |
|
22
|
|
|
* |
|
23
|
|
|
* @param mixed $msg |
|
24
|
|
|
*/ |
|
25
|
|
|
public function doDefault($msg = '') |
|
26
|
|
|
{ |
|
27
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
28
|
|
|
|
|
29
|
|
|
$attPre = function (&$rowdata) use ($data) { |
|
30
|
|
|
$rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']); |
|
31
|
|
|
}; |
|
32
|
|
|
|
|
33
|
|
|
$this->printTrail($this->subject); |
|
34
|
|
|
$this->printTabs($this->subject, 'columns'); |
|
35
|
|
|
$this->printMsg($msg); |
|
36
|
|
|
|
|
37
|
|
|
// Get view |
|
38
|
|
|
$vdata = $data->getView($_REQUEST[$this->subject]); |
|
39
|
|
|
// Get columns (using same method for getting a view) |
|
40
|
|
|
$attrs = $data->getTableAttributes($_REQUEST[$this->subject]); |
|
41
|
|
|
|
|
42
|
|
|
// Show comment if any |
|
43
|
|
|
if (null !== $vdata->fields['relcomment']) { |
|
44
|
|
|
echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), '</p>'.PHP_EOL; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$columns = [ |
|
48
|
|
|
'column' => [ |
|
49
|
|
|
'title' => $this->lang['strcolumn'], |
|
50
|
|
|
'field' => Decorator::field('attname'), |
|
51
|
|
|
'url' => "colproperties?subject=column&{$this->misc->href}&view=".urlencode($_REQUEST[$this->subject]).'&', |
|
52
|
|
|
'vars' => ['column' => 'attname'], |
|
53
|
|
|
], |
|
54
|
|
|
'type' => [ |
|
55
|
|
|
'title' => $this->lang['strtype'], |
|
56
|
|
|
'field' => Decorator::field('+type'), |
|
57
|
|
|
], |
|
58
|
|
|
'default' => [ |
|
59
|
|
|
'title' => $this->lang['strdefault'], |
|
60
|
|
|
'field' => Decorator::field('adsrc'), |
|
61
|
|
|
], |
|
62
|
|
|
'actions' => [ |
|
63
|
|
|
'title' => $this->lang['stractions'], |
|
64
|
|
|
], |
|
65
|
|
|
'comment' => [ |
|
66
|
|
|
'title' => $this->lang['strcomment'], |
|
67
|
|
|
'field' => Decorator::field('comment'), |
|
68
|
|
|
], |
|
69
|
|
|
]; |
|
70
|
|
|
|
|
71
|
|
|
$actions = [ |
|
72
|
|
|
'alter' => [ |
|
73
|
|
|
'content' => $this->lang['stralter'], |
|
74
|
|
|
'attr' => [ |
|
75
|
|
|
'href' => [ |
|
76
|
|
|
'url' => $this->view_name, |
|
77
|
|
|
'urlvars' => [ |
|
78
|
|
|
'action' => 'properties', |
|
79
|
|
|
$this->subject => $_REQUEST[$this->subject], |
|
80
|
|
|
'column' => Decorator::field('attname'), |
|
81
|
|
|
], |
|
82
|
|
|
], |
|
83
|
|
|
], |
|
84
|
|
|
], |
|
85
|
|
|
]; |
|
86
|
|
|
|
|
87
|
|
|
echo $this->printTable($attrs, $columns, $actions, "{$this->view_name}-{$this->view_name}", $this->lang['strnodata'], $attPre); |
|
88
|
|
|
|
|
89
|
|
|
echo '<br />'.PHP_EOL; |
|
90
|
|
|
|
|
91
|
|
|
$navlinks = [ |
|
92
|
|
|
'browse' => [ |
|
93
|
|
|
'attr' => [ |
|
94
|
|
|
'href' => [ |
|
95
|
|
|
'url' => 'display', |
|
96
|
|
|
'urlvars' => [ |
|
97
|
|
|
'server' => $_REQUEST['server'], |
|
98
|
|
|
'database' => $_REQUEST['database'], |
|
99
|
|
|
'schema' => $_REQUEST['schema'], |
|
100
|
|
|
$this->subject => $_REQUEST[$this->subject], |
|
101
|
|
|
'subject' => $this->subject, |
|
102
|
|
|
'return' => $this->subject, |
|
103
|
|
|
], |
|
104
|
|
|
], |
|
105
|
|
|
], |
|
106
|
|
|
'content' => $this->lang['strbrowse'], |
|
107
|
|
|
], |
|
108
|
|
|
'select' => [ |
|
109
|
|
|
'attr' => [ |
|
110
|
|
|
'href' => [ |
|
111
|
|
|
'url' => str_replace('properties', 's', $this->view_name), |
|
112
|
|
|
'urlvars' => [ |
|
113
|
|
|
'action' => 'confselectrows', |
|
114
|
|
|
'server' => $_REQUEST['server'], |
|
115
|
|
|
'database' => $_REQUEST['database'], |
|
116
|
|
|
'schema' => $_REQUEST['schema'], |
|
117
|
|
|
$this->subject => $_REQUEST[$this->subject], |
|
118
|
|
|
], |
|
119
|
|
|
], |
|
120
|
|
|
], |
|
121
|
|
|
'content' => $this->lang['strselect'], |
|
122
|
|
|
], |
|
123
|
|
|
'drop' => [ |
|
124
|
|
|
'attr' => [ |
|
125
|
|
|
'href' => [ |
|
126
|
|
|
'url' => str_replace('properties', 's', $this->view_name), |
|
127
|
|
|
'urlvars' => [ |
|
128
|
|
|
'action' => 'confirm_drop', |
|
129
|
|
|
'server' => $_REQUEST['server'], |
|
130
|
|
|
'database' => $_REQUEST['database'], |
|
131
|
|
|
'schema' => $_REQUEST['schema'], |
|
132
|
|
|
$this->subject => $_REQUEST[$this->subject], |
|
133
|
|
|
], |
|
134
|
|
|
], |
|
135
|
|
|
], |
|
136
|
|
|
'content' => $this->lang['strdrop'], |
|
137
|
|
|
], |
|
138
|
|
|
'alter' => [ |
|
139
|
|
|
'attr' => [ |
|
140
|
|
|
'href' => [ |
|
141
|
|
|
'url' => $this->view_name, |
|
142
|
|
|
'urlvars' => [ |
|
143
|
|
|
'action' => 'confirm_alter', |
|
144
|
|
|
'server' => $_REQUEST['server'], |
|
145
|
|
|
'database' => $_REQUEST['database'], |
|
146
|
|
|
'schema' => $_REQUEST['schema'], |
|
147
|
|
|
$this->subject => $_REQUEST[$this->subject], |
|
148
|
|
|
], |
|
149
|
|
|
], |
|
150
|
|
|
], |
|
151
|
|
|
'content' => $this->lang['stralter'], |
|
152
|
|
|
], |
|
153
|
|
|
]; |
|
154
|
|
|
$this->prtrace($this->view_name); |
|
155
|
|
|
if ($this->view_name === 'materializedviewproperties') { |
|
156
|
|
|
$navlinks['refresh'] = [ |
|
157
|
|
|
'attr' => [ |
|
158
|
|
|
'href' => [ |
|
159
|
|
|
'url' => $this->view_name, |
|
160
|
|
|
'urlvars' => [ |
|
161
|
|
|
'action' => 'refresh', |
|
162
|
|
|
'server' => $_REQUEST['server'], |
|
163
|
|
|
'database' => $_REQUEST['database'], |
|
164
|
|
|
'schema' => $_REQUEST['schema'], |
|
165
|
|
|
$this->subject => $_REQUEST[$this->subject], |
|
166
|
|
|
], |
|
167
|
|
|
], |
|
168
|
|
|
], |
|
169
|
|
|
'content' => $this->lang['strrefresh'], |
|
170
|
|
|
]; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
$this->printNavLinks($navlinks, "{$this->view_name}-{$this->view_name}", get_defined_vars()); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function doTree() |
|
177
|
|
|
{ |
|
178
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
179
|
|
|
|
|
180
|
|
|
$reqvars = $this->misc->getRequestVars('column'); |
|
181
|
|
|
$columns = $data->getTableAttributes($_REQUEST[$this->subject]); |
|
182
|
|
|
|
|
183
|
|
|
$attrs = [ |
|
184
|
|
|
'text' => Decorator::field('attname'), |
|
185
|
|
|
'action' => Decorator::actionurl( |
|
186
|
|
|
'colproperties', |
|
187
|
|
|
$reqvars, |
|
188
|
|
|
[ |
|
189
|
|
|
$this->subject => $_REQUEST[$this->subject], |
|
190
|
|
|
'column' => Decorator::field('attname'), |
|
191
|
|
|
] |
|
192
|
|
|
), |
|
193
|
|
|
'icon' => 'Column', |
|
194
|
|
|
'iconAction' => Decorator::url( |
|
195
|
|
|
'display', |
|
196
|
|
|
$reqvars, |
|
197
|
|
|
[ |
|
198
|
|
|
$this->subject => $_REQUEST[$this->subject], |
|
199
|
|
|
'column' => Decorator::field('attname'), |
|
200
|
|
|
'query' => Decorator::replace( |
|
201
|
|
|
'SELECT "%column%", count(*) AS "count" FROM %view% GROUP BY "%column%" ORDER BY "%column%"', |
|
202
|
|
|
[ |
|
203
|
|
|
'%column%' => Decorator::field('attname'), |
|
204
|
|
|
'%view%' => $_REQUEST[$this->subject], |
|
205
|
|
|
] |
|
206
|
|
|
), |
|
207
|
|
|
] |
|
208
|
|
|
), |
|
209
|
|
|
'toolTip' => Decorator::field('comment'), |
|
210
|
|
|
]; |
|
211
|
|
|
|
|
212
|
|
|
return $this->printTree($columns, $attrs, 'viewcolumns'); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Allow the dumping of the data "in" a view |
|
217
|
|
|
* NOTE:: PostgreSQL doesn't currently support dumping the data in a view |
|
218
|
|
|
* so I have disabled the data related parts for now. In the future |
|
219
|
|
|
* we should allow it conditionally if it becomes supported. This is |
|
220
|
|
|
* a SMOP since it is based on pg_dump version not backend version. |
|
221
|
|
|
* |
|
222
|
|
|
* @param mixed $msg |
|
223
|
|
|
*/ |
|
224
|
|
|
public function doExport($msg = '') |
|
225
|
|
|
{ |
|
226
|
|
|
$this->printTrail($this->subject); |
|
227
|
|
|
$this->printTabs($this->subject, 'export'); |
|
228
|
|
|
$this->printMsg($msg); |
|
229
|
|
|
|
|
230
|
|
|
$subject = $this->subject; |
|
231
|
|
|
$object = $_REQUEST[$this->subject]; |
|
232
|
|
|
|
|
233
|
|
|
echo $this->formHeader(); |
|
234
|
|
|
// Data only |
|
235
|
|
|
// echo $this->dataOnly(false); |
|
236
|
|
|
|
|
237
|
|
|
// Structure only |
|
238
|
|
|
echo $this->structureOnly(true); |
|
239
|
|
|
|
|
240
|
|
|
// Structure and data |
|
241
|
|
|
// echo $this->structureAndData(); |
|
242
|
|
|
|
|
243
|
|
|
echo $this->displayOrDownload(); |
|
244
|
|
|
|
|
245
|
|
|
echo $this->formFooter($subject, $object); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Show definition for a view or matview. |
|
250
|
|
|
* |
|
251
|
|
|
* @param mixed $msg |
|
252
|
|
|
*/ |
|
253
|
|
|
public function doDefinition($msg = '') |
|
254
|
|
|
{ |
|
255
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
256
|
|
|
|
|
257
|
|
|
// Get view |
|
258
|
|
|
$vdata = $data->getView($_REQUEST[$this->subject]); |
|
259
|
|
|
|
|
260
|
|
|
$this->printTrail($this->subject); |
|
261
|
|
|
$this->printTabs($this->subject, 'definition'); |
|
262
|
|
|
$this->printMsg($msg); |
|
263
|
|
|
|
|
264
|
|
|
if ($vdata->RecordCount() > 0) { |
|
265
|
|
|
// Show comment if any |
|
266
|
|
|
if (null !== $vdata->fields['relcomment']) { |
|
267
|
|
|
echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), '</p>'.PHP_EOL; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
echo '<table style="width: 100%">'.PHP_EOL; |
|
271
|
|
|
echo "<tr><th class=\"data\">{$this->lang['strdefinition']}</th></tr>".PHP_EOL; |
|
272
|
|
|
echo '<tr><td class="data1">', $this->misc->printVal($vdata->fields['vwdefinition']), '</td></tr>'.PHP_EOL; |
|
273
|
|
|
echo '</table>'.PHP_EOL; |
|
274
|
|
|
} else { |
|
275
|
|
|
echo "<p>{$this->lang['strnodata']}</p>".PHP_EOL; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
$this->printNavLinks(['alter' => [ |
|
279
|
|
|
'attr' => [ |
|
280
|
|
|
'href' => [ |
|
281
|
|
|
'url' => $this->view_name, |
|
282
|
|
|
'urlvars' => [ |
|
283
|
|
|
'action' => 'edit', |
|
284
|
|
|
'server' => $_REQUEST['server'], |
|
285
|
|
|
'database' => $_REQUEST['database'], |
|
286
|
|
|
'schema' => $_REQUEST['schema'], |
|
287
|
|
|
$this->subject => $_REQUEST[$this->subject], |
|
288
|
|
|
], |
|
289
|
|
|
], |
|
290
|
|
|
], |
|
291
|
|
|
'content' => $this->lang['stralter'], |
|
292
|
|
|
]], "{$this->view_name}-definition", get_defined_vars()); |
|
293
|
|
|
} |
|
294
|
|
|
} |
|
295
|
|
|
|