admin db search rewritten + removed some obsolete action files
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Sun, 15 Mar 2009 16:45:26 +0000 (16:45 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Sun, 15 Mar 2009 16:45:26 +0000 (16:45 +0000)
12 files changed:
planetlab/common/adminsearch.php
planetlab/css/plc_style.css
planetlab/includes/plc_session.php
planetlab/nodes/setting_action.php [deleted file]
planetlab/nodes/sliver_action.php [deleted file]
planetlab/slices/delete_slice.php [deleted file]
planetlab/slices/slice.php
planetlab/slices/slice_action.php [deleted file]
planetlab/slices/slice_nodes.php [deleted file]
planetlab/slices/slice_users.php [deleted file]
planetlab/slices/update_slice.php [deleted file]
plekit/php/toggle.php

index 45a1c61..6ac2a02 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 
-  // Require login
+  // $Id$
+
+// Require login
 require_once 'plc_login.php';
 
 // Get session and API handles
@@ -16,544 +18,289 @@ include 'plc_header.php';
 // Common functions
 require_once 'plc_functions.php';
 require_once 'plc_objects.php';
-require_once 'plc_sorts.php';
+require_once 'table.php';
+require_once 'form.php';
+require_once 'toggle.php';
+
+ini_set("memory_limit","256M");
+
+if ( ! plc_is_admin()) {
+  plc_warning ("DB Search is available to admins only");
+  return;
+ }
 
-function is_possible_domainname($token) {
-  if ( strpos ( $token, "@" ) === False && substr_count($token, ".") >= 2 ) {
-    return true;
+$pattern="";
+if (isset($_GET['pattern'])) { $pattern=$_GET['pattern']; }
+if (isset($_POST['pattern'])) { $pattern=$_POST['pattern']; }
+$tokens=split(" ",$pattern);
+
+////////////////////
+// from a single search form, extract all tokens entered 
+// and then show all entities that match one of that tokens among
+// nodes - persons - sites - slices
+////////////////////
+function display_form ($pattern) {
+  if ($pattern) {
+    $title="Searching for $pattern";
+    $visible=false;
   } else {
-    return false;
+    $title="Search for what";
+    $visible=true;
   }
+  $toggle=new PlekitToggle("admin-search",$title,array('start-visible'=>$visible));
+  $toggle->start();
+  print <<< EOF
+    <p id='admin-search-message'> This form searches for any entry in the database matching a name fragment, or token. Specifically it searches for persons, slices, nodes or slices. You can specify a space-separated list of tokens, entries matching any token would then get listed.
+</p>
+EOF;
+  print "<div id='admin-search-form'>";
+  $form=new PlekitForm ('/db/common/adminsearch.php',array());
+  $form->start();
+  print $form->label_html('pattern',"Enter space-separated tokens");
+  print $form->text_html('pattern',$pattern);
+  print $form->submit_html('submit','Submit');
+  $form->end();
+  print "</div>\n";
+  $toggle->end();
 }
 
-function get_and_print_site($site_array) {
+// just look for *token*
+function token_pattern ($token) {
+  return "*" . $token . "*";
+}
+
+// $type is e.g. 'Persons' -- $field is e.g. 'email'
+function generic_search ($type,$field,$tokens) {
   global $api;
-  $sites = $api->GetSites( $site_array, array( "name", "site_id", 
-                                              "url", "enabled", "node_ids", "person_ids", "date_created", 
-                                              "slice_ids", "max_slivers", "max_slices", "login_base" ) );
-  if ( count($sites) > 0 ) {
-    foreach( $sites as $site) {
-      $name = $site['name'];
-      $site_id = $site['site_id'];
-      $url =  $site['url'];
-      $enabled = $site['enabled'];
-      $node_ids =  $site['node_ids'];
-      $slice_ids_count =  count($site['slice_ids']);
-      $person_ids =  $site['person_ids'];
-      $date_created = date("M j G:i Y", $site['date_created']);
-      $max_slivers = $site['max_slivers'];
-      $max_slices =  $site['max_slices'];
-      $login_base =  $site['login_base'];
-
-      echo "<tr>\n";
-
-      echo "<td WIDTH='35%'><a href='/db/sites/index.php?id=$site_id'>$name</a>\n";
-      echo "(<a href='$url'>home</a>)</td>\n";
-      echo "<td NOWRAP>[ $slice_ids_count of $max_slices ]</td>\n";
-
-      echo "<td NOWRAP>";
-      if (!$enabled) echo "<font color=red>Not Enabled</font><br>\n";
-      //else echo "<td NOWRAP><i>$date_created</i></td>\n";
-      echo "<i>$date_created</i></td>\n";
-                       
-      echo "<td><strong>Nodes:</strong> ";
-      foreach ($site['node_ids'] as $node_id) 
-       { 
-         echo " <a href='/db/nodes/index.php?id=$node_id'>$node_id</a>, "; 
-       }
-
-      echo "</td></tr>\n";
-    }
+  $results=array();
+  $methodname='Get'.$type;
+  if ( ! method_exists($api,$methodname)) {
+    plc_error("generic_search failed with methodname=$methodname");
+    return $results;
   }
+  foreach ($tokens as $token) {
+    $filter=array($field=>token_pattern($token));
+    $results = 
+      array_merge ($results,$api->$methodname($filter));
+  }
+  return $results;
 }
 
-function get_and_print_hostname($host_array) {
-  global $api;
-  $nodes = $api->GetNodes( $host_array, array( "hostname", "node_id", 
-                                              "site_id", "date_created", "last_contact", "boot_state" ) );
-  if ( count ($nodes) > 0 ) {
-    foreach($nodes as $node) {
-      $hostname= $node['hostname'];
-      $node_id = $node['node_id'];
-      $boot_state= $node['boot_state'];
-      $last_contact = $node['last_contact'];
-      $date_created = date("M j G:i Y", $node['date_created']);
-      echo "<tr>";
-      echo "<td><a href='/db/nodes/index.php?id=$node_id'>$node_id</a></td> ";
-      echo "<td><a href='/db/nodes/index.php?id=$node_id'>$hostname</a></td>";
-      echo "<td>$boot_state</td>";
-      if( $last_contact != NULL ) {
-       $last_contact_str = timeDiff($last_contact);
+// $objects is e.g. a collection of persons
+// then, e.g. on slice,  $key='site_id'  & $plural=false
+// or,   e.g. on person, $key='site_ids'  & $plural=true
+function generic_gather_related ($objects, $key, $plural) {
+  if ( empty ($objects)) 
+    return array();
+  // else, look for either 'site_id' or 'site_ids' in the first object
+  $sample=$objects[0];
+  if ( array_key_exists($key,$sample)) {
+    $result=array();
+    foreach ($objects as $object) {
+      if ($plural) {
+       $result = array_merge ($result, $object[$key]);
       } else {
-       $last_contact_str = "Never";
+       $result []= $object[$key];
       }
-      echo "<td NOWRAP>$last_contact_str</td>\n";
-      echo "<td NOWRAP>$date_created</td>\n";
-      echo "</tr>\n";
     }
+    return $result;
+  } else {
+    plc_debug("gather_related failed with $key",$sample);
+    return array();
   }
-
-  return $nodes;
 }
 
-function get_and_print_user ($user_array) {
-  global $api;
-  $persons= $api->GetPersons( $user_array, array( "person_id", "first_name", 
-                                                 "last_name", "email", "roles", "enabled", "date_created", 
-                                                 "site_ids" ) );
-
-  if ( count($persons) > 0 ) {
-    foreach($persons as $person) {
-      $first= $person['first_name'];
-      $last = $person['last_name'];
-      $person_id= $person['person_id'];
-      $email= $person['email'];
-      $enabled= $person['enabled'];
-      $roles = $person['roles'];
-      $role = $person['roles'][0];
-      $date_created = date("M j G:i Y", $person['date_created']);
-      $site_ids= $person['site_ids'];
-
-      echo "<tr><td>\n";
-
-      echo "<a href='/db/persons/index.php?id=$person_id'>";
-      echo "$first $last</a></td>";
-      echo "<td>($person_id)</td> ";
-      echo "<td><a href='mailto:$email'>$email</a> </td>";
-
-      echo "<td NOWRAP>";
-      if (!$enabled) echo "<font color=red>Not Enabled</font><br>\n";
-      //else echo "<td NOWRAP><i>$date_created</i></td>\n";
-      echo "<i>$date_created</i></td>\n";
-      //if (!$enabled) echo "<td><font color=red> Not Enabled </font></td>";
-      //else echo "<td><i>$date</i></td>";
-                       
-      echo "<td> <strong>roles:</strong> ";
-      foreach ($person['roles'] as $role) { echo " $role, "; }
-
-      echo "</td></tr>\n";
+////////// 
+// create link from an id, using the various global hashes
+function plc_person_link ($person_id) {global $persons_hash; return l_person_obj($persons_hash[$person_id]);}
+function plc_slice_link ($slice_id) {global $slices_hash; return l_slice_obj($slices_hash[$slice_id]);}
+function plc_site_link ($site_id) {global $sites_hash; return l_site_obj($sites_hash[$site_id]);}
+function plc_node_link ($node_id) {global $nodes_hash; return l_node_obj($nodes_hash[$node_id]);}
+
+function display_persons ($persons) {
+  if ( ! $persons) return;
+  
+  $toggle=new PlekitToggle('persons-area',"Persons");
+  $toggle->start();
+
+  $headers=array('id'=>'int',
+                'email'=>'string',
+                'sites'=>'string',
+                'slices'=>'string',
+                'roles'=>'string');
+  $table=new PlekitTable('persons',$headers,1);
+  $table->start();
+  foreach ($persons as $person) {
+    $table->row_start();       
+    $table->cell($person['person_id']);
+    $table->cell(l_person_obj($person));
+    $table->cell(plc_vertical_table(array_map("plc_site_link",$person['site_ids'])));
+    $table->cell(plc_vertical_table(array_map("plc_slice_link",$person['slice_ids'])));
+    $table->cell(plc_vertical_table($person['roles']));
+    $table->row_end();
+  }
+  $table->end();
+  $toggle->end();
+}
 
-    }
-               
+function display_slices ($slices) {
+  if ( ! $slices) return;
+  
+  $toggle=new PlekitToggle('slices-area',"Slices");
+  $toggle->start();
+
+  $headers=array('id'=>'int',
+                'name'=>'string',
+                'site'=>'string',
+                'persons'=>'string',
+                'N'=>'string');
+  $table=new PlekitTable('slices',$headers,1);
+  $table->start();
+  foreach ($slices as $slice) {
+    $table->row_start();       
+    $table->cell($slice['slice_id']);
+    $table->cell(l_slice_obj($slice));
+    global $sites_hash;
+    $site=$sites_hash[$slice['site_id']];
+    $table->cell(l_site_obj($site));
+    $table->cell(plc_vertical_table(array_map("plc_person_link",$slice['person_ids'])));
+    // this makes really long tables, use the slice link to see details
+    //$table->cell(plc_vertical_table(array_map("plc_node_link",$slice['node_ids'])));
+    $table->cell(count($slice['node_ids']));
+    $table->row_end();
   }
-  return $persons;
+  $table->end();
+  $toggle->end();
 }
 
-// find person roles
-$_person= $plc->person;
-$_roles= $_person['role_ids'];
-
-
-///////////////////////////////////////////////////////////////////////
-// Initially, we need a search form, and blank information after that.  
-// Based on the fields of the search form, we should be able to populate a lot
-// of information, related to user, site, keys, 
-// 
-//     from a simple domain name search, it would display the site, 
-//             nodes -> pcu
-//             users grouped by role, 
-//  from a user search, it would find,
-//             user info link, site, roles, etc.
-//
-//  userquery will be one of these types:
-//             part of a user name, email, user_id
-//             part of a site name, site alias, site_id
-//             part of a node name, domain, node_id
-//
-//  we should be able to return results based on these guesses.  If they're
-//  good, we'll get hits, if nothing comes back, we won't display anything.
-
-
-echo "<div>\n
-        <form method=post action='/db/common/adminsearch.php'>\n";
-
-if( $_POST['userquery'] or $_GET['userquery']) {
-  if ( $_POST['userquery'] ) {
-    $query = $_POST['userquery'];
-  } else {
-    $query = $_GET['userquery'];
+function display_sites ($sites) {
+  if ( ! $sites) return;
+  
+  $toggle=new PlekitToggle('sites-area',"Sites");
+  $toggle->start();
+
+  $headers=array('id'=>'int',
+                'name'=>'string',
+                'url'=>'string',
+                'persons'=>'string',
+                'slices'=>'string',
+                'nodes'=>'string');
+  $table=new PlekitTable('sites',$headers,1);
+  $table->start();
+  foreach ($sites as $site) {
+    $table->row_start();       
+    $table->cell($site['site_id']);
+    $table->cell(l_site_obj($site));
+    $table->cell(href($site['url'],$site['url']));
+    $table->cell(plc_vertical_table(array_map("plc_person_link",$site['person_ids'])));
+    $table->cell(plc_vertical_table(array_map("plc_slice_link",$site['slice_ids'])));
+    $table->cell(plc_vertical_table(array_map("plc_node_link",$site['node_ids'])));
+    $table->row_end();
   }
- }
+  $table->end();
+  $toggle->end();
+}
 
-echo "<p><label for='testinput'>User or Site Name/loginbase/Email/User or Site ID:</label> (Separate with commas for multiple queries.)\n
-        <input type='text' id='testinput' name='userquery' size=50 value='$query' />\n
-        <input type=submit value='Search' />\n
-               </form>\n
-        </div>\n
-        <br />\n";
-
-// if userquery then search based on string
-if( $_POST['userquery'] or $_GET['userquery']) {
-  if ( $_POST['userquery'] ) {
-    $query = $_POST['userquery'];
-  } else {
-    $query = $_GET['userquery'];
+function display_nodes ($nodes) {
+  if ( ! $nodes) return;
+  
+  $toggle=new PlekitToggle('nodes-area',"Nodes");
+  $toggle->start();
+
+  $headers=array('id'=>'int',
+                'hostname'=>'string',
+                'site'=>'string',
+                'slices'=>'string');
+  $table=new PlekitTable('nodes',$headers,1);
+  $table->start();
+  foreach ($nodes as $node) {
+    $table->row_start();       
+    $table->cell($node['node_id']);
+    $table->cell(l_node_obj($node));
+    global $sites_hash;
+    $site=$sites_hash[$node['site_id']];
+    $table->cell(l_site_obj($site));
+    $table->cell(plc_vertical_table(array_map("plc_slice_link",$node['slice_ids'])));
+    $table->row_end();
   }
-  echo "<table cellspacing=2 cellpadding=1 width=100%><thead><caption><b>Search Results:</b><caption></thead><tbody>\n";
-
-  $f_commas = explode(",", $query);
-  // PHASE 1: query contains email, user_id, or part of a user name
-  foreach($f_commas as $tok) {
-    $tok = trim($tok); // strip white space.
-
-    $e = false;
-    //find user by email
-    if ( is_valid_email_addr($tok) ){
-      $u = get_and_print_user(array("email"=>$tok));
-      $e = true;
-      if( count( $u ) == 0 ) $none = 1;
-    }
-    $n = false;
-    // find user by user_id
-    if ( is_numeric($tok) ){
-      $u = get_and_print_user(array("person_id"=>intval($tok)));
-      $n = true;
-      if( count( $u ) == 0 ) $none = 1;
-    }
-    // neither of the above, 
-    if (!$n && !$e) {
-      // split on spaces, and search each part.
-      // TODO: search upper and lower-case
-      $f_spaces = explode(" ", $tok);
-      foreach($f_spaces as $stok) {
-       // assume $tok is part of a name
-       // get_user
-       $a = get_and_print_user(array("first_name"=>$stok));
-       $b = get_and_print_user(array("last_name"=>$stok));
-       // c = intersect_users(a, b)
-       // if c 
-       //     print_user(c), 
-       // else 
-       //     print_user(a,b)
-      }
-      if( count( $a ) == 0 && count( $b ) == 0 ) $none = 1;
-    }
+  $table->end();
+  $toggle->end();
+}
 
-    // PHASE 2: query contains login_base, site_id, or part of a site name
 
-    // find site by login_base
-    $lb = false;
-    $s = get_and_print_site(array("login_base"=>strtolower($tok)));
-    if( count( $s ) == 0 ) $none = 1;
-    else $lb = true;
+////////////////////////////////////////////////////////////
+display_form($pattern);
 
-    $n = false;
-    // find site by site_id
-    if ( is_numeric($tok) ){
-      $s = get_and_print_site(array("site_id"=>intval($tok)));
-      $n = true;
-      if( count( $s ) == 0 ) $none = 1;
-    }
+if ($pattern) {
 
-    if( !$lb && !$n ) {
-      $f_spaces = explode(" ", $tok);
-      foreach($f_spaces as $stok) {
-       $a = get_and_print_site(array("name"=>$stok));
-      }
-      if( count($a) == 0 ) $none = 1;
-    }
+  ////////// search database
+  // search persons on email
+  $persons = array();
+  $persons = array_merge ($persons, generic_search ('Persons','email',$tokens));
 
-    // PHASE 3:        query contains part of a node name, domain, node_id
+  // search slices on name
+  $slices=array();
+  $slices = array_merge ($slices, generic_search ('Slices','name',$tokens));
 
-    //if( $none == 1 ) echo "<tr><td>No Results. </td></tr>\n";
-    if ( is_possible_domainname($tok) ) {
-      $n = get_and_print_hostname(array("hostname"=>$tok));
-    }
+  // search sites on name and login_base
+  $sites=array();
+  $sites = array_merge ($sites, generic_search('Sites','name',$tokens));
+  $sites = array_merge ($sites, generic_search('Sites','login_base',$tokens));
+
+  // nodes on hostname
+  $nodes=array();
+  $nodes = array_merge ($nodes, generic_search('Nodes','hostname',$tokens));
+
+  print "Search results for <span class='tokens'> $pattern </span>\n";
+  if ( !$nodes && !$persons && !$slices && !$sites) {
+    plc_warning ("No result found");
+    return;
   }
-  echo "</tbody></table>\n";
- }
 
-if (false) {
-  // if a site_id is given, display the site nodes only
-  if( $_GET['site_id'] ) {
-    $site_id= $_GET['site_id'];
+  ////////// collect all related objects 
+  $rel_person_ids = array();
+  $rel_person_ids = array_merge($rel_person_ids, generic_gather_related ($sites,'person_ids',true));
+  $rel_person_ids = array_merge($rel_person_ids, generic_gather_related ($slices,'person_ids',true));
 
-    // Get site info
-    $site_info= $api->GetSites( array( intval( $site_id ) ), array( "name", "person_ids" ) );
+  $rel_slice_ids = array();
+  $rel_slice_ids = array_merge($rel_slice_ids, generic_gather_related ($persons,'slice_ids',true));
+  $rel_slice_ids = array_merge($rel_slice_ids, generic_gather_related ($sites,'slice_ids',true));
+  $rel_slice_ids = array_merge($rel_slice_ids, generic_gather_related ($nodes,'slice_ids',true));
 
-    // Get site nodes
-    $persons= $api->GetPersons( $site_info[0]['person_ids'], array( "person_id", "first_name", "last_name", "email", "roles", "peer_id", "enabled" ) );
-         
-    drupal_set_title("People with " . $site_info[0]['name']);
+  $rel_site_ids = array();
+  $rel_site_ids = array_merge ( $rel_site_ids, generic_gather_related ($persons,'site_ids',true));
+  $rel_site_ids = array_merge ( $rel_site_ids, generic_gather_related ($slices,'site_id',false));
+  $rel_site_ids = array_merge ( $rel_site_ids, generic_gather_related ($nodes,'site_id',false));
 
-    sort_persons( $persons );
+  $rel_node_ids = array();
+  $rel_node_ids = array_merge($rel_node_ids, generic_gather_related ($sites,'node_ids',true));
+  $rel_node_ids = array_merge($rel_node_ids, generic_gather_related ($slices,'node_ids',true));
 
-    echo paginate_trash ( $persons, "person_id", "Persons", 25, "email" );
 
-  }
-  // if no person id, display list of persons to choose
-  elseif( !$_GET['id'] ) {
-
-    // GetPersons API call
-    $persons= $api->GetPersons( NULL, array( "person_id", "first_name", "last_name", "email", "roles" , "peer_id", "enabled" ) );
-
-    sort_persons( $persons );
-
-    echo "<div>\n
-                       <form method=post action='/db/persons/allinfo.php'>\n";
-    if( $pers_email ) echo "<font color=red>'$pers_email' is not a valid person email.</font>\n";
-    echo "<p><label for='testinput'>Query: </label>\n
-                       <input type='text' id='testinput' name='userquery' size=50 value='' />\n
-                       <input type=submit value='Search' />\n
-                       </div>\n
-                       <br />\n";
-  } else {
-    // get the person_id from the URL
-    $person_id= intval( $_GET['id'] );
-
-    // GetPersons API call for this person
-    $person_info= $api->GetPersons( array( $person_id ) );
-         
-    if( empty( $person_info ) ) {
-      echo "No such person.";
-                       
-    } else {
-      // vars from api
-      $first_name= $person_info[0]['first_name'];
-      $last_name= $person_info[0]['last_name'];
-      $title= $person_info[0]['title'];
-      $url= $person_info[0]['url'];
-      $phone= $person_info[0]['phone'];
-      $email= $person_info[0]['email'];
-      $enabled= $person_info[0]['enabled'];
-      $peer_id=$person_info[0]['peer_id'];
-                       
-      // arrays from api
-      $role_ids= $person_info[0]['role_ids'];
-      $roles= $person_info[0]['roles'];
-      $site_ids= $person_info[0]['site_ids'];
-      $slice_ids= $person_info[0]['slice_ids'];
-      $key_ids= $person_info[0]['key_ids'];
-                       
-      // gets more data from API calls
-      $site_info= $api->GetSites( $site_ids, array( "site_id", "name" ) );
-      $slice_info= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
-      $key_info= $api->GetKeys( $key_ids );
-                       
-      drupal_set_title("$first_name $last_name Account Information");
-
-      // start form
-      if ( ! $peer_id ) {
-       echo "<form action='/db/persons/person_action.php' method='post'>\n";
-      } else {
-       echo "<div class='plc-foreign'>";
-      }
-      echo "<input type=hidden name='person_id' value='$person_id'>\n";
-               
-      if ( ! $peer_id ) {
-# if ( Admin, PI, or user ) allow deletion
-       if( in_array( 10, $_roles ) || 
-           ( in_array( 20, $_roles ) && in_array( $site_ids[0], $_person['site_ids'] ) )  ||
-           $_person['person_id'] == $person_id) {
-
-         // list to take person action
-         echo "<p><select name='actions' onChange=\"submit();\">\n";
-                               
-         $actions= array( ''=>'Choose Action', 'delete'=>"Delete $first_name" );
-         $select_end = "</select>\n";
-
-# if ( Admin or PI ) check whether to allow # 'enabling/disabling'.
-         if( in_array( 10, $_roles ) || 
-             ( in_array( 20, $_roles ) && in_array( $site_ids[0], $_person['site_ids'] ) ) ) { 
-
-           if( $enabled == true ) {
-             $actions['disable']= "Disable $first_name";
-           } else {
-             $actions['enable']= "Enable $first_name";
-             $select_end = $select_end . " &nbsp; <font color=red size=-1>".
-               "<- This user is not enabled. Choose here to enable or delete.</font>";
-           }
-           if ( in_array( 10, $_roles )) {
-             $actions['su'] = "Become $first_name";
-           }
-         } 
-                               
-# for all cases, list each 'select' key
-         foreach( $actions as $key => $val ) {
-           echo "<option value='$key'";
-               
-           if( $key == $_POST['actions'] )
-             echo " selected";
-               
-           echo ">$val\n";
-         }
-               
-         echo $select_end;
-       }
-      } 
-               
-      // basic person info
-      echo "<p><table border=0>\n";
-      echo "<tr><td>First Name: </td><td> $first_name</td></tr>\n";
-      echo "<tr><td>Last Name: </td><td> $last_name</td></tr>\n";
-      echo "<tr><td>Title: </td><td> $title</td></tr>\n";
-      echo "<tr><td>Email: </td><td><a href='mailto:$email'>$email</a></td></tr>\n";
-      echo "<tr><td>Password: </td><td>***********</td></tr>\n";
-      echo "<tr><td>Phone: </td><td>$phone</td></tr>\n";
-      echo "<tr><td>URL: </td><td>$url</td></tr>\n";
-      echo "</table>\n";
-               
-      if( in_array( 10, $_roles ) || $_person['person_id'] == $person_id )
-       echo "<br /><a href='/db/persons/update.php?id=$person_id'>Update account information</a>\n";
-
-      echo "<hr />\n";
-                       
-      // keys
-      $can_manage_keys = ( ( ! $peer_id ) && (in_array( "10", $_roles ) || $person_id == $_person['person_id']));
-      echo "<h3>Keys</h3>\n";
-      if( !empty( $key_ids ) ) {
-       echo "<p><table border=0 width=450>\n";
-       echo "<thead><tr><th>Type</th><th>Key</th></tr></thead><tbody>\n";
-                               
-       foreach( $key_info as $key ) {
-         $key_type= $key['key_type'];
-         $key_id= $key['key_id'];
-         $key_html= wordwrap( $key['key'], 70, "<br />\n", 1 );
-         echo "<tr><td>$key_type</td><td>$key_html</td></tr>\n";
-       }
-               
-       echo "</tbody></table>\n";
-
-               
-      } else {
-       echo "<span class='plc-warning'> This user has no known key</span>";
-      }
-                       
-      if( $can_manage_keys )
-       echo "<p><a href='/db/persons/keys.php?id=$person_id'>Manage Keys</a>\n";
-      echo "<hr />";
-               
-               
-      // sites
-      echo "<h3>Sites</h3>\n";
-      if( !empty( $site_info ) ) {
-       echo "<table cellpadding=3><tbody>\n";
-               
-       foreach( $site_info as $site ) {
-         $site_name= $site['name'];
-         $site_id= $site['site_id'];
-               
-         echo "<tr><td><a href='/db/sites/index.php?id=$site_id'>$site_name</a> </td><td> (<input type=checkbox name='rem_site[]' value='$site_id'> remove)</td></tr>\n";
-       }
-       echo "</tbody></table>\n";
-       echo "<input type=submit value='Remove Sites'>\n";
-               
-      } else {
-       echo "<span class='plc-warning'> This user is not affiliated with a site !!</span>";
-      }
-               
-      // diplay site select list to add another site for user
-      if( ! $peer_id && in_array( 10, $_roles ) ) {
-       // get site info
-       $full_site_info= $api->GetSites( NULL, array( "site_id", "name" ) );
-                               
-       if( $site_info )
-         $person_site= arr_diff( $full_site_info, $site_info );
-       else
-         $person_site= $full_site_info;
-                               
-       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>";
-               
-      }
-      echo "<hr />\n";
-               
-      // roles
-      echo "<h3>Roles</h3>\n";
-      echo "<p><table>\n";
-      echo "<thead><tr><th>Role</th>";
-      if( in_array( "10", $_roles ) )
-       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] );
-      }
-                       
-
-      if ( !empty ($roles) ) {
-       foreach( $proles as $role ) {
-         $role_name= $role['name'];
-         $role_id= $role['role_id'];
-                               
-         echo "<tr><td>$role_name";
-                               
-
-         if( in_array( 10, $_roles ) ) {
-           echo "</td><td><input type=checkbox name='rem_role[]' value='$role_id'>";
-
-         }
-                                       
-         echo "</td></tr>\n";
-       }
-      } else {
-       echo "<span class='plc-warning'> This user has no known role !!</span>";
-      }
-                       
-      echo "</tbody></table>\n";
-
-      if ( in_array( 10, $_roles ) )
-       echo "<input type=submit value='Update Roles'><br />\n";
-
-
-               
-      // if admin show roles to add
-      if( in_array( 10, $_roles ) ) {
-       $all_roles= $api->GetRoles();
-       $addable_roles= arr_diff( $all_roles, $proles );
-               
-       if( !empty( $addable_roles ) ) {
-         echo "<p><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";
-               
-       }
-      }
-               
-      echo "<hr />\n";
-                       
-      // slices
-      echo "<h3>Slices</h3>\n";
-      if( !empty( $slice_info ) ) {
-                         
-       foreach( $slice_info as $slice ) {
-         $slice_name= $slice['name'];
-         $slice_id= $slice['slice_id'];
-               
-         echo "<a href='/db/slices/index.php?id=$slice_id'>$slice_name</a><br />\n";
-       }
-               
-      } else {
-       echo "No slices found for that user";
-      }
+  ////////// fetch related and store in a global hash
+  $rel_persons = $api->GetPersons ($rel_person_ids);
+  global $persons_hash; $persons_hash=array();
+  foreach ($rel_persons as $person) $persons_hash[$person['person_id']]=$person;
 
-      if ( ! $peer_id ) {
-       echo "</form>\n";
-      } else {
-       echo "</div>\n";
-      }
+  $rel_slices = $api->GetSlices ($rel_slice_ids);
+  global $slices_hash; $slices_hash=array();
+  foreach ($rel_slices as $slice) $slices_hash[$slice['slice_id']]=$slice;
 
-    }
-    echo "<br /><hr /><p><a href='/db/persons/index.php'>Back to person list</a></div>";
+  $rel_sites = $api->GetSites ($rel_site_ids);
+  global $sites_hash; $sites_hash=array();
+  foreach ($rel_sites as $site) $sites_hash[$site['site_id']]=$site;
 
-  }
- }
+  $rel_nodes = $api->GetNodes ($rel_node_ids);
+  global $nodes_hash; $nodes_hash=array();
+  foreach ($rel_nodes as $node) $nodes_hash[$node['node_id']]=$node;
+
+  ////////// show results
+  display_persons ($persons);
+  display_slices ($slices);
+  display_sites($sites);
+  display_nodes($nodes);
 
+ }
 
 // Print footer
 include 'plc_footer.php';
index f0238fc..40ccf29 100644 (file)
@@ -20,6 +20,7 @@ a:hover.expandlink {
     color:#fff
 }
 
+/* -------------------- general */
 body {
     position: relative;
 }
@@ -39,7 +40,7 @@ body {
 .plc-warning a:visited { text-decoration: none; color:white }
 .plc-warning a:hover { text-decoration: none; color:black }
 
-/* styling the planetlab module area */
+/* -------------------- the planetlab module area */
 div.block-planetlab a {
     font-weight:normal;
     font-style:italic;
@@ -47,3 +48,21 @@ div.block-planetlab a {
 /* -------------------- sites */
 .addresses { text-align: center; font-weight: bold; }
 
+/* -------------------- admin search */
+#admin-search-form {
+    text-align: center;
+    padding: 10px;
+}
+
+#admin-search-form input {
+    padding-left : 20 px;
+}
+
+span.tokens {
+    font-weight: bold;
+    font-style: italic;
+}
+
+#admin-search-message {
+    padding: 30px;
+}
index c0f9656..91fb247 100644 (file)
@@ -142,8 +142,10 @@ if (!empty($_SESSION['plc'])) {
   if ($_SESSION['plc']['expires'] > time()) {
     $plc->person = $_SESSION['plc']['person'];
     $plc->api = new PLCAPI($_SESSION['plc']['auth']);
-    $plc->alt_person = $_SESSION['plc']['alt_person'];
-    $plc->alt_auth = $_SESSION['plc']['alt_auth'];
+    if (array_key_exists('alt_person',$_SESSION['plc']))
+      $plc->alt_person = $_SESSION['plc']['alt_person'];
+    if (array_key_exists('alt_auth',$_SESSION['plc']))
+      $plc->alt_auth = $_SESSION['plc']['alt_auth'];
   } else {
     // Destroy PHP session
     session_destroy();
diff --git a/planetlab/nodes/setting_action.php b/planetlab/nodes/setting_action.php
deleted file mode 100644 (file)
index 1d04d10..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-<?php
-
-// $Id$
-
-// Require login
-require_once 'plc_login.php';
-
-// Get session and API handles
-require_once 'plc_session.php';
-global $plc, $api;
-
-// Common functions
-require_once 'plc_functions.php';
-require_once 'plc_sorts.php';
-
-// find person roles
-$_person= $plc->person;
-$_roles= $_person['role_ids'];
-
-//plc_debug('GET',$_GET);
-//plc_debug('POST',$_POST);
-
-// tag type updates
-if( $_POST['edit_type'] ) {
-  $setting_type_id= intval( $_POST['interface_tag_type_id'] );
-  $setting_type = array ('category' => $_POST['category'],
-                        'name' => $_POST['name'],
-                        'min_role_id' => intval( $_POST['min_role_id'] ),
-                        'description' => $_POST['description']);
-  
-  // Update it!
-  $api->UpdateTagType( $setting_type_id, $setting_type );
-  $api_error=$api->error();
-  if (!empty($api_error)) {
-    print "<div class='plc-error'>" . $api_error . "</div>";
-  }
-  
-  // xxx check the destination page
-  plc_redirect ("settings.php");
-}
-
-// tag type adds
-if( $_POST['add_type'] ) {
-  $setting_type = array ('category' => $_POST['category'],
-                        'name' => $_POST['name'],
-                        'min_role_id' => intval( $_POST['min_role_id'] ),
-                        'description' => $_POST['description']);
-  // add it!!
-  $api->AddTagType( $setting_type );
-
-  // xxx check the destination page
-  plc_redirect ("settings.php");
-}
-  
-
-// tag deletion
-if( $_GET['rem_id'] ) {
-  // get the id of the tag to remove from GET
-  $setting_id= intval( $_GET['rem_id'] );
-
-  // get interface_id 
-  $setting= $api->GetInterfaceTags( array( $setting_id ), array( "interface_id" ) );
-  $interface_id= $setting[0]['interface_id'];
-  
-  // delete the tag
-  $api->DeleteInterfaceTag( $setting_id );
-
-  plc_redirect (l_interface($interface_id));
-}
-
-// tag adds
-if( $_POST['add_setting'] ) {
-  // get the interface_id, tag_type_id, and value from POST
-  $interface_id= intval( $_POST['interface_id'] );
-  $interface_tag_type_id= intval( $_POST['interface_tag_type_id'] );
-  $value= $_POST['value'];
-
-  // add it!
-  $api->AddInterfaceTag( $interface_id, $interface_tag_type_id, $value );
-
-  plc_redirect (l_interface($interface_id));
-}
-
-// tag updates
-if( $_POST['edit_setting'] ) {
-  // get the id of the setting to update and the value from POST
-  $setting_id= intval( $_POST['setting_id'] );
-  $value= $_POST['value'];
-  $interface_id= $_POST['interface_id'];
-
-  // update it!
-  $api->UpdateInterfaceTag($setting_id, $value );
-
-  plc_redirect (l_interface($interface_id));
-}
-
-// Settings -------------------------------------------------
-
-// TAG TYPES ---------------------------------------------------
-  
-// delete tag types
-if( $_GET['del_type'] ) {
-  // get vars
-  $type_id= intval( $_GET['del_type'] );
-
-  // delete it!
-  $api->DeleteTagType( $type_id );
-  
-  // xxx check the destination page
-  plc_redirect ("settings.php" );
-}
-  
-/*
-// Print footer
-include 'plc_footer.php';
-*/
-
-?>
diff --git a/planetlab/nodes/sliver_action.php b/planetlab/nodes/sliver_action.php
deleted file mode 100644 (file)
index 77abdad..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-
-// Require login
-require_once 'plc_login.php';
-
-// Get session and API handles
-require_once 'plc_session.php';
-global $plc, $api;
-
-/*
-// Print header
-require_once 'plc_drupal.php';
-drupal_set_title('Slices');
-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'];
-
-
-if( !empty( $_POST['add_sub'] ) ) {
-  $tag_type= $_POST['sliver'];
-  $value= $_POST['value'];
-  $node_id= $_POST['node_id'];
-  $slice_id= $_POST['slice_id'];
-
-  $api->AddSliceTag( intval( $slice_id ), intval( $tag_type ), $value, intval( $node_id ) );
-
-  // xxx l_sliver ?
-  plc_redirect (l_sliver ($node_id,$slice_id));
-  //header( "location: slivers.php?slice=$slice_id&node=$node_id" );
-}
-
-
-// 
-if( $_GET['rem_id'] ) {
-  $tag_id= $_GET['rem_id'];
-  
-  // get the slivers for this node
-  $slivers= $api->GetSliceTags( array( "slice_tag_id"=>intval( $tag_id ) ), array( "slice_id", "node_id" ) );
-  $sliver=$slivers[0];
-  
-  $api->DeleteSliceTag( intval( $tag_id ) );
-
-  $node_id=$sliver['node_id'];
-  $slice_id=$sliver['slice_id'];
-  plc_redirect (l_sliver ($node_id,$slice_id));
-}
-
-  
-/*
-// Print footer
-include 'plc_footer.php';
-*/
-
-?>
diff --git a/planetlab/slices/delete_slice.php b/planetlab/slices/delete_slice.php
deleted file mode 100644 (file)
index 75ff980..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-
-// Require login
-require_once 'plc_login.php';
-
-// Get session and API handles
-require_once 'plc_session.php';
-global $plc, $api;
-
-// Common functions
-require_once 'plc_functions.php';
-require_once 'plc_sorts.php';
-  
-// find person roles
-$_person= $plc->person;
-$_roles= $_person['role_ids'];
-
-//print_r( $_person );
-
-// if no id then go back to slice index
-if( !$_GET['id'] )
-  header( "index.php" );
-
-// get slice id from get
-$slice_id= $_GET['id'];
-
-// delete it!
-if( $_POST['delete'] ) {
-  $api->DeleteSlice( intval( $slice_id ) );
-  plc_redirect(l_slices());
-}
-
-// Print header
-require_once 'plc_drupal.php';
-drupal_set_title('Slices');
-include 'plc_header.php';
-
-
-// get slice info from API call
-$slice_info= $api->GetSlices( array( intval( $slice_id ) ), array( "name", "expires", "description" ) );
-
-// start form
-echo "<form action='delete_slice.php?id=$slice_id' method=post>\n";
-
-// show delete confirmation
-echo "<h2>Delete slice ". $slice_info[0]['name'] ."</h2>\n";
-echo "<p>Are you sure you want to delete this slice?\n";
-
-echo "<table><tbody>\n";
-echo "<tr><th>Name: </th><td> ". $slice_info[0]['name'] ."</td></tr>\n";
-echo "<tr><th>Description: </th><td> ". $slice_info[0]['description'] ."</td></tr>\n";
-echo "<tr><th>Expiration: </th><td> ". gmstrftime( "%A %b-%d-%y %T %Z", $slice_info[0]['expires'] ) ."</td></tr>\n";
-echo "</tbody></table>\n";
-echo "<input type=submit value='Delete Slice' name='delete'>\n";
-echo "</form\n";
-
-// Print footer
-include 'plc_footer.php';
-
-?>
index 24b12da..5797f04 100644 (file)
@@ -273,8 +273,9 @@ $toggle->start();
 // hide if both current+add are included
 // so user can chose which section is of interest
 // show otherwise
+$count=count($persons);
 $toggle_persons = new PlekitToggle ('my-slice-persons-current',
-                                   "People currently in $name",
+                                   "$count people currently in $name",
                                    array('start-visible'=>!$privileges));
 $toggle_persons->start();
 
@@ -314,8 +315,9 @@ $toggle_persons->end();
 
 ////////// people to add
 if ($privileges) {
+  $count=count($potential_persons);
   $toggle_persons = new PlekitToggle ('my-slice-persons-add',
-                                     "People to add to $name",
+                                     "$count people may be added to $name",
                                      array('start-visible'=>false));
   $toggle_persons->start();
   if ( ! $potential_persons ) {
@@ -375,8 +377,9 @@ $toggle=new PlekitToggle ('my-slice-nodes',"Nodes",
 $toggle->start();
 
 ////////// nodes currently in
+$count=count($nodes);
 $toggle_nodes=new PlekitToggle('my-slice-nodes-current',
-                              "Nodes currently in $name",
+                              "$count nodes currently in $name",
                               array('start-visible'=>!$privileges));
 $toggle_nodes->start();
 
@@ -412,8 +415,9 @@ $toggle_nodes->end();
 
 ////////// nodes to add
 if ($privileges) {
+  $count=count($potential_nodes);
   $toggle_nodes=new PlekitToggle('my-slice-nodes-add',
-                                "Nodes to add to $name",
+                                "$count more nodes available",
                                 array('start-visible'=>false));
   $toggle_nodes->start();
 
diff --git a/planetlab/slices/slice_action.php b/planetlab/slices/slice_action.php
deleted file mode 100644 (file)
index 007c7f9..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-
-// Require login
-require_once 'plc_login.php';
-
-// Get session and API handles
-require_once 'plc_session.php';
-global $plc, $api;
-
-/*
-// Print header
-require_once 'plc_drupal.php';
-drupal_set_title('Slices');
-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'];
-
-
-
-// echo "<pre>"; print_r( $_POST ); echo "</pre>";
-// SLICES ------------------------------------------------------
-
-// if action exists figure out what to do
-if( $_POST['actions'] ) {
-  // get slice_id as int
-  $slice_id= intval( $_POST['slice_id'] );
-
-  // depending on action, run function
-  switch( $_POST['actions'] ) {
-    case "renew":
-      plc_redirect("renew_slice.php?id=$slice_id" );
-      break;
-    case "delete":
-      plc_redirect( "delete_slice.php?id=$slice_id" );
-      break;
-    case "nodes":
-      plc_redirect( "slice_nodes.php?id=$slice_id" );
-      break;
-    case "users":
-      plc_redirect( "slice_users.php?id=$slice_id" );
-      break;
-     
-  }
-
-}
-
-  
-/*
-// Print footer
-include 'plc_footer.php';
-*/
-
-?>
diff --git a/planetlab/slices/slice_nodes.php b/planetlab/slices/slice_nodes.php
deleted file mode 100644 (file)
index 72f0ae7..0000000
+++ /dev/null
@@ -1,264 +0,0 @@
-<?php
-
-// $Id$
-// Thierry on 2007-02-20
-// There's no reason why we should see this page with a foreign slice, at least
-// so long as the UI is used in a natural way, given the UI's logic as of now
-// however it's always possible that someone forges her own url like
-// http://one-lab.org/db/slices/slice_nodes?id=176
-// So just to be consistent, we protect ourselves against such a usage
-
-// Require login
-require_once 'plc_login.php';
-
-// Get session and API handles
-require_once 'plc_session.php';
-global $plc, $api, $adm;
-
-// Print header
-require_once 'plc_drupal.php';
-drupal_set_title('Slices');
-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'];
-
-//print_r( $_person );
-
-// if no id ... redirect to slice index
-if( !$_GET['id'] && !$_POST['id'] ) {
-  plc_redirect( l_slices());
- }
-
-
-// get slice id from GET or POST
-if( $_GET['id'] )
-  $slice_id= intval( $_GET['id'] );
-elseif ( $_POST['id'] )
-  $slice_id= intval( $_POST['id'] );
-else
-  echo "no slice_id<br />\n";
-
-
-// if add node submitted add the nodes to slice
-if( $_POST['add'] ) {
-  $add_nodes= $_POST['add_nodes'];
-  
-  foreach( $add_nodes as $nodes) {
-    $new_nodes[]= intval( $nodes );
-  }
-
-  // update it!
-  $api->AddSliceToNodes( $slice_id, $new_nodes );
-
-  $errors= $api->error();
-
-  if( empty( $errors ) )
-    $added= "<font color=blue>Nodes Added.</font><br /><br />";
-  else
-    $added= "<font color=red>Error: '$errors'</font><br /><br />";
-}
-
-// if rem node submitted remove the nodes from slice
-if( $_POST['remove'] ) {
-  $rem_nodes= $_POST['rem_nodes'];
-
-  foreach( $rem_nodes as $nodes) {
-    $new_nodes[]= intval( $nodes );
-  }
-  
-  // Delete them!
-  $api->DeleteSliceFromNodes( $slice_id, $new_nodes );
-
-  $errors= $api->error();
-
-  if( empty( $errors ) )
-    $removed= "<font color=blue>Nodes Removed.</font><br />";
-  else
-    $removed= "<font color=red>Error: '$errors'</font><br /><br />";
-
-}
-
-
-// get slice info
-$slice_info= $adm->GetSlices( array( $slice_id ), array( "name", "node_ids", "peer_id" ) );
-$slice_readonly = $slice_info[0]['peer_id'];
-drupal_set_title("Slice " . $slice_info[0]['name'] . " - Nodes");
-
-// get node info
-if( !empty( $slice_info[0]['node_ids'] ) )
-  $node_info= $adm->GetNodes( $slice_info[0]['node_ids'], array( "hostname", "node_id", "site_id" , "peer_id") );
-  
-// get site names and ids
-$site_info= $adm->GetSites( NULL, array( "site_id", "name", "peer_id" ) );
-sort_sites( $site_info );
-
-// if site_id is in post use it, if not use the user's primary
-if( $_POST['site_id'] )
-  $site_id= $_POST['site_id'];
-else
-  $site_id= $_person['site_ids'][0];
-
-
-// get site nodes for $site_id
-if( $site_id == 'all_site' ) {
-  $full_node_info= $adm->GetNodes( array("node_type","regular"),
-                                  array( "hostname", "node_id" , "peer_id", "boot_state","last_updated") );
-
-  $snode_info= array();
-  foreach( $full_node_info as $full_node ) {
-    if( !in_array( $full_node['node_id'], $slice_info[0]['node_ids'] ) )
-      $snode_info[]= $full_node;
-  }
-}
-else {
-  $sid= intval( $site_id );
-  $site_node_info= $adm->GetSites( array( $sid ), array( "node_ids" ) );
-  $site_nodes= $site_node_info[0]['node_ids'];
-       
-  // gets all node_ids from site that arent already associated with the slice
-  foreach( $site_nodes as $snode) {
-    if( !in_array( $snode, $slice_info[0]['node_ids'] ) )
-      $snodes[]= $snode;
-  }
-       
-  // Get node info from new list
-  if( !empty( $snodes ) )
-    $snode_info= $adm->GetNodes( $snodes, array( "hostname", "node_id" , "peer_id", "boot_state","last_updated" ) );
-  
-}
-
-// start form   
-if ( $slice_readonly) 
-  echo "<div class='plc-foreign'>";
-else
-  echo "<form action='slice_nodes.php?id=$slice_id' method=post>\n";
-
-// section for adding nodes : for local slices only
-if ( ! $slice_readonly ) {
-  echo "<hr />";
-  echo "<h5> Select a site to add nodes from.</h5>\n";
-  echo "<table><tr><td>";
-  if ($site_id != 'all_site') {
-    echo plc_comon_button("site_id",$site_id,"_blank");
-    echo "</td><td>";
-  }
-  echo "<select name='site_id' onChange='submit()'>\n";
-  echo "<option value='all_site'";
-  if( $site_id == 'all_site' )
-    echo " selected";
-  echo ">--All Sites--</option>\n";
-
-  foreach( $site_info as $site ) {
-    echo "<option value=". $site['site_id'];
-    if( $site['site_id'] == $site_id )
-      echo " selected";
-    if ($site["peer_id"]) 
-      echo " class='plc-foreign'";
-    echo ">". $site['name'] ."</option>\n";
-    
-  }
-  
-  echo "</select></td></tr></table>\n";
-
-  // show all availible nodes at $site_id
-  //echo "<pre>"; print_r( $snode_info ); echo "</pre>";
-  if( $snode_info ) {
-    echo $added;
-    echo "<table cellpadding=2><tbody >\n<tr>";
-    echo "<th></th> <th> check </th><th>Hostname</th><th> Boot State </th><th> Last Update</th>
-        </tr>";
-    foreach( $snode_info as $snodes ) {
-      $class="";
-      if ($snodes['peer_id']) {
-       $class="class='plc-foreign'";
-      } 
-      echo "<tr " . $class . "><td>";
-      echo plc_comon_button("node_id",$snodes['node_id'],"_blank");
-      echo "</td><td>";
-      echo "<input type=checkbox name='add_nodes[]' value=". $snodes['node_id'] .">";
-      echo "</td><td align='center'>";
-      echo $snodes['hostname'];
-      echo "</td><td align='center'>";
-      echo $snodes['boot_state'];
-      echo "</td><td align='center'>";
-      echo date('Y-m-d',$snodes['last_updated']);
-      echo "</td></tr>\n";
-    }
-  
-    echo "</tbody></table>\n";
-    echo "<p><input type=submit value='Add Nodes' name='add'>\n";
-  } else {
-    echo "<p>No site nodes or all are already added.\n";
-  }
-}
-
-echo "<hr />\n";
-
-// show all nodes currently associated
-echo $removed;
-echo "<h5>Nodes currently associated with slice</h5>\n";
-if( $node_info ) {
-  if ( ! $slice_readonly) {
-    echo "<u>Check boxes of nodes to remove:</u>\n";
-    echo "<table cellpadding=2><tbody><tr>\n";
-    echo "<th></th> <th> check </th><th>Hostname</th><th> Boot State </th><th> Last Update</th>
-        </tr>";
-  } else {
-    echo "<table cellpadding=2><tbody><tr>\n";
-    echo "<th></th> <th> check </th><th>Hostname</th><th> Boot State </th><th> Last Update</th>
-        </tr>";
-  }
-
-  foreach( $node_info as $node ) {
-    $class="";
-      if ($node['peer_id']) {
-       $class="class='plc-foreign'";
-      } 
-    if ( ! $slice_readonly) {
-      echo "<tr " . $class . "><td>";
-      echo plc_comon_button("node_id",$node['node_id'],"_blank");
-      echo "</td><td>";
-      echo "<input type=checkbox name='rem_nodes[]' value=". $node['node_id'] .">";
-      echo "</td><td>" ;
-      echo $node['hostname'];
-      echo "</td><td align='center'>";
-      echo $snodes['boot_state'];
-      echo "</td><td align='center'>";
-      echo date('Y-m-d',$snodes['last_updated']);
-      echo "</td></tr>\n";
-    } else {
-      echo "<tr " . $class . "><td>";
-      echo plc_comon_button("node_id",$node['node_id'],"_blank");
-      echo "</td><td>" ;
-      echo $node['hostname'];
-      echo "</td></tr>";
-    }
-  
-  }
-  
-  echo "</tbody></table>\n";
-  if ( ! $slice_readonly) 
-    echo "<p><input type=submit value='Remove Nodes' name='remove'>\n";
-  
-} else {
-  echo "<p>No nodes associated with slice.\n";
-}
-
-if ($slice_readonly)
-  echo "</div>";
- else 
-   echo "</form>";
-
-echo "<p><a href='index.php?id=$slice_id'>Back to Slice</a>\n";
-
-
-// Print footer
-include 'plc_footer.php';
-
-?>
diff --git a/planetlab/slices/slice_users.php b/planetlab/slices/slice_users.php
deleted file mode 100644 (file)
index a07c63a..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-<?php
-
-// Thierry on 2007-02-20
-// There's no reason why we should see this page with a foreign slice, at least
-// so long as the UI is used in a natural way, given the UI's logic as of now
-// however it's always possible that someone forges her own url like
-// http://one-lab.org/db/slices/slice_users?id=176
-// So just to be consistent, we protect ourselves against such a usage
-
-// Require login
-require_once 'plc_login.php';
-
-// Get session and API handles
-require_once 'plc_session.php';
-global $plc, $api, $adm;
-
-// Print header
-require_once 'plc_drupal.php';
-drupal_set_title('Slices');
-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'];
-
-//print_r( $_person );
-
-// if no id ... redirect to slice index
-if( !$_GET['id'] && !$_POST['id'] ) {
-  plc_redirect(l_slices());
- }
-
-  
-// get slice id from GET or POST
-if( $_GET['id'] )
-  $slice_id= intval( $_GET['id'] );
-elseif ( $_POST['id'] )
-  $slice_id= intval( $_POST['id'] );
-else
-  echo "no slice_id<br />\n";
-
-// if add node submitted add the nodes to slice
-if( $_POST['add'] ) {
-  $add_user= $_POST['add_user'];
-  
-  foreach( $add_user as $user) {
-    $api->AddPersonToSlice( intval( $user ), $slice_id );
-  }
-
-  $added= "<font color=blue>People Added.</font><br />";
-}
-
-// if rem node submitted remove the nodes from slice
-if( $_POST['remove'] ) {
-  $rem_user= $_POST['rem_user'];
-
-  foreach( $rem_user as $user) {
-    $api->DeletePersonFromSlice( intval( $user ), $slice_id );
-  }
-  
-  $removed= "<font color=blue>People Removed.</font><br />";
-}
-
-// get slice info
-$slice_info= $api->GetSlices( array( $slice_id ), array( "name", "person_ids" , "peer_id") );
-$slice_readonly = $slice_info[0]['peer_id'];
-drupal_set_title("Slice " . $slice_info[0]['name'] . " - Users");
-
-// get person info
-if( !empty( $slice_info[0]['person_ids'] ) ) {
-  $person_info= $adm->GetPersons( $slice_info[0]['person_ids'], array( "first_name", "last_name", "email", "person_id","roles" ) );
-  sort_persons( $person_info );
-}
-
-// if site_id is in post use it, if not use the user's primary
-if( $_POST['site_id'] )
-  $site_id= $_POST['site_id'];
-else
-  $site_id= $_person['site_ids'][0];
-  
-// get site nodes for $site_id
-$sid= intval( $site_id );
-$site_user_info= $adm->GetSites( array( $sid ), array( "person_ids" ) );
-$site_user= $site_user_info[0]['person_ids'];
-
-
-// gets all person_ids from site that arent already associated with the slice
-foreach( $site_user as $suser) {
-  if( !in_array( $suser, $slice_info[0]['person_ids'] ) )
-    $susers[]= $suser;
-
-}
-
-// Get person info from new list
-if( !empty( $susers ) ) {
-  $all_suser_info= $adm->GetPersons( $susers, array( "email", "first_name", "last_name", "person_id", "role_ids", 'roles' ) );
-//Filter the new list of user info to omit the tech user  
-  foreach( $all_suser_info as $user_info) {
-    if ( (count($user_info["role_ids"])==1 ) && ( in_array(40,  $user_info["role_ids"]) )) {
-      continue;
-    }
-    $suser_info[]= $user_info;
-  }
-  if ( ! empty($suser_info) ) {
-    sort_persons( $suser_info );
-  }
- }
-
-
-// start form   
-if ( $slice_readonly) 
-  echo "<div class='plc-foreign'>";
-else
-  echo "<form action='slice_users.php?id=$slice_id' method=post>\n";
-
-// section for adding people : for local slices only
-if ( ! $slice_readonly ) {
-  echo "<hr />";
-  echo "<h5>Select a site to add People from.</h5>\n";
-  echo "<select name='site_id' onChange='submit()'>\n";
-
-  // get site names and ids
-  $site_info= $adm->GetSites( NULL, array( "site_id", "name" ) );
-  sort_sites( $site_info );
-
-  foreach( $site_info as $site ) {
-    echo "<option value=". $site['site_id'];
-    if( $site['site_id'] == $site_id )
-      echo " selected";
-    echo ">". $site['name'] ."</option>\n";
-    
-  }
-
-  echo "</select>\n";
-
-  
-  if( $suser_info ) {
-    echo $added;
-    echo "<table cellpadding=2><tbody >\n<tr>";
-    echo "<th></th> <th> Email </th><th> First Name </th><th> Last Name </th><th> Roles </th>
-        </tr>";
-    $proles="";
-    foreach( $suser_info as $susers ) {
-      foreach ( $susers['roles'] as $prole)
-       $proles.=" ".$prole;
-      echo "<tr><td><input type=checkbox name='add_user[]' value=". $susers['person_id'] ."> </td><td> ". $susers['email'] ."  </td><td align='center'> ". $susers['first_name'] ."</td><td align='center'> ". $susers['last_name'] ."</td><td align='center'> ".$proles."</td></tr>\n";
-      unset($proles);
-    }
-  
-    echo "</tbody></table>\n";
-    echo "<p><input type=submit value='Add People' name='add'>\n";
-  } else {
-    echo "<p>All People on site already added.\n";
-  }
- }
-
-
-echo "<hr />\n";
-
-// show all people currently associated
-echo $removed;
-echo "<h5>People currently associated with slice</h5>\n";
-if( $person_info ) {
-  if ( ! $slice_readonly ) {
-    echo "<u>Check boxes of people to remove:</u>\n";
-    echo "<table cellpadding=2><tbody >\n<tr>";
-    echo "<th></th><th> Email </th><th> First Name</th><th> Last Name</th><th> Roles </th>
-        </tr>";
-  } else {
-    echo "<table cellpadding=2><tbody>\n";
-    echo "<tr><th> E-mail <th> First name <th> Last name<th> Roles </th> </tr>";
-  }
-
-  foreach( $person_info as $person ) {
-    foreach ( $person['roles'] as $prole)
-      $proles.=" ".$prole;
-    if ( ! $slice_readonly ) 
-      echo "<tr><td><input type=checkbox name='rem_user[]' value=". $person['person_id'] ."> </td><td> ". $person['email'] ." </td><td align='center'> ". $person['first_name']." </td><td align='center'>".$person['last_name'] ." </td><td align='center'>".$proles."</td></tr>\n";
-    else 
-      echo "<tr><td align='center'>" . $person['email'] . "</td><td align='center'>" . $person['first_name'] . "</td><td align='center'>" . $person['last_name'] ." </td><td align='center'>".$proles."</td></tr>"; 
-    unset($proles);
-  }
-  
-  echo "</tbody></table>\n";
-  if ( ! $slice_readonly )
-    echo "<p><input type=submit value='Remove People' name='remove'>\n";
-  
-} else {
-  echo "<p>No People associated with slice.\n";
-}
-
-if ($slice_readonly)
-  echo "</div>";
- else 
-   echo "</form>";
-
-echo "<p><a href='index.php?id=$slice_id'>Back to Slice</a>\n";
-
-// Print footer
-include 'plc_footer.php';
-
-?>
-
diff --git a/planetlab/slices/update_slice.php b/planetlab/slices/update_slice.php
deleted file mode 100644 (file)
index 59c3f6a..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-<?php
-
-// Require login
-require_once 'plc_login.php';
-
-// Get session and API handles
-require_once 'plc_session.php';
-global $plc, $api;
-
-// Common functions
-require_once 'plc_functions.php';
-require_once 'plc_sorts.php';
-  
-// find person roles
-$_person= $plc->person;
-$_roles= $_person['role_ids'];
-
-
-if( !empty( $_GET['id'] ) ) {
-  $slice_id= $_GET['id'];
-  // Fetch slice information
-  $slices= $api->GetSlices( array( intval( $slice_id ) ) );
-  if( !empty( $slices ) ) {
-    $slice= $slices[0];
-  }
-}
-
-// Invalid slice name
-if( !isset( $slice ) ) {
-  plc_redirect( l_slices());
-}
-
-// Defaults
-$url_error = "";
-$description_error = "";
-
-if( isset( $_POST['submitted'] ) ) {
-  if( !empty($_POST['url'] ) )
-    $slice['url']= $_POST['url'];
-  else
-    $url_error= "Provide a link to a project website.";
-
-  if( !empty($_POST['desc'] ) )
-    $slice['description'] = $_POST['desc'];
-  else
-    $description_error= "Provide a short description of the slice.";
-
-  if( empty( $url_error ) && empty( $description_error ) ) {
-    // Update the slice URL and description
-    $fields= array( "description"=>$slice['description'], "url"=>$slice['url'] );
-    $api->UpdateSlice( intval( $slice_id ), $fields );
-    plc_redirect(l_slice($slice_id));
-  }
-}
-
-// Print header
-require_once 'plc_drupal.php';
-drupal_set_title('Slices');
-include 'plc_header.php';
-
-$slice_name= $slice['name'];
-
-print "<h2>Update Slice ". $slice['name'] ."</h2>";
-
-//echo "<pre>"; print_r( $slice ); echo "</pre>";
-$url =  $slice['url'] ;
-$description =  $slice['description'] ;
-
-echo <<<EOF
-
-<p>You must provide a short description as well as a
-link to a project website. Do <b>not</b> provide
-bogus information; if a complaint is lodged against your slice and
-PlanetLab Operations is unable to determine what the normal behavior
-of your slice is, your slice may be deleted to resolve the
-complaint.</p>
-
-<form method="post" action="update_slice.php?id=$slice_id">
-
-<table>
-  <tbody>
-    <tr>
-      <th>Name:</th>
-      <td>$slice_name</td>
-      <td></td>
-    </tr>
-    <tr>
-      <th>URL:</th>
-      <td><input size="50" name="url" value="$url" /></td>
-      <td><font color="red"><strong>$url_error</strong></font></td>
-    </tr>
-    <tr>
-      <th>Description:</th>
-      <td><textarea name="desc" rows="5" cols="40">$description</textarea></td>
-      <td><font color="red"><strong>$description_error</strong></font></td>
-    </tr>
-  </tbody>
-</table>
-
-<input type="submit" name="submitted" value="Update" />
-
-</form>
-
-EOF;
-
-// Print footer
-include 'plc_footer.php';
-
-?>
index c7ffc39..1796766 100644 (file)
@@ -43,6 +43,7 @@ class PlekitToggle {
       $options['start-hidden'] = ! $options['start-visible'];
       unset ($options['start-visible']);
     }
+    if (!isset ($options['start-hidden'])) $options['start-hidden']=false;
     $this->options = $options;
   }
 
@@ -84,8 +85,9 @@ class PlekitToggle {
   function trigger_html () {
     $trigger_id=$this->id_name('trigger');
     if (array_key_exists ('trigger-tagname',$this->options)) $tagname=$this->options['trigger-tagname'];
-    if (array_key_exists ('trigger-bubble',$this->options)) $bubble=$this->options['trigger-bubble'];
     if (empty($tagname)) $tagname="span";
+    $bubble="";
+    if (array_key_exists ('trigger-bubble',$this->options)) $bubble=$this->options['trigger-bubble'];
     
     $html="<$tagname";
     $html .= " id='$trigger_id'";