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