Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
6a488035 | 29 | * @package CRM |
fa938177 | 30 | * @copyright CiviCRM LLC (c) 2004-2016 |
6a488035 TO |
31 | */ |
32 | ||
33 | /** | |
3bdf1f3a | 34 | * This class generates form components for processing Event. |
6a488035 TO |
35 | */ |
36 | class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { | |
37 | ||
38 | /** | |
66f9e52b | 39 | * Event type. |
6a488035 TO |
40 | */ |
41 | protected $_eventType = NULL; | |
42 | ||
43 | /** | |
66f9e52b | 44 | * Set variables up before form is built. |
6a488035 | 45 | */ |
00be9182 | 46 | public function preProcess() { |
2a4e505f | 47 | parent::preProcess(); |
6a488035 TO |
48 | |
49 | if ($this->_id) { | |
50 | $this->assign('entityID', $this->_id); | |
51 | $eventType = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', | |
52 | $this->_id, | |
53 | 'event_type_id' | |
54 | ); | |
55 | } | |
56 | else { | |
57 | $eventType = 'null'; | |
58 | } | |
59 | ||
60 | $showLocation = FALSE; | |
61 | // when custom data is included in this page | |
a7488080 | 62 | if (!empty($_POST['hidden_custom'])) { |
6a488035 TO |
63 | $this->set('type', 'Event'); |
64 | $this->set('subType', CRM_Utils_Array::value('event_type_id', $_POST)); | |
65 | $this->set('entityId', $this->_id); | |
66 | ||
f19dc468 | 67 | CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_eventType, 1, 'Event', $this->_id); |
6a488035 TO |
68 | CRM_Custom_Form_CustomData::buildQuickForm($this); |
69 | CRM_Custom_Form_CustomData::setDefaultValues($this); | |
70 | } | |
71 | } | |
72 | ||
73 | /** | |
3bdf1f3a | 74 | * Set default values for the form. |
6a488035 | 75 | * |
3bdf1f3a | 76 | * For edit/view mode he default values are retrieved from the database. |
6a488035 | 77 | */ |
00be9182 | 78 | public function setDefaultValues() { |
6a488035 TO |
79 | $defaults = parent::setDefaultValues(); |
80 | ||
81 | // in update mode, we need to set custom data subtype to tpl | |
a7488080 | 82 | if (!empty($defaults['event_type_id'])) { |
6a488035 TO |
83 | $this->assign('customDataSubType', $defaults['event_type_id']); |
84 | } | |
85 | ||
86 | $this->_showHide = new CRM_Core_ShowHideBlocks(); | |
87 | // Show waitlist features or event_full_text if max participants set | |
a7488080 | 88 | if (!empty($defaults['max_participants'])) { |
6a488035 | 89 | $this->_showHide->addShow('id-waitlist'); |
a7488080 | 90 | if (!empty($defaults['has_waitlist'])) { |
6a488035 TO |
91 | $this->_showHide->addShow('id-waitlist-text'); |
92 | $this->_showHide->addHide('id-event_full'); | |
93 | } | |
94 | else { | |
95 | $this->_showHide->addHide('id-waitlist-text'); | |
96 | $this->_showHide->addShow('id-event_full'); | |
97 | } | |
98 | } | |
99 | else { | |
100 | $this->_showHide->addHide('id-event_full'); | |
101 | $this->_showHide->addHide('id-waitlist'); | |
102 | $this->_showHide->addHide('id-waitlist-text'); | |
103 | } | |
104 | ||
105 | $this->_showHide->addToTemplate(); | |
106 | $this->assign('elemType', 'table-row'); | |
107 | ||
108 | $this->assign('description', CRM_Utils_Array::value('description', $defaults)); | |
109 | ||
110 | // Provide suggested text for event full and waitlist messages if they're empty | |
111 | $defaults['event_full_text'] = CRM_Utils_Array::value('event_full_text', $defaults, ts('This event is currently full.')); | |
112 | ||
113 | $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.')); | |
114 | list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('start_date', $defaults), 'activityDateTime'); | |
115 | ||
a7488080 | 116 | if (!empty($defaults['end_date'])) { |
6a488035 TO |
117 | list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['end_date'], 'activityDateTime'); |
118 | } | |
119 | return $defaults; | |
120 | } | |
121 | ||
122 | /** | |
66f9e52b | 123 | * Build the form object. |
6a488035 TO |
124 | */ |
125 | public function buildQuickForm() { | |
6a488035 TO |
126 | //need to assign custom data type and subtype to the template |
127 | $this->assign('customDataType', 'Event'); | |
128 | if ($this->_eventType) { | |
129 | $this->assign('customDataSubType', $this->_eventType); | |
130 | } | |
131 | $this->assign('entityId', $this->_id); | |
132 | ||
133 | $this->_first = TRUE; | |
134 | $this->applyFilter('__ALL__', 'trim'); | |
135 | $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event'); | |
136 | ||
137 | if ($this->_isTemplate) { | |
138 | $this->add('text', 'template_title', ts('Template Title'), $attributes['template_title'], TRUE); | |
139 | } | |
140 | ||
141 | if ($this->_action & CRM_Core_Action::ADD) { | |
142 | $eventTemplates = CRM_Event_PseudoConstant::eventTemplates(); | |
143 | if (CRM_Utils_System::isNull($eventTemplates) && !$this->_isTemplate) { | |
144 | $url = CRM_Utils_System::url('civicrm/admin/eventTemplate', array('reset' => 1)); | |
145 | 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'); | |
146 | } | |
147 | if (!CRM_Utils_System::isNull($eventTemplates)) { | |
a2015e41 | 148 | $this->add('select', 'template_id', ts('From Template'), array('' => ts('- select -')) + $eventTemplates, FALSE, array('class' => 'crm-select2 huge')); |
6a488035 | 149 | } |
bfd83a87 CW |
150 | // Make sure this form redirects properly |
151 | $this->preventAjaxSubmit(); | |
6a488035 TO |
152 | } |
153 | ||
154 | // add event title, make required if this is not a template | |
155 | $this->add('text', 'title', ts('Event Title'), $attributes['event_title'], !$this->_isTemplate); | |
156 | ||
e1462487 CW |
157 | $this->addSelect('event_type_id', |
158 | array('onChange' => "CRM.buildCustomData( 'Event', this.value );"), | |
159 | TRUE | |
6a488035 TO |
160 | ); |
161 | ||
162 | //CRM-7362 --add campaigns. | |
163 | $campaignId = NULL; | |
164 | if ($this->_id) { | |
165 | $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'campaign_id'); | |
166 | } | |
167 | CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); | |
168 | ||
e1462487 | 169 | $this->addSelect('default_role_id', array(), TRUE); |
6a488035 | 170 | |
3a6b5d94 | 171 | $this->addSelect('participant_listing_id', array('placeholder' => ts('Disabled'), 'option_url' => NULL)); |
6a488035 TO |
172 | |
173 | $this->add('textarea', 'summary', ts('Event Summary'), $attributes['summary']); | |
5d51a2f9 | 174 | $this->add('wysiwyg', 'description', ts('Complete Description'), $attributes['event_description']); |
0781df9b | 175 | $this->addElement('checkbox', 'is_public', ts('Public Event')); |
6a488035 | 176 | $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?')); |
0781df9b | 177 | $this->addElement('checkbox', 'is_map', ts('Include Map to Event Location')); |
6a488035 TO |
178 | |
179 | $this->addDateTime('start_date', ts('Start Date'), FALSE, array('formatType' => 'activityDateTime')); | |
180 | $this->addDateTime('end_date', ts('End Date / Time'), FALSE, array('formatType' => 'activityDateTime')); | |
181 | ||
182 | $this->add('text', 'max_participants', ts('Max Number of Participants'), | |
183 | 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;}") | |
184 | ); | |
185 | $this->addRule('max_participants', ts('Max participants should be a positive number'), 'positiveInteger'); | |
186 | ||
187 | $participantStatuses = CRM_Event_PseudoConstant::participantStatus(); | |
188 | $waitlist = 0; | |
189 | if (in_array('On waitlist', $participantStatuses) and in_array('Pending from waitlist', $participantStatuses)) { | |
190 | $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);")); | |
191 | $this->add('textarea', 'waitlist_text', ts('Waitlist Message'), $attributes['waitlist_text']); | |
192 | $waitlist = 1; | |
193 | } | |
194 | $this->assign('waitlist', $waitlist); | |
195 | ||
196 | $this->add('textarea', 'event_full_text', ts('Message if Event Is Full'), $attributes['event_full_text']); | |
197 | ||
198 | $this->addElement('checkbox', 'is_active', ts('Is this Event Active?')); | |
199 | ||
200 | $this->addFormRule(array('CRM_Event_Form_ManageEvent_EventInfo', 'formRule')); | |
201 | ||
202 | parent::buildQuickForm(); | |
203 | } | |
204 | ||
205 | /** | |
66f9e52b | 206 | * Global validation rules for the form. |
6a488035 | 207 | * |
c490a46a | 208 | * @param array $values |
6a488035 | 209 | * |
a6c01b45 CW |
210 | * @return array |
211 | * list of errors to be posted back to the form | |
6a488035 | 212 | */ |
00be9182 | 213 | public static function formRule($values) { |
6a488035 TO |
214 | $errors = array(); |
215 | ||
216 | if (!$values['is_template']) { | |
217 | if (CRM_Utils_System::isNull($values['start_date'])) { | |
218 | $errors['start_date'] = ts('Start Date and Time are required fields'); | |
219 | } | |
220 | else { | |
221 | $start = CRM_Utils_Date::processDate($values['start_date']); | |
222 | $end = CRM_Utils_Date::processDate($values['end_date']); | |
223 | if (($end < $start) && ($end != 0)) { | |
9a0187a0 | 224 | $errors['end_date'] = ts('End date should be after Start date.'); |
6a488035 TO |
225 | } |
226 | } | |
227 | } | |
228 | ||
229 | //CRM-4286 | |
230 | if (strstr($values['title'], '/')) { | |
231 | $errors['title'] = ts("Please do not use '/' in Event Title."); | |
232 | } | |
233 | ||
234 | return $errors; | |
235 | } | |
236 | ||
237 | /** | |
66f9e52b | 238 | * Process the form submission. |
6a488035 TO |
239 | */ |
240 | public function postProcess() { | |
241 | $params = $this->controller->exportValues($this->_name); | |
242 | ||
243 | //format params | |
244 | $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']); | |
245 | $params['end_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('end_date', $params), | |
246 | CRM_Utils_Array::value('end_date_time', $params), | |
247 | TRUE | |
248 | ); | |
249 | $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, FALSE); | |
250 | $params['is_map'] = CRM_Utils_Array::value('is_map', $params, FALSE); | |
251 | $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); | |
252 | $params['is_public'] = CRM_Utils_Array::value('is_public', $params, FALSE); | |
253 | $params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE); | |
254 | $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, FALSE); | |
255 | $params['id'] = $this->_id; | |
256 | ||
257 | $customFields = CRM_Core_BAO_CustomField::getFields('Event', FALSE, FALSE, | |
258 | CRM_Utils_Array::value('event_type_id', $params) | |
259 | ); | |
260 | $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, | |
6a488035 TO |
261 | $this->_id, |
262 | 'Event' | |
263 | ); | |
264 | ||
265 | //merge params with defaults from templates | |
a7488080 | 266 | if (!empty($params['template_id'])) { |
6a488035 TO |
267 | $params = array_merge(CRM_Event_BAO_Event::getTemplateDefaultValues($params['template_id']), $params); |
268 | } | |
269 | ||
270 | $event = CRM_Event_BAO_Event::create($params); | |
271 | ||
272 | // now that we have the event’s id, do some more template-based stuff | |
a7488080 | 273 | if (!empty($params['template_id'])) { |
6a488035 | 274 | CRM_Event_BAO_Event::copy($params['template_id'], $event, TRUE); |
6a488035 | 275 | } |
03e04002 | 276 | |
6a488035 TO |
277 | $this->set('id', $event->id); |
278 | ||
c654c119 | 279 | $this->postProcessHook(); |
280 | ||
6a488035 TO |
281 | if ($this->_action & CRM_Core_Action::ADD) { |
282 | $url = 'civicrm/event/manage/location'; | |
283 | $urlParams = "action=update&reset=1&id={$event->id}"; | |
284 | // special case for 'Save and Done' consistency. | |
285 | if ($this->controller->getButtonName('submit') == '_qf_EventInfo_upload_done') { | |
286 | $url = 'civicrm/event/manage'; | |
287 | $urlParams = 'reset=1'; | |
288 | CRM_Core_Session::setStatus(ts("'%1' information has been saved.", | |
353ffa53 TO |
289 | array(1 => $this->getTitle()) |
290 | ), ts('Saved'), 'success'); | |
6a488035 TO |
291 | } |
292 | ||
293 | CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams)); | |
294 | } | |
295 | ||
296 | parent::endPostProcess(); | |
297 | } | |
6a488035 TO |
298 | |
299 | /** | |
3bdf1f3a | 300 | * Return a descriptive name for the page, used in wizard header. |
6a488035 TO |
301 | * |
302 | * @return string | |
6a488035 TO |
303 | */ |
304 | public function getTitle() { | |
305 | return ts('Event Information and Settings'); | |
306 | } | |
307 | ||
6a488035 | 308 | } |