ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 $max_length = 40;
16  protected $validateauthpost = "";
17  protected $requiredonauth = false;
18  protected $preselection = false;
19  protected $maxlength = false;
20  protected $autocomplete = false;
21 
28  function __construct($a_title = "", $a_postvar = "")
29  {
30  parent::__construct($a_title, $a_postvar);
31  $this->setRetype(true);
32  $this->setSkipSyntaxCheck(false);
33  }
34 
40  function setValue($a_value)
41  {
42  $this->value = $a_value;
43  }
44 
50  function getValue()
51  {
52  return $this->value;
53  }
54 
60  function setRetype($a_val)
61  {
62  $this->retype = $a_val;
63  }
64 
70  function getRetype()
71  {
72  return $this->retype;
73  }
74 
80  function setRetypeValue($a_retypevalue)
81  {
82  $this->retypevalue = $a_retypevalue;
83  }
84 
90  function getRetypeValue()
91  {
92  return $this->retypevalue;
93  }
94 
100  function setMaxLength($a_maxlength)
101  {
102  $this->maxlength = $a_maxlength;
103  }
104 
110  function getMaxLength()
111  {
112  return $this->maxlength;
113  }
114 
120  function setSize($a_size)
121  {
122  $this->size = $a_size;
123  }
124 
130  function setPreSelection($a_val)
131  {
132  $this->preselection = $a_val;
133  }
134 
140  function getPreSelection()
141  {
142  return $this->preselection;
143  }
144 
150  function setValueByArray($a_values)
151  {
152  $this->setValue($a_values[$this->getPostVar()]);
153  $this->setRetypeValue($a_values[$this->getPostVar()."_retype"]);
154  }
155 
161  function getSize()
162  {
163  return $this->size;
164  }
165 
171  function setValidateAuthPost($a_validateauthpost)
172  {
173  $this->validateauthpost = $a_validateauthpost;
174  }
175 
182  {
184  }
185 
191  function setRequiredOnAuth($a_requiredonauth)
192  {
193  $this->requiredonauth = $a_requiredonauth;
194  }
195 
201  function getRequiredOnAuth()
202  {
203  return $this->requiredonauth;
204  }
205 
211  function setSkipSyntaxCheck($a_val)
212  {
213  $this->skip_syntax_check = $a_val;
214  }
215 
222  {
223  return $this->skip_syntax_check;
224  }
225 
231  function setAutoComplete($a_value)
232  {
233  $this->autocomplete = (bool)$a_value;
234  }
235 
241  function getAutoComplete()
242  {
243  return $this->autocomplete;
244  }
245 
251  function checkInput()
252  {
253  global $lng;
254 
255  $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
256  $_POST[$this->getPostVar()."_retype"] = ilUtil::stripSlashes($_POST[$this->getPostVar()."_retype"]);
257  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
258  {
259  $this->setAlert($lng->txt("msg_input_is_required"));
260 
261  return false;
262  }
263  if ($this->getValidateAuthPost() != "")
264  {
266 
267  // check, if password is required dependent on auth mode
269  && trim($_POST[$this->getPostVar()]) == "")
270  {
271  $this->setAlert($lng->txt("form_password_required_for_auth"));
272 
273  return false;
274  }
275 
276  // check, if password is allowed to be set for given auth mode
277  if (trim($_POST[$this->getPostVar()]) != "" &&
279  {
280  $this->setAlert($lng->txt("form_password_not_allowed_for_auth"));
281 
282  return false;
283  }
284  }
285  if ($this->getRetype() && !$this->getPreSelection() &&
286  ($_POST[$this->getPostVar()] != $_POST[$this->getPostVar()."_retype"]))
287  {
288  $this->setAlert($lng->txt("passwd_not_match"));
289 
290  return false;
291  }
292  if (!$this->getSkipSyntaxCheck() &&
293  !ilUtil::isPassword($_POST[$this->getPostVar()],$custom_error) &&
294  $_POST[$this->getPostVar()] != "")
295  {
296  if($custom_error != '') $this->setAlert($custom_error);
297  else $this->setAlert($lng->txt("passwd_invalid"));
298 
299  return false;
300  }
301 
302  return $this->checkSubItemsInput();
303  }
304 
308  function insert(&$a_tpl)
309  {
310  global $lng;
311 
312  $ptpl = new ilTemplate("tpl.prop_password.html", true, true, "Services/Form");
313 
314  if (!$this->getPreSelection())
315  {
316  if ($this->getRetype())
317  {
318  $ptpl->setCurrentBlock("retype");
319  $ptpl->setVariable("RSIZE", $this->getSize());
320  $ptpl->setVariable("RID", $this->getFieldId());
321  $ptpl->setVariable("RMAXLENGTH", $this->getMaxLength());
322  $ptpl->setVariable("RPOST_VAR", $this->getPostVar());
323 
324  if(!$this->getAutoComplete())
325  {
326  $ptpl->setVariable("RAUTOCOMPLETE", "autocomplete=\"off\"");
327  }
328 
329  // this is creating an "auto entry" in the setup, if the retype is missing
330  /*$retype_value = ($this->getRetypeValue() != "")
331  ? $this->getRetypeValue()
332  : $this->getValue();*/
333  $retype_value = $this->getRetypeValue();
334  $ptpl->setVariable("PROPERTY_RETYPE_VALUE", ilUtil::prepareFormOutput($retype_value));
335  if ($this->getDisabled())
336  {
337  $ptpl->setVariable("RDISABLED",
338  " disabled=\"disabled\"");
339  }
340  $ptpl->setVariable("TXT_RETYPE", $lng->txt("form_retype_password"));
341  $ptpl->parseCurrentBlock();
342  }
343 
344  if (strlen($this->getValue()))
345  {
346  $ptpl->setCurrentBlock("prop_password_propval");
347  $ptpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
348  $ptpl->parseCurrentBlock();
349  }
350  $ptpl->setVariable("POST_VAR", $this->getPostVar());
351  $ptpl->setVariable("ID", $this->getFieldId());
352  $ptpl->setVariable("SIZE", $this->getSize());
353  $ptpl->setVariable("MAXLENGTH", $this->getMaxLength());
354  if ($this->getDisabled())
355  {
356  $ptpl->setVariable("DISABLED",
357  " disabled=\"disabled\"");
358  }
359  if(!$this->getAutoComplete())
360  {
361  $ptpl->setVariable("AUTOCOMPLETE", "autocomplete=\"off\"");
362  }
363  }
364  else
365  {
366  // preselection
367  $passwd_list = ilUtil::generatePasswords(5);
368  foreach ($passwd_list as $passwd)
369  {
370  $i++;
371  $ptpl->setCurrentBlock("select_input");
372  $ptpl->setVariable("POST_VAR", $this->getPostVar());
373  $ptpl->setVariable("OP_ID", $this->getPostVar()."_".$i);
374  $ptpl->setVariable("VAL_RADIO_OPTION", $passwd);
375  $ptpl->setVariable("TXT_RADIO_OPTION", $passwd);
376  $ptpl->parseCurrentBlock();
377  }
378 
379  }
380  $a_tpl->setCurrentBlock("prop_generic");
381  $a_tpl->setVariable("PROP_GENERIC" ,$ptpl->get());
382  $a_tpl->parseCurrentBlock();
383  }
384 
385 
386 }
387 ?>