Permalink
Browse files

- Added searching in all addressbook sources (global-search)

- Added addressbook source selection in contacts import
  • Loading branch information...
1 parent 6f3fa96 commit ecf295f6ef2b83c5e51cc74adf833fd8e18b6cfb @alecpl alecpl committed Jun 14, 2011
View
@@ -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
View
@@ -450,6 +450,7 @@ $rcmail_config['address_book_type'] = 'sql';
// 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
View
@@ -336,7 +336,7 @@ function rcube_webmail()
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 @@ function rcube_webmail()
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 @@ function rcube_webmail()
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 @@ function rcube_webmail()
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 @@ function rcube_webmail()
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 @@ function rcube_webmail()
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 @@ function rcube_webmail()
for (childcol in colprop.childs)
cols.push(childcol);
}
-
+
for (var i=0; i < cols.length; i++) {
childcol = cols[i];
cp = colprop.childs[childcol];
@@ -4241,16 +4266,22 @@ function rcube_webmail()
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 @@ function rcube_webmail()
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 @@ function rcube_webmail()
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 @@ function rcube_webmail()
return frame_name;
};
-
+
// starts interval for keep-alive/check-recent signal
this.start_keepalive = function()
{
@@ -326,6 +326,7 @@ $labels['personaladrbook'] = 'Personal Addresses';
$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';
@@ -413,5 +413,6 @@ $labels['allfields'] = 'Wszystkie pola';
$labels['search'] = 'Szukaj';
$labels['advsearch'] = 'Wyszukiwanie zaawansowane';
$labels['other'] = 'Inne';
+$labels['importtarget'] = 'Dodaj nowe kontakty do książki adresowej:';
?>
@@ -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);
- $ids = array();
+ // It maight happen when copying records from search result
+ // Do nothing, go to next source
+ if ($target == $source) {
+ continue;
+ }
- foreach ($arr_cids as $cid) {
- $a_record = $CONTACTS->get_record($cid, true);
+ $CONTACTS = $RCMAIL->get_address_book($source);
+ $TARGET = $RCMAIL->get_address_book($target);
- // check if contact exists, if so, we'll need it's ID
- $result = $TARGET->search('email', $a_record['email'], true, true);
+ if (!$TARGET || !$TARGET->ready || $TARGET->readonly) {
+ break;
+ }
- // insert contact record
- if (!$result->count) {
- $plugin = $RCMAIL->plugins->exec_hook('contact_create', array(
- 'record' => $a_record, 'source' => $target, 'group' => $target_group));
+ $ids = array();
- if (!$plugin['abort']) {
- if ($insert_id = $TARGET->insert($plugin['record'], false)) {
- $ids[] = $insert_id;
- $success++;
- }
+ 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);
+
+ // 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++;
+ }
+ }
+ else if ($plugin['result']) {
+ $ids = array_merge($ids, $plugin['result']);
+ $success++;
+ }
}
- else if ($plugin['result']) {
- $ids = array_merge($ids, $plugin['result']);
- $success++;
+ else {
+ $record = $result->first();
+ $ids[] = $record['ID'];
}
- }
- else {
- $record = $result->first();
- $ids[] = $record['ID'];
- }
}
// assign to group
if ($target_group && $TARGET->groups && !empty($ids)) {
- $plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array(
- 'group_id' => $target_group, 'ids' => $ids, 'source' => $target));
+ $plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array(
+ 'group_id' => $target_group, 'ids' => $ids, 'source' => $target));
- if (!$plugin['abort']) {
- $TARGET->reset();
- $TARGET->set_group($target_group);
+ if (!$plugin['abort']) {
+ $TARGET->reset();
+ $TARGET->set_group($target_group);
- if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($TARGET->count()->count + count($plugin['ids']) > $maxnum)) {
- $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum));
- $OUTPUT->send();
- }
+ if ($maxnum && ($TARGET->count()->count + count($plugin['ids']) > $maxnum)) {
+ $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum));
+ $OUTPUT->send();
+ }
- if (($cnt = $TARGET->add_to_group($target_group, $plugin['ids'])) && $cnt > $success)
- $success = $cnt;
- }
- else if ($plugin['result'])
- $success = $plugin['result'];
+ if (($cnt = $TARGET->add_to_group($target_group, $plugin['ids'])) && $cnt > $success)
+ $success = $cnt;
+ }
+ else if ($plugin['result']) {
+ $success = $plugin['result'];
+ }
}
- }
+}
- if ($success == 0)
+if ($success == 0)
$OUTPUT->show_message('copyerror', 'error');
- else
+else
$OUTPUT->show_message('copysuccess', 'notice', array('nr' => $success));
-}
// send response
$OUTPUT->send();
-
Oops, something went wrong.

0 comments on commit ecf295f

Please sign in to comment.