support for vicci simplified portal
[plewww.git] / modules / planetlab.module
index e24e933..3fd2c5b 100644 (file)
@@ -12,6 +12,8 @@ require_once 'plc_config.php';
 require_once 'plc_session.php';
 require_once 'plc_functions.php';
 
+drupal_set_html_head('<link href="/planetlab/css/plc_style.css" rel="stylesheet" type="text/css"/>');
+
 function planetlab_help($section) {
   switch ($section) {
   case 'admin/modules#description':
@@ -34,8 +36,8 @@ function planetlab_menu($may_cache) {
 
   if ($may_cache) {
     $items[] = array(
-                    'path' => 'planetlab/logout',
-                    'title' => t('Log out of %s', array('%s' => variable_get('site_name', 'local'))),
+                    'path' => 'planetlab/common/logout',
+                    'title' => t('Logout of %s', array('%s' => variable_get('site_name', 'local'))),
                     'callback' => 'planetlab_logout',
                     'access' => TRUE,
                     'type' => MENU_CALLBACK
@@ -52,12 +54,36 @@ function planetlab_menu($may_cache) {
   return $items;
 }
 
-// formatting helpers
-function ul_start () { return '<ul class=menu>'; }
+//////////////////// formatting helpers - specific to module presentation
+function ul_start () { return '<ul class="menu">'; }
 function ul_end () { return '</ul>'; }
-function leaf($text) { return '<li class=leaf>' . $text . '</li>'; }
-function expanded($text) { return '<li class=expanded>' . $text . '</li>'; }
+function leaf($text) { return '<li class="leaf">' . $text . '</li>'; }
+function expanded($text) { return '<li class="expanded">' . $text . '</li>'; }
 function p($text) { return '<p>' . $text . '</p>'; }
+
+# this should get embedded into a ul_start()/ul_end() pair
+function plc_my_site_links() {
+  $html = '';
+  $sites = plc_my_sites();
+  if (count($sites)>1) foreach ($sites as $site) {
+      $html .= leaf( href(l_site($site['site_id']),$site['abbreviated_name']));
+    } else {
+    $html .= leaf( href(l_site(plc_my_site_id()),"My Site"));
+  }
+  return $html;
+}
+
+// ditto
+function plc_my_node_links () {
+  $html = '';
+  if (count (plc_my_site_ids()) == 1) {
+    $html .= leaf( href (l_nodes_my_site() ,"My Site Nodes"));
+  } else {
+    $html .= leaf( href (l_nodes_all_my_site(),"All My Sites Nodes"));
+  }
+  return $html;
+}
+
 // fake theme to look like menu
 function menu_theme ($menu) {
   $result = '';
@@ -104,99 +130,108 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array()) {
       $block['content'] .= p( href (l_reset_password(),"Forgot your password?") );
       $block['content'] .= p( href(l_person_register(),"Create an account") );
       $block['content'] .= p( href(l_site_register(),"File a site registration") );
-    } else {
-      $block['subject'] = $plc->person['email'];
-      $is_admin = in_array(10,$plc->person['role_ids']);
-      $is_pi    = in_array(20,$plc->person['role_ids']);
-      $is_user  = in_array(30,$plc->person['role_ids']);
-      $is_tech  = in_array(40,$plc->person['role_ids']);
+    } else if (plc_advanced()) {
+      $block['subject'] = truncate($plc->person['email'],30);
 
-      //////////////////// Sites
-      $site_item = '';
-      $site_item .= href(l_sites(),"Sites");
-      $site_item .= ul_start();
-      $site_item .= leaf( href(l_site(plc_my_site_id()),"My site"));
-      if ( $is_admin ) 
-       $site_item .= leaf( href(l_site_pending(),"Pending Requests"));
-      $site_item .= ul_end();
-      $items[] = expanded($site_item);
-
-      //////////////////// Users
-      $user_item = '';
-      $user_item .= href(l_persons(),'Users');
-      $user_item .= ul_start();
-      $user_item .= leaf( l_person_t(plc_my_person_id(),"My account"));
-      if (is_pi) 
-       $user_item .= leaf( href( l_persons_site(plc_my_site_id()), "My users"));
+      //////////////////// Logout 
+      $bullet_item = '';
+      if ($user->uid) {
+       // Drupal logout (destroys the session and cleans up $user)
+       // Thierry unclear when this triggers, I suspect this is obsolete
+       $bullet_item .= l(t('Logout of %s', 
+                         array('%s' => variable_get('site_name', 'local'))), 'logout');
+      } else {
+       // PlanetLab logout (just destroy the session)
+       $bullet_item .= href (l_logout(),'Logout');
+      }
+      $bullet_item .= ul_start();
+      // logout 
       if ( $plc->alt_person && $plc->alt_auth) {
-       $email = $plc->person['email']
-       $user_item .= leaf( href( l_sulogout(),"Log out of $email"));
+       $email = truncate($plc->person['email'],20)
+       $bullet_item .= leaf( href( l_sulogout(),"Un-become $email"));
       }        
-      $user_item .= ul_end();
-      $items [] = expanded($user_item);
+      $bullet_item .= ul_end();
+      $items []= expanded ($bullet_item);
+
+      //////////////////// accounts
+      $bullet_item = '';
+      $bullet_item .=  l_person_t(plc_my_person_id(),"My Account");
+      $bullet_item .= ul_start();
+      if (plc_is_admin() || plc_is_pi()) 
+       $bullet_item .= leaf( href( l_persons_site(plc_my_site_id()), "My Site Accounts"));
+      if (plc_is_admin()) {
+       $bullet_item .= leaf(href(l_persons_peer('local'),'Local Accounts (slow)'));
+       $bullet_item .= leaf(href(l_persons(),'All Accounts (slow)'));
+      }
+       
+      $bullet_item .= ul_end();
+      $items [] = expanded($bullet_item);
+
+      //////////////////// Sites
+      $bullet_item = '';
+      $bullet_item .= href(l_sites(),"Sites");
+      $bullet_item .= ul_start();
+      $bullet_item .= plc_my_site_links();
+      if ( plc_is_admin() ) 
+       $bullet_item .= leaf( href(l_sites_pending(),"Pending Requests"));
+      $bullet_item .= ul_end();
+      $items[] = expanded($bullet_item);
 
       //////////////////// Nodes
-      $node_item = '';
-      $node_item .= href(l_nodes(),"Nodes");
-      $node_item .= ul_start();
-      $node_item .= leaf( href (l_nodes_site (plc_my_site_id()),"My Site Nodes"));
-      $node_item .= leaf( href (l_node_add(),"Add Node"));
-      $node_item .= ul_end();
-      $items [] = expanded($node_item);
+      $bullet_item = '';
+      $bullet_item .= href(l_nodes(),"Nodes");
+      $bullet_item .= ul_start();
+      $bullet_item .= plc_my_node_links();
+      if (plc_is_admin() || plc_is_pi() || plc_is_tech()) 
+       $bullet_item .= leaf( href (l_register_node(),"Register Node"));
+      $bullet_item .= ul_end();
+      $items [] = expanded($bullet_item);
 
       //////////////////// Slices
-      $slice_item = '';
-      //if( !( $is_tech && ! $is_user && ! $is_pi && ! $is_admin ) ) 
-      $slice_item .= href(l_slices(),"Slices");
-      $slice_item .= ul_start();
-      if( $is_admin || $is_pi ) {
-       $slice_item .= leaf(href(l_slice_add(),"Create Slice"));
+      $bullet_item = '';
+      //if( !( plc_is_tech() && ! plc_is_user() && ! plc_is_pi() && ! plc_is_admin() ) ) 
+      if (plc_is_admin()) {
+        $bullet_item .= href(l_slices(),"Slices");
+      } else {
+        $bullet_item .= href(l_slices(),"My Slices");
       }
-      if( !( $is_tech && ! $is_user && ! $is_pi && ! $is_admin ) ) 
-       $slice_item .= leaf(href(l_sirius(),"Sirius"));
-      $slice_item .= ul_end();
-      $items [] = expanded($slice_item);
+      $bullet_item .= ul_start();
+      if (plc_is_admin()) 
+       $bullet_item .= leaf ( href(l_slices_my_site(), 'My Site Slices'));
+      if( plc_is_admin() || plc_is_pi() ) {
+       $bullet_item .= leaf(href(l_slice_add(),"Create Slice"));
+      }
+      if( !( plc_is_tech() && ! plc_is_user() && ! plc_is_pi() && ! plc_is_admin() ) ) 
+       $bullet_item .= leaf(href(l_sirius(),"Sirius"));
+      $bullet_item .= ul_end();
+      $items [] = expanded($bullet_item);
 
       //////////////////// Admin
-      if( $is_admin || $is_pi ) {
-       $admin_item = '';
-       $admin_item .= href(l_admin(),"Admin");
-       $admin_item .= ul_start();
-       $admin_item .= leaf( href( l_tags(),"Tags"));
-       $admin_item .= leaf( href( l_nodegroups(),"Node groups (xxx)"));
-       // xxx need to cleanup
-       //$admin_item .= leaf( href( l_tags_slice(),"Slice Tags"));
-       //$admin_item .= leaf( href( l_tags_interface(),"Interface Tags"));
-       //$admin_item .= leaf( href (l_tags_interface(),"Setting Types (dup xxx)"));
-       //$admin_item .= leaf( href( l_tags_node(),"Node Tags"));
-       $admin_item .= leaf (href(l_peers(),'Peers'));
-       $admin_item .= ul_end();
-       $items [] = expanded($admin_item);
+      if( plc_is_admin() || plc_is_pi() ) {
+       $bullet_item = '';
+       $bullet_item .= href(l_admin(),"Admin search");
+       $bullet_item .= ul_start();
+       if ( plc_is_admin() )
+         $bullet_item .= leaf( href (l_node_add(),"Add Node"));
+       $bullet_item .= leaf( href( l_tags(),"Tags"));
+       $bullet_item .= leaf( href( l_nodegroups(),"Node groups"));
+       $bullet_item .= leaf (href(l_peers(),'Peers'));
+       if ( plc_is_admin() )
+         $bullet_item .= leaf (href(l_events(),'Events'));
+       $bullet_item .= ul_end();
+       $items [] = expanded($bullet_item);
       }
 
-      $doc_item = '';
-      $doc_item .= href(l_about(),'About MyPLC');
-      $doc_item .= ul_start();
-      $doc_item .= leaf ( href (l_doc_plcapi(),"PLCAPI doc"));
-      $doc_item .= leaf ( href (l_doc_nmapi(),"NMAPI doc"));
-      if ( $is_admin )
-       $doc_item .= leaf (href(l_events(),'Events'));
-      $doc_item .= ul_end();
-      $items[] = expanded($doc_item);
+      $bullet_item = '';
+      $bullet_item .= href(l_about(),'About MyPLC');
+      $bullet_item .= ul_start();
+      $bullet_item .= leaf ( href (l_doc_plcapi(),"PLCAPI doc"));
+      $bullet_item .= leaf ( href (l_doc_nmapi(),"NMAPI doc"));
+      $bullet_item .= ul_end();
+      $items[] = expanded($bullet_item);
 
-      if ($user->uid) {
-       // Drupal logout (destroys the session and cleans up $user)
-       // Thierry unclear when this triggers, I suspect this is obsolete
-       $items[] = leaf (l(t('Log out of %s', 
-                            array('%s' => variable_get('site_name', 'local'))), 'logout'));
-      } else {
-       // PlanetLab logout (just destroy the session)
-       $items[] = leaf ( href (l_logout(),'Log out'));
-      }
-      
       //$block['content'] = theme('list_item', $items);
       $block['content'] = menu_theme($items);
-      //      plc_debug("content",$block['content']);
     }
 
     /*
@@ -275,7 +310,7 @@ function planetlab_login_submit($form_id, $form_values) {
       if ($url[0] != "/") {
        $url = "/$url";
       }
-      Header("Location: $url");
+      header("Location: $url");
       exit();
     }
   }