| Total Complexity | 27 |
| Total Lines | 282 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | class RulesController extends BaseController |
||
| 15 | { |
||
| 16 | public $controller_name = 'RulesController'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Default method to render the controller according to the action parameter. |
||
| 20 | */ |
||
| 21 | public function render() |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * List all the rules on the table. |
||
| 72 | * |
||
| 73 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 74 | */ |
||
| 75 | public function doDefault($msg = '') |
||
| 76 | { |
||
| 77 | $conf = $this->conf; |
||
| 78 | |||
| 79 | $lang = $this->lang; |
||
| 80 | $data = $this->misc->getDatabaseAccessor(); |
||
| 81 | |||
| 82 | $this->printTrail($_REQUEST['subject']); |
||
| 83 | $this->printTabs($_REQUEST['subject'], 'rules'); |
||
| 84 | $this->printMsg($msg); |
||
| 85 | |||
| 86 | $rules = $data->getRules($_REQUEST[$_REQUEST['subject']]); |
||
| 87 | |||
| 88 | $columns = [ |
||
| 89 | 'rule' => [ |
||
| 90 | 'title' => $lang['strname'], |
||
| 91 | 'field' => Decorator::field('rulename'), |
||
| 92 | ], |
||
| 93 | 'definition' => [ |
||
| 94 | 'title' => $lang['strdefinition'], |
||
| 95 | 'field' => Decorator::field('definition'), |
||
| 96 | ], |
||
| 97 | 'actions' => [ |
||
| 98 | 'title' => $lang['stractions'], |
||
| 99 | ], |
||
| 100 | ]; |
||
| 101 | |||
| 102 | $subject = urlencode($_REQUEST['subject']); |
||
| 103 | $object = urlencode($_REQUEST[$_REQUEST['subject']]); |
||
| 104 | |||
| 105 | $actions = [ |
||
| 106 | 'drop' => [ |
||
| 107 | 'content' => $lang['strdrop'], |
||
| 108 | 'attr' => [ |
||
| 109 | 'href' => [ |
||
| 110 | 'url' => 'rules.php', |
||
| 111 | 'urlvars' => [ |
||
| 112 | 'action' => 'confirm_drop', |
||
| 113 | 'reltype' => $subject, |
||
| 114 | $subject => $object, |
||
| 115 | 'subject' => 'rule', |
||
| 116 | 'rule' => Decorator::field('rulename'), |
||
| 117 | ], |
||
| 118 | ], |
||
| 119 | ], |
||
| 120 | ], |
||
| 121 | ]; |
||
| 122 | |||
| 123 | echo $this->printTable($rules, $columns, $actions, 'rules-rules', $lang['strnorules']); |
||
| 124 | |||
| 125 | $this->printNavLinks(['create' => [ |
||
|
1 ignored issue
–
show
|
|||
| 126 | 'attr' => [ |
||
| 127 | 'href' => [ |
||
| 128 | 'url' => 'rules.php', |
||
| 129 | 'urlvars' => [ |
||
| 130 | 'action' => 'create_rule', |
||
| 131 | 'server' => $_REQUEST['server'], |
||
| 132 | 'database' => $_REQUEST['database'], |
||
| 133 | 'schema' => $_REQUEST['schema'], |
||
| 134 | $subject => $object, |
||
| 135 | 'subject' => $subject, |
||
| 136 | ], |
||
| 137 | ], |
||
| 138 | ], |
||
| 139 | 'content' => $lang['strcreaterule'], |
||
| 140 | ]], 'rules-rules', get_defined_vars()); |
||
|
1 ignored issue
–
show
|
|||
| 141 | } |
||
| 142 | |||
| 143 | public function doTree() |
||
|
1 ignored issue
–
show
|
|||
| 144 | { |
||
| 145 | $conf = $this->conf; |
||
| 146 | |||
| 147 | $lang = $this->lang; |
||
| 148 | $data = $this->misc->getDatabaseAccessor(); |
||
| 149 | |||
| 150 | $rules = $data->getRules($_REQUEST[$_REQUEST['subject']]); |
||
| 151 | |||
| 152 | $reqvars = $this->misc->getRequestVars($_REQUEST['subject']); |
||
| 153 | |||
| 154 | $attrs = [ |
||
| 155 | 'text' => Decorator::field('rulename'), |
||
| 156 | 'icon' => 'Rule', |
||
| 157 | ]; |
||
| 158 | |||
| 159 | return $this->printTree($rules, $attrs, 'rules'); |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Confirm and then actually create a rule. |
||
| 164 | * |
||
| 165 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 166 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 167 | */ |
||
| 168 | public function createRule($confirm, $msg = '') |
||
| 169 | { |
||
| 170 | $conf = $this->conf; |
||
| 171 | |||
| 172 | $lang = $this->lang; |
||
| 173 | $data = $this->misc->getDatabaseAccessor(); |
||
| 174 | |||
| 175 | if (!isset($_POST['name'])) { |
||
| 176 | $_POST['name'] = ''; |
||
| 177 | } |
||
| 178 | |||
| 179 | if (!isset($_POST['event'])) { |
||
| 180 | $_POST['event'] = ''; |
||
| 181 | } |
||
| 182 | |||
| 183 | if (!isset($_POST['where'])) { |
||
| 184 | $_POST['where'] = ''; |
||
| 185 | } |
||
| 186 | |||
| 187 | if (!isset($_POST['type'])) { |
||
| 188 | $_POST['type'] = 'SOMETHING'; |
||
| 189 | } |
||
| 190 | |||
| 191 | if (!isset($_POST['raction'])) { |
||
| 192 | $_POST['raction'] = ''; |
||
| 193 | } |
||
| 194 | |||
| 195 | if ($confirm) { |
||
| 196 | $this->printTrail($_REQUEST['subject']); |
||
| 197 | $this->printTitle($lang['strcreaterule'], 'pg.rule.create'); |
||
| 198 | $this->printMsg($msg); |
||
| 199 | |||
| 200 | echo '<form action="'.\SUBFOLDER."/src/views/rules.php\" method=\"post\">\n"; |
||
| 201 | echo "<table>\n"; |
||
| 202 | echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
| 203 | echo "<td class=\"data1\"><input name=\"name\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 204 | htmlspecialchars($_POST['name']), "\" /></td></tr>\n"; |
||
| 205 | echo "<tr><th class=\"data left required\">{$lang['strevent']}</th>\n"; |
||
| 206 | echo "<td class=\"data1\"><select name=\"event\">\n"; |
||
| 207 | foreach ($data->rule_events as $v) { |
||
| 208 | echo "<option value=\"{$v}\"", ($v == $_POST['event']) ? ' selected="selected"' : '', |
||
| 209 | ">{$v}</option>\n"; |
||
| 210 | } |
||
| 211 | echo "</select></td></tr>\n"; |
||
| 212 | echo "<tr><th class=\"data left\">{$lang['strwhere']}</th>\n"; |
||
| 213 | echo '<td class="data1"><input name="where" size="32" value="', |
||
| 214 | htmlspecialchars($_POST['where']), "\" /></td></tr>\n"; |
||
| 215 | echo "<tr><th class=\"data left\"><label for=\"instead\">{$lang['strinstead']}</label></th>\n"; |
||
| 216 | echo '<td class="data1">'; |
||
| 217 | echo '<input type="checkbox" id="instead" name="instead" ', (isset($_POST['instead'])) ? ' checked="checked"' : '', " />\n"; |
||
| 218 | echo "</td></tr>\n"; |
||
| 219 | echo "<tr><th class=\"data left required\">{$lang['straction']}</th>\n"; |
||
| 220 | echo '<td class="data1">'; |
||
| 221 | echo '<input type="radio" id="type1" name="type" value="NOTHING"', ('NOTHING' == $_POST['type']) ? ' checked="checked"' : '', " /> <label for=\"type1\">NOTHING</label><br />\n"; |
||
| 222 | echo '<input type="radio" name="type" value="SOMETHING"', ('SOMETHING' == $_POST['type']) ? ' checked="checked"' : '', " />\n"; |
||
| 223 | echo '(<input name="raction" size="32" value="', |
||
| 224 | htmlspecialchars($_POST['raction']), "\" />)</td></tr>\n"; |
||
| 225 | echo "</table>\n"; |
||
| 226 | |||
| 227 | echo "<input type=\"hidden\" name=\"action\" value=\"save_create_rule\" />\n"; |
||
| 228 | echo '<input type="hidden" name="subject" value="', htmlspecialchars($_REQUEST['subject']), "\" />\n"; |
||
| 229 | echo '<input type="hidden" name="', htmlspecialchars($_REQUEST['subject']), |
||
| 230 | '" value="', htmlspecialchars($_REQUEST[$_REQUEST['subject']]), "\" />\n"; |
||
| 231 | echo $this->misc->form; |
||
| 232 | echo "<p><input type=\"submit\" name=\"ok\" value=\"{$lang['strcreate']}\" />\n"; |
||
| 233 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 234 | echo "</form>\n"; |
||
| 235 | } else { |
||
| 236 | if ('' == trim($_POST['name'])) { |
||
| 237 | $this->createRule(true, $lang['strruleneedsname']); |
||
| 238 | } else { |
||
| 239 | $status = $data->createRule( |
||
| 240 | $_POST['name'], |
||
| 241 | $_POST['event'], |
||
| 242 | $_POST[$_POST['subject']], |
||
| 243 | $_POST['where'], |
||
| 244 | isset($_POST['instead']), |
||
| 245 | $_POST['type'], |
||
| 246 | $_POST['raction'] |
||
| 247 | ); |
||
| 248 | if (0 == $status) { |
||
| 249 | $this->doDefault($lang['strrulecreated']); |
||
| 250 | } else { |
||
| 251 | $this->createRule(true, $lang['strrulecreatedbad']); |
||
| 252 | } |
||
| 253 | } |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Show confirmation of drop and perform actual drop. |
||
| 259 | * |
||
| 260 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 261 | */ |
||
| 262 | public function doDrop($confirm) |
||
| 296 | } |
||
| 297 | } |
||
| 298 | } |
||
| 299 | } |
||
| 300 |