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