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.
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 protected $_isRepeatingEvent;
91 * Set variables up before form is built.
95 public function preProcess() {
96 $config = CRM_Core_Config
::singleton();
97 if (in_array('CiviEvent', $config->enableComponents
)) {
98 $this->assign('CiviEvent', TRUE);
101 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
103 $this->assign('action', $this->_action
);
105 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
107 $this->_isRepeatingEvent
= CRM_Core_BAO_RecurringEntity
::getParentFor($this->_id
, 'civicrm_event');
108 $this->assign('eventId', $this->_id
);
109 if (!empty($this->_addBlockName
) && empty($this->_addProfileBottom
) && empty($this->_addProfileBottomAdd
)) {
110 $this->add('hidden', 'id', $this->_id
);
112 $this->_single
= TRUE;
114 $params = array('id' => $this->_id
);
115 CRM_Event_BAO_Event
::retrieve($params, $eventInfo);
117 // its an update mode, do a permission check
118 if (!CRM_Event_BAO_Event
::checkPermission($this->_id
, CRM_Core_Permission
::EDIT
)) {
119 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
122 $participantListingID = CRM_Utils_Array
::value('participant_listing_id', $eventInfo);
123 //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' );
124 if ($participantListingID) {
125 $participantListingURL = CRM_Utils_System
::url('civicrm/event/participant',
126 "reset=1&id={$this->_id}",
127 TRUE, NULL, TRUE, TRUE
129 $this->assign('participantListingURL', $participantListingURL);
132 $this->assign('isOnlineRegistration', CRM_Utils_Array
::value('is_online_registration', $eventInfo));
134 $this->assign('id', $this->_id
);
137 // figure out whether we’re handling an event or an event template
139 $this->_isTemplate
= CRM_Utils_Array
::value('is_template', $eventInfo);
141 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
142 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
145 $this->assign('isTemplate', $this->_isTemplate
);
148 if ($this->_isTemplate
) {
149 $title = CRM_Utils_Array
::value('template_title', $eventInfo);
150 CRM_Utils_System
::setTitle(ts('Edit Event Template') . " - $title");
153 $configureText = ts('Configure Event');
154 $title = CRM_Utils_Array
::value('title', $eventInfo);
155 //If it is a repeating event change title
156 if ($this->_isRepeatingEvent
) {
157 $configureText = 'Configure Repeating Event';
159 CRM_Utils_System
::setTitle($configureText . " - $title");
161 $this->assign('title', $title);
163 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
164 if ($this->_isTemplate
) {
165 $title = ts('New Event Template');
166 CRM_Utils_System
::setTitle($title);
169 $title = ts('New Event');
170 CRM_Utils_System
::setTitle($title);
172 $this->assign('title', $title);
175 if (CRM_Core_Permission
::check('view event participants') &&
176 CRM_Core_Permission
::check('view all contacts')
178 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
179 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
180 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
181 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
182 $this->assign('findParticipants', $findParticipants);
185 $this->_templateId
= (int) CRM_Utils_Request
::retrieve('template_id', 'Integer', $this);
187 //Is a repeating event
188 if ($this->_isRepeatingEvent
) {
189 $isRepeatingEntity = TRUE;
190 $this->assign('isRepeatingEntity', $isRepeatingEntity);
194 CRM_Event_Form_ManageEvent_TabHeader
::build($this);
196 // Set Done button URL and breadcrumb. Templates go back to Manage Templates,
197 // otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
198 $breadCrumb = array();
199 if (!$this->_isTemplate
) {
201 $this->_doneUrl
= CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
202 "action=update&reset=1&id={$this->_id}"
206 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/event/manage',
211 'title' => ts('Manage Events'),
212 'url' => $this->_doneUrl
,
218 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1');
221 'title' => ts('Manage Event Templates'),
222 'url' => $this->_doneUrl
,
226 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
230 * Set default values for the form. For edit/view mode
231 * the default values are retrieved from the database
236 public function setDefaultValues() {
238 if (isset($this->_id
)) {
239 $params = array('id' => $this->_id
);
240 CRM_Event_BAO_Event
::retrieve($params, $defaults);
242 $this->_campaignID
= CRM_Utils_Array
::value('campaign_id', $defaults);
244 elseif ($this->_templateId
) {
245 $params = array('id' => $this->_templateId
);
246 CRM_Event_BAO_Event
::retrieve($params, $defaults);
247 $defaults['is_template'] = $this->_isTemplate
;
248 $defaults['template_id'] = $defaults['id'];
249 unset($defaults['id']);
252 $defaults['is_active'] = 1;
253 $defaults['style'] = 'Inline';
260 * 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 public 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()
374 ->pushUserContext(CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1'));
377 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/event/manage', 'reset=1'));
381 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url("civicrm/event/manage/{$subPage}",
382 "action=update&reset=1&id={$this->_id}"
391 public function getTemplateFileName() {
392 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
$this->_action
& CRM_Core_Action
::DELETE
) {
393 return parent
::getTemplateFileName();
396 // hack lets suppress the form rendering for now
397 self
::$_template->assign('isForm', FALSE);
398 return 'CRM/Event/Form/ManageEvent/Tab.tpl';
403 * Pre-load libraries required by Online Registration Profile fields
405 public static function addProfileEditScripts() {
406 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
407 CRM_UF_Page_ProfileEditor
::registerSchemas(array('IndividualModel', 'ParticipantModel'));