2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*********************************************************************************
40 * Description: TODO: To be written.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
49 if (!empty($data['listViewExternalClient'])) {
51 echo $email->getNamePlusEmailAddressesForCompose($_REQUEST['action_module'], (explode(",", $_REQUEST['uid'])));
53 //For the full compose/email screen, the compose package is generated and script execution
54 //continues to the Emails/index.php page.
55 else if(!isset($data['forQuickCreate'])) {
56 $ret = generateComposeDataPackage($data);
60 * Initialize the full compose window by creating the compose package
61 * and then including Emails index.php file.
65 function initFullCompose($ret)
69 $composeOut = $json->encode($ret);
71 //For listview 'Email' call initiated by subpanels, just returned the composePackage data, do not
72 //include the entire Emails page
73 if ( isset($_REQUEST['ajaxCall']) && $_REQUEST['ajaxCall'])
79 //For normal full compose screen
80 include('modules/Emails/index.php');
81 echo "<script type='text/javascript' language='javascript'>\ncomposePackage = {$composeOut};\n</script>";
86 * Generate the compose data package consumed by the full and quick compose screens.
89 * @param Bool $forFullCompose If full compose is set to TRUE, then continue execution and include the full Emails UI. Otherwise
90 * the data generated is returned.
92 function generateComposeDataPackage($data,$forFullCompose = TRUE)
94 // we will need the following:
95 if( isset($data['parent_type']) && !empty($data['parent_type']) &&
96 isset($data['parent_id']) && !empty($data['parent_id']) &&
97 !isset($data['ListView']) && !isset($data['replyForward'])) {
103 $class = $beanList[$data['parent_type']];
104 require_once($beanFiles[$class]);
106 $bean = new $class();
107 $bean->retrieve($data['parent_id']);
108 if (isset($bean->full_name)) {
109 $parentName = $bean->full_name;
110 } elseif(isset($bean->name)) {
111 $parentName = $bean->name;
115 $parentName = from_html($parentName);
117 if (isset($data['to_email_addrs'])) {
118 $namePlusEmail = $data['to_email_addrs'];
119 $namePlusEmail = from_html(str_replace(" ", " ", $namePlusEmail));
121 if (isset($bean->full_name)) {
122 $namePlusEmail = from_html($bean->full_name) . " <". from_html($bean->emailAddress->getPrimaryAddress($bean)).">";
123 } else if(isset($bean->emailAddress)){
124 $namePlusEmail = "<".from_html($bean->emailAddress->getPrimaryAddress($bean)).">";
131 $attachments = array();
132 if ($bean->module_dir == 'Cases') {
133 $subject = str_replace('%1', $bean->case_number, $bean->getEmailSubjectMacro() . " ". from_html($bean->name)) ;//bug 41928
134 $bean->load_relationship("contacts");
135 $contact_ids = $bean->contacts->get();
136 $contact = new Contact();
137 foreach($contact_ids as $cid)
139 $contact->retrieve($cid);
140 $namePlusEmail .= empty($namePlusEmail) ? "" : ", ";
141 $namePlusEmail .= from_html($contact->full_name) . " <".from_html($contact->emailAddress->getPrimaryAddress($contact)).">";
144 if ($bean->module_dir == 'KBDocuments') {
146 require_once("modules/Emails/EmailUI.php");
147 $subject = $bean->kbdocument_name;
148 $article_body = str_replace('/'.$GLOBALS['sugar_config']['cache_dir'].'images/',$GLOBALS['sugar_config']['site_url'].'/'.$GLOBALS['sugar_config']['cache_dir'].'images/',KBDocument::get_kbdoc_body_without_incrementing_count($bean->id));
149 $body = from_html($article_body);
150 $attachments = KBDocument::get_kbdoc_attachments_for_newemail($bean->id);
151 $attachments = $attachments['attachments'];
153 if ($bean->module_dir == 'Quotes' && isset($data['recordId'])) {
154 $quotesData = getQuotesRelatedData($bean,$data);
155 global $current_language;
156 $namePlusEmail = $quotesData['toAddress'];
157 $subject = $quotesData['subject'];
158 $body = $quotesData['body'];
159 $attachments = $quotesData['attachments'];
160 $email_id = $quotesData['email_id'];
163 'to_email_addrs' => $namePlusEmail,
164 'parent_type' => $data['parent_type'],
165 'parent_id' => $data['parent_id'],
166 'parent_name' => $parentName,
167 'subject' => $subject,
169 'attachments' => $attachments,
170 'email_id' => $email_id,
173 } else if(isset($_REQUEST['ListView'])) {
175 $email = new Email();
176 $namePlusEmail = $email->getNamePlusEmailAddressesForCompose($_REQUEST['action_module'], (explode(",", $_REQUEST['uid'])));
178 'to_email_addrs' => $namePlusEmail,
180 } else if (isset($data['replyForward'])) {
182 require_once("modules/Emails/EmailUI.php");
185 $ie = new InboundEmail();
186 $ie->email = new Email();
187 $ie->email->email2init();
188 $replyType = $data['reply'];
189 $email_id = $data['record'];
190 $ie->email->retrieve($email_id);
192 if ($ie->email->type == 'draft') {
193 $emailType = $ie->email->type;
195 $ie->email->from_addr = $ie->email->from_addr_name;
196 $ie->email->to_addrs = to_html($ie->email->to_addrs_names);
197 $ie->email->cc_addrs = to_html($ie->email->cc_addrs_names);
198 $ie->email->bcc_addrs = $ie->email->bcc_addrs_names;
199 $ie->email->from_name = $ie->email->from_addr;
200 $preBodyHTML = " <div><hr></div>";
201 if ($ie->email->type != 'draft') {
202 $email = $ie->email->et->handleReplyType($ie->email, $replyType);
207 if ($ie->email->type != 'draft') {
208 $emailHeader = $email->description;
210 $ret = $ie->email->et->displayComposeEmail($email);
211 if ($ie->email->type != 'draft') {
212 $ret['description'] = $emailHeader;
214 if ($replyType == 'forward' || $emailType == 'draft') {
215 $ret = $ie->email->et->getDraftAttachments($ret);
217 $return = $ie->email->et->getFromAllAccountsArray($ie, $ret);
219 if ($replyType == "forward") {
222 if ($email->type != 'draft') {
223 $return['to'] = from_html($ie->email->from_addr);
227 'to_email_addrs' => $return['to'],
228 'parent_type' => $return['parent_type'],
229 'parent_id' => $return['parent_id'],
230 'parent_name' => $return['parent_name'],
231 'subject' => $return['name'],
232 'body' => $preBodyHTML . $return['description'],
233 'attachments' => (isset($return['attachments']) ? $return['attachments'] : array()),
234 'email_id' => $email_id,
235 'fromAccounts' => $return['fromAccounts'],
240 'to_email_addrs' => '',
245 initFullCompose($ret);
250 function getQuotesRelatedData($bean,$data) {
252 $emailId = $data['recordId'];
254 require_once("modules/Emails/EmailUI.php");
255 $email = new Email();
256 $email->retrieve($emailId);
257 $return['subject'] = $email->name;
258 $return['body'] = from_html($email->description_html);
259 $return['toAddress'] = $email->to_addrs;
261 $ret['uid'] = $emailId;
262 $ret = EmailUI::getDraftAttachments($ret);
263 $return['attachments'] = $ret['attachments'];
264 $return['email_id'] = $emailId;