Default action according to username

A place for users and developers of the Xataface to discuss and receive support.

Default action according to username

Postby 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
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France

Postby 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
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France

Postby 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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby 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
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 31 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved