Skip to content

Commit

Permalink
Merge pull request #1213 from wielebenwir/feature/issue-1144
Browse files Browse the repository at this point in the history
Added iCal Download to confirmed booking page
  • Loading branch information
hansmorb committed Apr 28, 2024
2 parents 5bcf73e + 556ea67 commit 8f199a8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
6 changes: 6 additions & 0 deletions assets/public/css/public.css
Original file line number Diff line number Diff line change
Expand Up @@ -3616,6 +3616,12 @@
box-shadow: none !important;
font-size: 0.875rem;
}
.cb-wrapper input.cb-action-get_ics {
background-color: var(--commonsbooking-color-primary);
box-shadow: none !important;
font-size: 0.875rem;
float: left;
}
.cb-wrapper #booking-form-container,
.cb-wrapper #booking-form-container div {
border-bottom: 0;
Expand Down
7 changes: 7 additions & 0 deletions assets/public/sass/partials/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@
font-size: 0.875rem;
}

input.cb-action-get_ics {
background-color: var(--commonsbooking-color-primary);
box-shadow: none !important;
font-size: 0.875rem;
float:left;
}

#booking-form-container,
#booking-form-container div {
border-bottom: 0;
Expand Down
27 changes: 26 additions & 1 deletion src/Wordpress/CustomPostType/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use CommonsBooking\Helper\Helper;
use CommonsBooking\Messages\BookingMessage;
use CommonsBooking\Service\BookingRuleApplied;
use CommonsBooking\Settings\Settings;
use Exception;
use function wp_verify_nonce;

/**
Expand Down Expand Up @@ -344,7 +346,30 @@ public static function handleBookingRequest(
PHP_EOL . $postId->get_error_messages()
);
}

elseif (
function_exists( 'wp_verify_nonce' ) &&
isset( $_REQUEST[ static::getWPNonceId() ] ) &&
wp_verify_nonce( $_REQUEST[ static::getWPNonceId() ], static::getWPAction() ) &&
isset ( $_POST['calendar-download'] )
){
$postID = intval($_POST['post_ID']);
$booking = New \CommonsBooking\Model\Booking( $postID );
$template_objects = [
'booking' => $booking,
'item' => $booking->getItem(),
'location' => $booking->getLocation(),
'user' => $booking->getUserData(),
];
$eventTitle = Settings::getOption( 'commonsbooking_options_templates', 'emailtemplates_mail-booking_ics_event-title' );
$eventTitle = commonsbooking_sanitizeHTML ( commonsbooking_parse_template ( $eventTitle, $template_objects ) );
$eventDescription = Settings::getOption( 'commonsbooking_options_templates', 'emailtemplates_mail-booking_ics_event-description' );
$eventDescription = commonsbooking_sanitizeHTML ( strip_tags ( commonsbooking_parse_template ( $eventDescription, $template_objects ) ) );
$calendar = $booking->getiCal($eventTitle,$eventDescription);
header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename="booking.ics"');
echo $calendar;
exit;
}
return $postId;
}

Expand Down
6 changes: 5 additions & 1 deletion templates/booking-single-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

if ( $current_status === 'confirmed' && $form_action === 'cancel' && $booking->canCancel() ) {
$form_post_status = 'canceled';
$icalbutton_label = esc_html__( 'Add to Calendar', 'commonsbooking' );
$button_label = esc_html__( 'Cancel Booking', 'commonsbooking' );
}

Expand Down Expand Up @@ -43,7 +44,10 @@
<input type="hidden" name="post_status" value="<?php echo esc_attr( $form_post_status ); ?>"/>
<input type="hidden" name="repetition-start" value="<?php echo esc_attr( $booking->getMeta( 'repetition-start' ) ); ?>">
<input type="hidden" name="repetition-end" value="<?php echo esc_attr( $booking->getMeta( 'repetition-end' ) ); ?>">
<input type="submit" value="<?php echo esc_attr( $button_label ); ?>" class="<?php echo 'cb-action-' . commonsbooking_sanitizeHTML( $form_post_status ); ?>"/>
<input type="submit" value="<?php echo esc_attr( $button_label ); ?>" class="<?php echo 'cb-action-' . commonsbooking_sanitizeHTML( $form_post_status ); ?>"/>
<?php if ( ! empty($icalbutton_label) ) { ?>
<input type="submit" name="calendar-download" value="<?php echo esc_attr( $icalbutton_label ) ?>" class="cb-action-get_ics"/>
<?php } ?>
</form>
</li>
</form>
Expand Down
2 changes: 1 addition & 1 deletion templates/timeframe-calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<?php
if ( is_user_logged_in() ) {
?>
<input type="submit" disabled="disabled"
<input type="submit" name="booking-update" disabled="disabled"
value="<?php echo esc_html__( 'Continue to booking confirmation', 'commonsbooking' ); ?>"/>
<?php } ?>
</form>
Expand Down

0 comments on commit 8f199a8

Please sign in to comment.