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() {
90 * @param string $default
92 * @throws \CRM_Core_Exception
94 public function setSelectedChild($default = NULL) {
95 $selectedChild = CRM_Utils_Request
::retrieve('selectedChild', 'Alphanumeric', $this, FALSE, $default);
96 if (!empty($selectedChild)) {
97 $this->set('selectedChild', $selectedChild);
98 $this->assign('selectedChild', $selectedChild);
103 * Set variables up before form is built.
105 public function preProcess() {
106 $config = CRM_Core_Config
::singleton();
107 if (in_array('CiviEvent', $config->enableComponents
)) {
108 $this->assign('CiviEvent', TRUE);
110 CRM_Core_Form_RecurringEntity
::preProcess('civicrm_event');
112 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
114 $this->assign('action', $this->_action
);
116 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
118 $this->_isRepeatingEvent
= CRM_Core_BAO_RecurringEntity
::getParentFor($this->_id
, 'civicrm_event');
119 $this->assign('eventId', $this->_id
);
120 if (!empty($this->_addBlockName
) && empty($this->_addProfileBottom
) && empty($this->_addProfileBottomAdd
)) {
121 $this->add('hidden', 'id', $this->_id
);
123 $this->_single
= TRUE;
125 $params = ['id' => $this->_id
];
126 CRM_Event_BAO_Event
::retrieve($params, $eventInfo);
128 // its an update mode, do a permission check
129 if (!CRM_Event_BAO_Event
::checkPermission($this->_id
, CRM_Core_Permission
::EDIT
)) {
130 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
133 $participantListingID = CRM_Utils_Array
::value('participant_listing_id', $eventInfo);
134 //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' );
135 if ($participantListingID) {
136 $participantListingURL = CRM_Utils_System
::url('civicrm/event/participant',
137 "reset=1&id={$this->_id}",
138 TRUE, NULL, TRUE, TRUE
140 $this->assign('participantListingURL', $participantListingURL);
143 $this->assign('isOnlineRegistration', CRM_Utils_Array
::value('is_online_registration', $eventInfo));
145 $this->assign('id', $this->_id
);
148 // figure out whether we’re handling an event or an event template
150 $this->_isTemplate
= CRM_Utils_Array
::value('is_template', $eventInfo);
152 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
153 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
156 $this->assign('isTemplate', $this->_isTemplate
);
158 // Set "Manage Event" Title
161 if ($this->_isTemplate
) {
162 $title = ts('Edit Event Template') . ' - ' . CRM_Utils_Array
::value('template_title', $eventInfo);
165 $configureText = $this->_isRepeatingEvent ?
ts('Configure Repeating Event') : ts('Configure Event');
166 $title = $configureText . ' - ' . CRM_Utils_Array
::value('title', $eventInfo);
169 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
170 $title = $this->_isTemplate ?
ts('New Event Template') : ts('New Event');
172 $this->setTitle($title);
174 if (CRM_Core_Permission
::check('view event participants') &&
175 CRM_Core_Permission
::check('view all contacts')
177 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
178 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
179 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
180 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
181 $this->assign('findParticipants', $findParticipants);
184 $this->_templateId
= (int) CRM_Utils_Request
::retrieve('template_id', 'Integer', $this);
186 //Is a repeating event
187 if ($this->_isRepeatingEvent
) {
188 $isRepeatingEntity = TRUE;
189 $this->assign('isRepeatingEntity', $isRepeatingEntity);
192 // CRM-16776 - show edit/copy/create buttons for Profiles if user has required permission.
193 $ufGroups = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_UFField', 'uf_group_id');
194 $ufCreate = CRM_ACL_API
::group(CRM_Core_Permission
::CREATE
, NULL, 'civicrm_uf_group', $ufGroups);
195 $ufEdit = CRM_ACL_API
::group(CRM_Core_Permission
::EDIT
, NULL, 'civicrm_uf_group', $ufGroups);
198 'administer CiviCRM',
199 'manage event profiles',
202 if (CRM_Core_Permission
::check($checkPermission) ||
!empty($ufCreate) ||
!empty($ufEdit)) {
203 $this->assign('perm', TRUE);
207 CRM_Event_Form_ManageEvent_TabHeader
::build($this);
209 // Set Done button URL and breadcrumb. Templates go back to Manage Templates,
210 // otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
212 if (!$this->_isTemplate
) {
214 $this->_doneUrl
= CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
215 "action=update&reset=1&id={$this->_id}"
219 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/event/manage',
224 'title' => ts('Manage Events'),
225 'url' => $this->_doneUrl
,
231 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1');
234 'title' => ts('Manage Event Templates'),
235 'url' => $this->_doneUrl
,
239 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
243 * Set default values for the form.
245 * For edit/view mode the default values are retrieved from the database.
247 public function setDefaultValues() {
249 if (isset($this->_id
)) {
250 $params = ['id' => $this->_id
];
251 CRM_Event_BAO_Event
::retrieve($params, $defaults);
253 $this->_campaignID
= CRM_Utils_Array
::value('campaign_id', $defaults);
255 elseif ($this->_templateId
) {
256 $params = ['id' => $this->_templateId
];
257 CRM_Event_BAO_Event
::retrieve($params, $defaults);
258 $defaults['is_template'] = $this->_isTemplate
;
259 $defaults['template_id'] = $defaults['id'];
260 unset($defaults['id']);
261 unset($defaults['start_date']);
262 unset($defaults['end_date']);
265 $defaults['is_active'] = 1;
266 $defaults['style'] = 'Inline';
273 * Build the form object.
275 public function buildQuickForm() {
276 $session = CRM_Core_Session
::singleton();
278 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
280 if (!$this->_cancelURL
) {
281 if ($this->_isTemplate
) {
282 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/eventTemplate',
287 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/event/manage',
293 if ($this->_cancelURL
) {
294 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
297 if ($this->_single
) {
301 'name' => ts('Save'),
306 'name' => ts('Save and Done'),
307 'spacing' => ' ',
312 'name' => ts('Cancel'),
315 $this->addButtons($buttons);
319 if (!$this->_first
) {
322 'name' => ts('Previous'),
323 'spacing' => ' ',
328 'name' => ts('Continue'),
329 'spacing' => ' ',
334 'name' => ts('Cancel'),
337 $this->addButtons($buttons);
339 $session->replaceUserContext($this->_cancelURL
);
340 $this->add('hidden', 'is_template', $this->_isTemplate
);
343 public function endPostProcess() {
344 // make submit buttons keep the current working tab opened.
345 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
346 $className = CRM_Utils_String
::getClassName($this->_name
);
348 // hack for special cases.
349 switch ($className) {
351 $attributes = $this->getVar('_attributes');
352 $subPage = CRM_Utils_Request
::retrieveComponent($attributes);
356 $subPage = 'settings';
359 case 'ScheduleReminders':
360 $subPage = 'reminder';
364 $subPage = strtolower($className);
368 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
369 [1 => CRM_Utils_Array
::value('title', CRM_Utils_Array
::value($subPage, $this->get('tabHeader')), $className)]
370 ), $this->getTitle(), 'success');
372 $config = CRM_Core_Config
::singleton();
373 if (in_array('CiviCampaign', $config->enableComponents
)) {
374 $values = $this->controller
->exportValues($this->_name
);
375 $newCampaignID = CRM_Utils_Array
::value('campaign_id', $values);
376 $eventID = CRM_Utils_Array
::value('id', $values);
377 if ($eventID && $this->_campaignID
!= $newCampaignID) {
378 CRM_Event_BAO_Event
::updateParticipantCampaignID($eventID, $newCampaignID);
381 $this->postProcessHook();
382 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_done") {
383 if ($this->_isTemplate
) {
384 CRM_Core_Session
::singleton()
385 ->pushUserContext(CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1'));
388 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/event/manage', 'reset=1'));
392 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url("civicrm/event/manage/{$subPage}",
393 "action=update&reset=1&id={$this->_id}"
402 public function getTemplateFileName() {
403 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
$this->_action
& CRM_Core_Action
::DELETE
) {
404 return parent
::getTemplateFileName();
407 // hack lets suppress the form rendering for now
408 self
::$_template->assign('isForm', FALSE);
409 return 'CRM/Event/Form/ManageEvent/Tab.tpl';
414 * Pre-load libraries required by Online Registration Profile fields
416 public static function addProfileEditScripts() {
417 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
418 CRM_UF_Page_ProfileEditor
::registerSchemas(['IndividualModel', 'ParticipantModel']);