3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
14 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 * This class generates form components for processing Event.
20 class CRM_Event_Form_ManageEvent
extends CRM_Core_Form
{
23 * The id of the event we are processing.
30 * Is this the first page?
34 protected $_first = FALSE;
37 * Are we in single form mode or wizard mode?
46 * Are we actually managing an event template?
49 protected $_isTemplate = FALSE;
52 * Pre-populate fields based on this template event_id.
56 protected $_templateId;
58 protected $_cancelURL = NULL;
61 * The campaign id of the existing event, we use this to know if we need to update
62 * the participant records
65 protected $_campaignID = NULL;
68 * Check if repeating event.
71 public $_isRepeatingEvent;
74 * Explicitly declare the entity api name.
76 public function getDefaultEntity() {
81 * Explicitly declare the form context.
83 public function getDefaultContext() {
88 * Set variables up before form is built.
90 public function preProcess() {
91 $this->assign('CiviEvent', CRM_Core_Component
::isEnabled('CiviEvent'));
92 CRM_Core_Form_RecurringEntity
::preProcess('civicrm_event');
94 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
96 $this->assign('action', $this->_action
);
98 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
100 $this->_isRepeatingEvent
= CRM_Core_BAO_RecurringEntity
::getParentFor($this->_id
, 'civicrm_event');
101 $this->assign('eventId', $this->_id
);
102 if (!empty($this->_addBlockName
) && empty($this->_addProfileBottom
) && empty($this->_addProfileBottomAdd
)) {
103 $this->add('hidden', 'id', $this->_id
);
105 $this->_single
= TRUE;
107 $params = ['id' => $this->_id
];
108 CRM_Event_BAO_Event
::retrieve($params, $eventInfo);
110 // its an update mode, do a permission check
111 if (!CRM_Event_BAO_Event
::checkPermission($this->_id
, CRM_Core_Permission
::EDIT
)) {
112 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
115 $participantListingID = $eventInfo['participant_listing_id'] ??
NULL;
116 //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' );
117 if ($participantListingID) {
118 $participantListingURL = CRM_Utils_System
::url('civicrm/event/participant',
119 "reset=1&id={$this->_id}",
120 TRUE, NULL, TRUE, TRUE
122 $this->assign('participantListingURL', $participantListingURL);
125 $this->assign('isOnlineRegistration', CRM_Utils_Array
::value('is_online_registration', $eventInfo));
127 $this->assign('id', $this->_id
);
130 // figure out whether we’re handling an event or an event template
132 $this->_isTemplate
= $eventInfo['is_template'] ??
NULL;
134 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
135 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
138 $this->assign('isTemplate', $this->_isTemplate
);
140 // Set "Manage Event" Title
143 if ($this->_isTemplate
) {
144 $title = ts('Edit Event Template') . ' - ' . CRM_Utils_Array
::value('template_title', $eventInfo);
147 $configureText = $this->_isRepeatingEvent ?
ts('Configure Repeating Event') : ts('Configure Event');
148 $title = $configureText . ' - ' . CRM_Utils_Array
::value('title', $eventInfo);
151 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
152 $title = $this->_isTemplate ?
ts('New Event Template') : ts('New Event');
154 $this->setTitle($title);
156 if (CRM_Core_Permission
::check('view event participants') &&
157 CRM_Core_Permission
::check('view all contacts')
159 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
160 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
161 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
162 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
163 $this->assign('findParticipants', $findParticipants);
166 $this->_templateId
= (int) CRM_Utils_Request
::retrieve('template_id', 'Integer', $this);
168 //Is a repeating event
169 if ($this->_isRepeatingEvent
) {
170 $isRepeatingEntity = TRUE;
171 $this->assign('isRepeatingEntity', $isRepeatingEntity);
174 // CRM-16776 - show edit/copy/create buttons for Profiles if user has required permission.
175 $ufGroups = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_UFField', 'uf_group_id');
176 $ufCreate = CRM_ACL_API
::group(CRM_Core_Permission
::CREATE
, NULL, 'civicrm_uf_group', $ufGroups);
177 $ufEdit = CRM_ACL_API
::group(CRM_Core_Permission
::EDIT
, NULL, 'civicrm_uf_group', $ufGroups);
180 'administer CiviCRM data',
181 'manage event profiles',
184 if (CRM_Core_Permission
::check($checkPermission) ||
!empty($ufCreate) ||
!empty($ufEdit)) {
185 $this->assign('perm', TRUE);
189 CRM_Event_Form_ManageEvent_TabHeader
::build($this);
191 // Set Done button URL and breadcrumb. Templates go back to Manage Templates,
192 // otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
194 if (!$this->_isTemplate
) {
196 $this->_doneUrl
= CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
197 "action=update&reset=1&id={$this->_id}"
201 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/event/manage',
206 'title' => ts('Manage Events'),
207 'url' => $this->_doneUrl
,
213 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1');
216 'title' => ts('Manage Event Templates'),
217 'url' => $this->_doneUrl
,
221 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
225 * Set default values for the form.
227 * For edit/view mode the default values are retrieved from the database.
229 public function setDefaultValues() {
231 if (isset($this->_id
)) {
232 $params = ['id' => $this->_id
];
233 CRM_Event_BAO_Event
::retrieve($params, $defaults);
235 $this->_campaignID
= $defaults['campaign_id'] ??
NULL;
237 elseif ($this->_templateId
) {
238 $params = ['id' => $this->_templateId
];
239 CRM_Event_BAO_Event
::retrieve($params, $defaults);
240 $defaults['is_template'] = $this->_isTemplate
;
241 $defaults['template_id'] = $defaults['id'];
242 unset($defaults['id']);
243 unset($defaults['start_date']);
244 unset($defaults['end_date']);
247 $defaults['is_active'] = 1;
248 $defaults['style'] = 'Inline';
255 * Build the form object.
257 public function buildQuickForm() {
258 $session = CRM_Core_Session
::singleton();
260 $this->_cancelURL
= $_POST['cancelURL'] ??
NULL;
262 if (!$this->_cancelURL
) {
263 if ($this->_isTemplate
) {
264 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/eventTemplate',
269 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/event/manage',
275 if ($this->_cancelURL
) {
276 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
279 if ($this->_single
) {
283 'name' => ts('Save'),
288 'name' => ts('Save and Done'),
289 'spacing' => ' ',
294 'name' => ts('Cancel'),
297 $this->addButtons($buttons);
301 if (!$this->_first
) {
304 'name' => ts('Previous'),
305 'spacing' => ' ',
310 'name' => ts('Continue'),
311 'spacing' => ' ',
316 'name' => ts('Cancel'),
319 $this->addButtons($buttons);
321 $session->replaceUserContext($this->_cancelURL
);
322 $this->add('hidden', 'is_template', $this->_isTemplate
);
325 public function endPostProcess() {
326 // make submit buttons keep the current working tab opened.
327 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
328 $className = CRM_Utils_String
::getClassName($this->_name
);
330 // hack for special cases.
331 switch ($className) {
333 $attributes = $this->getVar('_attributes');
334 $subPage = CRM_Utils_Request
::retrieveComponent($attributes);
338 $subPage = 'settings';
341 case 'ScheduleReminders':
342 $subPage = 'reminder';
346 $subPage = strtolower($className);
350 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
351 [1 => CRM_Utils_Array
::value('title', CRM_Utils_Array
::value($subPage, $this->get('tabHeader')), $className)]
352 ), $this->getTitle(), 'success');
354 if (CRM_Core_Component
::isEnabled('CiviCampaign')) {
355 $values = $this->controller
->exportValues($this->_name
);
356 $newCampaignID = $values['campaign_id'] ??
NULL;
357 $eventID = $values['id'] ??
NULL;
358 if ($eventID && $this->_campaignID
!= $newCampaignID) {
359 CRM_Event_BAO_Event
::updateParticipantCampaignID($eventID, $newCampaignID);
362 $this->postProcessHook();
363 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_done") {
364 if ($this->_isTemplate
) {
365 CRM_Core_Session
::singleton()
366 ->pushUserContext(CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1'));
369 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/event/manage', 'reset=1'));
373 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url("civicrm/event/manage/{$subPage}",
374 "action=update&reset=1&id={$this->_id}"
383 public function getTemplateFileName() {
384 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
$this->_action
& CRM_Core_Action
::DELETE
) {
385 return parent
::getTemplateFileName();
388 // hack lets suppress the form rendering for now
389 self
::$_template->assign('isForm', FALSE);
390 return 'CRM/Event/Form/ManageEvent/Tab.tpl';
395 * Pre-load libraries required by Online Registration Profile fields
397 public static function addProfileEditScripts() {
398 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
399 CRM_UF_Page_ProfileEditor
::registerSchemas(['IndividualModel', 'ParticipantModel']);