Total Complexity | 167 |
Total Lines | 1252 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like TablesController 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 TablesController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class TablesController extends BaseController |
||
17 | { |
||
18 | use \PHPPgAdmin\Traits\AdminTrait; |
||
19 | public $table_place = 'tables-tables'; |
||
20 | public $controller_title = 'strtables'; |
||
21 | /** |
||
22 | * Default method to render the controller according to the action parameter. |
||
23 | */ |
||
24 | public function render() |
||
25 | { |
||
26 | if ('tree' == $this->action) { |
||
27 | return $this->doTree(); |
||
28 | } |
||
29 | if ('subtree' == $this->action) { |
||
30 | return $this->doSubTree(); |
||
31 | } |
||
32 | if ('json' == $this->action) { |
||
33 | return $this->displayJson(); |
||
34 | } |
||
35 | |||
36 | $header_template = 'header.twig'; |
||
37 | $footer_template = 'footer.twig'; |
||
|
|||
38 | |||
39 | ob_start(); |
||
40 | |||
41 | switch ($this->action) { |
||
42 | case 'create': |
||
43 | |||
44 | if (isset($_POST['cancel'])) { |
||
45 | $this->doDefault(); |
||
46 | } else { |
||
47 | $header_template = 'header_select2.twig'; |
||
48 | $this->doCreate(); |
||
49 | } |
||
50 | |||
51 | break; |
||
52 | case 'createlike': |
||
53 | $header_template = 'header_select2.twig'; |
||
54 | $this->doCreateLike(false); |
||
55 | |||
56 | break; |
||
57 | case 'confcreatelike': |
||
58 | if (isset($_POST['cancel'])) { |
||
59 | $header_template = 'header_datatables.twig'; |
||
60 | $this->doDefault(); |
||
61 | } else { |
||
62 | //$header_template = 'header_select2.twig'; |
||
63 | $this->doCreateLike(true); |
||
64 | } |
||
65 | |||
66 | break; |
||
67 | case 'selectrows': |
||
68 | if (!isset($_POST['cancel'])) { |
||
69 | $this->doSelectRows(false); |
||
70 | } else { |
||
71 | $header_template = 'header_datatables.twig'; |
||
72 | $this->doDefault(); |
||
73 | } |
||
74 | |||
75 | break; |
||
76 | case 'confselectrows': |
||
77 | $this->doSelectRows(true); |
||
78 | |||
79 | break; |
||
80 | case 'insertrow': |
||
81 | if (!isset($_POST['cancel'])) { |
||
82 | $this->doInsertRow(false); |
||
83 | } else { |
||
84 | $header_template = 'header_datatables.twig'; |
||
85 | $this->doDefault(); |
||
86 | } |
||
87 | |||
88 | break; |
||
89 | case 'confinsertrow': |
||
90 | $this->doInsertRow(true); |
||
91 | |||
92 | break; |
||
93 | case 'empty': |
||
94 | if (isset($_POST['empty'])) { |
||
95 | $this->doEmpty(false); |
||
96 | } else { |
||
97 | $header_template = 'header_datatables.twig'; |
||
98 | $this->doDefault(); |
||
99 | } |
||
100 | |||
101 | break; |
||
102 | case 'confirm_empty': |
||
103 | $this->doEmpty(true); |
||
104 | |||
105 | break; |
||
106 | case 'drop': |
||
107 | if (isset($_POST['drop'])) { |
||
108 | $this->doDrop(false); |
||
109 | } else { |
||
110 | $header_template = 'header_datatables.twig'; |
||
111 | $this->doDefault(); |
||
112 | } |
||
113 | |||
114 | break; |
||
115 | case 'confirm_drop': |
||
116 | $this->doDrop(true); |
||
117 | |||
118 | break; |
||
119 | default: |
||
120 | if (false === $this->adminActions($this->action, 'table')) { |
||
121 | $header_template = 'header_datatables.twig'; |
||
122 | $this->doDefault(); |
||
123 | } |
||
124 | |||
125 | break; |
||
126 | } |
||
127 | |||
128 | $output = ob_get_clean(); |
||
129 | |||
130 | $this->printHeader($this->headerTitle(), null, true, $header_template); |
||
131 | $this->printBody(); |
||
132 | |||
133 | echo $output; |
||
134 | |||
135 | return $this->printFooter(); |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Show default list of tables in the database. |
||
140 | * |
||
141 | * @param mixed $msg |
||
142 | */ |
||
143 | public function doDefault($msg = '') |
||
144 | { |
||
145 | $data = $this->misc->getDatabaseAccessor(); |
||
146 | |||
147 | $this->printTrail('schema'); |
||
148 | $this->printTabs('schema', 'tables'); |
||
149 | $this->printMsg($msg); |
||
150 | |||
151 | $tables = $data->getTables(); |
||
152 | |||
153 | $columns = [ |
||
154 | 'table' => [ |
||
155 | 'title' => $this->lang['strtable'], |
||
156 | 'field' => Decorator::field('relname'), |
||
157 | 'url' => \SUBFOLDER . "/redirect/table?{$this->misc->href}&", |
||
158 | 'vars' => ['table' => 'relname'], |
||
159 | ], |
||
160 | 'owner' => [ |
||
161 | 'title' => $this->lang['strowner'], |
||
162 | 'field' => Decorator::field('relowner'), |
||
163 | ], |
||
164 | 'tablespace' => [ |
||
165 | 'title' => $this->lang['strtablespace'], |
||
166 | 'field' => Decorator::field('tablespace'), |
||
167 | ], |
||
168 | 'tuples' => [ |
||
169 | 'title' => $this->lang['strestimatedrowcount'], |
||
170 | 'field' => Decorator::field('reltuples'), |
||
171 | 'type' => 'numeric', |
||
172 | ], |
||
173 | 'table_size' => [ |
||
174 | 'title' => $this->lang['strsize'], |
||
175 | 'field' => Decorator::field('table_size'), |
||
176 | ], |
||
177 | 'actions' => [ |
||
178 | 'title' => $this->lang['stractions'], |
||
179 | ], |
||
180 | 'comment' => [ |
||
181 | 'title' => $this->lang['strcomment'], |
||
182 | 'field' => Decorator::field('relcomment'), |
||
183 | ], |
||
184 | ]; |
||
185 | |||
186 | $actions = [ |
||
187 | 'multiactions' => [ |
||
188 | 'keycols' => ['table' => 'relname'], |
||
189 | 'url' => 'tables', |
||
190 | 'default' => 'analyze', |
||
191 | ], |
||
192 | 'browse' => [ |
||
193 | 'content' => $this->lang['strbrowse'], |
||
194 | 'attr' => [ |
||
195 | 'href' => [ |
||
196 | 'url' => 'display', |
||
197 | 'urlvars' => [ |
||
198 | 'subject' => 'table', |
||
199 | 'return' => 'table', |
||
200 | 'table' => Decorator::field('relname'), |
||
201 | ], |
||
202 | ], |
||
203 | ], |
||
204 | ], |
||
205 | 'select' => [ |
||
206 | 'content' => $this->lang['strselect'], |
||
207 | 'attr' => [ |
||
208 | 'href' => [ |
||
209 | 'url' => 'tables', |
||
210 | 'urlvars' => [ |
||
211 | 'action' => 'confselectrows', |
||
212 | 'table' => Decorator::field('relname'), |
||
213 | ], |
||
214 | ], |
||
215 | ], |
||
216 | ], |
||
217 | 'insert' => [ |
||
218 | 'content' => $this->lang['strinsert'], |
||
219 | 'attr' => [ |
||
220 | 'href' => [ |
||
221 | 'url' => 'tables', |
||
222 | 'urlvars' => [ |
||
223 | 'action' => 'confinsertrow', |
||
224 | 'table' => Decorator::field('relname'), |
||
225 | ], |
||
226 | ], |
||
227 | ], |
||
228 | ], |
||
229 | 'empty' => [ |
||
230 | 'multiaction' => 'confirm_empty', |
||
231 | 'content' => $this->lang['strempty'], |
||
232 | 'attr' => [ |
||
233 | 'href' => [ |
||
234 | 'url' => 'tables', |
||
235 | 'urlvars' => [ |
||
236 | 'action' => 'confirm_empty', |
||
237 | 'table' => Decorator::field('relname'), |
||
238 | ], |
||
239 | ], |
||
240 | ], |
||
241 | ], |
||
242 | 'alter' => [ |
||
243 | 'content' => $this->lang['stralter'], |
||
244 | 'attr' => [ |
||
245 | 'href' => [ |
||
246 | 'url' => 'tblproperties', |
||
247 | 'urlvars' => [ |
||
248 | 'action' => 'confirm_alter', |
||
249 | 'table' => Decorator::field('relname'), |
||
250 | ], |
||
251 | ], |
||
252 | ], |
||
253 | ], |
||
254 | 'drop' => [ |
||
255 | 'multiaction' => 'confirm_drop', |
||
256 | 'content' => $this->lang['strdrop'], |
||
257 | 'attr' => [ |
||
258 | 'href' => [ |
||
259 | 'url' => 'tables', |
||
260 | 'urlvars' => [ |
||
261 | 'action' => 'confirm_drop', |
||
262 | 'table' => Decorator::field('relname'), |
||
263 | ], |
||
264 | ], |
||
265 | ], |
||
266 | ], |
||
267 | 'vacuum' => [ |
||
268 | 'multiaction' => 'confirm_vacuum', |
||
269 | 'content' => $this->lang['strvacuum'], |
||
270 | 'attr' => [ |
||
271 | 'href' => [ |
||
272 | 'url' => 'tables', |
||
273 | 'urlvars' => [ |
||
274 | 'action' => 'confirm_vacuum', |
||
275 | 'table' => Decorator::field('relname'), |
||
276 | ], |
||
277 | ], |
||
278 | ], |
||
279 | ], |
||
280 | 'analyze' => [ |
||
281 | 'multiaction' => 'confirm_analyze', |
||
282 | 'content' => $this->lang['stranalyze'], |
||
283 | 'attr' => [ |
||
284 | 'href' => [ |
||
285 | 'url' => 'tables', |
||
286 | 'urlvars' => [ |
||
287 | 'action' => 'confirm_analyze', |
||
288 | 'table' => Decorator::field('relname'), |
||
289 | ], |
||
290 | ], |
||
291 | ], |
||
292 | ], |
||
293 | 'reindex' => [ |
||
294 | 'multiaction' => 'confirm_reindex', |
||
295 | 'content' => $this->lang['strreindex'], |
||
296 | 'attr' => [ |
||
297 | 'href' => [ |
||
298 | 'url' => 'tables', |
||
299 | 'urlvars' => [ |
||
300 | 'action' => 'confirm_reindex', |
||
301 | 'table' => Decorator::field('relname'), |
||
302 | ], |
||
303 | ], |
||
304 | ], |
||
305 | ], |
||
306 | //'cluster' TODO ? |
||
307 | ]; |
||
308 | |||
309 | if (!$data->hasTablespaces()) { |
||
310 | unset($columns['tablespace']); |
||
311 | } |
||
312 | |||
313 | //\Kint::dump($tables); |
||
314 | |||
315 | echo $this->printTable($tables, $columns, $actions, $this->table_place, $this->lang['strnotables']); |
||
316 | |||
317 | $navlinks = [ |
||
318 | 'create' => [ |
||
319 | 'attr' => [ |
||
320 | 'href' => [ |
||
321 | 'url' => 'tables', |
||
322 | 'urlvars' => [ |
||
323 | 'action' => 'create', |
||
324 | 'server' => $_REQUEST['server'], |
||
325 | 'database' => $_REQUEST['database'], |
||
326 | 'schema' => $_REQUEST['schema'], |
||
327 | ], |
||
328 | ], |
||
329 | ], |
||
330 | 'content' => $this->lang['strcreatetable'], |
||
331 | ], |
||
332 | ]; |
||
333 | |||
334 | if (($tables->recordCount() > 0) && $data->hasCreateTableLike()) { |
||
335 | $navlinks['createlike'] = [ |
||
336 | 'attr' => [ |
||
337 | 'href' => [ |
||
338 | 'url' => 'tables', |
||
339 | 'urlvars' => [ |
||
340 | 'action' => 'createlike', |
||
341 | 'server' => $_REQUEST['server'], |
||
342 | 'database' => $_REQUEST['database'], |
||
343 | 'schema' => $_REQUEST['schema'], |
||
344 | ], |
||
345 | ], |
||
346 | ], |
||
347 | 'content' => $this->lang['strcreatetablelike'], |
||
348 | ]; |
||
349 | } |
||
350 | $this->printNavLinks($navlinks, 'tables-tables', get_defined_vars()); |
||
351 | } |
||
352 | |||
353 | public function displayJson() |
||
354 | { |
||
355 | $data = $this->misc->getDatabaseAccessor(); |
||
356 | |||
357 | $tables = $data->getTables(); |
||
358 | |||
359 | $all_tables = $tables->getAll(); |
||
360 | |||
361 | return $this |
||
362 | ->container |
||
363 | ->responseobj |
||
364 | ->withStatus(200) |
||
365 | ->withJson($all_tables); |
||
366 | } |
||
367 | |||
368 | /** |
||
369 | * Generate XML for the browser tree. |
||
370 | */ |
||
371 | public function doTree() |
||
372 | { |
||
373 | $data = $this->misc->getDatabaseAccessor(); |
||
374 | |||
375 | //\PC::debug($this->misc->getDatabase(), 'getDatabase'); |
||
376 | |||
377 | $tables = $data->getTables(); |
||
378 | |||
379 | $reqvars = $this->misc->getRequestVars('table'); |
||
380 | |||
381 | $attrs = [ |
||
382 | 'text' => Decorator::field('relname'), |
||
383 | 'icon' => 'Table', |
||
384 | 'iconAction' => Decorator::url('display', $reqvars, ['table' => Decorator::field('relname')]), |
||
385 | 'toolTip' => Decorator::field('relcomment'), |
||
386 | 'action' => Decorator::redirecturl('redirect', $reqvars, ['table' => Decorator::field('relname')]), |
||
387 | 'branch' => Decorator::url('tables', $reqvars, ['action' => 'subtree', 'table' => Decorator::field('relname')]), |
||
388 | ]; |
||
389 | |||
390 | return $this->printTree($tables, $attrs, 'tables'); |
||
391 | } |
||
392 | |||
393 | public function doSubTree() |
||
425 | } |
||
426 | |||
427 | /** |
||
428 | * Displays a screen where they can enter a new table. |
||
429 | * |
||
430 | * @param mixed $msg |
||
431 | */ |
||
432 | public function doCreate($msg = '') |
||
433 | { |
||
434 | $data = $this->misc->getDatabaseAccessor(); |
||
435 | |||
436 | if (!isset($_REQUEST['stage'])) { |
||
437 | $_REQUEST['stage'] = 1; |
||
438 | $default_with_oids = $data->getDefaultWithOid(); |
||
439 | if ('off' == $default_with_oids) { |
||
440 | $_REQUEST['withoutoids'] = 'on'; |
||
441 | } |
||
442 | } |
||
443 | |||
444 | if (!isset($_REQUEST['name'])) { |
||
445 | $_REQUEST['name'] = ''; |
||
446 | } |
||
447 | |||
448 | if (!isset($_REQUEST['fields'])) { |
||
449 | $_REQUEST['fields'] = ''; |
||
450 | } |
||
451 | |||
452 | if (!isset($_REQUEST['tblcomment'])) { |
||
453 | $_REQUEST['tblcomment'] = ''; |
||
454 | } |
||
455 | |||
456 | if (!isset($_REQUEST['spcname'])) { |
||
457 | $_REQUEST['spcname'] = ''; |
||
458 | } |
||
459 | |||
460 | switch ($_REQUEST['stage']) { |
||
461 | case 1: |
||
462 | // You are presented with a form in which you describe the table, pick the tablespace and state how many fields it will have |
||
463 | // Fetch all tablespaces from the database |
||
464 | if ($data->hasTablespaces()) { |
||
465 | $tablespaces = $data->getTablespaces(); |
||
466 | } |
||
467 | |||
468 | $this->printTrail('schema'); |
||
469 | $this->printTitle($this->lang['strcreatetable'], 'pg.table.create'); |
||
470 | $this->printMsg($msg); |
||
471 | |||
472 | echo '<form action="' . \SUBFOLDER . '/src/views/' . $this->script . '" method="post">'; |
||
473 | echo "\n"; |
||
474 | echo "<table>\n"; |
||
475 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strname']}</th>\n"; |
||
476 | echo "\t\t<td class=\"data\"><input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
477 | htmlspecialchars($_REQUEST['name']), "\" /></td>\n\t</tr>\n"; |
||
478 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strnumcols']}</th>\n"; |
||
479 | echo "\t\t<td class=\"data\"><input name=\"fields\" size=\"5\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
480 | htmlspecialchars($_REQUEST['fields']), "\" /></td>\n\t</tr>\n"; |
||
481 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['stroptions']}</th>\n"; |
||
482 | echo "\t\t<td class=\"data\"><label for=\"withoutoids\"><input type=\"checkbox\" id=\"withoutoids\" name=\"withoutoids\"", isset($_REQUEST['withoutoids']) ? ' checked="checked"' : '', " />WITHOUT OIDS</label></td>\n\t</tr>\n"; |
||
483 | |||
484 | // Tablespace (if there are any) |
||
485 | if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) { |
||
486 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strtablespace']}</th>\n"; |
||
487 | echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"spcname\">\n"; |
||
488 | // Always offer the default (empty) option |
||
489 | echo "\t\t\t\t<option value=\"\"", |
||
490 | ('' == $_REQUEST['spcname']) ? ' selected="selected"' : '', "></option>\n"; |
||
491 | // Display all other tablespaces |
||
492 | while (!$tablespaces->EOF) { |
||
493 | $spcname = htmlspecialchars($tablespaces->fields['spcname']); |
||
494 | echo "\t\t\t\t<option value=\"{$spcname}\"", |
||
495 | ($tablespaces->fields['spcname'] == $_REQUEST['spcname']) ? ' selected="selected"' : '', ">{$spcname}</option>\n"; |
||
496 | $tablespaces->moveNext(); |
||
497 | } |
||
498 | echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n"; |
||
499 | } |
||
500 | |||
501 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strcomment']}</th>\n"; |
||
502 | echo "\t\t<td><textarea name=\"tblcomment\" rows=\"3\" cols=\"32\">", |
||
503 | htmlspecialchars($_REQUEST['tblcomment']), "</textarea></td>\n\t</tr>\n"; |
||
504 | |||
505 | echo "</table>\n"; |
||
506 | echo "<p><input type=\"hidden\" name=\"action\" value=\"create\" />\n"; |
||
507 | echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n"; |
||
508 | echo $this->misc->form; |
||
509 | echo "<input type=\"submit\" value=\"{$this->lang['strnext']}\" />\n"; |
||
510 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
511 | echo "</form>\n"; |
||
512 | |||
513 | break; |
||
514 | case 2: |
||
515 | |||
516 | // Check inputs |
||
517 | $fields = trim($_REQUEST['fields']); |
||
518 | if ('' == trim($_REQUEST['name'])) { |
||
519 | $_REQUEST['stage'] = 1; |
||
520 | $this->doCreate($this->lang['strtableneedsname']); |
||
521 | |||
522 | return; |
||
523 | } |
||
524 | if ('' == $fields || !is_numeric($fields) || $fields != (int) $fields || $fields < 1) { |
||
525 | $_REQUEST['stage'] = 1; |
||
526 | $this->doCreate($this->lang['strtableneedscols']); |
||
527 | |||
528 | return; |
||
529 | } |
||
530 | |||
531 | $types = $data->getTypes(true, false, true); |
||
532 | $types_for_js = []; |
||
533 | |||
534 | $this->printTrail('schema'); |
||
535 | $this->printTitle($this->lang['strcreatetable'], 'pg.table.create'); |
||
536 | $this->printMsg($msg); |
||
537 | |||
538 | echo '<script src="' . \SUBFOLDER . '/assets/js/tables.js" type="text/javascript"></script>'; |
||
539 | echo '<form action="' . \SUBFOLDER . "/src/views/tables\" method=\"post\">\n"; |
||
540 | |||
541 | // Output table header |
||
542 | echo "<table>\n"; |
||
543 | echo "\t<tr><th colspan=\"2\" class=\"data required\">{$this->lang['strcolumn']}</th><th colspan=\"2\" class=\"data required\">{$this->lang['strtype']}</th>"; |
||
544 | echo "<th class=\"data\">{$this->lang['strlength']}</th><th class=\"data\">{$this->lang['strnotnull']}</th>"; |
||
545 | echo "<th class=\"data\">{$this->lang['struniquekey']}</th><th class=\"data\">{$this->lang['strprimarykey']}</th>"; |
||
546 | echo "<th class=\"data\">{$this->lang['strdefault']}</th><th class=\"data\">{$this->lang['strcomment']}</th></tr>\n"; |
||
547 | |||
548 | for ($i = 0; $i < $_REQUEST['fields']; ++$i) { |
||
549 | if (!isset($_REQUEST['field'][$i])) { |
||
550 | $_REQUEST['field'][$i] = ''; |
||
551 | } |
||
552 | |||
553 | if (!isset($_REQUEST['length'][$i])) { |
||
554 | $_REQUEST['length'][$i] = ''; |
||
555 | } |
||
556 | |||
557 | if (!isset($_REQUEST['default'][$i])) { |
||
558 | $_REQUEST['default'][$i] = ''; |
||
559 | } |
||
560 | |||
561 | if (!isset($_REQUEST['colcomment'][$i])) { |
||
562 | $_REQUEST['colcomment'][$i] = ''; |
||
563 | } |
||
564 | |||
565 | echo "\t<tr>\n\t\t<td>", $i + 1, ". </td>\n"; |
||
566 | echo "\t\t<td><input name=\"field[{$i}]\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
567 | htmlspecialchars($_REQUEST['field'][$i]), "\" /></td>\n"; |
||
568 | echo "\t\t<td>\n\t\t\t<select name=\"type[{$i}]\" class=\"select2\" id=\"types{$i}\" onchange=\"checkLengths(this.options[this.selectedIndex].value,{$i});\">\n"; |
||
569 | // Output any "magic" types |
||
570 | foreach ($data->extraTypes as $v) { |
||
571 | $types_for_js[strtolower($v)] = 1; |
||
572 | echo "\t\t\t\t<option value=\"", htmlspecialchars($v), '"', |
||
573 | (isset($_REQUEST['type'][$i]) && $_REQUEST['type'][$i] == $v) ? ' selected="selected"' : '', '>', |
||
574 | $this->misc->printVal($v), "</option>\n"; |
||
575 | } |
||
576 | $types->moveFirst(); |
||
577 | while (!$types->EOF) { |
||
578 | $typname = $types->fields['typname']; |
||
579 | $types_for_js[$typname] = 1; |
||
580 | echo "\t\t\t\t<option value=\"", htmlspecialchars($typname), '"', |
||
581 | (isset($_REQUEST['type'][$i]) && $_REQUEST['type'][$i] == $typname) ? ' selected="selected"' : '', '>', |
||
582 | $this->misc->printVal($typname), "</option>\n"; |
||
583 | $types->moveNext(); |
||
584 | } |
||
585 | echo "\t\t\t</select>\n\t\t\n"; |
||
586 | if (0 == $i) { |
||
587 | // only define js types array once |
||
588 | $predefined_size_types = array_intersect($data->predefined_size_types, array_keys($types_for_js)); |
||
589 | $escaped_predef_types = []; // the JS escaped array elements |
||
590 | foreach ($predefined_size_types as $value) { |
||
591 | $escaped_predef_types[] = "'{$value}'"; |
||
592 | } |
||
593 | echo '<script type="text/javascript">predefined_lengths = new Array(' . implode(',', $escaped_predef_types) . ");</script>\n\t</td>"; |
||
594 | } |
||
595 | |||
596 | // Output array type selector |
||
597 | echo "\t\t<td>\n\t\t\t<select name=\"array[{$i}]\">\n"; |
||
598 | echo "\t\t\t\t<option value=\"\"", (isset($_REQUEST['array'][$i]) && $_REQUEST['array'][$i] == '') ? ' selected="selected"' : '', "></option>\n"; |
||
599 | echo "\t\t\t\t<option value=\"[]\"", (isset($_REQUEST['array'][$i]) && $_REQUEST['array'][$i] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n"; |
||
600 | echo "\t\t\t</select>\n\t\t</td>\n"; |
||
601 | |||
602 | echo "\t\t<td><input name=\"length[{$i}]\" id=\"lengths{$i}\" size=\"10\" value=\"", |
||
603 | htmlspecialchars($_REQUEST['length'][$i]), "\" /></td>\n"; |
||
604 | echo "\t\t<td><input type=\"checkbox\" name=\"notnull[{$i}]\"", (isset($_REQUEST['notnull'][$i])) ? ' checked="checked"' : '', " /></td>\n"; |
||
605 | echo "\t\t<td style=\"text-align: center\"><input type=\"checkbox\" name=\"uniquekey[{$i}]\"" |
||
606 | . (isset($_REQUEST['uniquekey'][$i]) ? ' checked="checked"' : '') . " /></td>\n"; |
||
607 | echo "\t\t<td style=\"text-align: center\"><input type=\"checkbox\" name=\"primarykey[{$i}]\" " |
||
608 | . (isset($_REQUEST['primarykey'][$i]) ? ' checked="checked"' : '') |
||
609 | . " /></td>\n"; |
||
610 | echo "\t\t<td><input name=\"default[{$i}]\" size=\"20\" value=\"", |
||
611 | htmlspecialchars($_REQUEST['default'][$i]), "\" /></td>\n"; |
||
612 | echo "\t\t<td><input name=\"colcomment[{$i}]\" size=\"40\" value=\"", |
||
613 | htmlspecialchars($_REQUEST['colcomment'][$i]), "\" /> |
||
614 | <script type=\"text/javascript\">checkLengths(document.getElementById('types{$i}').value,{$i});</script> |
||
615 | </td>\n\t</tr>\n"; |
||
616 | } |
||
617 | echo "</table>\n"; |
||
618 | echo "<p><input type=\"hidden\" name=\"action\" value=\"create\" />\n"; |
||
619 | echo "<input type=\"hidden\" name=\"stage\" value=\"3\" />\n"; |
||
620 | echo $this->misc->form; |
||
621 | echo '<input type="hidden" name="name" value="', htmlspecialchars($_REQUEST['name']), "\" />\n"; |
||
622 | echo '<input type="hidden" name="fields" value="', htmlspecialchars($_REQUEST['fields']), "\" />\n"; |
||
623 | if (isset($_REQUEST['withoutoids'])) { |
||
624 | echo "<input type=\"hidden\" name=\"withoutoids\" value=\"true\" />\n"; |
||
625 | } |
||
626 | echo '<input type="hidden" name="tblcomment" value="', htmlspecialchars($_REQUEST['tblcomment']), "\" />\n"; |
||
627 | if (isset($_REQUEST['spcname'])) { |
||
628 | echo '<input type="hidden" name="spcname" value="', htmlspecialchars($_REQUEST['spcname']), "\" />\n"; |
||
629 | } |
||
630 | echo "<input type=\"submit\" value=\"{$this->lang['strcreate']}\" />\n"; |
||
631 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
632 | echo "</form>\n"; |
||
633 | |||
634 | break; |
||
635 | case 3: |
||
636 | |||
637 | if (!isset($_REQUEST['notnull'])) { |
||
638 | $_REQUEST['notnull'] = []; |
||
639 | } |
||
640 | |||
641 | if (!isset($_REQUEST['uniquekey'])) { |
||
642 | $_REQUEST['uniquekey'] = []; |
||
643 | } |
||
644 | |||
645 | if (!isset($_REQUEST['primarykey'])) { |
||
646 | $_REQUEST['primarykey'] = []; |
||
647 | } |
||
648 | |||
649 | if (!isset($_REQUEST['length'])) { |
||
650 | $_REQUEST['length'] = []; |
||
651 | } |
||
652 | |||
653 | // Default tablespace to null if it isn't set |
||
654 | if (!isset($_REQUEST['spcname'])) { |
||
655 | $_REQUEST['spcname'] = null; |
||
656 | } |
||
657 | |||
658 | // Check inputs |
||
659 | $fields = trim($_REQUEST['fields']); |
||
660 | if ('' == trim($_REQUEST['name'])) { |
||
661 | $_REQUEST['stage'] = 1; |
||
662 | $this->doCreate($this->lang['strtableneedsname']); |
||
663 | |||
664 | return; |
||
665 | } |
||
666 | if ('' == $fields || !is_numeric($fields) || $fields != (int) $fields || $fields <= 0) { |
||
667 | $_REQUEST['stage'] = 1; |
||
668 | $this->doCreate($this->lang['strtableneedscols']); |
||
669 | |||
670 | return; |
||
671 | } |
||
672 | |||
673 | $status = $data->createTable( |
||
674 | $_REQUEST['name'], |
||
675 | $_REQUEST['fields'], |
||
676 | $_REQUEST['field'], |
||
677 | $_REQUEST['type'], |
||
678 | $_REQUEST['array'], |
||
679 | $_REQUEST['length'], |
||
680 | $_REQUEST['notnull'], |
||
681 | $_REQUEST['default'], |
||
682 | isset($_REQUEST['withoutoids']), |
||
683 | $_REQUEST['colcomment'], |
||
684 | $_REQUEST['tblcomment'], |
||
685 | $_REQUEST['spcname'], |
||
686 | $_REQUEST['uniquekey'], |
||
687 | $_REQUEST['primarykey'] |
||
688 | ); |
||
689 | |||
690 | if (0 == $status) { |
||
691 | $this->misc->setReloadBrowser(true); |
||
692 | |||
693 | return $this->doDefault($this->lang['strtablecreated']); |
||
694 | } |
||
695 | if ($status == -1) { |
||
696 | $_REQUEST['stage'] = 2; |
||
697 | $this->doCreate($this->lang['strtableneedsfield']); |
||
698 | |||
699 | return; |
||
700 | } |
||
701 | $_REQUEST['stage'] = 2; |
||
702 | $this->doCreate($this->lang['strtablecreatedbad']); |
||
703 | |||
704 | return; |
||
705 | break; |
||
706 | default: |
||
707 | echo "<p>{$this->lang['strinvalidparam']}</p>\n"; |
||
708 | } |
||
709 | } |
||
710 | |||
711 | /** |
||
712 | * Dsiplay a screen where user can create a table from an existing one. |
||
713 | * We don't have to check if pg supports schema cause create table like |
||
714 | * is available under pg 7.4+ which has schema. |
||
715 | * |
||
716 | * @param mixed $confirm |
||
717 | * @param mixed $msg |
||
718 | */ |
||
719 | public function doCreateLike($confirm, $msg = '') |
||
720 | { |
||
721 | $data = $this->misc->getDatabaseAccessor(); |
||
722 | |||
723 | if (!$confirm) { |
||
724 | if (!isset($_REQUEST['name'])) { |
||
725 | $_REQUEST['name'] = ''; |
||
726 | } |
||
727 | |||
728 | if (!isset($_REQUEST['like'])) { |
||
729 | $_REQUEST['like'] = ''; |
||
730 | } |
||
731 | |||
732 | if (!isset($_REQUEST['tablespace'])) { |
||
733 | $_REQUEST['tablespace'] = ''; |
||
734 | } |
||
735 | |||
736 | $this->printTrail('schema'); |
||
737 | $this->printTitle($this->lang['strcreatetable'], 'pg.table.create'); |
||
738 | $this->printMsg($msg); |
||
739 | |||
740 | $tbltmp = $data->getTables(true); |
||
741 | $tbltmp = $tbltmp->getArray(); |
||
742 | |||
743 | $tables = []; |
||
744 | $tblsel = ''; |
||
745 | foreach ($tbltmp as $a) { |
||
746 | $data->fieldClean($a['nspname']); |
||
747 | $data->fieldClean($a['relname']); |
||
748 | $tables["\"{$a['nspname']}\".\"{$a['relname']}\""] = serialize(['schema' => $a['nspname'], 'table' => $a['relname']]); |
||
749 | if ($_REQUEST['like'] == $tables["\"{$a['nspname']}\".\"{$a['relname']}\""]) { |
||
750 | $tblsel = htmlspecialchars($tables["\"{$a['nspname']}\".\"{$a['relname']}\""]); |
||
751 | } |
||
752 | } |
||
753 | |||
754 | unset($tbltmp); |
||
755 | |||
756 | echo '<form action="' . \SUBFOLDER . "/src/views/tables\" method=\"post\">\n"; |
||
757 | echo "<table>\n\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strname']}</th>\n"; |
||
758 | echo "\t\t<td class=\"data\"><input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_REQUEST['name']), "\" /></td>\n\t</tr>\n"; |
||
759 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strcreatetablelikeparent']}</th>\n"; |
||
760 | echo "\t\t<td class=\"data\">"; |
||
761 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($tables, 'like', true, $tblsel, false); |
||
762 | echo "</td>\n\t</tr>\n"; |
||
763 | if ($data->hasTablespaces()) { |
||
764 | $tblsp_ = $data->getTablespaces(); |
||
765 | if ($tblsp_->recordCount() > 0) { |
||
766 | $tblsp_ = $tblsp_->getArray(); |
||
767 | $tblsp = []; |
||
768 | foreach ($tblsp_ as $a) { |
||
769 | $tblsp[$a['spcname']] = $a['spcname']; |
||
770 | } |
||
771 | |||
772 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strtablespace']}</th>\n"; |
||
773 | echo "\t\t<td class=\"data\">"; |
||
774 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($tblsp, 'tablespace', true, $_REQUEST['tablespace'], false); |
||
775 | echo "</td>\n\t</tr>\n"; |
||
776 | } |
||
777 | } |
||
778 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['stroptions']}</th>\n\t\t<td class=\"data\">"; |
||
779 | echo '<label for="withdefaults"><input type="checkbox" id="withdefaults" name="withdefaults"', |
||
780 | isset($_REQUEST['withdefaults']) ? ' checked="checked"' : '', |
||
781 | "/>{$this->lang['strcreatelikewithdefaults']}</label>"; |
||
782 | if ($data->hasCreateTableLikeWithConstraints()) { |
||
783 | echo '<br /><label for="withconstraints"><input type="checkbox" id="withconstraints" name="withconstraints"', |
||
784 | isset($_REQUEST['withconstraints']) ? ' checked="checked"' : '', |
||
785 | "/>{$this->lang['strcreatelikewithconstraints']}</label>"; |
||
786 | } |
||
787 | if ($data->hasCreateTableLikeWithIndexes()) { |
||
788 | echo '<br /><label for="withindexes"><input type="checkbox" id="withindexes" name="withindexes"', |
||
789 | isset($_REQUEST['withindexes']) ? ' checked="checked"' : '', |
||
790 | "/>{$this->lang['strcreatelikewithindexes']}</label>"; |
||
791 | } |
||
792 | echo "</td>\n\t</tr>\n"; |
||
793 | echo '</table>'; |
||
794 | |||
795 | echo "<input type=\"hidden\" name=\"action\" value=\"confcreatelike\" />\n"; |
||
796 | echo $this->misc->form; |
||
797 | echo "<p><input type=\"submit\" value=\"{$this->lang['strcreate']}\" />\n"; |
||
798 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
799 | echo "</form>\n"; |
||
800 | } else { |
||
801 | if ('' == trim($_REQUEST['name'])) { |
||
802 | $this->doCreateLike(false, $this->lang['strtableneedsname']); |
||
803 | |||
804 | return; |
||
805 | } |
||
806 | if ('' == trim($_REQUEST['like'])) { |
||
807 | $this->doCreateLike(false, $this->lang['strtablelikeneedslike']); |
||
808 | |||
809 | return; |
||
810 | } |
||
811 | |||
812 | if (!isset($_REQUEST['tablespace'])) { |
||
813 | $_REQUEST['tablespace'] = ''; |
||
814 | } |
||
815 | |||
816 | $status = $data->createTableLike( |
||
817 | $_REQUEST['name'], |
||
818 | unserialize($_REQUEST['like']), |
||
819 | isset($_REQUEST['withdefaults']), |
||
820 | isset($_REQUEST['withconstraints']), |
||
821 | isset($_REQUEST['withindexes']), |
||
822 | $_REQUEST['tablespace'] |
||
823 | ); |
||
824 | |||
825 | if (0 == $status) { |
||
826 | $this->misc->setReloadBrowser(true); |
||
827 | |||
828 | return $this->doDefault($this->lang['strtablecreated']); |
||
829 | } |
||
830 | $this->doCreateLike(false, $this->lang['strtablecreatedbad']); |
||
831 | |||
832 | return; |
||
833 | } |
||
834 | } |
||
835 | |||
836 | /** |
||
837 | * Ask for select parameters and perform select. |
||
838 | * |
||
839 | * @param mixed $confirm |
||
840 | * @param mixed $msg |
||
841 | */ |
||
842 | public function doSelectRows($confirm, $msg = '') |
||
843 | { |
||
844 | $data = $this->misc->getDatabaseAccessor(); |
||
845 | |||
846 | if ($confirm) { |
||
847 | $this->printTrail('table'); |
||
848 | $this->printTabs('table', 'select'); |
||
849 | $this->printMsg($msg); |
||
850 | |||
851 | $attrs = $data->getTableAttributes($_REQUEST['table']); |
||
852 | |||
853 | echo '<form action="' . \SUBFOLDER . "/src/views/tables\" method=\"post\" id=\"selectform\">\n"; |
||
854 | if ($attrs->recordCount() > 0) { |
||
855 | // JavaScript for select all feature |
||
856 | echo "<script type=\"text/javascript\">\n"; |
||
857 | echo "//<![CDATA[\n"; |
||
858 | echo " function selectAll() {\n"; |
||
859 | echo " for (var i=0; i<document.getElementById('selectform').elements.length; i++) {\n"; |
||
860 | echo " var e = document.getElementById('selectform').elements[i];\n"; |
||
861 | echo " if (e.name.indexOf('show') == 0) e.checked = document.getElementById('selectform').selectall.checked;\n"; |
||
862 | echo " }\n"; |
||
863 | echo " }\n"; |
||
864 | echo "//]]>\n"; |
||
865 | echo "</script>\n"; |
||
866 | |||
867 | echo "<table>\n"; |
||
868 | |||
869 | // Output table header |
||
870 | echo "<tr><th class=\"data\">{$this->lang['strshow']}</th><th class=\"data\">{$this->lang['strcolumn']}</th>"; |
||
871 | echo "<th class=\"data\">{$this->lang['strtype']}</th><th class=\"data\">{$this->lang['stroperator']}</th>"; |
||
872 | echo "<th class=\"data\">{$this->lang['strvalue']}</th></tr>"; |
||
873 | |||
874 | $i = 0; |
||
875 | while (!$attrs->EOF) { |
||
876 | $attrs->fields['attnotnull'] = $data->phpBool($attrs->fields['attnotnull']); |
||
877 | // Set up default value if there isn't one already |
||
878 | if (!isset($_REQUEST['values'][$attrs->fields['attname']])) { |
||
879 | $_REQUEST['values'][$attrs->fields['attname']] = null; |
||
880 | } |
||
881 | |||
882 | if (!isset($_REQUEST['ops'][$attrs->fields['attname']])) { |
||
883 | $_REQUEST['ops'][$attrs->fields['attname']] = null; |
||
884 | } |
||
885 | |||
886 | // Continue drawing row |
||
887 | $id = (0 == ($i % 2) ? '1' : '2'); |
||
888 | echo "<tr class=\"data{$id}\">\n"; |
||
889 | echo '<td style="white-space:nowrap;">'; |
||
890 | echo '<input type="checkbox" name="show[', htmlspecialchars($attrs->fields['attname']), ']"', |
||
891 | isset($_REQUEST['show'][$attrs->fields['attname']]) ? ' checked="checked"' : '', ' /></td>'; |
||
892 | echo '<td style="white-space:nowrap;">', $this->misc->printVal($attrs->fields['attname']), '</td>'; |
||
893 | echo '<td style="white-space:nowrap;">', $this->misc->printVal($data->formatType($attrs->fields['type'], $attrs->fields['atttypmod'])), '</td>'; |
||
894 | echo '<td style="white-space:nowrap;">'; |
||
895 | echo "<select name=\"ops[{$attrs->fields['attname']}]\">\n"; |
||
896 | foreach (array_keys($data->selectOps) as $v) { |
||
897 | echo '<option value="', htmlspecialchars($v), '"', ($_REQUEST['ops'][$attrs->fields['attname']] == $v) ? ' selected="selected"' : '', |
||
898 | '>', htmlspecialchars($v), "</option>\n"; |
||
899 | } |
||
900 | echo "</select>\n</td>\n"; |
||
901 | echo '<td style="white-space:nowrap;">', $data->printField( |
||
902 | "values[{$attrs->fields['attname']}]", |
||
903 | $_REQUEST['values'][$attrs->fields['attname']], |
||
904 | $attrs->fields['type'] |
||
905 | ), '</td>'; |
||
906 | echo "</tr>\n"; |
||
907 | ++$i; |
||
908 | $attrs->moveNext(); |
||
909 | } |
||
910 | // Select all checkbox |
||
911 | echo "<tr><td colspan=\"5\"><input type=\"checkbox\" id=\"selectall\" name=\"selectall\" accesskey=\"a\" onclick=\"javascript:selectAll()\" /><label for=\"selectall\">{$this->lang['strselectallfields']}</label></td>"; |
||
912 | echo "</tr></table>\n"; |
||
913 | } else { |
||
914 | echo "<p>{$this->lang['strinvalidparam']}</p>\n"; |
||
915 | } |
||
916 | |||
917 | echo "<p><input type=\"hidden\" name=\"action\" value=\"selectrows\" />\n"; |
||
918 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
919 | echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n"; |
||
920 | echo $this->misc->form; |
||
921 | echo "<input type=\"submit\" name=\"select\" accesskey=\"r\" value=\"{$this->lang['strselect']}\" />\n"; |
||
922 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
923 | echo "</form>\n"; |
||
924 | |||
925 | return; |
||
926 | } |
||
927 | if (!isset($_POST['show'])) { |
||
928 | $_POST['show'] = []; |
||
929 | } |
||
930 | |||
931 | if (!isset($_POST['values'])) { |
||
932 | $_POST['values'] = []; |
||
933 | } |
||
934 | |||
935 | if (!isset($_POST['nulls'])) { |
||
936 | $_POST['nulls'] = []; |
||
937 | } |
||
938 | |||
939 | // Verify that they haven't supplied a value for unary operators |
||
940 | foreach ($_POST['ops'] as $k => $v) { |
||
941 | if ('p' == $data->selectOps[$v] && $_POST['values'][$k] != '') { |
||
942 | $this->doSelectRows(true, $this->lang['strselectunary']); |
||
943 | |||
944 | return; |
||
945 | } |
||
946 | } |
||
947 | |||
948 | if (0 == sizeof($_POST['show'])) { |
||
949 | $this->doSelectRows(true, $this->lang['strselectneedscol']); |
||
950 | } else { |
||
951 | // Generate query SQL |
||
952 | $query = $data->getSelectSQL( |
||
953 | $_REQUEST['table'], |
||
954 | array_keys($_POST['show']), |
||
955 | $_POST['values'], |
||
956 | $_POST['ops'] |
||
957 | ); |
||
958 | $_REQUEST['query'] = $query; |
||
959 | $_REQUEST['return'] = 'selectrows'; |
||
960 | |||
961 | $this->setNoOutput(true); |
||
962 | |||
963 | $display_controller = new DisplayController($this->getContainer()); |
||
964 | |||
965 | return $display_controller->render(); |
||
966 | } |
||
967 | } |
||
968 | |||
969 | /** |
||
970 | * Ask for insert parameters and then actually insert row. |
||
971 | * |
||
972 | * @param mixed $confirm |
||
973 | * @param mixed $msg |
||
974 | */ |
||
975 | public function doInsertRow($confirm, $msg = '') |
||
976 | { |
||
977 | $data = $this->misc->getDatabaseAccessor(); |
||
978 | |||
979 | if ($confirm) { |
||
980 | $this->printTrail('table'); |
||
981 | $this->printTabs('table', 'insert'); |
||
982 | |||
983 | $this->printMsg($msg); |
||
984 | |||
985 | $attrs = $data->getTableAttributes($_REQUEST['table']); |
||
986 | |||
987 | if (('disable' != $this->conf['autocomplete'])) { |
||
988 | $fksprops = $this->misc->getAutocompleteFKProperties($_REQUEST['table']); |
||
989 | if (false !== $fksprops) { |
||
990 | echo $fksprops['code']; |
||
991 | } |
||
992 | } else { |
||
993 | $fksprops = false; |
||
994 | } |
||
995 | |||
996 | echo '<form action="' . \SUBFOLDER . "/src/views/tables\" method=\"post\" id=\"ac_form\">\n"; |
||
997 | if ($attrs->recordCount() > 0) { |
||
998 | echo "<table>\n"; |
||
999 | |||
1000 | // Output table header |
||
1001 | echo "<tr><th class=\"data\">{$this->lang['strcolumn']}</th><th class=\"data\">{$this->lang['strtype']}</th>"; |
||
1002 | echo "<th class=\"data\">{$this->lang['strformat']}</th>"; |
||
1003 | echo "<th class=\"data\">{$this->lang['strnull']}</th><th class=\"data\">{$this->lang['strvalue']}</th></tr>"; |
||
1004 | |||
1005 | $i = 0; |
||
1006 | $fields = []; |
||
1007 | while (!$attrs->EOF) { |
||
1008 | $fields[$attrs->fields['attnum']] = $attrs->fields['attname']; |
||
1009 | $attrs->fields['attnotnull'] = $data->phpBool($attrs->fields['attnotnull']); |
||
1010 | // Set up default value if there isn't one already |
||
1011 | if (!isset($_REQUEST['values'][$attrs->fields['attnum']])) { |
||
1012 | $_REQUEST['values'][$attrs->fields['attnum']] = $attrs->fields['adsrc']; |
||
1013 | } |
||
1014 | |||
1015 | // Default format to 'VALUE' if there is no default, |
||
1016 | // otherwise default to 'EXPRESSION' |
||
1017 | if (!isset($_REQUEST['format'][$attrs->fields['attnum']])) { |
||
1018 | $_REQUEST['format'][$attrs->fields['attnum']] = (null === $attrs->fields['adsrc']) ? 'VALUE' : 'EXPRESSION'; |
||
1019 | } |
||
1020 | |||
1021 | // Continue drawing row |
||
1022 | $id = (0 == ($i % 2) ? '1' : '2'); |
||
1023 | echo "<tr class=\"data{$id}\">\n"; |
||
1024 | echo '<td style="white-space:nowrap;">', $this->misc->printVal($attrs->fields['attname']), '</td>'; |
||
1025 | echo "<td style=\"white-space:nowrap;\">\n"; |
||
1026 | echo $this->misc->printVal($data->formatType($attrs->fields['type'], $attrs->fields['atttypmod'])); |
||
1027 | echo "<input type=\"hidden\" name=\"types[{$attrs->fields['attnum']}]\" value=\"", |
||
1028 | htmlspecialchars($attrs->fields['type']), '" /></td>'; |
||
1029 | echo "<td style=\"white-space:nowrap;\">\n"; |
||
1030 | echo "<select name=\"format[{$attrs->fields['attnum']}]\">\n"; |
||
1031 | echo '<option value="VALUE"', ($_REQUEST['format'][$attrs->fields['attnum']] == 'VALUE') ? ' selected="selected"' : '', ">{$this->lang['strvalue']}</option>\n"; |
||
1032 | echo '<option value="EXPRESSION"', ($_REQUEST['format'][$attrs->fields['attnum']] == 'EXPRESSION') ? ' selected="selected"' : '', ">{$this->lang['strexpression']}</option>\n"; |
||
1033 | echo "</select>\n</td>\n"; |
||
1034 | echo '<td style="white-space:nowrap;">'; |
||
1035 | // Output null box if the column allows nulls (doesn't look at CHECKs or ASSERTIONS) |
||
1036 | if (!$attrs->fields['attnotnull']) { |
||
1037 | echo "<label><span><input type=\"checkbox\" name=\"nulls[{$attrs->fields['attnum']}]\"", |
||
1038 | isset($_REQUEST['nulls'][$attrs->fields['attnum']]) ? ' checked="checked"' : '', ' /></span></label></td>'; |
||
1039 | } else { |
||
1040 | echo ' </td>'; |
||
1041 | } |
||
1042 | echo "<td id=\"row_att_{$attrs->fields['attnum']}\" style=\"white-space:nowrap;\">"; |
||
1043 | if ((false !== $fksprops) && isset($fksprops['byfield'][$attrs->fields['attnum']])) { |
||
1044 | echo $data->printField( |
||
1045 | "values[{$attrs->fields['attnum']}]", |
||
1046 | $_REQUEST['values'][$attrs->fields['attnum']], |
||
1047 | 'fktype' /*force FK*/, |
||
1048 | [ |
||
1049 | 'id' => "attr_{$attrs->fields['attnum']}", |
||
1050 | 'autocomplete' => 'off', |
||
1051 | ] |
||
1052 | ); |
||
1053 | } else { |
||
1054 | echo $data->printField("values[{$attrs->fields['attnum']}]", $_REQUEST['values'][$attrs->fields['attnum']], $attrs->fields['type']); |
||
1055 | } |
||
1056 | echo "</td>\n"; |
||
1057 | echo "</tr>\n"; |
||
1058 | ++$i; |
||
1059 | $attrs->moveNext(); |
||
1060 | } |
||
1061 | echo "</table>\n"; |
||
1062 | |||
1063 | if (!isset($_SESSION['counter'])) { |
||
1064 | $_SESSION['counter'] = 0; |
||
1065 | } |
||
1066 | |||
1067 | echo "<input type=\"hidden\" name=\"action\" value=\"insertrow\" />\n"; |
||
1068 | echo '<input type="hidden" name="fields" value="', htmlentities(serialize($fields), ENT_QUOTES, 'UTF-8'), "\" />\n"; |
||
1069 | echo '<input type="hidden" name="protection_counter" value="' . $_SESSION['counter'] . "\" />\n"; |
||
1070 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
1071 | echo "<p><input type=\"submit\" name=\"insert\" value=\"{$this->lang['strinsert']}\" />\n"; |
||
1072 | echo "<input type=\"submit\" name=\"insertandrepeat\" accesskey=\"r\" value=\"{$this->lang['strinsertandrepeat']}\" />\n"; |
||
1073 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />\n"; |
||
1074 | |||
1075 | if (false !== $fksprops) { |
||
1076 | if ('default off' != $this->conf['autocomplete']) { |
||
1077 | echo "<input type=\"checkbox\" id=\"no_ac\" value=\"1\" checked=\"checked\" /><label for=\"no_ac\">{$this->lang['strac']}</label>\n"; |
||
1078 | } else { |
||
1079 | echo "<input type=\"checkbox\" id=\"no_ac\" value=\"0\" /><label for=\"no_ac\">{$this->lang['strac']}</label>\n"; |
||
1080 | } |
||
1081 | } |
||
1082 | echo "</p>\n"; |
||
1083 | } else { |
||
1084 | echo "<p>{$this->lang['strnofieldsforinsert']}</p>\n"; |
||
1085 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />\n"; |
||
1086 | } |
||
1087 | echo $this->misc->form; |
||
1088 | echo "</form>\n"; |
||
1089 | } else { |
||
1090 | if (!isset($_POST['values'])) { |
||
1091 | $_POST['values'] = []; |
||
1092 | } |
||
1093 | |||
1094 | if (!isset($_POST['nulls'])) { |
||
1095 | $_POST['nulls'] = []; |
||
1096 | } |
||
1097 | |||
1098 | $_POST['fields'] = unserialize(htmlspecialchars_decode($_POST['fields'], ENT_QUOTES)); |
||
1099 | |||
1100 | if ($_SESSION['counter']++ == $_POST['protection_counter']) { |
||
1101 | $status = $data->insertRow($_POST['table'], $_POST['fields'], $_POST['values'], $_POST['nulls'], $_POST['format'], $_POST['types']); |
||
1102 | if (0 == $status) { |
||
1103 | if (isset($_POST['insert'])) { |
||
1104 | return $this->doDefault($this->lang['strrowinserted']); |
||
1105 | } |
||
1106 | $_REQUEST['values'] = []; |
||
1107 | $_REQUEST['nulls'] = []; |
||
1108 | $this->doInsertRow(true, $this->lang['strrowinserted']); |
||
1109 | } else { |
||
1110 | $this->doInsertRow(true, $this->lang['strrowinsertedbad']); |
||
1111 | } |
||
1112 | } else { |
||
1113 | $this->doInsertRow(true, $this->lang['strrowduplicate']); |
||
1114 | } |
||
1115 | } |
||
1116 | } |
||
1117 | |||
1118 | /** |
||
1119 | * Show confirmation of empty and perform actual empty. |
||
1120 | * |
||
1121 | * @param mixed $confirm |
||
1122 | */ |
||
1123 | public function doEmpty($confirm) |
||
1124 | { |
||
1125 | $data = $this->misc->getDatabaseAccessor(); |
||
1126 | |||
1127 | if (empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { |
||
1128 | return $this->doDefault($this->lang['strspecifytabletoempty']); |
||
1129 | } |
||
1130 | |||
1131 | if ($confirm) { |
||
1132 | if (isset($_REQUEST['ma'])) { |
||
1133 | $this->printTrail('schema'); |
||
1134 | $this->printTitle($this->lang['strempty'], 'pg.table.empty'); |
||
1135 | |||
1136 | echo '<form action="' . \SUBFOLDER . "/src/views/tables\" method=\"post\">\n"; |
||
1137 | foreach ($_REQUEST['ma'] as $v) { |
||
1138 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
1139 | echo '<p>' . sprintf($this->lang['strconfemptytable'], $this->misc->printVal($a['table'])); |
||
1140 | |||
1141 | echo "</p>\n"; |
||
1142 | printf('<input type="hidden" name="table[]" value="%s" />', htmlspecialchars($a['table'])); |
||
1143 | } // END mutli empty |
||
1144 | } else { |
||
1145 | $this->printTrail('table'); |
||
1146 | $this->printTitle($this->lang['strempty'], 'pg.table.empty'); |
||
1147 | |||
1148 | echo '<p>', sprintf($this->lang['strconfemptytable'], $this->misc->printVal($_REQUEST['table'])), "</p>\n"; |
||
1149 | |||
1150 | echo '<form action="' . \SUBFOLDER . "/src/views/tables\" method=\"post\">\n"; |
||
1151 | |||
1152 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
1153 | // END not mutli empty |
||
1154 | } |
||
1155 | echo "<input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$this->lang['strcascade']}</label>"; |
||
1156 | echo "<input type=\"hidden\" name=\"action\" value=\"empty\" />\n"; |
||
1157 | echo $this->misc->form; |
||
1158 | echo "<input type=\"submit\" name=\"empty\" value=\"{$this->lang['strempty']}\" /> <input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />\n"; |
||
1159 | echo "</form>\n"; // END if confirm |
||
1160 | } else { |
||
1161 | // Do Empty |
||
1162 | $msg = ''; |
||
1163 | if (is_array($_REQUEST['table'])) { |
||
1164 | foreach ($_REQUEST['table'] as $t) { |
||
1165 | list($status, $sql) = $data->emptyTable($t, isset($_POST['cascade'])); |
||
1166 | if (0 == $status) { |
||
1167 | $msg .= sprintf('%s<br />', $sql); |
||
1168 | $msg .= sprintf('%s: %s<br />', htmlentities($t, ENT_QUOTES, 'UTF-8'), $this->lang['strtableemptied']); |
||
1169 | } else { |
||
1170 | $this->doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($t, ENT_QUOTES, 'UTF-8'), $this->lang['strtableemptiedbad'])); |
||
1171 | |||
1172 | return; |
||
1173 | } |
||
1174 | } |
||
1175 | $this->doDefault($msg); // END mutli empty |
||
1176 | } else { |
||
1177 | list($status, $sql) = $data->emptyTable($_POST['table'], isset($_POST['cascade'])); |
||
1178 | if (0 == $status) { |
||
1179 | $msg .= sprintf('%s<br />', $sql); |
||
1180 | $msg .= sprintf('%s: %s<br />', htmlentities($_POST['table'], ENT_QUOTES, 'UTF-8'), $this->lang['strtableemptied']); |
||
1181 | |||
1182 | return $this->doDefault($msg); |
||
1183 | } |
||
1184 | |||
1185 | return $this->doDefault($sql . '<br>' . $this->lang['strtableemptiedbad']); |
||
1186 | // END not mutli empty |
||
1187 | } |
||
1188 | // END do Empty |
||
1189 | } |
||
1190 | } |
||
1191 | |||
1192 | /** |
||
1193 | * Show confirmation of drop and perform actual drop. |
||
1194 | * |
||
1195 | * @param mixed $confirm |
||
1196 | */ |
||
1197 | public function doDrop($confirm) |
||
1268 | // END DROP |
||
1269 | } |
||
1270 | } |
||
1271 | |||
1272 | // END Function |
||
1273 | } |
||
1274 |