Total Complexity | 112 |
Total Lines | 910 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like ViewsController 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 ViewsController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class ViewsController extends BaseController |
||
15 | { |
||
16 | public $script = 'views.php'; |
||
17 | public $controller_name = 'ViewsController'; |
||
18 | public $table_place = 'views-views'; |
||
19 | |||
20 | /** |
||
21 | * Default method to render the controller according to the action parameter. |
||
22 | */ |
||
23 | public function render() |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Show default list of views in the database. |
||
110 | * |
||
111 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
112 | */ |
||
113 | public function doDefault($msg = '') |
||
114 | { |
||
115 | $conf = $this->conf; |
||
116 | |||
117 | $lang = $this->lang; |
||
118 | $data = $this->misc->getDatabaseAccessor(); |
||
119 | |||
120 | $this->printTrail('schema'); |
||
121 | $this->printTabs('schema', 'views'); |
||
122 | $this->printMsg($msg); |
||
123 | |||
124 | $views = $data->getViews(); |
||
125 | |||
126 | $columns = [ |
||
127 | 'view' => [ |
||
128 | 'title' => $lang['strview'], |
||
129 | 'field' => Decorator::field('relname'), |
||
130 | 'url' => \SUBFOLDER."/redirect/view?{$this->misc->href}&", |
||
131 | 'vars' => ['view' => 'relname'], |
||
132 | ], |
||
133 | 'owner' => [ |
||
134 | 'title' => $lang['strowner'], |
||
135 | 'field' => Decorator::field('relowner'), |
||
136 | ], |
||
137 | 'actions' => [ |
||
138 | 'title' => $lang['stractions'], |
||
139 | ], |
||
140 | 'comment' => [ |
||
141 | 'title' => $lang['strcomment'], |
||
142 | 'field' => Decorator::field('relcomment'), |
||
143 | ], |
||
144 | ]; |
||
145 | |||
146 | $actions = [ |
||
147 | 'multiactions' => [ |
||
148 | 'keycols' => ['view' => 'relname'], |
||
149 | 'url' => 'views.php', |
||
150 | ], |
||
151 | 'browse' => [ |
||
152 | 'content' => $lang['strbrowse'], |
||
153 | 'attr' => [ |
||
154 | 'href' => [ |
||
155 | 'url' => 'display.php', |
||
156 | 'urlvars' => [ |
||
157 | 'action' => 'confselectrows', |
||
158 | 'subject' => 'view', |
||
159 | 'return' => 'schema', |
||
160 | 'view' => Decorator::field('relname'), |
||
161 | ], |
||
162 | ], |
||
163 | ], |
||
164 | ], |
||
165 | 'select' => [ |
||
166 | 'content' => $lang['strselect'], |
||
167 | 'attr' => [ |
||
168 | 'href' => [ |
||
169 | 'url' => 'views.php', |
||
170 | 'urlvars' => [ |
||
171 | 'action' => 'confselectrows', |
||
172 | 'view' => Decorator::field('relname'), |
||
173 | ], |
||
174 | ], |
||
175 | ], |
||
176 | ], |
||
177 | |||
178 | // Insert is possible if the relevant rule for the view has been created. |
||
179 | // 'insert' => array( |
||
180 | // 'title' => $lang['strinsert'], |
||
181 | // 'url' => "views.php?action=confinsertrow&{$this->misc->href}&", |
||
182 | // 'vars' => array('view' => 'relname'), |
||
183 | // ), |
||
184 | |||
185 | 'alter' => [ |
||
186 | 'content' => $lang['stralter'], |
||
187 | 'attr' => [ |
||
188 | 'href' => [ |
||
189 | 'url' => 'viewproperties.php', |
||
190 | 'urlvars' => [ |
||
191 | 'action' => 'confirm_alter', |
||
192 | 'view' => Decorator::field('relname'), |
||
193 | ], |
||
194 | ], |
||
195 | ], |
||
196 | ], |
||
197 | 'drop' => [ |
||
198 | 'multiaction' => 'confirm_drop', |
||
199 | 'content' => $lang['strdrop'], |
||
200 | 'attr' => [ |
||
201 | 'href' => [ |
||
202 | 'url' => 'views.php', |
||
203 | 'urlvars' => [ |
||
204 | 'action' => 'confirm_drop', |
||
205 | 'view' => Decorator::field('relname'), |
||
206 | ], |
||
207 | ], |
||
208 | ], |
||
209 | ], |
||
210 | ]; |
||
211 | |||
212 | echo $this->printTable($views, $columns, $actions, $this->table_place, $lang['strnoviews']); |
||
213 | |||
214 | $navlinks = [ |
||
215 | 'create' => [ |
||
216 | 'attr' => [ |
||
217 | 'href' => [ |
||
218 | 'url' => 'views.php', |
||
219 | 'urlvars' => [ |
||
220 | 'action' => 'create', |
||
221 | 'server' => $_REQUEST['server'], |
||
222 | 'database' => $_REQUEST['database'], |
||
223 | 'schema' => $_REQUEST['schema'], |
||
224 | ], |
||
225 | ], |
||
226 | ], |
||
227 | 'content' => $lang['strcreateview'], |
||
228 | ], |
||
229 | 'createwiz' => [ |
||
230 | 'attr' => [ |
||
231 | 'href' => [ |
||
232 | 'url' => 'views.php', |
||
233 | 'urlvars' => [ |
||
234 | 'action' => 'wiz_create', |
||
235 | 'server' => $_REQUEST['server'], |
||
236 | 'database' => $_REQUEST['database'], |
||
237 | 'schema' => $_REQUEST['schema'], |
||
238 | ], |
||
239 | ], |
||
240 | ], |
||
241 | 'content' => $lang['strcreateviewwiz'], |
||
242 | ], |
||
243 | ]; |
||
244 | $this->printNavLinks($navlinks, $this->table_place, get_defined_vars()); |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * Generate XML for the browser tree. |
||
249 | */ |
||
250 | public function doTree() |
||
251 | { |
||
252 | $conf = $this->conf; |
||
253 | |||
254 | $lang = $this->lang; |
||
255 | $data = $this->misc->getDatabaseAccessor(); |
||
256 | |||
257 | $views = $data->getViews(); |
||
258 | |||
259 | $reqvars = $this->misc->getRequestVars('view'); |
||
260 | |||
261 | $attrs = [ |
||
262 | 'text' => Decorator::field('relname'), |
||
263 | 'icon' => 'View', |
||
264 | 'iconAction' => Decorator::url('display.php', $reqvars, ['view' => Decorator::field('relname')]), |
||
265 | 'toolTip' => Decorator::field('relcomment'), |
||
266 | 'action' => Decorator::redirecturl('redirect.php', $reqvars, ['view' => Decorator::field('relname')]), |
||
267 | 'branch' => Decorator::url('views.php', $reqvars, ['action' => 'subtree', 'view' => Decorator::field('relname')]), |
||
268 | ]; |
||
269 | |||
270 | return $this->printTree($views, $attrs, 'views'); |
||
271 | } |
||
272 | |||
273 | public function doSubTree() |
||
1 ignored issue
–
show
|
|||
274 | { |
||
275 | $conf = $this->conf; |
||
276 | |||
277 | $lang = $this->lang; |
||
278 | $data = $this->misc->getDatabaseAccessor(); |
||
279 | |||
280 | $tabs = $this->misc->getNavTabs('view'); |
||
281 | $items = $this->adjustTabsForTree($tabs); |
||
282 | $reqvars = $this->misc->getRequestVars('view'); |
||
283 | |||
284 | $attrs = [ |
||
285 | 'text' => Decorator::field('title'), |
||
286 | 'icon' => Decorator::field('icon'), |
||
287 | 'action' => Decorator::actionurl(Decorator::field('url'), $reqvars, Decorator::field('urlvars'), ['view' => $_REQUEST['view']]), |
||
288 | 'branch' => Decorator::ifempty( |
||
289 | Decorator::field('branch'), |
||
290 | '', |
||
291 | Decorator::url( |
||
292 | Decorator::field('url'), |
||
293 | Decorator::field('urlvars'), |
||
294 | $reqvars, |
||
295 | [ |
||
296 | 'action' => 'tree', |
||
297 | 'view' => $_REQUEST['view'], |
||
298 | ] |
||
299 | ) |
||
300 | ), |
||
301 | ]; |
||
302 | |||
303 | return $this->printTree($items, $attrs, 'view'); |
||
304 | } |
||
305 | |||
306 | /** |
||
307 | * Ask for select parameters and perform select. |
||
308 | * |
||
309 | * @param mixed $confirm |
||
1 ignored issue
–
show
|
|||
310 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
311 | */ |
||
312 | public function doSelectRows($confirm, $msg = '') |
||
313 | { |
||
314 | $conf = $this->conf; |
||
315 | |||
316 | $lang = $this->lang; |
||
317 | $data = $this->misc->getDatabaseAccessor(); |
||
318 | |||
319 | if ($confirm) { |
||
320 | $this->printTrail('view'); |
||
321 | $this->printTabs('view', 'select'); |
||
322 | $this->printMsg($msg); |
||
323 | |||
324 | $attrs = $data->getTableAttributes($_REQUEST['view']); |
||
325 | |||
326 | echo '<form action="'.\SUBFOLDER.'/src/views/'.$this->script.'" method="post" id="selectform">'; |
||
327 | echo "\n"; |
||
328 | |||
329 | if ($attrs->recordCount() > 0) { |
||
330 | // JavaScript for select all feature |
||
331 | echo "<script type=\"text/javascript\">\n"; |
||
332 | echo "//<![CDATA[\n"; |
||
333 | echo " function selectAll() {\n"; |
||
334 | echo " for (var i=0; i<document.getElementById('selectform').elements.length; i++) {\n"; |
||
335 | echo " var e = document.getElementById('selectform').elements[i];\n"; |
||
336 | echo " if (e.name.indexOf('show') == 0) { \n "; |
||
337 | echo " e.checked = document.getElementById('selectform').selectall.checked;\n"; |
||
338 | echo " }\n"; |
||
339 | echo " }\n"; |
||
340 | echo " }\n"; |
||
341 | echo "//]]>\n"; |
||
342 | echo "</script>\n"; |
||
343 | |||
344 | echo "<table>\n"; |
||
345 | |||
346 | // Output table header |
||
347 | echo "<tr><th class=\"data\">{$lang['strshow']}</th><th class=\"data\">{$lang['strcolumn']}</th>"; |
||
348 | echo "<th class=\"data\">{$lang['strtype']}</th><th class=\"data\">{$lang['stroperator']}</th>"; |
||
349 | echo "<th class=\"data\">{$lang['strvalue']}</th></tr>"; |
||
350 | |||
351 | $i = 0; |
||
352 | while (!$attrs->EOF) { |
||
353 | $attrs->fields['attnotnull'] = $data->phpBool($attrs->fields['attnotnull']); |
||
354 | // Set up default value if there isn't one already |
||
355 | if (!isset($_REQUEST['values'][$attrs->fields['attname']])) { |
||
356 | $_REQUEST['values'][$attrs->fields['attname']] = null; |
||
357 | } |
||
358 | |||
359 | if (!isset($_REQUEST['ops'][$attrs->fields['attname']])) { |
||
360 | $_REQUEST['ops'][$attrs->fields['attname']] = null; |
||
361 | } |
||
362 | |||
363 | // Continue drawing row |
||
364 | $id = (0 == ($i % 2) ? '1' : '2'); |
||
365 | echo "<tr class=\"data{$id}\">\n"; |
||
366 | echo '<td style="white-space:nowrap;">'; |
||
367 | echo '<input type="checkbox" name="show[', htmlspecialchars($attrs->fields['attname']), ']"', |
||
368 | isset($_REQUEST['show'][$attrs->fields['attname']]) ? ' checked="checked"' : '', ' /></td>'; |
||
369 | echo '<td style="white-space:nowrap;">', $this->misc->printVal($attrs->fields['attname']), '</td>'; |
||
370 | echo '<td style="white-space:nowrap;">', $this->misc->printVal($data->formatType($attrs->fields['type'], $attrs->fields['atttypmod'])), '</td>'; |
||
371 | echo '<td style="white-space:nowrap;">'; |
||
372 | echo "<select name=\"ops[{$attrs->fields['attname']}]\">\n"; |
||
373 | foreach (array_keys($data->selectOps) as $v) { |
||
374 | echo '<option value="', htmlspecialchars($v), '"', ($_REQUEST['ops'][$attrs->fields['attname']] == $v) ? ' selected="selected"' : '', |
||
375 | '>', htmlspecialchars($v), "</option>\n"; |
||
376 | } |
||
377 | echo "</select></td>\n"; |
||
378 | echo '<td style="white-space:nowrap;">', $data->printField( |
||
379 | "values[{$attrs->fields['attname']}]", |
||
380 | $_REQUEST['values'][$attrs->fields['attname']], |
||
381 | $attrs->fields['type'] |
||
382 | ), '</td>'; |
||
383 | echo "</tr>\n"; |
||
384 | ++$i; |
||
385 | $attrs->moveNext(); |
||
386 | } |
||
387 | // Select all checkbox |
||
388 | echo "<tr><td colspan=\"5\"><input type=\"checkbox\" id=\"selectall\" name=\"selectall\" accesskey=\"a\" onclick=\"javascript:selectAll()\" /><label for=\"selectall\">{$lang['strselectallfields']}</label></td></tr>"; |
||
389 | echo "</table>\n"; |
||
390 | } else { |
||
391 | echo "<p>{$lang['strinvalidparam']}</p>\n"; |
||
392 | } |
||
393 | |||
394 | echo "<p><input type=\"hidden\" name=\"action\" value=\"selectrows\" />\n"; |
||
395 | echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['view']), "\" />\n"; |
||
396 | echo "<input type=\"hidden\" name=\"subject\" value=\"view\" />\n"; |
||
397 | echo $this->misc->form; |
||
398 | echo "<input type=\"submit\" name=\"select\" accesskey=\"r\" value=\"{$lang['strselect']}\" />\n"; |
||
399 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
400 | echo "</form>\n"; |
||
401 | |||
402 | return; |
||
403 | } |
||
404 | if (!isset($_POST['show'])) { |
||
405 | $_POST['show'] = []; |
||
406 | } |
||
407 | |||
408 | if (!isset($_POST['values'])) { |
||
409 | $_POST['values'] = []; |
||
410 | } |
||
411 | |||
412 | if (!isset($_POST['nulls'])) { |
||
413 | $_POST['nulls'] = []; |
||
414 | } |
||
415 | |||
416 | // Verify that they haven't supplied a value for unary operators |
||
417 | foreach ($_POST['ops'] as $k => $v) { |
||
418 | if ('p' == $data->selectOps[$v] && $_POST['values'][$k] != '') { |
||
419 | $this->doSelectRows(true, $lang['strselectunary']); |
||
420 | |||
421 | return; |
||
422 | } |
||
423 | } |
||
424 | |||
425 | if (0 == sizeof($_POST['show'])) { |
||
426 | return $this->doSelectRows(true, $lang['strselectneedscol']); |
||
427 | } |
||
428 | // Generate query SQL |
||
429 | $query = $data->getSelectSQL($_REQUEST['view'], array_keys($_POST['show']), $_POST['values'], $_POST['ops']); |
||
430 | |||
431 | $_REQUEST['query'] = $query; |
||
432 | $_REQUEST['return'] = 'schema'; |
||
433 | |||
434 | $this->setNoOutput(true); |
||
435 | |||
436 | $display_controller = new DisplayController($this->getContainer()); |
||
437 | |||
438 | return $display_controller->render(); |
||
439 | } |
||
440 | |||
441 | /** |
||
442 | * Show confirmation of drop and perform actual drop. |
||
443 | * |
||
444 | * @param mixed $confirm |
||
1 ignored issue
–
show
|
|||
445 | */ |
||
446 | public function doDrop($confirm) |
||
513 | } |
||
514 | } |
||
515 | } |
||
516 | } |
||
517 | |||
518 | /** |
||
519 | * Sets up choices for table linkage, and which fields to select for the view we're creating. |
||
520 | * |
||
521 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
522 | */ |
||
523 | public function doSetParamsCreate($msg = '') |
||
524 | { |
||
525 | $conf = $this->conf; |
||
526 | |||
527 | $lang = $this->lang; |
||
528 | $data = $this->misc->getDatabaseAccessor(); |
||
529 | |||
530 | // Check that they've chosen tables for the view definition |
||
531 | if (!isset($_POST['formTables'])) { |
||
532 | $this->doWizardCreate($lang['strviewneedsdef']); |
||
533 | } else { |
||
534 | // Initialise variables |
||
535 | if (!isset($_REQUEST['formView'])) { |
||
536 | $_REQUEST['formView'] = ''; |
||
537 | } |
||
538 | |||
539 | if (!isset($_REQUEST['formComment'])) { |
||
540 | $_REQUEST['formComment'] = ''; |
||
541 | } |
||
542 | |||
543 | $this->printTrail('schema'); |
||
544 | $this->printTitle($lang['strcreateviewwiz'], 'pg.view.create'); |
||
545 | $this->printMsg($msg); |
||
546 | |||
547 | $tblCount = sizeof($_POST['formTables']); |
||
548 | //unserialize our schema/table information and store in arrSelTables |
||
549 | for ($i = 0; $i < $tblCount; ++$i) { |
||
550 | $arrSelTables[] = unserialize($_POST['formTables'][$i]); |
||
551 | } |
||
552 | |||
553 | $linkCount = $tblCount; |
||
554 | |||
555 | //get linking keys |
||
556 | $rsLinkKeys = $data->getLinkingKeys($arrSelTables); |
||
557 | $linkCount = $rsLinkKeys->recordCount() > $tblCount ? $rsLinkKeys->recordCount() : $tblCount; |
||
558 | |||
559 | $arrFields = []; //array that will hold all our table/field names |
||
560 | |||
561 | //if we have schemas we need to specify the correct schema for each table we're retrieiving |
||
562 | //with getTableAttributes |
||
563 | $curSchema = $data->_schema; |
||
564 | for ($i = 0; $i < $tblCount; ++$i) { |
||
565 | if ($arrSelTables[$i]['schemaname'] != $data->_schema) { |
||
566 | $data->setSchema($arrSelTables[$i]['schemaname']); |
||
567 | } |
||
568 | |||
569 | $attrs = $data->getTableAttributes($arrSelTables[$i]['tablename']); |
||
570 | while (!$attrs->EOF) { |
||
571 | $arrFields["{$arrSelTables[$i]['schemaname']}.{$arrSelTables[$i]['tablename']}.{$attrs->fields['attname']}"] = serialize( |
||
572 | [ |
||
573 | 'schemaname' => $arrSelTables[$i]['schemaname'], |
||
574 | 'tablename' => $arrSelTables[$i]['tablename'], |
||
575 | 'fieldname' => $attrs->fields['attname'], ] |
||
576 | ); |
||
577 | $attrs->moveNext(); |
||
578 | } |
||
579 | |||
580 | $data->setSchema($curSchema); |
||
581 | } |
||
582 | asort($arrFields); |
||
583 | |||
584 | echo '<form action="'.\SUBFOLDER."/src/views/views.php\" method=\"post\">\n"; |
||
585 | echo "<table>\n"; |
||
586 | echo "<tr><th class=\"data\">{$lang['strviewname']}</th></tr>"; |
||
587 | echo "<tr>\n<td class=\"data1\">\n"; |
||
588 | // View name |
||
589 | echo '<input name="formView" value="', htmlspecialchars($_REQUEST['formView']), "\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />\n"; |
||
590 | echo "</td>\n</tr>\n"; |
||
591 | echo "<tr><th class=\"data\">{$lang['strcomment']}</th></tr>"; |
||
592 | echo "<tr>\n<td class=\"data1\">\n"; |
||
593 | // View comments |
||
594 | echo '<textarea name="formComment" rows="3" cols="32">', |
||
595 | htmlspecialchars($_REQUEST['formComment']), "</textarea>\n"; |
||
596 | echo "</td>\n</tr>\n"; |
||
597 | echo "</table>\n"; |
||
598 | |||
599 | // Output selector for fields to be retrieved from view |
||
600 | echo "<table>\n"; |
||
601 | echo "<tr><th class=\"data\">{$lang['strcolumns']}</th></tr>"; |
||
602 | echo "<tr>\n<td class=\"data1\">\n"; |
||
603 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, 'formFields[]', false, '', true); |
||
604 | echo "</td>\n</tr>"; |
||
605 | echo "<tr><td><input type=\"radio\" name=\"dblFldMeth\" id=\"dblFldMeth1\" value=\"rename\" /><label for=\"dblFldMeth1\">{$lang['strrenamedupfields']}</label>"; |
||
606 | echo "<br /><input type=\"radio\" name=\"dblFldMeth\" id=\"dblFldMeth2\" value=\"drop\" /><label for=\"dblFldMeth2\">{$lang['strdropdupfields']}</label>"; |
||
607 | echo "<br /><input type=\"radio\" name=\"dblFldMeth\" id=\"dblFldMeth3\" value=\"\" checked=\"checked\" /><label for=\"dblFldMeth3\">{$lang['strerrordupfields']}</label></td></tr></table><br />"; |
||
608 | |||
609 | // Output the Linking keys combo boxes |
||
610 | echo "<table>\n"; |
||
611 | echo "<tr><th class=\"data\">{$lang['strviewlink']}</th></tr>"; |
||
612 | $rowClass = 'data1'; |
||
613 | for ($i = 0; $i < $linkCount; ++$i) { |
||
614 | // Initialise variables |
||
615 | if (!isset($formLink[$i]['operator'])) { |
||
616 | $formLink[$i]['operator'] = 'INNER JOIN'; |
||
617 | } |
||
618 | |||
619 | echo "<tr>\n<td class=\"${rowClass}\">\n"; |
||
620 | |||
621 | if (!$rsLinkKeys->EOF) { |
||
622 | $curLeftLink = htmlspecialchars(serialize(['schemaname' => $rsLinkKeys->fields['p_schema'], 'tablename' => $rsLinkKeys->fields['p_table'], 'fieldname' => $rsLinkKeys->fields['p_field']])); |
||
623 | $curRightLink = htmlspecialchars(serialize(['schemaname' => $rsLinkKeys->fields['f_schema'], 'tablename' => $rsLinkKeys->fields['f_table'], 'fieldname' => $rsLinkKeys->fields['f_field']])); |
||
624 | $rsLinkKeys->moveNext(); |
||
625 | } else { |
||
626 | $curLeftLink = ''; |
||
627 | $curRightLink = ''; |
||
628 | } |
||
629 | |||
630 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formLink[${i}][leftlink]", true, $curLeftLink, false); |
||
631 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($data->joinOps, "formLink[${i}][operator]", true, $formLink[$i]['operator']); |
||
632 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formLink[${i}][rightlink]", true, $curRightLink, false); |
||
633 | echo "</td>\n</tr>\n"; |
||
634 | $rowClass = 'data1' == $rowClass ? 'data2' : 'data1'; |
||
635 | } |
||
636 | echo "</table>\n<br />\n"; |
||
637 | |||
638 | // Build list of available operators (infix only) |
||
639 | $arrOperators = []; |
||
640 | foreach ($data->selectOps as $k => $v) { |
||
641 | if ('i' == $v) { |
||
642 | $arrOperators[$k] = $k; |
||
643 | } |
||
644 | } |
||
645 | |||
646 | // Output additional conditions, note that this portion of the wizard treats the right hand side as literal values |
||
647 | //(not as database objects) so field names will be treated as strings, use the above linking keys section to perform joins |
||
648 | echo "<table>\n"; |
||
649 | echo "<tr><th class=\"data\">{$lang['strviewconditions']}</th></tr>"; |
||
650 | $rowClass = 'data1'; |
||
651 | for ($i = 0; $i < $linkCount; ++$i) { |
||
652 | echo "<tr>\n<td class=\"${rowClass}\">\n"; |
||
653 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formCondition[${i}][field]"); |
||
654 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrOperators, "formCondition[${i}][operator]", false, false); |
||
655 | echo "<input type=\"text\" name=\"formCondition[${i}][txt]\" />\n"; |
||
656 | echo "</td>\n</tr>\n"; |
||
657 | $rowClass = 'data1' == $rowClass ? 'data2' : 'data1'; |
||
658 | } |
||
659 | echo "</table>\n"; |
||
660 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_wiz\" />\n"; |
||
661 | |||
662 | foreach ($arrSelTables as $curTable) { |
||
663 | echo '<input type="hidden" name="formTables[]" value="'.htmlspecialchars(serialize($curTable))."\" />\n"; |
||
664 | } |
||
665 | |||
666 | echo $this->misc->form; |
||
667 | echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n"; |
||
668 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
669 | echo "</form>\n"; |
||
670 | } |
||
671 | } |
||
672 | |||
673 | /** |
||
674 | * Display a wizard where they can enter a new view. |
||
675 | * |
||
676 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
677 | */ |
||
678 | public function doWizardCreate($msg = '') |
||
679 | { |
||
680 | $conf = $this->conf; |
||
681 | |||
682 | $lang = $this->lang; |
||
683 | $data = $this->misc->getDatabaseAccessor(); |
||
684 | |||
685 | $tables = $data->getTables(true); |
||
686 | |||
687 | $this->printTrail('schema'); |
||
688 | $this->printTitle($lang['strcreateviewwiz'], 'pg.view.create'); |
||
689 | $this->printMsg($msg); |
||
690 | |||
691 | echo '<form action="'.\SUBFOLDER."/src/views/views.php\" method=\"post\">\n"; |
||
692 | echo "<table>\n"; |
||
693 | echo "<tr><th class=\"data\">{$lang['strtables']}</th></tr>"; |
||
694 | echo "<tr>\n<td class=\"data1\">\n"; |
||
695 | |||
696 | $arrTables = []; |
||
697 | while (!$tables->EOF) { |
||
698 | $arrTmp = []; |
||
699 | $arrTmp['schemaname'] = $tables->fields['nspname']; |
||
700 | $arrTmp['tablename'] = $tables->fields['relname']; |
||
701 | $arrTables[$tables->fields['nspname'].'.'.$tables->fields['relname']] = serialize($arrTmp); |
||
702 | $tables->moveNext(); |
||
703 | } |
||
704 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrTables, 'formTables[]', false, '', true); |
||
705 | |||
706 | echo "</td>\n</tr>\n"; |
||
707 | echo "</table>\n"; |
||
708 | echo "<p><input type=\"hidden\" name=\"action\" value=\"set_params_create\" />\n"; |
||
709 | echo $this->misc->form; |
||
710 | echo "<input type=\"submit\" value=\"{$lang['strnext']}\" />\n"; |
||
711 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
712 | echo "</form>\n"; |
||
713 | } |
||
714 | |||
715 | /** |
||
716 | * Displays a screen where they can enter a new view. |
||
717 | * |
||
718 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
719 | */ |
||
720 | public function doCreate($msg = '') |
||
721 | { |
||
722 | $conf = $this->conf; |
||
723 | |||
724 | $lang = $this->lang; |
||
725 | $data = $this->misc->getDatabaseAccessor(); |
||
726 | |||
727 | if (!isset($_REQUEST['formView'])) { |
||
728 | $_REQUEST['formView'] = ''; |
||
729 | } |
||
730 | |||
731 | if (!isset($_REQUEST['formDefinition'])) { |
||
732 | if (isset($_SESSION['sqlquery'])) { |
||
733 | $_REQUEST['formDefinition'] = $_SESSION['sqlquery']; |
||
734 | } else { |
||
735 | $_REQUEST['formDefinition'] = 'SELECT '; |
||
736 | } |
||
737 | } |
||
738 | if (!isset($_REQUEST['formComment'])) { |
||
739 | $_REQUEST['formComment'] = ''; |
||
740 | } |
||
741 | |||
742 | $this->printTrail('schema'); |
||
743 | $this->printTitle($lang['strcreateview'], 'pg.view.create'); |
||
744 | $this->printMsg($msg); |
||
745 | |||
746 | echo '<form action="'.\SUBFOLDER."/src/views/views.php\" method=\"post\">\n"; |
||
747 | echo "<table style=\"width: 100%\">\n"; |
||
748 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
749 | echo "\t<td class=\"data1\"><input name=\"formView\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
750 | htmlspecialchars($_REQUEST['formView']), "\" /></td>\n\t</tr>\n"; |
||
751 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strdefinition']}</th>\n"; |
||
752 | echo "\t<td class=\"data1\"><textarea style=\"width:100%;\" rows=\"10\" cols=\"50\" name=\"formDefinition\">", |
||
753 | htmlspecialchars($_REQUEST['formDefinition']), "</textarea></td>\n\t</tr>\n"; |
||
754 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n"; |
||
755 | echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", |
||
756 | htmlspecialchars($_REQUEST['formComment']), "</textarea></td>\n\t</tr>\n"; |
||
757 | echo "</table>\n"; |
||
758 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n"; |
||
759 | echo $this->misc->form; |
||
760 | echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n"; |
||
761 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
762 | echo "</form>\n"; |
||
763 | } |
||
764 | |||
765 | /** |
||
766 | * Actually creates the new view in the database. |
||
767 | */ |
||
768 | public function doSaveCreate() |
||
769 | { |
||
770 | $conf = $this->conf; |
||
771 | |||
772 | $lang = $this->lang; |
||
773 | $data = $this->misc->getDatabaseAccessor(); |
||
774 | |||
775 | // Check that they've given a name and a definition |
||
776 | if ('' == $_POST['formView']) { |
||
777 | $this->doCreate($lang['strviewneedsname']); |
||
778 | } elseif ('' == $_POST['formDefinition']) { |
||
779 | $this->doCreate($lang['strviewneedsdef']); |
||
780 | } else { |
||
781 | $status = $data->createView($_POST['formView'], $_POST['formDefinition'], false, $_POST['formComment']); |
||
782 | if (0 == $status) { |
||
783 | $this->misc->setReloadBrowser(true); |
||
784 | $this->doDefault($lang['strviewcreated']); |
||
785 | } else { |
||
786 | $this->doCreate($lang['strviewcreatedbad']); |
||
787 | } |
||
788 | } |
||
789 | } |
||
790 | |||
791 | /** |
||
792 | * Actually creates the new wizard view in the database. |
||
793 | */ |
||
794 | public function doSaveCreateWiz() |
||
924 | } |
||
925 | } |
||
926 | } |
||
927 | } |
||
928 |