Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for processing Event | |
38 | * | |
39 | */ | |
40 | class CRM_Event_Form_ManageEvent extends CRM_Core_Form { | |
41 | ||
42 | /** | |
43 | * the id of the event we are proceessing | |
44 | * | |
45 | * @var int | |
46 | * @protected | |
47 | */ | |
48 | public $_id; | |
49 | ||
50 | /** | |
51 | * is this the first page? | |
52 | * | |
53 | * @var boolean | |
54 | * @access protected | |
55 | */ | |
56 | protected $_first = FALSE; | |
57 | ||
58 | /** | |
59 | * are we in single form mode or wizard mode? | |
60 | * | |
61 | * @var boolean | |
62 | * @access protected | |
63 | */ | |
64 | protected $_single; | |
65 | ||
66 | protected $_action; | |
67 | ||
68 | /** | |
69 | * are we actually managing an event template? | |
70 | * @var boolean | |
71 | */ | |
72 | protected $_isTemplate = FALSE; | |
73 | ||
74 | /** | |
75 | * pre-populate fields based on this template event_id | |
76 | * @var integer | |
77 | */ | |
78 | protected $_templateId; | |
79 | ||
80 | protected $_cancelURL = NULL; | |
81 | ||
49f68a22 DL |
82 | /** |
83 | * The campaign id of the existing event, we use this to know if we need to update | |
84 | * the participant records | |
85 | */ | |
86 | protected $_campaignID = NULL; | |
87 | ||
6a488035 TO |
88 | /** |
89 | * Function to set variables up before form is built | |
90 | * | |
91 | * @return void | |
92 | * @access public | |
93 | */ | |
94 | function preProcess() { | |
95 | $config = CRM_Core_Config::singleton(); | |
96 | if (in_array('CiviEvent', $config->enableComponents)) { | |
97 | $this->assign('CiviEvent', TRUE); | |
98 | } | |
99 | ||
100 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST'); | |
101 | ||
102 | $this->assign('action', $this->_action); | |
103 | ||
639b6887 | 104 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET'); |
6a488035 TO |
105 | if ($this->_id) { |
106 | $this->assign('eventId', $this->_id); | |
107 | if (empty($this->_addProfileBottom) && empty($this->_addProfileBottomAdd)) { | |
108 | $this->add('hidden', 'id', $this->_id); | |
109 | } | |
110 | $this->_single = TRUE; | |
111 | ||
112 | $params = array('id' => $this->_id); | |
113 | CRM_Event_BAO_Event::retrieve($params, $eventInfo); | |
114 | ||
115 | // its an update mode, do a permission check | |
116 | if (!CRM_Event_BAO_Event::checkPermission($this->_id, CRM_Core_Permission::EDIT)) { | |
117 | CRM_Core_Error::fatal(ts('You do not have permission to access this page')); | |
118 | } | |
119 | ||
120 | $participantListingID = CRM_Utils_Array::value('participant_listing_id', $eventInfo); | |
121 | //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' ); | |
122 | if ($participantListingID) { | |
123 | $participantListingURL = CRM_Utils_System::url('civicrm/event/participant', | |
124 | "reset=1&id={$this->_id}", | |
125 | TRUE, NULL, TRUE, TRUE | |
126 | ); | |
127 | $this->assign('participantListingURL', $participantListingURL); | |
128 | } | |
129 | ||
130 | $this->assign('isOnlineRegistration', CRM_Utils_Array::value('is_online_registration', $eventInfo)); | |
131 | ||
132 | $this->assign('id', $this->_id); | |
133 | } | |
134 | ||
135 | // figure out whether we’re handling an event or an event template | |
136 | if ($this->_id) { | |
137 | $this->_isTemplate = CRM_Utils_Array::value('is_template', $eventInfo); | |
138 | } | |
139 | elseif ($this->_action & CRM_Core_Action::ADD) { | |
140 | $this->_isTemplate = CRM_Utils_Request::retrieve('is_template', 'Boolean', $this); | |
141 | } | |
142 | ||
143 | $this->assign('isTemplate', $this->_isTemplate); | |
144 | ||
145 | if ($this->_id) { | |
146 | if ($this->_isTemplate) { | |
147 | $title = CRM_Utils_Array::value('template_title', $eventInfo); | |
148 | CRM_Utils_System::setTitle(ts('Edit Event Template') . " - $title"); | |
149 | } | |
150 | else { | |
151 | $title = CRM_Utils_Array::value('title', $eventInfo); | |
152 | CRM_Utils_System::setTitle(ts('Configure Event') . " - $title"); | |
153 | } | |
154 | $this->assign('title', $title); | |
155 | } | |
156 | elseif ($this->_action & CRM_Core_Action::ADD) { | |
157 | if ($this->_isTemplate) { | |
158 | $title = ts('New Event Template'); | |
159 | CRM_Utils_System::setTitle($title); | |
160 | } | |
161 | else { | |
162 | $title = ts('New Event'); | |
163 | CRM_Utils_System::setTitle($title); | |
164 | } | |
165 | $this->assign('title', $title); | |
166 | } | |
167 | ||
168 | if (CRM_Core_Permission::check('view event participants') && | |
169 | CRM_Core_Permission::check('view all contacts') | |
170 | ) { | |
171 | $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label'); | |
172 | $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label'); | |
173 | $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes)); | |
174 | $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending)); | |
175 | $this->assign('findParticipants', $findParticipants); | |
176 | } | |
177 | ||
178 | $this->_templateId = (int) CRM_Utils_Request::retrieve('template_id', 'Integer', $this); | |
179 | ||
180 | // also set up tabs | |
181 | CRM_Event_Form_ManageEvent_TabHeader::build($this); | |
182 | ||
183 | // Set Done button URL and breadcrumb. Templates go back to Manage Templates, | |
184 | // otherwise go to Manage Event for new event or ManageEventEdit if event if exists. | |
185 | $breadCrumb = array(); | |
186 | if (!$this->_isTemplate) { | |
187 | if ($this->_id) { | |
188 | $this->_doneUrl = CRM_Utils_System::url(CRM_Utils_System::currentPath(), | |
189 | "action=update&reset=1&id={$this->_id}" | |
190 | ); | |
191 | } | |
192 | else { | |
193 | $this->_doneUrl = CRM_Utils_System::url('civicrm/event/manage', | |
194 | 'reset=1' | |
195 | ); | |
196 | $breadCrumb = array(array('title' => ts('Manage Events'), | |
197 | 'url' => $this->_doneUrl, | |
198 | )); | |
199 | } | |
200 | } | |
201 | else { | |
202 | $this->_doneUrl = CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'); | |
203 | $breadCrumb = array(array('title' => ts('Manage Event Templates'), | |
204 | 'url' => $this->_doneUrl, | |
205 | )); | |
206 | } | |
207 | CRM_Utils_System::appendBreadCrumb($breadCrumb); | |
208 | } | |
209 | ||
210 | /** | |
211 | * This function sets the default values for the form. For edit/view mode | |
212 | * the default values are retrieved from the database | |
213 | * | |
214 | * @access public | |
215 | * | |
355ba699 | 216 | * @return void |
6a488035 TO |
217 | */ |
218 | function setDefaultValues() { | |
219 | $defaults = array(); | |
220 | if (isset($this->_id)) { | |
221 | $params = array('id' => $this->_id); | |
222 | CRM_Event_BAO_Event::retrieve($params, $defaults); | |
49f68a22 DL |
223 | |
224 | $this->_campaignID = CRM_Utils_Array::value('campaign_id', $defaults); | |
6a488035 TO |
225 | } |
226 | elseif ($this->_templateId) { | |
227 | $params = array('id' => $this->_templateId); | |
228 | CRM_Event_BAO_Event::retrieve($params, $defaults); | |
229 | $defaults['is_template'] = $this->_isTemplate; | |
230 | $defaults['template_id'] = $defaults['id']; | |
231 | unset($defaults['id']); | |
232 | } | |
233 | else { | |
234 | $defaults['is_active'] = 1; | |
235 | $defaults['style'] = 'Inline'; | |
236 | } | |
237 | ||
238 | return $defaults; | |
239 | } | |
240 | ||
241 | /** | |
242 | * Function to build the form | |
243 | * | |
355ba699 | 244 | * @return void |
6a488035 TO |
245 | * @access public |
246 | */ | |
247 | public function buildQuickForm() { | |
248 | $session = CRM_Core_Session::singleton(); | |
249 | ||
250 | $this->_cancelURL = CRM_Utils_Array::value('cancelURL', $_POST); | |
251 | ||
252 | if (!$this->_cancelURL) { | |
253 | if ($this->_isTemplate) { | |
254 | $this->_cancelURL = CRM_Utils_System::url('civicrm/admin/eventTemplate', | |
255 | 'reset=1' | |
256 | ); | |
257 | } | |
258 | else { | |
259 | $this->_cancelURL = CRM_Utils_System::url('civicrm/event/manage', | |
260 | 'reset=1' | |
261 | ); | |
262 | } | |
263 | } | |
264 | ||
265 | if ($this->_cancelURL) { | |
266 | $this->addElement('hidden', 'cancelURL', $this->_cancelURL); | |
267 | } | |
268 | ||
269 | if ($this->_single) { | |
270 | $buttons = array( | |
271 | array( | |
272 | 'type' => 'upload', | |
273 | 'name' => ts('Save'), | |
274 | 'isDefault' => TRUE, | |
275 | ), | |
276 | array( | |
277 | 'type' => 'upload', | |
278 | 'name' => ts('Save and Done'), | |
279 | 'spacing' => ' ', | |
280 | 'subName' => 'done', | |
281 | ), | |
282 | array( | |
283 | 'type' => 'cancel', | |
284 | 'name' => ts('Cancel'), | |
285 | ), | |
286 | ); | |
287 | $this->addButtons($buttons); | |
288 | } | |
289 | else { | |
290 | $buttons = array(); | |
291 | if (!$this->_first) { | |
292 | $buttons[] = array( | |
293 | 'type' => 'back', | |
294 | 'name' => ts('<< Previous'), | |
295 | 'spacing' => ' ', | |
296 | ); | |
297 | } | |
298 | $buttons[] = array( | |
299 | 'type' => 'upload', | |
300 | 'name' => ts('Continue >>'), | |
301 | 'spacing' => ' ', | |
302 | 'isDefault' => TRUE, | |
303 | ); | |
304 | $buttons[] = array( | |
305 | 'type' => 'cancel', | |
306 | 'name' => ts('Cancel'), | |
307 | ); | |
308 | ||
309 | $this->addButtons($buttons); | |
310 | } | |
311 | $session->replaceUserContext($this->_cancelURL); | |
312 | $this->add('hidden', 'is_template', $this->_isTemplate); | |
313 | } | |
314 | ||
315 | function endPostProcess() { | |
316 | // make submit buttons keep the current working tab opened. | |
317 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
318 | $className = CRM_Utils_String::getClassName($this->_name); | |
319 | ||
320 | // hack for special cases. | |
321 | switch ($className) { | |
322 | case 'Event': | |
323 | $attributes = $this->getVar('_attributes'); | |
324 | $subPage = strtolower(basename(CRM_Utils_Array::value('action', $attributes))); | |
325 | break; | |
326 | ||
327 | case 'EventInfo': | |
328 | $subPage = 'settings'; | |
329 | break; | |
330 | ||
331 | case 'ScheduleReminders': | |
332 | $subPage = 'reminder'; | |
333 | break; | |
334 | ||
335 | default: | |
336 | $subPage = strtolower($className); | |
337 | break; | |
338 | } | |
339 | ||
340 | CRM_Core_Session::setStatus(ts("'%1' information has been saved.", | |
4b628e67 | 341 | array(1 => CRM_Utils_Array::value('title', CRM_Utils_Array::value($subPage, $this->get('tabHeader')), $className)) |
6a488035 TO |
342 | ), ts('Saved'), 'success'); |
343 | ||
49f68a22 DL |
344 | $config = CRM_Core_Config::singleton(); |
345 | if (in_array('CiviCampaign', $config->enableComponents)) { | |
346 | $values = $this->controller->exportValues($this->_name); | |
347 | $newCampaignID = CRM_Utils_Array::value('campaign_id', $values); | |
348 | $eventID = CRM_Utils_Array::value('id', $values); | |
349 | if ($eventID && $this->_campaignID != $newCampaignID) { | |
350 | CRM_Event_BAO_Event::updateParticipantCampaignID($eventID, $newCampaignID); | |
351 | } | |
352 | } | |
d06bcfa8 | 353 | $this->postProcessHook(); |
6a488035 TO |
354 | if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_done") { |
355 | if ($this->_isTemplate) { | |
4b628e67 | 356 | CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1')); |
6a488035 TO |
357 | } |
358 | else { | |
4b628e67 | 359 | CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/event/manage', 'reset=1')); |
6a488035 TO |
360 | } |
361 | } | |
362 | else { | |
4b628e67 | 363 | CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url("civicrm/event/manage/{$subPage}", |
6a488035 TO |
364 | "action=update&reset=1&id={$this->_id}" |
365 | )); | |
366 | } | |
367 | } | |
368 | } | |
369 | ||
370 | function getTemplateFileName() { | |
cc4f2812 | 371 | if ($this->controller->getPrint() || $this->getVar('_id') <= 0 || $this->_action & CRM_Core_Action::DELETE) { |
6a488035 TO |
372 | return parent::getTemplateFileName(); |
373 | } | |
374 | else { | |
375 | // hack lets suppress the form rendering for now | |
376 | self::$_template->assign('isForm', FALSE); | |
377 | return 'CRM/Event/Form/ManageEvent/Tab.tpl'; | |
378 | } | |
379 | } | |
380 | } | |
381 |