ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTextInputGUI.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 include_once("./Services/Table/interfaces/interface.ilTableFilterItem.php");
5 include_once("./Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
6 include_once 'Services/UIComponent/Toolbar/interfaces/interface.ilToolbarItem.php';
7 
16 {
17  protected $value;
18  protected $maxlength = 200;
19  protected $size = 40;
20  protected $validationRegexp;
21  protected $validationFailureMessage = '';
22  protected $suffix;
23  protected $style_css;
24  protected $css_class;
25 
26  // added for YUI autocomplete feature
27  protected $yui_dataSource;
28  protected $yui_dataSchema;
30  protected $yui_delimiterarray = array();
31  protected $submit_form_on_enter = false;
32 
39  function __construct($a_title = "", $a_postvar = "")
40  {
41  parent::__construct($a_title, $a_postvar);
42  $this->setInputType("text");
43  $this->validationRegexp = "";
44  }
45 
51  function setValue($a_value)
52  {
53  $this->value = $a_value;
54  }
55 
61  function getValue()
62  {
63  return $this->value;
64  }
65 
71  public function setValidationFailureMessage($a_msg)
72  {
73  $this->validationFailureMessage = $a_msg;
74  }
75 
76  public function getValidationFailureMessage()
77  {
79  }
80 
86  public function setValidationRegexp($a_value)
87  {
88  $this->validationRegexp = $a_value;
89  }
90 
97  {
99  }
100 
106  function setMaxLength($a_maxlength)
107  {
108  $this->maxlength = $a_maxlength;
109  }
110 
116  function getMaxLength()
117  {
118  return $this->maxlength;
119  }
120 
126  function setSize($a_size)
127  {
128  $this->size = $a_size;
129  }
130 
136  function setInlineStyle($a_style)
137  {
138  $this->style_css = $a_style;
139  }
140 
146  function getInlineStyle()
147  {
148  return $this->style_css;
149  }
150 
151  public function setCssClass($a_class)
152  {
153  $this->css_class = $a_class;
154  }
155 
156  public function getCssClass()
157  {
158  return $this->css_class;
159  }
160 
161 
167  function setValueByArray($a_values)
168  {
169  $this->setValue($a_values[$this->getPostVar()]);
170  }
171 
177  function getSize()
178  {
179  return $this->size;
180  }
181 
187  function setSuffix($a_value)
188  {
189  $this->suffix = $a_value;
190  }
191 
197  function getSuffix()
198  {
199  return $this->suffix;
200  }
201 
209  public function setInputType($a_type)
210  {
211  $this->input_type = $a_type;
212  }
213 
219  public function getInputType()
220  {
221  return $this->input_type;
222  }
223 
229  function setSubmitFormOnEnter($a_val)
230  {
231  $this->submit_form_on_enter = $a_val;
232  }
233 
240  {
242  }
243 
249  function checkInput()
250  {
251  global $lng;
252 
253  $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
254  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
255  {
256  $this->setAlert($lng->txt("msg_input_is_required"));
257 
258  return false;
259  }
260  else if (strlen($this->getValidationRegexp()))
261  {
262  if (!preg_match($this->getValidationRegexp(), $_POST[$this->getPostVar()]))
263  {
264  $this->setAlert(
265  $this->getValidationFailureMessage() ?
266  $this->getValidationFailureMessage() :
267  $lng->txt('msg_wrong_format')
268  );
269  return FALSE;
270  }
271  }
272 
273  return $this->checkSubItemsInput();
274  }
275 
280  function getDataSource()
281  {
282  return $this->yui_dataSource;
283  }
284 
289  function setDataSource($href)
290  {
291  $this->yui_dataSource = $href;
292  }
293 
299  {
300  return $this->yui_dataSchema;
301  }
302 
316  function setDataSourceSchema($ds)
317  {
318  $this->yui_dataSchema = $ds;
319  }
320 
325  {
327  }
328 
335  function setDataSourceResultFormat($callback)
336  {
337  $this->yui_formatCallback = $callback;
338  }
339 
346  public function setDataSourceDelimiter($ar)
347  {
348  if (!is_array($ar))
349  $ar = array($ar);
350  $this->yui_delimiterarray = $ar;
351  }
352 
357  public function getDataSourceDelimiter()
358  {
360  }
361 
365  protected function render($a_mode = "")
366  {
367  $tpl = new ilTemplate("tpl.prop_textinput.html", true, true, "Services/Form");
368  if (strlen($this->getValue()))
369  {
370  $tpl->setCurrentBlock("prop_text_propval");
371  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
372  $tpl->parseCurrentBlock();
373  }
374  if (strlen($this->getInlineStyle()))
375  {
376  $tpl->setCurrentBlock("stylecss");
377  $tpl->setVariable("CSS_STYLE", ilUtil::prepareFormOutput($this->getInlineStyle()));
378  $tpl->parseCurrentBlock();
379  }
380  if(strlen($this->getCssClass()))
381  {
382  $tpl->setCurrentBlock("classcss");
383  $tpl->setVariable('CLASS_CSS', ilUtil::prepareFormOutput($this->getCssClass()));
384  $tpl->parseCurrentBlock();
385  }
386  if ($this->getSubmitFormOnEnter())
387  {
388  $tpl->touchBlock("submit_form_on_enter");
389  }
390 
391  switch($this->getInputType())
392  {
393  case 'password':
394  $tpl->setVariable('PROP_INPUT_TYPE','password');
395  break;
396  case 'hidden':
397  $tpl->setVariable('PROP_INPUT_TYPE','hidden');
398  break;
399  case 'text':
400  default:
401  $tpl->setVariable('PROP_INPUT_TYPE','text');
402  }
403  $tpl->setVariable("ID", $this->getFieldId());
404  $tpl->setVariable("SIZE", $this->getSize());
405  if($this->getMaxLength() != null)
406  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
407  if (strlen($this->getSuffix())) $tpl->setVariable("INPUT_SUFFIX", $this->getSuffix());
408 
409  if ($this->getDisabled())
410  {
411  $tpl->setVariable("DISABLED",
412  " disabled=\"disabled\"");
413  $tpl->setVariable("HIDDEN_INPUT",
414  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
415  }
416  else
417  {
418  $tpl->setVariable("POST_VAR", $this->getPostVar());
419  }
420 
421  // use autocomplete feature?
422  if ($this->getDataSource() && $this->getDataSourceSchema())
423  {
424  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
425  include_once "./Services/JSON/classes/class.ilJsonUtil.php";
427  $tpl->setVariable('ID_AUTOCOMPLETE', $this->getFieldId() . "_autocomplete");
428  $tpl->setVariable('YUI_DATASOURCE', $this->getDataSource());
429  $tpl->setVariable('YUI_DATASCHEMA', ilJsonUtil::encode($this->getDataSourceSchema()));
430  if ($this->getDataSourceResultFormat())
431  {
432  $tpl->setVariable('YUI_FORMAT_CALLBACK', $this->getDataSourceResultFormat());
433  }
434 
435  if ($this->getDataSourceDelimiter())
436  {
437  $tpl->setVariable('DELIMITER_ARRAY', ilJsonUtil::encode($this->getDataSourceDelimiter()));
438  }
439  }
440 
441  if ($a_mode == "toolbar")
442  {
443  // block-inline hack, see: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
444  // -moz-inline-stack for FF2
445  // zoom 1; *display:inline for IE6 & 7
446  $tpl->setVariable("STYLE_PAR", 'display: -moz-inline-stack; display:inline-block; zoom: 1; *display:inline;');
447  if ($this->getDataSource() && $this->getDataSourceSchema())
448  {
449  $tpl->setVariable("AC_STYLE", 'style="position:absolute; width:400px;"');
450  }
451  }
452  else
453  {
454  $tpl->setVariable("STYLE_PAR", '');
455  }
456 
457  return $tpl->get();
458  }
459 
465  function insert(&$a_tpl)
466  {
467  $html = $this->render();
468 
469  $a_tpl->setCurrentBlock("prop_generic");
470  $a_tpl->setVariable("PROP_GENERIC", $html);
471  $a_tpl->parseCurrentBlock();
472  }
473 
478  {
479  $html = $this->render();
480  return $html;
481  }
482 
486  function getToolbarHTML()
487  {
488  $html = $this->render("toolbar");
489  return $html;
490  }
491 
492 }
493 ?>