custom condition of display for an action button

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

custom condition of display for an action button

Postby Jean » Mon Jun 23, 2008 1:59 am

Hi Steve,

I have a button to order items. I would like to hide/display according to the user. I could not find the solution in the forum. Could you help me ?

My action is :

Code: Select all
[command_selected]
   url="javascript:commandSelected('result_list')"
   label="Commander"
   description="Commander les besoins sélectionnés"
   category=selected_result_actions
   permission=edit
   icon="{$dataface_url}/images/edit.gif"


Thank you
Jean
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France

Postby shannah » Mon Jun 23, 2008 8:30 am

Hi Jean,

There are a couple of options here:
1. Use the permission parameter.
2. Use the condition parameter.

To use the permission parameter, you would need to deny the user the permission needed to see the action. Currently your action uses the edit permission. You could just create a new permission in the permissions.ini for your action, and deny him that....

A more direct approach is to use the condition parameter. This allows you to specify a php expression that evaluates to a boolean.

e.g.
Code: Select all
[command_selected]
   url="javascript:commandSelected('result_list')"
   label="Commander"
   description="Commander les besoins sélectionnés"
   category=selected_result_actions
   permission=edit
   icon="{$dataface_url}/images/edit.gif"
   condition="canOrderItems();"



Then just define a function somewhere in your PHP code called canOrderItems() that returns true if the current user can order the items, and false otherwise.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Jean » Tue Jun 24, 2008 7:11 am

Steve,
I add the function into my class in the table (xata_needs.php)

Code: Select all
function canOrderItems(){
      $auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser(); // returns a Dataface_Record object
      $app =& Dataface_Application::getInstance();
$db = $app->db(); // database resource handle...
    $record =& $app->getRecord();
$usager=trim(strtolower($user));
    $sql="select * from glpi_users where LOWER('name') LIKE '$usager' AND (location='492111728' OR location='492023960')";
    if ($res=mysql_query($sql, $db)){
    return true;
    }
      return false;
      }


Now the button does not appear in any case.
Do you have an idea ?
Jean
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France

Postby Jean » Wed Jul 09, 2008 1:50 am

Hi Steve,

It is as if the function was not loaded. I tried to insert it into xata_needs.php in the table directory xata_needs, into ApplicationDelegate.php in the conf directory, into the order.php that is the action itself but nothing happens.

The condition works if I put 1==1...

Jean
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France

Postby shannah » Wed Jul 09, 2008 9:29 am

One pesky thing about the conditions for actions is that errors are suppressed with executing the content, so if there is an error in your function it may not show up.

You may want to try testing your function to make sure that it is bug free by calling it somewhere after it is defined (so you know that it will run).
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Jean » Thu Jul 10, 2008 5:41 am

I tried to have my function return only true to see if the button appears, it does not. My function is placed inside DelegateClass.php in the conf directory. I tried in other files (xata_needs.php in the xata_needs directory, in the action file commander.php) but with the same result.
Jean :?
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France

Postby shannah » Fri Jul 11, 2008 10:58 am

What i'm thinking is that there might be some kind of error ocurring inside the function when it is called. When functions are called inside actions the errors are suppressed so you may not be able to see the error.

Try calling your function in your index.php file (some time after the function has been defined) to test and make sure it returns properly.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Jean » Tue Jul 15, 2008 5:55 am

Well Steve, I have followed your advice and my function returns 1.
Here is my function :
Code: Select all
function isAdmin(){
    $auth =& Dataface_AuthenticationTool::getInstance();
    $user =& $auth->getLoggedInUser();
     $app =& Dataface_Application::getInstance();
    $db = $app->db(); // database resource handle...
    $usager=$user->strval('identifiant');
    $sql="select * from glpi_users where name LIKE '$usager' AND (location='492111728' OR location='492023960')";
    if ($res=mysql_query($sql, $db)){
    return true;
    }
    return false;
}

Then I put it into the myAction.php file but it is as if my function was not loaded. The button never appears.
Jean
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France

Postby shannah » Tue Jul 15, 2008 9:21 am

Then I put it into the myAction.php file

Does this mean that the function is defined in your myAction.php file, or that you are calling it in your myAction.php file.

If it is defined in the myAction.php file then that is your problem. All actions.ini expressions are executed before any individual php action files are loaded. Best to place functions like this in some central file that is included at the beginning at your index.php file.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Jean » Wed Jul 16, 2008 7:18 am

I tried so many directions, I am getting lost. May be to-morrow I'll be clear to solve the whole of it.
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 24 guests

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