ckp - persons/nodes/peers/events complete
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 29 Jan 2009 10:11:53 +0000 (10:11 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 29 Jan 2009 10:11:53 +0000 (10:11 +0000)
14 files changed:
modules/planetlab.module
planetlab/css/plc_tables.css
planetlab/events/index.php
planetlab/includes/plc_forms.php
planetlab/includes/plc_functions.php
planetlab/includes/plc_tables.php
planetlab/nodes/node.php
planetlab/nodes/nodes.php
planetlab/nodes/settings.php
planetlab/peers/peers.php
planetlab/persons/person.php
planetlab/persons/person_actions.php
planetlab/persons/persons.php
planetlab/sites/index.php

index 8d838ea..e24e933 100644 (file)
@@ -111,6 +111,7 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array()) {
       $is_user  = in_array(30,$plc->person['role_ids']);
       $is_tech  = in_array(40,$plc->person['role_ids']);
 
+      //////////////////// Sites
       $site_item = '';
       $site_item .= href(l_sites(),"Sites");
       $site_item .= ul_start();
@@ -120,6 +121,7 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array()) {
       $site_item .= ul_end();
       $items[] = expanded($site_item);
 
+      //////////////////// Users
       $user_item = '';
       $user_item .= href(l_persons(),'Users');
       $user_item .= ul_start();
@@ -133,16 +135,16 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array()) {
       $user_item .= ul_end();
       $items [] = expanded($user_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_node_add(),"Add Node"));
-      if ( $is_admin) 
-       $node_item .= leaf (href(l_peers(),'Peers'));
       $node_item .= ul_end();
       $items [] = expanded($node_item);
 
+      //////////////////// Slices
       $slice_item = '';
       //if( !( $is_tech && ! $is_user && ! $is_pi && ! $is_admin ) ) 
       $slice_item .= href(l_slices(),"Slices");
@@ -155,17 +157,21 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array()) {
       $slice_item .= ul_end();
       $items [] = expanded($slice_item);
 
+      //////////////////// Admin
       if( $is_admin || $is_pi ) {
-       $tag_item = '';
-       $tag_item .= href(l_tags(),"All Tag Types");
-       $tag_item .= ul_start();
-       $tag_item .= leaf( href( l_tags_slice(),"Slice Tags"));
-       $tag_item .= leaf( href( l_tags_interface(),"Interface Tags"));
-       $tag_item .= leaf( href (l_tags_interface(),"Setting Types (dup xxx)"));
-       $tag_item .= leaf( href( l_tags_node(),"Node Tags"));
-       $tag_item .= leaf( href( l_nodegroups(),"Node groups (xxx)"));
-       $tag_item .= ul_end();
-       $items [] = expanded($tag_item);
+       $admin_item = '';
+       $admin_item .= href(l_admin(),"Admin");
+       $admin_item .= ul_start();
+       $admin_item .= leaf( href( l_tags(),"Tags"));
+       $admin_item .= leaf( href( l_nodegroups(),"Node groups (xxx)"));
+       // xxx need to cleanup
+       //$admin_item .= leaf( href( l_tags_slice(),"Slice Tags"));
+       //$admin_item .= leaf( href( l_tags_interface(),"Interface Tags"));
+       //$admin_item .= leaf( href (l_tags_interface(),"Setting Types (dup xxx)"));
+       //$admin_item .= leaf( href( l_tags_node(),"Node Tags"));
+       $admin_item .= leaf (href(l_peers(),'Peers'));
+       $admin_item .= ul_end();
+       $items [] = expanded($admin_item);
       }
 
       $doc_item = '';
index 2fad1f2..1fce227 100644 (file)
@@ -3,9 +3,12 @@ table.plc_table {
     width: auto;
     padding: 0;
     margin: 0 auto 1.5em auto;
-    border-left: 1px solid #C1DAD7;
     border-collapse:collapse;
 }
+table.plc_table thead tr, table.plc_table tbody tr {
+    border-left: 1px solid #C1DAD7; 
+}    
+
 th.plc_table {
     font: bold 10px/22px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
     color: #4f6b72;
index d076ca3..e1b9ad2 100644 (file)
@@ -358,7 +358,7 @@ if ( ! plc_is_admin()) {
     foreach ($messages as $line) 
       drupal_set_message($line);
 
-  $columns=array("Id"=>"int",
+  $headers=array("Id"=>"int",
                 "Time"=>"EnglishDateTime",
                 "Method"=>"string",
                 "Message"=>"string",
@@ -370,10 +370,10 @@ if ( ! plc_is_admin()) {
                 );
 
   $table_options=array('notes'=>array("The R column shows the call result value, a.k.a. fault_code",
-                                     "Click the button in the D(etails) columns to get more details",
+                                     "Click the button in the D(etails) column to get more details",
                                      ),
                       'max_pages'=>20);
-  plc_table_start("events",$columns,"0r",$table_options);
+  plc_table_start("events",$headers,"0r",$table_options);
   foreach ($events as $event) {
 
     // the call button
index 41c02e8..2197e13 100644 (file)
@@ -4,6 +4,10 @@
 
 require_once 'plc_functions.php';
 
+// the rationale behind having function names with _text is that
+// the first functions that we had were actually printing the stuff instead of returning it
+// so basically the foo (...) function should do ``print (foo_text(...))''
+
 function plc_form_start ($url, $values, $options=array()) {
   $method = array_key_exists('method',$options) ? $options['method'] : 'POST';
   print "<form method=$method action='$url' enctype='multipart/form-data'>";
@@ -29,8 +33,22 @@ function plc_form_file_text ($name,$size) {
   return "<input type=file name='$name' size=$size>";
 }
 
-function plc_form_label_text ($label,$name) {
-  return "<label for=$name>$text </label>";
+function plc_form_label_text ($name,$display) {
+  return "<label for=$name>$display </label>";
 }
  
+function plc_form_select_text ($name,$values,$label="") {
+  $selector="";
+  $selector.="<select name='$name'>";
+  if ($label) 
+    $selector.="<option value=''>$label</option>";
+  foreach ($values as $chunk) {
+    $display=$chunk['display'];
+    $value=$chunk['value'];
+    $selector .= "<option value='$value'>$display</option>\n";
+  }
+  $selector .= "</select>";
+  return $selector;
+}
+
 ?>
index a28c3c7..7e43d39 100644 (file)
@@ -95,6 +95,7 @@ function l_sirius()                   { return "/db/sirius/index.php"; }
 function l_about()                     { return "/db/about.php"; }
 function l_doc_plcapi()                        { return "/db/doc/PLCAPI.php"; }
 function l_doc_nmapi()                 { return "/db/doc/NMAPI.php"; }
+function l_admin()                     { return "/db/admin-not-yet-implemented-see-plcwww"; }
 
 function l_logout()                    { return "/planetlab/logout.php"; }
 function l_sulogout()                  { return "/planetlab/sulogout.php"; }
@@ -186,7 +187,7 @@ function is_reserved_network_addr($network_addr) {
 
 ////////////////////////////////////////////////////////////  peer & peerscopes
 // when shortnames are needed on peers
-function plc_peer_get_hash ($api) {
+function plc_peer_global_hash ($api) {
   $peer_columns=array('peer_id','shortname');
   $peer_filter=array();
   $peers = $api->GetPeers($peer_filter,$peer_columns);
@@ -314,6 +315,9 @@ function plc_vertical_table ($messages, $class="") {
   return $formatted;
 }
 
+//////////////////////////////////////////////////////////// various mappers
+function get_site_id ($site) { return $site['site_id'];}
+
 ////////////////////////////////////////////////////////////
 function plc_error ($text) {
   // should use the same channel as the php errors..
index e2c08ce..5b13810 100644 (file)
@@ -9,7 +9,7 @@ drupal_set_html_head('
 ');
 
 
-//// hash to retrieve the columns and options as passed at table-creation time
+//// hash to retrieve the headers and options as passed at table-creation time
 // this means that table_id's need to be different across the page,
 // which is required anyway for the search and pagesize areas to work properly
 $plc_table_hash=array();
@@ -30,6 +30,7 @@ function plc_table_cell($cell) {
 //  - pagesize: the initial pagination size
 //  - pagesize_def: the page size when one clicks the pagesize reset button
 //  - max_pages: the max number of pages to display in the paginator
+//  - footers: a list of table rows (<tr> will be added) for building the table's tfoot area
 function plc_table_start ($table_id, $headers, $column_sort, $options=NULL) {
   if ( ! $options ) $options = array();
   global $plc_table_hash;
@@ -44,9 +45,14 @@ function plc_table_start ($table_id, $headers, $column_sort, $options=NULL) {
   plc_table_head($table_id,$headers,$column_sort,$max_pages,$pagesize);
 }
 
-function plc_table_end ($table_id) {
+// for convenience, the options that apply to the footer only can be passed in plc_table_end()
+// they add up to the ones provided to the begin clause
+// makes code more readable, as preparing the footer before the table is displayed is confusing
+function plc_table_end ($table_id,$options_end=NULL) {
   global $plc_table_hash;
   list($headers,$options) = $plc_table_hash[$table_id];
+  if ($options_end) 
+    $options=array_merge($options,$options_end);
 
   plc_table_foot($options);
   $notes_area = array_key_exists('notes_area',$options) ? $options['notes_area'] : true;
@@ -132,7 +138,9 @@ EOF;
 ////////////////////////////////////////
 function plc_table_foot ($options) {
   print "</tbody><tfoot>";
-  print $options['footer'];
+  if ($options['footers']) 
+    foreach ($options['footers'] as $footer) 
+      print "<tr> $footer </tr>";
   print "</tfoot></table>\n";
 }
 
index d8ad55a..096428d 100644 (file)
@@ -93,7 +93,7 @@ if (empty($nodes)) {
   //////////////////// display node info
 
   // fetches peers and initialize hash peer_id->peer
-  $peer_hash = plc_peer_get_hash ($api);
+  $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);
   
@@ -198,12 +198,12 @@ if (empty($nodes)) {
   if ( ! $slices  ) {
     echo "<p><span class='plc-warning'>This node is not associated to any slice.</span></p>\n";
   } else {
-    $columns=array();
-    $columns['Peer']="string";
-    $columns['Name']="string";
-    $columns['Slivers']="string";
+    $headers=array();
+    $headers['Peer']="string";
+    $headers['Name']="string";
+    $headers['Slivers']="string";
     $table_options = array('notes_area'=>false);
-    plc_table_start ("slivers",$columns,1,$table_options);
+    plc_table_start ("slivers",$headers,1,$table_options);
 
     foreach ($slices as $slice) {
       plc_table_row_start($slice['name']);
@@ -222,22 +222,22 @@ if (empty($nodes)) {
     if( ! $interfaces ) {
       echo "<p><span class='plc-warning'>No interface</span>.  Please add an interface to make this a usable PLC node</p>.\n";
     } else {
-      $columns=array();
+      $headers=array();
       if ( $privileges ) {
        // a single symbol, marking 'p' for primary and a delete button for non-primary
-       $columns[' ']='string';
+       $headers[' ']='string';
       }
         
-      $columns["IP"]="IPAddress";
-      $columns["Method"]="string";
-      $columns["Type"]="string";
-      $columns["MAC"]="string";
-      $columns["bw limit"]="FileSize";
+      $headers["IP"]="IPAddress";
+      $headers["Method"]="string";
+      $headers["Type"]="string";
+      $headers["MAC"]="string";
+      $headers["bw limit"]="FileSize";
 
       print "<hr/>\n";
       plc_table_title('Interfaces');
       $table_options=array('search_area'=>false);
-      plc_table_start("interfaces",$columns,2,$table_options);
+      plc_table_start("interfaces",$headers,2,$table_options);
        
       foreach ( $interfaces as $interface ) {
        $interface_id= $interface['interface_id'];
@@ -282,15 +282,15 @@ if (empty($nodes)) {
   if ( ! $nodegroups ) {
     echo "<p><span class='plc-warning'>This node is not in any nodegroup.</span></p>\n";
   } else {
-    $columns=array();
-    $columns['Name']="string";
-    $columns['Tag']="string";
-    $columns['Value']="string";
+    $headers=array();
+    $headers['Name']="string";
+    $headers['Tag']="string";
+    $headers['Value']="string";
       
     print "<hr/>\n";
     plc_table_title("Nodegroups");
     $table_options = array('search_area'=>false);
-    plc_table_start("nodegroups",$columns,0,$table_options);
+    plc_table_start("nodegroups",$headers,0,$table_options);
 
     foreach( $nodegroups as $nodegroup ) {
       plc_table_row_start();
index 6e1f501..0db6054 100644 (file)
@@ -102,9 +102,7 @@ $interface_filter=array('is_primary'=>TRUE,'interface_id'=>$interface_ids);
 $interfaces=$api->GetInterfaces($interface_filter,$interface_columns);
 
 $interface_hash=array();
-foreach ($interfaces as $interface) {
-    $interface_hash[$interface['node_id']]=$interface;
-}
+foreach ($interfaces as $interface) $interface_hash[$interface['node_id']]=$interface;
 
 // fetch related sites
 $site_columns=array('site_id','login_base');
@@ -112,9 +110,7 @@ $site_filter=array('site_id'=>$site_ids);
 $sites=$api->GetSites($site_filter,$site_columns);
 
 $site_hash=array();
-foreach ($sites as $site) {
-    $site_hash[$site['site_id']]=$site;
-}
+foreach ($sites as $site) $site_hash[$site['site_id']]=$site;
 
 // --------------------
 drupal_set_title($title);
@@ -126,7 +122,7 @@ if ( ! $nodes ) {
   return;
  }
   
-$columns = array ("Peer"=>"string",
+$headers = array ("Peer"=>"string",
                  "Region"=>"string",
                  "Site"=>"string",
                  "State"=>"string",
@@ -138,9 +134,9 @@ $columns = array ("Peer"=>"string",
                  "Float"=>"float");
 
 # initial sort on hostnames
-plc_table_start("nodes",$columns,4);
+plc_table_start("nodes",$headers,4);
 
-$peer_hash = plc_peer_get_hash ($api);
+$peer_hash = plc_peer_global_hash ($api);
 // write rows
 $fake1=1; $fake2=3.14; $fake_i=0;
 foreach ($nodes as $node) {
index 6fc759b..cf1d21a 100644 (file)
@@ -24,7 +24,7 @@ $_roles= $_person['role_ids'];
 
 //plc_debug("person", $_person );
 
-$columns=array( "tag_type_id", "category", "tagname", "description", "min_role_id" );
+$tag_columns=array( "tag_type_id", "category", "tagname", "description", "min_role_id" );
 
 // prepare dict role_id => role_name
 global $roles;
@@ -65,7 +65,7 @@ if( !$_GET['id'] && !$_GET['add'] && !$_GET['add_type'] && !$_GET['edit_type'] )
   // get types
   global $person_role;
   $filter = array (']min_role_id'=>$person_role,'category'=>'interface*');
-  $setting_types= $api->GetTagTypes( $filter, $columns );
+  $setting_types= $api->GetTagTypes( $filter, $tag_columns );
   $setting_types = array_map(layout_setting_type,$setting_types);
   sort_interface_tags ($setting_types);
   
index a9af51a..11cd42f 100644 (file)
@@ -31,14 +31,14 @@ if ( empty($peers)) {
   drupal_set_message ("You seem to be running a standalone deployment");
   } else {
   
-  $columns=array( 'Name'=>'string',
+  $headers=array( 'Name'=>'string',
                  'SN' =>'string',
                  'HRN' => 'string',
                  'URL'=>'string',
                  'Comon'=>'string');
                  
   $table_options=array('search_area'=>false, 'notes_area'=>false);
-  plc_table_start ("peers",$columns,1,$table_options);
+  plc_table_start ("peers",$headers,1,$table_options);
   foreach ($peers as $peer) {
     plc_table_row_start();
     plc_table_cell (href(l_peer($peer['peer_id']),$peer['peername']));
index 3a83228..4156076 100644 (file)
@@ -57,13 +57,14 @@ $slice_ids= $person['slice_ids'];
 $key_ids= $person['key_ids'];
 
 // gets more data from API calls
-$sites= $api->GetSites( $site_ids, array( "site_id", "name", "login_base" ) );
+$site_columns=array( "site_id", "name", "login_base" );
+$sites= $api->GetSites( $site_ids, $site_columns);
 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
 $keys= $api->GetKeys( $key_ids );
 
 drupal_set_title("Details for account " . $first_name . " " . $last_name);
 
-$plc_hash=plc_peer_get_hash($api);
+$plc_hash=plc_peer_global_hash($api);
 
 $local_peer = plc_peer_block_start ($peer_hash,$peer_id);
 $is_my_account = plc_my_person_id() == $person_id;
@@ -145,13 +146,13 @@ plc_details_end();
 echo "<hr />\n";
 plc_table_title('Slices');
 
-if( empty( $slices ) ) {
-  drupal_set_message ("User has no slice");
+if( ! $slices) {
+  plc_warning ("User has no slice");
  } else {
-  $columns=array('Slice name'=>'string');
+  $headers=array('Slice name'=>'string');
   $table_options=array('notes_area'=>false,
                       'pagesize'=>5);
-  plc_table_start("person_slices",$columns,1,$table_options);
+  plc_table_start("person_slices",$headers,1,$table_options);
 
   foreach( $slices as $slice ) {
     $slice_name= $slice['name'];
@@ -163,7 +164,14 @@ if( empty( $slices ) ) {
   plc_table_end("person_slices");
  }
 
-////////// keys          
+// we don't set 'action', but use the submit button name instead
+plc_form_start(l_person_actions(),
+              array("person_id"=>$person_id,
+                    // uncomment this to run the 'debug' action 
+                    //"action"=>"debug",
+                    ));
+
+//////////////////// keys
 echo "<hr />\n";
 plc_table_title ("Keys");
                
@@ -171,29 +179,14 @@ $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
 if ( empty( $key_ids ) ) {
   plc_warning("This user has no known key");
  } 
-// we don't set 'action', but use the submit button name instead
-plc_form_start(l_person_actions(),
-              array("person_id"=>$person_id,
-                    //"action"=>"debug",
-                    ));
 
-// the headers
-$columns=array("Type"=>"string",
+// headers
+$headers=array("Type"=>"string",
               "Key"=>"string");
-if ($can_manage_keys) $columns['Remove']="none";
+if ($can_manage_keys) $headers['Remove']="none";
 // table overall options
 $table_options=array("search_area"=>false,"notes_area"=>false);
-// add the 'remove site' button and key upload areas as the table footer
-if ($can_manage_keys) {
-  $remove_keys_area=plc_form_submit_text ("delete-keys","Remove keys");
-  $upload_key_left_area= plc_form_label_text("Upload new key","key") . plc_form_file_text("key",60);
-  $upload_key_right_area=plc_form_submit_text("upload-key","Upload key");
-  $table_options['footer']="";
-  if ($keys) $table_options['footer'].="<tr><td colspan=3 style='text-align:right'> $remove_keys_area </td></tr>";
-  $table_options['footer'].="<tr><td colspan=2 style='text-align:right'> $upload_key_left_area </td>".
-    "<td> $upload_key_right_area </td></tr>";
- }
-plc_table_start("person_keys",$columns,"1",$table_options);
+plc_table_start("person_keys",$headers,"1",$table_options);
     
 if ($keys) foreach ($keys as $key) {
   $key_id=$key['key_id'];
@@ -204,125 +197,127 @@ if ($keys) foreach ($keys as $key) {
     plc_table_cell (plc_form_checkbox_text('key_ids[]',$key_id));
   plc_table_row_end();
 }
-plc_table_end("person_keys");
-plc_form_end();
+// the footer area is used for displaying key-management buttons
+$footers=array();
+// add the 'remove keys' button and key upload areas as the table footer
+if ($can_manage_keys) {
+  $remove_keys_area=plc_form_submit_text ("delete-keys","Remove keys");
+  $upload_key_left_area= plc_form_label_text("key","Upload new key") . plc_form_file_text("key",60);
+  $upload_key_right_area=plc_form_submit_text("upload-key","Upload key");
+  // no need to remove if there's no key
+  if ($keys) 
+    $footers[]="<td colspan=3 style='text-align:right'> $remove_keys_area </td>";
+  // upload a new key
+  $footers []="<td colspan=2 style='text-align:right'> $upload_key_left_area </td>".
+    "<td> $upload_key_right_area </td>";
+}
 
-// sites
+plc_table_end("person_keys",array("footers"=>$footers));
+
+//////////////////// sites
 echo "<hr />\n";
 plc_table_title('Sites');
   
 // sites
 if (empty( $sites ) ) {
   plc_warning('This user is not affiliated with a site !!');
- } else {
-  $columns=array();
-  $columns['Name']="string";
-  $columns['Login_base']="string";
-  $columns['Remove']="string";
-  $table_options = array('notes_area'=>false,'search_area'=>false);
-  plc_table_start ("person_sites",$columns,1,$table_options);
-  foreach( $sites as $site ) {
-    $site_name= $site['name'];
-    $site_id= $site['site_id'];
-    $login_base=$site['login_base'];
-    plc_table_row_start();
-    plc_table_cell (l_site_t($site_id,$site_name));
-    plc_table_cell ($login_base);
-    plc_table_cell ("<input id=" . $login_base . " type=checkbox name='rem_site[]' value=" . $site_id . ">");
-    plc_table_row_end ();
-  }
-  plc_table_end("person_sites");
- }
+ } 
+$can_manage_sites = $local_peer && plc_is_admin() || $is_my_account;
+$headers=array();
+$headers['Login_base']="string";
+$headers['Name']="string";
+if ($can_manage_sites) 
+  $headers['Remove']="string";
+$table_options = array('notes_area'=>false,'search_area'=>false);
+plc_table_start ("person_sites",$headers,0,$table_options);
+foreach( $sites as $site ) {
+  $site_name= $site['name'];
+  $site_id= $site['site_id'];
+  $login_base=$site['login_base'];
+  plc_table_row_start();
+  plc_table_cell ($login_base);
+  plc_table_cell (l_site_t($site_id,$site_name));
+  if ($can_manage_sites)
+    plc_table_cell (plc_form_checkbox_text('site_ids[]',$site_id));
+  plc_table_row_end ();
+}
+// footers : the remove and add buttons
+$footers=array();
+if ($can_manage_sites) {
+  // remove selected sites
+  $remove_sites_area = plc_form_submit_text("remove-person-from-sites","Remove Sites");
 
-echo "<input type=submit name='Remove_Sites' value='Remove Sites'>\n";
-  
-       
-// diplay site select list to add another site for user
-if ($local_peer && plc_is_admin()) {
-  // get site info
-  $all_sites= $api->GetSites( NULL, array( "site_id", "name" ) );
-    
-  if( $sites )
-    $person_site= arr_diff( $all_sites, $sites );
-  else
-    $person_site= $all_sites;
-    
-  //    sort_sites( $person_site );
-    
-  echo "<p>Select a site to add this user to: ";
-  echo "<select name='site_add' onChange='submit()'>\n<option value=''>Choose a site to add:</option>\n";
-    
-  foreach( $person_site as $site ) {
-    echo "<option value=". $site['site_id'] .">". $site['name'] ."</option>\n";
-      
-  }
-    
-  echo "</select>";
-    
+  // add a site : the button
+  $add_site_left_area=plc_form_submit_text("add-person-to-site","Add in site");
+  // get list of local sites that the person is not in
+  $person_site_ids=array_map("get_site_id",$sites);
+  $relevant_sites= $api->GetSites( array("peer_id"=>NULL,"~site_id"=>$person_site_ids), $site_columns);
+
+  // xxx cannot use onchange=submit() - would need to somehow pass action name 
+  $selector=array();
+  foreach ($relevant_sites as $site) 
+    $selector[]= array('display'=>$site['name'],"value"=>$site['site_id']);
+  $add_site_right_area=plc_form_select_text("site_id",$selector,"Choose a site to add");
+  if ($sites) 
+    $footers[]="<td colspan=3 style='text-align:right'> $remove_sites_area </td>";
+  // add a new site
+  $footers []="<td style='text-align:right'> $add_site_left_area </td>".
+    "<td colspan=2> $add_site_right_area </td>";
  }
+plc_table_end("person_sites",array("footers"=>$footers));
+
+//////////////////// roles
 echo "<hr />\n";
+plc_table_title("Roles");
+if (! $roles) plc_warning ("This user has no role !");
+
+$can_manage_roles= ($local_peer && plc_is_admin());
+$table_options=array("search_area"=>false,"notes_area"=>false);
+
+$headers=array("Role"=>"none");
+if ($can_manage_roles) $headers ["Remove"]="none";
+
+plc_table_start("person_roles",$headers,0,$table_options);  
   
-// roles
-echo "<h3>Roles</h3>\n";
-echo "<p><table>\n";
-echo "<thead><tr><th>Role</th>";
-if( plc_is_admin())
-  echo "<th>Remove</th>";
-echo "</tr></thead><tbody>\n";
-  
-// construct role array
-for( $n=0; $n<count($roles); $n++ ) {
-  $proles[]= array( 'role_id'=>$role_ids[$n], 'name'=>$roles[$n] );
+// construct array of role objs
+$role_objs=array();
+for ($n=0; $n<count($roles); $n++) {
+  $role_objs[]= array('role_id'=>$role_ids[$n], 'name'=>$roles[$n]);
  }
-    
-$button_shown=0;
-if ( !empty ($roles) ) {
-  foreach( $proles as $role ) {
-    $role_name= $role['name'];
-    $role_id= $role['role_id'];
-      
-    echo "<tr><td>$role_name";
-             
-
-    if( plc_is_admin()) {
-      echo "</td><td><input type=checkbox name='rem_role[]' value='$role_id'>";
-      if ( ! $button_shown ) {
-       $rowspan=count($roles);
-       echo "</td><td rowspan=$rowspan valign=center><input type=submit name='Remove_Roles' value='Remove Roles'></td></tr>\n";
-       $button_shown=1;
-      }
-    }
-      
-    echo "</td></tr>\n";
-  }
- } else {
-  echo "<span class='plc-warning'> This user has no known role !!</span>";
+
+if ($role_objs) foreach ($role_objs as $role_obj) {
+  plc_table_row_start();
+  plc_table_cell($role_obj['name']);
+  if ($can_manage_roles) plc_table_cell (plc_form_checkbox_text('role_ids[]',$role_obj['role_id']));
+  plc_table_row_end();
  }
-echo "</tbody></table>\n";
-         
-// if admin show roles to add
-if( plc_is_admin()) {
-  $all_roles= $api->GetRoles();
-  $addable_roles= arr_diff( $all_roles, $proles );
-  ##when the proles array is empty strangely the method arr_diff($all_roles, $proles )
-  ##return an empty array and the scrolling roles list is not displayed in this case
-  ##assign to addablerole all the roles
-  if (count($proles)==0)
-    $addable_roles=$all_roles;
-    
-  if( !empty( $addable_roles ) ) {
-    echo "<p>Add role: <select name='add_role' onChange='submit()'>\n<option value=''>Choose a Role to add:</option>\n";
-      
-    foreach( $addable_roles as $arole ) {
-      echo "<option value=". $arole['role_id'] .">". $arole['name'] ."</option>\n";
-       
-    }
-      
-    echo "</select>\n";
-      
-  }
+
+// footers : the remove and add buttons
+$footers=array();
+if ($can_manage_roles) {
+  // remove selected roles
+  $remove_roles_area = plc_form_submit_text("remove-roles-from-person","Remove Roles");
+
+  // add a role : the button
+  $add_role_left_area=plc_form_submit_text("add-role-to-person","Add role");
+  // get list of local roles that the person has not yet
+  // xxx this does not work because GetRoles does not support filters
+  $relevant_roles = $api->GetRoles( array("~role_id"=>$role_ids));
+
+  $selector=array();
+  foreach ($relevant_roles as $role) 
+    $selector[]= array('display'=>$role['name'],"value"=>$role['role_id']);
+  $add_role_right_area=plc_form_select_text("role_id",$selector,"Choose a role to add");
+  if ($roles) 
+    $footers[]="<td colspan=3 style='text-align:right'> $remove_roles_area </td>";
+  // add a new role
+  $footers []="<td style='text-align:right'> $add_role_left_area </td>".
+    "<td colspan=2> $add_role_right_area </td>";
  }
-  
+plc_table_end("person_roles",array("footers"=>$footers));
+
+//////////////////////////////
+plc_form_end();
 plc_peer_block_end();
   
 // Print footer
index f00e360..1a2c82e 100644 (file)
@@ -20,7 +20,7 @@ $known_actions=array();
 // (*) set 'action' to one of the following
 $known_actions []= "add-person-to-site";
 //       expects:      person_id & site_id
-$known_actions []= "remove-person-from-site";
+$known_actions []= "remove-person-from-sites";
 //       expects:      person_id & site_ids
 $known_actions []= "remove-roles-from-person";
 //       expects:      person_id & role_ids
@@ -56,6 +56,7 @@ $person_id = $_POST['person_id'];     // usually needed
 
 if ( ! $action ) {
   drupal_set_message ("person_actions.php: action not set");
+  plc_debug('POST',$_POST);
   return;
  }
 
index d3fff78..31408c4 100644 (file)
@@ -53,17 +53,20 @@ function person_status ($person) {
     $messages [] = "No Key";
   if ( ! $person['enabled'] ) 
     $messages[] = "Disabled";
-  //detect tech-only people involved in slices. 
+  // for tech-only people: outline user if in a slice
   if ( ( count($person['roles'])==1 ) && 
-       ( in_array('tech',$person['roles']) )  && 
-       (! empty($person["slice_ids"])) ) 
-    $messages[]="Tech involved in a Slice";  
+       ( in_array('tech',$person['roles']) ) ) {
+    if (! empty($person["slice_ids"]) ) $messages[]="Tech in a Slice";  
+  } else {
+    // or for other kind of people, if they have no slice
+    if ( count($person['slice_ids']) == 0) $messages [] = "No Slice";
+  }
   return plc_vertical_table($messages,$class);
 }
 
 
 // fetch persons 
-$person_columns=array('person_id','first_name','last_name','email','roles','peer_id','key_ids','site_ids','enabled');
+$person_columns=array('person_id','first_name','last_name','email','roles','peer_id','key_ids','site_ids','enabled','slice_ids');
 // PIs and admins can see users not yet enabled
 $privileges=plc_is_admin() || plc_is_pi();
 if ( ! $privileges ) 
@@ -130,7 +133,7 @@ if ( ! $persons ) {
   return;
  }
   
-$columns = array ("Peer"=>"string",
+$headers = array ("Peer"=>"string",
                  "Roles"=>"string",
                  "First"=>"string",
                  "Last"=>"string",
@@ -140,9 +143,9 @@ $columns = array ("Peer"=>"string",
                  );
 
 // initial sort on email
-plc_table_start("persons",$columns,4);
+plc_table_start("persons",$headers,4);
 
-$peer_hash = plc_peer_get_hash ($api);
+$peer_hash = plc_peer_global_hash ($api);
 // write rows
 
 foreach ($persons as $person) {
index d92ce68..4b7443f 100644 (file)
@@ -27,10 +27,10 @@ $_roles= $_person['role_ids'];
 // The set of columns to fetch
 // and the filter applied for fetching sites
 if ( !in_array( '10', $_roles ) ) {
-  $columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" );
+  $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" );
   $filter = array ("enabled" => TRUE);
  } else {
-  $columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" , "enabled", "person_ids", "max_slices", "slice_ids", "node_ids");
+  $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" , "enabled", "person_ids", "max_slices", "slice_ids", "node_ids");
   $filter = array ();
  }
 
@@ -126,7 +126,7 @@ if( $_GET['sitepattern'] || $_GET['peerscope']) {
     break;
   }
 
-  $sites= $api->GetSites( $filter , $columns);
+  $sites= $api->GetSites( $filter , $site_columns);
   $sites = array_map(layout_site,$sites);
 
   $sites_count = count ($sites);
@@ -148,7 +148,7 @@ elseif( !$_GET['id'] ) {
 
   // GetSites API call
   // careful, need to pass NULL and *not* array() if no filter is given
-  $sites= $api->GetSites( empty($filter) ? NULL : $filter, $columns );
+  $sites= $api->GetSites( empty($filter) ? NULL : $filter, $site_columns );
   $sites = array_map(layout_site,$sites);
   if ( empty ($sites)) {
     echo "No site to display";