ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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;
61  private $allowed_domains;
62 
64  {
65  $this->__read();
66  }
67 
69  {
71  }
72  function setRegistrationType($a_type)
73  {
74  $this->registration_type = $a_type;
75  }
76 
78  {
79  global $ilias;
80 
81  return $ilias->getSetting('new_registration_type',IL_REG_DISABLED);
82  }
83 
84  function enabled()
85  {
86  return $this->registration_type != IL_REG_DISABLED;
87  }
88  function directEnabled()
89  {
90  return $this->registration_type == IL_REG_DIRECT;
91  }
92  function approveEnabled()
93  {
94  return $this->registration_type == IL_REG_APPROVE;
95  }
96  public function activationEnabled()
97  {
98  return $this->registration_type == IL_REG_ACTIVATION;
99  }
101  {
102  return $this->registration_type == IL_REG_CODES;
103  }
104 
106  {
108  }
109  function setPasswordGenerationStatus($a_status)
110  {
111  $this->password_generation_enabled = $a_status;
112  }
113 
115  {
117  }
118 
119  function setAccessLimitation($a_access_limitation)
120  {
121  $this->access_limitation = $a_access_limitation;
122  }
123 
124  function setApproveRecipientLogins($a_rec_string)
125  {
126  $this->approve_recipient_logins = $a_rec_string;
127  $this->approve_recipient_ids = array();
128 
129  // convert logins to array of ids
130  foreach(explode(',',trim($this->approve_recipient_logins)) as $login)
131  {
132  if($uid = ilObjUser::_lookupId(trim($login)))
133  {
134  $this->approve_recipient_ids[] = $uid;
135  }
136  }
137  }
139  {
141  }
143  {
144  return $this->approve_recipient_ids ? $this->approve_recipient_ids : array();
145  }
146  function getUnknown()
147  {
148  return implode(',',$this->unknown);
149  }
150 
152  {
153  return $this->role_type == IL_REG_ROLES_FIXED;
154  }
156  {
157  return $this->role_type == IL_REG_ROLES_EMAIL;
158  }
159  function setRoleType($a_type)
160  {
161  $this->role_type = $a_type;
162  }
163 
164  public function setRegistrationHashLifetime($a_lifetime)
165  {
166  $this->reg_hash_life_time = $a_lifetime;
167 
168  return $this;
169  }
170 
171  public function getRegistrationHashLifetime()
172  {
173  return max($this->reg_hash_life_time, self::REG_HASH_LIFETIME_MIN_VALUE);
174  }
175 
176  public function setAllowCodes($a_allow_codes)
177  {
178  $this->reg_allow_codes = (bool)$a_allow_codes;
179 
180  return $this;
181  }
182 
183  public function getAllowCodes()
184  {
185  return $this->reg_allow_codes;
186  }
187 
188  public function setAllowedDomains($a_value)
189  {
190  $a_value = explode(";", trim($a_value));
191  $this->allowed_domains = $a_value;
192  }
193 
194  public function getAllowedDomains()
195  {
196  return (array)$this->allowed_domains;
197  }
198 
199  function validate()
200  {
201  $this->unknown = array();
202  $this->mail_perm = array();
203 
204  $login_arr = explode(',',$this->getApproveRecipientLogins());
205  $login_arr = $login_arr ? $login_arr : array();
206  foreach($login_arr as $recipient)
207  {
208  if(!$recipient = trim($recipient))
209  {
210  continue;
211  }
212  if(!ilObjUser::_lookupId($recipient))
213  {
214  $this->unknown[] = $recipient;
215  continue;
216  }
217  else
218  {
219  $valid = $recipient;
220  }
221  }
222  if(count($this->unknown))
223  {
224  return self::ERR_UNKNOWN_RCP;
225  }
226  if($this->getRegistrationType() == IL_REG_APPROVE and !count((array) $valid))
227  {
228  return self::ERR_MISSING_RCP;
229  }
230  return 0;
231  }
232 
233 
234  function save()
235  {
236  global $ilias;
237 
238  $ilias->setSetting('reg_role_assignment',$this->role_type);
239  $ilias->setSetting('new_registration_type',$this->registration_type);
240  $ilias->setSetting('passwd_reg_auto_generate',$this->password_generation_enabled);
241  $ilias->setSetting('approve_recipient',addslashes(serialize($this->approve_recipient_ids)));
242  $ilias->setSetting('reg_access_limitation',$this->access_limitation);
243  $ilias->setSetting('reg_hash_life_time',$this->reg_hash_life_time);
244  $ilias->setSetting('reg_allow_codes',$this->reg_allow_codes);
245  $ilias->setSetting('reg_allowed_domains',implode(';', $this->allowed_domains));
246 
247  return true;
248  }
249 
250  function __read()
251  {
252  global $ilias;
253 
254  $this->registration_type = $ilias->getSetting('new_registration_type');
255  $this->role_type = $ilias->getSetting('reg_role_assignment',1);
256  $this->password_generation_enabled = $ilias->getSetting('passwd_reg_auto_generate');
257  $this->access_limitation = $ilias->getSetting('reg_access_limitation');
258  $this->reg_hash_life_time = $ilias->getSetting('reg_hash_life_time');
259  $this->reg_allow_codes = (bool)$ilias->getSetting('reg_allow_codes');
260 
261  $this->approve_recipient_ids = unserialize(stripslashes($ilias->getSetting('approve_recipient')));
262  $this->approve_recipient_ids = $this->approve_recipient_ids ?
263  $this->approve_recipient_ids :
264  array();
265 
266  // create login array
267  $tmp_logins = array();
268  foreach($this->approve_recipient_ids as $id)
269  {
270  if($login = ilObjUser::_lookupLogin($id))
271  {
272  $tmp_logins[] = $login;
273  }
274  }
275  $this->approve_recipient_logins = implode(',',$tmp_logins);
276 
277  $this->setAllowedDomains($ilias->getSetting('reg_allowed_domains'));
278  }
279 }
280 ?>