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