PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.1.7
LatePoint – Calendar Booking Plugin for Appointments and Events v5.1.7
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
381 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 save_custom_day_schedule() {
218 $this->check_nonce( 'save_custom_day_schedule' );
219 $response_html = __( 'Work Schedule Updated', 'latepoint' );
220 $status = LATEPOINT_STATUS_SUCCESS;
221 $day_date = new OsWpDateTime( $this->params['start_custom_date'] );
222 // if end date is provided and is range
223 $period_type = ( $this->params['period_type'] == 'range' && $this->params['end_custom_date'] ) ? 'range' : 'single';
224
225 $start_date = new OsWpDateTime( $this->params['start_custom_date'] );
226 $end_date = ( $period_type == 'range' ) ? new OsWpDateTime( $this->params['end_custom_date'] ) : $start_date;
227 $chain_id = ( isset( $this->params['chain_id'] ) ) ? $this->params['chain_id'] : false;
228 $existing_work_periods_ids = ( isset( $this->params['existing_work_periods_ids'] ) ) ? $this->params['existing_work_periods_ids'] : false;
229
230 // remove existing chained periods by chain ID
231 if ( $chain_id ) {
232 $work_periods_to_delete = new OsWorkPeriodModel();
233 $work_periods_to_delete->delete_where( [ 'chain_id' => $chain_id ] );
234 if ( $period_type == 'single' ) {
235 $chain_id = false;
236 }
237 } else {
238 $chain_id = ( $period_type == 'range' ) ? uniqid() : false;
239 }
240
241 // remove existing periods by period ID
242 if ( $existing_work_periods_ids ) {
243 $work_periods_to_delete = new OsWorkPeriodModel();
244 $delete_ids = explode( ',', $existing_work_periods_ids );
245 foreach ( $delete_ids as $delete_id ) {
246 $work_periods_to_delete->delete_where( [ 'id' => $delete_id ] );
247 }
248 }
249
250 for ( $day_date = clone $start_date; $day_date <= $end_date; $day_date->modify( '+1 day' ) ) {
251 $work_periods = $this->params['work_periods'];
252 foreach ( $work_periods as &$work_period ) {
253 $work_period['custom_date'] = $day_date->format( 'Y-m-d' );
254 $work_period['week_day'] = $day_date->format( 'N' );
255 $work_period['chain_id'] = $chain_id ? $chain_id : null;
256 }
257 unset( $work_period );
258
259 OsWorkPeriodsHelper::save_work_periods( $work_periods, true );
260 }
261
262 if ( $this->get_return_format() == 'json' ) {
263 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
264 }
265 }
266
267
268 public function custom_day_schedule_form() {
269 $target_date_string = isset( $this->params['target_date'] ) ? $this->params['target_date'] : 'now + 1 month';
270 $this->vars['date_is_preselected'] = isset( $this->params['target_date'] );
271 $this->vars['target_date'] = new OsWpDateTime( $target_date_string );
272 $this->vars['day_off'] = isset( $this->params['day_off'] ) ? true : false;
273 $this->vars['agent_id'] = isset( $this->params['agent_id'] ) ? $this->params['agent_id'] : 0;
274 $this->vars['service_id'] = isset( $this->params['service_id'] ) ? $this->params['service_id'] : 0;
275 $this->vars['location_id'] = isset( $this->params['location_id'] ) ? $this->params['location_id'] : 0;
276 $chain_id = isset( $this->params['chain_id'] ) ? $this->params['chain_id'] : false;
277 $this->vars['chain_id'] = $chain_id;
278 $this->vars['chain_end_date'] = false;
279 if ( $chain_id ) {
280 $work_period = new OsWorkPeriodModel();
281 $chained_work_period = $work_period->where( [ 'chain_id' => $chain_id ] )->order_by( 'custom_date desc' )->set_limit( 1 )->get_results_as_models();
282 if ( $chained_work_period ) {
283 $this->vars['chain_end_date'] = new OsWpDateTime( $chained_work_period->custom_date );
284 } else {
285 $this->vars['chain_id'] = false;
286 }
287 }
288 $this->format_render( __FUNCTION__ );
289 }
290
291
292 public function update_work_periods() {
293 $this->check_nonce( 'update_work_periods' );
294 OsWorkPeriodsHelper::save_work_periods( $this->params['work_periods'] );
295 $response_html = __( 'Work Schedule Updated', 'latepoint' );
296 $status = LATEPOINT_STATUS_SUCCESS;
297
298 if ( $this->get_return_format() == 'json' ) {
299 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
300 }
301 }
302
303
304 public function update() {
305 $this->check_nonce( 'update_settings' );
306 $errors = array();
307
308 if ( $this->params['settings'] ) {
309 // make sure thousands and decimal separator are not the same symbol
310 if ( isset( $this->params['settings']['thousand_separator'] ) && isset( $this->params['settings']['decimal_separator'] ) && ( $this->params['settings']['thousand_separator'] == $this->params['settings']['decimal_separator'] ) ) {
311 $this->params['settings']['thousand_separator'] = '';
312 }
313 foreach ( $this->params['settings'] as $setting_name => $setting_value ) {
314 $setting = new OsSettingsModel();
315 $setting = $setting->load_by_name( $setting_name );
316 $is_new_record = $setting->is_new_record();
317 if ( ! $is_new_record ) {
318 $old_setting_value = $setting->value;
319 }
320 $setting->name = $setting_name;
321 $setting->value = OsSettingsHelper::prepare_value( $setting_name, $setting_value );
322 if ( $setting->save() ) {
323 if ( $is_new_record ) {
324 do_action( 'latepoint_setting_created', $setting );
325 } else {
326 do_action( 'latepoint_setting_updated', $setting, $old_setting_value );
327 }
328 } else {
329 $errors[] = $setting->get_error_messages();
330 }
331 }
332
333 do_action( 'latepoint_settings_updated', $this->params['settings'] );
334 }
335
336 if ( empty( $errors ) ) {
337 $response_html = esc_html__( 'Settings Updated', 'latepoint' );
338 $status = LATEPOINT_STATUS_SUCCESS;
339 } else {
340 $response_html = esc_html__( 'Settings Updated With Errors:', 'latepoint' ) . implode( ', ', $errors );
341 $status = LATEPOINT_STATUS_ERROR;
342 }
343
344 if ( $this->get_return_format() == 'json' ) {
345 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
346 }
347 }
348
349 public function load_step_settings() {
350
351 }
352
353
354 public function load_work_period_form() {
355 $args = [ 'week_day' => 1, 'agent_id' => 0, 'service_id' => 0, 'location_id' => 0 ];
356
357 if ( isset( $this->params['week_day'] ) ) {
358 $args['week_day'] = $this->params['week_day'];
359 }
360 if ( isset( $this->params['agent_id'] ) ) {
361 $args['agent_id'] = $this->params['agent_id'];
362 }
363 if ( isset( $this->params['service_id'] ) ) {
364 $args['service_id'] = $this->params['service_id'];
365 }
366 if ( isset( $this->params['location_id'] ) ) {
367 $args['location_id'] = $this->params['location_id'];
368 }
369
370 $response_html = OsWorkPeriodsHelper::generate_work_period_form( $args );
371 $status = LATEPOINT_STATUS_SUCCESS;
372
373 if ( $this->get_return_format() == 'json' ) {
374 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
375 }
376 }
377
378 }
379
380
381 endif;