more inline updates & cleaned up tags
[plewww.git] / planetlab / sites / site.php
index cdce78e..eac14ef 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']);
+$abbreviated_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,44 +77,40 @@ $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();
+$disabled_persons = 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 ( in_array( '20', $role_ids ))    $pis[] = $person;
+  if ( in_array( '40', $role_ids ))    $techs[] = $person;
+  if ( ! $person['enabled'] )          $disabled_persons[] = $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),
-                       '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 $sitename",
@@ -133,80 +131,107 @@ $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("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",plc_peer_label($peer));
-
-if ( ! $peer_id ) {
-
-  // 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($address['line1'],
-                                         $address['line2'],
-                                         $address['line3'],
-                                         $address['city'],
-                                         $address['state'],
-                                         $address['postalcode'],
-                                         $address['country']));
-    }
-  }
+$can_update=plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
+$details = new PlcDetails($can_update);
+
+if ( ! $site['is_public']) 
+  plc_warning("This site is not public!");
+
+$details->start();
+$details->line("Peer",$peers->peer_link($peer_id));
+$details->space();
+
+$details->form_start(l_actions(),array('action'=>'update-site','site_id'=>$site_id));
+$save_w=$details->set_field_width(30);
+$details->line("Full name",$sitename,'name');
+$details->set_field_width($save_w);
+$details->line("Abbreviated name",$abbreviated_name,'abbreviated_name');
+$details->line("URL",$site_url,'url');
+$details->line("Latitude",$site_lat,'latitude');
+$details->line("Longitude",$site_long,'longitude');
+if (plc_is_admin()) 
+  $details->line("Login base",$login_base,'login_base');
+else
+  $details->line("Login base",$login_base);
+if (plc_is_admin())
+  $details->line("Max slices",$max_slices,'max_slices');
+else
+  $details->line("Max slices",$max_slices);
+$details->line("",$details->submit_html("submit","Update Site"));
+$details->form_end();
+
+if ( $local_peer ) {
 
   // Nodes
-  plc_details_space_line();
+  $details->space();
   $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));
+  $node_label = $nb_boot . " boot / " .  count($nodes) . " total";
+  $details->line("# Nodes", href(l_nodes_site($site_id),$node_label));
   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);
-                  
+  $nodes_label= plc_vertical_table(array_map ("n_link",$nodes));
+  $details->line ("Hostnames",$nodes_label);
+  $button=new PlcFormButton (l_node_add(),"add_node","Add node","POST");
+  $details->line("",$button->html());
+
   // Users
-  plc_details_space_line();
-  $user_text = count($person_ids) . " total / " .
+  $details->space();
+  $user_label = count($person_ids) . " Total / " .
     count ($pis) . " PIs / " .
-    count ($techs) . " techs";
+    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));
+    $user_label = plc_warning_html ($user_label);
+  $details->line ("# Users",href(l_persons_site($site_id),$user_label));
   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);
+  $details->line("PI's",plc_vertical_table (array_map ("p_link",$pis)));
+  // techs
+  $details->line("Techs's",plc_vertical_table (array_map ("p_link",$techs)));
+  if (count ($disabled_persons)) 
+    $details->line("Disabled",plc_vertical_table (array_map ("p_link",$disabled_persons)));
 
   // 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));
+  $details->space();
+  // summary on slices
+  $slice_label = count($slice_ids) . " running / " . $max_slices . " max";
+  if (count($slice_ids) >= $max_slices) 
+    $slice_label = plc_warning_html ($slice_label);
+  $details->line("# Slices", href(l_slices_site($site_id),$slice_label));
   if ($slices) foreach ($slices as $slice)
-     plc_details_line($slice['instantiation'],l_slice_text($slice));
+     $details->line($slice['instantiation'],l_slice_obj($slice));
+  $button=new PlcFormButton (l_slice_add(),"slice_add","Add slice","POST");
+  $details->line("",$button->html());
 
+  // Addresses
+  if ($addresses) {
+    $details->space();
+    $details->line("Addresses","");
+    foreach ($addresses as $address) {
+      $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();
+$details->end();
 
 ////////////////////////////////////////
-plc_peer_block_end();
+$peers->block_end($peer_id);
 
 // Print footer
 include 'plc_footer.php';