3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
37 * form to process actions on the group aspect of Custom Data
39 class CRM_Contribute_Form_ContributionPage_Custom
extends CRM_Contribute_Form_ContributionPage
{
42 * Function to actually build the form
47 public function buildQuickForm() {
48 $types = array_merge(array('Contact', 'Individual', 'Contribution', 'Membership'),
49 CRM_Contact_BAO_ContactType
::subTypes('Individual')
52 $profiles = CRM_Core_BAO_UFGroup
::getProfiles($types);
53 $excludeTypes = array('Organization', 'Household', 'Participant', 'Activity');
55 $excludeProfiles = CRM_Core_BAO_UFGroup
::getProfiles($excludeTypes);
56 foreach ($excludeProfiles as $key => $value) {
57 if (array_key_exists( $key, $profiles)) {
58 unset($profiles[$key]);
62 if (empty($profiles)) {
63 $this->assign('noProfile', TRUE);
66 $this->add('select', 'custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), array('' => ts('- select -')) +
$profiles);
67 $this->add('select', 'custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), array('' => ts('- select -')) +
$profiles);
69 $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Custom', 'formRule'), $this->_id
);
71 parent
::buildQuickForm();
75 * This function sets the default values for the form. Note that in edit/view mode
76 * the default values are retrieved from the database
82 function setDefaultValues() {
83 $defaults = parent
::setDefaultValues();
86 $title = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id
, 'title');
87 CRM_Utils_System
::setTitle(ts('Include Profiles (%1)', array(1 => $title)));
91 $ufJoinParams = array(
92 'module' => 'CiviContribute',
93 'entity_table' => 'civicrm_contribution_page',
94 'entity_id' => $this->_id
,
96 list($defaults['custom_pre_id'],
97 $defaults['custom_post_id']
98 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
109 public function postProcess() {
110 // get the submitted form values.
111 $params = $this->controller
->exportValues($this->_name
);
113 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
114 $params['id'] = $this->_id
;
117 $transaction = new CRM_Core_Transaction();
119 // also update uf join table
120 $ufJoinParams = array(
122 'module' => 'CiviContribute',
123 'entity_table' => 'civicrm_contribution_page',
124 'entity_id' => $this->_id
,
127 // first delete all past entries
128 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParams);
130 if (!empty($params['custom_pre_id'])) {
131 $ufJoinParams['weight'] = 1;
132 $ufJoinParams['uf_group_id'] = $params['custom_pre_id'];
133 CRM_Core_BAO_UFJoin
::create($ufJoinParams);
136 unset($ufJoinParams['id']);
138 if (!empty($params['custom_post_id'])) {
139 $ufJoinParams['weight'] = 2;
140 $ufJoinParams['uf_group_id'] = $params['custom_post_id'];
141 CRM_Core_BAO_UFJoin
::create($ufJoinParams);
144 $transaction->commit();
145 parent
::endPostProcess();
149 * Return a descriptive name for the page, used in wizard header
154 public function getTitle() {
155 return ts('Include Profiles');
161 * @param array $fields the input form values
163 * @return true if no errors, else array of errors
167 static function formRule($fields, $files, $contributionPageId) {
169 $preProfileType = $postProfileType = NULL;
170 // for membership profile make sure Membership section is enabled
171 // get membership section for this contribution page
172 $dao = new CRM_Member_DAO_MembershipBlock();
173 $dao->entity_table
= 'civicrm_contribution_page';
174 $dao->entity_id
= $contributionPageId;
176 $membershipEnable = FALSE;
178 if ($dao->find(TRUE) && $dao->is_active
) {
179 $membershipEnable = TRUE;
182 if ($fields['custom_pre_id']) {
183 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($fields['custom_pre_id']);
186 if ($fields['custom_post_id']) {
187 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($fields['custom_post_id']);
190 $errorMsg = ts('You must enable the Membership Block for this Contribution Page if you want to include a Profile with Membership fields.');
192 if (($preProfileType == 'Membership') && !$membershipEnable) {
193 $errors['custom_pre_id'] = $errorMsg;
196 if (($postProfileType == 'Membership') && !$membershipEnable) {
197 $errors['custom_post_id'] = $errorMsg;
200 $behalf = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'is_for_organization');
201 if ($fields['custom_pre_id']) {
202 $errorMsg = ts('You should move the membership related fields in the "On Behalf" profile for this Contribution Page');
203 if ($preProfileType == 'Membership' && $behalf) {
204 $errors['custom_pre_id'] = isset($errors['custom_pre_id']) ?
$errors['custom_pre_id'] . $errorMsg : $errorMsg;
208 if ($fields['custom_post_id']) {
209 $errorMsg = ts('You should move the membership related fields in the "On Behalf" profile for this Contribution Page');
210 if ($postProfileType == 'Membership' && $behalf) {
211 $errors['custom_post_id'] = isset($errors['custom_post_id']) ?
$errors['custom_post_id'] . $errorMsg : $errorMsg;
214 return empty($errors) ?
TRUE : $errors;