checkpoint
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 28 Jan 2009 21:59:38 +0000 (21:59 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 28 Jan 2009 21:59:38 +0000 (21:59 +0000)
13 files changed:
planetlab/events/index.php
planetlab/includes/plc_forms.php [new file with mode: 0644]
planetlab/includes/plc_functions.php
planetlab/includes/plc_tables.php
planetlab/nodes/node.php
planetlab/nodes/node_add.php [moved from planetlab/nodes/add_node.php with 100% similarity]
planetlab/nodes/nodes.php
planetlab/peers/peers.php
planetlab/persons/person.php
planetlab/persons/person_actions.php
planetlab/persons/persons.php
planetlab/sites/index.php
planetlab/sites/join_request.php

index 5c8db26..d076ca3 100644 (file)
@@ -181,14 +181,14 @@ function e_event ($event_id) {
   return href(l_event("Event","event",$event_id),$event_id);
 }
 
-function e_link ($type,$id) {
+function e_subject ($type,$id) {
   $mess=$type . " " . $id;
   switch ($type) {
   case 'Node': return l_node_t ($id,$mess);
   case 'Site': return l_site_t ($id,$mess);
   case 'Person': return l_person_t ($id,$mess);
   case 'Slice': return l_slice_t ($id,$mess);
-  case 'Role': case 'Key': case 'PCU': case 'Interface': case 'NodeGroup':
+  case 'Role': case 'Key': case 'PCU': case 'Interface': case 'NodeGroup': case "Address":
     return "$mess";
   default: return "Unknown $type" . "-" . $id;
   }
@@ -199,12 +199,12 @@ function e_subjects ($param) {
   $types=$param['object_types'];
   $ids=$param['object_ids'];
   if ( ! $types) return "";
-  return plc_vertical_table(array_map ("e_link",$types,$ids));
+  return plc_vertical_table(array_map ("e_subject",$types,$ids));
 }
 
 function e_issuer ($param) {
-  if ($param['node_id'])       return e_link('Node',$param['node_id']);
-  if ($param['person_id'])     return e_link('Person',$param['person_id']);
+  if ($param['node_id'])       return e_subject('Node',$param['node_id']);
+  if ($param['person_id'])     return e_subject('Person',$param['person_id']);
   return '???';
 }
 
@@ -358,8 +358,7 @@ if ( ! plc_is_admin()) {
     foreach ($messages as $line) 
       drupal_set_message($line);
 
-  $columns=array(
-                "Id"=>"int",
+  $columns=array("Id"=>"int",
                 "Time"=>"EnglishDateTime",
                 "Method"=>"string",
                 "Message"=>"string",
@@ -403,7 +402,7 @@ if ( ! plc_is_admin()) {
     plc_table_cell($details);
     plc_table_row_end();
   }
-  plc_table_end($table_options);
+  plc_table_end("events");
  }
 
 
diff --git a/planetlab/includes/plc_forms.php b/planetlab/includes/plc_forms.php
new file mode 100644 (file)
index 0000000..44a9fa1
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+// $Id: plc_details.php 11645 2009-01-21 23:09:49Z thierry $
+
+require_once 'plc_functions.php';
+
+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'>";
+  foreach ($values as $key=>$value) {
+    print "<input type=hidden name='$key' value='$value'>";
+  }
+}
+
+function plc_form_end($options=array()) {
+  print "</form>";
+}
+
+function plc_form_checkbox_text ($name,$value,$selected=false) {
+  return "<input type=checkbox name='$key' value='$value'>";
+}
+
+function plc_form_submit_text ($name,$display) {
+  return "<input type=submit name='$name' value='$display'>";
+}
+  
+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>";
+}
+?>
index fa28702..c93dc1c 100644 (file)
@@ -45,7 +45,7 @@ function href ($url,$text) { return "<a href='" . $url . "'>" . $text . "</a>";
 function l_nodes ()                    { return "/db/nodes/index.php"; }
 function l_node ($node_id)             { return "/db/nodes/node.php?id=" . $node_id; }
 function l_node_t ($node_id,$text)     { return href (l_node($node_id),$text); }
-function l_node_add ()                 { return "/db/nodes/add_node.php"; }
+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_interface ($interface_id)   { return "/db/nodes/interfaces.php?id=" . $interface_id; }
@@ -70,6 +70,7 @@ function l_persons ()                 { return "/db/persons/index.php"; }
 function l_person ($person_id)         { return "/db/persons/index.php?id=" . $person_id; }
 function l_person_t ($person_id,$text) { return href (l_person($person_id),$text); }
 function l_persons_site ($site_id)     { return "/db/persons/index.php?site_id=" . $site_id; }
+function l_person_actions()            { return "/db/persons/person_actions.php"; }
 
 function l_tags ()                     { return "/db/tags/index.php"; }
 function l_tags_node ()                        { return "/db/tags/index.php?type=node"; }
index d41c15e..e2c08ce 100644 (file)
@@ -9,6 +9,11 @@ drupal_set_html_head('
 ');
 
 
+//// hash to retrieve the columns 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();
+
 ////////////////////////////////////////
 function plc_table_cell($cell) {
   printf ('<td class="plc_table"> %s </td>',$cell);
@@ -25,7 +30,10 @@ 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
-function plc_table_start ($table_id, $headers, $column_sort, $options) {
+function plc_table_start ($table_id, $headers, $column_sort, $options=NULL) {
+  if ( ! $options ) $options = array();
+  global $plc_table_hash;
+  $plc_table_hash[$table_id]=array($headers,$options);
   $search_area = array_key_exists('search_area',$options) ? $options['search_area'] : true;
   $max_pages = array_key_exists('max_pages',$options) ? $options['max_pages'] : 10;
   $pagesize = array_key_exists('pagesize',$options) ? $options['pagesize'] : 25;
@@ -36,8 +44,11 @@ function plc_table_start ($table_id, $headers, $column_sort, $options) {
   plc_table_head($table_id,$headers,$column_sort,$max_pages,$pagesize);
 }
 
-function plc_table_end ($options) {
-  plc_table_foot();
+function plc_table_end ($table_id) {
+  global $plc_table_hash;
+  list($headers,$options) = $plc_table_hash[$table_id];
+
+  plc_table_foot($options);
   $notes_area = array_key_exists('notes_area',$options) ? $options['notes_area'] : true;
   if ($notes_area) 
     plc_table_notes($options);
@@ -119,13 +130,10 @@ EOF;
 }
 
 ////////////////////////////////////////
-function plc_table_foot () {
-  print <<< EOF
-</tbody>
-<tfoot>
-</tfoot>
-</table>
-EOF;
+function plc_table_foot ($options) {
+  print "</tbody><tfoot>";
+  print $options['footer'];
+  print "</tfoot></table>\n";
 }
 
 ////////////////////////////////////////
index 825dd31..d8ad55a 100644 (file)
@@ -212,7 +212,7 @@ if (empty($nodes)) {
       plc_table_cell (l_sliver_t ($node_id,$slice['slice_id'],'view'));
       plc_table_row_end();
     }
-    plc_table_end($table_options);
+    plc_table_end("slivers");
   }
 
   //////////////////////////////////////////////////////////// interfaces
@@ -272,7 +272,7 @@ if (empty($nodes)) {
        plc_table_cell($interface_bwlimit);
        plc_table_row_end();
       }
-      plc_table_end($table_options);
+      plc_table_end("interfaces");
     }
       
   }
@@ -300,7 +300,7 @@ if (empty($nodes)) {
       plc_table_cell($nodegroup['value']);
       plc_table_row_end();
     }
-    plc_table_end($table_options);
+    plc_table_end("nodegroups");
   }    
 
   ////////////////////////////////////////////////////////////
index d03c7b5..6e1f501 100644 (file)
@@ -138,8 +138,7 @@ $columns = array ("Peer"=>"string",
                  "Float"=>"float");
 
 # initial sort on hostnames
-$table_options=array();
-plc_table_start("nodes",$columns,4,$table_options);
+plc_table_start("nodes",$columns,4);
 
 $peer_hash = plc_peer_get_hash ($api);
 // write rows
@@ -174,7 +173,7 @@ foreach ($nodes as $node) {
     $fake_i += 1;
 }
 
-plc_table_end($table_options);
+plc_table_end("nodes");
 
 // Print footer
 include 'plc_footer.php';
index c547a19..a9af51a 100644 (file)
@@ -49,7 +49,7 @@ if ( empty($peers)) {
     plc_table_cell (href(l_comon("peer_id",$peer['peer_id']),'Comon'));
     plc_table_row_end();
   }
-  plc_table_end($table_options);
+  plc_table_end("peers");
  }
                    
 // Print footer
index ce87e07..0fafa41 100644 (file)
@@ -18,11 +18,15 @@ require_once 'plc_functions.php';
 require_once 'plc_minitabs.php';
 require_once 'plc_tables.php';
 require_once 'plc_details.php';
+require_once 'plc_forms.php';
 
 // -------------------- 
 // recognized URL arguments
 $person_id=intval($_GET['id']);
-if ( ! $person_id ) { plc_error('Malformed URL - id not set'); return; }
+if ( ! $person_id ) { 
+  plc_error('Malformed URL - id not set'); 
+  return;
+ }
 
 ////////////////////
 // Get all columns as we focus on only one entry
@@ -30,273 +34,294 @@ $persons= $api->GetPersons( array($person_id));
 
 if (empty($persons)) {
   drupal_set_message ("Person " . $person_id . " not found");
- } else {
-  $person=$persons[0];
-  
-  // vars from api
-  $first_name= $person['first_name'];
-  $last_name= $person['last_name'];
-  $title= $person['title'];
-  $url= $person['url'];
-  $phone= $person['phone'];
-  $email= $person['email'];
-  $enabled= $person['enabled'];
-  $peer_id=$person['peer_id'];
-  
-  // arrays from api
-  $role_ids= $person['role_ids'];
-  $roles= $person['roles'];
-  $site_ids= $person['site_ids'];
-  $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" ) );
-  $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
-  $keys= $api->GetKeys( $key_ids );
+  return;
+ }
+$person=$persons[0];
   
-  drupal_set_title("Details for account " . $first_name . " " . $last_name);
+// vars from api
+$enabled= $person['enabled'];
+$first_name= $person['first_name'];
+$last_name= $person['last_name'];
+$email= $person['email'];
+$url= $person['url'];
+$phone= $person['phone'];
+$title= $person['title'];
+$bio= $person['bio'];
+$peer_id=$person['peer_id'];
 
-  $plc_hash=plc_peer_get_hash($api);
+// arrays from api
+$role_ids= $person['role_ids'];
+$roles= $person['roles'];
+$site_ids= $person['site_ids'];
+$slice_ids= $person['slice_ids'];
+$key_ids= $person['key_ids'];
 
-  $local_peer = plc_peer_block_start ($peer_hash,$peer_id);
-  $is_my_account = plc_my_person_id() == $person_id;
-  $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
+// gets more data from API calls
+$sites= $api->GetSites( $site_ids, array( "site_id", "name", "login_base" ) );
+$slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
+$keys= $api->GetKeys( $key_ids );
 
-  $tabs=array();
+drupal_set_title("Details for account " . $first_name . " " . $last_name);
 
-  if ($local_peer && $privileges) {
-    if (plc_is_admin())
-      $tabs['Events'] = array('url'=>l_events(),
-                             'values'=>array('type'=>'Person','person'=>$person_id),
-                             'bubble'=>'Related events',
-                             'image'=>'/planetlab/icons/event.png',
-                             'height'=>18);
-    if ($enabled) 
-      $tabs['Disable'] = array ('method'=>'POST',
-                               'url'=>'/db/persons/person_actions.php',
-                               'values'=> array ('person_id'=>$person_id,
-                                                 'action'=>'disable'),
-                               'bubble'=>"Disable $first_name",
-                               'confirm'=>"Are you sure you want to disable $first_name $last_name");
-    else 
-      $tabs['Enable'] = array ('method'=>'POST',
-                               'url'=>'/db/persons/person_actions.php',
-                               'values'=> array ('person_id'=>$person_id,
-                                                 'action'=>'enable'),
-                               'bubble'=>"Enable $first_name");
-      $tabs['Delete'] = array ('method'=>'POST',
-                               'url'=>'/db/persons/person_actions.php',
-                               'values'=> array ('person_id'=>$person_id,
-                                                 'action'=>'delete'),
-                              'bubble'=>"Delete $first_name",
-                              'confirm'=>"Are you sure to delete $first_name $last_name");
-  }
+$plc_hash=plc_peer_get_hash($api);
 
-  if ($privileges || $is_my_account) 
-    $tabs['Update'] = array('url'=>'/db/persons/update.php',
-                           'values'=>array('id'=>$person_id),
-                           'bubble'=>"Update $first_name");
+$local_peer = plc_peer_block_start ($peer_hash,$peer_id);
+$is_my_account = plc_my_person_id() == $person_id;
+$privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
 
-  $tabs['All Users'] = array ('url'=>l_persons());
+$tabs=array();
 
-  plc_tabs($tabs);
-    
-  if ($privileges && ! $enabled ) 
-    drupal_set_message ("$first_name $last_name is not enabled yet, please use the 'Enable' button below");
+// update
+if ($privileges || $is_my_account) 
+  $tabs['Update'] = array('url'=>'/db/persons/update.php',
+                         'values'=>array('id'=>$person_id),
+                         'bubble'=>"Update $first_name $last_name");
+  
+// enable / disable
+if ($local_peer && $privileges) 
+  if ($enabled) 
+    $tabs['Disable'] = array ('method'=>'POST',
+                             'url'=>l_person_actions(),
+                             'values'=> array ('person_id'=>$person_id,
+                                               'action'=>'disable-person'),
+                             'bubble'=>"Disable $first_name $last_name",
+                             'confirm'=>"Are you sure you want to disable $first_name $last_name");
+  else 
+    $tabs['Enable'] = array ('method'=>'POST',
+                            'url'=>l_person_actions(),
+                            'values'=> array ('person_id'=>$person_id,
+                                              'action'=>'enable-person'),
+                            'bubble'=>"Enable $first_name $last_name",
+                            'confirm'=>"Are you sure you want to enable $first_name $last_name");
 
-  $enabled_text="Enabled";
-  if ( ! $enabled ) $enabled_text = plc_warning_div("Disabled");
+// become
+if (plc_is_admin() && ! $is_my_account) 
+  $tabs['Become'] = array('url'=>l_person_actions(),
+                         'values'=>array('action'=>'become-person',
+                                         'person_id'=>$person_id),
+                         'bubble'=>"Become $first_name $last_name",
+                         'confirm'=>"Are you sure you want to su $first_name $last_name");
+    
+// delete
+if ($local_peer && $privileges) 
+  $tabs['Delete'] = array ('method'=>'POST',
+                          'url'=>l_person_actions(),
+                          'values'=> array ('person_id'=>$person_id,
+                                            'action'=>'delete-person'),
+                          'bubble'=>"Delete $first_name $last_name",
+                          'confirm'=>"Are you sure to delete $first_name $last_name");
+// events for that person
+if ( $privileges) 
+  $tabs['Events'] = array('url'=>l_events(),
+                         'values'=>array('type'=>'Person','person'=>$person_id),
+                         'bubble'=>"Events about $first_name $last_name",
+                         'image'=>'/planetlab/icons/event.png',
+                         'height'=>18);
 
-  plc_details_start();
-  plc_details_line("Enabled",$enabled_text);
-  plc_details_line("First Name",$first_name);
-  plc_details_line("Last Name",$last_name);
-  plc_details_line("Title",$title);
-  plc_details_line("Email",href("mailto:$email",$email));
-  plc_details_line("Phone",$phone);
-  plc_details_line("URL",$url);
-  plc_details_end();
+// Back button
+$tabs['All Users'] = array ('url'=>l_persons(),
+                           'bubble'=>'Back to the Users page');
 
-         
-  echo "<hr />\n";
-               
-  // keys
-  $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
-  plc_table_title('Keys');
-  if ( empty( $key_ids ) ) {
-    echo "<span class='plc-warning'> This user has no known key</span>";
-  } else {
-    echo "<p><table border=0 width=450>\n";
-    echo "<thead><tr><th>Type</th><th>Key</th>";
-    if ( $can_manage_keys )
-      echo "<th>Remove</th>";
-    echo "</tr></thead><tbody>\n";
+plc_tabs($tabs);
     
-    foreach( $keys as $key ) {
-      $key_type= $key['key_type'];
-      $key_id= $key['key_id'];
-      $key_text= wordwrap( $key['key'], 70, "<br />\n", 1 );
-      echo "<tr><td>$key_type</td><td>$key_text";
-      
-      if ( $can_manage_keys ) 
-       echo "</td><td><input type=checkbox name='rem_key[]' value='$key_id'>";
-      
-      echo "</td></tr>\n";
-    }
-    
-    echo "</tbody></table>\n";
-    if ($can_manage_keys)
-      echo "<p><input type=submit name='Remove_keys' value='Remove keys'><br />\n";
+if ($local_peer && $privileges && ! $enabled ) 
+  drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below");
+
+$enabled_text="Enabled";
+if ( ! $enabled ) $enabled_text = plc_warning_div("Disabled");
+
+plc_details_start();
+plc_details_line("Enabled",$enabled_text);
+plc_details_line("First Name",$first_name);
+plc_details_line("Last Name",$last_name);
+plc_details_line("Email",href("mailto:$email",$email));
+plc_details_line("URL",$url);
+plc_details_line("Phone",$phone);
+plc_details_line("Title",$title);
+plc_details_line("Bio",wordwrap($bio,50,"<br/>"));
+plc_details_end();
+
+//////////////////// slices
+echo "<hr />\n";
+plc_table_title('Slices');
+
+if( empty( $slices ) ) {
+  drupal_set_message ("User has no slice");
+ } else {
+  $columns=array('Slice name'=>'string');
+  plc_table_start("person_slices",$columns,1,$table_options);
+
+  foreach( $slices as $slice ) {
+    $slice_name= $slice['name'];
+    $slice_id= $slice['slice_id'];
+    plc_table_row_start();
+    plc_table_cell(l_slice_t($slice_id,$slice_name));
+    plc_table_row_end();
   }
+  plc_table_end("person_slices");
+ }
+
+////////// keys          
+echo "<hr />\n";
+plc_table_title ("Keys");
                
-  if( $can_manage_keys ){
-    echo "<br /> Upload new key: <input type='file' name='key' size=30>\n
-        <input type='submit' name='Upload' value='Upload'>\n
-        <br /><hr />\n";
+$can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
+if ( empty( $key_ids ) ) {
+  plc_warning("This user has no known key");
+ } else {
+  // we don't set 'action', but use the submit button name instead
+  plc_form_start(l_person_actions(),
+                array("person_id"=>$person_id));
+
+  // the headers
+  $columns=array("Type"=>"string",
+                "Key"=>"string");
+  if ($can_manage_keys) $columns['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']="";
+    $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);
+    
+  foreach( $keys as $key ) {
+    $key_id=$key['key_id'];
+    plc_table_row_start($key_id);
+    plc_table_cell ($key['key_type']);
+    plc_table_cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
+    if ($can_manage_keys) 
+      plc_table_cell (plc_form_checkbox_text('key_ids[]',$key_id));
+    plc_table_row_end();
   }
+  plc_table_end("person_keys");
+  plc_form_end();
+ }
 
-  // sites
-  plc_table_title('Sites');
+// 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_slices",$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($table_options);
+// 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");
+ }
 
-  echo "<input type=submit name='Remove_Sites' value='Remove Sites'>\n";
+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" ) );
+// 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;
+  if( $sites )
+    $person_site= arr_diff( $all_sites, $sites );
+  else
+    $person_site= $all_sites;
     
-    //    sort_sites( $person_site );
+  //    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";
+  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";
+  foreach( $person_site as $site ) {
+    echo "<option value=". $site['site_id'] .">". $site['name'] ."</option>\n";
       
-    }
+  }
     
-    echo "</select>";
+  echo "</select>";
     
 }
-  echo "<hr />\n";
+ }
+echo "<hr />\n";
   
-  // 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";
+// 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 role array
+for( $n=0; $n<count($roles); $n++ ) {
+  $proles[]= 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'];
+$button_shown=0;
+if ( !empty ($roles) ) {
+  foreach( $proles as $role ) {
+    $role_name= $role['name'];
+    $role_id= $role['role_id'];
       
-      echo "<tr><td>$role_name";
+    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;
-       }
+    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>";
+      
+    echo "</td></tr>\n";
   }
-  echo "</tbody></table>\n";
+ } else {
+  echo "<span class='plc-warning'> This user has no known role !!</span>";
+ }
+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 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";
+  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";
+    foreach( $addable_roles as $arole ) {
+      echo "<option value=". $arole['role_id'] .">". $arole['name'] ."</option>\n";
        
-      }
+    }
       
-      echo "</select>\n";
+    echo "</select>\n";
       
-    }
   }
+ }
   
-  echo "<hr />\n";
+plc_peer_block_end();
   
-  // slices
-  plc_table_title('Slices');
-
-  if( empty( $slices ) ) {
-    drupal_set_message ("User has no slice");
-  } else {
-    $columns=array('Slice name'=>'string');
-    $table_options=array();
-    plc_table_start("person_slices",$columns,1,$table_options);
-
-    foreach( $slices as $slice ) {
-      $slice_name= $slice['name'];
-      $slice_id= $slice['slice_id'];
-      plc_table_row_start();
-      plc_table_cell(l_slice_t($slice_id,$slice_name));
-      plc_table_row_end();
-    }
-    plc_table_end($table_options);
-  }
-
-  plc_peer_block_end();
-  
- }
-
 // Print footer
 include 'plc_footer.php';
 
index 9dbcd34..1905af6 100644 (file)
@@ -9,225 +9,185 @@ global $plc, $api;
 
 //print header
 require_once 'plc_drupal.php';
-//set default
-drupal_set_title('Persons');
-include 'plc_header.php';
 
 // Common functions
 require_once 'plc_functions.php';
-require_once 'plc_sorts.php';
 
-// find person roles
-$_person= $plc->person;
-$_roles= $_person['role_ids'];
+$known_actions=array();
+////////////////////////////////////////////////////////////
+// interface :
+// (*) use POST 
+// (*) set 'action' to one of the following
+$known_actions []= "add-person-to-site";
+//       expects:      person_id & site_id
+$known_actions []= "remove-person-from-site";
+//       expects:      person_id & site_ids
+$known_actions []= "remove-roles-from-person";
+//       expects:      person_id & role_ids
+$known_actions []= "add-role-to-person";
+//       expects:      role_person_id & id
+$known_actions []= "enable-person";
+//       expects:      person_id
+$known_actions []= "disable-person";
+//       expects:      person_id
+$known_actions []= "become-person";
+//       expects:      person_id
+$known_actions []= "delete-person";
+//       expects:      person_id
+$known_actions []= "delete-keys";
+//       expects:      key_ids & person_id (for redirecting to the person's page)
+$known_actions []= "upload-key";
+//       expects:      person_id & $_FILES['key']
 
 //////////////////////////////
-// get person id
-if( $_POST['person_id'] )
-  $person_id= $_POST['person_id'];
-
-
-//////////////////// add in site
-if( $_POST['site_add'] ) {
-  $site_id= $_POST['site_add'];
-
-  $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
-  header( "location: index.php?id=$person_id" );
-  exit();
-
-}
-
-//////////////////// remove from sites
-if ( $_POST['Remove_Sites']){
-  if( $_POST['rem_site'] ) {
-    foreach( $_POST['rem_site'] as $site_id ) {
-      $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
-    }
-    header( "location: index.php?id=$person_id" );
-    exit();
-  }else{
-    echo "<h3><span class='plc-warning'>Please select one or more Sites to  remove.<br /></h3> </span>\n";
-    echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
-    return;
-  }
-}
-
-//////////////////// remove roles
-// remove role
-if ( $_POST['Remove_Roles']){
-  if($_POST['rem_role']) {
-    $rem_ids= $_POST['rem_role'];
-    foreach( $rem_ids as $role_id ) {
-      $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
+// sometimes we don't set 'action', but use the submit button name instead
+// so if 'action' not set, see if $_POST has one of the actions as a key
+if ($_POST['action']) 
+  $action=$_POST['action']
+else 
+  foreach ($known_actions as $known_action) 
+    if ($_POST[$known_action]) {
+      $action=$known_action;
+      break;
     }
-    header( "location: index.php?id=$person_id" );
-    exit();
-  }else{
-    echo "<h3><span class='plc-warning'>Please select one or more Roles to  remove.<br /></h3> </span>\n";
-    echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
-  }
-}
-
-//////////////////// add roles
-if( $_POST['add_role'] ) {
-  $role_id= $_POST['add_role'];
-
-  $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
-
-  header( "location: index.php?id=$person_id" );
-  exit();
-}
 
-//////////////////// enable
-// enable person
-if ( $_GET['enab_id'] ) {
-  $per_id= $_GET['enab_id'];
+//
+$person_id = $_POST['person_id'];      // usually needed
 
-  $fields= array( "enabled"=>true );
-
-  $api->UpdatePerson( intval( $per_id ), $fields );
-
-  header( "location: index.php?id=$per_id" );
-  exit();
-
-}
-
-//////////////////// disable person
-if( $_GET['dis_id'] ) {
-  $per_id= $_GET['dis_id'];
-
-  $fields= array( "enabled"=>false );
+if ( ! $action ) {
+  drupal_set_message ("person_actions.php: action not set");
+  return;
+ }
 
-  $api->UpdatePerson( intval( $per_id ), $fields );
+switch ($action) {
 
-  header( "location: index.php?id=$per_id" );
-  exit();
-  
-}
+ case 'add-person-to-site': {
+   $site_id = $_POST['site_id'];
+   $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
+   header( "location: " . l_person($person_id));
+   exit();
+ }
 
-// if action exists figure out what to do
-if( $_POST['action'] ) {
+ case 'remove-person-from-sites': {
+   $site_ids = $_POST['site_ids'];
+   if ( ! $site_ids) {
+     drupal_set_message("action=$action - No site selected");
+     return;
+   }
+   foreach ( $site_ids as $site_id ) {
+     $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
+   }
+   header( "location: " . l_person($person_id));
+   exit();
+ }
 
-  // depending on action, run function
-  switch( $_POST['action'] ) {
-    case "delete":
-      header( "location: person_actions.php?del_id=$person_id" );
-      exit();
-      break;
-    case "disable":
-      header( "location: person_actions.php?dis_id=$person_id" );
-      exit();
-      break;
-    case "enable":
-      header( "location: person_actions.php?enab_id=$person_id" );
-      exit();
-      break;
-    case "su":
-      plc_debug('plc',$plc);
-      $plc->BecomePerson (intval($person_id));
-      header ( "location: index.php" );
-      break;
-  }
+ case 'remove-roles-from-person' : {
+   $role_ids=$_POST['role_ids'];
+   if ( ! $role_ids) {
+     drupal_set_message("action=$action - No role selected");
+     return;
+   }
+   foreach( $role_ids as $role_id)  {
+     $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
+   }
+   header( "location: " . l_person($person_id));
+   exit();
+ }
+     
+ case 'add-role-to-person' : {
+   $role_id=$_POST['role_id'];
+   $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
+   header( "location: " . l_person($person_id));
+   exit();
+ }
 
-}
+ case 'enable-person' : {
+   $fields = array( "enabled"=>true );
+   $api->UpdatePerson( intval( $person_id ), $fields );
+   header( "location: " . l_person($person_id));
+   exit();
+ }
 
-//////////////////// delete person
-if( $_GET['per_id'] ) {
-  $per_id= $_GET['per_id'];
+ case 'disable-person' : {
+   $fields = array( "enabled"=>false );
+   $api->UpdatePerson( intval( $person_id ), $fields );
+   header( "location: " . l_person($person_id));
+   exit();
+ }
 
-  $api->DeletePerson( intval( $per_id ) );
+ case 'become-person' : {
+   $plc->BecomePerson (intval($person_id));
+   header ("location: " . l_persons());
+   exit();
+ }
 
-  header( "location: index.php" );
+ case 'delete-person' : {
+  $api->DeletePerson( intval( $person_id ) );
+  header( "location: " . l_persons() );
   exit();
  }
 
-//delete a key
-if ( $_POST['Remove_keys'] ){
-  if( $_POST['rem_key'] ) {
-    $key_ids= $_POST['rem_key'];
-    
-    foreach( $key_ids AS $key_id ) {
-      $api->DeleteKey( intval( $key_id ) );
-    }
-    header( "location: index.php?id=$person_id" );
-    exit();
-  }else{
-    echo "<h3><span class='plc-warning'>Please select one or more keys to remove.<br /></h3> </span>\n";
-    echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
-  }
+ case 'delete-keys' : {
+   $key_ids=$_POST['key_ids'];
+   if ( ! $key_ids) {
+     drupal_set_message("action=$action - No key selected");
+     return;
+   }
+   foreach( $key_ids as $key_id ) {
+     $api->DeleteKey( intval( $key_id ) );
+   }
+   header( "location: " . l_person($person_id));
+   exit();
  }
 
-// upload a key if the user submitted one
-if ( $_POST['Upload']){
-  if( isset( $_FILES['key'] ) ) {
-    $key_file= $_FILES['key']['tmp_name'];
-    if( $key_file ){
-      $fp = fopen( $key_file, "r" );
-      $key = "";
-      if( $fp ) {
-       // opened the key file, read the one line of contents
-       // The POST operation always creates a file even if the filename
-       // the user specified was garbage.  If there was some problem
-       // with the source file, we'll get a zero length read here.
-       $key = fread($fp, filesize($key_file));
-       fclose($fp);
-       
-       $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
-       
-       if (!$key_id){
-         $error=  $api->error();
-         echo "<h3><span class='plc-warning'> Please verify your SSH  file content.<br /></h3> </span>\n";
-         print '<br /><div class="messages error">' . $error . '</div>';
-         echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
-       }
-       else{
-         header( "location: index.php?id=$person_id" );
-         exit();
-       }
-      }else {
-       $error= "Unable to open key file.";
-       print '<div class="messages error">' . $error . '</div>';
-      }
-    }else{
-      echo "<h3><span class='plc-warning'>Please select a valid SSH key file to upload.<br /></h3> </span>\n";
-      echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
-    }
-  }
+ case 'upload-key' : {
+   if ( ! isset( $_FILES['key'] ) ) {
+     drupal_set_message ("action=$action, no key file set");
+     return;
+   }
+   
+   $key_file= $_FILES['key']['tmp_name'];
+   if ( ! $key_file ) {
+     plc_error("Please select a valid SSH key file to upload");
+     return;
+   } 
+   $fp = fopen( $key_file, "r" );
+   $key = "";
+   if( ! $fp ) {
+     plc_error("Unable to open key file $key_file");
+     return;
+   }
+   // opened the key file, read the one line of contents
+   // The POST operation always creates a file even if the filename
+   // the user specified was garbage.  If there was some problem
+   // with the source file, we'll get a zero length read here.
+   $key = fread($fp, filesize($key_file));
+   fclose($fp);
+   
+   $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
+   
+   if ( ! $key_id ) {
+     $error=  $api->error();
+     plc_error("$error");
+     plc_error("Please verify your SSH  file content");
+     return;
+   }
+   header( "location: " . l_person($person_id));
+   exit();
  }
 
-// delete person confimation
-if( $_GET['del_id'] ) {
-  $person_id= $_GET['del_id'];
-
-  // get person info from API
-  $person_info= $api->GetPersons( array( intval( $person_id ) ), array( "first_name", "last_name", "email", "roles" ) );
-
-  // start form
-  echo "<form action='person_actions.php?per_id=$person_id' method=post>\n";
-
-  // show delete confirmation
-  echo "<h2>Delete ". $person_info[0]['first_name'] ." ". $person_info[0]['last_name'] ."</h2>\n";
-  echo "<p>Are you sure you want to delete this user?\n";
-
-  echo "<table><tbody>\n";
-  echo "<tr><th>Email: </th><td> ". $person_info[0]['email'] ."</td></tr>\n";
-  echo "<tr><th>Roles: </th><td> ";
-
-  foreach( $person_info[0]['roles'] as $role ) {
-    echo "$role<br />\n";
-  }
-
-  echo "</td></tr>\n";
-
-  echo "</tbody></table>\n";
-  echo "<p><input type=submit value='Delete User' name='delete'>\n";
-  echo "</form>\n";
-
-
-}
+ case 'debug': {
+   plc_debug('GET',$_GET);
+   plc_debug('POST',$_POST);
+   plc_debug('FILES',$_FILES);
+   return;
+ }
 
-// Print footer
-include 'plc_footer.php';
+ default: {
+   plc_error ("Unknown action $action in person_actions.php");
+   return;
+ }
 
+ }
 
 ?>
index 7197e01..d3fff78 100644 (file)
@@ -31,10 +31,9 @@ $slice_id=intval($_GET['slice_id']);
 // --- decoration
 $title="Accounts";
 $tabs=array();
-$mysite_id=plc_my_site_id();
 $tabs['My accounts'] = array('url'=>l_persons(),
                             'values'=>array('site_id'=>plc_my_site_id()),
-                            'bubble'=>'Lists accounts on site ' . $mysite_id);
+                            'bubble'=>'Lists accounts on site ' . plc_my_site_id());
 // -------------------- 
 $peer_filter=array();
 $person_filter=array();
@@ -141,8 +140,7 @@ $columns = array ("Peer"=>"string",
                  );
 
 // initial sort on email
-$table_options=array();
-plc_table_start("persons",$columns,4,$table_options);
+plc_table_start("persons",$columns,4);
 
 $peer_hash = plc_peer_get_hash ($api);
 // write rows
@@ -169,7 +167,7 @@ foreach ($persons as $person) {
                                 
 }
 
-plc_table_end($table_options);
+plc_table_end("persons");
 
 // Print footer
 include 'plc_footer.php';
index a4cf270..d92ce68 100644 (file)
@@ -382,8 +382,8 @@ else {
       $right_role = in_array(30,$_roles) || in_array(40,$_roles);
       $can_add = $right_site && $right_role;
       if ($can_add) {
-       $href_add_node = "'/db/nodes/add_node.php'";
-       printf ("<td><a href=%s>0 <span class='plc-warning'>Site has no node, please add one</span></a></td>",$href_add_node); 
+       $href_node_add = "'/db/nodes/node_add.php'";
+       printf ("<td><a href=%s>0 <span class='plc-warning'>Site has no node, please add one</span></a></td>",$href_node_add); 
       } else {
        printf ("<td><a href=%s>0 <span class='plc-warning'>Site has no node</span></a></td>",$href);
       }
index cb70109..48dafd8 100644 (file)
@@ -139,7 +139,7 @@ You can directly access your site information at
 https://%s:%d/db/sites/index.php?id=%d
 
 Please start with adding nodes for this site with
-https://%s:%d/db/nodes/add_node.php
+https://%s:%d/db/nodes/node_add.php
 
 Our support team will be glad to answer any question that you might have
 They are reachable at mailto:%s