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