]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Emails/DetailView.php
Release 6.2.0
[Github/sugarcrm.git] / modules / Emails / DetailView.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46 ///////////////////////////////////////////////////////////////////////////////
47 ////    CANCEL HANDLING
48 if(!isset($_REQUEST['record']) || empty($_REQUEST['record'])) {
49         header("Location: index.php?module=Emails&action=index");
50 }
51 ////    CANCEL HANDLING
52 ///////////////////////////////////////////////////////////////////////////////
53
54
55 require_once('include/DetailView/DetailView.php');
56 global $gridline;
57 global $app_strings;
58
59 // SETTING DEFAULTS
60 $focus          = new Email();
61 $detailView     = new DetailView();
62 $offset         = 0;
63 $email_type     = 'archived';
64
65 ///////////////////////////////////////////////////////////////////////////////
66 ////    TO HANDLE 'NEXT FREE'
67 if(!empty($_REQUEST['next_free']) && $_REQUEST['next_free'] == true) {
68         $_REQUEST['record'] = $focus->getNextFree();
69 }
70 ////    END 'NEXT FREE'
71 ///////////////////////////////////////////////////////////////////////////////
72
73 if (isset($_REQUEST['offset']) or isset($_REQUEST['record'])) {
74         $result = $detailView->processSugarBean("EMAIL", $focus, $offset);
75         if($result == null) {
76             sugar_die($app_strings['ERROR_NO_RECORD']);
77         }
78         $focus=$result;
79 } else {
80         header("Location: index.php?module=Emails&action=index");
81         die();
82 }
83
84 /* if the Email status is draft, say as a saved draft to a Lead/Case/etc.,
85  * don't show detail view. go directly to EditView */
86 if($focus->status == 'draft') {
87         //header('Location: index.php?module=Emails&action=EditView&record='.$_REQUEST['record']);
88         //die();
89 }
90
91 // ACL Access Check
92 if (!$focus->ACLAccess('DetailView')){
93         ACLController::displayNoAccess(true);
94         sugar_cleanup(true);
95 }
96
97 //needed when creating a new email with default values passed in
98 if (isset($_REQUEST['contact_name']) && is_null($focus->contact_name)) {
99         $focus->contact_name = $_REQUEST['contact_name'];
100 }
101 if (isset($_REQUEST['contact_id']) && is_null($focus->contact_id)) {
102         $focus->contact_id = $_REQUEST['contact_id'];
103 }
104 if (isset($_REQUEST['opportunity_name']) && is_null($focus->parent_name)) {
105         $focus->parent_name = $_REQUEST['opportunity_name'];
106 }
107 if (isset($_REQUEST['opportunity_id']) && is_null($focus->parent_id)) {
108         $focus->parent_id = $_REQUEST['opportunity_id'];
109 }
110 if (isset($_REQUEST['account_name']) && is_null($focus->parent_name)) {
111         $focus->parent_name = $_REQUEST['account_name'];
112 }
113 if (isset($_REQUEST['account_id']) && is_null($focus->parent_id)) {
114         $focus->parent_id = $_REQUEST['account_id'];
115 }
116
117 // un/READ flags
118 if (!empty($focus->status)) {
119         // "Read" flag for InboundEmail
120         if($focus->status == 'unread') {
121                 // creating a new instance here to avoid data corruption below
122                 $e = new Email();
123                 $e->retrieve($focus->id);
124                 $e->status = 'read';
125                 $e->save();
126                 $email_type = $e->status;
127         } else {
128                 $email_type = $focus->status;
129         }
130
131 } elseif (!empty($_REQUEST['type'])) {
132         $email_type = $_REQUEST['type'];
133 }
134
135
136 ///////////////////////////////////////////////////////////////////////////////
137 ////    OUTPUT
138 ///////////////////////////////////////////////////////////////////////////////
139 echo "\n<p>\n";
140 $GLOBALS['log']->info("Email detail view");
141 if ($email_type == 'archived') {
142         echo getClassicModuleTitle('Emails', array($mod_strings['LBL_ARCHIVED_EMAIL'],$focus->name), true);
143         $xtpl=new XTemplate ('modules/Emails/DetailView.html');
144 } else {
145         $xtpl=new XTemplate ('modules/Emails/DetailViewSent.html');
146         if($focus->type == 'out') {
147                 echo getClassicModuleTitle('Emails', array($mod_strings['LBL_SENT_MODULE_NAME'],$focus->name), true);
148                 //$xtpl->assign('DISABLE_REPLY_BUTTON', 'NONE');
149         } elseif ($focus->type == 'draft') {
150                 $xtpl->assign('DISABLE_FORWARD_BUTTON', 'NONE');
151                 echo getClassicModuleTitle('Emails', array($mod_strings['LBL_LIST_FORM_DRAFTS_TITLE'],$focus->name), true);
152         } elseif($focus->type == 'inbound') {
153                 echo getClassicModuleTitle('Emails', array($mod_strings['LBL_INBOUND_TITLE'],$focus->name), true);
154         }
155 }
156 echo "\n</p>\n";
157
158
159
160 ///////////////////////////////////////////////////////////////////////////////
161 ////    RETURN NAVIGATION
162 $uri = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'index.php';
163 $start = $focus->getStartPage($uri);
164 if (isset($_REQUEST['return_id'])) { // coming from a subpanel, return_module|action is not set
165         $xtpl->assign('RETURN_ID', $_REQUEST['return_id']);
166         if (isset($_REQUEST['return_module']))  $xtpl->assign('RETURN_MODULE', $_REQUEST['return_module']);
167         else $xtpl->assign('RETURN_MODULE', 'Emails');
168         if (isset($_REQUEST['return_action']))  $xtpl->assign('RETURN_ACTION', $_REQUEST['return_action']);
169         else $xtpl->assign('RETURN_ACTION', 'DetailView');
170 }
171
172 if(isset($start['action']) && !empty($start['action'])) {
173         $xtpl->assign('DELETE_RETURN_ACTION', $start['action']);
174 }
175 if(isset($start['module']) && !empty($start['module'])) {
176         $xtpl->assign('DELETE_RETURN_MODULE', $start['module']);
177 }
178 if(isset($start['record']) && !empty($start['record'])) {
179         $xtpl->assign('DELETE_RETURN_ID', $start['record']);
180 }
181 // this is to support returning to My Inbox
182 if(isset($start['type']) && !empty($start['type'])) {
183         $xtpl->assign('DELETE_RETURN_TYPE', $start['type']);
184 }
185 if(isset($start['assigned_user_id']) && !empty($start['assigned_user_id'])) {
186         $xtpl->assign('DELETE_RETURN_ASSIGNED_USER_ID', $start['assigned_user_id']);
187 }
188
189
190
191 ////    END RETURN NAVIGATION
192 ///////////////////////////////////////////////////////////////////////////////
193
194
195 // DEFAULT TO TEXT IF NO HTML CONTENT:
196 $html = trim(from_html($focus->description_html));
197 if(empty($html)) {
198         $xtpl->assign('SHOW_PLAINTEXT', 'true');
199         $description = nl2br($focus->description);
200 } else {
201         $xtpl->assign('SHOW_PLAINTEXT', 'false');
202         $description = from_html($focus->description_html);
203 }
204 $show_subpanels=true;
205 //if the email is of type campaign, process the macros...using the values stored in the relationship table.
206 //this is is part of the feature that adds support for one email per campaign.
207 if ($focus->type=='campaign' and !empty($_REQUEST['parent_id']) and !empty($_REQUEST['parent_module'])) {
208     $show_subpanels=false;
209     $parent_id=$_REQUEST['parent_id'];
210
211         // cn: bug 14300 - emails_beans schema refactor - fixing query
212         $query="SELECT * FROM emails_beans WHERE email_id='{$focus->id}' AND bean_id='{$parent_id}' AND bean_module = '{$_REQUEST['parent_module']}' " ;
213
214     $res=$focus->db->query($query);
215     $row=$focus->db->fetchByAssoc($res);
216     if (!empty($row)) {
217         $campaign_data=$row['campaign_data'];
218         $macro_values=array();
219         if (!empty($campaign_data)) {
220             $macro_values=unserialize(from_html($campaign_data));
221         }
222
223         if (count($macro_values) > 0) {
224             $m_keys=array_keys($macro_values);
225             $m_values=array_values($macro_values);
226
227             $focus->name = str_replace($m_keys,$m_values,$focus->name);
228             $focus->description = str_replace($m_keys,$m_values,$focus->description);
229             $focus->description_html = str_replace($m_keys,$m_values,$focus->description_html);
230             if (!empty($macro_values['sugar_to_email_address'])) {
231                 $focus->to_addrs=$macro_values['sugar_to_email_address'];
232             }
233         }
234     }
235 }
236 //if not empty or set to test (from test campaigns)
237 if (!empty($focus->parent_type) && $focus->parent_type !='test') {
238         $xtpl->assign('PARENT_MODULE', $focus->parent_type);
239         $xtpl->assign('PARENT_TYPE_UNTRANSLATE', $focus->parent_type);
240     $xtpl->assign('PARENT_TYPE', $app_list_strings['record_type_display'][$focus->parent_type] . ':');
241 }
242
243 $to_addr = !empty($focus->to_addrs_names) ? htmlspecialchars($focus->to_addrs_names, ENT_COMPAT, 'UTF-8') : nl2br($focus->to_addrs);
244 $from_addr = !empty($focus->from_addr_name) ? htmlspecialchars($focus->from_addr_name, ENT_COMPAT, 'UTF-8') : nl2br($focus->from_addr);
245 $cc_addr = !empty($focus->cc_addrs_names) ? htmlspecialchars($focus->cc_addrs_names, ENT_COMPAT, 'UTF-8') : nl2br($focus->cc_addrs);
246 $bcc_addr = !empty($focus->bcc_addrs_names) ? htmlspecialchars($focus->bcc_addrs_names, ENT_COMPAT, 'UTF-8') : nl2br($focus->bcc_addrs);
247
248 $xtpl->assign('MOD', $mod_strings);
249 $xtpl->assign('APP', $app_strings);
250 $xtpl->assign('GRIDLINE', $gridline);
251 $xtpl->assign('PRINT_URL', 'index.php?'.$GLOBALS['request_string']);
252 $xtpl->assign('ID', $focus->id);
253 $xtpl->assign('TYPE', $email_type);
254 $xtpl->assign('PARENT_NAME', $focus->parent_name);
255 $xtpl->assign('PARENT_ID', $focus->parent_id);
256 $xtpl->assign('NAME', $focus->name);
257 $xtpl->assign('ASSIGNED_TO', $focus->assigned_user_name);
258 $xtpl->assign('DATE_MODIFIED', $focus->date_modified);
259 $xtpl->assign('DATE_ENTERED', $focus->date_entered);
260 $xtpl->assign('DATE_START', $focus->date_start);
261 $xtpl->assign('TIME_START', $focus->time_start);
262 $xtpl->assign('FROM', $from_addr);
263 $xtpl->assign('TO', $to_addr);
264 $xtpl->assign('CC', $cc_addr);
265 $xtpl->assign('BCC', $bcc_addr);
266 $xtpl->assign('CREATED_BY', $focus->created_by_name);
267 $xtpl->assign('MODIFIED_BY', $focus->modified_by_name);
268 $xtpl->assign('DESCRIPTION', nl2br($focus->description));
269 $xtpl->assign('DESCRIPTION_HTML', from_html($focus->description_html));
270 $xtpl->assign('DATE_SENT', $focus->date_entered);
271 $xtpl->assign('EMAIL_NAME', 'RE: '.$focus->name);
272 $xtpl->assign("TAG", $focus->listviewACLHelper());
273 if(!empty($focus->raw_source)) {
274         $xtpl->assign("RAW_METADATA", $focus->id);
275 } else {
276         $xtpl->assign("DISABLE_RAW_BUTTON", 'none');
277 }
278
279 if(!empty($focus->reply_to_email)) {
280         $replyTo = "
281                 <tr>
282         <td class=\"tabDetailViewDL\"><slot>".$mod_strings['LBL_REPLY_TO_NAME']."</slot></td>
283         <td colspan=3 class=\"tabDetailViewDF\"><slot>".$focus->reply_to_email."</slot></td>
284         </tr>";
285         $xtpl->assign("REPLY_TO", $replyTo);
286 }
287
288 ///////////////////////////////////////////////////////////////////////////////
289 ////    JAVASCRIPT VARS
290 $jsVars  = '';
291 $jsVars .= "var showRaw = '{$mod_strings['LBL_BUTTON_RAW_LABEL']}';";
292 $jsVars .= "var hideRaw = '{$mod_strings['LBL_BUTTON_RAW_LABEL_HIDE']}';";
293 $xtpl->assign("JS_VARS", $jsVars);
294
295
296 // ADMIN EDIT
297 if(is_admin($GLOBALS['current_user']) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
298         $xtpl->assign("ADMIN_EDIT","<a href='index.php?action=index&module=DynamicLayout&from_action=".$_REQUEST['action'] ."&from_module=".$_REQUEST['module'] ."&record=".$_REQUEST['record']. "'>".SugarThemeRegistry::current()->getImage("EditLayout","border='0' alt='Edit Layout' align='bottom'")."</a>");
299 }
300
301 if(isset($_REQUEST['offset']) && !empty($_REQUEST['offset'])) { $offset = $_REQUEST['offset']; }
302 else $offset = 1;
303 $detailView->processListNavigation($xtpl, "EMAIL", $offset, false);
304
305
306
307 // adding custom fields:
308 require_once('modules/DynamicFields/templates/Files/DetailView.php');
309 $do_open = true;
310 if ($do_open) {
311         $xtpl->parse("main.open_source");
312 }
313
314 ///////////////////////////////////////////////////////////////////////////////
315 ////    NOTES (attachements, etc.)
316 ///////////////////////////////////////////////////////////////////////////////
317
318 $note = new Note();
319 $where = "notes.parent_id='{$focus->id}'";
320 //take in account if this is from campaign and the template id is stored in the macros.
321
322 if(isset($macro_values) && isset($macro_values['email_template_id'])){
323     $where = "notes.parent_id='{$macro_values['email_template_id']}'";
324 }
325 $notes_list = $note->get_full_list("notes.name", $where, true);
326
327 if(! isset($notes_list)) {
328         $notes_list = array();
329 }
330
331 $attachments = '';
332 for($i=0; $i<count($notes_list); $i++) {
333         $the_note = $notes_list[$i];
334         if(!empty($the_note->filename))
335         $attachments .= "<a href=\"index.php?entryPoint=download&id=".$the_note->id."&type=Notes\">".$the_note->name."</a><br />";
336 }
337
338 $xtpl->assign("ATTACHMENTS", $attachments);
339 $xtpl->parse("main");
340 $xtpl->out("main");
341
342 $sub_xtpl = $xtpl;
343 $old_contents = ob_get_contents();
344 ob_end_clean();
345 ob_start();
346 echo $old_contents;
347
348 ///////////////////////////////////////////////////////////////////////////////
349 ////    SUBPANELS
350 ///////////////////////////////////////////////////////////////////////////////
351 if ($show_subpanels) {
352     require_once('include/SubPanel/SubPanelTiles.php');
353     $subpanel = new SubPanelTiles($focus, 'Emails');
354     echo $subpanel->display();
355 }
356 ?>