ILIAS  Release_4_0_x_branch Revision 61816
 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 
15 {
16  protected $value;
17  protected $maxlength = 200;
18  protected $size = 40;
19  protected $validationRegexp;
20  protected $validationFailureMessage = '';
21  protected $suffix;
22  protected $style_css;
23 
24  // added for YUI autocomplete feature
25  protected $yui_dataSource;
26  protected $yui_dataSchema;
28  protected $yui_delimiterarray = array();
29  protected $submit_form_on_enter = false;
30 
37  function __construct($a_title = "", $a_postvar = "")
38  {
39  parent::__construct($a_title, $a_postvar);
40  $this->setInputType("text");
41  $this->validationRegexp = "";
42  }
43 
49  function setValue($a_value)
50  {
51  $this->value = $a_value;
52  }
53 
59  function getValue()
60  {
61  return $this->value;
62  }
63 
69  public function setValidationFailureMessage($a_msg)
70  {
71  $this->validationFailureMessage = $a_msg;
72  }
73 
74  public function getValidationFailureMessage()
75  {
77  }
78 
84  function setValidationRegexp($a_value)
85  {
86  $this->validationRegexp = $a_value;
87  }
88 
95  {
97  }
98 
104  function setMaxLength($a_maxlength)
105  {
106  $this->maxlength = $a_maxlength;
107  }
108 
114  function getMaxLength()
115  {
116  return $this->maxlength;
117  }
118 
124  function setSize($a_size)
125  {
126  $this->size = $a_size;
127  }
128 
134  function setInlineStyle($a_style)
135  {
136  $this->style_css = $a_style;
137  }
138 
144  function getInlineStyle()
145  {
146  return $this->style_css;
147  }
148 
154  function setValueByArray($a_values)
155  {
156  $this->setValue($a_values[$this->getPostVar()]);
157  }
158 
164  function getSize()
165  {
166  return $this->size;
167  }
168 
174  function setSuffix($a_value)
175  {
176  $this->suffix = $a_value;
177  }
178 
184  function getSuffix()
185  {
186  return $this->suffix;
187  }
188 
196  public function setInputType($a_type)
197  {
198  $this->input_type = $a_type;
199  }
200 
206  public function getInputType()
207  {
208  return $this->input_type;
209  }
210 
216  function setSubmitFormOnEnter($a_val)
217  {
218  $this->submit_form_on_enter = $a_val;
219  }
220 
227  {
229  }
230 
236  function checkInput()
237  {
238  global $lng;
239 
240  $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
241  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
242  {
243  $this->setAlert($lng->txt("msg_input_is_required"));
244 
245  return false;
246  }
247  else if (strlen($this->getValidationRegexp()))
248  {
249  if (!preg_match($this->getValidationRegexp(), $_POST[$this->getPostVar()]))
250  {
251  $this->setAlert(
252  $this->getValidationFailureMessage() ?
253  $this->getValidationFailureMessage() :
254  $lng->txt('msg_wrong_format')
255  );
256  return FALSE;
257  }
258  }
259 
260  return $this->checkSubItemsInput();
261  }
262 
267  function getDataSource()
268  {
269  return $this->yui_dataSource;
270  }
271 
276  function setDataSource($href)
277  {
278  $this->yui_dataSource = $href;
279  }
280 
286  {
287  return $this->yui_dataSchema;
288  }
289 
303  function setDataSourceSchema($ds)
304  {
305  $this->yui_dataSchema = $ds;
306  }
307 
312  {
314  }
315 
322  function setDataSourceResultFormat($callback)
323  {
324  $this->yui_formatCallback = $callback;
325  }
326 
333  public function setDataSourceDelimiter($ar)
334  {
335  if (!is_array($ar))
336  $ar = array($ar);
337  $this->yui_delimiterarray = $ar;
338  }
339 
344  public function getDataSourceDelimiter()
345  {
347  }
348 
352  protected function render($a_mode = "")
353  {
354  $tpl = new ilTemplate("tpl.prop_textinput.html", true, true, "Services/Form");
355  if (strlen($this->getValue()))
356  {
357  $tpl->setCurrentBlock("prop_text_propval");
358  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
359  $tpl->parseCurrentBlock();
360  }
361  if (strlen($this->getInlineStyle()))
362  {
363  $tpl->setCurrentBlock("stylecss");
364  $tpl->setVariable("CSS_STYLE", ilUtil::prepareFormOutput($this->getInlineStyle()));
365  $tpl->parseCurrentBlock();
366  }
367  if ($this->getSubmitFormOnEnter())
368  {
369  $tpl->touchBlock("submit_form_on_enter");
370  }
371 
372  switch($this->getInputType())
373  {
374  case 'password':
375  $tpl->setVariable('PROP_INPUT_TYPE','password');
376  break;
377  case 'hidden':
378  $tpl->setVariable('PROP_INPUT_TYPE','hidden');
379  break;
380  case 'text':
381  default:
382  $tpl->setVariable('PROP_INPUT_TYPE','text');
383  }
384  $tpl->setVariable("ID", $this->getFieldId());
385  $tpl->setVariable("SIZE", $this->getSize());
386  if($this->getMaxLength() != null)
387  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
388  if (strlen($this->getSuffix())) $tpl->setVariable("INPUT_SUFFIX", $this->getSuffix());
389 
390  if ($this->getDisabled())
391  {
392  $tpl->setVariable("DISABLED",
393  " disabled=\"disabled\"");
394  $tpl->setVariable("HIDDEN_INPUT",
395  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
396  }
397  else
398  {
399  $tpl->setVariable("POST_VAR", $this->getPostVar());
400  }
401 
402  // use autocomplete feature?
403  if ($this->getDataSource() && $this->getDataSourceSchema())
404  {
405  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
406  include_once "./Services/JSON/classes/class.ilJsonUtil.php";
408  $tpl->setVariable('ID_AUTOCOMPLETE', $this->getFieldId() . "_autocomplete");
409  $tpl->setVariable('YUI_DATASOURCE', $this->getDataSource());
410  $tpl->setVariable('YUI_DATASCHEMA', ilJsonUtil::encode($this->getDataSourceSchema()));
411  if ($this->getDataSourceResultFormat())
412  {
413  $tpl->setVariable('YUI_FORMAT_CALLBACK', $this->getDataSourceResultFormat());
414  }
415 
416  if ($this->getDataSourceDelimiter())
417  {
418  $tpl->setVariable('DELIMITER_ARRAY', ilJsonUtil::encode($this->getDataSourceDelimiter()));
419  }
420  }
421 
422  if ($a_mode == "toolbar")
423  {
424  // block-inline hack, see: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
425  // -moz-inline-stack for FF2
426  // zoom 1; *display:inline for IE6 & 7
427  $tpl->setVariable("STYLE_PAR", 'display: -moz-inline-stack; display:inline-block; zoom: 1; *display:inline; z-index:3000;');
428  $tpl->setVariable("AC_STYLE", 'style="position:absolute; width:400px;"');
429  }
430  else
431  {
432  $tpl->setVariable("STYLE_PAR", 'z-index:3000;');
433  }
434 
435  return $tpl->get();
436  }
437 
443  function insert(&$a_tpl)
444  {
445  $html = $this->render();
446 
447  $a_tpl->setCurrentBlock("prop_generic");
448  $a_tpl->setVariable("PROP_GENERIC", $html);
449  $a_tpl->parseCurrentBlock();
450  }
451 
456  {
457  $html = $this->render();
458  return $html;
459  }
460 
464  function getToolbarHTML()
465  {
466  $html = $this->render("toolbar");
467  return $html;
468  }
469 
470 }
471 ?>