3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
37 * form to process actions on the group aspect of Custom Data
39 class CRM_Contribute_Form_ContributionPage
extends CRM_Core_Form
{
42 * The page id saved to the session for an update.
49 * The pledgeBlock id saved to the session for an update.
53 protected $_pledgeBlockID;
56 * Are we in single form mode or wizard mode?
63 * Is this the first page?
67 protected $_first = FALSE;
70 * Is this the last page?
74 protected $_last = FALSE;
81 protected $_priceSetID = NULL;
86 * Set variables up before form is built.
90 public function preProcess() {
91 // current contribution page id
92 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive',
93 $this, FALSE, NULL, 'REQUEST'
95 $this->assign('contributionPageID', $this->_id
);
97 // get the requested action
98 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String',
99 // default to 'browse'
100 $this, FALSE, 'browse'
103 // setting title and 3rd level breadcrumb for html page if contrib page exists
105 $title = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id
, 'title');
107 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
108 $this->_single
= TRUE;
113 CRM_Contribute_Form_ContributionPage_TabHeader
::build($this);
115 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
116 CRM_Utils_System
::setTitle(ts('Configure Page - %1', array(1 => $title)));
118 elseif ($this->_action
== CRM_Core_Action
::VIEW
) {
119 CRM_Utils_System
::setTitle(ts('Preview Page - %1', array(1 => $title)));
121 elseif ($this->_action
== CRM_Core_Action
::DELETE
) {
122 CRM_Utils_System
::setTitle(ts('Delete Page - %1', array(1 => $title)));
126 $this->_values
= $this->get('values');
127 if (!is_array($this->_values
)) {
128 $this->_values
= array();
129 if (isset($this->_id
) && $this->_id
) {
130 $params = array('id' => $this->_id
);
131 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values
);
133 $this->set('values', $this->_values
);
136 // Preload libraries required by the "Profiles" tab
137 $schemas = array('IndividualModel', 'OrganizationModel', 'ContributionModel');
138 if (in_array('CiviMember', CRM_Core_Config
::singleton()->enableComponents
)) {
139 $schemas[] = 'MembershipModel';
141 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
142 CRM_UF_Page_ProfileEditor
::registerSchemas($schemas);
146 * Build the form object.
150 public function buildQuickForm() {
151 $this->applyFilter('__ALL__', 'trim');
153 $session = CRM_Core_Session
::singleton();
154 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
156 if (!$this->_cancelURL
) {
157 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1');
160 if ($this->_cancelURL
) {
161 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
164 if ($this->_single
) {
168 'name' => ts('Save'),
169 'spacing' => ' ',
174 'name' => ts('Save and Done'),
175 'spacing' => ' ',
182 'name' => ts('Save and Next'),
183 'spacing' => ' ',
184 'subName' => 'savenext',
189 'name' => ts('Cancel'),
191 $this->addButtons($buttons);
195 if (!$this->_first
) {
198 'name' => ts('Previous'),
199 'spacing' => ' ',
204 'name' => ts('Continue'),
205 'spacing' => ' ',
210 'name' => ts('Cancel'),
213 $this->addButtons($buttons);
216 $session->replaceUserContext($this->_cancelURL
);
217 // views are implemented as frozen form
218 if ($this->_action
& CRM_Core_Action
::VIEW
) {
220 $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'"));
223 // don't show option for contribution amounts section if membership price set
224 // this flag is sent to template
226 $membershipBlock = new CRM_Member_DAO_MembershipBlock();
227 $membershipBlock->entity_table
= 'civicrm_contribution_page';
228 $membershipBlock->entity_id
= $this->_id
;
229 $membershipBlock->is_active
= 1;
230 $hasMembershipBlk = FALSE;
231 if ($membershipBlock->find(TRUE) &&
232 ($setID = CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, NULL, 1))
234 $extends = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
235 if ($extends && $extends == CRM_Core_Component
::getComponentID('CiviMember')) {
236 $hasMembershipBlk = TRUE;
239 // set value in DOM that membership price set exists
240 CRM_Core_Resources
::singleton()->addSetting(array('memberPriceset' => $hasMembershipBlk));
244 * Set default values for the form. Note that in edit/view mode
245 * the default values are retrieved from the database
251 public function setDefaultValues() {
252 //some child classes calling setdefaults directly w/o preprocess.
253 $this->_values
= $this->get('values');
254 if (!is_array($this->_values
)) {
255 $this->_values
= array();
256 if (isset($this->_id
) && $this->_id
) {
257 $params = array('id' => $this->_id
);
258 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values
);
260 $this->set('values', $this->_values
);
262 $defaults = $this->_values
;
264 $config = CRM_Core_Config
::singleton();
265 if (isset($this->_id
)) {
267 //set defaults for pledgeBlock values.
268 $pledgeBlockParams = array(
269 'entity_id' => $this->_id
,
270 'entity_table' => ts('civicrm_contribution_page'),
272 $pledgeBlockDefaults = array();
273 CRM_Pledge_BAO_PledgeBlock
::retrieve($pledgeBlockParams, $pledgeBlockDefaults);
274 if ($this->_pledgeBlockID
= CRM_Utils_Array
::value('id', $pledgeBlockDefaults)) {
275 $defaults['is_pledge_active'] = TRUE;
277 $pledgeBlock = array(
278 'is_pledge_interval',
280 'initial_reminder_day',
281 'additional_reminder_day',
283 foreach ($pledgeBlock as $key) {
284 $defaults[$key] = CRM_Utils_Array
::value($key, $pledgeBlockDefaults);
286 if (!empty($pledgeBlockDefaults['pledge_frequency_unit'])) {
287 $defaults['pledge_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
288 $pledgeBlockDefaults['pledge_frequency_unit']
292 // fix the display of the monetary value, CRM-4038
293 if (isset($defaults['goal_amount'])) {
294 $defaults['goal_amount'] = CRM_Utils_Money
::format($defaults['goal_amount'], NULL, '%a');
297 // get price set of type contributions
298 //this is the value for stored in db if price set extends contribution
300 $this->_priceSetID
= CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, $usedFor, 1);
301 if ($this->_priceSetID
) {
302 $defaults['price_set_id'] = $this->_priceSetID
;
305 if (!empty($defaults['end_date'])) {
306 list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['end_date']);
309 if (!empty($defaults['start_date'])) {
310 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['start_date']);
314 $defaults['is_active'] = 1;
315 // set current date as start date
316 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults();
319 if (!isset($defaults['for_organization'])) {
320 $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
323 if (!empty($defaults['recur_frequency_unit'])) {
324 $defaults['recur_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
325 $defaults['recur_frequency_unit']
330 $defaults['recur_frequency_unit'] = array('month' => 1);
333 if (!empty($defaults['is_for_organization'])) {
334 $defaults['is_organization'] = 1;
337 $defaults['is_for_organization'] = 1;
340 // confirm page starts out enabled
341 if (!isset($defaults['is_confirm_enabled'])) {
342 $defaults['is_confirm_enabled'] = 1;
353 public function postProcess() {
354 $pageId = $this->get('id');
355 //page is newly created.
356 if ($pageId && !$this->_id
) {
357 $session = CRM_Core_Session
::singleton();
358 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1'));
362 public function endPostProcess() {
363 // make submit buttons keep the current working tab opened, or save and next tab
364 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
365 $className = CRM_Utils_String
::getClassName($this->_name
);
367 //retrieve list of pages from StateMachine and find next page
368 //this is quite painful because StateMachine is full of protected variables
369 //so we have to retrieve all pages, find current page, and then retrieve next
370 $stateMachine = new CRM_Contribute_StateMachine_ContributionPage($this);
371 $states = $stateMachine->getStates();
372 $statesList = array_keys($states);
373 $currKey = array_search($className, $statesList);
374 $nextPage = (array_key_exists($currKey +
1, $statesList)) ?
$statesList[$currKey +
1] : '';
376 //unfortunately, some classes don't map to subpage names, so we alter the exceptions
378 switch ($className) {
380 $attributes = $this->getVar('_attributes');
381 $subPage = strtolower(basename(CRM_Utils_Array
::value('action', $attributes)));
382 $subPageName = ucfirst($subPage);
383 if ($subPage == 'friend') {
384 $nextPage = 'custom';
387 $nextPage = 'settings';
391 case 'MembershipBlock':
392 $subPage = 'membership';
393 $subPageName = 'MembershipBlock';
394 $nextPage = 'thankyou';
398 $subPage = strtolower($className);
399 $subPageName = $className;
400 $nextPage = strtolower($nextPage);
402 if ($subPage == 'amount') {
403 $nextPage = 'membership';
405 elseif ($subPage == 'thankyou') {
406 $nextPage = 'friend';
411 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
412 array(1 => $subPageName)
413 ), ts('Saved'), 'success');
415 $this->postProcessHook();
417 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_next") {
418 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$subPage}",
419 "action=update&reset=1&id={$this->_id}"
422 elseif ($this->controller
->getButtonName('submit') == "_qf_{$className}_submit_savenext") {
424 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$nextPage}",
425 "action=update&reset=1&id={$this->_id}"
429 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute",
435 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute", 'reset=1'));
441 * Use the form name to create the tpl file name.
448 public function getTemplateFileName() {
449 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
450 ($this->_action
& CRM_Core_Action
::DELETE
) ||
451 (CRM_Utils_String
::getClassName($this->_name
) == 'AddProduct')
453 return parent
::getTemplateFileName();
456 // hack lets suppress the form rendering for now
457 self
::$_template->assign('isForm', FALSE);
458 return 'CRM/Contribute/Form/ContributionPage/Tab.tpl';