3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2019
34 * This class generates form components for processing Event.
36 class CRM_Event_Form_ManageEvent
extends CRM_Core_Form
{
39 * The id of the event we are processing.
46 * Is this the first page?
50 protected $_first = FALSE;
53 * Are we in single form mode or wizard mode?
62 * Are we actually managing an event template?
65 protected $_isTemplate = FALSE;
68 * Pre-populate fields based on this template event_id
71 protected $_templateId;
73 protected $_cancelURL = NULL;
76 * The campaign id of the existing event, we use this to know if we need to update
77 * the participant records
80 protected $_campaignID = NULL;
83 * Check if repeating event.
86 public $_isRepeatingEvent;
89 * Explicitly declare the entity api name.
91 public function getDefaultEntity() {
96 * Explicitly declare the form context.
98 public function getDefaultContext() {
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
::fatal(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
);
159 if ($this->_isTemplate
) {
160 $title = CRM_Utils_Array
::value('template_title', $eventInfo);
161 CRM_Utils_System
::setTitle(ts('Edit Event Template') . " - $title");
164 $configureText = ts('Configure Event');
165 $title = CRM_Utils_Array
::value('title', $eventInfo);
166 //If it is a repeating event change title
167 if ($this->_isRepeatingEvent
) {
168 $configureText = 'Configure Repeating Event';
170 CRM_Utils_System
::setTitle($configureText . " - $title");
172 $this->assign('title', $title);
174 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
175 if ($this->_isTemplate
) {
176 $title = ts('New Event Template');
177 CRM_Utils_System
::setTitle($title);
180 $title = ts('New Event');
181 CRM_Utils_System
::setTitle($title);
183 $this->assign('title', $title);
186 if (CRM_Core_Permission
::check('view event participants') &&
187 CRM_Core_Permission
::check('view all contacts')
189 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
190 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
191 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
192 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
193 $this->assign('findParticipants', $findParticipants);
196 $this->_templateId
= (int) CRM_Utils_Request
::retrieve('template_id', 'Integer', $this);
198 //Is a repeating event
199 if ($this->_isRepeatingEvent
) {
200 $isRepeatingEntity = TRUE;
201 $this->assign('isRepeatingEntity', $isRepeatingEntity);
204 // CRM-16776 - show edit/copy/create buttons for Profiles if user has required permission.
205 $ufGroups = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_UFField', 'uf_group_id');
206 $ufCreate = CRM_ACL_API
::group(CRM_Core_Permission
::CREATE
, NULL, 'civicrm_uf_group', $ufGroups);
207 $ufEdit = CRM_ACL_API
::group(CRM_Core_Permission
::EDIT
, NULL, 'civicrm_uf_group', $ufGroups);
210 'administer CiviCRM',
211 'manage event profiles',
214 if (CRM_Core_Permission
::check($checkPermission) ||
!empty($ufCreate) ||
!empty($ufEdit)) {
215 $this->assign('perm', TRUE);
219 CRM_Event_Form_ManageEvent_TabHeader
::build($this);
221 // Set Done button URL and breadcrumb. Templates go back to Manage Templates,
222 // otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
224 if (!$this->_isTemplate
) {
226 $this->_doneUrl
= CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
227 "action=update&reset=1&id={$this->_id}"
231 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/event/manage',
236 'title' => ts('Manage Events'),
237 'url' => $this->_doneUrl
,
243 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1');
246 'title' => ts('Manage Event Templates'),
247 'url' => $this->_doneUrl
,
251 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
255 * Set default values for the form.
257 * For edit/view mode the default values are retrieved from the database.
259 public function setDefaultValues() {
261 if (isset($this->_id
)) {
262 $params = ['id' => $this->_id
];
263 CRM_Event_BAO_Event
::retrieve($params, $defaults);
265 $this->_campaignID
= CRM_Utils_Array
::value('campaign_id', $defaults);
267 elseif ($this->_templateId
) {
268 $params = ['id' => $this->_templateId
];
269 CRM_Event_BAO_Event
::retrieve($params, $defaults);
270 $defaults['is_template'] = $this->_isTemplate
;
271 $defaults['template_id'] = $defaults['id'];
272 unset($defaults['id']);
275 $defaults['is_active'] = 1;
276 $defaults['style'] = 'Inline';
283 * Build the form object.
285 public function buildQuickForm() {
286 $session = CRM_Core_Session
::singleton();
288 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
290 if (!$this->_cancelURL
) {
291 if ($this->_isTemplate
) {
292 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/eventTemplate',
297 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/event/manage',
303 if ($this->_cancelURL
) {
304 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
307 if ($this->_single
) {
311 'name' => ts('Save'),
316 'name' => ts('Save and Done'),
317 'spacing' => ' ',
322 'name' => ts('Cancel'),
325 $this->addButtons($buttons);
329 if (!$this->_first
) {
332 'name' => ts('Previous'),
333 'spacing' => ' ',
338 'name' => ts('Continue'),
339 'spacing' => ' ',
344 'name' => ts('Cancel'),
347 $this->addButtons($buttons);
349 $session->replaceUserContext($this->_cancelURL
);
350 $this->add('hidden', 'is_template', $this->_isTemplate
);
353 public function endPostProcess() {
354 // make submit buttons keep the current working tab opened.
355 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
356 $className = CRM_Utils_String
::getClassName($this->_name
);
358 // hack for special cases.
359 switch ($className) {
361 $attributes = $this->getVar('_attributes');
362 $subPage = CRM_Utils_Request
::retrieveComponent($attributes);
366 $subPage = 'settings';
369 case 'ScheduleReminders':
370 $subPage = 'reminder';
374 $subPage = strtolower($className);
378 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
379 [1 => CRM_Utils_Array
::value('title', CRM_Utils_Array
::value($subPage, $this->get('tabHeader')), $className)]
380 ), ts('Saved'), 'success');
382 $config = CRM_Core_Config
::singleton();
383 if (in_array('CiviCampaign', $config->enableComponents
)) {
384 $values = $this->controller
->exportValues($this->_name
);
385 $newCampaignID = CRM_Utils_Array
::value('campaign_id', $values);
386 $eventID = CRM_Utils_Array
::value('id', $values);
387 if ($eventID && $this->_campaignID
!= $newCampaignID) {
388 CRM_Event_BAO_Event
::updateParticipantCampaignID($eventID, $newCampaignID);
391 $this->postProcessHook();
392 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_done") {
393 if ($this->_isTemplate
) {
394 CRM_Core_Session
::singleton()
395 ->pushUserContext(CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1'));
398 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/event/manage', 'reset=1'));
402 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url("civicrm/event/manage/{$subPage}",
403 "action=update&reset=1&id={$this->_id}"
412 public function getTemplateFileName() {
413 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
$this->_action
& CRM_Core_Action
::DELETE
) {
414 return parent
::getTemplateFileName();
417 // hack lets suppress the form rendering for now
418 self
::$_template->assign('isForm', FALSE);
419 return 'CRM/Event/Form/ManageEvent/Tab.tpl';
424 * Pre-load libraries required by Online Registration Profile fields
426 public static function addProfileEditScripts() {
427 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
428 CRM_UF_Page_ProfileEditor
::registerSchemas(['IndividualModel', 'ParticipantModel']);