Пример #1
0
 function update_7_3()
 {
     add_option('ab_appearance_text_info_third_step_guest', '');
     $staff_members = AB_Staff::query('s')->select('s.id, s.full_name')->fetchArray();
     foreach ($staff_members as $staff) {
         do_action('wpml_register_single_string', 'bookly', 'staff_' . $staff['id'], $staff['full_name']);
     }
     $categories = AB_Category::query('c')->select('c.id, c.name')->fetchArray();
     foreach ($categories as $category) {
         do_action('wpml_register_single_string', 'bookly', 'category_' . $category['id'], $category['name']);
     }
     $services = AB_Service::query('s')->select('s.id, s.title')->fetchArray();
     foreach ($services as $service) {
         do_action('wpml_register_single_string', 'bookly', 'service_' . $service['id'], $service['title']);
     }
 }
Пример #2
0
 public function addAdminMenu()
 {
     /** @var WP_User $current_user */
     global $current_user;
     // Translated submenu pages.
     $calendar = __('Calendar', 'bookly');
     $appointments = __('Appointments', 'bookly');
     $staff_members = __('Staff Members', 'bookly');
     $services = __('Services', 'bookly');
     $sms = __('SMS Notifications', 'bookly');
     $notifications = __('Email Notifications', 'bookly');
     $customers = __('Customers', 'bookly');
     $payments = __('Payments', 'bookly');
     $appearance = __('Appearance', 'bookly');
     $settings = __('Settings', 'bookly');
     $coupons = __('Coupons', 'bookly');
     $custom_fields = __('Custom Fields', 'bookly');
     if ($current_user->has_cap('administrator') || AB_Staff::query()->where('wp_user_id', $current_user->ID)->count()) {
         if (function_exists('add_options_page')) {
             $dynamic_position = '80.0000001' . mt_rand(1, 1000);
             // position always is under `Settings`
             add_menu_page('Bookly', 'Bookly', 'read', 'ab-system', '', plugins_url('resources/images/menu.png', __FILE__), $dynamic_position);
             add_submenu_page('ab-system', $calendar, $calendar, 'read', 'ab-calendar', array($this->calendarController, 'index'));
             add_submenu_page('ab-system', $appointments, $appointments, 'manage_options', 'ab-appointments', array($this->appointmentsController, 'index'));
             if ($current_user->has_cap('administrator')) {
                 add_submenu_page('ab-system', $staff_members, $staff_members, 'manage_options', AB_StaffController::page_slug, array($this->staffController, 'index'));
             } else {
                 if (1 == get_option('ab_settings_allow_staff_members_edit_profile')) {
                     add_submenu_page('ab-system', __('Profile', 'bookly'), __('Profile', 'bookly'), 'read', AB_StaffController::page_slug, array($this->staffController, 'index'));
                 }
             }
             add_submenu_page('ab-system', $services, $services, 'manage_options', AB_ServiceController::page_slug, array($this->serviceController, 'index'));
             add_submenu_page('ab-system', $customers, $customers, 'manage_options', AB_CustomerController::page_slug, array($this->customerController, 'index'));
             add_submenu_page('ab-system', $notifications, $notifications, 'manage_options', 'ab-notifications', array($this->notificationsController, 'index'));
             add_submenu_page('ab-system', $sms, $sms, 'manage_options', AB_SmsController::page_slug, array($this->smsController, 'index'));
             add_submenu_page('ab-system', $payments, $payments, 'manage_options', 'ab-payments', array($this->paymentController, 'index'));
             add_submenu_page('ab-system', $appearance, $appearance, 'manage_options', 'ab-appearance', array($this->apearanceController, 'index'));
             add_submenu_page('ab-system', $custom_fields, $custom_fields, 'manage_options', 'ab-custom-fields', array($this->customFieldsController, 'index'));
             add_submenu_page('ab-system', $coupons, $coupons, 'manage_options', 'ab-coupons', array($this->couponsController, 'index'));
             add_submenu_page('ab-system', $settings, $settings, 'manage_options', AB_SettingsController::page_slug, array($this->settingsController, 'index'));
             global $submenu;
             do_action('bookly_addons_menu', 'ab-system');
             unset($submenu['ab-system'][0]);
         }
     }
 }
Пример #3
0
 public function index()
 {
     /** @var WP_Locale $wp_locale */
     global $wp_locale;
     $this->enqueueStyles(array('frontend' => array('css/intlTelInput.css', 'css/ladda.min.css'), 'backend' => array('css/bookly.main-backend.css', 'bootstrap/css/bootstrap.min.css', 'css/jCal.css'), 'module' => array('css/staff.css')));
     $this->enqueueScripts(array('backend' => array('bootstrap/js/bootstrap.min.js' => array('jquery'), 'js/ab_popup.js' => array('jquery'), 'js/jCal.js' => array('jquery')), 'module' => array('js/staff.js' => array('jquery-ui-sortable', 'jquery')), 'frontend' => array('js/intlTelInput.min.js' => array('jquery'), 'js/spin.min.js' => array('jquery'), 'js/ladda.min.js' => array('jquery'))));
     wp_localize_script('ab-staff.js', 'BooklyL10n', array('are_you_sure' => __('Are you sure?', 'bookly'), 'we_are_not_working' => __('We are not working on this day', 'bookly'), 'repeat' => __('Repeat every year', 'bookly'), 'months' => array_values($wp_locale->month), 'days' => array_values($wp_locale->weekday_abbrev), 'country' => get_option('ab_settings_phone_default_country'), 'intlTelInput_utils' => plugins_url('intlTelInput.utils.js', AB_PATH . '/frontend/resources/js/intlTelInput.utils.js')));
     $this->form = new AB_StaffMemberNewForm();
     $this->staff_members = AB_Utils::isCurrentUserAdmin() ? AB_Staff::query()->sortBy('position')->fetchArray() : AB_Staff::query()->where('wp_user_id', get_current_user_id())->fetchArray();
     if (!isset($this->active_staff_id)) {
         if ($this->hasParameter('staff_id')) {
             $this->active_staff_id = $this->getParameter('staff_id');
         } else {
             $this->active_staff_id = !empty($this->staff_members) ? $this->staff_members[0]['id'] : 0;
         }
     }
     // Check if this request is the request after google auth, set the token-data to the staff.
     if ($this->hasParameter('code')) {
         $google = new AB_Google();
         $success_auth = $google->authCodeHandler($this->getParameter('code'));
         if ($success_auth) {
             $staff_id = base64_decode(strtr($this->getParameter('state'), '-_,', '+/='));
             $staff = new AB_Staff();
             $staff->load($staff_id);
             $staff->set('google_data', $google->getAccessToken());
             $staff->save();
             echo '<script>location.href="' . AB_Google::generateRedirectURI() . '&staff_id=' . $staff_id . '";</script>';
             exit(0);
         } else {
             $_SESSION['google_auth_error'] = json_encode($google->getErrors());
         }
     }
     if ($this->hasParameter('google_logout')) {
         $google = new AB_Google();
         $this->active_staff_id = $google->logoutByStaffId($this->getParameter('google_logout'));
     }
     $this->render('list');
 }
Пример #4
0
 /**
  * Get list of users available for particular staff.
  *
  * @global string $table_prefix
  * @param integer $staff_id If null then it means new staff
  * @return array
  */
 public function getUsersForStaff($staff_id = null)
 {
     /** @var wpdb $wpdb */
     global $wpdb;
     if (!is_multisite()) {
         $query = sprintf('SELECT ID, user_email, display_name FROM ' . $wpdb->users . '
            WHERE ID NOT IN(SELECT DISTINCT IFNULL( wp_user_id, 0 ) FROM ' . AB_Staff::getTableName() . ' %s)
            ORDER BY display_name', $staff_id !== null ? "WHERE " . AB_Staff::getTableName() . ".id <> {$staff_id}" : '');
         $users = $wpdb->get_results($query);
     } else {
         // In Multisite show users only for current blog.
         if ($staff_id == null) {
             $query = AB_Staff::query('s')->select('DISTINCT wp_user_id')->whereNot('wp_user_id', null);
         } else {
             $query = AB_Staff::query('s')->select('wp_user_id')->whereNot('id', $staff_id);
         }
         $occupied_wp_users = array();
         foreach ($query->fetchArray() as $staff) {
             $occupied_wp_users[] = $staff['wp_user_id'];
         }
         $users = get_users(array('blog_id' => get_current_blog_id(), 'orderby' => 'display_name', 'exclude' => $occupied_wp_users));
     }
     return $users;
 }
Пример #5
0
 /**
  * Ajax request for Holidays calendar
  */
 public function executeSettingsHoliday()
 {
     $id = $this->getParameter('id', false);
     $holiday = $this->getParameter('holiday') == 'true';
     $repeat = $this->getParameter('repeat') == 'true';
     $day = $this->getParameter('day', false);
     // update or delete the event
     if ($id) {
         if ($holiday) {
             $this->getWpdb()->update(AB_Holiday::getTableName(), array('repeat_event' => intval($repeat)), array('id' => $id), array('%d'));
             $this->getWpdb()->update(AB_Holiday::getTableName(), array('repeat_event' => intval($repeat)), array('parent_id' => $id), array('%d'));
         } else {
             $this->getWpdb()->delete(AB_Holiday::getTableName(), array('id' => $id), array('%d'));
             $this->getWpdb()->delete(AB_Holiday::getTableName(), array('parent_id' => $id), array('%d'));
         }
         // add the new event
     } elseif ($holiday && $day) {
         $holiday = new AB_Holiday(array('date' => $day, 'repeat_event' => intval($repeat)));
         $holiday->save();
         foreach (AB_Staff::query()->fetchArray() as $employee) {
             $staff_holiday = new AB_Holiday(array('date' => $day, 'repeat_event' => intval($repeat), 'staff_id' => $employee['id'], 'parent_id' => $holiday->get('id')));
             $staff_holiday->save();
         }
     }
     // and return refreshed events
     echo $this->getHolidays();
     exit;
 }
Пример #6
0
 /**
  * @return mixed
  */
 private function getStaffCollection()
 {
     return AB_Staff::query()->fetchArray();
 }
Пример #7
0
 /**
  * Prepare data for staff.
  *
  * @param DateTime $start_date
  */
 private function _prepareStaffData(DateTime $start_date)
 {
     $this->staffData = array();
     $services = AB_StaffService::query('ss')->select('ss.staff_id, ss.price, ss.capacity')->whereIn('ss.staff_id', $this->staff_ids)->where('ss.service_id', $this->userData->get('service_id'))->fetchArray();
     foreach ($services as $item) {
         $this->staffData[$item['staff_id']] = array('price' => $item['price'], 'capacity' => $item['capacity'], 'holidays' => array(), 'bookings' => array(), 'working_hours' => array());
     }
     // Load holidays.
     $holidays = AB_Holiday::query('h')->whereIn('h.staff_id', $this->staff_ids)->fetchArray();
     foreach ($holidays as $item) {
         $this->staffData[$item['staff_id']]['holidays'][] = $item;
     }
     // Load working schedule.
     $working_schedule = AB_StaffScheduleItem::query('ssi')->select('ssi.*, break.start_time AS break_start, break.end_time AS break_end')->leftJoin('AB_ScheduleItemBreak', 'break', 'break.staff_schedule_item_id = ssi.id')->whereIn('ssi.staff_id', $this->staff_ids)->whereNot('ssi.start_time', null)->fetchArray();
     foreach ($working_schedule as $item) {
         if (!isset($this->staffData[$item['staff_id']]['working_hours'][$item['day_index']])) {
             $this->staffData[$item['staff_id']]['working_hours'][$item['day_index']] = array('start_time' => $item['start_time'], 'end_time' => $item['end_time'], 'breaks' => array());
         }
         if ($item['break_start']) {
             $this->staffData[$item['staff_id']]['working_hours'][$item['day_index']]['breaks'][] = array('start' => $item['break_start'], 'end' => $item['break_end']);
         }
     }
     // Load bookings.
     $bookings = AB_CustomerAppointment::query('ca')->select('a.*, SUM(ca.number_of_persons) AS number_of_bookings')->leftJoin('AB_Appointment', 'a', 'a.id = ca.appointment_id')->leftJoin('AB_StaffService', 'ss', 'ss.staff_id = a.staff_id AND ss.service_id = a.service_id')->whereIn('a.staff_id', $this->staff_ids)->whereGte('a.start_date', $this->userData->get('date_from'))->groupBy('a.start_date')->groupBy('a.staff_id')->groupBy('a.service_id')->fetchArray();
     foreach ($bookings as $item) {
         $item['from_google'] = false;
         // Handle bookings which end at 24:00.
         if (substr($item['end_date'], 11) == '00:00:00') {
             // Set time to 24:00:00 (date part does not matter, it just needs to be 10 characters length).
             $item['end_date'] = '10_symbols 24:00:00';
         }
         $this->staffData[$item['staff_id']]['bookings'][] = $item;
     }
     // Handle Google Calendar events.
     if (get_option('ab_settings_google_two_way_sync')) {
         $query = AB_Staff::query('s')->whereIn('s.id', array_merge($this->userData->get('staff_ids'), array(0)));
         foreach ($query->find() as $staff) {
             $google = new AB_Google();
             if ($google->loadByStaff($staff)) {
                 $this->staffData[$staff->get('id')]['bookings'] = array_merge($this->staffData[$staff->get('id')]['bookings'], $google->getCalendarEvents($start_date) ?: array());
             }
         }
     }
 }
Пример #8
0
 /**
  * Get data needed for appointment form initialisation.
  */
 public function executeGetDataForAppointmentForm()
 {
     $result = array('staff' => array(), 'customers' => array(), 'custom_fields' => array(), 'time' => array(), 'time_interval' => get_option('ab_settings_time_slot_length') * 60);
     // Staff list.
     $staff_members = AB_Utils::isCurrentUserAdmin() ? AB_Staff::query()->sortBy('position')->find() : AB_Staff::query()->where('wp_user_id', get_current_user_id())->find();
     /** @var AB_Staff $staff_member */
     foreach ($staff_members as $staff_member) {
         $services = array();
         foreach ($staff_member->getStaffServices() as $staff_service) {
             $services[] = array('id' => $staff_service->service->get('id'), 'title' => sprintf('%s (%s)', $staff_service->service->get('title'), AB_Service::durationToString($staff_service->service->get('duration'))), 'duration' => $staff_service->service->get('duration'), 'capacity' => $staff_service->get('capacity'));
         }
         $result['staff'][] = array('id' => $staff_member->get('id'), 'full_name' => $staff_member->get('full_name'), 'services' => $services);
     }
     // Customers list.
     foreach (AB_Customer::query()->sortBy('name')->find() as $customer) {
         $name = $customer->get('name');
         if ($customer->get('email') != '' || $customer->get('phone') != '') {
             $name .= ' (' . trim($customer->get('email') . ', ' . $customer->get('phone'), ', ') . ')';
         }
         $result['customers'][] = array('id' => $customer->get('id'), 'name' => $name, 'custom_fields' => array(), 'number_of_persons' => 1);
     }
     // Time list.
     $ts_length = AB_BookingConfiguration::getTimeSlotLength();
     $time_start = AB_StaffScheduleItem::WORKING_START_TIME;
     $time_end = AB_StaffScheduleItem::WORKING_END_TIME;
     // Run the loop.
     while ($time_start <= $time_end) {
         $result['time'][] = array('value' => AB_DateTimeUtils::buildTimeString($time_start, false), 'title' => AB_DateTimeUtils::formatTime($time_start));
         $time_start += $ts_length;
     }
     wp_send_json($result);
 }