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 $config = CRM_Core_Config
::singleton();
92 if (in_array('CiviEvent', $config->enableComponents
)) {
93 $this->assign('CiviEvent', TRUE);
95 CRM_Core_Form_RecurringEntity
::preProcess('civicrm_event');
97 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
99 $this->assign('action', $this->_action
);
101 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
103 $this->_isRepeatingEvent
= CRM_Core_BAO_RecurringEntity
::getParentFor($this->_id
, 'civicrm_event');
104 $this->assign('eventId', $this->_id
);
105 if (!empty($this->_addBlockName
) && empty($this->_addProfileBottom
) && empty($this->_addProfileBottomAdd
)) {
106 $this->add('hidden', 'id', $this->_id
);
108 $this->_single
= TRUE;
110 $params = ['id' => $this->_id
];
111 CRM_Event_BAO_Event
::retrieve($params, $eventInfo);
113 // its an update mode, do a permission check
114 if (!CRM_Event_BAO_Event
::checkPermission($this->_id
, CRM_Core_Permission
::EDIT
)) {
115 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
118 $participantListingID = $eventInfo['participant_listing_id'] ??
NULL;
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
125 $this->assign('participantListingURL', $participantListingURL);
128 $this->assign('isOnlineRegistration', CRM_Utils_Array
::value('is_online_registration', $eventInfo));
130 $this->assign('id', $this->_id
);
133 // figure out whether we’re handling an event or an event template
135 $this->_isTemplate
= $eventInfo['is_template'] ??
NULL;
137 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
138 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
141 $this->assign('isTemplate', $this->_isTemplate
);
143 // Set "Manage Event" Title
146 if ($this->_isTemplate
) {
147 $title = ts('Edit Event Template') . ' - ' . CRM_Utils_Array
::value('template_title', $eventInfo);
150 $configureText = $this->_isRepeatingEvent ?
ts('Configure Repeating Event') : ts('Configure Event');
151 $title = $configureText . ' - ' . CRM_Utils_Array
::value('title', $eventInfo);
154 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
155 $title = $this->_isTemplate ?
ts('New Event Template') : ts('New Event');
157 $this->setTitle($title);
159 if (CRM_Core_Permission
::check('view event participants') &&
160 CRM_Core_Permission
::check('view all contacts')
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);
169 $this->_templateId
= (int) CRM_Utils_Request
::retrieve('template_id', 'Integer', $this);
171 //Is a repeating event
172 if ($this->_isRepeatingEvent
) {
173 $isRepeatingEntity = TRUE;
174 $this->assign('isRepeatingEntity', $isRepeatingEntity);
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);
183 'administer CiviCRM',
184 'manage event profiles',
187 if (CRM_Core_Permission
::check($checkPermission) ||
!empty($ufCreate) ||
!empty($ufEdit)) {
188 $this->assign('perm', TRUE);
192 CRM_Event_Form_ManageEvent_TabHeader
::build($this);
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.
197 if (!$this->_isTemplate
) {
199 $this->_doneUrl
= CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
200 "action=update&reset=1&id={$this->_id}"
204 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/event/manage',
209 'title' => ts('Manage Events'),
210 'url' => $this->_doneUrl
,
216 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1');
219 'title' => ts('Manage Event Templates'),
220 'url' => $this->_doneUrl
,
224 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
228 * Set default values for the form.
230 * For edit/view mode the default values are retrieved from the database.
232 public function setDefaultValues() {
234 if (isset($this->_id
)) {
235 $params = ['id' => $this->_id
];
236 CRM_Event_BAO_Event
::retrieve($params, $defaults);
238 $this->_campaignID
= $defaults['campaign_id'] ??
NULL;
240 elseif ($this->_templateId
) {
241 $params = ['id' => $this->_templateId
];
242 CRM_Event_BAO_Event
::retrieve($params, $defaults);
243 $defaults['is_template'] = $this->_isTemplate
;
244 $defaults['template_id'] = $defaults['id'];
245 unset($defaults['id']);
246 unset($defaults['start_date']);
247 unset($defaults['end_date']);
250 $defaults['is_active'] = 1;
251 $defaults['style'] = 'Inline';
258 * Build the form object.
260 public function buildQuickForm() {
261 $session = CRM_Core_Session
::singleton();
263 $this->_cancelURL
= $_POST['cancelURL'] ??
NULL;
265 if (!$this->_cancelURL
) {
266 if ($this->_isTemplate
) {
267 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/eventTemplate',
272 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/event/manage',
278 if ($this->_cancelURL
) {
279 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
282 if ($this->_single
) {
286 'name' => ts('Save'),
291 'name' => ts('Save and Done'),
292 'spacing' => ' ',
297 'name' => ts('Cancel'),
300 $this->addButtons($buttons);
304 if (!$this->_first
) {
307 'name' => ts('Previous'),
308 'spacing' => ' ',
313 'name' => ts('Continue'),
314 'spacing' => ' ',
319 'name' => ts('Cancel'),
322 $this->addButtons($buttons);
324 $session->replaceUserContext($this->_cancelURL
);
325 $this->add('hidden', 'is_template', $this->_isTemplate
);
328 public function endPostProcess() {
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
);
333 // hack for special cases.
334 switch ($className) {
336 $attributes = $this->getVar('_attributes');
337 $subPage = CRM_Utils_Request
::retrieveComponent($attributes);
341 $subPage = 'settings';
344 case 'ScheduleReminders':
345 $subPage = 'reminder';
349 $subPage = strtolower($className);
353 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
354 [1 => CRM_Utils_Array
::value('title', CRM_Utils_Array
::value($subPage, $this->get('tabHeader')), $className)]
355 ), $this->getTitle(), 'success');
357 $config = CRM_Core_Config
::singleton();
358 if (in_array('CiviCampaign', $config->enableComponents
)) {
359 $values = $this->controller
->exportValues($this->_name
);
360 $newCampaignID = $values['campaign_id'] ??
NULL;
361 $eventID = $values['id'] ??
NULL;
362 if ($eventID && $this->_campaignID
!= $newCampaignID) {
363 CRM_Event_BAO_Event
::updateParticipantCampaignID($eventID, $newCampaignID);
366 $this->postProcessHook();
367 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_done") {
368 if ($this->_isTemplate
) {
369 CRM_Core_Session
::singleton()
370 ->pushUserContext(CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1'));
373 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/event/manage', 'reset=1'));
377 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url("civicrm/event/manage/{$subPage}",
378 "action=update&reset=1&id={$this->_id}"
387 public function getTemplateFileName() {
388 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
$this->_action
& CRM_Core_Action
::DELETE
) {
389 return parent
::getTemplateFileName();
392 // hack lets suppress the form rendering for now
393 self
::$_template->assign('isForm', FALSE);
394 return 'CRM/Event/Form/ManageEvent/Tab.tpl';
399 * Pre-load libraries required by Online Registration Profile fields
401 public static function addProfileEditScripts() {
402 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
403 CRM_UF_Page_ProfileEditor
::registerSchemas(['IndividualModel', 'ParticipantModel']);