Adding the table name with the caption in user permissions

I made a change to my template to load the Table Caption with the table name in parenthesis to make assigning user level permissions easier. I modified the page.

Changes to userpriv.php in the template to display the table name and caption in the user permissions page

Added the following in userpriv.php:

switch ($this->CurrentAction) {
        case "show":
            if (!$Security->setupUserLevelEx()) {
                $this->terminate("<#= userLevelListPage #>");
                return;
            }
            $ar = [];
            for ($i = 0; $i < $this->TableNameCount; $i++) {
                $table = $this->TableList[$i];
                $cnt = count($table);
                $tempPriv = $Security->getUserLevelPrivEx($table[4] . $table[0], $this-><#= userLevelIdFldParm #>->CurrentValue);
                
                // Retrieve the table caption
                $tableCaption = $this->getTableCaption($i);
                
                $ar[] = [
                    "table" => ConvertToUtf8($tableCaption . " (" . $table[1] . ")"), // Caption with table name in parentheses
                    "name" => $table[1],
                    "index" => $i,
                    "permission" => $tempPriv,
                    "allowed" => $table[$cnt - 1]
                ];
            }
            $this->Privileges["disabled"] = $this->Disabled;
            $this->Privileges["permissions"] = $ar;
            $this->Privileges["ids"] = PRIVILEGES;
            foreach (PRIVILEGES as $priv) {
                $this->Privileges[$priv] = GetPrivilege($priv);
            }
            break;

        case "update":
            if ($this->editRow()) {
                if ($this->getSuccessMessage() == "") {
                    $this->setSuccessMessage($Language->phrase("UpdateSuccess"));
                }
                $this->terminate("<#= userLevelListPage #>");
                return;
            }
    }

Now my user permissions looks like:

Caption (table name)

1 Like

This worked for PHPmaker 2024

v2025 always uses utf-8, there is no more ConvertToUtf8(). You better always turn on Debug during development.

UPDATE: Change the following PHPMaker 2025 template file userpriv.php to add table names to the captions for UserLevelPermissions. Replace the “Get table caption” section with the following function:

// Get table caption with table name in parentheses 
protected function getTableCaption(int $i): string
{
    $caption = "";
    if ($i < $this->TableNameCount) {
        $caption = Language()->tablePhrase($this->TableList[$i][1], "TblCaption");
        if ($caption == "") {
            $caption = $this->TableList[$i][2];
        }
        if ($caption == "") {
            $caption = $this->TableList[$i][0];
            $caption = preg_replace('/^\{\w{8}-\w{4}-\w{4}-\w{4}-\w{12}\}/', '', $caption); // Remove project id
        }
        // Append table name in parentheses
        $tableName = $this->TableList[$i][1]; // Assuming index 1 holds the actual table name
        $caption .= " ($tableName)";
    }
    return $caption;
}

Just curious, Can this change be initiated through the software instead of altering the template?

You may create your own Extensions to do that.