details can be updated inline - old forms still to be cleaned up
[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     // extract var=value settings from url if any
44     $full_url=$todo['url'];
45     $split=split_url($full_url);
46     $url=$split['url'];
47     $url_values=$split['values'];
48
49     // create form
50     printf ('<form name="%s" action="%s" method="%s">',$label,$url,$todo['method']);
51     // set values
52     $values=$todo['values'];
53     if ( ! $values) $values = array();
54     if ($url_values) $values = array_merge($values,$url_values);
55     if ( $values ) foreach ($values as $key=>$value) {
56         printf('<input class="minitabs-hidden" type=hidden name="%s" value="%s" />',$key,$value);
57       }
58     $tracer="class=minitabs-submit";
59     // image and its companions 'height' 
60     if ($todo['image']) {
61       $type='type=image src="' . $todo['image'] . '"';
62       if ($todo['height']) $type.= ' height=' . $todo['height'];
63     } else {
64       $type='type=button value="' . $label . '"';
65     }
66     printf('<span title="%s">',$todo['bubble']);
67     $message="";
68     if ($todo['confirm']) $message=$todo['confirm'] . " ?";
69     printf('<input %s %s onclick=\'miniTab.submit("%s");\' />',$tracer,$type,$message);
70     printf('</span>',$todo['bubble']);
71     printf("</form></li>\n");
72   }
73   print '</ul>';
74   print '</div>';
75   print "<p class='plc-minittabs'></p>\n";
76 }
77
78 ?>