]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Emails/DetailView.php
Release 6.5.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-2012 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 global $focus;
59
60 // SETTING DEFAULTS
61 $focus          = new Email();
62 $detailView     = new DetailView();
63 $offset         = 0;
64 $email_type     = 'archived';
65
66 ///////////////////////////////////////////////////////////////////////////////
67 ////    TO HANDLE 'NEXT FREE'
68 if(!empty($_REQUEST['next_free']) && $_REQUEST['next_free'] == true) {
69         $_REQUEST['record'] = $focus->getNextFree();
70 }
71 ////    END 'NEXT FREE'
72 ///////////////////////////////////////////////////////////////////////////////
73
74 if (isset($_REQUEST['offset']) or isset($_REQUEST['record'])) {
75         $result = $detailView->processSugarBean("EMAIL", $focus, $offset);
76         if($result == null) {
77             sugar_die($app_strings['ERROR_NO_RECORD']);
78         }
79         $focus=$result;
80 } else {
81         header("Location: index.php?module=Emails&action=index");
82         die();
83 }
84
85 /* if the Email status is draft, say as a saved draft to a Lead/Case/etc.,
86  * don't show detail view. go directly to EditView */
87 if($focus->status == 'draft') {
88         //header('Location: index.php?module=Emails&action=EditView&record='.$_REQUEST['record']);
89         //die();
90 }
91
92 // ACL Access Check
93 if (!$focus->ACLAccess('DetailView')){
94         ACLController::displayNoAccess(true);
95         sugar_cleanup(true);
96 }
97
98 //needed when creating a new email with default values passed in
99 if (isset($_REQUEST['contact_name']) && is_null($focus->contact_name)) {
100         $focus->contact_name = $_REQUEST['contact_name'];
101 }
102 if (isset($_REQUEST['contact_id']) && is_null($focus->contact_id)) {
103         $focus->contact_id = $_REQUEST['contact_id'];
104 }
105 if (isset($_REQUEST['opportunity_name']) && is_null($focus->parent_name)) {
106         $focus->parent_name = $_REQUEST['opportunity_name'];
107 }
108 if (isset($_REQUEST['opportunity_id']) && is_null($focus->parent_id)) {
109         $focus->parent_id = $_REQUEST['opportunity_id'];
110 }
111 if (isset($_REQUEST['account_name']) && is_null($focus->parent_name)) {
112         $focus->parent_name = $_REQUEST['account_name'];
113 }
114 if (isset($_REQUEST['account_id']) && is_null($focus->parent_id)) {
115         $focus->parent_id = $_REQUEST['account_id'];
116 }
117
118 // un/READ flags
119 if (!empty($focus->status)) {
120         // "Read" flag for InboundEmail
121         if($focus->status == 'unread') {
122                 // creating a new instance here to avoid data corruption below
123                 $e = new Email();
124                 $e->retrieve($focus->id);
125                 $e->status = 'read';
126                 $e->save();
127                 $email_type = $e->status;
128         } else {
129                 $email_type = $focus->status;
130         }
131
132 } elseif (!empty($_REQUEST['type'])) {
133         $email_type = $_REQUEST['type'];
134 }
135
136
137 ///////////////////////////////////////////////////////////////////////////////
138 ////    OUTPUT
139 ///////////////////////////////////////////////////////////////////////////////
140 echo "\n<p>\n";
141 $GLOBALS['log']->info("Email detail view");
142 $show_forward = true;
143 if ($email_type == 'archived') {
144         echo getClassicModuleTitle('Emails', array($mod_strings['LBL_ARCHIVED_EMAIL'],$focus->name), true);
145         $xtpl=new XTemplate ('modules/Emails/DetailView.html');
146 } else {
147         $xtpl=new XTemplate ('modules/Emails/DetailViewSent.html');
148         if($focus->type == 'out') {
149                 echo getClassicModuleTitle('Emails', array($mod_strings['LBL_SENT_MODULE_NAME'],$focus->name), true);
150                 //$xtpl->assign('DISABLE_REPLY_BUTTON', 'NONE');
151         } elseif ($focus->type == 'draft') {
152                 $xtpl->assign('DISABLE_FORWARD_BUTTON', 'NONE');
153         $show_forward = false;
154                 echo getClassicModuleTitle('Emails', array($mod_strings['LBL_LIST_FORM_DRAFTS_TITLE'],$focus->name), true);
155         } elseif($focus->type == 'inbound') {
156                 echo getClassicModuleTitle('Emails', array($mod_strings['LBL_INBOUND_TITLE'],$focus->name), true);
157         }
158 }
159 echo "\n</p>\n";
160
161
162
163 ///////////////////////////////////////////////////////////////////////////////
164 ////    RETURN NAVIGATION
165 $uri = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'index.php';
166 $start = $focus->getStartPage($uri);
167 $ret_mod = '';
168 $ret_action = '';
169 if (isset($_REQUEST['return_id'])) { // coming from a subpanel, return_module|action is not set
170         $xtpl->assign('RETURN_ID', $_REQUEST['return_id']);
171         if (isset($_REQUEST['return_module'])){
172         $xtpl->assign('RETURN_MODULE', $_REQUEST['return_module']);
173         $ret_mod = $_REQUEST['return_module'];
174     }
175         else {
176         $xtpl->assign('RETURN_MODULE', 'Emails');
177         $ret_mod = 'Emails';
178     }
179         if (isset($_REQUEST['return_action'])){
180         $xtpl->assign('RETURN_ACTION', $_REQUEST['return_action']);
181         $ret_action = $_REQUEST['return_action'];
182     }
183         else {
184         $xtpl->assign('RETURN_ACTION', 'DetailView');
185         $ret_action = 'DetailView';
186     }
187 }
188
189 if(isset($start['action']) && !empty($start['action'])) {
190     $xtpl->assign('DELETE_RETURN_ACTION', $start['action']);
191 } else {
192     $start['action'] = '';
193 }
194 if(isset($start['module']) && !empty($start['module'])) {
195     $xtpl->assign('DELETE_RETURN_MODULE', $start['module']);
196 } else {
197     $start['module'] = '';
198 }
199 if(isset($start['record']) && !empty($start['record'])) {
200     $xtpl->assign('DELETE_RETURN_ID', $start['record']);
201 } else {
202     $start['record'] = '';
203 }
204 // this is to support returning to My Inbox
205 if(isset($start['type']) && !empty($start['type'])) {
206     $xtpl->assign('DELETE_RETURN_TYPE', $start['type']);
207 } else {
208     $start['type'] = '';
209 }
210 if(isset($start['assigned_user_id']) && !empty($start['assigned_user_id'])) {
211     $xtpl->assign('DELETE_RETURN_ASSIGNED_USER_ID', $start['assigned_user_id']);
212 } else {
213     $start['assigned_user_id'] = '';
214 }
215
216
217
218 ////    END RETURN NAVIGATION
219 ///////////////////////////////////////////////////////////////////////////////
220
221
222 // DEFAULT TO TEXT IF NO HTML CONTENT:
223 $html = trim(from_html($focus->description_html));
224 if(empty($html)) {
225         $xtpl->assign('SHOW_PLAINTEXT', 'true');
226 } else {
227         $xtpl->assign('SHOW_PLAINTEXT', 'false');
228 }
229 $show_subpanels=true;
230 //if the email is of type campaign, process the macros...using the values stored in the relationship table.
231 //this is is part of the feature that adds support for one email per campaign.
232 if ($focus->type=='campaign' and !empty($_REQUEST['parent_id']) and !empty($_REQUEST['parent_module'])) {
233     $show_subpanels=false;
234     $parent_id=$_REQUEST['parent_id'];
235
236         // cn: bug 14300 - emails_beans schema refactor - fixing query
237         $query="SELECT * FROM emails_beans WHERE email_id='{$focus->id}' AND bean_id='{$parent_id}' AND bean_module = '{$_REQUEST['parent_module']}' " ;
238
239     $res=$focus->db->query($query);
240     $row=$focus->db->fetchByAssoc($res);
241     if (!empty($row)) {
242         $campaign_data=$row['campaign_data'];
243         $macro_values=array();
244         if (!empty($campaign_data)) {
245             $macro_values=unserialize(from_html($campaign_data));
246         }
247
248         if (count($macro_values) > 0) {
249             $m_keys=array_keys($macro_values);
250             $m_values=array_values($macro_values);
251
252             $focus->name = str_replace($m_keys,$m_values,$focus->name);
253             $focus->description = str_replace($m_keys,$m_values,$focus->description);
254             $focus->description_html = str_replace($m_keys,$m_values,$focus->description_html);
255             if (!empty($macro_values['sugar_to_email_address'])) {
256                 $focus->to_addrs=$macro_values['sugar_to_email_address'];
257             }
258         }
259     }
260 }
261 //if not empty or set to test (from test campaigns)
262 if (!empty($focus->parent_type) && $focus->parent_type !='test') {
263         $xtpl->assign('PARENT_MODULE', $focus->parent_type);
264         $xtpl->assign('PARENT_TYPE_UNTRANSLATE', $focus->parent_type);
265     $xtpl->assign('PARENT_TYPE', $app_list_strings['record_type_display'][$focus->parent_type] . ':');
266 }
267
268 $to_addr = !empty($focus->to_addrs_names) ? htmlspecialchars($focus->to_addrs_names, ENT_COMPAT, 'UTF-8') : nl2br($focus->to_addrs);
269 $from_addr = !empty($focus->from_addr_name) ? htmlspecialchars($focus->from_addr_name, ENT_COMPAT, 'UTF-8') : nl2br($focus->from_addr);
270 $cc_addr = !empty($focus->cc_addrs_names) ? htmlspecialchars($focus->cc_addrs_names, ENT_COMPAT, 'UTF-8') : nl2br($focus->cc_addrs);
271 $bcc_addr = !empty($focus->bcc_addrs_names) ? htmlspecialchars($focus->bcc_addrs_names, ENT_COMPAT, 'UTF-8') : nl2br($focus->bcc_addrs);
272
273 $xtpl->assign('MOD', $mod_strings);
274 $xtpl->assign('APP', $app_strings);
275 $xtpl->assign('GRIDLINE', $gridline);
276 $xtpl->assign('PRINT_URL', 'index.php?'.$GLOBALS['request_string']);
277 $xtpl->assign('ID', $focus->id);
278 $xtpl->assign('TYPE', $email_type);
279 $xtpl->assign('PARENT_NAME', $focus->parent_name);
280 $xtpl->assign('PARENT_ID', $focus->parent_id);
281 $xtpl->assign('NAME', $focus->name);
282 $xtpl->assign('ASSIGNED_TO', $focus->assigned_user_name);
283 $xtpl->assign('DATE_MODIFIED', $focus->date_modified);
284 $xtpl->assign('DATE_ENTERED', $focus->date_entered);
285 $xtpl->assign('DATE_START', $focus->date_start);
286 $xtpl->assign('TIME_START', $focus->time_start);
287 $xtpl->assign('FROM', $from_addr);
288 $xtpl->assign('TO', $to_addr);
289 $xtpl->assign('CC', $cc_addr);
290 $xtpl->assign('BCC', $bcc_addr);
291 $xtpl->assign('CREATED_BY', $focus->created_by_name);
292 $xtpl->assign('MODIFIED_BY', $focus->modified_by_name);
293 $xtpl->assign('DATE_SENT', $focus->date_entered);
294 $xtpl->assign('EMAIL_NAME', 'RE: '.$focus->name);
295 $xtpl->assign("TAG", $focus->listviewACLHelper());
296
297 $show_raw = FALSE;
298 if(!empty($focus->raw_source)) {
299     $xtpl->assign("RAW_METADATA", $focus->id);
300     $show_raw = TRUE;
301 }
302
303 if(!empty($focus->reply_to_email)) {
304         $replyTo = "
305                 <tr>
306         <td class=\"tabDetailViewDL\"><slot>".$mod_strings['LBL_REPLY_TO_NAME']."</slot></td>
307         <td colspan=3 class=\"tabDetailViewDF\"><slot>".$focus->reply_to_email."</slot></td>
308         </tr>";
309         $xtpl->assign("REPLY_TO", $replyTo);
310 }
311
312
313
314 // Using action menu (new UI) instead of buttons for Archived Email DetailView.
315 $buttons = array(
316     <<<EOD
317             <input      title="{$app_strings['LBL_EDIT_BUTTON_TITLE']}" accessKey="{$app_strings['LBL_EDIT_BUTTON_KEY']}" class="button"
318                     id="edit_button"
319                                         onclick="       this.form.return_module.value='Emails';
320                                                                 this.form.return_action.value='DetailView';
321                                                                 this.form.return_id.value='{$focus->id}';
322                                                                 this.form.action.value='EditView'"
323                                         type="submit" name="Edit" value=" {$app_strings['LBL_EDIT_BUTTON_LABEL']}">
324 EOD
325 ,
326     <<<EOD
327             <input title="{$app_strings['LBL_DELETE_BUTTON_TITLE']}"
328                                         accessKey="{$app_strings['LBL_DELETE_BUTTON_KEY']}"
329                                         class="button"
330                                         id="delete_button"
331                                         onclick="this.form.return_module.value='{$start['module']}';
332                                                                                         this.form.return_action.value='{$start['action']}';
333                                                                                         this.form.return_id.value='{$start['record']}';
334                                                                                         this.form.type.value='{$start['type']}';
335                                                                                         this.form.assigned_user_id.value='{$start['assigned_user_id']}';
336                                                                                         this.form.action.value='Delete';
337                                                                                         return confirm('{$app_strings['NTC_DELETE_CONFIRMATION']}')"
338                                         type="submit" name="button"
339                                         value="{$app_strings['LBL_DELETE_BUTTON_LABEL']}"
340                         >
341 EOD
342 );
343
344 // Bug #52046: Disable the 'Show Raw' link where it does not need to be shown.
345 if($show_raw) {
346     $buttons[] = <<<EOD
347         <input type="button" name="button" class="button"
348             id="rawButton"
349             title="{$mod_strings['LBL_BUTTON_RAW_TITLE']}"
350             value="{$mod_strings['LBL_BUTTON_RAW_LABEL']}"
351             onclick="open_popup('Emails', 800, 600, '', true, true, '', 'show_raw', '', '{$focus->id}');"
352         />
353 EOD;
354 }
355
356 require_once('include/Smarty/plugins/function.sugar_action_menu.php');
357 $action_button = smarty_function_sugar_action_menu(array(
358     'id' => 'detail_header_action_menu',
359     'buttons' => $buttons,
360     'class' => 'clickMenu fancymenu',
361 ), $xtpl);
362
363 $xtpl->assign("ACTION_BUTTON", $action_button);
364
365 /////////
366 ///Using action menu (new UI) instead of buttons for Sent Email DetailView.
367 $buttons_sent_email = array();
368 if($show_forward){
369 $buttons_sent_email[] = <<<EOD
370             <input title="{$mod_strings['LBL_BUTTON_FORWARD']}"
371                                         class="button" onclick="this.form.return_module.value='{$ret_mod}';
372                                                                                         this.form.return_action.value='{$ret_action}';
373                                                                                         this.form.return_id.value='{$focus->id}';
374                                                                                         this.form.action.value='EditView';
375                                                                                         this.form.type.value='forward'"
376                                         type="submit" name="button"
377                                         value="  {$mod_strings['LBL_BUTTON_FORWARD']}  "
378                                         style="display:{DISABLE_FORWARD_BUTTON};"
379                         >
380 EOD;
381 }
382 $buttons_sent_email[] = <<<EOD
383             <input title="{$mod_strings['LBL_BUTTON_REPLY_TITLE']}"
384                                         class="button" onclick="this.form.return_module.value='{$ret_mod}';
385                                                                                         this.form.return_action.value='{$ret_action}';
386                                                                                         this.form.return_id.value='{$focus->id}';
387                                                                                         this.form.action.value='EditView'"
388                                         type="submit" name="button"
389                                         value="  {$mod_strings['LBL_BUTTON_REPLY']}  "
390                         >
391 EOD;
392 $buttons_sent_email[] = <<<EOD
393             <input title="{$app_strings['LBL_DELETE_BUTTON_TITLE']}"
394                                         accessKey="{$app_strings['LBL_DELETE_BUTTON_KEY']}"
395                                         class="button" onclick="this.form.return_module.value='{$start['module']}';
396                                                                                         this.form.return_action.value='{$start['action']}';
397                                                                                         this.form.return_id.value='{$start['record']}';
398                                                                                         this.form.type.value='{$start['type']}';
399                                                                                         this.form.assigned_user_id.value='{$start['assigned_user_id']}';
400                                                                                         this.form.action.value='Delete';
401                                                                                         return confirm('{$app_strings['NTC_DELETE_CONFIRMATION']}')"
402                                         type="submit" name="button"
403                                         value="    {$app_strings['LBL_DELETE_BUTTON']}    "
404                         >
405 EOD;
406
407 if($show_raw) {
408     $buttons_sent_email[] = <<<EOD
409             <input type="button" name="button" class="button"
410                                 id="rawButton"
411                                 title="{$mod_strings['LBL_BUTTON_RAW_TITLE']}"
412                                 value=" {$mod_strings['LBL_BUTTON_RAW_LABEL']} "
413                                 onclick="open_popup('Emails', 800, 600, '', true, true, '', 'show_raw', '', '{$focus->id}');"
414                         />
415 EOD;
416 }
417
418 require_once('include/Smarty/plugins/function.sugar_action_menu.php');
419 $action_button_sent_email = smarty_function_sugar_action_menu(array(
420     'id' => 'detail_header_action_menu',
421     'buttons' => $buttons_sent_email,
422     'class' => 'clickMenu fancymenu',
423 ), $xtpl);
424
425 $xtpl->assign("ACTION_BUTTON_SENT_EMAIL", $action_button_sent_email);
426
427 ///////////////////////////////////////////////////////////////////////////////
428 ////    JAVASCRIPT VARS
429 $jsVars  = '';
430 $jsVars .= "var showRaw = '{$mod_strings['LBL_BUTTON_RAW_LABEL']}';";
431 $jsVars .= "var hideRaw = '{$mod_strings['LBL_BUTTON_RAW_LABEL_HIDE']}';";
432 $xtpl->assign("JS_VARS", $jsVars);
433
434
435 // ADMIN EDIT
436 if(is_admin($GLOBALS['current_user']) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
437         $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' align='bottom'",null,null,'.gif',$mod_strings['LBL_EDIT_LAYOUT'])."</a>");
438 }
439
440 if(isset($_REQUEST['offset']) && !empty($_REQUEST['offset'])) { $offset = $_REQUEST['offset']; }
441 else $offset = 1;
442 $detailView->processListNavigation($xtpl, "EMAIL", $offset, false);
443
444
445
446 // adding custom fields:
447 require_once('modules/DynamicFields/templates/Files/DetailView.php');
448 $do_open = true;
449 if ($do_open) {
450         $xtpl->parse("main.open_source");
451 }
452
453 ///////////////////////////////////////////////////////////////////////////////
454 ////    NOTES (attachements, etc.)
455 ///////////////////////////////////////////////////////////////////////////////
456
457 $note = new Note();
458 $where = "notes.parent_id='{$focus->id}'";
459 //take in account if this is from campaign and the template id is stored in the macros.
460
461 if(isset($macro_values) && isset($macro_values['email_template_id'])){
462     $where = "notes.parent_id='{$macro_values['email_template_id']}'";
463 }
464 $notes_list = $note->get_full_list("notes.name", $where, true);
465
466 if(! isset($notes_list)) {
467         $notes_list = array();
468 }
469
470 $attachments = '';
471 for($i=0; $i<count($notes_list); $i++) {
472         $the_note = $notes_list[$i];
473         if(!empty($the_note->filename))
474         $attachments .= "<a href=\"index.php?entryPoint=download&id=".$the_note->id."&type=Notes\">".$the_note->name."</a><br />";
475     $focus->cid2Link($the_note->id, $the_note->file_mime_type);
476 }
477
478 $xtpl->assign('DESCRIPTION', nl2br($focus->description));
479 $xtpl->assign('DESCRIPTION_HTML', from_html($focus->description_html));
480 $xtpl->assign("ATTACHMENTS", $attachments);
481 $xtpl->parse("main");
482 $xtpl->out("main");
483
484 $sub_xtpl = $xtpl;
485 $old_contents = ob_get_contents();
486 ob_end_clean();
487 ob_start();
488 echo $old_contents;
489
490 ///////////////////////////////////////////////////////////////////////////////
491 ////    SUBPANELS
492 ///////////////////////////////////////////////////////////////////////////////
493 if ($show_subpanels) {
494     require_once('include/SubPanel/SubPanelTiles.php');
495     $subpanel = new SubPanelTiles($focus, 'Emails');
496     echo $subpanel->display();
497 }
498 ?>