ckp
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 29 Jan 2009 16:41:07 +0000 (16:41 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 29 Jan 2009 16:41:07 +0000 (16:41 +0000)
14 files changed:
planetlab/actions.php [moved from planetlab/persons/person_actions.php with 71% similarity]
planetlab/includes/plc_details.php
planetlab/includes/plc_forms.php
planetlab/includes/plc_functions.php
planetlab/includes/plc_tables.php
planetlab/nodes/interfaces.php
planetlab/nodes/setting_action.php
planetlab/nodes/settings.php [deleted file]
planetlab/persons/person.php
planetlab/tags/index.php
planetlab/tags/tag_action.php
planetlab/tags/tag_form.php [new file with mode: 0644]
planetlab/tags/tag_set.php [new file with mode: 0644]
planetlab/tags/tags.php [new file with mode: 0644]

similarity index 71%
rename from planetlab/persons/person_actions.php
rename to planetlab/actions.php
index 1a2c82e..7e18dfd 100644 (file)
@@ -19,25 +19,29 @@ $known_actions=array();
 // (*) use POST 
 // (*) set 'action' to one of the following
 $known_actions []= "add-person-to-site";
-//       expects:      person_id & site_id
+//     expects:        person_id & site_id
 $known_actions []= "remove-person-from-sites";
-//       expects:      person_id & site_ids
+//     expects:        person_id & site_ids
 $known_actions []= "remove-roles-from-person";
-//       expects:      person_id & role_ids
+//     expects:        person_id & role_ids
 $known_actions []= "add-role-to-person";
-//       expects:      role_person_id & id
+//     expects:        role_person_id & id
 $known_actions []= "enable-person";
-//       expects:      person_id
+//     expects:        person_id
 $known_actions []= "disable-person";
-//       expects:      person_id
+//     expects:        person_id
 $known_actions []= "become-person";
-//       expects:      person_id
+//     expects:        person_id
 $known_actions []= "delete-person";
-//       expects:      person_id
+//     expects:        person_id
 $known_actions []= "delete-keys";
-//       expects:      key_ids & person_id (for redirecting to the person's page)
+//     expects:        key_ids & person_id (for redirecting to the person's page)
 $known_actions []= "upload-key";
-//       expects:      person_id & $_FILES['key']
+//     expects:        person_id & $_FILES['key']
+$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  
 
 //////////////////////////////
 // sometimes we don't set 'action', but use the submit button name instead
@@ -55,7 +59,7 @@ else
 $person_id = $_POST['person_id'];      // usually needed
 
 if ( ! $action ) {
-  drupal_set_message ("person_actions.php: action not set");
+  drupal_set_message ("actions.php: action not set");
   plc_debug('POST',$_POST);
   return;
  }
@@ -177,6 +181,50 @@ switch ($action) {
    exit();
  }
 
+ case 'update-tag-type': {
+  // get post vars 
+   $tag_type_id= intval( $_POST['tag_type_id'] );
+   $name = $_POST['name'];
+   $min_role_id= intval( $_POST['min_role_id'] );
+   $description= $_POST['description'];  
+   $category= $_POST['category'];  
+  
+   // make tag_type_fields dict
+   $tag_type_fields= array( "min_role_id" => $min_role_id, 
+                           "tagname" => $name, 
+                           "description" => $description,
+                           "category" => $category,
+                           );
+
+   // Update it!
+   $api->UpdateTagType( $tag_type_id, $tag_type_fields );
+   
+   header( "location: " . l_tag($tag_type_id));
+   exit();
+ }
+
+ case 'add-tag-type': {
+  // get post vars 
+   $name = $_POST['name'];
+   $min_role_id= intval( $_POST['min_role_id'] );
+   $description= $_POST['description'];  
+   $category= $_POST['category'];  
+  
+   // make tag_type_fields dict
+   $tag_type_fields= array( "min_role_id" => $min_role_id, 
+                           "tagname" => $name, 
+                           "description" => $description,
+                           "category" => $category,
+                           );
+
+  // Add it!
+   $id=$api->AddTagType( $tag_type_fields );
+   drupal_set_message ("tag type $id created");
+  
+   header( "location: " . l_tag($id));
+   exit();
+ }
+
  case 'debug': {
    plc_debug('GET',$_GET);
    plc_debug('POST',$_POST);
@@ -185,7 +233,7 @@ switch ($action) {
  }
 
  default: {
-   plc_error ("Unknown action $action in person_actions.php");
+   plc_error ("Unknown action $action in actions.php");
    return;
  }
 
index 5244e27..d28d1c7 100644 (file)
@@ -30,6 +30,15 @@ function plc_details_line_list($title,$list) {
   plc_details_line($title,plc_vertical_table($list,"foo"));
 }
 
+// same but the values are multiple and displayed in an embedded vertical table
+function plc_details_line1_text($title,$align=NULL) {
+  $result="<tr><td colspan=2";
+  if ($align) $result .= " style='text-align:$align'";
+  $result .=">$title</td></tr>";
+  return $result;
+}
+function plc_details_line1($title,$align) {print plc_details_line1_text($title,$align);}
+
 // a dummy line for getting some air
 function plc_details_space_line () {
   echo "<tr><td colspan=2>&nbsp;</td></tr>\n";
index 2197e13..15480dc 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-// $Id: plc_details.php 11645 2009-01-21 23:09:49Z thierry $
+// $Id$
 
 require_once 'plc_functions.php';
 
@@ -8,11 +8,17 @@ require_once 'plc_functions.php';
 // the first functions that we had were actually printing the stuff instead of returning it
 // so basically the foo (...) function should do ``print (foo_text(...))''
 
+function plc_form_hidden_text ($key,$value) {
+  return "<input type=hidden name='$key' value='$value'/>";  
+}
+function plc_form_hidden ($key,$value) { print plc_form_hidden_text($key,$value); }
+  
+// options unused so far
 function plc_form_start ($url, $values, $options=array()) {
   $method = array_key_exists('method',$options) ? $options['method'] : 'POST';
   print "<form method=$method action='$url' enctype='multipart/form-data'>";
   foreach ($values as $key=>$value) {
-    print "<input type=hidden name='$key' value='$value'>";
+    print plc_form_hidden_text($ke,$value);
   }
 }
 
@@ -22,20 +28,28 @@ function plc_form_end($options=array()) {
 
 function plc_form_checkbox_text ($name,$value,$selected=false) {
   if ($selected) $xtra=" selected=selected";
-  return "<input type=checkbox name='$name' value='$value'$xtra>";
+  return "<input type=checkbox name='$name' value='$value'$xtra/>";
 }
 
 function plc_form_submit_text ($name,$display) {
-  return "<input type=submit name='$name' value='$display'>";
+  return "<input type=submit name='$name' value='$display'/>";
 }
+function plc_form_submit ($name, $display) { print plc_form_submit_text($name,$display); }
   
 function plc_form_file_text ($name,$size) {
-  return "<input type=file name='$name' size=$size>";
+  return "<input type=file name='$name' size=$size/>";
 }
 
 function plc_form_label_text ($name,$display) {
   return "<label for=$name>$display </label>";
 }
+
+function plc_form_text_text ($name,$value,$size) {
+  return "<input type=text name='$name' size=$size value='$value'>";
+}
+function plc_form_textarea_text ($name,$value,$cols,$rows) {
+  return "<textarea name='$name' cols=$cols rows=$rows>$value</textarea>";
+}
  
 function plc_form_select_text ($name,$values,$label="") {
   $selector="";
@@ -45,10 +59,17 @@ function plc_form_select_text ($name,$values,$label="") {
   foreach ($values as $chunk) {
     $display=$chunk['display'];
     $value=$chunk['value'];
-    $selector .= "<option value='$value'>$display</option>\n";
+    $selector .= "<option value='$value'";
+    if ($chunk['selected']) $selector .= " selected=selected";
+    $selector .= ">$display</option>\n";
   }
   $selector .= "</select>";
   return $selector;
 }
 
+function plc_form_simple_button ($url,$text,$method="POST") {
+  $button=plc_form_submit_text("anonymous",$text);
+  return "<form method=$method action=$url>$button</form>";
+}
+
 ?>
index 7a8ac86..a25f747 100644 (file)
@@ -42,55 +42,55 @@ function href ($url,$text) { return "<a href='" . $url . "'>" . $text . "</a>";
 // l_object_t($object_id,text) -> an <a> tag that shows text and links to the above
 // l_object_add ()             -> the url to that object-afding page
 
+function l_actions ()                  { return "/db/actions.php"; }
+
 function l_nodes ()                    { return "/db/nodes/index.php"; }
-function l_node ($node_id)             { return "/db/nodes/node.php?id=" . $node_id; }
+function l_nodes_local ()              { return "/db/nodes/index.php?peerscope=local"; }
+function l_node ($node_id)             { return "/db/nodes/node.php?id=$node_id"; }
 function l_node_t ($node_id,$text)     { return href (l_node($node_id),$text); }
 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_site ($site_id)       { return "/db/nodes/index.php?site_id=$site_id"; }
 
-function l_interface ($interface_id)   { return "/db/nodes/interfaces.php?id=" . $interface_id; }
+function l_interface ($interface_id)   { return "/db/nodes/interfaces.php?id=$interface_id"; }
 function l_interface_t ($interface_id,$text) { 
                                          return href (l_interface($interface_id),$text); }
-function l_interface_add($node_id)     { return "/db/nodes/interfaces.php?node_id=" . $node_id; }
+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_site ($site_id)             { return "/db/sites/index.php?id=" . $site_id; }
+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_slices ()                   { return "/db/slices/index.php"; }
-function l_slice ($slice_id)           { return "/db/slices/index.php?id=" . $slice_id; }
+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_sliver ($node_id,$slice_id) { return "/db/nodes/slivers.php?node_id=" . $node_id. "&slice_id=" . $slice_id; }
+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) { 
                                          return href (l_sliver($node_id,$slice_id),$text) ; }
 
 function l_persons ()                  { return "/db/persons/index.php"; }
-function l_person ($person_id)         { return "/db/persons/index.php?id=" . $person_id; }
+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_person_actions()            { return "/db/persons/person_actions.php"; }
+function l_persons_site ($site_id)     { return "/db/persons/index.php?site_id=$site_id"; }
 
 function l_tags ()                     { return "/db/tags/index.php"; }
-function l_tags_node ()                        { return "/db/tags/index.php?type=node"; }
-# xxx cleanup duplicate pages
-#function l_tags_interface ()          { return "/db/tags/index.php?type=interface"; }
-function l_tags_interface ()           { return "/db/nodes/settings.php"; }
-function l_tags_slice ()               { return "/db/tags/index.php?type=slice"; }
+function l_tag ($tag_type_id)          { return "/db/tags/index.php"; }
+function l_tag_add()                   { return "/db/tags/tag_form.php"; }
+function l_tag_update($id)             { return "/db/tags/tag_form.php&action=update-tag-type&id=$id"; }
 
 function l_nodegroups ()               { return "/db/tags/node_groups.php"; }
-function l_nodegroup ($nodegroup_id)   { return "/db/tags/node_groups.php?id=" . $nodegroup_id; }
+function l_nodegroup ($nodegroup_id)   { return "/db/tags/node_groups.php?id=$nodegroup_id"; }
 function l_nodegroup_t ($nodegroup_id,$text) { 
                                          return href(l_nodegroup($nodegroup_id),$text); }
 
-function l_events ()                   { return '/db/events/index.php'; }
-function l_event ($type,$param,$id)    { return '/db/events/index.php?type=' . $type . '&' . $param . '=' . $id; }
+function l_events ()                   { return "/db/events/index.php"; }
+function l_event ($type,$param,$id)    { return "/db/events/index.php?type=$type&$param=$id"; }
 
 function l_peers()                     { return "/db/peers/index.php"; }
-function l_peer($peer_id)              { return "/db/peers/index.php?id=" . $peer_id; }
+function l_peer($peer_id)              { return "/db/peers/index.php?id=$peer_id"; }
 
-function l_comon($id_name,$id_value)   { return '/db/nodes/comon.php?' . $id_name . "=" . $id_value; }
+function l_comon($id_name,$id_value)   { return "/db/nodes/comon.php?$id_name=$id_value"; }
 function l_sirius()                    { return "/db/sirius/index.php"; }
 function l_about()                     { return "/db/about.php"; }
 function l_doc_plcapi()                        { return "/db/doc/PLCAPI.php"; }
@@ -185,6 +185,16 @@ function is_reserved_network_addr($network_addr) {
   return false;
 }
 
+////////////////////////////////////////////////////////////  peer & peerscopes
+function plc_role_global_hash ($api) {
+  $hash=array();
+  $roles=$api->GetRoles();
+  foreach ($roles as $role) {
+    $hash[$role['role_id']]=$role['name'];
+  }
+  return $hash;
+}
+  
 ////////////////////////////////////////////////////////////  peer & peerscopes
 // when shortnames are needed on peers
 function plc_peer_global_hash ($api) {
index 5b13810..ee3a5d2 100644 (file)
@@ -176,5 +176,14 @@ function plc_table_row_end () {
   print "</tr>\n";
 }
 
+function plc_table_td_text ($text,$colspan=0,$align=NULL) {
+  $result="";
+  $result .= "<td";
+  if ($colspan) $result .= " colspan=$colspan";
+  if ($align) $result .= " style='text-align:$align'";
+  $result .= ">$text</td>";
+  return $result;
+}
+
 ?>
 
index ab5e60e..9cbdca0 100644 (file)
@@ -195,6 +195,7 @@ print "<hr />";
 if (empty ($interface['interface_tag_ids'])) {
   print "<p> This network interface has no additional setting</p>";
   if( $is_admin || $is_pi )
+    // xxx check the destination page
     echo "<p><a href='settings.php?add=$id'>Add an Interface Setting</a></p>\n";
  } else {
   $interface_tags = $api->GetInterfaceTags($interface['interface_tag_ids']);
@@ -214,6 +215,7 @@ if (empty ($interface['interface_tag_ids'])) {
       echo("</td>");
     }
     if ($is_admin || $is_pi) 
+    // xxx check the destination page
       printf ("<td class='list_set'> <a href='settings.php?id=%s'>%s </a></td>",$setting['interface_tag_id'],$setting['tagname']);
     else
       printf ("<td class='list_set'> %s </td>",$setting['tagname']);
@@ -223,6 +225,7 @@ if (empty ($interface['interface_tag_ids'])) {
            $setting['value']);
   }
   if( $is_admin || $is_pi )
+    // xxx check the destination page
     echo "<tr><td colspan=4><a href='settings.php?add=$id'>Add a Network Setting</td</tr>\n";
   
   print "</tbody></table>";
index 498068d..8576a96 100644 (file)
@@ -9,13 +9,6 @@ require_once 'plc_login.php';
 require_once 'plc_session.php';
 global $plc, $api;
 
-/*
-// Print header
-require_once 'plc_drupal.php';
-drupal_set_title('Slices');
-include 'plc_header.php';
-*/
-
 // Common functions
 require_once 'plc_functions.php';
 require_once 'plc_sorts.php';
@@ -42,6 +35,7 @@ if( $_POST['edit_type'] ) {
     print "<div class='plc-error'>" . $api_error . "</div>";
   }
   
+  // xxx check the destination page
   header( "location: settings.php" );
   exit();
 }
@@ -55,6 +49,7 @@ if( $_POST['add_type'] ) {
   // add it!!
   $api->AddTagType( $setting_type );
 
+  // xxx check the destination page
   header( "location: settings.php" );
   exit();
 }
@@ -116,6 +111,7 @@ if( $_GET['del_type'] ) {
   // delete it!
   $api->DeleteTagType( $type_id );
   
+  // xxx check the destination page
   header( "location: settings.php" );
   exit();
 }
diff --git a/planetlab/nodes/settings.php b/planetlab/nodes/settings.php
deleted file mode 100644 (file)
index cf1d21a..0000000
+++ /dev/null
@@ -1,234 +0,0 @@
-<?php
-
-// $Id$
-
-// 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';
-drupal_set_title('Interface Setting Types');
-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'];
-
-//plc_debug("person", $_person );
-
-$tag_columns=array( "tag_type_id", "category", "tagname", "description", "min_role_id" );
-
-// prepare dict role_id => role_name
-global $roles;
-$roles= $api->GetRoles();
-global $roles_id_to_name;
-$roles_id_to_name=array();
-foreach ($roles as $role) {
-  $roles_id_to_name[$role['role_id']] = $role['name'];
-}
-
-// compute person's smallest role
-global $person_role;
-$person_role=50;
-foreach ($_person['role_ids'] as $role_id) {
-  if ($role_id < $person_role) {
-    $person_role=$role_id;
-  }
-}
-//plc_debug("person_role",$person_role);
-
-// post-process results from GetTagTypes
-// with planetlab 4.2, we've moved to php-5.2
-// with the former 5.0 reelase, I could invoke array_map 
-// with a function that took a reference and could do side-effects
-// Now I have to return the copy...
-// this new way of doing things might require more memory
-// on the other hand we should move to a schema where 
-// pagination is done in the API, so it's no big deal hopefully
-function layout_setting_type ($setting_type) {
-  // replace role_id with name
-  global $roles_id_to_name;
-  $setting_type['min_role']=$roles_id_to_name[$setting_type['min_role_id']];
-  return $setting_type;
-}
-
-// if no id, display list of tag types
-if( !$_GET['id'] && !$_GET['add'] && !$_GET['add_type'] && !$_GET['edit_type'] ) {
-  // get types
-  global $person_role;
-  $filter = array (']min_role_id'=>$person_role,'category'=>'interface*');
-  $setting_types= $api->GetTagTypes( $filter, $tag_columns );
-  $setting_types = array_map(layout_setting_type,$setting_types);
-  sort_interface_tags ($setting_types);
-  
-  // list them
-  
-  echo "<table cellpadding=2>";
-  echo "<thead><tr>";
-  // if admin we need one more cells for delete links
-  if(  in_array( "10", $_person['role_ids'] ) )
-    echo "<th></th>";
-  $role_header="<table><tr><th>min</th></tr><tr><th>Role</th></tr></table>";
-  echo "<th>Name</th>";
-  echo "<th>Category</th>";
-  echo "<th>" . $role_header . "</th>";
-  echo "<th>Id</th>";
-  echo "<th>Description</th>";
-  echo "</tr></thead>";
-  echo "<tbody>";
-
-  foreach( $setting_types as $type ) {
-    echo "<tr>";
-    // if admin display delete links
-    if(  in_array( "10", $_person['role_ids'] ) ) {
-      echo "<td>";
-      echo plc_delete_link_button('setting_action.php?del_type='. $type['tag_type_id'],
-                                 $type['tagname']);
-      echo "</td>";
-    }
-    // if admin, the name is a link to edition
-    if (in_array( "10", $_person['role_ids'])) {
-      echo "<td><a href='settings.php?edit_type=". $type['tag_type_id'] . "'>" . $type['tagname'] . "</a></td>";
-    } else {
-      echo "<td>" . $type['tagname'] . "</td>";
-    }
-    echo "<td>" . $type['category'] . "</td>";
-    echo "<td>" . $type['min_role'] . "</td><td>" . $type['min_role_id'] . "</td><td>" . $type['description'] . "</td>";
-    echo "</tr>\n";
-  }
-  
-  if( in_array( "10", $_person['role_ids'] ) )
-    echo "<tr><td colspan=6><a href='settings.php?add_type=true'>Add a Setting Type</td></tr>";
-
-  echo "</tbody></table>\n";
-  
-  
-  // back link o nodes
-  echo "<p><p><a href='/db/nodes/index.php'>Back to Nodes</a>\n";
-
-}
-elseif( $_GET['add_type'] || $_GET['edit_type'] ) {
-  // if its edit get the tag info
-  if( $_GET['edit_type'] ) {
-    $type_id= intval( $_GET['edit_type'] );
-    $type= $api->GetTagTypes( array( $type_id ) );
-    
-    $category=$type[0]['category'];
-    $name= $type[0]['tagname'];
-    $min_role_id= $type[0]['min_role_id'];
-    $description= $type[0]['description'];
-    
-  }
-  
-  // display form for setting types
-  echo "<form action='setting_action.php' method='post'>\n";
-  if ($_GET['edit_type']) {
-    drupal_set_title("Edit Setting Type");
-  } else {
-    drupal_set_title("Add Setting Type");
-  }
-  echo "<table cellpadding='5' cellspacing='5' border='0'>";
-  echo "<tr><th>Category:</th><td><input type=text name='category' size=20 value='$category'></td></tr>\n";
-  echo "<tr><th>Name:</th><td><input type=text name='name' size=20 value='$name'></td></tr>\n";
-  echo "<tr><th>Min Role:</th><td><select name='min_role_id'>\n";
-  global $roles;
-  foreach ($roles as $role) {
-    echo "<option value='" . $role['role_id'] . "'"; 
-    if( $min_role_id == intval($role['role_id']) ) echo " selected"; 
-    echo ">" . $role['name'] . "</option>\n";
-  }
-  echo "</select></td></tr>\n";
-  echo "<tr><th>Description:</th><td>";
-  echo "<textarea name='description' cols=50 rows=5>$description</textarea>\n";
-  echo "</td></tr>\n";
-  echo "<tr><td colspan=2 align=center>";
-  if( $_GET['edit_type'] ) {
-    echo "<input type=hidden name='tag_type_id' value='$type_id'>\n";
-    echo "<input type=submit name='edit_type' value='Edit Setting Type'>\n";
-  } else {
-    echo "<input type=submit name='add_type' value='Add Interface Type'>\n";
-  }
-  echo "</td></tr>";
-  echo "</table>";
-
-  echo "</form>\n";
-
-  echo "<p><a href='/db/nodes/settings.php'>Back to Setting Types</a>\n";
-}
-elseif( $_GET['add'] ) {
-
-  // get interface id from GET
-  $interface_id= intval( $_GET['add'] );
-  
-  // get all setting types 
-  global $person_role;
-  $filter = array (']min_role_id'=>$person_role,'category'=>'interface*');
-  $setting_types= $api->GetTagTypes( $filter, array( "tag_type_id", "tagname" , "category") );
-  sort_interface_tags($setting_types);
-    
-  // get interface's settings
-  $interface = $api->GetInterfaces( array( $interface_id ), array( "interface_tag_ids","ip" ) );
-  
-  drupal_set_title("Add a setting to  ". $interface[0]['ip']);
-
-  // start form
-  echo "<form action='setting_action.php' method='post'>\n";
-  echo "<input type=hidden name='interface_id' value='$interface_id'>\n";
-  
-  echo "<table cellpadding='2'> <caption> New Setting </caption>";
-
-  echo "<tr><th>Select</th><td><select name='tag_type_id'><option value=''>Choose a type to add</option>\n";
-  
-  foreach( $setting_types as $setting_type ) {
-    echo "<option value='". $setting_type['tag_type_id'] ."'>". $setting_type['category'] . ":" . $setting_type['tagname'] ."</option>\n";
-  
-  }
-  echo "</select></td</tr>\n";
-  
-  echo "<tr><th>Value: </th><td><input type=text name='value'></td></tr>\n";
-  
-  echo "<tr><td colspan=2 align=center><input type=submit name='add_setting' value='Add Setting'></td></tr>\n";
-  echo "</table>";
-  echo "</form>\n";
-
-}
-else {
-  $setting_id= intval( $_GET['id'] );
-  
-  // get setting info
-  $setting= $api->GetInterfaceTags( array( $setting_id ));
-  
-  // interface info
-  $interface= $api->GetInterfaces( array( $setting[0]['interface_id'] ), array( "ip" ) );
-  
-  drupal_set_title("Edit setting ". $setting[0]['tagname'] ." on ". $interface[0]['ip']);
-
-  // start form and put values in to be edited.
-  echo "<form action='setting_action.php' method='post'>\n";
-  echo "<input type=hidden name='setting_id' value='". $setting[0]['interface_tag_id'] ."'>\n";
-  echo "<input type=hidden name='interface_id' value='". $setting[0]['interface_id'] ."'>\n";
-  
-  echo "<table cellpadding='2'> <caption> Edit Setting </caption>";
-  echo "<tr><th> Category </th> <td>" . $setting[0]['category'] . "</td></tr>";
-  echo "<tr><th> Name </th> <td>" . $setting[0]['tagname'] . "</td></tr>";
-  echo "<tr><th> Value </th> <td><input type=text name='value' value='" . $setting[0]['value'] . "'> </td></tr>";
-  echo "<tr><td colspan=2> <input type=submit value='Edit Setting' name='edit_setting'></td></tr>";
-  echo "</table>";
-  echo "</form>\n";
-  
-}
-
-// back link is case-dependant
-
-// Print footer
-include 'plc_footer.php';
-
-?>
index 4156076..83d7ff9 100644 (file)
@@ -82,14 +82,14 @@ if ($privileges || $is_my_account)
 if ($local_peer && $privileges) 
   if ($enabled) 
     $tabs['Disable'] = array ('method'=>'POST',
-                             'url'=>l_person_actions(),
+                             'url'=>l_actions(),
                              'values'=> array ('person_id'=>$person_id,
                                                'action'=>'disable-person'),
                              'bubble'=>"Disable $first_name $last_name",
                              'confirm'=>"Are you sure you want to disable $first_name $last_name");
   else 
     $tabs['Enable'] = array ('method'=>'POST',
-                            'url'=>l_person_actions(),
+                            'url'=>l_actions(),
                             'values'=> array ('person_id'=>$person_id,
                                               'action'=>'enable-person'),
                             'bubble'=>"Enable $first_name $last_name",
@@ -97,7 +97,7 @@ if ($local_peer && $privileges)
 
 // become
 if (plc_is_admin() && ! $is_my_account) 
-  $tabs['Become'] = array('url'=>l_person_actions(),
+  $tabs['Become'] = array('url'=>l_actions(),
                          'values'=>array('action'=>'become-person',
                                          'person_id'=>$person_id),
                          'bubble'=>"Become $first_name $last_name",
@@ -106,7 +106,7 @@ if (plc_is_admin() && ! $is_my_account)
 // delete
 if ($local_peer && $privileges) 
   $tabs['Delete'] = array ('method'=>'POST',
-                          'url'=>l_person_actions(),
+                          'url'=>l_actions(),
                           'values'=> array ('person_id'=>$person_id,
                                             'action'=>'delete-person'),
                           'bubble'=>"Delete $first_name $last_name",
@@ -165,7 +165,7 @@ if( ! $slices) {
  }
 
 // we don't set 'action', but use the submit button name instead
-plc_form_start(l_person_actions(),
+plc_form_start(l_actions(),
               array("person_id"=>$person_id,
                     // uncomment this to run the 'debug' action 
                     //"action"=>"debug",
index b4a0d34..8d27beb 100644 (file)
@@ -7,190 +7,20 @@ require_once 'plc_login.php';
 require_once 'plc_session.php';
 global $plc, $api;
 
-if (! isset($_GET['type']) || $_GET['type']=='all') {
-  $title="All tag types";
-  $tag_type_filter=array("-SORT"=>"tagname"); 
- } else {
-  $title="Tag Types for " . $_GET['type'] . "s";
-  $pattern=$_GET['type'] . '*';
-  $tag_type_filter=array("category"=>$pattern,"-SORT"=>"tagname");
- }
-
-
 // Print header
 require_once 'plc_drupal.php';
-drupal_set_title($title);
 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'];
-
-//print_r( $_person );
-
-// if no id, display list of tag types
-if( !$_GET['id'] && !$_GET['add'] && !$_GET['add_type'] && !$_GET['edit_type'] ) {
-  // get types
-  $tag_types= $api->GetTagTypes($tag_type_filter,
-                               array( "tag_type_id", "tagname", "category", "description", "min_role_id" ) );
-  
-  // get role names for the min role_ids
-  foreach( $tag_types as $tag_type ) {
-    $roles= $api->GetRoles();
-    foreach( $roles as $role ) {
-      if( $tag_type['min_role_id'] == $role['role_id'] )
-        $role_name= $role['name'];
-    }
-    
-    $tag_type_info[]= array( "tag_type_id" => $tag_type['tag_type_id'], 
-                            "tagname" => $tag_type['tagname'], 
-                            "description" => $tag_type['description'], 
-                            "min_role" => $role_name,
-                            "category" => $tag_type['category']);
-  }
 
-  // list them
-  echo "<h2>Tag Types</h2>\n";
-  
-  echo "<table cellpadding=2><thead><tr><th>Name</th><th>Category></th><th>Min Role</th><th>Description</th>";
-  // if admin we need to more cells
-  if(  in_array( "10", $_person['role_ids'] ) )
-    echo "<th></th><th></th>";
-  echo "</thead><tbody>";
-
-  foreach( $tag_type_info as $type ) {
-    echo "<tr>";
-    echo "<td>". $type['tagname'] ."</td>";
-    echo "<td>". $type['category'] ."</td>";
-    echo "<td>". $type['min_role'] ."</td>";
-    echo "<td>". $type['description'] ."</td>";
-    // if admin display edit/delet links
-    if(  in_array( "10", $_person['role_ids'] ) ) {
-      echo "<td><a href='tags.php?type=slice&edit_type=". $type['tag_type_id'] ."'>Edit</a></td>";
-      echo "<td>";
-      echo plc_delete_link_button ('tag_action.php?del_type='. $type['tag_type_id'],
-                                  $type['tagname']);
-      echo "</td>";
-    }
-    echo "</tr>\n";
-    
-  }
-  
-  echo "</tbody></table>\n";
-  
-  if( in_array( "10", $_person['role_ids'] ) )
-    echo "<p><a href='tags.php?type=slice&add_type=1'>Add a Tag Type</a>";
-  
+if ( $_GET['action'] ) {
+  include 'tag_edit.php';
+ } else if ( ! $_GET['add'] ) {
+  include 'tags.php';
+ } else {
+  include 'tag_set.php';
  }
-elseif( $_GET['add_type'] || $_GET['edit_type'] ) {
-  // if its edit get the tag info
-  if( $_GET['edit_type'] ) {
-    $type_id= intval( $_GET['edit_type'] );
-    $type_info= $api->GetTagTypes( array( $type_id ) );
-    
-    $tagname= $type_info[0]['tagname'];
-    $min_role_id= $type_info[0]['min_role_id'];
-    $description= $type_info[0]['description'];
-    $category=$type_info[0]['category'];
-    
-  }
-  
-  // display form for tag types
-  echo "<form action='tag_action.php' method='post'>\n";
-  echo "<h2>Add Tag Type</h2>\n";
-  echo "<p><strong>Name: </strong> <input type=text name='name' size=20 value='$tagname'>\n";
-  echo "<p><strong>Category: </strong><input type=text name='category' size=30 value='$category'>\n";
-  echo "<p><strong>Min Role: </strong><select name='min_role_id'>\n";
-  echo "<option value='10'"; if( $min_role_id == 10 ) echo " selected"; echo ">Admin</option>\n";
-  echo "<option value='20'"; if( $min_role_id == 20 ) echo " selected"; echo ">PI</option>\n";
-  echo "<option value='30'"; if( $min_role_id == 30 ) echo " selected"; echo ">User</option>\n";
-  echo "<option value='40'"; if( $min_role_id == 40 ) echo " selected"; echo ">Tech</option>\n";
-  echo "</select>\n";
-  echo "<p><strong>Description: </strong><br>\n";
-  echo "<textarea name='description' cols=40 rows=5>$description</textarea>\n";
-  echo "<p><input type=submit ";
-  if( $_GET['edit_type'] ) {
-    echo "name='edit_type' value='Edit Tag Type'>\n";
-    echo "<input type=hidden name='tag_type_id' value='$type_id'>\n";
-  }
-  else
-    echo "name='add_type' value='Add Tag Type'>\n";
-
-  echo "</form>\n";
-
-}
-elseif( $_GET['add'] ) {
-  // get slice id from GET
-  $slice_id= intval( $_GET['add'] );
-  
-  // get all tag types 
-  $tag_types= $api->GetTagTypes( $tag_type_filter , array( "tag_type_id", "tagname" ) );
-  
-  foreach( $tag_types as $tag_type ) {
-    $all_tags[$tag_type['tag_type_id']]= $tag_type['tagname'];
-  }
-  
-  // get slice's tag types
-  $slice_info= $api->GetSlices( array( $slice_id ), array( "slice_tag_ids" ) );
-  $tag_info= $api->GetSliceTags( $slice_info[0]['slice_tag_ids'], array( "tag_type_id", "tagname" ) );
-  
-  foreach( $tag_info as $info ) {
-    $slice_tag_types[$info['tag_type_id']]= $info['tagname'];
-  }
-
-
-    $tag_types= $all_tags;
-  
-  // start form
-  echo "<form action='tag_action.php' method='post'>\n";
-  echo "<h2>Edit ". $slice_info[0]['name'] ." tag: ". $tag_type[0]['tagname'] ."</h2>\n";
-  
-  echo "<select name='tag_type_id'><option value=''>Choose a type to add</option>\n";
-  
-  foreach( $tag_types as $key => $val ) {
-    echo "<option value='". $key ."'>". $val ."</option>\n";
-  
-  }
-  echo "</select>\n";
-  
-  echo "<p><strong>Value: </strong><input type=text name='value'>\n";
-  
-  echo "<p><input type=submit name='add_tag' value='Add Tag'>\n";
-  echo "<input type=hidden name='slice_id' value='$slice_id'>\n";
-  echo "</form>\n";
-  
-}
-else {
-  $tag_id= intval( $_GET['id'] );
-  
-  // get tag
-  $slice_tag= $api->GetSliceTags( array( $tag_id ), array( "slice_id", "slice_tag_id", "tag_type_id", "value", "description", "min_role_id" ) );
-  
-  // get type info 
-  $tag_type= $api->GetTagTypes( array( $slice_tag[0]['tag_type_id'] ), array( "tag_type_id", "tagname", "description" ) );
-  
-  // slice info
-  $slice_info= $api->GetSlices( array( $slice_tag[0]['slice_id'] ), array( "name" ) );
-  
-  // start form and put values in to be edited.
-  echo "<form action='tag_action.php' method='post'>\n";
-  echo "<h2>Edit ". $slice_info[0]['name'] ." tag: ". $tag_type[0]['tagname'] ."</h2>\n";
-  
-  echo $slice_tag[0]['description'] ."<br />\n";
-  echo "<strong>Value:</strong> <input type=text name=value value='". $slice_tag[0]['value'] ."'><br /><br />\n";
-  
-  echo "<input type=submit value='Edit Tag' name='edit_tag'>\n";
-  echo "<input type=hidden name='slice_id' value='". $slice_tag[0]['slice_id'] ."'>\n";
-  echo "<input type=hidden name='tag_id' value='". $tag_id ."'>\n";
-  echo "</form>\n";
-  
-}
-
-echo "<p><a href='index.php?id=$slice_id'>Back to Slices</a>\n";
 
 // Print footer
 include 'plc_footer.php';
index 170db85..abd0781 100644 (file)
@@ -45,7 +45,7 @@ if( $_GET['rem_id'] ) {
 
 // tag updates
 if( $_POST['edit_tag'] ) {
-  // get the id of the tag to update and teh value from POST
+  // get the id of the tag to update and the value from POST
   $tag_id= intval( $_POST['tag_id'] );
   $value= $_POST['value'];
   $slice_id= $_POST['slice_id'];
diff --git a/planetlab/tags/tag_form.php b/planetlab/tags/tag_form.php
new file mode 100644 (file)
index 0000000..2851e82
--- /dev/null
@@ -0,0 +1,82 @@
+<?php
+
+// $Id: nodes.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';
+
+// to create a new (action=='add-tag-type') 
+// or to update an existing (action='update-tag-type','tag_type_id'=<id>)
+
+// -------------------- 
+// recognized URL arguments
+$pattern=$_GET['pattern'];
+
+// --- decoration
+$title="Tag Types";
+$tabs=array();
+$tabs['All Types']=array('url'=>l_tags(),'bubble'=>"All Tag Types");
+
+// -------------------- 
+drupal_set_title($title);
+plc_tabs($tabs);
+
+// if its edit get the tag info
+$update_mode = ( $_GET['action'] == 'update-tag-type' ) ;
+
+if ($update_mode) {
+  $tag_type_id= intval( $_GET['id'] );
+  $type_info= $api->GetTagTypes( array( $tag_type_id ) );
+  
+  $tagname=$type_info[0]['tagname'];
+  $min_role_id= $type_info[0]['min_role_id'];
+  $description= $type_info[0]['description'];
+  $category=$type_info[0]['category'];
+ }  
+
+// display form for tag types
+plc_table_title($label);
+
+plc_form_start (l_actions(),array());
+plc_details_start();
+plc_details_line("Name", plc_form_text_text("name",$tagname,20));
+plc_details_line("Category", plc_form_text_text("category",$category,30));
+plc_details_line("Description",plc_form_textarea_text("description",$description,40,5));
+//tmp
+// select the option corresponding with min_role_id
+$selector = "<select name='min_role_id'>".
+  "<option value='10'>Admin</option>".
+  "<option value='20'>PI</option>".
+  "<option value='30'>User</option>" .
+  "<option value='40'>Tech</option>" . "</select>\n";
+plc_details_line("Min Role",$selector);
+if ($update_mode) {
+  $submit=plc_form_hidden_text ('tag_type_id',$tag_type_id) . 
+    plc_form_submit_text('update-tag-type',"Update tag type");
+ } else {
+  $submit=plc_form_submit_text('add-tag-type',"Add tag type");
+ }
+plc_details_line1 ($submit,"right");
+
+plc_details_end();
+plc_form_end();
+
+// Print footer
+include 'plc_footer.php';
+
+?>
diff --git a/planetlab/tags/tag_set.php b/planetlab/tags/tag_set.php
new file mode 100644 (file)
index 0000000..69b7a0d
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+
+// $Id$
+
+// 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';
+
+  // get slice id from GET
+  $slice_id= intval( $_GET['add'] );
+  
+  // get all tag types 
+  $tag_types= $api->GetTagTypes( $tag_type_filter , array( "tag_type_id", "tagname" ) );
+  
+  foreach( $tag_types as $tag_type ) {
+    $all_tags[$tag_type['tag_type_id']]= $tag_type['tagname'];
+  }
+  
+  // get slice's tag types
+  $slice_info= $api->GetSlices( array( $slice_id ), array( "slice_tag_ids" ) );
+  $tag_info= $api->GetSliceTags( $slice_info[0]['slice_tag_ids'], array( "tag_type_id", "tagname" ) );
+  
+  foreach( $tag_info as $info ) {
+    $slice_tag_types[$info['tag_type_id']]= $info['tagname'];
+  }
+
+
+    $tag_types= $all_tags;
+  
+  // start form
+  echo "<form action='tag_action.php' method='post'>\n";
+  echo "<h2>Edit ". $slice_info[0]['name'] ." tag: ". $tag_type[0]['tagname'] ."</h2>\n";
+  
+  echo "<select name='tag_type_id'><option value=''>Choose a type to add</option>\n";
+  
+  foreach( $tag_types as $key => $val ) {
+    echo "<option value='". $key ."'>". $val ."</option>\n";
+  
+  }
+  echo "</select>\n";
+  
+  echo "<p><strong>Value: </strong><input type=text name='value'>\n";
+  
+  echo "<p><input type=submit name='add_tag' value='Add Tag'>\n";
+  echo "<input type=hidden name='slice_id' value='$slice_id'>\n";
+  echo "</form>\n";
+  
+}
+else {
+  $tag_id= intval( $_GET['id'] );
+  
+  // get tag
+  $slice_tag= $api->GetSliceTags( array( $tag_id ), array( "slice_id", "slice_tag_id", "tag_type_id", "value", "description", "min_role_id" ) );
+  
+  // get type info 
+  $tag_type= $api->GetTagTypes( array( $slice_tag[0]['tag_type_id'] ), array( "tag_type_id", "tagname", "description" ) );
+  
+  // slice info
+  $slice_info= $api->GetSlices( array( $slice_tag[0]['slice_id'] ), array( "name" ) );
+  
+  // start form and put values in to be edited.
+  echo "<form action='tag_action.php' method='post'>\n";
+  echo "<h2>Edit ". $slice_info[0]['name'] ." tag: ". $tag_type[0]['tagname'] ."</h2>\n";
+  
+  echo $slice_tag[0]['description'] ."<br />\n";
+  echo "<strong>Value:</strong> <input type=text name=value value='". $slice_tag[0]['value'] ."'><br /><br />\n";
+  
+  echo "<input type=submit value='Edit Tag' name='edit_tag'>\n";
+  echo "<input type=hidden name='slice_id' value='". $slice_tag[0]['slice_id'] ."'>\n";
+  echo "<input type=hidden name='tag_id' value='". $tag_id ."'>\n";
+  echo "</form>\n";
+  
+}
+
+// Print footer
+include 'plc_footer.php';
+
+?>
diff --git a/planetlab/tags/tags.php b/planetlab/tags/tags.php
new file mode 100644 (file)
index 0000000..8b768d7
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+
+// $Id$
+
+// 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_forms.php';
+
+// -------------------- 
+// recognized URL arguments
+$pattern=$_GET['pattern'];
+
+// --- decoration
+$title="Tag Types";
+$tabs=array();
+$tabs['New Tag Type']=array('url'=>l_tag_add(),'bubble'=>"Create a new tag type");
+$tabs['All Nodes']=array('url'=>l_nodes(),'bubble'=>"Nodes from all peers");
+$tabs['Local Nodes']=array('url'=>l_nodes(),'values'=>array('peerscope'=>'local'),'bubble'=>"All local nodes");
+//$tabs['Interfaces']=l_interfaces();
+$tabs['All Slices']=array('url'=>l_slices(),'bubble'=>"Slices from all peers");
+
+// -------------------- 
+drupal_set_title($title);
+plc_tabs($tabs);
+
+$tag_type_columns = array( "tag_type_id", "tagname", "category", "description", "min_role_id" );
+
+$tag_type_filter=NULL;
+if ($pattern) 
+  $tag_type_filter['category']=$pattern;
+
+// get types
+$tag_types= $api->GetTagTypes($tag_type_filter, $tag_type_columns);
+  
+$headers=array();
+// delete button
+if (plc_is_admin()) $headers[' ']="none";
+$headers["Id"]="int";
+$headers['Name']="string";
+$headers['Description']="string";
+$headers['Min role']="string";
+$headers['Category']="string";
+
+plc_table_start("tags",$headers,1);
+
+$roles_hash=plc_role_global_hash($api);
+
+foreach( $tag_types as $tag_type ) {
+  $role_name=$roles_hash[$tag_type['min_role_id']];
+
+  plc_table_row_start();
+  $id=$tag_type['tag_type_id'];
+  if (plc_is_admin()) 
+    plc_table_cell(plc_delete_link_button ('tag_action.php?del_type='. $id,
+                                          $tag_type['tagname']));
+  plc_table_cell($id);
+  plc_table_cell(href(l_tag_update($id),$tag_type['tagname']));
+  plc_table_cell(wordwrap($tag_type['description'],40,"<br/>"));
+  plc_table_cell($role_name);
+  plc_table_cell($tag_type['category']);
+  plc_table_row_end();
+}
+$footers=array();
+if (plc_is_admin()) 
+  $footers[]=plc_table_td_text(plc_form_simple_button(l_tag_add(),"Add a Tag Type","GET"),6,"right");
+
+plc_table_end("tags",array('footers'=>$footers));
+
+// Print footer
+include 'plc_footer.php';
+
+?>