ILIAS  release_7 Revision v7.30-3-g800a261c036
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;
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 protected $listtitle;
47 protected $aria_listtitle;
48
49 /*
50
51 The modes implement the following html for non-js fallback:
52
53 MODE_LINKS:
54
55 <a href="...">...</a> <a href="...">...<a>
56
57 MODE_FORM_SELECT: (form and submit tags are optional)
58
59 <form id="..." class="..." method="post" action="..." target="_top">
60 <select name="..." class="..." size="0">
61 <option value="...">...</option>
62 ...
63 </select>
64 <input class="ilEditSubmit" type="submit" value="Go"/>
65 </form>
66
67 */
68
73 public function __construct()
74 {
75 global $DIC;
76
77 $this->lng = $DIC->language();
81 }
82
86 public function setLinksMode($a_link_class = "")
87 {
89 $this->links_mode = array(
90 "link_class" => $a_link_class);
91 }
92
98 public function setFormSelectMode(
99 $a_select_name,
100 $a_select_class = "",
101 $a_include_form_tag = false,
102 $a_form_action = "",
103 $a_form_id = "",
104 $a_form_class = "",
105 $a_form_target = "_top",
106 $a_button_text = "",
107 $a_button_class = "",
108 $a_button_cmd = ""
109 ) {
111 $this->form_mode = array(
112 "select_name" => $a_select_name,
113 "select_class" => $a_select_class,
114 "include_form_tag" => $a_include_form_tag,
115 "form_action" => $a_form_action,
116 "form_id" => $a_form_id,
117 "form_class" => $a_form_class,
118 "form_target" => $a_form_target,
119 "button_text" => $a_button_text,
120 "button_class" => $a_button_class,
121 "button_cmd" => $a_button_cmd
122 );
123 }
124
136 public function addItem(
137 $a_title,
138 $a_value = "",
139 $a_link = "",
140 $a_img = "",
141 $a_alt = "",
142 $a_frame = "",
143 $a_html = "",
144 $a_prevent_background_click = false,
145 $a_onclick = "",
146 $a_ttip = "",
147 $a_tt_my = "right center",
148 $a_tt_at = "left center",
149 $a_tt_use_htmlspecialchars = true,
150 $a_data = array()
151 ) {
152 $this->items[] = array("title" => $a_title, "value" => $a_value,
153 "link" => $a_link, "img" => $a_img, "alt" => $a_alt, "frame" => $a_frame,
154 "html" => $a_html, "prevent_background_click" => $a_prevent_background_click,
155 "onclick" => $a_onclick, "ttip" => $a_ttip, "tt_my" => $a_tt_my, "tt_at" => $a_tt_at,
156 "tt_use_htmlspecialchars" => $a_tt_use_htmlspecialchars, "data" => $a_data);
157 }
158
164 public function setGroupedList($a_val)
165 {
166 $this->grouped_list = $a_val;
167 }
168
174 public function getGroupedList()
175 {
176 return $this->grouped_list;
177 }
178
179 public function flush()
180 {
181 $this->items = array();
182 }
183
189 public function getItems()
190 {
191 return $this->items;
192 }
193
199 public function setListTitle($a_listtitle)
200 {
201 $this->listtitle = $a_listtitle;
202 }
203
209 public function getListTitle()
210 {
211 return $this->listtitle;
212 }
213
219 public function setAriaListTitle($a_listtitle)
220 {
221 $this->aria_listtitle = $a_listtitle;
222 }
223
229 public function getAriaListTitle()
230 {
231 return strip_tags($this->aria_listtitle);
232 }
233
241 public function setSelectionHeaderClass($a_selectionheaderclass)
242 {
243 $this->selectionheaderclass = $a_selectionheaderclass;
244 }
245
251 public function getSelectionHeaderClass()
252 {
253 return $this->selectionheaderclass;
254 }
255
261 public function setStyle($a_val)
262 {
263 $this->style = $a_val;
264 }
265
271 public function getStyle()
272 {
273 return $this->style;
274 }
275
276
277
283 public function setSelectionHeaderSpanClass($a_val)
284 {
285 $this->sel_head_span_class = $a_val;
286 }
287
294 {
295 return $this->sel_head_span_class;
296 }
297
303 public function setHeaderIcon($a_headericon)
304 {
305 $this->headericon = $a_headericon;
306 }
307
313 public function getHeaderIcon()
314 {
315 return $this->headericon;
316 }
317
323 public function setNoJSLinkClass($a_nojslinkclass)
324 {
325 $this->nojslinkclass = $a_nojslinkclass;
326 }
327
333 public function getNoJSLinkClass()
334 {
335 return $this->nojslinkclass;
336 }
337
343 public function setItemLinkClass($a_itemlinkclass)
344 {
345 $this->itemlinkclass = $a_itemlinkclass;
346 }
347
353 public function getItemLinkClass()
354 {
355 return $this->itemlinkclass;
356 }
357
363 public function setId($a_id)
364 {
365 $this->id = $a_id;
366 }
367
373 public function getId()
374 {
375 return $this->id;
376 }
377
383 public function setUseImages($a_useimages)
384 {
385 $this->useimages = $a_useimages;
386 }
387
393 public function getUseImages()
394 {
395 return $this->useimages;
396 }
397
403 public function setAccessKey($a_val)
404 {
405 $this->access_key = $a_val;
406 }
407
413 public function getAccessKey()
414 {
415 return $this->access_key;
416 }
417
421 public function setTriggerEvent($a_val)
422 {
423 $this->trigger_event = $a_val;
424 }
425
429 public function getTriggerEvent()
430 {
432 }
433
437 public function setAutoHide($a_val)
438 {
439 $this->auto_hide = $a_val;
440 }
441
445 public function getAutoHide()
446 {
447 return $this->auto_hide;
448 }
449
460 public function setOnClickMode($a_val, $a_onclick_form_id = "")
461 {
462 $this->on_click = $a_val;
463 $this->on_click_form_id = $a_onclick_form_id;
464 }
465
471 public function getOnClickMode()
472 {
473 return $this->on_click;
474 }
475
481 public function setSelectedValue($a_val)
482 {
483 $this->selected_value = $a_val;
484 }
485
491 public function getSelectedValue()
492 {
494 }
495
502 public function setAdditionalToggleElement($a_el, $a_on)
503 {
504 $this->toggle = array("el" => $a_el, "class_on" => $a_on);
505 }
506
513 {
514 return $this->toggle;
515 }
516
522 public function setAsynch($a_val)
523 {
524 if ($a_val) {
525 include_once("./Services/YUI/classes/class.ilYuiUtil.php");
527 }
528 $this->asynch = $a_val;
529 }
530
536 public function getAsynch()
537 {
538 return $this->asynch;
539 }
540
546 public function setAsynchUrl($a_val)
547 {
548 $this->asynch_url = $a_val;
549 }
550
556 public function getAsynchUrl()
557 {
558 return $this->asynch_url;
559 }
560
564 public function setSelectCallback($a_val)
565 {
566 $this->select_callback = $a_val;
567 }
568
572 public function getSelectCallback()
573 {
574 return $this->select_callback;
575 }
576
582 public function setPullRight($a_val)
583 {
584 $this->dd_pullright = $a_val;
585 }
586
592 public function getPullRight()
593 {
594 return $this->dd_pullright;
595 }
596
601 public function getToolbarHTML()
602 {
603 return $this->getHTML();
604 }
605
609 public function getHTML($a_only_cmd_list_asynch = false)
610 {
611 $items = $this->getItems();
612
613 // do not show list, if no item is in list
614 if (count($items) == 0 && !$this->getAsynch() && $this->getGroupedList() == null) {
615 return "";
616 }
617
618 /* bootstrap made this obsolete ?!
619 include_once("./Services/YUI/classes/class.ilYuiUtil.php");
620 ilYuiUtil::initOverlay();
621 $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/Overlay/js/ilOverlay.js");
622 */
623 $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js");
624
625 $tpl = new ilTemplate(
626 "tpl.adv_selection_list.html",
627 true,
628 true,
629 "Services/UIComponent/AdvancedSelectionList",
630 "DEFAULT",
631 false,
632 true
633 );
634
635 reset($items);
636
637 $cnt = 0;
638
639 if ($this->getAsynch()) {
640 $tpl->setCurrentBlock("asynch_request");
641 $tpl->setVariable("IMG_LOADER", ilUtil::getImagePath("loader.svg"));
642 $tpl->parseCurrentBlock();
643 } else {
644 if ($this->getGroupedList() != null) {
645 $tpl->setVariable("GROUPED_LIST_HTML", $this->getGroupedList()->getHTML());
646 } else {
647 foreach ($items as $item) {
648 $item["value"] = htmlspecialchars($item["value"], ENT_QUOTES);
649 if (isset($item["ref_id"])) {
650 $sel_arr[$item["ref_id"]] = (isset($item["title"]))
651 ? $item["title"]
652 : "";
653 }
654 $this->css_row = ($this->css_row != "tblrow1_mo")
655 ? "tblrow1_mo"
656 : "tblrow2_mo";
657
658 if ($this->getUseImages()) {
659 if ($item["img"]) {
660 $tpl->setCurrentBlock("image");
661 $tpl->setVariable("IMG_ITEM", $item["img"]);
662 $tpl->setVariable("ALT_ITEM", $item["alt"]);
663 $tpl->parseCurrentBlock();
664 } else {
665 $tpl->touchBlock("no_image");
666 }
667 }
668
669 if ($this->getOnClickMode() ==
671 $this->getItemLinkClass() != "") {
672 if ($item["frame"]) {
673 $tpl->setCurrentBlock("frame");
674 $tpl->setVariable("TARGET_ITEM", $item["frame"]);
675 $tpl->parseCurrentBlock();
676 }
677
678 if ($this->getItemLinkClass() != "") {
679 $tpl->setCurrentBlock("item_link_class");
680 $tpl->setVariable("ITEM_LINK_CLASS", $this->getItemLinkClass());
681 $tpl->parseCurrentBlock();
682 }
683
684 if (is_array($item["data"])) {
685 foreach ($item["data"] as $k => $v) {
686 $tpl->setCurrentBlock("f_data");
687 $tpl->setVariable("DATA_KEY", $k);
688 $tpl->setVariable("DATA_VAL", ilUtil::prepareFormOutput($v));
689 $tpl->parseCurrentBlock();
690 }
691 }
692 if ($item["value"] != "") {
693 $tpl->setCurrentBlock("item_id");
694 $tpl->setVariable("ID_ITEM", $this->getId() . "_" . $item["value"]);
695 $tpl->parseCurrentBlock();
696 }
697
698 $tpl->setCurrentBlock("href_s");
699 $tpl->setVariable("HREF_ITEM", 'href="' . $item["link"] . '"');
700 $tpl->parseCurrentBlock();
701
702 $tpl->touchBlock("href_e");
703 }
704
705 $tpl->setCurrentBlock("item");
706 if ($this->getOnClickMode() ==
708 if ($item["prevent_background_click"]) {
709 $tpl->setVariable("ONCLICK_ITEM", '');
710 } else {
711 if ($item["onclick"] == "" && $item["frame"] != "") { // see #28730
712 $tpl->setVariable(
713 "ONCLICK_ITEM",
714 'onclick="' . "return il.AdvancedSelectionList.openTarget('" . $item["link"] . "','" . $item["frame"] . "');" . '"'
715 );
716 } elseif ($item["onclick"] != "") {
717 $tpl->setVariable(
718 "ONCLICK_ITEM",
719 'onclick="' . "return " . $item["onclick"] . ";" . '"'
720 );
721 }
722 }
723 } elseif ($this->getOnClickMode() ==
725 $tpl->setVariable(
726 "ONCLICK_ITEM",
727 'onclick="return il.AdvancedSelectionList.submitForm(\'' . $this->getId() . '\'' .
728 ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," .
729 "'" . $this->on_click_form_id . "','" . $this->form_mode["button_cmd"] . "');\""
730 );
731 } elseif ($this->getOnClickMode() ==
733 $tpl->setVariable(
734 "ONCLICK_ITEM",
735 'onclick="return il.AdvancedSelectionList.selectForm(\'' . $this->getId() . '\'' .
736 ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," .
737 "'" . $item["title"] . "');\""
738 );
739 } elseif ($this->getOnClickMode() ==
741 $tpl->setVariable(
742 "ONCLICK_ITEM",
743 'onclick="il.AdvancedSelectionList.clickNop(\'' . $this->getId() . '\'' .
744 ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," .
745 "'" . $item["title"] . "');\""
746 );
747 }
748
749 $tpl->setVariable("CSS_ROW", $this->css_row);
750 if ($item["html"] == "") {
751 $tpl->setVariable("TXT_ITEM", $item["title"]);
752 } else {
753 $tpl->setVariable("TXT_ITEM", $item["html"]);
754 }
755
756 $tpl->setVariable("ID_ITEM_TR", $this->getId() . "_" . $item["value"] . "_tr");
757 if ($item["ttip"] != "") {
758 include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
760 $this->getId() . "_" . $item["value"] . "_tr",
761 $item["ttip"],
762 "",
763 $item["tt_my"],
764 $item["tt_at"],
765 $item["tt_use_htmlspecialchars"]
766 );
767 }
768
769 $tpl->parseCurrentBlock();
770
771 // add item to js object
772 $tpl->setCurrentBlock("js_item");
773 $tpl->setVariable("IT_ID", $this->getId());
774 $tpl->setVariable("IT_HID_NAME", $this->form_mode["select_name"]);
775 $tpl->setVariable("IT_HID_VAL", $item["value"]);
776 $tpl->setVariable("IT_TITLE", str_replace("'", "\\'", $item["title"]));
777 $tpl->parseCurrentBlock();
778 }
779
780 // output hidden input, if click mode is form submission
782 $tpl->setCurrentBlock("hidden_input");
783 $tpl->setVariable("HID", $this->getId());
784 $tpl->parseCurrentBlock();
785 }
786
787 // output hidden input and initialize
789 $tpl->setCurrentBlock("hidden_input");
790 $tpl->setVariable("HID", $this->getId());
791 $tpl->parseCurrentBlock();
792
793 // init hidden input with selected value
794 $tpl->setCurrentBlock("init_hidden_input");
795 $tpl->setVariable("H2ID", $this->getId());
796 $tpl->setVariable("HID_NAME", $this->form_mode["select_name"]);
797 $tpl->setVariable("HID_VALUE", $this->getSelectedValue());
798 $tpl->parseCurrentBlock();
799 }
800 }
801 }
802
803 if ($a_only_cmd_list_asynch) {
804 $tpl->touchBlock("cmd_table");
805 return $tpl->get("cmd_table");
806 }
807
808 if ($this->getGroupedList() == null) {
809 $tpl->setCurrentBlock("dd_content");
810 if ($this->getPullRight()) {
811 $tpl->setVariable("UL_CLASS", "dropdown-menu pull-right");
812 } else {
813 $tpl->setVariable("UL_CLASS", "dropdown-menu");
814 }
815 $tpl->setVariable("TABLE_ID", $this->getId());
816 $tpl->parseCurrentBlock();
817 }
818
820 $tpl->setCurrentBlock("top_img");
821 switch ($this->getHeaderIcon()) {
823 $tpl->setVariable("IMG_SPAN_STYLE", ilAdvancedSelectionListGUI::ICON_CONFIG);
824 break;
825
827 default:
828 $tpl->setVariable("IMG_SPAN_STYLE", ilAdvancedSelectionListGUI::ICON_ARROW);
829 break;
830 }
831 $tpl->parseCurrentBlock();
832 }
833
834
835 if ($this->getAsynch()) {
836 $tpl->setCurrentBlock("asynch_bl");
837 $tpl->setVariable("ASYNCH_URL", $this->getAsynchUrl());
838 $tpl->setVariable("ASYNCH_ID", $this->getId());
839 $tpl->setVariable("ASYNCH_TRIGGER_ID", $this->getId());
840 $tpl->parseCurrentBlock();
841 }
842
843 // js section
844 $tpl->setCurrentBlock("js_section");
845 if ($this->getAccessKey() > 0) {
846 include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
847 $tpl->setVariable("ACCKEY", ilAccessKeyGUI::getAttribute($this->getAccessKey()));
848 }
849
850 $cfg["trigger_event"] = $this->getTriggerEvent();
851 $cfg["auto_hide"] = $this->getAutoHide();
852
853 if ($this->getSelectCallback() != "") {
854 $cfg["select_callback"] = $this->getSelectCallback();
855 }
856 $cfg["anchor_id"] = "ilAdvSelListAnchorElement_" . $this->getId();
857 $cfg["asynch"] = $this->getAsynch()
858 ? true
859 : false;
860 $cfg["asynch_url"] = $this->getAsynchUrl();
862 if (is_array($toggle)) {
863 $cfg["toggle_el"] = $toggle["el"];
864 $cfg["toggle_class_on"] = $toggle["class_on"];
865 }
866 //echo "<br>".htmlentities($this->getAsynchUrl());
867 include_once("./Services/JSON/classes/class.ilJsonUtil.php");
868 $tpl->setVariable("CFG", ilJsonUtil::encode($cfg));
869
870 //echo htmlentities(ilJsonUtil::encode($cfg));
871
872 $tpl->setVariable("TXT_SEL_TOP", $this->getListTitle());
873 if ($this->getListTitle() == "" || $this->getAriaListTitle() != "") {
874 $aria_title = ($this->getAriaListTitle() != "")
875 ? $this->getAriaListTitle()
876 : $this->lng->txt("actions");
877 $tpl->setVariable("TXT_ARIA_TOP", $aria_title);
878 }
879 $tpl->setVariable("ID", $this->getId());
880
881 //$tpl->setVariable("CLASS_SEL_TOP", $this->getSelectionHeaderClass());
882 switch ($this->getStyle()) {
884 $tpl->setVariable("BTN_CLASS", "btn btn-default");
885 $tpl->setVariable("TAG", "button");
886 break;
887
888 case self::STYLE_EMPH:
889 $tpl->setVariable("BTN_CLASS", "btn btn-primary");
890 $tpl->setVariable("TAG", "button");
891 break;
892
894 $tpl->setVariable("BTN_CLASS", "btn btn-link");
895 $tpl->setVariable("TAG", "button");
896 break;
897
898 case self::STYLE_LINK:
899 $tpl->setVariable("BTN_CLASS", "");
900 $tpl->setVariable("TAG", "a");
901 $tpl->touchBlock("href_link");
902 break;
903 }
904
905
906 if ($this->getSelectionHeaderSpanClass() != "") {
907 $tpl->setVariable(
908 "CLASS_SEL_TOP_SPAN",
910 );
911 }
912
913 // set the async url to an extra template variable
914 // (needed for a mobile skin)
915 // $tpl->setVariable("ASYNC_URL", $this->getAsynchUrl());
916
917 $tpl->parseCurrentBlock();
918
919 return $tpl->get();
920 }
921}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
static getAttribute($a_func_id)
Get accesskey HTML attribute.
User interface class for advanced drop-down selection lists.
setItemLinkClass($a_itemlinkclass)
Set Item Link Class.
setLinksMode($a_link_class="")
Set links mode (for no js fallback)
setAdditionalToggleElement($a_el, $a_on)
Set additional toggle element.
getAdditionalToggleElement()
Get additional toggle element.
setOnClickMode($a_val, $a_onclick_form_id="")
Set "onClick"- Mode.
setSelectionHeaderClass($a_selectionheaderclass)
Set Selection Header Class.
getSelectionHeaderClass()
Get Selection Header Class.
setUseImages($a_useimages)
Set Use Images.
getHTML($a_only_cmd_list_asynch=false)
Get selection list HTML.
setSelectionHeaderSpanClass($a_val)
Set selection header span class.
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, $a_data=array())
Add an item.
setAsynch($a_val)
Set asynch mode (this is set to true, if list should get items asynchronously)
getNoJSLinkClass()
Get No Javascript Link Style Class.
getSelectionHeaderSpanClass()
Get selection header span class.
setAriaListTitle($a_listtitle)
Set List Title.
setNoJSLinkClass($a_nojslinkclass)
Set No Javascript Link Style 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.
setListTitle($a_listtitle)
Set List Title.
setSelectCallback($a_val)
Set select callback.
static encode($mixed, $suppress_native=false)
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.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
static initConnection(ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Connection module.
global $DIC
Definition: goto.php:24
Interface for property form input GUI classes that can be used in ilToolbarGUI.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41