| 1 |
<?php |
| 2 |
/** |
| 3 |
* Modular Step 7 weekly Working Hours proposal editor. |
| 4 |
* |
| 5 |
* @package Booking Calendar |
| 6 |
* @var array<string,mixed> $template_context Authorized step context. |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
$step_data = $template_context['step_data']; |
| 14 |
$working_hours = isset( $step_data['working_hours'] ) && is_array( $step_data['working_hours'] ) ? $step_data['working_hours'] : array(); |
| 15 |
$weekdays = isset( $step_data['weekdays'] ) && is_array( $step_data['weekdays'] ) ? $step_data['weekdays'] : array(); |
| 16 |
$time_options = isset( $step_data['time_options'] ) && is_array( $step_data['time_options'] ) ? $step_data['time_options'] : array(); |
| 17 |
$max_intervals_per_day = isset( $step_data['max_intervals_per_day'] ) ? absint( $step_data['max_intervals_per_day'] ) : 8; |
| 18 |
$working_hours_json = wp_json_encode( $working_hours ); |
| 19 |
$working_hours_json = false === $working_hours_json ? '{"enabled":"On","weekdays":{}}' : $working_hours_json; |
| 20 |
$working_hours_enabled = ! isset( $working_hours['enabled'] ) || 'Off' !== $working_hours['enabled']; |
| 21 |
?> |
| 22 |
<section class="wpbc_setup_wizard__step-content wpbc_setup_wizard__working-hours-step" aria-labelledby="wpbc-setup-wizard-step-title"> |
| 23 |
<header class="wpbc_setup_wizard__step-heading"> |
| 24 |
<h1 id="wpbc-setup-wizard-step-title"><?php esc_html_e( 'Set your working hours', 'booking' ); ?></h1> |
| 25 |
<p class="wpbc_setup_wizard__lead"><?php esc_html_e( 'Define the weekly schedule used to calculate available booking times.', 'booking' ); ?></p> |
| 26 |
</header> |
| 27 |
<?php |
| 28 |
$template_context['templates']->render( |
| 29 |
'settings-hint', |
| 30 |
array( 'settings_hint' => $template_context['settings_hint'] ) |
| 31 |
); |
| 32 |
?> |
| 33 |
|
| 34 |
<form id="wpbc-setup-wizard-step-form" novalidate> |
| 35 |
<input |
| 36 |
type="hidden" |
| 37 |
name="working_hours" |
| 38 |
value="<?php echo esc_attr( $working_hours_json ); ?>" |
| 39 |
required |
| 40 |
data-wpbc-setup-wizard-field |
| 41 |
data-wpbc-working-hours-draft |
| 42 |
data-max-intervals="<?php echo esc_attr( (string) $max_intervals_per_day ); ?>" |
| 43 |
aria-describedby="wpbc-setup-wizard-working-hours-error" |
| 44 |
> |
| 45 |
|
| 46 |
<div class="wpbc_setup_wizard__working-hours-panel<?php echo $working_hours_enabled ? '' : ' is-disabled'; ?>" data-wpbc-working-hours-editor> |
| 47 |
<div class="wpbc_setup_wizard__working-hours-master"> |
| 48 |
<label for="wpbc-setup-wizard-working-hours-enabled"> |
| 49 |
<input |
| 50 |
id="wpbc-setup-wizard-working-hours-enabled" |
| 51 |
type="checkbox" |
| 52 |
value="1" |
| 53 |
data-wpbc-working-hours-enabled |
| 54 |
aria-describedby="wpbc-setup-wizard-working-hours-enabled-description" |
| 55 |
<?php checked( $working_hours_enabled ); ?> |
| 56 |
> |
| 57 |
<strong><?php esc_html_e( 'Limit booking times to working hours', 'booking' ); ?></strong> |
| 58 |
</label> |
| 59 |
<p id="wpbc-setup-wizard-working-hours-enabled-description"><?php esc_html_e( 'Turn this on to restrict available booking times to the weekly schedule below.', 'booking' ); ?></p> |
| 60 |
</div> |
| 61 |
|
| 62 |
<fieldset class="wpbc_setup_wizard__working-hours-controls" data-wpbc-working-hours-controls <?php disabled( ! $working_hours_enabled ); ?>> |
| 63 |
<legend class="screen-reader-text"><?php esc_html_e( 'Weekly working-hours schedule', 'booking' ); ?></legend> |
| 64 |
<div class="wpbc_setup_wizard__working-hours-header"> |
| 65 |
<strong><?php esc_html_e( 'Day', 'booking' ); ?></strong> |
| 66 |
<strong><?php esc_html_e( 'Working hours', 'booking' ); ?></strong> |
| 67 |
<button |
| 68 |
type="button" |
| 69 |
class="button button-secondary wpbc_setup_wizard__copy-schedule-toggle" |
| 70 |
aria-expanded="false" |
| 71 |
aria-controls="wpbc-setup-wizard-copy-schedule" |
| 72 |
data-wpbc-copy-schedule-toggle |
| 73 |
> |
| 74 |
<i class="menu_icon icon-1x wpbc_icn_content_copy" aria-hidden="true"></i> |
| 75 |
<span><?php esc_html_e( 'Copy schedule', 'booking' ); ?></span> |
| 76 |
</button> |
| 77 |
</div> |
| 78 |
|
| 79 |
<section id="wpbc-setup-wizard-copy-schedule" class="wpbc_setup_wizard__copy-schedule" aria-labelledby="wpbc-setup-wizard-copy-schedule-title" data-wpbc-copy-schedule-panel hidden> |
| 80 |
<div class="wpbc_setup_wizard__copy-schedule-heading"> |
| 81 |
<div> |
| 82 |
<h2 id="wpbc-setup-wizard-copy-schedule-title"><?php esc_html_e( 'Copy a day schedule', 'booking' ); ?></h2> |
| 83 |
<p><?php esc_html_e( 'Choose one source day and the days that should receive its complete interval list.', 'booking' ); ?></p> |
| 84 |
</div> |
| 85 |
<button type="button" class="wpbc_setup_wizard__copy-schedule-close" data-wpbc-copy-schedule-cancel aria-label="<?php esc_attr_e( 'Close schedule copy controls', 'booking' ); ?>"> |
| 86 |
<i class="menu_icon icon-1x wpbc_icn_close" aria-hidden="true"></i> |
| 87 |
</button> |
| 88 |
</div> |
| 89 |
|
| 90 |
<div class="wpbc_setup_wizard__copy-schedule-controls"> |
| 91 |
<div class="wpbc_setup_wizard__field"> |
| 92 |
<label for="wpbc-setup-wizard-copy-source"><?php esc_html_e( 'Copy from', 'booking' ); ?></label> |
| 93 |
<select id="wpbc-setup-wizard-copy-source" data-wpbc-copy-source> |
| 94 |
<?php foreach ( $weekdays as $weekday ) : ?> |
| 95 |
<option value="<?php echo esc_attr( (string) $weekday['day_number'] ); ?>" <?php selected( 1, (int) $weekday['day_number'] ); ?>><?php echo esc_html( $weekday['label'] ); ?></option> |
| 96 |
<?php endforeach; ?> |
| 97 |
</select> |
| 98 |
</div> |
| 99 |
|
| 100 |
<fieldset class="wpbc_setup_wizard__copy-targets"> |
| 101 |
<legend><?php esc_html_e( 'Copy to', 'booking' ); ?></legend> |
| 102 |
<div> |
| 103 |
<?php foreach ( $weekdays as $weekday ) : ?> |
| 104 |
<?php $copy_day_number = isset( $weekday['day_number'] ) ? absint( $weekday['day_number'] ) : 0; ?> |
| 105 |
<label> |
| 106 |
<input type="checkbox" value="<?php echo esc_attr( (string) $copy_day_number ); ?>" data-wpbc-copy-target <?php checked( in_array( $copy_day_number, array( 2, 3, 4, 5 ), true ) ); ?> <?php disabled( 1 === $copy_day_number ); ?>> |
| 107 |
<span><?php echo esc_html( $weekday['label'] ); ?></span> |
| 108 |
</label> |
| 109 |
<?php endforeach; ?> |
| 110 |
</div> |
| 111 |
</fieldset> |
| 112 |
</div> |
| 113 |
|
| 114 |
<div class="wpbc_setup_wizard__copy-schedule-actions"> |
| 115 |
<button type="button" class="button button-secondary" data-wpbc-copy-schedule-cancel><?php esc_html_e( 'Cancel', 'booking' ); ?></button> |
| 116 |
<button type="button" class="button button-primary" data-wpbc-copy-schedule-apply><?php esc_html_e( 'Copy hours', 'booking' ); ?></button> |
| 117 |
</div> |
| 118 |
</section> |
| 119 |
|
| 120 |
<div class="wpbc_setup_wizard__working-days"> |
| 121 |
<?php foreach ( $weekdays as $weekday ) : ?> |
| 122 |
<?php |
| 123 |
$day_number = isset( $weekday['day_number'] ) ? absint( $weekday['day_number'] ) : 0; |
| 124 |
$day_label = isset( $weekday['label'] ) ? (string) $weekday['label'] : ''; |
| 125 |
$day_intervals = isset( $working_hours['weekdays'][ $day_number ] ) && is_array( $working_hours['weekdays'][ $day_number ] ) ? $working_hours['weekdays'][ $day_number ] : array(); |
| 126 |
$is_enabled = ! empty( $day_intervals ); |
| 127 |
$checkbox_id = 'wpbc-setup-wizard-working-day-' . $day_number; |
| 128 |
/* translators: %s: Weekday name. */ |
| 129 |
$working_intervals_label = sprintf( __( '%s working intervals', 'booking' ), $day_label ); |
| 130 |
/* translators: %s: Weekday name. */ |
| 131 |
$availability_label = sprintf( __( '%s availability', 'booking' ), $day_label ); |
| 132 |
?> |
| 133 |
<div |
| 134 |
class="wpbc_setup_wizard__working-day<?php echo $is_enabled ? ' is-enabled' : ''; ?>" |
| 135 |
data-wpbc-working-day="<?php echo esc_attr( (string) $day_number ); ?>" |
| 136 |
data-day-label="<?php echo esc_attr( $day_label ); ?>" |
| 137 |
> |
| 138 |
<label class="wpbc_setup_wizard__working-day-toggle" for="<?php echo esc_attr( $checkbox_id ); ?>"> |
| 139 |
<input |
| 140 |
id="<?php echo esc_attr( $checkbox_id ); ?>" |
| 141 |
type="checkbox" |
| 142 |
value="1" |
| 143 |
data-wpbc-working-day-toggle |
| 144 |
<?php checked( $is_enabled ); ?> |
| 145 |
<?php if ( 1 === $day_number ) : ?>data-wpbc-setup-wizard-error-control-for="working_hours"<?php endif; ?> |
| 146 |
> |
| 147 |
<span><?php echo esc_html( $day_label ); ?></span> |
| 148 |
</label> |
| 149 |
|
| 150 |
<div class="wpbc_setup_wizard__working-day-schedule"> |
| 151 |
<div |
| 152 |
class="wpbc_setup_wizard__working-intervals" |
| 153 |
data-wpbc-working-intervals |
| 154 |
aria-label="<?php echo esc_attr( $working_intervals_label ); ?>" |
| 155 |
></div> |
| 156 |
<select class="wpbc_setup_wizard__working-unavailable" disabled data-wpbc-working-unavailable aria-label="<?php echo esc_attr( $availability_label ); ?>"> |
| 157 |
<option><?php esc_html_e( 'Unavailable', 'booking' ); ?></option> |
| 158 |
</select> |
| 159 |
</div> |
| 160 |
|
| 161 |
<button type="button" class="wpbc_setup_wizard__add-interval" data-wpbc-add-working-interval> |
| 162 |
<i class="menu_icon icon-1x wpbc_icn_add" aria-hidden="true"></i> |
| 163 |
<span><?php esc_html_e( 'Add interval', 'booking' ); ?></span> |
| 164 |
</button> |
| 165 |
</div> |
| 166 |
<?php endforeach; ?> |
| 167 |
</div> |
| 168 |
|
| 169 |
<div class="wpbc_setup_wizard__working-hours-notice wpbc_setup_wizard__message wpbc_setup_wizard__message--info"> |
| 170 |
<i class="menu_icon icon-1x wpbc_icn_info_outline" aria-hidden="true"></i> |
| 171 |
<p><?php esc_html_e( 'Journey-specific slots and durations will be calculated inside these hours.', 'booking' ); ?></p> |
| 172 |
</div> |
| 173 |
</fieldset> |
| 174 |
|
| 175 |
</div> |
| 176 |
<span class="wpbc_setup_wizard__field-error wpbc_setup_wizard__field-error--group" id="wpbc-setup-wizard-working-hours-error" data-wpbc-setup-wizard-error-for="working_hours"></span> |
| 177 |
</form> |
| 178 |
|
| 179 |
<template data-wpbc-working-interval-template> |
| 180 |
<div class="wpbc_setup_wizard__working-interval"> |
| 181 |
<label class="screen-reader-text" data-wpbc-working-start-label><?php esc_html_e( 'Start time', 'booking' ); ?></label> |
| 182 |
<select data-wpbc-working-start> |
| 183 |
<?php foreach ( $time_options as $time_option ) : ?> |
| 184 |
<option value="<?php echo esc_attr( (string) $time_option['value'] ); ?>"><?php echo esc_html( $time_option['label'] ); ?></option> |
| 185 |
<?php endforeach; ?> |
| 186 |
</select> |
| 187 |
<span class="wpbc_setup_wizard__working-interval-separator" aria-hidden="true">–</span> |
| 188 |
<label class="screen-reader-text" data-wpbc-working-end-label><?php esc_html_e( 'End time', 'booking' ); ?></label> |
| 189 |
<select data-wpbc-working-end> |
| 190 |
<?php foreach ( $time_options as $time_option ) : ?> |
| 191 |
<option value="<?php echo esc_attr( (string) $time_option['value'] ); ?>"><?php echo esc_html( $time_option['label'] ); ?></option> |
| 192 |
<?php endforeach; ?> |
| 193 |
</select> |
| 194 |
<button type="button" class="wpbc_setup_wizard__remove-interval" data-wpbc-remove-working-interval> |
| 195 |
<i class="menu_icon icon-1x wpbc_icn_delete_outline" aria-hidden="true"></i> |
| 196 |
<span class="screen-reader-text"><?php esc_html_e( 'Remove working interval', 'booking' ); ?></span> |
| 197 |
</button> |
| 198 |
</div> |
| 199 |
</template> |
| 200 |
</section> |
| 201 |
|