Page 1 of 1

Redirect to default page based on user level

Posted: Tue Jan 17, 2017 11:26 am
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


Re: Redirect to default page based on user level

Posted: Tue Jan 17, 2017 3:26 pm
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.


Re: Redirect to default page based on user level

Posted: Wed Jan 18, 2017 5:06 am
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.


Re: Redirect to default page based on user level

Posted: Wed Jan 18, 2017 9:08 am
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.


Re: Redirect to default page based on user level

Posted: Wed Jan 18, 2017 9:42 pm
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");


Re: Redirect to default page based on user level

Posted: Thu Jan 19, 2017 9:51 am
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";


Re: Redirect to default page based on user level

Posted: Thu Jan 19, 2017 9:52 am
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";


Re: Redirect to default page based on user level

Posted: Wed Aug 25, 2021 3:27 am
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,


Re: Redirect to default page based on user level

Posted: Wed Aug 25, 2021 8:03 am
by mobhar

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


Re: Redirect to default page based on user level

Posted: Thu Aug 26, 2021 2:39 am
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");
             }

Re: Redirect to default page based on user level

Posted: Fri Sep 10, 2021 10:00 pm
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());