4 <script type="text/javascript" src="/planetlab/tablesort/tablesort.js"></script>
5 <script type="text/javascript" src="/planetlab/tablesort/customsort.js"></script>
6 <script type="text/javascript" src="/planetlab/tablesort/paginate.js"></script>
7 <script type="text/javascript" src="/planetlab/js/plc_tables.js"></script>
8 <link href="/planetlab/css/plc_tables.css" rel="stylesheet" type="text/css" />
12 //// hash to retrieve the headers and options as passed at table-creation time
13 // this means that table_id's need to be different across the page,
14 // which is required anyway for the search and pagesize areas to work properly
15 $plc_table_hash=array();
17 ////////////////////////////////////////
18 function plc_table_cell($cell) {
19 printf ('<td class="plc_table"> %s </td>',$cell);
22 ////////////////////////////////////////
23 // table_id: <table>'s id tag
24 // headers: an associative array "label"=>"type"
25 // column_sort: the column to sort on at load-time
26 // options : an associative array to override options (should be passed to both _stsart and _end)
27 // - search_area : boolean (default true)
28 // - notes_area : boolean (default true)
29 // - notes : an array of additional notes
30 // - pagesize: the initial pagination size
31 // - pagesize_def: the page size when one clicks the pagesize reset button
32 // - max_pages: the max number of pages to display in the paginator
33 // - footers: a list of table rows (<tr> will be added) for building the table's tfoot area
34 function plc_table_start ($table_id, $headers, $column_sort, $options=NULL) {
35 if ( ! $options ) $options = array();
36 global $plc_table_hash;
37 $plc_table_hash[$table_id]=array($headers,$options);
38 $search_area = array_key_exists('search_area',$options) ? $options['search_area'] : true;
39 $max_pages = array_key_exists('max_pages',$options) ? $options['max_pages'] : 10;
40 $pagesize = array_key_exists('pagesize',$options) ? $options['pagesize'] : 25;
41 $pagesize_def = array_key_exists('pagesize_def',$options) ? $options['pagesize_def'] : 999;
44 plc_table_search_area($table_id,$pagesize,$pagesize_def);
45 plc_table_head($table_id,$headers,$column_sort,$max_pages,$pagesize);
48 // for convenience, the options that apply to the footer only can be passed in plc_table_end()
49 // they add up to the ones provided to the begin clause
50 // makes code more readable, as preparing the footer before the table is displayed is confusing
51 function plc_table_end ($table_id,$options_end=NULL) {
52 global $plc_table_hash;
53 list($headers,$options) = $plc_table_hash[$table_id];
55 $options=array_merge($options,$options_end);
57 plc_table_foot($options);
58 $notes_area = array_key_exists('notes_area',$options) ? $options['notes_area'] : true;
60 plc_table_notes($options);
64 function plc_table_search_area ($table_id,$pagesize,$pagesize_def) {
65 $pagesize_text_id = $table_id . "_pagesize";
66 $search_text_id = $table_id . "_search";
67 $search_reset_id = $table_id . "_search_reset";
68 $search_and_id = $table_id . "_search_and";
70 <table class='table_dialogs'> <tr>
71 <td class='table_flushleft'>
72 <form class='pagesize'>
73 <input class='pagesize_input' type='text' id="$pagesize_text_id" value=$pagesize
74 onkeyup='plc_pagesize_set("$table_id","$pagesize_text_id", $pagesize);'
76 <label class='pagesize_label'> items/page </label>
77 <img class='table_reset' src="/planetlab/icons/clear.png"
78 onmousedown='plc_pagesize_reset("$table_id","$pagesize_text_id",$pagesize_def);'>
82 <td class='table_flushright'>
83 <form class='table_search'>
84 <label class='table_search_label'> Search </label>
85 <input class='table_search_input' type='text' id='$search_text_id'
86 onkeyup='plc_table_filter("$table_id","$search_text_id","$search_and_id");'
87 size=40 maxlength=256 />
89 <input id='$search_and_id' class='table_search_and'
90 type='checkbox' checked='checked'
91 onchange='plc_table_filter("$table_id","$search_text_id","$search_and_id");' />
92 <img class='table_reset' src="/planetlab/icons/clear.png"
93 onmousedown='plc_table_filter_reset("$table_id","$search_text_id","$search_and_id");'>
100 ////////////////////////////////////////
101 function plc_table_head ($table_id,$headers,$column_sort,$max_pages,$pagesize) {
102 $paginator=$table_id."_paginator";
103 $classname="paginationcallback-".$paginator;
104 $classname.=" max-pages-" . $max_pages;
105 $classname.=" paginate-" . $pagesize;
107 <!-- instantiate paginator callback -->
108 <script type="text/javascript">
109 function $paginator (opts) { plc_table_paginator (opts,"$table_id"); }
112 <table id="$table_id" cellpadding="0" cellspacing="0" border="0"
113 class="plc_table sortable-onload-$column_sort rowstyle-alt colstyle-alt no-arrow $classname">
118 foreach ($headers as $label => $type) {
119 if ($type == "none" ) {
122 if ($type == "string") $type="";
123 if ($type == "int") $type="";
124 if ($type == "float") $type="";
126 if ( ! empty($type)) $class .= "-sort" . $type;
128 printf ('<th class="%s plc_table">%s</th>',$class,$label);
138 ////////////////////////////////////////
139 function plc_table_foot ($options) {
140 print "</tbody><tfoot>";
141 if ($options['footers'])
142 foreach ($options['footers'] as $footer)
143 print "<tr> $footer </tr>";
144 print "</tfoot></table>\n";
147 ////////////////////////////////////////
148 function plc_table_notes ($options) {
150 <p class='plc_filter_note'>
151 Notes: Enter & or | in the search area to alternate between <bold>AND</bold> and <bold>OR</bold> search modes
153 Hold down the shift key to select multiple columns to sort
155 if (array_key_exists('notes',$options)) {
156 foreach ($options['notes'] as $line) {
157 print "<br/>" . $line . "\n";
163 ////////////////////////////////////////
164 function plc_table_title ($text) {
165 print "<h2> $text </h2>\n";
168 function plc_table_row_start ($id="") {
170 printf ('<tr id="%s">',$id);
175 function plc_table_row_end () {
179 function plc_table_td_text ($text,$colspan=0,$align=NULL) {
182 if ($colspan) $result .= " colspan=$colspan";
183 if ($align) $result .= " style='text-align:$align'";
184 $result .= ">$text</td>";