From 63fda8af57a285020dc094adcf6eeb46bee1c2d5 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Fri, 08 Jul 2011 09:03:42 -0400
Subject: [PATCH] - Make Undo action optional by setting undo_timeout=0

---
 program/include/rcube_addressbook.php |    3 ++-
 program/include/rcube_ldap.php        |    5 +++--
 program/steps/addressbook/func.inc    |    5 +++--
 program/steps/addressbook/delete.inc  |    9 +++++----
 config/main.inc.php.dist              |    5 +++++
 program/include/rcube_contacts.php    |   17 +++++++++--------
 6 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 56e5a79..71c2380 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -442,6 +442,11 @@
 // or any integer value indicating number of seconds.
 $rcmail_config['upload_progress'] = false;
 
+// Specifies for how many seconds the Undo button will be available
+// after object delete action. Currently used with supporting address book sources.
+// Setting it to 0, disables the feature.
+$rcmail_config['undo_timeout'] = 0;
+
 // ----------------------------------
 // ADDRESSBOOK SETTINGS
 // ----------------------------------
diff --git a/program/include/rcube_addressbook.php b/program/include/rcube_addressbook.php
index 3581b83..45ad0be 100644
--- a/program/include/rcube_addressbook.php
+++ b/program/include/rcube_addressbook.php
@@ -250,8 +250,9 @@
      * Mark one or more contact records as deleted
      *
      * @param array  Record identifiers
+     * @param bool   Remove records irreversible (see self::undelete)
      */
-    function delete($ids)
+    function delete($ids, $force=true)
     {
         /* empty for read-only address books */
     }
diff --git a/program/include/rcube_contacts.php b/program/include/rcube_contacts.php
index 52667fa..799d596 100644
--- a/program/include/rcube_contacts.php
+++ b/program/include/rcube_contacts.php
@@ -604,13 +604,13 @@
 
         return $updated;
     }
-    
-    
+
+
     private function convert_db_data($sql_arr)
     {
         $record = array();
         $record['ID'] = $sql_arr[$this->primary_key];
-        
+
         if ($sql_arr['vcard']) {
             unset($sql_arr['email']);
             $vcard = new rcube_vcard($sql_arr['vcard']);
@@ -620,7 +620,7 @@
             $record += $sql_arr;
             $record['email'] = preg_split('/,\s*/', $record['email']);
         }
-        
+
         return $record;
     }
 
@@ -668,16 +668,17 @@
     /**
      * Mark one or more contact records as deleted
      *
-     * @param array  Record identifiers
+     * @param array   Record identifiers
+     * @param boolean Remove record(s) irreversible (unsupported)
      */
-    function delete($ids)
+    function delete($ids, $force=true)
     {
         if (!is_array($ids))
             $ids = explode(',', $ids);
 
         $ids = $this->db->array2list($ids, 'integer');
 
-        // flag record as deleted
+        // flag record as deleted (always)
         $this->db->query(
             "UPDATE ".get_table_name($this->db_name).
             " SET del=1, changed=".$this->db->now().
@@ -704,7 +705,7 @@
 
         $ids = $this->db->array2list($ids, 'integer');
 
-        // flag record as deleted
+        // clear deleted flag
         $this->db->query(
             "UPDATE ".get_table_name($this->db_name).
             " SET del=0, changed=".$this->db->now().
diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php
index 4ea4f60..4205df2 100644
--- a/program/include/rcube_ldap.php
+++ b/program/include/rcube_ldap.php
@@ -834,11 +834,12 @@
     /**
      * Mark one or more contact records as deleted
      *
-     * @param array  Record identifiers
+     * @param array   Record identifiers
+     * @param boolean Remove record(s) irreversible (unsupported)
      *
      * @return boolean True on success, False on error
      */
-    function delete($ids)
+    function delete($ids, $force=true)
     {
         if (!is_array($ids)) {
             // Not an array, break apart the encoded DNs.
diff --git a/program/steps/addressbook/delete.inc b/program/steps/addressbook/delete.inc
index f11752b..b0b255e 100644
--- a/program/steps/addressbook/delete.inc
+++ b/program/steps/addressbook/delete.inc
@@ -27,6 +27,7 @@
 $delcnt = 0;
 
 // remove previous deletes
+$undo_time = $RCMAIL->config->get('undo_timeout', 0);
 $RCMAIL->session->remove('contact_undo');
 
 foreach ($cids as $source => $cid)
@@ -47,7 +48,7 @@
     $plugin = $RCMAIL->plugins->exec_hook('contact_delete', array(
         'id' => $cid, 'source' => $source));
 
-    $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid) : $plugin['result'];
+    $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid, $undo_time < 1) : $plugin['result'];
 
     if (!$deleted) {
         $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'contactdelerror', 'error');
@@ -57,8 +58,8 @@
     else {
         $delcnt += $deleted;
 
-        // store deleted contacts IDs in session for undelete
-        if ($CONTACTS->undelete) {
+        // store deleted contacts IDs in session for undo action
+        if ($undo_time > 0 && $CONTACTS->undelete) {
             $_SESSION['contact_undo']['data'][$source] = $cid;
         }
     }
@@ -147,7 +148,7 @@
     $msg = html::span(null, rcube_label(array('name' => 'itemsdeleted', 'vars' => array('num' => $deleted))))
         . ' ' . html::a(array('onclick' => JS_OBJECT_NAME.".command('undo', '', this)"), rcube_label('undo'));
 
-    $OUTPUT->show_message($msg, 'confirmation', null, true, $RCMAIL->config->get('undo_timeout', 15));
+    $OUTPUT->show_message($msg, 'confirmation', null, true, $undo_time);
 }
 else {
     $OUTPUT->show_message('contactdeleted', 'confirmation');
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index a895b61..62c61ec 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -90,8 +90,9 @@
 
 // remove undo information...
 if ($undo = $_SESSION['contact_undo']) {
-    // ...after 30 seconds
-    if ($undo['ts'] < time() - 30)
+    // ...after timeout
+    $undo_time = $RCMAIL->config->get('undo_timeout', 0);
+    if ($undo['ts'] < time() - $undo_time)
         $RCMAIL->session->remove('contact_undo');
 }
 

--
Gitblit v1.9.1