From: Thierry Parmentelat Date: Thu, 5 Feb 2009 17:06:57 +0000 (+0000) Subject: details can be updated inline - old forms still to be cleaned up X-Git-Tag: PLEWWW-4.3-1~58 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=350bb4d9c096b0cfb877fb67ab94ebac753a98a5;p=plewww.git details can be updated inline - old forms still to be cleaned up --- diff --git a/planetlab/actions.php b/planetlab/actions.php index b41dc5d..5d73030 100644 --- a/planetlab/actions.php +++ b/planetlab/actions.php @@ -18,6 +18,7 @@ $known_actions=array(); // interface : // (*) use POST // (*) set 'action' to one of the following +//////////////////////////////////////// persons $known_actions []= "add-person-to-site"; // expects: person_id & site_id $known_actions []= "remove-person-from-sites"; @@ -38,14 +39,27 @@ $known_actions []= "delete-keys"; // expects: key_ids & person_id (for redirecting to the person's page) $known_actions []= "upload-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 +$known_actions []= "update-person"; +// expects: person_id & first_name last_name title email phone url bio + [password1 password2] + +//////////////////////////////////////// nodes +$known_actions []= "node-boot-state"; +// expects: node_id boot_state +$known_actions []= "delete-node"; +// expects: node_id +$known_actions []= "update-node"; +// expects: node_id, hostname, model +//////////////////////////////////////// sites $known_actions []= "delete-site"; // expects: site_id $known_actions []= "expire-all-slices-in-site"; // expects: slice_ids + +//////////////////////////////////////// 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 $known_actions []= "set-tag-on-node"; // expects: node_id tagname value @@ -144,6 +158,7 @@ switch ($action) { plc_redirect(l_person($person_id)); } + case 'upload-key' : { if ( ! isset( $_FILES['key'] ) ) { drupal_set_message ("action=$action, no key file set"); @@ -179,6 +194,121 @@ switch ($action) { plc_redirect(l_person($person_id)); } + case 'update-person': { + $person_id=$_POST['person_id']; + // attempt to update this person + $first_name= $_POST['first_name']; + $last_name= $_POST['last_name']; + $title= $_POST['title']; + $email= $_POST['email']; + $phone= $_POST['phone']; + $url= $_POST['url']; + $bio= str_replace("\r", "", $_POST['bio']); + $password1= $_POST['password1']; + $password2= $_POST['password2']; + + if( $password1 != $password2 ) { + drupal_set_error ("The passwords do not match"); + plc_redirect(l_person($person_id)); + } + + $update_vals= array(); + $update_vals['first_name']= $first_name; + $update_vals['last_name']= $last_name; + $update_vals['title']= $title; + $update_vals['email']= $email; + $update_vals['phone']= $phone; + $update_vals['url']= $url; + $update_vals['bio']= $bio; + + if( $password1 != "" ) + $update_vals['password']= $password1; + + $rc= $api->UpdatePerson( intval( $person_id ), $update_vals); + + if ( $rc == 1 ) { + drupal_set_message("$first_name $last_name updated"); + } else { + drupal_set_error ("Could not update person $person_id" . $api->error()); + } + plc_redirect(l_person($person_id)); + break; + } + +//////////////////////////////////////////////////////////// nodes + case 'node-boot-state': { + $node_id=intval($_POST['node_id']); + $boot_state=$_POST['boot_state']; + $result=$api->UpdateNode( $node_id, array( "boot_state" => $boot_state ) ); + if ($result==1) { + drupal_set_message("boot state updated"); + plc_redirect (l_node($node_id)); + } else { + drupal_set_error("Could not set boot_state '$boot_state'"); + } + break; + } + + case 'delete-node': { + $node_id=intval($_POST['node_id']); + $result=$api->DeleteNode( intval( $node_id ) ); + if ($api==1) { + drupal_set_message("Node $node_id deleted"); + plc_redirect (l_nodes()); + } else { + drupal_set_error ("Could not delete node $node_id"); + } + break; + } + + case 'update-node': { + $hostname= $_POST['hostname']; + $model= $_POST['model']; + + $fields= array( "hostname"=>$hostname, "model"=>$model ); + $api->UpdateNode( intval( $node_id ), $fields ); + $error= $api->error(); + + if( empty( $error ) ) { + drupal_set_message("Update node $hostname"); + plc_redirect(l_node($node_id)); + } else { + drupal_set_error($error); + } + break; + } + +//////////////////////////////////////////////////////////// sites + case 'delete-site': { + $site_id = intval($_POST['site_id']); + if ($api->DeleteSite($site_id) ==1) + drupal_set_message ("Site $site_id deleted"); + else + drupal_set_error("Failed to delete site $site_id"); + plc_redirect (l_sites()); + } + + case 'expire-all-slices-in-site': { + // xxx todo + drupal_set_message("action $action not implemented in actions.php -- need tweaks and test"); + return; + + //// old code from sites/expire.php + $sites = $api->GetSites( array( intval( $site_id ))); + $site=$sites[0]; + // xxx why not 'now?' + $expiration= strtotime( $_POST['expires'] ); + // loop through all slices for site + foreach ($site['slice_ids'] as $slice_id) { + $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) ); + } + // update site to not allow slice creation or renewal + $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ; + plc_redirect (l_site($site_id)); + } + +//////////////////////////////////////////////////////////// tags + case 'update-tag-type': { // get post vars $tag_type_id= intval( $_POST['tag_type_id'] ); @@ -221,34 +351,6 @@ switch ($action) { plc_redirect( l_tag($id)); } - case 'delete-site': { - $site_id = intval($_POST['site_id']); - if ($api->DeleteSite($site_id) ==1) - drupal_set_message ("Site $site_id deleted"); - else - drupal_set_error("Failed to delete site $site_id"); - plc_redirect (l_sites()); - } - - case 'expire-all-slices-in-site': { - // xxx todo - drupal_set_message("action $action not implemented in actions.php -- need tweaks and test"); - return; - - //// old code from sites/expire.php - $sites = $api->GetSites( array( intval( $site_id ))); - $site=$sites[0]; - // xxx why not 'now?' - $expiration= strtotime( $_POST['expires'] ); - // loop through all slices for site - foreach ($site['slice_ids'] as $slice_id) { - $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) ); - } - // update site to not allow slice creation or renewal - $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ; - plc_redirect (l_site($site_id)); - } - case 'set-tag-on-node': { $node_id = intval($_POST['node_id']); @@ -280,6 +382,7 @@ switch ($action) { plc_redirect (l_node($node_id)); } +//////////////////////////////////////// case 'debug': { plc_debug('GET',$_GET); diff --git a/planetlab/adminsearch.php b/planetlab/adminsearch.php index 1e7d347..c3c32d9 100644 --- a/planetlab/adminsearch.php +++ b/planetlab/adminsearch.php @@ -408,8 +408,8 @@ if (false) { foreach( $key_info as $key ) { $key_type= $key['key_type']; $key_id= $key['key_id']; - $key_text= wordwrap( $key['key'], 70, "
\n", 1 ); - echo "$key_type$key_text\n"; + $key_html= wordwrap( $key['key'], 70, "
\n", 1 ); + echo "$key_type$key_html\n"; } echo "\n"; diff --git a/planetlab/css/plc_style.css b/planetlab/css/plc_style.css index 7e21a05..9152078 100644 --- a/planetlab/css/plc_style.css +++ b/planetlab/css/plc_style.css @@ -28,11 +28,13 @@ h2.plc { text-align: center; } - +/* tmp - for visual checking */ +.plc-local { + border: 1px solid #00f; +} .plc-foreign { background: #e0e0e0; } - .plc-warning { background: orange; } @@ -45,3 +47,7 @@ h2.plc { *.plc-warning a:visited { text-decoration: none; color:white } *.plc-warning a:hover { text-decoration: none; color:black } +/* separator below the minitabs area */ +p.plc-minitabs { + height:15px; +} diff --git a/planetlab/css/plc_tables.css b/planetlab/css/plc_tables.css index 973ad97..9f3d1c3 100644 --- a/planetlab/css/plc_tables.css +++ b/planetlab/css/plc_tables.css @@ -236,4 +236,4 @@ ul.fdtablePaginater {display:inline-block;} mul.fdtablePaginater {display:inline;} ul.fdtablePaginater li {float:left;} ul.fdtablePaginater {text-align:center;} -table.plc_table { border-bottom:1px solid #C1DAD7; } +/*table.plc_table { border-bottom:1px solid #C1DAD7; }*/ diff --git a/planetlab/includes/plc_details.php b/planetlab/includes/plc_details.php index 10af0af..06dd3ed 100644 --- a/planetlab/includes/plc_details.php +++ b/planetlab/includes/plc_details.php @@ -3,49 +3,129 @@ // $Id$ require_once 'plc_functions.php'; +require_once 'plc_forms.php'; drupal_set_html_head(' '); -// rough implem, no class for now -// start the details area, with an optional caption -function plc_details_start ($title="") { - print ""; - if ($caption) { - printf ("\n",$caption); +// the basic idea is to define an area for displaying details like +// fieldname=>value +// and we add in-line editing capabilities + +class PlcDetails { + + var $editable; + var $form; + // set manually + var $field_width; + var $field_height; + var $input_type="text"; + + function PlcDetails ($editable) { + $this->editable=$editable; + $this->form=NULL; + $this->field_width=""; + $this->field_height="2"; } - echo ""; -} -// end the area -function plc_details_end() { - print "
%s
\n"; -} + // start the details area, with an optional caption + function start ($caption="") { print $this->start_html("$caption");} + function start_html ($caption="") { + $html=""; + if ($caption) $html .= ""; + $html .= ""; + return $html; + } -// display a line with caption and value -function plc_details_line ($title,$value) { - printf("\n",$title,$value); -} + function end() { print $this->end_html(); } + function end_html () { + return "
$caption
%s%s
\n"; + } -// same but the values are multiple and displayed in an embedded vertical table -function plc_details_line_list($title,$list) { - plc_details_line($title,plc_vertical_table($list,"foo")); -} + // starts an inner form if the details are editable + // accpets same args as PlcForm + function form_start ($url,$values,$method="POST") { print $this->form_start_html($url,$values,$method); } + function form_start_html ($url,$values,$method="POST") { + $this->form = new PlcForm ($url,$values,$method); + return $this->form->start_html(); + } -// same but the values are multiple and displayed in an embedded vertical table -function plc_details_line1_text($title,$align=NULL) { - $result="form_end_html(); } + function form_end_html () { + if ( ! $this->form) return ""; + $html = $this->form->end_html(); + $form=NULL; + return $html; + } + + // must be embedded in a line or a single + // xxx need a way to ask for confirmation + function submit_html ($name,$display) { + if ( ! $this->form) return ""; + if ( ! $this->editable) return ""; + return $this->form->submit_html($name,$display); + } + + // give a form_varname if the field can be edited + function line ($title,$value,$form_varname="") { + print $this->line_html ($title,$value,$form_varname); + } + function line_html ($title,$value,$form_varname="") { + if ( ! ($this->editable && $form_varname) ) { + return "$title$value"; + } 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/"; + } else { + if ($this->field_width) $html .= " size=$this->field_width/"; + } + $html .= ">"; + return $html; + } + } + + // same but the values are multiple and displayed in an embedded vertical table (not editable) + function lines($title,$list) { print $this->lines_html($title,$list); } + function lines_html($title,$list) { + return $this->line_html($title,plc_vertical_table($list,"foo")); + } + + // 1 item, colspan=2 + function single($title,$align=NULL) { print $this->single_html($title,$align);} + function single_html($title,$align=NULL) { + $result="space_html(); } + function space_html () { return " \n"; } + + function set_field_width ($field_width) { + $old=$this->field_width; + $this->field_width=$field_width; + return $old; + } + function set_field_height ($field_height) { + $old=$this->field_height; + $this->field_height=$field_height; + return $old; + } + + function set_input_type ($input_type) { + $old=$this->input_type; + $this->input_type=$input_type; + return $old; + } -// a dummy line for getting some air -function plc_details_space_line () { - echo " \n"; } ?> diff --git a/planetlab/includes/plc_forms.php b/planetlab/includes/plc_forms.php index ff86ec3..8a0e0b6 100644 --- a/planetlab/includes/plc_forms.php +++ b/planetlab/includes/plc_forms.php @@ -4,84 +4,115 @@ require_once 'plc_functions.php'; -// the rationale behind having function names with _text is that +// the rationale behind having function names with _html is that // 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(...))'' +// so basically the foo (...) function should just do ``print (foo_html(...))'' -// options unused so far -function plc_form_start ($full_url, $values, $options=array()) { - if ( ! $values ) $values = array(); - // extract var=value settings from url if any - $split=split_url($full_url); - $url=$split['url']; - $url_values=$split['values']; - if ( $url_values ) $values=array_merge($values,$url_values); - $method = array_key_exists('method',$options) ? $options['method'] : 'POST'; - print "
"; - if ($values) foreach ($values as $key=>$value) { - print plc_form_hidden_text($key,$value); - } -} +class PlcForm { + // mandatory + var $url; + var $values; // a hash var=>value - default is empty array + var $method; // default is POST -function plc_form_end($options=array()) { - print "
"; -} + function PlcForm ($full_url, $values, $method="POST") { + // so we can use the various l_* functions: + // we parse the url to extract var-values pairs, + // and add them to the 'values' argument if any -function plc_form_hidden_text ($key,$value) { - return ""; -} -function plc_form_hidden ($key,$value) { print plc_form_hidden_text($key,$value); } - -function plc_form_checkbox_text ($name,$value,$selected=false) { - if ($selected) $xtra=" selected=selected"; - return ""; -} + // extract var=value settings from url if any + $split=split_url($full_url); + $this->url=$split['url']; + + $url_values=$split['values']; + if ( ! $values ) $values = array(); + if ( $url_values ) $values=array_merge($values,$url_values); + $this->values=$values; -function plc_form_submit_text ($name,$display) { - return ""; -} -function plc_form_submit ($name, $display) { print plc_form_submit_text($name,$display); } - -function plc_form_file_text ($name,$size) { - return ""; -} + $this->method=$method; + } -function plc_form_label_text ($name,$display) { - return ""; -} + function start () { print $this->start_html(); } + function start_html () { + $html="
method action='$this->url' enctype='multipart/form-data'>"; + if ($this->values) + foreach ($this->values as $key=>$value) + $html .= $this->hidden_html($key,$value); + return $html; + } -function plc_form_text_text ($name,$value,$size) { - return ""; -} -function plc_form_textarea_text ($name,$value,$cols,$rows) { - return ""; -} + function end() { print $this->end_html(); } + function end_html() { return "
"; } + + static function hidden_html ($key,$value) { + return ""; + } + static function checkbox_html ($name,$value,$selected=false) { + if ($selected) $xtra=" selected=selected"; + return ""; + } + static function submit_html ($name,$display) { + return ""; + } + static function file_html ($name,$size) { + return ""; + } + static function label_html ($name,$display) { + return ""; + } + static function text_html ($name,$value,$size) { + return ""; + } + static function textarea_html ($name,$value,$cols,$rows) { + return ""; + } -function plc_form_select_text ($name,$values,$label="") { - $encoded=htmlentities($label,ENT_QUOTES); - $selector=""; - $selector.="\n"; - echo "\n"; - echo ""; + $boot_value .= $boot_form->select_html("boot_state",$selectors,NULL,true); + $boot_value .= $boot_form->end_html(); } -echo "\n"; +$details->line ("Boot state",$boot_value); // same here for the download area if ( $local_peer && $privileges) { - echo "Download "; - echo "
\n"; - echo "\n"; - echo "
"; - echo "\n"; - + $download_value=""; + $download_form = new PlcForm (l_actions_download(),array("node_id"=>$node_id)); + $download_value .= $download_form->start_html(); + $selectors = array( + array("display"=>"-- All in one images --","disabled"=>true), + array("value"=>"download-node-iso","display"=>"Download ISO image for $hostname"), + array("value"=>"download-node-usb","display"=>"Download USB image for $hostname<"), + array("display"=>"-- Floppy + generic image --","disabled"=>true), + array("value"=>"download-node-floppy","display"=>"Download Floppy file for $hostname"), + array("value"=>"download-generic-iso","display"=>"Download generic ISO image (requires floppy)"), + array("value"=>"download-generic-usb","display"=>"Download generic USB image (requires floppy)")); + $download_value .= $download_form->select_html("action",$selectors,"Download mode",true); + $download_value .= $download_form->end_html(); + $details->line ("Download",$download_value); } // site info and all site nodes -plc_details_space_line (); -plc_details_line("Site",l_site_t($site_id,$site_name)); +$details->space (); +$details->line("Site",l_site_t($site_id,$site_name)); // build list of node links $nodes_area=array(); foreach ($site_node_hash as $hash_node_id => $hash_hostname) { $nodes_area []= l_node_t($hash_node_id,$hash_hostname); } -plc_details_line_list ("All site nodes",$nodes_area); +$details->lines ("All site nodes",$nodes_area); -plc_details_end (); +$details->end (); -plc_form_start(l_actions(), array('node_id'=>$node_id)); +$form=new PlcForm (l_actions(), array('node_id'=>$node_id)); +$form->start(); //////////////////////////////////////////////////////////// Tags // get tags @@ -236,7 +234,8 @@ if ( $local_peer ) { $table->cell($tag['tagname']); $table->cell($tag['value']); $table->cell($nodegroup_name); - $table->cell (plc_form_checkbox_text('node_tag_ids[]',$tag['node_tag_id'])); + // the remove checkbox + $table->cell ($form->checkbox_html('node_tag_ids[]',$tag['node_tag_id'])); $table->row_end(); } @@ -245,7 +244,7 @@ if ( $local_peer ) { // remove tag $table->row_start(); - $table->cell(plc_form_submit_text("remove-node-tags","Remove Tags"), + $table->cell($form->submit_html("remove-node-tags","Remove Tags"), // use the whole columns and right adjust $table->columns(), "right"); $table->row_end(); @@ -257,45 +256,15 @@ if ( $local_peer ) { // xxx cannot use onchange=submit() - would need to somehow pass action name function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); } $selector=array_map("tag_selector",$all_tags); - $table->cell(plc_form_select_text("tag_type_id",$selector,"Choose")); - $table->cell(plc_form_text_text("value","",8)); - $table->cell(plc_form_submit_text("set-tag-on-node","Set Tag"),2,"left"); + $table->cell($form->select_html("tag_type_id",$selector,"Choose")); + $table->cell($form->text_html("value","",8)); + $table->cell($form->submit_html("set-tag-on-node","Set Tag"),2,"left"); $table->row_end(); } $table->end(); } -//////////////////////////////////////////////////////////// slices -// display slices - -plc_section ("Slices"); -if ( ! $slices ) { - plc_warning ("This node is not associated to any slice"); - } else { - $headers=array(); - $headers['Peer']="string"; - $headers['Name']="string"; - $headers['Slivers']="string"; - $reasonable_page=10; - $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page); - if (count ($slices) <= $reasonable_page) { - $table_options['search_area']=false; - $table_options['pagesize_area']=false; - } - $table=new PlcTable("node_slices",$headers,1,$table_options); - $table->start(); - - foreach ($slices as $slice) { - $table->row_start(); - $table->cell ($peers->shortname($peer_id)); - $table->cell (l_slice_t ($slice['slice_id'],$slice['name'])); - $table->cell (l_sliver_t ($node_id,$slice['slice_id'],'view')); - $table->row_end(); - } - $table->end(); - } - //////////////////////////////////////////////////////////// interfaces if ( $local_peer ) { @@ -303,7 +272,7 @@ if ( $local_peer ) { // display interfaces if( ! $interfaces ) { echo '

'; - plc_warning_text("This node has no interface"); + plc_warning_html("This node has no interface"); echo "Please add an interface to make this a usable PLC node.

\n"; } else { $headers=array(); @@ -358,15 +327,45 @@ if ( $local_peer ) { if ($privileges) { $table->tfoot_start(); $table->row_start(); - $table->cell(plc_form_simple_button(l_interface_add($node_id),"Add interface","GET"), - $table->columns(),"right"); + $button=new PlcFormButton (l_interface_add($node_id),"add_interface","Add interface","GET"); + $table->cell($button->html(), $table->columns(),"right"); $table->row_end(); } $table->end(); } } -plc_form_end(); +//////////////////////////////////////////////////////////// slices +// display slices + +plc_section ("Slices"); +if ( ! $slices ) { + plc_warning ("This node is not associated to any slice"); + } else { + $headers=array(); + $headers['Peer']="string"; + $headers['Name']="string"; + $headers['Slivers']="string"; + $reasonable_page=10; + $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page); + if (count ($slices) <= $reasonable_page) { + $table_options['search_area']=false; + $table_options['pagesize_area']=false; + } + $table=new PlcTable("node_slices",$headers,1,$table_options); + $table->start(); + + foreach ($slices as $slice) { + $table->row_start(); + $table->cell ($peers->shortname($peer_id)); + $table->cell (l_slice_t ($slice['slice_id'],$slice['name'])); + $table->cell (l_sliver_t ($node_id,$slice['slice_id'],'view')); + $table->row_end(); + } + $table->end(); + } + +$form->end(); //////////////////////////////////////////////////////////// $peers->block_end($peer_id); diff --git a/planetlab/nodes/node_actions.php b/planetlab/nodes/node_downloads.php similarity index 72% rename from planetlab/nodes/node_actions.php rename to planetlab/nodes/node_downloads.php index 6de70c9..6baadb0 100644 --- a/planetlab/nodes/node_actions.php +++ b/planetlab/nodes/node_downloads.php @@ -1,34 +1,9 @@ actual UpdateNode - // (POST) node_id=node_id ng_add=nodegroup_id - // AddNodeToNodeGroup - // (POST) boot_state=boot_state node_id=node_id - // (POST) ng_add=nodegroup_id - // (*) downloadconf.php - // (GET) id=node_id [download=1] - // either showed current status, or performed actual config download - - // in this new version we support only POST behaviour with the following interface + + // cleaned up, keep only the actions related to downloading stuff // REQUIRED : node_id=node_id - // (*) action='prompt-update' : former node_update.php - // (*) action='update' - // hostname= - // model= : actually updated the node - // (*) action='boot-state' - // boot_state= : changes bootstate - // (*) action='delete' : deletes node // (*) action='download-node-floppy' : // (*) action='download-node-iso' : // (*) action='download-node-usb' : @@ -38,12 +13,6 @@ // (*) action='download-generic-iso': // (*) action='download-generic-usb': // : performs actual generic download - // (*) action='add-in-nodegroup': should include this for compatibility, replaces ng_add, - // though I could not figure where it's called - - - // TODO : manage a post field for displaying results of previous page - // see the special 'flash' in rails // delivering node-dependant images requires larger memory limit // trial and error, based on the current sizes @@ -115,7 +84,7 @@ function show_download_confirm_button ($api, $node_id, $action, $can_gen_config, 'download-node-usb' => 'USB image' ); $format = $action_labels [ $action ] ; - print( "

\n"); + print( "

\n"); print ("\n"); print ("\n"); print ("\n"); @@ -138,78 +107,6 @@ $action=$_POST['action']; switch ($action) { - // ACTION: prompt-update - // from former node_update.php - case "prompt-update": - - require_once('plc_drupal.php'); - $node_info= $api->GetNodes( array( $node_id ), array( "hostname", "model" ) ); - drupal_set_title("Updating " . $node_info[0]['hostname']); - include 'plc_header.php'; - - // start form - echo "\n"; - echo "\n"; - echo "\n"; - if( $_POST['error'] ) plc_error(unserialize( $_POST['error'])); - echo "

\n - \n - \n -
Hostname:
Model:
\n -

\n -

\n"; - - echo "

Back to Node\n"; - - break; - - // ACTION: update - // from former node_actions.php - case "update": - - $hostname= $_POST['hostname']; - $model= $_POST['model']; - - $fields= array( "hostname"=>$hostname, "model"=>$model ); - $api->UpdateNode( intval( $node_id ), $fields ); - $error= $api->error(); - - if( empty( $error ) ) { - plc_redirect(l_node($node_id)); - } else { - echo "". $error . "\n" ; - echo "

Press back to retry

"; - } - - break; - - // ACTION: delete - // from former node_actions.php - case "delete": - $api->DeleteNode( intval( $node_id ) ); - plc_redirect(l_nodes()); - break; - - // ACTION: boot-state - // from former node_actions.php - case "boot-state": - switch( $_POST['boot_state'] ) { - case 'boot': - case 'dbg': - case 'inst': - case 'rins': - case 'rcnf': - case 'new': - $api->UpdateNode( intval( $node_id ), array( "boot_state" => $_POST['boot_state'] ) ); - plc_redirect (l_node($node_id)); - break; - default: - print "
no such boot state " . $_POST['boot_state'] . "
"; - break; - } - break; - - // ACTION: download-generic case "download-generic-iso": case "download-generic-usb": @@ -415,7 +312,7 @@ if( $has_primary ) { break; default: - echo "Unkown action <$action>."; + drupal-set_error("Unkown action $action in node_downloads.php"); plc_redirect (l_node($node_id)); break; } diff --git a/planetlab/peers/peer.php b/planetlab/peers/peer.php index d21c051..47c24bb 100644 --- a/planetlab/peers/peer.php +++ b/planetlab/peers/peer.php @@ -40,21 +40,22 @@ $peer_id=$peer['peer_id']; drupal_set_title("Details for Peer " . $peername); -plc_details_start(); -plc_details_line("Peer name",$peer['peername']); -plc_details_line("Short name",$peer['shortname']); -plc_details_line("Hierarchical name",$peer['hrn_root']); -plc_details_line("API URL",$peer['peer_url']); +$details=new PlcDetails(false); +$details->start(); +$details->line("Peer name",$peer['peername']); +$details->line("Short name",$peer['shortname']); +$details->line("Hierarchical name",$peer['hrn_root']); +$details->line("API URL",$peer['peer_url']); $nb=sizeof($peer['site_ids']); -plc_details_line("Number of sites",href(l_sites_peer($peer_id),"$nb sites")); +$details->line("Number of sites",href(l_sites_peer($peer_id),"$nb sites")); $nb=sizeof($peer['node_ids']); -plc_details_line("Number of nodes",href(l_nodes_peer($peer_id),"$nb nodes")); +$details->line("Number of nodes",href(l_nodes_peer($peer_id),"$nb nodes")); $nb=sizeof($peer['person_ids']); -plc_details_line("Number of users",href(l_persons_peer($peer_id),"$nb users")); +$details->line("Number of users",href(l_persons_peer($peer_id),"$nb users")); $nb=sizeof($peer['slice_ids']); -plc_details_line("Number of slices",href(l_slices_peer($peer_id),"$nb slices")); -plc_details_end(); +$details->line("Number of slices",href(l_slices_peer($peer_id),"$nb slices")); +$details->end(); // Print footer include 'plc_footer.php'; diff --git a/planetlab/persons/person.php b/planetlab/persons/person.php index 4194874..6331398 100644 --- a/planetlab/persons/person.php +++ b/planetlab/persons/person.php @@ -74,11 +74,11 @@ $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi()); $tabs=array(); // update -if ($privileges || $is_my_account) - $tabs['Update'] = array('url'=>'/db/persons/update.php', - 'values'=>array('id'=>$person_id), - 'bubble'=>"Update $first_name $last_name"); - +//if ($privileges || $is_my_account) +// $tabs['Update'] = array('url'=>'/db/persons/update.php', +// 'values'=>array('id'=>$person_id), +// 'bubble'=>"Update $first_name $last_name"); +// // enable / disable if ($local_peer && $privileges) if ($enabled) @@ -131,20 +131,36 @@ $peers->block_start ($peer_id); if ($local_peer && $privileges && ! $enabled ) drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below"); -$enabled_text="Enabled"; -if ( ! $enabled ) $enabled_text = plc_warning_text("Disabled"); - -plc_details_start(); -plc_details_line("Enabled",$enabled_text); -plc_details_line("First Name",$first_name); -plc_details_line("Last Name",$last_name); -plc_details_line("Email",href("mailto:$email",$email)); -plc_details_line("URL",$url); -plc_details_line("Phone",$phone); -plc_details_line("Title",$title); -plc_details_line("Bio",wordwrap($bio,50,"
")); -plc_details_line("Peer",$peers->peer_link($peer_id)); -plc_details_end(); +$enabled_label="Enabled"; +if ( ! $enabled ) $enabled_label = plc_warning_html("Disabled"); + +$can_update = $is_my_account || plc_is_admin(); +$details = new PlcDetails($can_update); +$details->start(); +$details->line("Enabled",$enabled_label); +$details->space(); +$details->form_start(l_actions(),array("action"=>"update-person", + "person_id"=>$person_id)); +$details->line("Title",$title,"title"); +$details->line("First Name",$first_name,"first_name"); +$details->line("Last Name",$last_name,"last_name"); +$details->line(href("mailto:$email","Email"),$email,"email"); +$details->line("URL",$url,"url"); +$details->line("Phone",$phone,"phone"); +$details->line("Bio",wordwrap($bio,50,"
"),"bio"); +// xxx need to check that this is working +if ($can_update) { + $save=$details->set_input_type("password"); + $details->line("Password","","password1"); + $details->line("Repeat","","password2"); + $details->set_input_type($save); + } +// xxx need fields to reset password ? +$details->line("",$details->submit_html("submit","Update Account")); +$details->form_end(); + +$details->line("Peer",$peers->peer_link($peer_id)); +$details->end(); //////////////////// slices plc_section('Slices'); @@ -173,7 +189,8 @@ if( ! $slices) { } // we don't set 'action', but use the submit button name instead -plc_form_start(l_actions(), array("person_id"=>$person_id,)); +$form=new PlcForm(l_actions(), array("person_id"=>$person_id)); +$form->start(); //////////////////// keys plc_section ("Keys"); @@ -198,7 +215,7 @@ if ($keys) foreach ($keys as $key) { $table->cell ($key['key_type']); $table->cell(wordwrap( $key['key'], 60, "
\n", 1 )); if ($can_manage_keys) - $table->cell (plc_form_checkbox_text('key_ids[]',$key_id)); + $table->cell ($form->checkbox_html('key_ids[]',$key_id)); $table->row_end(); } // the footer area is used for displaying key-management buttons @@ -208,14 +225,14 @@ if ($can_manage_keys) { // no need to remove if there's no key if ($keys) { $table->row_start(); - $table->cell(plc_form_submit_text ("delete-keys","Remove keys"), + $table->cell($form->submit_html ("delete-keys","Remove keys"), $table->columns(),"right"); $table->row_end(); } $table->row_start(); - $table->cell(plc_form_label_text("key","Upload new key") . plc_form_file_text("key",60), + $table->cell($form->label_html("key","Upload new key") . $form->file_html("key",60), $table->columns()-1,"right"); - $table->cell(plc_form_submit_text("upload-key","Upload key")); + $table->cell($form->submit_html("upload-key","Upload key")); $table->row_end(); } @@ -245,7 +262,7 @@ foreach( $sites as $site ) { $table->cell ($login_base); $table->cell (l_site_t($site_id,$site_name)); if ($can_manage_sites) - $table->cell (plc_form_checkbox_text('site_ids[]',$site_id)); + $table->cell ($form->checkbox_html('site_ids[]',$site_id)); $table->row_end (); } if ($can_manage_sites) { @@ -253,7 +270,7 @@ if ($can_manage_sites) { if ($sites) { $table->row_start(); - $table->cell(plc_form_submit_text("remove-person-from-sites","Remove Sites"), + $table->cell($form->submit_html("remove-person-from-sites","Remove Sites"), $table->columns(),"right"); $table->row_end(); } @@ -267,8 +284,8 @@ if ($can_manage_sites) { // xxx cannot use onchange=submit() - would need to somehow pass action name function select_arguments($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); } $selectors = array_map ("select_arguments",$relevant_sites); - $table->cell (plc_form_select_text("site_id",$selectors,"Choose a site to add"). - plc_form_submit_text("add-person-to-site","Add in site"), + $table->cell ($form->select_html("site_id",$selectors,"Choose a site to add"). + $form->submit_html("add-person-to-site","Add in site"), $table->columns(),"right"); $table->row_end(); } @@ -297,7 +314,7 @@ for ($n=0; $nrow_start(); $table->cell($role_obj['name']); - if ($can_manage_roles) $table->cell (plc_form_checkbox_text('role_ids[]',$role_obj['role_id'])); + if ($can_manage_roles) $table->cell ($form->checkbox_html('role_ids[]',$role_obj['role_id'])); $table->row_end(); } @@ -306,7 +323,7 @@ if ($can_manage_roles) { $table->tfoot_start(); if ($roles) { $table->row_start(); - $table->cell(plc_form_submit_text("remove-roles-from-person","Remove Roles"), + $table->cell($form->submit_html("remove-roles-from-person","Remove Roles"), $table->columns(),"right"); $table->row_end(); } @@ -317,9 +334,9 @@ if ($can_manage_roles) { $relevant_roles = $api->GetRoles( array("~role_id"=>$role_ids)); function selector_argument ($role) { return array('display'=>$role['name'],"value"=>$role['role_id']); } $selectors=array_map("selector_argument",$relevant_roles); - $add_role_left_area=plc_form_select_text("role_id",$selectors,"Choose a role to add"); + $add_role_left_area=$form->select_html("role_id",$selectors,"Choose a role to add"); // add a role : the button - $add_role_right_area=plc_form_submit_text("add-role-to-person","Add role"); + $add_role_right_area=$form->submit_html("add-role-to-person","Add role"); $table->cell ($add_role_left_area . $add_role_right_area, $table->columns(),"right"); $table->row_end(); @@ -327,7 +344,7 @@ if ($can_manage_roles) { $table->end(); ////////////////////////////// -plc_form_end(); +$form->end(); $peers->block_end($peer_id); // Print footer diff --git a/planetlab/persons/update.php b/planetlab/persons/update.php index b1fd143..6088239 100644 --- a/planetlab/persons/update.php +++ b/planetlab/persons/update.php @@ -28,42 +28,6 @@ if( isset($_GET['id']) && is_numeric($_GET['id']) ) { $errors= array(); if( $is_submitted ) { - // attempt to update this person - $first_name= $_POST['first_name']; - $last_name= $_POST['last_name']; - $title= $_POST['title']; - $email= $_POST['email']; - $phone= $_POST['phone']; - $url= $_POST['url']; - $bio= str_replace("\r", "", $_POST['bio']); - $password1= $_POST['password1']; - $password2= $_POST['password2']; - - if( $password1 != $password2 ) { - $errors[]= "The passwords do not match"; - } - - if( count($errors) == 0 ) { - $update_vals= array(); - $update_vals['first_name']= $first_name; - $update_vals['last_name']= $last_name; - $update_vals['title']= $title; - $update_vals['email']= $email; - $update_vals['phone']= $phone; - $update_vals['url']= $url; - $update_vals['bio']= $bio; - - if( $password1 != "" ) - $update_vals['password']= $password1; - - $rc= $api->UpdatePerson( intval( $person_id ), $update_vals); - - if ( $rc == 1 ) { - plc_redirect(l_person($person_id)); - } elseif ($rc === NULL) { - $errors[] = $api->error(); - } - } } else { // get details for the user $person_details= $api->GetPersons( array( intval( $person_id ) ), array( "person_id", "first_name", "last_name", "title", "email", "phone", "url", "bio" ) ); diff --git a/planetlab/sites/site.php b/planetlab/sites/site.php index 7bb738e..105bfd1 100644 --- a/planetlab/sites/site.php +++ b/planetlab/sites/site.php @@ -142,61 +142,62 @@ 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 () || ( plc_in_site($site_id) && plc_is_pi()); +$details = new PlcDetails($can_update); +// XXX make this updatable +$details->start(); +$details->line("Full name",$sitename); +$details->line("Login base",$login_base); +$details->line("Abbreviated name",$abbrev_name); +$details->line("URL",$site_url); +$details->line("Latitude",$site_lat); +$details->line("Longitude",$site_long); +$details->line("Peer",$peers->peer_link($peer_id)); 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); // 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"; 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))); // 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_obj($slice)); - + $details->line($slice['instantiation'],l_slice_obj($slice)); // Addresses if ($addresses) { - plc_details_space_line(); - plc_details_line("Addresses",""); + $details->space(); + $details->line("Addresses",""); foreach ($addresses as $address) { - plc_details_line(plc_vertical_table($address['address_types']), + $details->line(plc_vertical_table($address['address_types']), plc_vertical_table(array($address['line1'], $address['line2'], $address['line3'], @@ -209,7 +210,7 @@ if ( $local_peer ) { } -plc_details_end(); +$details->end(); //////////////////////////////////////// $peers->block_end($peer_id); diff --git a/planetlab/sites/site_update.php b/planetlab/sites/site_update.php index 5bda0a9..b27bc07 100644 --- a/planetlab/sites/site_update.php +++ b/planetlab/sites/site_update.php @@ -133,10 +133,8 @@ if( $error['max_slices'] ) $max_err= " style='border: 1px solid red;'"; // start form -require_once 'plc_forms.php'; -plc_ -echo "
\n"; +echo "\n"; echo "

$do $name

\n"; echo "\n"; diff --git a/planetlab/tags/nodegroup.php b/planetlab/tags/nodegroup.php index 892cfc8..09fb885 100644 --- a/planetlab/tags/nodegroup.php +++ b/planetlab/tags/nodegroup.php @@ -18,8 +18,6 @@ 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'; -//require_once 'plc_peers.php'; // -------------------- // recognized URL arguments @@ -54,12 +52,13 @@ $tabs ["Local nodes"] = array ('url'=>l_nodes_peer('local'), drupal_set_title("Details for node group " . $nodegroup['groupname']); plc_tabs($tabs); -plc_details_start(); -plc_details_line ("Node group name",$nodegroup['groupname']); -plc_details_line ("Based on tag",href(l_tag($nodegroup['tag_type_id']),$tagname)); -plc_details_line("Matching value",$nodegroup['value']); -plc_details_line("# nodes",count($nodegroup['node_ids'])); -plc_details_end(); +$details=new PlcDetails(false); +$details->start(); +$details->line ("Node group name",$nodegroup['groupname']); +$details->line ("Based on tag",href(l_tag($nodegroup['tag_type_id']),$tagname)); +$details->line("Matching value",$nodegroup['value']); +$details->line("# nodes",count($nodegroup['node_ids'])); +$details->end(); // xxx : add & delete buttons would make sense here too plc_section("Nodes"); diff --git a/planetlab/tags/tag_form.php b/planetlab/tags/tag_form.php index f695bc7..390fee6 100644 --- a/planetlab/tags/tag_form.php +++ b/planetlab/tags/tag_form.php @@ -52,11 +52,14 @@ if ($update_mode) { // display form for tag types plc_section($label,false); -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)); +$form = new PlcForm (l_actions(),array()); +$form->start(); +// XXX make this updatable ? +$details = new PlcDetails(false); +$details->start(); +$details->line("Name", $form->text_html("name",$tagname,20)); +$details->line("Category", $form->text_html("category",$category,30)); +$details->line("Description",$form->textarea_html("description",$description,40,5)); //tmp // select the option corresponding with min_role_id $selector = "". "". "" . "" . "\n"; -plc_details_line("Min Role",$selector); +$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"); + $submit=$form->hidden_html ('tag_type_id',$tag_type_id) . + $form->submit_html('update-tag-type',"Update tag type"); } else { - $submit=plc_form_submit_text('add-tag-type',"Add tag type"); + $submit=$form->submit_html('add-tag-type',"Add tag type"); } -plc_details_line1 ($submit,"right"); +$details->single ($submit,"right"); -plc_details_end(); -plc_form_end(); +$details->end(); +$form->end(); // Print footer include 'plc_footer.php'; diff --git a/planetlab/tags/tags.php b/planetlab/tags/tags.php index c094c9a..c79bf86 100644 --- a/planetlab/tags/tags.php +++ b/planetlab/tags/tags.php @@ -78,8 +78,8 @@ foreach( $tag_types as $tag_type ) { if (plc_is_admin()) { $table->tfoot_start(); $table->row_start(); - $table->cell (plc_form_simple_button(l_tag_add(),"Add a Tag Type","GET"), - $table->columns(),"right"); + $button=new PlcFormButton(l_tag_add(),"add_type_id","Add a Tag Type","GET"); + $table->cell ($button->html(), $table->columns(),"right"); $table->row_end(); }