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