ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilEMailInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
31 {
35  protected $lng;
36 
37  protected $value;
38  protected $size = 30;
39  protected $max_length = 80;
40  protected $allowRFC822 = false; // [bool]
41 
45  protected $retype = false;
46 
50  protected $retypevalue = '';
51 
57  public function __construct($a_title = "", $a_postvar = "")
58  {
59  global $DIC;
60 
61  $this->lng = $DIC->language();
62  parent::__construct($a_title, $a_postvar);
63  $this->setRetype(false);
64  }
65 
70  public function setValue($a_value)
71  {
72  $this->value = $a_value;
73  }
74 
79  public function getValue()
80  {
81  return $this->value;
82  }
83 
88  public function setValueByArray($a_values)
89  {
90  $this->setValue($a_values[$this->getPostVar()]);
91  $this->setRetypeValue($a_values[$this->getPostVar() . '_retype']);
92  }
93 
101  public function allowRFC822($a_value)
102  {
103  $this->allowRFC822 = (bool) $a_value;
104  }
105 
110  public function checkInput()
111  {
112  $lng = $this->lng;
113 
114  $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()], !(bool) $this->allowRFC822);
115  $_POST[$this->getPostVar() . '_retype'] = ilUtil::stripSlashes($_POST[$this->getPostVar() . '_retype'], !(bool) $this->allowRFC822);
116  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "") {
117  $this->setAlert($lng->txt("msg_input_is_required"));
118 
119  return false;
120  }
121  if ($this->getRetype() && ($_POST[$this->getPostVar()] != $_POST[$this->getPostVar() . '_retype'])) {
122  $this->setAlert($lng->txt('email_not_match'));
123 
124  return false;
125  }
126  if (!ilUtil::is_email($_POST[$this->getPostVar()]) &&
127  trim($_POST[$this->getPostVar()]) != ""
128  ) {
129  $this->setAlert($lng->txt("email_not_valid"));
130 
131  return false;
132  }
133 
134 
135  return true;
136  }
137 
141  public function insert(ilTemplate $a_tpl)
142  {
143  $lng = $this->lng;
144 
145  $ptpl = new ilTemplate('tpl.prop_email.html', true, true, 'Services/Form');
146 
147  if ($this->getRetype()) {
148  $ptpl->setCurrentBlock('retype_email');
149  $ptpl->setVariable('RSIZE', $this->getSize());
150  $ptpl->setVariable('RID', $this->getFieldId());
151  $ptpl->setVariable('RMAXLENGTH', $this->getMaxLength());
152  $ptpl->setVariable('RPOST_VAR', $this->getPostVar());
153 
154  $retype_value = $this->getRetypeValue();
155  $ptpl->setVariable('PROPERTY_RETYPE_VALUE', ilUtil::prepareFormOutput($retype_value));
156  if ($this->getDisabled()) {
157  $ptpl->setVariable('RDISABLED', ' disabled="disabled"');
158  }
159  $ptpl->setVariable('TXT_RETYPE', $lng->txt('form_retype_email'));
160  $ptpl->parseCurrentBlock();
161  }
162 
163  $ptpl->setVariable('POST_VAR', $this->getPostVar());
164  $ptpl->setVariable('ID', $this->getFieldId());
165  $ptpl->setVariable('PROPERTY_VALUE', ilUtil::prepareFormOutput($this->getValue()));
166  $ptpl->setVariable('SIZE', $this->getSize());
167  $ptpl->setVariable('MAXLENGTH', $this->getMaxLength());
168  if ($this->getDisabled()) {
169  $ptpl->setVariable('DISABLED', ' disabled="disabled"');
170  $ptpl->setVariable('HIDDEN_INPUT', $this->getHiddenTag($this->getPostVar(), $this->getValue()));
171  }
172 
173  if ($this->getRequired()) {
174  $ptpl->setVariable("REQUIRED", "required=\"required\"");
175  }
176 
177  $a_tpl->setCurrentBlock('prop_generic');
178  $a_tpl->setVariable('PROP_GENERIC', $ptpl->get());
179  $a_tpl->parseCurrentBlock();
180  }
181 
185  public function setRetype($a_val)
186  {
187  $this->retype = $a_val;
188  }
189 
193  public function getRetype()
194  {
195  return $this->retype;
196  }
197 
201  public function setRetypeValue($a_retypevalue)
202  {
203  $this->retypevalue = $a_retypevalue;
204  }
205 
209  public function getRetypeValue()
210  {
211  return $this->retypevalue;
212  }
213 
217  public function setSize($size)
218  {
219  $this->size = $size;
220  }
221 
225  public function getSize()
226  {
227  return $this->size;
228  }
229 
233  public function setMaxLength($max_length)
234  {
235  $this->max_length = $max_length;
236  }
237 
241  public function getMaxLength()
242  {
243  return $this->max_length;
244  }
245 }
setValue($a_value)
Set Value.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getHiddenTag($a_post_var, $a_value)
Get hidden tag (used for disabled properties)
global $DIC
Definition: saml.php:7
static is_email($a_email, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
This preg-based function checks whether an e-mail address is formally valid.
insert(ilTemplate $a_tpl)
getPostVar()
Get Post Variable.
This class represents a email property in a property form.
__construct($a_title="", $a_postvar="")
Constructor.
setAlert($a_alert)
Set Alert Text.
setRetypeValue($a_retypevalue)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:613
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
setCurrentBlock($part="DEFAULT")
Überladene Funktion, die sich hier lokal noch den aktuellen Block merkt.
setValueByArray($a_values)
Set value by array.
font size
Definition: langcheck.php:162
checkInput()
Check input, strip slashes etc.
This class represents a property in a property form.
allowRFC822($a_value)
Allow extended email address format.
$_POST["username"]
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt public...