[Svn] r4850 - in trunk/roundcubemail: . config program/js program/localization/en_US program/localization/pl_PL program/steps/addressbook

trac at roundcube.net trac at roundcube.net
Tue Jun 14 15:45:26 CEST 2011


Author: alec
Date: 2011-06-14 08:45:26 -0500 (Tue, 14 Jun 2011)
New Revision: 4850

Modified:
   trunk/roundcubemail/CHANGELOG
   trunk/roundcubemail/config/main.inc.php.dist
   trunk/roundcubemail/program/js/app.js
   trunk/roundcubemail/program/localization/en_US/labels.inc
   trunk/roundcubemail/program/localization/pl_PL/labels.inc
   trunk/roundcubemail/program/steps/addressbook/copy.inc
   trunk/roundcubemail/program/steps/addressbook/delete.inc
   trunk/roundcubemail/program/steps/addressbook/edit.inc
   trunk/roundcubemail/program/steps/addressbook/export.inc
   trunk/roundcubemail/program/steps/addressbook/func.inc
   trunk/roundcubemail/program/steps/addressbook/groups.inc
   trunk/roundcubemail/program/steps/addressbook/import.inc
   trunk/roundcubemail/program/steps/addressbook/list.inc
   trunk/roundcubemail/program/steps/addressbook/mailto.inc
   trunk/roundcubemail/program/steps/addressbook/save.inc
   trunk/roundcubemail/program/steps/addressbook/search.inc
   trunk/roundcubemail/program/steps/addressbook/show.inc
Log:
- Added searching in all addressbook sources (global-search)
- Added addressbook source selection in contacts import


Modified: trunk/roundcubemail/CHANGELOG
===================================================================
--- trunk/roundcubemail/CHANGELOG	2011-06-13 21:33:51 UTC (rev 4849)
+++ trunk/roundcubemail/CHANGELOG	2011-06-14 13:45:26 UTC (rev 4850)
@@ -1,6 +1,8 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Added searching in all addressbook sources
+- Added addressbook source selection in contacts import
 - Implement LDAPv3 Virtual List View (VLV) for paged results listing
 - Use 'address_template' config option when adding a new address block (#1487944)
 - Added addressbook advanced search

Modified: trunk/roundcubemail/config/main.inc.php.dist
===================================================================
--- trunk/roundcubemail/config/main.inc.php.dist	2011-06-13 21:33:51 UTC (rev 4849)
+++ trunk/roundcubemail/config/main.inc.php.dist	2011-06-14 13:45:26 UTC (rev 4850)
@@ -450,6 +450,7 @@
 
 // In order to enable public ldap search, configure an array like the Verisign
 // example further below. if you would like to test, simply uncomment the example.
+// Array key must contain only safe characters, ie. a-zA-Z0-9_
 $rcmail_config['ldap_public'] = array();
 
 // If you are going to use LDAP for individual address books, you will need to 

Modified: trunk/roundcubemail/program/js/app.js
===================================================================
--- trunk/roundcubemail/program/js/app.js	2011-06-13 21:33:51 UTC (rev 4849)
+++ trunk/roundcubemail/program/js/app.js	2011-06-14 13:45:26 UTC (rev 4850)
@@ -336,7 +336,7 @@
         if (this.contact_list && this.contact_list.rowcount > 0)
           this.enable_command('export', true);
 
-        this.enable_command('add', 'import', !this.env.readonly);
+        this.enable_command('add', 'import', this.env.writable_source);
         this.enable_command('list', 'listgroup', 'advanced-search', true);
         break;
 
@@ -529,12 +529,12 @@
           if (this.env.trash_mailbox)
             this.set_alttext('delete', this.env.mailbox != this.env.trash_mailbox ? 'movemessagetotrash' : 'deletemessage');
         }
-        else if (this.task=='addressbook') {
+        else if (this.task == 'addressbook') {
           if (!this.env.search_request || (props != this.env.source))
             this.reset_qsearch();
 
           this.list_contacts(props);
-          this.enable_command('add', 'import', (this.env.address_sources && !this.env.address_sources[this.env.source].readonly));
+          this.enable_command('add', 'import', this.env.writable_source);
         }
         break;
 
@@ -988,8 +988,14 @@
 
         if (s && this.env.mailbox)
           this.list_mailbox(this.env.mailbox);
-        else if (s && this.task == 'addressbook')
+        else if (s && this.task == 'addressbook') {
+          if (this.env.source == '') {
+            for (var n in this.env.address_sources) break;
+            this.env.source = n;
+            this.env.group = '';
+          }
           this.list_contacts(this.env.source, this.env.group);
+        }
         break;
 
       case 'listgroup':
@@ -3651,15 +3657,34 @@
     if (this.preview_timer)
       clearTimeout(this.preview_timer);
 
-    var id, frame, ref = this;
+    var n, id, sid, ref = this, writable = false,
+      source = this.env.source ? this.env.address_sources[this.env.source] : null;
+
     if (id = list.get_single_selection())
       this.preview_timer = window.setTimeout(function(){ ref.load_contact(id, 'show'); }, 200);
     else if (this.env.contentframe)
       this.show_contentframe(false);
 
+    // no source = search result, we'll need to detect if any of
+    // selected contacts are in writable addressbook to enable edit/delete
+    if (list.selection.length) {
+      if (!source) {
+        for (n in list.selection) {
+          sid = String(list.selection[n]).replace(/^[^-]+-/, '');
+          if (sid && this.env.address_sources[sid] && !this.env.address_sources[sid].readonly) {
+            writable = true;
+            break;
+          }
+        }
+      }
+      else {
+        writable = !source.readonly;
+      }
+    }
+
     this.enable_command('compose', list.selection.length > 0);
-    this.enable_command('edit', (id && this.env.address_sources && !this.env.address_sources[this.env.source].readonly) ? true : false);
-    this.enable_command('delete', list.selection.length && this.env.address_sources && !this.env.address_sources[this.env.source].readonly);
+    this.enable_command('edit', id && writable);
+    this.enable_command('delete', list.selection.length && writable);
 
     return false;
   };
@@ -3797,12 +3822,12 @@
     if (!(selection.length || this.env.cid) || !confirm(this.get_label('deletecontactconfirm')))
       return;
 
-    var id, a_cids = [], qs = '';
+    var id, n, a_cids = [], qs = '';
 
     if (this.env.cid)
       a_cids.push(this.env.cid);
     else {
-      for (var n=0; n<selection.length; n++) {
+      for (n=0; n<selection.length; n++) {
         id = selection[n];
         a_cids.push(id);
         this.contact_list.remove_row(id, (n == selection.length-1));
@@ -3817,7 +3842,7 @@
       qs += '&_gid='+urlencode(this.env.group);
 
     // also send search request to get the right records from the next page
-    if (this.env.search_request) 
+    if (this.env.search_request)
       qs += '&_search='+this.env.search_request;
 
     // send request to server
@@ -4119,7 +4144,7 @@
             for (childcol in colprop.childs)
               cols.push(childcol);
           }
-          
+
           for (var i=0; i < cols.length; i++) {
             childcol = cols[i];
             cp = colprop.childs[childcol];
@@ -4241,17 +4266,23 @@
       target = window.frames[this.env.contentframe];
       this.contact_list.clear_selection();
     }
-    else if (framed)
-      return false;
 
-    this.location_href(this.env.comm_path+'&_action=search'+add_url
-      +'&_source='+urlencode(this.env.source)
-      +(this.env.group ? '&_gid='+urlencode(this.env.group) : ''), target);
+    this.location_href(this.env.comm_path+'&_action=search'+add_url, target);
 
     return true;
   };
 
+  // unselect directory/group
+  this.unselect_directory = function()
+  {
+    if (this.env.address_sources.length > 1 || this.env.group != '') {
+      this.select_folder('', (this.env.group ? 'G'+this.env.source+this.env.group : this.env.source));
+      this.env.group = '';
+      this.env.source = '';
+    }
+  };
 
+
   /*********************************************************/
   /*********        user settings methods          *********/
   /*********************************************************/
@@ -5468,9 +5499,20 @@
     switch (response.action) {
       case 'delete':
         if (this.task == 'addressbook') {
-          var uid = this.contact_list.get_selection();
+          var sid, uid = this.contact_list.get_selection(), writable = false;
+
+          if (uid && this.contact_list.rows[uid]) {
+            // search results, get source ID from record ID
+            if (this.env.source == '') {
+              sid = String(uid).replace(/^[^-]+-/, '');
+              writable = sid && this.env.address_sources[sid] && !this.env.address_sources[sid].readonly;
+            }
+            else {
+              writable = !this.env.address_sources[this.env.source].readonly;
+            }
+          }
           this.enable_command('compose', (uid && this.contact_list.rows[uid]));
-          this.enable_command('delete', 'edit', (uid && this.contact_list.rows[uid] && this.env.address_sources && !this.env.address_sources[this.env.source].readonly));
+          this.enable_command('delete', 'edit', writable);
           this.enable_command('export', (this.contact_list && this.contact_list.rowcount > 0));
         }
 
@@ -5519,10 +5561,9 @@
           this.enable_command('export', (this.contact_list && this.contact_list.rowcount > 0));
 
           if (response.action == 'list' || response.action == 'search') {
-            this.enable_command('group-create',
-              (this.env.address_sources[this.env.source].groups && !this.env.address_sources[this.env.source].readonly));
-            this.enable_command('group-rename', 'group-delete',
-              (this.env.address_sources[this.env.source].groups && this.env.group && !this.env.address_sources[this.env.source].readonly));
+            var source = this.env.source != '' ? this.env.address_sources[this.env.source] : null;
+            this.enable_command('group-create', (source && source.groups && !source.readonly));
+            this.enable_command('group-rename', 'group-delete', (source && source.groups && this.env.group && !source.readonly));
             this.triggerEvent('listupdate', { folder:this.env.source, rowcount:this.contact_list.rowcount });
           }
         }
@@ -5580,7 +5621,7 @@
 
     return frame_name;
   };
-  
+
   // starts interval for keep-alive/check-recent signal
   this.start_keepalive = function()
   {

Modified: trunk/roundcubemail/program/localization/en_US/labels.inc
===================================================================
--- trunk/roundcubemail/program/localization/en_US/labels.inc	2011-06-13 21:33:51 UTC (rev 4849)
+++ trunk/roundcubemail/program/localization/en_US/labels.inc	2011-06-14 13:45:26 UTC (rev 4850)
@@ -326,6 +326,7 @@
 $labels['import'] = 'Import';
 $labels['importcontacts'] = 'Import contacts';
 $labels['importfromfile'] = 'Import from file:';
+$labels['importtarget'] = 'Add new contacts to address book:';
 $labels['importreplace'] = 'Replace the entire address book';
 $labels['importtext'] = 'You can upload contacts from an existing address book.<br/>We currently support importing addresses from the <a href="http://en.wikipedia.org/wiki/VCard">vCard</a> data format.';
 $labels['done'] = 'Done';

Modified: trunk/roundcubemail/program/localization/pl_PL/labels.inc
===================================================================
--- trunk/roundcubemail/program/localization/pl_PL/labels.inc	2011-06-13 21:33:51 UTC (rev 4849)
+++ trunk/roundcubemail/program/localization/pl_PL/labels.inc	2011-06-14 13:45:26 UTC (rev 4850)
@@ -413,5 +413,6 @@
 $labels['search'] = 'Szukaj';
 $labels['advsearch'] = 'Wyszukiwanie zaawansowane';
 $labels['other'] = 'Inne';
+$labels['importtarget'] = 'Dodaj nowe kontakty do książki adresowej:';
 
 ?>

Modified: trunk/roundcubemail/program/steps/addressbook/copy.inc
===================================================================
--- trunk/roundcubemail/program/steps/addressbook/copy.inc	2011-06-13 21:33:51 UTC (rev 4849)
+++ trunk/roundcubemail/program/steps/addressbook/copy.inc	2011-06-14 13:45:26 UTC (rev 4850)
@@ -23,75 +23,91 @@
 if (!$OUTPUT->ajax_call)
   return;
 
-$cid = get_input_value('_cid', RCUBE_INPUT_POST);
-$target = get_input_value('_to', RCUBE_INPUT_POST);
+
+$cids         = rcmail_get_cids();
+$target       = get_input_value('_to', RCUBE_INPUT_POST);
 $target_group = get_input_value('_togid', RCUBE_INPUT_POST);
 
-if ($cid && preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid) && strlen($target) && $target !== $source)
+$success = 0;
+$maxnum  = $RCMAIL->config->get('max_group_members', 0);
+
+foreach ($cids as $source => $cid)
 {
-  $success = 0;
-  $TARGET = $RCMAIL->get_address_book($target);
+    // Something wrong, target not specified
+    if (!strlen($target)) {
+        break;
+    }
 
-  if ($TARGET && $TARGET->ready && !$TARGET->readonly) {
-    $arr_cids = explode(',', $cid);
+    // It maight happen when copying records from search result
+    // Do nothing, go to next source
+    if ($target == $source) {
+        continue;
+    }
+
+    $CONTACTS = $RCMAIL->get_address_book($source);
+    $TARGET   = $RCMAIL->get_address_book($target);
+
+    if (!$TARGET || !$TARGET->ready || $TARGET->readonly) {
+        break;
+    }
+
     $ids = array();
 
-    foreach ($arr_cids as $cid) {
-      $a_record = $CONTACTS->get_record($cid, true);
+    foreach ($cid as $cid) {
+        $a_record = $CONTACTS->get_record($cid, true);
 
-      // check if contact exists, if so, we'll need it's ID
-      $result = $TARGET->search('email', $a_record['email'], true, true);
+        // check if contact exists, if so, we'll need it's ID
+        $result = $TARGET->search('email', $a_record['email'], true, true);
 
-      // insert contact record
-      if (!$result->count) {
-        $plugin = $RCMAIL->plugins->exec_hook('contact_create', array(
-          'record' => $a_record, 'source' => $target, 'group' => $target_group));
+        // insert contact record
+        if (!$result->count) {
+            $plugin = $RCMAIL->plugins->exec_hook('contact_create', array(
+                'record' => $a_record, 'source' => $target, 'group' => $target_group));
 
-        if (!$plugin['abort']) {
-          if ($insert_id = $TARGET->insert($plugin['record'], false)) {
-            $ids[] = $insert_id;
-            $success++;
-          }
+            if (!$plugin['abort']) {
+                if ($insert_id = $TARGET->insert($plugin['record'], false