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