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