3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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
);
137 * Function to actually build the form
142 public function buildQuickForm() {
143 $this->applyFilter('__ALL__', 'trim');
145 $session = CRM_Core_Session
::singleton();
146 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
148 if (!$this->_cancelURL
) {
149 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1');
152 if ($this->_cancelURL
) {
153 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
157 if ($this->_single
) {
158 $this->addButtons(array(
161 'name' => ts('Save'),
162 'spacing' => ' ',
167 'name' => ts('Save and Done'),
168 'spacing' => ' ',
173 'name' => ts('Save and Next'),
174 'spacing' => ' ',
175 'subName' => 'savenext',
179 'name' => ts('Cancel'),
186 if (!$this->_first
) {
189 'name' => ts('<< Previous'),
190 'spacing' => ' ',
195 'name' => ts('Continue >>'),
196 'spacing' => ' ',
201 'name' => ts('Cancel'),
204 $this->addButtons($buttons);
207 $session->replaceUserContext($this->_cancelURL
);
208 // views are implemented as frozen form
209 if ($this->_action
& CRM_Core_Action
::VIEW
) {
211 $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'"));
216 * This function sets the default values for the form. Note that in edit/view mode
217 * the default values are retrieved from the database
223 function setDefaultValues() {
224 //some child classes calling setdefaults directly w/o preprocess.
225 $this->_values
= $this->get('values');
226 if (!is_array($this->_values
)) {
227 $this->_values
= array();
228 if (isset($this->_id
) && $this->_id
) {
229 $params = array('id' => $this->_id
);
230 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values
);
232 $this->set('values', $this->_values
);
234 $defaults = $this->_values
;
236 $config = CRM_Core_Config
::singleton();
237 if (isset($this->_id
)) {
239 //set defaults for pledgeBlock values.
240 $pledgeBlockParams = array(
241 'entity_id' => $this->_id
,
242 'entity_table' => ts('civicrm_contribution_page'),
244 $pledgeBlockDefaults = array();
245 CRM_Pledge_BAO_PledgeBlock
::retrieve($pledgeBlockParams, $pledgeBlockDefaults);
246 if ($this->_pledgeBlockID
= CRM_Utils_Array
::value('id', $pledgeBlockDefaults)) {
247 $defaults['is_pledge_active'] = TRUE;
249 $pledgeBlock = array(
250 'is_pledge_interval', 'max_reminders',
251 'initial_reminder_day', 'additional_reminder_day',
253 foreach ($pledgeBlock as $key) {
254 $defaults[$key] = CRM_Utils_Array
::value($key, $pledgeBlockDefaults);
256 if (CRM_Utils_Array
::value('pledge_frequency_unit', $pledgeBlockDefaults)) {
257 $defaults['pledge_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
258 $pledgeBlockDefaults['pledge_frequency_unit']
262 // fix the display of the monetary value, CRM-4038
263 if (isset($defaults['goal_amount'])) {
264 $defaults['goal_amount'] = CRM_Utils_Money
::format($defaults['goal_amount'], NULL, '%a');
267 // get price set of type contributions
268 //this is the value for stored in db if price set extends contribution
270 $this->_priceSetID
= CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, $usedFor, 1);
271 if ($this->_priceSetID
) {
272 $defaults['price_set_id'] = $this->_priceSetID
;
275 if (CRM_Utils_Array
::value('end_date', $defaults)) {
276 list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['end_date']);
279 if (CRM_Utils_Array
::value('start_date', $defaults)) {
280 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['start_date']);
284 $defaults['is_active'] = 1;
285 // set current date as start date
286 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults();
289 if (!isset($defaults['for_organization'])) {
290 $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
293 if (CRM_Utils_Array
::value('recur_frequency_unit', $defaults)) {
294 $defaults['recur_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
295 $defaults['recur_frequency_unit']
300 $defaults['recur_frequency_unit'] = array('month' => 1);
303 if (CRM_Utils_Array
::value('is_for_organization', $defaults)) {
304 $defaults['is_organization'] = 1;
307 $defaults['is_for_organization'] = 1;
310 // confirm page starts out enabled
311 if (!isset($defaults['is_confirm_enabled'])) {
312 $defaults['is_confirm_enabled'] = 1;
324 public function postProcess() {
325 $pageId = $this->get('id');
326 //page is newly created.
327 if ($pageId && !$this->_id
) {
328 $session = CRM_Core_Session
::singleton();
329 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1'));
333 function endPostProcess() {
334 // make submit buttons keep the current working tab opened, or save and next tab
335 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
336 $className = CRM_Utils_String
::getClassName($this->_name
);
338 //retrieve list of pages from StateMachine and find next page
339 //this is quite painful because StateMachine is full of protected variables
340 //so we have to retrieve all pages, find current page, and then retrieve next
341 $stateMachine = new CRM_Contribute_StateMachine_ContributionPage($this);
342 $states = $stateMachine->getStates();
343 $statesList = array_keys($states);
344 $currKey = array_search($className, $statesList);
345 $nextPage = (array_key_exists($currKey +
1, $statesList)) ?
$statesList[$currKey +
1] : '';
347 //unfortunately, some classes don't map to subpage names, so we alter the exceptions
349 switch ($className) {
351 $attributes = $this->getVar('_attributes');
352 $subPage = strtolower(basename(CRM_Utils_Array
::value('action', $attributes)));
353 $subPageName = ucFirst($subPage);
354 if ($subPage == 'friend') {
355 $nextPage = 'custom';
358 $nextPage = 'settings';
362 case 'MembershipBlock':
363 $subPage = 'membership';
364 $subPageName = 'MembershipBlock';
365 $nextPage = 'thankyou';
369 $subPage = strtolower($className);
370 $subPageName = $className;
371 $nextPage = strtolower($nextPage);
373 if ($subPage == 'amount') {
374 $nextPage = 'membership';
376 elseif ($subPage == 'thankyou') {
377 $nextPage = 'friend';
382 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
383 array(1 => $subPageName)
384 ), ts('Saved'), 'success');
386 $this->postProcessHook();
388 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_next") {
389 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$subPage}",
390 "action=update&reset=1&id={$this->_id}"
393 elseif ($this->controller
->getButtonName('submit') == "_qf_{$className}_submit_savenext") {
395 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$nextPage}",
396 "action=update&reset=1&id={$this->_id}"
400 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute",
406 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute", 'reset=1'));
411 function getTemplateFileName() {
412 if ($this->controller
->getPrint() == CRM_Core_Smarty
::PRINT_NOFORM ||
413 $this->getVar('_id') <= 0 ||
414 ($this->_action
& CRM_Core_Action
::DELETE
) ||
415 (CRM_Utils_String
::getClassName($this->_name
) == 'AddProduct')
417 return parent
::getTemplateFileName();
420 // hack lets suppress the form rendering for now
421 self
::$_template->assign('isForm', FALSE);
422 return 'CRM/Contribute/Form/ContributionPage/Tab.tpl';