ILIAS  eassessment Revision 61809
 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 
27  function __construct($a_title = "", $a_postvar = "")
28  {
29  parent::__construct($a_title, $a_postvar);
30  $this->setRetype(true);
31  $this->setSkipSyntaxCheck(false);
32  }
33 
39  function setValue($a_value)
40  {
41  $this->value = $a_value;
42  }
43 
49  function getValue()
50  {
51  return $this->value;
52  }
53 
59  function setRetype($a_val)
60  {
61  $this->retype = $a_val;
62  }
63 
69  function getRetype()
70  {
71  return $this->retype;
72  }
73 
79  function setRetypeValue($a_retypevalue)
80  {
81  $this->retypevalue = $a_retypevalue;
82  }
83 
89  function getRetypeValue()
90  {
91  return $this->retypevalue;
92  }
93 
99  function setMaxLength($a_maxlength)
100  {
101  $this->maxlength = $a_maxlength;
102  }
103 
109  function getMaxLength()
110  {
111  return $this->maxlength;
112  }
113 
119  function setSize($a_size)
120  {
121  $this->size = $a_size;
122  }
123 
129  function setPreSelection($a_val)
130  {
131  $this->preselection = $a_val;
132  }
133 
139  function getPreSelection()
140  {
141  return $this->preselection;
142  }
143 
149  function setValueByArray($a_values)
150  {
151  $this->setValue($a_values[$this->getPostVar()]);
152  $this->setRetypeValue($a_values[$this->getPostVar()."_retype"]);
153  }
154 
160  function getSize()
161  {
162  return $this->size;
163  }
164 
170  function setValidateAuthPost($a_validateauthpost)
171  {
172  $this->validateauthpost = $a_validateauthpost;
173  }
174 
181  {
183  }
184 
190  function setRequiredOnAuth($a_requiredonauth)
191  {
192  $this->requiredonauth = $a_requiredonauth;
193  }
194 
200  function getRequiredOnAuth()
201  {
202  return $this->requiredonauth;
203  }
204 
210  function setSkipSyntaxCheck($a_val)
211  {
212  $this->skip_syntax_check = $a_val;
213  }
214 
221  {
222  return $this->skip_syntax_check;
223  }
224 
230  function checkInput()
231  {
232  global $lng;
233 
234  $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
235  $_POST[$this->getPostVar()."_retype"] = ilUtil::stripSlashes($_POST[$this->getPostVar()."_retype"]);
236  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
237  {
238  $this->setAlert($lng->txt("msg_input_is_required"));
239 
240  return false;
241  }
242  if ($this->getValidateAuthPost() != "")
243  {
245 
246  // check, if password is required dependent on auth mode
248  && trim($_POST[$this->getPostVar()]) == "")
249  {
250  $this->setAlert($lng->txt("form_password_required_for_auth"));
251 
252  return false;
253  }
254 
255  // check, if password is allowed to be set for given auth mode
256  if (trim($_POST[$this->getPostVar()]) != "" &&
258  {
259  $this->setAlert($lng->txt("form_password_not_allowed_for_auth"));
260 
261  return false;
262  }
263  }
264  if ($this->getRetype() && !$this->getPreSelection() &&
265  ($_POST[$this->getPostVar()] != $_POST[$this->getPostVar()."_retype"]))
266  {
267  $this->setAlert($lng->txt("passwd_not_match"));
268 
269  return false;
270  }
271  if (!$this->getSkipSyntaxCheck() &&
272  !ilUtil::isPassword($_POST[$this->getPostVar()],$custom_error) &&
273  $_POST[$this->getPostVar()] != "")
274  {
275  if($custom_error != '') $this->setAlert($custom_error);
276  else $this->setAlert($lng->txt("passwd_invalid"));
277 
278  return false;
279  }
280 
281  return $this->checkSubItemsInput();
282  }
283 
287  function insert(&$a_tpl)
288  {
289  global $lng;
290 
291  $ptpl = new ilTemplate("tpl.prop_password.html", true, true, "Services/Form");
292 
293  if (!$this->getPreSelection())
294  {
295  if ($this->getRetype())
296  {
297  $ptpl->setCurrentBlock("retype");
298  $ptpl->setVariable("RSIZE", $this->getSize());
299  $ptpl->setVariable("RID", $this->getFieldId());
300  $ptpl->setVariable("RMAXLENGTH", $this->getMaxLength());
301  $ptpl->setVariable("RPOST_VAR", $this->getPostVar());
302 
303  // this is creating an "auto entry" in the setup, if the retype is missing
304  /*$retype_value = ($this->getRetypeValue() != "")
305  ? $this->getRetypeValue()
306  : $this->getValue();*/
307  $retype_value = $this->getRetypeValue();
308  $ptpl->setVariable("PROPERTY_RETYPE_VALUE", ilUtil::prepareFormOutput($retype_value));
309  if ($this->getDisabled())
310  {
311  $ptpl->setVariable("RDISABLED",
312  " disabled=\"disabled\"");
313  }
314  $ptpl->setVariable("TXT_RETYPE", $lng->txt("form_retype_password"));
315  $ptpl->parseCurrentBlock();
316  }
317 
318  if (strlen($this->getValue()))
319  {
320  $ptpl->setCurrentBlock("prop_password_propval");
321  $ptpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
322  $ptpl->parseCurrentBlock();
323  }
324  $ptpl->setVariable("POST_VAR", $this->getPostVar());
325  $ptpl->setVariable("ID", $this->getFieldId());
326  $ptpl->setVariable("SIZE", $this->getSize());
327  $ptpl->setVariable("MAXLENGTH", $this->getMaxLength());
328  if ($this->getDisabled())
329  {
330  $ptpl->setVariable("DISABLED",
331  " disabled=\"disabled\"");
332  }
333  }
334  else
335  {
336  // preselection
337  $passwd_list = ilUtil::generatePasswords(5);
338  foreach ($passwd_list as $passwd)
339  {
340  $i++;
341  $ptpl->setCurrentBlock("select_input");
342  $ptpl->setVariable("POST_VAR", $this->getPostVar());
343  $ptpl->setVariable("OP_ID", $this->getPostVar()."_".$i);
344  $ptpl->setVariable("VAL_RADIO_OPTION", $passwd);
345  $ptpl->setVariable("TXT_RADIO_OPTION", $passwd);
346  $ptpl->parseCurrentBlock();
347  }
348 
349  }
350  $a_tpl->setCurrentBlock("prop_generic");
351  $a_tpl->setVariable("PROP_GENERIC" ,$ptpl->get());
352  $a_tpl->parseCurrentBlock();
353  }
354 
355 
356 }
357 ?>