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