PluginProbe
Booking Calendar / 10.10
Booking Calendar v10.10
11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 All 203 releases
booking / includes / page-form-simple / form_simple__submit.php

form_simple__submit.php in Booking Calendar 10.10, at includes/page-form-simple/form_simple__submit.php

264 lines 14.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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( 'rangetime', 'captcha' ); //FixIn: TimeFreeGenerator
137
138 $visual_form_structure = array();
139
140 // $visual_form_structure[] = array(
141 // 'type' => 'calendar'
142 // , 'obligatory' => 'On'
143 // );
144
145 // Loop all form filds for saving them.
146 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
147 if ( isset( $_POST['form_field_name'] ) ) {
148 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
149 foreach ( $_POST['form_field_name'] as $field_key => $field_name ) {
150
151 $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
152 $form_field_type_val = ( 'select-one' === $form_field_type_val ) ? 'selectbox-one' : $form_field_type_val;
153 $form_field_type_val = ( 'select-multiple' === $form_field_type_val ) ? 'selectbox-multiple' : $form_field_type_val;
154
155 $visual_form_structure[] = array(
156 'type' => $form_field_type_val,
157 'name' => wpbc_clean_text_value( $field_name ),
158 // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
159 'obligatory' => ( ( in_array( wpbc_clean_text_value( $_POST['form_field_type'][ $field_key ] ), $skip_obligatory_field_types ) ) ? 'On' : 'Off' ),
160 // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
161 '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' ) ),
162 // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
163 'required' => ( ( in_array( wpbc_clean_text_value( $_POST['form_field_type'][ $field_key ] ), $skip_obligatory_field_types ) )
164 ? 'On'
165 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
166 : ( ( in_array( wpbc_clean_text_value( $field_name ), $if_exist_required ) ) ? 'On' : ( isset( $_POST['form_field_required'][ $field_key ] ) ? 'On' : 'Off' ) ) ),
167 'if_exist_required' => ( ( in_array( wpbc_clean_text_value( $field_name ), $if_exist_required ) ) ? 'On' : 'Off' ),
168 'label' => WPBC_Settings_API::validate_text_post_static( 'form_field_label', $field_key ),
169 'value' => WPBC_Settings_API::validate_text_post_static( 'form_field_value', $field_key ),
170 );
171
172 if ( 'captcha' === $visual_form_structure[ ( count( $visual_form_structure ) - 1 ) ]['type'] ) {
173 if ( wpbc_is_mu_user_can_be_here( 'only_super_admin' ) ) {
174 update_bk_option( 'booking_is_use_captcha', ( 'On' === $visual_form_structure[ ( count( $visual_form_structure ) - 1 ) ]['active'] ) ? 'On' : 'Off' );
175 } else {
176 // For regular users we set Captcha settings from Super booking admin.
177 $visual_form_structure[ ( count( $visual_form_structure ) - 1 ) ]['active'] = get_option( 'booking_is_use_captcha' );
178 }
179 }
180 }
181 }
182
183 // $visual_form_structure[] = array(
184 // 'type' => 'captcha'
185 // , 'name' => 'captcha'
186 // , 'obligatory' => 'On'
187 // , 'active' => get_bk_option( 'booking_is_use_captcha' )
188 // , 'required' => 'On'
189 // , 'label' => ''
190 // );
191 // $visual_form_structure[] = array(
192 // 'type' => 'submit'
193 // , 'name' => 'submit'
194 // , 'obligatory' => 'On'
195 // , 'active' => 'On'
196 // , 'required' => 'On'
197 // , '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')
198 // );
199
200
201 if(
202 ( function_exists( 'wpbc_is_custom_booking_form_submitted__for_simple_form_mode' ) ) &&
203 ( wpbc_is_custom_booking_form_submitted__for_simple_form_mode() ) &&
204 ( ! empty( wpbc_get_sanitized_custom_booking_form_name_from_url() ) ) &&
205 ( 'standard' !== wpbc_get_sanitized_custom_booking_form_name_from_url() )
206 ){
207
208 $_POST['booking_form'] = str_replace( '\\n\\', '', wpbc_simple_form__get_booking_form__as_shortcodes( $visual_form_structure ) );
209 $_POST['booking_form_show'] = str_replace( '\\n\\', '', wpbc_simple_form__get_form_show__as_shortcodes( $visual_form_structure ) );
210
211 make_bk_action( 'wpbc_make_save_custom_booking_form' ); // Check here: wpbc_make_save_custom_booking_form()
212
213 $form_name = wpbc_get_sanitized_custom_booking_form_name_from_url();
214 wpbc_save_custom_booking_form__for_simple_form_mode( $form_name, $visual_form_structure );
215
216 } else {
217
218 update_bk_option( 'booking_form_visual', $visual_form_structure );
219 update_bk_option( 'booking_form', str_replace( '\\n\\', '', wpbc_simple_form__get_booking_form__as_shortcodes( $visual_form_structure ) ) );
220 update_bk_option( 'booking_form_show', str_replace( '\\n\\', '', wpbc_simple_form__get_form_show__as_shortcodes() ) );
221 }
222
223
224
225 // FixIn: 9.8.6.1.
226 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
227 if ( ! empty( $_POST['form_visible_section'] ) ) {
228 ?><script type="text/javascript">
229 jQuery(document).ready(function(){
230 jQuery( '<?php
231 // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
232 echo esc_js( $_POST['form_visible_section'] );
233 ?> a' ).trigger('click');
234 });
235 </script><?php
236 }
237
238
239 if ( class_exists( 'wpdev_bk_personal' ) ) {
240 $is_use_simgple_form = get_bk_option( 'booking_is_use_simple_booking_form' );
241 if ( 'Off' === $is_use_simgple_form ) {
242 ?><script type="text/javascript"> window.location.href = '<?php
243 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
244 echo ( wpbc_get_settings_url() ) . '&tab=form'; ?>'; </script><?php
245 }
246 }
247
248 wpbc_show_changes_saved_message();
249
250 // To refresh the Calendar skin we need to reload the page
251 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
252 if ( isset( $_POST['booking_form_theme'] ) ) {
253 $url = wpbc_get_settings_url() . '&tab=form';
254 if ( function_exists( 'wpbc_get_sanitized_custom_booking_form_name_from_url' ) ) {
255 $url .= '&booking_form=' . wpbc_get_sanitized_custom_booking_form_name_from_url();
256 }
257 ?>
258 <script type="text/javascript"> window.location.href = '<?php
259 // phpcs:ignore WordPress.Security.EscapeOutput
260 echo $url;
261 ?>'; </script><?php
262 }
263 }
264