ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilLDAPRoleGroupMappingSettings.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 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{
34 private static $instances = array();
35 private $server_id = null;
36 private $db = null;
37 private $mappings = null;
38
41
48 private function __construct($a_server_id)
49 {
50 global $ilDB,$lng;
51
52 $this->db = $ilDB;
53 $this->lng = $lng;
54 $this->server_id = $a_server_id;
55 $this->read();
56 }
57
65 public static function _getInstanceByServerId($a_server_id)
66 {
67 if(array_key_exists($a_server_id,self::$instances) and is_object(self::$instances[$a_server_id]))
68 {
69 return self::$instances[$a_server_id];
70 }
71 return self::$instances[$a_server_id] = new ilLDAPRoleGroupMappingSettings($a_server_id);
72 }
73
74 public static function _deleteByRole($a_role_id)
75 {
76 global $ilDB;
77
78 $query = "DELETE FROM ldap_rg_mapping ".
79 "WHERE role = ".$ilDB->quote($a_role_id,'integer');
80 $res = $ilDB->manipulate($query);
81
82 return true;
83 }
84
85 public static function _deleteByServerId($a_server_id)
86 {
87 global $ilDB;
88
89 $query = "DELETE FROM ldap_rg_mapping ".
90 "WHERE server_id = ".$ilDB->quote($a_server_id,'integer');
91 $res = $ilDB->manipulate($query);
92
93 return true;
94 }
95
96 public static function _getAllActiveMappings()
97 {
98 global $ilDB,$rbacreview;
99
100 $query = "SELECT rgm.* FROM ldap_rg_mapping rgm JOIN ldap_server_settings lss ".
101 "ON rgm.server_id = lss.server_id ".
102 "WHERE lss.active = 1 ".
103 "AND lss.role_sync_active = 1 ";
104 $res = $ilDB->query($query);
105 while($row = $ilDB->fetchObject($res))
106 {
107 $data['server_id'] = $row->server_id;
108 $data['url'] = $row->url;
109 $data['mapping_id'] = $row->mapping_id;
110 $data['dn'] = $row->dn;
111 $data['member'] = $row->member_attribute;
112 $data['isdn'] = $row->member_isdn;
113 $data['info'] = $row->mapping_info;
114 $data['info_type'] = $row->mapping_info_type;
115 // read assigned object
116 $data['object_id'] = $rbacreview->getObjectOfRole($row->role);
117
118
119 $active[$row->role][] = $data;
120 }
121 return $active ? $active : array();
122 }
123
124 public function getServerId()
125 {
126 return $this->server_id;
127 }
128
135 public function getMappings()
136 {
137 return $this->mappings ? $this->mappings : array();
138 }
139
140 public function loadFromPost($a_mappings)
141 {
142 global $rbacreview;
143
144 if(!$a_mappings)
145 {
146 return;
147 }
148
149 $this->mappings = array();
150 foreach($a_mappings as $mapping_id => $data)
151 {
152 if($mapping_id == 0)
153 {
154 if(!$data['dn'] and !$data['member'] and !$data['memberisdn'] and !$data['role'])
155 {
156 continue;
157 }
158 }
159 $this->mappings[$mapping_id]['dn'] = ilUtil::stripSlashes($data['dn']);
160 $this->mappings[$mapping_id]['url'] = ilUtil::stripSlashes($data['url']);
161 $this->mappings[$mapping_id]['member_attribute'] = ilUtil::stripSlashes($data['member']);
162 $this->mappings[$mapping_id]['member_isdn'] = ilUtil::stripSlashes($data['memberisdn']);
163 $this->mappings[$mapping_id]['role_name'] = ilUtil::stripSlashes($data['role']);
164 $this->mappings[$mapping_id]['role'] = $rbacreview->roleExists(ilUtil::stripSlashes($data['role']));
165 $this->mappings[$mapping_id]['info'] = ilUtil::stripSlashes($data['info']);
166 $this->mappings[$mapping_id]['info_type'] = ilUtil::stripSlashes($data['info_type']);
167 }
168 }
169
176 public function validate()
177 {
178 global $ilErr,$rbacreview;
179
180 $ilErr->setMessage('');
181 $found_missing = false;
182 foreach($this->mappings as $mapping_id => $data)
183 {
184 // Check if all required fields are available
185 if(!strlen($data['dn']) || !strlen($data['member_attribute']) || !strlen($data['role_name']))
186 {
187 if(!$found_missing)
188 {
189 $found_missing = true;
190 $ilErr->appendMessage($this->lng->txt('fill_out_all_required_fields'));
191 }
192 }
193 // Check role valid
194 if(strlen($data['role_name']) and !$rbacreview->roleExists($data['role_name']))
195 {
196 $ilErr->appendMessage($this->lng->txt('ldap_role_not_exists').' '.$data['role_name']);
197 }
198 }
199 return strlen($ilErr->getMessage()) ? false : true;
200 }
201
209 public function save()
210 {
211 global $ilDB;
212
213 foreach($this->mappings as $mapping_id => $data)
214 {
215 if(!$mapping_id)
216 {
217 $next_id = $ilDB->nextId('ldap_rg_mapping');
218 $query = "INSERT INTO ldap_rg_mapping (mapping_id,server_id,url,dn,member_attribute,member_isdn,role,mapping_info,mapping_info_type) ".
219 "VALUES ( ".
220 $ilDB->quote($next_id,'integer').", ".
221 $this->db->quote($this->getServerId(),'integer').", ".
222 $this->db->quote($data['url'],'text').", ".
223 $this->db->quote($data['dn'],'text').", ".
224 $this->db->quote($data['member_attribute'],'text').", ".
225 $this->db->quote($data['member_isdn'],'integer').", ".
226 $this->db->quote($data['role'],'integer').", ".
227 $this->db->quote($data['info'],'text').", ".
228 $this->db->quote($data['info_type'],'integer').
229 ")";
230 $res = $ilDB->manipulate($query);
231 }
232 else
233 {
234 $query = "UPDATE ldap_rg_mapping ".
235 "SET server_id = ".$this->db->quote($this->getServerId(),'integer').", ".
236 "url = ".$this->db->quote($data['url'],'text').", ".
237 "dn =".$this->db->quote($data['dn'],'text').", ".
238 "member_attribute = ".$this->db->quote($data['member_attribute'],'text').", ".
239 "member_isdn = ".$this->db->quote($data['member_isdn'],'integer').", ".
240 "role = ".$this->db->quote($data['role'],'integer').", ".
241 "mapping_info = ".$this->db->quote($data['info'],'text').", ".
242 "mapping_info_type = ".$this->db->quote($data['info_type'],'integer')." ".
243 "WHERE mapping_id = ".$this->db->quote($mapping_id,'integer');
244 $res = $ilDB->manipulate($query);
245
246 }
247 }
248 $this->read();
249 }
250
251
259 public function delete($a_mapping_id)
260 {
261 global $ilDB;
262
263 $query = "DELETE FROM ldap_rg_mapping ".
264 "WHERE server_id = ".$this->db->quote($this->getServerId(),'integer')." ".
265 "AND mapping_id = ".$this->db->quote($a_mapping_id ,'integer');
266 $res = $ilDB->manipulate($query);
267 $this->read();
268 }
269
270
277 public function getMappingInfoString($a_mapping_id)
278 {
279 $role = $this->mappings[$a_mapping_id]['role_name'];
280 $dn_parts = explode(',',$this->mappings[$a_mapping_id]['dn']);
281
282 return (array_key_exists(0,$dn_parts) ? $dn_parts[0] : "''");
283 }
284
285
292 private function read()
293 {
294 global $ilObjDataCache,$rbacreview,$tree;
295
296 $this->mappings = array();
297 $query = "SELECT * FROM ldap_rg_mapping LEFT JOIN object_data ".
298 "ON role = obj_id ".
299 "WHERE server_id =".$this->db->quote($this->getServerId(),'integer').' '.
300 "ORDER BY title,dn";
301
302 $res = $this->db->query($query);
303 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
304 {
305 $this->mappings[$row->mapping_id]['mapping_id'] = $row->mapping_id;
306 $this->mappings[$row->mapping_id]['dn'] = $row->dn;
307 $this->mappings[$row->mapping_id]['url'] = $row->url;
308 $this->mappings[$row->mapping_id]['member_attribute'] = $row->member_attribute;
309 $this->mappings[$row->mapping_id]['member_isdn'] = $row->member_isdn;
310 $this->mappings[$row->mapping_id]['role'] = $row->role;
311 $this->mappings[$row->mapping_id]['info'] = $row->mapping_info;
312 $this->mappings[$row->mapping_id]['info_type'] = $row->mapping_info_type;
313 if($ilObjDataCache->lookupType($row->role) == 'role')
314 {
315 $this->mappings[$row->mapping_id]['role_name'] = $ilObjDataCache->lookupTitle($row->role);
316 }
317 else
318 {
319 $this->mappings[$row->mapping_id]['role_name'] = $row->role;
320 }
321
322 }
323 }
324
325}
326
327?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
getMappingInfoString($a_mapping_id)
Create an info string for a role group mapping.
__construct($a_server_id)
Private constructor (Singleton for each server_id)
static _getInstanceByServerId($a_server_id)
Get instance of class.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$data
global $lng
Definition: privfeed.php:40
global $ilDB