3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Contribute_Form_ContributionPage_Settings
extends CRM_Contribute_Form_ContributionPage
{
38 * Set variables up before form is built
42 public function preProcess() {
47 * Set default values for the form. Note that in edit/view mode
48 * the default values are retrieved from the database
53 public function setDefaultValues() {
54 $defaults = parent
::setDefaultValues();
55 $soft_credit_types = CRM_Core_OptionGroup
::values('soft_credit_type', TRUE, FALSE, FALSE, NULL, 'name');
58 $title = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage',
62 CRM_Utils_System
::setTitle(ts('Title and Settings') . " ($title)");
64 $ufJoinParams = array(
65 'module' => 'OnBehalf',
66 'entity_table' => 'civicrm_contribution_page',
67 'entity_id' => $this->_id
,
69 $onBehalfIDs = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
71 // get the first one only
72 $defaults['onbehalf_profile_id'] = $onBehalfIDs[0];
75 $ufJoinDAO = new CRM_Core_DAO_UFJoin();
76 $ufJoinDAO->module
= 'soft_credit';
77 $ufJoinDAO->entity_id
= $this->_id
;
78 if ($ufJoinDAO->find(TRUE)) {
79 $defaults['honoree_profile'] = $ufJoinDAO->uf_group_id
;
80 $jsonData = CRM_Contribute_BAO_ContributionPage
::formatMultilingualHonorParams($ufJoinDAO->module_data
, TRUE);
81 $defaults = array_merge($defaults, $jsonData);
82 $defaults['honor_block_is_active'] = $ufJoinDAO->is_active
;
85 $ufGroupDAO = new CRM_Core_DAO_UFGroup();
86 $ufGroupDAO->name
= 'honoree_individual';
87 if ($ufGroupDAO->find(TRUE)) {
88 $defaults['honoree_profile'] = $ufGroupDAO->id
;
90 $defaults['soft_credit_types'] = array(
91 CRM_Utils_Array
::value('in_honor_of', $soft_credit_types),
92 CRM_Utils_Array
::value('in_memory_of', $soft_credit_types)
97 CRM_Utils_System
::setTitle(ts('Title and Settings'));
99 $ufGroupDAO = new CRM_Core_DAO_UFGroup();
100 $ufGroupDAO->name
= 'honoree_individual';
101 if ($ufGroupDAO->find(TRUE)) {
102 $defaults['honoree_profile'] = $ufGroupDAO->id
;
104 $defaults['soft_credit_types'] = array(
105 CRM_Utils_Array
::value('in_honor_of', $soft_credit_types),
106 CRM_Utils_Array
::value('in_memory_of', $soft_credit_types)
114 * Build the form object
118 public function buildQuickForm() {
120 $this->_first
= TRUE;
121 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_ContributionPage');
124 $this->addSelect('financial_type_id', array(), TRUE);
127 $this->add('text', 'title', ts('Title'), $attributes['title'], TRUE);
129 //CRM-7362 --add campaigns.
130 CRM_Campaign_BAO_Campaign
::addCampaign($this, CRM_Utils_Array
::value('campaign_id', $this->_values
));
132 $this->addWysiwyg('intro_text', ts('Introductory Message'), $attributes['intro_text']);
134 $this->addWysiwyg('footer_text', ts('Footer Message'), $attributes['footer_text']);
136 //Register schema which will be used for OnBehalOf and HonorOf profile Selector
137 CRM_UF_Page_ProfileEditor
::registerSchemas(array('OrganizationModel', 'HouseholdModel'));
139 // is on behalf of an organization ?
140 $this->addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), NULL, array('onclick' => "showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);"));
142 $allowCoreTypes = array_merge(array('Contact', 'Organization'), CRM_Contact_BAO_ContactType
::subTypes('Organization'));
143 $allowSubTypes = array();
146 'entity_name' => 'contact_1',
147 'entity_type' => 'OrganizationModel',
151 $this->addProfileSelector('onbehalf_profile_id', ts('Organization Profile'), $allowCoreTypes, $allowSubTypes, $entities);
154 $options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1);
155 $options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2);
156 $this->addGroup($options, 'is_for_organization', ts(''));
157 $this->add('textarea', 'for_organization', ts('On behalf of Label'), $attributes['for_organization']);
159 // collect goal amount
160 $this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12));
161 $this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money
::format('99.99', ' '))), 'money');
163 // is confirmation page enabled?
164 $this->addElement('checkbox', 'is_confirm_enabled', ts('Use a confirmation page?'));
166 // is this page shareable through social media ?
167 $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
169 // is this page active ?
170 $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?'));
172 // should the honor be enabled
173 $this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), NULL, array('onclick' => "showHonor()"));
175 $this->add('text', 'honor_block_title', ts('Honoree Section Title'), array('maxlength' => 255, 'size' => 45));
177 $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), array('rows' => 2, 'cols' => 50));
179 $this->addSelect('soft_credit_types', array(
180 'label' => ts('Honor Types'),
181 'entity' => 'ContributionSoft',
182 'field' => 'soft_credit_type_id',
189 'entity_name' => 'contact_1',
190 'entity_type' => 'IndividualModel',
194 $allowCoreTypes = array_merge(array('Contact', 'Individual', 'Organization', 'Household'), CRM_Contact_BAO_ContactType
::subTypes('Individual'));
195 $allowSubTypes = array();
197 $this->addProfileSelector('honoree_profile', ts('Honoree Profile'), $allowCoreTypes, $allowSubTypes, $entities);
199 if (!empty($this->_submitValues
['honor_block_is_active'])) {
200 $this->addRule('soft_credit_types', ts('At least one value must be selected if Honor Section is active'), 'required');
201 $this->addRule('honoree_profile', ts('Please select a profile used for honoree'), 'required');
204 // add optional start and end dates
205 $this->addDateTime('start_date', ts('Start Date'));
206 $this->addDateTime('end_date', ts('End Date'));
208 $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'), $this);
210 parent
::buildQuickForm();
214 * Global validation rules for the form
216 * @param array $values posted values of the form
221 * @return array list of errors to be posted back to the form
224 public static function formRule($values, $files, $self) {
226 $contributionPageId = $self->_id
;
228 if (strstr($values['title'], '/')) {
229 $errors['title'] = ts("Please do not use '/' in Title");
232 // ensure on-behalf-of profile meets minimum requirements
233 if (!empty($values['is_organization'])) {
234 if (empty($values['onbehalf_profile_id']) ) {
235 $errors['onbehalf_profile_id'] = ts('Please select a profile to collect organization information on this contribution page.');
238 $requiredProfileFields = array('organization_name', 'email');
239 if (!CRM_Core_BAO_UFGroup
::checkValidProfile($values['onbehalf_profile_id'], $requiredProfileFields)) {
240 $errors['onbehalf_profile_id'] = ts('Profile does not contain the minimum required fields for an On Behalf Of Organization');
246 $start = CRM_Utils_Date
::processDate($values['start_date']);
247 $end = CRM_Utils_Date
::processDate($values['end_date']);
248 if (($end < $start) && ($end != 0)) {
249 $errors['end_date'] = ts('End date should be after Start date.');
252 if (!empty($self->_values
['payment_processor']) && $financialType = CRM_Contribute_BAO_Contribution
::validateFinancialType($values['financial_type_id'])) {
253 $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
256 //dont allow on behalf of save when
257 //pre or post profile consists of membership fields
258 if ($contributionPageId && !empty($values['is_organization'])) {
259 $ufJoinParams = array(
260 'module' => 'CiviContribute',
261 'entity_table' => 'civicrm_contribution_page',
262 'entity_id' => $contributionPageId,
265 list($contributionProfiles['custom_pre_id'],
266 $contributionProfiles['custom_post_id']
267 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
269 $conProfileType = NULL;
270 if ($contributionProfiles['custom_pre_id']) {
271 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($contributionProfiles['custom_pre_id']);
272 if ($preProfileType == 'Membership') {
273 $conProfileType = "'Includes Profile (top of page)'";
277 if ($contributionProfiles['custom_post_id']) {
278 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($contributionProfiles['custom_post_id']);
279 if ($postProfileType == 'Membership') {
280 $conProfileType = empty($conProfileType) ?
"'Includes Profile (bottom of page)'" : "{$conProfileType} and 'Includes Profile (bottom of page)'";
283 if (!empty($conProfileType)) {
284 $errors['is_organization'] = ts("You should move the membership related fields configured in %1 to the 'On Behalf' profile for this Contribution Page", array(1 => $conProfileType));
295 public function postProcess() {
296 // get the submitted form values.
297 $params = $this->controller
->exportValues($this->_name
);
299 // we do this in case the user has hit the forward/back button
301 $params['id'] = $this->_id
;
304 $session = CRM_Core_Session
::singleton();
305 $params['created_id'] = $session->get('userID');
306 $params['created_date'] = date('YmdHis');
307 $config = CRM_Core_Config
::singleton();
308 $params['currency'] = $config->defaultCurrency
;
311 $params['is_confirm_enabled'] = CRM_Utils_Array
::value('is_confirm_enabled', $params, FALSE);
312 $params['is_share'] = CRM_Utils_Array
::value('is_share', $params, FALSE);
313 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
314 $params['is_credit_card_only'] = CRM_Utils_Array
::value('is_credit_card_only', $params, FALSE);
315 $params['honor_block_is_active'] = CRM_Utils_Array
::value('honor_block_is_active', $params, FALSE);
316 $params['is_for_organization'] = !empty($params['is_organization']) ? CRM_Utils_Array
::value('is_for_organization', $params, FALSE) : 0;
318 $params['start_date'] = CRM_Utils_Date
::processDate($params['start_date'], $params['start_date_time'], TRUE);
319 $params['end_date'] = CRM_Utils_Date
::processDate($params['end_date'], $params['end_date_time'], TRUE);
321 $params['goal_amount'] = CRM_Utils_Rule
::cleanMoney($params['goal_amount']);
323 if (!$params['honor_block_is_active']) {
324 $params['honor_block_title'] = NULL;
325 $params['honor_block_text'] = NULL;
328 $sctJSON = CRM_Contribute_BAO_ContributionPage
::formatMultilingualHonorParams($params);
331 $dao = CRM_Contribute_BAO_ContributionPage
::create($params);
333 $ufJoinParams = array(
334 'onbehalf_profile_id' =>
337 'module' => 'OnBehalf',
338 'entity_table' => 'civicrm_contribution_page',
339 'entity_id' => $dao->id
,
341 'honor_block_is_active' =>
343 'module' => 'soft_credit',
344 'entity_table' => 'civicrm_contribution_page',
345 'entity_id' => $dao->id
,
350 foreach ($ufJoinParams as $index => $ufJoinParam) {
351 if (!empty($params[$index])) {
352 $ufJoinParam['weight'] = 1;
353 if ($index == 'honor_block_is_active') {
354 $ufJoinParam['is_active'] = 1;
355 $ufJoinParam['module'] = 'soft_credit';
356 $ufJoinParam['uf_group_id'] = $params['honoree_profile'];
357 $ufJoinParam['module_data'] = $sctJSON;
360 // first delete all past entries
361 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParam);
362 $ufJoinParam['uf_group_id'] = $params[$index];
364 CRM_Core_BAO_UFJoin
::create($ufJoinParam);
366 elseif ($index == 'honor_block_is_active') {
367 //On subsequent honor_block_is_active uncheck, disable(don't delete)
368 //that particular honoree profile entry in UFjoin table, CRM-13981
369 $ufId = CRM_Core_BAO_UFJoin
::findJoinEntryId($ufJoinParam);
371 $ufJoinParam['uf_group_id'] = CRM_Core_BAO_UFJoin
::findUFGroupId($ufJoinParam);
372 $ufJoinParam['is_active'] = 0;
373 CRM_Core_BAO_UFJoin
::create($ufJoinParam);
378 $this->set('id', $dao->id
);
379 if ($this->_action
& CRM_Core_Action
::ADD
) {
380 $url = 'civicrm/admin/contribute/amount';
381 $urlParams = "action=update&reset=1&id={$dao->id}";
382 // special case for 'Save and Done' consistency.
383 if ($this->controller
->getButtonName('submit') == '_qf_Amount_upload_done') {
384 $url = 'civicrm/admin/contribute';
385 $urlParams = 'reset=1';
386 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
387 array(1 => $this->getTitle())
388 ), ts('Saved'), 'success');
391 CRM_Utils_System
::redirect(CRM_Utils_System
::url($url, $urlParams));
393 parent
::endPostProcess();
397 * Return a descriptive name for the page, used in wizard header
401 public function getTitle() {
402 return ts('Title and Settings');