PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.2.2
LatePoint – Calendar Booking Plugin for Appointments and Events v5.2.2
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 / customer_cabinet_controller.php
latepoint / lib / controllers Last commit date
activities_controller.php 1 year 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
customer_cabinet_controller.php
484 lines
1 <?php
2 /*
3 * Copyright (c) 2023 LatePoint LLC. All rights reserved.
4 */
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10
11 if ( ! class_exists( 'OsCustomerCabinetController' ) ) :
12
13
14 class OsCustomerCabinetController extends OsController {
15
16 function __construct() {
17 parent::__construct();
18
19 $this->action_access['customer'] = array_merge( $this->action_access['customer'], [
20 'update',
21 'request_cancellation',
22 'print_booking_info',
23 'print_order_info',
24 'ical_download',
25 'process_reschedule_request',
26 'request_reschedule_calendar',
27 'view_order_summary_in_lightbox',
28 'view_booking_summary_in_lightbox',
29 'scheduling_summary_for_bundle',
30 'reload_booking_tile'
31 ] );
32 $this->action_access['public'] = array_merge( $this->action_access['public'], [
33 'logout',
34 'dashboard',
35 'login',
36 'do_login',
37 'password_reset_form',
38 'request_password_reset_token',
39 'change_password',
40 'set_account_password_on_booking_completion'
41 ] );
42 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'customer_cabinet/';
43 }
44
45
46 public function scheduling_summary_for_bundle() {
47 if ( ! filter_var( $this->params['order_item_id'], FILTER_VALIDATE_INT ) ) {
48 exit();
49 }
50 $order_item = new OsOrderItemModel( $this->params['order_item_id'] );
51 $order = new OsOrderModel( $order_item->order_id );
52
53 if ( $order->is_new_record() || ( $order->customer_id != OsAuthHelper::get_logged_in_customer_id() ) ) {
54 $this->send_json( array( 'status' => LATEPOINT_STATUS_ERROR, 'message' => __('Not Allowed', 'latepoint') ) );
55 }
56
57 $bundle = $order_item->build_original_object_from_item_data();
58 $this->vars['order_item'] = $order_item;
59 $this->vars['bundle'] = $bundle;
60 $this->format_render( __FUNCTION__ );
61 }
62
63 public function view_order_summary_in_lightbox() {
64 if ( ! filter_var( $this->params['order_id'], FILTER_VALIDATE_INT ) ) {
65 exit();
66 }
67 $order = new OsOrderModel( $this->params['order_id'] );
68
69 if ( $order->is_new_record() || ( $order->customer_id != OsAuthHelper::get_logged_in_customer_id() ) ) {
70 $this->send_json( array( 'status' => LATEPOINT_STATUS_ERROR, 'message' => __('Not Allowed', 'latepoint') ) );
71 }
72
73 $this->vars['order'] = $order;
74 $this->vars['price_breakdown_rows'] = $order->generate_price_breakdown_rows();
75 $this->format_render( __FUNCTION__ );
76 }
77
78 public function view_booking_summary_in_lightbox() {
79 if ( ! filter_var( $this->params['booking_id'], FILTER_VALIDATE_INT ) ) {
80 exit();
81 }
82 $booking = new OsBookingModel( $this->params['booking_id'] );
83 $order_item = new OsOrderItemModel( $booking->order_item_id );
84 $order = new OsOrderModel( $order_item->order_id );
85
86 if ( $order->is_new_record() || ( $order->customer_id != OsAuthHelper::get_logged_in_customer_id() ) ) {
87 $this->send_json( array( 'status' => LATEPOINT_STATUS_ERROR, 'message' => __('Not Allowed', 'latepoint') ) );
88 }
89
90 $this->vars['booking'] = $booking;
91 $this->vars['order_item'] = $order_item;
92 $this->vars['order'] = $order;
93 $this->format_render( __FUNCTION__ );
94 }
95
96
97 function print_order_info() {
98 if ( ! filter_var( $this->params['latepoint_order_id'], FILTER_VALIDATE_INT ) ) {
99 exit();
100 }
101 $order_id = $this->params['latepoint_order_id'];
102 if ( empty( $order_id ) ) {
103 return;
104 }
105 $order = new OsOrderModel( $order_id );
106 if ( $order->id && OsAuthHelper::is_customer_logged_in() && ( $order->customer_id == OsAuthHelper::get_logged_in_customer_id() ) ) {
107 $customer = $order->customer;
108 $this->vars['order'] = $order;
109 $this->vars['customer'] = $customer;
110 $this->set_layout( 'print' );
111 $content = $this->format_render_return( __FUNCTION__, [], [], true );
112 echo $content;
113 }
114 }
115
116 function print_booking_info() {
117 if ( ! filter_var( $this->params['latepoint_booking_id'], FILTER_VALIDATE_INT ) ) {
118 exit();
119 }
120 $booking_id = $this->params['latepoint_booking_id'];
121 if ( empty( $booking_id ) ) {
122 return;
123 }
124 $booking = new OsBookingModel( $booking_id );
125 if ( $booking->id && OsAuthHelper::is_customer_logged_in() && ( $booking->customer_id == OsAuthHelper::get_logged_in_customer_id() ) ) {
126 $customer = $booking->customer;
127 $this->vars['booking'] = $booking;
128 $this->vars['customer'] = $customer;
129 $this->set_layout( 'print' );
130 $content = $this->format_render_return( __FUNCTION__, [], [], true );
131 echo $content;
132 }
133 }
134
135 function ical_download() {
136 if ( ! filter_var( $this->params['latepoint_booking_id'], FILTER_VALIDATE_INT ) ) {
137 exit();
138 }
139 $booking_id = $this->params['latepoint_booking_id'];
140 if ( empty( $booking_id ) ) {
141 return;
142 }
143 $booking = new OsBookingModel( $booking_id );
144 if ( $booking->id && OsAuthHelper::is_customer_logged_in() && ( $booking->customer_id == OsAuthHelper::get_logged_in_customer_id() ) ) {
145
146 header( 'Content-Type: text/calendar; charset=utf-8' );
147 header( 'Content-Disposition: attachment; filename=booking_' . $booking->id . '.ics' );
148
149 echo OsBookingHelper::generate_ical_event_string( $booking );
150 }
151 }
152
153
154 function process_reschedule_request() {
155 if ( ! filter_var( $this->params['booking_id'], FILTER_VALIDATE_INT ) ) {
156 exit();
157 }
158 $booking = new OsBookingModel( $this->params['booking_id'] );
159
160 if ( empty( $booking->id ) || empty( $this->params['start_date'] ) || empty( $this->params['start_time'] ) ) {
161 return;
162 }
163
164 if ( ( OsAuthHelper::get_logged_in_customer_id() == $booking->customer_id ) && OsCustomerHelper::can_reschedule_booking( $booking ) ) {
165 $old_booking = clone $booking;
166 $booking->start_date = $this->params['start_date'];
167 $booking->start_time = $this->params['start_time'];
168
169 $booking->convert_start_datetime_into_server_timezone($booking->get_customer_timezone_name());
170
171 if ( $booking->is_start_date_and_time_set() ) {
172 $booking->calculate_end_date_and_time();
173 $booking->set_utc_datetimes();
174 }
175
176 // check if booking time is still available
177 if ( ! OsBookingHelper::is_booking_request_available( \LatePoint\Misc\BookingRequest::create_from_booking_model( $booking ), [ 'exclude_booking_ids' => [ $booking->id ] ] ) ) {
178 $response_html = __( 'Unfortunately the selected time slot is not available anymore, please select another timeslot.', 'latepoint' );
179 $status = LATEPOINT_STATUS_ERROR;
180 } else {
181 if ( OsSettingsHelper::is_on( 'change_status_on_customer_reschedule' ) ) {
182 $allowed_statuses = OsBookingHelper::get_statuses_list();
183 if ( isset( $allowed_statuses[ OsSettingsHelper::get_settings_value( 'status_to_set_after_customer_reschedule' ) ] ) ) {
184 $booking->status = OsSettingsHelper::get_settings_value( 'status_to_set_after_customer_reschedule' );
185 }
186 }
187 if ( $booking->save() ) {
188 /**
189 * Booking is updated
190 *
191 * @param {OsBookingModel} $this->>booking Updated instance of booking model
192 * @param {OsBookingModel} $old_booking Instance of booking model before it was updated
193 *
194 * @since 4.9.0
195 * @hook latepoint_booking_updated
196 *
197 */
198 do_action( 'latepoint_booking_updated', $booking, $old_booking );
199 $this->vars['booking'] = $booking;
200 $this->vars['timezone_name'] = OsTimeHelper::get_timezone_name_from_session();
201 $this->vars['viewer'] = 'customer';
202 $status = LATEPOINT_STATUS_SUCCESS;
203 $this->set_layout( 'none' );
204 $response_html = $this->format_render_return( __FUNCTION__, [], [], true );
205 } else {
206 OsDebugHelper::log( 'Error rescheduling appointment', 'booking_reschedule_error', $booking->get_error_messages() );
207 $response_html = __( 'Error! Please try again later', 'latepoint' );
208 $status = LATEPOINT_STATUS_ERROR;
209 }
210 }
211 } else {
212 $status = LATEPOINT_STATUS_ERROR;
213 $response_html = __( 'Error! LKDFU343', 'latepoint' );
214 }
215
216 if ( $this->get_return_format() == 'json' ) {
217 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
218 }
219 }
220
221 function request_reschedule_calendar() {
222 if ( ! filter_var( $this->params['booking_id'], FILTER_VALIDATE_INT ) ) {
223 exit();
224 }
225 $booking = new OsBookingModel( $this->params['booking_id'] );
226
227 if ( ! empty( $booking->id ) && ( OsAuthHelper::get_logged_in_customer_id() == $booking->customer_id ) && OsCustomerHelper::can_reschedule_booking( $booking ) ) {
228 $this->vars['booking'] = $booking;
229 $this->vars['calendar_start_date'] = ! empty( $this->params['calendar_start_date'] ) ? new OsWpDateTime( $this->params['calendar_start_date'] ) : new OsWpDateTime( 'today' );
230 $this->vars['timezone_name'] = $booking->get_customer_timezone_name();
231
232 $this->set_layout( 'none' );
233 $response_html = $this->format_render_return( __FUNCTION__, [], [], true );
234 } else {
235 $status = LATEPOINT_STATUS_ERROR;
236 $response_html = __( 'Reschedule is not allowed', 'latepoint' );
237 }
238 if ( $this->get_return_format() == 'json' ) {
239 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
240 }
241 }
242
243 function request_cancellation() {
244 if ( ! filter_var( $this->params['id'], FILTER_VALIDATE_INT ) ) {
245 exit();
246 }
247
248 $booking_id = $this->params['id'];
249 $booking = new OsBookingModel( $booking_id );
250 if ( ! empty( $booking->id ) && ( OsAuthHelper::get_logged_in_customer_id() == $booking->customer_id ) && OsCustomerHelper::can_cancel_booking( $booking ) ) {
251 if ( $booking->update_status( LATEPOINT_BOOKING_STATUS_CANCELLED ) ) {
252 $status = LATEPOINT_STATUS_SUCCESS;
253 $response_html = __( 'Appointment Status Updated', 'latepoint' );
254 } else {
255 $status = LATEPOINT_STATUS_ERROR;
256 $response_html = __( 'Error Updating Booking Status!', 'latepoint' ) . ' ' . implode( ',', $booking->get_error_messages() );
257 }
258 } else {
259 $status = LATEPOINT_STATUS_ERROR;
260 $response_html = __( 'Not allowed to cancel', 'latepoint' );
261 }
262 if ( $this->get_return_format() == 'json' ) {
263 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
264 }
265 }
266
267 /*
268 Update profile
269 */
270
271 public function update() {
272 $customer = OsAuthHelper::get_logged_in_customer();
273 if( !$customer ) {
274 exit();
275 }
276 $this->check_nonce('update_customer_'.$customer->get_uuid());
277
278
279 if($customer){
280 $old_customer_data = $customer->get_data_vars();
281 $customer->set_data( $this->params['customer'], LATEPOINT_PARAMS_SCOPE_CUSTOMER );
282 if ( $customer->save() ) {
283 $response_html = __( 'Information Saved', 'latepoint' );
284 $status = LATEPOINT_STATUS_SUCCESS;
285 do_action( 'latepoint_customer_updated', $customer, $old_customer_data );
286 } else {
287 $response_html = $customer->get_error_messages();
288 $status = LATEPOINT_STATUS_ERROR;
289 }
290 }else{
291 $response_html = __('Customer not found', 'latepoint');
292 $status = LATEPOINT_STATUS_ERROR;
293 }
294 if ( $this->get_return_format() == 'json' ) {
295 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
296 }
297 }
298
299 public function reload_booking_tile() {
300 if ( ! filter_var( $this->params['booking_id'], FILTER_VALIDATE_INT ) ) {
301 exit();
302 }
303
304 $booking_id = $this->params['booking_id'];
305 $booking = new OsBookingModel( $booking_id );
306
307 if ( $booking->id && OsAuthHelper::get_logged_in_customer_id() == $booking->customer_id ) {
308 $this->vars['booking'] = $booking;
309 $this->vars['is_upcoming_booking'] = $booking->is_upcoming();
310 $this->set_layout( 'none' );
311 $response_html = $this->format_render_return( '_booking_tile' );
312 $status = LATEPOINT_STATUS_SUCCESS;
313 } else {
314 $response_html = __( 'Invalid Booking', 'latepoint' );
315 $status = LATEPOINT_STATUS_ERROR;
316 }
317
318 if ( $this->get_return_format() == 'json' ) {
319 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
320 }
321
322 }
323
324 public function logout() {
325 OsAuthHelper::logout_customer();
326 nocache_headers();
327 wp_redirect( OsSettingsHelper::get_customer_dashboard_url(), 302 );
328 }
329
330 public function login() {
331 $this->set_layout( 'none' );
332
333 return $this->format_render_return( __FUNCTION__ );
334 }
335
336 public function do_login() {
337 $customer = OsAuthHelper::login_customer( sanitize_email( $this->params['auth']['email'] ), $this->params['auth']['password'] );
338 if ( $customer ) {
339 $response_html = OsSettingsHelper::get_customer_dashboard_url();
340 $status = LATEPOINT_STATUS_SUCCESS;
341 } else {
342 $status = LATEPOINT_STATUS_ERROR;
343 $response_html = __( 'Invalid password or email', 'latepoint' );
344 }
345 if ( $this->get_return_format() == 'json' ) {
346 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
347 }
348 }
349
350
351 public function password_reset_form() {
352 $this->vars['from_booking'] = ( isset( $this->params['from_booking'] ) && $this->params['from_booking'] );
353 $this->set_layout( 'none' );
354
355 return $this->format_render_return( __FUNCTION__ );
356 }
357
358 public function request_password_reset_token() {
359 $this->set_layout( 'none' );
360 $this->vars['from_booking'] = ( isset( $this->params['from_booking'] ) && $this->params['from_booking'] );
361
362 if ( isset( $this->params['password_reset_email'] ) ) {
363 $customer_model = new OsCustomerModel();
364 $customer = $customer_model->where( [ 'email' => sanitize_email( $this->params['password_reset_email'] ) ] )->set_limit( 1 )->get_results_as_models();
365 $customer_mailer = new OsCustomerMailer();
366 if ( $customer && $customer_mailer->password_reset_request( $customer, $customer->account_nonse ) ) {
367 return $this->format_render_return( 'password_reset_form' );
368 } else {
369 $this->vars['reset_token_error'] = ( $customer ) ? __( 'Error! Email was not sent.', 'latepoint' ) : __( 'Email does not match any customer', 'latepoint' );
370
371 return $this->format_render_return( __FUNCTION__ );
372 }
373 } else {
374 return $this->format_render_return( __FUNCTION__ );
375 }
376 }
377
378 public function dashboard( array $params = [] ) {
379 if ( ! OsAuthHelper::is_customer_logged_in() ) {
380 $this->set_layout( 'none' );
381
382 return $this->format_render_return( 'login' );
383 } else {
384 $customer = OsAuthHelper::get_logged_in_customer();
385 $this->vars['customer'] = $customer;
386 $this->vars['orders'] = $customer->get_orders();
387
388 $this->vars['future_bookings'] = $customer->get_future_bookings();
389 $this->vars['past_bookings'] = $customer->get_past_bookings();
390 $this->vars['cancelled_bookings'] = $customer->get_cancelled_bookings();
391 $this->vars['not_scheduled_bundles'] = $customer->get_not_scheduled_bundles();
392
393 $this->vars['cart_not_empty'] = ( ! OsCartsHelper::is_current_cart_empty() && OsCartsHelper::can_checkout_multiple_items() );
394
395 $this->vars['hide_new_appointment_ui'] = $params['hide_new_appointment_ui'] ?? false;
396
397 $this->set_layout( 'none' );
398
399 return $this->format_render_return( __FUNCTION__ );
400 }
401 }
402
403 public function change_password() {
404 $params = OsParamsHelper::permit_params( $this->params, [
405 'password_reset_token',
406 'password',
407 'password_confirmation',
408 'change_password_nonce'
409 ] );
410
411 if(empty($params['password'])){
412 $this->send_json( array( 'status' => LATEPOINT_STATUS_ERROR, 'message' => __('Password can not be blank', 'latepoint') ) );
413 }
414
415
416 $customer = false;
417 if ( OsAuthHelper::is_customer_logged_in() ) {
418 $this->check_nonce('change_password_'.OsAuthHelper::get_logged_in_customer_uuid(), $params['change_password_nonce']);
419 $customer = OsAuthHelper::get_logged_in_customer();
420 } elseif ( !empty($params['password_reset_token'] )) {
421 $params['password_reset_token'] = sanitize_text_field( $params['password_reset_token'] );
422 $customer = OsCustomerHelper::get_by_account_nonse( $params['password_reset_token'] );
423 }
424 if ( $customer ) {
425 if ( ! empty( $params['password'] ) && $params['password'] == $params['password_confirmation'] ) {
426 if ( $customer->update_password( $params['password'] ) ) {
427 $status = LATEPOINT_STATUS_SUCCESS;
428 $response_html = __( 'Your password was successfully updated.', 'latepoint' );
429 } else {
430 $response_html = __( 'Error! Message Code: KS723J', 'latepoint' );
431 $status = LATEPOINT_STATUS_ERROR;
432 }
433 } else {
434 $status = LATEPOINT_STATUS_ERROR;
435 $response_html = __( 'Error! Passwords do not match.', 'latepoint' );
436 }
437 } else {
438 $status = LATEPOINT_STATUS_ERROR;
439 $response_html = __( 'Customer Not Found', 'latepoint' );
440 }
441
442
443 if ( $this->get_return_format() == 'json' ) {
444 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
445 }
446 }
447
448 public function set_account_password_on_booking_completion() {
449 $customer = OsAuthHelper::get_logged_in_customer();
450
451 if ( $customer ) {
452 $params = OsParamsHelper::permit_params( $this->params, [
453 'password',
454 'password_nonce'
455 ] );
456 $this->check_nonce('set_initial_password_for_customer_'.$customer->get_uuid(), $params['password_nonce']);
457 if ( ! empty( $params['password'] ) ) {
458 if ( $customer->update_password( $params['password'] ) ) {
459 $status = LATEPOINT_STATUS_SUCCESS;
460 $response_html = __( 'Account Password Set', 'latepoint' );
461 } else {
462 $response_html = __( 'Error! Message Code: KS723J', 'latepoint' );
463 $status = LATEPOINT_STATUS_ERROR;
464 }
465 } else {
466 $status = LATEPOINT_STATUS_ERROR;
467 $response_html = __( 'Error! Password is empty.', 'latepoint' );
468 }
469 } else {
470 $response_html = __( 'Invalid request', 'latepoint' );
471 $status = LATEPOINT_STATUS_ERROR;
472 }
473
474
475 if ( $this->get_return_format() == 'json' ) {
476 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
477 }
478 }
479
480
481 }
482
483
484 endif;