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