ILIAS  Release_4_4_x_branch Revision 61816
 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  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  // back 2 tab
439  if ($this->back_2_title != "")
440  {
441  $tpl->setCurrentBlock("back_2_tab");
442  $tpl->setVariable("BACK_2_TAB_LINK", $this->back_2_target);
443  $tpl->setVariable("BACK_2_TAB_TEXT", $this->back_2_title);
444  $tpl->setVariable("BACK_2_TAB_TARGET", $this->back_2_frame);
445  $tpl->parseCurrentBlock();
446  }
447 
448  // back tab
449  if ($this->back_title != "")
450  {
451  $tpl->setCurrentBlock("back_tab");
452  $tpl->setVariable("BACK_TAB_LINK", $this->back_target);
453  $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
454  $tpl->setVariable("BACK_TAB_TARGET", $this->back_frame);
455  $tpl->parseCurrentBlock();
456  }
457  }
458 
459  $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
460 
461  $i=0;
462 
463  // do not display one tab only
464  if ((count($targets) > 1) || ($this->back_title != "" && !$a_get_sub_tabs)
465  || (count($this->non_tabbed_link) > 0 && !$a_get_sub_tabs))
466  {
467  foreach ($targets as $target)
468  {
469  $i++;
470 
471  if (!is_array($target["cmd"]))
472  {
473  $target["cmd"] = array($target["cmd"]);
474  }
475  if (!$a_manual &&
476  (in_array($cmd, $target["cmd"]) || ($target["cmd"][0] == "" && count($target["cmd"]) == 1)) &&
477  (in_array($cmdClass,$target["cmdClass"]) || !$target["cmdClass"]))
478  {
479  $tabtype = $pre."tabactive";
480  }
481  else
482  {
483  $tabtype = $pre."tabinactive";
484  }
485 
486  if ($a_manual && $target["activate"])
487  {
488  $tabtype = $pre."tabactive";
489  }
490 
491  if ($tabtype == "tabactive" || $tabtype == "subtabactive")
492  {
493  $tpl->setCurrentBlock("sel_text");
494  $tpl->setVariable("TXT_SELECTED", $lng->txt("stat_selected"));
495  $tpl->parseCurrentBlock();
496 
497  if (!$this->getSetupMode())
498  {
499  if ($a_get_sub_tabs)
500  {
502  }
503  else
504  {
506  }
507  $ilHelp->setDefaultScreenId($part, $target["id"]);
508  }
509  }
510 
511  $tpl->setCurrentBlock($pre."tab");
512  $tpl->setVariable("ID", $pre."tab_".$target["id"]);
513 
514  // tooltip
515  if (!$this->getSetupMode())
516  {
517  $ttext = $ilHelp->getTabTooltipText($target["id"]);
518  if ($ttext != "")
519  {
520  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
521  ilTooltipGUI::addTooltip($pre."tab_".$target["id"], $ttext, "",
522  "bottom center", "top center", false);
523  }
524  }
525 
526  $tpl->setVariable($pre2."TAB_TYPE", $tabtype);
527  if (!$this->getSetupMode())
528  {
529  $hash = ($ilUser->getPref("screen_reader_optimization"))
530  ? "#after_".$sr_pre."tabs"
531  : "";
532  }
533 
534  $tpl->setVariable($pre2."TAB_LINK", $target["link"].$hash);
535  if ($target["dir_text"])
536  {
537  $tpl->setVariable($pre2."TAB_TEXT", $target["text"]);
538  }
539  else
540  {
541  $tpl->setVariable($pre2."TAB_TEXT", $lng->txt($target["text"]));
542  }
543  $tpl->setVariable($pre2."TAB_TARGET", $target["frame"]);
544  $tpl->parseCurrentBlock();
545  }
546 
547  if ($a_get_sub_tabs)
548  {
549  $tpl->setVariable("TXT_SUBTABS", $lng->txt("subtabs"));
550  }
551  else
552  {
553  $tpl->setVariable("TXT_TABS", $lng->txt("tabs"));
554 
555  // non tabbed links
556  foreach ($this->non_tabbed_link as $link)
557  {
558  $tpl->setCurrentBlock("tab");
559  $tpl->setVariable("TAB_TYPE", "nontabbed");
560  $tpl->setVariable("TAB_TEXT", $link["text"]);
561  $tpl->setVariable("TAB_LINK", $link["link"]);
562  $tpl->setVariable("TAB_TARGET", $link["frame"]);
563  $tpl->setVariable("ID", "nontab_".$link["id"]);
564  $tpl->parseCurrentBlock();
565 
566  // tooltip
567  if (!$this->getSetupMode())
568  {
569  $ttext = $ilHelp->getTabTooltipText($link["id"]);
570  if ($ttext != "")
571  {
572  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
573  ilTooltipGUI::addTooltip("nontab_".$link["id"], $ttext, "",
574  "bottom center", "top center", false);
575  }
576  }
577  }
578  }
579 
580  return $tpl->get();
581  }
582  else
583  {
584  return "";
585  }
586  }
587 
588  function getActiveTab(){
589  foreach($this->target as $i => $target){
590  if($this->target[$i]['activate'])
591  return $this->target[$i]['id'];
592  }
593  }
594 
595  function hasTabs()
596  {
597  return (bool)sizeof($this->target);
598  }
599 }
600 ?>