ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilChatroomAuthInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
12  const NAME_AUTH_PROP_1 = 'key';
13  const NAME_AUTH_PROP_2 = 'secret';
14 
18  protected $ctrl_path = array();
19 
23  protected $size = 10;
27  protected $values = array(
28  self::NAME_AUTH_PROP_1 => '',
29  self::NAME_AUTH_PROP_2 => ''
30  );
31 
33  protected $isReadOnly = false;
34 
38  public function setIsReadOnly(bool $isReadOnly) : void
39  {
40  $this->isReadOnly = $isReadOnly;
41  }
42 
46  protected function getRandomValues()
47  {
48  $response = new stdClass();
49 
50  $response->{self::NAME_AUTH_PROP_1} = $this->uuidV4();
51  $response->{self::NAME_AUTH_PROP_2} = $this->uuidV4();
52 
53  echo json_encode($response);
54  exit();
55  }
56 
61  private function uuidV4()
62  {
63  return sprintf(
64  '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
65  // 32 bits for "time_low"
66  mt_rand(0, 0xffff),
67  mt_rand(0, 0xffff),
68  // 16 bits for "time_mid"
69  mt_rand(0, 0xffff),
70  // 16 bits for "time_high_and_version",
71  // four most significant bits holds version number 4
72  mt_rand(0, 0x0fff) | 0x4000,
73  // 16 bits, 8 bits for "clk_seq_hi_res",
74  // 8 bits for "clk_seq_low",
75  // two most significant bits holds zero and one for variant DCE1.1
76  mt_rand(0, 0x3fff) | 0x8000,
77  // 48 bits for "node"
78  mt_rand(0, 0xffff),
79  mt_rand(0, 0xffff),
80  mt_rand(0, 0xffff)
81  );
82  }
83 
87  public function setCtrlPath($ctrl_path)
88  {
89  $this->ctrl_path = $ctrl_path;
90  }
91 
95  public function setValueByArray(array $a_values)
96  {
97  $this->values = array(
98  self::NAME_AUTH_PROP_1 => $a_values[$this->getPostVar()][self::NAME_AUTH_PROP_1],
99  self::NAME_AUTH_PROP_2 => $a_values[$this->getPostVar()][self::NAME_AUTH_PROP_2]
100  );
101 
102  foreach ($this->getSubItems() as $item) {
103  $item->setValueByArray($a_values);
104  }
105  }
106 
110  public function checkInput()
111  {
112  global $DIC;
113 
114  $_POST[$this->getPostVar()][self::NAME_AUTH_PROP_1] = ilUtil::stripSlashes($_POST[$this->getPostVar()][self::NAME_AUTH_PROP_1]);
115  $_POST[$this->getPostVar()][self::NAME_AUTH_PROP_2] = ilUtil::stripSlashes($_POST[$this->getPostVar()][self::NAME_AUTH_PROP_2]);
116 
117  $post = $_POST[$this->getPostVar()];
118 
119  if ($this->getRequired() && 2 > count(array_filter(array_map('trim', $post)))) {
120  $this->setAlert($DIC->language()->txt('msg_input_is_required'));
121  return false;
122  }
123 
124  return $this->checkSubItemsInput();
125  }
126 
130  public function insert(ilTemplate $a_tpl)
131  {
132  $a_tpl->setCurrentBlock('prop_generic');
133  $a_tpl->setVariable('PROP_GENERIC', $this->render());
134  $a_tpl->parseCurrentBlock();
135  }
136 
140  public function render()
141  {
142  global $DIC;
143 
144  $tpl = new ilTemplate('tpl.chatroom_auth_input.html', true, true, 'Modules/Chatroom');
145 
146  for ($i = 1; $i <= count($this->values); $i++) {
147  $const = 'NAME_AUTH_PROP_' . $i;
148  $const_val = constant('self::' . $const);
149 
150  $tpl->setVariable('TXT_AUTH_PROP_' . $i, $DIC->language()->txt('chatroom_auth_' . $const_val));
151  $tpl->setVariable('ID_AUTH_PROP_' . $i, $const_val);
152  $tpl->setVariable('NAME_AUTH_PROP_' . $i, $const_val);
153  $tpl->setVariable('VALUE_AUTH_PROP_' . $i, $this->values[$const_val]);
154  }
155 
156  if (!$this->isReadOnly && !$this->getDisabled()) {
157  for ($i = 1; $i <= count($this->values); $i++) {
158  $const = 'NAME_AUTH_PROP_' . $i;
159  $const_val = constant('self::' . $const);
160 
161  $tpl->setVariable('ID_AUTH_PROP_' . $i . '_BTN', $const_val);
162  }
163 
164  $DIC->ctrl()->setParameterByClass('ilformpropertydispatchgui', 'postvar', $this->getPostVar());
165  $tpl->setVariable(
166  'URL',
167  $DIC->ctrl()->getLinkTargetByClass($this->ctrl_path, 'getRandomValues', '', true, false)
168  );
169  $tpl->setVariable('ID_BTN', $this->getFieldId() . '_btn');
170  $tpl->setVariable('TXT_BTN', $DIC->language()->txt('chatroom_auth_btn_txt'));
171  }
172 
173  $tpl->setVariable('POST_VAR', $this->getPostVar());
174  $tpl->setVariable('SIZE', $this->getSize());
175 
176  if ($this->getDisabled()) {
177  $tpl->setVariable('DISABLED', ' disabled="disabled"');
178  }
179 
180  return $tpl->get();
181  }
182 
186  public function getSize()
187  {
188  return $this->size;
189  }
190 
194  public function setSize($size)
195  {
196  $this->size = $size;
197  }
198 }
exit
Definition: login.php:29
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:615
getFieldId()
Get Post Variable.
global $DIC
Definition: goto.php:24
Class ilChatroomAuthInputGUI.
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.
uuidV4()
Generates a pseudo random string following the RFC 4122.
This class represents a property that may include a sub form.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$response
$_POST["username"]
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt public...
$i
Definition: metadata.php:24