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