|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PHPPgAdmin 6.1.3 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\Controller; |
|
8
|
|
|
|
|
9
|
|
|
use PHPPgAdmin\Decorators\Decorator; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Base controller class. |
|
13
|
|
|
*/ |
|
14
|
|
|
class AggregatesController extends BaseController |
|
15
|
|
|
{ |
|
16
|
|
|
public $table_place = 'aggregates-aggregates'; |
|
17
|
|
|
|
|
18
|
|
|
public $controller_title = 'straggregates'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Default method to render the controller according to the action parameter. |
|
22
|
|
|
*/ |
|
23
|
|
|
public function render() |
|
24
|
|
|
{ |
|
25
|
|
|
if ('tree' === $this->action) { |
|
26
|
|
|
return $this->doTree(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
\ob_start(); |
|
30
|
|
|
|
|
31
|
|
|
switch ($this->action) { |
|
32
|
|
|
case 'create': |
|
33
|
|
|
$this->doCreate(); |
|
34
|
|
|
|
|
35
|
|
|
break; |
|
36
|
|
|
case 'save_create': |
|
37
|
|
|
if (null !== $this->getPostParam('cancel')) { |
|
38
|
|
|
$this->doDefault(); |
|
39
|
|
|
} else { |
|
40
|
|
|
$this->doSaveCreate(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
break; |
|
44
|
|
|
case 'alter': |
|
45
|
|
|
$this->doAlter(); |
|
46
|
|
|
|
|
47
|
|
|
break; |
|
48
|
|
|
case 'save_alter': |
|
49
|
|
|
if (null !== $this->getPostParam('alter')) { |
|
50
|
|
|
$this->doSaveAlter(); |
|
51
|
|
|
} else { |
|
52
|
|
|
$this->doProperties(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
break; |
|
56
|
|
|
case 'drop': |
|
57
|
|
|
if (null !== $this->getPostParam('drop')) { |
|
58
|
|
|
$this->doDrop(false); |
|
59
|
|
|
} else { |
|
60
|
|
|
$this->doDefault(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
break; |
|
64
|
|
|
case 'confirm_drop': |
|
65
|
|
|
$this->doDrop(true); |
|
66
|
|
|
|
|
67
|
|
|
break; |
|
68
|
|
|
|
|
69
|
|
|
default: |
|
70
|
|
|
$this->doDefault(); |
|
71
|
|
|
|
|
72
|
|
|
break; |
|
73
|
|
|
case 'properties': |
|
74
|
|
|
$this->doProperties(); |
|
75
|
|
|
|
|
76
|
|
|
break; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$output = \ob_get_clean(); |
|
80
|
|
|
|
|
81
|
|
|
$this->printHeader($this->headerTitle()); |
|
82
|
|
|
$this->printBody(); |
|
83
|
|
|
echo $output; |
|
84
|
|
|
|
|
85
|
|
|
return $this->printFooter(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Show default list of aggregate functions in the database. |
|
90
|
|
|
* |
|
91
|
|
|
* @param mixed $msg |
|
92
|
|
|
*/ |
|
93
|
|
|
public function doDefault($msg = ''): void |
|
94
|
|
|
{ |
|
95
|
|
|
$this->printTrail('schema'); |
|
96
|
|
|
$this->printTabs('schema', 'aggregates'); |
|
97
|
|
|
$this->printMsg($msg); |
|
98
|
|
|
|
|
99
|
|
|
$aggregates = $this->data->getAggregates(); |
|
100
|
|
|
$columns = [ |
|
101
|
|
|
'aggrname' => [ |
|
102
|
|
|
'title' => $this->lang['strname'], |
|
103
|
|
|
'field' => Decorator::field('proname'), |
|
104
|
|
|
'url' => \sprintf( |
|
105
|
|
|
'redirect.php?subject=aggregate&action=properties&%s&', |
|
106
|
|
|
$this->misc->href |
|
107
|
|
|
), |
|
108
|
|
|
'vars' => ['aggrname' => 'proname', 'aggrtype' => 'proargtypes'], |
|
109
|
|
|
], |
|
110
|
|
|
'aggrtype' => [ |
|
111
|
|
|
'title' => $this->lang['strtype'], |
|
112
|
|
|
'field' => Decorator::field('proargtypes'), |
|
113
|
|
|
], |
|
114
|
|
|
'aggrtransfn' => [ |
|
115
|
|
|
'title' => $this->lang['straggrsfunc'], |
|
116
|
|
|
'field' => Decorator::field('aggtransfn'), |
|
117
|
|
|
], |
|
118
|
|
|
'owner' => [ |
|
119
|
|
|
'title' => $this->lang['strowner'], |
|
120
|
|
|
'field' => Decorator::field('usename'), |
|
121
|
|
|
], |
|
122
|
|
|
'actions' => [ |
|
123
|
|
|
'title' => $this->lang['stractions'], |
|
124
|
|
|
], |
|
125
|
|
|
'comment' => [ |
|
126
|
|
|
'title' => $this->lang['strcomment'], |
|
127
|
|
|
'field' => Decorator::field('aggrcomment'), |
|
128
|
|
|
], |
|
129
|
|
|
]; |
|
130
|
|
|
|
|
131
|
|
|
$actions = [ |
|
132
|
|
|
'alter' => [ |
|
133
|
|
|
'content' => $this->lang['stralter'], |
|
134
|
|
|
'attr' => [ |
|
135
|
|
|
'href' => [ |
|
136
|
|
|
'url' => 'aggregates.php', |
|
137
|
|
|
'urlvars' => [ |
|
138
|
|
|
'action' => 'alter', |
|
139
|
|
|
'aggrname' => Decorator::field('proname'), |
|
140
|
|
|
'aggrtype' => Decorator::field('proargtypes'), |
|
141
|
|
|
], |
|
142
|
|
|
], |
|
143
|
|
|
], |
|
144
|
|
|
], |
|
145
|
|
|
'drop' => [ |
|
146
|
|
|
'content' => $this->lang['strdrop'], |
|
147
|
|
|
'attr' => [ |
|
148
|
|
|
'href' => [ |
|
149
|
|
|
'url' => 'aggregates.php', |
|
150
|
|
|
'urlvars' => [ |
|
151
|
|
|
'action' => 'confirm_drop', |
|
152
|
|
|
'aggrname' => Decorator::field('proname'), |
|
153
|
|
|
'aggrtype' => Decorator::field('proargtypes'), |
|
154
|
|
|
], |
|
155
|
|
|
], |
|
156
|
|
|
], |
|
157
|
|
|
], |
|
158
|
|
|
]; |
|
159
|
|
|
|
|
160
|
|
|
if (!$this->data->hasAlterAggregate()) { |
|
161
|
|
|
unset($actions['alter']); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
echo $this->printTable($aggregates, $columns, $actions, $this->table_place, $this->lang['strnoaggregates']); |
|
165
|
|
|
|
|
166
|
|
|
$navlinks = [ |
|
167
|
|
|
'create' => [ |
|
168
|
|
|
'attr' => [ |
|
169
|
|
|
'href' => [ |
|
170
|
|
|
'url' => 'aggregates.php', |
|
171
|
|
|
'urlvars' => [ |
|
172
|
|
|
'action' => 'create', |
|
173
|
|
|
'server' => $_REQUEST['server'], |
|
174
|
|
|
'database' => $_REQUEST['database'], |
|
175
|
|
|
'schema' => $_REQUEST['schema'], |
|
176
|
|
|
], |
|
177
|
|
|
], |
|
178
|
|
|
], |
|
179
|
|
|
'content' => $this->lang['strcreateaggregate'], |
|
180
|
|
|
], |
|
181
|
|
|
]; |
|
182
|
|
|
$this->printNavLinks($navlinks, $this->table_place, \get_defined_vars()); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function doTree() |
|
186
|
|
|
{ |
|
187
|
|
|
$this->data = $this->misc->getDatabaseAccessor(); |
|
188
|
|
|
|
|
189
|
|
|
$aggregates = $this->data->getAggregates(); |
|
190
|
|
|
$proto = Decorator::concat(Decorator::field('proname'), ' (', Decorator::field('proargtypes'), ')'); |
|
191
|
|
|
$reqvars = $this->misc->getRequestVars('aggregate'); |
|
192
|
|
|
|
|
193
|
|
|
$attrs = [ |
|
194
|
|
|
'text' => $proto, |
|
195
|
|
|
'icon' => 'Aggregate', |
|
196
|
|
|
'toolTip' => Decorator::field('aggcomment'), |
|
197
|
|
|
'action' => Decorator::redirecturl( |
|
198
|
|
|
'redirect', |
|
199
|
|
|
$reqvars, |
|
200
|
|
|
[ |
|
201
|
|
|
'action' => 'properties', |
|
202
|
|
|
'aggrname' => Decorator::field('proname'), |
|
203
|
|
|
'aggrtype' => Decorator::field('proargtypes'), |
|
204
|
|
|
] |
|
205
|
|
|
), |
|
206
|
|
|
]; |
|
207
|
|
|
|
|
208
|
|
|
return $this->printTree($aggregates, $attrs, 'aggregates'); |
|
|
|
|
|
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Actually creates the new aggregate in the database. |
|
213
|
|
|
*/ |
|
214
|
|
|
public function doSaveCreate() |
|
215
|
|
|
{ |
|
216
|
|
|
$this->data = $this->misc->getDatabaseAccessor(); |
|
217
|
|
|
// Check inputs |
|
218
|
|
|
if ('' === \trim($_REQUEST['name'])) { |
|
219
|
|
|
return $this->doCreate($this->lang['straggrneedsname']); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
if ('' === \trim($_REQUEST['basetype'])) { |
|
223
|
|
|
return $this->doCreate($this->lang['straggrneedsbasetype']); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
if ('' === \trim($_REQUEST['sfunc'])) { |
|
227
|
|
|
return $this->doCreate($this->lang['straggrneedssfunc']); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
if ('' === \trim($_REQUEST['stype'])) { |
|
231
|
|
|
return $this->doCreate($this->lang['straggrneedsstype']); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
$status = $this->data->createAggregate( |
|
235
|
|
|
$_REQUEST['name'], |
|
236
|
|
|
$_REQUEST['basetype'], |
|
237
|
|
|
$_REQUEST['sfunc'], |
|
238
|
|
|
$_REQUEST['stype'], |
|
239
|
|
|
$_REQUEST['ffunc'], |
|
240
|
|
|
$_REQUEST['initcond'], |
|
241
|
|
|
$_REQUEST['sortop'], |
|
242
|
|
|
$_REQUEST['aggrcomment'] |
|
243
|
|
|
); |
|
244
|
|
|
|
|
245
|
|
|
if (0 === $status) { |
|
246
|
|
|
$this->view->setReloadBrowser(true); |
|
247
|
|
|
$this->doDefault($this->lang['straggrcreated']); |
|
248
|
|
|
} else { |
|
249
|
|
|
$this->doCreate($this->lang['straggrcreatedbad']); |
|
250
|
|
|
} |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Displays a screen for create a new aggregate function. |
|
255
|
|
|
* |
|
256
|
|
|
* @param mixed $msg |
|
257
|
|
|
*/ |
|
258
|
|
|
public function doCreate($msg = ''): void |
|
259
|
|
|
{ |
|
260
|
|
|
$this->data = $this->misc->getDatabaseAccessor(); |
|
261
|
|
|
|
|
262
|
|
|
$this->coalesceArr($_REQUEST, 'name', ''); |
|
263
|
|
|
|
|
264
|
|
|
$this->coalesceArr($_REQUEST, 'basetype', ''); |
|
265
|
|
|
|
|
266
|
|
|
$this->coalesceArr($_REQUEST, 'sfunc', ''); |
|
267
|
|
|
|
|
268
|
|
|
$this->coalesceArr($_REQUEST, 'stype', ''); |
|
269
|
|
|
|
|
270
|
|
|
$this->coalesceArr($_REQUEST, 'ffunc', ''); |
|
271
|
|
|
|
|
272
|
|
|
$this->coalesceArr($_REQUEST, 'initcond', ''); |
|
273
|
|
|
|
|
274
|
|
|
$this->coalesceArr($_REQUEST, 'sortop', ''); |
|
275
|
|
|
|
|
276
|
|
|
$this->coalesceArr($_REQUEST, 'aggrcomment', ''); |
|
277
|
|
|
|
|
278
|
|
|
$this->printTrail('schema'); |
|
279
|
|
|
$this->printTitle($this->lang['strcreateaggregate'], 'pg.aggregate.create'); |
|
280
|
|
|
$this->printMsg($msg); |
|
281
|
|
|
|
|
282
|
|
|
echo '<form action="' . \containerInstance()->subFolder . '/src/views/aggregates" method="post">' . \PHP_EOL; |
|
283
|
|
|
echo '<table>' . \PHP_EOL; |
|
284
|
|
|
echo \sprintf( |
|
285
|
|
|
' <tr> |
|
286
|
|
|
<th class="data left required">%s</th>', |
|
287
|
|
|
$this->lang['strname'] |
|
288
|
|
|
) . \PHP_EOL; |
|
289
|
|
|
echo \sprintf( |
|
290
|
|
|
' <td class="data"><input name="name" size="32" maxlength="%s" value="', |
|
291
|
|
|
$this->data->_maxNameLen |
|
292
|
|
|
), |
|
293
|
|
|
\htmlspecialchars($_REQUEST['name']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
|
294
|
|
|
echo \sprintf( |
|
295
|
|
|
' <tr> |
|
296
|
|
|
<th class="data left required">%s</th>', |
|
297
|
|
|
$this->lang['straggrbasetype'] |
|
298
|
|
|
) . \PHP_EOL; |
|
299
|
|
|
echo \sprintf( |
|
300
|
|
|
' <td class="data"><input name="basetype" size="32" maxlength="%s" value="', |
|
301
|
|
|
$this->data->_maxNameLen |
|
302
|
|
|
), |
|
303
|
|
|
\htmlspecialchars($_REQUEST['basetype']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
|
304
|
|
|
echo \sprintf( |
|
305
|
|
|
' <tr> |
|
306
|
|
|
<th class="data left required">%s</th>', |
|
307
|
|
|
$this->lang['straggrsfunc'] |
|
308
|
|
|
) . \PHP_EOL; |
|
309
|
|
|
echo \sprintf( |
|
310
|
|
|
' <td class="data"><input name="sfunc" size="32" maxlength="%s" value="', |
|
311
|
|
|
$this->data->_maxNameLen |
|
312
|
|
|
), |
|
313
|
|
|
\htmlspecialchars($_REQUEST['sfunc']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
|
314
|
|
|
echo \sprintf( |
|
315
|
|
|
' <tr> |
|
316
|
|
|
<th class="data left required">%s</th>', |
|
317
|
|
|
$this->lang['straggrstype'] |
|
318
|
|
|
) . \PHP_EOL; |
|
319
|
|
|
echo \sprintf( |
|
320
|
|
|
' <td class="data"><input name="stype" size="32" maxlength="%s" value="', |
|
321
|
|
|
$this->data->_maxNameLen |
|
322
|
|
|
), |
|
323
|
|
|
\htmlspecialchars($_REQUEST['stype']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
|
324
|
|
|
echo \sprintf( |
|
325
|
|
|
' <tr> |
|
326
|
|
|
<th class="data left">%s</th>', |
|
327
|
|
|
$this->lang['straggrffunc'] |
|
328
|
|
|
) . \PHP_EOL; |
|
329
|
|
|
echo \sprintf( |
|
330
|
|
|
' <td class="data"><input name="ffunc" size="32" maxlength="%s" value="', |
|
331
|
|
|
$this->data->_maxNameLen |
|
332
|
|
|
), |
|
333
|
|
|
\htmlspecialchars($_REQUEST['ffunc']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
|
334
|
|
|
echo \sprintf( |
|
335
|
|
|
' <tr> |
|
336
|
|
|
<th class="data left">%s</th>', |
|
337
|
|
|
$this->lang['straggrinitcond'] |
|
338
|
|
|
) . \PHP_EOL; |
|
339
|
|
|
echo \sprintf( |
|
340
|
|
|
' <td class="data"><input name="initcond" size="32" maxlength="%s" value="', |
|
341
|
|
|
$this->data->_maxNameLen |
|
342
|
|
|
), |
|
343
|
|
|
\htmlspecialchars($_REQUEST['initcond']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
|
344
|
|
|
echo \sprintf( |
|
345
|
|
|
' <tr> |
|
346
|
|
|
<th class="data left">%s</th>', |
|
347
|
|
|
$this->lang['straggrsortop'] |
|
348
|
|
|
) . \PHP_EOL; |
|
349
|
|
|
echo \sprintf( |
|
350
|
|
|
' <td class="data"><input name="sortop" size="32" maxlength="%s" value="', |
|
351
|
|
|
$this->data->_maxNameLen |
|
352
|
|
|
), |
|
353
|
|
|
\htmlspecialchars($_REQUEST['sortop']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
|
354
|
|
|
echo \sprintf( |
|
355
|
|
|
' <tr> |
|
356
|
|
|
<th class="data left">%s</th>', |
|
357
|
|
|
$this->lang['strcomment'] |
|
358
|
|
|
) . \PHP_EOL; |
|
359
|
|
|
echo "\t\t<td><textarea name=\"aggrcomment\" rows=\"3\" cols=\"32\">", |
|
360
|
|
|
\htmlspecialchars($_REQUEST['aggrcomment']), "</textarea></td>\n\t</tr>" . \PHP_EOL; |
|
361
|
|
|
|
|
362
|
|
|
echo '</table>' . \PHP_EOL; |
|
363
|
|
|
echo '<p><input type="hidden" name="action" value="save_create" />' . \PHP_EOL; |
|
364
|
|
|
echo $this->view->form; |
|
365
|
|
|
echo \sprintf( |
|
366
|
|
|
'<input type="submit" value="%s" />', |
|
367
|
|
|
$this->lang['strcreate'] |
|
368
|
|
|
) . \PHP_EOL; |
|
369
|
|
|
echo \sprintf( |
|
370
|
|
|
'<input type="submit" name="cancel" value="%s" /></p>%s', |
|
371
|
|
|
$this->lang['strcancel'], |
|
372
|
|
|
\PHP_EOL |
|
373
|
|
|
); |
|
374
|
|
|
echo '</form>' . \PHP_EOL; |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* Function to save after altering an aggregate. |
|
379
|
|
|
*/ |
|
380
|
|
|
public function doSaveAlter(): void |
|
381
|
|
|
{ |
|
382
|
|
|
$this->data = $this->misc->getDatabaseAccessor(); |
|
383
|
|
|
|
|
384
|
|
|
// Check inputs |
|
385
|
|
|
if ('' === \trim($_REQUEST['aggrname'])) { |
|
386
|
|
|
$this->doAlter($this->lang['straggrneedsname']); |
|
387
|
|
|
|
|
388
|
|
|
return; |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
$status = $this->data->alterAggregate( |
|
392
|
|
|
$_REQUEST['aggrname'], |
|
393
|
|
|
$_REQUEST['aggrtype'], |
|
394
|
|
|
$_REQUEST['aggrowner'], |
|
395
|
|
|
$_REQUEST['aggrschema'], |
|
396
|
|
|
$_REQUEST['aggrcomment'], |
|
397
|
|
|
$_REQUEST['newaggrname'], |
|
398
|
|
|
$_REQUEST['newaggrowner'], |
|
399
|
|
|
$_REQUEST['newaggrschema'], |
|
400
|
|
|
$_REQUEST['newaggrcomment'] |
|
401
|
|
|
); |
|
402
|
|
|
|
|
403
|
|
|
if (0 === $status) { |
|
404
|
|
|
$this->doDefault($this->lang['straggraltered']); |
|
405
|
|
|
} else { |
|
406
|
|
|
$this->doAlter($this->lang['straggralteredbad']); |
|
407
|
|
|
|
|
408
|
|
|
return; |
|
409
|
|
|
} |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
/** |
|
413
|
|
|
* Function to allow editing an aggregate function. |
|
414
|
|
|
* |
|
415
|
|
|
* @param mixed $msg |
|
416
|
|
|
*/ |
|
417
|
|
|
public function doAlter($msg = ''): void |
|
418
|
|
|
{ |
|
419
|
|
|
$this->data = $this->misc->getDatabaseAccessor(); |
|
420
|
|
|
|
|
421
|
|
|
$this->printTrail('aggregate'); |
|
422
|
|
|
$this->printTitle($this->lang['stralter'], 'pg.aggregate.alter'); |
|
423
|
|
|
$this->printMsg($msg); |
|
424
|
|
|
|
|
425
|
|
|
echo '<form action="' . \containerInstance()->subFolder . '/src/views/aggregates" method="post">' . \PHP_EOL; |
|
426
|
|
|
$aggrdata = $this->data->getAggregate($_REQUEST['aggrname'], $_REQUEST['aggrtype']); |
|
427
|
|
|
|
|
428
|
|
|
if (0 < $aggrdata->recordCount()) { |
|
429
|
|
|
// Output table header |
|
430
|
|
|
echo '<table>' . \PHP_EOL; |
|
431
|
|
|
echo \sprintf( |
|
432
|
|
|
' <tr> |
|
433
|
|
|
<th class="data required">%s</th>', |
|
434
|
|
|
$this->lang['strname'] |
|
435
|
|
|
); |
|
436
|
|
|
echo \sprintf( |
|
437
|
|
|
'<th class="data required">%s</th>', |
|
438
|
|
|
$this->lang['strowner'] |
|
439
|
|
|
); |
|
440
|
|
|
echo \sprintf( |
|
441
|
|
|
'<th class="data required">%s</th> |
|
442
|
|
|
</tr>', |
|
443
|
|
|
$this->lang['strschema'] |
|
444
|
|
|
) . \PHP_EOL; |
|
445
|
|
|
|
|
446
|
|
|
// Display aggregate's name, owner and schema |
|
447
|
|
|
echo "\t<tr>\n\t\t<td><input name=\"newaggrname\" size=\"32\" maxlength=\"32\" value=\"", \htmlspecialchars($_REQUEST['aggrname']), '" /></td>'; |
|
448
|
|
|
echo '<td><input name="newaggrowner" size="32" maxlength="32" value="', \htmlspecialchars($aggrdata->fields['usename']), '" /></td>'; |
|
449
|
|
|
echo '<td><input name="newaggrschema" size="32" maxlength="32" value="', \htmlspecialchars($_REQUEST['schema']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
|
450
|
|
|
echo \sprintf( |
|
451
|
|
|
' <tr> |
|
452
|
|
|
<th class="data left">%s</th>', |
|
453
|
|
|
$this->lang['strcomment'] |
|
454
|
|
|
) . \PHP_EOL; |
|
455
|
|
|
echo "\t\t<td><textarea name=\"newaggrcomment\" rows=\"3\" cols=\"32\">", |
|
456
|
|
|
\htmlspecialchars($aggrdata->fields['aggrcomment']), "</textarea></td>\n\t</tr>" . \PHP_EOL; |
|
457
|
|
|
echo '</table>' . \PHP_EOL; |
|
458
|
|
|
echo '<p><input type="hidden" name="action" value="save_alter" />' . \PHP_EOL; |
|
459
|
|
|
echo $this->view->form; |
|
460
|
|
|
echo '<input type="hidden" name="aggrname" value="', \htmlspecialchars($_REQUEST['aggrname']), '" />' . \PHP_EOL; |
|
461
|
|
|
echo '<input type="hidden" name="aggrtype" value="', \htmlspecialchars($_REQUEST['aggrtype']), '" />' . \PHP_EOL; |
|
462
|
|
|
echo '<input type="hidden" name="aggrowner" value="', \htmlspecialchars($aggrdata->fields['usename']), '" />' . \PHP_EOL; |
|
463
|
|
|
echo '<input type="hidden" name="aggrschema" value="', \htmlspecialchars($_REQUEST['schema']), '" />' . \PHP_EOL; |
|
464
|
|
|
echo '<input type="hidden" name="aggrcomment" value="', \htmlspecialchars($aggrdata->fields['aggrcomment']), '" />' . \PHP_EOL; |
|
465
|
|
|
echo \sprintf( |
|
466
|
|
|
'<input type="submit" name="alter" value="%s" />', |
|
467
|
|
|
$this->lang['stralter'] |
|
468
|
|
|
) . \PHP_EOL; |
|
469
|
|
|
echo \sprintf( |
|
470
|
|
|
'<input type="submit" name="cancel" value="%s" /></p>%s', |
|
471
|
|
|
$this->lang['strcancel'], |
|
472
|
|
|
\PHP_EOL |
|
473
|
|
|
); |
|
474
|
|
|
} else { |
|
475
|
|
|
echo \sprintf( |
|
476
|
|
|
'<p>%s</p>', |
|
477
|
|
|
$this->lang['strnodata'] |
|
478
|
|
|
) . \PHP_EOL; |
|
479
|
|
|
echo \sprintf( |
|
480
|
|
|
'<input type="submit" name="cancel" value="%s" /></p>', |
|
481
|
|
|
$this->lang['strback'] |
|
482
|
|
|
) . \PHP_EOL; |
|
483
|
|
|
} |
|
484
|
|
|
echo '</form>' . \PHP_EOL; |
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
/** |
|
488
|
|
|
* Show confirmation of drop and perform actual drop of the aggregate function selected. |
|
489
|
|
|
* |
|
490
|
|
|
* @param mixed $confirm |
|
491
|
|
|
*/ |
|
492
|
|
|
public function doDrop($confirm): void |
|
493
|
|
|
{ |
|
494
|
|
|
$this->data = $this->misc->getDatabaseAccessor(); |
|
495
|
|
|
|
|
496
|
|
|
if ($confirm) { |
|
497
|
|
|
$this->printTrail('aggregate'); |
|
498
|
|
|
$this->printTitle($this->lang['strdrop'], 'pg.aggregate.drop'); |
|
499
|
|
|
|
|
500
|
|
|
echo '<p>', \sprintf( |
|
501
|
|
|
$this->lang['strconfdropaggregate'], |
|
502
|
|
|
\htmlspecialchars($_REQUEST['aggrname']) |
|
503
|
|
|
), '</p>' . \PHP_EOL; |
|
504
|
|
|
|
|
505
|
|
|
echo '<form action="' . \containerInstance()->subFolder . '/src/views/aggregates" method="post">' . \PHP_EOL; |
|
506
|
|
|
echo \sprintf( |
|
507
|
|
|
'<p><input type="checkbox" id="cascade" name="cascade" /> <label for="cascade">%s</label></p>', |
|
508
|
|
|
$this->lang['strcascade'] |
|
509
|
|
|
) . \PHP_EOL; |
|
510
|
|
|
echo '<p><input type="hidden" name="action" value="drop" />' . \PHP_EOL; |
|
511
|
|
|
echo '<input type="hidden" name="aggrname" value="', \htmlspecialchars($_REQUEST['aggrname']), '" />' . \PHP_EOL; |
|
512
|
|
|
echo '<input type="hidden" name="aggrtype" value="', \htmlspecialchars($_REQUEST['aggrtype']), '" />' . \PHP_EOL; |
|
513
|
|
|
echo $this->view->form; |
|
514
|
|
|
echo \sprintf( |
|
515
|
|
|
'<input type="submit" name="drop" value="%s" />', |
|
516
|
|
|
$this->lang['strdrop'] |
|
517
|
|
|
) . \PHP_EOL; |
|
518
|
|
|
echo \sprintf( |
|
519
|
|
|
'<input type="submit" name="cancel" value="%s" /></p>%s', |
|
520
|
|
|
$this->lang['strcancel'], |
|
521
|
|
|
\PHP_EOL |
|
522
|
|
|
); |
|
523
|
|
|
echo '</form>' . \PHP_EOL; |
|
524
|
|
|
} else { |
|
525
|
|
|
$status = $this->data->dropAggregate($_POST['aggrname'], $_POST['aggrtype'], isset($_POST['cascade'])); |
|
526
|
|
|
|
|
527
|
|
|
if (0 === $status) { |
|
528
|
|
|
$this->view->setReloadBrowser(true); |
|
529
|
|
|
$this->doDefault($this->lang['straggregatedropped']); |
|
530
|
|
|
} else { |
|
531
|
|
|
$this->doDefault($this->lang['straggregatedroppedbad']); |
|
532
|
|
|
} |
|
533
|
|
|
} |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
|
|
/** |
|
537
|
|
|
* Show the properties of an aggregate. |
|
538
|
|
|
* |
|
539
|
|
|
* @param mixed $msg |
|
540
|
|
|
*/ |
|
541
|
|
|
public function doProperties($msg = ''): void |
|
542
|
|
|
{ |
|
543
|
|
|
$this->data = $this->misc->getDatabaseAccessor(); |
|
544
|
|
|
|
|
545
|
|
|
$this->printTrail('aggregate'); |
|
546
|
|
|
$this->printTitle($this->lang['strproperties'], 'pg.aggregate'); |
|
547
|
|
|
$this->printMsg($msg); |
|
548
|
|
|
|
|
549
|
|
|
$aggrdata = $this->data->getAggregate($_REQUEST['aggrname'], $_REQUEST['aggrtype']); |
|
550
|
|
|
|
|
551
|
|
|
if (0 < $aggrdata->recordCount()) { |
|
552
|
|
|
// Display aggregate's info |
|
553
|
|
|
echo '<table>' . \PHP_EOL; |
|
554
|
|
|
echo \sprintf( |
|
555
|
|
|
'<tr> |
|
556
|
|
|
<th class="data left">%s</th>', |
|
557
|
|
|
$this->lang['strname'] |
|
558
|
|
|
) . \PHP_EOL; |
|
559
|
|
|
echo "\t<td class=\"data1\">", \htmlspecialchars($_REQUEST['aggrname']), "</td>\n</tr>" . \PHP_EOL; |
|
560
|
|
|
echo \sprintf( |
|
561
|
|
|
'<tr> |
|
562
|
|
|
<th class="data left">%s</th>', |
|
563
|
|
|
$this->lang['straggrbasetype'] |
|
564
|
|
|
) . \PHP_EOL; |
|
565
|
|
|
echo "\t<td class=\"data1\">", \htmlspecialchars($_REQUEST['aggrtype']), "</td>\n</tr>" . \PHP_EOL; |
|
566
|
|
|
echo \sprintf( |
|
567
|
|
|
'<tr> |
|
568
|
|
|
<th class="data left">%s</th>', |
|
569
|
|
|
$this->lang['straggrsfunc'] |
|
570
|
|
|
) . \PHP_EOL; |
|
571
|
|
|
echo "\t<td class=\"data1\">", \htmlspecialchars($aggrdata->fields['aggtransfn']), "</td>\n</tr>" . \PHP_EOL; |
|
572
|
|
|
echo \sprintf( |
|
573
|
|
|
'<tr> |
|
574
|
|
|
<th class="data left">%s</th>', |
|
575
|
|
|
$this->lang['straggrstype'] |
|
576
|
|
|
) . \PHP_EOL; |
|
577
|
|
|
echo "\t<td class=\"data1\">", \htmlspecialchars($aggrdata->fields['aggstype']), "</td>\n</tr>" . \PHP_EOL; |
|
578
|
|
|
echo \sprintf( |
|
579
|
|
|
'<tr> |
|
580
|
|
|
<th class="data left">%s</th>', |
|
581
|
|
|
$this->lang['straggrffunc'] |
|
582
|
|
|
) . \PHP_EOL; |
|
583
|
|
|
echo "\t<td class=\"data1\">", \htmlspecialchars($aggrdata->fields['aggfinalfn']), "</td>\n</tr>" . \PHP_EOL; |
|
584
|
|
|
echo \sprintf( |
|
585
|
|
|
'<tr> |
|
586
|
|
|
<th class="data left">%s</th>', |
|
587
|
|
|
$this->lang['straggrinitcond'] |
|
588
|
|
|
) . \PHP_EOL; |
|
589
|
|
|
echo "\t<td class=\"data1\">", \htmlspecialchars($aggrdata->fields['agginitval']), "</td>\n</tr>" . \PHP_EOL; |
|
590
|
|
|
|
|
591
|
|
|
if ($this->data->hasAggregateSortOp()) { |
|
592
|
|
|
echo \sprintf( |
|
593
|
|
|
'<tr> |
|
594
|
|
|
<th class="data left">%s</th>', |
|
595
|
|
|
$this->lang['straggrsortop'] |
|
596
|
|
|
) . \PHP_EOL; |
|
597
|
|
|
echo "\t<td class=\"data1\">", \htmlspecialchars($aggrdata->fields['aggsortop']), "</td>\n</tr>" . \PHP_EOL; |
|
598
|
|
|
} |
|
599
|
|
|
echo \sprintf( |
|
600
|
|
|
'<tr> |
|
601
|
|
|
<th class="data left">%s</th>', |
|
602
|
|
|
$this->lang['strowner'] |
|
603
|
|
|
) . \PHP_EOL; |
|
604
|
|
|
echo "\t<td class=\"data1\">", \htmlspecialchars($aggrdata->fields['usename']), "</td>\n</tr>" . \PHP_EOL; |
|
605
|
|
|
echo \sprintf( |
|
606
|
|
|
'<tr> |
|
607
|
|
|
<th class="data left">%s</th>', |
|
608
|
|
|
$this->lang['strcomment'] |
|
609
|
|
|
) . \PHP_EOL; |
|
610
|
|
|
echo "\t<td class=\"data1\">", $this->misc->printVal($aggrdata->fields['aggrcomment']), "</td>\n</tr>" . \PHP_EOL; |
|
611
|
|
|
echo '</table>' . \PHP_EOL; |
|
612
|
|
|
} else { |
|
613
|
|
|
echo \sprintf( |
|
614
|
|
|
'<p>%s</p>', |
|
615
|
|
|
$this->lang['strnodata'] |
|
616
|
|
|
) . \PHP_EOL; |
|
617
|
|
|
} |
|
618
|
|
|
|
|
619
|
|
|
$navlinks = [ |
|
620
|
|
|
'showall' => [ |
|
621
|
|
|
'attr' => [ |
|
622
|
|
|
'href' => [ |
|
623
|
|
|
'url' => 'aggregates', |
|
624
|
|
|
'urlvars' => [ |
|
625
|
|
|
'server' => $_REQUEST['server'], |
|
626
|
|
|
'database' => $_REQUEST['database'], |
|
627
|
|
|
'schema' => $_REQUEST['schema'], |
|
628
|
|
|
], |
|
629
|
|
|
], |
|
630
|
|
|
], |
|
631
|
|
|
'content' => $this->lang['straggrshowall'], |
|
632
|
|
|
], |
|
633
|
|
|
]; |
|
634
|
|
|
|
|
635
|
|
|
if ($this->data->hasAlterAggregate()) { |
|
636
|
|
|
$navlinks['alter'] = [ |
|
637
|
|
|
'attr' => [ |
|
638
|
|
|
'href' => [ |
|
639
|
|
|
'url' => 'aggregates', |
|
640
|
|
|
'urlvars' => [ |
|
641
|
|
|
'action' => 'alter', |
|
642
|
|
|
'server' => $_REQUEST['server'], |
|
643
|
|
|
'database' => $_REQUEST['database'], |
|
644
|
|
|
'schema' => $_REQUEST['schema'], |
|
645
|
|
|
'aggrname' => $_REQUEST['aggrname'], |
|
646
|
|
|
'aggrtype' => $_REQUEST['aggrtype'], |
|
647
|
|
|
], |
|
648
|
|
|
], |
|
649
|
|
|
], |
|
650
|
|
|
'content' => $this->lang['stralter'], |
|
651
|
|
|
]; |
|
652
|
|
|
} |
|
653
|
|
|
|
|
654
|
|
|
$navlinks['drop'] = [ |
|
655
|
|
|
'attr' => [ |
|
656
|
|
|
'href' => [ |
|
657
|
|
|
'url' => 'aggregates', |
|
658
|
|
|
'urlvars' => [ |
|
659
|
|
|
'action' => 'confirm_drop', |
|
660
|
|
|
'server' => $_REQUEST['server'], |
|
661
|
|
|
'database' => $_REQUEST['database'], |
|
662
|
|
|
'schema' => $_REQUEST['schema'], |
|
663
|
|
|
'aggrname' => $_REQUEST['aggrname'], |
|
664
|
|
|
'aggrtype' => $_REQUEST['aggrtype'], |
|
665
|
|
|
], |
|
666
|
|
|
], |
|
667
|
|
|
], |
|
668
|
|
|
'content' => $this->lang['strdrop'], |
|
669
|
|
|
]; |
|
670
|
|
|
|
|
671
|
|
|
$this->printNavLinks($navlinks, 'aggregates-properties', \get_defined_vars()); |
|
672
|
|
|
} |
|
673
|
|
|
} |
|
674
|
|
|
|