Changeset a605b25 in github


Ignore:
Timestamp:
May 2, 2012 4:56:29 PM (14 months ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo
Children:
24f1bf0
Parents:
ad31a69
Message:
  • Allow to configure the number of values allowed for each LDAP attribute
  • Support for serialized LDAP address values (usually delimited with a $)
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • config/main.inc.php.dist

    rb563fc8 ra605b25  
    581581  'required_fields' => array('cn', 'sn', 'mail'), 
    582582  'search_fields'   => array('mail', 'cn'),  // fields to search in 
    583   // Map of contact sub-objects (attribute name => objectClass(es)), e.g. 'c' => 'country' 
    584   'sub_fields' => array(), 
    585583  // mapping of contact fields to directory attributes 
     584  //   for every attribute one can specify the number of values (limit) allowed. 
     585  //   default is 1, a wildcard * means unlimited 
    586586  'fieldmap' => array( 
    587     // Roundcube  => LDAP 
     587    // Roundcube  => LDAP:limit 
    588588    'name'        => 'cn', 
    589589    'surname'     => 'sn', 
    590590    'firstname'   => 'givenName', 
    591591    'title'       => 'title', 
    592     'email'       => 'mail', 
     592    'email'       => 'mail:*', 
    593593    'phone:home'  => 'homePhone', 
    594594    'phone:work'  => 'telephoneNumber', 
     
    599599    'region'      => 'st', 
    600600    'locality'    => 'l', 
    601 // if you uncomment country, you need to modify 'sub_fields' above 
    602 //    'country'     => 'c', 
     601    // if you country is a complex object, you need to configure 'sub_fields' below 
     602    'country'      => 'c', 
    603603    'organization' => 'o', 
    604     'department'  => 'departmentNumber', 
    605     'notes'       => 'description', 
    606 // these currently don't work: 
    607 //    'phone:workfax' => 'facsimileTelephoneNumber', 
    608 //    'photo'        => 'jpegPhoto', 
    609 //    'manager'      => 'manager', 
    610 //    'assistant'    => 'secretary', 
     604    'department'   => 'ou', 
     605    'jobtitle'     => 'title', 
     606    'notes'        => 'description', 
     607    // these currently don't work: 
     608    // 'phone:workfax' => 'facsimileTelephoneNumber', 
     609    // 'photo'         => 'jpegPhoto', 
     610    // 'manager'       => 'manager', 
     611    // 'assistant'     => 'secretary', 
    611612  ), 
     613  // Map of contact sub-objects (attribute name => objectClass(es)), e.g. 'c' => 'country' 
     614  'sub_fields' => array(), 
    612615  'sort'          => 'cn',    // The field to sort the listing by. 
    613616  'scope'         => 'sub',   // search mode: sub|base|list 
  • program/include/rcube_ldap.php

    rbe98dfc2 ra605b25  
    103103 
    104104        // use fieldmap to advertise supported coltypes to the application 
    105         foreach ($this->fieldmap as $col => $lf) { 
    106             list($col, $type) = explode(':', $col); 
     105        foreach ($this->fieldmap as $colv => $lfv) { 
     106            list($col, $type) = explode(':', $colv); 
     107            list($lf, $limit, $delim) = explode(':', $lfv); 
     108 
     109            if ($limit == '*') $limit = null; 
     110            else               $limit = max(1, intval($limit)); 
     111 
    107112            if (!is_array($this->coltypes[$col])) { 
    108113                $subtypes = $type ? array($type) : null; 
    109                 $this->coltypes[$col] = array('limit' => 1, 'subtypes' => $subtypes); 
     114                $this->coltypes[$col] = array('limit' => $limit, 'subtypes' => $subtypes); 
    110115            } 
    111116            elseif ($type) { 
    112117                $this->coltypes[$col]['subtypes'][] = $type; 
    113                 $this->coltypes[$col]['limit']++; 
    114             } 
     118                $this->coltypes[$col]['limit'] += $limit; 
     119            } 
     120 
     121            if ($delim) 
     122               $this->coltypes[$col]['serialized'][$type] = $delim; 
     123 
    115124            if ($type && !$this->fieldmap[$col]) 
    116                 $this->fieldmap[$col] = $lf; 
     125               $this->fieldmap[$col] = $lf; 
     126 
     127            $this->fieldmap[$colv] = $lf; 
    117128        } 
    118129 
    119130        // support for composite address 
    120131        if ($this->fieldmap['street'] && $this->fieldmap['locality']) { 
    121             $this->coltypes['address'] = array('limit' => max(1, $this->coltypes['locality']['limit']), 'subtypes' => $this->coltypes['locality']['subtypes'], 'childs' => array()); 
     132            $this->coltypes['address'] = array( 
     133               'limit'    => max(1, $this->coltypes['locality']['limit'] + $this->coltypes['address']['limit']), 
     134               'subtypes' => array_merge((array)$this->coltypes['address']['subtypes'], $this->coltypes['locality']['subtypes']), 
     135               'childs' => array(), 
     136               ) + (array)$this->coltypes['address']; 
     137 
    122138            foreach (array('street','locality','zipcode','region','country') as $childcol) { 
    123139                if ($this->fieldmap[$childcol]) { 
     
    11821198            } // end if 
    11831199        } // end foreach 
    1184 /* 
    1185         console($old_data); 
    1186         console($ldap_data); 
    1187         console('----'); 
    1188         console($newdata); 
    1189         console($replacedata); 
    1190         console($deletedata); 
    1191         console('----'); 
    1192         console($subdata); 
    1193         console($subnewdata); 
    1194         console($subdeldata); 
    1195 */ 
     1200 
     1201        // console($old_data, $ldap_data, '----', $newdata, $replacedata, $deletedata, '----', $subdata, $subnewdata, $subdeldata); 
     1202 
    11961203        $dn = self::dn_decode($id); 
    11971204 
     
    14811488                else if (in_array($col, array('street','zipcode','locality','country','region'))) 
    14821489                    $out['address'.($subtype?':':'').$subtype][$i][$col] = $value; 
     1490                else if ($col == 'address' && strpos($value, '$') !== false)  // address data is represented as string separated with $ 
     1491                    list($out[$rf][$i]['street'], $out[$rf][$i]['locality'], $out[$rf][$i]['zipcode'], $out[$rf][$i]['country']) = explode('$', $value); 
    14831492                else if ($rec[$lf]['count'] > 1) 
    14841493                    $out[$rf][] = $value; 
     
    15231532                } 
    15241533            } 
     1534 
     1535            // if addresses are to be saved as serialized string, do so 
     1536            if (is_array($colprop['serialized'])) { 
     1537               foreach ($colprop['serialized'] as $subtype => $delim) { 
     1538                  $key = $col.':'.$subtype; 
     1539                  foreach ((array)$save_cols[$key] as $i => $val) 
     1540                     $save_cols[$key][$i] = join($delim, array($val['street'], $val['locality'], $val['zipcode'], $val['country'])); 
     1541               } 
     1542            } 
    15251543        } 
    15261544 
     
    15431561     * Returns unified attribute name (resolving aliases) 
    15441562     */ 
    1545     private static function _attr_name($name) 
     1563    private static function _attr_name($namev) 
    15461564    { 
    15471565        // list of known attribute aliases 
    1548         $aliases = array( 
     1566        static $aliases = array( 
    15491567            'gn' => 'givenname', 
    15501568            'rfc822mailbox' => 'email', 
     
    15531571            'pkcs9email' => 'email', 
    15541572        ); 
    1555         return isset($aliases[$name]) ? $aliases[$name] : $name; 
     1573 
     1574        list($name, $limit) = explode(':', $namev, 2); 
     1575        $suffix = $limit ? ':'.$limit : ''; 
     1576 
     1577        return (isset($aliases[$name]) ? $aliases[$name] : $name) . $suffix; 
    15561578    } 
    15571579 
Note: See TracChangeset for help on using the changeset viewer.