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;
112 // CRM-16776 - show edit/copy/create buttons on Profiles Tab if user has required permission.
113 if (CRM_Core_Permission
::check('administer CiviCRM')) {
114 $this->assign('perm', TRUE);
117 CRM_Contribute_Form_ContributionPage_TabHeader
::build($this);
119 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
120 CRM_Utils_System
::setTitle(ts('Configure Page - %1', array(1 => $title)));
122 elseif ($this->_action
== CRM_Core_Action
::VIEW
) {
123 CRM_Utils_System
::setTitle(ts('Preview Page - %1', array(1 => $title)));
125 elseif ($this->_action
== CRM_Core_Action
::DELETE
) {
126 CRM_Utils_System
::setTitle(ts('Delete Page - %1', array(1 => $title)));
130 $this->_values
= $this->get('values');
131 if (!is_array($this->_values
)) {
132 $this->_values
= array();
133 if (isset($this->_id
) && $this->_id
) {
134 $params = array('id' => $this->_id
);
135 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values
);
137 $this->set('values', $this->_values
);
140 // Preload libraries required by the "Profiles" tab
141 $schemas = array('IndividualModel', 'OrganizationModel', 'ContributionModel');
142 if (in_array('CiviMember', CRM_Core_Config
::singleton()->enableComponents
)) {
143 $schemas[] = 'MembershipModel';
145 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
146 CRM_UF_Page_ProfileEditor
::registerSchemas($schemas);
150 * Build the form object.
154 public function buildQuickForm() {
155 $this->applyFilter('__ALL__', 'trim');
157 $session = CRM_Core_Session
::singleton();
158 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
160 if (!$this->_cancelURL
) {
161 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1');
164 if ($this->_cancelURL
) {
165 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
168 if ($this->_single
) {
172 'name' => ts('Save'),
173 'spacing' => ' ',
178 'name' => ts('Save and Done'),
179 'spacing' => ' ',
186 'name' => ts('Save and Next'),
187 'spacing' => ' ',
188 'subName' => 'savenext',
193 'name' => ts('Cancel'),
195 $this->addButtons($buttons);
199 if (!$this->_first
) {
202 'name' => ts('Previous'),
203 'spacing' => ' ',
208 'name' => ts('Continue'),
209 'spacing' => ' ',
214 'name' => ts('Cancel'),
217 $this->addButtons($buttons);
220 $session->replaceUserContext($this->_cancelURL
);
221 // views are implemented as frozen form
222 if ($this->_action
& CRM_Core_Action
::VIEW
) {
224 $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'"));
227 // don't show option for contribution amounts section if membership price set
228 // this flag is sent to template
230 $membershipBlock = new CRM_Member_DAO_MembershipBlock();
231 $membershipBlock->entity_table
= 'civicrm_contribution_page';
232 $membershipBlock->entity_id
= $this->_id
;
233 $membershipBlock->is_active
= 1;
234 $hasMembershipBlk = FALSE;
235 if ($membershipBlock->find(TRUE) &&
236 ($setID = CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, NULL, 1))
238 $extends = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
239 if ($extends && $extends == CRM_Core_Component
::getComponentID('CiviMember')) {
240 $hasMembershipBlk = TRUE;
243 // set value in DOM that membership price set exists
244 CRM_Core_Resources
::singleton()->addSetting(array('memberPriceset' => $hasMembershipBlk));
248 * Set default values for the form. Note that in edit/view mode
249 * the default values are retrieved from the database
255 public function setDefaultValues() {
256 //some child classes calling setdefaults directly w/o preprocess.
257 $this->_values
= $this->get('values');
258 if (!is_array($this->_values
)) {
259 $this->_values
= array();
260 if (isset($this->_id
) && $this->_id
) {
261 $params = array('id' => $this->_id
);
262 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values
);
264 $this->set('values', $this->_values
);
266 $defaults = $this->_values
;
268 $config = CRM_Core_Config
::singleton();
269 if (isset($this->_id
)) {
271 //set defaults for pledgeBlock values.
272 $pledgeBlockParams = array(
273 'entity_id' => $this->_id
,
274 'entity_table' => ts('civicrm_contribution_page'),
276 $pledgeBlockDefaults = array();
277 CRM_Pledge_BAO_PledgeBlock
::retrieve($pledgeBlockParams, $pledgeBlockDefaults);
278 if ($this->_pledgeBlockID
= CRM_Utils_Array
::value('id', $pledgeBlockDefaults)) {
279 $defaults['is_pledge_active'] = TRUE;
281 $pledgeBlock = array(
282 'is_pledge_interval',
284 'initial_reminder_day',
285 'additional_reminder_day',
287 foreach ($pledgeBlock as $key) {
288 $defaults[$key] = CRM_Utils_Array
::value($key, $pledgeBlockDefaults);
290 if (!empty($pledgeBlockDefaults['pledge_frequency_unit'])) {
291 $defaults['pledge_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
292 $pledgeBlockDefaults['pledge_frequency_unit']
296 // fix the display of the monetary value, CRM-4038
297 if (isset($defaults['goal_amount'])) {
298 $defaults['goal_amount'] = CRM_Utils_Money
::format($defaults['goal_amount'], NULL, '%a');
301 // get price set of type contributions
302 //this is the value for stored in db if price set extends contribution
304 $this->_priceSetID
= CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, $usedFor, 1);
305 if ($this->_priceSetID
) {
306 $defaults['price_set_id'] = $this->_priceSetID
;
309 if (!empty($defaults['end_date'])) {
310 list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['end_date']);
313 if (!empty($defaults['start_date'])) {
314 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['start_date']);
318 $defaults['is_active'] = 1;
319 // set current date as start date
320 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults();
323 if (!isset($defaults['for_organization'])) {
324 $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
327 if (!empty($defaults['recur_frequency_unit'])) {
328 $defaults['recur_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
329 $defaults['recur_frequency_unit']
334 $defaults['recur_frequency_unit'] = array('month' => 1);
337 if (!empty($defaults['is_for_organization'])) {
338 $defaults['is_organization'] = 1;
341 $defaults['is_for_organization'] = 1;
344 // confirm page starts out enabled
345 if (!isset($defaults['is_confirm_enabled'])) {
346 $defaults['is_confirm_enabled'] = 1;
357 public function postProcess() {
358 $pageId = $this->get('id');
359 //page is newly created.
360 if ($pageId && !$this->_id
) {
361 $session = CRM_Core_Session
::singleton();
362 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1'));
366 public function endPostProcess() {
367 // make submit buttons keep the current working tab opened, or save and next tab
368 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
369 $className = CRM_Utils_String
::getClassName($this->_name
);
371 //retrieve list of pages from StateMachine and find next page
372 //this is quite painful because StateMachine is full of protected variables
373 //so we have to retrieve all pages, find current page, and then retrieve next
374 $stateMachine = new CRM_Contribute_StateMachine_ContributionPage($this);
375 $states = $stateMachine->getStates();
376 $statesList = array_keys($states);
377 $currKey = array_search($className, $statesList);
378 $nextPage = (array_key_exists($currKey +
1, $statesList)) ?
$statesList[$currKey +
1] : '';
380 //unfortunately, some classes don't map to subpage names, so we alter the exceptions
382 switch ($className) {
384 $attributes = $this->getVar('_attributes');
385 $subPage = strtolower(basename(CRM_Utils_Array
::value('action', $attributes)));
386 $subPageName = ucfirst($subPage);
387 if ($subPage == 'friend') {
388 $nextPage = 'custom';
391 $nextPage = 'settings';
395 case 'MembershipBlock':
396 $subPage = 'membership';
397 $subPageName = 'MembershipBlock';
398 $nextPage = 'thankyou';
402 $subPage = strtolower($className);
403 $subPageName = $className;
404 $nextPage = strtolower($nextPage);
406 if ($subPage == 'amount') {
407 $nextPage = 'membership';
409 elseif ($subPage == 'thankyou') {
410 $nextPage = 'friend';
415 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
416 array(1 => $subPageName)
417 ), ts('Saved'), 'success');
419 $this->postProcessHook();
421 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_next") {
422 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$subPage}",
423 "action=update&reset=1&id={$this->_id}"
426 elseif ($this->controller
->getButtonName('submit') == "_qf_{$className}_submit_savenext") {
428 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$nextPage}",
429 "action=update&reset=1&id={$this->_id}"
433 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute",
439 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute", 'reset=1'));
445 * Use the form name to create the tpl file name.
452 public function getTemplateFileName() {
453 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
454 ($this->_action
& CRM_Core_Action
::DELETE
) ||
455 (CRM_Utils_String
::getClassName($this->_name
) == 'AddProduct')
457 return parent
::getTemplateFileName();
460 // hack lets suppress the form rendering for now
461 self
::$_template->assign('isForm', FALSE);
462 return 'CRM/Contribute/Form/ContributionPage/Tab.tpl';