summaryrefslogtreecommitdiff
path: root/program/steps/addressbook/list.inc
blob: 87ac888dee3b5538ae55a7e1b79ff1d4b1d03bc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php

/*
 +-----------------------------------------------------------------------+
 | program/steps/addressbook/list.inc                                    |
 |                                                                       |
 | This file is part of the RoundCube Webmail client                     |
 | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
 | All rights reserved.                                                  |
 |                                                                       |
 | PURPOSE:                                                              |
 |   Send contacts list to client (as remote response)                   |
 |                                                                       |
 +-----------------------------------------------------------------------+
 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
 +-----------------------------------------------------------------------+

 $Id$

*/

$REMOTE_REQUEST = TRUE;

// count contacts for this user
$sql_result = $DB->query(sprintf("SELECT COUNT(contact_id) AS rows
                                  FROM   %s
                                  WHERE  del!='1'
                                  AND    user_id=%d",
                                 get_table_name('contacts'),
                                 $_SESSION['user_id']));
                                   
$sql_arr = $DB->fetch_assoc($sql_result);
$rowcount = $sql_arr['rows'];    

// update message count display
$pages = ceil($rowcount/$CONFIG['pagesize']);
$commands = sprintf("this.set_rowcount('%s');\n", rcmail_get_rowcount_text($rowcount));
$commands .= sprintf("this.set_env('pagecount', %d);\n", $pages);

$start_row = ($CONTACTS_LIST['page']-1) * $CONFIG['pagesize'];

// get contacts from DB
$sql_result = $DB->query(sprintf("SELECT * FROM %s
                                  WHERE  del!='1'
                                  AND    user_id=%d
                                  ORDER BY name
                                  LIMIT %d, %d",
                                 get_table_name('contacts'),
                                 $_SESSION['user_id'],
                                 $start_row,
                                 $CONFIG['pagesize']));
                                 
$commands .= rcmail_js_contacts_list($sql_result);
  
// send response
rcube_remote_response($commands);

exit;
?>