Default action according to username

Archived from the Xataface Users forum.

Jean — Mon Nov 26, 2007 7:04 am

Hello Steve,

Could you help me ? I need to have a default action according to the authentification and the username.

I tried several things with index.php and DelegateApplication.php without success ?

Thank you

Jean


Jean — Mon Dec 03, 2007 6:25 am

Eventually I found the solution with the after_action_new (http://xataface.com/documentation/how-to/after_action_triggers)

So in tables/demandes/demandes_particuliere.php I added :

Code: Select all
`class tables_demandes_particulieres {

function after_action_new (&$record) {
$lusager =$this->getUser($record);
$usager=$lusager->val(‘username’);
if ( @$_REQUEST[‘-table’]==’demandes_particulieres’ AND $usager==’demande’){
$url=”http://lintranet/fibre/index.php?-action=new&-table=”.$_REQUEST[‘-table’];
        header(“Location: $url”);
            exit;
}
}
function getUser(&$record){
  $auth =& Dataface_AuthenticationTool::getInstance();
    $user =& $auth->getLoggedInUser();
return $user;
}
}`

It works fine!

Jean


shannah — Mon Dec 03, 2007 5:18 pm

Hi Jean,

Sorry.. must have missed this post.

Your solution looks good for redirecting after adding a new record. The next release of Dataface will include a triggerf called “beforeHandleRequest” which will allow full control over things like default actions…. The current version leaves you to your own devices to achieve this sort of thing.

One possibility is to add some code to your getPreferences method to check for -action, and change it to a default depending on the user.

e.g.

Code: Select all
`function getPreferences(){
    $app =& Dataface_Application::getInstance();
    $query =& $app->getQuery();
    if ( !$_REQUEST[‘-action’] and !$_POST ){
        if ( isAdmin() /* this is a custom function defined elsewhere */){
            $query[‘-action’] = ‘admin_home’;
        } else {
            $query[‘-action’] = ‘default_home’;
        }

    }
    return array();
}`

-Steve


Jean — Tue Dec 04, 2007 8:26 am

Hi Steve,

No problem, thank you. I keep your code for my next app, il will be easier to apply when I’ll have several tables.

Kind regards

Jean