action) { return $this->doTree(); } // Different header if we're view rules or table rules $this->printHeader($_REQUEST[$_REQUEST['subject']].' - '.$this->lang['strrules']); $this->printBody(); switch ($this->action) { case 'create_rule': $this->createRule(true); break; case 'save_create_rule': if (isset($_POST['cancel'])) { $this->doDefault(); } else { $this->createRule(false); } break; case 'drop': if (isset($_POST['yes'])) { $this->doDrop(false); } else { $this->doDefault(); } break; case 'confirm_drop': $this->doDrop(true); break; default: $this->doDefault(); break; } return $this->printFooter(); } /** * List all the rules on the table. * * @param mixed $msg */ public function doDefault($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail($_REQUEST['subject']); $this->printTabs($_REQUEST['subject'], 'rules'); $this->printMsg($msg); $rules = $data->getRules($_REQUEST[$_REQUEST['subject']]); $columns = [ 'rule' => [ 'title' => $this->lang['strname'], 'field' => Decorator::field('rulename'), ], 'definition' => [ 'title' => $this->lang['strdefinition'], 'field' => Decorator::field('definition'), ], 'actions' => [ 'title' => $this->lang['stractions'], ], ]; $subject = urlencode($_REQUEST['subject']); $object = urlencode($_REQUEST[$_REQUEST['subject']]); $actions = [ 'drop' => [ 'content' => $this->lang['strdrop'], 'attr' => [ 'href' => [ 'url' => 'rules', 'urlvars' => [ 'action' => 'confirm_drop', 'reltype' => $subject, $subject => $object, 'subject' => 'rule', 'rule' => Decorator::field('rulename'), ], ], ], ], ]; echo $this->printTable($rules, $columns, $actions, 'rules-rules', $this->lang['strnorules']); $this->printNavLinks(['create' => [ 'attr' => [ 'href' => [ 'url' => 'rules', 'urlvars' => [ 'action' => 'create_rule', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], $subject => $object, 'subject' => $subject, ], ], ], 'content' => $this->lang['strcreaterule'], ]], 'rules-rules', get_defined_vars()); } public function doTree() { $data = $this->misc->getDatabaseAccessor(); $rules = $data->getRules($_REQUEST[$_REQUEST['subject']]); $attrs = [ 'text' => Decorator::field('rulename'), 'icon' => 'Rule', ]; return $this->printTree($rules, $attrs, 'rules'); } /** * Confirm and then actually create a rule. * * @param mixed $confirm * @param mixed $msg */ public function createRule($confirm, $msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->coalesceArr($_POST, 'name', ''); $this->coalesceArr($_POST, 'event', ''); $this->coalesceArr($_POST, 'where', ''); $this->coalesceArr($_POST, 'type', 'SOMETHING'); $this->coalesceArr($_POST, 'raction', ''); if ($confirm) { $this->printTrail($_REQUEST['subject']); $this->printTitle($this->lang['strcreaterule'], 'pg.rule.create'); $this->printMsg($msg); echo '
'.PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo "'.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; echo '
{$this->lang['strname']}_maxNameLen}\" value=\"", htmlspecialchars($_POST['name']), '" />
{$this->lang['strevent']}
{$this->lang['strwhere']}
'; echo ''.PHP_EOL; echo '
{$this->lang['straction']}'; echo '
'.PHP_EOL; echo ''.PHP_EOL; echo '()
'.PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; echo $this->misc->form; echo "

lang['strcreate']}\" />".PHP_EOL; echo "lang['strcancel']}\" />

".PHP_EOL; echo '
'.PHP_EOL; } else { if ('' == trim($_POST['name'])) { $this->createRule(true, $this->lang['strruleneedsname']); } else { $status = $data->createRule( $_POST['name'], $_POST['event'], $_POST[$_POST['subject']], $_POST['where'], isset($_POST['instead']), $_POST['type'], $_POST['raction'] ); if (0 == $status) { $this->doDefault($this->lang['strrulecreated']); } else { $this->createRule(true, $this->lang['strrulecreatedbad']); } } } } /** * Show confirmation of drop and perform actual drop. * * @param mixed $confirm */ public function doDrop($confirm) { $data = $this->misc->getDatabaseAccessor(); if ($confirm) { $this->printTrail($_REQUEST['subject']); $this->printTitle($this->lang['strdrop'], 'pg.rule.drop'); echo '

', sprintf( $this->lang['strconfdroprule'], $this->misc->printVal($_REQUEST['rule']), $this->misc->printVal($_REQUEST[$_REQUEST['reltype']]) ), '

'.PHP_EOL; echo '
'.PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; echo $this->misc->form; echo "

".PHP_EOL; echo "lang['stryes']}\" />".PHP_EOL; echo "lang['strno']}\" />".PHP_EOL; echo '
'.PHP_EOL; } else { $status = $data->dropRule($_POST['rule'], $_POST[$_POST['subject']], isset($_POST['cascade'])); if (0 == $status) { $this->doDefault($this->lang['strruledropped']); } else { $this->doDefault($this->lang['strruledroppedbad']); } } } }