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 * Set variables up before form is built.
102 public function preProcess() {
103 $config = CRM_Core_Config
::singleton();
104 if (in_array('CiviEvent', $config->enableComponents
)) {
105 $this->assign('CiviEvent', TRUE);
107 CRM_Core_Form_RecurringEntity
::preProcess('civicrm_event');
109 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
111 $this->assign('action', $this->_action
);
113 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
115 $this->_isRepeatingEvent
= CRM_Core_BAO_RecurringEntity
::getParentFor($this->_id
, 'civicrm_event');
116 $this->assign('eventId', $this->_id
);
117 if (!empty($this->_addBlockName
) && empty($this->_addProfileBottom
) && empty($this->_addProfileBottomAdd
)) {
118 $this->add('hidden', 'id', $this->_id
);
120 $this->_single
= TRUE;
122 $params = array('id' => $this->_id
);
123 CRM_Event_BAO_Event
::retrieve($params, $eventInfo);
125 // its an update mode, do a permission check
126 if (!CRM_Event_BAO_Event
::checkPermission($this->_id
, CRM_Core_Permission
::EDIT
)) {
127 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
130 $participantListingID = CRM_Utils_Array
::value('participant_listing_id', $eventInfo);
131 //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' );
132 if ($participantListingID) {
133 $participantListingURL = CRM_Utils_System
::url('civicrm/event/participant',
134 "reset=1&id={$this->_id}",
135 TRUE, NULL, TRUE, TRUE
137 $this->assign('participantListingURL', $participantListingURL);
140 $this->assign('isOnlineRegistration', CRM_Utils_Array
::value('is_online_registration', $eventInfo));
142 $this->assign('id', $this->_id
);
145 // figure out whether we’re handling an event or an event template
147 $this->_isTemplate
= CRM_Utils_Array
::value('is_template', $eventInfo);
149 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
150 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
153 $this->assign('isTemplate', $this->_isTemplate
);
156 if ($this->_isTemplate
) {
157 $title = CRM_Utils_Array
::value('template_title', $eventInfo);
158 CRM_Utils_System
::setTitle(ts('Edit Event Template') . " - $title");
161 $configureText = ts('Configure Event');
162 $title = CRM_Utils_Array
::value('title', $eventInfo);
163 //If it is a repeating event change title
164 if ($this->_isRepeatingEvent
) {
165 $configureText = 'Configure Repeating Event';
167 CRM_Utils_System
::setTitle($configureText . " - $title");
169 $this->assign('title', $title);
171 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
172 if ($this->_isTemplate
) {
173 $title = ts('New Event Template');
174 CRM_Utils_System
::setTitle($title);
177 $title = ts('New Event');
178 CRM_Utils_System
::setTitle($title);
180 $this->assign('title', $title);
183 if (CRM_Core_Permission
::check('view event participants') &&
184 CRM_Core_Permission
::check('view all contacts')
186 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
187 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
188 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
189 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
190 $this->assign('findParticipants', $findParticipants);
193 $this->_templateId
= (int) CRM_Utils_Request
::retrieve('template_id', 'Integer', $this);
195 //Is a repeating event
196 if ($this->_isRepeatingEvent
) {
197 $isRepeatingEntity = TRUE;
198 $this->assign('isRepeatingEntity', $isRepeatingEntity);
202 CRM_Event_Form_ManageEvent_TabHeader
::build($this);
204 // Set Done button URL and breadcrumb. Templates go back to Manage Templates,
205 // otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
206 $breadCrumb = array();
207 if (!$this->_isTemplate
) {
209 $this->_doneUrl
= CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
210 "action=update&reset=1&id={$this->_id}"
214 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/event/manage',
219 'title' => ts('Manage Events'),
220 'url' => $this->_doneUrl
,
226 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1');
229 'title' => ts('Manage Event Templates'),
230 'url' => $this->_doneUrl
,
234 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
238 * Set default values for the form. For edit/view mode
239 * the default values are retrieved from the database
244 public function setDefaultValues() {
246 if (isset($this->_id
)) {
247 $params = array('id' => $this->_id
);
248 CRM_Event_BAO_Event
::retrieve($params, $defaults);
250 $this->_campaignID
= CRM_Utils_Array
::value('campaign_id', $defaults);
252 elseif ($this->_templateId
) {
253 $params = array('id' => $this->_templateId
);
254 CRM_Event_BAO_Event
::retrieve($params, $defaults);
255 $defaults['is_template'] = $this->_isTemplate
;
256 $defaults['template_id'] = $defaults['id'];
257 unset($defaults['id']);
260 $defaults['is_active'] = 1;
261 $defaults['style'] = 'Inline';
268 * Build the form object.
272 public function buildQuickForm() {
273 $session = CRM_Core_Session
::singleton();
275 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
277 if (!$this->_cancelURL
) {
278 if ($this->_isTemplate
) {
279 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/eventTemplate',
284 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/event/manage',
290 if ($this->_cancelURL
) {
291 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
294 if ($this->_single
) {
298 'name' => ts('Save'),
303 'name' => ts('Save and Done'),
304 'spacing' => ' ',
309 'name' => ts('Cancel'),
312 $this->addButtons($buttons);
316 if (!$this->_first
) {
319 'name' => ts('Previous'),
320 'spacing' => ' ',
325 'name' => ts('Continue'),
326 'spacing' => ' ',
331 'name' => ts('Cancel'),
334 $this->addButtons($buttons);
336 $session->replaceUserContext($this->_cancelURL
);
337 $this->add('hidden', 'is_template', $this->_isTemplate
);
340 public function endPostProcess() {
341 // make submit buttons keep the current working tab opened.
342 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
343 $className = CRM_Utils_String
::getClassName($this->_name
);
345 // hack for special cases.
346 switch ($className) {
348 $attributes = $this->getVar('_attributes');
349 $subPage = strtolower(basename(CRM_Utils_Array
::value('action', $attributes)));
353 $subPage = 'settings';
356 case 'ScheduleReminders':
357 $subPage = 'reminder';
361 $subPage = strtolower($className);
365 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
366 array(1 => CRM_Utils_Array
::value('title', CRM_Utils_Array
::value($subPage, $this->get('tabHeader')), $className))
367 ), ts('Saved'), 'success');
369 $config = CRM_Core_Config
::singleton();
370 if (in_array('CiviCampaign', $config->enableComponents
)) {
371 $values = $this->controller
->exportValues($this->_name
);
372 $newCampaignID = CRM_Utils_Array
::value('campaign_id', $values);
373 $eventID = CRM_Utils_Array
::value('id', $values);
374 if ($eventID && $this->_campaignID
!= $newCampaignID) {
375 CRM_Event_BAO_Event
::updateParticipantCampaignID($eventID, $newCampaignID);
378 $this->postProcessHook();
379 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_done") {
380 if ($this->_isTemplate
) {
381 CRM_Core_Session
::singleton()
382 ->pushUserContext(CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1'));
385 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/event/manage', 'reset=1'));
389 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url("civicrm/event/manage/{$subPage}",
390 "action=update&reset=1&id={$this->_id}"
399 public function getTemplateFileName() {
400 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
$this->_action
& CRM_Core_Action
::DELETE
) {
401 return parent
::getTemplateFileName();
404 // hack lets suppress the form rendering for now
405 self
::$_template->assign('isForm', FALSE);
406 return 'CRM/Event/Form/ManageEvent/Tab.tpl';
411 * Pre-load libraries required by Online Registration Profile fields
413 public static function addProfileEditScripts() {
414 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
415 CRM_UF_Page_ProfileEditor
::registerSchemas(array('IndividualModel', 'ParticipantModel'));