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; | |
d75f2f47 | 87 | |
62933949 | 88 | /** |
89 | * Check if repeating event | |
90 | */ | |
91 | protected $_isRepeatingEvent; | |
49f68a22 | 92 | |
6a488035 TO |
93 | /** |
94 | * Function to set variables up before form is built | |
95 | * | |
96 | * @return void | |
97 | * @access public | |
98 | */ | |
99 | function preProcess() { | |
100 | $config = CRM_Core_Config::singleton(); | |
101 | if (in_array('CiviEvent', $config->enableComponents)) { | |
102 | $this->assign('CiviEvent', TRUE); | |
103 | } | |
d75f2f47 | 104 | |
6a488035 TO |
105 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST'); |
106 | ||
107 | $this->assign('action', $this->_action); | |
108 | ||
639b6887 | 109 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET'); |
6a488035 | 110 | if ($this->_id) { |
62933949 | 111 | $this->_isRepeatingEvent = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event'); |
6a488035 | 112 | $this->assign('eventId', $this->_id); |
be84b210 | 113 | if (!empty($this->_addBlockName) && empty($this->_addProfileBottom) && empty($this->_addProfileBottomAdd)) { |
6a488035 TO |
114 | $this->add('hidden', 'id', $this->_id); |
115 | } | |
116 | $this->_single = TRUE; | |
117 | ||
118 | $params = array('id' => $this->_id); | |
119 | CRM_Event_BAO_Event::retrieve($params, $eventInfo); | |
120 | ||
121 | // its an update mode, do a permission check | |
122 | if (!CRM_Event_BAO_Event::checkPermission($this->_id, CRM_Core_Permission::EDIT)) { | |
123 | CRM_Core_Error::fatal(ts('You do not have permission to access this page')); | |
124 | } | |
125 | ||
126 | $participantListingID = CRM_Utils_Array::value('participant_listing_id', $eventInfo); | |
127 | //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' ); | |
128 | if ($participantListingID) { | |
129 | $participantListingURL = CRM_Utils_System::url('civicrm/event/participant', | |
130 | "reset=1&id={$this->_id}", | |
131 | TRUE, NULL, TRUE, TRUE | |
132 | ); | |
133 | $this->assign('participantListingURL', $participantListingURL); | |
134 | } | |
135 | ||
136 | $this->assign('isOnlineRegistration', CRM_Utils_Array::value('is_online_registration', $eventInfo)); | |
137 | ||
138 | $this->assign('id', $this->_id); | |
139 | } | |
140 | ||
141 | // figure out whether we’re handling an event or an event template | |
142 | if ($this->_id) { | |
143 | $this->_isTemplate = CRM_Utils_Array::value('is_template', $eventInfo); | |
144 | } | |
145 | elseif ($this->_action & CRM_Core_Action::ADD) { | |
146 | $this->_isTemplate = CRM_Utils_Request::retrieve('is_template', 'Boolean', $this); | |
147 | } | |
148 | ||
149 | $this->assign('isTemplate', $this->_isTemplate); | |
150 | ||
151 | if ($this->_id) { | |
152 | if ($this->_isTemplate) { | |
153 | $title = CRM_Utils_Array::value('template_title', $eventInfo); | |
154 | CRM_Utils_System::setTitle(ts('Edit Event Template') . " - $title"); | |
155 | } | |
156 | else { | |
62933949 | 157 | $configureText = ts('Configure Event'); |
6a488035 | 158 | $title = CRM_Utils_Array::value('title', $eventInfo); |
62933949 | 159 | //If it is a repeating event change title |
a50a97b8 | 160 | if ($this->_isRepeatingEvent) { |
62933949 | 161 | $configureText = 'Configure Repeating Event'; |
162 | } | |
163 | CRM_Utils_System::setTitle($configureText . " - $title"); | |
6a488035 TO |
164 | } |
165 | $this->assign('title', $title); | |
166 | } | |
167 | elseif ($this->_action & CRM_Core_Action::ADD) { | |
168 | if ($this->_isTemplate) { | |
169 | $title = ts('New Event Template'); | |
170 | CRM_Utils_System::setTitle($title); | |
171 | } | |
172 | else { | |
173 | $title = ts('New Event'); | |
174 | CRM_Utils_System::setTitle($title); | |
175 | } | |
176 | $this->assign('title', $title); | |
177 | } | |
178 | ||
179 | if (CRM_Core_Permission::check('view event participants') && | |
180 | CRM_Core_Permission::check('view all contacts') | |
181 | ) { | |
182 | $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label'); | |
183 | $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label'); | |
184 | $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes)); | |
185 | $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending)); | |
186 | $this->assign('findParticipants', $findParticipants); | |
187 | } | |
188 | ||
189 | $this->_templateId = (int) CRM_Utils_Request::retrieve('template_id', 'Integer', $this); | |
d75f2f47 | 190 | |
62933949 | 191 | //Is a repeating event |
a50a97b8 | 192 | if ($this->_isRepeatingEvent) { |
62933949 | 193 | $isRepeat = 'repeat'; |
194 | $this->assign('isRepeat', $isRepeat); | |
195 | } | |
6a488035 TO |
196 | |
197 | // also set up tabs | |
198 | CRM_Event_Form_ManageEvent_TabHeader::build($this); | |
199 | ||
200 | // Set Done button URL and breadcrumb. Templates go back to Manage Templates, | |
201 | // otherwise go to Manage Event for new event or ManageEventEdit if event if exists. | |
202 | $breadCrumb = array(); | |
203 | if (!$this->_isTemplate) { | |
204 | if ($this->_id) { | |
205 | $this->_doneUrl = CRM_Utils_System::url(CRM_Utils_System::currentPath(), | |
206 | "action=update&reset=1&id={$this->_id}" | |
207 | ); | |
208 | } | |
209 | else { | |
210 | $this->_doneUrl = CRM_Utils_System::url('civicrm/event/manage', | |
211 | 'reset=1' | |
212 | ); | |
213 | $breadCrumb = array(array('title' => ts('Manage Events'), | |
214 | 'url' => $this->_doneUrl, | |
215 | )); | |
216 | } | |
217 | } | |
218 | else { | |
219 | $this->_doneUrl = CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'); | |
220 | $breadCrumb = array(array('title' => ts('Manage Event Templates'), | |
221 | 'url' => $this->_doneUrl, | |
222 | )); | |
223 | } | |
224 | CRM_Utils_System::appendBreadCrumb($breadCrumb); | |
225 | } | |
226 | ||
227 | /** | |
228 | * This function sets the default values for the form. For edit/view mode | |
229 | * the default values are retrieved from the database | |
230 | * | |
231 | * @access public | |
232 | * | |
355ba699 | 233 | * @return void |
6a488035 TO |
234 | */ |
235 | function setDefaultValues() { | |
236 | $defaults = array(); | |
237 | if (isset($this->_id)) { | |
238 | $params = array('id' => $this->_id); | |
239 | CRM_Event_BAO_Event::retrieve($params, $defaults); | |
49f68a22 DL |
240 | |
241 | $this->_campaignID = CRM_Utils_Array::value('campaign_id', $defaults); | |
6a488035 TO |
242 | } |
243 | elseif ($this->_templateId) { | |
244 | $params = array('id' => $this->_templateId); | |
245 | CRM_Event_BAO_Event::retrieve($params, $defaults); | |
246 | $defaults['is_template'] = $this->_isTemplate; | |
247 | $defaults['template_id'] = $defaults['id']; | |
248 | unset($defaults['id']); | |
249 | } | |
250 | else { | |
251 | $defaults['is_active'] = 1; | |
252 | $defaults['style'] = 'Inline'; | |
253 | } | |
254 | ||
255 | return $defaults; | |
256 | } | |
257 | ||
258 | /** | |
259 | * Function to build the form | |
260 | * | |
355ba699 | 261 | * @return void |
6a488035 TO |
262 | * @access public |
263 | */ | |
264 | public function buildQuickForm() { | |
265 | $session = CRM_Core_Session::singleton(); | |
266 | ||
267 | $this->_cancelURL = CRM_Utils_Array::value('cancelURL', $_POST); | |
268 | ||
269 | if (!$this->_cancelURL) { | |
270 | if ($this->_isTemplate) { | |
271 | $this->_cancelURL = CRM_Utils_System::url('civicrm/admin/eventTemplate', | |
272 | 'reset=1' | |
273 | ); | |
274 | } | |
275 | else { | |
276 | $this->_cancelURL = CRM_Utils_System::url('civicrm/event/manage', | |
277 | 'reset=1' | |
278 | ); | |
279 | } | |
280 | } | |
281 | ||
282 | if ($this->_cancelURL) { | |
283 | $this->addElement('hidden', 'cancelURL', $this->_cancelURL); | |
284 | } | |
285 | ||
286 | if ($this->_single) { | |
287 | $buttons = array( | |
288 | array( | |
289 | 'type' => 'upload', | |
290 | 'name' => ts('Save'), | |
291 | 'isDefault' => TRUE, | |
292 | ), | |
293 | array( | |
294 | 'type' => 'upload', | |
295 | 'name' => ts('Save and Done'), | |
296 | 'spacing' => ' ', | |
297 | 'subName' => 'done', | |
298 | ), | |
299 | array( | |
300 | 'type' => 'cancel', | |
301 | 'name' => ts('Cancel'), | |
302 | ), | |
303 | ); | |
304 | $this->addButtons($buttons); | |
305 | } | |
306 | else { | |
307 | $buttons = array(); | |
308 | if (!$this->_first) { | |
309 | $buttons[] = array( | |
310 | 'type' => 'back', | |
311 | 'name' => ts('<< Previous'), | |
312 | 'spacing' => ' ', | |
313 | ); | |
314 | } | |
315 | $buttons[] = array( | |
316 | 'type' => 'upload', | |
317 | 'name' => ts('Continue >>'), | |
318 | 'spacing' => ' ', | |
319 | 'isDefault' => TRUE, | |
320 | ); | |
321 | $buttons[] = array( | |
322 | 'type' => 'cancel', | |
323 | 'name' => ts('Cancel'), | |
324 | ); | |
325 | ||
326 | $this->addButtons($buttons); | |
327 | } | |
328 | $session->replaceUserContext($this->_cancelURL); | |
329 | $this->add('hidden', 'is_template', $this->_isTemplate); | |
330 | } | |
331 | ||
332 | function endPostProcess() { | |
333 | // make submit buttons keep the current working tab opened. | |
334 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
335 | $className = CRM_Utils_String::getClassName($this->_name); | |
336 | ||
337 | // hack for special cases. | |
338 | switch ($className) { | |
339 | case 'Event': | |
340 | $attributes = $this->getVar('_attributes'); | |
341 | $subPage = strtolower(basename(CRM_Utils_Array::value('action', $attributes))); | |
342 | break; | |
343 | ||
344 | case 'EventInfo': | |
345 | $subPage = 'settings'; | |
346 | break; | |
347 | ||
348 | case 'ScheduleReminders': | |
349 | $subPage = 'reminder'; | |
350 | break; | |
351 | ||
352 | default: | |
353 | $subPage = strtolower($className); | |
354 | break; | |
355 | } | |
356 | ||
357 | CRM_Core_Session::setStatus(ts("'%1' information has been saved.", | |
4b628e67 | 358 | array(1 => CRM_Utils_Array::value('title', CRM_Utils_Array::value($subPage, $this->get('tabHeader')), $className)) |
6a488035 TO |
359 | ), ts('Saved'), 'success'); |
360 | ||
49f68a22 DL |
361 | $config = CRM_Core_Config::singleton(); |
362 | if (in_array('CiviCampaign', $config->enableComponents)) { | |
363 | $values = $this->controller->exportValues($this->_name); | |
364 | $newCampaignID = CRM_Utils_Array::value('campaign_id', $values); | |
365 | $eventID = CRM_Utils_Array::value('id', $values); | |
366 | if ($eventID && $this->_campaignID != $newCampaignID) { | |
367 | CRM_Event_BAO_Event::updateParticipantCampaignID($eventID, $newCampaignID); | |
368 | } | |
369 | } | |
d06bcfa8 | 370 | $this->postProcessHook(); |
6a488035 TO |
371 | if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_done") { |
372 | if ($this->_isTemplate) { | |
4b628e67 | 373 | CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1')); |
6a488035 TO |
374 | } |
375 | else { | |
4b628e67 | 376 | CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/event/manage', 'reset=1')); |
6a488035 TO |
377 | } |
378 | } | |
379 | else { | |
4b628e67 | 380 | CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url("civicrm/event/manage/{$subPage}", |
6a488035 TO |
381 | "action=update&reset=1&id={$this->_id}" |
382 | )); | |
383 | } | |
384 | } | |
385 | } | |
386 | ||
0cf587a7 EM |
387 | /** |
388 | * @return string | |
389 | */ | |
6a488035 | 390 | function getTemplateFileName() { |
cc4f2812 | 391 | if ($this->controller->getPrint() || $this->getVar('_id') <= 0 || $this->_action & CRM_Core_Action::DELETE) { |
6a488035 TO |
392 | return parent::getTemplateFileName(); |
393 | } | |
394 | else { | |
395 | // hack lets suppress the form rendering for now | |
396 | self::$_template->assign('isForm', FALSE); | |
397 | return 'CRM/Event/Form/ManageEvent/Tab.tpl'; | |
398 | } | |
399 | } | |
bfd83a87 CW |
400 | |
401 | /** | |
402 | * Pre-load libraries required by Online Registration Profile fields | |
403 | */ | |
404 | static function addProfileEditScripts() { | |
405 | CRM_UF_Page_ProfileEditor::registerProfileScripts(); | |
406 | CRM_UF_Page_ProfileEditor::registerSchemas(array('IndividualModel', 'ParticipantModel')); | |
407 | } | |
6a488035 TO |
408 | } |
409 |