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.
72 protected $_templateId;
74 protected $_cancelURL = NULL;
77 * The campaign id of the existing event, we use this to know if we need to update
78 * the participant records
81 protected $_campaignID = NULL;
84 * Check if repeating event.
87 public $_isRepeatingEvent;
90 * Explicitly declare the entity api name.
92 public function getDefaultEntity() {
97 * Explicitly declare the form context.
99 public function getDefaultContext() {
106 * @param string $default
108 * @throws \CRM_Core_Exception
110 public function setSelectedChild($default = NULL) {
111 $selectedChild = CRM_Utils_Request
::retrieve('selectedChild', 'Alphanumeric', $this, FALSE, $default);
112 if (!empty($selectedChild)) {
113 $this->set('selectedChild', $selectedChild);
114 $this->assign('selectedChild', $selectedChild);
119 * Set variables up before form is built.
121 public function preProcess() {
122 $config = CRM_Core_Config
::singleton();
123 if (in_array('CiviEvent', $config->enableComponents
)) {
124 $this->assign('CiviEvent', TRUE);
126 CRM_Core_Form_RecurringEntity
::preProcess('civicrm_event');
128 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
130 $this->assign('action', $this->_action
);
132 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
134 $this->_isRepeatingEvent
= CRM_Core_BAO_RecurringEntity
::getParentFor($this->_id
, 'civicrm_event');
135 $this->assign('eventId', $this->_id
);
136 if (!empty($this->_addBlockName
) && empty($this->_addProfileBottom
) && empty($this->_addProfileBottomAdd
)) {
137 $this->add('hidden', 'id', $this->_id
);
139 $this->_single
= TRUE;
141 $params = ['id' => $this->_id
];
142 CRM_Event_BAO_Event
::retrieve($params, $eventInfo);
144 // its an update mode, do a permission check
145 if (!CRM_Event_BAO_Event
::checkPermission($this->_id
, CRM_Core_Permission
::EDIT
)) {
146 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
149 $participantListingID = CRM_Utils_Array
::value('participant_listing_id', $eventInfo);
150 //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' );
151 if ($participantListingID) {
152 $participantListingURL = CRM_Utils_System
::url('civicrm/event/participant',
153 "reset=1&id={$this->_id}",
154 TRUE, NULL, TRUE, TRUE
156 $this->assign('participantListingURL', $participantListingURL);
159 $this->assign('isOnlineRegistration', CRM_Utils_Array
::value('is_online_registration', $eventInfo));
161 $this->assign('id', $this->_id
);
164 // figure out whether we’re handling an event or an event template
166 $this->_isTemplate
= CRM_Utils_Array
::value('is_template', $eventInfo);
168 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
169 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
172 $this->assign('isTemplate', $this->_isTemplate
);
175 if ($this->_isTemplate
) {
176 $title = CRM_Utils_Array
::value('template_title', $eventInfo);
177 CRM_Utils_System
::setTitle(ts('Edit Event Template') . " - $title");
180 $configureText = ts('Configure Event');
181 $title = CRM_Utils_Array
::value('title', $eventInfo);
182 //If it is a repeating event change title
183 if ($this->_isRepeatingEvent
) {
184 $configureText = 'Configure Repeating Event';
186 CRM_Utils_System
::setTitle($configureText . " - $title");
188 $this->assign('title', $title);
190 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
191 if ($this->_isTemplate
) {
192 $title = ts('New Event Template');
193 CRM_Utils_System
::setTitle($title);
196 $title = ts('New Event');
197 CRM_Utils_System
::setTitle($title);
199 $this->assign('title', $title);
202 if (CRM_Core_Permission
::check('view event participants') &&
203 CRM_Core_Permission
::check('view all contacts')
205 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
206 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
207 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
208 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
209 $this->assign('findParticipants', $findParticipants);
212 $this->_templateId
= (int) CRM_Utils_Request
::retrieve('template_id', 'Integer', $this);
214 //Is a repeating event
215 if ($this->_isRepeatingEvent
) {
216 $isRepeatingEntity = TRUE;
217 $this->assign('isRepeatingEntity', $isRepeatingEntity);
220 // CRM-16776 - show edit/copy/create buttons for Profiles if user has required permission.
221 $ufGroups = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_UFField', 'uf_group_id');
222 $ufCreate = CRM_ACL_API
::group(CRM_Core_Permission
::CREATE
, NULL, 'civicrm_uf_group', $ufGroups);
223 $ufEdit = CRM_ACL_API
::group(CRM_Core_Permission
::EDIT
, NULL, 'civicrm_uf_group', $ufGroups);
226 'administer CiviCRM',
227 'manage event profiles',
230 if (CRM_Core_Permission
::check($checkPermission) ||
!empty($ufCreate) ||
!empty($ufEdit)) {
231 $this->assign('perm', TRUE);
235 CRM_Event_Form_ManageEvent_TabHeader
::build($this);
237 // Set Done button URL and breadcrumb. Templates go back to Manage Templates,
238 // otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
240 if (!$this->_isTemplate
) {
242 $this->_doneUrl
= CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
243 "action=update&reset=1&id={$this->_id}"
247 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/event/manage',
252 'title' => ts('Manage Events'),
253 'url' => $this->_doneUrl
,
259 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1');
262 'title' => ts('Manage Event Templates'),
263 'url' => $this->_doneUrl
,
267 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
271 * Set default values for the form.
273 * For edit/view mode the default values are retrieved from the database.
275 public function setDefaultValues() {
277 if (isset($this->_id
)) {
278 $params = ['id' => $this->_id
];
279 CRM_Event_BAO_Event
::retrieve($params, $defaults);
281 $this->_campaignID
= CRM_Utils_Array
::value('campaign_id', $defaults);
283 elseif ($this->_templateId
) {
284 $params = ['id' => $this->_templateId
];
285 CRM_Event_BAO_Event
::retrieve($params, $defaults);
286 $defaults['is_template'] = $this->_isTemplate
;
287 $defaults['template_id'] = $defaults['id'];
288 unset($defaults['id']);
291 $defaults['is_active'] = 1;
292 $defaults['style'] = 'Inline';
299 * Build the form object.
301 public function buildQuickForm() {
302 $session = CRM_Core_Session
::singleton();
304 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
306 if (!$this->_cancelURL
) {
307 if ($this->_isTemplate
) {
308 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/eventTemplate',
313 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/event/manage',
319 if ($this->_cancelURL
) {
320 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
323 if ($this->_single
) {
327 'name' => ts('Save'),
332 'name' => ts('Save and Done'),
333 'spacing' => ' ',
338 'name' => ts('Cancel'),
341 $this->addButtons($buttons);
345 if (!$this->_first
) {
348 'name' => ts('Previous'),
349 'spacing' => ' ',
354 'name' => ts('Continue'),
355 'spacing' => ' ',
360 'name' => ts('Cancel'),
363 $this->addButtons($buttons);
365 $session->replaceUserContext($this->_cancelURL
);
366 $this->add('hidden', 'is_template', $this->_isTemplate
);
369 public function endPostProcess() {
370 // make submit buttons keep the current working tab opened.
371 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
372 $className = CRM_Utils_String
::getClassName($this->_name
);
374 // hack for special cases.
375 switch ($className) {
377 $attributes = $this->getVar('_attributes');
378 $subPage = CRM_Utils_Request
::retrieveComponent($attributes);
382 $subPage = 'settings';
385 case 'ScheduleReminders':
386 $subPage = 'reminder';
390 $subPage = strtolower($className);
394 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
395 [1 => CRM_Utils_Array
::value('title', CRM_Utils_Array
::value($subPage, $this->get('tabHeader')), $className)]
396 ), ts('Saved'), 'success');
398 $config = CRM_Core_Config
::singleton();
399 if (in_array('CiviCampaign', $config->enableComponents
)) {
400 $values = $this->controller
->exportValues($this->_name
);
401 $newCampaignID = CRM_Utils_Array
::value('campaign_id', $values);
402 $eventID = CRM_Utils_Array
::value('id', $values);
403 if ($eventID && $this->_campaignID
!= $newCampaignID) {
404 CRM_Event_BAO_Event
::updateParticipantCampaignID($eventID, $newCampaignID);
407 $this->postProcessHook();
408 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_done") {
409 if ($this->_isTemplate
) {
410 CRM_Core_Session
::singleton()
411 ->pushUserContext(CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1'));
414 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/event/manage', 'reset=1'));
418 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url("civicrm/event/manage/{$subPage}",
419 "action=update&reset=1&id={$this->_id}"
428 public function getTemplateFileName() {
429 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
$this->_action
& CRM_Core_Action
::DELETE
) {
430 return parent
::getTemplateFileName();
433 // hack lets suppress the form rendering for now
434 self
::$_template->assign('isForm', FALSE);
435 return 'CRM/Event/Form/ManageEvent/Tab.tpl';
440 * Pre-load libraries required by Online Registration Profile fields
442 public static function addProfileEditScripts() {
443 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
444 CRM_UF_Page_ProfileEditor
::registerSchemas(['IndividualModel', 'ParticipantModel']);