ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
35  protected function getRandomValues()
36  {
37  $response = new stdClass();
38 
39  $response->{self::NAME_AUTH_PROP_1} = $this->uuidV4();
40  $response->{self::NAME_AUTH_PROP_2} = $this->uuidV4();
41 
42  echo json_encode($response);
43  exit();
44  }
45 
50  private function uuidV4()
51  {
52  return sprintf(
53  '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
54  // 32 bits for "time_low"
55  mt_rand(0, 0xffff),
56  mt_rand(0, 0xffff),
57  // 16 bits for "time_mid"
58  mt_rand(0, 0xffff),
59  // 16 bits for "time_high_and_version",
60  // four most significant bits holds version number 4
61  mt_rand(0, 0x0fff) | 0x4000,
62  // 16 bits, 8 bits for "clk_seq_hi_res",
63  // 8 bits for "clk_seq_low",
64  // two most significant bits holds zero and one for variant DCE1.1
65  mt_rand(0, 0x3fff) | 0x8000,
66  // 48 bits for "node"
67  mt_rand(0, 0xffff),
68  mt_rand(0, 0xffff),
69  mt_rand(0, 0xffff)
70  );
71  }
72 
76  public function getCtrlPath()
77  {
78  return $this->ctrl_path;
79  }
80 
84  public function setCtrlPath($ctrl_path)
85  {
86  $this->ctrl_path = $ctrl_path;
87  }
88 
92  public function setValueByArray(array $a_values)
93  {
94  $this->values = array(
95  self::NAME_AUTH_PROP_1 => $a_values[$this->getPostVar()][self::NAME_AUTH_PROP_1],
96  self::NAME_AUTH_PROP_2 => $a_values[$this->getPostVar()][self::NAME_AUTH_PROP_2]
97  );
98 
99  foreach ($this->getSubItems() as $item) {
100  $item->setValueByArray($a_values);
101  }
102  }
103 
107  public function checkInput()
108  {
109  global $DIC;
110 
111  $_POST[$this->getPostVar()][self::NAME_AUTH_PROP_1] = ilUtil::stripSlashes($_POST[$this->getPostVar()][self::NAME_AUTH_PROP_1]);
112  $_POST[$this->getPostVar()][self::NAME_AUTH_PROP_2] = ilUtil::stripSlashes($_POST[$this->getPostVar()][self::NAME_AUTH_PROP_2]);
113 
114  $post = $_POST[$this->getPostVar()];
115 
116  if ($this->getRequired() && 2 > count(array_filter(array_map('trim', $post)))) {
117  $this->setAlert($DIC->language()->txt('msg_input_is_required'));
118  return false;
119  }
120 
121  return $this->checkSubItemsInput();
122  }
123 
127  public function insert(ilTemplate $a_tpl)
128  {
129  $a_tpl->setCurrentBlock('prop_generic');
130  $a_tpl->setVariable('PROP_GENERIC', $this->render());
131  $a_tpl->parseCurrentBlock();
132  }
133 
137  public function render()
138  {
139  global $DIC;
140 
141  $tpl = new ilTemplate('tpl.chatroom_auth_input.html', true, true, 'Modules/Chatroom');
142 
143  for ($i = 1; $i <= count($this->values); $i++) {
144  $const = 'NAME_AUTH_PROP_' . $i;
145  $const_val = constant('self::' . $const);
146 
147  $tpl->setVariable('TXT_AUTH_PROP_' . $i, $DIC->language()->txt('chatroom_auth_' . $const_val));
148  $tpl->setVariable('ID_AUTH_PROP_' . $i, $const_val);
149  $tpl->setVariable('NAME_AUTH_PROP_' . $i, $const_val);
150  $tpl->setVariable('VALUE_AUTH_PROP_' . $i, $this->values[$const_val]);
151  }
152 
153  $DIC->ctrl()->setParameterByClass('ilformpropertydispatchgui', 'postvar', $this->getPostVar());
154  $tpl->setVariable('URL', $DIC->ctrl()->getLinkTargetByClass($this->ctrl_path, 'getRandomValues', '', true, false));
155  $tpl->setVariable('ID_BTN', $this->getFieldId() . '_btn');
156  $tpl->setVariable('TXT_BTN', $DIC->language()->txt('chatroom_auth_btn_txt'));
157  $tpl->setVariable('POST_VAR', $this->getPostVar());
158  $tpl->setVariable('SIZE', $this->getSize());
159  if ($this->getDisabled()) {
160  $tpl->setVariable('DISABLED', ' disabled="disabled"');
161  }
162 
163  return $tpl->get();
164  }
165 
169  public function getSize()
170  {
171  return $this->size;
172  }
173 
177  public function setSize($size)
178  {
179  $this->size = $size;
180  }
181 }
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:613
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
$post
Definition: post.php:34
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.
exit
Definition: backend.php:16
font size
Definition: langcheck.php:162
uuidV4()
Generates a pseudo random string following the RFC 4122.
This class represents a property that may include a sub form.
$i
Definition: disco.tpl.php:19
$response
$_POST["username"]
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt public...