summaryrefslogtreecommitdiff
path: root/program/steps
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-12-14 19:41:07 +0100
committerAleksander Machniak <alec@alec.pl>2012-12-14 19:41:07 +0100
commitff4a92c8e2f11711975f9697a057cd96ce370bc5 (patch)
tree79324bb25d30baa933603fbe4b0b18a2a0e6af8a /program/steps
parent5c421d9927c973049bfaea69609cdf760f8f7332 (diff)
Fix contact copy/add-to-group operations on search result (#1488862)
Diffstat (limited to 'program/steps')
-rw-r--r--program/steps/addressbook/func.inc28
-rw-r--r--program/steps/addressbook/groups.inc13
2 files changed, 22 insertions, 19 deletions
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index fded9a819..2f47483de 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -756,7 +756,7 @@ function rcmail_contact_key($row, $sort_col)
*
* @return array List of contact IDs per-source
*/
-function rcmail_get_cids()
+function rcmail_get_cids($filter = null)
{
// contact ID (or comma-separated list of IDs) is provided in two
// forms. If _source is an empty string then the ID is a string
@@ -765,24 +765,25 @@ function rcmail_get_cids()
$cid = get_input_value('_cid', RCUBE_INPUT_GPC);
$source = (string) get_input_value('_source', RCUBE_INPUT_GPC);
+ if (is_array($cid)) {
+ return $cid;
+ }
+
if (!preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid)) {
return array();
}
- $cid = explode(',', $cid);
- $got_source = strlen($source);
- $result = array();
+ $cid = explode(',', $cid);
+ $result = array();
// create per-source contact IDs array
foreach ($cid as $id) {
- // if _source is not specified we'll find it from decoded ID
- if (!$got_source) {
- if ($sep = strrpos($id, '-')) {
- $contact_id = substr($id, 0, $sep);
- $source_id = substr($id, $sep+1);
- if (strlen($source_id)) {
- $result[(string)$source_id][] = $contact_id;
- }
+ // get source from decoded ID
+ if ($sep = strrpos($id, '-')) {
+ $contact_id = substr($id, 0, $sep);
+ $source_id = substr($id, $sep+1);
+ if (strlen($source_id)) {
+ $result[(string)$source_id][] = $contact_id;
}
}
else {
@@ -790,9 +791,10 @@ function rcmail_get_cids()
}
}
- return $result;
+ return $filter !== null ? $result[$filter] : $result;
}
+
// register UI objects
$OUTPUT->add_handlers(array(
'directorylist' => 'rcmail_directory_list',
diff --git a/program/steps/addressbook/groups.inc b/program/steps/addressbook/groups.inc
index b70453889..3b9288a2b 100644
--- a/program/steps/addressbook/groups.inc
+++ b/program/steps/addressbook/groups.inc
@@ -20,7 +20,7 @@
*/
$source = get_input_value('_source', RCUBE_INPUT_GPC);
-$CONTACTS = rcmail_contact_source($source, true);
+$CONTACTS = rcmail_contact_source($source);
if ($CONTACTS->readonly || !$CONTACTS->groups) {
$OUTPUT->show_message('sourceisreadonly', 'warning');
@@ -28,11 +28,11 @@ if ($CONTACTS->readonly || !$CONTACTS->groups) {
}
if ($RCMAIL->action == 'group-addmembers') {
- if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) {
+ if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = rcmail_get_cids($source))) {
$plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source));
$CONTACTS->set_group($gid);
- $num2add = count(explode(',', $plugin['ids']));
+ $num2add = count($plugin['ids']);
if (!$plugin['abort']) {
if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + $num2add > $maxnum)) {
@@ -55,7 +55,7 @@ if ($RCMAIL->action == 'group-addmembers') {
}
else if ($RCMAIL->action == 'group-delmembers') {
- if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) {
+ if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = rcmail_get_cids($source))) {
$plugin = $RCMAIL->plugins->exec_hook('group_delmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source));
if (!$plugin['abort'])
@@ -63,10 +63,11 @@ else if ($RCMAIL->action == 'group-delmembers') {
else
$result = $plugin['result'];
- if ($result){
+ if ($result) {
$OUTPUT->show_message('contactremovedfromgroup');
$OUTPUT->command('remove_group_contacts',array('source' => $source, 'gid' => $gid));
- }else{
+ }
+ else {
$OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
}
}