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);
20 printf ('<td>%s</td>',$cell);
23 ////////////////////////////////////////
24 // table_id: <table>'s id tag - WARNING : do not use '-' in table ids as it's used for generating javascript code
25 // headers: an associative array "label"=>"type"
26 // column_sort: the column to sort on at load-time
27 // options : an associative array to override options (should be passed to both _stsart and _end)
28 // - search_area : boolean (default true)
29 // - pagesize_area : boolean (default true)
30 // - notes_area : boolean (default true)
31 // - search_width : size in chars of the search text dialog
32 // - notes : an array of additional notes
33 // - pagesize: the initial pagination size
34 // - pagesize_def: the page size when one clicks the pagesize reset button
35 // - max_pages: the max number of pages to display in the paginator
36 // - footers: an array of table rows (<tr> will be added) for building the table's tfoot area
37 function plc_table_start ($table_id, $headers, $column_sort, $options=NULL) {
38 if ( ! $options ) $options = array();
39 global $plc_table_hash;
40 $plc_table_hash[$table_id]=array($headers,$options);
41 $search_area = array_key_exists('search_area',$options) ? $options['search_area'] : true;
42 $pagesize_area = array_key_exists('pagesize_area',$options) ? $options['pagesize_area'] : true;
43 $max_pages = array_key_exists('max_pages',$options) ? $options['max_pages'] : 10;
44 $pagesize = array_key_exists('pagesize',$options) ? $options['pagesize'] : 25;
45 $pagesize_def = array_key_exists('pagesize_def',$options) ? $options['pagesize_def'] : 999;
46 $search_width = array_key_exists('search_width',$options) ? $options['search_width'] : 40;
48 $paginator=$table_id."_paginator";
49 $classname="paginationcallback-".$paginator;
50 $classname.=" max-pages-" . $max_pages;
51 $classname.=" paginate-" . $pagesize;
52 // instantiate paginator callback
54 <script type="text/javascript">
55 function $paginator (opts) { plc_table_paginator (opts,"$table_id"); }
58 <table id="$table_id" cellpadding="0" cellspacing="0" border="0"
59 class="plc_table sortable-onload-$column_sort rowstyle-alt colstyle-alt no-arrow $classname">
63 if ($pagesize_area) plc_table_pagesize_area ($table_id,$headers,$pagesize, $pagesize_def);
64 if ($search_area) plc_table_search_area ($table_id, $headers, $search_width);
67 foreach ($headers as $label => $type) {
68 if ($type == "none" ) {
71 if ($type == "string") $type="";
72 if ($type == "int") $type="";
73 if ($type == "float") $type="";
75 if ( ! empty($type)) $class .= "-sort" . $type;
77 printf ('<th class="%s plc_table">%s</th>',$class,$label);
88 function plc_table_pagesize_area ($table_id,$headers,$pagesize,$pagesize_def) {
89 $width=count($headers);
90 $pagesize_text_id = $table_id . "_pagesize";
92 <tr class=pagesize_area><td class=pagesize_area colspan=$width><form class='pagesize'>
93 <input class='pagesize_input' type='text' id="$pagesize_text_id" value=$pagesize
94 onkeyup='plc_pagesize_set("$table_id","$pagesize_text_id", $pagesize);'
96 <label class='pagesize_label'> items/page </label>
97 <img class='table_reset' src="/planetlab/icons/clear.png"
98 onmousedown='plc_pagesize_reset("$table_id","$pagesize_text_id",$pagesize_def);' />
104 function plc_table_search_area ($table_id,$headers,$search_width) {
105 $width=count($headers);
106 $search_text_id = $table_id . "_search";
107 $search_reset_id = $table_id . "_search_reset";
108 $search_and_id = $table_id . "_search_and";
110 <tr class=search_area><td class=search_area colspan=$width><form class='table_search'>
111 <label class='table_search_label'> Search </label>
112 <input class='table_search_input' type='text' id='$search_text_id'
113 onkeyup='plc_table_filter("$table_id","$search_text_id","$search_and_id");'
114 size=$search_width maxlength=256 />
116 <input id='$search_and_id' class='table_search_and'
117 type='checkbox' checked='checked'
118 onchange='plc_table_filter("$table_id","$search_text_id","$search_and_id");' />
119 <img class='table_reset' src="/planetlab/icons/clear.png"
120 onmousedown='plc_table_filter_reset("$table_id","$search_text_id","$search_and_id");'>
125 ////////////////////////////////////////
126 // for convenience, the options that apply to the footer only can be passed in plc_table_end()
127 // they add up to the ones provided to the begin clause
128 // makes code more readable, as preparing the footer before the table is displayed is confusing
129 function plc_table_end ($table_id,$options_end=NULL) {
130 global $plc_table_hash;
131 list($headers,$options) = $plc_table_hash[$table_id];
133 $options=array_merge($options,$options_end);
135 plc_table_foot($options);
136 $notes_area = array_key_exists('notes_area',$options) ? $options['notes_area'] : true;
138 plc_table_notes($options);
141 ////////////////////////////////////////
142 function plc_table_foot ($options) {
143 print "</tbody><tfoot>";
144 if ($options['footers'])
145 foreach ($options['footers'] as $footer)
146 print "<tr> $footer </tr>";
147 print "</tfoot></table>\n";
150 ////////////////////////////////////////
151 function plc_table_notes ($options) {
153 <p class='plc_filter_note'>
154 Notes: Enter & or | in the search area to alternate between <bold>AND</bold> and <bold>OR</bold> search modes
156 Hold down the shift key to select multiple columns to sort
158 if (array_key_exists('notes',$options)) {
159 foreach ($options['notes'] as $line) {
160 print "<br/>" . $line . "\n";
166 ////////////////////////////////////////
167 function plc_table_row_start ($id="") {
169 printf ('<tr id="%s">',$id);
174 function plc_table_row_end () {
178 function plc_table_td_text ($text,$colspan=0,$align=NULL) {
181 if ($colspan) $result .= " colspan=$colspan";
182 if ($align) $result .= " style='text-align:$align'";
183 $result .= ">$text</td>";