ILIAS  Release_4_2_x_branch Revision 61807
 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  foreach($this->target as $key => $target)
126  {
127  if($target['id'] == $a_id)
128  {
129  unset($this->target[$key]);
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  foreach($this->target as $key => $target)
268  {
269  $this->target[$key]['activate'] = $this->target[$key]['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, $ilPluginAdmin;
374 
375  // user interface hook [uihk]
376  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "UIComponent", "uihk");
377  foreach ($pl_names as $pl)
378  {
379  $ui_plugin = ilPluginAdmin::getPluginObject(IL_COMP_SERVICE, "UIComponent", "uihk", $pl);
380  $gui_class = $ui_plugin->getUIClassInstance();
381  $resp = $gui_class->modifyGUI("", $a_get_sub_tabs ? "sub_tabs" : "tabs",
382  array("tabs" => $this));
383  }
384 
385  $cmd = $ilCtrl->getCmd();
386  $cmdClass = $ilCtrl->getCmdClass();
387 
388  if ($a_get_sub_tabs)
389  {
390  $tpl = new ilTemplate("tpl.sub_tabs.html", true, true);
391  $pre = "sub";
392  $pre2 = "SUB_";
393  $sr_pre = "sub_";
394  }
395  else
396  {
397  $tpl = new ilTemplate("tpl.tabs.html", true, true);
398  if ($a_after_tabs_anchor)
399  {
400  $tpl->touchBlock("after_tabs");
401  }
402  $pre = $pre2 = "";
403 
404  // back 2 tab
405  if ($this->back_2_title != "")
406  {
407  $tpl->setCurrentBlock("back_2_tab");
408  $tpl->setVariable("BACK_2_TAB_LINK", $this->back_2_target);
409  $tpl->setVariable("BACK_2_TAB_TEXT", $this->back_2_title);
410  $tpl->setVariable("BACK_2_TAB_TARGET", $this->back_2_frame);
411  $tpl->parseCurrentBlock();
412  }
413 
414  // back tab
415  if ($this->back_title != "")
416  {
417  $tpl->setCurrentBlock("back_tab");
418  $tpl->setVariable("BACK_TAB_LINK", $this->back_target);
419  $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
420  $tpl->setVariable("BACK_TAB_TARGET", $this->back_frame);
421  $tpl->parseCurrentBlock();
422  }
423  }
424 
425  $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
426 
427  $i=0;
428 
429  // do not display one tab only
430  if ((count($targets) > 1) || ($this->back_title != "" && !$a_get_sub_tabs)
431  || (count($this->non_tabbed_link) > 0 && !$a_get_sub_tabs))
432  {
433  foreach ($targets as $target)
434  {
435  $i++;
436 
437  if (!is_array($target["cmd"]))
438  {
439  $target["cmd"] = array($target["cmd"]);
440  }
441 //echo "<br>-$a_manual-$cmd-".$target["cmd"]."-";
442  if (!$a_manual &&
443  (in_array($cmd, $target["cmd"]) || ($target["cmd"][0] == "" && count($target["cmd"]) == 1)) &&
444  (in_array($cmdClass,$target["cmdClass"]) || !$target["cmdClass"]))
445  {
446  $tabtype = $pre."tabactive";
447  }
448  else
449  {
450  $tabtype = $pre."tabinactive";
451  }
452 
453  if ($a_manual && $target["activate"])
454  {
455  $tabtype = $pre."tabactive";
456  }
457 
458  if ($tabtype == "tabactive" || $tabtype == "subtabactive")
459  {
460  $tpl->setCurrentBlock("sel_text");
461  $tpl->setVariable("TXT_SELECTED", $lng->txt("stat_selected"));
462  $tpl->parseCurrentBlock();
463  }
464 
465  $tpl->setCurrentBlock($pre."tab");
466  $tpl->setVariable($pre2."TAB_TYPE", $tabtype);
467  $hash = ($ilUser->getPref("screen_reader_optimization"))
468  ? "#after_".$sr_pre."tabs"
469  : "";
470 
471  $tpl->setVariable($pre2."TAB_LINK", $target["link"].$hash);
472  if ($target["dir_text"])
473  {
474  $tpl->setVariable($pre2."TAB_TEXT", $target["text"]);
475  }
476  else
477  {
478  $tpl->setVariable($pre2."TAB_TEXT", $lng->txt($target["text"]));
479  }
480  $tpl->setVariable($pre2."TAB_TARGET", $target["frame"]);
481  $tpl->parseCurrentBlock();
482  }
483 
484  if ($a_get_sub_tabs)
485  {
486  $tpl->setVariable("TXT_SUBTABS", $lng->txt("subtabs"));
487  }
488  else
489  {
490  $tpl->setVariable("TXT_TABS", $lng->txt("tabs"));
491 
492  // non tabbed links
493  foreach ($this->non_tabbed_link as $link)
494  {
495  $tpl->setCurrentBlock("tab");
496  $tpl->setVariable("TAB_TYPE", "nontabbed");
497  $tpl->setVariable("TAB_TEXT", $link["text"]);
498  $tpl->setVariable("TAB_LINK", $link["link"]);
499  $tpl->setVariable("TAB_TARGET", $link["frame"]);
500  $tpl->parseCurrentBlock();
501  }
502  }
503 
504  return $tpl->get();
505  }
506  else
507  {
508  return "";
509  }
510  }
511 
512  function hasTabs()
513  {
514  return (bool)sizeof($this->target);
515  }
516 }
517 ?>