4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/copy.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2007, Roundcube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Copy a contact record from one direcotry to another |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: copy.inc 471 2007-02-09 21:25:50Z thomasb $
22 // only process ajax requests
23 if (!$OUTPUT->ajax_call)
26 $cid = get_input_value('_cid', RCUBE_INPUT_POST);
27 $target = get_input_value('_to', RCUBE_INPUT_POST);
28 $target_group = get_input_value('_togid', RCUBE_INPUT_POST);
30 if ($cid && preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid) && strlen($target) && $target !== $source)
33 $TARGET = $RCMAIL->get_address_book($target);
35 if ($TARGET && $TARGET->ready && !$TARGET->readonly) {
36 $arr_cids = explode(',', $cid);
39 foreach ($arr_cids as $cid) {
40 $a_record = $CONTACTS->get_record($cid, true);
42 // check if contact exists, if so, we'll need it's ID
43 $result = $TARGET->search('email', $a_record['email'], true, true);
45 // insert contact record
46 if (!$result->count) {
47 $plugin = $RCMAIL->plugins->exec_hook('contact_create', array(
48 'record' => $a_record, 'source' => $target, 'group' => $target_group));
50 if (!$plugin['abort']) {
51 if ($insert_id = $TARGET->insert($a_record, false)) {
56 else if ($plugin['result']) {
57 $ids = array_merge($ids, $plugin['result']);
62 $record = $result->first();
63 $ids[] = $record['ID'];
68 if ($target_group && $TARGET->groups && !empty($ids)) {
69 $plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array(
70 'group_id' => $target_group, 'ids' => $ids, 'source' => $target));
72 if (!$plugin['abort']) {
74 $TARGET->set_group($target_group);
76 if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($TARGET->count()->count + count($plugin['ids']) > $maxnum)) {
77 $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum));
81 if (($cnt = $TARGET->add_to_group($target_group, $plugin['ids'])) && $cnt > $success)
84 else if ($plugin['result'])
85 $success = $plugin['result'];
90 $OUTPUT->show_message('copyerror', 'error');
92 $OUTPUT->show_message('copysuccess', 'notice', array('nr' => $success));