| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.3 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2013 | |
| 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-2013 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | /** |
| 37 | * form to configure thank-you messages and receipting features for an online contribution page |
| 38 | */ |
| 39 | class CRM_Contribute_Form_ContributionPage_ThankYou extends CRM_Contribute_Form_ContributionPage { |
| 40 | |
| 41 | /** |
| 42 | * This function sets the default values for the form. Note that in edit/view mode |
| 43 | * the default values are retrieved from the database |
| 44 | * |
| 45 | * @access public |
| 46 | * |
| 47 | * @return void |
| 48 | */ |
| 49 | function setDefaultValues() { |
| 50 | $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title'); |
| 51 | CRM_Utils_System::setTitle(ts('Thank-you and Receipting (%1)', array(1 => $title))); |
| 52 | return parent::setDefaultValues(); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Function to actually build the form |
| 57 | * |
| 58 | * @return void |
| 59 | * @access public |
| 60 | */ |
| 61 | public function buildQuickForm() { |
| 62 | $this->registerRule('emailList', 'callback', 'emailList', 'CRM_Utils_Rule'); |
| 63 | |
| 64 | // thank you title and text (html allowed in text) |
| 65 | $this->add('text', 'thankyou_title', ts('Thank-you Page Title'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'thankyou_title'), TRUE); |
| 66 | $this->addWysiwyg('thankyou_text', ts('Thank-you Message'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'thankyou_text')); |
| 67 | $this->addWysiwyg('thankyou_footer', ts('Thank-you Page Footer'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'thankyou_footer')); |
| 68 | |
| 69 | $this->addElement('checkbox', 'is_email_receipt', ts('Email Receipt to Contributor?'), NULL, array('onclick' => "showReceipt()")); |
| 70 | $this->add('text', 'receipt_from_name', ts('Receipt From Name'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_from_name')); |
| 71 | $this->add('text', 'receipt_from_email', ts('Receipt From Email'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_from_email')); |
| 72 | $this->add('textarea', 'receipt_text', ts('Receipt Message'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_text')); |
| 73 | |
| 74 | $this->add('text', 'cc_receipt', ts('CC Receipt To'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'cc_receipt')); |
| 75 | $this->addRule('cc_receipt', ts('Please enter a valid list of comma delimited email addresses'), 'emailList'); |
| 76 | |
| 77 | $this->add('text', 'bcc_receipt', ts('BCC Receipt To'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'bcc_receipt')); |
| 78 | $this->addRule('bcc_receipt', ts('Please enter a valid list of comma delimited email addresses'), 'emailList'); |
| 79 | |
| 80 | parent::buildQuickForm(); |
| 81 | $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_ThankYou', 'formRule'), $this); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * global form rule |
| 86 | * |
| 87 | * @param array $fields the input form values |
| 88 | * @param array $files the uploaded files if any |
| 89 | * @param array $options additional user data |
| 90 | * |
| 91 | * @return true if no errors, else array of errors |
| 92 | * @access public |
| 93 | * @static |
| 94 | */ |
| 95 | static function formRule($fields, $files, $options) { |
| 96 | $errors = array(); |
| 97 | |
| 98 | // if is_email_receipt is set, the receipt message must be non-empty |
| 99 | if (CRM_Utils_Array::value('is_email_receipt', $fields)) { |
| 100 | //added for CRM-1348 |
| 101 | $email = trim(CRM_Utils_Array::value('receipt_from_email', $fields)); |
| 102 | if (empty($email) || !CRM_Utils_Rule::email($email)) { |
| 103 | $errors['receipt_from_email'] = ts('A valid Receipt From Email address must be specified if Email Receipt to Contributor is enabled'); |
| 104 | } |
| 105 | } |
| 106 | return $errors; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Process the form |
| 111 | * |
| 112 | * @return void |
| 113 | * @access public |
| 114 | */ |
| 115 | public function postProcess() { |
| 116 | // get the submitted form values. |
| 117 | $params = $this->controller->exportValues($this->_name); |
| 118 | |
| 119 | $params['id'] = $this->_id; |
| 120 | $params['is_email_receipt'] = CRM_Utils_Array::value('is_email_receipt', $params, FALSE); |
| 121 | if (!$params['is_email_receipt']) { |
| 122 | $params['receipt_from_name'] = NULL; |
| 123 | $params['receipt_from_email'] = NULL; |
| 124 | $params['receipt_text'] = NULL; |
| 125 | $params['cc_receipt'] = NULL; |
| 126 | $params['bcc_receipt'] = NULL; |
| 127 | } |
| 128 | |
| 129 | $dao = CRM_Contribute_BAO_ContributionPage::create($params); |
| 130 | parent::endPostProcess(); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Return a descriptive name for the page, used in wizard header |
| 135 | * |
| 136 | * @return string |
| 137 | * @access public |
| 138 | */ |
| 139 | public function getTitle() { |
| 140 | return ts('Thanks and Receipt'); |
| 141 | } |
| 142 | } |
| 143 | |