sc_redir depending on user

Hi!

I have 3 different kinds of users. I would like to redirect each group to a initial application when they log in. For instance, user John from group 3 redirects to application ‘grid_3’, user May from group 2, redirects to application ‘grid_2’.

I’ve tried this code in event “OnValidateSuccess” in ‘app_login’ application:

/**
 * Conditional redirection
 */

// Redirection parameters
$redir_app  = 'grid_2'; // Application name
$redir_test  = {group} == '2'; // Redirection test
$redir_target = '_blank'; // Target window (_blank, _self, _parent or modal)
$redir_param = array(   // Param list, add as many as needed
					'param_1' => 'value_1',
					'param_2' => 'value_2',
);

// Redirection
if ($redir_test)
{
  sc_redir($redir_app, $redir_param, $redir_target);
}

In my database I have users and groups, so I am calling the field ‘group’ (I mean, it exists). But this code doesn’t work for me. I suppose I have to enter more values in ‘param_1’ and ‘param_2’ but I don’t know how to keep on. Could you help me?

Thanks.
Emma

Re: sc_redir depending on user

I’m not sure if this reply is appropiate. But sc_redir has optional parms which you can omit if you don’t need them. So sc_redir(‘myunit.php’) does work. I don’t see any reason why your code is wrong or it must be that $redir_test = {group} == ‘2’; might be $redir_test = ({group} == ‘2’); Also try $redir_app = ‘grid_2’ change to $redir_app = ‘grid_2.php’;

But why not:

if ({group} ==‘1’) {$redir=‘app1.php’;}

sc_redir($redir);

Re: sc_redir depending on user

Thanks for your reply!!

I think I need Scriptcase to check the table in MySQL where the ‘group’ field is before redirecting the user. Do you know how to do that? Sorry for my ignorance… I’m aware that I am asking obvious things!

Thanks again.

Emma

Re: sc_redir depending on user

In the generated login app there are some events you can use to do other things. In the right sidebar there are templates (generation links) for checking values in other tables. I modify them because I don’t like all those unnecessary variables, but there quite usable. But keep in mind that users can belong to more groups than one. What do you do then?

Re: sc_redir depending on user

Hi aideeaidee,
thanks for your reply!

Yes, I have made other applications with Scriptcase where users can belong to more than one group and where I had a different menu depending on the user group… But this time I only need to redirect an user to a certain App depending on which group he belongs. It’s a really simple and ‘small’ application which only needs this feature.

Re: sc_redir depending on user

Well if you have the username you can retrieve the group id in the onvalidateok event. There you can redirect depending on the group. IN the right sidebar you’ll find all you need then.
Cheers, Albert