// 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";
// 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
plc_redirect(l_person($person_id));
}
+
case 'upload-key' : {
if ( ! isset( $_FILES['key'] ) ) {
drupal_set_message ("action=$action, no key file set");
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'] );
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']);
plc_redirect (l_node($node_id));
}
+////////////////////////////////////////
case 'debug': {
plc_debug('GET',$_GET);
foreach( $key_info as $key ) {
$key_type= $key['key_type'];
$key_id= $key['key_id'];
- $key_text= wordwrap( $key['key'], 70, "<br />\n", 1 );
- echo "<tr><td>$key_type</td><td>$key_text</td></tr>\n";
+ $key_html= wordwrap( $key['key'], 70, "<br />\n", 1 );
+ echo "<tr><td>$key_type</td><td>$key_html</td></tr>\n";
}
echo "</tbody></table>\n";
text-align: center;
}
-
+/* tmp - for visual checking */
+.plc-local {
+ border: 1px solid #00f;
+}
.plc-foreign {
background: #e0e0e0;
}
-
.plc-warning {
background: orange;
}
*.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;
+}
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; }*/
// $Id$
require_once 'plc_functions.php';
+require_once 'plc_forms.php';
drupal_set_html_head('
<link href="/planetlab/css/plc_details.css" rel="stylesheet" type="text/css" />
');
-// rough implem, no class for now
-// start the details area, with an optional caption
-function plc_details_start ($title="") {
- print "<table class=plc_details><thead>";
- if ($caption) {
- printf ("<caption>%s</caption>\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 "</thead><tbody>";
-}
-// end the area
-function plc_details_end() {
- print "</tbody></table>\n";
-}
+ // start the details area, with an optional caption
+ function start ($caption="") { print $this->start_html("$caption");}
+ function start_html ($caption="") {
+ $html="<table class=plc_details><thead>";
+ if ($caption) $html .= "<caption>$caption</caption>";
+ $html .= "</thead><tbody>";
+ return $html;
+ }
-// display a line with caption and value
-function plc_details_line ($title,$value) {
- printf("<tr><th>%s</th><td>%s</td></tr>\n",$title,$value);
-}
+ function end() { print $this->end_html(); }
+ function end_html () {
+ return "</tbody></table>\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="<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);}
+ function form_end () { print $this->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 "<tr><th>$title</th><td>$value</td></tr>";
+ } else {
+ $html="";
+ $html .= "<tr><th><label for=$form_varname>$title</label></th>";
+ $html .= "<td><input type='$this->input_type' name='$form_varname' value='$value'";
+ if ($this->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 .= "></td></tr>";
+ 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="<tr><td colspan=2";
+ if ($align) $result .= " style='text-align:$align'";
+ $result .=">$title</td></tr>";
+ return $result;
+ }
+
+ // a dummy line for getting some air
+ function space () { print $this->space_html(); }
+ function space_html () { return "<tr><td colspan=2> </td></tr>\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 "<tr><td colspan=2> </td></tr>\n";
}
?>
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 "<form method=$method action='$url' enctype='multipart/form-data'>";
- 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 "</form>";
-}
+ 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 "<input type=hidden name='$key' value='$value'/>";
-}
-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 "<input type=checkbox name='$name' value='$value'$xtra/>";
-}
+ // 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 "<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/>";
-}
+ $this->method=$method;
+ }
-function plc_form_label_text ($name,$display) {
- return "<label for=$name>$display </label>";
-}
+ function start () { print $this->start_html(); }
+ function start_html () {
+ $html="<form method=$this->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 "<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 end() { print $this->end_html(); }
+ function end_html() { return "</form>"; }
+
+ static function hidden_html ($key,$value) {
+ return "<input type=hidden name='$key' value='$value'/>";
+ }
+ static function checkbox_html ($name,$value,$selected=false) {
+ if ($selected) $xtra=" selected=selected";
+ return "<input type=checkbox name='$name' value='$value'$xtra/>";
+ }
+ static function submit_html ($name,$display) {
+ return "<input type=submit name='$name' value='$display'/>";
+ }
+ static function file_html ($name,$size) {
+ return "<input type=file name='$name' size=$size/>";
+ }
+ static function label_html ($name,$display) {
+ return "<label for=$name>$display </label>";
+ }
+ static function text_html ($name,$value,$size) {
+ return "<input type=text name='$name' size=$size value='$value'>";
+ }
+ static function textarea_html ($name,$value,$cols,$rows) {
+ return "<textarea name='$name' cols=$cols rows=$rows>$value</textarea>";
+ }
-function plc_form_select_text ($name,$values,$label="") {
- $encoded=htmlentities($label,ENT_QUOTES);
- $selector="";
- $selector.="<select name='$name'>";
- if ($label)
- $selector.="<option value=''>$encoded</option>";
- foreach ($values as $chunk) {
- $display=htmlentities($chunk['display'],ENT_QUOTES);
- $value=$chunk['value'];
- $selector .= "<option value='$value'";
- if ($chunk['selected']) $selector .= " selected=selected";
- $selector .= ">$display</option>\n";
+ // selectors is an array of hashes with the following keys
+ // (*) display
+ // (*) value : the value that the 'name' variable will be assigned
+ // (*) optional 'selected': the entry selected initially
+ // (*) optional 'disabled': the entry is displayed but not selectable
+ // optional label is inserted as the first option, with no value attached
+ // autosubmit: onchange=submit()
+ static function select_html ($name,$selectors,$label=NULL,$autosubmit=false) {
+ $html="";
+ $html.="<select name='$name'";
+ if ($autosubmit) $html .= " onChange='submit();'";
+ $html .= ">";
+ if ($label) {
+ $encoded=htmlentities($label,ENT_QUOTES);
+ $html.="<option selected=selected value=''>$encoded</option>";
+ }
+ foreach ($selectors as $selector) {
+ $display=htmlentities($selector['display'],ENT_QUOTES);
+ $value=$selector['value'];
+ $html .= "<option value='$value'";
+ if ($selector['selected']) $html .= " selected=selected";
+ if ($selector['disabled']) $html .= " disabled=disabled";
+ $html .= ">$display</option>\n";
+ }
+ $html .= "</select>";
+ return $html;
}
- $selector .= "</select>";
- return $selector;
}
-function plc_form_simple_button ($full_url,$text,$method="POST") {
- $split=split_url($full_url);
- $url=$split['url'];
- $values=$split['values'];
- $button=plc_form_submit_text("anonymous",$text);
- if ($values) foreach ($values as $key=>$value)
- $button .= plc_form_hidden_text($key,$value);
- return "<form method=$method action=$url>$button</form>";
+// a form with a single button
+class PlcFormButton extends PlcForm {
+
+ var $button_id;
+ var $button_text;
+
+ function PlcFormButton ($full_url, $button_id, $button_text, $method="POST") {
+ $this->PlcForm($full_url,array(),$method);
+ $this->button_id=$button_id;
+ $this->button_text=$button_text;
+ }
+
+ function html () {
+ return
+ $this->start_html() .
+ $this->submit_html($this->button_id,$this->button_text).
+ $this->end_html();
+ }
}
?>
// l_object_add () -> the url to that object-afding page
function l_actions () { return "/db/actions.php"; }
+// some complex node actions are kept separate, e.g. the ones related to getbootmedium
+function l_actions_download () { return "/db/nodes/node_downloads.php"; }
function l_nodes () { return "/db/nodes/index.php"; }
function l_nodes_peer ($peer_id) { return "/db/nodes/index.php?peerscope=$peer_id"; }
}
}
-function plc_warning_text ($text) { return "<span class='plc-warning'>" . $text . "</span>";}
-function plc_warning ($text) { print plc_warning_text("Warning " . $text); }
-function plc_foreign_text($text) { return "<span class=plc-foreign>$text</span>"; }
+function plc_warning_html ($text) { return "<span class='plc-warning'>" . $text . "</span>";}
+function plc_warning ($text) { print plc_warning_html("Warning " . $text); }
+function plc_foreign_html($text) { return "<span class=plc-foreign>$text</span>"; }
// shows a php variable verbatim with a heading message
function plc_debug ($message,$object) {
//////////////////////////////////////////////////////////// sort out for obsolete / trash
// builds a table from an array of strings, with the given class
// attempt to normalize the delete buttons and confirmations
-function plc_delete_button($width=15) {
+function plc_delete_icon($width=15) {
return '<span title="Delete this entry"><img width=' . $width . ' alt="Delete this entry" src="/planetlab/icons/delete.png"></span>';
}
}
function plc_delete_link_button($url,$delete_message,$width=15) {
- return "<a href='" . $url . "' " . plc_js_confirm($delete_message) . ">" . plc_delete_button($width) . "</a>";
+ return "<a href='" . $url . "' " . plc_js_confirm($delete_message) . ">" . plc_delete_icon($width) . "</a>";
}
function plc_event_button($type,$param,$id) {
}
print '</ul>';
print '</div>';
- print "<p style='height:15px'></p>\n";
+ print "<p class='plc-minittabs'></p>\n";
}
?>
// to set the background to grey on foreign objects
// return true if the peer is local
if ( ! $peer_id ) {
- print "<div>";
+ print "<div class=\"plc-local\">";
} else {
$classname=strtolower($this->classname($peer_id));
// set two classes, one generic to all foreign, and one based on the peer's shortname for finer grain tuning
EOF;
if ($this->pagesize_area)
- print $this->pagesize_area_text ();
+ print $this->pagesize_area_html ();
if ($this->search_area)
- print $this->search_area_text ();
+ print $this->search_area_html ();
print "<tr>";
foreach ($this->headers as $label => $type) {
// xxx default should be used only if applicable
function end ($options=NULL) {
$this->set_options($options);
- print $this->bottom_text();
+ print $this->bottom_html();
if ($this->notes_area)
- print $this->notes_area_text();
+ print $this->notes_area_html();
}
////////////////////
- function pagesize_area_text () {
+ function pagesize_area_html () {
$width=count($this->headers);
$pagesize_text_id = $this->table_id . "_pagesize";
$result= <<< EOF
}
////////////////////
- function search_area_text () {
+ function search_area_html () {
$width=count($this->headers);
$search_text_id = $this->table_id . "_search";
$search_reset_id = $this->table_id . "_search_reset";
}
//////////////////// start a <tfoot> section
- function tfoot_start () {
- print $this->tfoot_start_text();
- }
-
- function tfoot_start_text () {
+ function tfoot_start () { print $this->tfoot_start_html(); }
+ function tfoot_start_html () {
$this->has_tfoot=true;
return "</tbody><tfoot>";
}
////////////////////////////////////////
- function bottom_text () {
+ function bottom_html () {
$result="";
if ($this->has_tfoot)
$result .= "</tfoot>";
}
////////////////////////////////////////
- function notes_area_text () {
+ function notes_area_html () {
$default_notes = array(
"Enter & or | in the search area to alternate between <bold>AND</bold> and <bold>OR</bold> search modes",
"Hold down the shift key to select multiple columns to sort");
}
////////////////////
- public function cell ($text,$colspan=0,$align=NULL) {
- print $this->cell_text ($text,$colspan,$align);
- }
- public function cell_text ($text,$colspan=0,$align=NULL) {
+ public function cell ($text,$colspan=0,$align=NULL) { print $this->cell_html ($text,$colspan,$align); }
+ public function cell_html ($text,$colspan=0,$align=NULL) {
$result="";
$result .= "<td";
if ($colspan) $result .= " colspan=$colspan";
// available actions
if ( $local_peer && $privileges ) {
- $tabs['Update'] = array ('url'=>"/db/nodes/node_actions.php",
+ $tabs['Delete'] = array ('url'=>l_actions(),
'method'=>'POST',
- 'values'=>array('action'=>'prompt-update','node_id'=>$node_id),
- 'bubble'=>"Update details of $hostname");
- $tabs['Delete'] = array ('url'=>"/db/nodes/node_actions.php",
- 'method'=>'POST',
- 'values'=>array('action'=>'delete','node_id'=>$node_id),
+ 'values'=>array('action'=>'delete-node','node_id'=>$node_id),
'bubble'=>"Delete node $hostname",
'confirm'=>'Are you sure to delete ' . $hostname. ' ?');
// xxx subject to roles
// show gray background on foreign objects : start a <div> with proper class
$peers->block_start ($peer_id);
-plc_details_start ();
+$details=new PlcDetails($privileges);
+$details->start();
if ( ! $local_peer) {
- plc_details_line("Peer",$peers->peer_link($peer_id));
- plc_details_space_line();
+ $details->line("Peer",$peers->peer_link($peer_id));
+ $details->space();
}
-plc_details_line("Hostname",$hostname);
-plc_details_line("Type",$node_type);
-plc_details_line("Model",$model);
-plc_details_line("Version",$version);
-// no tool to implement this multiple-choice setting yet
-// xxx would need at least to use the proper class, like plc_details_class() or something
-plc_details_space_line ();
-echo "<tr><th>Boot State: </th><td>";
-if ( ! $local_peer) {
- echo $boot_state;
+$details->form_start(l_actions(),array("action"=>"update-node",
+ "node_id"=>$node_id));
+$details->line("Hostname",$hostname,"hostname");
+$details->line("Model",$model,"model");
+$details->line("",$details->submit_html("submit","Update Node"));
+$details->form_end();
+$details->line("Type",$node_type);
+$details->line("Version",$version);
+
+// boot area
+$details->space ();
+if ( ! ($local_peer && $privileges)) {
+ // just display it
+ $boot_value=$boot_state;
} else {
- echo "<form name='bootstate' action='/db/nodes/node_actions.php' method=post>\n";
- echo "<input type=hidden name='node_id' value='$node_id'>\n";
- echo "<input type=hidden name='action' value='boot-state'>\n";
- echo "<select name='boot_state' onChange=\"submit();\">\n";
-
- $states= array( 'boot'=>'Boot', 'dbg'=>'Debug', 'inst'=>'Install', 'rins'=>'Reinstall', 'rcnf'=>'Reconfigure', 'new'=>'New' );
-
- foreach( $states as $key => $val ) {
- echo "<option value='$key'";
-
- if( $key == $boot_state )
- echo " selected";
-
- echo ">$val</option>\n";
-
+ $boot_value="";
+ $boot_form = new PlcForm (l_actions(), array("node_id"=>$node_id,
+ "action"=>"node-boot-state"));
+ $boot_value .= $boot_form->start_html();
+ $states = array( 'boot'=>'Boot', 'safeboot'=>'SafeBoot', 'failboot'=>'FailBoot',
+ 'disabled' => 'Disabled', 'install'=>'Install', 'reinstall'=>'Reinstall');
+ $selectors=array();
+ foreach ($states as $dbname=>$displayname) {
+ $selector=array("display"=>$displayname, "value"=>$dbname);
+ if ($dbname == $boot_state) $selector['selected']=true;
+ $selectors []= $selector;
}
- echo "</select></input></form>";
+ $boot_value .= $boot_form->select_html("boot_state",$selectors,NULL,true);
+ $boot_value .= $boot_form->end_html();
}
-echo "</td></tr>\n";
+$details->line ("Boot state",$boot_value);
// same here for the download area
if ( $local_peer && $privileges) {
- echo "<tr><th>Download </th><td>";
- echo "<form name='download' action='/db/nodes/node_actions.php' method='post'>\n";
- echo "<input type=hidden name='node_id' value='$node_id'></input>\n";
- echo "<select name='action' onChange='submit();'>\n";
- echo "<option value='' selected='selected'> Download Mode </option>\n";
- echo "<option value='' disabled='disabled'> -- All in one images -- </option>";
- echo "<option value='download-node-iso' $new_api_only> Download ISO image for $hostname</option>\n";
- echo "<option value='download-node-usb' $new_api_only> Download USB image for $hostname</option>\n";
- echo "<option value='' disabled='disabled'> -- Floppy + generic image -- </option>";
- echo "<option value='download-node-floppy'> Download Floppy file for $hostname</option>\n";
- echo "<option value='download-generic-iso' $new_api_only> Download generic ISO image (requires floppy) </option>\n";
- echo "<option value='download-generic-usb' $new_api_only> Download generic USB image (requires floppy) </option>\n";
- echo "</select></form>";
- echo "</td></tr>\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
$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();
}
// 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();
// 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 ) {
// display interfaces
if( ! $interfaces ) {
echo '<p>';
- 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.</p>\n";
} else {
$headers=array();
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);
<?php
// $Id$
- // This file was created when we decided to make the node page consistent with the other pages
- // That is to say, we wanted the 'Update' and 'Delete' functions to appear in a drop-down
- // menu like for the other objects
- // It appeared after analysis that it was easier to have the following
- // functions gathered in a single php file
- // (*) node_update.php
- // (GET) id=node_id
- // displays current settings and prompt for changes before going to node_actions.php
- // (*) node_actions.php
- // (GET) 'del=node_id'
- // (GET) 'update=node_id' -> 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' :
// (*) 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
'download-node-usb' => 'USB image' );
$format = $action_labels [ $action ] ;
- print( "<p><form method='post' action='node_actions.php'>\n");
+ print( "<p><form method='post' action='node_downloads.php'>\n");
print ("<input type='hidden' name='node_id' value='$node_id'>\n");
print ("<input type='hidden' name='action' value='$action'>\n");
print ("<input type='hidden' name='download' value='1'>\n");
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 "<form method=post action='node_actions.php'>\n";
- echo "<input type=hidden name='node_id' value='$node_id'></input>\n";
- echo "<input type=hidden name='action' value='update'></input>\n";
- if( $_POST['error'] ) plc_error(unserialize( $_POST['error']));
- echo "<p><table cellpadding=2><tbody>\n
- <tr><th>Hostname: </th><td> <input type=text size=35 name='hostname' value='". $node_info[0]['hostname'] ."'></td></tr>\n
- <tr><th>Model: </th><td> <input type=text size=35 name='model' value='". $node_info[0]['model'] ."'></td></tr>\n
- </tbody></table>\n
- <p><input type=submit value='Update Node'>\n
- </form>\n";
-
- echo "<p><a href='index.php?id=$node_id'>Back to Node</a>\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 "<font color=red>". $error . "</font>\n" ;
- echo "<p> Press back to retry</p>";
- }
-
- 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 "<div class='plc-error'> no such boot state " . $_POST['boot_state'] . "</div>";
- break;
- }
- break;
-
- // ACTION: download-generic
case "download-generic-iso":
case "download-generic-usb":
break;
default:
- echo "Unkown action <$action>.";
+ drupal-set_error("Unkown action $action in node_downloads.php");
plc_redirect (l_node($node_id));
break;
}
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';
$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)
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,"<br/>"));
-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,"<br/>"),"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');
}
// 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");
$table->cell ($key['key_type']);
$table->cell(wordwrap( $key['key'], 60, "<br />\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
// 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();
}
$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) {
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();
}
// 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();
}
if ($role_objs) foreach ($role_objs as $role_obj) {
$table->row_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();
}
$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();
}
$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();
$table->end();
//////////////////////////////
-plc_form_end();
+$form->end();
$peers->block_end($peer_id);
// Print footer
$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" ) );
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'],
}
-plc_details_end();
+$details->end();
////////////////////////////////////////
$peers->block_end($peer_id);
$max_err= " style='border: 1px solid red;'";
// start form
-require_once 'plc_forms.php';
-plc_
-echo "<form action='update_site.php?id=$site_id' method='post'>\n";
+echo "<form action='site_update.php?id=$site_id' method='post'>\n";
echo "<h2>$do $name</h2>\n";
echo "<table><tbody>\n";
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
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");
// 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 = "<select name='min_role_id'>".
"<option value='20'>PI</option>".
"<option value='30'>User</option>" .
"<option value='40'>Tech</option>" . "</select>\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';
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();
}