split in two
[plewww.git] / planetlab / sites / site.php
index c4d64dc..b56e62e 100644 (file)
@@ -16,10 +16,11 @@ 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';
-require_once 'plc_forms.php';
+require_once 'linetabs.php';
+require_once 'table.php';
+require_once 'details.php';
+require_once 'form.php';
+require_once 'toggle.php';
 
 // -------------------- 
 // recognized URL arguments
@@ -28,7 +29,7 @@ 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));
+$sites = $api->GetSites( array($site_id));
 
 if (empty($sites)) {
   drupal_set_message ("Site " . $site_id . " not found");
@@ -38,7 +39,7 @@ if (empty($sites)) {
 $site=$sites[0];
 // var names to api return
 $sitename= htmlentities($site['name']);
-$abbrev_name= htmlentities($site['abbreviated_name']);
+$abbreviated_name= htmlentities($site['abbreviated_name']);
 $site_url= $site['url'];
 $login_base= $site['login_base'];
 $site_lat= $site['latitude'];
@@ -51,11 +52,11 @@ $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
+// get peer 
 $peer_id= $site['peer_id'];
 $peers = new Peers ($api);
 
-$adress_ids= $site['address_ids'];
+$address_ids= $site['address_ids'];
 $pcu_ids= $site['pcu_ids'];
 $node_ids= $site['node_ids'];
 $person_ids= $site['person_ids'];
@@ -63,7 +64,7 @@ $slice_ids= $site['slice_ids'];
 
 $api->begin();
 // gets address info
-$api->GetAddresses( $adress_ids );
+$api->GetAddresses( $address_ids );
 
 // gets pcu info
 // GetPCUs is not accessible to the 'user' role
@@ -82,16 +83,18 @@ 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;
   
 }
 
+$has_disabled_persons = count ($disabled_persons) !=0;
+
 drupal_set_title("Details for site " . $sitename);
 $local_peer = ! $peer_id;
   
@@ -99,12 +102,12 @@ $local_peer = ! $peer_id;
 $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
   
 $tabs=array();
+
+$tabs []= tab_sites_local();
+
 // available actions
 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,
@@ -118,10 +121,10 @@ if ( $local_peer  && $privileges ) {
                                          'action'=>'delete-site'),
                          'bubble'=>"Delete site $sitename",
                          'confirm'=>"Are you sure you want to delete site $login_base");
-  $tabs["Events"]=array_merge (tabs_events(),
+  $tabs["Events"]=array_merge (tablook_event(),
                               array('url'=>l_event("Site","site",$site_id),
                                     'bubble'=>"Events for site $sitename"));
-  $tabs["Comon"]=array_merge(tabs_comon(),
+  $tabs["Comon"]=array_merge(tablook_comon(),
                             array('url'=>l_comon("site_id",$site_id),
                                   'bubble'=>"Comon page for $sitename"));
 
@@ -130,8 +133,6 @@ if ( $local_peer  && $privileges ) {
                              'bubble'=>'Review pending join requests');
  }
 
-$tabs["All sites"]=l_sites();
-
 plc_tabs($tabs);
 
 // show gray background on foreign objects : start a <div> with proper class
@@ -142,61 +143,145 @@ if ( ! $enabled )
               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",$peers->peer_link($peer_id));
+$can_update=(plc_is_admin ()  && $local_peer) || ( 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->form_start(l_actions(),array('action'=>'update-site','site_id'=>$site_id));
+$details->th_td("Full name",$sitename,'name',array('width'=>50));
+$details->th_td("Abbreviated name",$abbreviated_name,'abbreviated_name',array('width'=>15));
+$details->th_td("URL",$site_url,'url',array('width'=>40));
+$details->th_td("Latitude",$site_lat,'latitude');
+$details->th_td("Longitude",$site_long,'longitude');
+
+// modifiable by admins only
+if (plc_is_admin()) 
+  $details->th_td("Login base",$login_base,'login_base',array('width'=>12));
+else
+  $details->th_td("Login base",$login_base);
+if (plc_is_admin())
+  $details->th_td("Max slices",$max_slices,'max_slices');
+else
+  $details->th_td("Max slices",$max_slices);
+$details->tr_submit("submit","Update Site");
+$details->form_end();
+
+if ( ! $local_peer) {
+  $details->space();
+  $details->th_td("Peer",$peers->peer_link($peer_id));
+ }
+$details->end();
 
+//////////////////// mode details - for local object
 if ( $local_peer ) {
 
-  // Nodes
-  plc_details_space_line();
+  //////////////////// nodes
+  // xxx missing : would need to add columns on attached PCU name and port if avail
   $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));
 
+  $nodes_title = "# Nodes : ";
+  $nodes_title .= count($nodes) . " total";
+  $nodes_title .= " / " . $nb_boot . " boot";
+  if ($nb_boot < 2 ) 
+    $nodes_title = plc_warning_html ($nodes_title);
+  $nodes_title .= href(l_nodes_site($site_id)," (See as nodes)");
+
+  $toggle=new PlcToggle ('nodes',$nodes_title,array('trigger-tagname'=>'h2'));
+  $toggle->start();
+
+  $headers=array();
+  $headers['hostname']='string';
+  $headers['state']='string';
+
+  $table = new PlcTable ('nodes',$headers,'0',array('search_area'=>false,
+                                                   'notes_area'=>false,
+                                                   'pagesize_area'=>false));
+  $table->start();
+  foreach ($nodes as $node) {
+    $table->row_start();
+    $table->cell (l_node_obj($node));
+    $table->cell ($node['boot_state']);
+    $table->row_end();
+  }
+  $table->tfoot_start();
+  $table->row_start();
+  $button=new PlcFormButton (l_node_add(),"node_add","Add node","POST");
+  $table->cell($button->html(),$table->columns(),"right");
+  $table->row_end();
+  $table->end();
+  $toggle->end();
+    
+  //////////////////// Users
+  $persons_title = "# Users : ";
+  $persons_title .= count($person_ids) . " total";
+  $persons_title .= " / " . count ($pis) . " PIs";
+  $persons_title .= " / " . count ($techs) . " Techs";
+  if ($has_disabled_persons) 
+    $persons_title .= " / " . ($disabled_persons) . " Disabled";
+  if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >= 30) || count($disabled_persons) != 0 ) 
+    $persons_title = plc_warning_html ($persons_title);
+  $persons_title .= href(l_persons_site($site_id)," (See as users)");
+
+  $toggle=new PlcToggle ('persons',$persons_title,array('trigger-tagname'=>'h2'));
+  $toggle->start();
+
+  $headers = array ();
+  $headers["email"]='string';
+  $headers["PI"]='string';
+  $headers['User']='string';
+  $headers["Tech"]='string';
+  if ($has_disabled_persons) $headers["Disabled"]='string';
+  $table=new PlcTable('persons',$headers,'1r-3r-0',array('search_area'=>false,
+                                                        'notes_area'=>false,
+                                                        'pagesize_area'=>false));
+  $table->start();
+  foreach ($persons as $person) {
+    $table->row_start();
+    $table->cell(l_person_obj($person));
+    $table->cell( in_array ('20',$person['role_ids']) ? "yes" : "no");
+    $table->cell( in_array ('30',$person['role_ids']) ? "yes" : "no");
+    $table->cell( in_array ('40',$person['role_ids']) ? "yes" : "no");
+    if ($has_disabled_persons) $table->cell( $person['enabled'] ? "no" : "yes");
+    $table->row_end();
+  }
+  $table->end();
+  $toggle->end();
+
+  //////////////////// Slices
+  // xxx to review after slices gets reworked
+  $toggle=new PlcToggle ('slices',"Slices",array('trigger-tagname'=>'h2'));
+  $toggle->start();
+  $details=new PlcDetails (false);
+  $details->start();
+  // 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->th_td("# Slices", href(l_slices_site($site_id),$slice_label));
+  if ($slices) foreach ($slices as $slice)
+     $details->th_td($slice['instantiation'],l_slice_obj($slice));
+  $button=new PlcFormButton (l_slice_add(),"slice_add","Add slice","POST");
+  $details->tr($button->html(),"right");
+  $details->end();
+  $toggle->end();
 
   // Addresses
-  if ($addresses) {
-    plc_details_space_line();
-    plc_details_line("Addresses","");
+  $toggle=new PlcToggle ('addresses',"Addresses",array('trigger-tagname'=>'h2',
+                                                      'start-visible'=>false));
+  $toggle->start();
+  if ( ! $addresses) {
+    print "No known address for this site";
+  } else {
+    $details=new PlcDetails (false);
+    $details->start();
+    $details->th_td("Addresses","");
     foreach ($addresses as $address) {
-      plc_details_line(plc_vertical_table($address['address_types']),
+      $details->th_td(plc_vertical_table($address['address_types']),
                       plc_vertical_table(array($address['line1'],
                                                $address['line2'],
                                                $address['line3'],
@@ -205,15 +290,17 @@ if ( $local_peer ) {
                                                $address['postalcode'],
                                                $address['country'])));
     }
+    $details->end();
   }
+  $toggle->end();
 
  }
 
-plc_details_end();
-
 ////////////////////////////////////////
 $peers->block_end($peer_id);
 
+//plc_tabs ($tabs,"bottom");
+
 // Print footer
 include 'plc_footer.php';