| Total Complexity | 93 |
| Total Lines | 877 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like SequencesController 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 SequencesController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class SequencesController extends BaseController |
||
| 15 | { |
||
| 16 | public $controller_name = 'SequencesController'; |
||
| 17 | |||
| 18 | public function render() |
||
|
1 ignored issue
–
show
|
|||
| 19 | { |
||
| 20 | $conf = $this->conf; |
||
| 21 | |||
| 22 | $lang = $this->lang; |
||
| 23 | |||
| 24 | $action = $this->action; |
||
| 25 | if ('tree' == $action) { |
||
| 26 | return $this->doTree(); |
||
| 27 | } |
||
| 28 | |||
| 29 | // Print header |
||
| 30 | $this->printHeader($lang['strsequences']); |
||
| 31 | $this->printBody(); |
||
| 32 | |||
| 33 | switch ($action) { |
||
| 34 | case 'create': |
||
| 35 | $this->doCreateSequence(); |
||
| 36 | |||
| 37 | break; |
||
| 38 | case 'save_create_sequence': |
||
| 39 | if (isset($_POST['create'])) { |
||
| 40 | $this->doSaveCreateSequence(); |
||
| 41 | } else { |
||
| 42 | $this->doDefault(); |
||
| 43 | } |
||
| 44 | |||
| 45 | break; |
||
| 46 | case 'properties': |
||
| 47 | $this->doProperties(); |
||
| 48 | |||
| 49 | break; |
||
| 50 | case 'drop': |
||
| 51 | if (isset($_POST['drop'])) { |
||
| 52 | $this->doDrop(false); |
||
| 53 | } else { |
||
| 54 | $this->doDefault(); |
||
| 55 | } |
||
| 56 | |||
| 57 | break; |
||
| 58 | case 'confirm_drop': |
||
| 59 | $this->doDrop(true); |
||
| 60 | |||
| 61 | break; |
||
| 62 | case 'restart': |
||
| 63 | $this->doRestart(); |
||
| 64 | |||
| 65 | break; |
||
| 66 | case 'reset': |
||
| 67 | $this->doReset(); |
||
| 68 | |||
| 69 | break; |
||
| 70 | case 'nextval': |
||
| 71 | $this->doNextval(); |
||
| 72 | |||
| 73 | break; |
||
| 74 | case 'setval': |
||
| 75 | if (isset($_POST['setval'])) { |
||
| 76 | $this->doSaveSetval(); |
||
| 77 | } else { |
||
| 78 | $this->doDefault(); |
||
| 79 | } |
||
| 80 | |||
| 81 | break; |
||
| 82 | case 'confirm_setval': |
||
| 83 | $this->doSetval(); |
||
| 84 | |||
| 85 | break; |
||
| 86 | case 'alter': |
||
| 87 | if (isset($_POST['alter'])) { |
||
| 88 | $this->doSaveAlter(); |
||
| 89 | } else { |
||
| 90 | $this->doDefault(); |
||
| 91 | } |
||
| 92 | |||
| 93 | break; |
||
| 94 | case 'confirm_alter': |
||
| 95 | $this->doAlter(); |
||
| 96 | |||
| 97 | break; |
||
| 98 | default: |
||
| 99 | $this->doDefault(); |
||
| 100 | |||
| 101 | break; |
||
| 102 | } |
||
| 103 | |||
| 104 | // Print footer |
||
| 105 | return $this->printFooter(); |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Display list of all sequences in the database/schema |
||
| 110 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 111 | */ |
||
| 112 | public function doDefault($msg = '') |
||
| 113 | { |
||
| 114 | $conf = $this->conf; |
||
| 115 | |||
| 116 | $lang = $this->lang; |
||
| 117 | $data = $this->misc->getDatabaseAccessor(); |
||
| 118 | |||
| 119 | $this->printTrail('schema'); |
||
| 120 | $this->printTabs('schema', 'sequences'); |
||
| 121 | $this->printMsg($msg); |
||
| 122 | |||
| 123 | // Get all sequences |
||
| 124 | $sequences = $data->getSequences(); |
||
| 125 | |||
| 126 | $columns = [ |
||
| 127 | 'sequence' => [ |
||
| 128 | 'title' => $lang['strsequence'], |
||
| 129 | 'field' => Decorator::field('seqname'), |
||
| 130 | 'url' => "sequences.php?action=properties&{$this->misc->href}&", |
||
| 131 | 'vars' => ['sequence' => 'seqname'], |
||
| 132 | ], |
||
| 133 | 'owner' => [ |
||
| 134 | 'title' => $lang['strowner'], |
||
| 135 | 'field' => Decorator::field('seqowner'), |
||
| 136 | ], |
||
| 137 | 'actions' => [ |
||
| 138 | 'title' => $lang['stractions'], |
||
| 139 | ], |
||
| 140 | 'comment' => [ |
||
| 141 | 'title' => $lang['strcomment'], |
||
| 142 | 'field' => Decorator::field('seqcomment'), |
||
| 143 | ], |
||
| 144 | ]; |
||
| 145 | |||
| 146 | $actions = [ |
||
| 147 | 'multiactions' => [ |
||
| 148 | 'keycols' => ['sequence' => 'seqname'], |
||
| 149 | 'url' => 'sequences.php', |
||
| 150 | ], |
||
| 151 | 'alter' => [ |
||
| 152 | 'content' => $lang['stralter'], |
||
| 153 | 'attr' => [ |
||
| 154 | 'href' => [ |
||
| 155 | 'url' => 'sequences.php', |
||
| 156 | 'urlvars' => [ |
||
| 157 | 'action' => 'confirm_alter', |
||
| 158 | 'subject' => 'sequence', |
||
| 159 | 'sequence' => Decorator::field('seqname'), |
||
| 160 | ], |
||
| 161 | ], |
||
| 162 | ], |
||
| 163 | ], |
||
| 164 | 'drop' => [ |
||
| 165 | 'content' => $lang['strdrop'], |
||
| 166 | 'attr' => [ |
||
| 167 | 'href' => [ |
||
| 168 | 'url' => 'sequences.php', |
||
| 169 | 'urlvars' => [ |
||
| 170 | 'action' => 'confirm_drop', |
||
| 171 | 'sequence' => Decorator::field('seqname'), |
||
| 172 | ], |
||
| 173 | ], |
||
| 174 | ], |
||
| 175 | 'multiaction' => 'confirm_drop', |
||
| 176 | ], |
||
| 177 | 'privileges' => [ |
||
| 178 | 'content' => $lang['strprivileges'], |
||
| 179 | 'attr' => [ |
||
| 180 | 'href' => [ |
||
| 181 | 'url' => 'privileges.php', |
||
| 182 | 'urlvars' => [ |
||
| 183 | 'subject' => 'sequence', |
||
| 184 | 'sequence' => Decorator::field('seqname'), |
||
| 185 | ], |
||
| 186 | ], |
||
| 187 | ], |
||
| 188 | ], |
||
| 189 | ]; |
||
| 190 | |||
| 191 | echo $this->printTable($sequences, $columns, $actions, 'sequences-sequences', $lang['strnosequences']); |
||
| 192 | |||
| 193 | $this->printNavLinks(['create' => [ |
||
|
1 ignored issue
–
show
|
|||
| 194 | 'attr' => [ |
||
| 195 | 'href' => [ |
||
| 196 | 'url' => 'sequences.php', |
||
| 197 | 'urlvars' => [ |
||
| 198 | 'action' => 'create', |
||
| 199 | 'server' => $_REQUEST['server'], |
||
| 200 | 'database' => $_REQUEST['database'], |
||
| 201 | 'schema' => $_REQUEST['schema'], |
||
| 202 | ], |
||
| 203 | ], |
||
| 204 | ], |
||
| 205 | 'content' => $lang['strcreatesequence'], |
||
| 206 | ]], 'sequences-sequences', get_defined_vars()); |
||
|
1 ignored issue
–
show
|
|||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Generate XML for the browser tree. |
||
| 211 | */ |
||
| 212 | public function doTree() |
||
| 213 | { |
||
| 214 | $conf = $this->conf; |
||
| 215 | |||
| 216 | $lang = $this->lang; |
||
| 217 | $data = $this->misc->getDatabaseAccessor(); |
||
| 218 | |||
| 219 | $sequences = $data->getSequences(); |
||
| 220 | |||
| 221 | $reqvars = $this->misc->getRequestVars('sequence'); |
||
| 222 | |||
| 223 | $attrs = [ |
||
| 224 | 'text' => Decorator::field('seqname'), |
||
| 225 | 'icon' => 'Sequence', |
||
| 226 | 'toolTip' => Decorator::field('seqcomment'), |
||
| 227 | 'action' => Decorator::actionurl( |
||
| 228 | 'sequences.php', |
||
| 229 | $reqvars, |
||
| 230 | [ |
||
| 231 | 'action' => 'properties', |
||
| 232 | 'sequence' => Decorator::field('seqname'), |
||
| 233 | ] |
||
| 234 | ), |
||
| 235 | ]; |
||
| 236 | |||
| 237 | return $this->printTree($sequences, $attrs, 'sequences'); |
||
| 238 | } |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Display the properties of a sequence |
||
| 242 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 243 | */ |
||
| 244 | public function doProperties($msg = '') |
||
| 245 | { |
||
| 246 | $conf = $this->conf; |
||
| 247 | |||
| 248 | $lang = $this->lang; |
||
| 249 | $data = $this->misc->getDatabaseAccessor(); |
||
| 250 | $this->printTrail('sequence'); |
||
| 251 | $this->printTitle($lang['strproperties'], 'pg.sequence'); |
||
| 252 | $this->printMsg($msg); |
||
| 253 | |||
| 254 | // Fetch the sequence information |
||
| 255 | $sequence = $data->getSequence($_REQUEST['sequence']); |
||
| 256 | |||
| 257 | if (is_object($sequence) && $sequence->recordCount() > 0) { |
||
| 258 | $sequence->fields['is_cycled'] = $data->phpBool($sequence->fields['is_cycled']); |
||
| 259 | $sequence->fields['is_called'] = $data->phpBool($sequence->fields['is_called']); |
||
| 260 | |||
| 261 | // Show comment if any |
||
| 262 | if (null !== $sequence->fields['seqcomment']) { |
||
| 263 | echo '<p class="comment">', $this->misc->printVal($sequence->fields['seqcomment']), "</p>\n"; |
||
| 264 | } |
||
| 265 | |||
| 266 | echo '<table border="0">'; |
||
| 267 | echo "<tr><th class=\"data\">{$lang['strname']}</th>"; |
||
| 268 | if ($data->hasAlterSequenceStart()) { |
||
| 269 | echo "<th class=\"data\">{$lang['strstartvalue']}</th>"; |
||
| 270 | } |
||
| 271 | echo "<th class=\"data\">{$lang['strlastvalue']}</th>"; |
||
| 272 | echo "<th class=\"data\">{$lang['strincrementby']}</th>"; |
||
| 273 | echo "<th class=\"data\">{$lang['strmaxvalue']}</th>"; |
||
| 274 | echo "<th class=\"data\">{$lang['strminvalue']}</th>"; |
||
| 275 | echo "<th class=\"data\">{$lang['strcachevalue']}</th>"; |
||
| 276 | echo "<th class=\"data\">{$lang['strlogcount']}</th>"; |
||
| 277 | echo "<th class=\"data\">{$lang['strcancycle']}</th>"; |
||
| 278 | echo "<th class=\"data\">{$lang['striscalled']}</th></tr>"; |
||
| 279 | echo '<tr>'; |
||
| 280 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['seqname']), '</td>'; |
||
| 281 | if ($data->hasAlterSequenceStart()) { |
||
| 282 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['start_value']), '</td>'; |
||
| 283 | } |
||
| 284 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['last_value']), '</td>'; |
||
| 285 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['increment_by']), '</td>'; |
||
| 286 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['max_value']), '</td>'; |
||
| 287 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['min_value']), '</td>'; |
||
| 288 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['cache_value']), '</td>'; |
||
| 289 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['log_cnt']), '</td>'; |
||
| 290 | echo '<td class="data1">', ($sequence->fields['is_cycled'] ? $lang['stryes'] : $lang['strno']), '</td>'; |
||
| 291 | echo '<td class="data1">', ($sequence->fields['is_called'] ? $lang['stryes'] : $lang['strno']), '</td>'; |
||
| 292 | echo '</tr>'; |
||
| 293 | echo '</table>'; |
||
| 294 | |||
| 295 | $navlinks = [ |
||
| 296 | 'alter' => [ |
||
| 297 | 'attr' => [ |
||
| 298 | 'href' => [ |
||
| 299 | 'url' => 'sequences.php', |
||
| 300 | 'urlvars' => [ |
||
| 301 | 'action' => 'confirm_alter', |
||
| 302 | 'server' => $_REQUEST['server'], |
||
| 303 | 'database' => $_REQUEST['database'], |
||
| 304 | 'schema' => $_REQUEST['schema'], |
||
| 305 | 'sequence' => $sequence->fields['seqname'], |
||
| 306 | ], |
||
| 307 | ], |
||
| 308 | ], |
||
| 309 | 'content' => $lang['stralter'], |
||
| 310 | ], |
||
| 311 | 'setval' => [ |
||
| 312 | 'attr' => [ |
||
| 313 | 'href' => [ |
||
| 314 | 'url' => 'sequences.php', |
||
| 315 | 'urlvars' => [ |
||
| 316 | 'action' => 'confirm_setval', |
||
| 317 | 'server' => $_REQUEST['server'], |
||
| 318 | 'database' => $_REQUEST['database'], |
||
| 319 | 'schema' => $_REQUEST['schema'], |
||
| 320 | 'sequence' => $sequence->fields['seqname'], |
||
| 321 | ], |
||
| 322 | ], |
||
| 323 | ], |
||
| 324 | 'content' => $lang['strsetval'], |
||
| 325 | ], |
||
| 326 | 'nextval' => [ |
||
| 327 | 'attr' => [ |
||
| 328 | 'href' => [ |
||
| 329 | 'url' => 'sequences.php', |
||
| 330 | 'urlvars' => [ |
||
| 331 | 'action' => 'nextval', |
||
| 332 | 'server' => $_REQUEST['server'], |
||
| 333 | 'database' => $_REQUEST['database'], |
||
| 334 | 'schema' => $_REQUEST['schema'], |
||
| 335 | 'sequence' => $sequence->fields['seqname'], |
||
| 336 | ], |
||
| 337 | ], |
||
| 338 | ], |
||
| 339 | 'content' => $lang['strnextval'], |
||
| 340 | ], |
||
| 341 | 'restart' => [ |
||
| 342 | 'attr' => [ |
||
| 343 | 'href' => [ |
||
| 344 | 'url' => 'sequences.php', |
||
| 345 | 'urlvars' => [ |
||
| 346 | 'action' => 'restart', |
||
| 347 | 'server' => $_REQUEST['server'], |
||
| 348 | 'database' => $_REQUEST['database'], |
||
| 349 | 'schema' => $_REQUEST['schema'], |
||
| 350 | 'sequence' => $sequence->fields['seqname'], |
||
| 351 | ], |
||
| 352 | ], |
||
| 353 | ], |
||
| 354 | 'content' => $lang['strrestart'], |
||
| 355 | ], |
||
| 356 | 'reset' => [ |
||
| 357 | 'attr' => [ |
||
| 358 | 'href' => [ |
||
| 359 | 'url' => 'sequences.php', |
||
| 360 | 'urlvars' => [ |
||
| 361 | 'action' => 'reset', |
||
| 362 | 'server' => $_REQUEST['server'], |
||
| 363 | 'database' => $_REQUEST['database'], |
||
| 364 | 'schema' => $_REQUEST['schema'], |
||
| 365 | 'sequence' => $sequence->fields['seqname'], |
||
| 366 | ], |
||
| 367 | ], |
||
| 368 | ], |
||
| 369 | 'content' => $lang['strreset'], |
||
| 370 | ], |
||
| 371 | 'showall' => [ |
||
| 372 | 'attr' => [ |
||
| 373 | 'href' => [ |
||
| 374 | 'url' => 'sequences.php', |
||
| 375 | 'urlvars' => [ |
||
| 376 | 'server' => $_REQUEST['server'], |
||
| 377 | 'database' => $_REQUEST['database'], |
||
| 378 | 'schema' => $_REQUEST['schema'], |
||
| 379 | ], |
||
| 380 | ], |
||
| 381 | ], |
||
| 382 | 'content' => $lang['strshowallsequences'], |
||
| 383 | ], |
||
| 384 | ]; |
||
| 385 | |||
| 386 | if (!$data->hasAlterSequenceStart()) { |
||
| 387 | unset($navlinks['restart']); |
||
| 388 | } |
||
| 389 | |||
| 390 | $this->printNavLinks($navlinks, 'sequences-properties', get_defined_vars()); |
||
| 391 | } else { |
||
| 392 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
| 393 | } |
||
| 394 | } |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Drop a sequence |
||
| 398 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 399 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 400 | */ |
||
| 401 | public function doDrop($confirm, $msg = '') |
||
| 402 | { |
||
| 403 | $conf = $this->conf; |
||
| 404 | |||
| 405 | $lang = $this->lang; |
||
| 406 | $data = $this->misc->getDatabaseAccessor(); |
||
| 407 | |||
| 408 | if (empty($_REQUEST['sequence']) && empty($_REQUEST['ma'])) { |
||
| 409 | return $this->doDefault($lang['strspecifysequencetodrop']); |
||
| 410 | } |
||
| 411 | |||
| 412 | if ($confirm) { |
||
| 413 | $this->printTrail('sequence'); |
||
| 414 | $this->printTitle($lang['strdrop'], 'pg.sequence.drop'); |
||
| 415 | $this->printMsg($msg); |
||
| 416 | |||
| 417 | echo '<form action="' . SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n"; |
||
| 418 | |||
| 419 | //If multi drop |
||
| 420 | if (isset($_REQUEST['ma'])) { |
||
| 421 | foreach ($_REQUEST['ma'] as $v) { |
||
| 422 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
| 423 | echo '<p>', sprintf($lang['strconfdropsequence'], $this->misc->printVal($a['sequence'])), "</p>\n"; |
||
| 424 | printf('<input type="hidden" name="sequence[]" value="%s" />', htmlspecialchars($a['sequence'])); |
||
| 425 | } |
||
| 426 | } else { |
||
| 427 | echo '<p>', sprintf($lang['strconfdropsequence'], $this->misc->printVal($_REQUEST['sequence'])), "</p>\n"; |
||
| 428 | echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n"; |
||
| 429 | } |
||
| 430 | |||
| 431 | echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n"; |
||
| 432 | echo "<p><input type=\"hidden\" name=\"action\" value=\"drop\" />\n"; |
||
| 433 | echo $this->misc->form; |
||
| 434 | echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n"; |
||
| 435 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 436 | echo "</form>\n"; |
||
| 437 | } else { |
||
| 438 | if (is_array($_POST['sequence'])) { |
||
| 439 | $msg = ''; |
||
| 440 | $status = $data->beginTransaction(); |
||
| 441 | if (0 == $status) { |
||
| 442 | foreach ($_POST['sequence'] as $s) { |
||
| 443 | $status = $data->dropSequence($s, isset($_POST['cascade'])); |
||
| 444 | if (0 == $status) { |
||
| 445 | $msg .= sprintf('%s: %s<br />', htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strsequencedropped']); |
||
| 446 | } else { |
||
| 447 | $data->endTransaction(); |
||
| 448 | $this->doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strsequencedroppedbad'])); |
||
| 449 | |||
| 450 | return; |
||
| 451 | } |
||
| 452 | } |
||
| 453 | } |
||
| 454 | if (0 == $data->endTransaction()) { |
||
| 455 | // Everything went fine, back to the Default page.... |
||
| 456 | $this->misc->setReloadBrowser(true); |
||
| 457 | $this->doDefault($msg); |
||
| 458 | } else { |
||
| 459 | $this->doDefault($lang['strsequencedroppedbad']); |
||
| 460 | } |
||
| 461 | } else { |
||
| 462 | $status = $data->dropSequence($_POST['sequence'], isset($_POST['cascade'])); |
||
| 463 | if (0 == $status) { |
||
| 464 | $this->misc->setReloadBrowser(true); |
||
| 465 | $this->doDefault($lang['strsequencedropped']); |
||
| 466 | } else { |
||
| 467 | $this->doDrop(true, $lang['strsequencedroppedbad']); |
||
| 468 | } |
||
| 469 | } |
||
| 470 | } |
||
| 471 | } |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Displays a screen where they can enter a new sequence |
||
| 475 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 476 | */ |
||
| 477 | public function doCreateSequence($msg = '') |
||
| 478 | { |
||
| 479 | $conf = $this->conf; |
||
| 480 | |||
| 481 | $lang = $this->lang; |
||
| 482 | $data = $this->misc->getDatabaseAccessor(); |
||
| 483 | |||
| 484 | if (!isset($_POST['formSequenceName'])) { |
||
| 485 | $_POST['formSequenceName'] = ''; |
||
| 486 | } |
||
| 487 | |||
| 488 | if (!isset($_POST['formIncrement'])) { |
||
| 489 | $_POST['formIncrement'] = ''; |
||
| 490 | } |
||
| 491 | |||
| 492 | if (!isset($_POST['formMinValue'])) { |
||
| 493 | $_POST['formMinValue'] = ''; |
||
| 494 | } |
||
| 495 | |||
| 496 | if (!isset($_POST['formMaxValue'])) { |
||
| 497 | $_POST['formMaxValue'] = ''; |
||
| 498 | } |
||
| 499 | |||
| 500 | if (!isset($_POST['formStartValue'])) { |
||
| 501 | $_POST['formStartValue'] = ''; |
||
| 502 | } |
||
| 503 | |||
| 504 | if (!isset($_POST['formCacheValue'])) { |
||
| 505 | $_POST['formCacheValue'] = ''; |
||
| 506 | } |
||
| 507 | |||
| 508 | $this->printTrail('schema'); |
||
| 509 | $this->printTitle($lang['strcreatesequence'], 'pg.sequence.create'); |
||
| 510 | $this->printMsg($msg); |
||
| 511 | |||
| 512 | echo '<form action="' . SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n"; |
||
| 513 | echo "<table>\n"; |
||
| 514 | |||
| 515 | echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
| 516 | echo "<td class=\"data1\"><input name=\"formSequenceName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 517 | htmlspecialchars($_POST['formSequenceName']), "\" /></td></tr>\n"; |
||
| 518 | |||
| 519 | echo "<tr><th class=\"data left\">{$lang['strincrementby']}</th>\n"; |
||
| 520 | echo '<td class="data1"><input name="formIncrement" size="5" value="', |
||
| 521 | htmlspecialchars($_POST['formIncrement']), "\" /> </td></tr>\n"; |
||
| 522 | |||
| 523 | echo "<tr><th class=\"data left\">{$lang['strminvalue']}</th>\n"; |
||
| 524 | echo '<td class="data1"><input name="formMinValue" size="5" value="', |
||
| 525 | htmlspecialchars($_POST['formMinValue']), "\" /></td></tr>\n"; |
||
| 526 | |||
| 527 | echo "<tr><th class=\"data left\">{$lang['strmaxvalue']}</th>\n"; |
||
| 528 | echo '<td class="data1"><input name="formMaxValue" size="5" value="', |
||
| 529 | htmlspecialchars($_POST['formMaxValue']), "\" /></td></tr>\n"; |
||
| 530 | |||
| 531 | echo "<tr><th class=\"data left\">{$lang['strstartvalue']}</th>\n"; |
||
| 532 | echo '<td class="data1"><input name="formStartValue" size="5" value="', |
||
| 533 | htmlspecialchars($_POST['formStartValue']), "\" /></td></tr>\n"; |
||
| 534 | |||
| 535 | echo "<tr><th class=\"data left\">{$lang['strcachevalue']}</th>\n"; |
||
| 536 | echo '<td class="data1"><input name="formCacheValue" size="5" value="', |
||
| 537 | htmlspecialchars($_POST['formCacheValue']), "\" /></td></tr>\n"; |
||
| 538 | |||
| 539 | echo "<tr><th class=\"data left\"><label for=\"formCycledValue\">{$lang['strcancycle']}</label></th>\n"; |
||
| 540 | echo '<td class="data1"><input type="checkbox" id="formCycledValue" name="formCycledValue" ', |
||
| 541 | (isset($_POST['formCycledValue']) ? ' checked="checked"' : ''), " /></td></tr>\n"; |
||
| 542 | |||
| 543 | echo "</table>\n"; |
||
| 544 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_sequence\" />\n"; |
||
| 545 | echo $this->misc->form; |
||
| 546 | echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n"; |
||
| 547 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 548 | echo "</form>\n"; |
||
| 549 | } |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Actually creates the new sequence in the database |
||
| 553 | */ |
||
| 554 | public function doSaveCreateSequence() |
||
| 555 | { |
||
| 556 | $conf = $this->conf; |
||
| 557 | |||
| 558 | $lang = $this->lang; |
||
| 559 | $data = $this->misc->getDatabaseAccessor(); |
||
| 560 | |||
| 561 | // Check that they've given a name and at least one column |
||
| 562 | if ('' == $_POST['formSequenceName']) { |
||
| 563 | $this->doCreateSequence($lang['strsequenceneedsname']); |
||
| 564 | } else { |
||
| 565 | $status = $data->createSequence( |
||
| 566 | $_POST['formSequenceName'], |
||
| 567 | $_POST['formIncrement'], |
||
| 568 | $_POST['formMinValue'], |
||
| 569 | $_POST['formMaxValue'], |
||
| 570 | $_POST['formStartValue'], |
||
| 571 | $_POST['formCacheValue'], |
||
| 572 | isset($_POST['formCycledValue']) |
||
| 573 | ); |
||
| 574 | if (0 == $status) { |
||
| 575 | $this->doDefault($lang['strsequencecreated']); |
||
| 576 | } else { |
||
| 577 | $this->doCreateSequence($lang['strsequencecreatedbad']); |
||
| 578 | } |
||
| 579 | } |
||
| 580 | } |
||
| 581 | |||
| 582 | /** |
||
| 583 | * Restarts a sequence |
||
| 584 | */ |
||
| 585 | public function doRestart() |
||
| 586 | { |
||
| 587 | $conf = $this->conf; |
||
| 588 | |||
| 589 | $lang = $this->lang; |
||
| 590 | $data = $this->misc->getDatabaseAccessor(); |
||
| 591 | |||
| 592 | $status = $data->restartSequence($_REQUEST['sequence']); |
||
| 593 | if (0 == $status) { |
||
| 594 | $this->doProperties($lang['strsequencerestart']); |
||
| 595 | } else { |
||
| 596 | $this->doProperties($lang['strsequencerestartbad']); |
||
| 597 | } |
||
| 598 | } |
||
| 599 | |||
| 600 | /** |
||
| 601 | * Resets a sequence |
||
| 602 | */ |
||
| 603 | public function doReset() |
||
| 604 | { |
||
| 605 | $conf = $this->conf; |
||
| 606 | |||
| 607 | $lang = $this->lang; |
||
| 608 | $data = $this->misc->getDatabaseAccessor(); |
||
| 609 | |||
| 610 | $status = $data->resetSequence($_REQUEST['sequence']); |
||
| 611 | if (0 == $status) { |
||
| 612 | $this->doProperties($lang['strsequencereset']); |
||
| 613 | } else { |
||
| 614 | $this->doProperties($lang['strsequenceresetbad']); |
||
| 615 | } |
||
| 616 | } |
||
| 617 | |||
| 618 | /** |
||
| 619 | * Set Nextval of a sequence |
||
| 620 | */ |
||
| 621 | public function doNextval() |
||
| 622 | { |
||
| 623 | $conf = $this->conf; |
||
| 624 | |||
| 625 | $lang = $this->lang; |
||
| 626 | $data = $this->misc->getDatabaseAccessor(); |
||
| 627 | |||
| 628 | $status = $data->nextvalSequence($_REQUEST['sequence']); |
||
| 629 | if (0 == $status) { |
||
| 630 | $this->doProperties($lang['strsequencenextval']); |
||
| 631 | } else { |
||
| 632 | $this->doProperties($lang['strsequencenextvalbad']); |
||
| 633 | } |
||
| 634 | } |
||
| 635 | |||
| 636 | /** |
||
| 637 | * Function to save after 'setval'ing a sequence |
||
| 638 | */ |
||
| 639 | public function doSaveSetval() |
||
| 640 | { |
||
| 641 | $conf = $this->conf; |
||
| 642 | |||
| 643 | $lang = $this->lang; |
||
| 644 | $data = $this->misc->getDatabaseAccessor(); |
||
| 645 | |||
| 646 | $status = $data->setvalSequence($_POST['sequence'], $_POST['nextvalue']); |
||
| 647 | if (0 == $status) { |
||
| 648 | $this->doProperties($lang['strsequencesetval']); |
||
| 649 | } else { |
||
| 650 | $this->doProperties($lang['strsequencesetvalbad']); |
||
| 651 | } |
||
| 652 | } |
||
| 653 | |||
| 654 | /** |
||
| 655 | * Function to allow 'setval'ing of a sequence |
||
| 656 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 657 | */ |
||
| 658 | public function doSetval($msg = '') |
||
| 659 | { |
||
| 660 | $conf = $this->conf; |
||
| 661 | |||
| 662 | $lang = $this->lang; |
||
| 663 | $data = $this->misc->getDatabaseAccessor(); |
||
| 664 | |||
| 665 | $this->printTrail('sequence'); |
||
| 666 | $this->printTitle($lang['strsetval'], 'pg.sequence'); |
||
| 667 | $this->printMsg($msg); |
||
| 668 | |||
| 669 | // Fetch the sequence information |
||
| 670 | $sequence = $data->getSequence($_REQUEST['sequence']); |
||
| 671 | |||
| 672 | if (is_object($sequence) && $sequence->recordCount() > 0) { |
||
| 673 | echo '<form action="' . SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n"; |
||
| 674 | echo '<table border="0">'; |
||
| 675 | echo "<tr><th class=\"data left required\">{$lang['strlastvalue']}</th>\n"; |
||
| 676 | echo '<td class="data1">'; |
||
| 677 | echo "<input name=\"nextvalue\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 678 | $this->misc->printVal($sequence->fields['last_value']), "\" /></td></tr>\n"; |
||
| 679 | echo "</table>\n"; |
||
| 680 | echo "<p><input type=\"hidden\" name=\"action\" value=\"setval\" />\n"; |
||
| 681 | echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n"; |
||
| 682 | echo $this->misc->form; |
||
| 683 | echo "<input type=\"submit\" name=\"setval\" value=\"{$lang['strsetval']}\" />\n"; |
||
| 684 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 685 | echo "</form>\n"; |
||
| 686 | } else { |
||
| 687 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
| 688 | } |
||
| 689 | } |
||
| 690 | |||
| 691 | /** |
||
| 692 | * Function to save after altering a sequence |
||
| 693 | */ |
||
| 694 | public function doSaveAlter() |
||
| 767 | } |
||
| 768 | } |
||
| 769 | |||
| 770 | /** |
||
| 771 | * Function to allow altering of a sequence |
||
| 772 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 773 | */ |
||
| 774 | public function doAlter($msg = '') |
||
| 891 | } |
||
| 892 | } |
||
| 893 | } |
||
| 894 |