As we have already known, IsLoggedIn is a function to check whether users have logged in to your web application that generated with PHPMaker or not. This IsLoggedIn function is often being used to determine which menus can only be accessed by the logged in users. Sometimes, you want also to display the certain menu only for users which have the Administrator level. So, the next question is, How does the system check whether the user which has just logged in had the Administrator level or not.
For this purpose, then you should create another IsAdmin function that runs parallel with the IsLoggedIn function above. Actually, there was the same IsAdmin function that belongs to the cAdvancedSecurity class that located in your phpfn*.php file. But this time, we will create another IsAdmin function that still used that class but the new function can be used easily as well as the IsLoggedIn function above. This new IsAdmin function is very useful if you want to use it without having to declare the new cAdvancedSecurity class and using the Security variable object. Now let's customize the PHPMaker template in order to create the new one.
Updated on June 12, 2012: This customization has been implemented in PHPMaker version 9.0.2, it matches to each other, and as a result, it works properly.
Updated on July 22, 2012: This customization has been implemented in PHPMaker version 9.0.3, it matches to each other, and as a result, it works properly.
Updated on September 5, 2012: This customization has been implemented in PHPMaker version 9.0.4, it matches to each other, and as a result, it works properly.
Updated on November 28, 2012: This customization has been implemented in PHPMaker version 9.1.0, it matches to each other, and as a result, it works properly.
Updated on February 9, 2013: This customization has been implemented in PHPMaker version 9.2.0, it matches to each other, and as a result, it works properly.
[hidepost]
-
Open your /Script/phpfn.php file, and find this code:
// Is logged in function IsLoggedIn() { global $Security; return (isset($Security)) ? $Security->IsLoggedIn() : ($_SESSION[EW_SESSION_STATUS] == "login"); }after the last line of that code, please insert this following code:
// Is Admin function IsAdmin() { global $Security; return (isset($Security)) ? $Security->IsAdmin() : false; }then re-generate your phpfn*.php file to apply that code changes.
-
Now let's see how we can implement that new IsAdmin function that we have just created. Open your generated ewmenu.php file, and find one of your menu item, for example, I copy mine as following:
$RootMenu->AddMenuItem(10173, $Language->MenuPhrase("10173", "MenuText"), "clearusersession.php", 10037, "", IsLoggedIn(), FALSE);That menu item will open the clearusersession.php file for the logged in users. Now I want that menu item can only be visible for users which have the Administrator level. So, that code should be like this:
$RootMenu->AddMenuItem(10173, $Language->MenuPhrase("10173", "MenuText"), "clearusersession.php", 10037, "", IsLoggedIn() && IsAdmin(), FALSE);Please note that the values of 10173 and 10037 above may vary in your generated code. This is only an example of usage.
[/hidepost]
You might want to change this instruction for PHPMaker 9
“then re-generate your phpfn8.php file to apply that code changes. “
Yeah, thanks for reminding it. I just changed it become phpfn*.php.