ILIAS  Release_3_10_x_branch Revision 61812
 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_email_role_assignments ".
101  "WHERE assignment_id = ".$ilDB->quote($a_id);
102 
103  $this->db->query($query);
104 
105  $this->__read();
106  return true;
107  }
108 
109  function add()
110  {
111  $query = "INSERT INTO reg_email_role_assignments ".
112  "SET domain = '', ".
113  "role = ''";
114 
115  $this->db->query($query);
116 
117  $this->__read();
118  return true;
119  }
120 
121  function save()
122  {
123  global $ilias, $ilDB;
124 
125  // Save default role
126  $ilias->setSetting('reg_default_role',$this->getDefaultRole());
127 
128  foreach($this->assignments as $assignment)
129  {
130  $query = "UPDATE reg_email_role_assignments ".
131  "SET domain = ".$ilDB->quote($assignment['domain']).", ".
132  "role = ".$ilDB->quote($assignment['role'])." ".
133  "WHERE assignment_id = ".$ilDB->quote($assignment['id']);
134 
135  $this->db->query($query);
136  }
137  return true;
138  }
139 
140  function validate()
141  {
142  foreach($this->assignments as $assignment)
143  {
144  if(!strlen($assignment['domain']))
145  {
146  return IL_REG_MISSING_DOMAIN;
147  }
148  if(!$assignment['role'])
149  {
150  return IL_REG_MISSING_ROLE;
151  }
152  }
153  if(!$this->getDefaultRole())
154  {
155  return IL_REG_MISSING_ROLE;
156  }
157  return 0;
158  }
159 
160 
161 
162 
163  // Private
164  function __read()
165  {
166  global $ilias, $ilDB;
167 
168  $query = "SELECT * FROM reg_email_role_assignments ";
169  $res = $this->db->query($query);
170 
171  $this->assignments = array();
172  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
173  {
174  $this->assignments[$row->assignment_id]['id'] = $row->assignment_id;
175  $this->assignments[$row->assignment_id]['role'] = $row->role;
176  $this->assignments[$row->assignment_id]['domain'] = $row->domain;
177  }
178 
179  $this->default_role = $ilias->getSetting('reg_default_role');
180 
181  return true;
182  }
183 }
184 ?>