/**
  * Delete customer appointment.
  */
 public function executeDeleteCustomerAppointment()
 {
     $customer_appointment = new AB_CustomerAppointment();
     $customer_appointment->load($this->getParameter('id'));
     $appointment = new AB_Appointment();
     $appointment->load($customer_appointment->get('appointment_id'));
     $customer_appointment->delete();
     // Delete appointment, if there aren't customers.
     $count = AB_CustomerAppointment::query()->where('appointment_id', $customer_appointment->get('appointment_id'))->count();
     if (!$count) {
         $appointment->delete();
     } else {
         $appointment->handleGoogleCalendar();
     }
     wp_send_json_success();
 }
 /**
  * Cancel Appointment using token.
  */
 public function executeCancelAppointment()
 {
     $customer_appointment = new AB_Customer_Appointment();
     if ($customer_appointment->loadByToken($this->getParameter('token'))) {
         $customer_appointment->delete();
         // Delete appointment, if there aren't customers
         $current_capacity = $this->getWpdb()->get_var($this->getWpdb()->prepare('SELECT count(*) from `ab_customer_appointment` WHERE appointment_id = %d', $customer_appointment->get('appointment_id')));
         if (!$current_capacity) {
             $appointment = new AB_Appointment();
             $appointment->load($customer_appointment->get('appointment_id'));
             $appointment->delete();
         }
         if (get_option('ab_settings_cancel_page_url')) {
             exit(wp_redirect(get_option('ab_settings_cancel_page_url')));
         }
     }
     exit(wp_redirect(home_url()));
 }
 /**
  * Cancel Appointment using token.
  */
 public function executeCancelAppointment()
 {
     $customer_appointment = new AB_CustomerAppointment();
     if ($customer_appointment->loadBy(array('token' => $this->getParameter('token')))) {
         // Send email.
         AB_NotificationSender::send(AB_NotificationSender::INSTANT_CANCELLED_APPOINTMENT, $customer_appointment);
         $customer_appointment->delete();
         $appointment = new AB_Appointment();
         $appointment->load($customer_appointment->get('appointment_id'));
         // Delete appointment, if there aren't customers.
         $count = AB_CustomerAppointment::query('ca')->where('ca.appointment_id', $customer_appointment->get('appointment_id'))->count();
         if (!$count) {
             $appointment->delete();
         } else {
             $appointment->handleGoogleCalendar();
         }
         if ($this->url = get_option('ab_settings_cancel_page_url')) {
             wp_redirect($this->url);
             $this->render('cancel_appointment');
             exit(0);
         }
     }
     $this->url = home_url();
     if (isset($_SERVER['HTTP_REFERER'])) {
         if (parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) == parse_url($this->url, PHP_URL_HOST)) {
             // Redirect back if user came from our site.
             $this->url = $_SERVER['HTTP_REFERER'];
         }
     }
     wp_redirect($this->url);
     $this->render('cancel_appointment');
     exit(0);
 }
 public function executeDeleteAppointment()
 {
     $appointment = new AB_Appointment();
     $appointment->load($this->getParameter('appointment_id'));
     $appointment->delete();
     exit;
 }