Access Permission for new button

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
cahsolonomer1
User
Posts: 121

Access Permission for new button

Post by cahsolonomer1 »

I have created the Print button next to the Edit, View, Edit and Delete buttons.

function ListOptions_Load() {
$opt = &$this->ListOptions->Add("Print");
$opt->MoveTo(0);
}

function ListOptions_Rendered() {
$body = "<a href='report.php?id_report=".$this->id_report->CurrentValue."' <button class='btn btn-primary btn-xs' target='_blank'> Print</a>" ;
$this->ListOptions->Items["Print"]->Body = $body;
}

I have 2 users ( professors and students). For edit button, view, delete can be set in table tab. How do I get the Print button to appear only on the Professor's menu while the student does not appear?


mobhar
User
Posts: 11660

Post by mobhar »

Assume "professors" and "students" are the real username in your case, then simply try this:

function ListOptions_Load() {
if (CurrentUserName() == "professors") {
$opt = &$this->ListOptions->Add("Print");
$opt->MoveTo(0);
}
}

function ListOptions_Rendered() {
if (CurrentUserName() == "professors") {
$body = "<a href='report.php?id_report=".$this->id_report->CurrentValue."' <button class='btn btn-primary btn-xs' target='_blank'> Print</a>" ;
$this->ListOptions->Items["Print"]->Body = $body;
}
}


cahsolonomer1
User
Posts: 121

Post by cahsolonomer1 »

thank for ur answer.
if user level will increase, for example add 2 user again that is operator and headoffice, just change function if else? or there is another solution?


kirondedshem
User
Posts: 642

Post by kirondedshem »

If you have added report.php as a custom file in phpmaker project, then it will also be available to be assigned in group permissions.

And if you are using dynamic group permissions you should be able to create multiple user groups and assign permissions to those groups.
Assumming report.php includes common files with dynamic permissions set, NO user will be able to access this file unless theier user group has allowed list permission.
So You can change your condition to check if current use group is allowed to list the report.php page before you draw it.
Even if it has no common files included(if its like an API file where you only included files for DbHelper), the file permissions will still be saved so you can still check for them


mobhar
User
Posts: 11660

Post by mobhar »

cahsolonomer1 wrote:
for example add 2 user again that is operator and headoffice, just change function
if else? or there is another solution?

For current user level, you may simply check by using CurrentUserLevel() global function will return the numeric value. For example, if you have enabled "Dynamic User Level Security", and you defined userlevels "operator" = 1, and "headoffice" = 2, then you may simply add the condition:

if (CurrentUserLevel() == 1) { // if "operator"
// your code for "operator" goes here...
} elseif (CurrentUserLevel() == 2) { // if "headoffice"
// your code for "headoffice" goes here
}


Post Reply