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
35 * Contribution Page form.
37 class CRM_Contribute_Form_ContributionPage
extends CRM_Core_Form
{
40 * The page id saved to the session for an update.
47 * The pledgeBlock id saved to the session for an update.
51 protected $_pledgeBlockID;
54 * Are we in single form mode or wizard mode?
61 * Is this the first page?
65 protected $_first = FALSE;
68 * Is this the last page?
72 protected $_last = FALSE;
79 protected $_priceSetID = NULL;
84 * Explicitly declare the entity api name.
86 public function getDefaultEntity() {
87 return 'Contribution';
91 * Set variables up before form is built.
95 public function preProcess() {
96 // current contribution page id
97 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive',
98 $this, FALSE, NULL, 'REQUEST'
100 $this->assign('contributionPageID', $this->_id
);
102 // get the requested action
103 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String',
104 // default to 'browse'
105 $this, FALSE, 'browse'
108 // setting title and 3rd level breadcrumb for html page if contrib page exists
110 $title = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id
, 'title');
112 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
113 $this->_single
= TRUE;
117 // CRM-16776 - show edit/copy/create buttons on Profiles Tab if user has required permission.
118 if (CRM_Core_Permission
::check('administer CiviCRM')) {
119 $this->assign('perm', TRUE);
122 CRM_Contribute_Form_ContributionPage_TabHeader
::build($this);
124 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
125 CRM_Utils_System
::setTitle(ts('Configure Page - %1', array(1 => $title)));
127 elseif ($this->_action
== CRM_Core_Action
::VIEW
) {
128 CRM_Utils_System
::setTitle(ts('Preview Page - %1', array(1 => $title)));
130 elseif ($this->_action
== CRM_Core_Action
::DELETE
) {
131 CRM_Utils_System
::setTitle(ts('Delete Page - %1', array(1 => $title)));
135 $this->_values
= $this->get('values');
136 if (!is_array($this->_values
)) {
137 $this->_values
= array();
138 if (isset($this->_id
) && $this->_id
) {
139 $params = array('id' => $this->_id
);
140 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values
);
142 $this->set('values', $this->_values
);
145 // Preload libraries required by the "Profiles" tab
146 $schemas = array('IndividualModel', 'OrganizationModel', 'ContributionModel');
147 if (in_array('CiviMember', CRM_Core_Config
::singleton()->enableComponents
)) {
148 $schemas[] = 'MembershipModel';
150 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
151 CRM_UF_Page_ProfileEditor
::registerSchemas($schemas);
155 * Build the form object.
159 public function buildQuickForm() {
160 $this->applyFilter('__ALL__', 'trim');
162 $session = CRM_Core_Session
::singleton();
163 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
165 if (!$this->_cancelURL
) {
166 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1');
169 if ($this->_cancelURL
) {
170 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
173 if ($this->_single
) {
177 'name' => ts('Save'),
178 'spacing' => ' ',
183 'name' => ts('Save and Done'),
184 'spacing' => ' ',
191 'name' => ts('Save and Next'),
192 'spacing' => ' ',
193 'subName' => 'savenext',
198 'name' => ts('Cancel'),
200 $this->addButtons($buttons);
204 if (!$this->_first
) {
207 'name' => ts('Previous'),
208 'spacing' => ' ',
213 'name' => ts('Continue'),
214 'spacing' => ' ',
219 'name' => ts('Cancel'),
222 $this->addButtons($buttons);
225 $session->replaceUserContext($this->_cancelURL
);
226 // views are implemented as frozen form
227 if ($this->_action
& CRM_Core_Action
::VIEW
) {
229 $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'"));
232 // don't show option for contribution amounts section if membership price set
233 // this flag is sent to template
235 $membershipBlock = new CRM_Member_DAO_MembershipBlock();
236 $membershipBlock->entity_table
= 'civicrm_contribution_page';
237 $membershipBlock->entity_id
= $this->_id
;
238 $membershipBlock->is_active
= 1;
239 $hasMembershipBlk = FALSE;
240 if ($membershipBlock->find(TRUE) &&
241 ($setID = CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, NULL, 1))
243 $extends = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
244 if ($extends && $extends == CRM_Core_Component
::getComponentID('CiviMember')) {
245 $hasMembershipBlk = TRUE;
248 // set value in DOM that membership price set exists
249 CRM_Core_Resources
::singleton()->addSetting(array('memberPriceset' => $hasMembershipBlk));
253 * Set default values for the form. Note that in edit/view mode
254 * the default values are retrieved from the database
260 public function setDefaultValues() {
261 //some child classes calling setdefaults directly w/o preprocess.
262 $this->_values
= $this->get('values');
263 if (!is_array($this->_values
)) {
264 $this->_values
= array();
265 if (isset($this->_id
) && $this->_id
) {
266 $params = array('id' => $this->_id
);
267 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values
);
269 $this->set('values', $this->_values
);
271 $defaults = $this->_values
;
273 $config = CRM_Core_Config
::singleton();
274 if (isset($this->_id
)) {
276 //set defaults for pledgeBlock values.
277 $pledgeBlockParams = array(
278 'entity_id' => $this->_id
,
279 'entity_table' => ts('civicrm_contribution_page'),
281 $pledgeBlockDefaults = array();
282 CRM_Pledge_BAO_PledgeBlock
::retrieve($pledgeBlockParams, $pledgeBlockDefaults);
283 if ($this->_pledgeBlockID
= CRM_Utils_Array
::value('id', $pledgeBlockDefaults)) {
284 $defaults['is_pledge_active'] = TRUE;
286 $pledgeBlock = array(
287 'is_pledge_interval',
289 'initial_reminder_day',
290 'additional_reminder_day',
292 foreach ($pledgeBlock as $key) {
293 $defaults[$key] = CRM_Utils_Array
::value($key, $pledgeBlockDefaults);
295 if (!empty($pledgeBlockDefaults['pledge_frequency_unit'])) {
296 $defaults['pledge_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
297 $pledgeBlockDefaults['pledge_frequency_unit']
301 // fix the display of the monetary value, CRM-4038
302 if (isset($defaults['goal_amount'])) {
303 $defaults['goal_amount'] = CRM_Utils_Money
::format($defaults['goal_amount'], NULL, '%a');
306 // get price set of type contributions
307 //this is the value for stored in db if price set extends contribution
309 $this->_priceSetID
= CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, $usedFor, 1);
310 if ($this->_priceSetID
) {
311 $defaults['price_set_id'] = $this->_priceSetID
;
314 if (!empty($defaults['end_date'])) {
315 list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['end_date']);
318 if (!empty($defaults['start_date'])) {
319 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['start_date']);
323 $defaults['is_active'] = 1;
324 // set current date as start date
325 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults();
328 if (!isset($defaults['for_organization'])) {
329 $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
332 if (!empty($defaults['recur_frequency_unit'])) {
333 $defaults['recur_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
334 $defaults['recur_frequency_unit']
339 $defaults['recur_frequency_unit'] = array('month' => 1);
342 if (!empty($defaults['is_for_organization'])) {
343 $defaults['is_organization'] = 1;
346 $defaults['is_for_organization'] = 1;
349 // confirm page starts out enabled
350 if (!isset($defaults['is_confirm_enabled'])) {
351 $defaults['is_confirm_enabled'] = 1;
362 public function postProcess() {
363 $pageId = $this->get('id');
364 //page is newly created.
365 if ($pageId && !$this->_id
) {
366 $session = CRM_Core_Session
::singleton();
367 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1'));
371 public function endPostProcess() {
372 // make submit buttons keep the current working tab opened, or save and next tab
373 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
374 $className = CRM_Utils_String
::getClassName($this->_name
);
376 //retrieve list of pages from StateMachine and find next page
377 //this is quite painful because StateMachine is full of protected variables
378 //so we have to retrieve all pages, find current page, and then retrieve next
379 $stateMachine = new CRM_Contribute_StateMachine_ContributionPage($this);
380 $states = $stateMachine->getStates();
381 $statesList = array_keys($states);
382 $currKey = array_search($className, $statesList);
383 $nextPage = (array_key_exists($currKey +
1, $statesList)) ?
$statesList[$currKey +
1] : '';
385 //unfortunately, some classes don't map to subpage names, so we alter the exceptions
387 switch ($className) {
389 $attributes = $this->getVar('_attributes');
390 $subPage = strtolower(basename(CRM_Utils_Array
::value('action', $attributes)));
391 $subPageName = ucfirst($subPage);
392 if ($subPage == 'friend') {
393 $nextPage = 'custom';
396 $nextPage = 'settings';
400 case 'MembershipBlock':
401 $subPage = 'membership';
402 $subPageName = 'MembershipBlock';
403 $nextPage = 'thankyou';
407 $subPage = strtolower($className);
408 $subPageName = $className;
409 $nextPage = strtolower($nextPage);
411 if ($subPage == 'amount') {
412 $nextPage = 'membership';
414 elseif ($subPage == 'thankyou') {
415 $nextPage = 'friend';
420 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
421 array(1 => $subPageName)
422 ), ts('Saved'), 'success');
424 $this->postProcessHook();
426 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_next") {
427 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$subPage}",
428 "action=update&reset=1&id={$this->_id}"
431 elseif ($this->controller
->getButtonName('submit') == "_qf_{$className}_submit_savenext") {
433 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$nextPage}",
434 "action=update&reset=1&id={$this->_id}"
438 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute",
444 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute", 'reset=1'));
450 * Use the form name to create the tpl file name.
457 public function getTemplateFileName() {
458 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
459 ($this->_action
& CRM_Core_Action
::DELETE
) ||
460 (CRM_Utils_String
::getClassName($this->_name
) == 'AddProduct')
462 return parent
::getTemplateFileName();
465 // hack lets suppress the form rendering for now
466 self
::$_template->assign('isForm', FALSE);
467 return 'CRM/Contribute/Form/ContributionPage/Tab.tpl';