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