redo http://svn.planet-lab.org/changeset/13771 from scratch
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Sun, 7 Jun 2009 08:47:05 +0000 (08:47 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Sun, 7 Jun 2009 08:47:05 +0000 (08:47 +0000)
modules/planetlab.module
planetlab/includes/plc_functions.php
planetlab/sites/site.php

index f7248dd..1964686 100644 (file)
@@ -54,12 +54,25 @@ function planetlab_menu($may_cache) {
   return $items;
 }
 
-// formatting helpers
+//////////////////// 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;
+}
+
 // fake theme to look like menu
 function menu_theme ($menu) {
   $result = '';
@@ -108,68 +121,74 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array()) {
       $block['content'] .= p( href(l_site_register(),"File a site registration") );
     } else {
       $block['subject'] = truncate($plc->person['email'],30);
-      $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']);
 
-      //////////////////// Logout
+      //////////////////// 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
-       $items[] = leaf (l(t('Logout of %s', 
-                            array('%s' => variable_get('site_name', 'local'))), 'logout'));
+       $bullet_item .= l(t('Logout of %s', 
+                         array('%s' => variable_get('site_name', 'local'))), 'logout');
       } else {
        // PlanetLab logout (just destroy the session)
-       $items[] = leaf ( href (l_logout(),'Logout'));
+       $bullet_item .= href (l_logout(),'Logout');
       }
-      
-      //////////////////// 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"));
-      $site_item .= plc_my_site_links(); # leaf( href(l_site(plc_my_site_id()),"My Site"));
-      if ( $is_admin ) 
-       $site_item .= leaf( href(l_sites_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"));
+      $bullet_item .= ul_start();
+      // logout 
       if ( $plc->alt_person && $plc->alt_auth) {
        $email = truncate($plc->person['email'],20); 
-       $user_item .= leaf( href( l_sulogout(),"Logout of $email"));
+       $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 Users"));
+      if (plc_is_admin()) {
+       $bullet_item .= leaf(href(l_persons_peer('local'),'Local users (looong)'));
+       $bullet_item .= leaf(href(l_persons(),'All users (looong)'));
+      }
+       
+      $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_register_node(),"Register Node"));
-      $node_item .= ul_end();
-      $items [] = expanded($node_item);
+      $bullet_item = '';
+      $bullet_item .= href(l_nodes(),"Nodes");
+      $bullet_item .= ul_start();
+      $bullet_item .= leaf( href (l_nodes_site (plc_my_site_id()),"My Site Nodes"));
+      $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() ) ) 
+      $bullet_item .= href(l_slices(),"Slices");
+      $bullet_item .= ul_start();
+      if (plc_is_admin()) 
+       $bullet_item .= leaf ( href(l_slices_site(plc_my_site_id()), 'My Site Slices'));
+      if( plc_is_admin() || plc_is_pi() ) {
+       $bullet_item .= leaf(href(l_slice_add(),"Create Slice"));
       }
-      if( !( $is_tech && ! $is_user && ! $is_pi && ! $is_admin ) ) 
-       $slice_item .= leaf(href(l_sirius(),"Sirius"));
-      $slice_item .= ul_end();
-      $items [] = expanded($slice_item);
+      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() ) {
@@ -186,13 +205,13 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array()) {
        $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"));
-      $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);
 
       //$block['content'] = theme('list_item', $items);
       $block['content'] = menu_theme($items);
index 4e8928c..46b9c26 100644 (file)
@@ -36,26 +36,10 @@ function plc_my_site_ids () {
   global $plc;
   return $plc->person['site_ids'];
 }
-function plc_my_site_names () {
+function plc_my_sites () {
   global $plc;
   global $api;
-  $ret = $api->GetSites($plc->person['site_ids'], array('site_id', 'abbreviated_name'));
-  return $ret;
-}
-
-function plc_my_site_links()
-{
-  $site_item = '';
-  if ( sizeof(plc_my_site_ids()) > 1 )
-  {
-    foreach (plc_my_site_names() as $site) 
-    {
-       $site_item .= leaf( href(l_site($site['site_id']),$site['abbreviated_name']));
-    }
-  } else {
-      $site_item .= leaf( href(l_site(plc_my_site_id()),"My Site"));
-  }
-  return $site_item;
+  return $api->GetSites($plc->person['site_ids'], array('site_id', 'abbreviated_name'));
 }
 
 function plc_my_site_id () {
@@ -367,7 +351,8 @@ function plc_errors ($errors) {
 
 function plc_warning_html ($text)      { return "<span class='plc-warning'>" . $text . "</span>";}
 function plc_warning ($text)           { print plc_warning_html("Warning " . $text); }
-function plc_foreign_html($text)       { return "<span class=plc-foreign>$text</span>"; }
+
+function bold_html ($text)             { return "<span class='bold'>$text</span>"; }
 
 // shows a php variable verbatim with a heading message
 function plc_debug ($message,$object) {
index be4d5fb..d026a03 100644 (file)
@@ -92,7 +92,7 @@ else
 $techs = array();
 $pis = array();
 $disabled_persons = array();
-foreach( $persons as $person ) {
+if ($persons) foreach( $persons as $person ) {
   $role_ids= $person['role_ids'];
 
   if ( in_array( '20', $role_ids ))    $pis[] = $person;