| @@ -1,19 +1,19 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentBooking\App\Http\Controllers; |
| 4 | 4 | |
| 5 | -use FluentBooking\App\Models\Booking; | |
| 5 | +use FluentBooking\App\Models\Availability; | |
| 6 | 6 | use FluentBooking\App\Models\Calendar; |
| 7 | 7 | use FluentBooking\App\Models\CalendarSlot; |
| 8 | -use FluentBooking\App\Models\Availability; | |
| 9 | 8 | use FluentBooking\App\Services\Helper; |
| 10 | -use FluentBooking\App\Services\CurrenciesHelper; | |
| 11 | 9 | use FluentBooking\App\Services\LandingPage\LandingPageHelper; |
| 12 | 10 | use FluentBooking\App\Services\PermissionManager; |
| 13 | 11 | use FluentBooking\App\Services\AvailabilityService; |
| 14 | 12 | use FluentBooking\App\Services\SanitizeService; |
| 15 | 13 | use FluentBooking\App\Services\CalendarService; |
| 14 | +use FluentBooking\App\Services\OnboardingService; | |
| 15 | +use FluentBooking\App\Services\CalendarEventService; | |
| 16 | 16 | use FluentBooking\App\Services\BookingFieldService; |
| 17 | 17 | use FluentBooking\App\Hooks\Handlers\AdminMenuHandler; |
| 18 | 18 | use FluentBooking\Framework\Http\Request\Request; |
| 19 | 19 | use FluentBooking\Framework\Support\Arr; |
| @@ -33,9 +33,9 @@ | ||
| 33 | 33 | $query->where('title', 'LIKE', '%' . $search . '%'); |
| 34 | 34 | } |
| 35 | 35 | }; |
| 36 | 36 | |
| 37 | - $calendarsQuery = Calendar::with(['slots' => function($query) use ($applySearchFilter) { | |
| 37 | + $calendarsQuery = Calendar::with(['metas', 'slots' => function($query) use ($applySearchFilter) { | |
| 38 | 38 | $query->where($applySearchFilter); |
| 39 | 39 | }]) |
| 40 | 40 | ->where('status', '!=', 'expired'); |
| 41 | 41 | |
| @@ -48,9 +48,11 @@ | ||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | $calendarsQuery = $calendarsQuery->latest(); |
| 51 | 51 | |
| 52 | - if (!PermissionManager::hasAllCalendarAccess(true)) { | |
| 52 | + $hasPermission = PermissionManager::hasAllCalendarAccess(true); | |
| 53 | + | |
| 54 | + if (!$hasPermission) { | |
| 53 | 55 | $attachedCalendarIds = CalendarService::getAttachedCalendarIds($calendarsQuery); |
| 54 | 56 | $calendarsQuery->whereIn('id', $attachedCalendarIds); |
| 55 | 57 | } |
| 56 | 58 | |
| @@ -59,21 +61,29 @@ | ||
| 59 | 61 | foreach ($calendars as $calendar) { |
| 60 | 62 | $calendar->author_profile = $calendar->getAuthorProfile(); |
| 61 | 63 | $calendar->public_url = $calendar->getLandingPageUrl(); |
| 62 | 64 | $calendar->event_order = $calendar->getMeta('event_order'); |
| 65 | + | |
| 66 | + if (!$hasPermission) { | |
| 67 | + $calendar->setRelation('slots', $calendar->slots->filter(function ($slot) { | |
| 68 | + return CalendarEventService::isSharedCalendarEvent($slot); | |
| 69 | + })->values()); | |
| 70 | + } | |
| 71 | + | |
| 63 | 72 | foreach ($calendar->slots as $slot) { |
| 73 | + $slot->setRelation('calendar', $calendar); | |
| 64 | 74 | $slot->shortcode = '[fluent_booking id="' . $slot->id . '"]'; |
| 65 | 75 | $slot->public_url = $slot->getPublicUrl(); |
| 66 | 76 | $slot->duration = $slot->getDefaultDuration(); |
| 67 | - $slot->price_total = $slot->getPricingTotal(); | |
| 77 | + $slot->price_total = $slot->getEventPrice(); | |
| 68 | 78 | $slot->location_fields = $slot->getLocationFields(); |
| 69 | - $slot->short_description = Helper::excerpt($slot->getDescription()); | |
| 70 | 79 | $slot->author_profiles = $slot->isMultiHostEvent() ? $slot->getAuthorProfiles() : []; |
| 71 | 80 | do_action_ref_array('fluent_booking/calendar_slot', [&$slot]); |
| 81 | + $slot->unsetRelation('calendar'); | |
| 72 | 82 | } |
| 73 | 83 | |
| 74 | 84 | if(empty($calendar->author_profile['ID'])) { |
| 75 | - $calendar->generic_error = '<p style="color: red; margin:0;">Connected Host user is missing</p>'; | |
| 85 | + $calendar->generic_error = '<p style="color: var(--fcal-danger-fg); margin:0;">Connected Host user is missing</p>'; | |
| 76 | 86 | } |
| 77 | 87 | |
| 78 | 88 | do_action_ref_array('fluent_booking/calendar', [&$calendar, 'lists']); |
| 79 | 89 | } |
| @@ -103,9 +113,10 @@ | ||
| 103 | 113 | ], 422); |
| 104 | 114 | } |
| 105 | 115 | |
| 106 | 116 | return [ |
| 107 | - 'status' => true | |
| 117 | + 'status' => true, | |
| 118 | + 'message' => __('The provided slug is available', 'fluent-booking') | |
| 108 | 119 | ]; |
| 109 | 120 | } |
| 110 | 121 | |
| 111 | 122 | public function createCalendar(Request $request) |
| @@ -144,9 +155,9 @@ | ||
| 144 | 155 | $this->validate($data, $validationConfig['rules'], $validationConfig['messages']); |
| 145 | 156 | |
| 146 | 157 | do_action('fluent_booking/before_create_calendar', $data, $this); |
| 147 | 158 | |
| 148 | - if (!empty($data['user_id']) && PermissionManager::userCan('invite_team_members')) { | |
| 159 | + if (!empty($data['user_id']) && PermissionManager::userCan(['manage_all_data', 'invite_team_members'])) { | |
| 149 | 160 | $user = get_user_by('ID', $data['user_id']); |
| 150 | 161 | } else { |
| 151 | 162 | $user = get_user_by('ID', get_current_user_id()); |
| 152 | 163 | } |
| @@ -156,15 +167,25 @@ | ||
| 156 | 167 | 'message' => __('User not found', 'fluent-booking') |
| 157 | 168 | ], 422); |
| 158 | 169 | } |
| 159 | 170 | |
| 160 | - $type = sanitize_text_field(Arr::get($data, 'type', 'simple')); | |
| 171 | + $onboardinFeatures = $request->get('features'); | |
| 172 | + if (!empty($onboardinFeatures)) { | |
| 173 | + $installableAddons = SanitizeService::sanitizeAddons($onboardinFeatures); | |
| 174 | + OnboardingService::installAddons($installableAddons); | |
| 175 | + } | |
| 161 | 176 | |
| 177 | + $type = SanitizeService::checkCollection( | |
| 178 | + sanitize_text_field(Arr::get($data, 'type', 'simple')), | |
| 179 | + ['simple', 'team', 'event'], | |
| 180 | + 'simple' | |
| 181 | + ); | |
| 182 | + | |
| 162 | 183 | $isHostCalendar = $type == 'simple' ? true : false; |
| 163 | 184 | |
| 164 | 185 | if ($isHostCalendar && Calendar::where('user_id', $user->ID)->where('type', 'simple')->first()) { |
| 165 | 186 | return $this->sendError([ |
| 166 | - 'message' => __('The user already have a calendar. Please delete it first to create a new one', 'fluent-booking') | |
| 187 | + 'message' => __('The user already has a calendar. Please delete it first to create a new one', 'fluent-booking') | |
| 167 | 188 | ], 422); |
| 168 | 189 | } |
| 169 | 190 | |
| 170 | 191 | if ($isHostCalendar) { |
| @@ -180,10 +201,30 @@ | ||
| 180 | 201 | |
| 181 | 202 | if (!$isHostCalendar) { |
| 182 | 203 | $title = sanitize_text_field(Arr::get($data, 'title', '')); |
| 183 | 204 | $data['slug'] = sanitize_title($title, '', 'display'); |
| 184 | - $teamMembers = array_map('intval', Arr::get($slot, 'settings.team_members', [])); | |
| 185 | - if (!in_array($user->ID, $teamMembers)) { | |
| 205 | + $teamMembers = array_values(array_filter( | |
| 206 | + array_map('intval', (array) Arr::get($slot, 'settings.team_members', [])) | |
| 207 | + )); | |
| 208 | + | |
| 209 | + cache_users($teamMembers); | |
| 210 | + | |
| 211 | + foreach ($teamMembers as $memberId) { | |
| 212 | + if (!get_user_by('ID', $memberId)) { | |
| 213 | + return $this->sendError([ | |
| 214 | + 'message' => __('Invalid Team Member', 'fluent-booking') | |
| 215 | + ], 422); | |
| 216 | + } | |
| 217 | + } | |
| 218 | + | |
| 219 | + if (!in_array($user->ID, $teamMembers, true)) { | |
| 220 | + // Same privileged act as passing an explicit user_id above; gate it identically. | |
| 221 | + if (!PermissionManager::userCan(['manage_all_data', 'invite_team_members'])) { | |
| 222 | + return $this->sendError([ | |
| 223 | + 'message' => __('You are not allowed to create a calendar for another user', 'fluent-booking') | |
| 224 | + ], 403); | |
| 225 | + } | |
| 226 | + | |
| 186 | 227 | $user = get_user_by('ID', reset($teamMembers)); |
| 187 | 228 | if (!$user) { |
| 188 | 229 | return $this->sendError([ |
| 189 | 230 | 'message' => __('Invalid Team Member', 'fluent-booking') |
| @@ -238,13 +279,13 @@ | ||
| 238 | 279 | 'slug' => Helper::generateSlotSlug((int)$slot['duration'] . 'min', $calendar), |
| 239 | 280 | 'calendar_id' => $calendar->id, |
| 240 | 281 | 'user_id' => $calendar->user_id, |
| 241 | 282 | 'duration' => (int)$slot['duration'], |
| 242 | - 'description' => sanitize_textarea_field(Arr::get($slot, 'description')), | |
| 283 | + 'description' => wp_kses_post(Arr::get($slot, 'description')), | |
| 243 | 284 | 'settings' => [ |
| 244 | 285 | 'team_members' => !$isHostCalendar ? $teamMembers : [], |
| 245 | 286 | 'schedule_type' => sanitize_text_field($slot['schedule_type']), |
| 246 | - 'weekly_schedules' => SanitizeService::weeklySchedules($slot['weekly_schedules'], $calendar->author_timezone, 'UTC') | |
| 287 | + 'weekly_schedules' => SanitizeService::weeklySchedules($slot['weekly_schedules'], $calendar->author_timezone, 'UTC', true) | |
| 247 | 288 | ], |
| 248 | 289 | 'status' => SanitizeService::checkCollection($slot['status'], ['active', 'draft']), |
| 249 | 290 | 'color_schema' => sanitize_text_field(Arr::get($slot, 'color_schema', '#0099ff')), |
| 250 | 291 | 'event_type' => sanitize_text_field(Arr::get($slot, 'event_type')), |
| @@ -278,9 +319,28 @@ | ||
| 278 | 319 | $query->where('status', '!=', 'expired'); |
| 279 | 320 | }])->findOrFail($calendarId); |
| 280 | 321 | |
| 281 | 322 | $calendar->author_profile = $calendar->getAuthorProfile(); |
| 323 | + $calendar->event_order = $calendar->getMeta('event_order'); | |
| 282 | 324 | |
| 325 | + if (!PermissionManager::hasAllCalendarAccess(true)) { | |
| 326 | + $calendar->setRelation('slots', $calendar->slots->filter(function ($slot) { | |
| 327 | + return CalendarEventService::isSharedCalendarEvent($slot); | |
| 328 | + })->values()); | |
| 329 | + } | |
| 330 | + | |
| 331 | + foreach ($calendar->slots as $slot) { | |
| 332 | + $slot->setRelation('calendar', $calendar); | |
| 333 | + $slot->shortcode = '[fluent_booking id="' . $slot->id . '"]'; | |
| 334 | + $slot->public_url = $slot->getPublicUrl(); | |
| 335 | + $slot->duration = $slot->getDefaultDuration(); | |
| 336 | + $slot->price_total = $slot->getEventPrice(); | |
| 337 | + $slot->location_fields = $slot->getLocationFields(); | |
| 338 | + $slot->author_profiles = $slot->isMultiHostEvent() ? $slot->getAuthorProfiles() : []; | |
| 339 | + do_action_ref_array('fluent_booking/calendar_slot', [&$slot]); | |
| 340 | + $slot->unsetRelation('calendar'); | |
| 341 | + } | |
| 342 | + | |
| 283 | 343 | $data = [ |
| 284 | 344 | 'calendar' => $calendar |
| 285 | 345 | ]; |
| 286 | 346 | |
| @@ -287,8 +347,12 @@ | ||
| 287 | 347 | if (in_array('settings_menu', $request->get('with', []))) { |
| 288 | 348 | $data['settings_menu'] = AdminMenuHandler::getCalendarSettingsMenuItems($calendar); |
| 289 | 349 | } |
| 290 | 350 | |
| 351 | + if (in_array('public_url', $request->get('with', []))) { | |
| 352 | + $data['public_url'] = $calendar->getLandingPageUrl(); | |
| 353 | + } | |
| 354 | + | |
| 291 | 355 | return $data; |
| 292 | 356 | } |
| 293 | 357 | |
| 294 | 358 | public function getSharingSettings(Request $request, $calendarId) |
| @@ -309,9 +373,10 @@ | ||
| 309 | 373 | |
| 310 | 374 | if ($calendarDataItems) { |
| 311 | 375 | $this->validate($calendarDataItems, [ |
| 312 | 376 | 'title' => 'required', |
| 313 | - 'calendar_avatar' => 'url' | |
| 377 | + 'calendar_avatar' => 'nullable|url', | |
| 378 | + 'featured_image' => 'nullable|url' | |
| 314 | 379 | ]); |
| 315 | 380 | |
| 316 | 381 | $updatedTimezone = sanitize_text_field(Arr::get($calendarDataItems, 'timezone')); |
| 317 | 382 | if ($updatedTimezone && $updatedTimezone != $calendar->author_timezone) { |
| @@ -320,11 +385,11 @@ | ||
| 320 | 385 | } |
| 321 | 386 | |
| 322 | 387 | $calendar->title = sanitize_text_field(Arr::get($calendarDataItems, 'title')); |
| 323 | 388 | $calendar->description = wp_kses_post(Arr::get($calendarDataItems, 'description')); |
| 324 | - $calendar->save(); | |
| 325 | 389 | $calendar->updateMeta('profile_photo_url', sanitize_url(Arr::get($calendarDataItems, 'calendar_avatar'))); |
| 326 | 390 | $calendar->updateMeta('featured_image_url', sanitize_url(Arr::get($calendarDataItems, 'featured_image'))); |
| 391 | + $calendar->save(); | |
| 327 | 392 | |
| 328 | 393 | if ($calendar->user) { |
| 329 | 394 | $calendar->user->updateMeta('host_phone', sanitize_text_field(Arr::get($calendarDataItems, 'phone'))); |
| 330 | 395 | } |
| @@ -359,11 +424,11 @@ | ||
| 359 | 424 | 'message' => __('Calendar has been updated successfully', 'fluent-booking') |
| 360 | 425 | ]; |
| 361 | 426 | } |
| 362 | 427 | |
| 363 | - public function getEvent(Request $request, $calendarId, $slotId) | |
| 428 | + public function getEvent(Request $request, $calendarId, $eventId) | |
| 364 | 429 | { |
| 365 | - $calendarEvent = CalendarSlot::where('calendar_id', $calendarId)->with(['calendar.user'])->findOrFail($slotId); | |
| 430 | + $calendarEvent = CalendarSlot::where('calendar_id', $calendarId)->with(['calendar.user'])->findOrFail($eventId); | |
| 366 | 431 | |
| 367 | 432 | $calendarEvent->author_profile = $calendarEvent->getAuthorProfile(); |
| 368 | 433 | |
| 369 | 434 | $calendarEvent->calendar->author_profile = $calendarEvent->calendar->getAuthorProfile(); |
| @@ -377,8 +442,10 @@ | ||
| 377 | 442 | $eventSettings['date_overrides'] = (object)SanitizeService::slotDateOverrides(Arr::get($eventSettings, 'date_overrides', []), 'UTC', $calendarEvent->calendar->author_timezone, $calendarEvent); |
| 378 | 443 | |
| 379 | 444 | $eventSettings['location_fields'] = $calendarEvent->getLocationFields(); |
| 380 | 445 | |
| 446 | + $eventSettings['hosts_schedules'] = $calendarEvent->getHostsSchedules(); | |
| 447 | + | |
| 381 | 448 | $calendarEvent->settings = apply_filters('fluent_booking/get_calendar_event_settings', $eventSettings, $calendarEvent, $calendarEvent->calendar); |
| 382 | 449 | |
| 383 | 450 | $data = [ |
| 384 | 451 | 'calendar_event' => $calendarEvent |
| @@ -418,9 +485,9 @@ | ||
| 418 | 485 | 'slot' => $schema |
| 419 | 486 | ]; |
| 420 | 487 | } |
| 421 | 488 | |
| 422 | - public function getAvailabilitySettings(Request $request, $calendarId, $slotId) | |
| 489 | + public function getAvailabilitySettings(Request $request, $calendarId, $eventId) | |
| 423 | 490 | { |
| 424 | 491 | $availableSchedules = AvailabilityService::availabilitySchedules(); |
| 425 | 492 | |
| 426 | 493 | $scheduleOptions = AvailabilityService::getScheduleOptions(); |
| @@ -468,18 +535,18 @@ | ||
| 468 | 535 | |
| 469 | 536 | $availability = AvailabilityService::getDefaultSchedule($calendar->user_id); |
| 470 | 537 | |
| 471 | 538 | $slotData = [ |
| 472 | - 'title' => $slot['title'], | |
| 539 | + 'title' => sanitize_text_field($slot['title']), | |
| 473 | 540 | 'slug' => Helper::generateSlotSlug($slot['duration'] . 'min', $calendar), |
| 474 | 541 | 'calendar_id' => $calendar->id, |
| 475 | 542 | 'user_id' => $calendar->user_id, |
| 476 | 543 | 'duration' => (int)$slot['duration'], |
| 477 | - 'description' => sanitize_textarea_field(Arr::get($slot, 'description')), | |
| 544 | + 'description' => wp_kses_post(Arr::get($slot, 'description')), | |
| 478 | 545 | 'settings' => [ |
| 479 | 546 | 'schedule_type' => sanitize_text_field($slot['settings']['schedule_type']), |
| 480 | - 'weekly_schedules' => SanitizeService::weeklySchedules($slot['settings']['weekly_schedules'], $calendar->author_timezone, 'UTC'), | |
| 481 | - 'date_overrides' => SanitizeService::slotDateOverrides(Arr::get($slot['settings'], 'date_overrides', []), $calendar->author_timezone, 'UTC'), | |
| 547 | + 'weekly_schedules' => SanitizeService::weeklySchedules($slot['settings']['weekly_schedules'], $calendar->author_timezone, 'UTC', true), | |
| 548 | + 'date_overrides' => SanitizeService::slotDateOverrides(Arr::get($slot['settings'], 'date_overrides', []), $calendar->author_timezone, 'UTC', null, true), | |
| 482 | 549 | 'range_type' => sanitize_text_field(Arr::get($slot['settings'], 'range_type')), |
| 483 | 550 | 'range_days' => (int)(Arr::get($slot['settings'], 'range_days', 60)) ?: 60, |
| 484 | 551 | 'range_date_between' => SanitizeService::rangeDateBetween(Arr::get($slot['settings'], 'range_date_between', ['', ''])), |
| 485 | 552 | 'schedule_conditions' => SanitizeService::scheduleConditions(Arr::get($slot['settings'], 'schedule_conditions', [])), |
| @@ -567,9 +634,9 @@ | ||
| 567 | 634 | $event->title = sanitize_text_field($data['title']); |
| 568 | 635 | $event->duration = (int)$data['duration']; |
| 569 | 636 | $event->status = SanitizeService::checkCollection($data['status'], ['active', 'draft']); |
| 570 | 637 | $event->color_schema = sanitize_text_field(Arr::get($data, 'color_schema', '#0099ff')); |
| 571 | - $event->description = sanitize_textarea_field(Arr::get($data, 'description')); | |
| 638 | + $event->description = wp_kses_post(Arr::get($data, 'description')); | |
| 572 | 639 | $event->max_book_per_slot = (int)Arr::get($data, 'max_book_per_slot'); |
| 573 | 640 | $event->is_display_spots = (bool)Arr::get($data, 'is_display_spots'); |
| 574 | 641 | $event->location_settings = SanitizeService::locationSettings(Arr::get($data, 'location_settings', [])); |
| 575 | 642 | |
| @@ -596,12 +663,12 @@ | ||
| 596 | 663 | $data = $request->all(); |
| 597 | 664 | |
| 598 | 665 | $event = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($eventId); |
| 599 | 666 | |
| 600 | - $event->settings = [ | |
| 667 | + $eventSettings = [ | |
| 601 | 668 | 'schedule_type' => sanitize_text_field(Arr::get($data, 'schedule_type')), |
| 602 | - 'weekly_schedules' => SanitizeService::weeklySchedules(Arr::get($data, 'weekly_schedules'), $event->calendar->author_timezone, 'UTC'), | |
| 603 | - 'date_overrides' => SanitizeService::slotDateOverrides(Arr::get($data, 'date_overrides', []), $event->calendar->author_timezone, 'UTC'), | |
| 669 | + 'weekly_schedules' => SanitizeService::weeklySchedules(Arr::get($data, 'weekly_schedules'), $event->calendar->author_timezone, 'UTC', true), | |
| 670 | + 'date_overrides' => SanitizeService::slotDateOverrides(Arr::get($data, 'date_overrides', []), $event->calendar->author_timezone, 'UTC', null, true), | |
| 604 | 671 | 'range_type' => sanitize_text_field(Arr::get($data, 'range_type')), |
| 605 | 672 | 'range_days' => (int)(Arr::get($data, 'range_days', 60)) ?: 60, |
| 606 | 673 | 'range_date_between' => SanitizeService::rangeDateBetween(Arr::get($data, 'range_date_between', ['', ''])), |
| 607 | 674 | 'common_schedule' => Arr::isTrue($data, 'common_schedule', false) |
| @@ -606,11 +673,70 @@ | ||
| 606 | 673 | 'range_date_between' => SanitizeService::rangeDateBetween(Arr::get($data, 'range_date_between', ['', ''])), |
| 607 | 674 | 'common_schedule' => Arr::isTrue($data, 'common_schedule', false) |
| 608 | 675 | ]; |
| 609 | 676 | |
| 610 | - $event->availability_id = (int)Arr::get($data, 'availability_id'); | |
| 611 | - $event->availability_type = SanitizeService::checkCollection(Arr::get($data, 'availability_type'), ['existing_schedule', 'custom']); | |
| 677 | + $hostsSchedules = []; | |
| 612 | 678 | |
| 679 | + if ($event->isTeamEvent()) { | |
| 680 | + $hostsSchedules = array_map('intval', array_combine( | |
| 681 | + array_map('intval', array_keys(Arr::get($data, 'hosts_schedules', []))), | |
| 682 | + array_map('intval', Arr::get($data, 'hosts_schedules', [])) | |
| 683 | + )); | |
| 684 | + } | |
| 685 | + | |
| 686 | + $availabilityId = (int)Arr::get($data, 'availability_id'); | |
| 687 | + $availabilityType = SanitizeService::checkCollection(Arr::get($data, 'availability_type'), ['existing_schedule', 'custom']); | |
| 688 | + | |
| 689 | + $submittedIds = array_values(array_filter(array_unique(array_merge( | |
| 690 | + [$availabilityType === 'existing_schedule' ? $availabilityId : 0], | |
| 691 | + array_values($hostsSchedules) | |
| 692 | + )))); | |
| 693 | + | |
| 694 | + $usableIds = []; | |
| 695 | + $scheduleOwners = []; | |
| 696 | + | |
| 697 | + if ($submittedIds) { | |
| 698 | + $usableIds = array_map('intval', AvailabilityService::usableAvailabilityQuery() | |
| 699 | + ->whereIn('id', $submittedIds)->pluck('id')->toArray()); | |
| 700 | + | |
| 701 | + $scheduleOwners = array_map('intval', Availability::whereIn('id', $submittedIds) | |
| 702 | + ->pluck('object_id', 'id')->toArray()); | |
| 703 | + } | |
| 704 | + | |
| 705 | + foreach ($hostsSchedules as $hostId => $scheduleId) { | |
| 706 | + if (($scheduleOwners[$scheduleId] ?? 0) === (int)$hostId) { | |
| 707 | + continue; | |
| 708 | + } | |
| 709 | + | |
| 710 | + if (!in_array($scheduleId, $usableIds, true)) { | |
| 711 | + return $this->sendError([ | |
| 712 | + 'message' => __('You are not allowed to use the selected schedule', 'fluent-booking') | |
| 713 | + ], 403); | |
| 714 | + } | |
| 715 | + } | |
| 716 | + | |
| 717 | + if ($hostsSchedules) { | |
| 718 | + $eventSettings['hosts_schedules'] = $hostsSchedules; | |
| 719 | + } | |
| 720 | + | |
| 721 | + $eventHostIds = array_map('intval', array_merge( | |
| 722 | + $event->getHostIds(), | |
| 723 | + [$event->user_id, $event->calendar->user_id] | |
| 724 | + )); | |
| 725 | + | |
| 726 | + if ($availabilityType === 'existing_schedule' && $availabilityId | |
| 727 | + && !in_array($availabilityId, $usableIds, true) | |
| 728 | + && !in_array($scheduleOwners[$availabilityId] ?? 0, $eventHostIds, true)) { | |
| 729 | + return $this->sendError([ | |
| 730 | + 'message' => __('You are not allowed to use the selected schedule', 'fluent-booking') | |
| 731 | + ], 403); | |
| 732 | + } | |
| 733 | + | |
| 734 | + $event->settings = $eventSettings; | |
| 735 | + | |
| 736 | + $event->availability_id = $availabilityId; | |
| 737 | + $event->availability_type = $availabilityType; | |
| 738 | + | |
| 613 | 739 | $event->save(); |
| 614 | 740 | |
| 615 | 741 | return [ |
| 616 | 742 | 'message' => __('Data has been updated', 'fluent-booking'), |
| @@ -650,11 +776,11 @@ | ||
| 650 | 776 | 'event' => $event |
| 651 | 777 | ]; |
| 652 | 778 | } |
| 653 | 779 | |
| 654 | - public function patchCalendarEvent(Request $request, $calendarId, $slotId) | |
| 780 | + public function patchCalendarEvent(Request $request, $calendarId, $eventId) | |
| 655 | 781 | { |
| 656 | - $slot = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($slotId); | |
| 782 | + $slot = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($eventId); | |
| 657 | 783 | |
| 658 | 784 | $status = $request->get('status'); |
| 659 | 785 | |
| 660 | 786 | if ($status) { |
| @@ -671,8 +797,14 @@ | ||
| 671 | 797 | public function cloneCalendarEvent(Request $request, $calendarId, $eventId) |
| 672 | 798 | { |
| 673 | 799 | $newCalendarId = intval($request->get('new_calendar_id')) ?: $calendarId; |
| 674 | 800 | |
| 801 | + if (!PermissionManager::canWriteCalendar($newCalendarId)) { | |
| 802 | + return $this->sendError([ | |
| 803 | + 'message' => __('You do not have permission to write to the destination calendar.', 'fluent-booking') | |
| 804 | + ], 403); | |
| 805 | + } | |
| 806 | + | |
| 675 | 807 | $calendar = Calendar::findOrFail($newCalendarId); |
| 676 | 808 | |
| 677 | 809 | $originalEvent = CalendarSlot::with('event_metas')->where('calendar_id', $calendarId)->findOrFail($eventId); |
| 678 | 810 | |
| @@ -677,8 +809,10 @@ | ||
| 677 | 809 | $originalEvent = CalendarSlot::with('event_metas')->where('calendar_id', $calendarId)->findOrFail($eventId); |
| 678 | 810 | |
| 679 | 811 | $clonedEvent = $originalEvent->replicate(); |
| 680 | 812 | |
| 813 | + $clonedEvent->hash = null; | |
| 814 | + | |
| 681 | 815 | $clonedEvent->calendar_id = $calendar->id; |
| 682 | 816 | |
| 683 | 817 | $clonedEvent->user_id = $calendar->user_id; |
| 684 | 818 | |
| @@ -723,8 +857,14 @@ | ||
| 723 | 857 | $calendarEvent = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($eventId); |
| 724 | 858 | |
| 725 | 859 | $fromEventId = intval($request->get('from_event_id')); |
| 726 | 860 | |
| 861 | + if (!$fromEventId || !PermissionManager::canUpdateCalendarEvent($fromEventId)) { | |
| 862 | + return $this->sendError([ | |
| 863 | + 'message' => __('You do not have permission to clone from the selected event.', 'fluent-booking') | |
| 864 | + ], 403); | |
| 865 | + } | |
| 866 | + | |
| 727 | 867 | $fromCalendarEvent = CalendarSlot::findOrFail($fromEventId); |
| 728 | 868 | |
| 729 | 869 | $notification = $fromCalendarEvent->getNotifications(true); |
| 730 | 870 | |
| @@ -737,11 +877,11 @@ | ||
| 737 | 877 | 'notifications' => $notification |
| 738 | 878 | ]; |
| 739 | 879 | } |
| 740 | 880 | |
| 741 | - public function getEventEmailNotifications(Request $request, $calendarId, $slotId) | |
| 881 | + public function getEventEmailNotifications(Request $request, $calendarId, $eventId) | |
| 742 | 882 | { |
| 743 | - $calendarEvent = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($slotId); | |
| 883 | + $calendarEvent = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($eventId); | |
| 744 | 884 | |
| 745 | 885 | /* |
| 746 | 886 | * Confirmation Email to Attendee |
| 747 | 887 | * Confirmation Email to Organizer |
| @@ -762,11 +902,11 @@ | ||
| 762 | 902 | |
| 763 | 903 | return $data; |
| 764 | 904 | } |
| 765 | 905 | |
| 766 | - public function saveEventEmailNotifications(Request $request, $calendarId, $slotId) | |
| 906 | + public function saveEventEmailNotifications(Request $request, $calendarId, $eventId) | |
| 767 | 907 | { |
| 768 | - $slot = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($slotId); | |
| 908 | + $slot = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($eventId); | |
| 769 | 909 | |
| 770 | 910 | $notifications = $request->get('notifications', []); |
| 771 | 911 | |
| 772 | 912 | $formattedNotifications = []; |
| @@ -786,11 +926,11 @@ | ||
| 786 | 926 | 'message' => __('Notifications has been saved', 'fluent-booking') |
| 787 | 927 | ]; |
| 788 | 928 | } |
| 789 | 929 | |
| 790 | - public function getEventBookingFields(Request $request, $calendarId, $slotId) | |
| 930 | + public function getEventBookingFields(Request $request, $calendarId, $eventId) | |
| 791 | 931 | { |
| 792 | - $calendarEvent = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($slotId); | |
| 932 | + $calendarEvent = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($eventId); | |
| 793 | 933 | |
| 794 | 934 | $data = [ |
| 795 | 935 | 'fields' => $calendarEvent->getBookingFields() |
| 796 | 936 | ]; |
| @@ -810,58 +950,39 @@ | ||
| 810 | 950 | $calendarEvent = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($eventId); |
| 811 | 951 | |
| 812 | 952 | $bookingFields = $request->get('booking_fields'); |
| 813 | 953 | |
| 814 | - $optionRequiredFields = ['dropdown', 'radio', 'checkbox-group', 'multi-select']; | |
| 954 | + $formattedFields = BookingFieldService::sanitizeBookingFields($bookingFields, $calendarEvent); | |
| 815 | 955 | |
| 816 | - $formattedFields = []; | |
| 956 | + $calendarEvent->setBookingFields($formattedFields); | |
| 817 | 957 | |
| 818 | - $textFields = ['type', 'name', 'label', 'placeholder', 'limit', 'help_text', 'date_format']; | |
| 819 | - $booleanFields = ['enabled', 'required', 'system_defined', 'disable_alter', 'is_sms_number']; | |
| 958 | + return [ | |
| 959 | + 'message' => __('Fields has been updated', 'fluent-booking') | |
| 960 | + ]; | |
| 961 | + } | |
| 820 | 962 | |
| 821 | - foreach ($bookingFields as $value) { | |
| 822 | - if (empty($value['name'])) { | |
| 823 | - $value['name'] = BookingFieldService::generateFieldName($calendarEvent, $value['label']); | |
| 824 | - } else { | |
| 825 | - $value['name'] = BookingFieldService::maybeGenerateFieldName($calendarEvent, $value); | |
| 826 | - } | |
| 963 | + public function getEventPaymentSettings($calendarId, $eventId) | |
| 964 | + { | |
| 965 | + $calendarEvent = CalendarSlot::where('calendar_id', $calendarId)->findOrFail($eventId); | |
| 827 | 966 | |
| 828 | - $textValues = array_map('sanitize_text_field', Arr::only($value, $textFields)); | |
| 967 | + $config = [ | |
| 968 | + 'native_enabled' => Helper::isPaymentEnabled(), | |
| 969 | + 'stripe_configured' => Helper::isPaymentConfigured('stripe'), | |
| 970 | + 'paypal_configured' => Helper::isPaymentConfigured('paypal'), | |
| 971 | + 'offline_configured' => Helper::isPaymentConfigured('offline'), | |
| 972 | + 'native_config_link' => Helper::getAppBaseUrl('settings/payment-methods/stripe'), | |
| 973 | + 'woo_config_link' => Helper::getAppBaseUrl('settings/configure-integrations/global-modules'), | |
| 974 | + 'has_cart' => defined('FLUENTCART_VERSION'), | |
| 975 | + 'has_woo' => defined('WC_PLUGIN_FILE'), | |
| 976 | + 'woo_enabled' => defined('WC_PLUGIN_FILE') && Helper::isModuleEnabled('woo') | |
| 977 | + ]; | |
| 829 | 978 | |
| 830 | - $booleanValues = array_map(function ($valueItem) { | |
| 831 | - return $valueItem === true || $valueItem === 'true' || $valueItem == 1; | |
| 832 | - }, Arr::only($value, $booleanFields)); | |
| 979 | + $data = apply_filters('fluent_booking/payment/get_payment_settings', [ | |
| 980 | + 'settings' => $calendarEvent->getPaymentSettings(), | |
| 981 | + 'config' => $config | |
| 982 | + ], $calendarEvent); | |
| 833 | 983 | |
| 834 | - $formattedField = array_merge($textValues, $booleanValues); | |
| 835 | - | |
| 836 | - $formattedField['index'] = (int)Arr::get($value, 'index'); | |
| 837 | - if (in_array(Arr::get($value, 'type'), $optionRequiredFields)) { | |
| 838 | - $sanitizedOptions = array_map('sanitize_text_field', Arr::get($value, 'options')); | |
| 839 | - $formattedField['options'] = $sanitizedOptions; | |
| 840 | - } | |
| 841 | - if ($value['type'] == 'payment' && $calendarEvent->type === 'paid') { | |
| 842 | - $formattedField['payment_items'] = Arr::get($value, 'payment_items'); | |
| 843 | - $formattedField['currency_sign'] = CurrenciesHelper::getGlobalCurrencySign(); | |
| 844 | - } | |
| 845 | - if ($value['type'] == 'file') { | |
| 846 | - $formattedField['max_file_allow'] = intval(Arr::get($value, 'max_file_allow')); | |
| 847 | - $formattedField['allow_file_types'] = array_map('sanitize_text_field', Arr::get($value, 'allow_file_types')); | |
| 848 | - $formattedField['file_size_value'] = intval(Arr::get($value, 'file_size_value')); | |
| 849 | - $formattedField['file_size_unit'] = SanitizeService::checkCollection(Arr::get($value, 'file_size_unit'), ['kb','mb']); | |
| 850 | - } | |
| 851 | - | |
| 852 | - if ($value['type'] == 'hidden') { | |
| 853 | - $formattedField['default_value'] = sanitize_text_field(Arr::get($value, 'default_value')); | |
| 854 | - } | |
| 855 | - | |
| 856 | - $formattedFields[] = $formattedField; | |
| 857 | - } | |
| 858 | - | |
| 859 | - $calendarEvent->setBookingFields($formattedFields); | |
| 860 | - | |
| 861 | - return [ | |
| 862 | - 'message' => __('Fields has been updated', 'fluent-booking') | |
| 863 | - ]; | |
| 984 | + return $data; | |
| 864 | 985 | } |
| 865 | 986 | |
| 866 | 987 | public function deleteCalendarEvent(Request $request, $calendarId, $calendarEventId) |
| 867 | 988 | { |