From e019f2d0f2dc2fbfa345ab5d7ae85e67bfdd76b8 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sat, 25 Sep 2010 09:03:53 -0400
Subject: [PATCH] - s/RoundCube/Roundcube/

---
 program/steps/addressbook/delete.inc |   86 ++++++++----------------------------------
 1 files changed, 17 insertions(+), 69 deletions(-)

diff --git a/program/steps/addressbook/delete.inc b/program/steps/addressbook/delete.inc
index 789d841..08ae36d 100644
--- a/program/steps/addressbook/delete.inc
+++ b/program/steps/addressbook/delete.inc
@@ -4,8 +4,8 @@
  +-----------------------------------------------------------------------+
  | program/steps/addressbook/delete.inc                                  |
  |                                                                       |
- | This file is part of the RoundCube Webmail client                     |
- | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
+ | This file is part of the Roundcube Webmail client                     |
+ | Copyright (C) 2005-2009, Roundcube Dev. - Switzerland                 |
  | Licensed under the GNU GPL                                            |
  |                                                                       |
  | PURPOSE:                                                              |
@@ -19,86 +19,34 @@
 
 */
 
-$REMOTE_REQUEST = TRUE;
+if ($OUTPUT->ajax_call &&
+    ($cid = get_input_value('_cid', RCUBE_INPUT_POST)) &&
+    preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid)
+) {
+  $plugin = $RCMAIL->plugins->exec_hook('contact_delete', array('id' => $cid, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
 
-if ($_GET['_cid'])
-  {
-  $DB->query(sprintf("UPDATE %s
-                      SET    del='1'
-                      WHERE  user_id=%d
-                      AND    contact_id IN (%s)",
-                     get_table_name('contacts'),
-                     $_SESSION['user_id'],
-                     $_GET['_cid']));
-                     
-  $count = $DB->affected_rows();
-  if (!$count)
+  $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid) : false;
+  if (!$deleted)
     {
     // send error message
     exit;
     }
 
-
   // 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'];    
+  $result = $CONTACTS->count();
 
   // 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);
-
+  $OUTPUT->set_env('pagecount', ceil($result->count / $CONTACTS->page_size));
+  $OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result->count));
 
   // add new rows from next page (if any)
-  if ($_GET['_from']!='show' && $pages>1 && $_SESSION['page'] < $pages)
-    {
-    $start_row = ($_SESSION['page'] * $CONFIG['pagesize']) - $count;
-
-    // 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,
-                                     $count));
-                                     
-    $commands .= rcmail_js_contacts_list($sql_result);
-
-/*
-    // define list of cols to be displayed
-    $a_show_cols = array('name', 'email');
-    
-    while ($sql_arr = $DB->fetch_assoc($sql_result))
-      {
-      $a_row_cols = array();
-            
-      // format each col
-      foreach ($a_show_cols as $col)
-        {
-        $cont = rep_specialchars_output($sql_arr[$col]);
-        $a_row_cols[$col] = $cont;
-        }
-  
-      $commands .= sprintf("this.add_contact_row(%s, %s);\n",
-                           $sql_arr['contact_id'],
-                           array2js($a_row_cols));
-      }
-*/
-    }
+  $pages = ceil(($result->count + $deleted) / $CONTACTS->page_size);
+  if ($_GET['_from'] != 'show' && $pages > 1 && $CONTACTS->list_page < $pages)
+    rcmail_js_contacts_list($CONTACTS->list_records(null, -$deleted));
 
   // send response
-  rcube_remote_response($commands);
+  $OUTPUT->send();
   }
 
 exit;
-?>
\ No newline at end of file
+

--
Gitblit v1.9.1