ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTabsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
12 class ilTabsGUI
13 {
15  var $obj_type;
16  var $tpl;
17  var $lng;
18  var $tabs;
20  var $target = array();
21  var $sub_target = array();
22  var $non_tabbed_link = array();
23 
28  function ilTabsGUI()
29  {
30  global $tpl, $objDefinition, $lng;
31 
32  $this->tpl =& $tpl;
33  $this->lng =& $lng;
34  $this->objDefinition =& $objDefinition;
35  $this->manual_activation = false;
36  $this->subtab_manual_activation = false;
37  $this->temp_var = "TABS";
38  $this->sub_tabs = false;
39  $this->back_title = "";
40  $this->back_target = "";
41  $this->back_2_target = "";
42  $this->back_2_title = "";
43  }
44 
48  function setBackTarget($a_title, $a_target, $a_frame = "")
49  {
50  $this->back_title = $a_title;
51  $this->back_target = $a_target;
52  $this->back_frame = $a_frame;
53  }
54 
58  function setBack2Target($a_title, $a_target, $a_frame = "")
59  {
60  $this->back_2_title = $a_title;
61  $this->back_2_target = $a_target;
62  $this->back_2_frame = $a_frame;
63  }
64 
65 
83  function addTarget($a_text, $a_link, $a_cmd = "", $a_cmdClass = "", $a_frame = "", $a_activate = false,
84  $a_dir_text = false)
85  {
86  if(!$a_cmdClass)
87  {
88  $a_cmdClass = array();
89  }
90  $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
91  #$a_cmdClass = strtolower($a_cmdClass);
92 
93  if ($a_activate)
94  {
95  $this->manual_activation = true;
96  }
97  $this->target[] = array("text" => $a_text, "link" => $a_link,
98  "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
99  "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
100  }
101 
110  function addTab($a_id, $a_text, $a_link, $a_frame = "")
111  {
112  $this->target[] = array("text" => $a_text, "link" => $a_link,
113  "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
114  }
115 
123  public function removeTab($a_id)
124  {
125  for($i = 0; $i < count($this->target); $i++)
126  {
127  if($this->target[$i]['id'] == $a_id)
128  {
129  unset($this->target[$i]);
130  return true;
131  }
132  }
133  return false;
134  }
135 
143  public function removeSubTab($a_id)
144  {
145  for($i = 0; $i < count($this->sub_target); $i++)
146  {
147  if($this->sub_target[$i]['id'] == $a_id)
148  {
149  unset($this->sub_target[$i]);
150  return true;
151  }
152  }
153  return false;
154  }
155 
167  public function replaceTab($a_old_id,$a_new_id,$a_text,$a_link,$a_frame = '')
168  {
169  for($i = 0; $i < count($this->target); $i++)
170  {
171  if($this->target[$i]['id'] == $a_old_id)
172  {
173  $this->target[$i] = array();
174  $this->target[$i] = array(
175  "text" => $a_text,
176  "link" => $a_link,
177  "frame" => $a_frame,
178  "dir_text" => true,
179  "id" => $a_new_id,
180  "cmdClass" => array());
181  return true;
182  }
183  }
184  return false;
185  }
186 
190  function clearTargets()
191  {
192  $this->target = array();
193  $this->sub_target = array();
194  $this->non_tabbed_link = array();
195  $this->back_title = "";
196  $this->back_target = "";
197  $this->back_2_target = "";
198  $this->back_2_title = "";
199  $this->setTabActive("");
200  $this->setSubTabActive("");
201  }
202 
221  function addSubTabTarget($a_text, $a_link, $a_cmd = "", $a_cmdClass = "", $a_frame = "", $a_activate = false,
222  $a_dir_text = false)
223  {
224 
225  if(!$a_cmdClass)
226  {
227  $a_cmdClass = array();
228  }
229  $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
230  #$a_cmdClass = strtolower($a_cmdClass);
231 
232  if ($a_activate)
233  {
234  $this->subtab_manual_activation = true;
235  }
236  $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
237  "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
238  "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
239  }
240 
249  function addSubTab($a_id, $a_text, $a_link, $a_frame = "")
250  {
251  $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
252  "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
253  }
254 
265  function setTabActive($a_id)
266  {
267  for($i = 0; $i < count($this->target);$i++)
268  {
269  $this->target[$i]['activate'] = $this->target[$i]['id'] == $a_id;
270  }
271  if ($a_id != "")
272  {
273  $this->manual_activation = true;
274  }
275  else
276  {
277  $this->manual_activation = false;
278  }
279  return true;
280  }
281 
287  function activateTab($a_id)
288  {
289  $this->setTabActive($a_id);
290  }
291 
303  function setSubTabActive($a_text)
304  {
305  for($i = 0; $i < count($this->sub_target);$i++)
306  {
307  $this->sub_target[$i]['activate'] = $this->sub_target[$i]['id'] == $a_text;
308  }
309  $this->subtab_manual_activation = true;
310  return true;
311  }
312 
318  function activateSubTab($a_id)
319  {
320  $this->setSubTabActive($a_id);
321  }
322 
328  function clearSubTabs()
329  {
330  $this->sub_target = array();
331  return true;
332  }
333 
337  function getHTML($a_after_tabs_anchor = false)
338  {
339  return $this->__getHTML(false,$this->manual_activation, $a_after_tabs_anchor);
340  }
341 
345  function getSubTabHTML()
346  {
347  return $this->__getHTML(true,$this->subtab_manual_activation);
348  }
349 
350 
359  function addNonTabbedLink($a_id, $a_text, $a_link, $a_frame = "")
360  {
361  $this->non_tabbed_link[] = array("text" => $a_text, "link" => $a_link,
362  "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
363  }
364 
371  function __getHTML($a_get_sub_tabs,$a_manual, $a_after_tabs_anchor = false)
372  {
373  global $ilCtrl, $lng, $ilUser;
374 
375  $cmd = $ilCtrl->getCmd();
376  $cmdClass = $ilCtrl->getCmdClass();
377 
378  if ($a_get_sub_tabs)
379  {
380  $tpl = new ilTemplate("tpl.sub_tabs.html", true, true);
381  $pre = "sub";
382  $pre2 = "SUB_";
383  $sr_pre = "sub_";
384  }
385  else
386  {
387  $tpl = new ilTemplate("tpl.tabs.html", true, true);
388  if ($a_after_tabs_anchor)
389  {
390  $tpl->touchBlock("after_tabs");
391  }
392  $pre = $pre2 = "";
393 
394  // back 2 tab
395  if ($this->back_2_title != "")
396  {
397  $tpl->setCurrentBlock("back_2_tab");
398  $tpl->setVariable("BACK_2_TAB_LINK", $this->back_2_target);
399  $tpl->setVariable("BACK_2_TAB_TEXT", $this->back_2_title);
400  $tpl->setVariable("BACK_2_TAB_TARGET", $this->back_2_frame);
401  $tpl->parseCurrentBlock();
402  }
403 
404  // back tab
405  if ($this->back_title != "")
406  {
407  $tpl->setCurrentBlock("back_tab");
408  $tpl->setVariable("BACK_TAB_LINK", $this->back_target);
409  $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
410  $tpl->setVariable("BACK_TAB_TARGET", $this->back_frame);
411  $tpl->parseCurrentBlock();
412  }
413  }
414 
415  $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
416 
417  $i=0;
418 
419  // do not display one tab only
420  if ((count($targets) > 1) || ($this->back_title != "" && !$a_get_sub_tabs)
421  || (count($this->non_tabbed_link) > 0 && !$a_get_sub_tabs))
422  {
423  foreach ($targets as $target)
424  {
425  $i++;
426 
427  if (!is_array($target["cmd"]))
428  {
429  $target["cmd"] = array($target["cmd"]);
430  }
431 //echo "<br>-$a_manual-$cmd-".$target["cmd"]."-";
432  if (!$a_manual &&
433  (in_array($cmd, $target["cmd"]) || ($target["cmd"][0] == "" && count($target["cmd"]) == 1)) &&
434  (in_array($cmdClass,$target["cmdClass"]) || !$target["cmdClass"]))
435  {
436  $tabtype = $pre."tabactive";
437  }
438  else
439  {
440  $tabtype = $pre."tabinactive";
441  }
442 
443  if ($a_manual && $target["activate"])
444  {
445  $tabtype = $pre."tabactive";
446  }
447 
448  if ($tabtype == "tabactive" || $tabtype == "subtabactive")
449  {
450  $tpl->setCurrentBlock("sel_text");
451  $tpl->setVariable("TXT_SELECTED", $lng->txt("stat_selected"));
452  $tpl->parseCurrentBlock();
453  }
454 
455  $tpl->setCurrentBlock($pre."tab");
456  $tpl->setVariable($pre2."TAB_TYPE", $tabtype);
457  $hash = ($ilUser->getPref("screen_reader_optimization"))
458  ? "#after_".$sr_pre."tabs"
459  : "";
460 
461  $tpl->setVariable($pre2."TAB_LINK", $target["link"].$hash);
462  if ($target["dir_text"])
463  {
464  $tpl->setVariable($pre2."TAB_TEXT", $target["text"]);
465  }
466  else
467  {
468  $tpl->setVariable($pre2."TAB_TEXT", $lng->txt($target["text"]));
469  }
470  $tpl->setVariable($pre2."TAB_TARGET", $target["frame"]);
471  $tpl->parseCurrentBlock();
472  }
473 
474  if ($a_get_sub_tabs)
475  {
476  $tpl->setVariable("TXT_SUBTABS", $lng->txt("subtabs"));
477  }
478  else
479  {
480  $tpl->setVariable("TXT_TABS", $lng->txt("tabs"));
481 
482  // non tabbed links
483  foreach ($this->non_tabbed_link as $link)
484  {
485  $tpl->setCurrentBlock("tab");
486  $tpl->setVariable("TAB_TYPE", "nontabbed");
487  $tpl->setVariable("TAB_TEXT", $link["text"]);
488  $tpl->setVariable("TAB_LINK", $link["link"]);
489  $tpl->setVariable("TAB_TARGET", $link["frame"]);
490  $tpl->parseCurrentBlock();
491  }
492  }
493 
494  return $tpl->get();
495  }
496  else
497  {
498  return "";
499  }
500  }
501 }
502 ?>