3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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 * Function to set variables up before form is built
94 function preProcess() {
95 $config = CRM_Core_Config
::singleton();
96 if (in_array('CiviEvent', $config->enableComponents
)) {
97 $this->assign('CiviEvent', TRUE);
100 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
102 $this->assign('action', $this->_action
);
104 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
106 $this->assign('eventId', $this->_id
);
107 if (empty($this->_addProfileBottom
) && empty($this->_addProfileBottomAdd
)) {
108 $this->add('hidden', 'id', $this->_id
);
110 $this->_single
= TRUE;
112 $params = array('id' => $this->_id
);
113 CRM_Event_BAO_Event
::retrieve($params, $eventInfo);
115 // its an update mode, do a permission check
116 if (!CRM_Event_BAO_Event
::checkPermission($this->_id
, CRM_Core_Permission
::EDIT
)) {
117 CRM_Core_Error
::fatal(ts('You do not have permission to access this page'));
120 $participantListingID = CRM_Utils_Array
::value('participant_listing_id', $eventInfo);
121 //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' );
122 if ($participantListingID) {
123 $participantListingURL = CRM_Utils_System
::url('civicrm/event/participant',
124 "reset=1&id={$this->_id}",
125 TRUE, NULL, TRUE, TRUE
127 $this->assign('participantListingURL', $participantListingURL);
130 $this->assign('isOnlineRegistration', CRM_Utils_Array
::value('is_online_registration', $eventInfo));
132 $this->assign('id', $this->_id
);
135 // figure out whether we’re handling an event or an event template
137 $this->_isTemplate
= CRM_Utils_Array
::value('is_template', $eventInfo);
139 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
140 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
143 $this->assign('isTemplate', $this->_isTemplate
);
146 if ($this->_isTemplate
) {
147 $title = CRM_Utils_Array
::value('template_title', $eventInfo);
148 CRM_Utils_System
::setTitle(ts('Edit Event Template') . " - $title");
151 $title = CRM_Utils_Array
::value('title', $eventInfo);
152 CRM_Utils_System
::setTitle(ts('Configure Event') . " - $title");
154 $this->assign('title', $title);
156 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
157 if ($this->_isTemplate
) {
158 $title = ts('New Event Template');
159 CRM_Utils_System
::setTitle($title);
162 $title = ts('New Event');
163 CRM_Utils_System
::setTitle($title);
165 $this->assign('title', $title);
168 if (CRM_Core_Permission
::check('view event participants') &&
169 CRM_Core_Permission
::check('view all contacts')
171 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
172 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
173 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
174 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
175 $this->assign('findParticipants', $findParticipants);
178 $this->_templateId
= (int) CRM_Utils_Request
::retrieve('template_id', 'Integer', $this);
181 CRM_Event_Form_ManageEvent_TabHeader
::build($this);
183 // Set Done button URL and breadcrumb. Templates go back to Manage Templates,
184 // otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
185 $breadCrumb = array();
186 if (!$this->_isTemplate
) {
188 $this->_doneUrl
= CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
189 "action=update&reset=1&id={$this->_id}"
193 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/event/manage',
196 $breadCrumb = array(array('title' => ts('Manage Events'),
197 'url' => $this->_doneUrl
,
202 $this->_doneUrl
= CRM_Utils_System
::url('civicrm/admin/eventTemplate', 'reset=1');
203 $breadCrumb = array(array('title' => ts('Manage Event Templates'),
204 'url' => $this->_doneUrl
,
207 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
211 * This function sets the default values for the form. For edit/view mode
212 * the default values are retrieved from the database
218 function setDefaultValues() {
220 if (isset($this->_id
)) {
221 $params = array('id' => $this->_id
);
222 CRM_Event_BAO_Event
::retrieve($params, $defaults);
224 $this->_campaignID
= CRM_Utils_Array
::value('campaign_id', $defaults);
226 elseif ($this->_templateId
) {
227 $params = array('id' => $this->_templateId
);
228 CRM_Event_BAO_Event
::retrieve($params, $defaults);
229 $defaults['is_template'] = $this->_isTemplate
;
230 $defaults['template_id'] = $defaults['id'];
231 unset($defaults['id']);
234 $defaults['is_active'] = 1;
235 $defaults['style'] = 'Inline';
242 * Function to build the form
247 public function buildQuickForm() {
248 $session = CRM_Core_Session
::singleton();
250 $this->_cancelURL
= CRM_Utils_Array
::value('cancelURL', $_POST);
252 if (!$this->_cancelURL
) {
253 if ($this->_isTemplate
) {
254 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/admin/eventTemplate',
259 $this->_cancelURL
= CRM_Utils_System
::url('civicrm/event/manage',
265 if ($this->_cancelURL
) {
266 $this->addElement('hidden', 'cancelURL', $this->_cancelURL
);
269 if ($this->_single
) {
273 'name' => ts('Save'),
278 'name' => ts('Save and Done'),
279 'spacing' => ' ',
284 'name' => ts('Cancel'),
287 $this->addButtons($buttons);
291 if (!$this->_first
) {
294 'name' => ts('<< Previous'),
295 'spacing' => ' ',
300 'name' => ts('Continue >>'),
301 'spacing' => ' ',
306 'name' => ts('Cancel'),
309 $this->addButtons($buttons);
311 $session->replaceUserContext($this->_cancelURL
);
312 $this->add('hidden', 'is_template', $this->_isTemplate
);
315 function endPostProcess() {
316 // make submit buttons keep the current working tab opened.
317 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
318 $className = CRM_Utils_String
::getClassName($this->_name
);
320 // hack for special cases.
321 switch ($className) {
323 $attributes = $this->getVar('_attributes');
324 $subPage = strtolower(basename(CRM_Utils_Array
::value('action', $attributes)));
328 $subPage = 'settings';
331 case 'ScheduleReminders':
332 $subPage = 'reminder';
336 $subPage = strtolower($className);
340 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
341 array(1 => ($subPage == 'friend') ?
'Friend' : $className)
342 ), ts('Saved'), 'success');
344 $config = CRM_Core_Config
::singleton();
345 if (in_array('CiviCampaign', $config->enableComponents
)) {
346 $values = $this->controller
->exportValues($this->_name
);
347 $newCampaignID = CRM_Utils_Array
::value('campaign_id', $values);
348 $eventID = CRM_Utils_Array
::value('id', $values);
349 if ($eventID && $this->_campaignID
!= $newCampaignID) {
350 CRM_Event_BAO_Event
::updateParticipantCampaignID($eventID, $newCampaignID);
354 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_done") {
355 if ($this->_isTemplate
) {
356 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/eventTemplate',
361 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/event/manage',
367 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/event/manage/{$subPage}",
368 "action=update&reset=1&id={$this->_id}"
374 function getTemplateFileName() {
375 if ($this->controller
->getPrint() == CRM_Core_Smarty
::PRINT_NOFORM ||
376 $this->getVar('_id') <= 0 ||
377 ($this->_action
& CRM_Core_Action
::DELETE
)
379 return parent
::getTemplateFileName();
382 // hack lets suppress the form rendering for now
383 self
::$_template->assign('isForm', FALSE);
384 return 'CRM/Event/Form/ManageEvent/Tab.tpl';