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 | class CRM_Contribute_Form_ContributionPage_Widget extends CRM_Contribute_Form_ContributionPage { | |
36 | protected $_colors; | |
37 | ||
38 | protected $_widget; function preProcess() { | |
39 | parent::preProcess(); | |
40 | ||
41 | $this->_widget = new CRM_Contribute_DAO_Widget(); | |
42 | $this->_widget->contribution_page_id = $this->_id; | |
43 | if (!$this->_widget->find(TRUE)) { | |
44 | $this->_widget = NULL; | |
45 | } | |
46 | else { | |
47 | $this->assign('widget_id', $this->_widget->id); | |
48 | ||
49 | // check of home url is set, if set then it flash widget might be in use. | |
50 | $this->assign('showStatus', FALSE); | |
51 | if ($this->_widget->url_homepage) { | |
52 | $this->assign('showStatus', TRUE); | |
53 | } | |
54 | } | |
55 | ||
56 | $this->assign('cpageId', $this->_id); | |
57 | ||
58 | $config = CRM_Core_Config::singleton(); | |
59 | $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', | |
60 | $this->_id, | |
61 | 'title' | |
62 | ); | |
63 | ||
64 | $this->_fields = array('title' => array(ts('Title'), | |
65 | 'text', | |
66 | FALSE, | |
67 | $title, | |
68 | ), | |
69 | 'url_logo' => array(ts('URL to Logo Image'), | |
70 | 'text', | |
71 | FALSE, | |
72 | NULL, | |
73 | ), | |
74 | 'button_title' => array(ts('Button Title'), | |
75 | 'text', | |
76 | FALSE, | |
77 | ts('Contribute!'), | |
78 | ), | |
79 | ); | |
80 | ||
81 | $this->_colorFields = array('color_title' => array(ts('Title Text Color'), | |
82 | 'text', | |
83 | FALSE, | |
84 | '#2786C2', | |
85 | ), | |
86 | 'color_bar' => array(ts('Progress Bar Color'), | |
87 | 'text', | |
88 | FALSE, | |
89 | '#FFFFFF', | |
90 | ), | |
91 | 'color_main_text' => array(ts('Additional Text Color'), | |
92 | 'text', | |
93 | FALSE, | |
94 | '#FFFFFF', | |
95 | ), | |
96 | 'color_main' => array(ts('Background Color'), | |
97 | 'text', | |
98 | FALSE, | |
99 | '#96C0E7', | |
100 | ), | |
101 | 'color_main_bg' => array(ts('Background Color Top Area'), | |
102 | 'text', | |
103 | FALSE, | |
104 | '#B7E2FF', | |
105 | ), | |
106 | 'color_bg' => array(ts('Border Color'), | |
107 | 'text', | |
108 | FALSE, | |
109 | '#96C0E7', | |
110 | ), | |
111 | 'color_about_link' => array(ts('Button Link Color'), | |
112 | 'text', | |
113 | FALSE, | |
114 | '#556C82', | |
115 | ), | |
116 | 'color_button' => array(ts('Button Background Color'), | |
117 | 'text', | |
118 | FALSE, | |
119 | '#FFFFFF', | |
120 | ), | |
121 | 'color_homepage_link' => array(ts('Homepage Link Color'), | |
122 | 'text', | |
123 | FALSE, | |
124 | '#FFFFFF', | |
125 | ), | |
126 | ); | |
127 | } | |
128 | ||
129 | function setDefaultValues() { | |
130 | $defaults = array(); | |
131 | // check if there is a widget already created | |
132 | if ($this->_widget) { | |
133 | CRM_Core_DAO::storeValues($this->_widget, $defaults); | |
134 | } | |
135 | else { | |
136 | foreach ($this->_fields as $name => $val) { | |
137 | $defaults[$name] = $val[3]; | |
138 | } | |
139 | foreach ($this->_colorFields as $name => $val) { | |
140 | $defaults[$name] = $val[3]; | |
141 | } | |
142 | $defaults['about'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', | |
143 | $this->_id, | |
144 | 'intro_text' | |
145 | ); | |
146 | } | |
147 | ||
148 | $showHide = new CRM_Core_ShowHideBlocks(); | |
149 | $showHide->addHide('id-colors'); | |
150 | $showHide->addToTemplate(); | |
151 | return $defaults; | |
152 | } | |
153 | ||
154 | function buildQuickForm() { | |
155 | $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Widget'); | |
156 | ||
157 | $this->addElement('checkbox', | |
158 | 'is_active', | |
159 | ts('Enable Widget?'), | |
160 | NULL, | |
161 | array('onclick' => "widgetBlock(this)") | |
162 | ); | |
163 | ||
164 | $this->addWysiwyg('about', ts('About'), $attributes['about']); | |
165 | ||
166 | foreach ($this->_fields as $name => $val) { | |
167 | $this->add($val[1], | |
168 | $name, | |
169 | $val[0], | |
170 | $attributes[$name], | |
171 | $val[2] | |
172 | ); | |
173 | } | |
174 | foreach ($this->_colorFields as $name => $val) { | |
175 | $this->add($val[1], | |
176 | $name, | |
177 | $val[0], | |
178 | $attributes[$name], | |
179 | $val[2] | |
180 | ); | |
181 | } | |
182 | ||
183 | $this->assign_by_ref('fields', $this->_fields); | |
184 | $this->assign_by_ref('colorFields', $this->_colorFields); | |
185 | ||
186 | $this->_refreshButtonName = $this->getButtonName('refresh'); | |
187 | $this->addElement('submit', | |
188 | $this->_refreshButtonName, | |
189 | ts('Save and Preview') | |
190 | ); | |
191 | parent::buildQuickForm(); | |
192 | $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Widget', 'formRule'), $this); | |
193 | } | |
194 | ||
195 | /** | |
196 | * Function for validation | |
197 | * | |
198 | * @param array $params (ref.) an assoc array of name/value pairs | |
199 | * | |
200 | * @return mixed true or array of errors | |
201 | * @access public | |
202 | * @static | |
203 | */ | |
204 | public static function formRule($params, $files, $self) { | |
205 | $errors = array(); | |
206 | if (CRM_Utils_Array::value('is_active', $params)) { | |
207 | if (!CRM_Utils_Array::value('title', $params)) { | |
208 | $errors['title'] = ts('Title is a required field.'); | |
209 | } | |
210 | if (!CRM_Utils_Array::value('about', $params)) { | |
211 | $errors['about'] = ts('About is a required field.'); | |
212 | } | |
213 | ||
214 | foreach ($params as $key => $val) { | |
215 | if (substr($key, 0, 6) == 'color_' && !CRM_Utils_Array::value($key, $params)) { | |
216 | $errors[$key] = ts('%1 is a required field.', array(1 => $self->_colorFields[$key][0])); | |
217 | } | |
218 | } | |
219 | } | |
220 | return empty($errors) ? TRUE : $errors; | |
221 | } | |
222 | ||
223 | function postProcess() { | |
224 | //to reset quickform elements of next (pcp) page. | |
225 | if ($this->controller->getNextName('Widget') == 'PCP') { | |
226 | $this->controller->resetPage('PCP'); | |
227 | } | |
228 | ||
229 | // get the submitted form values. | |
230 | $params = $this->controller->exportValues($this->_name); | |
231 | ||
232 | if ($this->_widget) { | |
233 | $params['id'] = $this->_widget->id; | |
234 | } | |
235 | $params['contribution_page_id'] = $this->_id; | |
236 | $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); | |
237 | $params['url_homepage'] = 'null'; | |
238 | ||
239 | $widget = new CRM_Contribute_DAO_Widget(); | |
240 | $widget->copyValues($params); | |
241 | $widget->save(); | |
242 | ||
243 | $buttonName = $this->controller->getButtonName(); | |
244 | if ($buttonName == $this->_refreshButtonName) { | |
245 | return; | |
246 | } | |
247 | parent::endPostProcess(); | |
248 | } | |
249 | ||
250 | /** | |
251 | * Return a descriptive name for the page, used in wizard header | |
252 | * | |
253 | * @return string | |
254 | * @access public | |
255 | */ | |
256 | public function getTitle() { | |
257 | return ts('Widget Settings'); | |
258 | } | |
259 | } | |
260 |