| | |
| | | // replace placeholders in filter settings |
| | | if (!empty($this->prop['filter'])) |
| | | $this->prop['filter'] = strtr($this->prop['filter'], $replaces); |
| | | if (!empty($this->prop['groups']['filter'])) |
| | | $this->prop['groups']['filter'] = strtr($this->prop['groups']['filter'], $replaces); |
| | | if (!empty($this->prop['groups']['member_filter'])) |
| | | $this->prop['groups']['member_filter'] = strtr($this->prop['groups']['member_filter'], $replaces); |
| | | |
| | | foreach (array('base_dn','filter','member_filter') as $k) { |
| | | if (!empty($this->prop['groups'][$k])) |
| | | $this->prop['groups'][$k] = strtr($this->prop['groups'][$k], $replaces); |
| | | } |
| | | |
| | | if (!empty($this->prop['group_filters'])) { |
| | | foreach ($this->prop['group_filters'] as $i => $gf) { |
| | |
| | | } |
| | | else { |
| | | $prop = $this->group_id ? $this->group_data : $this->prop; |
| | | $base_dn = $this->group_id ? $this->group_base_dn : $this->base_dn; |
| | | $base_dn = $this->group_id ? $prop['base_dn'] : $this->base_dn; |
| | | |
| | | // use global search filter |
| | | if (!empty($this->filter)) |
| | |
| | | if ($result = $this->ldap->search($m[1], $filter, $m[2], $attrs, $this->group_data)) { |
| | | $entries = $result->entries(); |
| | | for ($j = 0; $j < $entries['count']; $j++) { |
| | | if (self::is_group_entry($entries[$j]) && ($nested_group_members = $this->list_group_members($entries[$j]['dn'], $count))) |
| | | if ($this->is_group_entry($entries[$j]) && ($nested_group_members = $this->list_group_members($entries[$j]['dn'], $count))) |
| | | $group_members = array_merge($group_members, $nested_group_members); |
| | | else |
| | | $group_members[] = $entries[$j]; |
| | |
| | | |
| | | /** |
| | | * Remove all contact records |
| | | * |
| | | * @param bool $with_groups Delete also groups if enabled |
| | | */ |
| | | function delete_all() |
| | | function delete_all($with_groups = false) |
| | | { |
| | | // searching for contact entries |
| | | $dn_list = $this->ldap->list_entries($this->base_dn, $this->prop['filter'] ? $this->prop['filter'] : '(objectclass=*)'); |
| | |
| | | $dn_list[$idx] = self::dn_encode($entry['dn']); |
| | | } |
| | | $this->delete($dn_list); |
| | | } |
| | | |
| | | if ($with_groups && $this->groups && ($groups = $this->_fetch_groups()) && count($groups)) { |
| | | foreach ($groups as $group) { |
| | | $this->ldap->delete($group['dn']); |
| | | } |
| | | |
| | | if ($this->cache) { |
| | | $this->cache->remove('groups'); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | $out[$this->primary_key] = self::dn_encode($rec['dn']); |
| | | |
| | | // determine record type |
| | | if (self::is_group_entry($rec)) { |
| | | if ($this->is_group_entry($rec)) { |
| | | $out['_type'] = 'group'; |
| | | $out['readonly'] = true; |
| | | $fieldmap['name'] = $this->group_data['name_attr'] ? $this->group_data['name_attr'] : $this->prop['groups']['name_attr']; |
| | | } |
| | | |
| | | // assign object type from object class mapping |
| | | if (!empty($this->prop['class_type_map'])) { |
| | | foreach (array_map('strtolower', (array)$rec['objectclass']) as $objcls) { |
| | | if (!empty($this->prop['class_type_map'][$objcls])) { |
| | | $out['_type'] = $this->prop['class_type_map'][$objcls]; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | foreach ($fieldmap as $rf => $lf) |
| | |
| | | /** |
| | | * Determines whether the given LDAP entry is a group record |
| | | */ |
| | | private static function is_group_entry($entry) |
| | | private function is_group_entry($entry) |
| | | { |
| | | $classes = array_map('strtolower', (array)$entry['objectclass']); |
| | | |
| | |
| | | // special case: list groups from 'group_filters' config |
| | | if ($vlv_page === null && !empty($this->prop['group_filters'])) { |
| | | $groups = array(); |
| | | $rcube = rcube::get_instance(); |
| | | |
| | | // list regular groups configuration as special filter |
| | | if (!empty($this->prop['groups']['filter'])) { |
| | | $id = '__groups__'; |
| | | $groups[$id] = array('ID' => $id, 'name' => rcube_label('groups'), 'virtual' => true) + $this->prop['groups']; |
| | | $groups[$id] = array('ID' => $id, 'name' => $rcube->gettext('groups'), 'virtual' => true) + $this->prop['groups']; |
| | | } |
| | | |
| | | foreach ($this->prop['group_filters'] as $id => $prop) { |