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