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