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