1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHPPgAdmin v6.0.0-beta.44 |
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 FunctionsController extends BaseController |
17
|
|
|
{ |
18
|
|
|
public $table_place = 'functions-functions'; |
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
|
|
|
$header_template = 'header_datatables.twig'; |
30
|
|
|
ob_start(); |
31
|
|
|
switch ($this->action) { |
32
|
|
|
case 'save_create': |
33
|
|
|
if (isset($_POST['cancel'])) { |
34
|
|
|
$this->doDefault(); |
35
|
|
|
} else { |
36
|
|
|
$this->doSaveCreate(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
break; |
40
|
|
|
case 'create': |
41
|
|
|
$header_template = 'header_select2.twig'; |
42
|
|
|
$this->doCreate(); |
43
|
|
|
|
44
|
|
|
break; |
45
|
|
|
case 'drop': |
46
|
|
|
if (isset($_POST['drop'])) { |
47
|
|
|
$this->doDrop(false); |
48
|
|
|
} else { |
49
|
|
|
$this->doDefault(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
break; |
53
|
|
|
case 'confirm_drop': |
54
|
|
|
$this->doDrop(true); |
55
|
|
|
|
56
|
|
|
break; |
57
|
|
|
case 'save_edit': |
58
|
|
|
if (isset($_POST['cancel'])) { |
59
|
|
|
$this->doDefault(); |
60
|
|
|
} else { |
61
|
|
|
$this->doSaveEdit(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
break; |
65
|
|
|
case 'edit': |
66
|
|
|
$header_template = 'header_select2.twig'; |
67
|
|
|
$this->doEdit(); |
68
|
|
|
|
69
|
|
|
break; |
70
|
|
|
case 'properties': |
71
|
|
|
$this->doProperties(); |
72
|
|
|
|
73
|
|
|
break; |
74
|
|
|
default: |
75
|
|
|
$this->doDefault(); |
76
|
|
|
|
77
|
|
|
break; |
78
|
|
|
} |
79
|
|
|
$output = ob_get_clean(); |
80
|
|
|
|
81
|
|
|
$this->printHeader($this->lang['strfunctions'], null, true, $header_template); |
82
|
|
|
$this->printBody(); |
83
|
|
|
echo $output; |
84
|
|
|
$this->printFooter(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Show default list of functions in the database. |
89
|
|
|
* |
90
|
|
|
* @param mixed $msg |
91
|
|
|
*/ |
92
|
|
|
public function doDefault($msg = '') |
93
|
|
|
{ |
94
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
95
|
|
|
|
96
|
|
|
$this->printTrail('schema'); |
97
|
|
|
$this->printTabs('schema', 'functions'); |
98
|
|
|
$this->printMsg($msg); |
99
|
|
|
|
100
|
|
|
$funcs = $data->getFunctions(); |
101
|
|
|
|
102
|
|
|
$columns = [ |
103
|
|
|
'function' => [ |
104
|
|
|
'title' => $this->lang['strfunction'], |
105
|
|
|
'field' => Decorator::field('proproto'), |
106
|
|
|
'url' => \SUBFOLDER."/redirect/function?action=properties&{$this->misc->href}&", |
107
|
|
|
'vars' => ['function' => 'proproto', 'function_oid' => 'prooid'], |
108
|
|
|
], |
109
|
|
|
'returns' => [ |
110
|
|
|
'title' => $this->lang['strreturns'], |
111
|
|
|
'field' => Decorator::field('proreturns'), |
112
|
|
|
], |
113
|
|
|
'owner' => [ |
114
|
|
|
'title' => $this->lang['strowner'], |
115
|
|
|
'field' => Decorator::field('proowner'), |
116
|
|
|
], |
117
|
|
|
'proglanguage' => [ |
118
|
|
|
'title' => $this->lang['strproglanguage'], |
119
|
|
|
'field' => Decorator::field('prolanguage'), |
120
|
|
|
], |
121
|
|
|
'actions' => [ |
122
|
|
|
'title' => $this->lang['stractions'], |
123
|
|
|
], |
124
|
|
|
'comment' => [ |
125
|
|
|
'title' => $this->lang['strcomment'], |
126
|
|
|
'field' => Decorator::field('procomment'), |
127
|
|
|
], |
128
|
|
|
]; |
129
|
|
|
|
130
|
|
|
$actions = [ |
131
|
|
|
'multiactions' => [ |
132
|
|
|
'keycols' => ['function' => 'proproto', 'function_oid' => 'prooid'], |
133
|
|
|
'url' => 'functions', |
134
|
|
|
], |
135
|
|
|
'alter' => [ |
136
|
|
|
'content' => $this->lang['stralter'], |
137
|
|
|
'attr' => [ |
138
|
|
|
'href' => [ |
139
|
|
|
'url' => 'functions', |
140
|
|
|
'urlvars' => [ |
141
|
|
|
'action' => 'edit', |
142
|
|
|
'function' => Decorator::field('proproto'), |
143
|
|
|
'function_oid' => Decorator::field('prooid'), |
144
|
|
|
], |
145
|
|
|
], |
146
|
|
|
], |
147
|
|
|
], |
148
|
|
|
'drop' => [ |
149
|
|
|
'multiaction' => 'confirm_drop', |
150
|
|
|
'content' => $this->lang['strdrop'], |
151
|
|
|
'attr' => [ |
152
|
|
|
'href' => [ |
153
|
|
|
'url' => 'functions', |
154
|
|
|
'urlvars' => [ |
155
|
|
|
'action' => 'confirm_drop', |
156
|
|
|
'function' => Decorator::field('proproto'), |
157
|
|
|
'function_oid' => Decorator::field('prooid'), |
158
|
|
|
], |
159
|
|
|
], |
160
|
|
|
], |
161
|
|
|
], |
162
|
|
|
'privileges' => [ |
163
|
|
|
'content' => $this->lang['strprivileges'], |
164
|
|
|
'attr' => [ |
165
|
|
|
'href' => [ |
166
|
|
|
'url' => 'privileges', |
167
|
|
|
'urlvars' => [ |
168
|
|
|
'subject' => 'function', |
169
|
|
|
'function' => Decorator::field('proproto'), |
170
|
|
|
'function_oid' => Decorator::field('prooid'), |
171
|
|
|
], |
172
|
|
|
], |
173
|
|
|
], |
174
|
|
|
], |
175
|
|
|
]; |
176
|
|
|
|
177
|
|
|
echo $this->printTable($funcs, $columns, $actions, $this->table_place, $this->lang['strnofunctions']); |
178
|
|
|
|
179
|
|
|
$navlinks = [ |
180
|
|
|
'createpl' => [ |
181
|
|
|
'attr' => [ |
182
|
|
|
'href' => [ |
183
|
|
|
'url' => 'functions', |
184
|
|
|
'urlvars' => [ |
185
|
|
|
'action' => 'create', |
186
|
|
|
'server' => $_REQUEST['server'], |
187
|
|
|
'database' => $_REQUEST['database'], |
188
|
|
|
'schema' => $_REQUEST['schema'], |
189
|
|
|
], |
190
|
|
|
], |
191
|
|
|
], |
192
|
|
|
'content' => $this->lang['strcreateplfunction'], |
193
|
|
|
], |
194
|
|
|
'createinternal' => [ |
195
|
|
|
'attr' => [ |
196
|
|
|
'href' => [ |
197
|
|
|
'url' => 'functions', |
198
|
|
|
'urlvars' => [ |
199
|
|
|
'action' => 'create', |
200
|
|
|
'language' => 'internal', |
201
|
|
|
'server' => $_REQUEST['server'], |
202
|
|
|
'database' => $_REQUEST['database'], |
203
|
|
|
'schema' => $_REQUEST['schema'], |
204
|
|
|
], |
205
|
|
|
], |
206
|
|
|
], |
207
|
|
|
'content' => $this->lang['strcreateinternalfunction'], |
208
|
|
|
], |
209
|
|
|
'createc' => [ |
210
|
|
|
'attr' => [ |
211
|
|
|
'href' => [ |
212
|
|
|
'url' => 'functions', |
213
|
|
|
'urlvars' => [ |
214
|
|
|
'action' => 'create', |
215
|
|
|
'language' => 'C', |
216
|
|
|
'server' => $_REQUEST['server'], |
217
|
|
|
'database' => $_REQUEST['database'], |
218
|
|
|
'schema' => $_REQUEST['schema'], |
219
|
|
|
], |
220
|
|
|
], |
221
|
|
|
], |
222
|
|
|
'content' => $this->lang['strcreatecfunction'], |
223
|
|
|
], |
224
|
|
|
]; |
225
|
|
|
|
226
|
|
|
$this->printNavLinks($navlinks, 'functions-functions', get_defined_vars()); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Generate XML for the browser tree. |
231
|
|
|
*/ |
232
|
|
|
public function doTree() |
233
|
|
|
{ |
234
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
235
|
|
|
|
236
|
|
|
$funcs = $data->getFunctions(); |
237
|
|
|
|
238
|
|
|
$proto = Decorator::concat(Decorator::field('proname'), ' (', Decorator::field('proarguments'), ')'); |
239
|
|
|
|
240
|
|
|
$reqvars = $this->misc->getRequestVars('function'); |
241
|
|
|
|
242
|
|
|
$attrs = [ |
243
|
|
|
'text' => $proto, |
244
|
|
|
'icon' => 'Function', |
245
|
|
|
'toolTip' => Decorator::field('procomment'), |
246
|
|
|
'action' => Decorator::redirecturl( |
247
|
|
|
'redirect', |
248
|
|
|
$reqvars, |
249
|
|
|
[ |
250
|
|
|
'action' => 'properties', |
251
|
|
|
'function' => $proto, |
252
|
|
|
'function_oid' => Decorator::field('prooid'), |
253
|
|
|
] |
254
|
|
|
), |
255
|
|
|
]; |
256
|
|
|
|
257
|
|
|
return $this->printTree($funcs, $attrs, 'functions'); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Function to save after editing a function. |
262
|
|
|
*/ |
263
|
|
|
public function doSaveEdit() |
264
|
|
|
{ |
265
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
266
|
|
|
|
267
|
|
|
$fnlang = strtolower($_POST['original_lang']); |
268
|
|
|
|
269
|
|
|
if ('c' == $fnlang) { |
270
|
|
|
$def = [$_POST['formObjectFile'], $_POST['formLinkSymbol']]; |
271
|
|
|
} elseif ('internal' == $fnlang) { |
272
|
|
|
$def = $_POST['formLinkSymbol']; |
273
|
|
|
} else { |
274
|
|
|
$def = $_POST['formDefinition']; |
275
|
|
|
} |
276
|
|
|
if (!$data->hasFunctionAlterSchema()) { |
277
|
|
|
$_POST['formFuncSchema'] = ''; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
$status = $data->setFunction( |
281
|
|
|
$_POST['original_function'], |
282
|
|
|
$_POST['formFunction'], |
283
|
|
|
$_POST['original_arguments'], |
284
|
|
|
$_POST['original_returns'], |
285
|
|
|
$def, |
286
|
|
|
$_POST['original_lang'], |
287
|
|
|
$_POST['formProperties'], |
288
|
|
|
isset($_POST['original_setof']), |
289
|
|
|
$_POST['original_owner'], |
290
|
|
|
$_POST['formFuncOwn'], |
291
|
|
|
$_POST['original_schema'], |
292
|
|
|
$_POST['formFuncSchema'], |
293
|
|
|
isset($_POST['formCost']) ? $_POST['formCost'] : null, |
294
|
|
|
isset($_POST['formRows']) ? $_POST['formRows'] : 0, |
295
|
|
|
$_POST['formComment'] |
296
|
|
|
); |
297
|
|
|
|
298
|
|
|
if (0 == $status) { |
299
|
|
|
// If function has had schema altered, need to change to the new schema |
300
|
|
|
// and reload the browser frame. |
301
|
|
|
if (!empty($_POST['formFuncSchema']) && ($_POST['formFuncSchema'] != $_POST['original_schema'])) { |
302
|
|
|
// Jump them to the new function schema |
303
|
|
|
$this->misc->setCurrentSchema($_POST['formFuncSchema']); |
304
|
|
|
// Force a browser reload |
305
|
|
|
$this->misc->setReloadBrowser(true); |
306
|
|
|
} |
307
|
|
|
$this->doProperties($this->lang['strfunctionupdated']); |
308
|
|
|
} else { |
309
|
|
|
$this->doEdit($this->lang['strfunctionupdatedbad']); |
310
|
|
|
} |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* Function to allow editing of a Function. |
315
|
|
|
* |
316
|
|
|
* @param mixed $msg |
317
|
|
|
*/ |
318
|
|
|
public function doEdit($msg = '') |
319
|
|
|
{ |
320
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
321
|
|
|
|
322
|
|
|
$this->printTrail('function'); |
323
|
|
|
$this->printTitle($this->lang['stralter'], 'pg.function.alter'); |
324
|
|
|
$this->printMsg($msg); |
325
|
|
|
|
326
|
|
|
$fndata = $data->getFunction($_REQUEST['function_oid']); |
327
|
|
|
|
328
|
|
|
if ($fndata->recordCount() > 0) { |
329
|
|
|
$fndata->fields['proretset'] = $data->phpBool($fndata->fields['proretset']); |
330
|
|
|
|
331
|
|
|
// Initialise variables |
332
|
|
|
if (!isset($_POST['formDefinition'])) { |
333
|
|
|
$_POST['formDefinition'] = $fndata->fields['prosrc']; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
if (!isset($_POST['formProperties'])) { |
337
|
|
|
$_POST['formProperties'] = $data->getFunctionProperties($fndata->fields); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
if (!isset($_POST['formFunction'])) { |
341
|
|
|
$_POST['formFunction'] = $fndata->fields['proname']; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
if (!isset($_POST['formComment'])) { |
345
|
|
|
$_POST['formComment'] = $fndata->fields['procomment']; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
if (!isset($_POST['formObjectFile'])) { |
349
|
|
|
$_POST['formObjectFile'] = $fndata->fields['probin']; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
if (!isset($_POST['formLinkSymbol'])) { |
353
|
|
|
$_POST['formLinkSymbol'] = $fndata->fields['prosrc']; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
if (!isset($_POST['formFuncOwn'])) { |
357
|
|
|
$_POST['formFuncOwn'] = $fndata->fields['proowner']; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
if (!isset($_POST['formFuncSchema'])) { |
361
|
|
|
$_POST['formFuncSchema'] = $fndata->fields['proschema']; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
if ($data->hasFunctionCosting()) { |
365
|
|
|
if (!isset($_POST['formCost'])) { |
366
|
|
|
$_POST['formCost'] = $fndata->fields['procost']; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
if (!isset($_POST['formRows'])) { |
370
|
|
|
$_POST['formRows'] = $fndata->fields['prorows']; |
371
|
|
|
} |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
// Deal with named parameters |
375
|
|
|
if ($data->hasNamedParams()) { |
376
|
|
|
if (isset($fndata->fields['proallarguments'])) { |
377
|
|
|
$args_arr = $data->phpArray($fndata->fields['proallarguments']); |
378
|
|
|
} else { |
379
|
|
|
$args_arr = explode(', ', $fndata->fields['proarguments']); |
380
|
|
|
} |
381
|
|
|
$names_arr = $data->phpArray($fndata->fields['proargnames']); |
382
|
|
|
$modes_arr = $data->phpArray($fndata->fields['proargmodes']); |
383
|
|
|
$args = ''; |
384
|
|
|
$args_arr_size = sizeof($args_arr); |
385
|
|
|
for ($i = 0; $i < $args_arr_size; ++$i) { |
386
|
|
|
if (0 != $i) { |
387
|
|
|
$args .= ', '; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
if (isset($modes_arr[$i])) { |
391
|
|
|
switch ($modes_arr[$i]) { |
392
|
|
|
case 'i': |
393
|
|
|
$args .= ' IN '; |
394
|
|
|
|
395
|
|
|
break; |
396
|
|
|
case 'o': |
397
|
|
|
$args .= ' OUT '; |
398
|
|
|
|
399
|
|
|
break; |
400
|
|
|
case 'b': |
401
|
|
|
$args .= ' INOUT '; |
402
|
|
|
|
403
|
|
|
break; |
404
|
|
|
case 'v': |
405
|
|
|
$args .= ' VARIADIC '; |
406
|
|
|
|
407
|
|
|
break; |
408
|
|
|
case 't': |
409
|
|
|
$args .= ' TABLE '; |
410
|
|
|
|
411
|
|
|
break; |
412
|
|
|
} |
413
|
|
|
} |
414
|
|
|
if (isset($names_arr[$i]) && '' != $names_arr[$i]) { |
415
|
|
|
$data->fieldClean($names_arr[$i]); |
416
|
|
|
$args .= '"'.$names_arr[$i].'" '; |
417
|
|
|
} |
418
|
|
|
$args .= $args_arr[$i]; |
419
|
|
|
} |
420
|
|
|
} else { |
421
|
|
|
$args = $fndata->fields['proarguments']; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
echo '<form action="'.\SUBFOLDER."/src/views/functions\" method=\"post\">\n"; |
425
|
|
|
echo "<table style=\"width: 90%\">\n"; |
426
|
|
|
echo "<tr>\n"; |
427
|
|
|
echo "<th class=\"data required\">{$this->lang['strschema']}</th>\n"; |
428
|
|
|
echo "<th class=\"data required\">{$this->lang['strfunction']}</th>\n"; |
429
|
|
|
echo "<th class=\"data\">{$this->lang['strarguments']}</th>\n"; |
430
|
|
|
echo "<th class=\"data required\">{$this->lang['strreturns']}</th>\n"; |
431
|
|
|
echo "<th class=\"data required\">{$this->lang['strproglanguage']}</th>\n"; |
432
|
|
|
echo "</tr>\n"; |
433
|
|
|
|
434
|
|
|
echo "<tr>\n"; |
435
|
|
|
echo '<td class="data1">'; |
436
|
|
|
echo '<input type="hidden" name="original_schema" value="', htmlspecialchars($fndata->fields['proschema']), "\" />\n"; |
437
|
|
|
if ($data->hasFunctionAlterSchema()) { |
438
|
|
|
$schemas = $data->getSchemas(); |
439
|
|
|
echo '<select name="formFuncSchema">'; |
440
|
|
|
while (!$schemas->EOF) { |
441
|
|
|
$schema = $schemas->fields['nspname']; |
442
|
|
|
echo '<option value="', htmlspecialchars($schema), '"', |
443
|
|
|
($schema == $_POST['formFuncSchema']) ? ' selected="selected"' : '', '>', htmlspecialchars($schema), "</option>\n"; |
444
|
|
|
$schemas->moveNext(); |
445
|
|
|
} |
446
|
|
|
echo "</select>\n"; |
447
|
|
|
} else { |
448
|
|
|
echo $fndata->fields['proschema']; |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
echo "</td>\n"; |
452
|
|
|
echo '<td class="data1">'; |
453
|
|
|
echo '<input type="hidden" name="original_function" value="', htmlspecialchars($fndata->fields['proname']), "\" />\n"; |
454
|
|
|
echo "<input name=\"formFunction\" style=\"width: 100%\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_POST['formFunction']), '" />'; |
455
|
|
|
echo "</td>\n"; |
456
|
|
|
|
457
|
|
|
echo '<td class="data1">', $this->misc->printVal($args), "\n"; |
458
|
|
|
echo '<input type="hidden" name="original_arguments" value="', htmlspecialchars($args), "\" />\n"; |
459
|
|
|
echo "</td>\n"; |
460
|
|
|
|
461
|
|
|
echo '<td class="data1">'; |
462
|
|
|
if ($fndata->fields['proretset']) { |
463
|
|
|
echo 'setof '; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
echo $this->misc->printVal($fndata->fields['proresult']), "\n"; |
467
|
|
|
echo '<input type="hidden" name="original_returns" value="', htmlspecialchars($fndata->fields['proresult']), "\" />\n"; |
468
|
|
|
if ($fndata->fields['proretset']) { |
469
|
|
|
echo "<input type=\"hidden\" name=\"original_setof\" value=\"yes\" />\n"; |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
echo "</td>\n"; |
473
|
|
|
|
474
|
|
|
echo '<td class="data1">', $this->misc->printVal($fndata->fields['prolanguage']), "\n"; |
475
|
|
|
echo '<input type="hidden" name="original_lang" value="', htmlspecialchars($fndata->fields['prolanguage']), "\" />\n"; |
476
|
|
|
echo "</td>\n"; |
477
|
|
|
echo "</tr>\n"; |
478
|
|
|
|
479
|
|
|
$fnlang = strtolower($fndata->fields['prolanguage']); |
480
|
|
|
if ('c' == $fnlang) { |
481
|
|
|
echo "<tr><th class=\"data required\" colspan=\"2\">{$this->lang['strobjectfile']}</th>\n"; |
482
|
|
|
echo "<th class=\"data\" colspan=\"2\">{$this->lang['strlinksymbol']}</th></tr>\n"; |
483
|
|
|
echo '<tr><td class="data1" colspan="2"><input type="text" name="formObjectFile" style="width:100%" value="', |
484
|
|
|
htmlspecialchars($_POST['formObjectFile']), "\" /></td>\n"; |
485
|
|
|
echo '<td class="data1" colspan="2"><input type="text" name="formLinkSymbol" style="width:100%" value="', |
486
|
|
|
htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n"; |
487
|
|
|
} elseif ('internal' == $fnlang) { |
488
|
|
|
echo "<tr><th class=\"data\" colspan=\"5\">{$this->lang['strlinksymbol']}</th></tr>\n"; |
489
|
|
|
echo '<tr><td class="data1" colspan="5"><input type="text" name="formLinkSymbol" style="width:100%" value="', |
490
|
|
|
htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n"; |
491
|
|
|
} else { |
492
|
|
|
echo "<tr><th class=\"data required\" colspan=\"5\">{$this->lang['strdefinition']}</th></tr>\n"; |
493
|
|
|
echo '<tr><td class="data1" colspan="5"><textarea style="width:100%;" rows="20" cols="50" name="formDefinition">', |
494
|
|
|
htmlspecialchars($_POST['formDefinition']), "</textarea></td></tr>\n"; |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
// Display function comment |
498
|
|
|
echo "<tr><th class=\"data\" colspan=\"5\">{$this->lang['strcomment']}</th></tr>\n"; |
499
|
|
|
echo '<tr><td class="data1" colspan="5"><textarea style="width:100%;" name="formComment" rows="3" cols="50">', |
500
|
|
|
htmlspecialchars($_POST['formComment']), "</textarea></td></tr>\n"; |
501
|
|
|
|
502
|
|
|
// Display function cost options |
503
|
|
|
if ($data->hasFunctionCosting()) { |
504
|
|
|
echo "<tr><th class=\"data required\" colspan=\"5\">{$this->lang['strfunctioncosting']}</th></tr>\n"; |
505
|
|
|
echo "<td class=\"data1\" colspan=\"2\">{$this->lang['strexecutioncost']}: <input name=\"formCost\" size=\"16\" value=\"". |
506
|
|
|
htmlspecialchars($_POST['formCost']).'" /></td>'; |
507
|
|
|
echo "<td class=\"data1\" colspan=\"2\">{$this->lang['strresultrows']}: <input name=\"formRows\" size=\"16\" value=\"", |
508
|
|
|
htmlspecialchars($_POST['formRows']), '"', (!$fndata->fields['proretset']) ? 'disabled' : '', '/></td>'; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
// Display function properties |
512
|
|
|
if (is_array($data->funcprops) && sizeof($data->funcprops) > 0) { |
513
|
|
|
echo "<tr><th class=\"data\" colspan=\"5\">{$this->lang['strproperties']}</th></tr>\n"; |
514
|
|
|
echo "<tr><td class=\"data1\" colspan=\"5\">\n"; |
515
|
|
|
$i = 0; |
516
|
|
|
foreach ($data->funcprops as $k => $v) { |
517
|
|
|
echo "<select name=\"formProperties[{$i}]\">\n"; |
518
|
|
|
foreach ($v as $p) { |
519
|
|
|
echo '<option value="', htmlspecialchars($p), '"', |
520
|
|
|
($_POST['formProperties'][$i] == $p) ? ' selected="selected"' : '', |
521
|
|
|
'>', $this->misc->printVal($p), "</option>\n"; |
522
|
|
|
} |
523
|
|
|
echo "</select><br />\n"; |
524
|
|
|
++$i; |
525
|
|
|
} |
526
|
|
|
echo "</td></tr>\n"; |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
// function owner |
530
|
|
|
if ($data->hasFunctionAlterOwner()) { |
531
|
|
|
$users = $data->getUsers(); |
532
|
|
|
echo "<tr><td class=\"data1\" colspan=\"5\">{$this->lang['strowner']}: <select name=\"formFuncOwn\">"; |
533
|
|
|
while (!$users->EOF) { |
534
|
|
|
$uname = $users->fields['usename']; |
535
|
|
|
echo '<option value="', htmlspecialchars($uname), '"', |
536
|
|
|
($uname == $_POST['formFuncOwn']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n"; |
537
|
|
|
$users->moveNext(); |
538
|
|
|
} |
539
|
|
|
echo "</select>\n"; |
540
|
|
|
echo '<input type="hidden" name="original_owner" value="', htmlspecialchars($fndata->fields['proowner']), "\" />\n"; |
541
|
|
|
echo "</td></tr>\n"; |
542
|
|
|
} |
543
|
|
|
echo "</table>\n"; |
544
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n"; |
545
|
|
|
echo '<input type="hidden" name="function" value="', htmlspecialchars($_REQUEST['function']), "\" />\n"; |
546
|
|
|
echo '<input type="hidden" name="function_oid" value="', htmlspecialchars($_REQUEST['function_oid']), "\" />\n"; |
547
|
|
|
echo $this->misc->form; |
548
|
|
|
echo "<input type=\"submit\" value=\"{$this->lang['stralter']}\" />\n"; |
549
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
550
|
|
|
echo "</form>\n"; |
551
|
|
|
} else { |
552
|
|
|
echo "<p>{$this->lang['strnodata']}</p>\n"; |
553
|
|
|
} |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
/** |
557
|
|
|
* Show read only properties of a function. |
558
|
|
|
* |
559
|
|
|
* @param mixed $msg |
560
|
|
|
*/ |
561
|
|
|
public function doProperties($msg = '') |
562
|
|
|
{ |
563
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
564
|
|
|
|
565
|
|
|
$this->printTrail('function'); |
566
|
|
|
$this->printTitle($this->lang['strproperties'], 'pg.function'); |
567
|
|
|
$this->printMsg($msg); |
568
|
|
|
|
569
|
|
|
$funcdata = $data->getFunction($_REQUEST['function_oid']); |
570
|
|
|
$func_full = ''; |
571
|
|
|
if ($funcdata->recordCount() > 0) { |
572
|
|
|
// Deal with named parameters |
573
|
|
|
if ($data->hasNamedParams()) { |
574
|
|
|
if (isset($funcdata->fields['proallarguments'])) { |
575
|
|
|
$args_arr = $data->phpArray($funcdata->fields['proallarguments']); |
576
|
|
|
} else { |
577
|
|
|
$args_arr = explode(', ', $funcdata->fields['proarguments']); |
578
|
|
|
} |
579
|
|
|
$names_arr = $data->phpArray($funcdata->fields['proargnames']); |
580
|
|
|
$modes_arr = $data->phpArray($funcdata->fields['proargmodes']); |
581
|
|
|
$args = ''; |
582
|
|
|
$args_arr_size = sizeof($args_arr); |
583
|
|
|
for ($i = 0; $i < $args_arr_size; ++$i) { |
584
|
|
|
if (0 != $i) { |
585
|
|
|
$args .= ', '; |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
if (isset($modes_arr[$i])) { |
589
|
|
|
switch ($modes_arr[$i]) { |
590
|
|
|
case 'i': |
591
|
|
|
$args .= ' IN '; |
592
|
|
|
|
593
|
|
|
break; |
594
|
|
|
case 'o': |
595
|
|
|
$args .= ' OUT '; |
596
|
|
|
|
597
|
|
|
break; |
598
|
|
|
case 'b': |
599
|
|
|
$args .= ' INOUT '; |
600
|
|
|
|
601
|
|
|
break; |
602
|
|
|
case 'v': |
603
|
|
|
$args .= ' VARIADIC '; |
604
|
|
|
|
605
|
|
|
break; |
606
|
|
|
case 't': |
607
|
|
|
$args .= ' TABLE '; |
608
|
|
|
|
609
|
|
|
break; |
610
|
|
|
} |
611
|
|
|
} |
612
|
|
|
if (isset($names_arr[$i]) && '' != $names_arr[$i]) { |
613
|
|
|
$data->fieldClean($names_arr[$i]); |
614
|
|
|
$args .= '"'.$names_arr[$i].'" '; |
615
|
|
|
} |
616
|
|
|
$args .= $args_arr[$i]; |
617
|
|
|
} |
618
|
|
|
} else { |
619
|
|
|
$args = $funcdata->fields['proarguments']; |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
// Show comment if any |
623
|
|
|
if (null !== $funcdata->fields['procomment']) { |
624
|
|
|
echo '<p class="comment">', $this->misc->printVal($funcdata->fields['procomment']), "</p>\n"; |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
$funcdata->fields['proretset'] = $data->phpBool($funcdata->fields['proretset']); |
628
|
|
|
$func_full = $funcdata->fields['proname'].'('.$funcdata->fields['proarguments'].')'; |
629
|
|
|
echo "<table style=\"width: 90%\">\n"; |
630
|
|
|
echo "<tr><th class=\"data\">{$this->lang['strfunction']}</th>\n"; |
631
|
|
|
echo "<th class=\"data\">{$this->lang['strarguments']}</th>\n"; |
632
|
|
|
echo "<th class=\"data\">{$this->lang['strreturns']}</th>\n"; |
633
|
|
|
echo "<th class=\"data\">{$this->lang['strproglanguage']}</th></tr>\n"; |
634
|
|
|
echo '<tr><td class="data1">', $this->misc->printVal($funcdata->fields['proname']), "</td>\n"; |
635
|
|
|
echo '<td class="data1">', $this->misc->printVal($args), "</td>\n"; |
636
|
|
|
echo '<td class="data1">'; |
637
|
|
|
if ($funcdata->fields['proretset']) { |
638
|
|
|
echo 'setof '; |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
echo $this->misc->printVal($funcdata->fields['proresult']), "</td>\n"; |
642
|
|
|
echo '<td class="data1">', $this->misc->printVal($funcdata->fields['prolanguage']), "</td></tr>\n"; |
643
|
|
|
|
644
|
|
|
$fnlang = strtolower($funcdata->fields['prolanguage']); |
645
|
|
|
if ('c' == $fnlang) { |
646
|
|
|
echo "<tr><th class=\"data\" colspan=\"2\">{$this->lang['strobjectfile']}</th>\n"; |
647
|
|
|
echo "<th class=\"data\" colspan=\"2\">{$this->lang['strlinksymbol']}</th></tr>\n"; |
648
|
|
|
echo '<tr><td class="data1" colspan="2">', $this->misc->printVal($funcdata->fields['probin']), "</td>\n"; |
649
|
|
|
echo '<td class="data1" colspan="2">', $this->misc->printVal($funcdata->fields['prosrc']), "</td></tr>\n"; |
650
|
|
|
} elseif ('internal' == $fnlang) { |
651
|
|
|
echo "<tr><th class=\"data\" colspan=\"4\">{$this->lang['strlinksymbol']}</th></tr>\n"; |
652
|
|
|
echo '<tr><td class="data1" colspan="4">', $this->misc->printVal($funcdata->fields['prosrc']), "</td></tr>\n"; |
653
|
|
|
} else { |
654
|
|
|
$highlight = new \PHPPgAdmin\Highlight(); |
655
|
|
|
|
656
|
|
|
echo "<tr><th class=\"data\" colspan=\"4\">{$this->lang['strdefinition']}</th></tr>\n"; |
657
|
|
|
// Check to see if we have syntax highlighting for this language |
658
|
|
|
if (array_key_exists($fnlang, $data->langmap)) { |
659
|
|
|
$temp = $highlight->syntax_highlight(htmlspecialchars($funcdata->fields['prosrc']), $data->langmap[$fnlang]); |
660
|
|
|
$tag = 'prenoescape'; |
661
|
|
|
} else { |
662
|
|
|
$temp = $funcdata->fields['prosrc']; |
663
|
|
|
$tag = 'pre'; |
664
|
|
|
} |
665
|
|
|
echo '<tr><td class="data1" colspan="4">', $this->misc->printVal($temp, $tag, ['lineno' => true, 'class' => 'data1']), "</td></tr>\n"; |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
// Display function cost options |
669
|
|
|
if ($data->hasFunctionCosting()) { |
670
|
|
|
echo "<tr><th class=\"data required\" colspan=\"4\">{$this->lang['strfunctioncosting']}</th></tr>\n"; |
671
|
|
|
echo "<td class=\"data1\" colspan=\"2\">{$this->lang['strexecutioncost']}: ", $this->misc->printVal($funcdata->fields['procost']), ' </td>'; |
672
|
|
|
echo "<td class=\"data1\" colspan=\"2\">{$this->lang['strresultrows']}: ", $this->misc->printVal($funcdata->fields['prorows']), ' </td>'; |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
// Show flags |
676
|
|
|
if (is_array($data->funcprops) && sizeof($data->funcprops) > 0) { |
677
|
|
|
// Fetch an array of the function properties |
678
|
|
|
$funcprops = $data->getFunctionProperties($funcdata->fields); |
679
|
|
|
echo "<tr><th class=\"data\" colspan=\"4\">{$this->lang['strproperties']}</th></tr>\n"; |
680
|
|
|
echo "<tr><td class=\"data1\" colspan=\"4\">\n"; |
681
|
|
|
foreach ($funcprops as $v) { |
682
|
|
|
echo $this->misc->printVal($v), "<br />\n"; |
683
|
|
|
} |
684
|
|
|
echo "</td></tr>\n"; |
685
|
|
|
} |
686
|
|
|
|
687
|
|
|
echo "<tr><td class=\"data1\" colspan=\"5\">{$this->lang['strowner']}: ", htmlspecialchars($funcdata->fields['proowner']), "\n"; |
688
|
|
|
echo "</td></tr>\n"; |
689
|
|
|
echo "</table>\n"; |
690
|
|
|
} else { |
691
|
|
|
echo "<p>{$this->lang['strnodata']}</p>\n"; |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
$navlinks = [ |
695
|
|
|
'showall' => [ |
696
|
|
|
'attr' => [ |
697
|
|
|
'href' => [ |
698
|
|
|
'url' => 'functions', |
699
|
|
|
'urlvars' => [ |
700
|
|
|
'server' => $_REQUEST['server'], |
701
|
|
|
'database' => $_REQUEST['database'], |
702
|
|
|
'schema' => $_REQUEST['schema'], |
703
|
|
|
], |
704
|
|
|
], |
705
|
|
|
], |
706
|
|
|
'content' => $this->lang['strshowallfunctions'], |
707
|
|
|
], |
708
|
|
|
'alter' => [ |
709
|
|
|
'attr' => [ |
710
|
|
|
'href' => [ |
711
|
|
|
'url' => 'functions', |
712
|
|
|
'urlvars' => [ |
713
|
|
|
'action' => 'edit', |
714
|
|
|
'server' => $_REQUEST['server'], |
715
|
|
|
'database' => $_REQUEST['database'], |
716
|
|
|
'schema' => $_REQUEST['schema'], |
717
|
|
|
'function' => $_REQUEST['function'], |
718
|
|
|
'function_oid' => $_REQUEST['function_oid'], |
719
|
|
|
], |
720
|
|
|
], |
721
|
|
|
], |
722
|
|
|
'content' => $this->lang['stralter'], |
723
|
|
|
], |
724
|
|
|
'drop' => [ |
725
|
|
|
'attr' => [ |
726
|
|
|
'href' => [ |
727
|
|
|
'url' => 'functions', |
728
|
|
|
'urlvars' => [ |
729
|
|
|
'action' => 'confirm_drop', |
730
|
|
|
'server' => $_REQUEST['server'], |
731
|
|
|
'database' => $_REQUEST['database'], |
732
|
|
|
'schema' => $_REQUEST['schema'], |
733
|
|
|
'function' => $func_full, |
734
|
|
|
'function_oid' => $_REQUEST['function_oid'], |
735
|
|
|
], |
736
|
|
|
], |
737
|
|
|
], |
738
|
|
|
'content' => $this->lang['strdrop'], |
739
|
|
|
], |
740
|
|
|
]; |
741
|
|
|
|
742
|
|
|
$this->printNavLinks($navlinks, 'functions-properties', get_defined_vars()); |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
/** |
746
|
|
|
* Show confirmation of drop and perform actual drop. |
747
|
|
|
* |
748
|
|
|
* @param mixed $confirm |
749
|
|
|
*/ |
750
|
|
|
public function doDrop($confirm) |
751
|
|
|
{ |
752
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
753
|
|
|
|
754
|
|
|
if (empty($_REQUEST['function']) && empty($_REQUEST['ma'])) { |
755
|
|
|
return $this->doDefault($this->lang['strspecifyfunctiontodrop']); |
756
|
|
|
} |
757
|
|
|
|
758
|
|
|
if ($confirm) { |
759
|
|
|
$this->printTrail('schema'); |
760
|
|
|
$this->printTitle($this->lang['strdrop'], 'pg.function.drop'); |
761
|
|
|
|
762
|
|
|
echo '<form action="'.\SUBFOLDER."/src/views/functions\" method=\"post\">\n"; |
763
|
|
|
|
764
|
|
|
//If multi drop |
765
|
|
|
if (isset($_REQUEST['ma'])) { |
766
|
|
|
foreach ($_REQUEST['ma'] as $v) { |
767
|
|
|
$a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
768
|
|
|
echo '<p>', sprintf($this->lang['strconfdropfunction'], $this->misc->printVal($a['function'])), "</p>\n"; |
769
|
|
|
echo '<input type="hidden" name="function[]" value="', htmlspecialchars($a['function']), "\" />\n"; |
770
|
|
|
echo '<input type="hidden" name="function_oid[]" value="', htmlspecialchars($a['function_oid']), "\" />\n"; |
771
|
|
|
} |
772
|
|
|
} else { |
773
|
|
|
echo '<p>', sprintf($this->lang['strconfdropfunction'], $this->misc->printVal($_REQUEST['function'])), "</p>\n"; |
774
|
|
|
echo '<input type="hidden" name="function" value="', htmlspecialchars($_REQUEST['function']), "\" />\n"; |
775
|
|
|
echo '<input type="hidden" name="function_oid" value="', htmlspecialchars($_REQUEST['function_oid']), "\" />\n"; |
776
|
|
|
} |
777
|
|
|
|
778
|
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n"; |
779
|
|
|
|
780
|
|
|
echo $this->misc->form; |
781
|
|
|
echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /><label for=\"cascade\">{$this->lang['strcascade']}</label></p>\n"; |
782
|
|
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$this->lang['strdrop']}\" />\n"; |
783
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />\n"; |
784
|
|
|
echo "</form>\n"; |
785
|
|
|
} else { |
786
|
|
|
if (is_array($_POST['function_oid'])) { |
787
|
|
|
$msg = ''; |
788
|
|
|
$status = $data->beginTransaction(); |
789
|
|
|
if (0 == $status) { |
790
|
|
|
foreach ($_POST['function_oid'] as $k => $s) { |
791
|
|
|
$status = $data->dropFunction($s, isset($_POST['cascade'])); |
792
|
|
|
if (0 == $status) { |
793
|
|
|
$msg .= sprintf('%s: %s<br />', htmlentities($_POST['function'][$k], ENT_QUOTES, 'UTF-8'), $this->lang['strfunctiondropped']); |
794
|
|
|
} else { |
795
|
|
|
$data->endTransaction(); |
796
|
|
|
$this->doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($_POST['function'][$k], ENT_QUOTES, 'UTF-8'), $this->lang['strfunctiondroppedbad'])); |
797
|
|
|
|
798
|
|
|
return; |
799
|
|
|
} |
800
|
|
|
} |
801
|
|
|
} |
802
|
|
|
if (0 == $data->endTransaction()) { |
803
|
|
|
// Everything went fine, back to the Default page.... |
804
|
|
|
$this->misc->setReloadBrowser(true); |
805
|
|
|
$this->doDefault($msg); |
806
|
|
|
} else { |
807
|
|
|
$this->doDefault($this->lang['strfunctiondroppedbad']); |
808
|
|
|
} |
809
|
|
|
} else { |
810
|
|
|
$status = $data->dropFunction($_POST['function_oid'], isset($_POST['cascade'])); |
811
|
|
|
if (0 == $status) { |
812
|
|
|
$this->misc->setReloadBrowser(true); |
813
|
|
|
$this->doDefault($this->lang['strfunctiondropped']); |
814
|
|
|
} else { |
815
|
|
|
$this->doDefault($this->lang['strfunctiondroppedbad']); |
816
|
|
|
} |
817
|
|
|
} |
818
|
|
|
} |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
/** |
822
|
|
|
* Displays a screen where they can enter a new function. |
823
|
|
|
* |
824
|
|
|
* @param string $msg message to display |
825
|
|
|
* @param mixed $szJS |
826
|
|
|
*/ |
827
|
|
|
public function doCreate($msg = '', $szJS = '') |
828
|
|
|
{ |
829
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
830
|
|
|
|
831
|
|
|
$this->printTrail('schema'); |
832
|
|
|
if (!isset($_POST['formFunction'])) { |
833
|
|
|
$_POST['formFunction'] = ''; |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
if (!isset($_POST['formArguments'])) { |
837
|
|
|
$_POST['formArguments'] = ''; |
838
|
|
|
} |
839
|
|
|
|
840
|
|
|
if (!isset($_POST['formReturns'])) { |
841
|
|
|
$_POST['formReturns'] = ''; |
842
|
|
|
} |
843
|
|
|
|
844
|
|
|
if (!isset($_POST['formLanguage'])) { |
845
|
|
|
$_POST['formLanguage'] = isset($_REQUEST['language']) ? $_REQUEST['language'] : 'sql'; |
846
|
|
|
} |
847
|
|
|
|
848
|
|
|
if (!isset($_POST['formDefinition'])) { |
849
|
|
|
$_POST['formDefinition'] = ''; |
850
|
|
|
} |
851
|
|
|
|
852
|
|
|
if (!isset($_POST['formObjectFile'])) { |
853
|
|
|
$_POST['formObjectFile'] = ''; |
854
|
|
|
} |
855
|
|
|
|
856
|
|
|
if (!isset($_POST['formLinkSymbol'])) { |
857
|
|
|
$_POST['formLinkSymbol'] = ''; |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
if (!isset($_POST['formProperties'])) { |
861
|
|
|
$_POST['formProperties'] = $data->defaultprops; |
862
|
|
|
} |
863
|
|
|
|
864
|
|
|
if (!isset($_POST['formSetOf'])) { |
865
|
|
|
$_POST['formSetOf'] = ''; |
866
|
|
|
} |
867
|
|
|
|
868
|
|
|
if (!isset($_POST['formArray'])) { |
869
|
|
|
$_POST['formArray'] = ''; |
870
|
|
|
} |
871
|
|
|
|
872
|
|
|
if (!isset($_POST['formCost'])) { |
873
|
|
|
$_POST['formCost'] = ''; |
874
|
|
|
} |
875
|
|
|
|
876
|
|
|
if (!isset($_POST['formRows'])) { |
877
|
|
|
$_POST['formRows'] = ''; |
878
|
|
|
} |
879
|
|
|
|
880
|
|
|
if (!isset($_POST['formComment'])) { |
881
|
|
|
$_POST['formComment'] = ''; |
882
|
|
|
} |
883
|
|
|
|
884
|
|
|
$types = $data->getTypes(true, true, true); |
885
|
|
|
$langs = $data->getLanguages(true); |
886
|
|
|
$fnlang = strtolower($_POST['formLanguage']); |
887
|
|
|
|
888
|
|
|
switch ($fnlang) { |
889
|
|
|
case 'c': |
890
|
|
|
$this->printTitle($this->lang['strcreatecfunction'], 'pg.function.create.c'); |
891
|
|
|
|
892
|
|
|
break; |
893
|
|
|
case 'internal': |
894
|
|
|
$this->printTitle($this->lang['strcreateinternalfunction'], 'pg.function.create.internal'); |
895
|
|
|
|
896
|
|
|
break; |
897
|
|
|
default: |
898
|
|
|
$this->printTitle($this->lang['strcreateplfunction'], 'pg.function.create.pl'); |
899
|
|
|
|
900
|
|
|
break; |
901
|
|
|
} |
902
|
|
|
$this->printMsg($msg); |
903
|
|
|
|
904
|
|
|
// Create string for return type list |
905
|
|
|
$szTypes = ''; |
906
|
|
|
while (!$types->EOF) { |
907
|
|
|
$szSelected = ''; |
908
|
|
|
if ($types->fields['typname'] == $_POST['formReturns']) { |
909
|
|
|
$szSelected = ' selected="selected"'; |
910
|
|
|
} |
911
|
|
|
// this variable is include in the JS code bellow, so we need to ENT_QUOTES |
912
|
|
|
$szTypes .= '<option value="'.htmlspecialchars($types->fields['typname'], ENT_QUOTES)."\"{$szSelected}>"; |
913
|
|
|
$szTypes .= htmlspecialchars($types->fields['typname'], ENT_QUOTES).'</option>'; |
914
|
|
|
$types->moveNext(); |
915
|
|
|
} |
916
|
|
|
|
917
|
|
|
$szFunctionName = "<td class=\"data1\"><input name=\"formFunction\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"". |
918
|
|
|
htmlspecialchars($_POST['formFunction']).'" /></td>'; |
919
|
|
|
|
920
|
|
|
$szArguments = '<td class="data1"><input name="formArguments" style="width:100%;" size="16" value="'. |
921
|
|
|
htmlspecialchars($_POST['formArguments']).'" /></td>'; |
922
|
|
|
|
923
|
|
|
$szSetOfSelected = ''; |
924
|
|
|
$szNotSetOfSelected = ''; |
925
|
|
|
if ('' == $_POST['formSetOf']) { |
926
|
|
|
$szNotSetOfSelected = ' selected="selected"'; |
927
|
|
|
} elseif ('SETOF' == $_POST['formSetOf']) { |
928
|
|
|
$szSetOfSelected = ' selected="selected"'; |
929
|
|
|
} |
930
|
|
|
$szReturns = '<td class="data1" colspan="2">'; |
931
|
|
|
$szReturns .= '<select name="formSetOf">'; |
932
|
|
|
$szReturns .= "<option value=\"\"{$szNotSetOfSelected}></option>"; |
933
|
|
|
$szReturns .= "<option value=\"SETOF\"{$szSetOfSelected}>SETOF</option>"; |
934
|
|
|
$szReturns .= '</select>'; |
935
|
|
|
|
936
|
|
|
$szReturns .= '<select class="select2" name="formReturns">'.$szTypes.'</select>'; |
937
|
|
|
|
938
|
|
|
// Create string array type selector |
939
|
|
|
|
940
|
|
|
$szArraySelected = ''; |
941
|
|
|
$szNotArraySelected = ''; |
942
|
|
|
if ('' == $_POST['formArray']) { |
943
|
|
|
$szNotArraySelected = ' selected="selected"'; |
944
|
|
|
} elseif ('[]' == $_POST['formArray']) { |
945
|
|
|
$szArraySelected = ' selected="selected"'; |
946
|
|
|
} |
947
|
|
|
|
948
|
|
|
$szReturns .= '<select name="formArray">'; |
949
|
|
|
$szReturns .= "<option value=\"\"{$szNotArraySelected}></option>"; |
950
|
|
|
$szReturns .= "<option value=\"[]\"{$szArraySelected}>[ ]</option>"; |
951
|
|
|
$szReturns .= "</select>\n</td>"; |
952
|
|
|
|
953
|
|
|
// Create string for language |
954
|
|
|
$szLanguage = '<td class="data1">'; |
955
|
|
|
if ('c' == $fnlang || 'internal' == $fnlang) { |
956
|
|
|
$szLanguage .= $_POST['formLanguage']."\n"; |
957
|
|
|
$szLanguage .= "<input type=\"hidden\" name=\"formLanguage\" value=\"{$_POST['formLanguage']}\" />\n"; |
958
|
|
|
} else { |
959
|
|
|
$szLanguage .= "<select name=\"formLanguage\">\n"; |
960
|
|
|
while (!$langs->EOF) { |
961
|
|
|
$szSelected = ''; |
962
|
|
|
if ($langs->fields['lanname'] == $_POST['formLanguage']) { |
963
|
|
|
$szSelected = ' selected="selected"'; |
964
|
|
|
} |
965
|
|
|
if ('c' != strtolower($langs->fields['lanname']) && 'internal' != strtolower($langs->fields['lanname'])) { |
966
|
|
|
$szLanguage .= '<option value="'.htmlspecialchars($langs->fields['lanname'])."\"{$szSelected}>\n". |
967
|
|
|
$this->misc->printVal($langs->fields['lanname']).'</option>'; |
968
|
|
|
} |
969
|
|
|
|
970
|
|
|
$langs->moveNext(); |
971
|
|
|
} |
972
|
|
|
$szLanguage .= "</select>\n"; |
973
|
|
|
} |
974
|
|
|
|
975
|
|
|
$szLanguage .= '</td>'; |
976
|
|
|
$szJSArguments = "<tr><th class=\"data\" colspan=\"7\">{$this->lang['strarguments']}</th></tr>"; |
977
|
|
|
$arrayModes = ['IN', 'OUT', 'INOUT']; |
978
|
|
|
$szModes = '<select name="formArgModes[]" style="width:100%;">'; |
979
|
|
|
foreach ($arrayModes as $pV) { |
980
|
|
|
$szModes .= "<option value=\"{$pV}\">{$pV}</option>"; |
981
|
|
|
} |
982
|
|
|
$szModes .= '</select>'; |
983
|
|
|
$szArgReturns = '<select name="formArgArray[]">'; |
984
|
|
|
$szArgReturns .= '<option value=""></option>'; |
985
|
|
|
$szArgReturns .= '<option value="[]">[]</option>'; |
986
|
|
|
$szArgReturns .= '</select>'; |
987
|
|
|
$subfolder = \SUBFOLDER; |
988
|
|
|
if (!empty($this->conf['theme'])) { |
989
|
|
|
$szImgPath = \SUBFOLDER."/assets/images/themes/{$this->conf['theme']}"; |
990
|
|
|
} else { |
991
|
|
|
$szImgPath = \SUBFOLDER.'/assets/images/themes/default'; |
992
|
|
|
} |
993
|
|
|
if (empty($msg)) { |
994
|
|
|
// $this->prtrace($subfolder); |
995
|
|
|
$szJSTRArg = "<script type=\"text/javascript\" >addArg('{$subfolder}');</script>\n"; |
996
|
|
|
} else { |
997
|
|
|
$szJSTRArg = ''; |
998
|
|
|
} |
999
|
|
|
$szJSAddTR = "<tr id=\"parent_add_tr\" onclick=\"addArg('{$subfolder}');\" onmouseover=\"this.style.cursor='pointer'\">\n"; |
1000
|
|
|
$szJSAddTR .= '<td style="text-align: right" colspan="6" class="data3"><table><tr><td class="data3">'; |
1001
|
|
|
$szJSAddTR .= "<img src=\"{$szImgPath}/AddArguments.png\" alt=\"Add Argument\" /></td>"; |
1002
|
|
|
$szJSAddTR .= "<td class=\"data3\"><span style=\"font-size: 8pt\">{$this->lang['strargadd']}</span></td></tr></table></td>\n</tr>\n"; |
1003
|
|
|
|
1004
|
|
|
echo '<script src="'.\SUBFOLDER."/assets/js/functions.js\" type=\"text/javascript\"></script> |
1005
|
|
|
<script type=\"text/javascript\"> |
1006
|
|
|
//<![CDATA[ |
1007
|
|
|
var g_types_select = '<select class=\"select2\" name=\"formArgType[]\">{$szTypes}</select>{$szArgReturns}'; |
1008
|
|
|
var g_modes_select = '{$szModes}'; |
1009
|
|
|
var g_name = ''; |
1010
|
|
|
var g_lang_strargremove = '", htmlspecialchars($this->lang['strargremove'], ENT_QUOTES), "'; |
1011
|
|
|
var g_lang_strargnoargs = '", htmlspecialchars($this->lang['strargnoargs'], ENT_QUOTES), "'; |
1012
|
|
|
var g_lang_strargenableargs = '", htmlspecialchars($this->lang['strargenableargs'], ENT_QUOTES), "'; |
1013
|
|
|
var g_lang_strargnorowabove = '", htmlspecialchars($this->lang['strargnorowabove'], ENT_QUOTES), "'; |
1014
|
|
|
var g_lang_strargnorowbelow = '", htmlspecialchars($this->lang['strargnorowbelow'], ENT_QUOTES), "'; |
1015
|
|
|
var g_lang_strargremoveconfirm = '", htmlspecialchars($this->lang['strargremoveconfirm'], ENT_QUOTES), "'; |
1016
|
|
|
var g_lang_strargraise = '", htmlspecialchars($this->lang['strargraise'], ENT_QUOTES), "'; |
1017
|
|
|
var g_lang_strarglower = '", htmlspecialchars($this->lang['strarglower'], ENT_QUOTES), "'; |
1018
|
|
|
//]]> |
1019
|
|
|
</script> |
1020
|
|
|
"; |
1021
|
|
|
echo '<form action="'.\SUBFOLDER."/src/views/functions\" method=\"post\">\n"; |
1022
|
|
|
echo "<table><tbody id=\"args_table\">\n"; |
1023
|
|
|
echo "<tr><th class=\"data required\">{$this->lang['strname']}</th>\n"; |
1024
|
|
|
echo "<th class=\"data required\" colspan=\"2\">{$this->lang['strreturns']}</th>\n"; |
1025
|
|
|
echo "<th class=\"data required\">{$this->lang['strproglanguage']}</th></tr>\n"; |
1026
|
|
|
echo "<tr>\n"; |
1027
|
|
|
echo "{$szFunctionName}\n"; |
1028
|
|
|
echo "{$szReturns}\n"; |
1029
|
|
|
echo "{$szLanguage}\n"; |
1030
|
|
|
echo "</tr>\n"; |
1031
|
|
|
echo "{$szJSArguments}\n"; |
1032
|
|
|
echo "<tr>\n"; |
1033
|
|
|
echo "<th class=\"data required\">{$this->lang['strargmode']}</th>\n"; |
1034
|
|
|
echo "<th class=\"data required\">{$this->lang['strname']}</th>\n"; |
1035
|
|
|
echo "<th class=\"data required\" colspan=\"2\">{$this->lang['strargtype']}</th>\n"; |
1036
|
|
|
echo "</tr>\n"; |
1037
|
|
|
echo "{$szJSAddTR}\n"; |
1038
|
|
|
|
1039
|
|
|
if ('c' == $fnlang) { |
1040
|
|
|
echo "<tr><th class=\"data required\" colspan=\"2\">{$this->lang['strobjectfile']}</th>\n"; |
1041
|
|
|
echo "<th class=\"data\" colspan=\"2\">{$this->lang['strlinksymbol']}</th></tr>\n"; |
1042
|
|
|
echo '<tr><td class="data1" colspan="2"><input type="text" name="formObjectFile" style="width:100%" value="', |
1043
|
|
|
htmlspecialchars($_POST['formObjectFile']), "\" /></td>\n"; |
1044
|
|
|
echo '<td class="data1" colspan="2"><input type="text" name="formLinkSymbol" style="width:100%" value="', |
1045
|
|
|
htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n"; |
1046
|
|
|
} elseif ('internal' == $fnlang) { |
1047
|
|
|
echo "<tr><th class=\"data\" colspan=\"4\">{$this->lang['strlinksymbol']}</th></tr>\n"; |
1048
|
|
|
echo '<tr><td class="data1" colspan="4"><input type="text" name="formLinkSymbol" style="width:100%" value="', |
1049
|
|
|
htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n"; |
1050
|
|
|
} else { |
1051
|
|
|
echo "<tr><th class=\"data required\" colspan=\"4\">{$this->lang['strdefinition']}</th></tr>\n"; |
1052
|
|
|
echo '<tr><td class="data1" colspan="4"><textarea style="width:100%;" rows="20" cols="50" name="formDefinition">', |
1053
|
|
|
htmlspecialchars($_POST['formDefinition']), "</textarea></td></tr>\n"; |
1054
|
|
|
} |
1055
|
|
|
|
1056
|
|
|
// Display function comment |
1057
|
|
|
echo "<tr><th class=\"data\" colspan=\"4\">{$this->lang['strcomment']}</th></tr>\n"; |
1058
|
|
|
echo '<tr><td class="data1" colspan="4"><textarea style="width:100%;" name="formComment" rows="3" cols="50">', |
1059
|
|
|
htmlspecialchars($_POST['formComment']), "</textarea></td></tr>\n"; |
1060
|
|
|
|
1061
|
|
|
// Display function cost options |
1062
|
|
|
if ($data->hasFunctionCosting()) { |
1063
|
|
|
echo "<tr><th class=\"data required\" colspan=\"4\">{$this->lang['strfunctioncosting']}</th></tr>\n"; |
1064
|
|
|
echo "<td class=\"data1\" colspan=\"2\">{$this->lang['strexecutioncost']}: <input name=\"formCost\" size=\"16\" value=\"". |
1065
|
|
|
htmlspecialchars($_POST['formCost']).'" /></td>'; |
1066
|
|
|
echo "<td class=\"data1\" colspan=\"2\">{$this->lang['strresultrows']}: <input name=\"formRows\" size=\"16\" value=\"". |
1067
|
|
|
htmlspecialchars($_POST['formRows']).'" /></td>'; |
1068
|
|
|
} |
1069
|
|
|
|
1070
|
|
|
// Display function properties |
1071
|
|
|
if (is_array($data->funcprops) && sizeof($data->funcprops) > 0) { |
1072
|
|
|
echo "<tr><th class=\"data required\" colspan=\"4\">{$this->lang['strproperties']}</th></tr>\n"; |
1073
|
|
|
echo "<tr><td class=\"data1\" colspan=\"4\">\n"; |
1074
|
|
|
$i = 0; |
1075
|
|
|
foreach ($data->funcprops as $k => $v) { |
1076
|
|
|
echo "<select name=\"formProperties[{$i}]\">\n"; |
1077
|
|
|
foreach ($v as $p) { |
1078
|
|
|
echo '<option value="', htmlspecialchars($p), '"', |
1079
|
|
|
($_POST['formProperties'][$i] == $p) ? ' selected="selected"' : '', |
1080
|
|
|
'>', $this->misc->printVal($p), "</option>\n"; |
1081
|
|
|
} |
1082
|
|
|
echo "</select><br />\n"; |
1083
|
|
|
++$i; |
1084
|
|
|
} |
1085
|
|
|
echo "</td></tr>\n"; |
1086
|
|
|
} |
1087
|
|
|
echo "</tbody></table>\n"; |
1088
|
|
|
echo $szJSTRArg; |
1089
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n"; |
1090
|
|
|
echo $this->misc->form; |
1091
|
|
|
echo "<input type=\"submit\" value=\"{$this->lang['strcreate']}\" />\n"; |
1092
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
1093
|
|
|
echo "</form>\n"; |
1094
|
|
|
echo $szJS; |
1095
|
|
|
} |
1096
|
|
|
|
1097
|
|
|
/** |
1098
|
|
|
* Actually creates the new function in the database. |
1099
|
|
|
*/ |
1100
|
|
|
public function doSaveCreate() |
1101
|
|
|
{ |
1102
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
1103
|
|
|
|
1104
|
|
|
$fnlang = strtolower($_POST['formLanguage']); |
1105
|
|
|
|
1106
|
|
|
if ('c' == $fnlang) { |
1107
|
|
|
$def = [$_POST['formObjectFile'], $_POST['formLinkSymbol']]; |
1108
|
|
|
} elseif ('internal' == $fnlang) { |
1109
|
|
|
$def = $_POST['formLinkSymbol']; |
1110
|
|
|
} else { |
1111
|
|
|
$def = $_POST['formDefinition']; |
1112
|
|
|
} |
1113
|
|
|
|
1114
|
|
|
$szJS = ''; |
1115
|
|
|
|
1116
|
|
|
echo '<script src="'.\SUBFOLDER.'/assets/js/functions.js" type="text/javascript"></script>'; |
1117
|
|
|
echo '<script type="text/javascript">'.$this->buildJSData().'</script>'; |
1118
|
|
|
if (!empty($_POST['formArgName'])) { |
1119
|
|
|
$szJS = $this->_buildJSRows($this->_buildFunctionArguments($_POST)); |
1120
|
|
|
} else { |
1121
|
|
|
$subfolder = \SUBFOLDER; |
1122
|
|
|
// $this->prtrace($subfolder); |
1123
|
|
|
$szJS = '<script type="text/javascript" src="'.\SUBFOLDER.'/assets/js/functions.js">noArgsRebuild(addArg("'.$subfolder.'"));</script>'; |
1124
|
|
|
} |
1125
|
|
|
|
1126
|
|
|
$cost = (isset($_POST['formCost'])) ? $_POST['formCost'] : null; |
1127
|
|
|
if ('' == $cost || !is_numeric($cost) || $cost != (int) $cost || $cost < 0) { |
1128
|
|
|
$cost = null; |
1129
|
|
|
} |
1130
|
|
|
|
1131
|
|
|
$rows = (isset($_POST['formRows'])) ? $_POST['formRows'] : null; |
1132
|
|
|
if ('' == $rows || !is_numeric($rows) || $rows != (int) $rows) { |
1133
|
|
|
$rows = null; |
1134
|
|
|
} |
1135
|
|
|
|
1136
|
|
|
// Check that they've given a name and a definition |
1137
|
|
|
if ('' == $_POST['formFunction']) { |
1138
|
|
|
$this->doCreate($this->lang['strfunctionneedsname'], $szJS); |
1139
|
|
|
} elseif ('internal' != $fnlang && !$def) { |
1140
|
|
|
$this->doCreate($this->lang['strfunctionneedsdef'], $szJS); |
1141
|
|
|
} else { |
1142
|
|
|
// Append array symbol to type if chosen |
1143
|
|
|
$status = $data->createFunction( |
1144
|
|
|
$_POST['formFunction'], |
1145
|
|
|
empty($_POST['nojs']) ? $this->_buildFunctionArguments($_POST) : $_POST['formArguments'], |
1146
|
|
|
$_POST['formReturns'].$_POST['formArray'], |
1147
|
|
|
$def, |
1148
|
|
|
$_POST['formLanguage'], |
1149
|
|
|
$_POST['formProperties'], |
1150
|
|
|
'SETOF' == $_POST['formSetOf'], |
1151
|
|
|
$cost, |
1152
|
|
|
$rows, |
1153
|
|
|
$_POST['formComment'], |
1154
|
|
|
false |
1155
|
|
|
); |
1156
|
|
|
if (0 == $status) { |
1157
|
|
|
$this->doDefault($this->lang['strfunctioncreated']); |
1158
|
|
|
} else { |
1159
|
|
|
$this->doCreate($this->lang['strfunctioncreatedbad'], $szJS); |
1160
|
|
|
} |
1161
|
|
|
} |
1162
|
|
|
} |
1163
|
|
|
|
1164
|
|
|
/** |
1165
|
|
|
* Build out the function arguments string. |
1166
|
|
|
* |
1167
|
|
|
* @param array $arrayVars |
1168
|
|
|
* |
1169
|
|
|
* @return string the imploded array vars |
1170
|
|
|
*/ |
1171
|
|
|
private function _buildFunctionArguments($arrayVars) |
1172
|
|
|
{ |
1173
|
|
|
if (isset($_POST['formArgName'])) { |
1174
|
|
|
$arrayArgs = []; |
1175
|
|
|
foreach ($arrayVars['formArgName'] as $pK => $pV) { |
1176
|
|
|
$arrayArgs[] = $arrayVars['formArgModes'][$pK].' '.trim($pV).' '.trim($arrayVars['formArgType'][$pK]).$arrayVars['formArgArray'][$pK]; |
1177
|
|
|
} |
1178
|
|
|
|
1179
|
|
|
return implode(',', $arrayArgs); |
1180
|
|
|
} |
1181
|
|
|
|
1182
|
|
|
return ''; |
1183
|
|
|
} |
1184
|
|
|
|
1185
|
|
|
/** |
1186
|
|
|
* Build out JS to re-create table rows for arguments. |
1187
|
|
|
* |
1188
|
|
|
* @param string $szArgs args to parse |
1189
|
|
|
*/ |
1190
|
|
|
private function _buildJSRows($szArgs) |
1191
|
|
|
{ |
1192
|
|
|
$arrayModes = ['IN', 'OUT', 'INOUT']; |
1193
|
|
|
$arrayArgs = explode(',', $szArgs); |
1194
|
|
|
$arrayProperArgs = []; |
1195
|
|
|
$nC = 0; |
1196
|
|
|
$szReturn = ''; |
1197
|
|
|
$szMode = []; |
1198
|
|
|
foreach ($arrayArgs as $pV) { |
1199
|
|
|
$arrayWords = explode(' ', $pV); |
1200
|
|
|
if (true === in_array($arrayWords[0], $arrayModes, true)) { |
1201
|
|
|
$szMode = $arrayWords[0]; |
1202
|
|
|
array_shift($arrayWords); |
1203
|
|
|
} |
1204
|
|
|
$szArgName = array_shift($arrayWords); |
1205
|
|
|
if (false === strpos($arrayWords[count($arrayWords) - 1], '[]')) { |
1206
|
|
|
$szArgType = implode(' ', $arrayWords); |
1207
|
|
|
$bArgIsArray = 'false'; |
1208
|
|
|
} else { |
1209
|
|
|
$szArgType = str_replace('[]', '', implode(' ', $arrayWords)); |
1210
|
|
|
$bArgIsArray = 'true'; |
1211
|
|
|
} |
1212
|
|
|
$arrayProperArgs[] = [$szMode, $szArgName, $szArgType, $bArgIsArray]; |
1213
|
|
|
$subfolder = \SUBFOLDER; |
1214
|
|
|
// $this->prtrace($subfolder); |
1215
|
|
|
$szReturn .= '<script type="text/javascript">'; |
1216
|
|
|
$szReturn .= "RebuildArgTR('{$szMode}','{$szArgName}','{$szArgType}',new Boolean({$bArgIsArray},{$subfolder}));"; |
1217
|
|
|
$szReturn .= '</script>;'; |
1218
|
|
|
++$nC; |
1219
|
|
|
} |
1220
|
|
|
|
1221
|
|
|
return $szReturn; |
1222
|
|
|
} |
1223
|
|
|
|
1224
|
|
|
private function buildJSData() |
|
|
|
|
1225
|
|
|
{ |
1226
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
1227
|
|
|
|
1228
|
|
|
$arrayModes = ['IN', 'OUT', 'INOUT']; |
1229
|
|
|
$arrayTypes = $data->getTypes(true, true, true); |
1230
|
|
|
$arrayPTypes = []; |
1231
|
|
|
$arrayPModes = []; |
1232
|
|
|
|
1233
|
|
|
while (!$arrayTypes->EOF) { |
1234
|
|
|
$arrayPTypes[] = "'".$arrayTypes->fields['typname']."'"; |
1235
|
|
|
$arrayTypes->moveNext(); |
1236
|
|
|
} |
1237
|
|
|
|
1238
|
|
|
foreach ($arrayModes as $pV) { |
1239
|
|
|
$arrayPModes[] = "'{$pV}'"; |
1240
|
|
|
} |
1241
|
|
|
|
1242
|
|
|
$szTypes = 'g_main_types = new Array('.implode(',', $arrayPTypes).');'; |
1243
|
|
|
$szModes = 'g_main_modes = new Array('.implode(',', $arrayPModes).');'; |
1244
|
|
|
|
1245
|
|
|
return $szTypes.$szModes; |
1246
|
|
|
} |
1247
|
|
|
} |
1248
|
|
|
|