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
242 public function setDefaultValues() {
243 //some child classes calling setdefaults directly w/o preprocess.
244 $this->_values
= $this->get('values');
245 if (!is_array($this->_values
)) {
246 $this->_values
= array();
247 if (isset($this->_id
) && $this->_id
) {
248 $params = array('id' => $this->_id
);
249 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values
);
251 $this->set('values', $this->_values
);
253 $defaults = $this->_values
;
255 $config = CRM_Core_Config
::singleton();
256 if (isset($this->_id
)) {
258 //set defaults for pledgeBlock values.
259 $pledgeBlockParams = array(
260 'entity_id' => $this->_id
,
261 'entity_table' => ts('civicrm_contribution_page'),
263 $pledgeBlockDefaults = array();
264 CRM_Pledge_BAO_PledgeBlock
::retrieve($pledgeBlockParams, $pledgeBlockDefaults);
265 if ($this->_pledgeBlockID
= CRM_Utils_Array
::value('id', $pledgeBlockDefaults)) {
266 $defaults['is_pledge_active'] = TRUE;
268 $pledgeBlock = array(
269 'is_pledge_interval',
271 'initial_reminder_day',
272 'additional_reminder_day',
274 foreach ($pledgeBlock as $key) {
275 $defaults[$key] = CRM_Utils_Array
::value($key, $pledgeBlockDefaults);
277 if (!empty($pledgeBlockDefaults['pledge_frequency_unit'])) {
278 $defaults['pledge_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
279 $pledgeBlockDefaults['pledge_frequency_unit']
283 // fix the display of the monetary value, CRM-4038
284 if (isset($defaults['goal_amount'])) {
285 $defaults['goal_amount'] = CRM_Utils_Money
::format($defaults['goal_amount'], NULL, '%a');
288 // get price set of type contributions
289 //this is the value for stored in db if price set extends contribution
291 $this->_priceSetID
= CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, $usedFor, 1);
292 if ($this->_priceSetID
) {
293 $defaults['price_set_id'] = $this->_priceSetID
;
296 if (!empty($defaults['end_date'])) {
297 list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['end_date']);
300 if (!empty($defaults['start_date'])) {
301 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['start_date']);
305 $defaults['is_active'] = 1;
306 // set current date as start date
307 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults();
310 if (!isset($defaults['for_organization'])) {
311 $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
314 if (!empty($defaults['recur_frequency_unit'])) {
315 $defaults['recur_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
316 $defaults['recur_frequency_unit']
321 $defaults['recur_frequency_unit'] = array('month' => 1);
324 if (!empty($defaults['is_for_organization'])) {
325 $defaults['is_organization'] = 1;
328 $defaults['is_for_organization'] = 1;
331 // confirm page starts out enabled
332 if (!isset($defaults['is_confirm_enabled'])) {
333 $defaults['is_confirm_enabled'] = 1;
344 public function postProcess() {
345 $pageId = $this->get('id');
346 //page is newly created.
347 if ($pageId && !$this->_id
) {
348 $session = CRM_Core_Session
::singleton();
349 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1'));
353 public function endPostProcess() {
354 // make submit buttons keep the current working tab opened, or save and next tab
355 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
356 $className = CRM_Utils_String
::getClassName($this->_name
);
358 //retrieve list of pages from StateMachine and find next page
359 //this is quite painful because StateMachine is full of protected variables
360 //so we have to retrieve all pages, find current page, and then retrieve next
361 $stateMachine = new CRM_Contribute_StateMachine_ContributionPage($this);
362 $states = $stateMachine->getStates();
363 $statesList = array_keys($states);
364 $currKey = array_search($className, $statesList);
365 $nextPage = (array_key_exists($currKey +
1, $statesList)) ?
$statesList[$currKey +
1] : '';
367 //unfortunately, some classes don't map to subpage names, so we alter the exceptions
369 switch ($className) {
371 $attributes = $this->getVar('_attributes');
372 $subPage = strtolower(basename(CRM_Utils_Array
::value('action', $attributes)));
373 $subPageName = ucfirst($subPage);
374 if ($subPage == 'friend') {
375 $nextPage = 'custom';
378 $nextPage = 'settings';
382 case 'MembershipBlock':
383 $subPage = 'membership';
384 $subPageName = 'MembershipBlock';
385 $nextPage = 'thankyou';
389 $subPage = strtolower($className);
390 $subPageName = $className;
391 $nextPage = strtolower($nextPage);
393 if ($subPage == 'amount') {
394 $nextPage = 'membership';
396 elseif ($subPage == 'thankyou') {
397 $nextPage = 'friend';
402 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
403 array(1 => $subPageName)
404 ), ts('Saved'), 'success');
406 $this->postProcessHook();
408 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_next") {
409 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$subPage}",
410 "action=update&reset=1&id={$this->_id}"
413 elseif ($this->controller
->getButtonName('submit') == "_qf_{$className}_submit_savenext") {
415 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute/{$nextPage}",
416 "action=update&reset=1&id={$this->_id}"
420 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute",
426 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/admin/contribute", 'reset=1'));
432 * Use the form name to create the tpl file name
439 public function getTemplateFileName() {
440 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
441 ($this->_action
& CRM_Core_Action
::DELETE
) ||
442 (CRM_Utils_String
::getClassName($this->_name
) == 'AddProduct')
444 return parent
::getTemplateFileName();
447 // hack lets suppress the form rendering for now
448 self
::$_template->assign('isForm', FALSE);
449 return 'CRM/Contribute/Form/ContributionPage/Tab.tpl';