ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $ajax_datasource_commit = FALSE;
30  protected $submit_form_on_enter = false;
31 
35  protected $autocomplete_disabled = false;
36 
43  function __construct($a_title = "", $a_postvar = "")
44  {
45  parent::__construct($a_title, $a_postvar);
46  $this->setInputType("text");
47  $this->setType("text");
48  $this->validationRegexp = "";
49  }
50 
56  function setValue($a_value)
57  {
58  if($this->getMulti() && is_array($a_value))
59  {
60  $this->setMultiValues($a_value);
61  $a_value = array_shift($a_value);
62  }
63  $this->value = $a_value;
64  }
65 
71  function getValue()
72  {
73  return $this->value;
74  }
75 
76 
82  public function setValidationFailureMessage($a_msg)
83  {
84  $this->validationFailureMessage = $a_msg;
85  }
86 
87  public function getValidationFailureMessage()
88  {
90  }
91 
97  public function setValidationRegexp($a_value)
98  {
99  $this->validationRegexp = $a_value;
100  }
101 
108  {
110  }
111 
117  function setMaxLength($a_maxlength)
118  {
119  $this->maxlength = $a_maxlength;
120  }
121 
127  function getMaxLength()
128  {
129  return $this->maxlength;
130  }
131 
137  function setSize($a_size)
138  {
139  $this->size = $a_size;
140  }
141 
147  function setInlineStyle($a_style)
148  {
149  $this->style_css = $a_style;
150  }
151 
157  function getInlineStyle()
158  {
159  return $this->style_css;
160  }
161 
162  public function setCssClass($a_class)
163  {
164  $this->css_class = $a_class;
165  }
166 
167  public function getCssClass()
168  {
169  return $this->css_class;
170  }
171 
172 
178  function setValueByArray($a_values)
179  {
180  $this->setValue($a_values[$this->getPostVar()]);
181  }
182 
188  function getSize()
189  {
190  return $this->size;
191  }
192 
198  function setSuffix($a_value)
199  {
200  $this->suffix = $a_value;
201  }
202 
208  function getSuffix()
209  {
210  return $this->suffix;
211  }
212 
220  public function setInputType($a_type)
221  {
222  $this->input_type = $a_type;
223  }
224 
230  public function getInputType()
231  {
232  return $this->input_type;
233  }
234 
240  function setSubmitFormOnEnter($a_val)
241  {
242  $this->submit_form_on_enter = $a_val;
243  }
244 
251  {
253  }
254 
260  function checkInput()
261  {
262  global $lng;
263 
264  if(!$this->getMulti())
265  {
266  //$_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
267  $_POST[$this->getPostVar()] = $this->stripSlashesAddSpaceFallback($_POST[$this->getPostVar()]);
268  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
269  {
270  $this->setAlert($lng->txt("msg_input_is_required"));
271 
272  return false;
273  }
274  else if (strlen($this->getValidationRegexp()))
275  {
276  if (!preg_match($this->getValidationRegexp(), $_POST[$this->getPostVar()]))
277  {
278  $this->setAlert(
279  $this->getValidationFailureMessage() ?
280  $this->getValidationFailureMessage() :
281  $lng->txt('msg_wrong_format')
282  );
283  return FALSE;
284  }
285  }
286  }
287  else
288  {
289  // #17296
290  if(!is_array($_POST[$this->getPostVar()]))
291  {
292  $_POST[$this->getPostVar()] = array();
293  }
294  foreach($_POST[$this->getPostVar()] as $idx => $value)
295  {
296  //$_POST[$this->getPostVar()][$idx] = ilUtil::stripSlashes($value);
297  $_POST[$this->getPostVar()][$idx] = $this->stripSlashesAddSpaceFallback($value);
298  }
299  $_POST[$this->getPostVar()] = array_unique($_POST[$this->getPostVar()]);
300 
301  if ($this->getRequired() && !trim(implode("", $_POST[$this->getPostVar()])))
302  {
303  $this->setAlert($lng->txt("msg_input_is_required"));
304 
305  return false;
306  }
307  else if (strlen($this->getValidationRegexp()))
308  {
309  $reg_valid = true;
310  foreach($_POST[$this->getPostVar()] as $value)
311  {
312  if (!preg_match($this->getValidationRegexp(), $value))
313  {
314  $reg_valid = false;
315  break;
316  }
317  }
318  if(!$reg_valid)
319  {
320  $this->setAlert(
321  $this->getValidationFailureMessage() ?
322  $this->getValidationFailureMessage() :
323  $lng->txt('msg_wrong_format')
324  );
325  return false;
326  }
327  }
328  }
329 
330  return $this->checkSubItemsInput();
331  }
332 
337  function getDataSource()
338  {
339  return $this->ajax_datasource;
340  }
341 
346  function setDataSource($href, $a_delimiter = null)
347  {
348  $this->ajax_datasource = $href;
349  $this->ajax_datasource_delimiter = $a_delimiter;
350  }
351 
352  public function setDataSourceSubmitOnSelection($a_stat)
353  {
354  $this->ajax_datasource_commit = $a_stat;
355  }
356 
358  {
360  }
361 
362  public function setDataSourceSubmitUrl($a_url)
363  {
364  $this->ajax_datasource_commit_url = $a_url;
365  }
366  public function getDataSourceSubmitUrl()
367  {
369  }
370 
371 
372  public function setMultiValues(array $a_values)
373  {
374  foreach($a_values as $idx => $value)
375  {
376  $a_values[$idx] = trim($value);
377  if($a_values[$idx] == "")
378  {
379  unset($a_values[$idx]);
380  }
381  }
382  parent::setMultiValues($a_values);
383  }
384 
388  public function render($a_mode = "")
389  {
393  global $lng;
394 
395  $tpl = new ilTemplate("tpl.prop_textinput.html", true, true, "Services/Form");
396  if (strlen($this->getValue()))
397  {
398  $tpl->setCurrentBlock("prop_text_propval");
399  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
400  $tpl->parseCurrentBlock();
401  }
402  if (strlen($this->getInlineStyle()))
403  {
404  $tpl->setCurrentBlock("stylecss");
405  $tpl->setVariable("CSS_STYLE", ilUtil::prepareFormOutput($this->getInlineStyle()));
406  $tpl->parseCurrentBlock();
407  }
408  if(strlen($this->getCssClass()))
409  {
410  $tpl->setCurrentBlock("classcss");
411  $tpl->setVariable('CLASS_CSS', ilUtil::prepareFormOutput($this->getCssClass()));
412  $tpl->parseCurrentBlock();
413  }
414  if ($this->getSubmitFormOnEnter())
415  {
416  $tpl->touchBlock("submit_form_on_enter");
417  }
418 
419  switch($this->getInputType())
420  {
421  case 'password':
422  $tpl->setVariable('PROP_INPUT_TYPE','password');
423  break;
424  case 'hidden':
425  $tpl->setVariable('PROP_INPUT_TYPE','hidden');
426  break;
427  case 'text':
428  default:
429  $tpl->setVariable('PROP_INPUT_TYPE','text');
430  }
431  $tpl->setVariable("ID", $this->getFieldId());
432  $tpl->setVariable("SIZE", $this->getSize());
433  if($this->getMaxLength() != null)
434  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
435  if (strlen($this->getSuffix())) $tpl->setVariable("INPUT_SUFFIX", $this->getSuffix());
436 
437  $postvar = $this->getPostVar();
438  if($this->getMulti() && substr($postvar, -2) != "[]")
439  {
440  $postvar .= "[]";
441  }
442 
443  if ($this->getDisabled())
444  {
445  if($this->getMulti())
446  {
447  $value = $this->getMultiValues();
448  $hidden = "";
449  if(is_array($value))
450  {
451  foreach($value as $item)
452  {
453  $hidden .= $this->getHiddenTag($postvar, $item);
454  }
455  }
456  }
457  else
458  {
459  $hidden = $this->getHiddenTag($postvar, $this->getValue());
460  }
461  if($hidden)
462  {
463  $tpl->setVariable("HIDDEN_INPUT", $hidden);
464  }
465  $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
466  }
467  else
468  {
469  $tpl->setVariable("POST_VAR", $postvar);
470  }
471 
472  // use autocomplete feature?
473  if ($this->getDataSource())
474  {
475  include_once "Services/jQuery/classes/class.iljQueryUtil.php";
478 
479  if ($this->getMulti())
480  {
481  $tpl->setCurrentBlock("ac_multi");
482  $tpl->setVariable('MURL_AUTOCOMPLETE', $this->getDataSource());
483  $tpl->setVariable('ID_AUTOCOMPLETE', $this->getFieldId());
484  $tpl->parseCurrentBlock();
485 
486  // set to fields that start with autocomplete selector
487  $sel_auto = '[id^="'.$this->getFieldId().'"]';
488  }
489  else
490  {
491  // use id for autocomplete selector
492  $sel_auto = "#".$this->getFieldId();
493  }
494 
495  $tpl->setCurrentBlock("autocomplete_bl");
496  if(!$this->ajax_datasource_delimiter and !$this->getDataSourceSubmitOnSelection())
497  {
498  $tpl->setVariable('SEL_AUTOCOMPLETE', $sel_auto);
499  $tpl->setVariable('URL_AUTOCOMPLETE', $this->getDataSource());
500  }
501  elseif($this->getDataSourceSubmitOnSelection())
502  {
503  $tpl->setVariable('SEL_AUTOCOMPLETE_AUTOSUBMIT', $sel_auto);
504  $tpl->setVariable('URL_AUTOCOMPLETE_AUTOSUBMIT_REQ', $this->getDataSource());
505  $tpl->setVariable('URL_AUTOCOMPLETE_AUTOSUBMIT_RESP', $this->getDataSourceSubmitUrl());
506  }
507  else
508  {
509  $tpl->setVariable('AUTOCOMPLETE_DELIMITER', $this->ajax_datasource_delimiter);
510  $tpl->setVariable('SEL_AUTOCOMPLETE_DELIMITER', $sel_auto);
511  $tpl->setVariable('URL_AUTOCOMPLETE_DELIMITER', $this->getDataSource());
512  }
513  $tpl->parseCurrentBlock();
514 
515  $tpl->setVariable('MORE_TXT', $lng->txt('autocomplete_more'));
516  }
517 
518  if ($a_mode == "toolbar")
519  {
520  // block-inline hack, see: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
521  // -moz-inline-stack for FF2
522  // zoom 1; *display:inline for IE6 & 7
523  $tpl->setVariable("STYLE_PAR", 'display: -moz-inline-stack; display:inline-block; zoom: 1; *display:inline;');
524  }
525  else
526  {
527  $tpl->setVariable("STYLE_PAR", '');
528  }
529 
530  if($this->isHtmlAutoCompleteDisabled())
531  {
532  $tpl->setVariable("AUTOCOMPLETE", "autocomplete=\"off\"");
533  }
534 
535  if($this->getRequired())
536  {
537  $tpl->setVariable("REQUIRED", "required=\"required\"");
538  }
539 
540  // multi icons
541  if($this->getMulti() && !$a_mode && !$this->getDisabled())
542  {
543  $tpl->touchBlock("inline_in_bl");
544  $tpl->setVariable("MULTI_ICONS", $this->getMultiIconsHTML());
545  }
546 
547  return $tpl->get();
548  }
549 
555  function insert($a_tpl)
556  {
557  $html = $this->render();
558 
559  $a_tpl->setCurrentBlock("prop_generic");
560  $a_tpl->setVariable("PROP_GENERIC", $html);
561  $a_tpl->parseCurrentBlock();
562  }
563 
568  {
569  $html = $this->render();
570  return $html;
571  }
572 
576  function getToolbarHTML()
577  {
578  $html = $this->render("toolbar");
579  return $html;
580  }
581 
585  public function setDisableHtmlAutoComplete($autocomplete)
586  {
587  $this->autocomplete_disabled = $autocomplete;
588  }
589 
593  public function isHtmlAutoCompleteDisabled()
594  {
596  }
597 }
598 ?>
setSubmitFormOnEnter($a_val)
Set submit form on enter.
insert($a_tpl)
Insert property html.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getMaxLength()
Get Max Length.
static initjQueryUI()
Init jQuery UI (see included_components.txt for included components)
getHiddenTag($a_post_var, $a_value)
Get hidden tag (used for disabled properties)
Interface for property form input GUI classes that can be used in table filters.
setDataSource($href, $a_delimiter=null)
set datasource link for js autocomplete
setDataSourceSubmitOnSelection($a_stat)
getDataSource()
get datasource link for js autocomplete
getPostVar()
Get Post Variable.
getSuffix()
Get suffix.
getToolbarHTML()
Get HTML for toolbar.
Interface for property form input GUI classes that can be used in ilToolbarGUI.
getMultiIconsHTML()
Get HTML for multiple value icons.
getTableFilterHTML()
Get HTML for table filter.
__construct($a_title="", $a_postvar="")
Constructor.
setAlert($a_alert)
Set Alert Text.
global $tpl
Definition: ilias.php:8
setType($a_type)
Set Type.
$a_type
Definition: workflow.php:93
getMultiValues()
Get multi values.
font size
Definition: langcheck.php:162
getSubmitFormOnEnter()
Get submit form on enter.
setMultiValues(array $a_values)
getValidationRegexp()
Get validation regexp.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
setSize($a_size)
Set Size.
This class represents a text property in a property form.
setDisableHtmlAutoComplete($autocomplete)
setValidationFailureMessage($a_msg)
Set message string for validation failure.
setMaxLength($a_maxlength)
Set Max Length.
Create styles array
The data for the language used.
checkInput()
Check input, strip slashes etc.
Interface for multi values support.
stripSlashesAddSpaceFallback($a_str)
Strip slashes with add space fallback, see https://www.ilias.de/mantis/view.php?id=19727.
setValueByArray($a_values)
Set value by array.
setSuffix($a_value)
Set suffix.
This class represents a property that may include a sub form.
global $lng
Definition: privfeed.php:17
getInputType()
get input type
setInlineStyle($a_style)
Set inline style.
static initjQuery($a_tpl=null)
Init jQuery.
setValidationRegexp($a_value)
Set validation regexp.
setValue($a_value)
Set Value.
setInputType($a_type)
set input type
$_POST["username"]
$html
Definition: example_001.php:87
getInlineStyle()
Get inline style.