| | |
| | | <?php |
| | | |
| | | /* |
| | | /** |
| | | +-----------------------------------------------------------------------+ |
| | | | This file is part of the Roundcube Webmail client | |
| | | | Copyright (C) 2006-2013, The Roundcube Dev Team | |
| | |
| | | $this->_connect(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Establish a connection to the LDAP server |
| | | */ |
| | | * Establish a connection to the LDAP server |
| | | */ |
| | | private function _connect() |
| | | { |
| | | $rcube = rcube::get_instance(); |
| | |
| | | } |
| | | |
| | | // Get the pieces needed for variable replacement. |
| | | if ($fu = $rcube->get_user_email()) |
| | | if ($fu = $rcube->get_user_email()) { |
| | | list($u, $d) = explode('@', $fu); |
| | | else |
| | | } |
| | | else { |
| | | $d = $this->mail_domain; |
| | | } |
| | | |
| | | $dc = 'dc='.strtr($d, array('.' => ',dc=')); // hierarchal domain string |
| | | |
| | | // resolve $dc through LDAP |
| | | if (!empty($this->prop['domain_filter']) && !empty($this->prop['search_bind_dn']) && |
| | | method_exists($this->ldap, 'domain_root_dn')) { |
| | | $this->ldap->bind($this->prop['search_bind_dn'], $this->prop['search_bind_pw']); |
| | | $dc = $this->ldap->domain_root_dn($d); |
| | | } |
| | | |
| | | $replaces = array('%dn' => '', '%dc' => $dc, '%d' => $d, '%fu' => $fu, '%u' => $u); |
| | | |
| | |
| | | return $this->ready; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Close connection to LDAP server |
| | | */ |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Returns address book name |
| | | * |
| | |
| | | { |
| | | return $this->prop['name']; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Set internal list page |
| | |
| | | $this->ldap->set_vlv_page($this->list_page, $this->page_size); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Set internal sort settings |
| | | * |
| | |
| | | $this->sort_col = $this->coltypes[$sort_col]['attributes'][0]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Save a search string for future listings |
| | | * |
| | |
| | | { |
| | | $this->filter = $filter; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Getter for saved search properties |
| | |
| | | return $this->filter; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Reset all saved results and search parameters |
| | | */ |
| | |
| | | $this->filter = ''; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * List the current set of contact records |
| | | * |
| | | * @param array List of cols to show |
| | | * @param int Only return this number of records |
| | | * @param array List of cols to show |
| | | * @param int Only return this number of records |
| | | * |
| | | * @return array Indexed list of contact records, each a hash array |
| | | * @return array Indexed list of contact records, each a hash array |
| | | */ |
| | | function list_records($cols=null, $subset=0) |
| | | { |
| | |
| | | return strcmp($a[$this->sort_col][0], $b[$this->sort_col][0]); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Search contacts |
| | | * |
| | |
| | | return $this->result; |
| | | } |
| | | |
| | | // use AND operator for advanced searches |
| | | $filter = is_array($value) ? '(&' : '(|'; |
| | | // set wildcards |
| | | $wp = $ws = ''; |
| | | if (!empty($this->prop['fuzzy_search']) && $mode != 1) { |
| | | $ws = '*'; |
| | | if (!$mode) { |
| | | $wp = '*'; |
| | | } |
| | | } |
| | | // advanced per-attribute search |
| | | if (is_array($value)) { |
| | | // use AND operator for advanced searches |
| | | $filter = '(&'; |
| | | |
| | | if ($fields == '*') { |
| | | // search_fields are required for fulltext search |
| | | if (empty($this->prop['search_fields'])) { |
| | | $this->set_error(self::ERROR_SEARCH, 'nofulltextsearch'); |
| | | $this->result = new rcube_result_set(); |
| | | return $this->result; |
| | | } |
| | | if (is_array($this->prop['search_fields'])) { |
| | | foreach ($this->prop['search_fields'] as $field) { |
| | | $filter .= "($field=$wp" . rcube_ldap_generic::quote_string($value) . "$ws)"; |
| | | // set wildcards |
| | | $wp = $ws = ''; |
| | | if (!empty($this->prop['fuzzy_search']) && $mode != 1) { |
| | | $ws = '*'; |
| | | if (!$mode) { |
| | | $wp = '*'; |
| | | } |
| | | } |
| | | } |
| | | else { |
| | | |
| | | foreach ((array)$fields as $idx => $field) { |
| | | $val = is_array($value) ? $value[$idx] : $value; |
| | | $val = $value[$idx]; |
| | | if (!strlen($val)) |
| | | continue; |
| | | if ($attrs = $this->_map_field($field)) { |
| | | if (count($attrs) > 1) |
| | | $filter .= '(|'; |
| | |
| | | $filter .= ')'; |
| | | } |
| | | } |
| | | |
| | | $filter .= ')'; |
| | | } |
| | | $filter .= ')'; |
| | | else { |
| | | if ($fields == '*') { |
| | | // search_fields are required for fulltext search |
| | | if (empty($this->prop['search_fields'])) { |
| | | $this->set_error(self::ERROR_SEARCH, 'nofulltextsearch'); |
| | | $this->result = new rcube_result_set(); |
| | | return $this->result; |
| | | } |
| | | $attributes = (array)$this->prop['search_fields']; |
| | | } |
| | | else { |
| | | // map address book fields into ldap attributes |
| | | $me = $this; |
| | | $attributes = array(); |
| | | array_walk((array) $fields, function($field) use ($me, &$attributes) { |
| | | if ($me->coltypes[$field] && ($attrs = (array)$me->coltypes[$field]['attributes'])) { |
| | | $attributes = array_merge($attributes, $attrs); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // compose a full-text-like search filter |
| | | $filter = rcube_ldap_generic::fulltext_search_filter($value, $attributes, $mode); |
| | | } |
| | | |
| | | // add required (non empty) fields filter |
| | | $req_filter = ''; |
| | |
| | | return $this->result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Count number of available contacts in database |
| | | * |
| | |
| | | |
| | | return new rcube_result_set($count, ($this->list_page-1) * $this->page_size); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return the last result set |
| | |
| | | |
| | | return $err; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Check the given data before saving. |
| | |
| | | return true; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Create a new contact record |
| | | * |
| | |
| | | |
| | | return $dn; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Update a specific contact record |
| | |
| | | return $newdn ? $newdn : true; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Mark one or more contact records as deleted |
| | | * |
| | |
| | | |
| | | return count($ids); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Remove all contact records |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Converts LDAP entry into an array |
| | | */ |
| | |
| | | return $out; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return LDAP attribute(s) for the given field |
| | | */ |
| | |
| | | { |
| | | return (array)$this->coltypes[$field]['attributes']; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Convert a record data set into LDAP field attributes |
| | |
| | | return $default; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * HTML-safe DN string encoding |
| | | * |
| | |
| | | $str = str_pad(strtr($str, '-_', '+/'), strlen($str) % 4, '=', STR_PAD_RIGHT); |
| | | return base64_decode($str); |
| | | } |
| | | |
| | | } |