| 1 |
<?php /** |
| 2 |
* @version 1.0 |
| 3 |
* @package Booking Calendar |
| 4 |
* @category Simple Booking Form - Save Changes - on Settings > Booking Form page |
| 5 |
* @author wpdevelop |
| 6 |
* |
| 7 |
* @web-site https://wpbookingcalendar.com/ |
| 8 |
* @email info@wpbookingcalendar.com |
| 9 |
* |
| 10 |
* @modified 2024-08-17 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 14 |
|
| 15 |
|
| 16 |
/* |
| 17 |
* Sanitize and Save changes |
| 18 |
*/ |
| 19 |
function wpbc_simple_form__page_save_submit(){ |
| 20 |
|
| 21 |
|
| 22 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 23 |
if ( isset( $_POST['reset_to_default_form'] ) && ( $_POST['reset_to_default_form'] == 'standard' ) ) { |
| 24 |
|
| 25 |
// == Custom Forms == Start // Get Custom booking form |
| 26 |
if ( class_exists( 'wpdev_bk_biz_m' ) ) { |
| 27 |
$form_name = wpbc_get_sanitized_custom_booking_form_name_from_url(); |
| 28 |
if ( ( ! empty( $form_name ) ) && ( 'standard' !== $form_name ) ) { |
| 29 |
|
| 30 |
$simple_form_configuration = wpbc_simple_form__visual__get_default_form(); // We are importing old structure to have default booking form. |
| 31 |
|
| 32 |
wpbc_save_custom_booking_form__for_simple_form_mode( $form_name, $simple_form_configuration ); |
| 33 |
|
| 34 |
wpbc_show_changes_saved_message(); |
| 35 |
|
| 36 |
return; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
update_bk_option( 'booking_form_structure_type', 'vertical' ); |
| 41 |
update_bk_option( 'booking_form_layout_max_cols', 1 ); |
| 42 |
|
| 43 |
$visual_form_structure = wpbc_simple_form__visual__get_default_form(); // We are importing old structure to have default booking form. |
| 44 |
update_bk_option( 'booking_form_visual', $visual_form_structure ); |
| 45 |
|
| 46 |
wpbc_show_changes_saved_message(); |
| 47 |
|
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
// ------------------------------------------------------------------------------------------------------------- |
| 52 |
// Update booking form structure |
| 53 |
update_bk_option( 'booking_form_structure_type', WPBC_Settings_API::validate_text_post_static( 'booking_form_structure_type' ) ); |
| 54 |
update_bk_option( 'booking_form_layout_max_cols', max( intval(WPBC_Settings_API::validate_text_post_static( 'booking_form_layout_max_cols' )),1) ); |
| 55 |
// ------------------------------------------------------------------------------------------------------------- |
| 56 |
// Update Color Theme and skins/picker not in MU versions |
| 57 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 58 |
if ( isset( $_POST[ 'booking_form_theme' ] ) ) { |
| 59 |
$wpbc_selected_theme = WPBC_Settings_API::validate_text_post_static( 'booking_form_theme' ); |
| 60 |
update_bk_option( 'booking_form_theme', $wpbc_selected_theme ); |
| 61 |
//if (! class_exists( 'wpdev_bk_multiuser' ) ){ |
| 62 |
if ( 'wpbc_theme_dark_1' === $wpbc_selected_theme ) { |
| 63 |
update_bk_option( 'booking_skin', '/css/skins/24_9__dark_1.css' ); |
| 64 |
update_bk_option( 'booking_timeslot_picker_skin', '/css/time_picker_skins/black.css' ); |
| 65 |
} |
| 66 |
if ( '' === $wpbc_selected_theme ) { |
| 67 |
//update_bk_option( 'booking_skin', '/css/skins/green-01.css' ); |
| 68 |
update_bk_option( 'booking_skin', '/css/skins/24_9__light_square_1.css' ); // FixIn: 10.4.0.1. |
| 69 |
//update_bk_option( 'booking_timeslot_picker_skin', '/css/time_picker_skins/grey.css' ); |
| 70 |
update_bk_option( 'booking_timeslot_picker_skin', '/css/time_picker_skins/light__24_8.css' ); // FixIn: 10.4.0.1. |
| 71 |
} |
| 72 |
//} |
| 73 |
} |
| 74 |
|
| 75 |
// ------------------------------------------------------------------------------------------------------------- |
| 76 |
// Calendar skin |
| 77 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 78 |
if ( isset( $_POST['set_calendar_skin'] ) ) { |
| 79 |
|
| 80 |
$selected_calendar_skin = WPBC_Settings_API::validate_text_post_static( 'set_calendar_skin' ); |
| 81 |
|
| 82 |
// FixIn: 10.3.0.5. |
| 83 |
$upload_dir = wp_upload_dir(); |
| 84 |
$custom_user_skin_folder = $upload_dir['basedir']; |
| 85 |
$custom_user_skin_url = $upload_dir['baseurl']; |
| 86 |
|
| 87 |
$selected_calendar_skin = str_replace( array( WPBC_PLUGIN_DIR, WPBC_PLUGIN_URL, $custom_user_skin_folder, $custom_user_skin_url ), '', $selected_calendar_skin ); |
| 88 |
|
| 89 |
// Check if this skin exist in the plugin folder |
| 90 |
if ( |
| 91 |
( file_exists( WPBC_PLUGIN_DIR . $selected_calendar_skin ) ) |
| 92 |
|| ( file_exists( $custom_user_skin_folder . $selected_calendar_skin ) ) |
| 93 |
){ |
| 94 |
update_bk_option( 'booking_skin', $selected_calendar_skin ); |
| 95 |
} |
| 96 |
|
| 97 |
} |
| 98 |
// Calendar skin |
| 99 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 100 |
if ( isset( $_POST['set_time_picker_skin'] ) ) { |
| 101 |
|
| 102 |
$selected_calendar_skin = WPBC_Settings_API::validate_text_post_static( 'set_time_picker_skin' ); |
| 103 |
|
| 104 |
$selected_calendar_skin = str_replace( array( WPBC_PLUGIN_DIR, WPBC_PLUGIN_URL ), '', $selected_calendar_skin ); |
| 105 |
|
| 106 |
// Check if this skin exist in the plugin folder |
| 107 |
if ( file_exists( WPBC_PLUGIN_DIR . $selected_calendar_skin ) ) { |
| 108 |
update_bk_option( 'booking_timeslot_picker_skin', $selected_calendar_skin ); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
// ------------------------------------------------------------------------------------------------------------- |
| 113 |
|
| 114 |
$booking_form_layout_width = WPBC_Settings_API::validate_text_post_static( 'booking_form_layout_width' ); |
| 115 |
$booking_form_layout_width = ( intval( $booking_form_layout_width ) <= 0 ) ? 100 : intval( $booking_form_layout_width ); |
| 116 |
update_bk_option( 'booking_form_layout_width', $booking_form_layout_width ); |
| 117 |
|
| 118 |
$booking_form_layout_width_px_pr = WPBC_Settings_API::validate_text_post_static( 'booking_form_layout_width_px_pr' ); |
| 119 |
if ( ! in_array( $booking_form_layout_width_px_pr, array( 'px', '%' ) ) ) { |
| 120 |
$booking_form_layout_width_px_pr = '%'; |
| 121 |
} |
| 122 |
update_bk_option( 'booking_form_layout_width_px_pr', $booking_form_layout_width_px_pr); |
| 123 |
|
| 124 |
if ( wpbc_is_mu_user_can_be_here( 'only_super_admin' ) ) { |
| 125 |
update_bk_option( 'booking_is_use_autofill_4_logged_user', WPBC_Settings_API::validate_checkbox_post_static( 'booking_is_use_autofill_4_logged_user' ) ); |
| 126 |
update_bk_option( 'booking_timeslot_picker', WPBC_Settings_API::validate_checkbox_post_static( 'booking_timeslot_picker' ) ); |
| 127 |
} |
| 128 |
|
| 129 |
// ------------------------------------------------------------------------------------------------------------- |
| 130 |
//TODO: 2024-08-11 18:28 customize it differently for each booking forms |
| 131 |
// update_bk_option( 'booking_send_button_title', WPBC_Settings_API::validate_text_post_static( 'booking_send_button_title_name' ) ); |
| 132 |
|
| 133 |
// ------------------------------------------------------------------------------------------------------------- |
| 134 |
$skip_obligatory_field_types = array( 'calendar', 'submit', 'email' ); |
| 135 |
|
| 136 |
$if_exist_required = array( |
| 137 |
'rangetime', |
| 138 |
'captcha', |
| 139 |
'durationtime', |
| 140 |
'starttime', |
| 141 |
'endtime', |
| 142 |
); //FixIn: TimeFreeGenerator |
| 143 |
|
| 144 |
$visual_form_structure = array(); |
| 145 |
|
| 146 |
// $visual_form_structure[] = array( |
| 147 |
// 'type' => 'calendar' |
| 148 |
// , 'obligatory' => 'On' |
| 149 |
// ); |
| 150 |
|
| 151 |
// Loop all form filds for saving them. |
| 152 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 153 |
if ( isset( $_POST['form_field_name'] ) ) { |
| 154 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 155 |
foreach ( $_POST['form_field_name'] as $field_key => $field_name ) { |
| 156 |
|
| 157 |
$form_field_type_val = wpbc_clean_text_value( $_POST['form_field_type'][ $field_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
| 158 |
$form_field_type_val = ( 'select-one' === $form_field_type_val ) ? 'selectbox-one' : $form_field_type_val; |
| 159 |
$form_field_type_val = ( 'select-multiple' === $form_field_type_val ) ? 'selectbox-multiple' : $form_field_type_val; |
| 160 |
|
| 161 |
$visual_form_structure[] = array( |
| 162 |
'type' => $form_field_type_val, |
| 163 |
'name' => wpbc_clean_text_value( $field_name ), |
| 164 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
| 165 |
'obligatory' => ( ( in_array( wpbc_clean_text_value( $_POST['form_field_type'][ $field_key ] ), $skip_obligatory_field_types ) ) ? 'On' : 'Off' ), |
| 166 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
| 167 |
'active' => ( ( in_array( wpbc_clean_text_value( $_POST['form_field_type'][ $field_key ] ), $skip_obligatory_field_types ) ) ? 'On' : ( isset( $_POST['form_field_active'][ $field_key ] ) ? 'On' : 'Off' ) ), |
| 168 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
| 169 |
'required' => ( ( in_array( wpbc_clean_text_value( $_POST['form_field_type'][ $field_key ] ), $skip_obligatory_field_types ) ) |
| 170 |
? 'On' |
| 171 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 172 |
: ( ( in_array( wpbc_clean_text_value( $field_name ), $if_exist_required ) ) ? 'On' : ( isset( $_POST['form_field_required'][ $field_key ] ) ? 'On' : 'Off' ) ) ), |
| 173 |
'if_exist_required' => ( ( in_array( wpbc_clean_text_value( $field_name ), $if_exist_required ) ) ? 'On' : 'Off' ), |
| 174 |
'label' => WPBC_Settings_API::validate_text_post_static( 'form_field_label', $field_key ), |
| 175 |
'value' => WPBC_Settings_API::validate_text_post_static( 'form_field_value', $field_key ), |
| 176 |
); |
| 177 |
|
| 178 |
if ( 'captcha' === $visual_form_structure[ ( count( $visual_form_structure ) - 1 ) ]['type'] ) { |
| 179 |
if ( wpbc_is_mu_user_can_be_here( 'only_super_admin' ) ) { |
| 180 |
update_bk_option( 'booking_is_use_captcha', ( 'On' === $visual_form_structure[ ( count( $visual_form_structure ) - 1 ) ]['active'] ) ? 'On' : 'Off' ); |
| 181 |
} else { |
| 182 |
// For regular users we set Captcha settings from Super booking admin. |
| 183 |
$visual_form_structure[ ( count( $visual_form_structure ) - 1 ) ]['active'] = get_option( 'booking_is_use_captcha' ); |
| 184 |
} |
| 185 |
} |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
// $visual_form_structure[] = array( |
| 190 |
// 'type' => 'captcha' |
| 191 |
// , 'name' => 'captcha' |
| 192 |
// , 'obligatory' => 'On' |
| 193 |
// , 'active' => get_bk_option( 'booking_is_use_captcha' ) |
| 194 |
// , 'required' => 'On' |
| 195 |
// , 'label' => '' |
| 196 |
// ); |
| 197 |
// $visual_form_structure[] = array( |
| 198 |
// 'type' => 'submit' |
| 199 |
// , 'name' => 'submit' |
| 200 |
// , 'obligatory' => 'On' |
| 201 |
// , 'active' => 'On' |
| 202 |
// , 'required' => 'On' |
| 203 |
// , 'label' => WPBC_Settings_API::validate_text_post_static( 'booking_send_button_title_name' )//get_bk_option( 'booking_send_button_title' ) //FixIn: 8.8.1.14 // __('Send', 'booking') |
| 204 |
// ); |
| 205 |
|
| 206 |
|
| 207 |
if( |
| 208 |
( function_exists( 'wpbc_is_custom_booking_form_submitted__for_simple_form_mode' ) ) && |
| 209 |
( wpbc_is_custom_booking_form_submitted__for_simple_form_mode() ) && |
| 210 |
( ! empty( wpbc_get_sanitized_custom_booking_form_name_from_url() ) ) && |
| 211 |
( 'standard' !== wpbc_get_sanitized_custom_booking_form_name_from_url() ) |
| 212 |
){ |
| 213 |
|
| 214 |
$_POST['booking_form'] = str_replace( '\\n\\', '', wpbc_simple_form__get_booking_form__as_shortcodes( $visual_form_structure ) ); |
| 215 |
$_POST['booking_form_show'] = str_replace( '\\n\\', '', wpbc_simple_form__get_form_show__as_shortcodes( $visual_form_structure ) ); |
| 216 |
|
| 217 |
make_bk_action( 'wpbc_make_save_custom_booking_form' ); // Check here: wpbc_make_save_custom_booking_form() |
| 218 |
|
| 219 |
$form_name = wpbc_get_sanitized_custom_booking_form_name_from_url(); |
| 220 |
wpbc_save_custom_booking_form__for_simple_form_mode( $form_name, $visual_form_structure ); |
| 221 |
|
| 222 |
} else { |
| 223 |
|
| 224 |
update_bk_option( 'booking_form_visual', $visual_form_structure ); |
| 225 |
update_bk_option( 'booking_form', str_replace( '\\n\\', '', wpbc_simple_form__get_booking_form__as_shortcodes( $visual_form_structure ) ) ); |
| 226 |
update_bk_option( 'booking_form_show', str_replace( '\\n\\', '', wpbc_simple_form__get_form_show__as_shortcodes() ) ); |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
// FixIn: 9.8.6.1. |
| 232 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 233 |
if ( ! empty( $_POST['form_visible_section'] ) ) { |
| 234 |
?><script type="text/javascript"> |
| 235 |
jQuery(document).ready(function(){ |
| 236 |
jQuery( '<?php |
| 237 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 238 |
echo esc_js( $_POST['form_visible_section'] ); |
| 239 |
?> a' ).trigger('click'); |
| 240 |
}); |
| 241 |
</script><?php |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
if ( class_exists( 'wpdev_bk_personal' ) ) { |
| 246 |
$is_use_simgple_form = get_bk_option( 'booking_is_use_simple_booking_form' ); |
| 247 |
if ( 'Off' === $is_use_simgple_form ) { |
| 248 |
?><script type="text/javascript"> window.location.href = '<?php |
| 249 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 250 |
echo ( wpbc_get_settings_url() ) . '&tab=form'; ?>'; </script><?php |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
wpbc_show_changes_saved_message(); |
| 255 |
|
| 256 |
// To refresh the Calendar skin we need to reload the page |
| 257 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 258 |
if ( isset( $_POST['booking_form_theme'] ) ) { |
| 259 |
$url = wpbc_get_settings_url() . '&tab=form'; |
| 260 |
if ( function_exists( 'wpbc_get_sanitized_custom_booking_form_name_from_url' ) ) { |
| 261 |
$url .= '&booking_form=' . wpbc_get_sanitized_custom_booking_form_name_from_url(); |
| 262 |
} |
| 263 |
?> |
| 264 |
<script type="text/javascript"> window.location.href = '<?php |
| 265 |
// phpcs:ignore WordPress.Security.EscapeOutput |
| 266 |
echo $url; |
| 267 |
?>'; </script><?php |
| 268 |
} |
| 269 |
} |
| 270 |
|