3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
35 * a page for mailing preview
37 class CRM_Mailing_Page_Preview
extends CRM_Core_Page
{
40 * Run this page (figure out the action needed and perform it).
42 public function run() {
44 $session = CRM_Core_Session
::singleton();
46 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', CRM_Core_DAO
::$_nullObject, FALSE, 'text');
47 $type = CRM_Utils_Request
::retrieve('type', 'String', CRM_Core_DAO
::$_nullObject, FALSE, 'text');
50 $session->getVars($options, "CRM_Mailing_Controller_Send_$qfKey");
52 // get the options if control come from search context, CRM-3711
53 if (empty($options)) {
54 $session->getVars($options, "CRM_Contact_Controller_Search_$qfKey");
57 // FIXME: the below and CRM_Mailing_Form_Test::testMail()
58 // should be refactored
60 $mailing = new CRM_Mailing_BAO_Mailing();
61 if (!empty($options)) {
62 $mailing->id
= $options['mailing_id'];
63 $fromEmail = CRM_Utils_Array
::value('from_email', $options);
68 CRM_Mailing_BAO_Mailing
::tokenReplace($mailing);
70 // get and format attachments
71 $attachments = CRM_Core_BAO_File
::getEntityFile('civicrm_mailing',
75 // get details of contact with token value including Custom Field Token Values.CRM-3734
76 $returnProperties = $mailing->getReturnProperties();
77 $params = array('contact_id' => $session->get('userID'));
79 $details = CRM_Utils_Token
::getTokenDetails($params,
82 $mailing->getFlattenedTokens(),
86 $mime = &$mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail,
87 TRUE, $details[0][$session->get('userID')], $attachments
90 if ($type == 'html') {
91 CRM_Utils_System
::setHttpHeader('Content-Type', 'text/html; charset=utf-8');
92 print $mime->getHTMLBody();
95 CRM_Utils_System
::setHttpHeader('Content-Type', 'text/plain; charset=utf-8');
96 print $mime->getTXTBody();
98 CRM_Utils_System
::civiExit();