4 require_once 'plekit-utils.php';
5 require_once 'prototype.php';
8 <script type="text/javascript" src="/plekit/linetabs/linetabs.js"></script>
9 <link href="/plekit/linetabs/linetabs.css" rel="stylesheet" type="text/css" />
13 // the expected argument is an (ordered) associative array
14 // ( label => todo , ...)
15 // label is expected to be the string to display in the menu
17 // (*) a string : it is then taken to be a URL to move to
18 // (*) or an associative array with the following keys
19 // (*) 'label' : if set, this overrides the string key just above
20 // this is used for functions that return a tab, more convenient to write&use
21 // (*) 'method': 'POST' or 'GET' -- default is 'GET'
22 // (*) 'url': where to go
23 // (*) 'values': an associative array of (key,value) pairs to send to the URL; values are strings
24 // (*) 'confirm': a question to display before actually triggering
25 // (*) 'bubble': a longer message displayed when the mouse stays quite for a while on the label
26 // (*) 'image' : the url of an image used instead of the label
27 // (*) 'height' : used for the image
28 // (*) 'id' : assign given id to the <li> element
31 // (*) values can also be set in the URL, e.g. ?var=value&foo=bar, even for POST'ing
32 // (*) several instances can appear on the same page but you need to give them different id's
35 // function my_tab () { return array('label'=>'Go to google','url'=>'http://google.com'); }
37 // $tabs[] = my_tab();
38 // $tabs['Simple Tab']="http://planet-lab.org";
39 // $tabs['Complex Tab']=array('url'=>'http://planet-lab.org/',
40 // 'bubble'=>'This text gets displayed when the mouse remains over for a while');
41 // plekit_linetabs($tabs);
43 ////////// Notes: limited support for images
44 // (*) for some reason, confirmation does not work with image tabs
45 // (the form gets submitted whatever the confirmation....)
46 // (*) you need to tune the image size, which is wrong, as the image should rather be bottom-aligned
48 function plekit_linetabs ($tabs, $id=NULL) {
49 // do not output anything if $tabs has no entry (unpleasant rendering)
50 if (empty ($tabs)) return;
51 $active_line_tab=get_array($_GET, 'active_line_tab');
52 // need id to pass to the onclick function attached to the input buttons
54 if (! $id) $id .= '-' + $id;
55 print "<div id='$id' class='linetabs'>";
57 foreach ($tabs as $label=>$todo) {
58 // in case we have a simple string, rewrite it as an array
59 if (is_string ($todo))
60 $todo = array('method'=>'GET', 'url'=>$todo);
61 // the 'label' key, if set in the hash, supersedes key
62 if (get_array($todo, 'label'))
63 $label = $todo['label'];
65 if (get_array($todo, 'id'))
66 $tracer .= "id=" . $todo['id'];
69 if ( ! get_array($todo, 'method') )
70 $todo['method'] = 'GET';
71 // extract var=value settings from url if any
72 $full_url=$todo['url'];
73 $split=plekit_split_url($full_url);
75 $url_values=$split['values'];
78 $method=strtolower($todo['method']);
79 print "<form action='$url' method='$method'><fieldset>";
81 $values = get_array($todo, 'values');
82 if ( ! $values) $values = array();
84 $values = array_merge($values, $url_values);
86 foreach ($values as $key=>$value) {
87 if ($key != "active_line_tab")
88 print "<input type='hidden' name='$key' value='$value' />";
90 print "<input type='hidden' name='active_line_tab' value='$label' />";
91 if ($label == $active_line_tab) $tracer = "class='linetabs-submit active'";
92 else $tracer="class='linetabs-submit'";
93 // image and its companions 'height'
94 if (get_array($todo, 'image')) {
96 $type="type='image' src='$what'";
97 if ($todo['height']) {
98 $what=$todo['height'];
99 $type .= " height='$what'";
102 $type="type='button' value='$label'";
104 $bubble=htmlspecialchars($todo['bubble'], ENT_QUOTES);
105 print "<span title='$bubble'>";
107 if (get_array($todo, 'confirm'))
108 $message=htmlspecialchars($todo['confirm'], ENT_QUOTES) . " ?";
109 print "<input $tracer $type onclick='linetabs_namespace.submit(\"$id\",\"$message\")' />";
111 print "</fieldset></form></li>\n";
115 print "<p class='linetabs'></p>\n";