3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
33 class CRM_Contribute_Form_ContributionPage_Settings
extends CRM_Contribute_Form_ContributionPage
{
36 * Set variables up before form is built.
38 public function preProcess() {
43 * Set default values for the form.
45 public function setDefaultValues() {
46 $defaults = parent
::setDefaultValues();
47 $soft_credit_types = CRM_Core_OptionGroup
::values('soft_credit_type', TRUE, FALSE, FALSE, NULL, 'name');
50 $title = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage',
54 CRM_Utils_System
::setTitle(ts('Title and Settings') . " ($title)");
56 foreach (array('on_behalf', 'soft_credit') as $module) {
57 $ufJoinDAO = new CRM_Core_DAO_UFJoin();
58 $ufJoinDAO->module
= $module;
59 $ufJoinDAO->entity_id
= $this->_id
;
60 if ($ufJoinDAO->find(TRUE)) {
61 $jsonData = CRM_Contribute_BAO_ContributionPage
::formatModuleData($ufJoinDAO->module_data
, TRUE, $module);
62 if ($module == 'soft_credit') {
63 $defaults['honoree_profile'] = $ufJoinDAO->uf_group_id
;
64 $defaults = array_merge($defaults, $jsonData);
65 $defaults['honor_block_is_active'] = $ufJoinDAO->is_active
;
68 $defaults['onbehalf_profile_id'] = $ufJoinDAO->uf_group_id
;
69 $defaults = array_merge($defaults, $jsonData);
70 $defaults['is_organization'] = $ufJoinDAO->is_active
;
74 if ($module == 'soft_credit') {
75 $ufGroupDAO = new CRM_Core_DAO_UFGroup();
76 $ufGroupDAO->name
= 'honoree_individual';
77 if ($ufGroupDAO->find(TRUE)) {
78 $defaults['honoree_profile'] = $ufGroupDAO->id
;
80 $defaults['soft_credit_types'] = array(
81 CRM_Utils_Array
::value('in_honor_of', $soft_credit_types),
82 CRM_Utils_Array
::value('in_memory_of', $soft_credit_types),
86 $ufGroupDAO = new CRM_Core_DAO_UFGroup();
87 $ufGroupDAO->name
= 'on_behalf_organization';
88 if ($ufGroupDAO->find(TRUE)) {
89 $defaults['onbehalf_profile_id'] = $ufGroupDAO->id
;
91 $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
92 $defaults['is_for_organization'] = 1;
98 $ufGroupDAO = new CRM_Core_DAO_UFGroup();
99 $ufGroupDAO->name
= 'honoree_individual';
100 if ($ufGroupDAO->find(TRUE)) {
101 $defaults['honoree_profile'] = $ufGroupDAO->id
;
103 $defaults['soft_credit_types'] = array(
104 CRM_Utils_Array
::value('in_honor_of', $soft_credit_types),
105 CRM_Utils_Array
::value('in_memory_of', $soft_credit_types),
113 * Build the form object.
115 public function buildQuickForm() {
117 $this->_first
= TRUE;
118 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_ContributionPage');
121 $this->addSelect('financial_type_id', array(), TRUE);
124 $this->add('text', 'title', ts('Title'), $attributes['title'], TRUE);
126 //CRM-7362 --add campaigns.
127 CRM_Campaign_BAO_Campaign
::addCampaign($this, CRM_Utils_Array
::value('campaign_id', $this->_values
));
129 $this->add('wysiwyg', 'intro_text', ts('Introductory Message'), $attributes['intro_text']);
131 $this->add('wysiwyg', 'footer_text', ts('Footer Message'), $attributes['footer_text']);
133 //Register schema which will be used for OnBehalOf and HonorOf profile Selector
134 CRM_UF_Page_ProfileEditor
::registerSchemas(array('OrganizationModel', 'HouseholdModel'));
136 // is on behalf of an organization ?
137 $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);"));
139 //CRM-15787 - If applicable, register 'membership_1'
140 $member = CRM_Member_BAO_Membership
::getMembershipBlock($this->_id
);
141 $coreTypes = array('Contact', 'Organization');
144 'entity_name' => array('contact_1'),
145 'entity_type' => 'OrganizationModel',
148 if ($member && $member['is_active']) {
149 $coreTypes[] = 'Membership';
151 'entity_name' => array('membership_1'),
152 'entity_type' => 'MembershipModel',
156 $allowCoreTypes = array_merge($coreTypes, CRM_Contact_BAO_ContactType
::subTypes('Organization'));
157 $allowSubTypes = array();
159 $this->addProfileSelector('onbehalf_profile_id', ts('Organization Profile'), $allowCoreTypes, $allowSubTypes, $entities);
162 $options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1);
163 $options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2);
164 $this->addGroup($options, 'is_for_organization', '');
165 $this->add('textarea', 'for_organization', ts('On behalf of Label'), array('rows' => 2, 'cols' => 50));
167 // collect goal amount
168 $this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12));
169 $this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money
::format('99.99', ' '))), 'money');
171 // is confirmation page enabled?
172 $this->addElement('checkbox', 'is_confirm_enabled', ts('Use a confirmation page?'));
174 // is this page shareable through social media ?
175 $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
177 // is this page active ?
178 $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?'));
180 // should the honor be enabled
181 $this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), NULL, array('onclick' => "showHonor()"));
183 $this->add('text', 'honor_block_title', ts('Honoree Section Title'), array('maxlength' => 255, 'size' => 45));
185 $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), array('rows' => 2, 'cols' => 50));
187 $this->addSelect('soft_credit_types', array(
188 'label' => ts('Honor Types'),
189 'entity' => 'ContributionSoft',
190 'field' => 'soft_credit_type_id',
197 'entity_name' => 'contact_1',
198 'entity_type' => 'IndividualModel',
202 $allowCoreTypes = array_merge(array(
207 ), CRM_Contact_BAO_ContactType
::subTypes('Individual'));
208 $allowSubTypes = array();
210 $this->addProfileSelector('honoree_profile', ts('Honoree Profile'), $allowCoreTypes, $allowSubTypes, $entities);
212 if (!empty($this->_submitValues
['honor_block_is_active'])) {
213 $this->addRule('soft_credit_types', ts('At least one value must be selected if Honor Section is active'), 'required');
214 $this->addRule('honoree_profile', ts('Please select a profile used for honoree'), 'required');
217 // add optional start and end dates
218 $this->addDateTime('start_date', ts('Start Date'));
219 $this->addDateTime('end_date', ts('End Date'));
221 $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'), $this);
223 parent
::buildQuickForm();
227 * Global validation rules for the form.
229 * @param array $values
230 * Posted values of the form.
236 * list of errors to be posted back to the form
238 public static function formRule($values, $files, $self) {
240 $contributionPageId = $self->_id
;
242 if (strstr($values['title'], '/')) {
243 $errors['title'] = ts("Please do not use '/' in Title");
246 // ensure on-behalf-of profile meets minimum requirements
247 if (!empty($values['is_organization'])) {
248 if (empty($values['onbehalf_profile_id'])) {
249 $errors['onbehalf_profile_id'] = ts('Please select a profile to collect organization information on this contribution page.');
252 $requiredProfileFields = array('organization_name', 'email');
253 if (!CRM_Core_BAO_UFGroup
::checkValidProfile($values['onbehalf_profile_id'], $requiredProfileFields)) {
254 $errors['onbehalf_profile_id'] = ts('Profile does not contain the minimum required fields for an On Behalf Of Organization');
260 $start = CRM_Utils_Date
::processDate($values['start_date']);
261 $end = CRM_Utils_Date
::processDate($values['end_date']);
262 if (($end < $start) && ($end != 0)) {
263 $errors['end_date'] = ts('End date should be after Start date.');
266 if (!empty($self->_values
['payment_processor']) && $financialType = CRM_Contribute_BAO_Contribution
::validateFinancialType($values['financial_type_id'])) {
267 $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
270 //dont allow on behalf of save when
271 //pre or post profile consists of membership fields
272 if ($contributionPageId && !empty($values['is_organization'])) {
273 $ufJoinParams = array(
274 'module' => 'CiviContribute',
275 'entity_table' => 'civicrm_contribution_page',
276 'entity_id' => $contributionPageId,
279 list($contributionProfiles['custom_pre_id'],
280 $contributionProfiles['custom_post_id']
281 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
283 $conProfileType = NULL;
284 if ($contributionProfiles['custom_pre_id']) {
285 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($contributionProfiles['custom_pre_id']);
286 if ($preProfileType == 'Membership') {
287 $conProfileType = "'Includes Profile (top of page)'";
291 if ($contributionProfiles['custom_post_id']) {
292 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($contributionProfiles['custom_post_id']);
293 if ($postProfileType == 'Membership') {
294 $conProfileType = empty($conProfileType) ?
"'Includes Profile (bottom of page)'" : "{$conProfileType} and 'Includes Profile (bottom of page)'";
297 if (!empty($conProfileType)) {
298 $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));
307 public function postProcess() {
308 // get the submitted form values.
309 $params = $this->controller
->exportValues($this->_name
);
311 // we do this in case the user has hit the forward/back button
313 $params['id'] = $this->_id
;
316 $session = CRM_Core_Session
::singleton();
317 $params['created_id'] = $session->get('userID');
318 $params['created_date'] = date('YmdHis');
319 $config = CRM_Core_Config
::singleton();
320 $params['currency'] = $config->defaultCurrency
;
323 $params['is_confirm_enabled'] = CRM_Utils_Array
::value('is_confirm_enabled', $params, FALSE);
324 $params['is_share'] = CRM_Utils_Array
::value('is_share', $params, FALSE);
325 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
326 $params['is_credit_card_only'] = CRM_Utils_Array
::value('is_credit_card_only', $params, FALSE);
327 $params['honor_block_is_active'] = CRM_Utils_Array
::value('honor_block_is_active', $params, FALSE);
328 $params['is_for_organization'] = !empty($params['is_organization']) ? CRM_Utils_Array
::value('is_for_organization', $params, FALSE) : 0;
330 $params['start_date'] = CRM_Utils_Date
::processDate($params['start_date'], $params['start_date_time'], TRUE);
331 $params['end_date'] = CRM_Utils_Date
::processDate($params['end_date'], $params['end_date_time'], TRUE);
333 $params['goal_amount'] = CRM_Utils_Rule
::cleanMoney($params['goal_amount']);
335 if (!$params['honor_block_is_active']) {
336 $params['honor_block_title'] = NULL;
337 $params['honor_block_text'] = NULL;
340 $dao = CRM_Contribute_BAO_ContributionPage
::create($params);
342 $ufJoinParams = array(
343 'is_organization' => array(
344 'module' => 'on_behalf',
345 'entity_table' => 'civicrm_contribution_page',
346 'entity_id' => $dao->id
,
348 'honor_block_is_active' => array(
349 'module' => 'soft_credit',
350 'entity_table' => 'civicrm_contribution_page',
351 'entity_id' => $dao->id
,
355 foreach ($ufJoinParams as $index => $ufJoinParam) {
356 if (!empty($params[$index])) {
357 // first delete all past entries
358 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParam);
359 $ufJoinParam['uf_group_id'] = $params[$index];
360 $ufJoinParam['weight'] = 1;
361 $ufJoinParam['is_active'] = 1;
362 if ($index == 'honor_block_is_active') {
363 $ufJoinParam['uf_group_id'] = $params['honoree_profile'];
364 $ufJoinParam['module_data'] = CRM_Contribute_BAO_ContributionPage
::formatModuleData($params, FALSE, 'soft_credit');
367 $ufJoinParam['uf_group_id'] = $params['onbehalf_profile_id'];
368 $ufJoinParam['module_data'] = CRM_Contribute_BAO_ContributionPage
::formatModuleData($params, FALSE, 'on_behalf');
370 CRM_Core_BAO_UFJoin
::create($ufJoinParam);
373 if ($index == 'honor_block_is_active') {
374 $params['honor_block_title'] = NULL;
375 $params['honor_block_text'] = NULL;
378 $params['for_organization'] = NULL;
381 //On subsequent honor_block_is_active uncheck, disable(don't delete)
382 //that particular honoree profile entry in UFjoin table, CRM-13981
383 $ufId = CRM_Core_BAO_UFJoin
::findJoinEntryId($ufJoinParam);
385 $ufJoinParam['uf_group_id'] = CRM_Core_BAO_UFJoin
::findUFGroupId($ufJoinParam);
386 $ufJoinParam['is_active'] = 0;
387 CRM_Core_BAO_UFJoin
::create($ufJoinParam);
392 $this->set('id', $dao->id
);
393 if ($this->_action
& CRM_Core_Action
::ADD
) {
394 $url = 'civicrm/admin/contribute/amount';
395 $urlParams = "action=update&reset=1&id={$dao->id}";
396 // special case for 'Save and Done' consistency.
397 if ($this->controller
->getButtonName('submit') == '_qf_Amount_upload_done') {
398 $url = 'civicrm/admin/contribute';
399 $urlParams = 'reset=1';
400 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
401 array(1 => $this->getTitle())
402 ), ts('Saved'), 'success');
405 CRM_Utils_System
::redirect(CRM_Utils_System
::url($url, $urlParams));
407 parent
::endPostProcess();
411 * Return a descriptive name for the page, used in wizard header
415 public function getTitle() {
416 return ts('Title and Settings');