Redirect to default page based on user level

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

Redirect to default page based on user level

Post by rcoven »

I have a few different "Dashboard" reports created in PHP Reportmaker and I want to display the reports based on user level access as the default page.

I appreciate any input.

Thank You


mobhar
User
Posts: 11721

Post by mobhar »

You may simply use "Page_Redirecting" server event from "Server Events" -> "Other" -> "Default Page" of your PHPMaker project.

Please read "Server Events and Client Scripts" topic from PHPMaker Help menu for more information and example.


rcoven
User
Posts: 9

Post by rcoven »

It would work if I could designate the default page based on a user's user level. I do not want to use a "static" page for everyone.


mobhar
User
Posts: 11721

Post by mobhar »

You may implement your business-logic dynamically in that server event I mentioned before. For example, each logged-in user's user level will be redirected to the certain page that derived from your config setting in Database.


riverman
User
Posts: 158
Location: Stockholm/Sweden

Post by riverman »

Can´t you use CurrentUserLevel() and Page_Terminate() in switch to make this happen?

Ex:
switch (CurrentUserLevel()) {
case 1:
CurrentPage()->Page_Terminate("dashpage_1.php");
break;
case 2:
CurrentPage()->Page_Terminate("dashpage_2.php");
break;
case 3:
CurrentPage()->Page_Terminate("dashpage_3.php");
break;
default:
CurrentPage()->Page_Terminate("dashpage_0.php");
break;
}

or even simpler: CurrentPage()->Page_Terminate("dashpage_".CurrentUserLevel().".php");


mobhar
User
Posts: 11721

Post by mobhar »

@riverman,

No. You cannot use that code in the "Page_Redirecting" server event from "Server Events" -> "Other" -> "Default Page" I mentioned above. It will raise an fatal error if you put your code in that event.

You only need to assign the only param in that event ($url), for example from your code above, it become:

if (IsLoggedIn())
$url = "dashpage_".CurrentUserLevel().".php";


mobhar
User
Posts: 11721

Post by mobhar »

@riverman,

No. You cannot use that code in the "Page_Redirecting" server event from "Server Events" -> "Other" -> "Default Page" I mentioned above. It will raise a fatal error if you put your code in that event.

You only need to assign the only param in that event ($url), for example from your code above, it become:

if (IsLoggedIn())
$url = "dashpage_".CurrentUserLevel().".php";


acuervo
User
Posts: 9

Post by acuervo »

Is there a way to do this in v2022?

There does not seem to be a "Server Events" -> "Other" -> "Default Page" in v2022,

Thanks,


mobhar
User
Posts: 11721

Post by mobhar »

For v2022, basically is the same as v2021. This should help: viewtopic.php?p=159546#p159546


brianheim
User
Posts: 36

Post by brianheim »

riverman wrote:

Can´t you use CurrentUserLevel() and Page_Terminate() in switch to make this happen?

Ex:
switch (CurrentUserLevel()) {
case 1:
CurrentPage()->Page_Terminate("dashpage_1.php");
break;
................

I use something very similar with success to do what you are trying.
In ServerEvents-> Other -> Login Page -> UserLoggedIn

      switch ($cul) {  //current user level
       case 6:  //if owner
             $this->terminate("page1");
             break;
       case 1:  // if supervisor
             $this->terminate("page2");
             break;
       case 2:  // if accounting
       		 $this->terminate("page3");
             break;

       default:  // timecard users, all others
             $this->terminate("pagedefault");
             }

lamorte1977
User
Posts: 92

Post by lamorte1977 »

brianheim wrote:

I use something very similar with success to do what you are trying.
In ServerEvents-> Other -> Login Page -> UserLoggedIn

      switch ($cul) {  //current user level
       case 6:  //if owner
             $this->terminate("page1");
             break;
       case 1:  // if supervisor
             $this->terminate("page2");
             break;
       case 2:  // if accounting
       		 $this->terminate("page3");
             break;

       default:  // timecard users, all others
             $this->terminate("pagedefault");
             }

I think will not works with last versions of phpmaker if Multiuserlevels is enabled.
maybe you have to use:

$cUL_arr = explode (",", CurrentUserLevel());


Post Reply