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