3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 * 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();
57 $soft_credit_types = CRM_Core_OptionGroup
::values('soft_credit_type', TRUE, FALSE, FALSE, NULL, 'name');
60 $title = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage',
64 CRM_Utils_System
::setTitle(ts('Title and Settings (%1)',
68 $ufJoinParams = array(
69 'module' => 'OnBehalf',
70 'entity_table' => 'civicrm_contribution_page',
71 'entity_id' => $this->_id
,
73 $onBehalfIDs = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
75 // get the first one only
76 $defaults['onbehalf_profile_id'] = $onBehalfIDs[0];
79 $ufJoinDAO = new CRM_Core_DAO_UFJoin();
80 $ufJoinDAO->module
= 'soft_credit';
81 $ufJoinDAO->entity_id
= $this->_id
;
82 if ($ufJoinDAO->find(TRUE)) {
83 $defaults['honoree_profile'] = $ufJoinDAO->uf_group_id
;
84 $jsonData = CRM_Contribute_BAO_ContributionPage
::formatMultilingualHonorParams($ufJoinDAO->module_data
, TRUE);
85 $defaults = array_merge($defaults, $jsonData);
86 $defaults['honor_block_is_active'] = $ufJoinDAO->is_active
;
89 $ufGroupDAO = new CRM_Core_DAO_UFGroup();
90 $ufGroupDAO->name
= 'honoree_individual';
91 if ($ufGroupDAO->find(TRUE)) {
92 $defaults['honoree_profile'] = $ufGroupDAO->id
;
94 $defaults['soft_credit_types'] = array(
95 CRM_Utils_Array
::value('in_honor_of', $soft_credit_types),
96 CRM_Utils_Array
::value('in_memory_of', $soft_credit_types)
101 CRM_Utils_System
::setTitle(ts('Title and Settings'));
103 $ufGroupDAO = new CRM_Core_DAO_UFGroup();
104 $ufGroupDAO->name
= 'honoree_individual';
105 if ($ufGroupDAO->find(TRUE)) {
106 $defaults['honoree_profile'] = $ufGroupDAO->id
;
108 $defaults['soft_credit_types'] = array(
109 CRM_Utils_Array
::value('in_honor_of', $soft_credit_types),
110 CRM_Utils_Array
::value('in_memory_of', $soft_credit_types)
118 * Function to actually build the form
123 public function buildQuickForm() {
125 $this->_first
= TRUE;
126 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_ContributionPage');
129 $this->addSelect('financial_type_id', array(), TRUE);
132 $this->add('text', 'title', ts('Title'), $attributes['title'], TRUE);
134 //CRM-7362 --add campaigns.
135 CRM_Campaign_BAO_Campaign
::addCampaign($this, CRM_Utils_Array
::value('campaign_id', $this->_values
));
137 $this->addWysiwyg('intro_text', ts('Introductory Message'), $attributes['intro_text']);
139 $this->addWysiwyg('footer_text', ts('Footer Message'), $attributes['footer_text']);
141 // is on behalf of an organization ?
142 $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);"));
144 $required = array('Contact', 'Organization');
145 $optional = array('Contribution', 'Membership');
147 $profiles = CRM_Core_BAO_UFGroup
::getValidProfiles($required, $optional);
148 //Check profiles for Organization subtypes
149 $contactSubType = CRM_Contact_BAO_ContactType
::subTypes('Organization');
150 foreach ($contactSubType as $type) {
151 $required = array('Contact', $type);
152 $subTypeProfiles = CRM_Core_BAO_UFGroup
::getValidProfiles($required, $optional);
153 foreach ($subTypeProfiles as $profileId => $profileName) {
154 $profiles[$profileId] = $profileName;
158 $requiredProfileFields = array('organization_name', 'email');
160 if (!empty($profiles)) {
161 foreach ($profiles as $id => $dontCare) {
162 $validProfile = CRM_Core_BAO_UFGroup
::checkValidProfile($id, $requiredProfileFields);
163 if (!$validProfile) {
164 unset($profiles[$id]);
169 if (empty($profiles)) {
170 $invalidProfiles = TRUE;
171 $this->assign('invalidProfiles', $invalidProfiles);
174 $this->add('select', 'onbehalf_profile_id', ts('Organization Profile'),
176 '' => ts('- select -')) +
$profiles
180 $options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1);
181 $options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2);
182 $this->addGroup($options, 'is_for_organization', ts(''));
183 $this->add('textarea', 'for_organization', ts('On behalf of Label'), $attributes['for_organization']);
185 // collect goal amount
186 $this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12));
187 $this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money
::format('99.99', ' '))), 'money');
189 // is confirmation page enabled?
190 $this->addElement('checkbox', 'is_confirm_enabled', ts('Use a confirmation page?'));
192 // is this page shareable through social media ?
193 $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
195 // is this page active ?
196 $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?'));
198 // should the honor be enabled
199 $this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), NULL, array('onclick' => "showHonor()"));
201 $this->add('text', 'honor_block_title', ts('Honoree Section Title'), array('maxlength' => 255, 'size' => 45));
203 $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), array('rows' => 2, 'cols' => 50));
205 $this->addSelect('soft_credit_types', array(
206 'label' => ts('Honor Types'),
207 'entity' => 'ContributionSoft',
208 'field' => 'soft_credit_type_id',
215 'entity_name' => 'contact_1',
216 'entity_type' => 'IndividualModel',
220 $allowCoreTypes = array_merge(array('Contact', 'Individual', 'Organization', 'Household'), CRM_Contact_BAO_ContactType
::subTypes('Individual'));
221 $allowSubTypes = array();
223 $this->addProfileSelector('honoree_profile', ts('Honoree Profile'), $allowCoreTypes, $allowSubTypes, $entities);
224 CRM_UF_Page_ProfileEditor
::registerSchemas(array('OrganizationModel','HouseholdModel'));
226 if (!empty($this->_submitValues
['honor_block_is_active'])) {
227 $this->addRule('soft_credit_types', ts('At least one value must be selected if Honor Section is active'), 'required');
228 $this->addRule('honoree_profile', ts('Please select a profile used for honoree'), 'required');
231 // add optional start and end dates
232 $this->addDateTime('start_date', ts('Start Date'));
233 $this->addDateTime('end_date', ts('End Date'));
235 $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'), $this);
237 parent
::buildQuickForm();
241 * global validation rules for the form
243 * @param array $values posted values of the form
245 * @return array list of errors to be posted back to the form
249 static function formRule($values, $files, $self) {
251 $contributionPageId = $self->_id
;
253 if (strstr($values['title'], '/')) {
254 $errors['title'] = ts("Please do not use '/' in Title");
257 if (!empty($values['is_organization']) && empty($values['onbehalf_profile_id'])) {
258 $errors['onbehalf_profile_id'] = ts('Please select a profile to collect organization information on this contribution page.');
262 $start = CRM_Utils_Date
::processDate($values['start_date']);
263 $end = CRM_Utils_Date
::processDate($values['end_date']);
264 if (($end < $start) && ($end != 0)) {
265 $errors['end_date'] = ts('End date should be after Start date.');
268 if (!empty($self->_values
['payment_processor']) && $financialType = CRM_Contribute_BAO_Contribution
::validateFinancialType($values['financial_type_id'])) {
269 $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
272 //dont allow on behalf of save when
273 //pre or post profile consists of membership fields
274 if ($contributionPageId && !empty($values['is_organization'])) {
275 $ufJoinParams = array(
276 'module' => 'CiviContribute',
277 'entity_table' => 'civicrm_contribution_page',
278 'entity_id' => $contributionPageId,
281 list($contributionProfiles['custom_pre_id'],
282 $contributionProfiles['custom_post_id']
283 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
285 $conProfileType = NULL;
286 if ($contributionProfiles['custom_pre_id']) {
287 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($contributionProfiles['custom_pre_id']);
288 if ($preProfileType == 'Membership') {
289 $conProfileType = "'Includes Profile (top of page)'";
293 if ($contributionProfiles['custom_post_id']) {
294 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($contributionProfiles['custom_post_id']);
295 if ($postProfileType == 'Membership') {
296 $conProfileType = empty($conProfileType) ?
"'Includes Profile (bottom of page)'" : "{$conProfileType} and 'Includes Profile (bottom of page)'";
299 if (!empty($conProfileType)) {
300 $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));
312 public function postProcess() {
313 // get the submitted form values.
314 $params = $this->controller
->exportValues($this->_name
);
316 // we do this in case the user has hit the forward/back button
318 $params['id'] = $this->_id
;
321 $session = CRM_Core_Session
::singleton();
322 $params['created_id'] = $session->get('userID');
323 $params['created_date'] = date('YmdHis');
324 $config = CRM_Core_Config
::singleton();
325 $params['currency'] = $config->defaultCurrency
;
328 $params['is_confirm_enabled'] = CRM_Utils_Array
::value('is_confirm_enabled', $params, FALSE);
329 $params['is_share'] = CRM_Utils_Array
::value('is_share', $params, FALSE);
330 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
331 $params['is_credit_card_only'] = CRM_Utils_Array
::value('is_credit_card_only', $params, FALSE);
332 $params['honor_block_is_active'] = CRM_Utils_Array
::value('honor_block_is_active', $params, FALSE);
333 $params['is_for_organization'] = !empty($params['is_organization']) ? CRM_Utils_Array
::value('is_for_organization', $params, FALSE) : 0;
335 $params['start_date'] = CRM_Utils_Date
::processDate($params['start_date'], $params['start_date_time'], TRUE);
336 $params['end_date'] = CRM_Utils_Date
::processDate($params['end_date'], $params['end_date_time'], TRUE);
338 $params['goal_amount'] = CRM_Utils_Rule
::cleanMoney($params['goal_amount']);
340 if (!$params['honor_block_is_active']) {
341 $params['honor_block_title'] = NULL;
342 $params['honor_block_text'] = NULL;
345 $sctJSON = CRM_Contribute_BAO_ContributionPage
::formatMultilingualHonorParams($params);
348 $dao = CRM_Contribute_BAO_ContributionPage
::create($params);
350 $ufJoinParams = array(
351 'onbehalf_profile_id' =>
354 'module' => 'OnBehalf',
355 'entity_table' => 'civicrm_contribution_page',
356 'entity_id' => $dao->id
,
358 'honor_block_is_active' =>
360 'module' => 'soft_credit',
361 'entity_table' => 'civicrm_contribution_page',
362 'entity_id' => $dao->id
,
367 foreach ($ufJoinParams as $index => $ufJoinParam) {
368 if (!empty($params[$index])) {
369 $ufJoinParam['weight'] = 1;
370 if ($index == 'honor_block_is_active') {
371 $ufJoinParam['is_active'] = 1;
372 $ufJoinParam['module'] = 'soft_credit';
373 $ufJoinParam['uf_group_id'] = $params['honoree_profile'];
374 $ufJoinParam['module_data'] = $sctJSON;
377 // first delete all past entries
378 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParam);
379 $ufJoinParam['uf_group_id'] = $params[$index];
381 CRM_Core_BAO_UFJoin
::create($ufJoinParam);
383 elseif ($index == 'honor_block_is_active') {
384 //On subsequent honor_block_is_active uncheck, disable(don't delete)
385 //that particular honoree profile entry in UFjoin table, CRM-13981
386 $ufId = CRM_Core_BAO_UFJoin
::findJoinEntryId($ufJoinParam);
388 $ufJoinParam['uf_group_id'] = CRM_Core_BAO_UFJoin
::findUFGroupId($ufJoinParam);
389 $ufJoinParam['is_active'] = 0;
390 CRM_Core_BAO_UFJoin
::create($ufJoinParam);
395 $this->set('id', $dao->id
);
396 if ($this->_action
& CRM_Core_Action
::ADD
) {
397 $url = 'civicrm/admin/contribute/amount';
398 $urlParams = "action=update&reset=1&id={$dao->id}";
399 // special case for 'Save and Done' consistency.
400 if ($this->controller
->getButtonName('submit') == '_qf_Amount_upload_done') {
401 $url = 'civicrm/admin/contribute';
402 $urlParams = 'reset=1';
403 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
404 array(1 => $this->getTitle())
405 ), ts('Saved'), 'success');
408 CRM_Utils_System
::redirect(CRM_Utils_System
::url($url, $urlParams));
410 parent
::endPostProcess();
414 * Return a descriptive name for the page, used in wizard header
419 public function getTitle() {
420 return ts('Title and Settings');