not sure why this was missing
[plewww.git] / planetlab / includes / plc_functions.php
index d5de8a5..b1ce672 100644 (file)
@@ -19,6 +19,10 @@ function plc_is_pi () {
   global $plc;
   return in_array( 20, $plc->person['role_ids']);
 }
+function plc_is_user () {
+  global $plc;
+  return in_array( 30, $plc->person['role_ids']);
+}
 function plc_is_tech () {
   global $plc;
   return in_array( 40, $plc->person['role_ids']);
@@ -28,11 +32,24 @@ function plc_in_site ($site_id) {
   return in_array( $site_id, $plc->person['site_ids']);
 }
 
+function plc_my_site_ids () {
+  global $plc;
+  return $plc->person['site_ids'];
+}
+function plc_my_sites () {
+  global $plc;
+  global $api;
+  return $api->GetSites($plc->person['site_ids'], array('site_id', 'abbreviated_name'));
+}
+
 function plc_my_site_id () {
   global $plc;
   return $plc->person['site_ids'][0];
 }
 
+function plc_my_person () {
+  return $plc->person;
+}
 function plc_my_person_id () {
   global $plc;
   return $plc->person['person_id'];
@@ -50,6 +67,9 @@ function href ($url,$text) { return "<a href='" . $url . "'>" . $text . "</a>";
 function l_actions ()                  { return "/db/common/actions.php"; }
 // some complex node actions are kept separate, e.g. the ones related to getbootmedium
 function l_actions_download ()         { return "/db/nodes/node_downloads.php"; }
+function l_register_node ()            { return "/registerwizard/index.php"; }
+function l_pcu_add ()                  { return "/registerwizard/index.php/register/stage1_addpcu"; }
+function l_pcu ($pcu_id)               { return "/db/sites/pcu.php?id=$pcu_id"; }
 
 function l_nodes ()                    { return "/db/nodes/index.php"; }
 function l_nodes_peer ($peer_id)       { return "/db/nodes/index.php?peerscope=$peer_id"; }
@@ -58,9 +78,13 @@ function l_node_t ($node_id,$text)   { return href (l_node($node_id),$text); }
 function l_node_obj($node)             { return href(l_node($node['node_id']),$node['hostname']); }
 function l_node_add ()                 { return "/db/nodes/node_add.php"; }
 function l_nodes_site ($site_id)       { return "/db/nodes/index.php?site_id=$site_id"; }
+function l_nodes_my_site ()             { return l_nodes_site(plc_my_site_id()) . "&active_line_tab=My site nodes"; }
+function l_nodes_all_my_site ()         { return l_nodes_person(plc_my_person_id()) . "&active_line_tab=All My site nodes"; }
+function l_nodes_person ($person_id)   { return "/db/nodes/index.php?person_id=$person_id"; }
 function l_nodes_slice ($slice_id)     { return "/db/nodes/index.php?slice_id=$slice_id"; }
 
 function l_interface ($interface_id)   { return "/db/nodes/interface.php?id=$interface_id"; }
+function l_interface_tags($interface_id){ return "/db/nodes/interface.php?id=$interface_id&show_details=0&show_tags=1"; }
 function l_interface_t ($interface_id,$text) { 
                                          return href (l_interface($interface_id),$text); }
 function l_interface_add($node_id)     { return "/db/nodes/interface.php?node_id=$node_id"; }
@@ -77,6 +101,8 @@ 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/slice_add.php"; }
 function l_slices_site($site_id)       { return "/db/slices/index.php?site_id=$site_id"; }
+function l_slices_my_site()            { return l_slices_site(plc_my_site_id()) . "&active_line_tab=My site slices"; }
+function l_slices_person($person_id)    { return "/db/slices/index.php?person_id=$person_id"; }
 function l_slices_local()              { return "/db/slices/index.php?peerscope=local"; }
 // from an object
 function l_slice_obj ($slice)          { return l_slice_t ($slice['slice_id'],$slice['name']); }
@@ -85,11 +111,12 @@ function l_sliver ($node_id,$slice_id)     { return "/db/nodes/slivers.php?node_id=$
 function l_sliver_t ($node_id,$slice_id,$text) { 
                                          return href (l_sliver($node_id,$slice_id),$text) ; }
 
-function l_persons ()                  { return "/db/persons/index.php"; }
-function l_persons_peer ($peer_id)     { return "/db/persons/index.php?peerscope=$peer_id"; }
+function l_persons ()                  { return "/db/persons/index.php&active_line_tab=All Accounts"; }
+function l_persons_peer ($peer_id)     { return "/db/persons/index.php?peerscope=$peer_id&active_line_tab=Local Accounts"; }
 function l_person ($person_id)         { return "/db/persons/index.php?id=$person_id"; }
 function l_person_t ($person_id,$text) { return href (l_person($person_id),$text); }
 function l_persons_site ($site_id)     { return "/db/persons/index.php?site_id=$site_id"; }
+function l_persons_slice ($slice_id)   { return "/db/persons/index.php?slice_id=$slice_id"; }
 function l_person_obj ($person)                { return l_person_t($person['person_id'],$person['email']); }
 
 function l_tags ()                     { return "/db/tags/index.php"; }
@@ -128,13 +155,15 @@ function l_sites_pending()                { return "/db/sites/join_request.php"; }
 function tab_nodes ()          { return array ('label'=>'All nodes','url'=>l_nodes(), 
                                                'bubble'=>'Display nodes from all peers'); }
 function tab_nodes_local ()    { return array ('label'=>'Local nodes', 'url'=>l_nodes_peer('local'), 
-                                               'bubble'=>'Display local nodes only'); }
+                                               'bubble'=>'Display all nodes local to this peer'); }
 function tab_nodes_site($site_id){ return array ('label'=>'Site nodes', 'url'=>l_nodes_site($site_id), 
                                                 'bubble'=>'Display nodes on that site'); }
 function tab_nodes_slice($slice_id){ return array ('label'=>'Slice nodes', 'url'=>l_nodes_slice($slice_id), 
                                                 'bubble'=>'Display nodes for that slice'); }
-function tab_nodes_mysite ()   { return array ('label'=>'My nodes', 'url'=>l_nodes_site(plc_my_site_id()), 
+function tab_nodes_mysite ()   { return array ('label'=>'My site nodes', 'url'=>l_nodes_my_site(), 
                                                'bubble'=>'Display nodes on my site'); }
+function tab_nodes_all_mysite (){ return array ('label'=>'All My site nodes', 'url'=>l_nodes_all_my_site(),
+                                               'bubble'=>'Display nodes on all my sites'); }
 function tab_node($node)       { return array ('label'=>'Node '.$node['hostname'], 'url'=>l_node($node['node_id']),
                                                'bubble'=>'Details for ' . $node['hostname']); }
 //////////
@@ -144,24 +173,24 @@ function tab_mysite()             { return array ('label'=>'My site', 'url'=>l_site(plc_my_
                                                'bubble'=>'Details for site ' . plc_my_site_id()); }
 function tab_sites ()          { return array ('label'=>'All sites' , 'url'=>l_sites(), 'bubble'=> 'Display all sites'); }
 function tab_sites_local ()    { return array ('label'=>'Local sites' , 'url'=>l_sites_peer('local'), 
-                                               'bubble'=> 'Display local sites'); }
+                                               'bubble'=> 'Display all siteslocal to this peer'); }
 //////////
 function tab_slices()          { return array ('label'=>'All slices', 'url'=>l_slices(),
                                                'bubble' => 'Display all slices'); }
-function tab_slices_mysite ()  { return array ('label'=>'My site slices', 'url'=>l_slices_site(plc_my_site_id()), 
-                                               'bubble'=>'Display all slices on my site'); }
-function tab_slices_mine ()    { return array ('label'=>'My site slices', 'url'=>l_slices_site(plc_my_site_id()), 
+function tab_slices_person()   { return array ('label'=>'My slices', 'url'=>l_slices_person(plc_my_person_id()),
+                                               'bubble' => 'Display my all slices'); }
+function tab_slices_mysite ()  { return array ('label'=>'My site slices', 'url'=>l_slices_my_site(), 
                                                'bubble'=>'Display all slices on my site'); }
 function tab_slices_local ()   { return array ('label'=>'Local slices', 'url'=>l_slices_local(), 
-                                               'bubble'=>'Display all slices on my site'); }
+                                               'bubble'=>'Display all slices local to this peer'); }
 function tab_slice($slice)     { return array ('label'=>'Slice '.$slice['name'], 'url'=>l_slice($slice['slice_id']),
                                                'bubble' => 'Details for ' . $slice['name']); }
 //////////
-function tab_persons()         { return array ('label'=>'All accounts', 'url'=>l_persons(),
+function tab_persons()         { return array ('label'=>'All Accounts', 'url'=>l_persons(),
                                                'bubble'=>'Display users from all peers'); }
-function tab_persons_local()   { return array ('label'=>'Local accounts', 'url'=>l_persons_peer('local'),
-                                               'bubble'=>'Display local users'); }
-function tab_persons_mysite()  { return array ('label'=>'My accounts' , 'url'=>l_persons_site(plc_my_site_id()),
+function tab_persons_local()   { return array ('label'=>'Local Accounts', 'url'=>l_persons_peer('local'),
+                                               'bubble'=>'Display all users local to this peer'); }
+function tab_persons_mysite()  { return array ('label'=>'My site accounts' , 'url'=>l_persons_site(plc_my_site_id()),
                                                'bubble'=>'Display accounts on site ' . plc_my_site_id()); }
 function tab_person($person)   { return array ('label'=>'Account '.$person['email'], 'url'=>l_person($person['person_id']),
                                                'bubble'=>'Details for ' . $person['email']); }
@@ -291,7 +320,6 @@ function t_person ($person) { return " belonging to " . $person['email'] . " ("
 
 //////////////////////////////////////////////////////////// html fragments
 function plc_vertical_table ($messages, $class="") {
-  // pretty print the cell
   if ( empty( $messages) ) return "";
   $formatted = "";
   $formatted .= "<table";
@@ -303,12 +331,24 @@ function plc_vertical_table ($messages, $class="") {
   $formatted .= "</table>";
   return $formatted;
 }
-
-function plc_error ($text) {
-  // should use the same channel as the php errors..
-  print "<div class='plc-error'> Error " . $text . "</div>";
+function plc_itemize ($messages, $class="") {
+  if ( empty( $messages) ) return "";
+  $formatted = "";
+  $formatted .= "<ul";
+  if ($class) $formatted .= " class='" . $class . "'";
+  $formatted .= ">";
+  foreach ($messages as $message) {
+    $formatted .= "<li>" . $message . "</li>";
+  }
+  $formatted .= "</ul>";
+  return $formatted;
 }
 
+//////////
+// should use the same channel as the php errors..
+function plc_error_html ($text)                { return  "<div class='plc-error'> " . $text . "</div>"; }
+function plc_error ($text)             { print plc_error_html ("Error " . $text); }
+
 function plc_errors ($errors) {
   if ($errors) {
     print( "<div class='plc-error'>" );
@@ -322,7 +362,8 @@ function plc_errors ($errors) {
 
 function plc_warning_html ($text)      { return "<span class='plc-warning'>" . $text . "</span>";}
 function plc_warning ($text)           { print plc_warning_html("Warning " . $text); }
-function plc_foreign_html($text)       { return "<span class=plc-foreign>$text</span>"; }
+
+function bold_html ($text)             { return "<span class='bold'>$text</span>"; }
 
 // shows a php variable verbatim with a heading message
 function plc_debug ($message,$object) {
@@ -358,6 +399,10 @@ function plc_delete_icon($width=15) {
   return "<img width='$width' src='/planetlab/icons/delete.png'>";
 }
 
+function plc_add_icon($width=15) {
+  return "<img width='$width' src='/planetlab/icons/add.png'>";
+}
+
 function plc_bubble($text,$bubble) {
   return "<span title='$bubble'>$text</span>";
 }
@@ -385,4 +430,59 @@ function plc_redirect ($url) {
   exit ();
 }
 
+//////////////////// the options for an interface - suitable for plekit/form
+//>>> GetNetworkMethods()
+//[u'static', u'dhcp', u'proxy', u'tap', u'ipmi', u'unknown']
+function interface_method_selectors ($api, $method, $primary) {
+  if ($primary) {
+    $builtin_methods=array("static"=>"Static",
+                          "dhcp"=>"DHCP");
+  } else {
+    $builtin_methods=array("static"=>"Static",
+                          "dhcp"=>"DHCP", 
+                          "proxy"=>"Proxy",  
+                          "tap"=>"TUN/TAP",
+                          "ipmi"=>"IPMI");
+  }
+  $selectors=array();
+  foreach ($builtin_methods as $value=>$display) {
+    $selector=array('display'=>$display, 'value'=>$value);
+    if ($value == $method) $selector['selected']=true;
+    $selectors []= $selector;
+  }
+  return $selectors;
+}
+
+//////////////////// 
+function instantiation_label ($slice) {
+  $instantiation_labels = array ('not-instantiated'=>'NOT',
+                                'plc-instantiated'=>'PLC',
+                                'delegated' => 'DEL',
+                                'nm-controller' => 'NM');
+  $result=$instantiation_labels[$slice['instantiation']];
+  if (!$result) $result = $slice['instantiation'];
+  if (!$result) $result = '??';
+  return $result;
+}
+  
+//////////////////// toggle areas
+// get_arg ('show_persons',false) returns $_GET['show_persons'] if set and false otherwise
+function get_arg ($name,$default,$method='get') {
+  if ($method == 'get') $var=$_GET; else $var=$_POST;
+  if (isset ($var[$name])) return $var[$name];
+  else return $default;
+}
+
+//////////////////// number of ...
+function count_english ($objs,$name) {
+  $count=count($objs);
+  if ($count == 0) return 'No ' . $name;
+  else if ($count == 1) return 'One ' . $name;
+  else return $count . ' ' . $name . 's';
+}
+function count_english_warning ($objs, $name) {
+  $x=count_english ($objs,$name);
+  if (count ($objs) == 0) $x=plc_warning_html($x . ' !!');
+  return $x;
+}
 ?>