ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTabsGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
32 class ilTabsGUI
33 {
35  var $obj_type;
36  var $tpl;
37  var $lng;
38  var $tabs;
40  var $target = array();
41  var $sub_target = array();
42 
47  function ilTabsGUI()
48  {
49  global $tpl, $objDefinition, $lng;
50 
51  $this->tpl =& $tpl;
52  $this->lng =& $lng;
53  $this->objDefinition =& $objDefinition;
54  $this->manual_activation = false;
55  $this->subtab_manual_activation = false;
56  $this->temp_var = "TABS";
57  $this->sub_tabs = false;
58  $this->back_title = "";
59  $this->back_target = "";
60  $this->back_2_target = "";
61  $this->back_2_title = "";
62  }
63 
67  function setBackTarget($a_title, $a_target, $a_frame = "")
68  {
69  $this->back_title = $a_title;
70  $this->back_target = $a_target;
71  $this->back_frame = $a_frame;
72  }
73 
77  function setBack2Target($a_title, $a_target, $a_frame = "")
78  {
79  $this->back_2_title = $a_title;
80  $this->back_2_target = $a_target;
81  $this->back_2_frame = $a_frame;
82  }
83 
84 /* Deprecated
85  function getTargetsByObjectType(&$a_gui_obj, $a_type)
86  {
87  global $ilCtrl;
88 
89  $d = $this->objDefinition->getProperties($a_type);
90 
91  foreach ($d as $key => $row)
92  {
93  $this->addTarget($row["lng"],
94  $ilCtrl->getLinkTarget($a_gui_obj, $row["name"]),
95  $row["name"], get_class($a_gui_obj));
96  }
97  }
98 */
99 
113  function addTarget($a_text, $a_link, $a_cmd = "", $a_cmdClass = "", $a_frame = "", $a_activate = false,
114  $a_dir_text = false)
115  {
116  if(!$a_cmdClass)
117  {
118  $a_cmdClass = array();
119  }
120  $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
121  #$a_cmdClass = strtolower($a_cmdClass);
122 
123  if ($a_activate)
124  {
125  $this->manual_activation = true;
126  }
127  $this->target[] = array("text" => $a_text, "link" => $a_link,
128  "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
129  "activate" => $a_activate, "dir_text" => $a_dir_text);
130  }
131 
135  function clearTargets()
136  {
137  $this->target = array();
138  $this->back_title = "";
139  $this->back_target = "";
140  $this->back_2_target = "";
141  $this->back_2_title = "";
142  $this->setTabActive("");
143  $this->setSubTabActive("");
144  }
145 
160  function addSubTabTarget($a_text, $a_link, $a_cmd = "", $a_cmdClass = "", $a_frame = "", $a_activate = false,
161  $a_dir_text = false)
162  {
163 
164  if(!$a_cmdClass)
165  {
166  $a_cmdClass = array();
167  }
168  $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
169  #$a_cmdClass = strtolower($a_cmdClass);
170 
171  if ($a_activate)
172  {
173  $this->subtab_manual_activation = true;
174  }
175  $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
176  "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
177  "activate" => $a_activate, "dir_text" => $a_dir_text);
178  }
179 
187  function setTabActive($a_text)
188  {
189  for($i = 0; $i < count($this->target);$i++)
190  {
191  $this->target[$i]['activate'] = $this->target[$i]['text'] == $a_text;
192  }
193  if ($a_text != "")
194  {
195  $this->manual_activation = true;
196  }
197  else
198  {
199  $this->manual_activation = false;
200  }
201  return true;
202  }
203 
211  function setSubTabActive($a_text)
212  {
213  for($i = 0; $i < count($this->sub_target);$i++)
214  {
215  $this->sub_target[$i]['activate'] = $this->sub_target[$i]['text'] == $a_text;
216  }
217  $this->subtab_manual_activation = true;
218  return true;
219  }
220 
226  function clearSubTabs()
227  {
228  $this->sub_target = array();
229  return true;
230  }
231 
235  function getHTML()
236  {
237  return $this->__getHTML(false,$this->manual_activation);
238  }
239 
243  function getSubTabHTML()
244  {
245  return $this->__getHTML(true,$this->subtab_manual_activation);
246  }
247 
248 
249 
256  function __getHTML($a_get_sub_tabs,$a_manual)
257  {
258  global $ilCtrl, $lng;
259 
260  $cmd = $ilCtrl->getCmd();
261  $cmdClass = $ilCtrl->getCmdClass();
262 
263  if ($a_get_sub_tabs)
264  {
265  $tpl = new ilTemplate("tpl.sub_tabs.html", true, true);
266  $pre = "sub";
267  $pre2 = "SUB_";
268  }
269  else
270  {
271  $tpl = new ilTemplate("tpl.tabs.html", true, true);
272  $pre = $pre2 = "";
273 
274  // back 2 tab
275  if ($this->back_2_title != "")
276  {
277  $tpl->setCurrentBlock("back_2_tab");
278  $tpl->setVariable("BACK_2_TAB_LINK", $this->back_2_target);
279  $tpl->setVariable("BACK_2_TAB_TEXT", $this->back_2_title);
280  $tpl->setVariable("BACK_2_TAB_TARGET", $this->back_2_frame);
281  $tpl->parseCurrentBlock();
282  }
283 
284  // back tab
285  if ($this->back_title != "")
286  {
287  $tpl->setCurrentBlock("back_tab");
288  $tpl->setVariable("BACK_TAB_LINK", $this->back_target);
289  $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
290  $tpl->setVariable("BACK_TAB_TARGET", $this->back_frame);
291  $tpl->parseCurrentBlock();
292  }
293  }
294 
295  $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
296 
297  // do not display one tab only
298  if ((count($targets) > 1) || ($this->back_title != "" && !$a_get_sub_tabs))
299  {
300  foreach ($targets as $target)
301  {
302  $i++;
303 
304  if (!is_array($target["cmd"]))
305  {
306  $target["cmd"] = array($target["cmd"]);
307  }
308 //echo "<br>-$a_manual-$cmd-".$target["cmd"]."-";
309  if (!$a_manual &&
310  (in_array($cmd, $target["cmd"]) || ($target["cmd"][0] == "" && count($target["cmd"]) == 1)) &&
311  (in_array($cmdClass,$target["cmdClass"]) || !$target["cmdClass"]))
312  {
313  $tabtype = $pre."tabactive";
314  }
315  else
316  {
317  $tabtype = $pre."tabinactive";
318  }
319 
320  if ($a_manual && $target["activate"])
321  {
322  $tabtype = $pre."tabactive";
323  }
324 
325  $tpl->setCurrentBlock($pre."tab");
326  $tpl->setVariable($pre2."TAB_TYPE", $tabtype);
327  $tpl->setVariable($pre2."TAB_LINK", $target["link"]);
328  if ($target["dir_text"])
329  {
330  $tpl->setVariable($pre2."TAB_TEXT", $target["text"]);
331  }
332  else
333  {
334  $tpl->setVariable($pre2."TAB_TEXT", $lng->txt($target["text"]));
335  }
336  $tpl->setVariable($pre2."TAB_TARGET", $target["frame"]);
337  $tpl->parseCurrentBlock();
338  }
339  return $tpl->get();
340  }
341  else
342  {
343  return "";
344  }
345  }
346 }
347 ?>