getPrivileges(); # Set starting index $Index = 0; $Counter = 0; # Loop through each privilege foreach ($Privileges as $Privilege) { # Determine if current privilege is not predefined if (!$Privilege->IsPredefined() && isset($_POST["F_PermissionText".$Index])) { # Initialize status $Status = "No Update"; # Determine privilege's update/delete status if (isset($_POST["F_PermissionText".$Index."_Delete"])) { # Delete the privilege and update status $Privilege->Delete(); $Status = "Deleted"; $Counter--; } elseif ($Privilege->Name() !== $_POST["F_PermissionText".$Index]) { # Update privilege and status $Privilege->Name(addslashes($_POST["F_PermissionText".$Index])); $Status = "Updated"; } # Display privilege and increment index $PrivilegesArray[] = [$Privilege->Name(), $Status]; $Index++; $Counter++; } } # Loop through remaining permission values for ($Index; isset($_POST["F_PermissionText".$Index]); $Index++) { $Name = trim($_POST["F_PermissionText".$Index]); $MarkedForDeletion = isset($_POST["F_PermissionText".$Index."_Delete"]); $PrivilegeExists = $PrivilegeFactory->privilegeNameExists($Name); # If not whitespace or an existing privilege, add new privilege and # display it if (strlen($Name) > 0 && !$MarkedForDeletion && !$PrivilegeExists) { $EscapedName = $Name; $Privilege = new Privilege(null, $EscapedName); $PrivilegesArray[] = [$Privilege->name(), "Added"]; $Counter++; } } # Determine if any privileges exist if ($Counter < 1) { $PrivilegesArray[] = ["No privileges", "No Update"]; } return $PrivilegesArray; } /** * Get a 2D array of all permission names and their update statuses * (always "No Update", since no updates are made in this function). * @return array Array of arrays each containing a privilege and update status * for each (always "No Update"). */ function getPrivileges(): array { $PrivilegesArray = []; # Create privilege factory and get all privileges $PrivilegeFactory = new PrivilegeFactory(); $Privileges = $PrivilegeFactory->getPrivileges(); # Determine if any privileges exist $PrivFactory = new PrivilegeFactory(); if (count($Privileges) - count($PrivFactory->getPredefinedPrivilegeConstants()) < 1) { $PrivilegesArray[] = ["No privileges", "No Update"]; } else { foreach ($Privileges as $Privilege) { # Determine if current privilege is not predefined if (!$Privilege->IsPredefined()) { $PrivilegesArray[] = [$Privilege->Name(), "No Update"]; } } } return $PrivilegesArray; } # ----- SETUP ---------------------------------------------------------------- $EditButton = new HtmlButton("Edit"); $EditButton->setIcon("Pencil.svg"); $EditButton->setLink("index.php?P=EditPrivilegeNames"); $ControlledNamesTable = new HtmlTable(); $ControlledNamesTable->setTableClass("table table-striped"); $ControlledNamesTable->addHeaderRow(["Permission Name", "Status"]); $ControlledNamesTable->addRows( (isset($_POST["Submit"]) && $_POST["Submit"] == "Cancel") ? getPrivileges() : updatePrivileges() ); # ----- DISPLAY -------------------------------------------------------------- ?>

# Per-Field User Permission Names

getHtml(); ?>
getHtml(); ?>