| Total Complexity | 123 |
| Total Lines | 885 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like RolesController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use RolesController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class RolesController extends BaseController |
||
| 15 | { |
||
| 16 | public $controller_name = 'RolesController'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Default method to render the controller according to the action parameter. |
||
| 20 | */ |
||
| 21 | public function render() |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Show default list of roles in the database. |
||
| 98 | * |
||
| 99 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 100 | */ |
||
| 101 | public function doDefault($msg = '') |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Displays a screen for create a new role. |
||
| 219 | * |
||
| 220 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 221 | */ |
||
| 222 | public function doCreate($msg = '') |
||
| 223 | { |
||
| 224 | $conf = $this->conf; |
||
| 225 | |||
| 226 | $lang = $this->lang; |
||
| 227 | $data = $this->misc->getDatabaseAccessor(); |
||
| 228 | |||
| 229 | if (!isset($_POST['formRolename'])) { |
||
| 230 | $_POST['formRolename'] = ''; |
||
| 231 | } |
||
| 232 | |||
| 233 | if (!isset($_POST['formPassword'])) { |
||
| 234 | $_POST['formPassword'] = ''; |
||
| 235 | } |
||
| 236 | |||
| 237 | if (!isset($_POST['formConfirm'])) { |
||
| 238 | $_POST['formConfirm'] = ''; |
||
| 239 | } |
||
| 240 | |||
| 241 | if (!isset($_POST['formConnLimit'])) { |
||
| 242 | $_POST['formConnLimit'] = ''; |
||
| 243 | } |
||
| 244 | |||
| 245 | if (!isset($_POST['formExpires'])) { |
||
| 246 | $_POST['formExpires'] = ''; |
||
| 247 | } |
||
| 248 | |||
| 249 | if (!isset($_POST['memberof'])) { |
||
| 250 | $_POST['memberof'] = []; |
||
| 251 | } |
||
| 252 | |||
| 253 | if (!isset($_POST['members'])) { |
||
| 254 | $_POST['members'] = []; |
||
| 255 | } |
||
| 256 | |||
| 257 | if (!isset($_POST['adminmembers'])) { |
||
| 258 | $_POST['adminmembers'] = []; |
||
| 259 | } |
||
| 260 | |||
| 261 | $this->printTrail('role'); |
||
| 262 | $this->printTitle($lang['strcreaterole'], 'pg.role.create'); |
||
| 263 | $this->printMsg($msg); |
||
| 264 | |||
| 265 | echo '<form action="'.\SUBFOLDER."/src/views/roles.php\" method=\"post\">\n"; |
||
| 266 | echo "<table>\n"; |
||
| 267 | echo "\t<tr>\n\t\t<th class=\"data left required\" style=\"width: 130px\">{$lang['strname']}</th>\n"; |
||
| 268 | echo "\t\t<td class=\"data1\"><input size=\"15\" maxlength=\"{$data->_maxNameLen}\" name=\"formRolename\" value=\"", htmlspecialchars($_POST['formRolename']), "\" /></td>\n\t</tr>\n"; |
||
| 269 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strpassword']}</th>\n"; |
||
| 270 | echo "\t\t<td class=\"data1\"><input size=\"15\" type=\"password\" name=\"formPassword\" value=\"", htmlspecialchars($_POST['formPassword']), "\" /></td>\n\t</tr>\n"; |
||
| 271 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strconfirm']}</th>\n"; |
||
| 272 | echo "\t\t<td class=\"data1\"><input size=\"15\" type=\"password\" name=\"formConfirm\" value=\"", htmlspecialchars($_POST['formConfirm']), "\" /></td>\n\t</tr>\n"; |
||
| 273 | echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formSuper\">{$lang['strsuper']}</label></th>\n"; |
||
| 274 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formSuper\" name=\"formSuper\"", |
||
| 275 | (isset($_POST['formSuper'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>\n"; |
||
| 276 | echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formCreateDB\">{$lang['strcreatedb']}</label></th>\n"; |
||
| 277 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCreateDB\" name=\"formCreateDB\"", |
||
| 278 | (isset($_POST['formCreateDB'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>\n"; |
||
| 279 | echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formCreateRole\">{$lang['strcancreaterole']}</label></th>\n"; |
||
| 280 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCreateRole\" name=\"formCreateRole\"", |
||
| 281 | (isset($_POST['formCreateRole'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>\n"; |
||
| 282 | echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formInherits\">{$lang['strinheritsprivs']}</label></th>\n"; |
||
| 283 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formInherits\" name=\"formInherits\"", |
||
| 284 | (isset($_POST['formInherits'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>\n"; |
||
| 285 | echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formCanLogin\">{$lang['strcanlogin']}</label></th>\n"; |
||
| 286 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCanLogin\" name=\"formCanLogin\"", |
||
| 287 | (isset($_POST['formCanLogin'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>\n"; |
||
| 288 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strconnlimit']}</th>\n"; |
||
| 289 | echo "\t\t<td class=\"data1\"><input size=\"4\" name=\"formConnLimit\" value=\"", htmlspecialchars($_POST['formConnLimit']), "\" /></td>\n\t</tr>\n"; |
||
| 290 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strexpires']}</th>\n"; |
||
| 291 | echo "\t\t<td class=\"data1\"><input size=\"23\" name=\"formExpires\" value=\"", htmlspecialchars($_POST['formExpires']), "\" /></td>\n\t</tr>\n"; |
||
| 292 | |||
| 293 | $roles = $data->getRoles(); |
||
| 294 | if ($roles->recordCount() > 0) { |
||
| 295 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strmemberof']}</th>\n"; |
||
| 296 | echo "\t\t<td class=\"data\">\n"; |
||
| 297 | echo "\t\t\t<select name=\"memberof[]\" multiple=\"multiple\" size=\"", min(20, $roles->recordCount()), "\">\n"; |
||
| 298 | while (!$roles->EOF) { |
||
| 299 | $rolename = $roles->fields['rolname']; |
||
| 300 | echo "\t\t\t\t<option value=\"{$rolename}\"", |
||
| 301 | (in_array($rolename, $_POST['memberof'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), "</option>\n"; |
||
| 302 | $roles->moveNext(); |
||
| 303 | } |
||
| 304 | echo "\t\t\t</select>\n"; |
||
| 305 | echo "\t\t</td>\n\t</tr>\n"; |
||
| 306 | |||
| 307 | $roles->moveFirst(); |
||
| 308 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strmembers']}</th>\n"; |
||
| 309 | echo "\t\t<td class=\"data\">\n"; |
||
| 310 | echo "\t\t\t<select name=\"members[]\" multiple=\"multiple\" size=\"", min(20, $roles->recordCount()), "\">\n"; |
||
| 311 | while (!$roles->EOF) { |
||
| 312 | $rolename = $roles->fields['rolname']; |
||
| 313 | echo "\t\t\t\t<option value=\"{$rolename}\"", |
||
| 314 | (in_array($rolename, $_POST['members'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), "</option>\n"; |
||
| 315 | $roles->moveNext(); |
||
| 316 | } |
||
| 317 | echo "\t\t\t</select>\n"; |
||
| 318 | echo "\t\t</td>\n\t</tr>\n"; |
||
| 319 | |||
| 320 | $roles->moveFirst(); |
||
| 321 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['stradminmembers']}</th>\n"; |
||
| 322 | echo "\t\t<td class=\"data\">\n"; |
||
| 323 | echo "\t\t\t<select name=\"adminmembers[]\" multiple=\"multiple\" size=\"", min(20, $roles->recordCount()), "\">\n"; |
||
| 324 | while (!$roles->EOF) { |
||
| 325 | $rolename = $roles->fields['rolname']; |
||
| 326 | echo "\t\t\t\t<option value=\"{$rolename}\"", |
||
| 327 | (in_array($rolename, $_POST['adminmembers'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), "</option>\n"; |
||
| 328 | $roles->moveNext(); |
||
| 329 | } |
||
| 330 | echo "\t\t\t</select>\n"; |
||
| 331 | echo "\t\t</td>\n\t</tr>\n"; |
||
| 332 | } |
||
| 333 | |||
| 334 | echo "</table>\n"; |
||
| 335 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n"; |
||
| 336 | echo $this->misc->form; |
||
| 337 | echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n"; |
||
| 338 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 339 | echo "</form>\n"; |
||
| 340 | } |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Actually creates the new role in the database. |
||
| 344 | */ |
||
| 345 | public function doSaveCreate() |
||
| 346 | { |
||
| 347 | $conf = $this->conf; |
||
| 348 | |||
| 349 | $lang = $this->lang; |
||
| 350 | $data = $this->misc->getDatabaseAccessor(); |
||
| 351 | |||
| 352 | if (!isset($_POST['memberof'])) { |
||
| 353 | $_POST['memberof'] = []; |
||
| 354 | } |
||
| 355 | |||
| 356 | if (!isset($_POST['members'])) { |
||
| 357 | $_POST['members'] = []; |
||
| 358 | } |
||
| 359 | |||
| 360 | if (!isset($_POST['adminmembers'])) { |
||
| 361 | $_POST['adminmembers'] = []; |
||
| 362 | } |
||
| 363 | |||
| 364 | // Check data |
||
| 365 | if ('' == $_POST['formRolename']) { |
||
| 366 | $this->doCreate($lang['strroleneedsname']); |
||
| 367 | } elseif ($_POST['formPassword'] != $_POST['formConfirm']) { |
||
| 368 | $this->doCreate($lang['strpasswordconfirm']); |
||
| 369 | } else { |
||
| 370 | $status = $data->createRole( |
||
| 371 | $_POST['formRolename'], |
||
| 372 | $_POST['formPassword'], |
||
| 373 | isset($_POST['formSuper']), |
||
| 374 | isset($_POST['formCreateDB']), |
||
| 375 | isset($_POST['formCreateRole']), |
||
| 376 | isset($_POST['formInherits']), |
||
| 377 | isset($_POST['formCanLogin']), |
||
| 378 | $_POST['formConnLimit'], |
||
| 379 | $_POST['formExpires'], |
||
| 380 | $_POST['memberof'], |
||
| 381 | $_POST['members'], |
||
| 382 | $_POST['adminmembers'] |
||
| 383 | ); |
||
| 384 | if (0 == $status) { |
||
| 385 | $this->doDefault($lang['strrolecreated']); |
||
| 386 | } else { |
||
| 387 | $this->doCreate($lang['strrolecreatedbad']); |
||
| 388 | } |
||
| 389 | } |
||
| 390 | } |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Function to allow alter a role. |
||
| 394 | * |
||
| 395 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 396 | */ |
||
| 397 | public function doAlter($msg = '') |
||
| 398 | { |
||
| 399 | $conf = $this->conf; |
||
| 400 | |||
| 401 | $lang = $this->lang; |
||
| 402 | $data = $this->misc->getDatabaseAccessor(); |
||
| 403 | |||
| 404 | $this->printTrail('role'); |
||
| 405 | $this->printTitle($lang['stralter'], 'pg.role.alter'); |
||
| 406 | $this->printMsg($msg); |
||
| 407 | |||
| 408 | $roledata = $data->getRole($_REQUEST['rolename']); |
||
| 409 | |||
| 410 | if ($roledata->recordCount() > 0) { |
||
| 411 | $server_info = $this->misc->getServerInfo(); |
||
| 412 | $canRename = $data->hasUserRename() && ($_REQUEST['rolename'] != $server_info['username']); |
||
| 413 | $roledata->fields['rolsuper'] = $data->phpBool($roledata->fields['rolsuper']); |
||
| 414 | $roledata->fields['rolcreatedb'] = $data->phpBool($roledata->fields['rolcreatedb']); |
||
| 415 | $roledata->fields['rolcreaterole'] = $data->phpBool($roledata->fields['rolcreaterole']); |
||
| 416 | $roledata->fields['rolinherit'] = $data->phpBool($roledata->fields['rolinherit']); |
||
| 417 | $roledata->fields['rolcanlogin'] = $data->phpBool($roledata->fields['rolcanlogin']); |
||
| 418 | |||
| 419 | if (!isset($_POST['formExpires'])) { |
||
| 420 | if ($canRename) { |
||
| 421 | $_POST['formNewRoleName'] = $roledata->fields['rolname']; |
||
| 422 | } |
||
| 423 | |||
| 424 | if ($roledata->fields['rolsuper']) { |
||
| 425 | $_POST['formSuper'] = ''; |
||
| 426 | } |
||
| 427 | |||
| 428 | if ($roledata->fields['rolcreatedb']) { |
||
| 429 | $_POST['formCreateDB'] = ''; |
||
| 430 | } |
||
| 431 | |||
| 432 | if ($roledata->fields['rolcreaterole']) { |
||
| 433 | $_POST['formCreateRole'] = ''; |
||
| 434 | } |
||
| 435 | |||
| 436 | if ($roledata->fields['rolinherit']) { |
||
| 437 | $_POST['formInherits'] = ''; |
||
| 438 | } |
||
| 439 | |||
| 440 | if ($roledata->fields['rolcanlogin']) { |
||
| 441 | $_POST['formCanLogin'] = ''; |
||
| 442 | } |
||
| 443 | |||
| 444 | $_POST['formConnLimit'] = '-1' == $roledata->fields['rolconnlimit'] ? '' : $roledata->fields['rolconnlimit']; |
||
| 445 | $_POST['formExpires'] = 'infinity' == $roledata->fields['rolvaliduntil'] ? '' : $roledata->fields['rolvaliduntil']; |
||
| 446 | $_POST['formPassword'] = ''; |
||
| 447 | } |
||
| 448 | |||
| 449 | echo '<form action="'.\SUBFOLDER."/src/views/roles.php\" method=\"post\">\n"; |
||
| 450 | echo "<table>\n"; |
||
| 451 | echo "\t<tr>\n\t\t<th class=\"data left\" style=\"width: 130px\">{$lang['strname']}</th>\n"; |
||
| 452 | echo "\t\t<td class=\"data1\">", ($canRename ? "<input name=\"formNewRoleName\" size=\"15\" maxlength=\"{$data->_maxNameLen}\" value=\"".htmlspecialchars($_POST['formNewRoleName']).'" />' : $this->misc->printVal($roledata->fields['rolname'])), "</td>\n\t</tr>\n"; |
||
| 453 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strpassword']}</th>\n"; |
||
| 454 | echo "\t\t<td class=\"data1\"><input type=\"password\" size=\"15\" name=\"formPassword\" value=\"", htmlspecialchars($_POST['formPassword']), "\" /></td>\n\t</tr>\n"; |
||
| 455 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strconfirm']}</th>\n"; |
||
| 456 | echo "\t\t<td class=\"data1\"><input type=\"password\" size=\"15\" name=\"formConfirm\" value=\"\" /></td>\n\t</tr>\n"; |
||
| 457 | echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formSuper\">{$lang['strsuper']}</label></th>\n"; |
||
| 458 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formSuper\" name=\"formSuper\"", |
||
| 459 | (isset($_POST['formSuper'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>\n"; |
||
| 460 | echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formCreateDB\">{$lang['strcreatedb']}</label></th>\n"; |
||
| 461 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCreateDB\" name=\"formCreateDB\"", |
||
| 462 | (isset($_POST['formCreateDB'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>\n"; |
||
| 463 | echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formCreateRole\">{$lang['strcancreaterole']}</label></th>\n"; |
||
| 464 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCreateRole\" name=\"formCreateRole\"", |
||
| 465 | (isset($_POST['formCreateRole'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>\n"; |
||
| 466 | echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formInherits\">{$lang['strinheritsprivs']}</label></th>\n"; |
||
| 467 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formInherits\" name=\"formInherits\"", |
||
| 468 | (isset($_POST['formInherits'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>\n"; |
||
| 469 | echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formCanLogin\">{$lang['strcanlogin']}</label></th>\n"; |
||
| 470 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCanLogin\" name=\"formCanLogin\"", |
||
| 471 | (isset($_POST['formCanLogin'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>\n"; |
||
| 472 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strconnlimit']}</th>\n"; |
||
| 473 | echo "\t\t<td class=\"data1\"><input size=\"4\" name=\"formConnLimit\" value=\"", htmlspecialchars($_POST['formConnLimit']), "\" /></td>\n\t</tr>\n"; |
||
| 474 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strexpires']}</th>\n"; |
||
| 475 | echo "\t\t<td class=\"data1\"><input size=\"23\" name=\"formExpires\" value=\"", htmlspecialchars($_POST['formExpires']), "\" /></td>\n\t</tr>\n"; |
||
| 476 | |||
| 477 | if (!isset($_POST['memberof'])) { |
||
| 478 | $memberof = $data->getMemberOf($_REQUEST['rolename']); |
||
| 479 | if ($memberof->recordCount() > 0) { |
||
| 480 | $i = 0; |
||
| 481 | while (!$memberof->EOF) { |
||
| 482 | $_POST['memberof'][$i++] = $memberof->fields['rolname']; |
||
| 483 | $memberof->moveNext(); |
||
| 484 | } |
||
| 485 | } else { |
||
| 486 | $_POST['memberof'] = []; |
||
| 487 | } |
||
| 488 | |||
| 489 | $memberofold = implode(',', $_POST['memberof']); |
||
| 490 | } |
||
| 491 | if (!isset($_POST['members'])) { |
||
| 492 | $members = $data->getMembers($_REQUEST['rolename']); |
||
| 493 | if ($members->recordCount() > 0) { |
||
| 494 | $i = 0; |
||
| 495 | while (!$members->EOF) { |
||
| 496 | $_POST['members'][$i++] = $members->fields['rolname']; |
||
| 497 | $members->moveNext(); |
||
| 498 | } |
||
| 499 | } else { |
||
| 500 | $_POST['members'] = []; |
||
| 501 | } |
||
| 502 | |||
| 503 | $membersold = implode(',', $_POST['members']); |
||
| 504 | } |
||
| 505 | if (!isset($_POST['adminmembers'])) { |
||
| 506 | $adminmembers = $data->getMembers($_REQUEST['rolename'], 't'); |
||
| 507 | if ($adminmembers->recordCount() > 0) { |
||
| 508 | $i = 0; |
||
| 509 | while (!$adminmembers->EOF) { |
||
| 510 | $_POST['adminmembers'][$i++] = $adminmembers->fields['rolname']; |
||
| 511 | $adminmembers->moveNext(); |
||
| 512 | } |
||
| 513 | } else { |
||
| 514 | $_POST['adminmembers'] = []; |
||
| 515 | } |
||
| 516 | |||
| 517 | $adminmembersold = implode(',', $_POST['adminmembers']); |
||
| 518 | } |
||
| 519 | |||
| 520 | $roles = $data->getRoles($_REQUEST['rolename']); |
||
| 521 | if ($roles->recordCount() > 0) { |
||
| 522 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strmemberof']}</th>\n"; |
||
| 523 | echo "\t\t<td class=\"data\">\n"; |
||
| 524 | echo "\t\t\t<select name=\"memberof[]\" multiple=\"multiple\" size=\"", min(20, $roles->recordCount()), "\">\n"; |
||
| 525 | while (!$roles->EOF) { |
||
| 526 | $rolename = $roles->fields['rolname']; |
||
| 527 | echo "\t\t\t\t<option value=\"{$rolename}\"", |
||
| 528 | (in_array($rolename, $_POST['memberof'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), "</option>\n"; |
||
| 529 | $roles->moveNext(); |
||
| 530 | } |
||
| 531 | echo "\t\t\t</select>\n"; |
||
| 532 | echo "\t\t</td>\n\t</tr>\n"; |
||
| 533 | |||
| 534 | $roles->moveFirst(); |
||
| 535 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strmembers']}</th>\n"; |
||
| 536 | echo "\t\t<td class=\"data\">\n"; |
||
| 537 | echo "\t\t\t<select name=\"members[]\" multiple=\"multiple\" size=\"", min(20, $roles->recordCount()), "\">\n"; |
||
| 538 | while (!$roles->EOF) { |
||
| 539 | $rolename = $roles->fields['rolname']; |
||
| 540 | echo "\t\t\t\t<option value=\"{$rolename}\"", |
||
| 541 | (in_array($rolename, $_POST['members'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), "</option>\n"; |
||
| 542 | $roles->moveNext(); |
||
| 543 | } |
||
| 544 | echo "\t\t\t</select>\n"; |
||
| 545 | echo "\t\t</td>\n\t</tr>\n"; |
||
| 546 | |||
| 547 | $roles->moveFirst(); |
||
| 548 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['stradminmembers']}</th>\n"; |
||
| 549 | echo "\t\t<td class=\"data\">\n"; |
||
| 550 | echo "\t\t\t<select name=\"adminmembers[]\" multiple=\"multiple\" size=\"", min(20, $roles->recordCount()), "\">\n"; |
||
| 551 | while (!$roles->EOF) { |
||
| 552 | $rolename = $roles->fields['rolname']; |
||
| 553 | echo "\t\t\t\t<option value=\"{$rolename}\"", |
||
| 554 | (in_array($rolename, $_POST['adminmembers'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), "</option>\n"; |
||
| 555 | $roles->moveNext(); |
||
| 556 | } |
||
| 557 | echo "\t\t\t</select>\n"; |
||
| 558 | echo "\t\t</td>\n\t</tr>\n"; |
||
| 559 | } |
||
| 560 | echo "</table>\n"; |
||
| 561 | |||
| 562 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_alter\" />\n"; |
||
| 563 | echo '<input type="hidden" name="rolename" value="', htmlspecialchars($_REQUEST['rolename']), "\" />\n"; |
||
| 564 | echo '<input type="hidden" name="memberofold" value="', isset($_POST['memberofold']) ? $_POST['memberofold'] : htmlspecialchars($memberofold), "\" />\n"; |
||
| 565 | echo '<input type="hidden" name="membersold" value="', isset($_POST['membersold']) ? $_POST['membersold'] : htmlspecialchars($membersold), "\" />\n"; |
||
| 566 | echo '<input type="hidden" name="adminmembersold" value="', isset($_POST['adminmembersold']) ? $_POST['adminmembersold'] : htmlspecialchars($adminmembersold), "\" />\n"; |
||
| 567 | echo $this->misc->form; |
||
| 568 | echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n"; |
||
| 569 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 570 | echo "</form>\n"; |
||
| 571 | } else { |
||
| 572 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
| 573 | } |
||
| 574 | } |
||
| 575 | |||
| 576 | /** |
||
| 577 | * Function to save after editing a role. |
||
| 578 | */ |
||
| 579 | public function doSaveAlter() |
||
| 580 | { |
||
| 581 | $conf = $this->conf; |
||
| 582 | |||
| 583 | $lang = $this->lang; |
||
| 584 | $data = $this->misc->getDatabaseAccessor(); |
||
| 585 | |||
| 586 | if (!isset($_POST['memberof'])) { |
||
| 587 | $_POST['memberof'] = []; |
||
| 588 | } |
||
| 589 | |||
| 590 | if (!isset($_POST['members'])) { |
||
| 591 | $_POST['members'] = []; |
||
| 592 | } |
||
| 593 | |||
| 594 | if (!isset($_POST['adminmembers'])) { |
||
| 595 | $_POST['adminmembers'] = []; |
||
| 596 | } |
||
| 597 | |||
| 598 | // Check name and password |
||
| 599 | if (isset($_POST['formNewRoleName']) && '' == $_POST['formNewRoleName']) { |
||
| 600 | $this->doAlter($lang['strroleneedsname']); |
||
| 601 | } elseif ($_POST['formPassword'] != $_POST['formConfirm']) { |
||
| 602 | $this->doAlter($lang['strpasswordconfirm']); |
||
| 603 | } else { |
||
| 604 | if (isset($_POST['formNewRoleName'])) { |
||
| 605 | $status = $data->setRenameRole($_POST['rolename'], $_POST['formPassword'], isset($_POST['formSuper']), isset($_POST['formCreateDB']), isset($_POST['formCreateRole']), isset($_POST['formInherits']), isset($_POST['formCanLogin']), $_POST['formConnLimit'], $_POST['formExpires'], $_POST['memberof'], $_POST['members'], $_POST['adminmembers'], $_POST['memberofold'], $_POST['membersold'], $_POST['adminmembersold'], $_POST['formNewRoleName']); |
||
| 606 | } else { |
||
| 607 | $status = $data->setRole($_POST['rolename'], $_POST['formPassword'], isset($_POST['formSuper']), isset($_POST['formCreateDB']), isset($_POST['formCreateRole']), isset($_POST['formInherits']), isset($_POST['formCanLogin']), $_POST['formConnLimit'], $_POST['formExpires'], $_POST['memberof'], $_POST['members'], $_POST['adminmembers'], $_POST['memberofold'], $_POST['membersold'], $_POST['adminmembersold']); |
||
| 608 | } |
||
| 609 | |||
| 610 | if (0 == $status) { |
||
| 611 | $this->doDefault($lang['strrolealtered']); |
||
| 612 | } else { |
||
| 613 | $this->doAlter($lang['strrolealteredbad']); |
||
| 614 | } |
||
| 615 | } |
||
| 616 | } |
||
| 617 | |||
| 618 | /** |
||
| 619 | * Show confirmation of drop a role and perform actual drop. |
||
| 620 | * |
||
| 621 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 622 | */ |
||
| 623 | public function doDrop($confirm) |
||
| 624 | { |
||
| 625 | $conf = $this->conf; |
||
| 626 | |||
| 627 | $lang = $this->lang; |
||
| 628 | $data = $this->misc->getDatabaseAccessor(); |
||
| 629 | |||
| 630 | if ($confirm) { |
||
| 631 | $this->printTrail('role'); |
||
| 632 | $this->printTitle($lang['strdroprole'], 'pg.role.drop'); |
||
| 633 | |||
| 634 | echo '<p>', sprintf($lang['strconfdroprole'], $this->misc->printVal($_REQUEST['rolename'])), "</p>\n"; |
||
| 635 | |||
| 636 | echo '<form action="'.\SUBFOLDER."/src/views/roles.php\" method=\"post\">\n"; |
||
| 637 | echo "<p><input type=\"hidden\" name=\"action\" value=\"drop\" />\n"; |
||
| 638 | echo '<input type="hidden" name="rolename" value="', htmlspecialchars($_REQUEST['rolename']), "\" />\n"; |
||
| 639 | echo $this->misc->form; |
||
| 640 | echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n"; |
||
| 641 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 642 | echo "</form>\n"; |
||
| 643 | } else { |
||
| 644 | $status = $data->dropRole($_REQUEST['rolename']); |
||
| 645 | if (0 == $status) { |
||
| 646 | $this->doDefault($lang['strroledropped']); |
||
| 647 | } else { |
||
| 648 | $this->doDefault($lang['strroledroppedbad']); |
||
| 649 | } |
||
| 650 | } |
||
| 651 | } |
||
| 652 | |||
| 653 | /** |
||
| 654 | * Show the properties of a role. |
||
| 655 | * |
||
| 656 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 657 | */ |
||
| 658 | public function doProperties($msg = '') |
||
| 659 | { |
||
| 660 | $conf = $this->conf; |
||
| 661 | |||
| 662 | $lang = $this->lang; |
||
| 663 | $data = $this->misc->getDatabaseAccessor(); |
||
| 664 | |||
| 665 | $this->printTrail('role'); |
||
| 666 | $this->printTitle($lang['strproperties'], 'pg.role'); |
||
| 667 | $this->printMsg($msg); |
||
| 668 | |||
| 669 | $roledata = $data->getRole($_REQUEST['rolename']); |
||
| 670 | if ($roledata->recordCount() > 0) { |
||
| 671 | $roledata->fields['rolsuper'] = $data->phpBool($roledata->fields['rolsuper']); |
||
| 672 | $roledata->fields['rolcreatedb'] = $data->phpBool($roledata->fields['rolcreatedb']); |
||
| 673 | $roledata->fields['rolcreaterole'] = $data->phpBool($roledata->fields['rolcreaterole']); |
||
| 674 | $roledata->fields['rolinherit'] = $data->phpBool($roledata->fields['rolinherit']); |
||
| 675 | $roledata->fields['rolcanlogin'] = $data->phpBool($roledata->fields['rolcanlogin']); |
||
| 676 | |||
| 677 | echo "<table>\n"; |
||
| 678 | echo "\t<tr>\n\t\t<th class=\"data\" style=\"width: 130px\">Description</th>\n"; |
||
| 679 | echo "\t\t<th class=\"data\" style=\"width: 120\">Value</th>\n\t</tr>\n"; |
||
| 680 | echo "\t<tr>\n\t\t<td class=\"data1\">{$lang['strname']}</td>\n"; |
||
| 681 | echo "\t\t<td class=\"data1\">", htmlspecialchars($_REQUEST['rolename']), "</td>\n\t</tr>\n"; |
||
| 682 | echo "\t<tr>\n\t\t<td class=\"data2\">{$lang['strsuper']}</td>\n"; |
||
| 683 | echo "\t\t<td class=\"data2\">", (($roledata->fields['rolsuper']) ? $lang['stryes'] : $lang['strno']), "</td>\n\t</tr>\n"; |
||
| 684 | echo "\t<tr>\n\t\t<td class=\"data1\">{$lang['strcreatedb']}</td>\n"; |
||
| 685 | echo "\t\t<td class=\"data1\">", (($roledata->fields['rolcreatedb']) ? $lang['stryes'] : $lang['strno']), "</td>\n"; |
||
| 686 | echo "\t<tr>\n\t\t<td class=\"data2\">{$lang['strcancreaterole']}</td>\n"; |
||
| 687 | echo "\t\t<td class=\"data2\">", (($roledata->fields['rolcreaterole']) ? $lang['stryes'] : $lang['strno']), "</td>\n"; |
||
| 688 | echo "\t<tr>\n\t\t<td class=\"data1\">{$lang['strinheritsprivs']}</td>\n"; |
||
| 689 | echo "\t\t<td class=\"data1\">", (($roledata->fields['rolinherit']) ? $lang['stryes'] : $lang['strno']), "</td>\n"; |
||
| 690 | echo "\t<tr>\n\t\t<td class=\"data2\">{$lang['strcanlogin']}</td>\n"; |
||
| 691 | echo "\t\t<td class=\"data2\">", (($roledata->fields['rolcanlogin']) ? $lang['stryes'] : $lang['strno']), "</td>\n"; |
||
| 692 | echo "\t<tr>\n\t\t<td class=\"data1\">{$lang['strconnlimit']}</td>\n"; |
||
| 693 | echo "\t\t<td class=\"data1\">", ('-1' == $roledata->fields['rolconnlimit'] ? $lang['strnolimit'] : $this->misc->printVal($roledata->fields['rolconnlimit'])), "</td>\n"; |
||
| 694 | echo "\t<tr>\n\t\t<td class=\"data2\">{$lang['strexpires']}</td>\n"; |
||
| 695 | echo "\t\t<td class=\"data2\">", ('infinity' == $roledata->fields['rolvaliduntil'] || is_null($roledata->fields['rolvaliduntil']) ? $lang['strnever'] : $this->misc->printVal($roledata->fields['rolvaliduntil'])), "</td>\n"; |
||
| 696 | echo "\t<tr>\n\t\t<td class=\"data1\">{$lang['strsessiondefaults']}</td>\n"; |
||
| 697 | echo "\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolconfig']), "</td>\n"; |
||
| 698 | echo "\t<tr>\n\t\t<td class=\"data2\">{$lang['strmemberof']}</td>\n"; |
||
| 699 | echo "\t\t<td class=\"data2\">"; |
||
| 700 | $memberof = $data->getMemberOf($_REQUEST['rolename']); |
||
| 701 | if ($memberof->recordCount() > 0) { |
||
| 702 | while (!$memberof->EOF) { |
||
| 703 | echo $this->misc->printVal($memberof->fields['rolname']), "<br />\n"; |
||
| 704 | $memberof->moveNext(); |
||
| 705 | } |
||
| 706 | } |
||
| 707 | echo "</td>\n\t</tr>\n"; |
||
| 708 | echo "\t<tr>\n\t\t<td class=\"data1\">{$lang['strmembers']}</td>\n"; |
||
| 709 | echo "\t\t<td class=\"data1\">"; |
||
| 710 | $members = $data->getMembers($_REQUEST['rolename']); |
||
| 711 | if ($members->recordCount() > 0) { |
||
| 712 | while (!$members->EOF) { |
||
| 713 | echo $this->misc->printVal($members->fields['rolname']), "<br />\n"; |
||
| 714 | $members->moveNext(); |
||
| 715 | } |
||
| 716 | } |
||
| 717 | echo "</td>\n\t</tr>\n"; |
||
| 718 | echo "\t<tr>\n\t\t<td class=\"data2\">{$lang['stradminmembers']}</td>\n"; |
||
| 719 | echo "\t\t<td class=\"data2\">"; |
||
| 720 | $adminmembers = $data->getMembers($_REQUEST['rolename'], 't'); |
||
| 721 | if ($adminmembers->recordCount() > 0) { |
||
| 722 | while (!$adminmembers->EOF) { |
||
| 723 | echo $this->misc->printVal($adminmembers->fields['rolname']), "<br />\n"; |
||
| 724 | $adminmembers->moveNext(); |
||
| 725 | } |
||
| 726 | } |
||
| 727 | echo "</td>\n\t</tr>\n"; |
||
| 728 | echo "</table>\n"; |
||
| 729 | } else { |
||
| 730 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
| 731 | } |
||
| 732 | |||
| 733 | $navlinks = [ |
||
| 734 | 'showall' => [ |
||
| 735 | 'attr' => [ |
||
| 736 | 'href' => [ |
||
| 737 | 'url' => 'roles.php', |
||
| 738 | 'urlvars' => [ |
||
| 739 | 'server' => $_REQUEST['server'], |
||
| 740 | ], |
||
| 741 | ], |
||
| 742 | ], |
||
| 743 | 'content' => $lang['strshowallroles'], |
||
| 744 | ], |
||
| 745 | 'alter' => [ |
||
| 746 | 'attr' => [ |
||
| 747 | 'href' => [ |
||
| 748 | 'url' => 'roles.php', |
||
| 749 | 'urlvars' => [ |
||
| 750 | 'action' => 'alter', |
||
| 751 | 'server' => $_REQUEST['server'], |
||
| 752 | 'rolename' => $_REQUEST['rolename'], |
||
| 753 | ], |
||
| 754 | ], |
||
| 755 | ], |
||
| 756 | 'content' => $lang['stralter'], |
||
| 757 | ], |
||
| 758 | 'drop' => [ |
||
| 759 | 'attr' => [ |
||
| 760 | 'href' => [ |
||
| 761 | 'url' => 'roles.php', |
||
| 762 | 'urlvars' => [ |
||
| 763 | 'action' => 'confirm_drop', |
||
| 764 | 'server' => $_REQUEST['server'], |
||
| 765 | 'rolename' => $_REQUEST['rolename'], |
||
| 766 | ], |
||
| 767 | ], |
||
| 768 | ], |
||
| 769 | 'content' => $lang['strdrop'], |
||
| 770 | ], |
||
| 771 | ]; |
||
| 772 | |||
| 773 | $this->printNavLinks($navlinks, 'roles-properties', get_defined_vars()); |
||
| 774 | } |
||
| 775 | |||
| 776 | /** |
||
| 777 | * If a role is not a superuser role, then we have an 'account management' |
||
| 778 | * page for change his password, etc. We don't prevent them from |
||
| 779 | * messing with the URL to gain access to other role admin stuff, because |
||
| 780 | * the PostgreSQL permissions will prevent them changing anything anyway. |
||
| 781 | * |
||
| 782 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 783 | */ |
||
| 784 | public function doAccount($msg = '') |
||
| 840 | } |
||
| 841 | |||
| 842 | /** |
||
| 843 | * Show confirmation of change password and actually change password. |
||
| 844 | * |
||
| 845 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 846 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 847 | */ |
||
| 848 | public function doChangePassword($confirm, $msg = '') |
||
| 899 | } |
||
| 900 | } |
||
| 904 |