user in several sites gets 'All My Sites Nodes' instead of 'My Site Nodes'
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Sun, 7 Jun 2009 12:33:12 +0000 (12:33 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Sun, 7 Jun 2009 12:33:12 +0000 (12:33 +0000)
modules/planetlab.module
planetlab/includes/plc_functions.php
planetlab/nodes/nodes.php

index 1964686..37de485 100644 (file)
@@ -73,6 +73,17 @@ function plc_my_site_links() {
   return $html;
 }
 
+// ditto
+function plc_my_node_links () {
+  $html = '';
+  if (count (plc_my_site_ids()) == 1) {
+    $html .= leaf( href (l_nodes_site (plc_my_site_id()),"My Site Nodes"));
+  } else {
+    $html .= leaf( href (l_nodes_person (plc_my_person_id()),"All My Sites Nodes"));
+  }
+  return $html;
+}
+
 // fake theme to look like menu
 function menu_theme ($menu) {
   $result = '';
@@ -170,7 +181,7 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array()) {
       $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 .= plc_my_node_links();
       $bullet_item .= leaf( href (l_register_node(),"Register Node"));
       $bullet_item .= ul_end();
       $items [] = expanded($bullet_item);
index 46b9c26..aa6cbd5 100644 (file)
@@ -47,6 +47,9 @@ function plc_my_site_id () {
   return $plc->person['site_ids'][0];
 }
 
+function plc_my_person () {
+  return $plc->person;
+}
 function plc_my_person_id () {
   global $plc;
   return $plc->person['person_id'];
@@ -74,6 +77,7 @@ function l_node_t ($node_id,$text)    { return href (l_node($node_id),$text); }
 function l_node_obj($node)             { return href(l_node($node['node_id']),$node['hostname']); }
 function l_node_add ()                 { return "/db/nodes/node_add.php"; }
 function l_nodes_site ($site_id)       { return "/db/nodes/index.php?site_id=$site_id"; }
+function l_nodes_person ($person_id)   { return "/db/nodes/index.php?person_id=$person_id"; }
 function l_nodes_slice ($slice_id)     { return "/db/nodes/index.php?slice_id=$slice_id"; }
 
 function l_interface ($interface_id)   { return "/db/nodes/interface.php?id=$interface_id"; }
index 3e819f4..a6528d1 100644 (file)
@@ -28,6 +28,7 @@ $peerscope=$_GET['peerscope'];
 $pattern=$_GET['pattern'];
 $site_id=intval($_GET['site_id']);
 $slice_id=intval($_GET['slice_id']);
+$person_id=intval($_GET['person_id']);
 
 // --- decoration
 $title="Nodes";
@@ -54,7 +55,6 @@ function node_status ($node) {
   return plc_vertical_table($messages,'plc-warning');
 }
 
-
 // fetch nodes 
 $node_columns=array('hostname','node_type','site_id','node_id','boot_state','interface_ids','peer_id', 'arch','slice_ids');
 // server-side filtering - set pattern in $_GET for filtering on hostname
@@ -88,6 +88,23 @@ if ($slice_id) {
   $node_filter['node_id'] = $slice['node_ids'];
  }
 
+// person_id is set : this is mostly oriented towards people managing several sites
+if ($person_id) {
+  // avoid doing a useless call to GetPersons if the person_id is already known though $plc,
+  // as this is mostly done for the 'all my sites nodes' link
+  if ($person_id == plc_my_person_id()) { 
+    $person=plc_my_person();
+    $site_ids = plc_my_site_ids();
+  } else {
+    // fetch the person's site_ids
+    $persons = $api->GetPersons(array('person_id'=>$person_id),array('person_id','email','site_ids'));
+    $person=$persons[0];
+    $site_ids=$person['site_ids'];
+  }
+  $title .= t_person($person);
+  $node_filter['site_id']=$site_ids;
+ }
+
 // go
 $nodes=$api->GetNodes($node_filter,$node_columns);