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