| Conditions | 28 |
| Paths | 1164 |
| Total Lines | 138 |
| Code Lines | 102 |
| 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 |
||
| 284 | public function doAlter($confirm, $mode, $msg = '') |
||
| 285 | { |
||
| 286 | $data = $this->misc->getDatabaseAccessor(); |
||
| 287 | |||
| 288 | $this->coalesceArr($_REQUEST, 'username', []); |
||
| 289 | |||
| 290 | $this->coalesceArr($_REQUEST, 'groupname', []); |
||
| 291 | |||
| 292 | $this->coalesceArr($_REQUEST, 'privilege', []); |
||
| 293 | |||
| 294 | if ($confirm) { |
||
| 295 | // Get users from the database |
||
| 296 | $users = $data->getUsers(); |
||
| 297 | // Get groups from the database |
||
| 298 | $groups = $data->getGroups(); |
||
| 299 | |||
| 300 | $this->printTrail($_REQUEST['subject']); |
||
| 301 | |||
| 302 | switch ($mode) { |
||
| 303 | case 'grant': |
||
| 304 | $this->printTitle($this->lang['strgrant'], 'pg.privilege.grant'); |
||
| 305 | |||
| 306 | break; |
||
| 307 | case 'revoke': |
||
| 308 | $this->printTitle($this->lang['strrevoke'], 'pg.privilege.revoke'); |
||
| 309 | |||
| 310 | break; |
||
| 311 | } |
||
| 312 | $this->printMsg($msg); |
||
| 313 | |||
| 314 | echo '<form action="'.\SUBFOLDER."/src/views/privileges\" method=\"post\">\n"; |
||
| 315 | echo "<table>\n"; |
||
| 316 | echo "<tr><th class=\"data left\">{$this->lang['strusers']}</th>\n"; |
||
| 317 | echo '<td class="data1"><select name="username[]" multiple="multiple" size="', min(6, $users->recordCount()), "\">\n"; |
||
| 318 | while (!$users->EOF) { |
||
| 319 | $uname = htmlspecialchars($users->fields['usename']); |
||
| 320 | echo "<option value=\"{$uname}\"", |
||
| 321 | in_array($users->fields['usename'], $_REQUEST['username'], true) ? ' selected="selected"' : '', ">{$uname}</option>\n"; |
||
| 322 | $users->moveNext(); |
||
| 323 | } |
||
| 324 | echo "</select></td></tr>\n"; |
||
| 325 | echo "<tr><th class=\"data left\">{$this->lang['strgroups']}</th>\n"; |
||
| 326 | echo "<td class=\"data1\">\n"; |
||
| 327 | echo '<input type="checkbox" id="public" name="public"', (isset($_REQUEST['public']) ? ' checked="checked"' : ''), " /><label for=\"public\">PUBLIC</label>\n"; |
||
| 328 | // Only show groups if there are groups! |
||
| 329 | if ($groups->recordCount() > 0) { |
||
| 330 | echo '<br /><select name="groupname[]" multiple="multiple" size="', min(6, $groups->recordCount()), "\">\n"; |
||
| 331 | while (!$groups->EOF) { |
||
| 332 | $gname = htmlspecialchars($groups->fields['groname']); |
||
| 333 | echo "<option value=\"{$gname}\"", |
||
| 334 | in_array($groups->fields['groname'], $_REQUEST['groupname'], true) ? ' selected="selected"' : '', ">{$gname}</option>\n"; |
||
| 335 | $groups->moveNext(); |
||
| 336 | } |
||
| 337 | echo "</select>\n"; |
||
| 338 | } |
||
| 339 | echo "</td></tr>\n"; |
||
| 340 | echo "<tr><th class=\"data left required\">{$this->lang['strprivileges']}</th>\n"; |
||
| 341 | echo "<td class=\"data1\">\n"; |
||
| 342 | foreach ($data->privlist[$_REQUEST['subject']] as $v) { |
||
| 343 | $v = htmlspecialchars($v); |
||
| 344 | echo "<input type=\"checkbox\" id=\"privilege[${v}]\" name=\"privilege[${v}]\"", |
||
| 345 | isset($_REQUEST['privilege'][$v]) ? ' checked="checked"' : '', " /><label for=\"privilege[${v}]\">{$v}</label><br />\n"; |
||
| 346 | } |
||
| 347 | echo "</td></tr>\n"; |
||
| 348 | // Grant option |
||
| 349 | if ($data->hasGrantOption()) { |
||
| 350 | echo "<tr><th class=\"data left\">{$this->lang['stroptions']}</th>\n"; |
||
| 351 | echo "<td class=\"data1\">\n"; |
||
| 352 | if ('grant' == $mode) { |
||
| 353 | echo '<input type="checkbox" id="grantoption" name="grantoption"', |
||
| 354 | isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', " /><label for=\"grantoption\">GRANT OPTION</label>\n"; |
||
| 355 | } elseif ('revoke' == $mode) { |
||
| 356 | echo '<input type="checkbox" id="grantoption" name="grantoption"', |
||
| 357 | isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', " /><label for=\"grantoption\">GRANT OPTION FOR</label><br />\n"; |
||
| 358 | echo '<input type="checkbox" id="cascade" name="cascade"', |
||
| 359 | isset($_REQUEST['cascade']) ? ' checked="checked"' : '', " /><label for=\"cascade\">CASCADE</label><br />\n"; |
||
| 360 | } |
||
| 361 | echo "</td></tr>\n"; |
||
| 362 | } |
||
| 363 | echo "</table>\n"; |
||
| 364 | |||
| 365 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save\" />\n"; |
||
| 366 | echo '<input type="hidden" name="mode" value="', htmlspecialchars($mode), "\" />\n"; |
||
| 367 | echo '<input type="hidden" name="subject" value="', htmlspecialchars($_REQUEST['subject']), "\" />\n"; |
||
| 368 | if (isset($_REQUEST[$_REQUEST['subject'].'_oid'])) { |
||
| 369 | echo '<input type="hidden" name="', htmlspecialchars($_REQUEST['subject'].'_oid'), |
||
| 370 | '" value="', htmlspecialchars($_REQUEST[$_REQUEST['subject'].'_oid']), "\" />\n"; |
||
| 371 | } |
||
| 372 | |||
| 373 | echo '<input type="hidden" name="', htmlspecialchars($_REQUEST['subject']), |
||
| 374 | '" value="', htmlspecialchars($_REQUEST[$_REQUEST['subject']]), "\" />\n"; |
||
| 375 | if ('column' == $_REQUEST['subject']) { |
||
| 376 | echo '<input type="hidden" name="table" value="', |
||
| 377 | htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
| 378 | } |
||
| 379 | |||
| 380 | echo $this->misc->form; |
||
| 381 | if ('grant' == $mode) { |
||
| 382 | echo "<input type=\"submit\" name=\"grant\" value=\"{$this->lang['strgrant']}\" />\n"; |
||
| 383 | } elseif ('revoke' == $mode) { |
||
| 384 | echo "<input type=\"submit\" name=\"revoke\" value=\"{$this->lang['strrevoke']}\" />\n"; |
||
| 385 | } |
||
| 386 | |||
| 387 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>"; |
||
| 388 | echo "</form>\n"; |
||
| 389 | } else { |
||
| 390 | // Determine whether object should be ref'd by name or oid. |
||
| 391 | if (isset($_REQUEST[$_REQUEST['subject'].'_oid'])) { |
||
| 392 | $object = $_REQUEST[$_REQUEST['subject'].'_oid']; |
||
| 393 | } else { |
||
| 394 | $object = $_REQUEST[$_REQUEST['subject']]; |
||
| 395 | } |
||
| 396 | |||
| 397 | if (isset($_REQUEST['table'])) { |
||
| 398 | $table = $_REQUEST['table']; |
||
| 399 | } else { |
||
| 400 | $table = null; |
||
| 401 | } |
||
| 402 | |||
| 403 | $status = $data->setPrivileges( |
||
| 404 | ('grant' == $mode) ? 'GRANT' : 'REVOKE', |
||
| 405 | $_REQUEST['subject'], |
||
| 406 | $object, |
||
| 407 | isset($_REQUEST['public']), |
||
| 408 | $_REQUEST['username'], |
||
| 409 | $_REQUEST['groupname'], |
||
| 410 | array_keys($_REQUEST['privilege']), |
||
| 411 | isset($_REQUEST['grantoption']), |
||
| 412 | isset($_REQUEST['cascade']), |
||
| 413 | $table |
||
| 414 | ); |
||
| 415 | |||
| 416 | if (0 == $status) { |
||
| 417 | $this->doDefault($this->lang['strgranted']); |
||
| 418 | } elseif ($status == -3 || $status == -4) { |
||
| 419 | $this->doAlter(true, $_REQUEST['mode'], $this->lang['strgrantbad']); |
||
| 420 | } else { |
||
| 421 | $this->doAlter(true, $_REQUEST['mode'], $this->lang['strgrantfailed']); |
||
| 422 | } |
||
| 426 |