ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
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 var $setup_mode = false;
24
29 function ilTabsGUI()
30 {
31 global $tpl, $objDefinition, $lng;
32
33 $this->tpl =& $tpl;
34 $this->lng =& $lng;
35 $this->objDefinition =& $objDefinition;
36 $this->manual_activation = false;
37 $this->subtab_manual_activation = false;
38 $this->temp_var = "TABS";
39 $this->sub_tabs = false;
40 $this->back_title = "";
41 $this->back_target = "";
42 $this->back_2_target = "";
43 $this->back_2_title = "";
44 }
45
51 function setSetupMode($a_val)
52 {
53 $this->setup_mode = $a_val;
54 }
55
61 function getSetupMode()
62 {
63 return $this->setup_mode;
64 }
65
69 function setBackTarget($a_title, $a_target, $a_frame = "")
70 {
71 $this->back_title = $a_title;
72 $this->back_target = $a_target;
73 $this->back_frame = $a_frame;
74 }
75
79 function setBack2Target($a_title, $a_target, $a_frame = "")
80 {
81 $this->back_2_title = $a_title;
82 $this->back_2_target = $a_target;
83 $this->back_2_frame = $a_frame;
84 }
85
86
104 function addTarget($a_text, $a_link, $a_cmd = "", $a_cmdClass = "", $a_frame = "", $a_activate = false,
105 $a_dir_text = false)
106 {
107 if(!$a_cmdClass)
108 {
109 $a_cmdClass = array();
110 }
111 $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
112 #$a_cmdClass = strtolower($a_cmdClass);
113
114 if ($a_activate)
115 {
116 $this->manual_activation = true;
117 }
118 $this->target[] = array("text" => $a_text, "link" => $a_link,
119 "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
120 "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
121 }
122
131 function addTab($a_id, $a_text, $a_link, $a_frame = "")
132 {
133 $this->target[] = array("text" => $a_text, "link" => $a_link,
134 "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
135 }
136
144 public function removeTab($a_id)
145 {
146 foreach($this->target as $key => $target)
147 {
148 if($target['id'] == $a_id)
149 {
150 unset($this->target[$key]);
151 return true;
152 }
153 }
154 return false;
155 }
156
164 public function removeSubTab($a_id)
165 {
166 foreach($this->sub_target as $i => $sub_target){
167 if($this->sub_target[$i]['id'] == $a_id)
168 {
169 unset($this->sub_target[$i]);
170 return true;
171 }
172 }
173 return false;
174 }
175
187 public function replaceTab($a_old_id,$a_new_id,$a_text,$a_link,$a_frame = '')
188 {
189 for($i = 0; $i < count($this->target); $i++)
190 {
191 if($this->target[$i]['id'] == $a_old_id)
192 {
193 $this->target[$i] = array();
194 $this->target[$i] = array(
195 "text" => $a_text,
196 "link" => $a_link,
197 "frame" => $a_frame,
198 "dir_text" => true,
199 "id" => $a_new_id,
200 "cmdClass" => array());
201 return true;
202 }
203 }
204 return false;
205 }
206
210 function clearTargets()
211 {
212 global $ilHelp;
213
214 if (!$this->getSetupMode())
215 {
216 $ilHelp->setScreenIdComponent("");
217 }
218
219 $this->target = array();
220 $this->sub_target = array();
221 $this->non_tabbed_link = array();
222 $this->back_title = "";
223 $this->back_target = "";
224 $this->back_2_target = "";
225 $this->back_2_title = "";
226 $this->setTabActive("");
227 $this->setSubTabActive("");
228 }
229
248 function addSubTabTarget($a_text, $a_link, $a_cmd = "", $a_cmdClass = "", $a_frame = "", $a_activate = false,
249 $a_dir_text = false)
250 {
251
252 if(!$a_cmdClass)
253 {
254 $a_cmdClass = array();
255 }
256 $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
257 #$a_cmdClass = strtolower($a_cmdClass);
258
259 if ($a_activate)
260 {
261 $this->subtab_manual_activation = true;
262 }
263 $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
264 "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
265 "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
266 }
267
276 function addSubTab($a_id, $a_text, $a_link, $a_frame = "")
277 {
278 $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
279 "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
280 }
281
292 function setTabActive($a_id)
293 {
294 foreach($this->target as $key => $target)
295 {
296 $this->target[$key]['activate'] = $this->target[$key]['id'] == $a_id;
297 }
298 if ($a_id != "")
299 {
300 $this->manual_activation = true;
301 }
302 else
303 {
304 $this->manual_activation = false;
305 }
306 return true;
307 }
308
314 function activateTab($a_id)
315 {
316 $this->setTabActive($a_id);
317 }
318
330 function setSubTabActive($a_text)
331 {
332 for($i = 0; $i < count($this->sub_target);$i++)
333 {
334 $this->sub_target[$i]['activate'] = $this->sub_target[$i]['id'] == $a_text;
335 }
336 $this->subtab_manual_activation = true;
337 return true;
338 }
339
345 function activateSubTab($a_id)
346 {
347 $this->setSubTabActive($a_id);
348 }
349
355 function clearSubTabs()
356 {
357 $this->sub_target = array();
358 return true;
359 }
360
364 function getHTML($a_after_tabs_anchor = false)
365 {
366 return $this->__getHTML(false,$this->manual_activation, $a_after_tabs_anchor);
367 }
368
372 function getSubTabHTML()
373 {
374 return $this->__getHTML(true,$this->subtab_manual_activation);
375 }
376
385 function addNonTabbedLink($a_id, $a_text, $a_link, $a_frame = "")
386 {
387 $this->non_tabbed_link[] = array("text" => $a_text, "link" => $a_link,
388 "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
389 }
390
397 function __getHTML($a_get_sub_tabs,$a_manual, $a_after_tabs_anchor = false)
398 {
399 global $ilCtrl, $lng, $ilUser, $ilPluginAdmin, $ilHelp;
400
401 // user interface hook [uihk]
402 if (!$this->getSetupMode())
403 {
404 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "UIComponent", "uihk");
405 foreach ($pl_names as $pl)
406 {
407 $ui_plugin = ilPluginAdmin::getPluginObject(IL_COMP_SERVICE, "UIComponent", "uihk", $pl);
408 $gui_class = $ui_plugin->getUIClassInstance();
409 $resp = $gui_class->modifyGUI("", $a_get_sub_tabs ? "sub_tabs" : "tabs",
410 array("tabs" => $this));
411 }
412 }
413
414
415 // user interface hook [uihk]
416 if (!$this->getSetupMode())
417 {
418 $cmd = $ilCtrl->getCmd();
419 $cmdClass = $ilCtrl->getCmdClass();
420 }
421
422 if ($a_get_sub_tabs)
423 {
424 $tpl = new ilTemplate("tpl.sub_tabs.html", true, true, "Services/UIComponent/Tabs");
425 $pre = "sub";
426 $pre2 = "SUB_";
427 $sr_pre = "sub_";
428 }
429 else
430 {
431 $tpl = new ilTemplate("tpl.tabs.html", true, true, "Services/UIComponent/Tabs");
432 if ($a_after_tabs_anchor)
433 {
434 $tpl->touchBlock("after_tabs");
435 }
436 $pre = $pre2 = "";
437
438 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
439
440 // back 2 tab
441 if ($this->back_2_title != "")
442 {
443 $tpl->setCurrentBlock("back_2_tab");
444 $tpl->setVariable("BACK_2_ICON", ilGlyphGUI::get(ilGlyphGUI::PREVIOUS, ilGlyphGUI::NO_TEXT));
445 $tpl->setVariable("BACK_2_TAB_LINK", $this->back_2_target);
446 $tpl->setVariable("BACK_2_TAB_TEXT", $this->back_2_title);
447 $tpl->setVariable("BACK_2_TAB_TARGET", $this->back_2_frame);
448 $tpl->parseCurrentBlock();
449 }
450
451 // back tab
452 if ($this->back_title != "")
453 {
454 $tpl->setCurrentBlock("back_tab");
456 $tpl->setVariable("BACK_TAB_LINK", $this->back_target);
457 $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
458 $tpl->setVariable("BACK_TAB_TARGET", $this->back_frame);
459 $tpl->parseCurrentBlock();
460 }
461 }
462
463 $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
464
465 $i=0;
466
467 // do not display one tab only
468 if ((count($targets) > 1) || ($this->back_title != "" && !$a_get_sub_tabs)
469 || (count($this->non_tabbed_link) > 0 && !$a_get_sub_tabs))
470 {
471 foreach ($targets as $target)
472 {
473 $i++;
474
475 if (!is_array($target["cmd"]))
476 {
477 $target["cmd"] = array($target["cmd"]);
478 }
479 if (!$a_manual &&
480 (in_array($cmd, $target["cmd"]) || ($target["cmd"][0] == "" && count($target["cmd"]) == 1)) &&
481 (in_array($cmdClass,$target["cmdClass"]) || !$target["cmdClass"]))
482 {
483 $tabtype = $pre."tabactive";
484 }
485 else
486 {
487 $tabtype = $pre."tabinactive";
488 }
489
490 if ($a_manual && $target["activate"])
491 {
492 $tabtype = $pre."tabactive";
493 }
494
495 if ($tabtype == "tabactive" || $tabtype == "subtabactive")
496 {
497 $tpl->setCurrentBlock("sel_text");
498 $tpl->setVariable("TXT_SELECTED", $lng->txt("stat_selected"));
499 $tpl->parseCurrentBlock();
500
501 if (!$this->getSetupMode())
502 {
503 if ($a_get_sub_tabs)
504 {
506 }
507 else
508 {
510 }
511 $ilHelp->setDefaultScreenId($part, $target["id"]);
512 }
513 }
514
515 $tpl->setCurrentBlock($pre."tab");
516 $tpl->setVariable("ID", $pre."tab_".$target["id"]);
517
518 // tooltip
519 if (!$this->getSetupMode())
520 {
521 $ttext = $ilHelp->getTabTooltipText($target["id"]);
522 if ($ttext != "")
523 {
524 include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
525 ilTooltipGUI::addTooltip($pre."tab_".$target["id"], $ttext, "",
526 "bottom center", "top center", false);
527 }
528 }
529
530 // bs-patch: start
531 $tabtype = in_array($tabtype, array("tabactive", "subtabactive"))
532 ? "active"
533 : "";
534 // bs-patch: end
535
536 $tpl->setVariable($pre2."TAB_TYPE", $tabtype);
537 if (!$this->getSetupMode())
538 {
539 $hash = ($ilUser->getPref("screen_reader_optimization"))
540 ? "#after_".$sr_pre."tabs"
541 : "";
542 }
543
544 $tpl->setVariable($pre2."TAB_LINK", $target["link"].$hash);
545 if ($target["dir_text"])
546 {
547 $tpl->setVariable($pre2."TAB_TEXT", $target["text"]);
548 }
549 else
550 {
551 $tpl->setVariable($pre2."TAB_TEXT", $lng->txt($target["text"]));
552 }
553 $tpl->setVariable($pre2."TAB_TARGET", $target["frame"]);
554 $tpl->parseCurrentBlock();
555 }
556
557 if ($a_get_sub_tabs)
558 {
559 $tpl->setVariable("TXT_SUBTABS", $lng->txt("subtabs"));
560 }
561 else
562 {
563 $tpl->setVariable("TXT_TABS", $lng->txt("tabs"));
564
565 // non tabbed links
566 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
567 foreach ($this->non_tabbed_link as $link)
568 {
569 $tpl->setCurrentBlock("tab");
570 $tpl->setVariable("TAB_TYPE", "nontabbed");
571 $tpl->setVariable("TAB_ICON", " ".ilGlyphGUI::get(ilGlyphGUI::NEXT, ilGlyphGUI::NO_TEXT));
572 $tpl->setVariable("TAB_TEXT", $link["text"]);
573 $tpl->setVariable("TAB_LINK", $link["link"]);
574 $tpl->setVariable("TAB_TARGET", $link["frame"]);
575 $tpl->setVariable("ID", "nontab_".$link["id"]);
576 $tpl->parseCurrentBlock();
577
578 // tooltip
579 if (!$this->getSetupMode())
580 {
581 $ttext = $ilHelp->getTabTooltipText($link["id"]);
582 if ($ttext != "")
583 {
584 include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
585 ilTooltipGUI::addTooltip("nontab_".$link["id"], $ttext, "",
586 "bottom center", "top center", false);
587 }
588 }
589 }
590 }
591
592 return $tpl->get();
593 }
594 else
595 {
596 return "";
597 }
598 }
599
600 function getActiveTab(){
601 foreach($this->target as $i => $target){
602 if($this->target[$i]['activate'])
603 return $this->target[$i]['id'];
604 }
605 }
606
607 function hasTabs()
608 {
609 return (bool)sizeof($this->target);
610 }
611}
612?>
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.
getSubTabHTML()
get sub tabs code as html
getHTML($a_after_tabs_anchor=false)
get tabs code as html
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.
ilTabsGUI()
Constructor @access public.
removeTab($a_id)
Remove a tab identified by its id.
__getHTML($a_get_sub_tabs, $a_manual, $a_after_tabs_anchor=false)
get tabs code as html
addSubTabTarget($a_text, $a_link, $a_cmd="", $a_cmdClass="", $a_frame="", $a_activate=false, $a_dir_text=false)
DEPRECATED.
clearTargets()
clear all targets
setTabActive($a_id)
DEPRECATED.
removeSubTab($a_id)
Remove a tab identified by its id.
setBackTarget($a_title, $a_target, $a_frame="")
back target for upper context
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.
addTarget($a_text, $a_link, $a_cmd="", $a_cmdClass="", $a_frame="", $a_activate=false, $a_dir_text=false)
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.
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
global $ilUser
Definition: imgupload.php:15