ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAdvancedSelectionListGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
12 {
13  private $items = array();
14  private $id = "asl";
15  private $asynch = false;
16 
17  const DOWN_ARROW_DARK = "down_arrow_dark";
18  const ICON_ARROW = "caret";
19  const ICON_CONFIG = "glyphicon glyphicon-cog";
20  const NO_ICON = "";
21 
22  const MODE_LINKS = "links";
23  const MODE_FORM_SELECT = "select";
24 
25  const ON_ITEM_CLICK_HREF = "href";
26  const ON_ITEM_CLICK_FORM_SUBMIT = "submit";
27  const ON_ITEM_CLICK_FORM_SELECT = "select";
28  const ON_ITEM_CLICK_NOP = "nop";
29 
30  const STYLE_DEFAULT = 0;
31  const STYLE_LINK = 1;
32  const STYLE_EMPH = 2;
33  const STYLE_LINK_BUTTON = 3;
34 
35  protected $css_row = "";
36  protected $access_key = false;
37  protected $toggle = false;
38  protected $asynch_url = false;
39  protected $selected_value = "";
40  protected $trigger_event = "click";
41  protected $auto_hide = false;
42  protected $grouped_list = null;
43  protected $style = 0;
44  private $dd_pullright = true;
45 
46  /*
47 
48  The modes implement the following html for non-js fallback:
49 
50  MODE_LINKS:
51 
52  <a href="...">...</a> <a href="...">...<a>
53 
54  MODE_FORM_SELECT: (form and submit tags are optional)
55 
56  <form id="..." class="..." method="post" action="..." target="_top">
57  <select name="..." class="..." size="0">
58  <option value="...">...</option>
59  ...
60  </select>
61  <input class="ilEditSubmit" type="submit" value="Go"/>
62  </form>
63 
64  */
65 
70  public function __construct()
71  {
75  }
76 
80  public function setLinksMode($a_link_class = "")
81  {
83  $this->links_mode = array(
84  "link_class" => $a_link_class);
85  }
86 
92  public function setFormSelectMode($a_select_name, $a_select_class = "",
93  $a_include_form_tag = false, $a_form_action = "", $a_form_id = "",
94  $a_form_class = "", $a_form_target = "_top",
95  $a_button_text = "", $a_button_class = "", $a_button_cmd = "")
96  {
98  $this->form_mode = array(
99  "select_name" => $a_select_name,
100  "select_class" => $a_select_class,
101  "include_form_tag" => $a_include_form_tag,
102  "form_action" => $a_form_action,
103  "form_id" => $a_form_id,
104  "form_class" => $a_form_class,
105  "form_target" => $a_form_target,
106  "button_text" => $a_button_text,
107  "button_class" => $a_button_class,
108  "button_cmd" => $a_button_cmd
109  );
110  }
111 
123  function addItem($a_title, $a_value = "", $a_link = "", $a_img = "", $a_alt = "", $a_frame = "",
124  $a_html = "", $a_prevent_background_click = false, $a_onclick = "", $a_ttip = "",
125  $a_tt_my = "right center", $a_tt_at = "left center", $a_tt_use_htmlspecialchars = true)
126  {
127  $this->items[] = array("title" => $a_title, "value" => $a_value,
128  "link" => $a_link, "img" => $a_img, "alt" => $a_alt, "frame" => $a_frame,
129  "html" => $a_html, "prevent_background_click" => $a_prevent_background_click,
130  "onclick" => $a_onclick, "ttip" => $a_ttip, "tt_my" => $a_tt_my, "tt_at" => $a_tt_at,
131  "tt_use_htmlspecialchars" => $a_tt_use_htmlspecialchars);
132  }
133 
139  function setGroupedList($a_val)
140  {
141  $this->grouped_list = $a_val;
142  }
143 
149  function getGroupedList()
150  {
151  return $this->grouped_list;
152  }
153 
154  public function flush()
155  {
156  $this->items = array();
157  }
158 
164  function getItems()
165  {
166  return $this->items;
167  }
168 
174  function setListTitle($a_listtitle)
175  {
176  $this->listtitle = $a_listtitle;
177  }
178 
184  function getListTitle()
185  {
186  return $this->listtitle;
187  }
188 
196  function setSelectionHeaderClass($a_selectionheaderclass)
197  {
198  $this->selectionheaderclass = $a_selectionheaderclass;
199  }
200 
207  {
208  return $this->selectionheaderclass;
209  }
210 
216  function setStyle($a_val)
217  {
218  $this->style = $a_val;
219  }
220 
226  function getStyle()
227  {
228  return $this->style;
229  }
230 
231 
232 
239  {
240  $this->sel_head_span_class = $a_val;
241  }
242 
249  {
250  return $this->sel_head_span_class;
251  }
252 
258  function setHeaderIcon($a_headericon)
259  {
260  $this->headericon = $a_headericon;
261  }
262 
268  function getHeaderIcon()
269  {
270  return $this->headericon;
271  }
272 
278  function setNoJSLinkClass($a_nojslinkclass)
279  {
280  $this->nojslinkclass = $a_nojslinkclass;
281  }
282 
288  function getNoJSLinkClass()
289  {
290  return $this->nojslinkclass;
291  }
292 
298  function setItemLinkClass($a_itemlinkclass)
299  {
300  $this->itemlinkclass = $a_itemlinkclass;
301  }
302 
308  function getItemLinkClass()
309  {
310  return $this->itemlinkclass;
311  }
312 
318  function setId($a_id)
319  {
320  $this->id = $a_id;
321  }
322 
328  function getId()
329  {
330  return $this->id;
331  }
332 
338  function setUseImages($a_useimages)
339  {
340  $this->useimages = $a_useimages;
341  }
342 
348  function getUseImages()
349  {
350  return $this->useimages;
351  }
352 
358  function setAccessKey($a_val)
359  {
360  $this->access_key = $a_val;
361  }
362 
368  function getAccessKey()
369  {
370  return $this->access_key;
371  }
372 
376  public function setTriggerEvent($a_val)
377  {
378  $this->trigger_event = $a_val;
379  }
380 
384  public function getTriggerEvent()
385  {
386  return $this->trigger_event;
387  }
388 
392  public function setAutoHide($a_val)
393  {
394  $this->auto_hide = $a_val;
395  }
396 
400  public function getAutoHide()
401  {
402  return $this->auto_hide;
403  }
404 
415  function setOnClickMode($a_val, $a_onclick_form_id = "")
416  {
417  $this->on_click = $a_val;
418  $this->on_click_form_id = $a_onclick_form_id;
419  }
420 
426  function getOnClickMode()
427  {
428  return $this->on_click;
429  }
430 
436  function setSelectedValue($a_val)
437  {
438  $this->selected_value = $a_val;
439  }
440 
446  function getSelectedValue()
447  {
448  return $this->selected_value;
449  }
450 
457  function setAdditionalToggleElement($a_el, $a_on)
458  {
459  $this->toggle = array("el" => $a_el, "class_on" => $a_on);
460  }
461 
468  {
469  return $this->toggle;
470  }
471 
477  function setAsynch($a_val)
478  {
479  if ($a_val)
480  {
481  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
483  }
484  $this->asynch = $a_val;
485  }
486 
492  function getAsynch()
493  {
494  return $this->asynch;
495  }
496 
502  function setAsynchUrl($a_val)
503  {
504  $this->asynch_url = $a_val;
505  }
506 
512  function getAsynchUrl()
513  {
514  return $this->asynch_url;
515  }
516 
520  public function setSelectCallback($a_val)
521  {
522  $this->select_callback = $a_val;
523  }
524 
528  public function getSelectCallback()
529  {
530  return $this->select_callback;
531  }
532 
538  function setPullRight($a_val)
539  {
540  $this->dd_pullright = $a_val;
541  }
542 
548  function getPullRight()
549  {
550  return $this->dd_pullright;
551  }
552 
556  public function getHTML($a_only_cmd_list_asynch = false)
557  {
558  $items = $this->getItems();
559 
560  // do not show list, if no item is in list
561  if (count($items) == 0 && !$this->getAsynch() && $this->getGroupedList() == null)
562  {
563  return "";
564  }
565 
566  /* bootstrap made this obsolete ?!
567  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
568  ilYuiUtil::initOverlay();
569  $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/Overlay/js/ilOverlay.js");
570  */
571  $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js");
572 
573  $tpl = new ilTemplate("tpl.adv_selection_list.html", true, true,
574  "Services/UIComponent/AdvancedSelectionList", "DEFAULT", false, true);
575 
576  reset($items);
577 
578  $cnt = 0;
579 
580  if ($this->getAsynch())
581  {
582  $tpl->setCurrentBlock("asynch_request");
583  $tpl->setVariable("IMG_LOADER", ilUtil::getImagePath("loader.svg"));
584  $tpl->parseCurrentBlock();
585  }
586  else
587  {
588  if ($this->getGroupedList() != null)
589  {
590  $tpl->setVariable("GROUPED_LIST_HTML", $this->getGroupedList()->getHTML());
591  }
592  else
593  {
594  foreach($items as $item)
595  {
596  if (isset($item["ref_id"]))
597  {
598  $sel_arr[$item["ref_id"]] = (isset($item["title"]))
599  ? $item["title"]
600  : "";
601  }
602  $this->css_row = ($this->css_row != "tblrow1_mo")
603  ? "tblrow1_mo"
604  : "tblrow2_mo";
605 
606  if ($this->getUseImages())
607  {
608  if ($item["img"])
609  {
610  $tpl->setCurrentBlock("image");
611  $tpl->setVariable("IMG_ITEM", $item["img"]);
612  $tpl->setVariable("ALT_ITEM", $item["alt"]);
613  $tpl->parseCurrentBlock();
614  }
615  else
616  {
617  $tpl->touchBlock("no_image");
618  }
619  }
620 
621  if ($this->getOnClickMode() ==
623  $this->getItemLinkClass() != "")
624  {
625  if ($item["frame"])
626  {
627  $tpl->setCurrentBlock("frame");
628  $tpl->setVariable("TARGET_ITEM", $item["frame"]);
629  $tpl->parseCurrentBlock();
630  }
631 
632  if ($this->getItemLinkClass() != "")
633  {
634  $tpl->setCurrentBlock("item_link_class");
635  $tpl->setVariable("ITEM_LINK_CLASS", $this->getItemLinkClass());
636  $tpl->parseCurrentBlock();
637  }
638 
639  $tpl->setCurrentBlock("href_s");
640  $tpl->setVariable("HREF_ITEM",'href="'.$item["link"].'"');
641  $tpl->setVariable("ID_ITEM", $this->getId()."_".$item["value"]);
642  $tpl->parseCurrentBlock();
643 
644  $tpl->touchBlock("href_e");
645 
646  }
647 
648  $tpl->setCurrentBlock("item");
649  if ($this->getOnClickMode() ==
651  {
652  if ($item["prevent_background_click"])
653  {
654  $tpl->setVariable("ONCLICK_ITEM",'');
655  }
656  else
657  {
658  if ($item["onclick"] == "")
659  {
660  $tpl->setVariable("ONCLICK_ITEM",
661  'onclick="'."return il.AdvancedSelectionList.openTarget('".$item["link"]."','".$item["frame"]."');".'"');
662  }
663  else
664  {
665  $tpl->setVariable("ONCLICK_ITEM",
666  'onclick="'."return ".$item["onclick"].";".'"');
667  }
668  }
669 
670  }
671  else if ($this->getOnClickMode() ==
673  {
674  $tpl->setVariable("ONCLICK_ITEM",
675  'onclick="return il.AdvancedSelectionList.submitForm(\''.$this->getId().'\''.
676  ", '".$this->form_mode["select_name"]."','".$item["value"]."',".
677  "'".$this->on_click_form_id."','".$this->form_mode["button_cmd"]."');\"");
678  }
679  else if ($this->getOnClickMode() ==
681  {
682  $tpl->setVariable("ONCLICK_ITEM",
683  'onclick="return il.AdvancedSelectionList.selectForm(\''.$this->getId().'\''.
684  ", '".$this->form_mode["select_name"]."','".$item["value"]."',".
685  "'".$item["title"]."');\"");
686  }
687  else if ($this->getOnClickMode() ==
689  {
690  $tpl->setVariable("ONCLICK_ITEM",
691  'onclick="il.AdvancedSelectionList.clickNop(\''.$this->getId().'\''.
692  ", '".$this->form_mode["select_name"]."','".$item["value"]."',".
693  "'".$item["title"]."');\"");
694  }
695 
696  $tpl->setVariable("CSS_ROW", $this->css_row);
697  if ($item["html"] == "")
698  {
699  $tpl->setVariable("TXT_ITEM", $item["title"]);
700  }
701  else
702  {
703  $tpl->setVariable("TXT_ITEM", $item["html"]);
704  }
705 
706  $tpl->setVariable("ID_ITEM_TR", $this->getId()."_".$item["value"]."_tr");
707  if ($item["ttip"] != "")
708  {
709  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
710  ilTooltipGUI::addTooltip($this->getId()."_".$item["value"]."_tr", $item["ttip"],
711  "", $item["tt_my"], $item["tt_at"], $item["tt_use_htmlspecialchars"]);
712  }
713 
714  $tpl->parseCurrentBlock();
715 
716  // add item to js object
717  $tpl->setCurrentBlock("js_item");
718  $tpl->setVariable("IT_ID", $this->getId());
719  $tpl->setVariable("IT_HID_NAME", $this->form_mode["select_name"]);
720  $tpl->setVariable("IT_HID_VAL", $item["value"]);
721  $tpl->setVariable("IT_TITLE", str_replace("'", "\\'", $item["title"]));
722  $tpl->parseCurrentBlock();
723  }
724 
725  // output hidden input, if click mode is form submission
727  {
728  $tpl->setCurrentBlock("hidden_input");
729  $tpl->setVariable("HID", $this->getId());
730  $tpl->parseCurrentBlock();
731  }
732 
733  // output hidden input and initialize
735  {
736  $tpl->setCurrentBlock("hidden_input");
737  $tpl->setVariable("HID", $this->getId());
738  $tpl->parseCurrentBlock();
739 
740  // init hidden input with selected value
741  $tpl->setCurrentBlock("init_hidden_input");
742  $tpl->setVariable("H2ID", $this->getId());
743  $tpl->setVariable("HID_NAME", $this->form_mode["select_name"]);
744  $tpl->setVariable("HID_VALUE", $this->getSelectedValue());
745  $tpl->parseCurrentBlock();
746  }
747  }
748  }
749 
750  if ($a_only_cmd_list_asynch)
751  {
752  $tpl->touchBlock("cmd_table");
753  return $tpl->get("cmd_table");
754  }
755 
756  if ($this->getGroupedList() == null)
757  {
758  $tpl->setCurrentBlock("dd_content");
759  if ($this->getPullRight())
760  {
761  $tpl->setVariable("UL_CLASS", "dropdown-menu pull-right");
762  }
763  else
764  {
765  $tpl->setVariable("UL_CLASS", "dropdown-menu");
766  }
767  $tpl->setVariable("TABLE_ID", $this->getId());
768  $tpl->parseCurrentBlock();
769  }
770 
772  {
773  $tpl->setCurrentBlock("top_img");
774  switch ($this->getHeaderIcon())
775  {
777  $tpl->setVariable("IMG_SPAN_STYLE", ilAdvancedSelectionListGUI::ICON_CONFIG);
778  break;
779 
781  default:
782  $tpl->setVariable("IMG_SPAN_STYLE", ilAdvancedSelectionListGUI::ICON_ARROW);
783  break;
784  }
785  $tpl->parseCurrentBlock();
786  }
787 
788 
789  if($this->getAsynch())
790  {
791  $tpl->setCurrentBlock("asynch_bl");
792  $tpl->setVariable("ASYNCH_URL", $this->getAsynchUrl());
793  $tpl->setVariable("ASYNCH_ID", $this->getId());
794  $tpl->setVariable("ASYNCH_TRIGGER_ID", $this->getId());
795  $tpl->parseCurrentBlock();
796  }
797 
798  // js section
799  $tpl->setCurrentBlock("js_section");
800  if ($this->getAccessKey() > 0)
801  {
802  include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
803  $tpl->setVariable("ACCKEY", ilAccessKeyGUI::getAttribute($this->getAccessKey()));
804  }
805 
806  $cfg["trigger_event"] = $this->getTriggerEvent();
807  $cfg["auto_hide"] = $this->getAutoHide();
808 
809  if ($this->getSelectCallback() != "")
810  {
811  $cfg["select_callback"] = $this->getSelectCallback();
812  }
813  $cfg["anchor_id"] = "ilAdvSelListAnchorElement_".$this->getId();
814  $cfg["asynch"] = $this->getAsynch()
815  ? true
816  : false;
817  $cfg["asynch_url"] = $this->getAsynchUrl();
819  if (is_array($toggle))
820  {
821  $cfg["toggle_el"] = $toggle["el"];
822  $cfg["toggle_class_on"] = $toggle["class_on"];
823  }
824 //echo "<br>".htmlentities($this->getAsynchUrl());
825  include_once("./Services/JSON/classes/class.ilJsonUtil.php");
826  $tpl->setVariable("CFG", ilJsonUtil::encode($cfg));
827 
828  //echo htmlentities(ilJsonUtil::encode($cfg));
829 
830  $tpl->setVariable("TXT_SEL_TOP", $this->getListTitle());
831  $tpl->setVariable("ID", $this->getId());
832 
833  //$tpl->setVariable("CLASS_SEL_TOP", $this->getSelectionHeaderClass());
834  switch ($this->getStyle())
835  {
836  case self::STYLE_DEFAULT:
837  $tpl->setVariable("BTN_CLASS", "btn btn-sm btn-default");
838  $tpl->setVariable("TAG", "button");
839  break;
840 
841  case self::STYLE_EMPH:
842  $tpl->setVariable("BTN_CLASS", "btn btn-sm btn-primary");
843  $tpl->setVariable("TAG", "button");
844  break;
845 
846  case self::STYLE_LINK_BUTTON:
847  $tpl->setVariable("BTN_CLASS", "btn btn-sm btn-link");
848  $tpl->setVariable("TAG", "button");
849  break;
850 
851  case self::STYLE_LINK:
852  $tpl->setVariable("BTN_CLASS", "");
853  $tpl->setVariable("TAG", "a");
854  break;
855  }
856 
857 
858  if ($this->getSelectionHeaderSpanClass() != "")
859  {
860  $tpl->setVariable("CLASS_SEL_TOP_SPAN",
861  $this->getSelectionHeaderSpanClass());
862  }
863 
864  // set the async url to an extra template variable
865  // (needed for a mobile skin)
866  // $tpl->setVariable("ASYNC_URL", $this->getAsynchUrl());
867 
868  $tpl->parseCurrentBlock();
869 
870  return $tpl->get();
871  }
872 }
873 ?>
setSelectionHeaderSpanClass($a_val)
Set selection header span class.
setFormSelectMode($a_select_name, $a_select_class="", $a_include_form_tag=false, $a_form_action="", $a_form_id="", $a_form_class="", $a_form_target="_top", $a_button_text="", $a_button_class="", $a_button_cmd="")
Set form mode (for no js fallback)
setHeaderIcon($a_headericon)
Set Header Icon.
setAdditionalToggleElement($a_el, $a_on)
Set additional toggle element.
setListTitle($a_listtitle)
Set List Title.
static initConnection()
Init YUI Connection module.
addItem($a_title, $a_value="", $a_link="", $a_img="", $a_alt="", $a_frame="", $a_html="", $a_prevent_background_click=false, $a_onclick="", $a_ttip="", $a_tt_my="right center", $a_tt_at="left center", $a_tt_use_htmlspecialchars=true)
Add an item.
getAdditionalToggleElement()
Get additional toggle element.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
"color:#CC0000 style
Definition: example_001.php:92
setSelectCallback($a_val)
Set select callback.
setSelectionHeaderClass($a_selectionheaderclass)
Set Selection Header Class.
global $tpl
Definition: ilias.php:8
setNoJSLinkClass($a_nojslinkclass)
Set No Javascript Link Style Class.
setOnClickMode($a_val, $a_onclick_form_id="")
Set "onClick"- Mode.
getNoJSLinkClass()
Get No Javascript Link Style Class.
setSelectedValue($a_val)
Set selected value.
getSelectionHeaderSpanClass()
Get selection header span class.
static encode($mixed, $suppress_native=false)
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.
setLinksMode($a_link_class="")
Set links mode (for no js fallback)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
setAsynch($a_val)
Set asynch mode (this is set to true, if list should get items asynchronously)
setItemLinkClass($a_itemlinkclass)
Set Item Link Class.
Create styles array
The data for the language used.
User interface class for advanced drop-down selection lists.
getHTML($a_only_cmd_list_asynch=false)
Get selection list HTML.
static getAttribute($a_func_id)
Get accesskey HTML attribute.
setUseImages($a_useimages)
Set Use Images.
getSelectionHeaderClass()
Get Selection Header Class.