PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.2.10
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.2.10
5.6.9 5.6.8 5.6.7 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 4 months ago auth_controller.php 4 months ago booking_form_settings_controller.php 5 months ago bookings_controller.php 1 year ago calendars_controller.php 9 months ago carts_controller.php 1 year ago controller.php 9 months ago customer_cabinet_controller.php 4 months ago customers_controller.php 4 months ago dashboard_controller.php 9 months ago default_agent_controller.php 1 year ago events_controller.php 1 year ago form_fields_controller.php 9 months ago integrations_controller.php 9 months ago invoices_controller.php 4 months ago manage_booking_by_key_controller.php 4 months ago manage_order_by_key_controller.php 1 year ago notifications_controller.php 1 year ago orders_controller.php 4 months ago pro_controller.php 1 year ago process_jobs_controller.php 4 months ago processes_controller.php 4 months ago search_controller.php 1 year ago services_controller.php 9 months ago settings_controller.php 4 months ago steps_controller.php 9 months ago stripe_connect_controller.php 9 months ago support_topics_controller.php 1 year ago todos_controller.php 1 year ago transactions_controller.php 4 months ago wizard_controller.php 4 months ago
settings_controller.php
451 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( 'label' => __( 'Settings', 'latepoint' ), 'link' => OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'settings', 'general' ) ) );
20 }
21
22 public function generate_instant_booking_page_url(){
23 $url_settings = [];
24 $instant_booking_settings = $this->params['instant_booking'] ?? [];
25 if(!empty($instant_booking_settings['selected_agent'])) $url_settings['selected_agent'] = $instant_booking_settings['selected_agent'];
26 if(!empty($instant_booking_settings['selected_location'])) $url_settings['selected_location'] = $instant_booking_settings['selected_location'];
27 if(!empty($instant_booking_settings['selected_service'])) $url_settings['selected_service'] = $instant_booking_settings['selected_service'];
28 if(!empty($instant_booking_settings['background_pattern'])) $url_settings['background_pattern'] = $instant_booking_settings['background_pattern'];
29 if(!empty($instant_booking_settings['hide_side_panel']) && $instant_booking_settings['hide_side_panel'] == LATEPOINT_VALUE_ON){
30 $url_settings['hide_side_panel'] = 'yes';
31 }
32 if(!empty($instant_booking_settings['hide_summary']) && $instant_booking_settings['hide_summary'] == LATEPOINT_VALUE_ON){
33 $url_settings['hide_summary'] = 'yes';
34 }
35
36
37 $url = OsSettingsHelper::generate_instant_booking_page_url($url_settings);
38
39 $this->send_json( [ 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => $url ] );
40 }
41
42 public function generate_instant_booking_page(){
43 $agents = new OsAgentModel();
44 $this->vars['agents'] = $agents->should_be_active()->get_results_as_models();
45 $services = new OsServiceModel();
46 $this->vars['services'] = $services->should_be_active()->get_results_as_models();
47 $locations = new OsLocationModel();
48 $this->vars['locations'] = $locations->should_be_active()->get_results_as_models();
49
50 $url_settings = [];
51 if(!empty($this->params['agent_id'])){
52 $this->vars['selected_agent_id'] = sanitize_text_field($this->params['agent_id']);
53 $url_settings['selected_agent'] = sanitize_text_field($this->params['agent_id']);
54 }
55 if(!empty($this->params['location_id'])){
56 $this->vars['selected_location_id'] = sanitize_text_field($this->params['location_id']);
57 $url_settings['selected_location'] = sanitize_text_field($this->params['location_id']);
58 }
59 if(!empty($this->params['service_id'])){
60 $this->vars['selected_service_id'] = sanitize_text_field($this->params['service_id']);
61 $url_settings['selected_service'] = sanitize_text_field($this->params['service_id']);
62 }
63
64 if(!empty($this->params['background_pattern'])){
65 $this->vars['background_pattern'] = sanitize_text_field($this->params['background_pattern']);
66 $url_settings['background_pattern'] = sanitize_text_field($this->params['background_pattern']);
67 }
68
69 $this->vars['instant_booking_page_url'] = OsSettingsHelper::generate_instant_booking_page_url($url_settings);
70 $this->vars['patterns'] = OsSettingsHelper::instant_page_background_patterns();
71
72 $this->format_render( __FUNCTION__ );
73 }
74
75 public function export_data() {
76 // Verify nonce.
77 $this->check_nonce( 'export_data' );
78
79 $this->set_layout( 'pure' );
80 $this->vars['content'] = OsSettingsHelper::export_data();
81 $this->format_render( __FUNCTION__ );
82 }
83
84 public function version_5_intro() {
85 $this->set_layout( 'full_modal' );
86 $this->format_render( __FUNCTION__ );
87 }
88
89 public function import_modal() {
90 $this->set_layout( 'full_modal' );
91 $this->format_render( __FUNCTION__ );
92 }
93
94 public function get_pro() {
95 $this->format_render( __FUNCTION__ );
96 }
97
98 public function start_import() {
99 $this->check_nonce( 'import_json_data' );
100 if ( $this->params['latepoint_data_erase_acknowledgement'] != 'on' ) {
101 $this->send_json( array( 'status' => LATEPOINT_STATUS_ERROR, 'message' => __( 'You have to acknowledge the data erase warning', 'latepoint' ) ) );
102 }
103
104 if ( !empty( $this->files['latepoint_json_data']['tmp_name'][0] )) {
105 WP_Filesystem();
106 global $wp_filesystem;
107
108 $temp_file = $this->files['latepoint_json_data']['tmp_name'][0];
109 $content = $wp_filesystem->get_contents( $temp_file );
110
111 if ( $content === false ) {
112 $status = LATEPOINT_STATUS_ERROR;
113 $message = __( 'Error reading import file', 'latepoint' );
114 } else {
115 try{
116 if ( OsSettingsHelper::import_data( $content ) ) {
117 $status = LATEPOINT_STATUS_SUCCESS;
118 $message = __( 'Data imported', 'latepoint' );
119
120 }
121 }catch(Exception $e){
122 $status = LATEPOINT_STATUS_ERROR;
123 $message = $e->getMessage();
124 }
125 }
126 } else {
127
128 $status = LATEPOINT_STATUS_ERROR;
129 $message = __( 'You must upload a JSON file to import data from', 'latepoint' );
130 }
131
132
133 $this->send_json( array( 'status' => $status, 'message' => $message ) );
134
135 }
136
137 public function steps_order_modal() {
138 $this->vars['steps'] = OsStepsHelper::unflatten_steps( OsStepsHelper::get_step_codes_in_order( true ) );
139
140 $this->format_render( __FUNCTION__ );
141 }
142
143 public function update_steps_order() {
144 $this->check_nonce( 'update_steps_order' );
145 $new_order = explode( ',', $this->params['steps_order'] );
146 $errors = [];
147
148 if ( $new_order ) {
149 $errors = OsStepsHelper::check_steps_for_errors( $new_order, OsStepsHelper::get_step_codes_with_rules() );
150 if ( empty( $errors ) ) {
151 OsStepsHelper::save_step_codes_in_order( $new_order );
152 }
153 }
154
155 if ( empty( $errors ) ) {
156 $status = LATEPOINT_STATUS_SUCCESS;
157 $message = __( 'Order of steps has been successfully updated', 'latepoint' );
158 } else {
159 $status = LATEPOINT_STATUS_ERROR;
160 $message = implode( ', ', $errors );
161 }
162
163 if ( $this->get_return_format() == 'json' ) {
164 $this->send_json( array( 'status' => $status, 'message' => $message ) );
165 }
166 }
167
168
169 public function set_menu_layout_style() {
170 $this->check_nonce( 'set_menu_layout_style' );
171 $menu_layout_style = ( isset( $this->params['menu_layout_style'] ) && in_array( $this->params['menu_layout_style'], [ 'full', 'compact' ] ) ) ? $this->params['menu_layout_style'] : 'full';
172 OsSettingsHelper::set_menu_layout_style( $menu_layout_style );
173
174 if ( $this->get_return_format() == 'json' ) {
175 $this->send_json( array( 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => '' ) );
176 }
177 }
178
179 public function notifications() {
180 $this->vars['notification_types'] = OsNotificationsHelper::get_available_notification_types();
181 $this->format_render( __FUNCTION__ );
182 }
183
184
185 public function pages() {
186 $this->vars['breadcrumbs'][] = array( 'label' => __( 'Pages Setup', 'latepoint' ), 'link' => false );
187
188 $pages = get_pages();
189
190 $this->vars['pages'] = $pages;
191
192 $this->format_render( __FUNCTION__ );
193 }
194
195 public function payments() {
196 $this->vars['breadcrumbs'][] = array( 'label' => __( 'Payment Processing', 'latepoint' ), 'link' => false );
197
198 $pages = get_pages();
199
200 $this->vars['pages'] = $pages;
201 $this->vars['payment_processors'] = OsPaymentsHelper::get_payment_processors();
202
203 $this->format_render( __FUNCTION__ );
204 }
205
206
207 public function work_periods() {
208
209 $this->vars['breadcrumbs'][] = array( 'label' => __( 'Work Schedule Settings', 'latepoint' ), 'link' => false );
210
211 $this->format_render( __FUNCTION__ );
212 }
213
214
215 public function general() {
216
217 $this->vars['breadcrumbs'][] = array( 'label' => __( 'General', 'latepoint' ), 'link' => false );
218
219
220 $this->format_render( __FUNCTION__ );
221 }
222
223 public function remove_chain_schedule() {
224 $this->check_nonce( 'remove_chain_schedule' );
225 $chain_id = $this->params['chain_id'];
226 if ( $chain_id && OsWorkPeriodsHelper::remove_periods_for_chain_id( $chain_id ) ) {
227 $response_html = __( 'Date Range Schedule Removed', 'latepoint' );
228 $status = LATEPOINT_STATUS_SUCCESS;
229 } else {
230 $response_html = __( 'Invalid Data', 'latepoint' );
231 $status = LATEPOINT_STATUS_ERROR;
232 }
233
234 if ( $this->get_return_format() == 'json' ) {
235 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
236 }
237 }
238
239 public function remove_custom_day_schedule() {
240 $this->check_nonce( 'remove_custom_day_schedule' );
241 $target_date_string = $this->params['date'];
242 $args = [];
243 $args['agent_id'] = isset( $this->params['agent_id'] ) ? $this->params['agent_id'] : 0;
244 $args['service_id'] = isset( $this->params['service_id'] ) ? $this->params['service_id'] : 0;
245 $args['location_id'] = isset( $this->params['location_id'] ) ? $this->params['location_id'] : 0;
246 if ( OsUtilHelper::is_date_valid( $target_date_string ) && OsWorkPeriodsHelper::remove_periods_for_date( $target_date_string, $args ) ) {
247 $response_html = __( 'Custom Day Schedule Removed', 'latepoint' );
248 $status = LATEPOINT_STATUS_SUCCESS;
249 } else {
250 $response_html = __( 'Invalid Date', 'latepoint' );
251 $status = LATEPOINT_STATUS_ERROR;
252 }
253
254 if ( $this->get_return_format() == 'json' ) {
255 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
256 }
257 }
258
259
260 public function save_columns_for_bookings_table() {
261 // Verify nonce.
262 $this->check_nonce( 'bookings_table_columns' );
263
264 $selected_columns = [];
265 if ( isset( $this->params['selected_columns'] ) && $this->params['selected_columns'] ) {
266 foreach ( $this->params['selected_columns'] as $column_type => $columns ) {
267 foreach ( $columns as $column_key => $selected_column ) {
268 if ( $selected_column == 'on' ) {
269 $selected_columns[ $column_type ][] = $column_key;
270 }
271 }
272 }
273 }
274 OsSettingsHelper::save_setting_by_name( 'bookings_table_columns', $selected_columns );
275 if ( $this->get_return_format() == 'json' ) {
276 $this->send_json( array( 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => __( 'Columns Saved', 'latepoint' ) ) );
277 }
278 }
279
280 public function premium_modal(){
281
282 $this->set_layout( 'none' );
283 $response_html = $this->format_render_return( __FUNCTION__ );
284 $this->send_json( array( 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => $response_html ) );
285 }
286
287 public function save_custom_day_schedule() {
288 $this->check_nonce( 'save_custom_day_schedule' );
289 $response_html = __( 'Work Schedule Updated', 'latepoint' );
290 $status = LATEPOINT_STATUS_SUCCESS;
291 $day_date = new OsWpDateTime( $this->params['start_custom_date'] );
292 // if end date is provided and is range
293 $period_type = ( $this->params['period_type'] == 'range' && $this->params['end_custom_date'] ) ? 'range' : 'single';
294
295 $start_date = new OsWpDateTime( $this->params['start_custom_date'] );
296 $end_date = ( $period_type == 'range' ) ? new OsWpDateTime( $this->params['end_custom_date'] ) : $start_date;
297 $chain_id = ( isset( $this->params['chain_id'] ) ) ? $this->params['chain_id'] : false;
298 $existing_work_periods_ids = ( isset( $this->params['existing_work_periods_ids'] ) ) ? $this->params['existing_work_periods_ids'] : false;
299
300 // remove existing chained periods by chain ID
301 if ( $chain_id ) {
302 $work_periods_to_delete = new OsWorkPeriodModel();
303 $work_periods_to_delete->delete_where( [ 'chain_id' => $chain_id ] );
304 if ( $period_type == 'single' ) {
305 $chain_id = false;
306 }
307 } else {
308 $chain_id = ( $period_type == 'range' ) ? uniqid() : false;
309 }
310
311 // remove existing periods by period ID
312 if ( $existing_work_periods_ids ) {
313 $work_periods_to_delete = new OsWorkPeriodModel();
314 $delete_ids = explode( ',', $existing_work_periods_ids );
315 foreach ( $delete_ids as $delete_id ) {
316 $work_periods_to_delete->delete_where( [ 'id' => $delete_id ] );
317 }
318 }
319
320 for ( $day_date = clone $start_date; $day_date <= $end_date; $day_date->modify( '+1 day' ) ) {
321 $work_periods = $this->params['work_periods'];
322 foreach ( $work_periods as &$work_period ) {
323 $work_period['custom_date'] = $day_date->format( 'Y-m-d' );
324 $work_period['week_day'] = $day_date->format( 'N' );
325 $work_period['chain_id'] = $chain_id ? $chain_id : null;
326 }
327 unset( $work_period );
328
329 OsWorkPeriodsHelper::save_work_periods( $work_periods, true );
330 }
331
332 if ( $this->get_return_format() == 'json' ) {
333 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
334 }
335 }
336
337
338 public function custom_day_schedule_form() {
339 $target_date_string = isset( $this->params['target_date'] ) ? $this->params['target_date'] : 'now + 1 month';
340 $this->vars['date_is_preselected'] = isset( $this->params['target_date'] );
341 $this->vars['target_date'] = new OsWpDateTime( $target_date_string );
342 $this->vars['day_off'] = isset( $this->params['day_off'] ) ? true : false;
343 $this->vars['agent_id'] = isset( $this->params['agent_id'] ) ? $this->params['agent_id'] : 0;
344 $this->vars['service_id'] = isset( $this->params['service_id'] ) ? $this->params['service_id'] : 0;
345 $this->vars['location_id'] = isset( $this->params['location_id'] ) ? $this->params['location_id'] : 0;
346 $chain_id = isset( $this->params['chain_id'] ) ? $this->params['chain_id'] : false;
347 $this->vars['chain_id'] = $chain_id;
348 $this->vars['chain_end_date'] = false;
349 if ( $chain_id ) {
350 $work_period = new OsWorkPeriodModel();
351 $chained_work_period = $work_period->where( [ 'chain_id' => $chain_id ] )->order_by( 'custom_date desc' )->set_limit( 1 )->get_results_as_models();
352 if ( $chained_work_period ) {
353 $this->vars['chain_end_date'] = new OsWpDateTime( $chained_work_period->custom_date );
354 } else {
355 $this->vars['chain_id'] = false;
356 }
357 }
358 $this->format_render( __FUNCTION__ );
359 }
360
361
362 public function update_work_periods() {
363 $this->check_nonce( 'update_work_periods' );
364 OsWorkPeriodsHelper::save_work_periods( $this->params['work_periods'] );
365 $response_html = __( 'Work Schedule Updated', 'latepoint' );
366 $status = LATEPOINT_STATUS_SUCCESS;
367
368 if ( $this->get_return_format() == 'json' ) {
369 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
370 }
371 }
372
373
374 public function update() {
375 $this->check_nonce( 'update_settings' );
376 $errors = array();
377
378 if ( $this->params['settings'] ) {
379 // make sure thousands and decimal separator are not the same symbol
380 if ( isset( $this->params['settings']['thousand_separator'] ) && isset( $this->params['settings']['decimal_separator'] ) && ( $this->params['settings']['thousand_separator'] == $this->params['settings']['decimal_separator'] ) ) {
381 $this->params['settings']['thousand_separator'] = '';
382 }
383 foreach ( $this->params['settings'] as $setting_name => $setting_value ) {
384 $setting = new OsSettingsModel();
385 $setting = $setting->load_by_name( $setting_name );
386 $is_new_record = $setting->is_new_record();
387 if ( ! $is_new_record ) {
388 $old_setting_value = $setting->value;
389 }
390 $setting->name = $setting_name;
391 $setting->value = OsSettingsHelper::prepare_value( $setting_name, $setting_value );
392 if ( $setting->save() ) {
393 if ( $is_new_record ) {
394 do_action( 'latepoint_setting_created', $setting );
395 } else {
396 do_action( 'latepoint_setting_updated', $setting, $old_setting_value );
397 }
398 } else {
399 $errors[] = $setting->get_error_messages();
400 }
401 }
402
403 do_action( 'latepoint_settings_updated', $this->params['settings'] );
404 }
405
406 if ( empty( $errors ) ) {
407 $response_html = esc_html__( 'Settings Updated', 'latepoint' );
408 $status = LATEPOINT_STATUS_SUCCESS;
409 } else {
410 $response_html = esc_html__( 'Settings Updated With Errors:', 'latepoint' ) . implode( ', ', $errors );
411 $status = LATEPOINT_STATUS_ERROR;
412 }
413
414 if ( $this->get_return_format() == 'json' ) {
415 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
416 }
417 }
418
419 public function load_step_settings() {
420
421 }
422
423
424 public function load_work_period_form() {
425 $args = [ 'week_day' => 1, 'agent_id' => 0, 'service_id' => 0, 'location_id' => 0 ];
426
427 if ( isset( $this->params['week_day'] ) ) {
428 $args['week_day'] = $this->params['week_day'];
429 }
430 if ( isset( $this->params['agent_id'] ) ) {
431 $args['agent_id'] = $this->params['agent_id'];
432 }
433 if ( isset( $this->params['service_id'] ) ) {
434 $args['service_id'] = $this->params['service_id'];
435 }
436 if ( isset( $this->params['location_id'] ) ) {
437 $args['location_id'] = $this->params['location_id'];
438 }
439
440 $response_html = OsWorkPeriodsHelper::generate_work_period_form( $args );
441 $status = LATEPOINT_STATUS_SUCCESS;
442
443 if ( $this->get_return_format() == 'json' ) {
444 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
445 }
446 }
447
448 }
449
450
451 endif;