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
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
50 * the pledgeBlock id saved to the session for an update
55 protected $_pledgeBlockID;
58 * are we in single form mode or wizard mode?
66 * is this the first page?
71 protected $_first = FALSE;
79 protected $_priceSetID = NULL;
84 * Function to set variables up before form is built
89 public function preProcess() {
90 // current contribution page id
91 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive',
92 $this, FALSE, NULL, 'REQUEST'
94 $this->assign('contributionPageID', $this->_id
);
96 // get the requested action
97 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String',
98 // default to 'browse'
99 $this, FALSE, 'browse'
102 // setting title and 3rd level breadcrumb for html page if contrib page exists
104 $title = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id
, 'title');
106 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
107 $this->_single
= TRUE;
112 CRM_Contribute_Form_ContributionPage_TabHeader
::build($this);
114 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
115 CRM_Utils_System
::setTitle(ts('Configure Page - %1', array(1 => $title)));
117 elseif ($this->_action
== CRM_Core_Action
::VIEW
) {
118 CRM_Utils_System
::setTitle(ts('Preview Page - %1', array(1 => $title)));
120 elseif ($this->_action
== CRM_Core_Action
::DELETE
) {
121 CRM_Utils_System
::setTitle(ts('Delete Page - %1', array(1 => $title)));
125 $this->_values
= $this->get('values');
126 if (!is_array($this->_values
)) {
127 $this->_values
= array();
128 if (isset($this->_id
) && $this->_id
) {
129 $params = array('id' => $this->_id
);
130 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values
);
132 $this->set('values', $this->_values
);
135 // Preload libraries required by the "Profiles" tab
136 $schemas = array('IndividualModel', 'OrganizationModel', 'ContributionModel');
137 if (in_array('CiviMember', CRM_Core_Config
::singleton()->enableComponents
)) {
138 $schemas[] = 'MembershipModel';
140 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
141 CRM_UF_Page_ProfileEditor
::registerSchemas($schemas);
145 * Function to actually build the form
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
);
165 if ($this->_single
) {
166 $this->addButtons(array(
169 'name' => ts('Save'),
170 'spacing' => ' ',
175 'name' => ts('Save and Done'),
176 'spacing' => ' ',
181 'name' => ts('Save and Next'),
182 'spacing' => ' ',
183 'subName' => 'savenext',
187 'name' => ts('Cancel'),
194 if (!$this->_first
) {
197 'name' => ts('<< Previous'),
198 'spacing' => ' ',
203 'name' => ts('Continue >>'),
204 'spacing' => ' ',
209 'name' => ts('Cancel'),
212 $this->addButtons($buttons);
215 $session->replaceUserContext($this->_cancelURL
);
216 // views are implemented as frozen form
217 if ($this->_action
& CRM_Core_Action
::VIEW
) {
219 $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'"));
222 // don't show option for contribution amounts section if membership price set
223 // this flag is sent to template
225 $membershipBlock = new CRM_Member_DAO_MembershipBlock();
226 $membershipBlock->entity_table
= 'civicrm_contribution_page';
227 $membershipBlock->entity_id
= $this->_id
;
228 $membershipBlock->is_active
= 1;
229 $hasMembershipBlk = FALSE;
230 if ($membershipBlock->find(TRUE) &&
231 ($setID = CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, NULL, 1))
233 $extends = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
234 if ($extends && $extends == CRM_Core_Component
::getComponentID('CiviMember')) {
235 $hasMembershipBlk = TRUE;
238 // set value in DOM that membership price set exists
239 CRM_Core_Resources
::singleton()->addSetting(array('memberPriceset' => $hasMembershipBlk));
243 * This function sets the default values for the form. Note that in edit/view mode
244 * the default values are retrieved from the database
250 function setDefaultValues() {
251 //some child classes calling setdefaults directly w/o preprocess.
252 $this->_values
= $this->get('values');
253 if (!is_array($this->_values
)) {
254 $this->_values
= array();
255 if (isset($this->_id
) && $this->_id
) {
256 $params = array('id' => $this->_id
);
257 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values
);
259 $this->set('values', $this->_values
);
261 $defaults = $this->_values
;
263 $config = CRM_Core_Config
::singleton();
264 if (isset($this->_id
)) {
266 //set defaults for pledgeBlock values.
267 $pledgeBlockParams = array(
268 'entity_id' => $this->_id
,
269 'entity_table' => ts('civicrm_contribution_page'),
271 $pledgeBlockDefaults = array();
272 CRM_Pledge_BAO_PledgeBlock
::retrieve($pledgeBlockParams, $pledgeBlockDefaults);
273 if ($this->_pledgeBlockID
= CRM_Utils_Array
::value('id', $pledgeBlockDefaults)) {
274 $defaults['is_pledge_active'] = TRUE;
276 $pledgeBlock = array(
277 'is_pledge_interval', 'max_reminders',
278 'initial_reminder_day', 'additional_reminder_day',
280 foreach ($pledgeBlock as $key) {
281 $defaults[$key] = CRM_Utils_Array
::value($key, $pledgeBlockDefaults);
283 if (!empty($pledgeBlockDefaults['pledge_frequency_unit'])) {
284 $defaults['pledge_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
285 $pledgeBlockDefaults['pledge_frequency_unit']
289 // fix the display of the monetary value, CRM-4038
290 if (isset($defaults['goal_amount'])) {
291 $defaults['goal_amount'] = CRM_Utils_Money
::format($defaults['goal_amount'], NULL, '%a');
294 // get price set of type contributions
295 //this is the value for stored in db if price set extends contribution
297 $this->_priceSetID
= CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, $usedFor, 1);
298 if ($this->_priceSetID
) {
299 $defaults['price_set_id'] = $this->_priceSetID
;
302 if (!empty($defaults['end_date'])) {
303 list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['end_date']);
306 if (!empty($defaults['start_date'])) {
307 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['start_date']);
311 $defaults['is_active'] = 1;
312 // set current date as start date
313 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults();
316 if (!isset($defaults['for_organization'])) {
317 $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
320 if (!empty($defaults['recur_frequency_unit'])) {
321 $defaults['recur_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
322 $defaults['recur_frequency_unit']
327 $defaults['recur_frequency_unit'] = array('month' => 1);
330 if (!empty($defaults['is_for_organization'])) {
331 $defaults['is_organization'] = 1;
334 $defaults['is_for_organization'] = 1;
337 // confirm page starts out enabled
338 if (!isset($defaults['is_confirm_enabled'])) {
339 $defaults['is_confirm_enabled'] = 1;
351 public function postProcess() {
352 $pageId = $this->get('id');
353 //page is newly created.
354 if ($pageId && !$this->_id
) {
355 $session = CRM_Core_Session
::singleton();
356 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1'));
360 function endPostProcess() {
361 // make submit buttons keep the current working tab opened, or save and next tab
362 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
363 $className = CRM_Utils_String
::getClassName($this->_name
);
365 //retrieve list of pages from StateMachine and find next page
366 //this is quite painful because StateMachine is full of protected variables
367 //so we have to retrieve all pages, find current page, and then retrieve next
368 $stateMachine = new CRM_Contribute_StateMachine_ContributionPage($this);
369 $states = $stateMachine->getStates();
370 $statesList = array_keys($states);
371 $currKey = array_search($className, $statesList);
372 $nextPage = (array_key_exists($currKey +
1, $statesList)) ?
$statesList[$currKey +
1] : '';
374 //unfortunately, some classes don't map to subpage names, so we alter the exceptions
376 switch ($className) {
378 $attributes = $this->getVar('_attributes');
379 $subPage = strtolower(basename(CRM_Utils_Array
::value('action', $attributes)));
380 $subPageName = ucFirst($subPage);
381 if ($subPage == 'friend') {
382 $nextPage = 'custom';
385 $nextPage = 'settings';
389 case 'MembershipBlock':
390 $subPage = 'membership';
391 $subPageName = 'MembershipBlock';
392 $nextPage = 'thankyou';
396 $subPage = strtolower($className);
397 $subPageName = $className;
398 $nextPage = strtolower($nextPage);
400 if ($subPage == 'amount') {
401 $nextPage = 'membership';
403 elseif ($subPage == 'thankyou') {
404 $nextPage = 'friend';
409 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
410 array(1 => $subPageName)
411 ), ts('Saved'), 'success');
413 $this->postProcessHook();
415 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_next") {
416 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$subPage}",
417 "action=update&reset=1&id={$this->_id}"
420 elseif ($this->controller
->getButtonName('submit') == "_qf_{$className}_submit_savenext") {
422 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$nextPage}",
423 "action=update&reset=1&id={$this->_id}"
427 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute",
433 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute", 'reset=1'));
438 function getTemplateFileName() {
439 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
440 ($this->_action
& CRM_Core_Action
::DELETE
) ||
441 (CRM_Utils_String
::getClassName($this->_name
) == 'AddProduct')
443 return parent
::getTemplateFileName();
446 // hack lets suppress the form rendering for now
447 self
::$_template->assign('isForm', FALSE);
448 return 'CRM/Contribute/Form/ContributionPage/Tab.tpl';