Total Complexity | 151 |
Total Lines | 1210 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like FunctionsController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FunctionsController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
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() |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Show default list of functions in the database. |
||
92 | * |
||
93 | * @param mixed $msg |
||
94 | */ |
||
95 | public function doDefault($msg = '') |
||
96 | { |
||
97 | $data = $this->misc->getDatabaseAccessor(); |
||
98 | |||
99 | $this->printTrail('schema'); |
||
100 | $this->printTabs('schema', 'functions'); |
||
101 | $this->printMsg($msg); |
||
102 | |||
103 | $funcs = $data->getFunctions(); |
||
104 | |||
105 | $columns = [ |
||
106 | 'function' => [ |
||
107 | 'title' => $this->lang['strfunction'], |
||
108 | 'field' => Decorator::field('proproto'), |
||
109 | 'url' => \SUBFOLDER . "/redirect/function?action=properties&{$this->misc->href}&", |
||
110 | 'vars' => ['function' => 'proproto', 'function_oid' => 'prooid'], |
||
111 | ], |
||
112 | 'returns' => [ |
||
113 | 'title' => $this->lang['strreturns'], |
||
114 | 'field' => Decorator::field('proreturns'), |
||
115 | ], |
||
116 | 'owner' => [ |
||
117 | 'title' => $this->lang['strowner'], |
||
118 | 'field' => Decorator::field('proowner'), |
||
119 | ], |
||
120 | 'proglanguage' => [ |
||
121 | 'title' => $this->lang['strproglanguage'], |
||
122 | 'field' => Decorator::field('prolanguage'), |
||
123 | ], |
||
124 | 'actions' => [ |
||
125 | 'title' => $this->lang['stractions'], |
||
126 | ], |
||
127 | 'comment' => [ |
||
128 | 'title' => $this->lang['strcomment'], |
||
129 | 'field' => Decorator::field('procomment'), |
||
130 | ], |
||
131 | ]; |
||
132 | |||
133 | $actions = [ |
||
134 | 'multiactions' => [ |
||
135 | 'keycols' => ['function' => 'proproto', 'function_oid' => 'prooid'], |
||
136 | 'url' => 'functions', |
||
137 | ], |
||
138 | 'alter' => [ |
||
139 | 'content' => $this->lang['stralter'], |
||
140 | 'attr' => [ |
||
141 | 'href' => [ |
||
142 | 'url' => 'functions', |
||
143 | 'urlvars' => [ |
||
144 | 'action' => 'edit', |
||
145 | 'function' => Decorator::field('proproto'), |
||
146 | 'function_oid' => Decorator::field('prooid'), |
||
147 | ], |
||
148 | ], |
||
149 | ], |
||
150 | ], |
||
151 | 'drop' => [ |
||
152 | 'multiaction' => 'confirm_drop', |
||
153 | 'content' => $this->lang['strdrop'], |
||
154 | 'attr' => [ |
||
155 | 'href' => [ |
||
156 | 'url' => 'functions', |
||
157 | 'urlvars' => [ |
||
158 | 'action' => 'confirm_drop', |
||
159 | 'function' => Decorator::field('proproto'), |
||
160 | 'function_oid' => Decorator::field('prooid'), |
||
161 | ], |
||
162 | ], |
||
163 | ], |
||
164 | ], |
||
165 | 'privileges' => [ |
||
166 | 'content' => $this->lang['strprivileges'], |
||
167 | 'attr' => [ |
||
168 | 'href' => [ |
||
169 | 'url' => 'privileges', |
||
170 | 'urlvars' => [ |
||
171 | 'subject' => 'function', |
||
172 | 'function' => Decorator::field('proproto'), |
||
173 | 'function_oid' => Decorator::field('prooid'), |
||
174 | ], |
||
175 | ], |
||
176 | ], |
||
177 | ], |
||
178 | ]; |
||
179 | |||
180 | echo $this->printTable($funcs, $columns, $actions, $this->table_place, $this->lang['strnofunctions']); |
||
181 | |||
182 | $this->_printNavLinks('functions-functions'); |
||
183 | } |
||
184 | |||
185 | private function _printNavLinks($place, $func_full = '') |
||
186 | { |
||
187 | |||
188 | if ($place === 'functions-properties') { |
||
189 | $navlinks = [ |
||
190 | 'showall' => [ |
||
191 | 'attr' => [ |
||
192 | 'href' => [ |
||
193 | 'url' => 'functions', |
||
194 | 'urlvars' => [ |
||
195 | 'server' => $_REQUEST['server'], |
||
196 | 'database' => $_REQUEST['database'], |
||
197 | 'schema' => $_REQUEST['schema'], |
||
198 | ], |
||
199 | ], |
||
200 | ], |
||
201 | 'content' => $this->lang['strshowallfunctions'], |
||
202 | ], |
||
203 | 'alter' => [ |
||
204 | 'attr' => [ |
||
205 | 'href' => [ |
||
206 | 'url' => 'functions', |
||
207 | 'urlvars' => [ |
||
208 | 'action' => 'edit', |
||
209 | 'server' => $_REQUEST['server'], |
||
210 | 'database' => $_REQUEST['database'], |
||
211 | 'schema' => $_REQUEST['schema'], |
||
212 | 'function' => $_REQUEST['function'], |
||
213 | 'function_oid' => $_REQUEST['function_oid'], |
||
214 | ], |
||
215 | ], |
||
216 | ], |
||
217 | 'content' => $this->lang['stralter'], |
||
218 | ], |
||
219 | 'drop' => [ |
||
220 | 'attr' => [ |
||
221 | 'href' => [ |
||
222 | 'url' => 'functions', |
||
223 | 'urlvars' => [ |
||
224 | 'action' => 'confirm_drop', |
||
225 | 'server' => $_REQUEST['server'], |
||
226 | 'database' => $_REQUEST['database'], |
||
227 | 'schema' => $_REQUEST['schema'], |
||
228 | 'function' => $func_full, |
||
229 | 'function_oid' => $_REQUEST['function_oid'], |
||
230 | ], |
||
231 | ], |
||
232 | ], |
||
233 | 'content' => $this->lang['strdrop'], |
||
234 | ], |
||
235 | ]; |
||
236 | } else if ($place === 'functions-functions') { |
||
237 | $navlinks = [ |
||
238 | 'createpl' => [ |
||
239 | 'attr' => [ |
||
240 | 'href' => [ |
||
241 | 'url' => 'functions', |
||
242 | 'urlvars' => [ |
||
243 | 'action' => 'create', |
||
244 | 'server' => $_REQUEST['server'], |
||
245 | 'database' => $_REQUEST['database'], |
||
246 | 'schema' => $_REQUEST['schema'], |
||
247 | ], |
||
248 | ], |
||
249 | ], |
||
250 | 'content' => $this->lang['strcreateplfunction'], |
||
251 | ], |
||
252 | 'createinternal' => [ |
||
253 | 'attr' => [ |
||
254 | 'href' => [ |
||
255 | 'url' => 'functions', |
||
256 | 'urlvars' => [ |
||
257 | 'action' => 'create', |
||
258 | 'language' => 'internal', |
||
259 | 'server' => $_REQUEST['server'], |
||
260 | 'database' => $_REQUEST['database'], |
||
261 | 'schema' => $_REQUEST['schema'], |
||
262 | ], |
||
263 | ], |
||
264 | ], |
||
265 | 'content' => $this->lang['strcreateinternalfunction'], |
||
266 | ], |
||
267 | 'createc' => [ |
||
268 | 'attr' => [ |
||
269 | 'href' => [ |
||
270 | 'url' => 'functions', |
||
271 | 'urlvars' => [ |
||
272 | 'action' => 'create', |
||
273 | 'language' => 'C', |
||
274 | 'server' => $_REQUEST['server'], |
||
275 | 'database' => $_REQUEST['database'], |
||
276 | 'schema' => $_REQUEST['schema'], |
||
277 | ], |
||
278 | ], |
||
279 | ], |
||
280 | 'content' => $this->lang['strcreatecfunction'], |
||
281 | ], |
||
282 | ]; |
||
283 | } |
||
284 | |||
285 | $this->printNavLinks($navlinks, $place, get_defined_vars()); |
||
|
|||
286 | } |
||
287 | |||
288 | /** |
||
289 | * Generate XML for the browser tree. |
||
290 | */ |
||
291 | public function doTree() |
||
292 | { |
||
293 | $data = $this->misc->getDatabaseAccessor(); |
||
294 | |||
295 | $funcs = $data->getFunctions(); |
||
296 | |||
297 | $proto = Decorator::concat(Decorator::field('proname'), ' (', Decorator::field('proarguments'), ')'); |
||
298 | |||
299 | $reqvars = $this->misc->getRequestVars('function'); |
||
300 | |||
301 | $attrs = [ |
||
302 | 'text' => $proto, |
||
303 | 'icon' => 'Function', |
||
304 | 'toolTip' => Decorator::field('procomment'), |
||
305 | 'action' => Decorator::redirecturl( |
||
306 | 'redirect', |
||
307 | $reqvars, |
||
308 | [ |
||
309 | 'action' => 'properties', |
||
310 | 'function' => $proto, |
||
311 | 'function_oid' => Decorator::field('prooid'), |
||
312 | ] |
||
313 | ), |
||
314 | ]; |
||
315 | |||
316 | return $this->printTree($funcs, $attrs, 'functions'); |
||
317 | } |
||
318 | |||
319 | /** |
||
320 | * Function to save after editing a function. |
||
321 | */ |
||
322 | public function doSaveEdit() |
||
323 | { |
||
324 | $data = $this->misc->getDatabaseAccessor(); |
||
325 | |||
326 | $fnlang = strtolower($_POST['original_lang']); |
||
327 | |||
328 | if ('c' == $fnlang) { |
||
329 | $def = [$_POST['formObjectFile'], $_POST['formLinkSymbol']]; |
||
330 | } elseif ('internal' == $fnlang) { |
||
331 | $def = $_POST['formLinkSymbol']; |
||
332 | } else { |
||
333 | $def = $_POST['formDefinition']; |
||
334 | } |
||
335 | if (!$data->hasFunctionAlterSchema()) { |
||
336 | $_POST['formFuncSchema'] = ''; |
||
337 | } |
||
338 | |||
339 | $status = $data->setFunction( |
||
340 | $_POST['original_function'], |
||
341 | $_POST['formFunction'], |
||
342 | $_POST['original_arguments'], |
||
343 | $_POST['original_returns'], |
||
344 | $def, |
||
345 | $_POST['original_lang'], |
||
346 | $_POST['formProperties'], |
||
347 | isset($_POST['original_setof']), |
||
348 | $_POST['original_owner'], |
||
349 | $_POST['formFuncOwn'], |
||
350 | $_POST['original_schema'], |
||
351 | $_POST['formFuncSchema'], |
||
352 | isset($_POST['formCost']) ? $_POST['formCost'] : null, |
||
353 | isset($_POST['formRows']) ? $_POST['formRows'] : 0, |
||
354 | $_POST['formComment'] |
||
355 | ); |
||
356 | |||
357 | if (0 == $status) { |
||
358 | // If function has had schema altered, need to change to the new schema |
||
359 | // and reload the browser frame. |
||
360 | if (!empty($_POST['formFuncSchema']) && ($_POST['formFuncSchema'] != $_POST['original_schema'])) { |
||
361 | // Jump them to the new function schema |
||
362 | $this->misc->setCurrentSchema($_POST['formFuncSchema']); |
||
363 | // Force a browser reload |
||
364 | $this->misc->setReloadBrowser(true); |
||
365 | } |
||
366 | $this->doProperties($this->lang['strfunctionupdated']); |
||
367 | } else { |
||
368 | $this->doEdit($this->lang['strfunctionupdatedbad']); |
||
369 | } |
||
370 | } |
||
371 | |||
372 | /** |
||
373 | * Function to allow editing of a Function. |
||
374 | * |
||
375 | * @param mixed $msg |
||
376 | */ |
||
377 | public function doEdit($msg = '') |
||
378 | { |
||
379 | $data = $this->misc->getDatabaseAccessor(); |
||
380 | |||
381 | $this->printTrail('function'); |
||
382 | $this->printTitle($this->lang['stralter'], 'pg.function.alter'); |
||
383 | $this->printMsg($msg); |
||
384 | |||
385 | $fndata = $data->getFunction($_REQUEST['function_oid']); |
||
386 | |||
387 | if ($fndata->recordCount() > 0) { |
||
388 | $fndata->fields['proretset'] = $data->phpBool($fndata->fields['proretset']); |
||
389 | |||
390 | // Initialise variables |
||
391 | $_POST['formDefinition'] = $this->getPostParam('formDefinition', $fndata->fields['prosrc']); |
||
392 | |||
393 | $_POST['formProperties'] = $this->getPostParam('formProperties', $data->getFunctionProperties($fndata->fields)); |
||
394 | |||
395 | $_POST['formFunction'] = $this->getPostParam('formFunction', $fndata->fields['proname']); |
||
396 | |||
397 | $_POST['formComment'] = $this->getPostParam('formComment', $fndata->fields['procomment']); |
||
398 | |||
399 | $_POST['formObjectFile'] = $this->getPostParam('formObjectFile', $fndata->fields['probin']); |
||
400 | |||
401 | $_POST['formLinkSymbol'] = $this->getPostParam('formLinkSymbol', $fndata->fields['prosrc']); |
||
402 | |||
403 | $_POST['formFuncOwn'] = $this->getPostParam('formFuncOwn', $fndata->fields['proowner']); |
||
404 | |||
405 | $_POST['formFuncSchema'] = $this->getPostParam('formFuncSchema', $fndata->fields['proschema']); |
||
406 | |||
407 | if ($data->hasFunctionCosting()) { |
||
408 | $_POST['formCost'] = $this->getPostParam('formCost', $fndata->fields['procost']); |
||
409 | |||
410 | $_POST['formRows'] = $this->getPostParam('formRows', $fndata->fields['prorows']); |
||
411 | } |
||
412 | |||
413 | // Deal with named parameters |
||
414 | if ($data->hasNamedParams()) { |
||
415 | if (isset($fndata->fields['proallarguments'])) { |
||
416 | $args_arr = $data->phpArray($fndata->fields['proallarguments']); |
||
417 | } else { |
||
418 | $args_arr = explode(', ', $fndata->fields['proarguments']); |
||
419 | } |
||
420 | $names_arr = $data->phpArray($fndata->fields['proargnames']); |
||
421 | $modes_arr = $data->phpArray($fndata->fields['proargmodes']); |
||
422 | $args = ''; |
||
423 | $args_arr_size = sizeof($args_arr); |
||
424 | for ($i = 0; $i < $args_arr_size; ++$i) { |
||
425 | if (0 != $i) { |
||
426 | $args .= ', '; |
||
427 | } |
||
428 | |||
429 | if (isset($modes_arr[$i])) { |
||
430 | switch ($modes_arr[$i]) { |
||
431 | case 'i': |
||
432 | $args .= ' IN '; |
||
433 | |||
434 | break; |
||
435 | case 'o': |
||
436 | $args .= ' OUT '; |
||
437 | |||
438 | break; |
||
439 | case 'b': |
||
440 | $args .= ' INOUT '; |
||
441 | |||
442 | break; |
||
443 | case 'v': |
||
444 | $args .= ' VARIADIC '; |
||
445 | |||
446 | break; |
||
447 | case 't': |
||
448 | $args .= ' TABLE '; |
||
449 | |||
450 | break; |
||
451 | } |
||
452 | } |
||
453 | if (isset($names_arr[$i]) && '' != $names_arr[$i]) { |
||
454 | $data->fieldClean($names_arr[$i]); |
||
455 | $args .= '"' . $names_arr[$i] . '" '; |
||
456 | } |
||
457 | $args .= $args_arr[$i]; |
||
458 | } |
||
459 | } else { |
||
460 | $args = $fndata->fields['proarguments']; |
||
461 | } |
||
462 | |||
463 | echo '<form action="' . \SUBFOLDER . "/src/views/functions\" method=\"post\">\n"; |
||
464 | echo "<table style=\"width: 90%\">\n"; |
||
465 | echo "<tr>\n"; |
||
466 | echo "<th class=\"data required\">{$this->lang['strschema']}</th>\n"; |
||
467 | echo "<th class=\"data required\">{$this->lang['strfunction']}</th>\n"; |
||
468 | echo "<th class=\"data\">{$this->lang['strarguments']}</th>\n"; |
||
469 | echo "<th class=\"data required\">{$this->lang['strreturns']}</th>\n"; |
||
470 | echo "<th class=\"data required\">{$this->lang['strproglanguage']}</th>\n"; |
||
471 | echo "</tr>\n"; |
||
472 | |||
473 | echo "<tr>\n"; |
||
474 | echo '<td class="data1">'; |
||
475 | echo '<input type="hidden" name="original_schema" value="', htmlspecialchars($fndata->fields['proschema']), "\" />\n"; |
||
476 | if ($data->hasFunctionAlterSchema()) { |
||
477 | $schemas = $data->getSchemas(); |
||
478 | echo '<select name="formFuncSchema">'; |
||
479 | while (!$schemas->EOF) { |
||
480 | $schema = $schemas->fields['nspname']; |
||
481 | echo '<option value="', htmlspecialchars($schema), '"', |
||
482 | ($schema == $_POST['formFuncSchema']) ? ' selected="selected"' : '', '>', htmlspecialchars($schema), "</option>\n"; |
||
483 | $schemas->moveNext(); |
||
484 | } |
||
485 | echo "</select>\n"; |
||
486 | } else { |
||
487 | echo $fndata->fields['proschema']; |
||
488 | } |
||
489 | |||
490 | echo "</td>\n"; |
||
491 | echo '<td class="data1">'; |
||
492 | echo '<input type="hidden" name="original_function" value="', htmlspecialchars($fndata->fields['proname']), "\" />\n"; |
||
493 | echo "<input name=\"formFunction\" style=\"width: 100%\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_POST['formFunction']), '" />'; |
||
494 | echo "</td>\n"; |
||
495 | |||
496 | echo '<td class="data1">', $this->misc->printVal($args), "\n"; |
||
497 | echo '<input type="hidden" name="original_arguments" value="', htmlspecialchars($args), "\" />\n"; |
||
498 | echo "</td>\n"; |
||
499 | |||
500 | echo '<td class="data1">'; |
||
501 | if ($fndata->fields['proretset']) { |
||
502 | echo 'setof '; |
||
503 | } |
||
504 | |||
505 | echo $this->misc->printVal($fndata->fields['proresult']), "\n"; |
||
506 | echo '<input type="hidden" name="original_returns" value="', htmlspecialchars($fndata->fields['proresult']), "\" />\n"; |
||
507 | if ($fndata->fields['proretset']) { |
||
508 | echo "<input type=\"hidden\" name=\"original_setof\" value=\"yes\" />\n"; |
||
509 | } |
||
510 | |||
511 | echo "</td>\n"; |
||
512 | |||
513 | echo '<td class="data1">', $this->misc->printVal($fndata->fields['prolanguage']), "\n"; |
||
514 | echo '<input type="hidden" name="original_lang" value="', htmlspecialchars($fndata->fields['prolanguage']), "\" />\n"; |
||
515 | echo "</td>\n"; |
||
516 | echo "</tr>\n"; |
||
517 | |||
518 | $fnlang = strtolower($fndata->fields['prolanguage']); |
||
519 | if ('c' == $fnlang) { |
||
520 | echo "<tr><th class=\"data required\" colspan=\"2\">{$this->lang['strobjectfile']}</th>\n"; |
||
521 | echo "<th class=\"data\" colspan=\"2\">{$this->lang['strlinksymbol']}</th></tr>\n"; |
||
522 | echo '<tr><td class="data1" colspan="2"><input type="text" name="formObjectFile" style="width:100%" value="', |
||
523 | htmlspecialchars($_POST['formObjectFile']), "\" /></td>\n"; |
||
524 | echo '<td class="data1" colspan="2"><input type="text" name="formLinkSymbol" style="width:100%" value="', |
||
525 | htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n"; |
||
526 | } elseif ('internal' == $fnlang) { |
||
527 | echo "<tr><th class=\"data\" colspan=\"5\">{$this->lang['strlinksymbol']}</th></tr>\n"; |
||
528 | echo '<tr><td class="data1" colspan="5"><input type="text" name="formLinkSymbol" style="width:100%" value="', |
||
529 | htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n"; |
||
530 | } else { |
||
531 | echo "<tr><th class=\"data required\" colspan=\"5\">{$this->lang['strdefinition']}</th></tr>\n"; |
||
532 | echo '<tr><td class="data1" colspan="5">'; |
||
533 | $textarea_id = ($fnlang === 'sql' || $fnlang === 'plpgsql') ? 'query' : 'formDefinition'; |
||
534 | echo '<textarea style="width:100%;" rows="20" cols="50" id="' . $textarea_id . '" name="formDefinition">'; |
||
535 | echo htmlspecialchars($_POST['formDefinition']); |
||
536 | echo "</textarea></td></tr>\n"; |
||
537 | } |
||
538 | |||
539 | // Display function comment |
||
540 | echo "<tr><th class=\"data\" colspan=\"5\">{$this->lang['strcomment']}</th></tr>\n"; |
||
541 | echo '<tr><td class="data1" colspan="5">'; |
||
542 | echo '<textarea style="width:100%;" name="formComment" rows="3" cols="50">'; |
||
543 | echo htmlspecialchars($_POST['formComment']); |
||
544 | echo "</textarea></td></tr>\n"; |
||
545 | |||
546 | // Display function cost options |
||
547 | if ($data->hasFunctionCosting()) { |
||
548 | echo "<tr><th class=\"data required\" colspan=\"5\">{$this->lang['strfunctioncosting']}</th></tr>\n"; |
||
549 | echo "<td class=\"data1\" colspan=\"2\">{$this->lang['strexecutioncost']}: <input name=\"formCost\" size=\"16\" value=\"" . |
||
550 | htmlspecialchars($_POST['formCost']) . '" /></td>'; |
||
551 | echo "<td class=\"data1\" colspan=\"2\">{$this->lang['strresultrows']}: <input name=\"formRows\" size=\"16\" value=\"", |
||
552 | htmlspecialchars($_POST['formRows']), '"', (!$fndata->fields['proretset']) ? 'disabled' : '', '/></td>'; |
||
553 | } |
||
554 | |||
555 | // Display function properties |
||
556 | if (is_array($data->funcprops) && sizeof($data->funcprops) > 0) { |
||
557 | echo "<tr><th class=\"data\" colspan=\"5\">{$this->lang['strproperties']}</th></tr>\n"; |
||
558 | echo "<tr><td class=\"data1\" colspan=\"5\">\n"; |
||
559 | $i = 0; |
||
560 | foreach ($data->funcprops as $k => $v) { |
||
561 | echo "<select name=\"formProperties[{$i}]\">\n"; |
||
562 | foreach ($v as $p) { |
||
563 | echo '<option value="', htmlspecialchars($p), '"', |
||
564 | ($_POST['formProperties'][$i] == $p) ? ' selected="selected"' : '', |
||
565 | '>', $this->misc->printVal($p), "</option>\n"; |
||
566 | } |
||
567 | echo "</select><br />\n"; |
||
568 | ++$i; |
||
569 | } |
||
570 | echo "</td></tr>\n"; |
||
571 | } |
||
572 | |||
573 | // function owner |
||
574 | if ($data->hasFunctionAlterOwner()) { |
||
575 | $users = $data->getUsers(); |
||
576 | echo "<tr><td class=\"data1\" colspan=\"5\">{$this->lang['strowner']}: <select name=\"formFuncOwn\">"; |
||
577 | while (!$users->EOF) { |
||
578 | $uname = $users->fields['usename']; |
||
579 | echo '<option value="', htmlspecialchars($uname), '"', |
||
580 | ($uname == $_POST['formFuncOwn']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n"; |
||
581 | $users->moveNext(); |
||
582 | } |
||
583 | echo "</select>\n"; |
||
584 | echo '<input type="hidden" name="original_owner" value="', htmlspecialchars($fndata->fields['proowner']), "\" />\n"; |
||
585 | echo "</td></tr>\n"; |
||
586 | } |
||
587 | echo "</table>\n"; |
||
588 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n"; |
||
589 | echo '<input type="hidden" name="function" value="', htmlspecialchars($_REQUEST['function']), "\" />\n"; |
||
590 | echo '<input type="hidden" name="function_oid" value="', htmlspecialchars($_REQUEST['function_oid']), "\" />\n"; |
||
591 | echo $this->misc->form; |
||
592 | echo "<input type=\"submit\" value=\"{$this->lang['stralter']}\" />\n"; |
||
593 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
594 | echo "</form>\n"; |
||
595 | } else { |
||
596 | echo "<p>{$this->lang['strnodata']}</p>\n"; |
||
597 | } |
||
598 | } |
||
599 | |||
600 | /** |
||
601 | * Show read only properties of a function. |
||
602 | * |
||
603 | * @param mixed $msg |
||
604 | */ |
||
605 | public function doProperties($msg = '') |
||
606 | { |
||
607 | $data = $this->misc->getDatabaseAccessor(); |
||
608 | |||
609 | $this->printTrail('function'); |
||
610 | $this->printTitle($this->lang['strproperties'], 'pg.function'); |
||
611 | $this->printMsg($msg); |
||
612 | |||
613 | $funcdata = $data->getFunction($_REQUEST['function_oid']); |
||
614 | $func_full = ''; |
||
615 | if ($funcdata->recordCount() > 0) { |
||
616 | // Deal with named parameters |
||
617 | $args = $this->_getPropertiesArgs($funcdata); |
||
618 | |||
619 | // Show comment if any |
||
620 | if (null !== $funcdata->fields['procomment']) { |
||
621 | echo '<p class="comment">', $this->misc->printVal($funcdata->fields['procomment']), "</p>\n"; |
||
622 | } |
||
623 | |||
624 | $funcdata->fields['proretset'] = $data->phpBool($funcdata->fields['proretset']); |
||
625 | $func_full = $funcdata->fields['proname'] . '(' . $funcdata->fields['proarguments'] . ')'; |
||
626 | echo "<table style=\"width: 90%\">\n"; |
||
627 | echo sprintf('<tr><th class="data">%s</th>%s', $this->lang['strfunction'], "\n"); |
||
628 | echo sprintf('<th class="data">%s</th>%s', $this->lang['strarguments'], "\n"); |
||
629 | echo sprintf('<th class="data">%s</th>%s', $this->lang['strreturns'], "\n"); |
||
630 | echo sprintf('<th class="data">%s</th></tr>%s', $this->lang['strproglanguage'], "\n"); |
||
631 | echo '<tr><td class="data1">', $this->misc->printVal($funcdata->fields['proname']), "</td>\n"; |
||
632 | echo '<td class="data1">', $this->misc->printVal($args), "</td>\n"; |
||
633 | echo '<td class="data1">'; |
||
634 | if ($funcdata->fields['proretset']) { |
||
635 | echo 'setof '; |
||
636 | } |
||
637 | |||
638 | echo $this->misc->printVal($funcdata->fields['proresult']), "</td>\n"; |
||
639 | echo '<td class="data1">', $this->misc->printVal($funcdata->fields['prolanguage']), "</td></tr>\n"; |
||
640 | |||
641 | $fnlang = strtolower($funcdata->fields['prolanguage']); |
||
642 | if ('c' == $fnlang) { |
||
643 | echo "<tr><th class=\"data\" colspan=\"2\">{$this->lang['strobjectfile']}</th>\n"; |
||
644 | echo "<th class=\"data\" colspan=\"2\">{$this->lang['strlinksymbol']}</th></tr>\n"; |
||
645 | echo '<tr><td class="data1" colspan="2">', $this->misc->printVal($funcdata->fields['probin']), "</td>\n"; |
||
646 | echo '<td class="data1" colspan="2">', $this->misc->printVal($funcdata->fields['prosrc']), "</td></tr>\n"; |
||
647 | } elseif ('internal' == $fnlang) { |
||
648 | echo "<tr><th class=\"data\" colspan=\"4\">{$this->lang['strlinksymbol']}</th></tr>\n"; |
||
649 | echo '<tr><td class="data1" colspan="4">', $this->misc->printVal($funcdata->fields['prosrc']), "</td></tr>\n"; |
||
650 | } else { |
||
651 | echo '<tr><td class="data1" colspan="4">'; |
||
652 | echo sprintf('<pre><code class="%s hljs">%s</code></pre>', $fnlang, $funcdata->fields['prosrc']); |
||
653 | echo "</td></tr>\n"; |
||
654 | } |
||
655 | |||
656 | // Display function cost options |
||
657 | if ($data->hasFunctionCosting()) { |
||
658 | echo "<tr><th class=\"data required\" colspan=\"4\">{$this->lang['strfunctioncosting']}</th></tr>\n"; |
||
659 | echo "<td class=\"data1\" colspan=\"2\">{$this->lang['strexecutioncost']}: ", $this->misc->printVal($funcdata->fields['procost']), ' </td>'; |
||
660 | echo "<td class=\"data1\" colspan=\"2\">{$this->lang['strresultrows']}: ", $this->misc->printVal($funcdata->fields['prorows']), ' </td>'; |
||
661 | } |
||
662 | |||
663 | // Show flags |
||
664 | if (is_array($data->funcprops) && sizeof($data->funcprops) > 0) { |
||
665 | // Fetch an array of the function properties |
||
666 | $funcprops = $data->getFunctionProperties($funcdata->fields); |
||
667 | echo "<tr><th class=\"data\" colspan=\"4\">{$this->lang['strproperties']}</th></tr>\n"; |
||
668 | echo "<tr><td class=\"data1\" colspan=\"4\">\n"; |
||
669 | foreach ($funcprops as $v) { |
||
670 | echo $this->misc->printVal($v), "<br />\n"; |
||
671 | } |
||
672 | echo "</td></tr>\n"; |
||
673 | } |
||
674 | |||
675 | echo "<tr><td class=\"data1\" colspan=\"5\">{$this->lang['strowner']}: ", htmlspecialchars($funcdata->fields['proowner']), "\n"; |
||
676 | echo "</td></tr>\n"; |
||
677 | echo "</table>\n"; |
||
678 | } else { |
||
679 | echo "<p>{$this->lang['strnodata']}</p>\n"; |
||
680 | } |
||
681 | |||
682 | $this->_printNavLinks('functions-properties', $func_full); |
||
683 | } |
||
684 | |||
685 | /** |
||
686 | * Show confirmation of drop and perform actual drop. |
||
687 | * |
||
688 | * @param mixed $confirm |
||
689 | */ |
||
690 | public function doDrop($confirm) |
||
756 | } |
||
757 | } |
||
758 | } |
||
759 | } |
||
760 | |||
761 | /** |
||
762 | * Displays a screen where they can enter a new function. |
||
763 | * |
||
764 | * @param string $msg message to display |
||
765 | * @param mixed $szJS |
||
766 | */ |
||
767 | public function doCreate($msg = '', $szJS = '') |
||
768 | { |
||
769 | $data = $this->misc->getDatabaseAccessor(); |
||
770 | |||
771 | $this->printTrail('schema'); |
||
772 | $_POST['formFunction'] = $this->getPostParam('formFunction', ''); |
||
773 | |||
774 | $_POST['formArguments'] = $this->getPostParam('formArguments', ''); |
||
775 | |||
776 | $_POST['formReturns'] = $this->getPostParam('formReturns', ''); |
||
777 | |||
778 | if (!isset($_POST['formLanguage'])) { |
||
779 | $_POST['formLanguage'] = isset($_REQUEST['language']) ? $_REQUEST['language'] : 'sql'; |
||
780 | } |
||
781 | |||
782 | $_POST['formDefinition'] = $this->getPostParam('formDefinition', ''); |
||
783 | |||
784 | $_POST['formObjectFile'] = $this->getPostParam('formObjectFile', ''); |
||
785 | |||
786 | $_POST['formLinkSymbol'] = $this->getPostParam('formLinkSymbol', ''); |
||
787 | |||
788 | $_POST['formProperties'] = $this->getPostParam('formProperties', $data->defaultprops); |
||
789 | |||
790 | $_POST['formSetOf'] = $this->getPostParam('formSetOf', ''); |
||
791 | |||
792 | $_POST['formArray'] = $this->getPostParam('formArray', ''); |
||
793 | |||
794 | $_POST['formCost'] = $this->getPostParam('formCost', ''); |
||
795 | |||
796 | $_POST['formRows'] = $this->getPostParam('formRows', ''); |
||
797 | |||
798 | $_POST['formComment'] = $this->getPostParam('formComment', ''); |
||
799 | |||
800 | $types = $data->getTypes(true, true, true); |
||
801 | $langs = $data->getLanguages(true); |
||
802 | $fnlang = strtolower($_POST['formLanguage']); |
||
803 | |||
804 | switch ($fnlang) { |
||
805 | case 'c': |
||
806 | $this->printTitle($this->lang['strcreatecfunction'], 'pg.function.create.c'); |
||
807 | |||
808 | break; |
||
809 | case 'internal': |
||
810 | $this->printTitle($this->lang['strcreateinternalfunction'], 'pg.function.create.internal'); |
||
811 | |||
812 | break; |
||
813 | default: |
||
814 | $this->printTitle($this->lang['strcreateplfunction'], 'pg.function.create.pl'); |
||
815 | |||
816 | break; |
||
817 | } |
||
818 | $this->printMsg($msg); |
||
819 | |||
820 | // Create string for return type list |
||
821 | $szTypes = ''; |
||
822 | while (!$types->EOF) { |
||
823 | $szSelected = ''; |
||
824 | if ($types->fields['typname'] == $_POST['formReturns']) { |
||
825 | $szSelected = ' selected="selected"'; |
||
826 | } |
||
827 | // this variable is include in the JS code bellow, so we need to ENT_QUOTES |
||
828 | $szTypes .= '<option value="' . htmlspecialchars($types->fields['typname'], ENT_QUOTES) . "\"{$szSelected}>"; |
||
829 | $szTypes .= htmlspecialchars($types->fields['typname'], ENT_QUOTES) . '</option>'; |
||
830 | $types->moveNext(); |
||
831 | } |
||
832 | |||
833 | $szFunctionName = "<td class=\"data1\"><input name=\"formFunction\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"" . |
||
834 | htmlspecialchars($_POST['formFunction']) . '" /></td>'; |
||
835 | |||
836 | $szArguments = '<td class="data1"><input name="formArguments" style="width:100%;" size="16" value="' . |
||
837 | htmlspecialchars($_POST['formArguments']) . '" /></td>'; |
||
838 | |||
839 | $szSetOfSelected = ''; |
||
840 | $szNotSetOfSelected = ''; |
||
841 | if ('' == $_POST['formSetOf']) { |
||
842 | $szNotSetOfSelected = ' selected="selected"'; |
||
843 | } elseif ('SETOF' == $_POST['formSetOf']) { |
||
844 | $szSetOfSelected = ' selected="selected"'; |
||
845 | } |
||
846 | $szReturns = '<td class="data1" colspan="2">'; |
||
847 | $szReturns .= '<select name="formSetOf">'; |
||
848 | $szReturns .= "<option value=\"\"{$szNotSetOfSelected}></option>"; |
||
849 | $szReturns .= "<option value=\"SETOF\"{$szSetOfSelected}>SETOF</option>"; |
||
850 | $szReturns .= '</select>'; |
||
851 | |||
852 | $szReturns .= '<select class="select2" name="formReturns">' . $szTypes . '</select>'; |
||
853 | |||
854 | // Create string array type selector |
||
855 | |||
856 | $szArraySelected = ''; |
||
857 | $szNotArraySelected = ''; |
||
858 | if ('' == $_POST['formArray']) { |
||
859 | $szNotArraySelected = ' selected="selected"'; |
||
860 | } elseif ('[]' == $_POST['formArray']) { |
||
861 | $szArraySelected = ' selected="selected"'; |
||
862 | } |
||
863 | |||
864 | $szReturns .= '<select name="formArray">'; |
||
865 | $szReturns .= "<option value=\"\"{$szNotArraySelected}></option>"; |
||
866 | $szReturns .= "<option value=\"[]\"{$szArraySelected}>[ ]</option>"; |
||
867 | $szReturns .= "</select>\n</td>"; |
||
868 | |||
869 | // Create string for language |
||
870 | $szLanguage = '<td class="data1">'; |
||
871 | if ('c' == $fnlang || 'internal' == $fnlang) { |
||
872 | $szLanguage .= $_POST['formLanguage'] . "\n"; |
||
873 | $szLanguage .= "<input type=\"hidden\" name=\"formLanguage\" value=\"{$_POST['formLanguage']}\" />\n"; |
||
874 | } else { |
||
875 | $szLanguage .= "<select name=\"formLanguage\">\n"; |
||
876 | while (!$langs->EOF) { |
||
877 | $szSelected = ''; |
||
878 | if ($langs->fields['lanname'] == $_POST['formLanguage']) { |
||
879 | $szSelected = ' selected="selected"'; |
||
880 | } |
||
881 | if ('c' != strtolower($langs->fields['lanname']) && 'internal' != strtolower($langs->fields['lanname'])) { |
||
882 | $szLanguage .= '<option value="' . htmlspecialchars($langs->fields['lanname']) . "\"{$szSelected}>\n" . |
||
883 | $this->misc->printVal($langs->fields['lanname']) . '</option>'; |
||
884 | } |
||
885 | |||
886 | $langs->moveNext(); |
||
887 | } |
||
888 | $szLanguage .= "</select>\n"; |
||
889 | } |
||
890 | |||
891 | $szLanguage .= '</td>'; |
||
892 | $szJSArguments = "<tr><th class=\"data\" colspan=\"7\">{$this->lang['strarguments']}</th></tr>"; |
||
893 | $arrayModes = ['IN', 'OUT', 'INOUT']; |
||
894 | $szModes = '<select name="formArgModes[]" style="width:100%;">'; |
||
895 | foreach ($arrayModes as $pV) { |
||
896 | $szModes .= "<option value=\"{$pV}\">{$pV}</option>"; |
||
897 | } |
||
898 | $szModes .= '</select>'; |
||
899 | $szArgReturns = '<select name="formArgArray[]">'; |
||
900 | $szArgReturns .= '<option value=""></option>'; |
||
901 | $szArgReturns .= '<option value="[]">[]</option>'; |
||
902 | $szArgReturns .= '</select>'; |
||
903 | $subfolder = \SUBFOLDER; |
||
904 | if (!empty($this->conf['theme'])) { |
||
905 | $szImgPath = \SUBFOLDER . "/assets/images/themes/{$this->conf['theme']}"; |
||
906 | } else { |
||
907 | $szImgPath = \SUBFOLDER . '/assets/images/themes/default'; |
||
908 | } |
||
909 | if (empty($msg)) { |
||
910 | // $this->prtrace($subfolder); |
||
911 | $szJSTRArg = "<script type=\"text/javascript\" >addArg('{$subfolder}');</script>\n"; |
||
912 | } else { |
||
913 | $szJSTRArg = ''; |
||
914 | } |
||
915 | $szJSAddTR = "<tr id=\"parent_add_tr\" onclick=\"addArg('{$subfolder}');\" onmouseover=\"this.style.cursor='pointer'\">\n"; |
||
916 | $szJSAddTR .= '<td style="text-align: right" colspan="6" class="data3"><table><tr><td class="data3">'; |
||
917 | $szJSAddTR .= "<img src=\"{$szImgPath}/AddArguments.png\" alt=\"Add Argument\" /></td>"; |
||
918 | $szJSAddTR .= "<td class=\"data3\"><span style=\"font-size: 8pt\">{$this->lang['strargadd']}</span></td></tr></table></td>\n</tr>\n"; |
||
919 | |||
920 | echo '<script src="' . \SUBFOLDER . "/assets/js/functions.js\" type=\"text/javascript\"></script> |
||
921 | <script type=\"text/javascript\"> |
||
922 | //<![CDATA[ |
||
923 | var g_types_select = '<select class=\"select2\" name=\"formArgType[]\">{$szTypes}</select>{$szArgReturns}'; |
||
924 | var g_modes_select = '{$szModes}'; |
||
925 | var g_name = ''; |
||
926 | var g_lang_strargremove = '", htmlspecialchars($this->lang['strargremove'], ENT_QUOTES), "'; |
||
927 | var g_lang_strargnoargs = '", htmlspecialchars($this->lang['strargnoargs'], ENT_QUOTES), "'; |
||
928 | var g_lang_strargenableargs = '", htmlspecialchars($this->lang['strargenableargs'], ENT_QUOTES), "'; |
||
929 | var g_lang_strargnorowabove = '", htmlspecialchars($this->lang['strargnorowabove'], ENT_QUOTES), "'; |
||
930 | var g_lang_strargnorowbelow = '", htmlspecialchars($this->lang['strargnorowbelow'], ENT_QUOTES), "'; |
||
931 | var g_lang_strargremoveconfirm = '", htmlspecialchars($this->lang['strargremoveconfirm'], ENT_QUOTES), "'; |
||
932 | var g_lang_strargraise = '", htmlspecialchars($this->lang['strargraise'], ENT_QUOTES), "'; |
||
933 | var g_lang_strarglower = '", htmlspecialchars($this->lang['strarglower'], ENT_QUOTES), "'; |
||
934 | //]]> |
||
935 | </script> |
||
936 | "; |
||
937 | echo '<form action="' . \SUBFOLDER . "/src/views/functions\" method=\"post\">\n"; |
||
938 | echo "<table><tbody id=\"args_table\">\n"; |
||
939 | echo "<tr><th class=\"data required\">{$this->lang['strname']}</th>\n"; |
||
940 | echo "<th class=\"data required\" colspan=\"2\">{$this->lang['strreturns']}</th>\n"; |
||
941 | echo "<th class=\"data required\">{$this->lang['strproglanguage']}</th></tr>\n"; |
||
942 | echo "<tr>\n"; |
||
943 | echo "{$szFunctionName}\n"; |
||
944 | echo "{$szReturns}\n"; |
||
945 | echo "{$szLanguage}\n"; |
||
946 | echo "</tr>\n"; |
||
947 | echo "{$szJSArguments}\n"; |
||
948 | echo "<tr>\n"; |
||
949 | echo "<th class=\"data required\">{$this->lang['strargmode']}</th>\n"; |
||
950 | echo "<th class=\"data required\">{$this->lang['strname']}</th>\n"; |
||
951 | echo "<th class=\"data required\" colspan=\"2\">{$this->lang['strargtype']}</th>\n"; |
||
952 | echo "</tr>\n"; |
||
953 | echo "{$szJSAddTR}\n"; |
||
954 | |||
955 | if ('c' == $fnlang) { |
||
956 | echo "<tr><th class=\"data required\" colspan=\"2\">{$this->lang['strobjectfile']}</th>\n"; |
||
957 | echo "<th class=\"data\" colspan=\"2\">{$this->lang['strlinksymbol']}</th></tr>\n"; |
||
958 | echo '<tr><td class="data1" colspan="2"><input type="text" name="formObjectFile" style="width:100%" value="', |
||
959 | htmlspecialchars($_POST['formObjectFile']), "\" /></td>\n"; |
||
960 | echo '<td class="data1" colspan="2"><input type="text" name="formLinkSymbol" style="width:100%" value="', |
||
961 | htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n"; |
||
962 | } elseif ('internal' == $fnlang) { |
||
963 | echo "<tr><th class=\"data\" colspan=\"4\">{$this->lang['strlinksymbol']}</th></tr>\n"; |
||
964 | echo '<tr><td class="data1" colspan="4"><input type="text" name="formLinkSymbol" style="width:100%" value="', |
||
965 | htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n"; |
||
966 | } else { |
||
967 | echo "<tr><th class=\"data required\" colspan=\"4\">{$this->lang['strdefinition']}</th></tr>\n"; |
||
968 | echo '<tr><td class="data1" colspan="4">'; |
||
969 | echo '<textarea style="width:100%;" rows="20" cols="50" name="formDefinition">'; |
||
970 | echo htmlspecialchars($_POST['formDefinition']); |
||
971 | echo "</textarea></td></tr>\n"; |
||
972 | } |
||
973 | |||
974 | // Display function comment |
||
975 | echo "<tr><th class=\"data\" colspan=\"4\">{$this->lang['strcomment']}</th></tr>\n"; |
||
976 | echo '<tr><td class="data1" colspan="4"><textarea style="width:100%;" name="formComment" rows="3" cols="50">', |
||
977 | htmlspecialchars($_POST['formComment']), "</textarea></td></tr>\n"; |
||
978 | |||
979 | // Display function cost options |
||
980 | if ($data->hasFunctionCosting()) { |
||
981 | echo "<tr><th class=\"data required\" colspan=\"4\">{$this->lang['strfunctioncosting']}</th></tr>\n"; |
||
982 | echo "<td class=\"data1\" colspan=\"2\">{$this->lang['strexecutioncost']}: <input name=\"formCost\" size=\"16\" value=\"" . |
||
983 | htmlspecialchars($_POST['formCost']) . '" /></td>'; |
||
984 | echo "<td class=\"data1\" colspan=\"2\">{$this->lang['strresultrows']}: <input name=\"formRows\" size=\"16\" value=\"" . |
||
985 | htmlspecialchars($_POST['formRows']) . '" /></td>'; |
||
986 | } |
||
987 | |||
988 | // Display function properties |
||
989 | if (is_array($data->funcprops) && sizeof($data->funcprops) > 0) { |
||
990 | echo "<tr><th class=\"data required\" colspan=\"4\">{$this->lang['strproperties']}</th></tr>\n"; |
||
991 | echo "<tr><td class=\"data1\" colspan=\"4\">\n"; |
||
992 | $i = 0; |
||
993 | foreach ($data->funcprops as $k => $v) { |
||
994 | echo "<select name=\"formProperties[{$i}]\">\n"; |
||
995 | foreach ($v as $p) { |
||
996 | echo '<option value="', htmlspecialchars($p), '"', |
||
997 | ($_POST['formProperties'][$i] == $p) ? ' selected="selected"' : '', |
||
998 | '>', $this->misc->printVal($p), "</option>\n"; |
||
999 | } |
||
1000 | echo "</select><br />\n"; |
||
1001 | ++$i; |
||
1002 | } |
||
1003 | echo "</td></tr>\n"; |
||
1004 | } |
||
1005 | echo "</tbody></table>\n"; |
||
1006 | echo $szJSTRArg; |
||
1007 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n"; |
||
1008 | echo $this->misc->form; |
||
1009 | echo "<input type=\"submit\" value=\"{$this->lang['strcreate']}\" />\n"; |
||
1010 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
1011 | echo "</form>\n"; |
||
1012 | echo $szJS; |
||
1013 | } |
||
1014 | |||
1015 | /** |
||
1016 | * Actually creates the new function in the database. |
||
1017 | */ |
||
1018 | public function doSaveCreate() |
||
1019 | { |
||
1020 | $data = $this->misc->getDatabaseAccessor(); |
||
1021 | |||
1022 | $fnlang = strtolower($_POST['formLanguage']); |
||
1023 | |||
1024 | if ('c' == $fnlang) { |
||
1025 | $def = [$_POST['formObjectFile'], $_POST['formLinkSymbol']]; |
||
1026 | } elseif ('internal' == $fnlang) { |
||
1027 | $def = $_POST['formLinkSymbol']; |
||
1028 | } else { |
||
1029 | $def = $_POST['formDefinition']; |
||
1030 | } |
||
1031 | |||
1032 | $szJS = ''; |
||
1033 | |||
1034 | echo '<script src="' . \SUBFOLDER . '/assets/js/functions.js" type="text/javascript"></script>'; |
||
1035 | echo '<script type="text/javascript">' . $this->_buildJSData() . '</script>'; |
||
1036 | if (!empty($_POST['formArgName'])) { |
||
1037 | $szJS = $this->_buildJSRows($this->_buildFunctionArguments($_POST)); |
||
1038 | } else { |
||
1039 | $subfolder = \SUBFOLDER; |
||
1040 | // $this->prtrace($subfolder); |
||
1041 | $szJS = '<script type="text/javascript" src="' . \SUBFOLDER . '/assets/js/functions.js">noArgsRebuild(addArg("' . $subfolder . '"));</script>'; |
||
1042 | } |
||
1043 | |||
1044 | $cost = (isset($_POST['formCost'])) ? $_POST['formCost'] : null; |
||
1045 | if ('' == $cost || !is_numeric($cost) || $cost != (int) $cost || $cost < 0) { |
||
1046 | $cost = null; |
||
1047 | } |
||
1048 | |||
1049 | $rows = (isset($_POST['formRows'])) ? $_POST['formRows'] : null; |
||
1050 | if ('' == $rows || !is_numeric($rows) || $rows != (int) $rows) { |
||
1051 | $rows = null; |
||
1052 | } |
||
1053 | |||
1054 | // Check that they've given a name and a definition |
||
1055 | if ('' == $_POST['formFunction']) { |
||
1056 | $this->doCreate($this->lang['strfunctionneedsname'], $szJS); |
||
1057 | } elseif ('internal' != $fnlang && !$def) { |
||
1058 | $this->doCreate($this->lang['strfunctionneedsdef'], $szJS); |
||
1059 | } else { |
||
1060 | // Append array symbol to type if chosen |
||
1061 | $status = $data->createFunction( |
||
1062 | $_POST['formFunction'], |
||
1063 | empty($_POST['nojs']) ? $this->_buildFunctionArguments($_POST) : $_POST['formArguments'], |
||
1064 | $_POST['formReturns'] . $_POST['formArray'], |
||
1065 | $def, |
||
1066 | $_POST['formLanguage'], |
||
1067 | $_POST['formProperties'], |
||
1068 | 'SETOF' == $_POST['formSetOf'], |
||
1069 | $cost, |
||
1070 | $rows, |
||
1071 | $_POST['formComment'], |
||
1072 | false |
||
1073 | ); |
||
1074 | if (0 == $status) { |
||
1075 | $this->doDefault($this->lang['strfunctioncreated']); |
||
1076 | } else { |
||
1077 | $this->doCreate($this->lang['strfunctioncreatedbad'], $szJS); |
||
1078 | } |
||
1079 | } |
||
1080 | } |
||
1081 | |||
1082 | /** |
||
1083 | * Build out the function arguments string. |
||
1084 | * |
||
1085 | * @param array $arrayVars |
||
1086 | * |
||
1087 | * @return string the imploded array vars |
||
1088 | */ |
||
1089 | private function _buildFunctionArguments($arrayVars) |
||
1090 | { |
||
1091 | if (isset($_POST['formArgName'])) { |
||
1092 | $arrayArgs = []; |
||
1093 | foreach ($arrayVars['formArgName'] as $pK => $pV) { |
||
1094 | $arrayArgs[] = $arrayVars['formArgModes'][$pK] . ' ' . trim($pV) . ' ' . trim($arrayVars['formArgType'][$pK]) . $arrayVars['formArgArray'][$pK]; |
||
1095 | } |
||
1096 | |||
1097 | return implode(',', $arrayArgs); |
||
1098 | } |
||
1099 | |||
1100 | return ''; |
||
1101 | } |
||
1102 | |||
1103 | /** |
||
1104 | * Build out JS to re-create table rows for arguments. |
||
1105 | * |
||
1106 | * @param string $szArgs args to parse |
||
1107 | */ |
||
1108 | private function _buildJSRows($szArgs) |
||
1140 | } |
||
1141 | |||
1142 | private function _buildJSData() |
||
1143 | { |
||
1144 | $data = $this->misc->getDatabaseAccessor(); |
||
1164 | } |
||
1165 | |||
1166 | /** |
||
1167 | * Get the concatenated arguments for a function |
||
1168 | * |
||
1169 | * @param \PHPPgAdmin\ADORecordSet $funcdata The funcdata record |
||
1170 | * |
||
1171 | * @return string The arguments of the function |
||
1172 | */ |
||
1173 | private function _getPropertiesArgs($funcdata) |
||
1228 |