From 05f0e486e32bf3145529718979f0587caa9b2d70 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Thu, 16 Jan 2014 14:05:07 +0000 Subject: [PATCH] Use long task UI to merge contacts into email templates --- etemplate/inc/class.bo_merge.inc.php | 44 +++++++++++------------ mail/inc/class.mail_bo.inc.php | 2 +- mail/inc/class.mail_compose.inc.php | 53 ++++++++++++++++++++++++---- 3 files changed, 70 insertions(+), 29 deletions(-) diff --git a/etemplate/inc/class.bo_merge.inc.php b/etemplate/inc/class.bo_merge.inc.php index 88e53b1a62..7fb44ad70d 100644 --- a/etemplate/inc/class.bo_merge.inc.php +++ b/etemplate/inc/class.bo_merge.inc.php @@ -1771,12 +1771,14 @@ abstract class bo_merge 'group' => 2, 'children' => array(), ); - if ($file['mime'] == 'message/rfc822') - { - self::document_mail_action($documents[$prefix.$file['name']], $file); - } } - $documents[$file['mime']]['children'][$prefix.$file['name']] = egw_vfs::decodePath($file['name']); + $documents[$file['mime']]['children'][$prefix.$file['name']] = array( + 'caption' => egw_vfs::decodePath($file['name']) + ); + if ($file['mime'] == 'message/rfc822') + { + self::document_mail_action($documents[$file['mime']]['children'][$prefix.$file['name']], $file); + } } else { @@ -1819,26 +1821,24 @@ abstract class bo_merge { unset($action['postSubmit']); - // These parameters trigger compose + merge - $extra = array( - 'from' => 'merge', - 'document' => $file['path'], - ); - $action['confirm_multiple'] = lang('Do you want to send the message to all selected entries, WITHOUT further editing?') . - lang('Popup will close when finished'); + // Lots takes a while, confirm + $action['confirm_multiple'] = lang('Do you want to send the message to all selected entries, WITHOUT further editing?'); - // egw.open() would work, but nextmatch actions only passes 1 ID through - //$action['egw_open'] = 'edit-mail--'.implode('&',$extra); - // - // We use location and send the popup info anyway instead - $action['nm_action'] = 'location'; - $action['popup'] = egw_link::get_registry('mail', 'edit_popup'); - $action['url'] = egw_link::get_registry('mail', 'edit') + $extra + array( - // Mail edit requires ID to have a value before it will look at the other variables - egw_link::get_registry('mail', 'edit_id') => 'true', - 'preset[mailtocontactbyid]' => '$id', + // These parameters trigger compose + merge - only if 1 row + $extra = array( + 'from=merge', + 'document='.$file['path'], ); + + // egw.open() used if only 1 row selected + $action['egw_open'] = 'edit-mail--'.implode('&',$extra); $action['target'] = 'compose_' .$file['path']; + + // long_task runs menuaction once for each selected row + $action['nm_action'] = 'long_task'; + $action['popup'] = egw_link::get_registry('mail', 'edit_popup'); + $action['message'] = lang('insert in %1',egw_vfs::decodePath($file['name'])); + $action['menuaction'] = 'mail.mail_compose.ajax_merge&document='.$file['path']; } /** diff --git a/mail/inc/class.mail_bo.inc.php b/mail/inc/class.mail_bo.inc.php index 8dd2eb72b4..cc95a06415 100644 --- a/mail/inc/class.mail_bo.inc.php +++ b/mail/inc/class.mail_bo.inc.php @@ -5362,7 +5362,7 @@ class mail_bo } else { - $errorInfo = $mailObject->ErrorInfo; + $errorInfo = 'Send Failed for '.$mailObject->Subject.' to '.$nfn.'<'.$email.'> Error:'.$mailObject->ErrorInfo; } } //error_log(__METHOD__.__LINE__.array2string($errorInfo)); diff --git a/mail/inc/class.mail_compose.inc.php b/mail/inc/class.mail_compose.inc.php index 5d2938fedc..fa5e601f3d 100644 --- a/mail/inc/class.mail_compose.inc.php +++ b/mail/inc/class.mail_compose.inc.php @@ -1318,9 +1318,9 @@ class mail_compose else if ($from == 'merge' && $_REQUEST['document']) { /* - * Special merge from everywhere else becase all other apps merge gives - * a document to be downloaded, this either opens a compose dialog or - * just sends emails + * Special merge from everywhere else because all other apps merge gives + * a document to be downloaded, this opens a compose dialog. + * Use ajax_merge to merge & send multiple */ // Merge selected ID (in mailtocontactbyid or $mail_id) into given document $document_merge = new addressbook_merge(); @@ -1341,11 +1341,13 @@ class mail_compose $GLOBALS['egw_info']['flags']['currentapp'] = 'addressbook'; // Actually do the merge - $results = $this->mail_bo->importMessageToMergeAndSend($document_merge, egw_vfs::PREFIX . $_REQUEST['document'], $merge_ids, $folder, $merged_mail_id); - - // Handle results - one email open compose, more than one just sent if(count($merge_ids) <= 1) { + $results = $this->mail_bo->importMessageToMergeAndSend( + $document_merge, egw_vfs::PREFIX . $_REQUEST['document'], $merge_ids, $folder, $merged_mail_id + ); + + // Open compose $merged_mail_id = trim($GLOBALS['egw_info']['user']['account_id']).mail_ui::$delimiter. $this->mail_bo->profileID.mail_ui::$delimiter. base64_encode($folder).mail_ui::$delimiter.$merged_mail_id; @@ -2718,4 +2720,43 @@ class mail_compose common::egw_exit(); } + /** + * Merge the selected contact ID into the document given in $_REQUEST['document'] + * and send it. + * + * @param int $contact_id + */ + public function ajax_merge($contact_id) + { + $response = egw_json_response::get(); + $document_merge = new addressbook_merge(); + $this->mail_bo->openConnection(); + + if($error = $document_merge->check_document($_REQUEST['document'],'')) + { + $response->error($error); + return; + } + + // Merge does not work correctly (missing to) if current app is not addressbook + $GLOBALS['egw_info']['flags']['currentapp'] = 'addressbook'; + + // Actually do the merge + $results = $this->mail_bo->importMessageToMergeAndSend( + $document_merge, egw_vfs::PREFIX . $_REQUEST['document'], + // Send an extra non-numeric ID to force actual send of document + // instead of save as draft + array((int)$contact_id, ''), + $folder,$merged_mail_id + ); + + if($results['success']) + { + $response->data(implode(',',$results['success'])); + } + if($results['failed']) + { + $response->error(implode(',',$results['failed'])); + } + } }