ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
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 {
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
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 $tpl->setVariable("BACK_2_TAB_TARGET", $this->back_2_frame);
490 $tpl->parseCurrentBlock();
491 }
492
493 // back tab
494 if ($this->back_title != "") {
495 $tpl->setCurrentBlock("back_tab");
497 $tpl->setVariable("BACK_TAB_LINK", $this->back_target);
498 $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
499 $tpl->setVariable("BACK_TAB_TARGET", $this->back_frame);
500 $tpl->parseCurrentBlock();
501 }
502 }
503
504 $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
505
506 $i=0;
507
508 // do not display one tab only
509 if ((count($targets) > 1 || $this->force_one_tab) || ($this->back_title != "" && !$a_get_sub_tabs)
510 || (count($this->non_tabbed_link) > 0 && !$a_get_sub_tabs)) {
511 foreach ($targets as $target) {
512 $i++;
513
514 if (!is_array($target["cmd"])) {
515 $target["cmd"] = array($target["cmd"]);
516 }
517 if (!$a_manual &&
518 (in_array($cmd, $target["cmd"]) || ($target["cmd"][0] == "" && count($target["cmd"]) == 1)) &&
519 (in_array($cmdClass, $target["cmdClass"]) || !$target["cmdClass"])) {
520 $tabtype = $pre . "tabactive";
521 } else {
522 $tabtype = $pre . "tabinactive";
523 }
524
525 if ($a_manual && $target["activate"]) {
526 $tabtype = $pre . "tabactive";
527 }
528
529 if ($tabtype == "tabactive" || $tabtype == "subtabactive") {
530 $tpl->setCurrentBlock("sel_text");
531 $tpl->setVariable("TXT_SELECTED", $lng->txt("stat_selected"));
532 $tpl->parseCurrentBlock();
533
534 if (!$this->getSetupMode()) {
535 if ($a_get_sub_tabs) {
537 } else {
539 }
540 $ilHelp->setDefaultScreenId($part, $target["id"]);
541 }
542 }
543
544 $tpl->setCurrentBlock($pre . "tab");
545 $tpl->setVariable("ID", $pre . "tab_" . $target["id"]);
546
547 // tooltip
548 if (!$this->getSetupMode()) {
549 $ttext = $ilHelp->getTabTooltipText($target["id"]);
550 if ($ttext != "") {
551 include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
553 $pre . "tab_" . $target["id"],
554 $ttext,
555 "",
556 "bottom center",
557 "top center",
558 false
559 );
560 }
561 }
562
563 // bs-patch: start
564 $tabtype = in_array($tabtype, array("tabactive", "subtabactive"))
565 ? "active"
566 : "";
567 // bs-patch: end
568
569 $tpl->setVariable($pre2 . "TAB_TYPE", $tabtype);
570 if (!$this->getSetupMode()) {
571 $hash = ($ilUser->getPref("screen_reader_optimization"))
572 ? "#after_" . $sr_pre . "tabs"
573 : "";
574 }
575
576 $tpl->setVariable($pre2 . "TAB_LINK", $target["link"] . $hash);
577 if ($target["dir_text"]) {
578 $tpl->setVariable($pre2 . "TAB_TEXT", $target["text"]);
579 } else {
580 $tpl->setVariable($pre2 . "TAB_TEXT", $lng->txt($target["text"]));
581 }
582 $tpl->setVariable($pre2 . "TAB_TARGET", $target["frame"]);
583 $tpl->parseCurrentBlock();
584 }
585
586 if ($a_get_sub_tabs) {
587 $tpl->setVariable("TXT_SUBTABS", $lng->txt("subtabs"));
588 } else {
589 $tpl->setVariable("TXT_TABS", $lng->txt("tabs"));
590
591 // non tabbed links
592 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
593 foreach ($this->non_tabbed_link as $link) {
594 $tpl->setCurrentBlock("tab");
595 $tpl->setVariable("TAB_TYPE", "nontabbed");
596 $tpl->setVariable("TAB_ICON", " " . ilGlyphGUI::get(ilGlyphGUI::NEXT, ilGlyphGUI::NO_TEXT));
597 $tpl->setVariable("TAB_TEXT", $link["text"]);
598 $tpl->setVariable("TAB_LINK", $link["link"]);
599 $tpl->setVariable("TAB_TARGET", $link["frame"]);
600 $tpl->setVariable("ID", "nontab_" . $link["id"]);
601 $tpl->parseCurrentBlock();
602
603 // tooltip
604 if (!$this->getSetupMode()) {
605 $ttext = $ilHelp->getTabTooltipText($link["id"]);
606 if ($ttext != "") {
607 include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
609 "nontab_" . $link["id"],
610 $ttext,
611 "",
612 "bottom center",
613 "top center",
614 false
615 );
616 }
617 }
618 }
619 }
620
621 return $tpl->get();
622 } else {
623 return "";
624 }
625 }
626
627 public function getActiveTab()
628 {
629 foreach ($this->target as $i => $target) {
630 if ($this->target[$i]['activate']) {
631 return $this->target[$i]['id'];
632 }
633 }
634 }
635
636 public function hasTabs()
637 {
638 return (bool) sizeof($this->target);
639 }
640}
An exception for terminatinating execution or to throw for unit testing.
const IL_COMP_SERVICE
static get($a_glyph, $a_text="")
Get glyph html.
const ID_PART_SCREEN
const ID_PART_SUB_SCREEN
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
Tabs GUI.
__construct()
Constructor @access public.
getSubTabHTML()
get sub tabs code as html
getHTML($a_after_tabs_anchor=false)
get tabs code as html
getForcePresentationOfSingleTab()
Get force presentation of single tab.
addNonTabbedLink($a_id, $a_text, $a_link, $a_frame="")
Add a non-tabbed link (outside of tabs at same level)
replaceTab($a_old_id, $a_new_id, $a_text, $a_link, $a_frame='')
Replace a tab.
activateSubTab($a_id)
Activate a specific subtab identified its id.
clearSubTabs()
Clear all already added sub tabs.
setSetupMode($a_val)
Set setup mode.
getSetupMode()
Get setup mode.
removeTab($a_id)
Remove a tab identified by its id.
setForcePresentationOfSingleTab($a_val)
Set force presentation of single tab.
__getHTML($a_get_sub_tabs, $a_manual, $a_after_tabs_anchor=false)
get tabs code as html
clearTargets()
clear all targets
setTabActive($a_id)
DEPRECATED.
removeSubTab($a_id)
Remove a tab identified by its id.
addTarget( $a_text, $a_link, $a_cmd="", $a_cmdClass="", $a_frame="", $a_activate=false, $a_dir_text=false)
setBackTarget($a_title, $a_target, $a_frame="")
back target for upper context
addSubTabTarget( $a_text, $a_link, $a_cmd="", $a_cmdClass="", $a_frame="", $a_activate=false, $a_dir_text=false)
DEPRECATED.
addTab($a_id, $a_text, $a_link, $a_frame="")
Add a Tab.
activateTab($a_id)
Activate a specific tab identified its id.
setBack2Target($a_title, $a_target, $a_frame="")
back target for tow level upper context
setSubTabActive($a_text)
DEPRECATED.
addSubTab($a_id, $a_text, $a_link, $a_frame="")
Add a Subtab.
special template class to simplify handling of ITX/PEAR
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.
$key
Definition: croninfo.php:18
$i
Definition: disco.tpl.php:19
global $ilCtrl
Definition: ilias.php:18
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18