ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilPasswordInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  protected $value;
14  protected $size = 20;
15  protected $validateauthpost = "";
16  protected $requiredonauth = false;
17  protected $preselection = false;
18  protected $maxlength = false;
19 
23  protected $autocomplete_disabled = true;
24 
31  function __construct($a_title = "", $a_postvar = "")
32  {
33  parent::__construct($a_title, $a_postvar);
34  $this->setRetype(true);
35  $this->setSkipSyntaxCheck(false);
36  }
37 
43  function setValue($a_value)
44  {
45  $this->value = $a_value;
46  }
47 
53  function getValue()
54  {
55  return $this->value;
56  }
57 
63  function setRetype($a_val)
64  {
65  $this->retype = $a_val;
66  }
67 
73  function getRetype()
74  {
75  return $this->retype;
76  }
77 
83  function setRetypeValue($a_retypevalue)
84  {
85  $this->retypevalue = $a_retypevalue;
86  }
87 
93  function getRetypeValue()
94  {
95  return $this->retypevalue;
96  }
97 
103  function setMaxLength($a_maxlength)
104  {
105  $this->maxlength = $a_maxlength;
106  }
107 
113  function getMaxLength()
114  {
115  return $this->maxlength;
116  }
117 
123  function setSize($a_size)
124  {
125  $this->size = $a_size;
126  }
127 
133  function setPreSelection($a_val)
134  {
135  $this->preselection = $a_val;
136  }
137 
143  function getPreSelection()
144  {
145  return $this->preselection;
146  }
147 
153  function setValueByArray($a_values)
154  {
155  $this->setValue($a_values[$this->getPostVar()]);
156  $this->setRetypeValue($a_values[$this->getPostVar()."_retype"]);
157  }
158 
164  function getSize()
165  {
166  return $this->size;
167  }
168 
174  function setValidateAuthPost($a_validateauthpost)
175  {
176  $this->validateauthpost = $a_validateauthpost;
177  }
178 
185  {
187  }
188 
194  function setRequiredOnAuth($a_requiredonauth)
195  {
196  $this->requiredonauth = $a_requiredonauth;
197  }
198 
204  function getRequiredOnAuth()
205  {
206  return $this->requiredonauth;
207  }
208 
214  function setSkipSyntaxCheck($a_val)
215  {
216  $this->skip_syntax_check = $a_val;
217  }
218 
225  {
226  return $this->skip_syntax_check;
227  }
228 
234  function setDisableHtmlAutoComplete($a_value)
235  {
236  $this->autocomplete_disabled = (bool)$a_value;
237  }
238 
245  {
247  }
248 
254  function checkInput()
255  {
256  global $lng;
257 
258  $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
259  $_POST[$this->getPostVar()."_retype"] = ilUtil::stripSlashes($_POST[$this->getPostVar()."_retype"]);
260  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
261  {
262  $this->setAlert($lng->txt("msg_input_is_required"));
263 
264  return false;
265  }
266  if ($this->getValidateAuthPost() != "")
267  {
269 
270  // check, if password is required dependent on auth mode
272  && trim($_POST[$this->getPostVar()]) == "")
273  {
274  $this->setAlert($lng->txt("form_password_required_for_auth"));
275 
276  return false;
277  }
278 
279  // check, if password is allowed to be set for given auth mode
280  if (trim($_POST[$this->getPostVar()]) != "" &&
282  {
283  $this->setAlert($lng->txt("form_password_not_allowed_for_auth"));
284 
285  return false;
286  }
287  }
288  if ($this->getRetype() && !$this->getPreSelection() &&
289  ($_POST[$this->getPostVar()] != $_POST[$this->getPostVar()."_retype"]))
290  {
291  $this->setAlert($lng->txt("passwd_not_match"));
292 
293  return false;
294  }
295  if (!$this->getSkipSyntaxCheck() &&
296  !ilUtil::isPassword($_POST[$this->getPostVar()],$custom_error) &&
297  $_POST[$this->getPostVar()] != "")
298  {
299  if($custom_error != '') $this->setAlert($custom_error);
300  else $this->setAlert($lng->txt("passwd_invalid"));
301 
302  return false;
303  }
304 
305  return $this->checkSubItemsInput();
306  }
307 
311  function render()
312  {
313  global $lng;
314 
315  $ptpl = new ilTemplate("tpl.prop_password.html", true, true, "Services/Form");
316 
317  if (!$this->getPreSelection())
318  {
319  if ($this->getRetype())
320  {
321  $ptpl->setCurrentBlock("retype");
322  $ptpl->setVariable("RSIZE", $this->getSize());
323  $ptpl->setVariable("RID", $this->getFieldId());
324  $ptpl->setVariable("RMAXLENGTH", $this->getMaxLength());
325  $ptpl->setVariable("RPOST_VAR", $this->getPostVar());
326 
327  if($this->isHtmlAutoCompleteDisabled())
328  {
329  $ptpl->setVariable("RAUTOCOMPLETE", "autocomplete=\"off\"");
330  }
331 
332  // this is creating an "auto entry" in the setup, if the retype is missing
333  /*$retype_value = ($this->getRetypeValue() != "")
334  ? $this->getRetypeValue()
335  : $this->getValue();*/
336  $retype_value = $this->getRetypeValue();
337  $ptpl->setVariable("PROPERTY_RETYPE_VALUE", ilUtil::prepareFormOutput($retype_value));
338  if ($this->getDisabled())
339  {
340  $ptpl->setVariable("RDISABLED",
341  " disabled=\"disabled\"");
342  }
343  $ptpl->setVariable("TXT_RETYPE", $lng->txt("form_retype_password"));
344  $ptpl->parseCurrentBlock();
345  }
346 
347  if (strlen($this->getValue()))
348  {
349  $ptpl->setCurrentBlock("prop_password_propval");
350  $ptpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
351  $ptpl->parseCurrentBlock();
352  }
353  $ptpl->setVariable("POST_VAR", $this->getPostVar());
354  $ptpl->setVariable("ID", $this->getFieldId());
355  $ptpl->setVariable("SIZE", $this->getSize());
356  $ptpl->setVariable("MAXLENGTH", $this->getMaxLength());
357  if ($this->getDisabled())
358  {
359  $ptpl->setVariable("DISABLED",
360  " disabled=\"disabled\"");
361  }
362  if($this->isHtmlAutoCompleteDisabled())
363  {
364  $ptpl->setVariable("AUTOCOMPLETE", "autocomplete=\"off\"");
365  }
366  }
367  else
368  {
369  // preselection
370  $passwd_list = ilUtil::generatePasswords(5);
371  foreach ($passwd_list as $passwd)
372  {
373  $i++;
374  $ptpl->setCurrentBlock("select_input");
375  $ptpl->setVariable("POST_VAR", $this->getPostVar());
376  $ptpl->setVariable("OP_ID", $this->getPostVar()."_".$i);
377  $ptpl->setVariable("VAL_RADIO_OPTION", $passwd);
378  $ptpl->setVariable("TXT_RADIO_OPTION", $passwd);
379  $ptpl->parseCurrentBlock();
380  }
381 
382  }
383  return $ptpl->get();
384  }
385 
391  function insert(&$a_tpl)
392  {
393  $html = $this->render();
394 
395  $a_tpl->setCurrentBlock("prop_generic");
396  $a_tpl->setVariable("PROP_GENERIC", $html);
397  $a_tpl->parseCurrentBlock();
398  }
399 }
400 ?>
getMaxLength()
Get Max Length.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
$_POST['username']
Definition: cron.php:12
setValidateAuthPost($a_validateauthpost)
Set Validate required status against authentication POST var.
getPostVar()
Get Post Variable.
getSkipSyntaxCheck()
Get skip syntax check.
getRetypeValue()
Get Retype Value.
static generatePasswords($a_number)
Generate a number of passwords.
getRetype()
Get retype on/off.
static isPassword($a_passwd, &$customError=null)
validates a password public
setRetype($a_val)
Set retype on/off.
setDisableHtmlAutoComplete($a_value)
Set autocomplete.
setValueByArray($a_values)
Set value by array.
setAlert($a_alert)
Set Alert Text.
static _allowPasswordModificationByAuthMode($a_auth_mode)
Allow password modification.
setRetypeValue($a_retypevalue)
Set Retype Value.
setRequiredOnAuth($a_requiredonauth)
Set input required, if authentication mode allows password setting.
getValidateAuthPost()
Get Validate required status against authentication POST var.
isHtmlAutoCompleteDisabled()
Get autocomplete.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
setSkipSyntaxCheck($a_val)
Set skip syntax check.
This class represents a password property in a property form.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
_getAuthMode($a_auth_mode, $a_db_handler='')
setValue($a_value)
Set Value.
setPreSelection($a_val)
Set preselection.
checkInput()
Check input, strip slashes etc.
This class represents a property that may include a sub form.
global $lng
Definition: privfeed.php:40
setMaxLength($a_maxlength)
Set Max Length.
getRequiredOnAuth()
Get input required, if authentication mode allows password setting.
getPreSelection()
Get preselection.
insert(&$a_tpl)
Insert property html.
$html
Definition: example_001.php:87
__construct($a_title="", $a_postvar="")
Constructor.