Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for Tell A Friend | |
38 | * | |
39 | */ | |
40 | class CRM_PCP_Form_Contribute extends CRM_Contribute_Form_ContributionPage { | |
41 | ||
42 | /** | |
43 | * the type of pcp component. | |
44 | * | |
45 | * @var int | |
46 | * @protected | |
47 | */ | |
48 | public $_component = 'contribute'; | |
49 | ||
50 | public function preProcess() { | |
51 | parent::preProcess(); | |
52 | } | |
53 | ||
54 | /** | |
55 | * This function sets the default values for the form. Note that in edit/view mode | |
56 | * the default values are retrieved from the database | |
57 | * | |
58 | * @access public | |
59 | * | |
355ba699 | 60 | * @return void |
6a488035 TO |
61 | */ |
62 | public function setDefaultValues() { | |
63 | // $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title' ); | |
64 | // CRM_Utils_System::setTitle(ts('Personal Campaign Page Settings (%1)', array(1 => $title))); | |
65 | ||
66 | $defaults = array(); | |
67 | ||
68 | if (isset($this->_id)) { | |
69 | $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_contribution_page'); | |
70 | CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $defaults); | |
71 | $defaults['pcp_active'] = CRM_Utils_Array::value('is_active', $defaults); | |
72 | // Assign contribution page ID to pageId for referencing in PCP.hlp - since $id is overwritten there. dgg | |
73 | $this->assign('pageId', $this->_id); | |
74 | } | |
75 | ||
a7488080 | 76 | if (empty($defaults['id'])) { |
6a488035 TO |
77 | $defaults['target_entity_type'] = 'contribute'; |
78 | $defaults['is_approval_needed'] = 1; | |
79 | $defaults['is_tellfriend_enabled'] = 1; | |
80 | $defaults['tellfriend_limit'] = 5; | |
81 | $defaults['link_text'] = ts('Create your own fundraising page'); | |
82 | ||
83 | if ($ccReceipt = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'cc_receipt')) { | |
84 | $defaults['notify_email'] = $ccReceipt; | |
85 | } | |
86 | } | |
87 | return $defaults; | |
88 | } | |
89 | ||
90 | /** | |
91 | * Function to build the form | |
92 | * | |
355ba699 | 93 | * @return void |
6a488035 TO |
94 | * @access public |
95 | */ | |
96 | public function buildQuickForm() { | |
97 | CRM_PCP_BAO_PCP::buildPCPForm($this); | |
98 | ||
99 | $this->addElement('checkbox', 'pcp_active', ts('Enable Personal Campaign Pages? (for this contribution page)'), NULL, array('onclick' => "return showHideByValue('pcp_active',true,'pcpFields','table-row','radio',false);")); | |
100 | ||
101 | parent::buildQuickForm(); | |
102 | $this->addFormRule(array('CRM_PCP_Form_Contribute', 'formRule'), $this); | |
103 | } | |
104 | ||
105 | /** | |
106 | * Function for validation | |
107 | * | |
108 | * @param array $params (ref.) an assoc array of name/value pairs | |
109 | * | |
110 | * @return mixed true or array of errors | |
111 | * @access public | |
112 | * @static | |
113 | */ | |
114 | public static function formRule($params, $files, $self) { | |
115 | $errors = array(); | |
a7488080 | 116 | if (!empty($params['is_active'])) { |
6a488035 | 117 | |
a7488080 | 118 | if (!empty($params['is_tellfriend_enabled']) && |
6a488035 TO |
119 | (CRM_Utils_Array::value('tellfriend_limit', $params) <= 0) |
120 | ) { | |
121 | $errors['tellfriend_limit'] = ts('if Tell Friend is enabled, Maximum recipients limit should be greater than zero.'); | |
122 | } | |
a7488080 | 123 | if (empty($params['supporter_profile_id'])) { |
6a488035 TO |
124 | $errors['supporter_profile_id'] = ts('Supporter profile is a required field.'); |
125 | } | |
126 | else { | |
127 | if (CRM_PCP_BAO_PCP::checkEmailProfile($params['supporter_profile_id'])) { | |
128 | $errors['supporter_profile_id'] = ts('Profile is not configured with Email address.'); | |
129 | } | |
130 | } | |
131 | ||
132 | if ($emails = CRM_Utils_Array::value('notify_email', $params)) { | |
133 | $emailArray = explode(',', $emails); | |
134 | foreach ($emailArray as $email) { | |
135 | if ($email && !CRM_Utils_Rule::email(trim($email))) { | |
136 | $errors['notify_email'] = ts('A valid Notify Email address must be specified'); | |
137 | } | |
138 | } | |
139 | } | |
140 | } | |
141 | return empty($errors) ? TRUE : $errors; | |
142 | } | |
143 | ||
144 | /** | |
145 | * Function to process the form | |
146 | * | |
147 | * @access public | |
148 | * | |
355ba699 | 149 | * @return void |
6a488035 TO |
150 | */ |
151 | public function postProcess() { | |
152 | // get the submitted form values. | |
153 | $params = $this->controller->exportValues($this->_name); | |
154 | ||
155 | // Source | |
156 | $params['entity_table'] = 'civicrm_contribution_page'; | |
157 | $params['entity_id'] = $this->_id; | |
158 | ||
159 | // Target | |
160 | $params['target_entity_type'] = CRM_Utils_Array::value('target_entity_type', $params, 'contribute'); | |
161 | $params['target_entity_id'] = $this->_id; | |
162 | ||
163 | $dao = new CRM_PCP_DAO_PCPBlock(); | |
164 | $dao->entity_table = $params['entity_table']; | |
165 | $dao->entity_id = $this->_id; | |
166 | $dao->find(TRUE); | |
167 | $params['id'] = $dao->id; | |
168 | $params['is_active'] = CRM_Utils_Array::value('pcp_active', $params, FALSE); | |
169 | $params['is_approval_needed'] = CRM_Utils_Array::value('is_approval_needed', $params, FALSE); | |
170 | $params['is_tellfriend_enabled'] = CRM_Utils_Array::value('is_tellfriend_enabled', $params, FALSE); | |
171 | ||
172 | $dao = CRM_PCP_BAO_PCP::add($params); | |
173 | ||
174 | parent::endPostProcess(); | |
175 | } | |
176 | ||
177 | /** | |
178 | * Return a descriptive name for the page, used in wizard header | |
179 | * | |
180 | * @return string | |
181 | * @access public | |
182 | */ | |
183 | public function getTitle() { | |
184 | return ts('Enable Personal Campaign Pages'); | |
185 | } | |
186 | } | |
187 |