thomascube
2006-08-30 107bde9cfd9a0392d18544b5a433552ce6f2f0a6
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/addressbook/delete.inc                                  |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8  | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
30233b 9  | Licensed under the GNU GPL                                            |
4e17e6 10  |                                                                       |
T 11  | PURPOSE:                                                              |
12  |   Delete the submitted contacts (CIDs) from the users address book    |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id$
19
20 */
21
22 $REMOTE_REQUEST = TRUE;
23
24 if ($_GET['_cid'])
25   {
d7cb77 26   $DB->query("UPDATE ".get_table_name('contacts')."
1cded8 27               SET    del=1
d7cb77 28               WHERE  user_id=?
S 29               AND    contact_id IN (".$_GET['_cid'].")",
30               $_SESSION['user_id']);
4e17e6 31                      
T 32   $count = $DB->affected_rows();
33   if (!$count)
34     {
35     // send error message
36     exit;
37     }
38
39
40   // count contacts for this user
d7cb77 41   $sql_result = $DB->query("SELECT COUNT(contact_id) AS rows
S 42                             FROM ".get_table_name('contacts')."
1cded8 43                             WHERE  del<>1
d7cb77 44                             AND    user_id=?",
S 45                             $_SESSION['user_id']);
4e17e6 46                                    
T 47   $sql_arr = $DB->fetch_assoc($sql_result);
48   $rowcount = $sql_arr['rows'];    
49
50   // update message count display
51   $pages = ceil($rowcount/$CONFIG['pagesize']);
52   $commands = sprintf("this.set_rowcount('%s');\n", rcmail_get_rowcount_text($rowcount));
53   $commands .= sprintf("this.set_env('pagecount', %d);\n", $pages);
54
55
56   // add new rows from next page (if any)
57   if ($_GET['_from']!='show' && $pages>1 && $_SESSION['page'] < $pages)
58     {
59     $start_row = ($_SESSION['page'] * $CONFIG['pagesize']) - $count;
60
61     // get contacts from DB
d7cb77 62     $sql_result = $DB->limitquery("SELECT * FROM ".get_table_name('contacts')."
1cded8 63                                    WHERE  del<>1
d7cb77 64                                    AND    user_id=?
S 65                                    ORDER BY name",
66                                    $start_row,
67                                    $count,
68                                    $_SESSION['user_id']);
4e17e6 69                                      
T 70     $commands .= rcmail_js_contacts_list($sql_result);
71
72 /*
73     // define list of cols to be displayed
74     $a_show_cols = array('name', 'email');
75     
76     while ($sql_arr = $DB->fetch_assoc($sql_result))
77       {
78       $a_row_cols = array();
79             
80       // format each col
81       foreach ($a_show_cols as $col)
82         {
83         $cont = rep_specialchars_output($sql_arr[$col]);
84         $a_row_cols[$col] = $cont;
85         }
86   
87       $commands .= sprintf("this.add_contact_row(%s, %s);\n",
88                            $sql_arr['contact_id'],
89                            array2js($a_row_cols));
90       }
91 */
92     }
93
94   // send response
95   rcube_remote_response($commands);
96   }
97
98 exit;
99 ?>