ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
53  // 32 bits for "time_low"
54  mt_rand(0, 0xffff), mt_rand(0, 0xffff),
55  // 16 bits for "time_mid"
56  mt_rand(0, 0xffff),
57  // 16 bits for "time_high_and_version",
58  // four most significant bits holds version number 4
59  mt_rand(0, 0x0fff) | 0x4000,
60  // 16 bits, 8 bits for "clk_seq_hi_res",
61  // 8 bits for "clk_seq_low",
62  // two most significant bits holds zero and one for variant DCE1.1
63  mt_rand(0, 0x3fff) | 0x8000,
64  // 48 bits for "node"
65  mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
66  );
67  }
68 
72  public function getCtrlPath()
73  {
74  return $this->ctrl_path;
75  }
76 
80  public function setCtrlPath($ctrl_path)
81  {
82  $this->ctrl_path = $ctrl_path;
83  }
84 
88  public function setValueByArray(array $a_values)
89  {
90  $this->values = array(
91  self::NAME_AUTH_PROP_1 => $a_values[$this->getPostVar()][self::NAME_AUTH_PROP_1],
92  self::NAME_AUTH_PROP_2 => $a_values[$this->getPostVar()][self::NAME_AUTH_PROP_2]
93  );
94 
95  foreach($this->getSubItems() as $item)
96  {
97  $item->setValueByArray($a_values);
98  }
99  }
100 
104  public function checkInput()
105  {
109  global $lng;
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  {
118  $this->setAlert($lng->txt('msg_input_is_required'));
119  return false;
120  }
121 
122  return $this->checkSubItemsInput();
123  }
124 
128  public function insert(ilTemplate $a_tpl)
129  {
130  $a_tpl->setCurrentBlock('prop_generic');
131  $a_tpl->setVariable('PROP_GENERIC', $this->render());
132  $a_tpl->parseCurrentBlock();
133  }
134 
138  public function render()
139  {
144  global $lng, $ilCtrl;
145 
146  $tpl = new ilTemplate('tpl.chatroom_auth_input.html', true, true, 'Modules/Chatroom');
147 
148  for($i = 1; $i <= count($this->values); $i++)
149  {
150  $const = 'NAME_AUTH_PROP_' . $i;
151  $const_val = constant('self::' . $const);
152 
153  $tpl->setVariable('TXT_AUTH_PROP_' . $i, $lng->txt('chatroom_auth_' . $const_val));
154  $tpl->setVariable('ID_AUTH_PROP_' . $i, $const_val);
155  $tpl->setVariable('NAME_AUTH_PROP_' . $i, $const_val);
156  $tpl->setVariable('VALUE_AUTH_PROP_' . $i, $this->values[$const_val]);
157  }
158 
159  $ilCtrl->setParameterByClass('ilformpropertydispatchgui', 'postvar', $this->getPostVar());
160  $tpl->setVariable('URL', $ilCtrl->getLinkTargetByClass($this->ctrl_path, 'getRandomValues', '', true, false));
161  $tpl->setVariable('ID_BTN', $this->getFieldId() . '_btn');
162  $tpl->setVariable('TXT_BTN', $lng->txt('chatroom_auth_btn_txt'));
163  $tpl->setVariable('POST_VAR', $this->getPostVar());
164  $tpl->setVariable('SIZE', $this->getSize());
165  if($this->getDisabled())
166  {
167  $tpl->setVariable('DISABLED', ' disabled="disabled"');
168  }
169 
170  return $tpl->get();
171  }
172 
176  public function getSize()
177  {
178  return $this->size;
179  }
180 
184  public function setSize($size)
185  {
186  $this->size = $size;
187  }
188 }
getPostVar()
Get Post Variable.
checkInput()
Check input, strip slashes etc.
setAlert($a_alert)
Set Alert Text.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:613
font size
Definition: langcheck.php:162
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
Class ilChatroomAuthInputGUI.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
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.
global $lng
Definition: privfeed.php:17
$_POST["username"]
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt public...