$details = new PlcDetails (true);
$details->start();
-$details->single ($form->submit_html('submit','Show Events'),'center');
+$details->tr ($form->submit_html('submit','Show Events'),'center');
$details->space();
-$details->line ( $form->radio_html ('events','type','Event',true) . "Events",
+$details->th_td ( $form->radio_html ('events','type','Event',true) . "Events",
$form->text_html('event','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'events.checked=true')));
-$details->line ( $form->radio_html ('sites','type','Site',false) . "Sites",
+$details->th_td ( $form->radio_html ('sites','type','Site',false) . "Sites",
$form->text_html('site','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'sites.checked=true')));
-$details->line ( $form->radio_html ('persons','type','Person',false) . "Persons",
+$details->th_td ( $form->radio_html ('persons','type','Person',false) . "Persons",
$form->text_html('person','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'persons.checked=true')));
-$details->line ( $form->radio_html ('nodes','type','Node',false) . "Nodes",
+$details->th_td ( $form->radio_html ('nodes','type','Node',false) . "Nodes",
$form->text_html('node','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'nodes.checked=true')));
-$details->line ( $form->radio_html ('slices','type','Slice',false) . "Slices",
+$details->th_td ( $form->radio_html ('slices','type','Slice',false) . "Slices",
$form->text_html('slice','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'slices.checked=true')));
$details->space();
-$details->single ($form->submit_html('submit','Show Events'),'center');
+$details->tr ($form->submit_html('submit','Show Events'),'center');
$details->space();
-$details->line_th(html_div($from_picker->html()) , html_div($until_picker->html()));
+$details->th_th(html_div($from_picker->html()) , html_div($until_picker->html()));
$details->end();
$form->end();
// fieldname=>value
// and we add in-line editing capabilities
+// $editable : if not set, no edition will be allowed in the table
+// this is typically set to false when user does not have write access
+// then each individual th_td provides its form_varname if and only iff edition is desired
+
+// start & end :create and close a 2-columns table
+// th_td -> display label & value, with optional inline editing capability
+// th_tds -> not editable, display a (vertical) list of values in the <td> area
+// th_th : special cases, display 2 <th>
+// xxx todo : accept optional arguments as an options hash, rather than using the set_ methods which are ugly
+
class PlcDetails {
var $editable;
var $form;
+ // various options for the editing area
// set manually
- var $field_width;
- var $field_height;
- var $input_type="text";
+ var $width;
+ var $height;
+ var $input_type;
function PlcDetails ($editable) {
$this->editable=$editable;
$this->form=NULL;
- $this->field_width="";
- $this->field_height="2";
+ $this->width="";
+ $this->height="2";
+ $this->input_type="text";
}
function form() { return $this->form; }
return $html;
}
- // must be embedded in a line or a single
+ //////////////////// several forms for submit button
// xxx need a way to ask for confirmation
+
+ // must be embedded in a th_td or a tr
function submit_html ($name,$display) {
if ( ! $this->form) return "";
if ( ! $this->editable) return "";
return $this->form->submit_html($name,$display);
}
+ function tr_submit_html ($name,$display) {
+ if ( ! $this->form) return "";
+ if ( ! $this->editable) return "";
+ return $this->tr_html($this->form->submit_html($name,$display),"right");
+ }
+ function tr_submit ($name,$display) { print $this->tr_submit_html ($name,$display); }
+
+
+ ////////////////////////////////////////
+ function set_width ($width) {
+ $old=$this->width;
+ $this->width=$width;
+ return $old;
+ }
+ function set_height ($height) {
+ $old=$this->height;
+ $this->height=$height;
+ return $old;
+ }
// 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 th_td ($title,$value,$form_varname="",$options=NULL) {
+ print $this->th_td_html ($title,$value,$form_varname,$options);
}
- function line_html ($title,$value,$form_varname="") {
+ function th_td_html ($title,$value,$form_varname="",$options=NULL) {
if ( ! ($this->editable && $form_varname) ) {
return "<tr><th>$title</th><td>$value</td></tr>";
} else {
+ if (!$options) $options = array();
+ // use options if provided, otherwise the latest set_ function
+ if (array_key_exists('input_type',$options)) $input_type=$options['input_type'];
+ else $input_type=$this->input_type;
+ if (array_key_exists('width',$options)) $width=$options['width'];
+ else $width=$this->width;
+ if (array_key_exists('height',$options)) $height=$options['height'];
+ else $height=$this->height;
+
$html="";
$html .= "<tr><th><label for=$form_varname>$title</label></th>";
$html .= "<td>";
// hack: if input_type is select : user provides the input field verbatim
- if ( $this->input_type == "select" ) {
+ if ( $input_type == "select" ) {
$html .= $value;
- } else if ($this->input_type == "textarea") {
+ } else if ($input_type == "textarea") {
$html .= "<textarea name='$form_varname'";
- if ($this->field_width) $html .= " cols=$this->field_width";
- if ($this->field_height) $html .= " rows=$this->field_height";
+ if ($width) $html .= " cols=$width";
+ if ($height) $html .= " rows=$height";
$html .= ">$value</textarea>";
} else {
- $html .= "<input type='$this->input_type' name='$form_varname' value='$value'";
- if ($this->field_width) $html .= " size=$this->field_width";
+ $html .= "<input type='$input_type' name='$form_varname' value='$value'";
+ if ($width) $html .= " size=$width";
$html .= "/>";
}
$html .= "</td></tr>";
}
// 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"));
+ function th_tds($title,$list) { print $this->th_tds_html($title,$list); }
+ function th_tds_html($title,$list) {
+ return $this->th_td_html($title,plc_vertical_table($list,"foo"));
}
- function line_th ($th1,$th2) { print $this->line_th_html ($th1, $th2);}
- function line_th_html ($th1, $th2) {
+ // only for special cases, not editable
+ function th_th ($th1,$th2) { print $this->th_th_html ($th1, $th2);}
+ function th_th_html ($th1, $th2) {
return "<tr><th>$th1</th><th>$th2</th></tr>";
}
// 1 item, colspan=2
- function single($title,$align=NULL) { print $this->single_html($title,$align);}
- function single_html($title,$align=NULL) {
+ function tr($title,$align=NULL) { print $this->tr_html($title,$align);}
+ function tr_html($title,$align=NULL) {
$result="<tr><td colspan=2";
if ($align) $result .= " style='text-align:$align'";
$result .=">$title</td></tr>";
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;
- }
-
}
?>
// extra privileges to admins, and (pi||tech) on this site
-$privileges = plc_is_admin () || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
+$privileges = (plc_is_admin () && $local_peer) || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
$tabs=array();
// available actions
$details=new PlcDetails($privileges);
$details->start();
if ( ! $local_peer) {
- $details->line("Peer",$peers->peer_link($peer_id));
+ $details->th_td("Peer",$peers->peer_link($peer_id));
$details->space();
}
$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->th_td("Hostname",$hostname,"hostname");
+$details->th_td("Model",$model,"model");
+$details->tr_submit("submit","Update Node");
$details->form_end();
+if ($privileges) $details->space();
-$details->line("Type",$node_type);
-$details->line("Version",$version);
+$details->th_td("Type",$node_type);
+$details->th_td("Version",$version);
// let's use plc_objects
$Node = new Node($node);
-$details->line("Date created",$Node->dateCreated());
-$details->line("Last contact",$Node->lastContact());
-$details->line("Last update",$Node->lastUpdated());
+$details->th_td("Date created",$Node->dateCreated());
+$details->th_td("Last contact",$Node->lastContact());
+$details->th_td("Last update",$Node->lastUpdated());
// boot area
$details->space ();
$boot_value .= $boot_form->select_html("boot_state",$selectors,NULL,true);
$boot_value .= $boot_form->end_html();
}
-$details->line ("Boot state",$boot_value);
+$details->th_td ("Boot state",$boot_value);
// same here for the download area
if ( $local_peer && $privileges) {
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);
+ $details->th_td ("Download",$download_value);
}
// site info and all site nodes
$details->space ();
-$details->line("Site",l_site_t($site_id,$site_name));
+$details->th_td("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);
}
-$details->lines ("All site nodes",$nodes_area);
+$details->th_tds ("All site nodes",$nodes_area);
$details->end ();
function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
$selector=array_map("tag_selector",$all_tags);
$table->cell($form->select_html("tag_type_id",$selector,"Choose"));
- $table->cell($form->text_html("value","",array('width'=>8));
+ $table->cell($form->text_html("value","",array('width'=>8)));
$table->cell($form->submit_html("set-tag-on-node","Set Tag"),2,"left");
$table->row_end();
}
$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']);
+$details->th_td("Peer name",$peer['peername']);
+$details->th_td("Short name",$peer['shortname']);
+$details->th_td("Hierarchical name",$peer['hrn_root']);
+$details->th_td("API URL",$peer['peer_url']);
$nb=sizeof($peer['site_ids']);
-$details->line("Number of sites",href(l_sites_peer($peer_id),"$nb sites"));
+$details->th_td("Number of sites",href(l_sites_peer($peer_id),"$nb sites"));
$nb=sizeof($peer['node_ids']);
-$details->line("Number of nodes",href(l_nodes_peer($peer_id),"$nb nodes"));
+$details->th_td("Number of nodes",href(l_nodes_peer($peer_id),"$nb nodes"));
$nb=sizeof($peer['person_ids']);
-$details->line("Number of users",href(l_persons_peer($peer_id),"$nb users"));
+$details->th_td("Number of users",href(l_persons_peer($peer_id),"$nb users"));
$nb=sizeof($peer['slice_ids']);
-$details->line("Number of slices",href(l_slices_peer($peer_id),"$nb slices"));
+$details->th_td("Number of slices",href(l_slices_peer($peer_id),"$nb slices"));
$details->end();
// Print footer
$enabled_label="Yes";
if ( ! $enabled ) $enabled_label = plc_warning_html("Disabled");
-$can_update = $is_my_account || plc_is_admin();
+$can_update = (plc_is_admin() && $local_peer) || $is_my_account;
$details = new PlcDetails($can_update);
$details->form_start(l_actions(),array("action"=>"update-person",
"person_id"=>$person_id));
$details->start();
-$details->line("Enabled",$enabled_label);
-$details->line("Peer",$peers->peer_link($peer_id));
-$details->space();
-// xxx this needs some more work on the PlcDetails class
-$details->set_field_width(5);
-$details->line("Title",$title,"title");
-$details->set_field_width("");
-$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("Phone",$phone,"phone");
-$save_w=$details->set_field_width(40);
-$details->line("URL",$url,"url");
-$details->set_field_height(4);
-$details->set_input_type("textarea");
-$details->line("Bio",$bio,"bio");
-$details->set_input_type("text");
-$details->set_field_width($save_w);
+
+
+$details->th_td("Title",$title,"title",array('width'=>5));
+$details->th_td("First Name",$first_name,"first_name");
+$details->th_td("Last Name",$last_name,"last_name");
+$details->th_td(href("mailto:$email","Email"),$email,"email");
+$details->th_td("Phone",$phone,"phone");
+$details->th_td("URL",$url,"url",array('width'=>40));
+$details->th_td("Bio",$bio,"bio",array('input_type'=>'textarea','height'=>4));
// xxx need to check that this is working
if ($can_update) {
- $save_i=$details->set_input_type("password");
- $details->line("Password","","password1");
- $details->line("Repeat","","password2");
- $details->set_input_type($save_i);
+ $details->th_td("Password","","password1",array('input_type'=>'password'));
+ $details->th_td("Repeat","","password2",array('input_type'=>'password'));
+ $details->tr_submit("submit","Update Account");
+ $details->space();
+ }
+
+$details->th_td("Enabled",$enabled_label);
+if ( ! $local_peer ) {
+ $details->th_td("Peer",$peers->peer_link($peer_id));
+ $details->space();
}
-// xxx need fields to reset password ?
-$details->line("",$details->submit_html("submit","Update Account"));
$details->end();
$details->form_end();
$tabs['My accounts'] = array('url'=>l_persons(),
'values'=>array('site_id'=>plc_my_site_id()),
'bubble'=>'Lists accounts on site ' . plc_my_site_id());
+if (plc_is_admin())
+ $tabs['Local accounts'] = array('url'=>l_persons(),
+ 'values'=>array('peerscope'=>'local'));
// --------------------
$person_filter=array();
}
$headers = array ("Peer"=>"string",
- "Roles"=>"string",
"First"=>"string",
"Last"=>"string",
"Email"=>"string",
"Site" => "string",
+ "Roles"=>"string",
"S" => "int",
"Status"=>"string",
);
$table->row_start();
$table->cell($shortname);
- $table->cell($roles);
$table->cell ($person['first_name']);
$table->cell ($person['last_name']);
$table->cell(l_person_t($person_id,$email));
- $table->cell($login_base);
+ $table->cell(l_site_t($site_id,$login_base));
+ $table->cell($roles);
$table->cell(count($person['slice_ids']));
$table->cell(person_status($person));
$table->row_end();
href (l_sites_pending(),"this page") .
" to review pending applications.");
-$can_update=plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
+$can_update=(plc_is_admin () && $local_peer) || ( plc_in_site($site_id) && plc_is_pi());
$details = new PlcDetails($can_update);
if ( ! $site['is_public'])
plc_warning("This site is not public!");
$details->start();
-$details->line("Peer",$peers->peer_link($peer_id));
-$details->space();
$details->form_start(l_actions(),array('action'=>'update-site','site_id'=>$site_id));
-$save_w=$details->set_field_width(30);
-$details->line("Full name",$sitename,'name');
-$details->set_field_width($save_w);
-$details->line("Abbreviated name",$abbreviated_name,'abbreviated_name');
-$details->line("URL",$site_url,'url');
-$details->line("Latitude",$site_lat,'latitude');
-$details->line("Longitude",$site_long,'longitude');
+$details->th_td("Full name",$sitename,'name',array('width'=>50));
+$details->th_td("Abbreviated name",$abbreviated_name,'abbreviated_name',array('width'=>15));
+$details->th_td("URL",$site_url,'url',array('width'=>50));
+$details->th_td("Latitude",$site_lat,'latitude');
+$details->th_td("Longitude",$site_long,'longitude');
+
+// modifiable by admins only
if (plc_is_admin())
- $details->line("Login base",$login_base,'login_base');
+ $details->th_td("Login base",$login_base,'login_base',array('width'=>12));
else
- $details->line("Login base",$login_base);
+ $details->th_td("Login base",$login_base);
if (plc_is_admin())
- $details->line("Max slices",$max_slices,'max_slices');
+ $details->th_td("Max slices",$max_slices,'max_slices');
else
- $details->line("Max slices",$max_slices);
-$details->line("",$details->submit_html("submit","Update Site"));
+ $details->th_td("Max slices",$max_slices);
+$details->tr_submit("submit","Update Site");
$details->form_end();
+if ( ! $local_peer) {
+ $details->space();
+ $details->th_td("Peer",$peers->peer_link($peer_id));
+ }
+
if ( $local_peer ) {
// Nodes
$nb_boot = 0;
if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++;
$node_label = $nb_boot . " boot / " . count($nodes) . " total";
- $details->line("# Nodes", href(l_nodes_site($site_id),$node_label));
+ $details->th_td("# 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_label= plc_vertical_table(array_map ("n_link",$nodes));
- $details->line ("Hostnames",$nodes_label);
+ $details->th_td ("Hostnames",$nodes_label);
$button=new PlcFormButton (l_node_add(),"add_node","Add node","POST");
- $details->line("",$button->html());
+ $details->tr($button->html(),"right");
// Users
$details->space();
count ($techs) . " Techs";
if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >=50))
$user_label = plc_warning_html ($user_label);
- $details->line ("# Users",href(l_persons_site($site_id),$user_label));
+ $details->th_td ("# Users",href(l_persons_site($site_id),$user_label));
function p_link ($p) { return l_person_t($p['person_id'],$p['email']); }
// PIs
- $details->line("PI's",plc_vertical_table (array_map ("p_link",$pis)));
+ $details->th_td("PI's",plc_vertical_table (array_map ("p_link",$pis)));
// techs
- $details->line("Techs's",plc_vertical_table (array_map ("p_link",$techs)));
+ $details->th_td("Techs's",plc_vertical_table (array_map ("p_link",$techs)));
if (count ($disabled_persons))
- $details->line("Disabled",plc_vertical_table (array_map ("p_link",$disabled_persons)));
+ $details->th_td("Disabled",plc_vertical_table (array_map ("p_link",$disabled_persons)));
// Slices
$details->space();
$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));
+ $details->th_td("# Slices", href(l_slices_site($site_id),$slice_label));
if ($slices) foreach ($slices as $slice)
- $details->line($slice['instantiation'],l_slice_obj($slice));
+ $details->th_td($slice['instantiation'],l_slice_obj($slice));
$button=new PlcFormButton (l_slice_add(),"slice_add","Add slice","POST");
- $details->line("",$button->html());
+ $details->tr($button->html(),"right");
// Addresses
if ($addresses) {
$details->space();
- $details->line("Addresses","");
+ $details->th_td("Addresses","");
foreach ($addresses as $address) {
- $details->line(plc_vertical_table($address['address_types']),
+ $details->th_td(plc_vertical_table($address['address_types']),
plc_vertical_table(array($address['line1'],
$address['line2'],
$address['line3'],
$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->th_td ("Node group name",$nodegroup['groupname']);
+$details->th_td ("Based on tag",href(l_tag($nodegroup['tag_type_id']),$tagname));
+$details->th_td("Matching value",$nodegroup['value']);
+$details->th_td("# nodes",count($nodegroup['node_ids']));
$details->end();
// xxx : add & delete buttons would make sense here too
$details->form_start(l_actions(),array("action"=>"update-tag-type",
"tag_type_id"=>$tag_type_id));
$details->start();
-$details->line("Name",$tagname,"tagname");
-$details->line("Category",$category,"category");
-$details->line("Description",$description,"description");
+$details->th_td("Name",$tagname,"tagname");
+$details->th_td("Category",$category,"category");
+$details->th_td("Description",$description,"description");
// xxx misses in PlcDetails
if ($can_update) {
$selectors = $details->form()->role_selectors($api,"",$min_role_id);
$select_field = $details->form()->select_html("min_role_id",$selectors);
$save_i=$details->set_input_type("select");
- $details->line("Min role",$select_field,"min_role_id");
+ $details->th_td("Min role",$select_field,"min_role_id");
$details->set_input_type($save_i);
} else {
- $details->line("Min role",$min_role_id);
+ $details->th_td("Min role",$min_role_id);
}
if ($can_update)
- $details->single($details->form()->submit_html('update-tag-type',"Update tag type"),"right");
+ $details->tr_submit('update-tag-type',"Update tag type");
$details->space();
-$details->line("Used in nodes",count($node_tags));
-$details->line("Used in interfaces",count($interface_tags));
-$details->line("Used in slices",count($slice_tags));
-$details->line("Used in slivers",count($sliver_tags));
+$details->th_td("Used in nodes",count($node_tags));
+$details->th_td("Used in interfaces",count($interface_tags));
+$details->th_td("Used in slices",count($slice_tags));
+$details->th_td("Used in slivers",count($sliver_tags));
$details->end();
$details->form_end();