sites almost there
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 30 Jan 2009 15:24:01 +0000 (15:24 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 30 Jan 2009 15:24:01 +0000 (15:24 +0000)
14 files changed:
modules/planetlab.module
planetlab/actions.php
planetlab/adminsearch.php
planetlab/events/index.php
planetlab/includes/plc_functions.php
planetlab/includes/plc_functions_trash.php
planetlab/nodes/node.php
planetlab/nodes/nodes.php
planetlab/persons/person.php
planetlab/persons/persons.php
planetlab/sites/expire.php [deleted file]
planetlab/sites/index.php
planetlab/sites/site.php [new file with mode: 0644]
planetlab/sites/sites.php [new file with mode: 0644]

index 5b91c09..5bb1355 100644 (file)
@@ -117,7 +117,7 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array()) {
       $site_item .= ul_start();
       $site_item .= leaf( href(l_site(plc_my_site_id()),"My site"));
       if ( $is_admin ) 
-       $site_item .= leaf( href(l_site_pending(),"Pending Requests"));
+       $site_item .= leaf( href(l_sites_pending(),"Pending Requests"));
       $site_item .= ul_end();
       $items[] = expanded($site_item);
 
index 7e18dfd..b69af23 100644 (file)
@@ -42,6 +42,8 @@ $known_actions []= "update-tag-type";
 //     expects:        tag_type_id & name & description & category & min_role_id  
 $known_actions []= "add-tag-type";
 //     expects:        tag_type_id & name & description & category & min_role_id  
+$known_actions []= "expire-all-slices-in-site";
+//     expects:        slice_ids
 
 //////////////////////////////
 // sometimes we don't set 'action', but use the submit button name instead
@@ -225,6 +227,25 @@ switch ($action) {
    exit();
  }
 
+ case 'expire-all-slices-in-site': {
+   drupal_set_message("action $action not implemented in actions.php -- need tweaks and test");
+   return;
+
+   //// old code from sites/expire.php
+   $sites = $api->GetSites( array( intval( $site_id )));
+   $site=$sites[0];
+   // xxx why not 'now?'
+   $expiration= strtotime( $_POST['expires'] );
+   // loop through all slices for site
+   foreach ($site['slice_ids'] as $slice_id) {
+     $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) );
+   }
+   // update site to not allow slice creation or renewal
+   $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ;
+   header ("location: " l_site($site_id));
+   exit(0);
+ }
+
  case 'debug': {
    plc_debug('GET',$_GET);
    plc_debug('POST',$_POST);
index 3f182a9..1e7d347 100644 (file)
@@ -19,18 +19,19 @@ require_once 'plc_objects.php';
 require_once 'plc_sorts.php';
 
 function is_possible_domainname($token) {
-  if( strpos ( $token, "@" ) === False && substr_count($token, ".") >= 2 ) {
+  if ( strpos ( $token, "@" ) === False && substr_count($token, ".") >= 2 ) {
     return true;
   } else {
     return false;
   }
 }
+
 function get_and_print_site($site_array) {
   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 ) {
+  if ( count($sites) > 0 ) {
     foreach( $sites as $site) {
       $name = $site['name'];
       $site_id = $site['site_id'];
@@ -64,8 +65,8 @@ function get_and_print_site($site_array) {
       echo "</td></tr>\n";
     }
   }
-
 }
+
 function get_and_print_hostname($host_array) {
   global $api;
   $nodes = $api->GetNodes( $host_array, array( "hostname", "node_id", 
@@ -95,7 +96,7 @@ function get_and_print_hostname($host_array) {
   return $nodes;
 }
 
-function get_and_print_user($user_array) {
+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", 
@@ -277,7 +278,7 @@ if (false) {
 
     sort_persons( $persons );
 
-    echo paginate( $persons, "person_id", "Persons", 25, "email" );
+    echo paginate_trash ( $persons, "person_id", "Persons", 25, "email" );
 
   }
   // if no person id, display list of persons to choose
index e1b9ad2..625ae3c 100644 (file)
@@ -23,7 +23,7 @@ ini_set("memory_limit","256M");
 //set default title
 drupal_set_title('Events');
 
-// paginate unit
+// page size
 $page_size=30;
 
 $messages = array ();
index 10172a2..2bcf31f 100644 (file)
@@ -57,13 +57,18 @@ function l_interface_t ($interface_id,$text) {
 function l_interface_add($node_id)     { return "/db/nodes/interfaces.php?node_id=$node_id"; }
 
 function l_sites ()                    { return "/db/sites/index.php"; }
+function l_sites_local ()              { return "/db/sites/index.php?peerscope=local"; }
 function l_site ($site_id)             { return "/db/sites/index.php?id=$site_id"; }
 function l_site_t ($site_id,$text)     { return href (l_site($site_id),$text); }
+function l_site_update($site_id)       { return "/xxx-undefined"; }
 
 function l_slices ()                   { return "/db/slices/index.php"; }
 function l_slice ($slice_id)           { return "/db/slices/index.php?id=$slice_id"; }
 function l_slice_t ($slice_id,$text)   { return href (l_slice($slice_id),$text); }
 function l_slice_add ()                        { return "/db/slices/add_slice.php"; }
+function l_slices_site($site_id)       { return "/db/slices/index.php?site_id=$site_id"; }
+// from an object
+function l_slice_text ($slice)         { return l_slice_t ($slice['slice_id'],$slice['name']); }
 
 function l_sliver ($node_id,$slice_id) { return "/db/nodes/slivers.php?node_id=$node_id&slice_id=$slice_id"; }
 function l_sliver_t ($node_id,$slice_id,$text) { 
@@ -102,7 +107,7 @@ function l_sulogout()                       { return "/planetlab/sulogout.php"; }
 function l_reset_password()            { return "/db/persons/reset_password.php"; }
 function l_person_register()           { return "/db/persons/register.php"; }
 function l_site_register()             { return "/db/sites/register.php"; }
-function l_site_pending()              { return "/db/sites/join_request.php"; }
+function l_sites_pending()             { return "/db/sites/join_request.php"; }
 
 // returns array ['url' => path, 'values' => hash (key=>value)* ]
 function split_url ($full_url) {
@@ -230,6 +235,15 @@ function plc_peer_shortname ($peer_hash,$peer_id) {
   }
 }
 
+function plc_peer_label ($peer) { 
+  if (! $peer) {
+    return "Local object on " . PLC_NAME . " (" . PLC_SHORTNAME . ")";
+  }
+  $result= $peer['peername'] . " (" . $peer['shortname'] . ")";
+  $result= href(l_peer($peer['peer_id']),$result);
+  return plc_foreign_text($result);
+}
+
 // to set the background to grey on foreign objects
 // return true if the peer is local 
 function plc_peer_block_start ($peer_hash,$peer_id) {
@@ -381,12 +395,9 @@ function plc_errors ($list) {
   print( "</ul></div>\n" );
 }
 
-function plc_warning_div ($text) {
-  return "<div class='plc-warning'>" . $text . "</div>";
-}
-function plc_warning ($text) {
-  print plc_warning_div("Warning " . $text);
-}
+function plc_warning_text ($text)      { return "<div class='plc-warning'>" . $text . "</div>";}
+function plc_warning ($text)           { print plc_warning_text("Warning " . $text); }
+function plc_foreign_text($text)       { return "<div class=plc-foreign>$text</div>"; }
 
 // shows a php variable verbatim with a heading message
 function plc_debug ($message,$object) {
@@ -395,4 +406,5 @@ function plc_debug ($message,$object) {
   print "</pre>";
 }
 
+
 ?>
index b4c18dd..d277c5c 100644 (file)
@@ -3,7 +3,7 @@
 // this will be trashed eventually
 
 // pagination function
-function paginate( $fn_array, $table_id, $caption, $limit, $main_field, $other_func= NULL, $fid= NULL ) {
+function paginate_trash ( $fn_array, $table_id, $caption, $limit, $main_field, $other_func= NULL, $fid= NULL ) {
   // get vars from call adjust them
   $dir= strtolower( $caption );
   $echo= "";
index 8e4117b..842b8b7 100644 (file)
@@ -2,7 +2,7 @@
 
   // $Id$
 
-  // Require login
+// Require login
 require_once 'plc_login.php';
 
 // Get session and API handles
@@ -51,7 +51,11 @@ $nodegroup_ids= $node['nodegroup_ids'];
 $pcu_ids= $node['pcu_ids'];
 
 // get peer
-$peer_id= $node['peer_id'];
+$peer_id = $node['peer_id'];
+if ($peer_id) {
+  $peers=$api->GetPeers(array($peer_id));
+  $peer=$peers[0];
+ }
 
 // gets site info
 $sites= $api->GetSites( array( $site_id ) );
@@ -131,6 +135,7 @@ $tabs["All nodes"]=l_nodes();
 plc_tabs($tabs);
 
 plc_details_start ();
+plc_details_line("Peer",plc_peer_label($peer));
 plc_details_line("Hostname",$hostname);
 plc_details_line("Type",$node_type);
 plc_details_line("Model",$model);
index 0db6054..13e61c2 100644 (file)
@@ -33,7 +33,6 @@ $tabs['My nodes'] = array('url'=>l_nodes(),
                          'values'=>array('site_id'=>plc_my_site_id()),
                          'bubble'=>'Lists nodes on site ' . $mysite_id);
 // -------------------- 
-$peer_filter=array();
 $node_filter=array();
 
 //////////////////
@@ -54,7 +53,7 @@ function node_status ($node) {
 
 
 // fetch nodes 
-$node_columns=array('hostname','node_type','site_id','node_id','boot_state','interface_ids','peer_id');
+$node_columns=array('hostname','node_type','site_id','node_id','boot_state','interface_ids','peer_id', "arch");
 // server-side filtering - set pattern in $_GET for filtering on hostname
 if ($pattern) {
   $node_filter['hostname']=$pattern;
@@ -129,16 +128,15 @@ $headers = array ("Peer"=>"string",
                  "Hostname"=>"string",
                  "IP"=>"IPAddress",
                  "Type"=>"string",
+                 "Arch"=>"string",
                  "?"=>"string",
-                 "Int"=>"int",
-                 "Float"=>"float");
+                 );
 
 # initial sort on hostnames
 plc_table_start("nodes",$headers,4);
 
 $peer_hash = plc_peer_global_hash ($api);
 // write rows
-$fake1=1; $fake2=3.14; $fake_i=0;
 foreach ($nodes as $node) {
     $hostname=$node['hostname'];
     $node_id=$node['node_id'];
@@ -159,14 +157,10 @@ foreach ($nodes as $node) {
     plc_table_cell (l_node_t($node_id,$hostname));
     plc_table_cell (l_interface_t($interface_id,$ip));
     plc_table_cell ($node_type);
+    plc_table_cell ($node['arch']);
     plc_table_cell (node_status($node));
-    plc_table_cell ($fake1);
-    plc_table_cell ($fake2);
     plc_table_row_end();
                                 
-    if ($fake_i % 5 == 0) $fake1 += 3; 
-    if ($fake_i % 3 == 0) $fake2 +=5; else $fake2 -= $fake_i;
-    $fake_i += 1;
 }
 
 plc_table_end("nodes");
index 965e1d8..87b6827 100644 (file)
@@ -130,7 +130,7 @@ 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");
+if ( ! $enabled ) $enabled_text = plc_warning_text("Disabled");
 
 plc_details_start();
 plc_details_line("Enabled",$enabled_text);
index 31408c4..f5ac603 100644 (file)
@@ -35,7 +35,6 @@ $tabs['My accounts'] = array('url'=>l_persons(),
                             'values'=>array('site_id'=>plc_my_site_id()),
                             'bubble'=>'Lists accounts on site ' . plc_my_site_id());
 // -------------------- 
-$peer_filter=array();
 $person_filter=array();
 
 ////////////////////
diff --git a/planetlab/sites/expire.php b/planetlab/sites/expire.php
deleted file mode 100644 (file)
index 6522909..0000000
+++ /dev/null
@@ -1,74 +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'];
-
-
-// if no site id redirect
-if( !$_GET['id'] ) {
-  header( "location: index.php" );
-  exit();
- }
-
-// get site id
-$site_id= $_GET['id'];
-
-// get site info
-$site_info= $api->GetSites( array( intval( $site_id ), array( "name", "url", "longitude", "latitude", "login_base", "max_slices", "abbreviated_name", "slice_ids" ) );
-
-// if submitted expire
-if( $_POST['action'] ) {
-  $expiration= strtotime( $_POST['expires'] );
-  
-  // loop through all slices for site
-  foreach( $site_info[0]['slice_ids'] as $slice_id ) {
-    $fields= array( "expires" => $expiration );
-    // update all slice's expiration
-    $api->UpdateSlice( $slice_id, $fields );
-  
-  }
-  
-  // update site to not allow slice creation or renewal
-  $site_fields= array( "max_slices" => 0 );
-  $api->UpdateSite( $site_id, $site_fields );
-
-}
-
-
-// Print header
-require_once 'plc_drupal.php';
-drupal_set_title('Sites');
-include 'plc_header.php';
-
-// start form
-echo "<form method=post action='expire.php?id=$site_id'>\n";
-echo "<h2>Expire ". $site_info[0]['name'] ."</h2>\n";
-echo "<b>Expiration:</b>&nbsp;<input name='expires' value='2 days' />\n";
-echo "<p>Are you sure you want to set the expiration date for all slices that expire after the above date to the above date as well as disable slice creation and renewal at this site?</p>\n";
-echo "<input type=submit name='action' value='Yes' />\n";
-
-echo "<p><a href='index.php?id=$site_id'>Back to Site</a>\n";
-
-
-echo "</form>\n";
-
-
-// Print footer
-include 'plc_footer.php';
-
-?>
index 4b7443f..a871948 100644 (file)
 <?php
+
 // $Id$
-//
 
 // 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';
-// set default
-drupal_set_title('Sites');
-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'];
-
-////////////////////
-// The set of columns to fetch
-// and the filter applied for fetching sites
-if ( !in_array( '10', $_roles ) ) {
-  $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" );
-  $filter = array ("enabled" => TRUE);
- } else {
-  $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" , "enabled", "person_ids", "max_slices", "slice_ids", "node_ids");
-  $filter = array ();
- }
-
-
-//////////////////
-// perform post-processing on site objects as returned by GetSites
-// performs sanity check and summarize the result in a single column
-// performs in-place replacement, so passes a reference
-function layout_site ($site) {
-
-  // we need the 'enabled' field to do this
-  // so regular users wont run this
-  if ( ! array_key_exists ('enabled', $site))
-    return $site;
-    
-  $messages=array();
-  
-  if (empty ($site['node_ids'])) $messages [] = "Site has no node";
-  $class='plc-foreign';
-
-  // do all this stuff on local sites only
-  if ( ! $site['peer_id'] ) {
-    
-    $class='plc-warning';
-
-    // check that site is enabled
-    if ( ! $site['enabled']) {
-      $messages [] = "Not enabled";
-    }
-  
-    // check that site has at least a PI and a tech
-    global $api;
-    $persons=$api->GetPersons(array("person_id"=>$site['person_ids']),array("role_ids"));
-    $nb_pis=0;
-    $nb_tech=0;
-    
-    if ( ! empty ($persons)) {
-      foreach ($persons as $person) {
-       if (in_array( '20', $person['role_ids'])) $nb_pis += 1;
-       if (in_array( '40', $person['role_ids'])) $nb_techs += 1;
-      }
-    }
-    if ($nb_pis == 0) $messages [] = "Site has no PI";
-    if ($nb_techs == 0) $messages [] = "Site has no Tech";
-    
-    // check number of slices
-    if ( $site['max_slices'] == 0) {
-      $messages [] = "No slice allowed";
-    } else if (count($site["slice_ids"]) >= $site['max_slices']) {
-      $messages [] = "Site has no slice left";
-    }
-    
-    // pretty print the cell
-  }
-  // but always cleanup $site columns
-  unset ($site['enabled']);
-  unset ($site['person_ids']);
-  unset ($site['max_slices']);
-  unset ($site['slice_ids']);
-  unset ($site['node_ids']);
-  $site['sanity check'] = plc_vertical_table($messages,$class);
-  
-  return $site;
-}
-
-
-// if sitepattern or peerscope is set : search the sites
-// we use GET rather than POST so paginate can display the right contents on subsequent pages
-// can be useful for writing bookmarkable URL's as well
-if( $_GET['sitepattern'] || $_GET['peerscope']) {
-  $sitename= $_GET['sitepattern'];
-  if (empty($sitename)) { 
-    $sitename="*";
-  }
-  $filter = array_merge (array( "name"=>$sitename ), $filter);
-  switch ($_GET['peerscope']) {
-  case '':
-    $peer_label="all peers";
-    break;
-  case 'local':
-    $filter=array_merge(array("peer_id"=>NULL),$filter);
-    $peer_label="local peer";
-    break;
-  case 'foreign':
-    $filter=array_merge(array("~peer_id"=>NULL),$filter);
-    $peer_label="foreign peers";
-    break;
-  default:
-    $peer_id=intval($_GET['peerscope']);
-    $filter=array_merge(array("peer_id"=>$peer_id),$filter);
-    $peer=$api->GetPeers(array("peer_id"=>$peer_id));
-    $peer_label='peer "' . $peer[0]['peername'] . '"';
-    break;
-  }
-
-  $sites= $api->GetSites( $filter , $site_columns);
-  $sites = array_map(layout_site,$sites);
-
-  $sites_count = count ($sites);
-  if ( $sites_count == 1) {
-    header( "location: index.php?id=". $sites[0]['site_id'] );
-    exit();
-  } else if ( $sites_count == 0) {
-    echo "<span class='plc-warning'> No site matching $sitename on " . $peer_label . " </span>";
-  } else {
-    drupal_set_title ("Sites matching $sitename on " . $peer_label);
-    sort_sites ($sites);
-    echo paginate( $sites, "site_id", "Sites", 25, "name");
-  }
-}
-
-
-// if no site id, display list of sites to choose
-elseif( !$_GET['id'] ) {
-
-  // GetSites API call
-  // careful, need to pass NULL and *not* array() if no filter is given
-  $sites= $api->GetSites( empty($filter) ? NULL : $filter, $site_columns );
-  $sites = array_map(layout_site,$sites);
-  if ( empty ($sites)) {
-    echo "No site to display";
-  } else {
-    sort_sites( $sites );
-
-    drupal_set_html_head('<script type="text/javascript" src="/planetlab/bsn/bsn.Ajax.js"></script>
-    <script type="text/javascript" src="/planetlab/bsn/bsn.DOM.js"></script>
-    <script type="text/javascript" src="/planetlab/bsn/bsn.AutoSuggest.js"></script>');
-    
-    echo "<div>\n
-        <form method=get action='index.php'>\n";
-    echo "<table><tr>\n
-<th><label for='testinput'>Enter Site Name or pattern: </label></th>\n
-<td><input type='text' id='testinput' name='sitepattern' size=40 value='' /></td>\n
-<td rowspan=2><input type=submit value='Search Sites' /></td>\n
-</tr> <tr>
-<th><label for='peerscope'>Federation scope: </label></th>\n
-<td><select id='peerscope' name='peerscope' onChange='submit()'>\n
-";
-    echo plc_peers_option_list($api);
-    echo "</select></td>\n
-</tr></table></form></div>\n
-<br />\n";
-    
-    echo paginate( $sites, "site_id", "Sites", 25, "name" );
-
-    echo "<script type=\"text/javascript\">\n
-var options = {\n
-       script:\"/planetlab/sites/test.php?\",\n
-       varname:\"input\",\n
-       minchars:1\n
-};\n
-var as = new AutoSuggest('testinput', options);\n
-</script>\n";
-  }
-}
-else {
-  // stores get variable and casts it as int
-  $site_id= intval( $_GET['id'] );
-
-  // api call GetSites
-  $site_info= $adm->GetSites( array( $site_id ) );
-
-  // var names to api return
-  $sitename= $site_info[0]['name'];
-  $abbrev_name= $site_info[0]['abbreviated_name'];
-  $site_url= $site_info[0]['url'];
-  $login_base= $site_info[0]['login_base'];
-  $site_lat= $site_info[0]['latitude'];
-  $site_long= $site_info[0]['longitude'];
-  $max_slivers= $site_info[0]['max_slivers'];
-  $max_slices= $site_info[0]['max_slices'];
-
-  $enabled = $site_info[0]['enabled'];
-
-  // peer id
-  $peer_id= $site_info[0]['peer_id'];
-
-  $site_addresses= $site_info[0]['address_ids'];
-  $site_pcus= $site_info[0]['pcu_ids'];
-  $site_nodes= $site_info[0]['node_ids'];
-  $site_persons= $site_info[0]['person_ids'];
-  $site_slices= $site_info[0]['slice_ids'];
-
-  $adm->begin();
-  // gets address info
-  $adm->GetAddresses( $site_addresses );
-
-  // gets pcu info
-  $adm->GetPCUs( $site_pcus );
-
-  // gets node info
-  $adm->GetNodes( $site_nodes, array( "node_id", "hostname", "boot_state" ) );
-
-  // gets person info
-  $adm->GetPersons( $site_persons, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" ) );
-
-  $adm->GetSlices ( $site_slices, array ("slice_id", "name", "instantiation" ) );
-
-  list( $addresses, $pcus, $nodes, $persons, $slices )= $adm->commit();
-  
-  $techs = array();
-  $pis = array();
-  foreach( $persons as $person ) {
-    $role_ids= $person['role_ids'];
-    if( in_array( '40', $role_ids ))
-      $techs[] = $person;
-
-    if( in_array( '20', $role_ids ))
-      $pis[] = $person;
-
-  }
-
-  if( $peer_id ) {
-    echo "<div class='plc-foreign'>\n";
-  }
-
-  // start form
-  drupal_set_title("Site $sitename details");
-  //  echo "<h3>$sitename Site details</h3>\n";
-
-  if( !$peer_id ) {
-    $actions= array( ''=>'Choose Action' );
-    
-    if( in_array( 10, $_roles ) 
-       || ( in_array( 20, $_roles ) && in_array( $site_id, $_person['site_ids'] ) ) ) {
-      $actions['update']= 'Update Site';
-    }
-    
-    if( in_array( 10, $_roles ) ) {
-      $actions['delete']= 'Delete Site';
-      $actions['expire']= 'Expire All Slices';
-    }
-    
-    echo "<table> <tr><td>";
-    if( in_array( 10, $_roles ) ) {
-      echo plc_event_button("Site","site",$site_id);
-      echo "</td><td>\n";
-    }
-    echo plc_comon_button("site_id",$site_id);
-    // comon link
-    echo "</td><td>";
-
-    // list to take site action
-    echo "<form action='/db/sites/site_action.php' method='post'>\n";
-    echo "<input type=hidden name=site_id value=$site_id>\n";
-    echo "<select name='actions' onChange=\"submit();\">\n";
-    foreach( $actions as $key => $val ) {
-      echo "<option value='$key'";
-      if( $key == $_POST['actions'] ) {
-       echo " selected";
-      }
-      echo ">$val\n";
-    }
-    echo "</select>\n";
-    echo "</form>";
-    
-    echo "</td></tr></table>\n";
-  }
-       
-
-  if ( ! $enabled ) {
-    echo "<p class='plc-warning'> This site is not enabled - Please visit <a href='/db/sites/join_request.php'> this page </a> to review pending applications. </p>";
-  }
-
-  // basic site info
-  echo "<p><table class='list_set' border=0>\n
-  <tr class='list_set'><th>Full name: </th><td class='list_set'> $sitename</td></tr>\n
-  <tr class='list_set'><th>Login base: </th><td class='list_set'> $login_base</td></tr>\n
-  <tr class='list_set'><th>Abbreviated Name: </th><td class='list_set'> $abbrev_name</td></tr>\n
-  <tr class='list_set'><th>URL: </th><td class='list_set'> <a href='$site_url'>$site_url</a></td></tr>\n
-  <tr class='list_set'><th>Latitude: </th><td class='list_set'> $site_lat</td></tr>\n
-  <tr class='list_set'><th>Longitude: </th><td class='list_set'> $site_long</td></tr>\n";
-       
-  if( $peer_id ) {
-    // display peer name
-    echo "<tr><th></th><td></td></tr>\n";
-    $peer = $api->GetPeers(array('peer_id'=>$peer_id));
-    echo "<tr><th>Managed at foreign peer:</th><td>" . $peer[0]['peername'] . "</td></tr>";
-    // we wrap up everything here
-    // the local version closes the table in the middle of the page...
-    echo "</table>";
-    echo "<br /></div>";
-  
-  } else {
-
-    // Slices
-    echo "<tr><th></th><td></td></tr>\n";
-    $href="'/db/slices/index.php?site_id=" . $site_id . "'";
-    $slice_text="" . count($site_slices) . "/" . $max_slices;
-    if (count($site_slices) >= $max_slices) {
-      $slice_text .= " <span class='plc-warning'>Maximum number of slices reached !</span>";
-    }
-    printf("<tr><th><a href=%s># Slices Used/Allocated:</a> </th><td> <a href=%s>%s</a></td></tr>\n",$href,$href,$slice_text);
-    if ( ! empty ($site_slices)) {
-      foreach ($slices as $slice) {
-       $href="'/db/slices/index.php?id=" . $slice['slice_id'] . "'";
-       printf ("<tr><td><a href=%s> %s</a></td><td> <a href=%d> %s </a> </td> </tr>\n",
-               $href,$slice['name'],$href,$slice['instantiation']);
-      }
-    }
-
-    // Users
-    echo "<tr><th></th><td></td></tr>\n";
-    $href="'/db/persons/index.php?site_id=" . $site_id . "'";
-    printf ("<tr><th> <a href=%s># Users</a></th><td><a href=%s>Total %d users</a></td>\n",$href,$href,count($site_persons));
-
-    echo "<tr><th>PI(s)</th><td>";
-    if ( ! $pis) {
-      echo "<span class='plc-warning'>Site has no PI !!</span>";
-    } else {
-      echo "<table border=0>";
-      foreach( $pis as $person ) {
-       echo "<tr><td>";
-       if ( ! $person['enabled'] ) {
-         printf("<span class='plc-warning'> <a href='/db/persons/index.php?id=%d'>%s</a> (not enabled yet)</span><br />\n",$person['person_id'],$person['email']);
-       } else {
-         printf("<a href='/db/persons/index.php?id=%d'>%s</a><br />\n",$person['person_id'],$person['email']);
-       }
-       echo "</td></tr>\n";
-      }
-      echo "</table>\n";
-    }
-    echo "</td></tr>\n";
-
-    echo "<tr><th>Tech(s)</th><td>";
-    if ( ! $techs) {
-      echo "<span class='plc-warning'>Site has no Technical contact !!</span>";
-    } else {
-      echo "<table border=0>";
-      foreach( $techs as $person ) {
-       echo "<tr><td>";
-       if ( ! $person['enabled'] ) {
-         printf("<span class='plc-warning'> <a href='/db/persons/index.php?id=%d'>%s</a> (not enabled yet)</span><br />\n",$person['person_id'],$person['email']);
-       } else {
-         printf("<a href='/db/persons/index.php?id=%d'>%s</a><br />\n",$person['person_id'],$person['email']);
-       }
-       echo "</td></tr>\n";
-      }
-      echo "</table>\n";
-    }
-    echo "</td></tr>\n";
-
-    // Nodes 
-    echo "<tr><th></th><td></td></tr>\n";
-    $href="'/db/nodes/index.php?site_id=" . $site_id . "'";
-    printf ("<tr><th><a href=%s># Nodes</a></th>",$href);
-    if (empty ($site_nodes)) {
-      $right_site = in_array($site_id,$_person['site_ids']);
-      $right_role = in_array(30,$_roles) || in_array(40,$_roles);
-      $can_add = $right_site && $right_role;
-      if ($can_add) {
-       $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);
-      }
-    } else {
-      printf ("<td><a href=%s>%d</a></td>",$href,count($nodes));
-    }
-    echo "</tr>";
-
-    if( !empty( $site_nodes ) ) {
-      foreach( $nodes as $node ) {
-       echo "<tr><td><a href='/db/nodes/index.php?id=". $node['node_id'] ."'>". $node['hostname'] ."</a></td><td class='list_set'>". $node['boot_state'] ."</td></tr>\n";
-      }
-      
-    }
-    
-    echo "</table>\n";
-
-    // Addresses
-    echo "<hr />\n";
-    
-    // if there is an address list it.
-    if( !empty( $addresses ) ) {
-      echo "<h4>Addresses</h4>\n";
-      
-      foreach( $addresses as $address ) {
-       echo "<p><table cellpadding=2><tbody><tr><td><a href='/db/addresses/index.php?id=". $address['address_id'] ."'>";
-       
-       $comma= count( $address['address_types'] );
-       $count= 0;
-       foreach( $address['address_types'] as $add_type ) {
-         echo $add_type;
-         $count++;
-         if ( $comma > 0 && $count != $comma )
-           echo ", ";
-       }
-       
-       echo "</a></td></tr>\n<tr><td>". $address['line1'] ."</td></tr>\n</tr><td>". $address['line2'] ."</td></tr>\n<tr><td>". $address['line3'] ."</td></tr>\n<tr><td>". $address['city'] .", ". $address['state'] ." ". $address['postalcode'] ."</td></tr>\n<tr><td>". $address['country'] ."</td></tr></tbody></table></p>\n";
-      }
-      
-    }
-    else {
-      echo "Site has no addresses. \n";
-    }
-    
-    // if eligable display add address
-    /*if( in_array( '10', $_roles ) || in_array( '20', $_roles ) )
-     echo "<br /><p><a href='/db/addresses/add_address.php'>Add an address</a>\n";*/
-    
-  }
-  
-  echo "<br /><hr /><p><a href='/db/sites/index.php'>Back to site list</a>";
-
-}
-
-
-// Print footer
-include 'plc_footer.php';
+if ($_GET['id']) require ('site.php') ;
+else             require ('sites.php');
 
 ?>
diff --git a/planetlab/sites/site.php b/planetlab/sites/site.php
new file mode 100644 (file)
index 0000000..822ed4c
--- /dev/null
@@ -0,0 +1,195 @@
+<?php
+
+  // $Id: index.php 11750 2009-01-29 10:11:53Z thierry $
+
+// 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';
+include 'plc_header.php';
+
+// Common functions
+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
+$site_id=intval($_GET['id']);
+if ( ! $site_id ) { plc_error('Malformed URL - id not set'); return; }
+
+////////////////////
+// Get all columns as we focus on only one entry
+$sites= $api->GetSites( array($site_id));
+
+if (empty($sites)) {
+  drupal_set_message ("Site " . $site_id . " not found");
+  return;
+ }
+
+$site=$sites[0];
+// var names to api return
+$sitename= $site['name'];
+$abbrev_name= $site['abbreviated_name'];
+$site_url= $site['url'];
+$login_base= $site['login_base'];
+$site_lat= $site['latitude'];
+$site_long= $site['longitude'];
+$max_slivers= $site['max_slivers'];
+$max_slices= $site['max_slices'];
+
+$enabled = $site['enabled'];
+
+// get peer details
+$peer_id= $site['peer_id'];
+if ($peer_id) {
+  $peers=$api->GetPeers(array("peer_id"=>$peer_id));
+  $peer=$peers[0];
+ }
+
+$adress_ids= $site['address_ids'];
+$pcu_ids= $site['pcu_ids'];
+$node_ids= $site['node_ids'];
+$person_ids= $site['person_ids'];
+$slice_ids= $site['slice_ids'];
+
+$api->begin();
+// gets address info
+$api->GetAddresses( $adress_ids );
+
+// gets pcu info
+$api->GetPCUs( $pcu_ids );
+
+// gets node info
+$api->GetNodes( $node_ids, array( "node_id", "hostname", "boot_state" ) );
+
+// gets person info
+$api->GetPersons( $person_ids, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" ) );
+
+$api->GetSlices ( $slice_ids, array ("slice_id", "name", "instantiation" ) );
+
+list( $addresses, $pcus, $nodes, $persons, $slices )= $api->commit();
+  
+$techs = array();
+$pis = array();
+foreach( $persons as $person ) {
+  $role_ids= $person['role_ids'];
+  if( in_array( '40', $role_ids ))
+    $techs[] = $person;
+  
+  if( in_array( '20', $role_ids ))
+    $pis[] = $person;
+  
+}
+
+// fetches peers and initialize hash peer_id->peer
+$peer_hash = plc_peer_global_hash ($api);
+// show gray background on foreign objects : start a <div> with proper class
+plc_peer_block_start ($peer_hash,$peer_id);
+
+drupal_set_title("Details for site " . $sitename);
+  
+// extra privileges to admins, and pi on this site
+$privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
+  
+$tabs=array();
+// available actions
+if ( ! $peer_id  && $privileges ) {
+  
+  $tabs['Update']=array('url'=>l_site_update($site_id));
+  // not avail to PI
+  $tabs['Expire slices'] = array('url'=>l_actions(),
+                                'values'=>array('site_id'=>$site_id,
+                                                'action'=>'expire-all-slices-in-site'),
+                                'bubble'=>"Expire all slices and prevent creation of new slices",
+                                'confirm'=>"Suspend all slices in $login_base");
+  if (plc_is_admin())
+    $tabs['Delete']=array('url'=>l_actions(),
+                         'values'=>array('site_id'=>$site_id,
+                                         'action'=>'delete-site'),
+                         'bubble'=>"Delete site $login_base",
+                         'confirm'=>"Are you sure you want to delete site $login_base");
+  $tabs["Events"]=array('url'=>l_event("Site","site",$site_id),
+                       'bubble'=>"Events for site $hostname");
+  $tabs["Comon"]=array('url'=>l_comon("site_id",$site_id),
+                      'buble'=>"Comon page for $hostname");
+
+  if (plc_is_admin()) 
+    $tabs['Pending'] = array ('url'=>l_sites_pending(),
+                             'bubble'=>'Review pending join requests');
+ }
+
+$tabs["All sites"]=l_sites();
+
+plc_tabs($tabs);
+
+if ( ! $enabled ) 
+  plc_warning ("This site is not enabled - Please visit " . 
+              href (l_sites_pending(),"this page") . 
+              " to review pending applications.");
+
+plc_details_start();
+plc_details_line("Peer",plc_peer_label($peer));
+plc_details_line("Full name",$sitename);
+plc_details_line("Login base",$login_base);
+plc_details_line("Abbreviated name",$abbrev_name);
+plc_details_line("URL",$site_url);
+plc_details_line("Latitude",$site_lat);
+plc_details_line("Longitude",$site_long);
+
+if ( ! $peer_id ) {
+
+  // Nodes
+  plc_details_space_line();
+  $nb_boot = 0;
+  if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++;
+  $node_text = $nb_boot . " boot / " .  count($nodes) . " total";
+  plc_details_line("# Nodes", href(l_nodes_site($site_id),$node_text));
+  function n_link ($n) { return l_node_t($n['node_id'],$n['hostname'] . " (" . $n['boot_state'] . ")");}
+  $nodes_text= plc_vertical_table(array_map ("n_link",$nodes));
+  plc_details_line ("hostnames",$nodes_text);
+                  
+  // Users
+  plc_details_space_line();
+  $user_text = count($person_ids) . " total / " .
+    count ($pis) . " PIs / " .
+    count ($techs) . " techs";
+  if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >=50)) 
+    $user_text = plc_warning_text ($user_text);
+  plc_details_line ("# Users",href(l_persons_site($site_id),$user_text));
+  function p_link ($p) { return l_person_t($p['person_id'],$p['email']); }
+  // PIs
+  $pi_text = plc_vertical_table (array_map ("p_link",$pis));
+  plc_details_line("PI's",$pi_text);
+  // PIs
+  $tech_text = plc_vertical_table (array_map ("p_link",$techs));
+  plc_details_line("techs's",$tech_text);
+
+  // Slices
+  plc_details_space_line();
+  // summary on # slices
+  $slice_text = count($slice_ids) . " running / " . $max_slices . " max";
+  if (count($slice_ids) >= $max_slices) $slice_text = plc_warning_text ($slice_text);
+  plc_details_line("# Slices", href(l_slices_site($site_id),$slice_text));
+  if ($slices) foreach ($slices as $slice)
+     plc_details_line($slice['instantiation'],l_slice_text($slice));
+
+
+ }
+
+plc_details_end();
+
+////////////////////////////////////////
+plc_peer_block_end();
+
+// Print footer
+include 'plc_footer.php';
+
+?>
diff --git a/planetlab/sites/sites.php b/planetlab/sites/sites.php
new file mode 100644 (file)
index 0000000..3a72f81
--- /dev/null
@@ -0,0 +1,140 @@
+<?php
+  // $Id: index.php 11750 2009-01-29 10:11:53Z thierry $
+  //
+
+  // 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';
+include 'plc_header.php';
+
+// Common functions
+require_once 'plc_functions.php';
+require_once 'plc_minitabs.php';
+require_once 'plc_tables.php';
+
+// -------------------- 
+// recognized URL arguments
+$peerscope=$_GET['peerscope'];
+$pattern=$_GET['pattern'];
+
+// --- decoration
+$title="Sites";
+$tabs=array();
+
+// -------------------- 
+$site_filter=array();
+
+function site_status ($site) {
+
+  $messages=array();
+  
+  if (empty ($site['node_ids'])) 
+    $messages [] = "No node";
+
+  $class=($site['peer_id']) ? 'plc-foreign' : 'plc-warning';
+
+  // do all this stuff on local sites only
+  if ( ! $site['peer_id'] ) {
+    
+    // check that site is enabled
+    if ( ! $site['enabled']) 
+      $messages [] = "Not enabled";
+  
+    // check that site has at least a PI and a tech
+    global $api;
+    $persons=$api->GetPersons(array("person_id"=>$site['person_ids']),array("role_ids"));
+    $nb_pis=0;
+    $nb_tech=0;
+    if ( $persons) foreach ($persons as $person) {
+       if (in_array( '20', $person['role_ids'])) $nb_pis += 1;
+       if (in_array( '40', $person['role_ids'])) $nb_techs += 1;
+      }
+    if ($nb_pis == 0) $messages [] = "No PI";
+    if ($nb_techs == 0) $messages [] = "No Tech";
+    
+    // check number of slices
+    if ( $site['max_slices'] == 0) {
+      $messages [] = "No slice allowed";
+    } else if (count($site["slice_ids"]) >= $site['max_slices']) {
+      $messages [] = "No slice left";
+    }
+  }
+
+  return plc_vertical_table ($messages,$class);
+}
+
+////////////////////
+// The set of columns to fetch
+// and the filter applied for fetching sites
+if ($pattern) {
+  $site_filter['login_base']=$pattern;
+  $title .= " with login_base matching " . $pattern;
+ } else {
+  $site_filter['login_base']="*";
+ }
+
+// server-side selection on peerscope
+list ( $peer_filter, $peer_label) = plc_peer_info($api,$_GET['peerscope']);
+$site_filter=array_merge($site_filter,$peer_filter);
+
+if (! plc_is_admin()) {
+  $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" );
+  $site_filter = array_merge ($site_filter, array ("enabled" => TRUE));
+ } else {
+  $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" , 
+                       "enabled", "person_ids", "max_slices", "slice_ids", "node_ids");
+ }
+
+$tabs['My site'] = array('url'=>l_site(plc_my_site_id()));
+$tabs['Local sites'] = array('url'=>l_sites_local());
+if (plc_is_admin()) 
+  $tabs['Pending'] = array ('url'=>l_sites_pending(),
+                           'bubble'=>'Review pending join requests');
+
+drupal_set_title($title);
+plc_tabs($tabs);
+
+// go
+$sites= $api->GetSites( $site_filter , $site_columns);
+
+$peer_hash = plc_peer_global_hash ($api);
+
+$headers['Peer']="string";
+$headers['Name']="string";
+$headers['Login_base']="string";
+$headers['Abbreviated']="string";
+if (plc_is_admin()) {
+  $headers['N']="int";
+  $headers['U']="int";
+  $headers['S']="int";
+  $headers['?']="string";
+ }
+
+plc_table_start("sites",$headers,3);
+if ($sites) foreach ($sites as $site) {
+  $shortname = plc_peer_shortname ($peer_hash,$site['peer_id']);
+  plc_table_row_start($site['login_base']);
+  plc_table_cell($shortname);
+  plc_table_cell (l_site_t($site['site_id'],$site['name']));
+  plc_table_cell ($site['login_base']);
+  plc_table_cell ($site['abbreviated_name']);
+  if (plc_is_admin()) {
+    plc_table_cell(count($site['node_ids']));
+    plc_table_cell(count($site['person_ids']));
+    plc_table_cell(count($site['slice_ids']));
+    plc_table_cell(site_status($site));
+  }
+  plc_table_row_end();
+}
+plc_table_end("sites");
+
+// Print footer
+include 'plc_footer.php';
+
+?>