rework footers
[plewww.git] / planetlab / nodes / node.php
index 8e4117b..3430a8d 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 
-  // $Id$
+// $Id$
 
-  // Require login
+// Require login
 require_once 'plc_login.php';
 
 // Get session and API handles
@@ -15,6 +15,7 @@ include 'plc_header.php';
 
 // Common functions
 require_once 'plc_functions.php';
+require_once 'plc_peers.php';
 require_once 'plc_minitabs.php';
 require_once 'plc_tables.php';
 require_once 'plc_details.php';
@@ -50,8 +51,9 @@ $interface_ids= $node['interface_ids'];
 $nodegroup_ids= $node['nodegroup_ids'];
 $pcu_ids= $node['pcu_ids'];
 
-// get peer
-$peer_id= $node['peer_id'];
+// get peers
+$peer_id = $node['peer_id'];
+$peers=new Peers ($api);
 
 // gets site info
 $sites= $api->GetSites( array( $site_id ) );
@@ -95,19 +97,16 @@ if( !empty( $pcu_ids ) )
 
 //////////////////// display node info
 
-// fetches peers and initialize hash peer_id->peer
-$peer_hash = plc_peer_global_hash ($api);
-// show gray background on foreign objects : start a <div> with proper class
-plc_peer_block_start ($peer_hash,$peer_id);
-  
 drupal_set_title("Details for node " . $hostname);
+$local_peer= ! $peer_id;
+
   
 // extra privileges to admins, and (pi||tech) on this site
 $privileges = plc_is_admin () || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
   
 $tabs=array();
 // available actions
-if ( ! $peer_id  && $privileges ) {
+if ( $local_peer  && $privileges ) {
     
   $tabs['Update'] = array ('url'=>"/db/nodes/node_actions.php",
                           'method'=>'POST',
@@ -116,30 +115,41 @@ if ( ! $peer_id  && $privileges ) {
   $tabs['Delete'] = array ('url'=>"/db/nodes/node_actions.php",
                           'method'=>'POST',
                           'values'=>array('action'=>'delete','node_id'=>$node_id),
-                          'bubble'=>"Delete $hostname",
+                          'bubble'=>"Delete node $hostname",
                           'confirm'=>'Are you sure to delete ' . $hostname. ' ?');
   // xxx subject to roles
-  $tabs["Add Interface"]=l_interface_add($node_id);
-  $tabs["Comon"]=array('url'=>l_comon("node_id",$node_id),
-                      'buble'=>"Comon page for $hostname");
-  $tabs["Events"]=array('url'=>l_event("Node","node",$node_id),
-                       'bubble'=>"Events for node $hostname");
+  $tabs["Add Interface"]=array('url'=>l_interface_add($node_id),
+                              'bubble'=>"Declare new network interface on $hostname");
+  $tabs["Events"]=array_merge(tabs_events(),
+                             array('url'=>l_event("Node","node",$node_id),
+                                   'bubble'=>"Events for node $hostname"));
+  $tabs["Comon"]=array_merge(tabs_comon(),
+                            array('url'=>l_comon("node_id",$node_id),
+                                  'bubble'=>"Comon page about node $hostname"));
  }
 
 $tabs["All nodes"]=l_nodes();
 
 plc_tabs($tabs);
 
+// show gray background on foreign objects : start a <div> with proper class
+$peers->block_start ($peer_id);
+  
 plc_details_start ();
+if ( ! $local_peer) {
+  plc_details_line("Peer",$peers->peer_link($peer_id));
+  plc_details_space_line();
+ }
+
 plc_details_line("Hostname",$hostname);
 plc_details_line("Type",$node_type);
 plc_details_line("Model",$model);
 plc_details_line("Version",$version);
-
 // no tool to implement this multiple-choice setting yet
 // xxx would need at least to use the proper class, like plc_details_class() or something
+plc_details_space_line ();
 echo "<tr><th>Boot State: </th><td>";
-if ($peer_id) {
+if ( ! $local_peer) {
   echo $boot_state;
  } else {
   echo "<form name='bootstate' action='/db/nodes/node_actions.php' method=post>\n";
@@ -163,7 +173,7 @@ if ($peer_id) {
 echo "</td></tr>\n";
 
 // same here for the download area
-if ( ! $peer_id  && $privileges) {
+if ( $local_peer  && $privileges) {
 
   echo "<tr><th>Download </th><td>";
   echo "<form name='download' action='/db/nodes/node_actions.php' method='post'>\n";
@@ -195,65 +205,106 @@ plc_details_line_list ("All site nodes",$nodes_area);
 
 plc_details_end ();
 
+plc_form_start(l_actions(), array('node_id'=>$node_id));
+
 //////////////////////////////////////////////////////////// Tags
 // get tags
-$tags=$api->GetNodeTags (array('node_id'=>$node_id));
-$tagnames = array_map ("get_tagname",$tags);
-//plc_debug('tagnames',$tagnames);
-$nodegroups_hash=plc_nodegroup_global_hash($api,$tagnames);
-//plc_debug('hash',$nodegroups_hash);
-
-plc_section("Tags");
-$headers=array("Name"=>"string",
-              "Value"=>"string",
-              "Nodegroup"=>"string");
-
-$table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
-plc_table_start("node_tags",$headers,0,$table_options);
-if ($tags) foreach ($tags as $tag) {
-  // does this match a nodegroup ?
-  $nodegroup_name="n/a";
-  $nodegroup_key=$tag['tagname'] . "=" . $tag['value'];
-  $nodegroup=$nodegroups_hash[$nodegroup_key];
-  if ($nodegroup) $nodegroup_name=l_nodegroup_t($nodegroup['nodegroup_id'],$nodegroup['groupname']);
-  plc_table_row_start();
-  plc_table_cell($tag['tagname']);
-  plc_table_cell($tag['value']);
-  plc_table_cell($nodegroup_name);
-  plc_table_row_end();
-}
-plc_table_end("node_tags");
+if ( $local_peer ) {
+  
+  $tags=$api->GetNodeTags (array('node_id'=>$node_id));
+  function get_tagname ($tag) { return $tag['tagname'];}
+  $tagnames = array_map ("get_tagname",$tags);
+  $nodegroups_hash=plc_nodegroup_global_hash($api,$tagnames);
+  
+  plc_section("Tags");
+  $headers=array("Name"=>"string",
+                "Value"=>"string",
+                "Nodegroup"=>"string",
+                "Remove"=>"string",
+                );
+  
+  $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
+  $table=new PlcTable("node_tags",$headers,0,$table_options);
+  $table->start();
+  if ($tags) foreach ($tags as $tag) {
+      // does this match a nodegroup ?
+      $nodegroup_name="n/a";
+      $nodegroup_key=$tag['tagname'] . "=" . $tag['value'];
+      $nodegroup=$nodegroups_hash[$nodegroup_key];
+      if ($nodegroup) $nodegroup_name=l_nodegroup_t($nodegroup['nodegroup_id'],$nodegroup['groupname']);
+      $table->row_start();
+      $table->cell($tag['tagname']);
+      $table->cell($tag['value']);
+      $table->cell($nodegroup_name);
+      $table->cell (plc_form_checkbox_text('node_tag_ids[]',$tag['node_tag_id']));
+      $table->row_end();
+    }
+  
+  if ($privileges) {
+    $table->tfoot_start();
+
+    // remove tag 
+    $table->row_start();
+    $table->cell(plc_form_submit_text("remove-node-tags","Remove Tags"),
+                // use the whole columns and right adjust
+                $table->columns(), "right");
+    $table->row_end();
+
+    // set tag area
+    $table->row_start();
+    // get list of tag names in the node/* category    
+    $all_tags= $api->GetTagTypes( array ("category"=>"node*"), array("tagname","tag_type_id"));
+    // xxx cannot use onchange=submit() - would need to somehow pass action name 
+    function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
+    $selector=array_map("tag_selector",$all_tags);
+    $table->cell(plc_form_select_text("tag_type_id",$selector,"Choose"));
+    $table->cell(plc_form_text_text("value","",8));
+    $table->cell(plc_form_submit_text("set-tag-on-node","Set Tag"),2,"left");
+    $table->row_end();
+  }
+  
+  $table->end();
+ }
 
 //////////////////////////////////////////////////////////// slices
 // display slices
 
 plc_section ("Slices");
 if ( ! $slices  ) {
-  echo "<p><span class='plc-warning'>This node is not associated to any slice.</span></p>\n";
+  plc_warning ("This node is not associated to any slice");
  } else {
   $headers=array();
   $headers['Peer']="string";
   $headers['Name']="string";
   $headers['Slivers']="string";
-  $table_options = array('notes_area'=>false,"search_width"=>10);
-  plc_table_start ("node_slices",$headers,1,$table_options);
+  $reasonable_page=10;
+  $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
+  if (count ($slices) <= $reasonable_page) {
+    $table_options['search_area']=false;
+    $table_options['pagesize_area']=false;
+  }
+  $table=new PlcTable("node_slices",$headers,1,$table_options);
+  $table->start();
 
   foreach ($slices as $slice) {
-    plc_table_row_start($slice['name']);
-    plc_table_cell (plc_peer_shortname($peer_hash,$slice['peer_id']));
-    plc_table_cell (l_slice_t ($slice['slice_id'],$slice['name']));
-    plc_table_cell (l_sliver_t ($node_id,$slice['slice_id'],'view'));
-    plc_table_row_end();
+    $table->row_start();
+    $table->cell ($peers->shortname($peer_id));
+    $table->cell (l_slice_t ($slice['slice_id'],$slice['name']));
+    $table->cell (l_sliver_t ($node_id,$slice['slice_id'],'view'));
+    $table->row_end();
   }
-  plc_table_end("node_slices");
+  $table->end();
  }
 
 //////////////////////////////////////////////////////////// interfaces
-if ( ! $peer_id ) {
+if ( $local_peer ) {
 
+  plc_section ("Interfaces");
   // display interfaces
   if( ! $interfaces ) {
-    echo "<p><span class='plc-warning'>No interface</span>.  Please add an interface to make this a usable PLC node</p>.\n";
+    echo '<p>';
+    plc_warning_text("This node has no interface");
+    echo "Please add an interface to make this a usable PLC node.</p>\n";
   } else {
     $headers=array();
     if ( $privileges ) {
@@ -267,9 +318,9 @@ if ( ! $peer_id ) {
     $headers["MAC"]="string";
     $headers["bw limit"]="FileSize";
 
-    plc_section('Interfaces');
     $table_options=array('search_area'=>false,"pagesize_area"=>false,'notes_area'=>false);
-    plc_table_start("node_interfaces",$headers,2,$table_options);
+    $table=new PlcTable("node_interfaces",$headers,2,$table_options);
+    $table->start();
        
     foreach ( $interfaces as $interface ) {
       $interface_id= $interface['interface_id'];
@@ -287,33 +338,38 @@ if ( ! $peer_id ) {
       $interface_type= $interface['type'];
       $interface_method= $interface['method'];
 
-      plc_table_row_start($interface['ip']);
+      $table->row_start();
       if ( $privileges ) {
        if (!$interface_primary) {
          // xxx 
-         plc_table_cell (plc_delete_link_button ('interfaces.php?id=' . $interface_id . '&delete=1&submitted=1', 
+         $table->cell (plc_delete_link_button ('interfaces.php?id=' . $interface_id . '&delete=1&submitted=1', 
                                                  '\\nInterface ' . $interface_ip));
        } else {
-         plc_table_cell('p');
+         $table->cell('p');
        }
       }
-      plc_table_cell(l_interface_t($interface_id,$interface_ip));
-      plc_table_cell($interface_method);
-      plc_table_cell($interface_type);
-      plc_table_cell($interface_mac);
-      plc_table_cell($interface_bwlimit);
-      plc_table_row_end();
+      $table->cell(l_interface_t($interface_id,$interface_ip));
+      $table->cell($interface_method);
+      $table->cell($interface_type);
+      $table->cell($interface_mac);
+      $table->cell($interface_bwlimit);
+      $table->row_end();
     }
     if ($privileges) {
-      $button=plc_form_simple_button(l_interface_add($node_id),"Add interface","GET");
-      $footers=array(plc_table_td_text($button,6,"right"));
+      $table->tfoot_start();
+      $table->row_start();
+      $table->cell(plc_form_simple_button(l_interface_add($node_id),"Add interface","GET"),
+                  $table->columns(),"right");
+      $table->row_end();
     }
-    plc_table_end("node_interfaces",array("footers"=>$footers));
+    $table->end();
   }
  }
-      
+
+plc_form_end();
+
 ////////////////////////////////////////////////////////////
-plc_peer_block_end();
+$peers->block_end($peer_id);
 
 
 // Print footer