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