// - pagesize: the initial pagination size
// - pagesize_def: the page size when one clicks the pagesize reset button
// - max_pages: the max number of pages to display in the paginator
-// - footers: an array of table rows (<tr> will be added) for building the table's tfoot area
class PlcTable {
// mandatory
var $pagesize_def; // the page size when one clicks the pagesize reset button
var $max_pages; // the max number of pages to display in the paginator
var $notes; // an array of additional notes
- var $footers; // an array of table rows (<tr> will be added) for building the table's tfoot area
+ var $has_tfoot;
function PlcTable ($table_id,$headers,$column_sort,$options=NULL) {
$this->table_id = $table_id;
$this->headers = $headers;
$this->column_sort = $column_sort;
+
+ $this->has_tfoot=false;
$this->search_area = true;
$this->pagesize_area = true;
$this->pagesize_def = 999;
$this->max_pages = 10;
$this->notes = array();
- $this->footers = array();
$this->set_options ($options);
}
if (array_key_exists('max_pages',$options)) $this->max_pages=$options['max_pages'];
if (array_key_exists('notes',$options)) $this->notes=array_merge($this->notes,$options['notes']);
- if (array_key_exists('footers',$options)) $this->footers=array_merge($this->footers,$options['footers']);
+ }
+
+ public function columns () {
+ return count ($this->headers);
}
////////////////////
}
////////////////////
- // for convenience, the options that apply to the footer can be passed here
- // typically footers or notes will add up to the ones provided so far
- // makes code more readable, as preparing the footer before the table is displayed is confusing
+ // for convenience, the options that apply to the bottom area can be passed here
+ // typically notes will add up to the ones provided so far, and to the default ones
+ // xxx default should be used only if applicable
function end ($options=NULL) {
$this->set_options($options);
- print $this->foot_text();
+ print $this->bottom_text();
if ($this->notes_area)
print $this->notes_area_text();
}
return $result;
}
+ //////////////////// start a <tfoot> section
+ function tfoot_start () {
+ print $this->tfoot_start_text();
+ }
+
+ function tfoot_start_text () {
+ $this->has_tfoot=true;
+ return "</tbody><tfoot>";
+ }
+
////////////////////////////////////////
- function foot_text () {
+ function bottom_text () {
$result="";
- $result .= "</tbody><tfoot>\n";
- if ($this->footers)
- foreach ($this->footers as $footer)
- $result .="<tr>$footer</tr>\n";
- $result .= "</tfoot></table>\n";
+ if ($this->has_tfoot)
+ $result .= "</tfoot>";
+ else
+ $result .= "</tbody>";
+ $result .= "</table>\n";
return $result;
}
}
////////////////////
- public function cell_text ($cell) {
- return "<td>$cell</td>";
- }
- public function cell ($cell) {
- print $this->cell_text($cell);
+ public function cell ($text,$colspan=0,$align=NULL) {
+ print $this->cell_text ($text,$colspan,$align);
}
-
- public static function td_text ($text,$colspan=0,$align=NULL) {
+ public function cell_text ($text,$colspan=0,$align=NULL) {
$result="";
$result .= "<td";
if ($colspan) $result .= " colspan=$colspan";
plc_section("Tags");
$headers=array("Name"=>"string",
"Value"=>"string",
- "Nodegroup"=>"string");
+ "Nodegroup"=>"string",
+ "Remove"=>"string",
+ );
$table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
$table=new PlcTable("node_tags",$headers,0,$table_options);
$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']));
$table->row_end();
}
- $footers=array();
if ($privileges) {
- // remove selected sites
+ $table->tfoot_start();
+
+ // remove tag
+ $table->row_start();
+ $table->cell(plc_form_submit_text("remove-node-tags","Remove Tags"),
+ // use the whole columns and right adjust
+ $table->columns(), "right");
+ $table->row_end();
+
+ // set tag area
+ $table->row_start();
// get list of tag names in the node/* category
$all_tags= $api->GetTagTypes( array ("category"=>"node*"), array("tagname","tag_type_id"));
-
// 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);
- $add_tag_name=plc_form_select_text("tag_type_id",$selector,"Choose");
- $add_tag_value=plc_form_text_text("value","",8);
- $add_tag_submit=plc_form_submit_text("set-tag-on-node","Set Tag");
-
- $add_tag_footer=PlcTable::td_text($add_tag_name).PlcTable::td_text($add_tag_value).PlcTable::td_text($add_tag_submit);
- $footers[]= $add_tag_footer;
+ $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->row_end();
}
- $table->end(array('footers'=>$footers));
+ $table->end();
}
//////////////////////////////////////////////////////////// slices
$table->row_end();
}
if ($privileges) {
- $button=plc_form_simple_button(l_interface_add($node_id),"Add interface","GET");
- $footers=array(PlcTable::td_text($button,6,"right"));
+ $table->tfoot_start();
+ $table->row_start();
+ $table->cell(plc_form_simple_button(l_interface_add($node_id),"Add interface","GET"),
+ $table->columns(),"right");
+ $table->row_end();
}
- $table->end(array("footers"=>$footers));
+ $table->end();
}
}
$table->row_end();
}
// the footer area is used for displaying key-management buttons
-$footers=array();
// add the 'remove keys' button and key upload areas as the table footer
if ($can_manage_keys) {
- $remove_keys_area=plc_form_submit_text ("delete-keys","Remove keys");
- $upload_key_left_area= plc_form_label_text("key","Upload new key") . plc_form_file_text("key",60);
- $upload_key_right_area=plc_form_submit_text("upload-key","Upload key");
+ $table->tfoot_start();
// no need to remove if there's no key
- if ($keys)
- $footers[]="<td colspan=3 style='text-align:right'> $remove_keys_area </td>";
- // upload a new key
- $footers []="<td colspan=2 style='text-align:right'> $upload_key_left_area </td>".
- "<td> $upload_key_right_area </td>";
+ if ($keys) {
+ $table->row_start();
+ $table->cell(plc_form_submit_text ("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->columns()-1,"right");
+ $table->cell(plc_form_submit_text("upload-key","Upload key"));
+ $table->row_end();
}
-$table->end(array("footers"=>$footers));
+$table->end();
//////////////////// sites
plc_section('Sites');
$table->cell (plc_form_checkbox_text('site_ids[]',$site_id));
$table->row_end ();
}
-// footers : the remove and add buttons
-$footers=array();
if ($can_manage_sites) {
- // remove selected sites
- $remove_sites_area = plc_form_submit_text("remove-person-from-sites","Remove Sites");
+ $table->tfoot_start();
+
+ if ($sites) {
+ $table->row_start();
+ $table->cell(plc_form_submit_text("remove-person-from-sites","Remove Sites"),
+ $table->columns(),"right");
+ $table->row_end();
+ }
+
+ $table->row_start();
- // add a site : the button
- $add_site_right_area=plc_form_submit_text("add-person-to-site","Add in site");
// get list of local sites that the person is not in
function get_site_id ($site) { return $site['site_id'];}
$person_site_ids=array_map("get_site_id",$sites);
$relevant_sites= $api->GetSites( array("peer_id"=>NULL,"~site_id"=>$person_site_ids), $site_columns);
-
// xxx cannot use onchange=submit() - would need to somehow pass action name
- $selector=array();
- foreach ($relevant_sites as $site)
- $selector[]= array('display'=>$site['name'],"value"=>$site['site_id']);
- $add_site_left_area=plc_form_select_text("site_id",$selector,"Choose a site to add");
- $add_site_area = $add_site_left_area . $add_site_right_area;
- if ($sites)
- $footers[]=PlcTable::td_text ($remove_sites_area,3,"right");
- // add a new site
- $footers []= PlcTable::td_text ($add_site_area,3,"right");
+ 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->columns(),"right");
+ $table->row_end();
}
-$table->end(array("footers"=>$footers));
+$table->end();
//////////////////// roles
plc_section("Roles");
}
// footers : the remove and add buttons
-$footers=array();
if ($can_manage_roles) {
- // remove selected roles
- $remove_roles_area = plc_form_submit_text("remove-roles-from-person","Remove Roles");
+ $table->tfoot_start();
+ if ($roles) {
+ $table->row_start();
+ $table->cell(plc_form_submit_text("remove-roles-from-person","Remove Roles"),
+ $table->columns(),"right");
+ $table->row_end();
+ }
- // add a role : the button
- $add_role_right_area=plc_form_submit_text("add-role-to-person","Add role");
+ $table->row_start();
// get list of local roles that the person has not yet
// xxx this does not work because GetRoles does not support filters
$relevant_roles = $api->GetRoles( array("~role_id"=>$role_ids));
-
- $selector=array();
- foreach ($relevant_roles as $role)
- $selector[]= array('display'=>$role['name'],"value"=>$role['role_id']);
- $add_role_left_area=plc_form_select_text("role_id",$selector,"Choose a role to add");
- $add_role_area = $add_role_left_area . $add_role_right_area;
- if ($roles)
- $footers[]="<td colspan=3 style='text-align:right'> $remove_roles_area </td>";
- // add a new role
- $footers[]="<td colspan=3 style='text-align:right'> $add_role_area </td>";
+ 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 a role : the button
+ $add_role_right_area=plc_form_submit_text("add-role-to-person","Add role");
+ $table->cell ($add_role_left_area . $add_role_right_area,
+ $table->columns(),"right");
+ $table->row_end();
}
-$table->end(array("footers"=>$footers));
+$table->end();
//////////////////////////////
plc_form_end();
"Nodes"=>"int");
# initial sort on groupname
-plc_table_start("nodegroups",$headers,0);
+$table=new PlcTable("nodegroups",$headers,0);
+$table->start();
foreach ($nodegroups as $nodegroup) {
$table->row_start();
$table->row_end();
}
-plc_table_end("nodegroups");
+$table->end();
// Print footer
include 'plc_footer.php';
$table->cell($tag_type['category']);
$table->row_end();
}
-$footers=array();
-if (plc_is_admin())
- $footers[]=PlcTable::td_text(plc_form_simple_button(l_tag_add(),"Add a Tag Type","GET"),6,"right");
+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");
+ $table->row_end();
+ }
-$table->end(array('footers'=>$footers));
+$table->end();
// Print footer
include 'plc_footer.php';