3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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
35 class CRM_Contribute_Form_ContributionPage_Settings
extends CRM_Contribute_Form_ContributionPage
{
38 * Function to set variables up before form is built
43 public function preProcess() {
48 * This function sets the default values for the form. Note that in edit/view mode
49 * the default values are retrieved from the database
55 function setDefaultValues() {
56 $defaults = parent
::setDefaultValues();
59 $title = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage',
63 CRM_Utils_System
::setTitle(ts('Title and Settings (%1)',
67 $ufJoinParams = array(
68 'module' => 'OnBehalf',
69 'entity_table' => 'civicrm_contribution_page',
70 'entity_id' => $this->_id
,
72 $onBehalfIDs = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
74 // get the first one only
75 $defaults['onbehalf_profile_id'] = $onBehalfIDs[0];
78 $ufJoinDAO = new CRM_Core_DAO_UFJoin();
79 $ufJoinDAO->module
= 'soft_credit';
80 $ufJoinDAO->entity_id
= $this->_id
;
81 if ($ufJoinDAO->find(TRUE)) {
82 $defaults['honoree_profile'] = $ufJoinDAO->uf_group_id
;
83 $jsonData = json_decode($ufJoinDAO->module_data
);
85 foreach ($jsonData->soft_credit
as $index => $value){
86 $defaults[$index] = $value;
92 CRM_Utils_System
::setTitle(ts('Title and Settings'));
95 if (empty($defaults['soft_credit_types'])) {
96 $defaults['soft_credit_types'] = array(1, 2);
103 * Function to actually build the form
108 public function buildQuickForm() {
110 $this->_first
= TRUE;
111 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_ContributionPage');
114 $financialType = CRM_Financial_BAO_FinancialType
::getIncomeFinancialType();
115 $this->add('select', 'financial_type_id',
116 ts('Financial Type'),
122 $this->add('text', 'title', ts('Title'), $attributes['title'], TRUE);
124 //CRM-7362 --add campaigns.
125 CRM_Campaign_BAO_Campaign
::addCampaign($this, CRM_Utils_Array
::value('campaign_id', $this->_values
));
127 $this->addWysiwyg('intro_text', ts('Introductory Message'), $attributes['intro_text']);
129 $this->addWysiwyg('footer_text', ts('Footer Message'), $attributes['footer_text']);
131 // is on behalf of an organization ?
132 $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);"));
134 $required = array('Contact', 'Organization');
135 $optional = array('Contribution', 'Membership');
137 $profiles = CRM_Core_BAO_UFGroup
::getValidProfiles($required, $optional);
138 //Check profiles for Organization subtypes
139 $contactSubType = CRM_Contact_BAO_ContactType
::subTypes('Organization');
140 foreach ($contactSubType as $type) {
141 $required = array('Contact', $type);
142 $subTypeProfiles = CRM_Core_BAO_UFGroup
::getValidProfiles($required, $optional);
143 foreach ($subTypeProfiles as $profileId => $profileName) {
144 $profiles[$profileId] = $profileName;
148 $requiredProfileFields = array('organization_name', 'email');
150 if (!empty($profiles)) {
151 foreach ($profiles as $id => $dontCare) {
152 $validProfile = CRM_Core_BAO_UFGroup
::checkValidProfile($id, $requiredProfileFields);
153 if (!$validProfile) {
154 unset($profiles[$id]);
159 if (empty($profiles)) {
160 $invalidProfiles = TRUE;
161 $this->assign('invalidProfiles', $invalidProfiles);
164 $this->add('select', 'onbehalf_profile_id', ts('Organization Profile'),
166 '' => ts('- select -')) +
$profiles
170 $options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1);
171 $options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2);
172 $this->addGroup($options, 'is_for_organization', ts(''));
173 $this->add('textarea', 'for_organization', ts('On behalf of Label'), $attributes['for_organization']);
175 // collect goal amount
176 $this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12));
177 $this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money
::format('99.99', ' '))), 'money');
179 // is confirmation page enabled?
180 $this->addElement('checkbox', 'is_confirm_enabled', ts('Use a confirmation page?'));
182 // is this page shareable through social media ?
183 $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
185 // is this page active ?
186 $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?'));
188 // should the honor be enabled
189 $this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), NULL, array('onclick' => "showHonor()"));
191 $this->add('text', 'honor_block_title', ts('Honoree Section Title'), array('maxlength' => 255, 'size' => 45));
193 $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), array('rows' => 2, 'cols' => 50));
195 $softCreditTypes = &$this->add('select', 'soft_credit_types',
197 CRM_Core_OptionGroup
::values("soft_credit_type", FALSE),
200 'id' => 'soft_credit_types',
201 'multiple' => 'multiple',
202 'title' => '- ' . ts('select') . ' -',
207 array('entity_name' => 'contact_1',
208 'entity_type' => 'IndividualModel'
210 array('entity_name' => 'organization_1',
211 'entity_type' => 'OrganizationModel'
213 array('entity_name' => 'household_1',
214 'entity_type' => 'HouseholdModel'
217 $allowCoreTypes = array_merge(array('Contact', 'Individual', 'Organization', 'Household'), CRM_Contact_BAO_ContactType
::subTypes('Individual'));
218 $allowSubTypes = array();
220 $this->addProfileSelector('honoree_profile', ts('Honoree Profile'), $allowCoreTypes, $allowSubTypes, $entities);
222 if (!empty($this->_submitValues
['honor_block_is_active'])) {
223 $this->addRule('soft_credit_types', ts('At least one value must be selected if Honor Section is active'), 'required');
224 $this->addRule('honoree_profile', ts('Please select a profile used for honoree'), 'required');
227 // add optional start and end dates
228 $this->addDateTime('start_date', ts('Start Date'));
229 $this->addDateTime('end_date', ts('End Date'));
231 $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'), $this);
233 parent
::buildQuickForm();
237 * global validation rules for the form
239 * @param array $values posted values of the form
241 * @return array list of errors to be posted back to the form
245 static function formRule($values, $files, $self) {
247 $contributionPageId = $self->_id
;
249 if (strstr($values['title'], '/')) {
250 $errors['title'] = ts("Please do not use '/' in Title");
253 if (!empty($values['is_organization']) && empty($values['onbehalf_profile_id'])) {
254 $errors['onbehalf_profile_id'] = ts('Please select a profile to collect organization information on this contribution page.');
258 $start = CRM_Utils_Date
::processDate($values['start_date']);
259 $end = CRM_Utils_Date
::processDate($values['end_date']);
260 if (($end < $start) && ($end != 0)) {
261 $errors['end_date'] = ts('End date should be after Start date.');
264 if (!empty($self->_values
['payment_processor']) && $financialType = CRM_Contribute_BAO_Contribution
::validateFinancialType($values['financial_type_id'])) {
265 $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
268 //dont allow on behalf of save when
269 //pre or post profile consists of membership fields
270 if ($contributionPageId && !empty($values['is_organization'])) {
271 $ufJoinParams = array(
272 'module' => 'CiviContribute',
273 'entity_table' => 'civicrm_contribution_page',
274 'entity_id' => $contributionPageId,
277 list($contributionProfiles['custom_pre_id'],
278 $contributionProfiles['custom_post_id']
279 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
281 $conProfileType = NULL;
282 if ($contributionProfiles['custom_pre_id']) {
283 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($contributionProfiles['custom_pre_id']);
284 if ($preProfileType == 'Membership') {
285 $conProfileType = "'Includes Profile (top of page)'";
289 if ($contributionProfiles['custom_post_id']) {
290 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($contributionProfiles['custom_post_id']);
291 if ($postProfileType == 'Membership') {
292 $conProfileType = empty($conProfileType) ?
"'Includes Profile (bottom of page)'" : "{$conProfileType} and 'Includes Profile (bottom of page)'";
295 if (!empty($conProfileType)) {
296 $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));
308 public function postProcess() {
309 // get the submitted form values.
310 $params = $this->controller
->exportValues($this->_name
);
312 // we do this in case the user has hit the forward/back button
314 $params['id'] = $this->_id
;
317 $session = CRM_Core_Session
::singleton();
318 $params['created_id'] = $session->get('userID');
319 $params['created_date'] = date('YmdHis');
320 $config = CRM_Core_Config
::singleton();
321 $params['currency'] = $config->defaultCurrency
;
324 $params['is_confirm_enabled'] = CRM_Utils_Array
::value('is_confirm_enabled', $params, FALSE);
325 $params['is_share'] = CRM_Utils_Array
::value('is_share', $params, FALSE);
326 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
327 $params['is_credit_card_only'] = CRM_Utils_Array
::value('is_credit_card_only', $params, FALSE);
328 $params['honor_block_is_active'] = CRM_Utils_Array
::value('honor_block_is_active', $params, FALSE);
329 $params['is_for_organization'] = !empty($params['is_organization']) ? CRM_Utils_Array
::value('is_for_organization', $params, FALSE) : 0;
331 $params['start_date'] = CRM_Utils_Date
::processDate($params['start_date'], $params['start_date_time'], TRUE);
332 $params['end_date'] = CRM_Utils_Date
::processDate($params['end_date'], $params['end_date_time'], TRUE);
334 $params['goal_amount'] = CRM_Utils_Rule
::cleanMoney($params['goal_amount']);
336 if (!$params['honor_block_is_active']) {
337 $params['honor_block_title'] = NULL;
338 $params['honor_block_text'] = NULL;
341 $sctJSON = json_encode(array(
342 'soft_credit' => array(
343 'soft_credit_types' => $params['soft_credit_types'],
344 'honor_block_title' => $params['honor_block_title'],
345 'honor_block_text' => $params['honor_block_text']
351 $dao = CRM_Contribute_BAO_ContributionPage
::create($params);
353 $ufJoinParams = array(
354 'onbehalf_profile_id' =>
357 'module' => 'OnBehalf',
358 'entity_table' => 'civicrm_contribution_page',
359 'entity_id' => $dao->id
,
361 'honor_block_is_active' =>
363 'module' => 'soft_credit',
364 'entity_table' => 'civicrm_contribution_page',
365 'entity_id' => $dao->id
,
370 foreach ($ufJoinParams as $index => $ufJoinParam) {
371 if (!empty($params[$index])) {
372 $ufJoinParam['weight'] = 1;
373 if ($index == 'honor_block_is_active') {
374 $ufJoinParam['is_active'] = 1;
375 $ufJoinParam['uf_group_id'] = $params['honoree_profile'];
376 $ufJoinParam['module_data'] = $sctJSON;
379 // first delete all past entries
380 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParam);
381 $ufJoinParam['uf_group_id'] = $params[$index];
383 CRM_Core_BAO_UFJoin
::create($ufJoinParam);
385 elseif ($index == 'honor_block_is_active') {
386 //On subsequent honor_block_is_active uncheck, disable(don't delete)
387 //that particular honoree profile entry in UFjoin table, CRM-13981
388 $ufId = CRM_Core_BAO_UFJoin
::findJoinEntryId($ufJoinParam);
390 $ufJoinParam['uf_group_id'] = CRM_Core_BAO_UFJoin
::findUFGroupId($ufJoinParam);
391 $ufJoinParam['is_active'] = 0;
392 CRM_Core_BAO_UFJoin
::create($ufJoinParam);
397 $this->set('id', $dao->id
);
398 if ($this->_action
& CRM_Core_Action
::ADD
) {
399 $url = 'civicrm/admin/contribute/amount';
400 $urlParams = "action=update&reset=1&id={$dao->id}";
401 // special case for 'Save and Done' consistency.
402 if ($this->controller
->getButtonName('submit') == '_qf_Amount_upload_done') {
403 $url = 'civicrm/admin/contribute';
404 $urlParams = 'reset=1';
405 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
406 array(1 => $this->getTitle())
407 ), ts('Saved'), 'success');
410 CRM_Utils_System
::redirect(CRM_Utils_System
::url($url, $urlParams));
412 parent
::endPostProcess();
416 * Return a descriptive name for the page, used in wizard header
421 public function getTitle() {
422 return ts('Title and Settings');