ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExplorerSelectInputGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Table/interfaces/interface.ilTableFilterItem.php");
6 include_once("./Services/Form/classes/class.ilFormPropertyGUI.php");
7 
17 {
24  public function __construct($a_title, $a_postvar, $a_explorer_gui, $a_multi = false)
25  {
26  global $DIC;
27 
28  $this->lng = $DIC->language();
29  $lng = $DIC->language();
30 
31  $this->multi_nodes = $a_multi;
32  $this->explorer_gui = $a_explorer_gui;
33 
34  parent::__construct($a_title, $a_postvar);
35  $this->setType("exp_select");
36  }
37 
44  public function getExplHandleCmd()
45  {
46  return "handleExplorerCommand";
47  }
48 
52  public function handleExplorerCommand()
53  {
54  $val = $this->getValue();
55  if (is_array($val)) {
56  foreach ($val as $v) {
57  $this->explorer_gui->setNodeOpen($v);
58  $this->explorer_gui->setNodeSelected($v);
59  }
60  } elseif ($val != "") {
61  $this->explorer_gui->setNodeOpen($val);
62  $this->explorer_gui->setNodeSelected($val);
63  }
64  $this->explorer_gui->handleCommand();
65  }
66 
73  abstract public function getTitleForNodeId($a_id);
74 
80  public function setValue($a_value)
81  {
82  if ($this->multi_nodes && !is_array($a_value)) {
83  if ($a_value !== false) {
84  $this->value = array($a_value);
85  } else {
86  $this->value = array();
87  }
88  } else {
89  $this->value = $a_value;
90  }
91  }
92 
98  public function getValue()
99  {
100  return $this->value;
101  }
102 
108  public function setValueByArray($a_values)
109  {
110  $this->setValue($a_values[$this->getPostVar()]);
111  }
112 
118  public function checkInput()
119  {
120  $lng = $this->lng;
121 
122  // sanitize
123  if ($this->multi_nodes) {
124  if (!is_array($_POST[$this->getPostVar()])) {
125  $_POST[$this->getPostVar()] = array();
126  }
127 
128  foreach ($_POST[$this->getPostVar()] as $k => $v) {
129  $_POST[$this->getPostVar()][$k] = ilUtil::stripSlashes($v);
130  }
131  } else {
132  $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
133  }
134 
135  // check required
136  if ($this->getRequired()) {
137  if ((!$this->multi_nodes && trim($_POST[$this->getPostVar()]) == "") ||
138  ($this->multi_nodes && count($_POST[$this->getPostVar()]) == 0)) {
139  $this->setAlert($lng->txt("msg_input_is_required"));
140  return false;
141  }
142  }
143  return true;
144  }
145 
146 
150  public function render($a_mode = "property_form")
151  {
152  $lng = $this->lng;
153 
154  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
156  $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/Explorer2/js/Explorer2.js");
157 
158  $tpl = new ilTemplate("tpl.prop_expl_select.html", true, true, "Services/UIComponent/Explorer2");
159 
160  if ($a_mode != "property_form") {
161  $tpl->touchBlock("tiny_presentation");
162  }
163 
164  // set values
165  $val = $this->getValue();
166  if (is_array($val)) {
167  $val_txt = $sep = "";
168  foreach ($val as $v) {
169  $tpl->setCurrentBlock("node_hid");
170  $tpl->setVariable("HID_NAME", $this->getPostVar() . "[]");
171  $tpl->setVariable("HID_VAL", $v);
172  $tpl->parseCurrentBlock();
173  $val_txt .= $sep . $this->getTitleForNodeId($v);
174  $sep = ", ";
175  $this->explorer_gui->setNodeOpen($v);
176  $this->explorer_gui->setNodeSelected($v);
177  }
178  $tpl->setVariable("VAL_TXT", $val_txt);
179  } elseif ($val != "") {
180  $tpl->setCurrentBlock("node_hid");
181  $tpl->setVariable("HID_NAME", $this->getPostVar());
182  $tpl->setVariable("HID_VAL", $val);
183  $tpl->parseCurrentBlock();
184  $tpl->setVariable("VAL_TXT", $this->getTitleForNodeId($val));
185  $this->explorer_gui->setNodeOpen($val);
186  $this->explorer_gui->setNodeSelected($val);
187  }
188 
189  $tpl->setVariable("POST_VAR", $this->getPostVar());
190  $tpl->setVariable("ID", $this->getFieldId());
191  // $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
192 
193  //added disabled
194  if (!$this->disabled) {
195  $tpl->setCurrentBlock("txt_select");
196  $tpl->setVariable("TXT_SELECT", $lng->txt("select"));
197  $tpl->setVariable("ID_TXT_SELECT", $this->getFieldId());
198  $tpl->parseCurrentBlock();
199 
200  $tpl->setCurrentBlock("txt_reset");
201  $tpl->setVariable("TXT_RESET", $lng->txt("reset"));
202  $tpl->setVariable("ID_TXT_RESET", $this->getFieldId());
203  $tpl->parseCurrentBlock();
204  }
205 
206  $tpl->setVariable("EXPL", $this->explorer_gui->getHTML());
207 
208  $top_tb = new ilToolbarGUI();
209 
210  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
211 
212  $button = ilLinkButton::getInstance();
213  $button->setCaption("select");
214  $button->addCSSClass("ilExplSelectInputButS");
215  $button->setOmitPreventDoubleSubmission(true);
216  $top_tb->addButtonInstance($button);
217 
218  $button = ilLinkButton::getInstance();
219  $button->setCaption("cancel");
220  $button->addCSSClass("ilExplSelectInputButC");
221  $button->setOmitPreventDoubleSubmission(true);
222  $top_tb->addButtonInstance($button);
223 
224  // :TODO: we should probably clone the buttons properly
225  $tpl->setVariable("TOP_TB", $top_tb->getHTML());
226  $tpl->setVariable("BOT_TB", $top_tb->getHTML());
227 
228  //$tpl->setVariable("HREF_SELECT",
229  // $ilCtrl->getLinkTargetByClass(array($parent_gui, "ilformpropertydispatchgui", "ilrepositoryselectorinputgui"),
230  // "showRepositorySelection"));
231 
232  /*if ($this->getValue() > 0 && $this->getValue() != ROOT_FOLDER_ID)
233  {
234  $tpl->setVariable("TXT_ITEM",
235  $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($this->getValue())));
236  }
237  else
238  {
239  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
240  $title = $nd["title"];
241  if ($title == "ILIAS")
242  {
243  $title = $lng->txt("repository");
244  }
245  if (in_array($nd["type"], $this->getClickableTypes()))
246  {
247  $tpl->setVariable("TXT_ITEM", $title);
248  }
249  }*/
250 
251  return $tpl->get();
252  }
253 
258  public function insert(&$a_tpl)
259  {
260  $a_tpl->setCurrentBlock("prop_generic");
261  $a_tpl->setVariable("PROP_GENERIC", $this->render());
262  $a_tpl->parseCurrentBlock();
263  }
264 
268  public function getTableFilterHTML()
269  {
270  $html = $this->render("table_filter");
271  return $html;
272  }
273 }
Interface for property form input GUI classes that can be used in table filters.
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
getPostVar()
Get Post Variable.
getTableFilterHTML()
Get HTML for table filter.
__construct($a_title, $a_postvar, $a_explorer_gui, $a_multi=false)
Constructor.
checkInput()
Check input, strip slashes etc.
setAlert($a_alert)
Set Alert Text.
setType($a_type)
Set Type.
setValueByArray($a_values)
Set value by array.
getExplHandleCmd()
Get explorer handle command function.
getTitleForNodeId($a_id)
Get title for node id (needs to be overwritten, if explorer is not a tree eplorer.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
handleExplorerCommand()
Handle explorer command.
This class represents a property in a property form.
Select explorer tree nodes input GUI.
insert(&$a_tpl)
Insert property html.
render($a_mode="property_form")
Render item.
static initPanel($a_resize=false, ilTemplate $a_main_tpl=null)
Init yui panel.
$_POST["username"]
$html
Definition: example_001.php:87
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.