|
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 OperatorsController extends BaseController |
|
15
|
|
|
{ |
|
16
|
|
|
public $controller_title = 'stroperators'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Default method to render the controller according to the action parameter. |
|
20
|
|
|
*/ |
|
21
|
|
|
public function render() |
|
22
|
|
|
{ |
|
23
|
|
|
if ('tree' === $this->action) { |
|
24
|
|
|
return $this->doTree(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
$this->printHeader(); |
|
28
|
|
|
$this->printBody(); |
|
29
|
|
|
|
|
30
|
|
|
switch ($this->action) { |
|
31
|
|
|
/*case 'save_create': |
|
32
|
|
|
if($this->getPostParam('cancel')!==null){ |
|
33
|
|
|
$this->doDefault(); |
|
34
|
|
|
} else { |
|
35
|
|
|
$this->doSaveCreate(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
break; |
|
39
|
|
|
case 'create': |
|
40
|
|
|
$this->doCreate(); |
|
41
|
|
|
|
|
42
|
|
|
break;*/ |
|
43
|
|
|
case 'drop': |
|
44
|
|
|
if (null !== $this->getPostParam('cancel')) { |
|
45
|
|
|
$this->doDefault(); |
|
46
|
|
|
} else { |
|
47
|
|
|
$this->doDrop(false); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
break; |
|
51
|
|
|
case 'confirm_drop': |
|
52
|
|
|
$this->doDrop(true); |
|
53
|
|
|
|
|
54
|
|
|
break; |
|
55
|
|
|
case 'properties': |
|
56
|
|
|
$this->doProperties(); |
|
57
|
|
|
|
|
58
|
|
|
break; |
|
59
|
|
|
|
|
60
|
|
|
default: |
|
61
|
|
|
$this->doDefault(); |
|
62
|
|
|
|
|
63
|
|
|
break; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$this->printFooter(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Generate XML for the browser tree. |
|
71
|
|
|
*/ |
|
72
|
|
|
public function doTree() |
|
73
|
|
|
{ |
|
74
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
75
|
|
|
|
|
76
|
|
|
$operators = $data->getOperators(); |
|
77
|
|
|
|
|
78
|
|
|
// Operator prototype: "type operator type" |
|
79
|
|
|
$proto = Decorator::concat(Decorator::field('oprleftname'), ' ', Decorator::field('oprname'), ' ', Decorator::field('oprrightname')); |
|
80
|
|
|
|
|
81
|
|
|
$reqvars = $this->misc->getRequestVars('operator'); |
|
82
|
|
|
|
|
83
|
|
|
$attrs = [ |
|
84
|
|
|
'text' => $proto, |
|
85
|
|
|
'icon' => 'Operator', |
|
86
|
|
|
'toolTip' => Decorator::field('oprcomment'), |
|
87
|
|
|
'action' => Decorator::actionurl( |
|
88
|
|
|
'operators', |
|
89
|
|
|
$reqvars, |
|
90
|
|
|
[ |
|
91
|
|
|
'action' => 'properties', |
|
92
|
|
|
'operator' => $proto, |
|
93
|
|
|
'operator_oid' => Decorator::field('oid'), |
|
94
|
|
|
] |
|
95
|
|
|
), |
|
96
|
|
|
]; |
|
97
|
|
|
|
|
98
|
|
|
return $this->printTree($operators, $attrs, 'operators'); |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Show default list of operators in the database. |
|
103
|
|
|
* |
|
104
|
|
|
* @param mixed $msg |
|
105
|
|
|
*/ |
|
106
|
|
|
public function doDefault($msg = ''): void |
|
107
|
|
|
{ |
|
108
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
109
|
|
|
|
|
110
|
|
|
$this->printTrail('schema'); |
|
111
|
|
|
$this->printTabs('schema', 'operators'); |
|
112
|
|
|
$this->printMsg($msg); |
|
113
|
|
|
|
|
114
|
|
|
$operators = $data->getOperators(); |
|
115
|
|
|
|
|
116
|
|
|
$columns = [ |
|
117
|
|
|
'operator' => [ |
|
118
|
|
|
'title' => $this->lang['stroperator'], |
|
119
|
|
|
'field' => Decorator::field('oprname'), |
|
120
|
|
|
'url' => "operators?action=properties&{$this->misc->href}&", |
|
121
|
|
|
'vars' => ['operator' => 'oprname', 'operator_oid' => 'oid'], |
|
122
|
|
|
], |
|
123
|
|
|
'leftarg' => [ |
|
124
|
|
|
'title' => $this->lang['strleftarg'], |
|
125
|
|
|
'field' => Decorator::field('oprleftname'), |
|
126
|
|
|
], |
|
127
|
|
|
'rightarg' => [ |
|
128
|
|
|
'title' => $this->lang['strrightarg'], |
|
129
|
|
|
'field' => Decorator::field('oprrightname'), |
|
130
|
|
|
], |
|
131
|
|
|
'returns' => [ |
|
132
|
|
|
'title' => $this->lang['strreturns'], |
|
133
|
|
|
'field' => Decorator::field('resultname'), |
|
134
|
|
|
], |
|
135
|
|
|
'actions' => [ |
|
136
|
|
|
'title' => $this->lang['stractions'], |
|
137
|
|
|
], |
|
138
|
|
|
'comment' => [ |
|
139
|
|
|
'title' => $this->lang['strcomment'], |
|
140
|
|
|
'field' => Decorator::field('oprcomment'), |
|
141
|
|
|
], |
|
142
|
|
|
]; |
|
143
|
|
|
|
|
144
|
|
|
$actions = [ |
|
145
|
|
|
'drop' => [ |
|
146
|
|
|
// 'title' => $this->lang['strdrop'], |
|
147
|
|
|
// 'url' => "operators?action=confirm_drop&{$this->misc->href}&", |
|
148
|
|
|
// 'vars' => array('operator' => 'oprname', 'operator_oid' => 'oid'), |
|
149
|
|
|
'content' => $this->lang['strdrop'], |
|
150
|
|
|
'attr' => [ |
|
151
|
|
|
'href' => [ |
|
152
|
|
|
'url' => 'operators', |
|
153
|
|
|
'urlvars' => [ |
|
154
|
|
|
'action' => 'confirm_drop', |
|
155
|
|
|
'operator' => Decorator::field('oprname'), |
|
156
|
|
|
'operator_oid' => Decorator::field('oid'), |
|
157
|
|
|
], |
|
158
|
|
|
], |
|
159
|
|
|
], |
|
160
|
|
|
], |
|
161
|
|
|
]; |
|
162
|
|
|
|
|
163
|
|
|
echo $this->printTable($operators, $columns, $actions, 'operators-operators', $this->lang['strnooperators']); |
|
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
// TODO operators action=create $this->lang['strcreateoperator'] |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Show read only properties for an operator. |
|
170
|
|
|
* |
|
171
|
|
|
* @param mixed $msg |
|
172
|
|
|
*/ |
|
173
|
|
|
public function doProperties($msg = ''): void |
|
174
|
|
|
{ |
|
175
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
176
|
|
|
|
|
177
|
|
|
$this->printTrail('operator'); |
|
178
|
|
|
$this->printTitle($this->lang['strproperties'], 'pg.operator'); |
|
179
|
|
|
$this->printMsg($msg); |
|
180
|
|
|
|
|
181
|
|
|
$oprdata = $data->getOperator($_REQUEST['operator_oid']); |
|
182
|
|
|
$oprdata->fields['oprcanhash'] = $data->phpBool($oprdata->fields['oprcanhash']); |
|
183
|
|
|
|
|
184
|
|
|
if (0 < $oprdata->recordCount()) { |
|
185
|
|
|
echo '<table>' . \PHP_EOL; |
|
186
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strname']}</th>" . \PHP_EOL; |
|
187
|
|
|
echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprname']), '</td></tr>' . \PHP_EOL; |
|
188
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strleftarg']}</th>" . \PHP_EOL; |
|
189
|
|
|
echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprleftname']), '</td></tr>' . \PHP_EOL; |
|
190
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strrightarg']}</th>" . \PHP_EOL; |
|
191
|
|
|
echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprrightname']), '</td></tr>' . \PHP_EOL; |
|
192
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strcommutator']}</th>" . \PHP_EOL; |
|
193
|
|
|
echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprcom']), '</td></tr>' . \PHP_EOL; |
|
194
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strnegator']}</th>" . \PHP_EOL; |
|
195
|
|
|
echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprnegate']), '</td></tr>' . \PHP_EOL; |
|
196
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strjoin']}</th>" . \PHP_EOL; |
|
197
|
|
|
echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprjoin']), '</td></tr>' . \PHP_EOL; |
|
198
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strhashes']}</th>" . \PHP_EOL; |
|
199
|
|
|
echo '<td class="data1">', ($oprdata->fields['oprcanhash']) ? $this->lang['stryes'] : $this->lang['strno'], '</td></tr>' . \PHP_EOL; |
|
200
|
|
|
|
|
201
|
|
|
// these field only exists in 8.2 and before in pg_catalog |
|
202
|
|
|
if (isset($oprdata->fields['oprlsortop'])) { |
|
203
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strmerges']}</th>" . \PHP_EOL; |
|
204
|
|
|
echo '<td class="data1">', ('0' !== $oprdata->fields['oprlsortop'] && '0' !== $oprdata->fields['oprrsortop']) ? $this->lang['stryes'] : $this->lang['strno'], '</td></tr>' . \PHP_EOL; |
|
|
|
|
|
|
205
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strrestrict']}</th>" . \PHP_EOL; |
|
206
|
|
|
echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprrest']), '</td></tr>' . \PHP_EOL; |
|
207
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strleftsort']}</th>" . \PHP_EOL; |
|
208
|
|
|
echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprlsortop']), '</td></tr>' . \PHP_EOL; |
|
209
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strrightsort']}</th>" . \PHP_EOL; |
|
210
|
|
|
echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprrsortop']), '</td></tr>' . \PHP_EOL; |
|
211
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strlessthan']}</th>" . \PHP_EOL; |
|
212
|
|
|
echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprltcmpop']), '</td></tr>' . \PHP_EOL; |
|
213
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strgreaterthan']}</th>" . \PHP_EOL; |
|
214
|
|
|
echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprgtcmpop']), '</td></tr>' . \PHP_EOL; |
|
215
|
|
|
} else { |
|
216
|
|
|
echo "<tr><th class=\"data left\">{$this->lang['strmerges']}</th>" . \PHP_EOL; |
|
217
|
|
|
echo '<td class="data1">', $data->phpBool($oprdata->fields['oprcanmerge']) ? $this->lang['stryes'] : $this->lang['strno'], '</td></tr>' . \PHP_EOL; |
|
218
|
|
|
} |
|
219
|
|
|
echo '</table>' . \PHP_EOL; |
|
220
|
|
|
|
|
221
|
|
|
$this->printNavLinks( |
|
222
|
|
|
[ |
|
223
|
|
|
'showall' => [ |
|
224
|
|
|
'attr' => [ |
|
225
|
|
|
'href' => [ |
|
226
|
|
|
'url' => 'operators', |
|
227
|
|
|
'urlvars' => [ |
|
228
|
|
|
'server' => $_REQUEST['server'], |
|
229
|
|
|
'database' => $_REQUEST['database'], |
|
230
|
|
|
'schema' => $_REQUEST['schema'], |
|
231
|
|
|
], |
|
232
|
|
|
], |
|
233
|
|
|
], |
|
234
|
|
|
'content' => $this->lang['strshowalloperators'], |
|
235
|
|
|
], ], |
|
236
|
|
|
'operators-properties', |
|
237
|
|
|
\get_defined_vars() |
|
238
|
|
|
); |
|
239
|
|
|
} else { |
|
240
|
|
|
$this->doDefault($this->lang['strinvalidparam']); |
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Show confirmation of drop and perform actual drop. |
|
246
|
|
|
* |
|
247
|
|
|
* @param mixed $confirm |
|
248
|
|
|
*/ |
|
249
|
|
|
public function doDrop($confirm): void |
|
250
|
|
|
{ |
|
251
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
252
|
|
|
|
|
253
|
|
|
if ($confirm) { |
|
254
|
|
|
$this->printTrail('operator'); |
|
255
|
|
|
$this->printTitle($this->lang['strdrop'], 'pg.operator.drop'); |
|
256
|
|
|
|
|
257
|
|
|
echo '<p>', \sprintf($this->lang['strconfdropoperator'], $this->misc->printVal($_REQUEST['operator'])), '</p>' . \PHP_EOL; |
|
258
|
|
|
|
|
259
|
|
|
echo '<form action="' . \containerInstance()->subFolder . '/src/views/operators" method="post">' . \PHP_EOL; |
|
260
|
|
|
echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$this->lang['strcascade']}</label></p>" . \PHP_EOL; |
|
261
|
|
|
echo '<p><input type="hidden" name="action" value="drop" />' . \PHP_EOL; |
|
262
|
|
|
echo '<input type="hidden" name="operator" value="', \htmlspecialchars($_REQUEST['operator']), '" />' . \PHP_EOL; |
|
263
|
|
|
echo '<input type="hidden" name="operator_oid" value="', \htmlspecialchars($_REQUEST['operator_oid']), '" />' . \PHP_EOL; |
|
264
|
|
|
echo $this->view->form; |
|
265
|
|
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$this->lang['strdrop']}\" />" . \PHP_EOL; |
|
266
|
|
|
echo \sprintf('<input type="submit" name="cancel" value="%s" /></p>%s', $this->lang['strcancel'], \PHP_EOL); |
|
267
|
|
|
echo '</form>' . \PHP_EOL; |
|
268
|
|
|
} else { |
|
269
|
|
|
$status = $data->dropOperator($_POST['operator_oid'], isset($_POST['cascade'])); |
|
270
|
|
|
|
|
271
|
|
|
if (0 === $status) { |
|
272
|
|
|
$this->doDefault($this->lang['stroperatordropped']); |
|
273
|
|
|
} else { |
|
274
|
|
|
$this->doDefault($this->lang['stroperatordroppedbad']); |
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
|