ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRegistrationEmailRoleAssignments.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 
33 define('IL_REG_MISSING_DOMAIN',1);
34 define('IL_REG_MISSING_ROLE',2);
35 
37 {
38  var $assignments = array();
39  var $default_role = 0;
40 
42  {
43  global $ilDB;
44 
45  $this->db =& $ilDB;
46  $this->__read();
47  }
48 
49  function getRoleByEmail($a_email)
50  {
51  global $ilObjDataCache;
52 
53  foreach($this->assignments as $assignment)
54  {
55  if(!$assignment['domain'] or !$assignment['role'])
56  {
57  continue;
58  }
59  if(stristr($a_email,$assignment['domain']))
60  {
61  // check if role exists
62  if(!$ilObjDataCache->lookupType($assignment['role']))
63  {
64  continue;
65  }
66  return $assignment['role'];
67  }
68  }
69  // return default
70  return $this->getDefaultRole();
71  }
72 
73  function getAssignments()
74  {
75  return $this->assignments ? $this->assignments : array();
76  }
77 
78  function setDomain($a_id,$a_domain)
79  {
80  $this->assignments[$a_id]['domain'] = $a_domain;
81  }
82  function setRole($a_id,$a_role)
83  {
84  $this->assignments[$a_id]['role'] = $a_role;
85  }
86 
87  function getDefaultRole()
88  {
89  return $this->default_role;
90  }
91  function setDefaultRole($a_role_id)
92  {
93  $this->default_role = $a_role_id;
94  }
95 
96  function delete($a_id)
97  {
98  global $ilDB;
99 
100  $query = "DELETE FROM reg_er_assignments ".
101  "WHERE assignment_id = ".$ilDB->quote($a_id ,'integer');
102  $res = $ilDB->manipulate($query);
103  $this->__read();
104  return true;
105  }
106 
107  function add()
108  {
109  global $ilDB;
110 
111  $next_id = $ilDB->nextId('reg_er_assignments');
112  $query = "INSERT INTO reg_er_assignments (assignment_id,domain,role) ".
113  "VALUES( ".
114  $ilDB->quote($next_id,'integer').', '.
115  $ilDB->quote('','text').", ".
116  $ilDB->quote(0,'integer').
117  ")";
118  $res = $ilDB->manipulate($query);
119  $this->__read();
120  return true;
121  }
122 
123  function save()
124  {
125  global $ilias, $ilDB;
126 
127  // Save default role
128  $ilias->setSetting('reg_default_role',$this->getDefaultRole());
129 
130  foreach($this->assignments as $assignment)
131  {
132  $query = "UPDATE reg_er_assignments ".
133  "SET domain = ".$ilDB->quote($assignment['domain'] ,'text').", ".
134  "role = ".$ilDB->quote($assignment['role'] ,'integer')." ".
135  "WHERE assignment_id = ".$ilDB->quote($assignment['id'] ,'integer');
136  $res = $ilDB->manipulate($query);
137  }
138  return true;
139  }
140 
141  function validate()
142  {
143  foreach($this->assignments as $assignment)
144  {
145  if(!strlen($assignment['domain']))
146  {
147  return IL_REG_MISSING_DOMAIN;
148  }
149  if(!$assignment['role'])
150  {
151  return IL_REG_MISSING_ROLE;
152  }
153  }
154  if(!$this->getDefaultRole())
155  {
156  return IL_REG_MISSING_ROLE;
157  }
158  return 0;
159  }
160 
161 
162 
163 
164  // Private
165  function __read()
166  {
167  global $ilias, $ilDB;
168 
169  $query = "SELECT * FROM reg_er_assignments ";
170  $res = $this->db->query($query);
171 
172  $this->assignments = array();
173  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
174  {
175  $this->assignments[$row->assignment_id]['id'] = $row->assignment_id;
176  $this->assignments[$row->assignment_id]['role'] = $row->role;
177  $this->assignments[$row->assignment_id]['domain'] = $row->domain;
178  }
179 
180  $this->default_role = $ilias->getSetting('reg_default_role');
181 
182  return true;
183  }
184 }
185 ?>