3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
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;
74 protected $_priceSetID = NULL;
79 * Set variables up before form is built
83 public function preProcess() {
84 // current contribution page id
85 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive',
86 $this, FALSE, NULL, 'REQUEST'
88 $this->assign('contributionPageID', $this->_id
);
90 // get the requested action
91 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String',
92 // default to 'browse'
93 $this, FALSE, 'browse'
96 // setting title and 3rd level breadcrumb for html page if contrib page exists
98 $title = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id
, 'title');
100 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
101 $this->_single
= TRUE;
106 CRM_Contribute_Form_ContributionPage_TabHeader
::build($this);
108 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
109 CRM_Utils_System
::setTitle(ts('Configure Page - %1', array(1 => $title)));
111 elseif ($this->_action
== CRM_Core_Action
::VIEW
) {
112 CRM_Utils_System
::setTitle(ts('Preview Page - %1', array(1 => $title)));
114 elseif ($this->_action
== CRM_Core_Action
::DELETE
) {
115 CRM_Utils_System
::setTitle(ts('Delete Page - %1', array(1 => $title)));
119 $this->_values
= $this->get('values');
120 if (!is_array($this->_values
)) {
121 $this->_values
= array();
122 if (isset($this->_id
) && $this->_id
) {
123 $params = array('id' => $this->_id
);
124 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values
);
126 $this->set('values', $this->_values
);
129 // Preload libraries required by the "Profiles" tab
130 $schemas = array('IndividualModel', 'OrganizationModel', 'ContributionModel');
131 if (in_array('CiviMember', CRM_Core_Config
::singleton()->enableComponents
)) {
132 $schemas[] = 'MembershipModel';
134 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
135 CRM_UF_Page_ProfileEditor
::registerSchemas($schemas);
139 * Build the form object
143 public function buildQuickForm() {
144 $this->applyFilter('__ALL__', 'trim');
146 $session = CRM_Core_Session
::singleton();
147 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
149 if (!$this->_cancelURL
) {
150 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1');
153 if ($this->_cancelURL
) {
154 $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'"));
214 // don't show option for contribution amounts section if membership price set
215 // this flag is sent to template
217 $membershipBlock = new CRM_Member_DAO_MembershipBlock();
218 $membershipBlock->entity_table
= 'civicrm_contribution_page';
219 $membershipBlock->entity_id
= $this->_id
;
220 $membershipBlock->is_active
= 1;
221 $hasMembershipBlk = FALSE;
222 if ($membershipBlock->find(TRUE) &&
223 ($setID = CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, NULL, 1))
225 $extends = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
226 if ($extends && $extends == CRM_Core_Component
::getComponentID('CiviMember')) {
227 $hasMembershipBlk = TRUE;
230 // set value in DOM that membership price set exists
231 CRM_Core_Resources
::singleton()->addSetting(array('memberPriceset' => $hasMembershipBlk));
235 * Set default values for the form. Note that in edit/view mode
236 * the default values are retrieved from the database
239 * @return array defaults
241 public function setDefaultValues() {
242 //some child classes calling setdefaults directly w/o preprocess.
243 $this->_values
= $this->get('values');
244 if (!is_array($this->_values
)) {
245 $this->_values
= array();
246 if (isset($this->_id
) && $this->_id
) {
247 $params = array('id' => $this->_id
);
248 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values
);
250 $this->set('values', $this->_values
);
252 $defaults = $this->_values
;
254 $config = CRM_Core_Config
::singleton();
255 if (isset($this->_id
)) {
257 //set defaults for pledgeBlock values.
258 $pledgeBlockParams = array(
259 'entity_id' => $this->_id
,
260 'entity_table' => ts('civicrm_contribution_page'),
262 $pledgeBlockDefaults = array();
263 CRM_Pledge_BAO_PledgeBlock
::retrieve($pledgeBlockParams, $pledgeBlockDefaults);
264 if ($this->_pledgeBlockID
= CRM_Utils_Array
::value('id', $pledgeBlockDefaults)) {
265 $defaults['is_pledge_active'] = TRUE;
267 $pledgeBlock = array(
268 'is_pledge_interval', 'max_reminders',
269 'initial_reminder_day', 'additional_reminder_day',
271 foreach ($pledgeBlock as $key) {
272 $defaults[$key] = CRM_Utils_Array
::value($key, $pledgeBlockDefaults);
274 if (!empty($pledgeBlockDefaults['pledge_frequency_unit'])) {
275 $defaults['pledge_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
276 $pledgeBlockDefaults['pledge_frequency_unit']
280 // fix the display of the monetary value, CRM-4038
281 if (isset($defaults['goal_amount'])) {
282 $defaults['goal_amount'] = CRM_Utils_Money
::format($defaults['goal_amount'], NULL, '%a');
285 // get price set of type contributions
286 //this is the value for stored in db if price set extends contribution
288 $this->_priceSetID
= CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, $usedFor, 1);
289 if ($this->_priceSetID
) {
290 $defaults['price_set_id'] = $this->_priceSetID
;
293 if (!empty($defaults['end_date'])) {
294 list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['end_date']);
297 if (!empty($defaults['start_date'])) {
298 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['start_date']);
302 $defaults['is_active'] = 1;
303 // set current date as start date
304 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults();
307 if (!isset($defaults['for_organization'])) {
308 $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
311 if (!empty($defaults['recur_frequency_unit'])) {
312 $defaults['recur_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
313 $defaults['recur_frequency_unit']
318 $defaults['recur_frequency_unit'] = array('month' => 1);
321 if (!empty($defaults['is_for_organization'])) {
322 $defaults['is_organization'] = 1;
325 $defaults['is_for_organization'] = 1;
328 // confirm page starts out enabled
329 if (!isset($defaults['is_confirm_enabled'])) {
330 $defaults['is_confirm_enabled'] = 1;
341 public function postProcess() {
342 $pageId = $this->get('id');
343 //page is newly created.
344 if ($pageId && !$this->_id
) {
345 $session = CRM_Core_Session
::singleton();
346 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1'));
350 public function endPostProcess() {
351 // make submit buttons keep the current working tab opened, or save and next tab
352 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
353 $className = CRM_Utils_String
::getClassName($this->_name
);
355 //retrieve list of pages from StateMachine and find next page
356 //this is quite painful because StateMachine is full of protected variables
357 //so we have to retrieve all pages, find current page, and then retrieve next
358 $stateMachine = new CRM_Contribute_StateMachine_ContributionPage($this);
359 $states = $stateMachine->getStates();
360 $statesList = array_keys($states);
361 $currKey = array_search($className, $statesList);
362 $nextPage = (array_key_exists($currKey +
1, $statesList)) ?
$statesList[$currKey +
1] : '';
364 //unfortunately, some classes don't map to subpage names, so we alter the exceptions
366 switch ($className) {
368 $attributes = $this->getVar('_attributes');
369 $subPage = strtolower(basename(CRM_Utils_Array
::value('action', $attributes)));
370 $subPageName = ucfirst($subPage);
371 if ($subPage == 'friend') {
372 $nextPage = 'custom';
375 $nextPage = 'settings';
379 case 'MembershipBlock':
380 $subPage = 'membership';
381 $subPageName = 'MembershipBlock';
382 $nextPage = 'thankyou';
386 $subPage = strtolower($className);
387 $subPageName = $className;
388 $nextPage = strtolower($nextPage);
390 if ($subPage == 'amount') {
391 $nextPage = 'membership';
393 elseif ($subPage == 'thankyou') {
394 $nextPage = 'friend';
399 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
400 array(1 => $subPageName)
401 ), ts('Saved'), 'success');
403 $this->postProcessHook();
405 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_next") {
406 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$subPage}",
407 "action=update&reset=1&id={$this->_id}"
410 elseif ($this->controller
->getButtonName('submit') == "_qf_{$className}_submit_savenext") {
412 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$nextPage}",
413 "action=update&reset=1&id={$this->_id}"
417 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute",
423 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute", 'reset=1'));
429 * Use the form name to create the tpl file name
436 public function getTemplateFileName() {
437 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
438 ($this->_action
& CRM_Core_Action
::DELETE
) ||
439 (CRM_Utils_String
::getClassName($this->_name
) == 'AddProduct')
441 return parent
::getTemplateFileName();
444 // hack lets suppress the form rendering for now
445 self
::$_template->assign('isForm', FALSE);
446 return 'CRM/Contribute/Form/ContributionPage/Tab.tpl';