• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/LDAP/classes/class.ilLDAPRoleGroupMappingSettings.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00032 class ilLDAPRoleGroupMappingSettings
00033 {
00034         private static $instances = array();
00035         private $server_id = null;
00036         private $db = null;
00037         private $mappings = null;
00038         
00039         const MAPPING_INFO_ALL = 1;
00040         const MAPPING_INFO_INFO_ONLY = 0;  
00041         
00048         private function __construct($a_server_id)
00049         {
00050                 global $ilDB,$lng;
00051                 
00052                 $this->db = $ilDB;
00053                 $this->lng = $lng;
00054                 $this->server_id = $a_server_id;
00055                 $this->read();  
00056         }
00057         
00065         public static function _getInstanceByServerId($a_server_id)
00066         {
00067                 if(array_key_exists($a_server_id,self::$instances) and is_object(self::$instances[$a_server_id]))
00068                 {
00069                         return self::$instances[$a_server_id];
00070                 }
00071                 return self::$instances[$a_server_id] = new ilLDAPRoleGroupMappingSettings($a_server_id);
00072         }
00073         
00074         public static function _deleteByRole($a_role_id)
00075         {
00076                 global $ilDB;
00077                 
00078                 $query = "DELETE FROM ldap_role_group_mapping ".
00079                         "WHERE role = ".$ilDB->quote($a_role_id);
00080                 $ilDB->query($query);
00081                 
00082                 return true;    
00083         }
00084         
00085         public static function _deleteByServerId($a_server_id)
00086         {
00087                 global $ilDB;
00088                 
00089                 $query = "DELETE FROM ldap_role_group_mapping ".
00090                         "WHERE server_id = ".$ilDB->quote($a_server_id);
00091                         
00092                 $ilDB->query($query);
00093                 return true;
00094         }
00095         
00096         public static function _getAllActiveMappings()
00097         {
00098                 global $ilDB,$rbacreview;
00099                 
00100                 $query = "SELECT rgm.* FROM ldap_role_group_mapping as rgm JOIN ldap_server_settings as lss ".
00101                         "ON rgm.server_id = lss.server_id ".
00102                         "WHERE lss.active = 1 ".
00103                         "AND lss.role_sync_active = 1 ";
00104                 $res = $ilDB->query($query);
00105                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00106                 {
00107                         $data['server_id']              = $row->server_id;
00108                         $data['url']                    = $row->url;
00109                         $data['mapping_id']             = $row->mapping_id;
00110                         $data['dn']                             = $row->dn;
00111                         $data['member']                 = $row->member_attribute;
00112                         $data['isdn']                   = $row->member_isdn;
00113                         $data['info']                   = $row->mapping_info;
00114                         $data['info_type']              = $row->mapping_info_type;
00115                         // read assigned object
00116                         $data['object_id']              = $rbacreview->getObjectOfRole($row->role);
00117                         
00118                         
00119                         $active[$row->role][] = $data;
00120                 }
00121                 return $active ? $active : array();
00122         }
00123         
00124         public function getServerId()
00125         {
00126                 return $this->server_id;
00127         }
00128         
00135         public function getMappings()
00136         {
00137                 return $this->mappings ? $this->mappings : array();
00138         }
00139         
00140         public 
00141         
00142         public function loadFromPost($a_mappings)
00143         {
00144                 global $rbacreview;
00145                 
00146                 $this->mappings = array();
00147                 foreach($a_mappings as $mapping_id => $data)
00148                 {
00149                         if($mapping_id == 0)
00150                         {
00151                                 if(!$data['dn'] and !$data['member'] and !$data['memberisdn'] and !$data['role'])
00152                                 {
00153                                         continue;
00154                                 }
00155                         }
00156                         $this->mappings[$mapping_id]['dn'] = ilUtil::stripSlashes($data['dn']);
00157                         $this->mappings[$mapping_id]['url'] = ilUtil::stripSlashes($data['url']);
00158                         $this->mappings[$mapping_id]['member_attribute'] = ilUtil::stripSlashes($data['member']);
00159                         $this->mappings[$mapping_id]['member_isdn'] = ilUtil::stripSlashes($data['memberisdn']);
00160                         $this->mappings[$mapping_id]['role_name'] = ilUtil::stripSlashes($data['role']);
00161                         $this->mappings[$mapping_id]['role'] = $rbacreview->roleExists(ilUtil::stripSlashes($data['role']));
00162                         $this->mappings[$mapping_id]['info'] = ilUtil::stripSlashes($data['info']);
00163                         $this->mappings[$mapping_id]['info_type'] = ilUtil::stripSlashes($data['info_type']);
00164                 }
00165         }
00166         
00173         public function validate()
00174         {
00175                 global $ilErr,$rbacreview;
00176                 
00177                 $ilErr->setMessage('');
00178                 $found_missing = false;
00179                 foreach($this->mappings as $mapping_id => $data)
00180                 {
00181                         // Check if all required fields are available
00182                         if(!strlen($data['dn']) || !strlen($data['member_attribute']) || !strlen($data['role_name']))
00183                         {
00184                                 if(!$found_missing)
00185                                 {
00186                                         $found_missing = true;
00187                                         $ilErr->appendMessage($this->lng->txt('fill_out_all_required_fields'));
00188                                 }
00189                         }
00190                         // Check role valid
00191                         if(strlen($data['role_name']) and !$rbacreview->roleExists($data['role_name']))
00192                         {
00193                                 $ilErr->appendMessage($this->lng->txt('ldap_role_not_exists').' '.$data['role_name']);
00194                         }
00195                 }
00196                 return strlen($ilErr->getMessage()) ? false : true;
00197         }
00198         
00206         public function save()
00207         {
00208                 foreach($this->mappings as $mapping_id => $data)
00209                 {
00210                         if(!$mapping_id)
00211                         {
00212                                 $query = "INSERT INTO ldap_role_group_mapping ".
00213                                         "SET server_id = ".$this->db->quote($this->getServerId()).", ".
00214                                         "url = ".$this->db->quote($data['url']).", ".
00215                                         "dn = ".$this->db->quote($data['dn']).", ".
00216                                         "member_attribute = ".$this->db->quote($data['member_attribute']).", ".
00217                                         "member_isdn = ".$this->db->quote($data['member_isdn']).", ".
00218                                         "role = ".$this->db->quote($data['role']).", ".
00219                                         "mapping_info = ".$this->db->quote($data['info']).", ".
00220                                         "mapping_info_type = ".$this->db->quote($data['info_type']);
00221                                         
00222                         
00223                                 $this->db->query($query);
00224                         }
00225                         else
00226                         {
00227                                 $query = "UPDATE ldap_role_group_mapping ".
00228                                         "SET server_id = ".$this->db->quote($this->getServerId()).", ".
00229                                         "url = ".$this->db->quote($data['url']).", ".
00230                                         "dn =".$this->db->quote($data['dn']).", ".
00231                                         "member_attribute = ".$this->db->quote($data['member_attribute']).", ".
00232                                         "member_isdn = ".$this->db->quote($data['member_isdn']).", ".
00233                                         "role = ".$this->db->quote($data['role']).", ".
00234                                         "mapping_info = ".$this->db->quote($data['info']).", ".
00235                                         "mapping_info_type = ".$this->db->quote($data['info_type'])." ".
00236                                         "WHERE mapping_id = ".$this->db->quote($mapping_id);
00237 
00238                                 $this->db->query($query);
00239                         }
00240                 }
00241                 $this->read();
00242         }
00243         
00244         
00252         public function delete($a_mapping_id)
00253         {
00254                 $query = "DELETE FROM ldap_role_group_mapping ".
00255                         "WHERE server_id = ".$this->db->quote($this->getServerId())." ".
00256                         "AND mapping_id = ".$this->db->quote($a_mapping_id);
00257                 $this->db->query($query);
00258                         
00259                 $this->read();
00260         }
00261         
00262         
00269         public function getMappingInfoString($a_mapping_id)
00270         {
00271                 $role = $this->mappings[$a_mapping_id]['role_name'];
00272                 $dn_parts = explode(',',$this->mappings[$a_mapping_id]['dn']);
00273                 
00274                 return (array_key_exists(0,$dn_parts) ? $dn_parts[0] : "''");
00275         }
00276         
00277         
00284         private function read()
00285         {
00286                 global $ilObjDataCache,$rbacreview,$tree;
00287                 
00288                 $this->mappings = array();
00289                 $query = "SELECT * FROM ldap_role_group_mapping LEFT JOIN object_data ".
00290                         "ON role = obj_id ".
00291                         "WHERE server_id =".$this->db->quote($this->getServerId()).' '.
00292                         "ORDER BY title,dn";
00293                         
00294                 $res = $this->db->query($query);
00295                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00296                 {
00297                         $this->mappings[$row->mapping_id]['dn']                                         = $row->dn;
00298                         $this->mappings[$row->mapping_id]['url']                                        = $row->url;
00299                         $this->mappings[$row->mapping_id]['member_attribute']           = $row->member_attribute;
00300                         $this->mappings[$row->mapping_id]['member_isdn']                        = $row->member_isdn;
00301                         $this->mappings[$row->mapping_id]['role']                                       = $row->role;
00302                         $this->mappings[$row->mapping_id]['info']                                       = $row->mapping_info;
00303                         $this->mappings[$row->mapping_id]['info_type']                          = $row->mapping_info_type;
00304                         if($ilObjDataCache->lookupType($row->role) == 'role')
00305                         {
00306                                 $this->mappings[$row->mapping_id]['role_name']                  = $ilObjDataCache->lookupTitle($row->role);
00307                         }
00308                         else
00309                         {
00310                                 $this->mappings[$row->mapping_id]['role_name']                  = $row->role;
00311                         }
00312                 
00313                 }
00314         }
00315         
00316 }
00317 
00318 ?>

Generated on Fri Dec 13 2013 17:56:57 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1