Framework  3.9
data_tabs.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4  Copyright (c) 2007-2010 Sonjara, Inc
5 
6  Permission is hereby granted, free of charge, to any person
7  obtaining a copy of this software and associated documentation
8  files (the "Software"), to deal in the Software without
9  restriction, including without limitation the rights to use,
10  copy, modify, merge, publish, distribute, sublicense, and/or sell
11  copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following
13  conditions:
14 
15  The above copyright notice and this permission notice shall be
16  included in all copies or substantial portions of the Software.
17 
18  Except as contained in this notice, the name(s) of the above
19  copyright holders shall not be used in advertising or otherwise
20  to promote the sale, use or other dealings in this Software
21  without prior written authorization.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30  OTHER DEALINGS IN THE SOFTWARE.
31 
32 *****************************************************************/
33 
34 
42 {
43  var $id;
44 
45  var $items;
46  var $format;
47 
48  var $uri;
50  var $spacer;
51 
52  function DataItemTabBar($id, $items, $format = null, $uri = "")
53  {
54  $this->id = $id;
55  $this->items = $items;
56  $this->format = $format;
57  if (count($this->items))
58  {
59  $this->primary_key = $this->items[0]->getPrimaryKey();
60  }
61 
62  $this->uri = $uri;
63  }
64 
65 
73  function appendQueryString($url, $qs)
74  {
75  if ($url[0] == "&")
76  {
77  $url = $qs.$url;
78  }
79  else
80  {
81  $url .= (strstr($url, "?") !== false) ? "&$qs" : "?$qs";
82  }
83  return $url;
84  }
85 
86  function writeScript()
87  {
88  $script = <<<ENDSCRIPT
89 <script type='text/javascript'>
90 window.addEvent('load', function()
91 {
92  new ScrollingTabs('{$this->id}');
93 });
94 </script>
95 ENDSCRIPT;
96 
97  return $script;
98  }
99 
103  function writeHTML()
104  {
105  if (array_key_exists($this->primary_key, $_GET))
106  {
107  $key = $_GET[$this->primary_key];
108  }
109  else
110  {
111  $key = $this->items[0]->get($this->primary_key);
112  }
113 
114  $first = true;
115  $future = false;
116 
117  if ($this->anchor) echo "<a name='<?echo $this->anchor?>'></a>";
118 
119  echo "<div id='{$this->id}'";
120 
121  if ($this->cssClass) echo " class='{$this->cssClass}'";
122 
123  echo "><ul>";
124 
125  $count = 0;
126 
127  foreach ($this->items as $item)
128  {
129  ++$count;
130  $active = "";
131  $style = "";
132 
133  $pk = $item->get($this->primary_key);
134 
135  $url = $this->uri . "?" . $this->primary_key . "=" . urlencode($pk);
136 
137  $text = $item->format($this->format);
138 
139  if (!$first)
140  {
141  echo $this->spacer;
142  }
143  else
144  {
145  $first = false;
146  }
147 
148  if ($pk == $key)
149  {
150  $style = " class='current'";
151  }
152 
153  if ($this->showNumber) $text = "$count.&nbsp;$text";
154 
155  $dest = ($this->queryString!="") ? $this->appendQueryString($url, $this->queryString) : $url;
156 
157  if ($this->anchor)
158  {
159  $dest = ($dest != "#") ? "$dest#{$this->anchor}" : "#{$this->anchor}";
160  }
161 
162  if ($this->showStates)
163  {
164  if (array_key_exists($url, $this->flags))
165  {
166  $text = "<img src='{$this->states[$this->flags[$pk]]}' style='border: none; display: inline-block;vertical-align: middle'/>&nbsp;$text";
167  }
168  else if ($this->defaultStateImage)
169  {
170  $text = "<img src='{$this->defaultStateImage}' style='border: none; display: inline-block;vertical-align: middle'/>&nbsp;$text";
171  }
172  }
173  echo "<li$style><a href=\"$dest\"$active>$text</a></li>";
174  }
175 
176  echo "</ul></div>\n";
177  }
178 }
179 ?>
The DataItemTabBar class is a user-interface control that manages a line of tabs for multi-page dialo...
Definition: data_tabs.inc:42
$id
The DOM ID of the DataItemTabBar container element.
Definition: data_tabs.inc:43
appendQueryString($url, $qs)
Appends a query string to the supplied URL.
Definition: data_tabs.inc:73
writeHTML()
Writes the HTML for this control to standard output.
Definition: data_tabs.inc:103
DataItemTabBar($id, $items, $format=null, $uri="")
Definition: data_tabs.inc:52