| @@ -87,16 +87,19 @@ | ||
| 87 | 87 | |
| 88 | 88 | $locationType = Arr::get($postedData, 'location_type'); |
| 89 | 89 | |
| 90 | 90 | if ($calendarEvent->isPhoneRequired()) { |
| 91 | - $rules['location_description'] = 'required'; | |
| 91 | + $rules['location_description'] = ['required', $this->validPhoneNumberRule()]; | |
| 92 | 92 | $messages['location_description.required'] = __('Please provide attendee\'s phone number', 'fluent-booking'); |
| 93 | 93 | } else if ($calendarEvent->isAddressRequired()) { |
| 94 | 94 | $rules['location_description'] = 'required'; |
| 95 | 95 | $messages['location_description.required'] = __('Please provide attendee\'s address', 'fluent-booking'); |
| 96 | + } else if ($locationType === 'phone_guest') { | |
| 97 | + $rules['location_description'] = [$this->validPhoneNumberRule()]; | |
| 96 | 98 | } |
| 97 | 99 | |
| 98 | - if ($additionalGuests = Arr::get($postedData, 'guests', [])) { | |
| 100 | + $additionalGuests = Arr::get($postedData, 'guests', []); | |
| 101 | + if (!empty($additionalGuests)) { | |
| 99 | 102 | if ($calendarEvent->isMultiGuestEvent()) { |
| 100 | 103 | $additionalGuests = $this->sanitize_mapped_data($additionalGuests); |
| 101 | 104 | $additionalGuests = array_values(array_filter($additionalGuests, function ($guest) { |
| 102 | 105 | return Arr::get($guest, 'name') && Arr::get($guest, 'email'); |
| @@ -146,27 +149,27 @@ | ||
| 146 | 149 | return; |
| 147 | 150 | } |
| 148 | 151 | |
| 149 | 152 | $duration = $calendarEvent->getDuration(Arr::get($postedData, 'duration', null)); |
| 150 | - $timezone = Arr::get($postedData, 'timezone', 'UTC'); | |
| 153 | + $timezone = sanitize_text_field($postedData['timezone']); | |
| 151 | 154 | |
| 152 | - $startDateTime = DateTimeHelper::convertToUtc($postedData['event_time'], $timezone); | |
| 155 | + $startDateTime = DateTimeHelper::convertToUtc(sanitize_text_field($postedData['event_time']), $timezone); | |
| 153 | 156 | $endDateTime = gmdate('Y-m-d H:i:s', strtotime($startDateTime) + ($duration * 60)); |
| 154 | 157 | |
| 155 | - $bookingData = [ | |
| 156 | - 'person_time_zone' => sanitize_text_field($timezone), | |
| 158 | + $bookingData = apply_filters('fluent_booking/initialize_booking_data', [ | |
| 159 | + 'person_time_zone' => $timezone, | |
| 157 | 160 | 'start_time' => $startDateTime, |
| 158 | 161 | 'name' => sanitize_text_field($postedData['name']), |
| 159 | 162 | 'email' => sanitize_email($postedData['email']), |
| 160 | 163 | 'message' => sanitize_textarea_field(wp_unslash(Arr::get($postedData, 'message', ''))), |
| 161 | - 'phone' => sanitize_textarea_field(Arr::get($postedData, 'phone_number', '')), | |
| 164 | + 'phone' => sanitize_text_field(Arr::get($postedData, 'phone_number', '')), | |
| 162 | 165 | 'address' => sanitize_textarea_field(Arr::get($postedData, 'address', '')), |
| 163 | 166 | 'ip_address' => Helper::getIp(), |
| 164 | - 'status' => sanitize_text_field($postedData['status']), | |
| 165 | - 'source' => 'admin', | |
| 167 | + 'status' => sanitize_text_field(Arr::get($postedData, 'status', 'scheduled')), | |
| 168 | + 'source' => Arr::get($postedData, 'source') == 'admin' ? 'admin' : 'web', | |
| 166 | 169 | 'event_type' => $calendarEvent->event_type, |
| 167 | 170 | 'slot_minutes' => $duration |
| 168 | - ]; | |
| 171 | + ], $postedData, $calendarEvent); | |
| 169 | 172 | |
| 170 | 173 | $eventLocations = []; |
| 171 | 174 | $locationSettings = $calendarEvent->location_settings; |
| 172 | 175 | foreach ($locationSettings as $index => $location) { |
| @@ -176,11 +179,11 @@ | ||
| 176 | 179 | $locationDetails['type'] = $locationType; |
| 177 | 180 | if ($locationType == 'phone_organizer') { |
| 178 | 181 | $locationDetails['description'] = $eventLocations[$locationType]['host_phone_number']; |
| 179 | 182 | } else if ($locationType == 'phone_guest') { |
| 180 | - $bookingData['phone'] = Arr::get($postedData, 'location_description', ''); | |
| 183 | + $bookingData['phone'] = sanitize_text_field(Arr::get($postedData, 'location_description', '')); | |
| 181 | 184 | } else if ($locationType == 'in_person_guest') { |
| 182 | - $locationDetails['description'] = Arr::get($postedData, 'location_description', ''); | |
| 185 | + $locationDetails['description'] = sanitize_textarea_field(Arr::get($postedData, 'location_description', '')); | |
| 183 | 186 | } else if (in_array($locationType, ['custom', 'in_person_organizer'])) { |
| 184 | 187 | $locationDetails['description'] = $eventLocations[$locationType]['description']; |
| 185 | 188 | } else if (in_array($locationType, ['google_meet', 'online_meeting', 'zoom_meeting', 'ms_teams'])) { |
| 186 | 189 | $locationDetails['description'] = Arr::get($eventLocations[$locationType], 'meeting_link', ''); |
| @@ -193,9 +196,17 @@ | ||
| 193 | 196 | $bookingData['source_url'] = sanitize_url($sourceUrl); |
| 194 | 197 | } |
| 195 | 198 | |
| 196 | 199 | if ($hostUserId = Arr::get($postedData, 'host_user_id', null)) { |
| 197 | - $bookingData['host_user_id'] = (int)$hostUserId; | |
| 200 | + $hostUserId = (int) $hostUserId; | |
| 201 | + | |
| 202 | + if (!in_array($hostUserId, array_map('intval', $calendarEvent->getHostIds()), true)) { | |
| 203 | + return $this->sendError([ | |
| 204 | + 'message' => __('The selected host is not a host of this event', 'fluent-booking') | |
| 205 | + ], 422); | |
| 206 | + } | |
| 207 | + | |
| 208 | + $bookingData['host_user_id'] = $hostUserId; | |
| 198 | 209 | } |
| 199 | 210 | |
| 200 | 211 | $hostIds = null; |
| 201 | 212 | if ($calendarEvent->isRoundRobin() && !$hostUserId) { |
| @@ -251,8 +262,20 @@ | ||
| 251 | 262 | 'message' => __('Booking has been created', 'fluent-booking'), |
| 252 | 263 | ]; |
| 253 | 264 | } |
| 254 | 265 | |
| 266 | + /** | |
| 267 | + * @return \Closure | |
| 268 | + */ | |
| 269 | + private function validPhoneNumberRule() | |
| 270 | + { | |
| 271 | + return function ($attribute, $value) { | |
| 272 | + if (!empty($value) && !Helper::isValidPhoneNumber($value)) { | |
| 273 | + return __('Please provide a valid phone number', 'fluent-booking'); | |
| 274 | + } | |
| 275 | + }; | |
| 276 | + } | |
| 277 | + | |
| 255 | 278 | public function getEvent(Request $request, $eventId) |
| 256 | 279 | { |
| 257 | 280 | $calendarEvent = CalendarSlot::find($eventId); |
| 258 | 281 | |
| @@ -290,9 +313,19 @@ | ||
| 290 | 313 | |
| 291 | 314 | $duration = $calendarEvent->getDuration($request->get('duration')); |
| 292 | 315 | |
| 293 | 316 | $hostId = $request->get('host_id', null); |
| 294 | - | |
| 317 | + | |
| 318 | + if ($hostId) { | |
| 319 | + $hostId = (int) $hostId; | |
| 320 | + | |
| 321 | + if (!in_array($hostId, array_map('intval', $calendarEvent->getHostIds()), true)) { | |
| 322 | + wp_send_json([ | |
| 323 | + 'message' => __('The selected host is not a host of this event', 'fluent-booking') | |
| 324 | + ], 422); | |
| 325 | + } | |
| 326 | + } | |
| 327 | + | |
| 295 | 328 | $timeSlotService = TimeSlotServiceHandler::initService($calendar, $calendarEvent); |
| 296 | 329 | |
| 297 | 330 | if (is_wp_error($timeSlotService)) { |
| 298 | 331 | return TimeSlotServiceHandler::sendError($timeSlotService, $calendarEvent, $timeZone); |
| @@ -360,9 +393,9 @@ | ||
| 360 | 393 | 'payment_status' => $booking->payment_status, |
| 361 | 394 | 'booking_title' => $booking->getBookingTitle(true), |
| 362 | 395 | 'author_name' => $booking->getHostDetails(false)['name'], |
| 363 | 396 | 'booking_date' => DateTimeHelper::formatToLocale($booking->getAttendeeStartTime(), 'date'), |
| 364 | - 'booking_time' => DateTimeHelper::formatToLocale($booking->getAttendeeEndTime(), 'time') . ' - ' . DateTimeHelper::formatToLocale($booking->getAttendeeEndTime(), 'time'), | |
| 397 | + 'booking_time' => DateTimeHelper::formatToLocale($booking->getAttendeeStartTime(), 'time') . ' - ' . DateTimeHelper::formatToLocale($booking->getAttendeeEndTime(), 'time'), | |
| 365 | 398 | ]; |
| 366 | 399 | } |
| 367 | 400 | |
| 368 | 401 | return [ |