ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTestPasswordProtectionGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
14 {
15  const CMD_SHOW_PASSWORD_FORM = 'showPasswordForm';
16  const CMD_SAVE_ENTERED_PASSWORD = 'saveEnteredPassword';
17  const CMD_BACK_TO_INFO_SCREEN = 'backToInfoScreen';
18 
22  protected $ctrl;
23 
27  protected $tpl;
28 
32  protected $lng;
33 
37  protected $parentGUI;
38 
42  protected $passwordChecker;
43 
48 
52  private $nextCommandCmd;
53 
55  {
56  $this->ctrl = $ctrl;
57  $this->tpl = $tpl;
58  $this->lng = $lng;
59  $this->parentGUI = $parentGUI;
60  $this->passwordChecker = $passwordChecker;
61  }
62 
63  public function executeCommand()
64  {
65  $this->ctrl->saveParameter($this, 'nextCommand');
66  $nextCommand = explode('::', $_GET['nextCommand']);
67  $this->setNextCommandClass($nextCommand[0]);
68  $this->setNextCommandCmd($nextCommand[1]);
69 
70  $this->ctrl->saveParameter($this->parentGUI, 'lock');
71 
72  switch ($this->ctrl->getNextClass()) {
73  default:
74 
75  $cmd = $this->ctrl->getCmd() . 'Cmd';
76  $this->$cmd();
77  }
78  }
79 
80  protected function buildPasswordMsg()
81  {
82  if (!$this->passwordChecker->wrongUserEnteredPasswordExist()) {
83  return '';
84  }
85 
86  return $this->tpl->getMessageHTML(
87  $this->lng->txt('tst_password_entered_wrong_password'),
88  'failure'
89  );
90  }
91 
95  protected function buildPasswordForm()
96  {
97  $form = new ilPropertyFormGUI();
98  $form->setTitle($this->lng->txt("tst_password_form"));
99  $form->setDescription($this->lng->txt("tst_password_introduction"));
100 
101  $form->setFormAction($this->ctrl->getFormAction($this));
102  $form->addCommandButton(self::CMD_SAVE_ENTERED_PASSWORD, $this->lng->txt("submit"));
103  $form->addCommandButton(self::CMD_BACK_TO_INFO_SCREEN, $this->lng->txt("cancel"));
104 
105  $inp = new ilPasswordInputGUI($this->lng->txt("tst_password"), 'password');
106  $inp->setRequired(true);
107  $inp->setRetype(false);
108  $form->addItem($inp);
109  return $form;
110  }
111 
112  private function showPasswordFormCmd()
113  {
114  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
115  require_once 'Services/Form/classes/class.ilPasswordInputGUI.php';
116 
117  $msg = $this->buildPasswordMsg();
118  $form = $this->buildPasswordForm();
119 
120  $this->tpl->setVariable(
121  $this->parentGUI->getContentBlockName(),
122  $msg . $this->ctrl->getHTML($form)
123  );
124  }
125 
126  private function saveEnteredPasswordCmd()
127  {
128  $this->passwordChecker->setUserEnteredPassword($_POST["password"]);
129 
130  if (!$this->passwordChecker->isUserEnteredPasswordCorrect()) {
131  $this->passwordChecker->logWrongEnteredPassword();
132  }
133 
134  $this->ctrl->redirectByClass($this->getNextCommandClass(), $this->getNextCommandCmd());
135  }
136 
137  private function backToInfoScreenCmd()
138  {
139  $this->ctrl->redirectByClass('ilObjTestGUI', 'infoScreen');
140  }
141 
143  {
144  $this->nextCommandClass = $nextCommandClass;
145  }
146 
147  private function getNextCommandClass()
148  {
150  }
151 
153  {
154  $this->nextCommandCmd = $nextCommandCmd;
155  }
156 
157  private function getNextCommandCmd()
158  {
159  return $this->nextCommandCmd;
160  }
161 }
This class provides processing control methods.
__construct(ilCtrl $ctrl, ilTemplate $tpl, ilLanguage $lng, ilTestPlayerAbstractGUI $parentGUI, ilTestPasswordChecker $passwordChecker)
This class represents a property form user interface.
$_GET["client_id"]
if(isset($_POST['submit'])) $form
special template class to simplify handling of ITX/PEAR
This class represents a password property in a property form.
language handling
$_POST["username"]
setRequired($a_required)
Set Required.
Output class for assessment test execution.