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