Ignore:
Timestamp:
Jun 14, 2011 9:45:26 AM (2 years ago)
Author:
alec
Message:
  • Added searching in all addressbook sources (global-search)
  • Added addressbook source selection in contacts import
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/steps/addressbook/export.inc

    r4752 r4850  
    77 | This file is part of the Roundcube Webmail client                     | 
    88 | Copyright (C) 2008-2011, The Roundcube Dev Team                       | 
     9 | Copyright (C) 2011, Kolab Systems AG                                  | 
    910 | Licensed under the GNU GPL                                            | 
    1011 |                                                                       | 
     
    1415 +-----------------------------------------------------------------------+ 
    1516 | Author: Thomas Bruederli <roundcube@gmail.com>                        | 
     17 | Author: Aleksander Machniak <machniak@kolabsys.com>                   | 
    1618 +-----------------------------------------------------------------------+ 
    1719 
    18  $Id$ 
     20 $Id$ 
    1921 
    2022*/ 
    2123 
    22 // get contacts for this user 
    23 $CONTACTS->set_page(1); 
    24 $CONTACTS->set_pagesize(99999); 
    25 $result = $CONTACTS->list_records(null, 0, true); 
     24// Use search result 
     25if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']])) 
     26{ 
     27    $search  = (array)$_SESSION['search'][$_REQUEST['_search']]; 
     28    $records = array(); 
     29 
     30    // Get records from all sources 
     31    foreach ($search as $s => $set) { 
     32        $source = $RCMAIL->get_address_book($s); 
     33 
     34        // reset page 
     35        $source->set_page(1); 
     36        $source->set_pagesize(99999); 
     37        $source->set_search_set($set); 
     38 
     39        // get records 
     40        $result = $source->list_records(); 
     41 
     42        while ($row = $result->next()) { 
     43            $row['sourceid'] = $s; 
     44            $key = $row['name'] . ':' . $row['sourceid']; 
     45            $records[$key] = $row; 
     46        } 
     47        unset($result); 
     48    } 
     49 
     50    // sort the records 
     51    ksort($records, SORT_LOCALE_STRING); 
     52 
     53    // create resultset object 
     54    $count  = count($records); 
     55    $result = new rcube_result_set($count); 
     56    $result->records = array_values($records); 
     57} 
     58// selected directory/group 
     59else { 
     60    $CONTACTS = rcmail_contact_source(null, true); 
     61 
     62    // get contacts for this user 
     63    $CONTACTS->set_page(1); 
     64    $CONTACTS->set_pagesize(99999); 
     65    $result = $CONTACTS->list_records(null, 0, true); 
     66} 
    2667 
    2768// send downlaod headers 
     
    3172 
    3273while ($result && ($row = $result->next())) { 
    33   // we already have a vcard record 
    34   if ($row['vcard'] && $row['name']) { 
    35     echo rcube_vcard::rfc2425_fold($row['vcard']) . "\n"; 
    36   } 
    37   // copy values into vcard object 
    38   else { 
    39     $vcard = new rcube_vcard($row['vcard']); 
    40     $vcard->reset(); 
    41     foreach ($row as $key => $values) { 
    42       list($field, $section) = explode(':', $key); 
    43       foreach ((array)$values as $value) { 
    44         if (is_array($value) || strlen($value)) 
    45           $vcard->set($field, $value, strtoupper($section)); 
    46       } 
     74    // we already have a vcard record 
     75    if ($row['vcard'] && $row['name']) { 
     76        echo rcube_vcard::rfc2425_fold($row['vcard']) . "\n"; 
    4777    } 
     78    // copy values into vcard object 
     79    else { 
     80        $vcard = new rcube_vcard($row['vcard']); 
     81        $vcard->reset(); 
    4882 
    49     echo $vcard->export(true) . "\n"; 
    50   } 
     83        foreach ($row as $key => $values) { 
     84            list($field, $section) = explode(':', $key); 
     85            foreach ((array)$values as $value) { 
     86                if (is_array($value) || strlen($value)) 
     87                    $vcard->set($field, $value, strtoupper($section)); 
     88            } 
     89        } 
     90 
     91        echo $vcard->export(true) . "\n"; 
     92    } 
    5193} 
    5294 
    5395exit; 
    54  
Note: See TracChangeset for help on using the changeset viewer.