3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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
51 * Is this the first page?
56 protected $_first = FALSE;
59 * Are we in single form mode or wizard mode?
69 * Are we actually managing an event template?
72 protected $_isTemplate = FALSE;
75 * Pre-populate fields based on this template event_id
78 protected $_templateId;
80 protected $_cancelURL = NULL;
83 * The campaign id of the existing event, we use this to know if we need to update
84 * the participant records
86 protected $_campaignID = NULL;
89 * Check if repeating event
91 protected $_isRepeatingEvent;
94 * Set variables up before form is built
99 function preProcess() {
100 $config = CRM_Core_Config
::singleton();
101 if (in_array('CiviEvent', $config->enableComponents
)) {
102 $this->assign('CiviEvent', TRUE);
105 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
107 $this->assign('action', $this->_action
);
109 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
111 $this->_isRepeatingEvent
= CRM_Core_BAO_RecurringEntity
::getParentFor($this->_id
, 'civicrm_event');
112 $this->assign('eventId', $this->_id
);
113 if (!empty($this->_addBlockName
) && empty($this->_addProfileBottom
) && empty($this->_addProfileBottomAdd
)) {
114 $this->add('hidden', 'id', $this->_id
);
116 $this->_single
= TRUE;
118 $params = array('id' => $this->_id
);
119 CRM_Event_BAO_Event
::retrieve($params, $eventInfo);
121 // its an update mode, do a permission check
122 if (!CRM_Event_BAO_Event
::checkPermission($this->_id
, CRM_Core_Permission
::EDIT
)) {
123 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
126 $participantListingID = CRM_Utils_Array
::value('participant_listing_id', $eventInfo);
127 //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' );
128 if ($participantListingID) {
129 $participantListingURL = CRM_Utils_System
::url('civicrm/event/participant',
130 "reset=1&id={$this->_id}",
131 TRUE, NULL, TRUE, TRUE
133 $this->assign('participantListingURL', $participantListingURL);
136 $this->assign('isOnlineRegistration', CRM_Utils_Array
::value('is_online_registration', $eventInfo));
138 $this->assign('id', $this->_id
);
141 // figure out whether we’re handling an event or an event template
143 $this->_isTemplate
= CRM_Utils_Array
::value('is_template', $eventInfo);
145 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
146 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
149 $this->assign('isTemplate', $this->_isTemplate
);
152 if ($this->_isTemplate
) {
153 $title = CRM_Utils_Array
::value('template_title', $eventInfo);
154 CRM_Utils_System
::setTitle(ts('Edit Event Template') . " - $title");
157 $configureText = ts('Configure Event');
158 $title = CRM_Utils_Array
::value('title', $eventInfo);
159 //If it is a repeating event change title
160 if ($this->_isRepeatingEvent
) {
161 $configureText = 'Configure Repeating Event';
163 CRM_Utils_System
::setTitle($configureText . " - $title");
165 $this->assign('title', $title);
167 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
168 if ($this->_isTemplate
) {
169 $title = ts('New Event Template');
170 CRM_Utils_System
::setTitle($title);
173 $title = ts('New Event');
174 CRM_Utils_System
::setTitle($title);
176 $this->assign('title', $title);
179 if (CRM_Core_Permission
::check('view event participants') &&
180 CRM_Core_Permission
::check('view all contacts')
182 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
183 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
184 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
185 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
186 $this->assign('findParticipants', $findParticipants);
189 $this->_templateId
= (int) CRM_Utils_Request
::retrieve('template_id', 'Integer', $this);
191 //Is a repeating event
192 if ($this->_isRepeatingEvent
) {
193 $isRepeatingEntity = TRUE;
194 $this->assign('isRepeatingEntity', $isRepeatingEntity);
198 CRM_Event_Form_ManageEvent_TabHeader
::build($this);
200 // Set Done button URL and breadcrumb. Templates go back to Manage Templates,
201 // otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
202 $breadCrumb = array();
203 if (!$this->_isTemplate
) {
205 $this->_doneUrl
= CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
206 "action=update&reset=1&id={$this->_id}"
210 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/event/manage',
213 $breadCrumb = array(array('title' => ts('Manage Events'),
214 'url' => $this->_doneUrl
,
219 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1');
220 $breadCrumb = array(array('title' => ts('Manage Event Templates'),
221 'url' => $this->_doneUrl
,
224 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
228 * Set default values for the form. For edit/view mode
229 * the default values are retrieved from the database
235 function setDefaultValues() {
237 if (isset($this->_id
)) {
238 $params = array('id' => $this->_id
);
239 CRM_Event_BAO_Event
::retrieve($params, $defaults);
241 $this->_campaignID
= CRM_Utils_Array
::value('campaign_id', $defaults);
243 elseif ($this->_templateId
) {
244 $params = array('id' => $this->_templateId
);
245 CRM_Event_BAO_Event
::retrieve($params, $defaults);
246 $defaults['is_template'] = $this->_isTemplate
;
247 $defaults['template_id'] = $defaults['id'];
248 unset($defaults['id']);
251 $defaults['is_active'] = 1;
252 $defaults['style'] = 'Inline';
259 * Build the form object
264 public function buildQuickForm() {
265 $session = CRM_Core_Session
::singleton();
267 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
269 if (!$this->_cancelURL
) {
270 if ($this->_isTemplate
) {
271 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/eventTemplate',
276 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/event/manage',
282 if ($this->_cancelURL
) {
283 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
286 if ($this->_single
) {
290 'name' => ts('Save'),
295 'name' => ts('Save and Done'),
296 'spacing' => ' ',
301 'name' => ts('Cancel'),
304 $this->addButtons($buttons);
308 if (!$this->_first
) {
311 'name' => ts('<< Previous'),
312 'spacing' => ' ',
317 'name' => ts('Continue >>'),
318 'spacing' => ' ',
323 'name' => ts('Cancel'),
326 $this->addButtons($buttons);
328 $session->replaceUserContext($this->_cancelURL
);
329 $this->add('hidden', 'is_template', $this->_isTemplate
);
332 function endPostProcess() {
333 // make submit buttons keep the current working tab opened.
334 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
335 $className = CRM_Utils_String
::getClassName($this->_name
);
337 // hack for special cases.
338 switch ($className) {
340 $attributes = $this->getVar('_attributes');
341 $subPage = strtolower(basename(CRM_Utils_Array
::value('action', $attributes)));
345 $subPage = 'settings';
348 case 'ScheduleReminders':
349 $subPage = 'reminder';
353 $subPage = strtolower($className);
357 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
358 array(1 => CRM_Utils_Array
::value('title', CRM_Utils_Array
::value($subPage, $this->get('tabHeader')), $className))
359 ), ts('Saved'), 'success');
361 $config = CRM_Core_Config
::singleton();
362 if (in_array('CiviCampaign', $config->enableComponents
)) {
363 $values = $this->controller
->exportValues($this->_name
);
364 $newCampaignID = CRM_Utils_Array
::value('campaign_id', $values);
365 $eventID = CRM_Utils_Array
::value('id', $values);
366 if ($eventID && $this->_campaignID
!= $newCampaignID) {
367 CRM_Event_BAO_Event
::updateParticipantCampaignID($eventID, $newCampaignID);
370 $this->postProcessHook();
371 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_done") {
372 if ($this->_isTemplate
) {
373 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1'));
376 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/event/manage', 'reset=1'));
380 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url("civicrm/event/manage/{$subPage}",
381 "action=update&reset=1&id={$this->_id}"
390 function getTemplateFileName() {
391 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
$this->_action
& CRM_Core_Action
::DELETE
) {
392 return parent
::getTemplateFileName();
395 // hack lets suppress the form rendering for now
396 self
::$_template->assign('isForm', FALSE);
397 return 'CRM/Event/Form/ManageEvent/Tab.tpl';
402 * Pre-load libraries required by Online Registration Profile fields
404 static function addProfileEditScripts() {
405 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
406 CRM_UF_Page_ProfileEditor
::registerSchemas(array('IndividualModel', 'ParticipantModel'));