| Conditions | 21 |
| Paths | 1152 |
| Total Lines | 104 |
| Code Lines | 75 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 283 | public function formAlter($mode, $msg = '') |
||
| 284 | { |
||
| 285 | $data = $this->misc->getDatabaseAccessor(); |
||
| 286 | |||
| 287 | $this->coalesceArr($_REQUEST, 'username', []); |
||
| 288 | |||
| 289 | $this->coalesceArr($_REQUEST, 'groupname', []); |
||
| 290 | |||
| 291 | $this->coalesceArr($_REQUEST, 'privilege', []); |
||
| 292 | |||
| 293 | // Get users from the database |
||
| 294 | $users = $data->getUsers(); |
||
| 295 | // Get groups from the database |
||
| 296 | $groups = $data->getGroups(); |
||
| 297 | |||
| 298 | $this->printTrail($_REQUEST['subject']); |
||
| 299 | |||
| 300 | switch ($mode) { |
||
| 301 | case 'grant': |
||
| 302 | $this->printTitle($this->lang['strgrant'], 'pg.privilege.grant'); |
||
| 303 | |||
| 304 | break; |
||
| 305 | case 'revoke': |
||
| 306 | $this->printTitle($this->lang['strrevoke'], 'pg.privilege.revoke'); |
||
| 307 | |||
| 308 | break; |
||
| 309 | } |
||
| 310 | $this->printMsg($msg); |
||
| 311 | |||
| 312 | echo '<form action="'.\SUBFOLDER."/src/views/privileges\" method=\"post\">\n"; |
||
| 313 | echo "<table>\n"; |
||
| 314 | echo "<tr><th class=\"data left\">{$this->lang['strusers']}</th>\n"; |
||
| 315 | echo '<td class="data1"><select name="username[]" multiple="multiple" size="', min(6, $users->recordCount()), "\">\n"; |
||
| 316 | while (!$users->EOF) { |
||
| 317 | $uname = htmlspecialchars($users->fields['usename']); |
||
| 318 | echo "<option value=\"{$uname}\"", |
||
| 319 | in_array($users->fields['usename'], $_REQUEST['username'], true) ? ' selected="selected"' : '', ">{$uname}</option>\n"; |
||
| 320 | $users->moveNext(); |
||
| 321 | } |
||
| 322 | echo "</select></td></tr>\n"; |
||
| 323 | echo "<tr><th class=\"data left\">{$this->lang['strgroups']}</th>\n"; |
||
| 324 | echo "<td class=\"data1\">\n"; |
||
| 325 | echo '<input type="checkbox" id="public" name="public"', (isset($_REQUEST['public']) ? ' checked="checked"' : ''), " /><label for=\"public\">PUBLIC</label>\n"; |
||
| 326 | // Only show groups if there are groups! |
||
| 327 | if ($groups->recordCount() > 0) { |
||
| 328 | echo '<br /><select name="groupname[]" multiple="multiple" size="', min(6, $groups->recordCount()), "\">\n"; |
||
| 329 | while (!$groups->EOF) { |
||
| 330 | $gname = htmlspecialchars($groups->fields['groname']); |
||
| 331 | echo "<option value=\"{$gname}\"", |
||
| 332 | in_array($groups->fields['groname'], $_REQUEST['groupname'], true) ? ' selected="selected"' : '', ">{$gname}</option>\n"; |
||
| 333 | $groups->moveNext(); |
||
| 334 | } |
||
| 335 | echo "</select>\n"; |
||
| 336 | } |
||
| 337 | echo "</td></tr>\n"; |
||
| 338 | echo "<tr><th class=\"data left required\">{$this->lang['strprivileges']}</th>\n"; |
||
| 339 | echo "<td class=\"data1\">\n"; |
||
| 340 | foreach ($data->privlist[$_REQUEST['subject']] as $v) { |
||
| 341 | $v = htmlspecialchars($v); |
||
| 342 | echo "<input type=\"checkbox\" id=\"privilege[${v}]\" name=\"privilege[${v}]\"", |
||
| 343 | isset($_REQUEST['privilege'][$v]) ? ' checked="checked"' : '', " /><label for=\"privilege[${v}]\">{$v}</label><br />\n"; |
||
| 344 | } |
||
| 345 | echo "</td></tr>\n"; |
||
| 346 | // Grant option |
||
| 347 | if ($data->hasGrantOption()) { |
||
| 348 | echo "<tr><th class=\"data left\">{$this->lang['stroptions']}</th>\n"; |
||
| 349 | echo "<td class=\"data1\">\n"; |
||
| 350 | if ('grant' == $mode) { |
||
| 351 | echo '<input type="checkbox" id="grantoption" name="grantoption"', |
||
| 352 | isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', " /><label for=\"grantoption\">GRANT OPTION</label>\n"; |
||
| 353 | } elseif ('revoke' == $mode) { |
||
| 354 | echo '<input type="checkbox" id="grantoption" name="grantoption"', |
||
| 355 | isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', " /><label for=\"grantoption\">GRANT OPTION FOR</label><br />\n"; |
||
| 356 | echo '<input type="checkbox" id="cascade" name="cascade"', |
||
| 357 | isset($_REQUEST['cascade']) ? ' checked="checked"' : '', " /><label for=\"cascade\">CASCADE</label><br />\n"; |
||
| 358 | } |
||
| 359 | echo "</td></tr>\n"; |
||
| 360 | } |
||
| 361 | echo "</table>\n"; |
||
| 362 | |||
| 363 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save\" />\n"; |
||
| 364 | echo '<input type="hidden" name="mode" value="', htmlspecialchars($mode), "\" />\n"; |
||
| 365 | echo '<input type="hidden" name="subject" value="', htmlspecialchars($_REQUEST['subject']), "\" />\n"; |
||
| 366 | if (isset($_REQUEST[$_REQUEST['subject'].'_oid'])) { |
||
| 367 | echo '<input type="hidden" name="', htmlspecialchars($_REQUEST['subject'].'_oid'), |
||
| 368 | '" value="', htmlspecialchars($_REQUEST[$_REQUEST['subject'].'_oid']), "\" />\n"; |
||
| 369 | } |
||
| 370 | |||
| 371 | echo '<input type="hidden" name="', htmlspecialchars($_REQUEST['subject']), |
||
| 372 | '" value="', htmlspecialchars($_REQUEST[$_REQUEST['subject']]), "\" />\n"; |
||
| 373 | if ('column' == $_REQUEST['subject']) { |
||
| 374 | echo '<input type="hidden" name="table" value="', |
||
| 375 | htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
| 376 | } |
||
| 377 | |||
| 378 | echo $this->misc->form; |
||
| 379 | if ('grant' == $mode) { |
||
| 380 | echo "<input type=\"submit\" name=\"grant\" value=\"{$this->lang['strgrant']}\" />\n"; |
||
| 381 | } elseif ('revoke' == $mode) { |
||
| 382 | echo "<input type=\"submit\" name=\"revoke\" value=\"{$this->lang['strrevoke']}\" />\n"; |
||
| 383 | } |
||
| 384 | |||
| 385 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>"; |
||
| 386 | echo "</form>\n"; |
||
| 387 | } |
||
| 439 |