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