ILIAS  eassessment Revision 61809
 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.gif";
18  const DOWN_ARROW_DARK = "mm_down_arrow_dark.gif";
19  const NO_ICON = "";
20 
21  const MODE_LINKS = "links";
22  const MODE_FORM_SELECT = "select";
23 
24  const ON_ITEM_CLICK_HREF = "href";
25  const ON_ITEM_CLICK_FORM_SUBMIT = "submit";
26  const ON_ITEM_CLICK_FORM_SELECT = "select";
27 
28  protected $css_row = "";
29  protected $access_key = false;
30  protected $toggle = false;
31  protected $asynch_url = false;
32  protected $selected_value = "";
33 
34  /*
35 
36  The modes implement the following html for non-js fallback:
37 
38  MODE_LINKS:
39 
40  <a href="...">...</a> <a href="...">...<a>
41 
42  MODE_FORM_SELECT: (form and submit tags are optional)
43 
44  <form id="..." class="..." method="post" action="..." target="_top">
45  <select name="..." class="..." size="0">
46  <option value="...">...</option>
47  ...
48  </select>
49  <input class="ilEditSubmit" type="submit" value="Go"/>
50  </form>
51 
52  */
53 
58  public function __construct()
59  {
63  }
64 
68  public function setLinksMode($a_link_class = "")
69  {
71  $this->links_mode = array(
72  "link_class" => $a_link_class);
73  }
74 
80  public function setFormSelectMode($a_select_name, $a_select_class = "",
81  $a_include_form_tag = false, $a_form_action = "", $a_form_id = "",
82  $a_form_class = "", $a_form_target = "_top",
83  $a_button_text = "", $a_button_class = "", $a_button_cmd = "")
84  {
86  $this->form_mode = array(
87  "select_name" => $a_select_name,
88  "select_class" => $a_select_class,
89  "include_form_tag" => $a_include_form_tag,
90  "form_action" => $a_form_action,
91  "form_id" => $a_form_id,
92  "form_class" => $a_form_class,
93  "form_target" => $a_form_target,
94  "button_text" => $a_button_text,
95  "button_class" => $a_button_class,
96  "button_cmd" => $a_button_cmd
97  );
98  }
99 
111  function addItem($a_title, $a_value = "", $a_link = "", $a_img = "", $a_alt = "", $a_frame = "",
112  $a_html = "", $a_prevent_background_click = false)
113  {
114  $this->items[] = array("title" => $a_title, "value" => $a_value,
115  "link" => $a_link, "img" => $a_img, "alt" => $a_alt, "frame" => $a_frame,
116  "html" => $a_html, "prevent_background_click" => $a_prevent_background_click);
117  }
118 
124  function getItems()
125  {
126  return $this->items;
127  }
128 
134  function setListTitle($a_listtitle)
135  {
136  $this->listtitle = $a_listtitle;
137  }
138 
144  function getListTitle()
145  {
146  return $this->listtitle;
147  }
148 
154  function setSelectionHeaderClass($a_selectionheaderclass)
155  {
156  $this->selectionheaderclass = $a_selectionheaderclass;
157  }
158 
165  {
166  return $this->selectionheaderclass;
167  }
168 
174  function setHeaderIcon($a_headericon)
175  {
176  $this->headericon = $a_headericon;
177  }
178 
184  function getHeaderIcon()
185  {
186  return $this->headericon;
187  }
188 
194  function setNoJSLinkClass($a_nojslinkclass)
195  {
196  $this->nojslinkclass = $a_nojslinkclass;
197  }
198 
204  function getNoJSLinkClass()
205  {
206  return $this->nojslinkclass;
207  }
208 
214  function setItemLinkClass($a_itemlinkclass)
215  {
216  $this->itemlinkclass = $a_itemlinkclass;
217  }
218 
224  function getItemLinkClass()
225  {
226  return $this->itemlinkclass;
227  }
228 
234  function setId($a_id)
235  {
236  $this->id = $a_id;
237  }
238 
244  function getId()
245  {
246  return $this->id;
247  }
248 
254  function setUseImages($a_useimages)
255  {
256  $this->useimages = $a_useimages;
257  }
258 
264  function getUseImages()
265  {
266  return $this->useimages;
267  }
268 
274  function setAccessKey($a_val)
275  {
276  $this->access_key = $a_val;
277  }
278 
284  function getAccessKey()
285  {
286  return $this->access_key;
287  }
288 
299  function setOnClickMode($a_val, $a_onclick_form_id = "")
300  {
301  $this->on_click = $a_val;
302  $this->on_click_form_id = $a_onclick_form_id;
303  }
304 
310  function getOnClickMode()
311  {
312  return $this->on_click;
313  }
314 
320  function setSelectedValue($a_val)
321  {
322  $this->selected_value = $a_val;
323  }
324 
330  function getSelectedValue()
331  {
332  return $this->selected_value;
333  }
334 
341  function setAdditionalToggleElement($a_el, $a_on)
342  {
343  $this->toggle = array("el" => $a_el, "class_on" => $a_on);
344  }
345 
352  {
353  return $this->toggle;
354  }
355 
361  function setAsynch($a_val)
362  {
363  if ($a_val)
364  {
365  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
367  }
368  $this->asynch = $a_val;
369  }
370 
376  function getAsynch()
377  {
378  return $this->asynch;
379  }
380 
386  function setAsynchUrl($a_val)
387  {
388  $this->asynch_url = $a_val;
389  }
390 
396  function getAsynchUrl()
397  {
398  return $this->asynch_url;
399  }
400 
404  public function getHTML($a_only_cmd_list_asynch = false)
405  {
406  $items = $this->getItems();
407 
408  // do not show list, if no item is in list
409  if (count($items) == 0 && !$this->getAsynch())
410  {
411  return "";
412  }
413 
414  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
416  $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/Overlay/js/ilOverlay.js");
417  $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js");
418 
419  $tpl = new ilTemplate("tpl.adv_selection_list.html", true, true,
420  "Services/UIComponent/AdvancedSelectionList", "DEFAULT", false, true);
421 
422  reset($items);
423 
424  $cnt = 0;
425 
426  if ($this->getAsynch())
427  {
428  $tpl->setCurrentBlock("asynch_request");
429  $tpl->setVariable("IMG_LOADER", ilUtil::getImagePath("loader.gif"));
430  $tpl->parseCurrentBlock();
431  }
432  else
433  {
434  foreach($items as $item)
435  {
436  if (isset($item["ref_id"]))
437  {
438  $sel_arr[$item["ref_id"]] = (isset($item["title"]))
439  ? $item["title"]
440  : "";
441  }
442  $this->css_row = ($this->css_row != "tblrow1_mo")
443  ? "tblrow1_mo"
444  : "tblrow2_mo";
445 
446  if ($this->getUseImages())
447  {
448  if ($item["img"])
449  {
450  $tpl->setCurrentBlock("image");
451  $tpl->setVariable("IMG_ITEM", $item["img"]);
452  $tpl->setVariable("ALT_ITEM", $item["alt"]);
453  $tpl->parseCurrentBlock();
454  }
455  else
456  {
457  $tpl->touchBlock("no_image");
458  }
459  }
460 
461  if ($item["frame"])
462  {
463  $tpl->setCurrentBlock("frame");
464  $tpl->setVariable("TARGET_ITEM", $item["frame"]);
465  $tpl->parseCurrentBlock();
466  }
467 
468  if ($this->getItemLinkClass() != "")
469  {
470  $tpl->setCurrentBlock("item_link_class");
471  $tpl->setVariable("ITEM_LINK_CLASS", $this->getItemLinkClass());
472  $tpl->parseCurrentBlock();
473  }
474 
475  $tpl->setCurrentBlock("item");
476  if ($this->getOnClickMode() ==
478  {
479 //var_dump($item);
480  if ($item["prevent_background_click"])
481  {
482  $tpl->setVariable("ONCLICK_ITEM",'');
483  }
484  else
485  {
486  $tpl->setVariable("ONCLICK_ITEM",
487  'onclick="'."return ilAdvancedSelectionList.openTarget('".$item["link"]."','".$item["frame"]."');".'"');
488  }
489 
490  $tpl->setVariable("HREF_ITEM",'href="'.$item["link"].'"');
491  $tpl->setVariable("ID_ITEM", $this->getId()."_".$item["value"]);
492  }
493  else if ($this->getOnClickMode() ==
495  {
496  $tpl->setVariable("ONCLICK_ITEM",
497  'onclick="ilAdvancedSelectionList.submitForm(\''.$this->getId().'\''.
498  ", '".$this->form_mode["select_name"]."','".$item["value"]."',".
499  "'".$this->on_click_form_id."','".$this->form_mode["button_cmd"]."');\"");
500  }
501  else if ($this->getOnClickMode() ==
503  {
504  $tpl->setVariable("ONCLICK_ITEM",
505  'onclick="ilAdvancedSelectionList.selectForm(\''.$this->getId().'\''.
506  ", '".$this->form_mode["select_name"]."','".$item["value"]."',".
507  "'".$item["title"]."');\"");
508  }
509 
510  $tpl->setVariable("CSS_ROW", $this->css_row);
511  if ($item["html"] == "")
512  {
513  $tpl->setVariable("TXT_ITEM", $item["title"]);
514  }
515  else
516  {
517  $tpl->setVariable("TXT_ITEM", $item["html"]);
518  }
519 
520  $tpl->parseCurrentBlock();
521  }
522  }
523 
524  $tpl->setCurrentBlock("cmd_table");
525  $tpl->parseCurrentBlock();
526 
527  if ($a_only_cmd_list_asynch)
528  {
529  return $tpl->get("cmd_table");
530  }
531 
533  {
534  $tpl->setCurrentBlock("top_img");
535  switch ($this->getHeaderIcon())
536  {
538  $tpl->setVariable("IMG_DOWN",
540  break;
542  $tpl->setVariable("IMG_DOWN",
544  break;
545  default:
546  $tpl->setVariable("IMG_DOWN", $this->getHeaderIcon());
547  break;
548  }
549  // do not repeat title (accessibility) -> empty alt
550  //$tpl->setVariable("ALT_SEL_TOP", $this->getListTitle());
551  $tpl->setVariable("ALT_SEL_TOP", "");
552  $tpl->parseCurrentBlock();
553  }
554 
555  // output hidden input, if click mode is form submission
557  {
558  $tpl->setCurrentBlock("hidden_input");
559  $tpl->setVariable("HID", $this->getId());
560  $tpl->parseCurrentBlock();
561  }
562 
563  // output hidden input and initialize
565  {
566  $tpl->setCurrentBlock("hidden_input");
567  $tpl->setVariable("HID", $this->getId());
568  $tpl->parseCurrentBlock();
569 
570  // init hidden input with selected value
571  $tpl->setCurrentBlock("init_hidden_input");
572  $tpl->setVariable("H2ID", $this->getId());
573  $tpl->setVariable("HID_NAME", $this->form_mode["select_name"]);
574  $tpl->setVariable("HID_VALUE", $this->getSelectedValue());
575  $tpl->parseCurrentBlock();
576  }
577 
578  // js section
579  $tpl->setCurrentBlock("js_section");
580  if ($this->getAccessKey() > 0)
581  {
582  include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
583  $tpl->setVariable("ACCKEY", ilAccessKeyGUI::getAttribute($this->getAccessKey()));
584  }
585 
586  $cfg["anchor_id"] = "ilAdvSelListAnchorElement_".$this->getId();
587  $cfg["asynch"] = $this->getAsynch()
588  ? true
589  : false;
590  $cfg["asynch_url"] = $this->getAsynchUrl();
592  if (is_array($toggle))
593  {
594  $cfg["toggle_el"] = $toggle["el"];
595  $cfg["toggle_class_on"] = $toggle["class_on"];
596  }
597 //echo "<br>".htmlentities($this->getAsynchUrl());
598  include_once("./Services/JSON/classes/class.ilJsonUtil.php");
599  $tpl->setVariable("TXT_SEL_TOP", $this->getListTitle());
600  $tpl->setVariable("ID", $this->getId());
601  $tpl->setVariable("CFG", ilJsonUtil::encode($cfg));
602 //echo htmlentities(ilJsonUtil::encode($cfg));
603  $tpl->setVariable("CLASS_SEL_TOP", $this->getSelectionHeaderClass());
604  $tpl->parseCurrentBlock();
605 
606  // no js sections
607  switch ($this->mode)
608  {
609  // links mode
611  reset($items);
612  $cnt = 0;
613  foreach($items as $item)
614  {
615  $tpl->setCurrentBlock("no_js_link");
616  $tpl->setVariable("LINKS_CLASS", $this->links_mode["link_class"]);
617  $tpl->setVariable("LINKS_HREF", $item["link"]);
618  $tpl->setVariable("LINKS_TXT", $item["title"]);
619  $tpl->parseCurrentBlock();
620  $tpl->setCurrentBlock("no_js_section");
621  $tpl->parseCurrentBlock();
622  }
623  break;
624 
626  reset($items);
627  $cnt = 0;
628  foreach($items as $item)
629  {
630  $tpl->setCurrentBlock("no_js_form_option");
631  $tpl->setVariable("FRM_OPTION_TXT", $item["title"]);
632  $tpl->setVariable("FRM_OPTION_VAL", $item["value"]);
633  if ($this->getSelectedValue() == $item["value"])
634  {
635  $tpl->setVariable("SELECTED", ' selected="selected" ');
636  }
637  $tpl->parseCurrentBlock();
638  }
639  if ($this->form_mode["include_form_tag"])
640  {
641  $tpl->setCurrentBlock("no_js_form_begin");
642  $tpl->setVariable("FRM_ID", $this->form_mode["form_id"]);
643  $tpl->setVariable("FRM_CLASS", $this->form_mode["form_class"]);
644  $tpl->setVariable("FRM_ACTION", $this->form_mode["form_action"]);
645  $tpl->setVariable("FRM_TARGET", $this->form_mode["form_target"]);
646  $tpl->parseCurrentBlock();
647  $tpl->touchBlock("no_js_form_end");
648  }
649  if ($this->form_mode["button_text"])
650  {
651  $tpl->setCurrentBlock("no_js_form_button");
652  $tpl->setVariable("FRM_BT_TXT", $this->form_mode["button_text"]);
653  $tpl->setVariable("FRM_BT_CLASS", $this->form_mode["button_class"]);
654  if ($this->form_mode["button_cmd"] != "")
655  {
656  $tpl->setVariable("FRM_BT_CMD", 'name="cmd['.$this->form_mode["button_cmd"].']"');
657  }
658  $tpl->parseCurrentBlock();
659  }
660  $tpl->setVariable("FRM_SELECT_NAME", $this->form_mode["select_name"]);
661  $tpl->setVariable("FRM_SELECT_CLASS", $this->form_mode["select_class"]);
662 
663  if ($this->getAccessKey() > 0)
664  {
665  include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
666  $tpl->setVariable("ACCKEYNJS", ilAccessKeyGUI::getAttribute($this->getAccessKey()));
667  }
668 
669  $tpl->setCurrentBlock("no_js_section");
670  $tpl->parseCurrentBlock();
671  break;
672 
673  }
674 
675  return $tpl->get();
676  }
677 }
678 ?>