ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTabsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
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  global $ilHelp;
193 
194  $ilHelp->setScreenIdComponent("");
195 
196  $this->target = array();
197  $this->sub_target = array();
198  $this->non_tabbed_link = array();
199  $this->back_title = "";
200  $this->back_target = "";
201  $this->back_2_target = "";
202  $this->back_2_title = "";
203  $this->setTabActive("");
204  $this->setSubTabActive("");
205  }
206 
225  function addSubTabTarget($a_text, $a_link, $a_cmd = "", $a_cmdClass = "", $a_frame = "", $a_activate = false,
226  $a_dir_text = false)
227  {
228 
229  if(!$a_cmdClass)
230  {
231  $a_cmdClass = array();
232  }
233  $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
234  #$a_cmdClass = strtolower($a_cmdClass);
235 
236  if ($a_activate)
237  {
238  $this->subtab_manual_activation = true;
239  }
240  $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
241  "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
242  "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
243  }
244 
253  function addSubTab($a_id, $a_text, $a_link, $a_frame = "")
254  {
255  $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
256  "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
257  }
258 
269  function setTabActive($a_id)
270  {
271  foreach($this->target as $key => $target)
272  {
273  $this->target[$key]['activate'] = $this->target[$key]['id'] == $a_id;
274  }
275  if ($a_id != "")
276  {
277  $this->manual_activation = true;
278  }
279  else
280  {
281  $this->manual_activation = false;
282  }
283  return true;
284  }
285 
291  function activateTab($a_id)
292  {
293  $this->setTabActive($a_id);
294  }
295 
307  function setSubTabActive($a_text)
308  {
309  for($i = 0; $i < count($this->sub_target);$i++)
310  {
311  $this->sub_target[$i]['activate'] = $this->sub_target[$i]['id'] == $a_text;
312  }
313  $this->subtab_manual_activation = true;
314  return true;
315  }
316 
322  function activateSubTab($a_id)
323  {
324  $this->setSubTabActive($a_id);
325  }
326 
332  function clearSubTabs()
333  {
334  $this->sub_target = array();
335  return true;
336  }
337 
341  function getHTML($a_after_tabs_anchor = false)
342  {
343  return $this->__getHTML(false,$this->manual_activation, $a_after_tabs_anchor);
344  }
345 
349  function getSubTabHTML()
350  {
351  return $this->__getHTML(true,$this->subtab_manual_activation);
352  }
353 
362  function addNonTabbedLink($a_id, $a_text, $a_link, $a_frame = "")
363  {
364  $this->non_tabbed_link[] = array("text" => $a_text, "link" => $a_link,
365  "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
366  }
367 
374  function __getHTML($a_get_sub_tabs,$a_manual, $a_after_tabs_anchor = false)
375  {
376  global $ilCtrl, $lng, $ilUser, $ilPluginAdmin, $ilHelp;
377 
378  // user interface hook [uihk]
379  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "UIComponent", "uihk");
380  foreach ($pl_names as $pl)
381  {
382  $ui_plugin = ilPluginAdmin::getPluginObject(IL_COMP_SERVICE, "UIComponent", "uihk", $pl);
383  $gui_class = $ui_plugin->getUIClassInstance();
384  $resp = $gui_class->modifyGUI("", $a_get_sub_tabs ? "sub_tabs" : "tabs",
385  array("tabs" => $this));
386  }
387 
388  $cmd = $ilCtrl->getCmd();
389  $cmdClass = $ilCtrl->getCmdClass();
390 
391  if ($a_get_sub_tabs)
392  {
393  $tpl = new ilTemplate("tpl.sub_tabs.html", true, true, "Services/UIComponent/Tabs");
394  $pre = "sub";
395  $pre2 = "SUB_";
396  $sr_pre = "sub_";
397  }
398  else
399  {
400  $tpl = new ilTemplate("tpl.tabs.html", true, true, "Services/UIComponent/Tabs");
401  if ($a_after_tabs_anchor)
402  {
403  $tpl->touchBlock("after_tabs");
404  }
405  $pre = $pre2 = "";
406 
407  // back 2 tab
408  if ($this->back_2_title != "")
409  {
410  $tpl->setCurrentBlock("back_2_tab");
411  $tpl->setVariable("BACK_2_TAB_LINK", $this->back_2_target);
412  $tpl->setVariable("BACK_2_TAB_TEXT", $this->back_2_title);
413  $tpl->setVariable("BACK_2_TAB_TARGET", $this->back_2_frame);
414  $tpl->parseCurrentBlock();
415  }
416 
417  // back tab
418  if ($this->back_title != "")
419  {
420  $tpl->setCurrentBlock("back_tab");
421  $tpl->setVariable("BACK_TAB_LINK", $this->back_target);
422  $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
423  $tpl->setVariable("BACK_TAB_TARGET", $this->back_frame);
424  $tpl->parseCurrentBlock();
425  }
426  }
427 
428  $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
429 
430  $i=0;
431 
432  // do not display one tab only
433  if ((count($targets) > 1) || ($this->back_title != "" && !$a_get_sub_tabs)
434  || (count($this->non_tabbed_link) > 0 && !$a_get_sub_tabs))
435  {
436  foreach ($targets as $target)
437  {
438  $i++;
439 
440  if (!is_array($target["cmd"]))
441  {
442  $target["cmd"] = array($target["cmd"]);
443  }
444 //echo "<br>-$a_manual-$cmd-".$target["cmd"]."-";
445  if (!$a_manual &&
446  (in_array($cmd, $target["cmd"]) || ($target["cmd"][0] == "" && count($target["cmd"]) == 1)) &&
447  (in_array($cmdClass,$target["cmdClass"]) || !$target["cmdClass"]))
448  {
449  $tabtype = $pre."tabactive";
450  }
451  else
452  {
453  $tabtype = $pre."tabinactive";
454  }
455 
456  if ($a_manual && $target["activate"])
457  {
458  $tabtype = $pre."tabactive";
459  }
460 
461  if ($tabtype == "tabactive" || $tabtype == "subtabactive")
462  {
463  $tpl->setCurrentBlock("sel_text");
464  $tpl->setVariable("TXT_SELECTED", $lng->txt("stat_selected"));
465  $tpl->parseCurrentBlock();
466  if ($a_get_sub_tabs)
467  {
469  }
470  else
471  {
473  }
474  $ilHelp->setDefaultScreenId($part, $target["id"]);
475  }
476 
477  $tpl->setCurrentBlock($pre."tab");
478  $tpl->setVariable("ID", $pre."tab_".$target["id"]);
479 
480  // tooltip
481  $ttext = $ilHelp->getTabTooltipText($target["id"]);
482  if ($ttext != "")
483  {
484  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
485  ilTooltipGUI::addTooltip($pre."tab_".$target["id"], $ttext, "",
486  "bottom center", "top center", false);
487  }
488 
489  $tpl->setVariable($pre2."TAB_TYPE", $tabtype);
490  $hash = ($ilUser->getPref("screen_reader_optimization"))
491  ? "#after_".$sr_pre."tabs"
492  : "";
493 
494  $tpl->setVariable($pre2."TAB_LINK", $target["link"].$hash);
495  if ($target["dir_text"])
496  {
497  $tpl->setVariable($pre2."TAB_TEXT", $target["text"]);
498  }
499  else
500  {
501  $tpl->setVariable($pre2."TAB_TEXT", $lng->txt($target["text"]));
502  }
503  $tpl->setVariable($pre2."TAB_TARGET", $target["frame"]);
504  $tpl->parseCurrentBlock();
505  }
506 
507  if ($a_get_sub_tabs)
508  {
509  $tpl->setVariable("TXT_SUBTABS", $lng->txt("subtabs"));
510  }
511  else
512  {
513  $tpl->setVariable("TXT_TABS", $lng->txt("tabs"));
514 
515  // non tabbed links
516  foreach ($this->non_tabbed_link as $link)
517  {
518  $tpl->setCurrentBlock("tab");
519  $tpl->setVariable("TAB_TYPE", "nontabbed");
520  $tpl->setVariable("TAB_TEXT", $link["text"]);
521  $tpl->setVariable("TAB_LINK", $link["link"]);
522  $tpl->setVariable("TAB_TARGET", $link["frame"]);
523  $tpl->setVariable("ID", "nontab_".$link["id"]);
524  $tpl->parseCurrentBlock();
525 
526  // tooltip
527  $ttext = $ilHelp->getTabTooltipText($link["id"]);
528  if ($ttext != "")
529  {
530  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
531  ilTooltipGUI::addTooltip("nontab_".$link["id"], $ttext, "",
532  "bottom center", "top center", false);
533  }
534  }
535  }
536 
537  return $tpl->get();
538  }
539  else
540  {
541  return "";
542  }
543  }
544 
545 
546 
547  function hasTabs()
548  {
549  return (bool)sizeof($this->target);
550  }
551 }
552 ?>