From 19ea00f9f677acff2b94f9c066c2949cc63d435c Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 6 Feb 2009 19:54:15 +0000 Subject: [PATCH] more inline updates & cleaned up tags --- planetlab/actions.php | 178 +++++++++++++++--- planetlab/css/plc_details.css | 5 + planetlab/css/plc_tables.css | 4 +- planetlab/includes/plc_details.php | 21 ++- planetlab/includes/plc_forms.php | 37 ++++ planetlab/includes/plc_functions.php | 30 ++- planetlab/includes/plc_functions_trash.php | 15 ++ planetlab/includes/plc_tables.php | 6 +- .../nodes/{interfaces.php => interface.php} | 2 +- planetlab/nodes/node.php | 48 ++--- planetlab/nodes/node_downloads.php | 4 +- planetlab/persons/person.php | 64 +++---- planetlab/sites/site.php | 62 +++--- planetlab/sites/site_update.php | 167 ---------------- planetlab/sites/sites.php | 2 + .../slices/{add_slice.php => slice_add.php} | 2 +- planetlab/sulogout.php | 3 +- planetlab/tags/index.php | 28 +-- planetlab/tags/tag.php | 144 ++++++++++++++ planetlab/tags/tag_action.php | 13 -- planetlab/tags/tag_form.php | 85 --------- planetlab/tags/tags.php | 54 ++++-- 22 files changed, 531 insertions(+), 443 deletions(-) rename planetlab/nodes/{interfaces.php => interface.php} (99%) delete mode 100644 planetlab/sites/site_update.php rename planetlab/slices/{add_slice.php => slice_add.php} (99%) create mode 100644 planetlab/tags/tag.php delete mode 100644 planetlab/tags/tag_form.php diff --git a/planetlab/actions.php b/planetlab/actions.php index 5d73030..ea142d5 100644 --- a/planetlab/actions.php +++ b/planetlab/actions.php @@ -49,19 +49,32 @@ $known_actions []= "delete-node"; // expects: node_id $known_actions []= "update-node"; // expects: node_id, hostname, model + +//////////////////////////////////////// interfaces +$known_actions []= "delete-interfaces"; +// expects: interface_ids + //////////////////////////////////////// sites $known_actions []= "delete-site"; // expects: site_id $known_actions []= "expire-all-slices-in-site"; // expects: slice_ids +$known_actions []= "update-site"; +// expects: site_id & name abbreviated_name url latitude longitude [login_base max_slices] //////////////////////////////////////// tags $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 +// expects: tag_type_id & tagname & description & category & min_role_id $known_actions []= "set-tag-on-node"; // expects: node_id tagname value +$known_actions []= "delete-tag-types"; +// expects: tag_type_ids + +//////////////////////////////////////// nodetags +$known_actions []= "delete-node-tags"; +// expects: node_id & node_tag_ids ////////////////////////////// // sometimes we don't set 'action', but use the submit button name instead @@ -75,13 +88,13 @@ else break; } -//debug +//uncomment for debugging incoming data //$action='debug'; $person_id = $_POST['person_id']; // usually needed if ( ! $action ) { - drupal_set_message ("actions.php: action not set"); + drupal_set_message ("actions.php: action not set or not in known_actions"); plc_debug('POST',$_POST); return; } @@ -152,9 +165,18 @@ switch ($action) { drupal_set_message("action=$action - No key selected"); return; } + $success=true; + $counter=0; foreach( $key_ids as $key_id ) { - $api->DeleteKey( intval( $key_id ) ); + if ($api->DeleteKey( intval( $key_id )) != 1) + $success=false; + else + $counter++; } + if ($success) + drupal_set_message ("Deleted $counter key(s)"); + else + drupal_set_error ("Could not delete all selected keys, only $counter were removed"); plc_redirect(l_person($person_id)); } @@ -183,14 +205,13 @@ switch ($action) { $key = fread($fp, filesize($key_file)); fclose($fp); - $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) ); + $key_id = $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) ); + + if ( $key_id == 1) + drupal_set_message ("New key added"); + else + drupal_set_error("Could not add key, please verify your SSH file content\n" . $api->error()); - if ( ! $key_id ) { - $error= $api->error(); - plc_error("$error"); - plc_error("Please verify your SSH file content"); - return; - } plc_redirect(l_person($person_id)); } @@ -221,16 +242,14 @@ switch ($action) { $update_vals['url']= $url; $update_vals['bio']= $bio; - if( $password1 != "" ) + if ( $password1 != "" ) $update_vals['password']= $password1; - $rc= $api->UpdatePerson( intval( $person_id ), $update_vals); - - if ( $rc == 1 ) { + if ( $api->UpdatePerson( intval( $person_id ), $update_vals) == 1 ) drupal_set_message("$first_name $last_name updated"); - } else { + else drupal_set_error ("Could not update person $person_id" . $api->error()); - } + plc_redirect(l_person($person_id)); break; } @@ -278,6 +297,30 @@ switch ($action) { break; } +//////////////////////////////////////////////////////////// interfaces + case 'delete-interfaces' : { + $interface_ids=$_POST['interface_ids']; + if ( ! $interface_ids) { + drupal_set_message("action=$action - No interface selected"); + return; + } + $success=true; + $counter=0; + foreach( $interface_ids as $interface_id ) { + if ($api->DeleteInterface( intval( $interface_id )) != 1) + $success=false; + else + $counter++; + } + if ($success) + drupal_set_message ("Deleted $counter interface(s)"); + else + drupal_set_error ("Could not delete all selected interfaces, only $counter were removed"); + plc_redirect(l_node($_POST['node_id'])); + } + + + //////////////////////////////////////////////////////////// sites case 'delete-site': { $site_id = intval($_POST['site_id']); @@ -286,6 +329,7 @@ switch ($action) { else drupal_set_error("Failed to delete site $site_id"); plc_redirect (l_sites()); + break; } case 'expire-all-slices-in-site': { @@ -305,6 +349,37 @@ switch ($action) { // update site to not allow slice creation or renewal $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ; plc_redirect (l_site($site_id)); + break; + } + + case 'update-site': { + $site_id=intval($_POST['site_id']); + $name= $_POST['name']; + $abbreviated_name= $_POST['abbreviated_name']; + $url= $_POST['url']; + $latitude= floatval($_POST['latitude']); + $longitude= floatval($_POST['longitude']); + //$max_slivers= $_POST['max_slivers']; + + $fields= array( "name" => $name, + "abbreviated_name" => $abbreviated_name, + "url" => $url, + "latitude" => floatval( $latitude ), + "longitude" => floatval( $longitude )); + + if ($_POST['login_base']) + $fields['login_base'] = $_POST['login_base']; + if ($_POST['max_slices']) + $fields['max_slices'] = intval($_POST['max_slices']); + + $retcod=$api->UpdateSite( intval( $site_id ), $fields ); + if ($retcod == 1) + drupal_set_message("Site $name updated"); + else + drupal_set_error ("Could not update site $site_id"); + + plc_redirect(l_site($site_id)); + break; } //////////////////////////////////////////////////////////// tags @@ -312,43 +387,46 @@ switch ($action) { case 'update-tag-type': { // get post vars $tag_type_id= intval( $_POST['tag_type_id'] ); - $name = $_POST['name']; + $tagname = $_POST['tagname']; $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, + "tagname" => $tagname, "description" => $description, "category" => $category, ); - // Update it! - $api->UpdateTagType( $tag_type_id, $tag_type_fields ); - + if ($api->UpdateTagType( $tag_type_id, $tag_type_fields ) == 1) + drupal_set_message ("Tag type $tagname updated"); + else + drupal_set_error ("Could not update tag type $tag_type_id\n".$api->error()); plc_redirect(l_tag($tag_type_id)); } case 'add-tag-type': { // get post vars - $name = $_POST['name']; + $tagname = $_POST['tagname']; $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, + "tagname" => $tagname, "description" => $description, "category" => $category, ); // Add it! - $id=$api->AddTagType( $tag_type_fields ); - drupal_set_message ("tag type $id created"); - - plc_redirect( l_tag($id)); + $tag_type_id=$api->AddTagType( $tag_type_fields ); + if ($tag_type_id > 0) + drupal_set_message ("tag type $tag_type_id created"); + else + drupal_set_error ("Could not create tag type $tagname"); + plc_redirect( l_tags()); } case 'set-tag-on-node': { @@ -382,6 +460,50 @@ switch ($action) { plc_redirect (l_node($node_id)); } + case 'delete-tag-types': { + $tag_type_ids = $_POST['tag_type_ids']; + if ( ! $tag_type_ids) { + drupal_set_message("action=$action - No tag selected"); + return; + } + $success=true; + $counter=0; + foreach ($tag_type_ids as $tag_type_id) + if ($api->DeleteTagType(intval($tag_type_id)) != 1) + $success=false; + else + $counter++; + if ($success) + drupal_set_message ("Deleted $counter tag(s)"); + else + drupal_set_error ("Could not delete all selected tags, only $counter were removed"); + plc_redirect (l_tags()); + break; + } + +//////////////////////////////////////// node tags + case 'delete-node-tags' : { + $node_tag_ids=$_POST['node_tag_ids']; + if ( ! $node_tag_ids) { + drupal_set_message("action=$action - No node tag selected"); + return; + } + $success=true; + $counter=0; + foreach( $node_tag_ids as $node_tag_id ) { + if ($api->DeleteNodeTag( intval( $node_tag_id )) != 1) + $success=false; + else + $counter++; + } + if ($success) + drupal_set_message ("Deleted $counter node tag(s)"); + else + drupal_set_error ("Could not delete all selected node tags, only $counter were removed"); + plc_redirect(l_node($_POST['node_id'])); + } + + //////////////////////////////////////// case 'debug': { diff --git a/planetlab/css/plc_details.css b/planetlab/css/plc_details.css index 7f028cd..d7808a2 100644 --- a/planetlab/css/plc_details.css +++ b/planetlab/css/plc_details.css @@ -5,3 +5,8 @@ table.plc_details { margin: 0 auto 1.5em auto; border-collapse:collapse; } + +table.plc_details>tbody>tr>th { + text-align: right; + font: bold 14px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; +} diff --git a/planetlab/css/plc_tables.css b/planetlab/css/plc_tables.css index 9f3d1c3..7bf4d99 100644 --- a/planetlab/css/plc_tables.css +++ b/planetlab/css/plc_tables.css @@ -26,10 +26,12 @@ th.plc_table { background: #CAE8EA url(/planetlab/icons/tablesort_header.jpg) no-repeat; vertical-align:middle; } -table.plc_table>tbody>tr>td { +table.plc_table>tbody>tr>td, table.plc_table textarea, table.plc_table input [type="text"] { font: normal 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; border-right: 1px solid #C1DAD7; border-bottom: 1px solid #C1DAD7; +} +table.plc_table>tbody>tr>td { padding: 6px 12px 6px 12px; color: #4f6b72; } diff --git a/planetlab/includes/plc_details.php b/planetlab/includes/plc_details.php index 06dd3ed..de77ebc 100644 --- a/planetlab/includes/plc_details.php +++ b/planetlab/includes/plc_details.php @@ -30,6 +30,8 @@ class PlcDetails { $this->field_height="2"; } + function form() { return $this->form; } + // start the details area, with an optional caption function start ($caption="") { print $this->start_html("$caption");} function start_html ($caption="") { @@ -78,14 +80,21 @@ class PlcDetails { } else { $html=""; $html .= ""; - $html .= "input_type == "textarea") { - if ($this->field_width) $html .= " cols=$this->field_width/"; - if ($this->field_height) $html .= " rows=$this->field_height/"; + $html .= ""; + // hack: if input_type is select : user provides the input field verbatim + if ( $this->input_type == "select" ) { + $html .= $value; + } else if ($this->input_type == "textarea") { + $html .= ""; } else { - if ($this->field_width) $html .= " size=$this->field_width/"; + $html .= "field_width) $html .= " size=$this->field_width"; + $html .= "/>"; } - $html .= ">"; + $html .= ""; return $html; } } diff --git a/planetlab/includes/plc_forms.php b/planetlab/includes/plc_forms.php index 8a0e0b6..7b68f2e 100644 --- a/planetlab/includes/plc_forms.php +++ b/planetlab/includes/plc_forms.php @@ -93,6 +93,43 @@ class PlcForm { $html .= ""; return $html; } + + // helper function to handle role-oriented selectors + // because GetRoles does not correctly support filters, it's really painful to do this + static public function role_selectors($api,$role_ids=NULL,$current=NULL) { + function role_selector ($role) { return array('display'=>$role['name'],"value"=>$role['role_id']); } + function role_id ($role) { return $role['role_id']; } + + $all_roles=$api->GetRoles(); + if ( ! $role_ids) + $role_ids=array_map("role_id",$all_roles); + + $selectors=array(); + // preserve input order + foreach ($role_ids as $role_id) { + foreach ($all_roles as $all_role) { + if ($all_role['role_id'] == $role_id) { + $selector=role_selector($all_role); + if ($role_id == $current) + $selector['selected']=true; + $selectors []= $selector; + } + } + } + return $selectors; + } + + static public function role_selectors_excluding ($api,$exclude_role_ids=NULL,$current=NULL) { + if ( ! $exclude_role_ids ) $exclude_role_ids = array(); + $all_roles=$api->GetRoles(); + $role_ids = array(); + foreach ($all_roles as $role) { + if ( ! in_array ($role['role_id'],$exclude_role_ids)) { + $role_ids [] = $role['role_id']; + } + } + return PlcForm::role_selectors($api,$role_ids,$current); + } } // a form with a single button diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index 526991a..8ea281d 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -3,7 +3,7 @@ // $Id$ // will trash this eventually -require_once 'plc_functions_trash.php'; + //require_once 'plc_functions_trash.php'; // utility function my_is_int ($x) { @@ -54,25 +54,25 @@ function l_nodes () { return "/db/nodes/index.php"; } function l_nodes_peer ($peer_id) { return "/db/nodes/index.php?peerscope=$peer_id"; } 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_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_interface ($interface_id) { return "/db/nodes/interfaces.php?id=$interface_id"; } +function l_interface ($interface_id) { return "/db/nodes/interface.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/interface.php?node_id=$node_id"; } function l_sites () { return "/db/sites/index.php"; } function l_sites_peer ($peer_id) { return "/db/sites/index.php?peerscope=$peer_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_site_update($site_id) { return "/db/sites/site_update.php?site_id=$site_id"; } function l_slices () { return "/db/slices/index.php"; } function l_slices_peer ($peer_id) { return "/db/slices/index.php?peerscope=$peer_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_slice_add () { return "/db/slices/slice_add.php"; } function l_slices_site($site_id) { return "/db/slices/index.php?site_id=$site_id"; } // from an object function l_slice_obj ($slice) { return l_slice_t ($slice['slice_id'],$slice['name']); } @@ -88,9 +88,8 @@ 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_tags () { return "/db/tags/index.php"; } -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_tag ($tag_type_id) { return "/db/tags/index.php?id=$tag_type_id"; } +function l_tag_obj ($tag) { return href(l_tag($tag['tag-type_id']),$tag['tagname']); } function l_nodegroups () { return "/db/tags/nodegroups.php"; } function l_nodegroup ($nodegroup_id) { return "/db/tags/nodegroup.php?id=$nodegroup_id"; } @@ -318,19 +317,14 @@ if (! function_exists ("drupal_set_error")) { // builds a table from an array of strings, with the given class // attempt to normalize the delete buttons and confirmations function plc_delete_icon($width=15) { - return 'Delete this entry'; + return ""; } -function plc_js_confirm($message) { - return "onclick=\"javascript:return confirm('Are you sure you want to delete " . $message . " ?')\""; +function plc_bubble($text,$bubble) { + return "$text"; } - -function plc_delete_link($url,$delete_message,$visible) { - return "" . $visible . ""; -} - -function plc_delete_link_button($url,$delete_message,$width=15) { - return "" . plc_delete_icon($width) . ""; +function plc_delete_icon_bubble ($bubble,$width=15) { + return plc_bubble(plc_delete_icon($width),$bubble); } function plc_event_button($type,$param,$id) { diff --git a/planetlab/includes/plc_functions_trash.php b/planetlab/includes/plc_functions_trash.php index 4ef99b5..95d2839 100644 --- a/planetlab/includes/plc_functions_trash.php +++ b/planetlab/includes/plc_functions_trash.php @@ -216,4 +216,19 @@ function arr_diff( $a1, $a2 ) { return $diff; } +// obsolete ? +function plc_js_confirm($message) { + return "onclick=\"javascript:return confirm('Are you sure you want to delete " . $message . " ?')\""; +} + +function plc_delete_link($url,$delete_message,$visible) { + return "" . $visible . ""; +} + +function plc_delete_link_button($url,$delete_message,$width=15) { + return "" . + plc_delete_icon_bubble($width,"Delete this entry") . + ""; +} + ?> diff --git a/planetlab/includes/plc_tables.php b/planetlab/includes/plc_tables.php index 3a15e0f..0cfeba4 100644 --- a/planetlab/includes/plc_tables.php +++ b/planetlab/includes/plc_tables.php @@ -79,8 +79,8 @@ class PlcTable { public function start () { $paginator=$this->table_id."_paginator"; $classname="paginationcallback-".$paginator; - $classname.=" max-pages-" . $max_pages; - $classname.=" paginate-" . $pagesize; + $classname.=" max-pages-" . $this->max_pages; + $classname.=" paginate-" . $this->pagesize; // instantiate paginator callback print <<< EOF