PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.4.2
LatePoint – Calendar Booking Plugin for Appointments and Events v5.4.2
5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / controllers / settings_controller.php
latepoint / lib / controllers Last commit date
activities_controller.php 3 months ago auth_controller.php 3 months ago booking_form_settings_controller.php 3 months ago bookings_controller.php 3 months ago calendars_controller.php 3 months ago carts_controller.php 3 months ago controller.php 3 months ago customer_cabinet_controller.php 2 months ago customers_controller.php 3 months ago dashboard_controller.php 3 months ago default_agent_controller.php 3 months ago events_controller.php 3 months ago form_fields_controller.php 3 months ago integrations_controller.php 3 months ago invoices_controller.php 2 months ago manage_booking_by_key_controller.php 3 months ago manage_order_by_key_controller.php 3 months ago notifications_controller.php 3 months ago orders_controller.php 3 months ago pro_controller.php 2 months ago process_jobs_controller.php 3 months ago processes_controller.php 3 months ago search_controller.php 3 months ago services_controller.php 3 months ago settings_controller.php 3 months ago steps_controller.php 3 months ago stripe_connect_controller.php 2 months ago support_topics_controller.php 3 months ago todos_controller.php 3 months ago transactions_controller.php 3 months ago wizard_controller.php 2 months ago
settings_controller.php
547 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5
6
7 if ( ! class_exists( 'OsSettingsController' ) ) :
8
9
10 class OsSettingsController extends OsController {
11
12
13 function __construct() {
14 parent::__construct();
15
16 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'settings/';
17 $this->vars['page_header'] = OsMenuHelper::get_menu_items_by_id( 'settings' );
18 $this->vars['pre_page_header'] = OsMenuHelper::get_label_by_id( 'settings' );
19 $this->vars['breadcrumbs'][] = array(
20 'label' => __( 'Settings', 'latepoint' ),
21 'link' => OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'settings', 'general' ) ),
22 );
23 }
24
25 public function generate_instant_booking_page_url() {
26 $url_settings = [];
27 $instant_booking_settings = $this->params['instant_booking'] ?? [];
28 if ( ! empty( $instant_booking_settings['selected_agent'] ) ) {
29 $url_settings['selected_agent'] = $instant_booking_settings['selected_agent'];
30 }
31 if ( ! empty( $instant_booking_settings['selected_location'] ) ) {
32 $url_settings['selected_location'] = $instant_booking_settings['selected_location'];
33 }
34 if ( ! empty( $instant_booking_settings['selected_service'] ) ) {
35 $url_settings['selected_service'] = $instant_booking_settings['selected_service'];
36 }
37 if ( ! empty( $instant_booking_settings['background_pattern'] ) ) {
38 $url_settings['background_pattern'] = $instant_booking_settings['background_pattern'];
39 }
40 if ( ! empty( $instant_booking_settings['hide_side_panel'] ) && $instant_booking_settings['hide_side_panel'] == LATEPOINT_VALUE_ON ) {
41 $url_settings['hide_side_panel'] = 'yes';
42 }
43 if ( ! empty( $instant_booking_settings['hide_summary'] ) && $instant_booking_settings['hide_summary'] == LATEPOINT_VALUE_ON ) {
44 $url_settings['hide_summary'] = 'yes';
45 }
46
47
48 $url = OsSettingsHelper::generate_instant_booking_page_url( $url_settings );
49
50 $this->send_json(
51 [
52 'status' => LATEPOINT_STATUS_SUCCESS,
53 'message' => $url,
54 ]
55 );
56 }
57
58 public function generate_instant_booking_page() {
59 $agents = new OsAgentModel();
60 $this->vars['agents'] = $agents->should_be_active()->get_results_as_models();
61 $services = new OsServiceModel();
62 $this->vars['services'] = $services->should_be_active()->get_results_as_models();
63 $locations = new OsLocationModel();
64 $this->vars['locations'] = $locations->should_be_active()->get_results_as_models();
65
66 $url_settings = [];
67 if ( ! empty( $this->params['agent_id'] ) ) {
68 $this->vars['selected_agent_id'] = sanitize_text_field( $this->params['agent_id'] );
69 $url_settings['selected_agent'] = sanitize_text_field( $this->params['agent_id'] );
70 }
71 if ( ! empty( $this->params['location_id'] ) ) {
72 $this->vars['selected_location_id'] = sanitize_text_field( $this->params['location_id'] );
73 $url_settings['selected_location'] = sanitize_text_field( $this->params['location_id'] );
74 }
75 if ( ! empty( $this->params['service_id'] ) ) {
76 $this->vars['selected_service_id'] = sanitize_text_field( $this->params['service_id'] );
77 $url_settings['selected_service'] = sanitize_text_field( $this->params['service_id'] );
78 }
79
80 if ( ! empty( $this->params['background_pattern'] ) ) {
81 $this->vars['background_pattern'] = sanitize_text_field( $this->params['background_pattern'] );
82 $url_settings['background_pattern'] = sanitize_text_field( $this->params['background_pattern'] );
83 }
84
85 $this->vars['instant_booking_page_url'] = OsSettingsHelper::generate_instant_booking_page_url( $url_settings );
86 $this->vars['patterns'] = OsSettingsHelper::instant_page_background_patterns();
87
88 $this->format_render( __FUNCTION__ );
89 }
90
91 public function export_data() {
92 // Verify nonce.
93 $this->check_nonce( 'export_data' );
94
95 $this->set_layout( 'pure' );
96 $this->vars['content'] = OsSettingsHelper::export_data();
97 $this->format_render( __FUNCTION__ );
98 }
99
100 public function version_5_intro() {
101 $this->set_layout( 'full_modal' );
102 $this->format_render( __FUNCTION__ );
103 }
104
105 public function import_modal() {
106 $this->set_layout( 'full_modal' );
107 $this->format_render( __FUNCTION__ );
108 }
109
110 public function get_pro() {
111 $this->format_render( __FUNCTION__ );
112 }
113
114 public function start_import() {
115 $this->check_nonce( 'import_json_data' );
116 if ( $this->params['latepoint_data_erase_acknowledgement'] != 'on' ) {
117 $this->send_json(
118 array(
119 'status' => LATEPOINT_STATUS_ERROR,
120 'message' => __( 'You have to acknowledge the data erase warning', 'latepoint' ),
121 )
122 );
123 }
124
125 if ( ! empty( $this->files['latepoint_json_data']['tmp_name'][0] ) ) {
126 WP_Filesystem();
127 global $wp_filesystem;
128
129 $temp_file = $this->files['latepoint_json_data']['tmp_name'][0];
130 $content = $wp_filesystem->get_contents( $temp_file );
131
132 if ( $content === false ) {
133 $status = LATEPOINT_STATUS_ERROR;
134 $message = __( 'Error reading import file', 'latepoint' );
135 } else {
136 try {
137 if ( OsSettingsHelper::import_data( $content ) ) {
138 $status = LATEPOINT_STATUS_SUCCESS;
139 $message = __( 'Data imported', 'latepoint' );
140
141 }
142 } catch ( Exception $e ) {
143 $status = LATEPOINT_STATUS_ERROR;
144 $message = $e->getMessage();
145 }
146 }
147 } else {
148
149 $status = LATEPOINT_STATUS_ERROR;
150 $message = __( 'You must upload a JSON file to import data from', 'latepoint' );
151 }
152
153
154 $this->send_json(
155 array(
156 'status' => $status,
157 'message' => $message,
158 )
159 );
160 }
161
162 public function steps_order_modal() {
163 $this->vars['steps'] = OsStepsHelper::unflatten_steps( OsStepsHelper::get_step_codes_in_order( true ) );
164
165 $this->format_render( __FUNCTION__ );
166 }
167
168 public function update_steps_order() {
169 $this->check_nonce( 'update_steps_order' );
170 $new_order = explode( ',', $this->params['steps_order'] );
171 $errors = [];
172
173 if ( $new_order ) {
174 $errors = OsStepsHelper::check_steps_for_errors( $new_order, OsStepsHelper::get_step_codes_with_rules() );
175 if ( empty( $errors ) ) {
176 OsStepsHelper::save_step_codes_in_order( $new_order );
177 }
178 }
179
180 if ( empty( $errors ) ) {
181 $status = LATEPOINT_STATUS_SUCCESS;
182 $message = __( 'Order of steps has been successfully updated', 'latepoint' );
183 } else {
184 $status = LATEPOINT_STATUS_ERROR;
185 $message = implode( ', ', $errors );
186 }
187
188 if ( $this->get_return_format() == 'json' ) {
189 $this->send_json(
190 array(
191 'status' => $status,
192 'message' => $message,
193 )
194 );
195 }
196 }
197
198
199 public function set_menu_layout_style() {
200 $this->check_nonce( 'set_menu_layout_style' );
201 $menu_layout_style = ( isset( $this->params['menu_layout_style'] ) && in_array( $this->params['menu_layout_style'], [ 'full', 'compact' ] ) ) ? $this->params['menu_layout_style'] : 'full';
202 OsSettingsHelper::set_menu_layout_style( $menu_layout_style );
203
204 if ( $this->get_return_format() == 'json' ) {
205 $this->send_json(
206 array(
207 'status' => LATEPOINT_STATUS_SUCCESS,
208 'message' => '',
209 )
210 );
211 }
212 }
213
214 public function notifications() {
215 $this->vars['notification_types'] = OsNotificationsHelper::get_available_notification_types();
216 $this->format_render( __FUNCTION__ );
217 }
218
219
220 public function pages() {
221 $this->vars['breadcrumbs'][] = array(
222 'label' => __( 'Pages Setup', 'latepoint' ),
223 'link' => false,
224 );
225
226 $pages = get_pages();
227
228 $this->vars['pages'] = $pages;
229
230 $this->format_render( __FUNCTION__ );
231 }
232
233 public function payments() {
234 $this->vars['breadcrumbs'][] = array(
235 'label' => __( 'Payment Processing', 'latepoint' ),
236 'link' => false,
237 );
238
239 $pages = get_pages();
240
241 $this->vars['pages'] = $pages;
242 $this->vars['payment_processors'] = OsPaymentsHelper::get_payment_processors();
243
244 $this->format_render( __FUNCTION__ );
245 }
246
247
248 public function work_periods() {
249
250 $this->vars['breadcrumbs'][] = array(
251 'label' => __( 'Work Schedule Settings', 'latepoint' ),
252 'link' => false,
253 );
254
255 $this->format_render( __FUNCTION__ );
256 }
257
258
259 public function general() {
260
261 $this->vars['breadcrumbs'][] = array(
262 'label' => __( 'General', 'latepoint' ),
263 'link' => false,
264 );
265
266
267 $this->format_render( __FUNCTION__ );
268 }
269
270 public function remove_chain_schedule() {
271 $this->check_nonce( 'remove_chain_schedule' );
272 $chain_id = $this->params['chain_id'];
273 if ( $chain_id && OsWorkPeriodsHelper::remove_periods_for_chain_id( $chain_id ) ) {
274 $response_html = __( 'Date Range Schedule Removed', 'latepoint' );
275 $status = LATEPOINT_STATUS_SUCCESS;
276 } else {
277 $response_html = __( 'Invalid Data', 'latepoint' );
278 $status = LATEPOINT_STATUS_ERROR;
279 }
280
281 if ( $this->get_return_format() == 'json' ) {
282 $this->send_json(
283 array(
284 'status' => $status,
285 'message' => $response_html,
286 )
287 );
288 }
289 }
290
291 public function remove_custom_day_schedule() {
292 $this->check_nonce( 'remove_custom_day_schedule' );
293 $target_date_string = $this->params['date'];
294 $args = [];
295 $args['agent_id'] = isset( $this->params['agent_id'] ) ? $this->params['agent_id'] : 0;
296 $args['service_id'] = isset( $this->params['service_id'] ) ? $this->params['service_id'] : 0;
297 $args['location_id'] = isset( $this->params['location_id'] ) ? $this->params['location_id'] : 0;
298 if ( OsUtilHelper::is_date_valid( $target_date_string ) && OsWorkPeriodsHelper::remove_periods_for_date( $target_date_string, $args ) ) {
299 $response_html = __( 'Custom Day Schedule Removed', 'latepoint' );
300 $status = LATEPOINT_STATUS_SUCCESS;
301 } else {
302 $response_html = __( 'Invalid Date', 'latepoint' );
303 $status = LATEPOINT_STATUS_ERROR;
304 }
305
306 if ( $this->get_return_format() == 'json' ) {
307 $this->send_json(
308 array(
309 'status' => $status,
310 'message' => $response_html,
311 )
312 );
313 }
314 }
315
316
317 public function save_columns_for_bookings_table() {
318 // Verify nonce.
319 $this->check_nonce( 'bookings_table_columns' );
320
321 $selected_columns = [];
322 if ( isset( $this->params['selected_columns'] ) && $this->params['selected_columns'] ) {
323 foreach ( $this->params['selected_columns'] as $column_type => $columns ) {
324 foreach ( $columns as $column_key => $selected_column ) {
325 if ( $selected_column == 'on' ) {
326 $selected_columns[ $column_type ][] = $column_key;
327 }
328 }
329 }
330 }
331 OsSettingsHelper::save_setting_by_name( 'bookings_table_columns', $selected_columns );
332 if ( $this->get_return_format() == 'json' ) {
333 $this->send_json(
334 array(
335 'status' => LATEPOINT_STATUS_SUCCESS,
336 'message' => __( 'Columns Saved', 'latepoint' ),
337 )
338 );
339 }
340 }
341
342 public function premium_modal() {
343
344 $this->set_layout( 'none' );
345 $response_html = $this->format_render_return( __FUNCTION__ );
346 $this->send_json(
347 array(
348 'status' => LATEPOINT_STATUS_SUCCESS,
349 'message' => $response_html,
350 )
351 );
352 }
353
354 public function save_custom_day_schedule() {
355 $this->check_nonce( 'save_custom_day_schedule' );
356 $response_html = __( 'Work Schedule Updated', 'latepoint' );
357 $status = LATEPOINT_STATUS_SUCCESS;
358 $day_date = new OsWpDateTime( $this->params['start_custom_date'] );
359 // if end date is provided and is range
360 $period_type = ( $this->params['period_type'] == 'range' && $this->params['end_custom_date'] ) ? 'range' : 'single';
361
362 $start_date = new OsWpDateTime( $this->params['start_custom_date'] );
363 $end_date = ( $period_type == 'range' ) ? new OsWpDateTime( $this->params['end_custom_date'] ) : $start_date;
364 $chain_id = ( isset( $this->params['chain_id'] ) ) ? $this->params['chain_id'] : false;
365 $existing_work_periods_ids = ( isset( $this->params['existing_work_periods_ids'] ) ) ? $this->params['existing_work_periods_ids'] : false;
366
367 // remove existing chained periods by chain ID
368 if ( $chain_id ) {
369 $work_periods_to_delete = new OsWorkPeriodModel();
370 $work_periods_to_delete->delete_where( [ 'chain_id' => $chain_id ] );
371 if ( $period_type == 'single' ) {
372 $chain_id = false;
373 }
374 } else {
375 $chain_id = ( $period_type == 'range' ) ? uniqid() : false;
376 }
377
378 // remove existing periods by period ID
379 if ( $existing_work_periods_ids ) {
380 $work_periods_to_delete = new OsWorkPeriodModel();
381 $delete_ids = explode( ',', $existing_work_periods_ids );
382 foreach ( $delete_ids as $delete_id ) {
383 $work_periods_to_delete->delete_where( [ 'id' => $delete_id ] );
384 }
385 }
386
387 for ( $day_date = clone $start_date; $day_date <= $end_date; $day_date->modify( '+1 day' ) ) {
388 $work_periods = $this->params['work_periods'];
389 foreach ( $work_periods as &$work_period ) {
390 $work_period['custom_date'] = $day_date->format( 'Y-m-d' );
391 $work_period['week_day'] = $day_date->format( 'N' );
392 $work_period['chain_id'] = $chain_id ? $chain_id : null;
393 }
394 unset( $work_period );
395
396 OsWorkPeriodsHelper::save_work_periods( $work_periods, true );
397 }
398
399 if ( $this->get_return_format() == 'json' ) {
400 $this->send_json(
401 array(
402 'status' => $status,
403 'message' => $response_html,
404 )
405 );
406 }
407 }
408
409
410 public function custom_day_schedule_form() {
411 $target_date_string = isset( $this->params['target_date'] ) ? $this->params['target_date'] : 'now + 1 month';
412 $this->vars['date_is_preselected'] = isset( $this->params['target_date'] );
413 $this->vars['target_date'] = new OsWpDateTime( $target_date_string );
414 $this->vars['day_off'] = isset( $this->params['day_off'] ) ? true : false;
415 $this->vars['agent_id'] = isset( $this->params['agent_id'] ) ? $this->params['agent_id'] : 0;
416 $this->vars['service_id'] = isset( $this->params['service_id'] ) ? $this->params['service_id'] : 0;
417 $this->vars['location_id'] = isset( $this->params['location_id'] ) ? $this->params['location_id'] : 0;
418 $chain_id = isset( $this->params['chain_id'] ) ? $this->params['chain_id'] : false;
419 $this->vars['chain_id'] = $chain_id;
420 $this->vars['chain_end_date'] = false;
421 if ( $chain_id ) {
422 $work_period = new OsWorkPeriodModel();
423 $chained_work_period = $work_period->where( [ 'chain_id' => $chain_id ] )->order_by( 'custom_date desc' )->set_limit( 1 )->get_results_as_models();
424 if ( $chained_work_period ) {
425 $this->vars['chain_end_date'] = new OsWpDateTime( $chained_work_period->custom_date );
426 } else {
427 $this->vars['chain_id'] = false;
428 }
429 }
430 $this->format_render( __FUNCTION__ );
431 }
432
433
434 public function update_work_periods() {
435 $this->check_nonce( 'update_work_periods' );
436 OsWorkPeriodsHelper::save_work_periods( $this->params['work_periods'] );
437 $response_html = __( 'Work Schedule Updated', 'latepoint' );
438 $status = LATEPOINT_STATUS_SUCCESS;
439
440 if ( $this->get_return_format() == 'json' ) {
441 $this->send_json(
442 array(
443 'status' => $status,
444 'message' => $response_html,
445 )
446 );
447 }
448 }
449
450
451 public function update() {
452 $this->check_nonce( 'update_settings' );
453 $errors = array();
454
455 if ( $this->params['settings'] ) {
456 // make sure thousands and decimal separator are not the same symbol
457 if ( isset( $this->params['settings']['thousand_separator'] ) && isset( $this->params['settings']['decimal_separator'] ) && ( $this->params['settings']['thousand_separator'] == $this->params['settings']['decimal_separator'] ) ) {
458 $this->params['settings']['thousand_separator'] = '';
459 }
460 foreach ( $this->params['settings'] as $setting_name => $setting_value ) {
461 $setting = new OsSettingsModel();
462 $setting = $setting->load_by_name( $setting_name );
463 $is_new_record = $setting->is_new_record();
464 if ( ! $is_new_record ) {
465 $old_setting_value = $setting->value;
466 }
467 $setting->name = $setting_name;
468 $setting->value = OsSettingsHelper::prepare_value( $setting_name, $setting_value );
469 if ( $setting->save() ) {
470 if ( $is_new_record ) {
471 do_action( 'latepoint_setting_created', $setting );
472 } else {
473 do_action( 'latepoint_setting_updated', $setting, $old_setting_value );
474 }
475 } else {
476 $errors[] = $setting->get_error_messages();
477 }
478 }
479
480 do_action( 'latepoint_settings_updated', $this->params['settings'] );
481 }
482
483 if ( empty( $errors ) ) {
484 $response_html = esc_html__( 'Settings Updated', 'latepoint' );
485 $status = LATEPOINT_STATUS_SUCCESS;
486 } else {
487 $response_html = esc_html__( 'Settings Updated With Errors:', 'latepoint' ) . implode( ', ', $errors );
488 $status = LATEPOINT_STATUS_ERROR;
489 }
490
491 if ( $this->get_return_format() == 'json' ) {
492 $this->send_json(
493 array(
494 'status' => $status,
495 'message' => $response_html,
496 )
497 );
498 }
499 }
500
501 public function load_step_settings() {
502 }
503
504
505 public function load_work_period_form() {
506 $args = [
507 'week_day' => 1,
508 'agent_id' => 0,
509 'service_id' => 0,
510 'location_id' => 0,
511 ];
512
513 if ( isset( $this->params['week_day'] ) ) {
514 $args['week_day'] = $this->params['week_day'];
515 }
516 if ( isset( $this->params['agent_id'] ) ) {
517 $args['agent_id'] = $this->params['agent_id'];
518 }
519 if ( isset( $this->params['service_id'] ) ) {
520 $args['service_id'] = $this->params['service_id'];
521 }
522 if ( isset( $this->params['location_id'] ) ) {
523 $args['location_id'] = $this->params['location_id'];
524 }
525
526 $field_prefix = 'work_periods';
527 if ( isset( $this->params['field_prefix'] ) ) {
528 $field_prefix = preg_replace( '/[^a-zA-Z0-9_\[\]]/', '', $this->params['field_prefix'] );
529 }
530
531 $response_html = OsWorkPeriodsHelper::generate_work_period_form( $args, true, $field_prefix );
532 $status = LATEPOINT_STATUS_SUCCESS;
533
534 if ( $this->get_return_format() == 'json' ) {
535 $this->send_json(
536 array(
537 'status' => $status,
538 'message' => $response_html,
539 )
540 );
541 }
542 }
543 }
544
545
546 endif;
547