support for vicci simplified portal
[plewww.git] / modules / planetlab.module
index e1f7d1f..3fd2c5b 100644 (file)
 
 require_once 'plc_config.php';
 require_once 'plc_session.php';
+require_once 'plc_functions.php';
 
-function planetlab_help($section)
-{
+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':
     return t('Enables authenticated login via a PlanetLab API server.');
   }
 }
 
-function planetlab_info($field = 0)
-{
+function planetlab_info($field = 0) {
   $info['name'] = 'PlanetLab';
 
   if ($field) {
     return $info[$field];
-  }
-  else {
+  } else {
     return $info;
   }
 }
 
-function planetlab_menu($may_cache)
-{
+function planetlab_menu($may_cache) {
   $items = array();
 
   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
@@ -55,16 +54,54 @@ function planetlab_menu($may_cache)
   return $items;
 }
 
-function planetlab_block($op = 'list', $delta = 0, $edit = array())
-{
+//////////////////// 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 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 = '';
+  $result .= ul_start();
+  foreach ($menu as $item) $result .= $item;
+  $result .= ul_end();
+  return $result;
+}
+
+function planetlab_block($op = 'list', $delta = 0, $edit = array()) {
   global $user, $plc;
 
   if ($op == 'list') {
     $blocks[0]['info'] = t('PlanetLab login');
 
     return $blocks;
-  }
-  else if ($op == 'view') {
+
+  else if ($op == 'view') {
     $block = array();
 
     if (!$plc->person) {
@@ -89,94 +126,112 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array())
 
       $block['subject'] = t('%s login', array('%s' => variable_get('site_name', 'local')));
       $block['content'] = drupal_get_form('planetlab_login_block', $form, 'planetlab_login');
-      $block['content'] .= '<p><p><a href="/db/persons/reset_password.php">Forgot your password?</a></p>';
-      $block['content'] .= '<p><a href="/db/persons/register.php">Create an account</a></p>';
-      $block['content'] .= '<p><a href="/db/sites/register.php">File a site registration</a></p>';
-    } 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']);
-
-      $site_item = '';
-      $site_item .= '<a href="/db/sites/">Sites</a>';
-      $site_item .= '<ul>';
-      $site_item .= '<li><a href="/db/sites/index.php?id='. $plc->person['site_ids'][0] .'">My Site</a></li>';
-      if ( $is_admin ) 
-       $site_item .= "<li><a href='/db/sites/join_request.php'>Join Requests</a></li>";
-      if( $is_admin )
-       $site_item .= "<li><a href='/db/sites/peers.php'>Migration Status</a></li>";
-      $site_item .= "</ul>";
-      $items[] = $site_item;
-
-      $user_item = '';
-      $user_item .= '<a href="/db/persons/">Users</a>';
-      $user_item .= '<ul>';
-      $user_item .= '<li><a href="/db/persons/index.php?id='. $plc->person['person_id'] .'">My account</a></li>';
-      if (is_pi) 
-       $user_item .= '<li><a href="/db/persons/index.php?site_id='. $plc->person['site_ids'][0] .'">My users</a></li>';
-      if ( $plc->alt_person && $plc->alt_auth) {
-       $email = $plc->person['email']; 
-       $user_item .= "<li><a href='/db/sulogout.php'>Log out of $email </a></li>";
-      }        
-
-
-      $user_item .= '</ul>';
-      $items [] = $user_item;
-
-      $node_item = '';
-      $node_item .= '<a href="/db/nodes/">Nodes</a>';
-      $node_item .= '<ul>';
-      $node_item .= '<li><a href="/db/nodes/newindex.php"> New nodes page </a></li>';
-      $node_item .= '<li><a href="/db/nodes/index.php?site_id='. $plc->person['site_ids'][0] .'">My Site Nodes</a></li>';
-      $node_item .= "<li><a href='/db/nodes/add_node.php'>Add Node</a></li>";
-      if ( $is_admin) 
-       $node_item .= "<li> <a href='/db/nodes/settings.php'> Setting Types </a> </li>";
-      $node_item .= '</ul>';
-      $items [] = $node_item;
-
-      $slice_item = '';
-      //if( !( $is_tech && ! $is_user && ! $is_pi && ! $is_admin ) ) 
-      $slice_item .= '<a href="/db/slices/">Slices</a>';
-      $slice_item .= '<ul>';
-      if( $is_admin || $is_pi ) {
-       $slice_item .= "<li><a href='/db/slices/add_slice.php'>Create Slice</a></li>";
-      }
-      if( !( $is_tech && ! $is_user && ! $is_pi && ! $is_admin ) ) 
-       $slice_item .= '<li><a href="/db/sirius/index.php">Sirius</a></li>';
-      $slice_item .= '</ul>';
-      $items [] = $slice_item;
-
-      if( $is_admin || $is_pi ) {
-       $tag_item = '';
-       $tag_item .= '<a href="/db/slices/tags.php?type=all">Tags</a>';
-       $tag_item .= '<ul>';
-       $tag_item .= "<li><a href='/db/slices/tags.php?type=node'>Node Tags</a></li>";
-       $tag_item .= "<li><a href='/db/slices/tags.php?type=interface'>Interface Tags</a></li>";
-       $tag_item .= "<li><a href='/db/slices/tags.php?type=slice'>Slice Tags</a></li>";
-       $tag_item .= '</ul>';
-       $items [] = $tag_item;
-      }
-      
-
-      if ( $is_admin )
-       $items[] = l(t('Peers'),'db/peers/');
-     
-      if ( $is_admin )
-       $items[] = l(t('Events'),'db/events/');
-      
-      $items[] = l(t('About'),'db/about.php');
-
+      $block['content'] .= p('');
+      $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 if (plc_advanced()) {
+      $block['subject'] = truncate($plc->person['email'],30);
+
+      //////////////////// Logout 
+      $bullet_item = '';
       if ($user->uid) {
        // Drupal logout (destroys the session and cleans up $user)
-       $items[] = l(t('Log out of %s', array('%s' => variable_get('site_name', 'local'))), 'logout');
+       // 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)
-       $items[] = l(t('Log out'), 'planetlab/logout');
+       $bullet_item .= href (l_logout(),'Logout');
       }
+      $bullet_item .= ul_start();
+      // logout 
+      if ( $plc->alt_person && $plc->alt_auth) {
+       $email = truncate($plc->person['email'],20); 
+       $bullet_item .= leaf( href( l_sulogout(),"Un-become $email"));
+      }        
+      $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
+      $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
+      $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");
+      }
+      $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( 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);
+      }
+
+      $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);
 
-      $block['content'] = theme('item_list', $items);
+      //$block['content'] = theme('list_item', $items);
+      $block['content'] = menu_theme($items);
     }
 
     /*
@@ -192,8 +247,7 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array())
   }
 }
 
-function planetlab_login_validate($form_id, $form_values)
-{
+function planetlab_login_validate($form_id, $form_values) {
   global $user, $plc;
 
   if ($form_values['name'] && $form_values['pass']) {
@@ -221,8 +275,7 @@ function planetlab_login_validate($form_id, $form_values)
   }
 }
 
-function planetlab_login_submit($form_id, $form_values)
-{
+function planetlab_login_submit($form_id, $form_values) {
   global $plc;
 
   // Our referring page is encased in a query string of the form
@@ -257,14 +310,13 @@ function planetlab_login_submit($form_id, $form_values)
       if ($url[0] != "/") {
        $url = "/$url";
       }
-      Header("Location: $url");
+      header("Location: $url");
       exit();
     }
   }
 }
 
-function planetlab_logout()
-{
+function planetlab_logout() {
   global $plc;
 
   if ($plc->person) {
@@ -280,8 +332,7 @@ function planetlab_logout()
   drupal_goto(NULL, 'time='. time());
 }
 
-function planetlab_user($type, &$edit, &$user, $category = NULL)
-{
+function planetlab_user($type, &$edit, &$user, $category = NULL) {
   switch ($type) {
   case 'logout':
     if ($plc->person) {
@@ -292,8 +343,7 @@ function planetlab_user($type, &$edit, &$user, $category = NULL)
   }
 }
 
-function planetlab_page()
-{
+function planetlab_page() {
   $path = $_SERVER['DOCUMENT_ROOT'] . preg_replace('/^db\//', '/planetlab/', $_GET['q']);
 
   // error_log("Requested " . $_GET['q'] . " -> $path");
@@ -322,8 +372,7 @@ function planetlab_page()
   drupal_not_found();
 }
 
-function theme_planetlab($content)
-{
+function theme_planetlab($content) {
   return $content;
 }