Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
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 | /** | |
c490a46a | 42 | * Set default values for the form. Note that in edit/view mode |
6a488035 TO |
43 | * the default values are retrieved from the database |
44 | * | |
6a488035 TO |
45 | * |
46 | * @return void | |
47 | */ | |
00be9182 | 48 | public function setDefaultValues() { |
6a488035 | 49 | $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title'); |
251668d9 | 50 | CRM_Utils_System::setTitle(ts('Thank-you and Receipting') . " ($title)"); |
6a488035 TO |
51 | return parent::setDefaultValues(); |
52 | } | |
53 | ||
54 | /** | |
fe482240 | 55 | * Build the form object. |
6a488035 TO |
56 | * |
57 | * @return void | |
6a488035 TO |
58 | */ |
59 | public function buildQuickForm() { | |
60 | $this->registerRule('emailList', 'callback', 'emailList', 'CRM_Utils_Rule'); | |
61 | ||
62 | // thank you title and text (html allowed in text) | |
63 | $this->add('text', 'thankyou_title', ts('Thank-you Page Title'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'thankyou_title'), TRUE); | |
2b99bb42 DG |
64 | |
65 | $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'thankyou_text'); | |
874c9be7 | 66 | $attributes['click_wysiwyg'] = TRUE; |
2b99bb42 DG |
67 | $this->addWysiwyg('thankyou_text', ts('Thank-you Message'), $attributes); |
68 | // FIXME: This hack forces height of editor to 175px. Need to modify QF classes for editors to allow passing | |
69 | // explicit height and width. | |
70 | $footerAttribs = array( | |
71 | 'rows' => 2, | |
72 | 'cols' => 40, | |
874c9be7 | 73 | 'click_wysiwyg' => TRUE, |
2b99bb42 DG |
74 | ); |
75 | $this->addWysiwyg('thankyou_footer', ts('Thank-you Footer'), $footerAttribs); | |
6a488035 TO |
76 | |
77 | $this->addElement('checkbox', 'is_email_receipt', ts('Email Receipt to Contributor?'), NULL, array('onclick' => "showReceipt()")); | |
78 | $this->add('text', 'receipt_from_name', ts('Receipt From Name'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_from_name')); | |
79 | $this->add('text', 'receipt_from_email', ts('Receipt From Email'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_from_email')); | |
80 | $this->add('textarea', 'receipt_text', ts('Receipt Message'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_text')); | |
81 | ||
82 | $this->add('text', 'cc_receipt', ts('CC Receipt To'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'cc_receipt')); | |
83 | $this->addRule('cc_receipt', ts('Please enter a valid list of comma delimited email addresses'), 'emailList'); | |
84 | ||
85 | $this->add('text', 'bcc_receipt', ts('BCC Receipt To'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'bcc_receipt')); | |
86 | $this->addRule('bcc_receipt', ts('Please enter a valid list of comma delimited email addresses'), 'emailList'); | |
87 | ||
88 | parent::buildQuickForm(); | |
89 | $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_ThankYou', 'formRule'), $this); | |
90 | } | |
91 | ||
92 | /** | |
fe482240 | 93 | * Global form rule. |
6a488035 | 94 | * |
014c4014 TO |
95 | * @param array $fields |
96 | * The input form values. | |
97 | * @param array $files | |
98 | * The uploaded files if any. | |
99 | * @param array $options | |
100 | * Additional user data. | |
6a488035 | 101 | * |
72b3a70c CW |
102 | * @return bool|array |
103 | * true if no errors, else array of errors | |
6a488035 | 104 | */ |
00be9182 | 105 | public static function formRule($fields, $files, $options) { |
6a488035 TO |
106 | $errors = array(); |
107 | ||
108 | // if is_email_receipt is set, the receipt message must be non-empty | |
a7488080 | 109 | if (!empty($fields['is_email_receipt'])) { |
6a488035 TO |
110 | //added for CRM-1348 |
111 | $email = trim(CRM_Utils_Array::value('receipt_from_email', $fields)); | |
112 | if (empty($email) || !CRM_Utils_Rule::email($email)) { | |
113 | $errors['receipt_from_email'] = ts('A valid Receipt From Email address must be specified if Email Receipt to Contributor is enabled'); | |
114 | } | |
115 | } | |
116 | return $errors; | |
117 | } | |
118 | ||
119 | /** | |
fe482240 | 120 | * Process the form. |
6a488035 TO |
121 | * |
122 | * @return void | |
6a488035 TO |
123 | */ |
124 | public function postProcess() { | |
125 | // get the submitted form values. | |
126 | $params = $this->controller->exportValues($this->_name); | |
127 | ||
128 | $params['id'] = $this->_id; | |
129 | $params['is_email_receipt'] = CRM_Utils_Array::value('is_email_receipt', $params, FALSE); | |
130 | if (!$params['is_email_receipt']) { | |
131 | $params['receipt_from_name'] = NULL; | |
132 | $params['receipt_from_email'] = NULL; | |
133 | $params['receipt_text'] = NULL; | |
134 | $params['cc_receipt'] = NULL; | |
135 | $params['bcc_receipt'] = NULL; | |
136 | } | |
137 | ||
138 | $dao = CRM_Contribute_BAO_ContributionPage::create($params); | |
139 | parent::endPostProcess(); | |
140 | } | |
141 | ||
142 | /** | |
143 | * Return a descriptive name for the page, used in wizard header | |
144 | * | |
145 | * @return string | |
6a488035 TO |
146 | */ |
147 | public function getTitle() { | |
148 | return ts('Thanks and Receipt'); | |
149 | } | |
96025800 | 150 | |
6a488035 | 151 | } |