checkpoint
[plewww.git] / planetlab / includes / plc_minitabs.php
1 <?php
2   // $Id$
3
4 drupal_set_html_head('
5 <script type="text/javascript" src="/planetlab/minitabs/minitabs.js"></script>
6 <link href="/planetlab/minitabs/minitabs.css" rel="stylesheet" type="text/css" />
7 ');
8
9
10 // the expected argument is an (ordered) associative array
11 // ( label => todo , ...)
12 // label is expected to be the string to display in the menu
13 // todo can be either
14 // (*) a string : it is then taken to be a URL to move to
15 // (*) or an associative array with the following keys
16 //     (*) 'method': 'POST' or 'GET' -- default is 'GET'
17 //     (*) 'url': where to go
18 //     (*) 'values': an associative array of (key,value) pairs to send to the URL; values are strings
19 //     (*) 'confirm': a question to display before actually triggering
20 //     (*) 'bubble': a longer message displayed when the mouse stays quite for a while on the label
21 //     (*) 'image' : the url of an image used instead of the full title
22 //     (*) 'height' : used for the image
23
24 ////////// Notes: limited support for images
25 // (*) for some reason, confirmation does not work with image tabs 
26 //     (the form gets submitted whatever the confirmation....)
27 // (*) you need to tune the image size, which is wrong, as the image should rather be bottom-aligned 
28
29
30 function plc_tabs($array) {
31   print '<div id="minitabs-container">';
32   print '<ul id="minitabs-list">';
33   print "\n";
34   foreach ($array as $label=>$todo) {
35     $tracer="class=minitabs";
36     if ($todo['id']) 
37       $tracer .= " id=".$todo['id'];
38     printf ("<li %s>\n",$tracer);
39     // in case we have a string, rewrite it as an array
40     if (is_string ($todo)) $todo=array('method'=>'GET','url'=>$todo);
41     // set default method
42     if ( ! $todo['method'] ) $todo['method']='GET';
43     // create form
44     printf ('<form name="%s" action="%s" method="%s">',$label,$todo['url'],$todo['method']);
45     // set values
46     if ( $todo['values'] ) {
47       foreach ($todo['values'] as $key=>$value) {
48         printf('<input class="minitabs-hidden" type=hidden name="%s" value="%s" />',$key,$value);
49       }
50     }
51     $tracer="class=minitabs-submit";
52     // image and its companions 'height' 
53     if ($todo['image']) {
54       $type='type=image src="' . $todo['image'] . '"';
55       if ($todo['height']) $type.= ' height=' . $todo['height'];
56     } else {
57       $type='type=button value="' . $label . '"';
58     }
59     printf('<span title="%s">',$todo['bubble']);
60     $message="";
61     if ($todo['confirm']) $message=$todo['confirm'] . " ?";
62     printf('<input %s %s onclick=\'miniTab.submit("%s");\' />',$tracer,$type,$message);
63     printf('</span>',$todo['bubble']);
64     printf("</form></li>\n");
65   }
66   print '</ul>';
67   print '</div>';
68   print "\n";
69   print "<br/>\n";
70 }
71
72 ?>