checkpoint
[plewww.git] / planetlab / includes / plc_tables.php
1 <?php
2
3 drupal_set_html_head('
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" />
9 ');
10
11
12 ////////////////////////////////////////
13 // table_id: <table>'s id tag
14 // headers: an associative array "label"=>"type" 
15 // column_sort: the column to sort on at load-time
16 // search_area : boolean
17 // pagesize: the initial pagination size
18 // pagesize_def: the page size when one clicks the pagesize reset button
19 // max_pages: the max number of pages to display in the paginator
20 function plc_table_start ($table_id, $headers, $column_sort,
21                           $search_area=true,$max_pages="10",$pagesize="25",$pagesize_def="999") {
22   if ($search_area) {
23     plc_table_search_area($table_id,$pagesize,$pagesize_def);
24   }
25   plc_table_head($table_id,$headers,$column_sort,$max_pages,$pagesize);
26 }
27
28 function plc_table_end () {
29   plc_table_foot();
30 }
31                     
32 ////////////////////
33 function plc_table_search_area ($table_id,$pagesize,$pagesize_def) {
34   $pagesize_text_id = $table_id . "_pagesize";
35   $search_text_id = $table_id . "_search";
36   $search_reset_id = $table_id . "_search_reset";
37   $search_and_id = $table_id . "_search_and";
38   print <<< EOF
39 <table class='table_dialogs'> <tr>
40 <td class='table_flushleft'>
41 <form class='pagesize'>
42    <input class='pagesize_input' type='text' id="$pagesize_text_id" value=$pagesize 
43       onkeyup='plc_pagesize_set("$table_id","$pagesize_text_id", $pagesize);' 
44       size=3 maxlength=3 /> 
45   <label class='pagesize_label'> items/page </label>   
46   <img class='table_reset' src="/planetlab/icons/clear.png" 
47       onmousedown='plc_pagesize_reset("$table_id","$pagesize_text_id",$pagesize_def);'>
48 </form>
49 </td>
50
51 <td class='table_flushright'> 
52 <form class='table_search'>
53    <label class='table_search_label'> Search </label> 
54    <input class='table_search_input' type='text' id='$search_text_id'
55       onkeyup='plc_table_filter("$table_id","$search_text_id","$search_and_id");'
56       size=40 maxlength=256 />
57    <label>and</label>
58    <input id='$search_and_id' class='table_search_and' 
59       type='checkbox' checked='checked' 
60       onchange='plc_table_filter("$table_id","$search_text_id","$search_and_id");' />
61    <img class='table_reset' src="/planetlab/icons/clear.png" 
62       onmousedown='plc_table_filter_reset("$table_id","$search_text_id","$search_and_id");'>
63 </form>
64 </td>
65 </tr></table>
66 EOF;
67 }
68
69 ////////////////////////////////////////
70 function plc_table_head ($table_id,$headers,$column_sort,$max_pages,$pagesize) {
71   $paginator=$table_id."_paginator";
72   $classname="paginationcallback-".$paginator;
73   $classname.=" max-pages-" . $max_pages;
74   $classname.=" paginate-" . $pagesize;
75   print <<< EOF
76 <!-- instantiate paginator callback -->
77 <script type"text/javascript"> 
78 function $paginator (opts) { plc_table_paginator (opts,"$table_id"); }
79 </script>
80 <br/>
81 <table id="$table_id" cellpadding="0" cellspacing="0" border="0" 
82 class="plc_table sortable-onload-$column_sort rowstyle-alt colstyle-alt no-arrow $classname">
83 <thead>
84 <tr>
85 EOF;
86
87   foreach ($headers as $label => $type) {
88     if ($type == "string") $type="";
89     if ($type == "int") $type="";
90     if ($type == "float") $type="";
91     $class="sortable";
92     if ( ! empty($type)) $class .= "-" . $type;
93     print '<th class="' . $class . ' plc_table">' . $label . "</th>\n";
94   }
95
96   print <<< EOF
97 </tr>
98 </thead>
99 <tbody>
100 EOF;
101 }
102
103 ////////////////////////////////////////
104 function plc_table_foot () {
105   print <<< EOF
106 </tbody>
107 <tfoot>
108 </tfoot>
109 </table>
110 EOF;
111 }
112
113 ////////////////////////////////////////
114 function plc_table_notes () {
115   print <<< EOF
116 <p class='plc_filter_note'> 
117 Notes: Enter & or | in the search area to alternate between <bold>AND</bold> and <bold>OR</bold> search modes
118 <br/> 
119 Hold down the shift key to select multiple columns to sort 
120 </p>
121 EOF;
122 }
123
124
125 ?>
126