ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLDAPAttributeMapping.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 
34 {
35  private static $instances = array();
36  private $server_id = null;
37  private $db = null;
38  private $mapping_rules = array();
39  private $rules_for_update = array();
40  private $lng;
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  return self::$instances[$a_server_id];
69  }
70  return self::$instances[$a_server_id] = new ilLDAPAttributeMapping($a_server_id);
71  }
72 
73 
81  public static function _delete($a_server_id)
82  {
83  global $ilDB;
84 
85  $query = "DELETE FROM ldap_attribute_mapping " .
86  "WHERE server_id =" . $ilDB->quote($a_server_id, 'integer');
87  $res = $ilDB->manipulate($query);
88  }
89 
97  public static function _lookupGlobalRole($a_server_id)
98  {
99  global $ilDB;
100 
101  $query = "SELECT value FROM ldap_attribute_mapping " .
102  "WHERE server_id =" . $ilDB->quote($a_server_id, 'integer') . " " .
103  "AND keyword = " . $ilDB->quote('global_role', 'text');
104 
105  $res = $ilDB->query($query);
106  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
107  return (int) $row->value;
108  }
109  return 0;
110  }
111 
118  public static function hasRulesForUpdate($a_server_id)
119  {
120  global $ilDB;
121 
122  $query = 'SELECT perform_update FROM ldap_attribute_mapping ' .
123  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
124  'AND perform_update = 1';
125  $res = $ilDB->query($query);
126  return $res->numRows() ? true : false;
127  }
128 
138  public function setRule($a_field_name, $a_ldap_attribute, $a_perform_update)
139  {
140  $this->mapping_rules[$a_field_name]['value'] = $a_ldap_attribute;
141  $this->mapping_rules[$a_field_name]['performUpdate'] = $a_perform_update;
142  }
143 
151  public function getRulesForUpdate()
152  {
153  return $this->rules_for_update ? $this->rules_for_update : array();
154  }
155 
163  public function getFieldsForUpdate()
164  {
165  foreach ($this->rules_for_update as $field => $rule) {
166  if (!strlen($rule['value'])) {
167  continue;
168  }
169  if (strpos($rule['value'], ',') === false) {
170  $fields[] = strtolower($rule['value']);
171  continue;
172  }
173  $tmp_fields = explode(',', $rule['value']);
174  $value = '';
175  foreach ($tmp_fields as $tmp_field) {
176  $fields[] = trim(strtolower($tmp_field));
177  }
178  }
179  return $fields ? $fields : array();
180  }
181 
189  public function getFields()
190  {
191  foreach ($this->mapping_rules as $field => $rule) {
192  if (!strlen($rule['value'])) {
193  continue;
194  }
195  if (strpos($rule['value'], ',') === false) {
196  $fields[] = strtolower($rule['value']);
197  continue;
198  }
199  $tmp_fields = explode(',', $rule['value']);
200  $value = '';
201  foreach ($tmp_fields as $tmp_field) {
202  $fields[] = trim(strtolower($tmp_field));
203  }
204  }
205  return $fields ? $fields : array();
206  }
207 
215  public function getRules()
216  {
217  return $this->mapping_rules;
218  }
219 
226  public function clearRules()
227  {
228  $this->mapping_rules = array();
229  }
230 
237  public function save()
238  {
239  global $ilDB;
240 
241  $this->delete();
242 
243  foreach ($this->mapping_rules as $keyword => $options) {
244  $query = "INSERT INTO ldap_attribute_mapping (server_id,keyword,value,perform_update) " .
245  "VALUES( " .
246  $this->db->quote($this->server_id, 'integer') . ", " .
247  $this->db->quote($keyword, 'text') . ", " .
248  $this->db->quote($options['value'], 'text') . ", " .
249  $this->db->quote($options['performUpdate'], 'integer') .
250  ')';
251  $res = $ilDB->manipulate($query);
252  }
253  }
254 
261  public function delete()
262  {
263  self::_delete($this->server_id);
264  }
265 
274  public function enabledUpdate($a_field_name)
275  {
276  if (array_key_exists($a_field_name, $this->mapping_rules)) {
277  return (bool) $this->mapping_rules[$a_field_name]['performUpdate'];
278  }
279  return false;
280  }
281 
289  public function getValue($a_field_name)
290  {
291  if (array_key_exists($a_field_name, $this->mapping_rules)) {
292  return $this->mapping_rules[$a_field_name]['value'];
293  }
294  return '';
295  }
296 
304  private function read()
305  {
306  global $ilDB;
307 
308  $query = "SELECT * FROM ldap_attribute_mapping " .
309  "WHERE server_id =" . $this->db->quote($this->server_id, 'integer') . " ";
310 
311  $res = $this->db->query($query);
312  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
313  $this->mapping_rules[$row->keyword]['value'] = $row->value;
314  $this->mapping_rules[$row->keyword]['performUpdate'] = (bool) $row->perform_update;
315 
316  if ($row->perform_update) {
317  $this->rules_for_update[$row->keyword]['value'] = $row->value;
318  }
319  }
320  }
321 }
clearRules()
Clear rules => Does not perform an update.
static _getInstanceByServerId($a_server_id)
Get instance of class.
setRule($a_field_name, $a_ldap_attribute, $a_perform_update)
Set mapping rule.
static hasRulesForUpdate($a_server_id)
Check if there is ldap attribute -> user data mapping which which is updated on login.
enabledUpdate($a_field_name)
Check whether an update should be performed on a specific user attribute or not.
getFieldsForUpdate()
Get field names of all mapping rules with option &#39;update&#39;.
static _lookupGlobalRole($a_server_id)
Lookup global role assignment.
getFields()
Get all mapping fields.
getRulesForUpdate()
Get all mapping rules with option &#39;update&#39;.
foreach($_POST as $key=> $value) $res
$rule
Definition: showstats.php:43
static _delete($a_server_id)
Delete mapping rules by server id.
$query
Create styles array
The data for the language used.
This class stores the settings that define the mapping between LDAP attribute and user profile fields...
read()
Read mapping setttings from db.
global $ilDB
__construct($a_server_id)
Private constructor (Singleton for each server_id)
getValue($a_field_name)
Get LDAP attribute name by given ILIAS profile field.
save()
Save mapping rules to db.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
PHPExcel root directory.
Definition: Database.php:30