ILIAS  Release_5_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 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  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
268  {
269  $this->setAlert($lng->txt("msg_input_is_required"));
270 
271  return false;
272  }
273  else if (strlen($this->getValidationRegexp()))
274  {
275  if (!preg_match($this->getValidationRegexp(), $_POST[$this->getPostVar()]))
276  {
277  $this->setAlert(
278  $this->getValidationFailureMessage() ?
279  $this->getValidationFailureMessage() :
280  $lng->txt('msg_wrong_format')
281  );
282  return FALSE;
283  }
284  }
285  }
286  else
287  {
288  foreach($_POST[$this->getPostVar()] as $idx => $value)
289  {
290  $_POST[$this->getPostVar()][$idx] = ilUtil::stripSlashes($value);
291  }
292  $_POST[$this->getPostVar()] = array_unique($_POST[$this->getPostVar()]);
293 
294  if ($this->getRequired() && !trim(implode("", $_POST[$this->getPostVar()])))
295  {
296  $this->setAlert($lng->txt("msg_input_is_required"));
297 
298  return false;
299  }
300  else if (strlen($this->getValidationRegexp()))
301  {
302  $reg_valid = true;
303  foreach($_POST[$this->getPostVar()] as $value)
304  {
305  if (!preg_match($this->getValidationRegexp(), $value))
306  {
307  $reg_valid = false;
308  break;
309  }
310  }
311  if(!$reg_valid)
312  {
313  $this->setAlert(
314  $this->getValidationFailureMessage() ?
315  $this->getValidationFailureMessage() :
316  $lng->txt('msg_wrong_format')
317  );
318  return false;
319  }
320  }
321  }
322 
323  return $this->checkSubItemsInput();
324  }
325 
330  function getDataSource()
331  {
332  return $this->ajax_datasource;
333  }
334 
339  function setDataSource($href, $a_delimiter = null)
340  {
341  $this->ajax_datasource = $href;
342  $this->ajax_datasource_delimiter = $a_delimiter;
343  }
344 
345  public function setDataSourceSubmitOnSelection($a_stat)
346  {
347  $this->ajax_datasource_commit = $a_stat;
348  }
349 
351  {
353  }
354 
355  public function setDataSourceSubmitUrl($a_url)
356  {
357  $this->ajax_datasource_commit_url = $a_url;
358  }
359  public function getDataSourceSubmitUrl()
360  {
362  }
363 
364 
365  public function setMultiValues(array $a_values)
366  {
367  foreach($a_values as $idx => $value)
368  {
369  $a_values[$idx] = trim($value);
370  if($a_values[$idx] == "")
371  {
372  unset($a_values[$idx]);
373  }
374  }
375  parent::setMultiValues($a_values);
376  }
377 
381  public function render($a_mode = "")
382  {
386  global $lng;
387 
388  $tpl = new ilTemplate("tpl.prop_textinput.html", true, true, "Services/Form");
389  if (strlen($this->getValue()))
390  {
391  $tpl->setCurrentBlock("prop_text_propval");
392  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
393  $tpl->parseCurrentBlock();
394  }
395  if (strlen($this->getInlineStyle()))
396  {
397  $tpl->setCurrentBlock("stylecss");
398  $tpl->setVariable("CSS_STYLE", ilUtil::prepareFormOutput($this->getInlineStyle()));
399  $tpl->parseCurrentBlock();
400  }
401  if(strlen($this->getCssClass()))
402  {
403  $tpl->setCurrentBlock("classcss");
404  $tpl->setVariable('CLASS_CSS', ilUtil::prepareFormOutput($this->getCssClass()));
405  $tpl->parseCurrentBlock();
406  }
407  if ($this->getSubmitFormOnEnter())
408  {
409  $tpl->touchBlock("submit_form_on_enter");
410  }
411 
412  switch($this->getInputType())
413  {
414  case 'password':
415  $tpl->setVariable('PROP_INPUT_TYPE','password');
416  break;
417  case 'hidden':
418  $tpl->setVariable('PROP_INPUT_TYPE','hidden');
419  break;
420  case 'text':
421  default:
422  $tpl->setVariable('PROP_INPUT_TYPE','text');
423  }
424  $tpl->setVariable("ID", $this->getFieldId());
425  $tpl->setVariable("SIZE", $this->getSize());
426  if($this->getMaxLength() != null)
427  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
428  if (strlen($this->getSuffix())) $tpl->setVariable("INPUT_SUFFIX", $this->getSuffix());
429 
430  $postvar = $this->getPostVar();
431  if($this->getMulti() && substr($postvar, -2) != "[]")
432  {
433  $postvar .= "[]";
434  }
435 
436  if ($this->getDisabled())
437  {
438  if($this->getMulti())
439  {
440  $value = $this->getMultiValues();
441  $hidden = "";
442  if(is_array($value))
443  {
444  foreach($value as $item)
445  {
446  $hidden .= $this->getHiddenTag($postvar, $item);
447  }
448  }
449  }
450  else
451  {
452  $hidden = $this->getHiddenTag($postvar, $this->getValue());
453  }
454  if($hidden)
455  {
456  $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
457  $tpl->setVariable("HIDDEN_INPUT", $hidden);
458  }
459  }
460  else
461  {
462  $tpl->setVariable("POST_VAR", $postvar);
463  }
464 
465  // use autocomplete feature?
466  if ($this->getDataSource())
467  {
468  include_once "Services/jQuery/classes/class.iljQueryUtil.php";
471 
472  if ($this->getMulti())
473  {
474  $tpl->setCurrentBlock("ac_multi");
475  $tpl->setVariable('MURL_AUTOCOMPLETE', $this->getDataSource());
476  $tpl->setVariable('ID_AUTOCOMPLETE', $this->getFieldId());
477  $tpl->parseCurrentBlock();
478 
479  // set to fields that start with autocomplete selector
480  $sel_auto = '[id^="'.$this->getFieldId().'"]';
481  }
482  else
483  {
484  // use id for autocomplete selector
485  $sel_auto = "#".$this->getFieldId();
486  }
487 
488  $tpl->setCurrentBlock("autocomplete_bl");
489  if(!$this->ajax_datasource_delimiter and !$this->getDataSourceSubmitOnSelection())
490  {
491  $tpl->setVariable('SEL_AUTOCOMPLETE', $sel_auto);
492  $tpl->setVariable('URL_AUTOCOMPLETE', $this->getDataSource());
493  }
494  elseif($this->getDataSourceSubmitOnSelection())
495  {
496  $tpl->setVariable('SEL_AUTOCOMPLETE_AUTOSUBMIT', $sel_auto);
497  $tpl->setVariable('URL_AUTOCOMPLETE_AUTOSUBMIT_REQ', $this->getDataSource());
498  $tpl->setVariable('URL_AUTOCOMPLETE_AUTOSUBMIT_RESP', $this->getDataSourceSubmitUrl());
499  }
500  else
501  {
502  $tpl->setVariable('AUTOCOMPLETE_DELIMITER', $this->ajax_datasource_delimiter);
503  $tpl->setVariable('SEL_AUTOCOMPLETE_DELIMITER', $sel_auto);
504  $tpl->setVariable('URL_AUTOCOMPLETE_DELIMITER', $this->getDataSource());
505  }
506  $tpl->parseCurrentBlock();
507 
508  $tpl->setVariable('MORE_TXT', $lng->txt('autocomplete_more'));
509  }
510 
511  if ($a_mode == "toolbar")
512  {
513  // block-inline hack, see: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
514  // -moz-inline-stack for FF2
515  // zoom 1; *display:inline for IE6 & 7
516  $tpl->setVariable("STYLE_PAR", 'display: -moz-inline-stack; display:inline-block; zoom: 1; *display:inline;');
517  }
518  else
519  {
520  $tpl->setVariable("STYLE_PAR", '');
521  }
522 
523  if($this->isHtmlAutoCompleteDisabled())
524  {
525  $tpl->setVariable("AUTOCOMPLETE", "autocomplete=\"off\"");
526  }
527 
528  // multi icons
529  if($this->getMulti() && !$a_mode && !$this->getDisabled())
530  {
531  $tpl->touchBlock("inline_in_bl");
532  $tpl->setVariable("MULTI_ICONS", $this->getMultiIconsHTML());
533  }
534 
535  return $tpl->get();
536  }
537 
543  function insert(&$a_tpl)
544  {
545  $html = $this->render();
546 
547  $a_tpl->setCurrentBlock("prop_generic");
548  $a_tpl->setVariable("PROP_GENERIC", $html);
549  $a_tpl->parseCurrentBlock();
550  }
551 
556  {
557  $html = $this->render();
558  return $html;
559  }
560 
564  function getToolbarHTML()
565  {
566  $html = $this->render("toolbar");
567  return $html;
568  }
569 
573  public function setDisableHtmlAutoComplete($autocomplete)
574  {
575  $this->autocomplete_disabled = $autocomplete;
576  }
577 
581  public function isHtmlAutoCompleteDisabled()
582  {
584  }
585 }
586 ?>