3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
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
79 protected $_campaignID = NULL;
82 * Check if repeating event.
84 public $_isRepeatingEvent;
87 * Explicitly declare the entity api name.
89 public function getDefaultEntity() {
94 * Explicitly declare the form context.
96 public function getDefaultContext() {
101 * Set variables up before form is built.
103 public function preProcess() {
104 $config = CRM_Core_Config
::singleton();
105 if (in_array('CiviEvent', $config->enableComponents
)) {
106 $this->assign('CiviEvent', TRUE);
108 CRM_Core_Form_RecurringEntity
::preProcess('civicrm_event');
110 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
112 $this->assign('action', $this->_action
);
114 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
116 $this->_isRepeatingEvent
= CRM_Core_BAO_RecurringEntity
::getParentFor($this->_id
, 'civicrm_event');
117 $this->assign('eventId', $this->_id
);
118 if (!empty($this->_addBlockName
) && empty($this->_addProfileBottom
) && empty($this->_addProfileBottomAdd
)) {
119 $this->add('hidden', 'id', $this->_id
);
121 $this->_single
= TRUE;
123 $params = array('id' => $this->_id
);
124 CRM_Event_BAO_Event
::retrieve($params, $eventInfo);
126 // its an update mode, do a permission check
127 if (!CRM_Event_BAO_Event
::checkPermission($this->_id
, CRM_Core_Permission
::EDIT
)) {
128 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
131 $participantListingID = CRM_Utils_Array
::value('participant_listing_id', $eventInfo);
132 //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' );
133 if ($participantListingID) {
134 $participantListingURL = CRM_Utils_System
::url('civicrm/event/participant',
135 "reset=1&id={$this->_id}",
136 TRUE, NULL, TRUE, TRUE
138 $this->assign('participantListingURL', $participantListingURL);
141 $this->assign('isOnlineRegistration', CRM_Utils_Array
::value('is_online_registration', $eventInfo));
143 $this->assign('id', $this->_id
);
146 // figure out whether we’re handling an event or an event template
148 $this->_isTemplate
= CRM_Utils_Array
::value('is_template', $eventInfo);
150 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
151 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
154 $this->assign('isTemplate', $this->_isTemplate
);
157 if ($this->_isTemplate
) {
158 $title = CRM_Utils_Array
::value('template_title', $eventInfo);
159 CRM_Utils_System
::setTitle(ts('Edit Event Template') . " - $title");
162 $configureText = ts('Configure Event');
163 $title = CRM_Utils_Array
::value('title', $eventInfo);
164 //If it is a repeating event change title
165 if ($this->_isRepeatingEvent
) {
166 $configureText = 'Configure Repeating Event';
168 CRM_Utils_System
::setTitle($configureText . " - $title");
170 $this->assign('title', $title);
172 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
173 if ($this->_isTemplate
) {
174 $title = ts('New Event Template');
175 CRM_Utils_System
::setTitle($title);
178 $title = ts('New Event');
179 CRM_Utils_System
::setTitle($title);
181 $this->assign('title', $title);
184 if (CRM_Core_Permission
::check('view event participants') &&
185 CRM_Core_Permission
::check('view all contacts')
187 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
188 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
189 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
190 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
191 $this->assign('findParticipants', $findParticipants);
194 $this->_templateId
= (int) CRM_Utils_Request
::retrieve('template_id', 'Integer', $this);
196 //Is a repeating event
197 if ($this->_isRepeatingEvent
) {
198 $isRepeatingEntity = TRUE;
199 $this->assign('isRepeatingEntity', $isRepeatingEntity);
202 // CRM-16776 - show edit/copy/create buttons for Profiles if user has required permission.
203 $ufGroups = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_UFField', 'uf_group_id');
204 $ufCreate = CRM_ACL_API
::group(CRM_Core_Permission
::CREATE
, NULL, 'civicrm_uf_group', $ufGroups);
205 $ufEdit = CRM_ACL_API
::group(CRM_Core_Permission
::EDIT
, NULL, 'civicrm_uf_group', $ufGroups);
206 $checkPermission = array(
208 'administer CiviCRM',
209 'manage event profiles',
212 if (CRM_Core_Permission
::check($checkPermission) ||
!empty($ufCreate) ||
!empty($ufEdit)) {
213 $this->assign('perm', TRUE);
217 CRM_Event_Form_ManageEvent_TabHeader
::build($this);
219 // Set Done button URL and breadcrumb. Templates go back to Manage Templates,
220 // otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
221 $breadCrumb = array();
222 if (!$this->_isTemplate
) {
224 $this->_doneUrl
= CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
225 "action=update&reset=1&id={$this->_id}"
229 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/event/manage',
234 'title' => ts('Manage Events'),
235 'url' => $this->_doneUrl
,
241 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1');
244 'title' => ts('Manage Event Templates'),
245 'url' => $this->_doneUrl
,
249 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
253 * Set default values for the form.
255 * For edit/view mode the default values are retrieved from the database.
257 public function setDefaultValues() {
259 if (isset($this->_id
)) {
260 $params = array('id' => $this->_id
);
261 CRM_Event_BAO_Event
::retrieve($params, $defaults);
263 $this->_campaignID
= CRM_Utils_Array
::value('campaign_id', $defaults);
265 elseif ($this->_templateId
) {
266 $params = array('id' => $this->_templateId
);
267 CRM_Event_BAO_Event
::retrieve($params, $defaults);
268 $defaults['is_template'] = $this->_isTemplate
;
269 $defaults['template_id'] = $defaults['id'];
270 unset($defaults['id']);
273 $defaults['is_active'] = 1;
274 $defaults['style'] = 'Inline';
281 * Build the form object.
283 public function buildQuickForm() {
284 $session = CRM_Core_Session
::singleton();
286 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
288 if (!$this->_cancelURL
) {
289 if ($this->_isTemplate
) {
290 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/eventTemplate',
295 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/event/manage',
301 if ($this->_cancelURL
) {
302 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
305 if ($this->_single
) {
309 'name' => ts('Save'),
314 'name' => ts('Save and Done'),
315 'spacing' => ' ',
320 'name' => ts('Cancel'),
323 $this->addButtons($buttons);
327 if (!$this->_first
) {
330 'name' => ts('Previous'),
331 'spacing' => ' ',
336 'name' => ts('Continue'),
337 'spacing' => ' ',
342 'name' => ts('Cancel'),
345 $this->addButtons($buttons);
347 $session->replaceUserContext($this->_cancelURL
);
348 $this->add('hidden', 'is_template', $this->_isTemplate
);
351 public function endPostProcess() {
352 // make submit buttons keep the current working tab opened.
353 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
354 $className = CRM_Utils_String
::getClassName($this->_name
);
356 // hack for special cases.
357 switch ($className) {
359 $attributes = $this->getVar('_attributes');
360 $subPage = strtolower(basename(CRM_Utils_Array
::value('action', $attributes)));
364 $subPage = 'settings';
367 case 'ScheduleReminders':
368 $subPage = 'reminder';
372 $subPage = strtolower($className);
376 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
377 array(1 => CRM_Utils_Array
::value('title', CRM_Utils_Array
::value($subPage, $this->get('tabHeader')), $className))
378 ), ts('Saved'), 'success');
380 $config = CRM_Core_Config
::singleton();
381 if (in_array('CiviCampaign', $config->enableComponents
)) {
382 $values = $this->controller
->exportValues($this->_name
);
383 $newCampaignID = CRM_Utils_Array
::value('campaign_id', $values);
384 $eventID = CRM_Utils_Array
::value('id', $values);
385 if ($eventID && $this->_campaignID
!= $newCampaignID) {
386 CRM_Event_BAO_Event
::updateParticipantCampaignID($eventID, $newCampaignID);
389 $this->postProcessHook();
390 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_done") {
391 if ($this->_isTemplate
) {
392 CRM_Core_Session
::singleton()
393 ->pushUserContext(CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1'));
396 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/event/manage', 'reset=1'));
400 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url("civicrm/event/manage/{$subPage}",
401 "action=update&reset=1&id={$this->_id}"
410 public function getTemplateFileName() {
411 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
$this->_action
& CRM_Core_Action
::DELETE
) {
412 return parent
::getTemplateFileName();
415 // hack lets suppress the form rendering for now
416 self
::$_template->assign('isForm', FALSE);
417 return 'CRM/Event/Form/ManageEvent/Tab.tpl';
422 * Pre-load libraries required by Online Registration Profile fields
424 public static function addProfileEditScripts() {
425 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
426 CRM_UF_Page_ProfileEditor
::registerSchemas(array('IndividualModel', 'ParticipantModel'));