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