ILIAS  Release_4_4_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 include_once 'Services/UIComponent/Toolbar/interfaces/interface.ilToolbarItem.php';
7 include_once 'Services/Form/interfaces/interface.ilMultiValuesItem.php';
8 
17 {
18  protected $value;
19  protected $maxlength = 200;
20  protected $size = 40;
21  protected $validationRegexp;
22  protected $validationFailureMessage = '';
23  protected $suffix;
24  protected $style_css;
25  protected $css_class;
26  protected $ajax_datasource;
28  protected $submit_form_on_enter = false;
29 
33  protected $autocomplete_disabled = false;
34 
41  function __construct($a_title = "", $a_postvar = "")
42  {
43  parent::__construct($a_title, $a_postvar);
44  $this->setInputType("text");
45  $this->setType("text");
46  $this->validationRegexp = "";
47  }
48 
54  function setValue($a_value)
55  {
56  if($this->getMulti() && is_array($a_value))
57  {
58  $this->setMultiValues($a_value);
59  $a_value = array_shift($a_value);
60  }
61  $this->value = $a_value;
62  }
63 
69  function getValue()
70  {
71  return $this->value;
72  }
73 
74 
80  public function setValidationFailureMessage($a_msg)
81  {
82  $this->validationFailureMessage = $a_msg;
83  }
84 
85  public function getValidationFailureMessage()
86  {
88  }
89 
95  public function setValidationRegexp($a_value)
96  {
97  $this->validationRegexp = $a_value;
98  }
99 
106  {
108  }
109 
115  function setMaxLength($a_maxlength)
116  {
117  $this->maxlength = $a_maxlength;
118  }
119 
125  function getMaxLength()
126  {
127  return $this->maxlength;
128  }
129 
135  function setSize($a_size)
136  {
137  $this->size = $a_size;
138  }
139 
145  function setInlineStyle($a_style)
146  {
147  $this->style_css = $a_style;
148  }
149 
155  function getInlineStyle()
156  {
157  return $this->style_css;
158  }
159 
160  public function setCssClass($a_class)
161  {
162  $this->css_class = $a_class;
163  }
164 
165  public function getCssClass()
166  {
167  return $this->css_class;
168  }
169 
170 
176  function setValueByArray($a_values)
177  {
178  $this->setValue($a_values[$this->getPostVar()]);
179  }
180 
186  function getSize()
187  {
188  return $this->size;
189  }
190 
196  function setSuffix($a_value)
197  {
198  $this->suffix = $a_value;
199  }
200 
206  function getSuffix()
207  {
208  return $this->suffix;
209  }
210 
218  public function setInputType($a_type)
219  {
220  $this->input_type = $a_type;
221  }
222 
228  public function getInputType()
229  {
230  return $this->input_type;
231  }
232 
238  function setSubmitFormOnEnter($a_val)
239  {
240  $this->submit_form_on_enter = $a_val;
241  }
242 
249  {
251  }
252 
258  function checkInput()
259  {
260  global $lng;
261 
262  if(!$this->getMulti())
263  {
264  $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
265  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
266  {
267  $this->setAlert($lng->txt("msg_input_is_required"));
268 
269  return false;
270  }
271  else if (strlen($this->getValidationRegexp()))
272  {
273  if (!preg_match($this->getValidationRegexp(), $_POST[$this->getPostVar()]))
274  {
275  $this->setAlert(
276  $this->getValidationFailureMessage() ?
277  $this->getValidationFailureMessage() :
278  $lng->txt('msg_wrong_format')
279  );
280  return FALSE;
281  }
282  }
283  }
284  else
285  {
286  foreach($_POST[$this->getPostVar()] as $idx => $value)
287  {
288  $_POST[$this->getPostVar()][$idx] = ilUtil::stripSlashes($value);
289  }
290  $_POST[$this->getPostVar()] = array_unique($_POST[$this->getPostVar()]);
291 
292  if ($this->getRequired() && !trim(implode("", $_POST[$this->getPostVar()])))
293  {
294  $this->setAlert($lng->txt("msg_input_is_required"));
295 
296  return false;
297  }
298  else if (strlen($this->getValidationRegexp()))
299  {
300  $reg_valid = true;
301  foreach($_POST[$this->getPostVar()] as $value)
302  {
303  if (!preg_match($this->getValidationRegexp(), $value))
304  {
305  $reg_valid = false;
306  break;
307  }
308  }
309  if(!$reg_valid)
310  {
311  $this->setAlert(
312  $this->getValidationFailureMessage() ?
313  $this->getValidationFailureMessage() :
314  $lng->txt('msg_wrong_format')
315  );
316  return false;
317  }
318  }
319  }
320 
321  return $this->checkSubItemsInput();
322  }
323 
328  function getDataSource()
329  {
330  return $this->ajax_datasource;
331  }
332 
337  function setDataSource($href, $a_delimiter = null)
338  {
339  $this->ajax_datasource = $href;
340  $this->ajax_datasource_delimiter = $a_delimiter;
341  }
342 
343  public function setMultiValues(array $a_values)
344  {
345  foreach($a_values as $idx => $value)
346  {
347  $a_values[$idx] = trim($value);
348  if($a_values[$idx] == "")
349  {
350  unset($a_values[$idx]);
351  }
352  }
353  parent::setMultiValues($a_values);
354  }
355 
359  public function render($a_mode = "")
360  {
361  $tpl = new ilTemplate("tpl.prop_textinput.html", true, true, "Services/Form");
362  if (strlen($this->getValue()))
363  {
364  $tpl->setCurrentBlock("prop_text_propval");
365  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
366  $tpl->parseCurrentBlock();
367  }
368  if (strlen($this->getInlineStyle()))
369  {
370  $tpl->setCurrentBlock("stylecss");
371  $tpl->setVariable("CSS_STYLE", ilUtil::prepareFormOutput($this->getInlineStyle()));
372  $tpl->parseCurrentBlock();
373  }
374  if(strlen($this->getCssClass()))
375  {
376  $tpl->setCurrentBlock("classcss");
377  $tpl->setVariable('CLASS_CSS', ilUtil::prepareFormOutput($this->getCssClass()));
378  $tpl->parseCurrentBlock();
379  }
380  if ($this->getSubmitFormOnEnter())
381  {
382  $tpl->touchBlock("submit_form_on_enter");
383  }
384 
385  switch($this->getInputType())
386  {
387  case 'password':
388  $tpl->setVariable('PROP_INPUT_TYPE','password');
389  break;
390  case 'hidden':
391  $tpl->setVariable('PROP_INPUT_TYPE','hidden');
392  break;
393  case 'text':
394  default:
395  $tpl->setVariable('PROP_INPUT_TYPE','text');
396  }
397  $tpl->setVariable("ID", $this->getFieldId());
398  $tpl->setVariable("SIZE", $this->getSize());
399  if($this->getMaxLength() != null)
400  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
401  if (strlen($this->getSuffix())) $tpl->setVariable("INPUT_SUFFIX", $this->getSuffix());
402 
403  $postvar = $this->getPostVar();
404  if($this->getMulti() && substr($postvar, -2) != "[]")
405  {
406  $postvar .= "[]";
407  }
408 
409  if ($this->getDisabled())
410  {
411  if($this->getMulti())
412  {
413  $value = $this->getMultiValues();
414  $hidden = "";
415  if(is_array($value))
416  {
417  foreach($value as $item)
418  {
419  $hidden .= $this->getHiddenTag($postvar, $item);
420  }
421  }
422  }
423  else
424  {
425  $hidden = $this->getHiddenTag($postvar, $this->getValue());
426  }
427  if($hidden)
428  {
429  $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
430  $tpl->setVariable("HIDDEN_INPUT", $hidden);
431  }
432  }
433  else
434  {
435  $tpl->setVariable("POST_VAR", $postvar);
436  }
437 
438  // use autocomplete feature?
439  if ($this->getDataSource())
440  {
441  include_once "Services/jQuery/classes/class.iljQueryUtil.php";
444 
445  if ($this->getMulti())
446  {
447  $tpl->setCurrentBlock("ac_multi");
448  $tpl->setVariable('MURL_AUTOCOMPLETE', $this->getDataSource());
449  $tpl->setVariable('ID_AUTOCOMPLETE', $this->getFieldId());
450  $tpl->parseCurrentBlock();
451 
452  // set to fields that start with autocomplete selector
453  $sel_auto = '[id^="'.$this->getFieldId().'"]';
454  }
455  else
456  {
457  // use id for autocomplete selector
458  $sel_auto = "#".$this->getFieldId();
459  }
460 
461  if(!$this->ajax_datasource_delimiter)
462  {
463  $tpl->setCurrentBlock("autocomplete_bl");
464  $tpl->setVariable('SEL_AUTOCOMPLETE', $sel_auto);
465  $tpl->setVariable('URL_AUTOCOMPLETE', $this->getDataSource());
466  $tpl->parseCurrentBlock();
467  }
468  else
469  {
470  $tpl->setCurrentBlock("autocomplete_bl");
471  $tpl->setVariable('AUTOCOMPLETE_DELIMITER', $this->ajax_datasource_delimiter);
472  $tpl->setVariable('SEL_AUTOCOMPLETE_DELIMITER', $sel_auto);
473  $tpl->setVariable('URL_AUTOCOMPLETE_DELIMITER', $this->getDataSource());
474  $tpl->parseCurrentBlock();
475  }
476  }
477 
478  if ($a_mode == "toolbar")
479  {
480  // block-inline hack, see: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
481  // -moz-inline-stack for FF2
482  // zoom 1; *display:inline for IE6 & 7
483  $tpl->setVariable("STYLE_PAR", 'display: -moz-inline-stack; display:inline-block; zoom: 1; *display:inline;');
484  }
485  else
486  {
487  $tpl->setVariable("STYLE_PAR", '');
488  }
489 
490  if($this->isHtmlAutoCompleteDisabled())
491  {
492  $tpl->setVariable("AUTOCOMPLETE", "autocomplete=\"off\"");
493  }
494 
495  // multi icons
496  if($this->getMulti() && !$a_mode && !$this->getDisabled())
497  {
498  $tpl->setVariable("MULTI_ICONS", $this->getMultiIconsHTML());
499  }
500 
501  return $tpl->get();
502  }
503 
509  function insert(&$a_tpl)
510  {
511  $html = $this->render();
512 
513  $a_tpl->setCurrentBlock("prop_generic");
514  $a_tpl->setVariable("PROP_GENERIC", $html);
515  $a_tpl->parseCurrentBlock();
516  }
517 
522  {
523  $html = $this->render();
524  return $html;
525  }
526 
530  function getToolbarHTML()
531  {
532  $html = $this->render("toolbar");
533  return $html;
534  }
535 
539  public function setDisableHtmlAutoComplete($autocomplete)
540  {
541  $this->autocomplete_disabled = $autocomplete;
542  }
543 
547  public function isHtmlAutoCompleteDisabled()
548  {
550  }
551 }
552 ?>