3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
37 * This class generates form components for processing Event
40 class CRM_Event_Form_ManageEvent
extends CRM_Core_Form
{
43 * The id of the event we are proceessing.
50 * Is this the first page?
54 protected $_first = FALSE;
57 * Are we in single form mode or wizard mode?
66 * Are we actually managing an event template?
69 protected $_isTemplate = FALSE;
72 * Pre-populate fields based on this template event_id
75 protected $_templateId;
77 protected $_cancelURL = NULL;
80 * The campaign id of the existing event, we use this to know if we need to update
81 * the participant records
83 protected $_campaignID = NULL;
86 * Check if repeating event.
88 public $_isRepeatingEvent;
91 * Explicitly declare the entity api name.
93 public function getDefaultEntity() {
98 * Explicitly declare the form context.
100 public function getDefaultContext() {
105 * Set variables up before form is built.
109 public function preProcess() {
110 $config = CRM_Core_Config
::singleton();
111 if (in_array('CiviEvent', $config->enableComponents
)) {
112 $this->assign('CiviEvent', TRUE);
114 CRM_Core_Form_RecurringEntity
::preProcess('civicrm_event');
116 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
118 $this->assign('action', $this->_action
);
120 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
122 $this->_isRepeatingEvent
= CRM_Core_BAO_RecurringEntity
::getParentFor($this->_id
, 'civicrm_event');
123 $this->assign('eventId', $this->_id
);
124 if (!empty($this->_addBlockName
) && empty($this->_addProfileBottom
) && empty($this->_addProfileBottomAdd
)) {
125 $this->add('hidden', 'id', $this->_id
);
127 $this->_single
= TRUE;
129 $params = array('id' => $this->_id
);
130 CRM_Event_BAO_Event
::retrieve($params, $eventInfo);
132 // its an update mode, do a permission check
133 if (!CRM_Event_BAO_Event
::checkPermission($this->_id
, CRM_Core_Permission
::EDIT
)) {
134 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
137 $participantListingID = CRM_Utils_Array
::value('participant_listing_id', $eventInfo);
138 //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' );
139 if ($participantListingID) {
140 $participantListingURL = CRM_Utils_System
::url('civicrm/event/participant',
141 "reset=1&id={$this->_id}",
142 TRUE, NULL, TRUE, TRUE
144 $this->assign('participantListingURL', $participantListingURL);
147 $this->assign('isOnlineRegistration', CRM_Utils_Array
::value('is_online_registration', $eventInfo));
149 $this->assign('id', $this->_id
);
152 // figure out whether we’re handling an event or an event template
154 $this->_isTemplate
= CRM_Utils_Array
::value('is_template', $eventInfo);
156 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
157 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
160 $this->assign('isTemplate', $this->_isTemplate
);
163 if ($this->_isTemplate
) {
164 $title = CRM_Utils_Array
::value('template_title', $eventInfo);
165 CRM_Utils_System
::setTitle(ts('Edit Event Template') . " - $title");
168 $configureText = ts('Configure Event');
169 $title = CRM_Utils_Array
::value('title', $eventInfo);
170 //If it is a repeating event change title
171 if ($this->_isRepeatingEvent
) {
172 $configureText = 'Configure Repeating Event';
174 CRM_Utils_System
::setTitle($configureText . " - $title");
176 $this->assign('title', $title);
178 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
179 if ($this->_isTemplate
) {
180 $title = ts('New Event Template');
181 CRM_Utils_System
::setTitle($title);
184 $title = ts('New Event');
185 CRM_Utils_System
::setTitle($title);
187 $this->assign('title', $title);
190 if (CRM_Core_Permission
::check('view event participants') &&
191 CRM_Core_Permission
::check('view all contacts')
193 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
194 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
195 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
196 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
197 $this->assign('findParticipants', $findParticipants);
200 $this->_templateId
= (int) CRM_Utils_Request
::retrieve('template_id', 'Integer', $this);
202 //Is a repeating event
203 if ($this->_isRepeatingEvent
) {
204 $isRepeatingEntity = TRUE;
205 $this->assign('isRepeatingEntity', $isRepeatingEntity);
209 CRM_Event_Form_ManageEvent_TabHeader
::build($this);
211 // Set Done button URL and breadcrumb. Templates go back to Manage Templates,
212 // otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
213 $breadCrumb = array();
214 if (!$this->_isTemplate
) {
216 $this->_doneUrl
= CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
217 "action=update&reset=1&id={$this->_id}"
221 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/event/manage',
226 'title' => ts('Manage Events'),
227 'url' => $this->_doneUrl
,
233 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1');
236 'title' => ts('Manage Event Templates'),
237 'url' => $this->_doneUrl
,
241 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
245 * Set default values for the form. For edit/view mode
246 * the default values are retrieved from the database
251 public function setDefaultValues() {
253 if (isset($this->_id
)) {
254 $params = array('id' => $this->_id
);
255 CRM_Event_BAO_Event
::retrieve($params, $defaults);
257 $this->_campaignID
= CRM_Utils_Array
::value('campaign_id', $defaults);
259 elseif ($this->_templateId
) {
260 $params = array('id' => $this->_templateId
);
261 CRM_Event_BAO_Event
::retrieve($params, $defaults);
262 $defaults['is_template'] = $this->_isTemplate
;
263 $defaults['template_id'] = $defaults['id'];
264 unset($defaults['id']);
267 $defaults['is_active'] = 1;
268 $defaults['style'] = 'Inline';
275 * Build the form object.
279 public function buildQuickForm() {
280 $session = CRM_Core_Session
::singleton();
282 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
284 if (!$this->_cancelURL
) {
285 if ($this->_isTemplate
) {
286 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/eventTemplate',
291 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/event/manage',
297 if ($this->_cancelURL
) {
298 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
301 if ($this->_single
) {
305 'name' => ts('Save'),
310 'name' => ts('Save and Done'),
311 'spacing' => ' ',
316 'name' => ts('Cancel'),
319 $this->addButtons($buttons);
323 if (!$this->_first
) {
326 'name' => ts('Previous'),
327 'spacing' => ' ',
332 'name' => ts('Continue'),
333 'spacing' => ' ',
338 'name' => ts('Cancel'),
341 $this->addButtons($buttons);
343 $session->replaceUserContext($this->_cancelURL
);
344 $this->add('hidden', 'is_template', $this->_isTemplate
);
347 public function endPostProcess() {
348 // make submit buttons keep the current working tab opened.
349 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
350 $className = CRM_Utils_String
::getClassName($this->_name
);
352 // hack for special cases.
353 switch ($className) {
355 $attributes = $this->getVar('_attributes');
356 $subPage = strtolower(basename(CRM_Utils_Array
::value('action', $attributes)));
360 $subPage = 'settings';
363 case 'ScheduleReminders':
364 $subPage = 'reminder';
368 $subPage = strtolower($className);
372 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
373 array(1 => CRM_Utils_Array
::value('title', CRM_Utils_Array
::value($subPage, $this->get('tabHeader')), $className))
374 ), ts('Saved'), 'success');
376 $config = CRM_Core_Config
::singleton();
377 if (in_array('CiviCampaign', $config->enableComponents
)) {
378 $values = $this->controller
->exportValues($this->_name
);
379 $newCampaignID = CRM_Utils_Array
::value('campaign_id', $values);
380 $eventID = CRM_Utils_Array
::value('id', $values);
381 if ($eventID && $this->_campaignID
!= $newCampaignID) {
382 CRM_Event_BAO_Event
::updateParticipantCampaignID($eventID, $newCampaignID);
385 $this->postProcessHook();
386 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_done") {
387 if ($this->_isTemplate
) {
388 CRM_Core_Session
::singleton()
389 ->pushUserContext(CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1'));
392 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/event/manage', 'reset=1'));
396 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url("civicrm/event/manage/{$subPage}",
397 "action=update&reset=1&id={$this->_id}"
406 public function getTemplateFileName() {
407 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
$this->_action
& CRM_Core_Action
::DELETE
) {
408 return parent
::getTemplateFileName();
411 // hack lets suppress the form rendering for now
412 self
::$_template->assign('isForm', FALSE);
413 return 'CRM/Event/Form/ManageEvent/Tab.tpl';
418 * Pre-load libraries required by Online Registration Profile fields
420 public static function addProfileEditScripts() {
421 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
422 CRM_UF_Page_ProfileEditor
::registerSchemas(array('IndividualModel', 'ParticipantModel'));