User selectable subdomain views

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

User selectable subdomain views

Postby rscales » Mon Feb 01, 2010 3:26 am

Hi,

I would like to have the ability to let a user select a subdomain of tables on login. On each user's login, they would receive a welcome screen asking them to select a particular subdomain they'd like to view. Based on their selection, some type of global variable would then be set, and all tables would be somewhat filtered, or even not displayed at all, based on this global variable.

Ideal would be that the user would be presented with some sort of drop down list and they would need to select one item, thus setting this global subdomain variable. Also, each user may have a different set of subdomains possible to choose from (set in a user domain priviledges table somewhere). It would be preferable that this occur before the table navigation pane is displayed.

Could you point me in the right direction for this? I tried searching the forum db but didn't see anything applicable in the application delegate class, permissions, or preferences function discussions.

Thanks for any help,
Rich
rscales
 
Posts: 18
Joined: Mon Sep 14, 2009 1:10 am
Location: FR

Re: User selectable subdomain views

Postby shannah » Thu Feb 04, 2010 11:58 am

There are some blocks that can help you with this:
tables_menu_head : insert content at beginning of tables tabs.
tables_menu_options : override the tables tabs.
tables_menu_tail : insert content at the end of the tables tabs.

Here is a snippet of code from the Application Delegate class of one of my apps. What it does is: if the user is not an admin it hides all of the table tabs ( I use the tables_menu_options block for this). Then for other users I insert some different tabs at the beginning (I use the tables_menu_head block for this).

Note that I could have just done this all in the tables_menu_options block, but I wanted to be able to add the 'home' tab at the beginning for all users, so it made sense to split them up.

Code: Select all
function block__tables_menu_head(){
      
      $links = array(array('url'=> DATAFACE_SITE_URL.'/admin.php', 'label'=>'Home'));
      $user =& getUser();
      if ( $user and !isAdmin() and $user->val('username') ){
         $people = df_get_records_array('people', array('username'=>'='.$user->val('username') ) );
         
         if ( $people ){
            $links[] = array(
               'url' => $people[0]->getURL('-action=edit'),
               'label' => 'My Profile'
               );
               
         }
         
         $groups = df_get_records_array('research_groups', array('my_role'=>'GROUP LEADER') );
         if ( $groups ){
            foreach ($groups as $group){
               $links[] = array(
                  'url' => $group->getURL('-action=edit'),
                  'label' => $group->getTitle()
                  );
            }
         
         }
      }
      
      foreach ($links as $link){
         echo '<li><a href="'.$link['url'].'">'.htmlspecialchars($link['label']).'</a></li>';
      
      }
   }
   
   function block__tables_menu_options(){
      if ( isAdmin() ){
         return PEAR::raiseError("not handled", DATAFACE_E_REQUEST_NOT_HANDLED);
      }
      else return null;
   }
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: User selectable subdomain views

Postby rscales » Fri Feb 05, 2010 8:08 am

Thanks for the response Steve,

I actually already went down the route of the dashboard example you provided. So, I start each login with a Dashboard page. From here I am able to direct the user to select a subdomain preference. However, I am not sure the best way for a user to select a subdomain variable that is then a variable accessible by the rest of the application. I thought about have a user_subdomain_pref table and just directing the user to the edit form of their record, but this doesn't seem so nice, and not very user friendly.

What I'd like is for the dashboard.html page to welcome the user, state their current default subdomain preference, provide them with a pull down menu of their other subdomain options (need to read from a user_subdomain_priviledges table for populating this), and then the user either changes the default or simply continues/accepts the default by going to the next table defined in conf.ini tables section.

How can I create a dashboard.html that can capture a selection from the user?

Thanks,
Rich
rscales
 
Posts: 18
Joined: Mon Sep 14, 2009 1:10 am
Location: FR

Re: User selectable subdomain views

Postby shannah » Fri Feb 05, 2010 8:52 am

Probably the easiest way to track this information is in the $_SESSION array. You'll want to add an action called, say, "select_subdomain" that just takes the subdomain data, stores it in the $_SESSION array, and redirects back to another page (either the page that the user was on previously, or another page).
Then on the dashboard you would have a form or links to this action.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: User selectable subdomain views

Postby rscales » Tue Feb 09, 2010 4:00 am

Thanks Steve,

I tried searching on the forum but can't find any description of what is already stored in $_SESSION, or how to add something new to it, like subdomain preference. I saw some examples but can't find a documented list of everything tracked in a session.

Could you give me an example of adding a new variable to be tracked in the $_SESSION?

Also, in the dashboard.html example, I can see how a url is set with an action depending on a user selection, how would I create a new action, and how would a user selection from a drop down list trigger this action?
rscales
 
Posts: 18
Joined: Mon Sep 14, 2009 1:10 am
Location: FR

Re: User selectable subdomain views

Postby 00Davo » Tue Feb 09, 2010 4:20 am

rscales wrote:Thanks Steve,

I tried searching on the forum but can't find any description of what is already stored in $_SESSION, or how to add something new to it, like subdomain preference. I saw some examples but can't find a documented list of everything tracked in a session.

Could you give me an example of adding a new variable to be tracked in the $_SESSION?

Adding to $_SESSION is very, very easy.
Code: Select all
$_SESSION['subdomain_pref'] = "blah blah blah";

rscales wrote:Also, in the dashboard.html example, I can see how a url is set with an action depending on a user selection, how would I create a new action, and how would a user selection from a drop down list trigger this action?

To create a new action, you just need to add a new .php file to your /actions folder (if you haven't created any actions yet, chances are you don't have one - your /actions folder needs to be in the same folder as your conf.ini, /tables, etc.). The documentation provides plenty of hints on action creation, but they generally look a bit like this:
Code: Select all
<?php
class actions_select_sub {
   function handle(&$params) {
      $app =& Dataface_Application::getInstance();
      // Uh... do stuff or something.
   }
}
?>

To fill in the drop-down, do something a bit like this (this is in dashboard.html):
Code: Select all
                   <select onchange="window.location.href=this.options[this.selectedIndex].value">
                    <option value="">Select a subdomain ...</option>
                    {foreach from=$subdomains item=subdomain}
                        <option value="{$subdomain->getURL('-action=select_sub')}">
                            {$subdomain->getTitle()}
                        </option>
                   
                    {/foreach}
                </select>

You've presumably got a dashboard.php too - the above example requires you to pass a $subdomains array from dashboard.php. Create that one something like this...
Code: Select all
<?php
class actions_dashboard{
   function handle(&$params) {
      $subdomains = df_get_records_array('subdomain', array());
      df_display(array('$subdomains'=>$subdomains), 'dashboard.html');
   }
}
?>

This one's assuming that you have a table called "subdomain", containing all your subdomains. This is probably a pretty tidy way of doing it. (read: do it that way)

Hope all that helps. :)
00Davo
 
Posts: 55
Joined: Sat Jan 02, 2010 9:02 pm

Re: User selectable subdomain views

Postby rscales » Tue Feb 09, 2010 10:42 am

Thanks OODavo - I'll give this a try then. Appreciate all the help!

-Rich
rscales
 
Posts: 18
Joined: Mon Sep 14, 2009 1:10 am
Location: FR


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 15 guests

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