Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * form to process actions on Premiums | |
38 | */ | |
39 | class CRM_Contribute_Form_ContributionPage_Premium extends CRM_Contribute_Form_ContributionPage { | |
40 | ||
41 | /** | |
42 | * This function sets the default values for the form. Note that in edit/view mode | |
43 | * the default values are retrieved from the database | |
44 | * | |
45 | * @access public | |
46 | * | |
47 | * @return void | |
48 | */ | |
49 | function setDefaultValues() { | |
50 | $defaults = array(); | |
51 | if (isset($this->_id)) { | |
52 | $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title'); | |
53 | CRM_Utils_System::setTitle(ts('Premiums (%1)', array(1 => $title))); | |
54 | $dao = new CRM_Contribute_DAO_Premium(); | |
55 | $dao->entity_table = 'civicrm_contribution_page'; | |
56 | $dao->entity_id = $this->_id; | |
57 | $dao->find(TRUE); | |
58 | CRM_Core_DAO::storeValues($dao, $defaults); | |
59 | } | |
60 | return $defaults; | |
61 | } | |
62 | ||
63 | /** | |
64 | * Function to actually build the form | |
65 | * | |
66 | * @return void | |
67 | * @access public | |
68 | */ | |
69 | public function buildQuickForm() { | |
70 | $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Premium'); | |
71 | $this->addElement('checkbox', 'premiums_active', ts('Premiums Section Enabled?'), NULL, array('onclick' => "premiumBlock(this);")); | |
72 | ||
73 | $this->addElement('text', 'premiums_intro_title', ts('Title'), $attributes['premiums_intro_title']); | |
74 | ||
75 | $this->add('textarea', 'premiums_intro_text', ts('Introductory Message'), 'rows=5, cols=50'); | |
76 | ||
77 | $this->add('text', 'premiums_contact_email', ts('Contact Email') . ' ', $attributes['premiums_contact_email']); | |
78 | ||
79 | $this->addRule('premiums_contact_email', ts('Please enter a valid email address for Contact Email') . ' ', 'email'); | |
80 | ||
81 | $this->add('text', 'premiums_contact_phone', ts('Contact Phone'), $attributes['premiums_contact_phone']); | |
82 | ||
83 | $this->addRule('premiums_contact_phone', ts('Please enter a valid phone number.'), 'phone'); | |
84 | ||
85 | $this->addElement('checkbox', 'premiums_display_min_contribution', ts('Display Minimum Contribution Amount?')); | |
86 | ||
87 | // CRM-10999 Control label and position for No Thank-you radio button | |
88 | $this->add('text', 'premiums_nothankyou_label', ts('No Thank-you Label'), $attributes['premiums_nothankyou_label'], TRUE); | |
89 | $positions = array(1 => ts('Before Premiums'), 2 => ts('After Premiums')); | |
90 | $this->add('select','premiums_nothankyou_position', ts('No Thank-you Option'), $positions); | |
91 | $showForm = TRUE; | |
92 | ||
93 | if ($this->_single) { | |
94 | if ($this->_id) { | |
95 | $daoPremium = new CRM_Contribute_DAO_Premium(); | |
96 | $daoPremium->entity_id = $this->_id; | |
97 | $daoPremium->entity_table = 'civicrm_contribution_page'; | |
98 | $daoPremium->premiums_active = 1; | |
99 | if ($daoPremium->find(TRUE)) { | |
100 | $showForm = FALSE; | |
101 | } | |
102 | } | |
103 | } | |
104 | $this->assign('showForm', $showForm); | |
105 | ||
106 | parent::buildQuickForm(); | |
107 | ||
108 | $premiumPage = new CRM_Contribute_Page_Premium(); | |
109 | $premiumPage->browse(); | |
110 | } | |
111 | ||
112 | /** | |
113 | * Process the form | |
114 | * | |
115 | * @return void | |
116 | * @access public | |
117 | */ | |
118 | public function postProcess() { | |
119 | // get the submitted form values. | |
120 | $params = $this->controller->exportValues($this->_name); | |
121 | ||
122 | // we do this in case the user has hit the forward/back button | |
123 | ||
124 | $dao = new CRM_Contribute_DAO_Premium(); | |
125 | $dao->entity_table = 'civicrm_contribution_page'; | |
126 | $dao->entity_id = $this->_id; | |
127 | $dao->find(TRUE); | |
128 | $premiumID = $dao->id; | |
129 | if ($premiumID) { | |
130 | $params['id'] = $premiumID; | |
131 | } | |
132 | ||
133 | $params['premiums_active'] = CRM_Utils_Array::value('premiums_active', $params, FALSE); | |
134 | $params['premiums_display_min_contribution'] = CRM_Utils_Array::value('premiums_display_min_contribution', $params, FALSE); | |
135 | $params['entity_table'] = 'civicrm_contribution_page'; | |
136 | $params['entity_id'] = $this->_id; | |
137 | ||
138 | $dao = new CRM_Contribute_DAO_Premium(); | |
139 | $dao->copyValues($params); | |
140 | $dao->save(); | |
141 | parent::endPostProcess(); | |
142 | } | |
143 | ||
144 | /** | |
145 | * Return a descriptive name for the page, used in wizard header | |
146 | * | |
147 | * @return string | |
148 | * @access public | |
149 | */ | |
150 | public function getTitle() { | |
151 | return ts('Premiums'); | |
152 | } | |
153 | } | |
154 |