| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 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. | |
| 13 | | | |
| 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. | |
| 18 | | | |
| 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 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | /** |
| 37 | * a page for mailing preview |
| 38 | */ |
| 39 | class CRM_Mailing_Page_Preview extends CRM_Core_Page { |
| 40 | |
| 41 | /** |
| 42 | * run this page (figure out the action needed and perform it). |
| 43 | * |
| 44 | * @return void |
| 45 | */ |
| 46 | function run() { |
| 47 | |
| 48 | $session = CRM_Core_Session::singleton(); |
| 49 | |
| 50 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text'); |
| 51 | $type = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text'); |
| 52 | |
| 53 | $options = array(); |
| 54 | $session->getVars($options, "CRM_Mailing_Controller_Send_$qfKey"); |
| 55 | |
| 56 | //get the options if control come from search context, CRM-3711 |
| 57 | if (empty($options)) { |
| 58 | $session->getVars($options, "CRM_Contact_Controller_Search_$qfKey"); |
| 59 | } |
| 60 | |
| 61 | // FIXME: the below and CRM_Mailing_Form_Test::testMail() |
| 62 | // should be refactored |
| 63 | $fromEmail = NULL; |
| 64 | $mailing = new CRM_Mailing_BAO_Mailing(); |
| 65 | if (!empty($options)) { |
| 66 | $mailing->id = $options['mailing_id']; |
| 67 | $fromEmail = CRM_Utils_Array::value('from_email', $options); |
| 68 | } |
| 69 | |
| 70 | $mailing->find(TRUE); |
| 71 | |
| 72 | CRM_Mailing_BAO_Mailing::tokenReplace($mailing); |
| 73 | |
| 74 | // get and format attachments |
| 75 | $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', |
| 76 | $mailing->id |
| 77 | ); |
| 78 | |
| 79 | //get details of contact with token value including Custom Field Token Values.CRM-3734 |
| 80 | $returnProperties = $mailing->getReturnProperties(); |
| 81 | $params = array('contact_id' => $session->get('userID')); |
| 82 | |
| 83 | $details = CRM_Utils_Token::getTokenDetails($params, |
| 84 | $returnProperties, |
| 85 | TRUE, TRUE, NULL, |
| 86 | $mailing->getFlattenedTokens(), |
| 87 | get_class($this) |
| 88 | ); |
| 89 | |
| 90 | $mime = &$mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, |
| 91 | TRUE, $details[0][$session->get('userID')], $attachments |
| 92 | ); |
| 93 | |
| 94 | if ($type == 'html') { |
| 95 | header('Content-Type: text/html; charset=utf-8'); |
| 96 | print $mime->getHTMLBody(); |
| 97 | } |
| 98 | else { |
| 99 | header('Content-Type: text/plain; charset=utf-8'); |
| 100 | print $mime->getTXTBody(); |
| 101 | } |
| 102 | CRM_Utils_System::civiExit(); |
| 103 | } |
| 104 | } |
| 105 | |