3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2018
34 * This class generates form components for processing Event.
36 class CRM_Event_Form_ManageEvent_EventInfo
extends CRM_Event_Form_ManageEvent
{
41 protected $_eventType = NULL;
44 * Set variables up before form is built.
46 public function preProcess() {
50 $this->assign('entityID', $this->_id
);
51 $eventType = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
60 $showLocation = FALSE;
61 // when custom data is included in this page
62 if (!empty($_POST['hidden_custom'])) {
63 $this->set('type', 'Event');
64 $this->set('subType', CRM_Utils_Array
::value('event_type_id', $_POST));
65 $this->assign('customDataSubType', CRM_Utils_Array
::value('event_type_id', $_POST));
66 $this->set('entityId', $this->_id
);
68 CRM_Custom_Form_CustomData
::preProcess($this, NULL, $this->_eventType
, 1, 'Event', $this->_id
);
69 CRM_Custom_Form_CustomData
::buildQuickForm($this);
70 CRM_Custom_Form_CustomData
::setDefaultValues($this);
75 * Set default values for the form.
77 * For edit/view mode he default values are retrieved from the database.
79 public function setDefaultValues() {
80 $defaults = parent
::setDefaultValues();
82 // in update mode, we need to set custom data subtype to tpl
83 if (!empty($defaults['event_type_id'])) {
84 $this->assign('customDataSubType', $defaults['event_type_id']);
87 $this->_showHide
= new CRM_Core_ShowHideBlocks();
88 // Show waitlist features or event_full_text if max participants set
89 if (!empty($defaults['max_participants'])) {
90 $this->_showHide
->addShow('id-waitlist');
91 if (!empty($defaults['has_waitlist'])) {
92 $this->_showHide
->addShow('id-waitlist-text');
93 $this->_showHide
->addHide('id-event_full');
96 $this->_showHide
->addHide('id-waitlist-text');
97 $this->_showHide
->addShow('id-event_full');
101 $this->_showHide
->addHide('id-event_full');
102 $this->_showHide
->addHide('id-waitlist');
103 $this->_showHide
->addHide('id-waitlist-text');
106 $this->_showHide
->addToTemplate();
107 $this->assign('elemType', 'table-row');
109 $this->assign('description', CRM_Utils_Array
::value('description', $defaults));
111 // Provide suggested text for event full and waitlist messages if they're empty
112 $defaults['event_full_text'] = CRM_Utils_Array
::value('event_full_text', $defaults, ts('This event is currently full.'));
114 $defaults['waitlist_text'] = CRM_Utils_Array
::value('waitlist_text', $defaults, ts('This event is currently full. However you can register now and get added to a waiting list. You will be notified if spaces become available.'));
115 list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date
::setDateDefaults(CRM_Utils_Array
::value('start_date', $defaults), 'activityDateTime');
117 if (!empty($defaults['end_date'])) {
118 list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date
::setDateDefaults($defaults['end_date'], 'activityDateTime');
124 * Build the form object.
126 public function buildQuickForm() {
127 //need to assign custom data type and subtype to the template
128 $this->assign('customDataType', 'Event');
129 if ($this->_eventType
) {
130 $this->assign('customDataSubType', $this->_eventType
);
132 $this->assign('entityId', $this->_id
);
134 $this->_first
= TRUE;
135 $this->applyFilter('__ALL__', 'trim');
136 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
138 if ($this->_isTemplate
) {
139 $this->add('text', 'template_title', ts('Template Title'), $attributes['template_title'], TRUE);
142 if ($this->_action
& CRM_Core_Action
::ADD
) {
143 $eventTemplates = CRM_Event_PseudoConstant
::eventTemplates();
144 if (CRM_Utils_System
::isNull($eventTemplates) && !$this->_isTemplate
) {
145 $url = CRM_Utils_System
::url('civicrm/admin/eventTemplate', array('reset' => 1));
146 CRM_Core_Session
::setStatus(ts('If you find that you are creating multiple events with similar settings, you may want to use the <a href="%1">Event Templates</a> feature to streamline your workflow.', array(1 => $url)), ts('Tip'), 'info');
148 if (!CRM_Utils_System
::isNull($eventTemplates)) {
149 $this->add('select', 'template_id', ts('From Template'), array('' => ts('- select -')) +
$eventTemplates, FALSE, array('class' => 'crm-select2 huge'));
151 // Make sure this form redirects properly
152 $this->preventAjaxSubmit();
155 // add event title, make required if this is not a template
156 $this->add('text', 'title', ts('Event Title'), $attributes['event_title'], !$this->_isTemplate
);
158 $this->addSelect('event_type_id',
159 array('onChange' => "CRM.buildCustomData( 'Event', this.value );"),
163 //CRM-7362 --add campaigns.
166 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_id
, 'campaign_id');
168 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
170 $this->addSelect('default_role_id', array(), TRUE);
172 $this->addSelect('participant_listing_id', array('placeholder' => ts('Disabled'), 'option_url' => NULL));
174 $this->add('textarea', 'summary', ts('Event Summary'), $attributes['summary']);
175 $this->add('wysiwyg', 'description', ts('Complete Description'), $attributes['event_description'] +
array('preset' => 'civievent'));
176 $this->addElement('checkbox', 'is_public', ts('Public Event'));
177 $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
178 $this->addElement('checkbox', 'is_map', ts('Include Map to Event Location'));
180 $this->addDateTime('start_date', ts('Start Date'), FALSE, array('formatType' => 'activityDateTime'));
181 $this->addDateTime('end_date', ts('End Date / Time'), FALSE, array('formatType' => 'activityDateTime'));
183 $this->add('text', 'max_participants', ts('Max Number of Participants'),
184 array('onchange' => "if (this.value != '') {cj('#id-waitlist').show(); showHideByValue('has_waitlist','0','id-waitlist-text','table-row','radio',false); showHideByValue('has_waitlist','0','id-event_full','table-row','radio',true); return;} else {cj('#id-event_full, #id-waitlist, #id-waitlist-text').hide(); return;}")
186 $this->addRule('max_participants', ts('Max participants should be a positive number'), 'positiveInteger');
188 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
190 if (in_array('On waitlist', $participantStatuses) and in_array('Pending from waitlist', $participantStatuses)) {
191 $this->addElement('checkbox', 'has_waitlist', ts('Offer a Waitlist?'), NULL, array('onclick' => "showHideByValue('has_waitlist','0','id-event_full','table-row','radio',true); showHideByValue('has_waitlist','0','id-waitlist-text','table-row','radio',false);"));
192 $this->add('textarea', 'waitlist_text', ts('Waitlist Message'), $attributes['waitlist_text']);
195 $this->assign('waitlist', $waitlist);
197 $this->add('textarea', 'event_full_text', ts('Message if Event Is Full'), $attributes['event_full_text']);
199 $this->addElement('checkbox', 'is_active', ts('Is this Event Active?'));
201 $this->addFormRule(array('CRM_Event_Form_ManageEvent_EventInfo', 'formRule'));
203 parent
::buildQuickForm();
207 * Global validation rules for the form.
209 * @param array $values
212 * list of errors to be posted back to the form
214 public static function formRule($values) {
217 if (!$values['is_template']) {
218 if (CRM_Utils_System
::isNull($values['start_date'])) {
219 $errors['start_date'] = ts('Start Date and Time are required fields');
222 $start = CRM_Utils_Date
::processDate($values['start_date']);
223 $end = CRM_Utils_Date
::processDate($values['end_date']);
224 if (($end < $start) && ($end != 0)) {
225 $errors['end_date'] = ts('End date should be after Start date.');
231 if (strstr($values['title'], '/')) {
232 $errors['title'] = ts("Please do not use '/' in Event Title.");
239 * Process the form submission.
241 public function postProcess() {
242 $params = $this->controller
->exportValues($this->_name
);
245 $params['start_date'] = CRM_Utils_Date
::processDate($params['start_date'], $params['start_date_time']);
246 $params['end_date'] = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('end_date', $params),
247 CRM_Utils_Array
::value('end_date_time', $params),
250 $params['has_waitlist'] = CRM_Utils_Array
::value('has_waitlist', $params, FALSE);
251 $params['is_map'] = CRM_Utils_Array
::value('is_map', $params, FALSE);
252 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
253 $params['is_public'] = CRM_Utils_Array
::value('is_public', $params, FALSE);
254 $params['is_share'] = CRM_Utils_Array
::value('is_share', $params, FALSE);
255 $params['default_role_id'] = CRM_Utils_Array
::value('default_role_id', $params, FALSE);
256 $params['id'] = $this->_id
;
258 $customFields = CRM_Core_BAO_CustomField
::getFields('Event', FALSE, FALSE,
259 CRM_Utils_Array
::value('event_type_id', $params)
261 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
266 //merge params with defaults from templates
267 if (!empty($params['template_id'])) {
268 $params = array_merge(CRM_Event_BAO_Event
::getTemplateDefaultValues($params['template_id']), $params);
271 $event = CRM_Event_BAO_Event
::create($params);
273 // now that we have the event’s id, do some more template-based stuff
274 if (!empty($params['template_id'])) {
275 CRM_Event_BAO_Event
::copy($params['template_id'], $event, TRUE);
278 $this->set('id', $event->id
);
280 $this->postProcessHook();
282 if ($this->_action
& CRM_Core_Action
::ADD
) {
283 $url = 'civicrm/event/manage/location';
284 $urlParams = "action=update&reset=1&id={$event->id}";
285 // special case for 'Save and Done' consistency.
286 if ($this->controller
->getButtonName('submit') == '_qf_EventInfo_upload_done') {
287 $url = 'civicrm/event/manage';
288 $urlParams = 'reset=1';
289 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
290 array(1 => $this->getTitle())
291 ), ts('Saved'), 'success');
294 CRM_Utils_System
::redirect(CRM_Utils_System
::url($url, $urlParams));
297 parent
::endPostProcess();
301 * Return a descriptive name for the page, used in wizard header.
305 public function getTitle() {
306 return ts('Event Information and Settings');