redirects
[plewww.git] / planetlab / sites / site.php
index 822ed4c..c4d64dc 100644 (file)
@@ -15,6 +15,7 @@ include 'plc_header.php';
 
 // Common functions
 require_once 'plc_functions.php';
+require_once 'plc_peers.php';
 require_once 'plc_minitabs.php';
 require_once 'plc_tables.php';
 require_once 'plc_details.php';
@@ -36,8 +37,8 @@ if (empty($sites)) {
 
 $site=$sites[0];
 // var names to api return
-$sitename= $site['name'];
-$abbrev_name= $site['abbreviated_name'];
+$sitename= htmlentities($site['name']);
+$abbrev_name= htmlentities($site['abbreviated_name']);
 $site_url= $site['url'];
 $login_base= $site['login_base'];
 $site_lat= $site['latitude'];
@@ -47,12 +48,12 @@ $max_slices= $site['max_slices'];
 
 $enabled = $site['enabled'];
 
+// extra privileges to admins, and (pi||tech) on this site
+$privileges = plc_is_admin () || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
+  
 // get peer details
 $peer_id= $site['peer_id'];
-if ($peer_id) {
-  $peers=$api->GetPeers(array("peer_id"=>$peer_id));
-  $peer=$peers[0];
- }
+$peers = new Peers ($api);
 
 $adress_ids= $site['address_ids'];
 $pcu_ids= $site['pcu_ids'];
@@ -65,7 +66,8 @@ $api->begin();
 $api->GetAddresses( $adress_ids );
 
 // gets pcu info
-$api->GetPCUs( $pcu_ids );
+// GetPCUs is not accessible to the 'user' role
+//$api->GetPCUs( $pcu_ids );
 
 // gets node info
 $api->GetNodes( $node_ids, array( "node_id", "hostname", "boot_state" ) );
@@ -75,7 +77,8 @@ $api->GetPersons( $person_ids, array( "role_ids", "person_id", "first_name", "la
 
 $api->GetSlices ( $slice_ids, array ("slice_id", "name", "instantiation" ) );
 
-list( $addresses, $pcus, $nodes, $persons, $slices )= $api->commit();
+//list( $addresses, $pcus, $nodes, $persons, $slices )= $api->commit();
+list( $addresses, $nodes, $persons, $slices )= $api->commit();
   
 $techs = array();
 $pis = array();
@@ -89,37 +92,38 @@ foreach( $persons as $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);
+$local_peer = ! $peer_id;
   
 // 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 ) {
+if ( $local_peer  && $privileges ) {
   
-  $tabs['Update']=array('url'=>l_site_update($site_id));
+  $tabs['Update']=array('url'=>l_site_update($site_id),
+                       'bubble'=>"Update details of $sitename");
   // not avail to PI
   $tabs['Expire slices'] = array('url'=>l_actions(),
+                                'method'=>'POST',
                                 '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(),
+                         'method'=>'POST',
                          'values'=>array('site_id'=>$site_id,
                                          'action'=>'delete-site'),
-                         'bubble'=>"Delete site $login_base",
+                         'bubble'=>"Delete site $sitename",
                          '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");
+  $tabs["Events"]=array_merge (tabs_events(),
+                              array('url'=>l_event("Site","site",$site_id),
+                                    'bubble'=>"Events for site $sitename"));
+  $tabs["Comon"]=array_merge(tabs_comon(),
+                            array('url'=>l_comon("site_id",$site_id),
+                                  'bubble'=>"Comon page for $sitename"));
 
   if (plc_is_admin()) 
     $tabs['Pending'] = array ('url'=>l_sites_pending(),
@@ -130,21 +134,24 @@ $tabs["All sites"]=l_sites();
 
 plc_tabs($tabs);
 
+// show gray background on foreign objects : start a <div> with proper class
+$peers->block_start ($peer_id);
+
 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);
+plc_details_line("Peer",$peers->peer_link($peer_id));
 
-if ( ! $peer_id ) {
+if ( $local_peer ) {
 
   // Nodes
   plc_details_space_line();
@@ -156,6 +163,7 @@ if ( ! $peer_id ) {
   $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 / " .
@@ -172,6 +180,7 @@ if ( ! $peer_id ) {
   $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
@@ -182,12 +191,28 @@ if ( ! $peer_id ) {
      plc_details_line($slice['instantiation'],l_slice_text($slice));
 
 
+  // Addresses
+  if ($addresses) {
+    plc_details_space_line();
+    plc_details_line("Addresses","");
+    foreach ($addresses as $address) {
+      plc_details_line(plc_vertical_table($address['address_types']),
+                      plc_vertical_table(array($address['line1'],
+                                               $address['line2'],
+                                               $address['line3'],
+                                               $address['city'],
+                                               $address['state'],
+                                               $address['postalcode'],
+                                               $address['country'])));
+    }
+  }
+
  }
 
 plc_details_end();
 
 ////////////////////////////////////////
-plc_peer_block_end();
+$peers->block_end($peer_id);
 
 // Print footer
 include 'plc_footer.php';