From 608f3e3cce1d6e3d55d0e85a902b9ab861a804e4 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Fri, 8 Nov 2013 19:17:19 +0000 Subject: [PATCH] Add "copy" feature for copying contact(s) to addressbook --- addressbook/inc/class.addressbook_ui.inc.php | 50 ++++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 023c0da8fa..4103e242af 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -148,7 +148,7 @@ class addressbook_ui extends addressbook_bo else { if ($this->action($content['nm']['action'],$content['nm']['selected'],$content['nm']['select_all'], - $success,$failed,$action_msg,$content['do_email'] ? 'email' : 'index',$msg)) + $success,$failed,$action_msg,$content['do_email'] ? 'email' : 'index',$msg,$content['nm']['checkboxes'])) { $msg .= lang('%1 contact(s) %2',$success,$action_msg); } @@ -511,6 +511,13 @@ class addressbook_ui extends addressbook_bo 'caption' => $label, ); } + // copy checkbox + $move2addressbooks= array( + 'copy' =>array( + 'id' => 'move_to_copy', + 'caption' => 'Copy instead of move', + 'checkbox' => true, + )) + $move2addressbooks; $actions['move_to'] = array( 'caption' => 'Move to addressbook', 'children' => $move2addressbooks, @@ -774,7 +781,7 @@ class addressbook_ui extends addressbook_bo * @param string/array $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup * @return boolean true if all actions succeded, false otherwise */ - function action($action,$checked,$use_all,&$success,&$failed,&$action_msg,$session_name,&$msg) + function action($action,$checked,$use_all,&$success,&$failed,&$action_msg,$session_name,&$msg, $checkboxes = NULL) { //echo "

uicontacts::action('$action',".print_r($checked,true).','.(int)$use_all.",...)

\n"; $success = $failed = 0; @@ -1042,18 +1049,41 @@ class addressbook_ui extends addressbook_bo { return false; } - $action_msg = lang('moved'); - if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(EGW_ACL_DELETE,$contact))) + if (!$checkboxes['move_to_copy']) { - if (!$contact['owner']) // no mass-change of accounts + $action_msg = lang('moved'); + if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(EGW_ACL_DELETE,$contact))) { - $Ok = false; + if (!$contact['owner']) // no mass-change of accounts + { + $Ok = false; + } + elseif ($contact['owner'] != (int)$action || $contact['private'] != (int)(substr($action,-1) == 'p')) + { + $contact['owner'] = (int) $action; + $contact['private'] = (int)(substr($action,-1) == 'p'); + $Ok = $this->save($contact); + } } - elseif ($contact['owner'] != (int)$action || $contact['private'] != (int)(substr($action,-1) == 'p')) + } + else + { + $action_msg = lang('copied'); + if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(EGW_ACL_DELETE,$contact))) { - $contact['owner'] = (int) $action; - $contact['private'] = (int)(substr($action,-1) == 'p'); - $Ok = $this->save($contact); + if (!$contact['owner']) // no mass-change of accounts + { + $Ok = false; + } + elseif ($contact['owner'] != (int)$action || $contact['private'] != (int)(substr($action,-1) == 'p')) + { + unset($contact['id']); + unset($contact['uid']); + unset($contact['etag']); + $contact['owner'] = (int) $action; + $contact['private'] = (int)(substr($action,-1) == 'p'); + $Ok = $this->save($contact); + } } } break;