Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
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 | /** | |
66f9e52b | 43 | * The id of the event we are proceessing. |
6a488035 TO |
44 | * |
45 | * @var int | |
6a488035 TO |
46 | */ |
47 | public $_id; | |
48 | ||
49 | /** | |
100fef9d | 50 | * Is this the first page? |
6a488035 TO |
51 | * |
52 | * @var boolean | |
6a488035 TO |
53 | */ |
54 | protected $_first = FALSE; | |
55 | ||
56 | /** | |
100fef9d | 57 | * Are we in single form mode or wizard mode? |
6a488035 TO |
58 | * |
59 | * @var boolean | |
6a488035 TO |
60 | */ |
61 | protected $_single; | |
62 | ||
63 | protected $_action; | |
64 | ||
65 | /** | |
100fef9d | 66 | * Are we actually managing an event template? |
6a488035 TO |
67 | * @var boolean |
68 | */ | |
69 | protected $_isTemplate = FALSE; | |
70 | ||
71 | /** | |
100fef9d | 72 | * Pre-populate fields based on this template event_id |
6a488035 TO |
73 | * @var integer |
74 | */ | |
75 | protected $_templateId; | |
76 | ||
77 | protected $_cancelURL = NULL; | |
78 | ||
49f68a22 DL |
79 | /** |
80 | * The campaign id of the existing event, we use this to know if we need to update | |
81 | * the participant records | |
82 | */ | |
83 | protected $_campaignID = NULL; | |
59d63f8b | 84 | |
62933949 | 85 | /** |
66f9e52b | 86 | * Check if repeating event. |
62933949 | 87 | */ |
c65ce939 | 88 | public $_isRepeatingEvent; |
4d18d9a1 | 89 | |
4a44fd8a TM |
90 | /** |
91 | * Explicitly declare the entity api name. | |
92 | */ | |
6e62b28c TM |
93 | public function getDefaultEntity() { |
94 | return 'Event'; | |
95 | } | |
49f68a22 | 96 | |
055e4167 TM |
97 | /** |
98 | * Explicitly declare the form context. | |
99 | */ | |
100 | public function getDefaultContext() { | |
101 | return 'create'; | |
102 | } | |
103 | ||
6a488035 | 104 | /** |
66f9e52b | 105 | * Set variables up before form is built. |
6a488035 TO |
106 | * |
107 | * @return void | |
6a488035 | 108 | */ |
00be9182 | 109 | public function preProcess() { |
6a488035 TO |
110 | $config = CRM_Core_Config::singleton(); |
111 | if (in_array('CiviEvent', $config->enableComponents)) { | |
112 | $this->assign('CiviEvent', TRUE); | |
113 | } | |
b1e18356 | 114 | CRM_Core_Form_RecurringEntity::preProcess('civicrm_event'); |
59d63f8b | 115 | |
6a488035 TO |
116 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST'); |
117 | ||
118 | $this->assign('action', $this->_action); | |
119 | ||
639b6887 | 120 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET'); |
6a488035 | 121 | if ($this->_id) { |
62933949 | 122 | $this->_isRepeatingEvent = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event'); |
6a488035 | 123 | $this->assign('eventId', $this->_id); |
be84b210 | 124 | if (!empty($this->_addBlockName) && empty($this->_addProfileBottom) && empty($this->_addProfileBottomAdd)) { |
6a488035 TO |
125 | $this->add('hidden', 'id', $this->_id); |
126 | } | |
127 | $this->_single = TRUE; | |
128 | ||
129 | $params = array('id' => $this->_id); | |
130 | CRM_Event_BAO_Event::retrieve($params, $eventInfo); | |
131 | ||
132 | // its an update mode, do a permission check | |
133 | if (!CRM_Event_BAO_Event::checkPermission($this->_id, CRM_Core_Permission::EDIT)) { | |
0499b0ad | 134 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
6a488035 TO |
135 | } |
136 | ||
137 | $participantListingID = CRM_Utils_Array::value('participant_listing_id', $eventInfo); | |
138 | //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' ); | |
139 | if ($participantListingID) { | |
140 | $participantListingURL = CRM_Utils_System::url('civicrm/event/participant', | |
141 | "reset=1&id={$this->_id}", | |
142 | TRUE, NULL, TRUE, TRUE | |
143 | ); | |
144 | $this->assign('participantListingURL', $participantListingURL); | |
145 | } | |
146 | ||
147 | $this->assign('isOnlineRegistration', CRM_Utils_Array::value('is_online_registration', $eventInfo)); | |
148 | ||
149 | $this->assign('id', $this->_id); | |
150 | } | |
151 | ||
152 | // figure out whether we’re handling an event or an event template | |
153 | if ($this->_id) { | |
154 | $this->_isTemplate = CRM_Utils_Array::value('is_template', $eventInfo); | |
155 | } | |
156 | elseif ($this->_action & CRM_Core_Action::ADD) { | |
157 | $this->_isTemplate = CRM_Utils_Request::retrieve('is_template', 'Boolean', $this); | |
158 | } | |
159 | ||
160 | $this->assign('isTemplate', $this->_isTemplate); | |
161 | ||
162 | if ($this->_id) { | |
163 | if ($this->_isTemplate) { | |
164 | $title = CRM_Utils_Array::value('template_title', $eventInfo); | |
165 | CRM_Utils_System::setTitle(ts('Edit Event Template') . " - $title"); | |
166 | } | |
167 | else { | |
62933949 | 168 | $configureText = ts('Configure Event'); |
6a488035 | 169 | $title = CRM_Utils_Array::value('title', $eventInfo); |
62933949 | 170 | //If it is a repeating event change title |
a50a97b8 | 171 | if ($this->_isRepeatingEvent) { |
62933949 | 172 | $configureText = 'Configure Repeating Event'; |
173 | } | |
174 | CRM_Utils_System::setTitle($configureText . " - $title"); | |
6a488035 TO |
175 | } |
176 | $this->assign('title', $title); | |
177 | } | |
178 | elseif ($this->_action & CRM_Core_Action::ADD) { | |
179 | if ($this->_isTemplate) { | |
180 | $title = ts('New Event Template'); | |
181 | CRM_Utils_System::setTitle($title); | |
182 | } | |
183 | else { | |
184 | $title = ts('New Event'); | |
185 | CRM_Utils_System::setTitle($title); | |
186 | } | |
187 | $this->assign('title', $title); | |
188 | } | |
189 | ||
190 | if (CRM_Core_Permission::check('view event participants') && | |
191 | CRM_Core_Permission::check('view all contacts') | |
192 | ) { | |
193 | $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label'); | |
194 | $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label'); | |
195 | $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes)); | |
196 | $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending)); | |
197 | $this->assign('findParticipants', $findParticipants); | |
198 | } | |
199 | ||
200 | $this->_templateId = (int) CRM_Utils_Request::retrieve('template_id', 'Integer', $this); | |
59d63f8b | 201 | |
62933949 | 202 | //Is a repeating event |
a50a97b8 | 203 | if ($this->_isRepeatingEvent) { |
6266861e | 204 | $isRepeatingEntity = TRUE; |
205 | $this->assign('isRepeatingEntity', $isRepeatingEntity); | |
62933949 | 206 | } |
6a488035 | 207 | |
e4fa553b | 208 | // CRM-16776 - show edit/copy/create buttons for Profiles if user has required permission. |
209 | $ufGroups = CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id'); | |
210 | $ufCreate = CRM_ACL_API::group(CRM_Core_Permission::CREATE, NULL, 'civicrm_uf_group', $ufGroups); | |
211 | $ufEdit = CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', $ufGroups); | |
212 | $checkPermission = array( | |
213 | array( | |
214 | 'administer CiviCRM', | |
215 | 'manage event profiles', | |
216 | ), | |
217 | ); | |
218 | if (CRM_Core_Permission::check($checkPermission) || !empty($ufCreate) || !empty($ufEdit)) { | |
219 | $this->assign('perm', TRUE); | |
220 | } | |
221 | ||
6a488035 TO |
222 | // also set up tabs |
223 | CRM_Event_Form_ManageEvent_TabHeader::build($this); | |
224 | ||
225 | // Set Done button URL and breadcrumb. Templates go back to Manage Templates, | |
226 | // otherwise go to Manage Event for new event or ManageEventEdit if event if exists. | |
227 | $breadCrumb = array(); | |
228 | if (!$this->_isTemplate) { | |
229 | if ($this->_id) { | |
230 | $this->_doneUrl = CRM_Utils_System::url(CRM_Utils_System::currentPath(), | |
231 | "action=update&reset=1&id={$this->_id}" | |
232 | ); | |
233 | } | |
234 | else { | |
235 | $this->_doneUrl = CRM_Utils_System::url('civicrm/event/manage', | |
236 | 'reset=1' | |
237 | ); | |
353ffa53 TO |
238 | $breadCrumb = array( |
239 | array( | |
240 | 'title' => ts('Manage Events'), | |
6a488035 | 241 | 'url' => $this->_doneUrl, |
389bcebf | 242 | ), |
353ffa53 | 243 | ); |
6a488035 TO |
244 | } |
245 | } | |
246 | else { | |
247 | $this->_doneUrl = CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'); | |
353ffa53 TO |
248 | $breadCrumb = array( |
249 | array( | |
250 | 'title' => ts('Manage Event Templates'), | |
6a488035 | 251 | 'url' => $this->_doneUrl, |
389bcebf | 252 | ), |
353ffa53 | 253 | ); |
6a488035 TO |
254 | } |
255 | CRM_Utils_System::appendBreadCrumb($breadCrumb); | |
256 | } | |
257 | ||
258 | /** | |
c490a46a | 259 | * Set default values for the form. For edit/view mode |
6a488035 TO |
260 | * the default values are retrieved from the database |
261 | * | |
6a488035 | 262 | * |
355ba699 | 263 | * @return void |
6a488035 | 264 | */ |
00be9182 | 265 | public function setDefaultValues() { |
6a488035 TO |
266 | $defaults = array(); |
267 | if (isset($this->_id)) { | |
268 | $params = array('id' => $this->_id); | |
269 | CRM_Event_BAO_Event::retrieve($params, $defaults); | |
49f68a22 DL |
270 | |
271 | $this->_campaignID = CRM_Utils_Array::value('campaign_id', $defaults); | |
6a488035 TO |
272 | } |
273 | elseif ($this->_templateId) { | |
274 | $params = array('id' => $this->_templateId); | |
275 | CRM_Event_BAO_Event::retrieve($params, $defaults); | |
276 | $defaults['is_template'] = $this->_isTemplate; | |
277 | $defaults['template_id'] = $defaults['id']; | |
278 | unset($defaults['id']); | |
279 | } | |
280 | else { | |
281 | $defaults['is_active'] = 1; | |
282 | $defaults['style'] = 'Inline'; | |
283 | } | |
284 | ||
285 | return $defaults; | |
286 | } | |
287 | ||
288 | /** | |
66f9e52b | 289 | * Build the form object. |
6a488035 | 290 | * |
355ba699 | 291 | * @return void |
6a488035 TO |
292 | */ |
293 | public function buildQuickForm() { | |
294 | $session = CRM_Core_Session::singleton(); | |
295 | ||
296 | $this->_cancelURL = CRM_Utils_Array::value('cancelURL', $_POST); | |
297 | ||
298 | if (!$this->_cancelURL) { | |
299 | if ($this->_isTemplate) { | |
300 | $this->_cancelURL = CRM_Utils_System::url('civicrm/admin/eventTemplate', | |
301 | 'reset=1' | |
302 | ); | |
303 | } | |
304 | else { | |
305 | $this->_cancelURL = CRM_Utils_System::url('civicrm/event/manage', | |
306 | 'reset=1' | |
307 | ); | |
308 | } | |
309 | } | |
310 | ||
311 | if ($this->_cancelURL) { | |
312 | $this->addElement('hidden', 'cancelURL', $this->_cancelURL); | |
313 | } | |
314 | ||
315 | if ($this->_single) { | |
316 | $buttons = array( | |
317 | array( | |
318 | 'type' => 'upload', | |
319 | 'name' => ts('Save'), | |
320 | 'isDefault' => TRUE, | |
321 | ), | |
322 | array( | |
323 | 'type' => 'upload', | |
324 | 'name' => ts('Save and Done'), | |
325 | 'spacing' => ' ', | |
326 | 'subName' => 'done', | |
327 | ), | |
328 | array( | |
329 | 'type' => 'cancel', | |
330 | 'name' => ts('Cancel'), | |
331 | ), | |
332 | ); | |
333 | $this->addButtons($buttons); | |
334 | } | |
335 | else { | |
336 | $buttons = array(); | |
337 | if (!$this->_first) { | |
338 | $buttons[] = array( | |
339 | 'type' => 'back', | |
f212d37d | 340 | 'name' => ts('Previous'), |
6a488035 TO |
341 | 'spacing' => ' ', |
342 | ); | |
343 | } | |
344 | $buttons[] = array( | |
345 | 'type' => 'upload', | |
f212d37d | 346 | 'name' => ts('Continue'), |
6a488035 TO |
347 | 'spacing' => ' ', |
348 | 'isDefault' => TRUE, | |
349 | ); | |
350 | $buttons[] = array( | |
351 | 'type' => 'cancel', | |
352 | 'name' => ts('Cancel'), | |
353 | ); | |
354 | ||
355 | $this->addButtons($buttons); | |
356 | } | |
357 | $session->replaceUserContext($this->_cancelURL); | |
358 | $this->add('hidden', 'is_template', $this->_isTemplate); | |
359 | } | |
360 | ||
00be9182 | 361 | public function endPostProcess() { |
6a488035 TO |
362 | // make submit buttons keep the current working tab opened. |
363 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
364 | $className = CRM_Utils_String::getClassName($this->_name); | |
365 | ||
366 | // hack for special cases. | |
367 | switch ($className) { | |
368 | case 'Event': | |
369 | $attributes = $this->getVar('_attributes'); | |
370 | $subPage = strtolower(basename(CRM_Utils_Array::value('action', $attributes))); | |
371 | break; | |
372 | ||
373 | case 'EventInfo': | |
374 | $subPage = 'settings'; | |
375 | break; | |
376 | ||
377 | case 'ScheduleReminders': | |
378 | $subPage = 'reminder'; | |
379 | break; | |
380 | ||
381 | default: | |
382 | $subPage = strtolower($className); | |
383 | break; | |
384 | } | |
385 | ||
386 | CRM_Core_Session::setStatus(ts("'%1' information has been saved.", | |
353ffa53 TO |
387 | array(1 => CRM_Utils_Array::value('title', CRM_Utils_Array::value($subPage, $this->get('tabHeader')), $className)) |
388 | ), ts('Saved'), 'success'); | |
6a488035 | 389 | |
49f68a22 DL |
390 | $config = CRM_Core_Config::singleton(); |
391 | if (in_array('CiviCampaign', $config->enableComponents)) { | |
392 | $values = $this->controller->exportValues($this->_name); | |
393 | $newCampaignID = CRM_Utils_Array::value('campaign_id', $values); | |
394 | $eventID = CRM_Utils_Array::value('id', $values); | |
395 | if ($eventID && $this->_campaignID != $newCampaignID) { | |
396 | CRM_Event_BAO_Event::updateParticipantCampaignID($eventID, $newCampaignID); | |
397 | } | |
398 | } | |
d06bcfa8 | 399 | $this->postProcessHook(); |
6a488035 TO |
400 | if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_done") { |
401 | if ($this->_isTemplate) { | |
353ffa53 TO |
402 | CRM_Core_Session::singleton() |
403 | ->pushUserContext(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1')); | |
6a488035 TO |
404 | } |
405 | else { | |
4b628e67 | 406 | CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/event/manage', 'reset=1')); |
6a488035 TO |
407 | } |
408 | } | |
409 | else { | |
4b628e67 | 410 | CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url("civicrm/event/manage/{$subPage}", |
353ffa53 TO |
411 | "action=update&reset=1&id={$this->_id}" |
412 | )); | |
6a488035 TO |
413 | } |
414 | } | |
415 | } | |
416 | ||
0cf587a7 EM |
417 | /** |
418 | * @return string | |
419 | */ | |
00be9182 | 420 | public function getTemplateFileName() { |
cc4f2812 | 421 | if ($this->controller->getPrint() || $this->getVar('_id') <= 0 || $this->_action & CRM_Core_Action::DELETE) { |
6a488035 TO |
422 | return parent::getTemplateFileName(); |
423 | } | |
424 | else { | |
425 | // hack lets suppress the form rendering for now | |
426 | self::$_template->assign('isForm', FALSE); | |
427 | return 'CRM/Event/Form/ManageEvent/Tab.tpl'; | |
428 | } | |
429 | } | |
bfd83a87 CW |
430 | |
431 | /** | |
432 | * Pre-load libraries required by Online Registration Profile fields | |
433 | */ | |
00be9182 | 434 | public static function addProfileEditScripts() { |
bfd83a87 CW |
435 | CRM_UF_Page_ProfileEditor::registerProfileScripts(); |
436 | CRM_UF_Page_ProfileEditor::registerSchemas(array('IndividualModel', 'ParticipantModel')); | |
437 | } | |
96025800 | 438 | |
6a488035 | 439 | } |