ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
14 
18  protected $ctrl;
19 
21  public $obj_type;
22  public $tpl;
23  public $lng;
24  public $tabs;
25  public $target = array();
26  public $sub_target = array();
27  public $non_tabbed_link = array();
28  public $setup_mode = false;
29 
30  protected $force_one_tab = false;
31 
36  public function __construct()
37  {
38  global $DIC;
39 
40  $this->ctrl = $DIC->ctrl();
41  $tpl = $DIC["tpl"];
42  $lng = $DIC->language();
43 
44  $this->tpl = $tpl;
45  $this->lng = $lng;
46  $this->manual_activation = false;
47  $this->subtab_manual_activation = false;
48  $this->temp_var = "TABS";
49  $this->sub_tabs = false;
50  $this->back_title = "";
51  $this->back_target = "";
52  $this->back_2_target = "";
53  $this->back_2_title = "";
54  }
55 
61  public function setSetupMode($a_val)
62  {
63  $this->setup_mode = $a_val;
64  }
65 
71  public function getSetupMode()
72  {
73  return $this->setup_mode;
74  }
75 
79  public function setBackTarget($a_title, $a_target, $a_frame = "")
80  {
81  $this->back_title = $a_title;
82  $this->back_target = $a_target;
83  $this->back_frame = $a_frame;
84  }
85 
89  public function setBack2Target($a_title, $a_target, $a_frame = "")
90  {
91  $this->back_2_title = $a_title;
92  $this->back_2_target = $a_target;
93  $this->back_2_frame = $a_frame;
94  }
95 
101  public function setForcePresentationOfSingleTab($a_val)
102  {
103  $this->force_one_tab = $a_val;
104  }
105 
112  {
113  return $this->force_one_tab;
114  }
115 
133  public function addTarget(
134  $a_text,
135  $a_link,
136  $a_cmd = "",
137  $a_cmdClass = "",
138  $a_frame = "",
139  $a_activate = false,
140  $a_dir_text = false
141  ) {
142  if (!$a_cmdClass) {
143  $a_cmdClass = array();
144  }
145  $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
146  #$a_cmdClass = strtolower($a_cmdClass);
147 
148  if ($a_activate) {
149  $this->manual_activation = true;
150  }
151  $this->target[] = array("text" => $a_text, "link" => $a_link,
152  "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
153  "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
154  }
155 
164  public function addTab($a_id, $a_text, $a_link, $a_frame = "")
165  {
166  $this->target[] = array("text" => $a_text, "link" => $a_link,
167  "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
168  }
169 
177  public function removeTab($a_id)
178  {
179  foreach ($this->target as $key => $target) {
180  if ($target['id'] == $a_id) {
181  unset($this->target[$key]);
182  return true;
183  }
184  }
185  return false;
186  }
187 
195  public function removeSubTab($a_id)
196  {
197  foreach ($this->sub_target as $i => $sub_target) {
198  if ($this->sub_target[$i]['id'] == $a_id) {
199  unset($this->sub_target[$i]);
200  return true;
201  }
202  }
203  return false;
204  }
205 
217  public function replaceTab($a_old_id, $a_new_id, $a_text, $a_link, $a_frame = '')
218  {
219  for ($i = 0; $i < count($this->target); $i++) {
220  if ($this->target[$i]['id'] == $a_old_id) {
221  $this->target[$i] = array();
222  $this->target[$i] = array(
223  "text" => $a_text,
224  "link" => $a_link,
225  "frame" => $a_frame,
226  "dir_text" => true,
227  "id" => $a_new_id,
228  "cmdClass" => array());
229  return true;
230  }
231  }
232  return false;
233  }
234 
238  public function clearTargets()
239  {
240  global $DIC;
241 
242  $ilHelp = null;
243  if (isset($DIC["ilHelp"])) {
244  $ilHelp = $DIC["ilHelp"];
245  }
246 
247  if (!$this->getSetupMode()) {
248  $ilHelp->setScreenIdComponent("");
249  }
250 
251  $this->target = array();
252  $this->sub_target = array();
253  $this->non_tabbed_link = array();
254  $this->back_title = "";
255  $this->back_target = "";
256  $this->back_2_target = "";
257  $this->back_2_title = "";
258  $this->setTabActive("");
259  $this->setSubTabActive("");
260  }
261 
280  public function addSubTabTarget(
281  $a_text,
282  $a_link,
283  $a_cmd = "",
284  $a_cmdClass = "",
285  $a_frame = "",
286  $a_activate = false,
287  $a_dir_text = false
288  ) {
289  if (!$a_cmdClass) {
290  $a_cmdClass = array();
291  }
292  $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
293  #$a_cmdClass = strtolower($a_cmdClass);
294 
295  if ($a_activate) {
296  $this->subtab_manual_activation = true;
297  }
298  $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
299  "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
300  "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
301  }
302 
311  public function addSubTab($a_id, $a_text, $a_link, $a_frame = "")
312  {
313  $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
314  "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
315  }
316 
328  public function setTabActive($a_id)
329  {
330  foreach ($this->target as $key => $target) {
331  $this->target[$key]['activate'] = $this->target[$key]['id'] == $a_id;
332  }
333  if ($a_id != "") {
334  $this->manual_activation = true;
335  } else {
336  $this->manual_activation = false;
337  }
338  return true;
339  }
340 
346  public function activateTab($a_id)
347  {
348  $this->setTabActive($a_id);
349  }
350 
362  public function setSubTabActive($a_text)
363  {
364  for ($i = 0; $i < count($this->sub_target);$i++) {
365  $this->sub_target[$i]['activate'] = $this->sub_target[$i]['id'] == $a_text;
366  }
367  $this->subtab_manual_activation = true;
368  return true;
369  }
370 
376  public function activateSubTab($a_id)
377  {
378  $this->setSubTabActive($a_id);
379  }
380 
386  public function clearSubTabs()
387  {
388  $this->sub_target = array();
389  return true;
390  }
391 
395  public function getHTML($a_after_tabs_anchor = false)
396  {
397  return $this->__getHTML(false, $this->manual_activation, $a_after_tabs_anchor);
398  }
399 
403  public function getSubTabHTML()
404  {
405  return $this->__getHTML(true, $this->subtab_manual_activation);
406  }
407 
416  public function addNonTabbedLink($a_id, $a_text, $a_link, $a_frame = "")
417  {
418  $this->non_tabbed_link[] = array("text" => $a_text, "link" => $a_link,
419  "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
420  }
421 
428  public function __getHTML($a_get_sub_tabs, $a_manual, $a_after_tabs_anchor = false)
429  {
430  global $DIC;
431 
432  $ilHelp = null;
433  if (isset($DIC["ilHelp"])) {
434  $ilHelp = $DIC["ilHelp"];
435  }
436 
438  $lng = $this->lng;
439  $ilUser = null;
440  if (isset($DIC["ilUser"])) {
441  $ilUser = $DIC->user();
442  }
443  $ilPluginAdmin = null;
444  if (isset($DIC["ilPluginAdmin"])) {
445  $ilPluginAdmin = $DIC["ilPluginAdmin"];
446  }
447 
448  // user interface hook [uihk]
449  if (!$this->getSetupMode()) {
450  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "UIComponent", "uihk");
451  foreach ($pl_names as $pl) {
452  $ui_plugin = ilPluginAdmin::getPluginObject(IL_COMP_SERVICE, "UIComponent", "uihk", $pl);
453  $gui_class = $ui_plugin->getUIClassInstance();
454  $resp = $gui_class->modifyGUI(
455  "",
456  $a_get_sub_tabs ? "sub_tabs" : "tabs",
457  array("tabs" => $this)
458  );
459  }
460  }
461 
462 
463  // user interface hook [uihk]
464  if (!$this->getSetupMode()) {
465  $cmd = $ilCtrl->getCmd();
466  $cmdClass = $ilCtrl->getCmdClass();
467  }
468 
469  if ($a_get_sub_tabs) {
470  $tpl = new ilTemplate("tpl.sub_tabs.html", true, true, "Services/UIComponent/Tabs");
471  $pre = "sub";
472  $pre2 = "SUB_";
473  $sr_pre = "sub_";
474  } else {
475  $tpl = new ilTemplate("tpl.tabs.html", true, true, "Services/UIComponent/Tabs");
476  if ($a_after_tabs_anchor) {
477  $tpl->touchBlock("after_tabs");
478  }
479  $pre = $pre2 = "";
480 
481  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
482 
483  // back 2 tab
484  if ($this->back_2_title != "") {
485  $tpl->setCurrentBlock("back_2_tab");
486  $tpl->setVariable("BACK_2_ICON", ilGlyphGUI::get(ilGlyphGUI::PREVIOUS, ilGlyphGUI::NO_TEXT));
487  $tpl->setVariable("BACK_2_TAB_LINK", $this->back_2_target);
488  $tpl->setVariable("BACK_2_TAB_TEXT", $this->back_2_title);
489  if ($this->back_2_frame != "") {
490  $tpl->setVariable("BACK_2_TAB_TARGET", ' target="'.$this->back_2_frame.'" ');
491  }
492 
493  $tpl->parseCurrentBlock();
494  }
495 
496  // back tab
497  if ($this->back_title != "") {
498  $tpl->setCurrentBlock("back_tab");
499  $tpl->setVariable("BACK_ICON", ilGlyphGUI::get(ilGlyphGUI::PREVIOUS, ilGlyphGUI::NO_TEXT));
500  $tpl->setVariable("BACK_TAB_LINK", $this->back_target);
501  $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
502  if ($this->back_frame != "") {
503  $tpl->setVariable("BACK_TAB_TARGET", ' target="'.$this->back_frame.'" ');
504  }
505  $tpl->parseCurrentBlock();
506  }
507  }
508 
509  $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
510 
511  $i = 0;
512 
513  // do not display one tab only
514  if ((count($targets) > 1 || $this->force_one_tab) || ($this->back_title != "" && !$a_get_sub_tabs)
515  || (count($this->non_tabbed_link) > 0 && !$a_get_sub_tabs)) {
516  foreach ($targets as $target) {
517  $i++;
518 
519  if (!is_array($target["cmd"])) {
520  $target["cmd"] = array($target["cmd"]);
521  }
522  if (!$a_manual &&
523  (in_array($cmd, $target["cmd"]) || ($target["cmd"][0] == "" && count($target["cmd"]) == 1)) &&
524  (in_array($cmdClass, $target["cmdClass"]) || !$target["cmdClass"])) {
525  $tabtype = $pre . "tabactive";
526  } else {
527  $tabtype = $pre . "tabinactive";
528  }
529 
530  if ($a_manual && $target["activate"]) {
531  $tabtype = $pre . "tabactive";
532  }
533 
534  if ($tabtype == "tabactive" || $tabtype == "subtabactive") {
535  $tpl->setCurrentBlock("sel_text");
536  $tpl->setVariable("TXT_SELECTED", $lng->txt("stat_selected"));
537  $tpl->parseCurrentBlock();
538 
539  if (!$this->getSetupMode()) {
540  if ($a_get_sub_tabs) {
542  } else {
544  }
545  $ilHelp->setDefaultScreenId($part, $target["id"]);
546  }
547  }
548 
549  $tpl->setCurrentBlock($pre . "tab");
550  $tpl->setVariable("ID", $pre . "tab_" . $target["id"]);
551 
552  // tooltip
553  if (!$this->getSetupMode()) {
554  $ttext = $ilHelp->getTabTooltipText($target["id"]);
555  if ($ttext != "") {
556  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
558  $pre . "tab_" . $target["id"],
559  $ttext,
560  "",
561  "bottom center",
562  "top center",
563  false
564  );
565  }
566  }
567 
568  // bs-patch: start
569  $tabtype = in_array($tabtype, array("tabactive", "subtabactive"))
570  ? "active"
571  : "";
572  // bs-patch: end
573 
574  $tpl->setVariable($pre2 . "TAB_TYPE", $tabtype);
575  if (!$this->getSetupMode()) {
576  $hash = ($ilUser->getPref("screen_reader_optimization"))
577  ? "#after_" . $sr_pre . "tabs"
578  : "";
579  }
580 
581  $tpl->setVariable($pre2 . "TAB_LINK", $target["link"] . $hash);
582  if ($target["dir_text"]) {
583  $tpl->setVariable($pre2 . "TAB_TEXT", $target["text"]);
584  } else {
585  $tpl->setVariable($pre2 . "TAB_TEXT", $lng->txt($target["text"]));
586  }
587  if ($target["frame"] != "") {
588  $tpl->setVariable($pre2 . "TAB_TARGET", ' target="'.$target["frame"].'" ');
589  }
590  $tpl->parseCurrentBlock();
591  }
592 
593  if ($a_get_sub_tabs) {
594  $tpl->setVariable("TXT_SUBTABS", $lng->txt("subtabs"));
595  } else {
596  $tpl->setVariable("TXT_TABS", $lng->txt("tabs"));
597 
598  // non tabbed links
599  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
600  foreach ($this->non_tabbed_link as $link) {
601  $tpl->setCurrentBlock("tab");
602  $tpl->setVariable("TAB_TYPE", "nontabbed");
603  $tpl->setVariable("TAB_ICON", " " . ilGlyphGUI::get(ilGlyphGUI::NEXT, ilGlyphGUI::NO_TEXT));
604  $tpl->setVariable("TAB_TEXT", $link["text"]);
605  $tpl->setVariable("TAB_LINK", $link["link"]);
606  $tpl->setVariable("TAB_TARGET", $link["frame"]);
607  $tpl->setVariable("ID", "nontab_" . $link["id"]);
608  $tpl->parseCurrentBlock();
609 
610  // tooltip
611  if (!$this->getSetupMode()) {
612  $ttext = $ilHelp->getTabTooltipText($link["id"]);
613  if ($ttext != "") {
614  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
616  "nontab_" . $link["id"],
617  $ttext,
618  "",
619  "bottom center",
620  "top center",
621  false
622  );
623  }
624  }
625  }
626  }
627 
628  return $tpl->get();
629  } else {
630  return "";
631  }
632  }
633 
634  public function getActiveTab()
635  {
636  foreach ($this->target as $i => $target) {
637  if ($this->target[$i]['activate']) {
638  return $this->target[$i]['id'];
639  }
640  }
641  }
642 
643  public function hasTabs()
644  {
645  return (bool) sizeof($this->target);
646  }
647 }
getSetupMode()
Get setup mode.
static addTooltip( $a_el_id, $a_text, $a_container="", $a_my="bottom center", $a_at="top center", $a_use_htmlspecialchars=true)
Adds a tooltip to an HTML element.
addSubTabTarget( $a_text, $a_link, $a_cmd="", $a_cmdClass="", $a_frame="", $a_activate=false, $a_dir_text=false)
DEPRECATED.
setTabActive($a_id)
DEPRECATED.
Tabs GUI.
global $DIC
Definition: saml.php:7
activateSubTab($a_id)
Activate a specific subtab identified its id.
getSubTabHTML()
get sub tabs code as html
static get($a_glyph, $a_text="")
Get glyph html.
setBack2Target($a_title, $a_target, $a_frame="")
back target for tow level upper context
addTarget( $a_text, $a_link, $a_cmd="", $a_cmdClass="", $a_frame="", $a_activate=false, $a_dir_text=false)
const ID_PART_SUB_SCREEN
setBackTarget($a_title, $a_target, $a_frame="")
back target for upper context
getForcePresentationOfSingleTab()
Get force presentation of single tab.
global $ilCtrl
Definition: ilias.php:18
replaceTab($a_old_id, $a_new_id, $a_text, $a_link, $a_frame='')
Replace a tab.
setSubTabActive($a_text)
DEPRECATED.
special template class to simplify handling of ITX/PEAR
$ilUser
Definition: imgupload.php:18
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
setForcePresentationOfSingleTab($a_val)
Set force presentation of single tab.
addSubTab($a_id, $a_text, $a_link, $a_frame="")
Add a Subtab.
clearSubTabs()
Clear all already added sub tabs.
__getHTML($a_get_sub_tabs, $a_manual, $a_after_tabs_anchor=false)
get tabs code as html
clearTargets()
clear all targets
addNonTabbedLink($a_id, $a_text, $a_link, $a_frame="")
Add a non-tabbed link (outside of tabs at same level)
__construct()
Constructor public.
removeTab($a_id)
Remove a tab identified by its id.
activateTab($a_id)
Activate a specific tab identified its id.
removeSubTab($a_id)
Remove a tab identified by its id.
getHTML($a_after_tabs_anchor=false)
get tabs code as html
setSetupMode($a_val)
Set setup mode.
$i
Definition: disco.tpl.php:19
addTab($a_id, $a_text, $a_link, $a_frame="")
Add a Tab.
$key
Definition: croninfo.php:18
const ID_PART_SCREEN
const IL_COMP_SERVICE