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 public $_isRepeatingEvent;
91 * Explicitly declare the entity api name.
93 public $entityName = 'Event';
96 * Set variables up before form is built.
100 public function preProcess() {
101 $config = CRM_Core_Config
::singleton();
102 if (in_array('CiviEvent', $config->enableComponents
)) {
103 $this->assign('CiviEvent', TRUE);
105 CRM_Core_Form_RecurringEntity
::preProcess('civicrm_event');
107 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
109 $this->assign('action', $this->_action
);
111 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
113 $this->_isRepeatingEvent
= CRM_Core_BAO_RecurringEntity
::getParentFor($this->_id
, 'civicrm_event');
114 $this->assign('eventId', $this->_id
);
115 if (!empty($this->_addBlockName
) && empty($this->_addProfileBottom
) && empty($this->_addProfileBottomAdd
)) {
116 $this->add('hidden', 'id', $this->_id
);
118 $this->_single
= TRUE;
120 $params = array('id' => $this->_id
);
121 CRM_Event_BAO_Event
::retrieve($params, $eventInfo);
123 // its an update mode, do a permission check
124 if (!CRM_Event_BAO_Event
::checkPermission($this->_id
, CRM_Core_Permission
::EDIT
)) {
125 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
128 $participantListingID = CRM_Utils_Array
::value('participant_listing_id', $eventInfo);
129 //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' );
130 if ($participantListingID) {
131 $participantListingURL = CRM_Utils_System
::url('civicrm/event/participant',
132 "reset=1&id={$this->_id}",
133 TRUE, NULL, TRUE, TRUE
135 $this->assign('participantListingURL', $participantListingURL);
138 $this->assign('isOnlineRegistration', CRM_Utils_Array
::value('is_online_registration', $eventInfo));
140 $this->assign('id', $this->_id
);
143 // figure out whether we’re handling an event or an event template
145 $this->_isTemplate
= CRM_Utils_Array
::value('is_template', $eventInfo);
147 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
148 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
151 $this->assign('isTemplate', $this->_isTemplate
);
154 if ($this->_isTemplate
) {
155 $title = CRM_Utils_Array
::value('template_title', $eventInfo);
156 CRM_Utils_System
::setTitle(ts('Edit Event Template') . " - $title");
159 $configureText = ts('Configure Event');
160 $title = CRM_Utils_Array
::value('title', $eventInfo);
161 //If it is a repeating event change title
162 if ($this->_isRepeatingEvent
) {
163 $configureText = 'Configure Repeating Event';
165 CRM_Utils_System
::setTitle($configureText . " - $title");
167 $this->assign('title', $title);
169 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
170 if ($this->_isTemplate
) {
171 $title = ts('New Event Template');
172 CRM_Utils_System
::setTitle($title);
175 $title = ts('New Event');
176 CRM_Utils_System
::setTitle($title);
178 $this->assign('title', $title);
181 if (CRM_Core_Permission
::check('view event participants') &&
182 CRM_Core_Permission
::check('view all contacts')
184 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
185 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
186 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
187 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
188 $this->assign('findParticipants', $findParticipants);
191 $this->_templateId
= (int) CRM_Utils_Request
::retrieve('template_id', 'Integer', $this);
193 //Is a repeating event
194 if ($this->_isRepeatingEvent
) {
195 $isRepeatingEntity = TRUE;
196 $this->assign('isRepeatingEntity', $isRepeatingEntity);
200 CRM_Event_Form_ManageEvent_TabHeader
::build($this);
202 // Set Done button URL and breadcrumb. Templates go back to Manage Templates,
203 // otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
204 $breadCrumb = array();
205 if (!$this->_isTemplate
) {
207 $this->_doneUrl
= CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
208 "action=update&reset=1&id={$this->_id}"
212 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/event/manage',
217 'title' => ts('Manage Events'),
218 'url' => $this->_doneUrl
,
224 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1');
227 'title' => ts('Manage Event Templates'),
228 'url' => $this->_doneUrl
,
232 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
236 * Set default values for the form. For edit/view mode
237 * the default values are retrieved from the database
242 public function setDefaultValues() {
244 if (isset($this->_id
)) {
245 $params = array('id' => $this->_id
);
246 CRM_Event_BAO_Event
::retrieve($params, $defaults);
248 $this->_campaignID
= CRM_Utils_Array
::value('campaign_id', $defaults);
250 elseif ($this->_templateId
) {
251 $params = array('id' => $this->_templateId
);
252 CRM_Event_BAO_Event
::retrieve($params, $defaults);
253 $defaults['is_template'] = $this->_isTemplate
;
254 $defaults['template_id'] = $defaults['id'];
255 unset($defaults['id']);
258 $defaults['is_active'] = 1;
259 $defaults['style'] = 'Inline';
266 * Build the form object.
270 public function buildQuickForm() {
271 $session = CRM_Core_Session
::singleton();
273 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
275 if (!$this->_cancelURL
) {
276 if ($this->_isTemplate
) {
277 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/eventTemplate',
282 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/event/manage',
288 if ($this->_cancelURL
) {
289 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
292 if ($this->_single
) {
296 'name' => ts('Save'),
301 'name' => ts('Save and Done'),
302 'spacing' => ' ',
307 'name' => ts('Cancel'),
310 $this->addButtons($buttons);
314 if (!$this->_first
) {
317 'name' => ts('Previous'),
318 'spacing' => ' ',
323 'name' => ts('Continue'),
324 'spacing' => ' ',
329 'name' => ts('Cancel'),
332 $this->addButtons($buttons);
334 $session->replaceUserContext($this->_cancelURL
);
335 $this->add('hidden', 'is_template', $this->_isTemplate
);
338 public function endPostProcess() {
339 // make submit buttons keep the current working tab opened.
340 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
341 $className = CRM_Utils_String
::getClassName($this->_name
);
343 // hack for special cases.
344 switch ($className) {
346 $attributes = $this->getVar('_attributes');
347 $subPage = strtolower(basename(CRM_Utils_Array
::value('action', $attributes)));
351 $subPage = 'settings';
354 case 'ScheduleReminders':
355 $subPage = 'reminder';
359 $subPage = strtolower($className);
363 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
364 array(1 => CRM_Utils_Array
::value('title', CRM_Utils_Array
::value($subPage, $this->get('tabHeader')), $className))
365 ), ts('Saved'), 'success');
367 $config = CRM_Core_Config
::singleton();
368 if (in_array('CiviCampaign', $config->enableComponents
)) {
369 $values = $this->controller
->exportValues($this->_name
);
370 $newCampaignID = CRM_Utils_Array
::value('campaign_id', $values);
371 $eventID = CRM_Utils_Array
::value('id', $values);
372 if ($eventID && $this->_campaignID
!= $newCampaignID) {
373 CRM_Event_BAO_Event
::updateParticipantCampaignID($eventID, $newCampaignID);
376 $this->postProcessHook();
377 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_done") {
378 if ($this->_isTemplate
) {
379 CRM_Core_Session
::singleton()
380 ->pushUserContext(CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1'));
383 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/event/manage', 'reset=1'));
387 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url("civicrm/event/manage/{$subPage}",
388 "action=update&reset=1&id={$this->_id}"
397 public function getTemplateFileName() {
398 if ($this->controller
->getPrint() ||
$this->getVar('_id') <= 0 ||
$this->_action
& CRM_Core_Action
::DELETE
) {
399 return parent
::getTemplateFileName();
402 // hack lets suppress the form rendering for now
403 self
::$_template->assign('isForm', FALSE);
404 return 'CRM/Event/Form/ManageEvent/Tab.tpl';
409 * Pre-load libraries required by Online Registration Profile fields
411 public static function addProfileEditScripts() {
412 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
413 CRM_UF_Page_ProfileEditor
::registerSchemas(array('IndividualModel', 'ParticipantModel'));