source: subversion/trunk/roundcubemail/program/steps/mail/list_contacts.inc @ 5787

Last change on this file since 5787 was 5787, checked in by thomasb, 17 months ago

Changed license to GNU GPLv3+ with exceptions for skins and plugins

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date Author Revision
File size: 3.8 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/mail/list_contacts.inc                                  |
6 |                                                                       |
7 | This file is part of the Roundcube Webmail client                     |
8 | Copyright (C) 2012, The Roundcube Dev Team                            |
9 |                                                                       |
10 | Licensed under the GNU General Public License version 3 or            |
11 | any later version with exceptions for skins & plugins.                |
12 | See the README file for a full license statement.                     |
13 |                                                                       |
14 | PURPOSE:                                                              |
15 |   Send contacts list to client (as remote response)                   |
16 |                                                                       |
17 +-----------------------------------------------------------------------+
18 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19 +-----------------------------------------------------------------------+
20
21 $Id$
22
23*/
24
25$jsenv = array();
26$source = get_input_value('_source', RCUBE_INPUT_GPC);
27$CONTACTS = $RCMAIL->get_address_book($source);
28$PAGE_SIZE = $RCMAIL->config->get('addressbook_pagesize', $RCMAIL->config->get('pagesize', 50));
29
30if ($CONTACTS && $CONTACTS->ready) {
31    // set list properties
32    $CONTACTS->set_pagesize($PAGE_SIZE);
33    $CONTACTS->set_page(max(1, intval($_GET['_page'])));
34
35    // list groups of this source (on page one)
36    if ($CONTACTS->groups && $CONTACTS->list_page == 1) {
37        foreach ($CONTACTS->list_groups() as $group) {
38            $CONTACTS->reset();
39            $CONTACTS->set_group($group['ID']);
40            $group_prop = $CONTACTS->get_group($group['ID']);
41
42            // group (distribution list) with email address(es)
43            if ($group_prop['email']) {
44                foreach ((array)$group_prop['email'] as $email) {
45                    $row_id = 'G'.$group['ID'];
46                    $jsresult[$row_id] = format_email_recipient($email, $group['name']);
47                    $OUTPUT->command('add_contact_row', $row_id, array(
48                        'contactgroup' => html::span(array('title' => $email), Q($group['name']))));
49                }
50            }
51            // show group with count
52            else if (($result = $CONTACTS->count()) && $result->count) {
53                $row_id = 'E'.$group['ID'];
54                $jsresult[$row_id] = $group['name'];
55                $OUTPUT->command('add_contact_row', $row_id, array(
56                    'contactgroup' => Q($group['name'] . ' (' . intval($result->count) . ')')));
57            }
58        }
59    }
60
61    // get contacts for this user
62    $CONTACTS->set_group(0);
63    $result = $CONTACTS->list_records(array('name', 'email'));
64
65    if (!$result->count && $result->searchonly) {
66        $OUTPUT->show_message('contactsearchonly', 'notice');
67    }
68    else if (!empty($result) && $result->count > 0) {
69        // create javascript list
70        while ($row = $result->next()) {
71            $name = rcube_addressbook::compose_display_name($row, true);
72
73            // add record for every email address of the contact
74            foreach ($CONTACTS->get_col_values('email', $row, true) as $i => $email) {
75                $row_id = $row['ID'].$i;
76                $jsresult[$row_id] = format_email_recipient($email, $name);
77                $OUTPUT->command('add_contact_row', $row_id, array(
78                    'contact' => html::span(array('title' => $email), Q($name ? $name : $email))));
79            }
80        }
81    }
82}
83
84// update env
85$OUTPUT->set_env('contactdata', $jsresult);
86$OUTPUT->set_env('pagecount', ceil($result->count / $PAGE_SIZE));
87$OUTPUT->command('set_page_buttons');
88
89// send response
90$OUTPUT->send();
Note: See TracBrowser for help on using the repository browser.