get_array
[plewww.git] / planetlab / slices / slices.php
index f4ebb5c..319f379 100644 (file)
@@ -21,17 +21,25 @@ require_once 'plc_functions.php';
 require_once 'plc_peers.php';
 require_once 'linetabs.php';
 require_once 'table.php';
+require_once 'nifty.php';
 
-// -------------------- 
+// --------------------
 // recognized URL arguments
-$peerscope=$_GET['peerscope'];
-$pattern=$_GET['pattern'];
-$site_id=intval($_GET['site_id']);
-$person_id=intval($_GET['person_id']);
+$peerscope=get_array($_GET, 'peerscope');
+$pattern=get_array($_GET, 'pattern');
+$site_id=intval(get_array($_GET, 'site_id'));
+$person_id=intval(get_array($_GET, 'person_id'));
 
 // --- decoration
 $title="Slices";
 $tabs=array();
+
+if (plc_is_admin()) {
+    $tabs []= tab_slices();
+}
+if (plc_is_user()) {
+    $tabs []= tab_slices_person();
+}
 $tabs []= tab_slices_mysite();
 if (plc_is_admin()) $tabs []= tab_slices_local();
 
@@ -50,7 +58,7 @@ if ($pattern) {
  }
 
 // server-side selection on peerscope
-$peerscope=new PeerScope($api,$_GET['peerscope']);
+$peerscope=new PeerScope($api,get_array($_GET, 'peerscope'));
 $slice_filter=array_merge($slice_filter,$peerscope->filter());
 $title .= ' - ' . $peerscope->label();
 
@@ -66,12 +74,13 @@ if ($site_id) {
 }
 
 if ($person_id) {
-  $persons=$api->GetPersons(array('person_id'=>$person_id,array('email','person_id','slice_ids')));
-  $person=$persons[0];
-  $title .= t_person($person);
-  $tabs .= tab_person($person);
-  $slice_filter['slice_id']=$person['slice_ids'];
- }
+    // fetch the person's slice_ids
+    $persons = $api->GetPersons(array('person_id'=>$person_id),array('person_id','email','slice_ids'));
+    $person=$persons[0];
+    $slice_ids['slice_id']=$person['slice_ids'];
+    $title .= t_person($person);
+    $slice_filter['slice_id']=$person['slice_ids'];
+}
 
 // go
 $slices=$api->GetSlices($slice_filter,$slice_columns);
@@ -86,8 +95,8 @@ global $person_hash;
 $person_hash=array();
 if ($persons) foreach ($persons as $person) $person_hash[$person['person_id']]=$person;
 
-function email_link_from_hash($person_id) { 
-  global $person_hash; 
+function email_link_from_hash($person_id) {
+  global $person_hash;
   return l_person_obj($person_hash[$person_id]);
 }
 
@@ -100,36 +109,49 @@ if ( ! $slices ) {
   drupal_set_message ('No slice found');
   return;
  }
-  
-$headers = array ("Peer"=>"string",
-                 "Name"=>"string",
-                 "Users"=>"string",
-                 "N"=>"int",
-                 "Exp. d/m/y"=>"date-dmy");
+
+$nifty=new PlekitNifty ('','objects-list','big');
+$nifty->start();
+if (plc_is_admin()) $headers["I"]="int";
+$headers["Peer"]="string";
+$headers["Name"]="string";
+$headers["Users"]="string";
+$headers["U"]="int";
+$headers["N"]="int";
+$headers["Exp. d/m/y"]="date-dmy";
 
 # initial sort on hostnames
-$table=new PlekitTable ("slices",$headers,2,
+if (plc_is_admin()) $slices_sort_column = 3;
+else $slices_sort_column = 2;
+
+$table=new PlekitTable ("slices",$headers,$slices_sort_column,
                        array('search_width'=>20));
 $table->start();
 
 $peers = new Peers ($api);
 // write rows
 foreach ($slices as $slice) {
+  $slice_id=$slice['slice_id'];
   $peer_id=$slice['peer_id'];
-  $shortname = $peers->shortname($peer_id);
   $users=plc_vertical_table (array_map ("email_link_from_hash",$slice['person_ids']));
   $expires= date( "d/m/Y", $slice['expires'] );
 
   $table->row_start();
-  $table->cell ($peers->link($peer_id,$shortname));
-  $table->cell (l_slice_obj($slice));
+  if (plc_is_admin()) $table->cell (l_slice_t($slice_id,$slice_id));
+  $peers->cell($table,$peer_id);
+  $table->cell (href(l_slice_nodes($slice_id),$slice['name']));
   $table->cell ($users);
-  $table->cell (href(l_nodes_slice($slice['slice_id']),count($slice['node_ids'])));
+  $table->cell(href(l_persons_slice($slice_id),count($slice['person_ids'])));
+  $table->cell (href(l_nodes_slice($slice_id),count($slice['node_ids'])));
   $table->cell ($expires);
   $table->row_end();
 }
 
-$table->end();
+$notes=array();
+$notes []= "U = number of users";
+$notes []= "N = number of nodes";
+$table->end(array('notes'=>$notes));
+$nifty->end();
 
 //plekit_linetabs ($tabs,"bottom");