ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilRegistrationSettings.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
25 define('IL_REG_DISABLED', 1);
26 define('IL_REG_DIRECT', 2);
27 define('IL_REG_APPROVE', 3);
28 define('IL_REG_ACTIVATION', 4);
29 define('IL_REG_CODES', 5);
30 
31 define('IL_REG_ROLES_FIXED', 1);
32 define('IL_REG_ROLES_EMAIL', 2);
33 
34 define('IL_REG_ERROR_UNKNOWN', 1);
35 define('IL_REG_ERROR_NO_PERM', 2);
36 
46 {
47  const ERR_UNKNOWN_RCP = 1;
48  const ERR_MISSING_RCP = 2;
49 
51 
57  private $role_type;
58  private $unknown;
59  private $reg_hash_life_time = 0;
60  private $reg_allow_codes = false;
62 
63  public function __construct()
64  {
65  $this->__read();
66  }
67 
68  public function getRegistrationType()
69  {
71  }
72  public function setRegistrationType($a_type)
73  {
74  $this->registration_type = $a_type;
75  }
76 
77  public static function _lookupRegistrationType()
78  {
79  global $DIC;
80 
81  $ilSetting = $DIC['ilSetting'];
82 
83  $ret = (int) $ilSetting->get('new_registration_type', IL_REG_DISABLED);
84 
85  if ($ret < 1 or $ret > 5) {
86  //data is corrupted and should be processed like "No Registration possible" (#18261)
88  }
89 
90  return $ret;
91  }
92 
93  public function enabled()
94  {
95  return $this->registration_type != IL_REG_DISABLED;
96  }
97  public function directEnabled()
98  {
99  return $this->registration_type == IL_REG_DIRECT;
100  }
101  public function approveEnabled()
102  {
103  return $this->registration_type == IL_REG_APPROVE;
104  }
105  public function activationEnabled()
106  {
107  return $this->registration_type == IL_REG_ACTIVATION;
108  }
109  public function registrationCodeRequired()
110  {
111  return $this->registration_type == IL_REG_CODES;
112  }
113 
114  public function passwordGenerationEnabled()
115  {
117  }
118  public function setPasswordGenerationStatus($a_status)
119  {
120  $this->password_generation_enabled = $a_status;
121  }
122 
123  public function getAccessLimitation()
124  {
126  }
127 
128  public function setAccessLimitation($a_access_limitation)
129  {
130  $this->access_limitation = $a_access_limitation;
131  }
132 
133  public function setApproveRecipientLogins($a_rec_string)
134  {
135  $this->approve_recipient_logins = $a_rec_string;
136  $this->approve_recipient_ids = array();
137 
138  // convert logins to array of ids
139  foreach (explode(',', trim($this->approve_recipient_logins)) as $login) {
140  if ($uid = ilObjUser::_lookupId(trim($login))) {
141  $this->approve_recipient_ids[] = $uid;
142  }
143  }
144  }
145  public function getApproveRecipientLogins()
146  {
148  }
149  public function getApproveRecipients()
150  {
151  return $this->approve_recipient_ids ? $this->approve_recipient_ids : array();
152  }
153  public function getUnknown()
154  {
155  return implode(',', $this->unknown);
156  }
157 
158  public function roleSelectionEnabled()
159  {
160  return $this->role_type == IL_REG_ROLES_FIXED;
161  }
163  {
164  return $this->role_type == IL_REG_ROLES_EMAIL;
165  }
166  public function setRoleType($a_type)
167  {
168  $this->role_type = $a_type;
169  }
170 
171  public function setRegistrationHashLifetime($a_lifetime)
172  {
173  $this->reg_hash_life_time = $a_lifetime;
174 
175  return $this;
176  }
177 
178  public function getRegistrationHashLifetime()
179  {
180  return max($this->reg_hash_life_time, self::REG_HASH_LIFETIME_MIN_VALUE);
181  }
182 
183  public function setAllowCodes($a_allow_codes)
184  {
185  $this->reg_allow_codes = (bool) $a_allow_codes;
186 
187  return $this;
188  }
189 
190  public function getAllowCodes()
191  {
192  return $this->reg_allow_codes;
193  }
194 
195  public function setAllowedDomains($a_value)
196  {
197  $a_value = explode(";", trim($a_value));
198  $this->allowed_domains = $a_value;
199  }
200 
201  public function getAllowedDomains()
202  {
203  return (array) $this->allowed_domains;
204  }
205 
206  public function validate()
207  {
208  $this->unknown = array();
209  $this->mail_perm = array();
210 
211  $login_arr = explode(',', $this->getApproveRecipientLogins());
212  $login_arr = $login_arr ? $login_arr : array();
213  foreach ($login_arr as $recipient) {
214  if (!$recipient = trim($recipient)) {
215  continue;
216  }
217  if (!ilObjUser::_lookupId($recipient)) {
218  $this->unknown[] = $recipient;
219  continue;
220  } else {
221  $valid = $recipient;
222  }
223  }
224  if (count($this->unknown)) {
225  return self::ERR_UNKNOWN_RCP;
226  }
227  if ($this->getRegistrationType() == IL_REG_APPROVE and !count((array) $valid)) {
228  return self::ERR_MISSING_RCP;
229  }
230  return 0;
231  }
232 
233 
234  public function save()
235  {
236  global $DIC;
237 
238  $ilias = $DIC['ilias'];
239 
240  $ilias->setSetting('reg_role_assignment', $this->role_type);
241  $ilias->setSetting('new_registration_type', $this->registration_type);
242  $ilias->setSetting('passwd_reg_auto_generate', $this->password_generation_enabled);
243  $ilias->setSetting('approve_recipient', addslashes(serialize($this->approve_recipient_ids)));
244  $ilias->setSetting('reg_access_limitation', $this->access_limitation);
245  $ilias->setSetting('reg_hash_life_time', $this->reg_hash_life_time);
246  $ilias->setSetting('reg_allow_codes', $this->reg_allow_codes);
247  $ilias->setSetting('reg_allowed_domains', implode(';', $this->allowed_domains));
248 
249  return true;
250  }
251 
252  public function __read()
253  {
254  global $DIC;
255 
256  $ilias = $DIC['ilias'];
257 
258  //static method validates value
259  $this->registration_type = self::_lookupRegistrationType();
260 
261  $this->role_type = $ilias->getSetting('reg_role_assignment', 1);
262  $this->password_generation_enabled = $ilias->getSetting('passwd_reg_auto_generate');
263  $this->access_limitation = $ilias->getSetting('reg_access_limitation');
264  $this->reg_hash_life_time = $ilias->getSetting('reg_hash_life_time');
265  $this->reg_allow_codes = (bool) $ilias->getSetting('reg_allow_codes');
266 
267  $this->approve_recipient_ids = unserialize(stripslashes($ilias->getSetting('approve_recipient')));
268  $this->approve_recipient_ids = $this->approve_recipient_ids ?
269  $this->approve_recipient_ids :
270  array();
271 
272  // create login array
273  $tmp_logins = array();
274  foreach ($this->approve_recipient_ids as $id) {
275  if ($login = ilObjUser::_lookupLogin($id)) {
276  $tmp_logins[] = $login;
277  }
278  }
279  $this->approve_recipient_logins = implode(',', $tmp_logins);
280 
281  $this->setAllowedDomains($ilias->getSetting('reg_allowed_domains'));
282  }
283 }
static _lookupLogin($a_user_id)
lookup login
global $DIC
Definition: saml.php:7
$valid
if(!array_key_exists('StateId', $_REQUEST)) $id
static _lookupId($a_user_str)
Lookup id by login.
const IL_REG_ROLES_EMAIL
setAccessLimitation($a_access_limitation)
$a_type
Definition: workflow.php:92
const IL_REG_ACTIVATION
const IL_REG_ROLES_FIXED
global $ilSetting
Definition: privfeed.php:17
$ret
Definition: parser.php:6
$login
Definition: cron.php:13