ILIAS  Release_4_0_x_branch Revision 61816
 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  $this->target = array_slice($this->target, $i - 1, 1);
130  return true;
131  }
132  }
133  return false;
134  }
135 
147  public function replaceTab($a_old_id,$a_new_id,$a_text,$a_link,$a_frame = '')
148  {
149  for($i = 0; $i < count($this->target); $i++)
150  {
151  if($this->target[$i]['id'] == $a_old_id)
152  {
153  $this->target[$i] = array();
154  $this->target[$i] = array(
155  "text" => $a_text,
156  "link" => $a_link,
157  "frame" => $a_frame,
158  "dir_text" => true,
159  "id" => $a_new_id,
160  "cmdClass" => array());
161  return true;
162  }
163  }
164  return false;
165  }
166 
170  function clearTargets()
171  {
172  $this->target = array();
173  $this->back_title = "";
174  $this->back_target = "";
175  $this->back_2_target = "";
176  $this->back_2_title = "";
177  $this->setTabActive("");
178  $this->setSubTabActive("");
179  }
180 
199  function addSubTabTarget($a_text, $a_link, $a_cmd = "", $a_cmdClass = "", $a_frame = "", $a_activate = false,
200  $a_dir_text = false)
201  {
202 
203  if(!$a_cmdClass)
204  {
205  $a_cmdClass = array();
206  }
207  $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
208  #$a_cmdClass = strtolower($a_cmdClass);
209 
210  if ($a_activate)
211  {
212  $this->subtab_manual_activation = true;
213  }
214  $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
215  "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
216  "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
217  }
218 
227  function addSubTab($a_id, $a_text, $a_link, $a_frame = "")
228  {
229  $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
230  "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
231  }
232 
243  function setTabActive($a_id)
244  {
245  for($i = 0; $i < count($this->target);$i++)
246  {
247  $this->target[$i]['activate'] = $this->target[$i]['id'] == $a_id;
248  }
249  if ($a_id != "")
250  {
251  $this->manual_activation = true;
252  }
253  else
254  {
255  $this->manual_activation = false;
256  }
257  return true;
258  }
259 
265  function activateTab($a_id)
266  {
267  $this->setTabActive($a_id);
268  }
269 
281  function setSubTabActive($a_text)
282  {
283  for($i = 0; $i < count($this->sub_target);$i++)
284  {
285  $this->sub_target[$i]['activate'] = $this->sub_target[$i]['id'] == $a_text;
286  }
287  $this->subtab_manual_activation = true;
288  return true;
289  }
290 
296  function activateSubTab($a_id)
297  {
298  $this->setSubTabActive($a_id);
299  }
300 
306  function clearSubTabs()
307  {
308  $this->sub_target = array();
309  return true;
310  }
311 
315  function getHTML($a_after_tabs_anchor = false)
316  {
317  return $this->__getHTML(false,$this->manual_activation, $a_after_tabs_anchor);
318  }
319 
323  function getSubTabHTML()
324  {
325  return $this->__getHTML(true,$this->subtab_manual_activation);
326  }
327 
328 
337  function addNonTabbedLink($a_id, $a_text, $a_link, $a_frame = "")
338  {
339  $this->non_tabbed_link[] = array("text" => $a_text, "link" => $a_link,
340  "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
341  }
342 
349  function __getHTML($a_get_sub_tabs,$a_manual, $a_after_tabs_anchor = false)
350  {
351  global $ilCtrl, $lng, $ilUser;
352 
353  $cmd = $ilCtrl->getCmd();
354  $cmdClass = $ilCtrl->getCmdClass();
355 
356  if ($a_get_sub_tabs)
357  {
358  $tpl = new ilTemplate("tpl.sub_tabs.html", true, true);
359  $pre = "sub";
360  $pre2 = "SUB_";
361  $sr_pre = "sub_";
362  }
363  else
364  {
365  $tpl = new ilTemplate("tpl.tabs.html", true, true);
366  if ($a_after_tabs_anchor)
367  {
368  $tpl->touchBlock("after_tabs");
369  }
370  $pre = $pre2 = "";
371 
372  // back 2 tab
373  if ($this->back_2_title != "")
374  {
375  $tpl->setCurrentBlock("back_2_tab");
376  $tpl->setVariable("BACK_2_TAB_LINK", $this->back_2_target);
377  $tpl->setVariable("BACK_2_TAB_TEXT", $this->back_2_title);
378  $tpl->setVariable("BACK_2_TAB_TARGET", $this->back_2_frame);
379  $tpl->parseCurrentBlock();
380  }
381 
382  // back tab
383  if ($this->back_title != "")
384  {
385  $tpl->setCurrentBlock("back_tab");
386  $tpl->setVariable("BACK_TAB_LINK", $this->back_target);
387  $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
388  $tpl->setVariable("BACK_TAB_TARGET", $this->back_frame);
389  $tpl->parseCurrentBlock();
390  }
391  }
392 
393  $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
394 
395  // do not display one tab only
396  if ((count($targets) > 1) || ($this->back_title != "" && !$a_get_sub_tabs)
397  || (count($this->non_tabbed_link) > 0 && !$a_get_sub_tabs))
398  {
399  foreach ($targets as $target)
400  {
401  $i++;
402 
403  if (!is_array($target["cmd"]))
404  {
405  $target["cmd"] = array($target["cmd"]);
406  }
407 //echo "<br>-$a_manual-$cmd-".$target["cmd"]."-";
408  if (!$a_manual &&
409  (in_array($cmd, $target["cmd"]) || ($target["cmd"][0] == "" && count($target["cmd"]) == 1)) &&
410  (in_array($cmdClass,$target["cmdClass"]) || !$target["cmdClass"]))
411  {
412  $tabtype = $pre."tabactive";
413  }
414  else
415  {
416  $tabtype = $pre."tabinactive";
417  }
418 
419  if ($a_manual && $target["activate"])
420  {
421  $tabtype = $pre."tabactive";
422  }
423 
424  if ($tabtype == "tabactive" || $tabtype == "subtabactive")
425  {
426  $tpl->setCurrentBlock("sel_text");
427  $tpl->setVariable("TXT_SELECTED", $lng->txt("stat_selected"));
428  $tpl->parseCurrentBlock();
429  }
430 
431  $tpl->setCurrentBlock($pre."tab");
432  $tpl->setVariable($pre2."TAB_TYPE", $tabtype);
433  $hash = ($ilUser->prefs["screen_reader_optimization"])
434  ? "#after_".$sr_pre."tabs"
435  : "";
436 
437  $tpl->setVariable($pre2."TAB_LINK", $target["link"].$hash);
438  if ($target["dir_text"])
439  {
440  $tpl->setVariable($pre2."TAB_TEXT", $target["text"]);
441  }
442  else
443  {
444  $tpl->setVariable($pre2."TAB_TEXT", $lng->txt($target["text"]));
445  }
446  $tpl->setVariable($pre2."TAB_TARGET", $target["frame"]);
447  $tpl->parseCurrentBlock();
448  }
449 
450  if ($a_get_sub_tabs)
451  {
452  $tpl->setVariable("TXT_SUBTABS", $lng->txt("subtabs"));
453  }
454  else
455  {
456  $tpl->setVariable("TXT_TABS", $lng->txt("tabs"));
457 
458  // non tabbed links
459  foreach ($this->non_tabbed_link as $link)
460  {
461  $tpl->setCurrentBlock("tab");
462  $tpl->setVariable("TAB_TYPE", "nontabbed");
463  $tpl->setVariable("TAB_TEXT", $link["text"]);
464  $tpl->setVariable("TAB_LINK", $link["link"]);
465  $tpl->setVariable("TAB_TARGET", $link["frame"]);
466  $tpl->parseCurrentBlock();
467  }
468  }
469 
470  return $tpl->get();
471  }
472  else
473  {
474  return "";
475  }
476  }
477 }
478 ?>