ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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();
23  var $setup_mode = false;
24 
25  protected $force_one_tab = false;
26 
31  function __construct()
32  {
33  global $tpl, $objDefinition, $lng;
34 
35  $this->tpl = $tpl;
36  $this->lng = $lng;
37  $this->objDefinition = $objDefinition;
38  $this->manual_activation = false;
39  $this->subtab_manual_activation = false;
40  $this->temp_var = "TABS";
41  $this->sub_tabs = false;
42  $this->back_title = "";
43  $this->back_target = "";
44  $this->back_2_target = "";
45  $this->back_2_title = "";
46  }
47 
53  function setSetupMode($a_val)
54  {
55  $this->setup_mode = $a_val;
56  }
57 
63  function getSetupMode()
64  {
65  return $this->setup_mode;
66  }
67 
71  function setBackTarget($a_title, $a_target, $a_frame = "")
72  {
73  $this->back_title = $a_title;
74  $this->back_target = $a_target;
75  $this->back_frame = $a_frame;
76  }
77 
81  function setBack2Target($a_title, $a_target, $a_frame = "")
82  {
83  $this->back_2_title = $a_title;
84  $this->back_2_target = $a_target;
85  $this->back_2_frame = $a_frame;
86  }
87 
94  {
95  $this->force_one_tab = $a_val;
96  }
97 
104  {
105  return $this->force_one_tab;
106  }
107 
125  function addTarget($a_text, $a_link, $a_cmd = "", $a_cmdClass = "", $a_frame = "", $a_activate = false,
126  $a_dir_text = false)
127  {
128  if(!$a_cmdClass)
129  {
130  $a_cmdClass = array();
131  }
132  $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
133  #$a_cmdClass = strtolower($a_cmdClass);
134 
135  if ($a_activate)
136  {
137  $this->manual_activation = true;
138  }
139  $this->target[] = array("text" => $a_text, "link" => $a_link,
140  "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
141  "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
142  }
143 
152  function addTab($a_id, $a_text, $a_link, $a_frame = "")
153  {
154  $this->target[] = array("text" => $a_text, "link" => $a_link,
155  "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
156  }
157 
165  public function removeTab($a_id)
166  {
167  foreach($this->target as $key => $target)
168  {
169  if($target['id'] == $a_id)
170  {
171  unset($this->target[$key]);
172  return true;
173  }
174  }
175  return false;
176  }
177 
185  public function removeSubTab($a_id)
186  {
187  foreach($this->sub_target as $i => $sub_target){
188  if($this->sub_target[$i]['id'] == $a_id)
189  {
190  unset($this->sub_target[$i]);
191  return true;
192  }
193  }
194  return false;
195  }
196 
208  public function replaceTab($a_old_id,$a_new_id,$a_text,$a_link,$a_frame = '')
209  {
210  for($i = 0; $i < count($this->target); $i++)
211  {
212  if($this->target[$i]['id'] == $a_old_id)
213  {
214  $this->target[$i] = array();
215  $this->target[$i] = array(
216  "text" => $a_text,
217  "link" => $a_link,
218  "frame" => $a_frame,
219  "dir_text" => true,
220  "id" => $a_new_id,
221  "cmdClass" => array());
222  return true;
223  }
224  }
225  return false;
226  }
227 
231  function clearTargets()
232  {
233  global $ilHelp;
234 
235  if (!$this->getSetupMode())
236  {
237  $ilHelp->setScreenIdComponent("");
238  }
239 
240  $this->target = array();
241  $this->sub_target = array();
242  $this->non_tabbed_link = array();
243  $this->back_title = "";
244  $this->back_target = "";
245  $this->back_2_target = "";
246  $this->back_2_title = "";
247  $this->setTabActive("");
248  $this->setSubTabActive("");
249  }
250 
269  function addSubTabTarget($a_text, $a_link, $a_cmd = "", $a_cmdClass = "", $a_frame = "", $a_activate = false,
270  $a_dir_text = false)
271  {
272 
273  if(!$a_cmdClass)
274  {
275  $a_cmdClass = array();
276  }
277  $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
278  #$a_cmdClass = strtolower($a_cmdClass);
279 
280  if ($a_activate)
281  {
282  $this->subtab_manual_activation = true;
283  }
284  $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
285  "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
286  "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
287  }
288 
297  function addSubTab($a_id, $a_text, $a_link, $a_frame = "")
298  {
299  $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
300  "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
301  }
302 
314  function setTabActive($a_id)
315  {
316  foreach($this->target as $key => $target)
317  {
318  $this->target[$key]['activate'] = $this->target[$key]['id'] == $a_id;
319  }
320  if ($a_id != "")
321  {
322  $this->manual_activation = true;
323  }
324  else
325  {
326  $this->manual_activation = false;
327  }
328  return true;
329  }
330 
336  function activateTab($a_id)
337  {
338  $this->setTabActive($a_id);
339  }
340 
352  function setSubTabActive($a_text)
353  {
354  for($i = 0; $i < count($this->sub_target);$i++)
355  {
356  $this->sub_target[$i]['activate'] = $this->sub_target[$i]['id'] == $a_text;
357  }
358  $this->subtab_manual_activation = true;
359  return true;
360  }
361 
367  function activateSubTab($a_id)
368  {
369  $this->setSubTabActive($a_id);
370  }
371 
377  function clearSubTabs()
378  {
379  $this->sub_target = array();
380  return true;
381  }
382 
386  function getHTML($a_after_tabs_anchor = false)
387  {
388  return $this->__getHTML(false,$this->manual_activation, $a_after_tabs_anchor);
389  }
390 
394  function getSubTabHTML()
395  {
396  return $this->__getHTML(true,$this->subtab_manual_activation);
397  }
398 
407  function addNonTabbedLink($a_id, $a_text, $a_link, $a_frame = "")
408  {
409  $this->non_tabbed_link[] = array("text" => $a_text, "link" => $a_link,
410  "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
411  }
412 
419  function __getHTML($a_get_sub_tabs,$a_manual, $a_after_tabs_anchor = false)
420  {
421  global $ilCtrl, $lng, $ilUser, $ilPluginAdmin, $ilHelp;
422 
423  // user interface hook [uihk]
424  if (!$this->getSetupMode())
425  {
426  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "UIComponent", "uihk");
427  foreach ($pl_names as $pl)
428  {
429  $ui_plugin = ilPluginAdmin::getPluginObject(IL_COMP_SERVICE, "UIComponent", "uihk", $pl);
430  $gui_class = $ui_plugin->getUIClassInstance();
431  $resp = $gui_class->modifyGUI("", $a_get_sub_tabs ? "sub_tabs" : "tabs",
432  array("tabs" => $this));
433  }
434  }
435 
436 
437  // user interface hook [uihk]
438  if (!$this->getSetupMode())
439  {
440  $cmd = $ilCtrl->getCmd();
441  $cmdClass = $ilCtrl->getCmdClass();
442  }
443 
444  if ($a_get_sub_tabs)
445  {
446  $tpl = new ilTemplate("tpl.sub_tabs.html", true, true, "Services/UIComponent/Tabs");
447  $pre = "sub";
448  $pre2 = "SUB_";
449  $sr_pre = "sub_";
450  }
451  else
452  {
453  $tpl = new ilTemplate("tpl.tabs.html", true, true, "Services/UIComponent/Tabs");
454  if ($a_after_tabs_anchor)
455  {
456  $tpl->touchBlock("after_tabs");
457  }
458  $pre = $pre2 = "";
459 
460  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
461 
462  // back 2 tab
463  if ($this->back_2_title != "")
464  {
465  $tpl->setCurrentBlock("back_2_tab");
466  $tpl->setVariable("BACK_2_ICON", ilGlyphGUI::get(ilGlyphGUI::PREVIOUS, ilGlyphGUI::NO_TEXT));
467  $tpl->setVariable("BACK_2_TAB_LINK", $this->back_2_target);
468  $tpl->setVariable("BACK_2_TAB_TEXT", $this->back_2_title);
469  $tpl->setVariable("BACK_2_TAB_TARGET", $this->back_2_frame);
470  $tpl->parseCurrentBlock();
471  }
472 
473  // back tab
474  if ($this->back_title != "")
475  {
476  $tpl->setCurrentBlock("back_tab");
477  $tpl->setVariable("BACK_ICON", ilGlyphGUI::get(ilGlyphGUI::PREVIOUS, ilGlyphGUI::NO_TEXT));
478  $tpl->setVariable("BACK_TAB_LINK", $this->back_target);
479  $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
480  $tpl->setVariable("BACK_TAB_TARGET", $this->back_frame);
481  $tpl->parseCurrentBlock();
482  }
483  }
484 
485  $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
486 
487  $i=0;
488 
489  // do not display one tab only
490  if ((count($targets) > 1 || $this->force_one_tab) || ($this->back_title != "" && !$a_get_sub_tabs)
491  || (count($this->non_tabbed_link) > 0 && !$a_get_sub_tabs))
492  {
493  foreach ($targets as $target)
494  {
495  $i++;
496 
497  if (!is_array($target["cmd"]))
498  {
499  $target["cmd"] = array($target["cmd"]);
500  }
501  if (!$a_manual &&
502  (in_array($cmd, $target["cmd"]) || ($target["cmd"][0] == "" && count($target["cmd"]) == 1)) &&
503  (in_array($cmdClass,$target["cmdClass"]) || !$target["cmdClass"]))
504  {
505  $tabtype = $pre."tabactive";
506  }
507  else
508  {
509  $tabtype = $pre."tabinactive";
510  }
511 
512  if ($a_manual && $target["activate"])
513  {
514  $tabtype = $pre."tabactive";
515  }
516 
517  if ($tabtype == "tabactive" || $tabtype == "subtabactive")
518  {
519  $tpl->setCurrentBlock("sel_text");
520  $tpl->setVariable("TXT_SELECTED", $lng->txt("stat_selected"));
521  $tpl->parseCurrentBlock();
522 
523  if (!$this->getSetupMode())
524  {
525  if ($a_get_sub_tabs)
526  {
528  }
529  else
530  {
532  }
533  $ilHelp->setDefaultScreenId($part, $target["id"]);
534  }
535  }
536 
537  $tpl->setCurrentBlock($pre."tab");
538  $tpl->setVariable("ID", $pre."tab_".$target["id"]);
539 
540  // tooltip
541  if (!$this->getSetupMode())
542  {
543  $ttext = $ilHelp->getTabTooltipText($target["id"]);
544  if ($ttext != "")
545  {
546  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
547  ilTooltipGUI::addTooltip($pre."tab_".$target["id"], $ttext, "",
548  "bottom center", "top center", false);
549  }
550  }
551 
552  // bs-patch: start
553  $tabtype = in_array($tabtype, array("tabactive", "subtabactive"))
554  ? "active"
555  : "";
556  // bs-patch: end
557 
558  $tpl->setVariable($pre2."TAB_TYPE", $tabtype);
559  if (!$this->getSetupMode())
560  {
561  $hash = ($ilUser->getPref("screen_reader_optimization"))
562  ? "#after_".$sr_pre."tabs"
563  : "";
564  }
565 
566  $tpl->setVariable($pre2."TAB_LINK", $target["link"].$hash);
567  if ($target["dir_text"])
568  {
569  $tpl->setVariable($pre2."TAB_TEXT", $target["text"]);
570  }
571  else
572  {
573  $tpl->setVariable($pre2."TAB_TEXT", $lng->txt($target["text"]));
574  }
575  $tpl->setVariable($pre2."TAB_TARGET", $target["frame"]);
576  $tpl->parseCurrentBlock();
577  }
578 
579  if ($a_get_sub_tabs)
580  {
581  $tpl->setVariable("TXT_SUBTABS", $lng->txt("subtabs"));
582  }
583  else
584  {
585  $tpl->setVariable("TXT_TABS", $lng->txt("tabs"));
586 
587  // non tabbed links
588  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
589  foreach ($this->non_tabbed_link as $link)
590  {
591  $tpl->setCurrentBlock("tab");
592  $tpl->setVariable("TAB_TYPE", "nontabbed");
593  $tpl->setVariable("TAB_ICON", " ".ilGlyphGUI::get(ilGlyphGUI::NEXT, ilGlyphGUI::NO_TEXT));
594  $tpl->setVariable("TAB_TEXT", $link["text"]);
595  $tpl->setVariable("TAB_LINK", $link["link"]);
596  $tpl->setVariable("TAB_TARGET", $link["frame"]);
597  $tpl->setVariable("ID", "nontab_".$link["id"]);
598  $tpl->parseCurrentBlock();
599 
600  // tooltip
601  if (!$this->getSetupMode())
602  {
603  $ttext = $ilHelp->getTabTooltipText($link["id"]);
604  if ($ttext != "")
605  {
606  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
607  ilTooltipGUI::addTooltip("nontab_".$link["id"], $ttext, "",
608  "bottom center", "top center", false);
609  }
610  }
611  }
612  }
613 
614  return $tpl->get();
615  }
616  else
617  {
618  return "";
619  }
620  }
621 
622  function getActiveTab(){
623  foreach($this->target as $i => $target){
624  if($this->target[$i]['activate'])
625  return $this->target[$i]['id'];
626  }
627  }
628 
629  function hasTabs()
630  {
631  return (bool)sizeof($this->target);
632  }
633 }
634 ?>
getSetupMode()
Get setup mode.
setTabActive($a_id)
DEPRECATED.
Tabs GUI.
activateSubTab($a_id)
Activate a specific subtab identified its id.
getSubTabHTML()
get sub tabs code as html
$cmd
Definition: sahs_server.php:35
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.
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.
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
Create styles array
The data for the language used.
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.
addTab($a_id, $a_text, $a_link, $a_frame="")
Add a Tab.
const ID_PART_SCREEN
const IL_COMP_SERVICE