ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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_LIGHT = "mm_down_arrow.png";
18  const DOWN_ARROW_DARK = "mm_down_arrow_dark.png";
19  const DOWN_ARROW_TOPBAR = "mm_down_arrow_topbar.png";
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  protected $css_row = "";
31  protected $access_key = false;
32  protected $toggle = false;
33  protected $asynch_url = false;
34  protected $selected_value = "";
35  protected $trigger_event = "click";
36  protected $auto_hide = false;
37 
38  /*
39 
40  The modes implement the following html for non-js fallback:
41 
42  MODE_LINKS:
43 
44  <a href="...">...</a> <a href="...">...<a>
45 
46  MODE_FORM_SELECT: (form and submit tags are optional)
47 
48  <form id="..." class="..." method="post" action="..." target="_top">
49  <select name="..." class="..." size="0">
50  <option value="...">...</option>
51  ...
52  </select>
53  <input class="ilEditSubmit" type="submit" value="Go"/>
54  </form>
55 
56  */
57 
62  public function __construct()
63  {
67  }
68 
72  public function setLinksMode($a_link_class = "")
73  {
75  $this->links_mode = array(
76  "link_class" => $a_link_class);
77  }
78 
84  public function setFormSelectMode($a_select_name, $a_select_class = "",
85  $a_include_form_tag = false, $a_form_action = "", $a_form_id = "",
86  $a_form_class = "", $a_form_target = "_top",
87  $a_button_text = "", $a_button_class = "", $a_button_cmd = "")
88  {
90  $this->form_mode = array(
91  "select_name" => $a_select_name,
92  "select_class" => $a_select_class,
93  "include_form_tag" => $a_include_form_tag,
94  "form_action" => $a_form_action,
95  "form_id" => $a_form_id,
96  "form_class" => $a_form_class,
97  "form_target" => $a_form_target,
98  "button_text" => $a_button_text,
99  "button_class" => $a_button_class,
100  "button_cmd" => $a_button_cmd
101  );
102  }
103 
115  function addItem($a_title, $a_value = "", $a_link = "", $a_img = "", $a_alt = "", $a_frame = "",
116  $a_html = "", $a_prevent_background_click = false, $a_onclick = "", $a_ttip = "",
117  $a_tt_my = "right center", $a_tt_at = "left center", $a_tt_use_htmlspecialchars = true)
118  {
119  $this->items[] = array("title" => $a_title, "value" => $a_value,
120  "link" => $a_link, "img" => $a_img, "alt" => $a_alt, "frame" => $a_frame,
121  "html" => $a_html, "prevent_background_click" => $a_prevent_background_click,
122  "onclick" => $a_onclick, "ttip" => $a_ttip, "tt_my" => $a_tt_my, "tt_at" => $a_tt_at,
123  "tt_use_htmlspecialchars" => $a_tt_use_htmlspecialchars);
124  }
125 
126  public function flush()
127  {
128  $this->items = array();
129  }
130 
136  function getItems()
137  {
138  return $this->items;
139  }
140 
146  function setListTitle($a_listtitle)
147  {
148  $this->listtitle = $a_listtitle;
149  }
150 
156  function getListTitle()
157  {
158  return $this->listtitle;
159  }
160 
166  function setSelectionHeaderClass($a_selectionheaderclass)
167  {
168  $this->selectionheaderclass = $a_selectionheaderclass;
169  }
170 
177  {
178  return $this->selectionheaderclass;
179  }
180 
187  {
188  $this->sel_head_span_class = $a_val;
189  }
190 
197  {
198  return $this->sel_head_span_class;
199  }
200 
206  function setHeaderIcon($a_headericon)
207  {
208  $this->headericon = $a_headericon;
209  }
210 
216  function getHeaderIcon()
217  {
218  return $this->headericon;
219  }
220 
226  function setNoJSLinkClass($a_nojslinkclass)
227  {
228  $this->nojslinkclass = $a_nojslinkclass;
229  }
230 
236  function getNoJSLinkClass()
237  {
238  return $this->nojslinkclass;
239  }
240 
246  function setItemLinkClass($a_itemlinkclass)
247  {
248  $this->itemlinkclass = $a_itemlinkclass;
249  }
250 
256  function getItemLinkClass()
257  {
258  return $this->itemlinkclass;
259  }
260 
266  function setId($a_id)
267  {
268  $this->id = $a_id;
269  }
270 
276  function getId()
277  {
278  return $this->id;
279  }
280 
286  function setUseImages($a_useimages)
287  {
288  $this->useimages = $a_useimages;
289  }
290 
296  function getUseImages()
297  {
298  return $this->useimages;
299  }
300 
306  function setAccessKey($a_val)
307  {
308  $this->access_key = $a_val;
309  }
310 
316  function getAccessKey()
317  {
318  return $this->access_key;
319  }
320 
324  public function setTriggerEvent($a_val)
325  {
326  $this->trigger_event = $a_val;
327  }
328 
332  public function getTriggerEvent()
333  {
334  return $this->trigger_event;
335  }
336 
340  public function setAutoHide($a_val)
341  {
342  $this->auto_hide = $a_val;
343  }
344 
348  public function getAutoHide()
349  {
350  return $this->auto_hide;
351  }
352 
363  function setOnClickMode($a_val, $a_onclick_form_id = "")
364  {
365  $this->on_click = $a_val;
366  $this->on_click_form_id = $a_onclick_form_id;
367  }
368 
374  function getOnClickMode()
375  {
376  return $this->on_click;
377  }
378 
384  function setSelectedValue($a_val)
385  {
386  $this->selected_value = $a_val;
387  }
388 
394  function getSelectedValue()
395  {
396  return $this->selected_value;
397  }
398 
405  function setAdditionalToggleElement($a_el, $a_on)
406  {
407  $this->toggle = array("el" => $a_el, "class_on" => $a_on);
408  }
409 
416  {
417  return $this->toggle;
418  }
419 
425  function setAsynch($a_val)
426  {
427  if ($a_val)
428  {
429  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
431  }
432  $this->asynch = $a_val;
433  }
434 
440  function getAsynch()
441  {
442  return $this->asynch;
443  }
444 
450  function setAsynchUrl($a_val)
451  {
452  $this->asynch_url = $a_val;
453  }
454 
460  function getAsynchUrl()
461  {
462  return $this->asynch_url;
463  }
464 
468  public function setSelectCallback($a_val)
469  {
470  $this->select_callback = $a_val;
471  }
472 
476  public function getSelectCallback()
477  {
478  return $this->select_callback;
479  }
480 
484  public function getHTML($a_only_cmd_list_asynch = false)
485  {
486  $items = $this->getItems();
487 
488  // do not show list, if no item is in list
489  if (count($items) == 0 && !$this->getAsynch())
490  {
491  return "";
492  }
493 
494  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
496  $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/Overlay/js/ilOverlay.js");
497  $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js");
498  $tpl = new ilTemplate("tpl.adv_selection_list.html", true, true,
499  "Services/UIComponent/AdvancedSelectionList", "DEFAULT", false, true);
500 
501  reset($items);
502 
503  $cnt = 0;
504 
505  if ($this->getAsynch())
506  {
507  $tpl->setCurrentBlock("asynch_request");
508  $tpl->setVariable("IMG_LOADER", ilUtil::getImagePath("loader.gif"));
509  $tpl->parseCurrentBlock();
510  }
511  else
512  {
513  foreach($items as $item)
514  {
515  if (isset($item["ref_id"]))
516  {
517  $sel_arr[$item["ref_id"]] = (isset($item["title"]))
518  ? $item["title"]
519  : "";
520  }
521  $this->css_row = ($this->css_row != "tblrow1_mo")
522  ? "tblrow1_mo"
523  : "tblrow2_mo";
524 
525  if ($this->getUseImages())
526  {
527  if ($item["img"])
528  {
529  $tpl->setCurrentBlock("image");
530  $tpl->setVariable("IMG_ITEM", $item["img"]);
531  $tpl->setVariable("ALT_ITEM", $item["alt"]);
532  $tpl->parseCurrentBlock();
533  }
534  else
535  {
536  $tpl->touchBlock("no_image");
537  }
538  }
539 
540  if ($this->getOnClickMode() ==
542  $this->getItemLinkClass() != "")
543  {
544  if ($item["frame"])
545  {
546  $tpl->setCurrentBlock("frame");
547  $tpl->setVariable("TARGET_ITEM", $item["frame"]);
548  $tpl->parseCurrentBlock();
549  }
550 
551  if ($this->getItemLinkClass() != "")
552  {
553  $tpl->setCurrentBlock("item_link_class");
554  $tpl->setVariable("ITEM_LINK_CLASS", $this->getItemLinkClass());
555  $tpl->parseCurrentBlock();
556  }
557 
558  $tpl->setCurrentBlock("href_s");
559  $tpl->setVariable("HREF_ITEM",'href="'.$item["link"].'"');
560  $tpl->setVariable("ID_ITEM", $this->getId()."_".$item["value"]);
561  $tpl->parseCurrentBlock();
562 
563  $tpl->touchBlock("href_e");
564 
565  }
566 
567  $tpl->setCurrentBlock("item");
568  if ($this->getOnClickMode() ==
570  {
571  if ($item["prevent_background_click"])
572  {
573  $tpl->setVariable("ONCLICK_ITEM",'');
574  }
575  else
576  {
577  if ($item["onclick"] == "")
578  {
579  $tpl->setVariable("ONCLICK_ITEM",
580  'onclick="'."return il.AdvancedSelectionList.openTarget('".$item["link"]."','".$item["frame"]."');".'"');
581  }
582  else
583  {
584  $tpl->setVariable("ONCLICK_ITEM",
585  'onclick="'."return ".$item["onclick"].";".'"');
586  }
587  }
588 
589  }
590  else if ($this->getOnClickMode() ==
592  {
593  $tpl->setVariable("ONCLICK_ITEM",
594  'onclick="return il.AdvancedSelectionList.submitForm(\''.$this->getId().'\''.
595  ", '".$this->form_mode["select_name"]."','".$item["value"]."',".
596  "'".$this->on_click_form_id."','".$this->form_mode["button_cmd"]."');\"");
597  }
598  else if ($this->getOnClickMode() ==
600  {
601  $tpl->setVariable("ONCLICK_ITEM",
602  'onclick="return il.AdvancedSelectionList.selectForm(\''.$this->getId().'\''.
603  ", '".$this->form_mode["select_name"]."','".$item["value"]."',".
604  "'".$item["title"]."');\"");
605  }
606  else if ($this->getOnClickMode() ==
608  {
609  $tpl->setVariable("ONCLICK_ITEM",
610  'onclick="il.AdvancedSelectionList.clickNop(\''.$this->getId().'\''.
611  ", '".$this->form_mode["select_name"]."','".$item["value"]."',".
612  "'".$item["title"]."');\"");
613  }
614 
615  $tpl->setVariable("CSS_ROW", $this->css_row);
616  if ($item["html"] == "")
617  {
618  $tpl->setVariable("TXT_ITEM", $item["title"]);
619  }
620  else
621  {
622  $tpl->setVariable("TXT_ITEM", $item["html"]);
623  }
624 
625  $tpl->setVariable("ID_ITEM_TR", $this->getId()."_".$item["value"]."_tr");
626  if ($item["ttip"] != "")
627  {
628  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
629  ilTooltipGUI::addTooltip($this->getId()."_".$item["value"]."_tr", $item["ttip"],
630  "", $item["tt_my"], $item["tt_at"], $item["tt_use_htmlspecialchars"]);
631  }
632 
633  $tpl->parseCurrentBlock();
634 
635  // add item to js object
636  $tpl->setCurrentBlock("js_item");
637  $tpl->setVariable("IT_ID", $this->getId());
638  $tpl->setVariable("IT_HID_NAME", $this->form_mode["select_name"]);
639  $tpl->setVariable("IT_HID_VAL", $item["value"]);
640  $tpl->setVariable("IT_TITLE", str_replace("'", "\\'", $item["title"]));
641  $tpl->parseCurrentBlock();
642  }
643  }
644 
645  $tpl->setCurrentBlock("cmd_table");
646  $tpl->parseCurrentBlock();
647 
648  if ($a_only_cmd_list_asynch)
649  {
650  return $tpl->get("cmd_table");
651  }
652 
654  {
655  $tpl->setCurrentBlock("top_img");
656  switch ($this->getHeaderIcon())
657  {
659  $tpl->setVariable("IMG_DOWN",
661  break;
663  $tpl->setVariable("IMG_DOWN",
665  break;
667  $tpl->setVariable("IMG_DOWN",
669  break;
670  default:
671  $tpl->setVariable("IMG_DOWN", $this->getHeaderIcon());
672  break;
673  }
674  // do not repeat title (accessibility) -> empty alt
675  //$tpl->setVariable("ALT_SEL_TOP", $this->getListTitle());
676  $tpl->setVariable("ALT_SEL_TOP", "");
677  $tpl->parseCurrentBlock();
678  }
679 
680  // output hidden input, if click mode is form submission
682  {
683  $tpl->setCurrentBlock("hidden_input");
684  $tpl->setVariable("HID", $this->getId());
685  $tpl->parseCurrentBlock();
686  }
687 
688  // output hidden input and initialize
690  {
691  $tpl->setCurrentBlock("hidden_input");
692  $tpl->setVariable("HID", $this->getId());
693  $tpl->parseCurrentBlock();
694 
695  // init hidden input with selected value
696  $tpl->setCurrentBlock("init_hidden_input");
697  $tpl->setVariable("H2ID", $this->getId());
698  $tpl->setVariable("HID_NAME", $this->form_mode["select_name"]);
699  $tpl->setVariable("HID_VALUE", $this->getSelectedValue());
700  $tpl->parseCurrentBlock();
701  }
702 
703  // js section
704  $tpl->setCurrentBlock("js_section");
705  if ($this->getAccessKey() > 0)
706  {
707  include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
708  $tpl->setVariable("ACCKEY", ilAccessKeyGUI::getAttribute($this->getAccessKey()));
709  }
710 
711  $cfg["trigger_event"] = $this->getTriggerEvent();
712  $cfg["auto_hide"] = $this->getAutoHide();
713 
714  if ($this->getSelectCallback() != "")
715  {
716  $cfg["select_callback"] = $this->getSelectCallback();
717  }
718  $cfg["anchor_id"] = "ilAdvSelListAnchorElement_".$this->getId();
719  $cfg["asynch"] = $this->getAsynch()
720  ? true
721  : false;
722  $cfg["asynch_url"] = $this->getAsynchUrl();
724  if (is_array($toggle))
725  {
726  $cfg["toggle_el"] = $toggle["el"];
727  $cfg["toggle_class_on"] = $toggle["class_on"];
728  }
729 //echo "<br>".htmlentities($this->getAsynchUrl());
730  include_once("./Services/JSON/classes/class.ilJsonUtil.php");
731  $tpl->setVariable("TXT_SEL_TOP", $this->getListTitle());
732  $tpl->setVariable("ID", $this->getId());
733  $tpl->setVariable("CFG", ilJsonUtil::encode($cfg));
734 //echo htmlentities(ilJsonUtil::encode($cfg));
735  $tpl->setVariable("CLASS_SEL_TOP", $this->getSelectionHeaderClass());
736  if ($this->getSelectionHeaderSpanClass() != "")
737  {
738  $tpl->setVariable("CLASS_SEL_TOP_SPAN",
739  $this->getSelectionHeaderSpanClass());
740  }
741 
742  // set the async url to an extra template variable
743  // (needed for a mobile skin)
744  $tpl->setVariable("ASYNC_URL", $this->getAsynchUrl());
745 
746  $tpl->parseCurrentBlock();
747 
748  // no js sections
749 if (false)
750 {
751  switch ($this->mode)
752  {
753  // links mode
755  reset($items);
756  $cnt = 0;
757  foreach($items as $item)
758  {
759  $tpl->setCurrentBlock("no_js_link");
760  $tpl->setVariable("LINKS_CLASS", $this->links_mode["link_class"]);
761  $tpl->setVariable("LINKS_HREF", $item["link"]);
762  $tpl->setVariable("LINKS_TXT", $item["title"]);
763  $tpl->parseCurrentBlock();
764  $tpl->setCurrentBlock("no_js_section");
765  $tpl->parseCurrentBlock();
766  }
767  break;
768 
770  reset($items);
771  $cnt = 0;
772  foreach($items as $item)
773  {
774  $tpl->setCurrentBlock("no_js_form_option");
775  $tpl->setVariable("FRM_OPTION_TXT", $item["title"]);
776  $tpl->setVariable("FRM_OPTION_VAL", $item["value"]);
777  if ($this->getSelectedValue() == $item["value"])
778  {
779  $tpl->setVariable("SELECTED", ' selected="selected" ');
780  }
781  $tpl->parseCurrentBlock();
782  }
783  if ($this->form_mode["include_form_tag"])
784  {
785  $tpl->setCurrentBlock("no_js_form_begin");
786  $tpl->setVariable("FRM_ID", $this->form_mode["form_id"]);
787  $tpl->setVariable("FRM_CLASS", $this->form_mode["form_class"]);
788  $tpl->setVariable("FRM_ACTION", $this->form_mode["form_action"]);
789  $tpl->setVariable("FRM_TARGET", $this->form_mode["form_target"]);
790  $tpl->parseCurrentBlock();
791  $tpl->touchBlock("no_js_form_end");
792  }
793  if ($this->form_mode["button_text"])
794  {
795  $tpl->setCurrentBlock("no_js_form_button");
796  $tpl->setVariable("FRM_BT_TXT", $this->form_mode["button_text"]);
797  $tpl->setVariable("FRM_BT_CLASS", $this->form_mode["button_class"]);
798  if ($this->form_mode["button_cmd"] != "")
799  {
800  $tpl->setVariable("FRM_BT_CMD", 'name="cmd['.$this->form_mode["button_cmd"].']"');
801  }
802  $tpl->parseCurrentBlock();
803  }
804  $tpl->setVariable("FRM_SELECT_NAME", $this->form_mode["select_name"]);
805  $tpl->setVariable("FRM_SELECT_CLASS", $this->form_mode["select_class"]);
806 
807  if ($this->getAccessKey() > 0)
808  {
809  include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
810  $tpl->setVariable("ACCKEYNJS", ilAccessKeyGUI::getAttribute($this->getAccessKey()));
811  }
812 
813  $tpl->setCurrentBlock("no_js_section");
814  $tpl->parseCurrentBlock();
815  break;
816  }
817 }
818 
819  return $tpl->get();
820  }
821 }
822 ?>