<?php

/*
* Title                   : Pinpoint Booking System WordPress Plugin (PRO)
* Version                 : 2.1.8
* File                    : includes/class-backend.php
* File Version            : 1.3.9
* Created / Last Modified : 15 March 2016
* Author                  : Dot on Paper
* Copyright               : © 2012 Dot on Paper
* Website                 : http://www.dotonpaper.net
* Description             : Back end PHP class.
*/

if (!class_exists('DOPBSPBackEnd')){
    class DOPBSPBackEnd{
        /*
         * Constructor
         */
        function __construct(){
            global $pagenow;

            /*
             * Init back end.
             */
            add_action('init',
                       array(&$this,
                             'init'));

            /*
             * Add styles needed outside plugin pages.
             */
            add_action('admin_enqueue_scripts',
                       array(&$this,
                             'addWPAdminStyles'));

            /*
             * Add widgets scripts.
             */
            if ($pagenow == 'widgets.php'){
                add_action('admin_enqueue_scripts',
                           array(&$this,
                                 'addWidgetScripts'));
            }

            /*
             * Add styles and scripts only on plugin pages.
             */
            if ($this->validPage()){
                add_action('admin_enqueue_scripts',
                           array(&$this,
                                 'addStyles'));
                add_action('admin_enqueue_scripts',
                           array(&$this,
                                 'addScripts'));
            }
            else{
                add_action('admin_enqueue_scripts',
                           array(&$this,
                                 'addWPAdminScripts'));
            }

            /*
             * Initialize rating request.
             */
            add_action('admin_notices',
                       array(&$this,
                             'rating'));
        }

        /*
         * Add plugin's CSS files outside plugin's pages.
         */
        function addWPAdminStyles(){
            global $DOPBSP;

            /*
             * Register Styles.
             */
            wp_register_style('DOPBSP-css-backend-wp-admin',
                              $DOPBSP->paths->url.'assets/gui/css/backend-wp-admin.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-shortcodes',
                              $DOPBSP->paths->url.'assets/gui/css/backend-shortcodes.css',
                              [],
                              DOT_VERSION);

            /*
             * Enqueue Styles.
             */
            wp_enqueue_style('DOPBSP-css-backend-wp-admin');
            wp_enqueue_style('DOPBSP-css-backend-shortcodes');
        }

        /*
         * Add plugin's CSS files.
         */
        function addStyles(){
            global $DOPBSP;

            /*
             * Register styles.
             */
            wp_register_style('DOPBSP-css-dopselect',
                              $DOPBSP->paths->url.'libraries/css/jquery.dop.Select.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-businesses',
                              $DOPBSP->paths->url.'libraries/css/pinpoint-businesses.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend',
                              $DOPBSP->paths->url.'assets/gui/css/backend.css',
                              [],
                              DOT_VERSION);

            wp_register_style('DOPBSP-css-backend-calendar',
                              $DOPBSP->paths->url.'assets/gui/css/jquery.dop.backend.BSPCalendar.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-coupons',
                              $DOPBSP->paths->url.'assets/gui/css/backend-coupons.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-dashboard',
                              $DOPBSP->paths->url.'assets/gui/css/backend-dashboard.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-discounts',
                              $DOPBSP->paths->url.'assets/gui/css/backend-discounts.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-emails',
                              $DOPBSP->paths->url.'assets/gui/css/backend-emails.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-extras',
                              $DOPBSP->paths->url.'assets/gui/css/backend-extras.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-forms',
                              $DOPBSP->paths->url.'assets/gui/css/backend-forms.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-locations',
                              $DOPBSP->paths->url.'assets/gui/css/backend-locations.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-reservations',
                              $DOPBSP->paths->url.'assets/gui/css/backend-reservations.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-reservations-add',
                              $DOPBSP->paths->url.'assets/gui/css/jquery.dop.backend.BSPReservationsAdd.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-reservations-calendar',
                              $DOPBSP->paths->url.'assets/gui/css/jquery.dop.backend.BSPReservationsCalendar.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-settings',
                              $DOPBSP->paths->url.'assets/gui/css/backend-settings.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-smses',
                              $DOPBSP->paths->url.'assets/gui/css/backend-smses.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-tools',
                              $DOPBSP->paths->url.'assets/gui/css/backend-tools.css',
                              [],
                              DOT_VERSION);
            wp_register_style('DOPBSP-css-backend-translation',
                              $DOPBSP->paths->url.'assets/gui/css/backend-translation.css',
                              [],
                              DOT_VERSION);

            /*
             * Enqueue styles.
             */
            wp_enqueue_style('thickbox');
            wp_enqueue_style('DOPBSP-css-dopselect');
            wp_enqueue_style('DOPBSP-css-businesses');
            wp_enqueue_style('DOPBSP-css-backend');
            wp_enqueue_style('DOPBSP-css-backend-calendar');
            wp_enqueue_style('DOPBSP-css-backend-coupons');
            wp_enqueue_style('DOPBSP-css-backend-dashboard');
            wp_enqueue_style('DOPBSP-css-backend-emails');
            wp_enqueue_style('DOPBSP-css-backend-discounts');
            wp_enqueue_style('DOPBSP-css-backend-extras');
            wp_enqueue_style('DOPBSP-css-backend-forms');
            wp_enqueue_style('DOPBSP-css-backend-locations');
            wp_enqueue_style('DOPBSP-css-backend-reservations');
            wp_enqueue_style('DOPBSP-css-backend-reservations-add');
            wp_enqueue_style('DOPBSP-css-backend-reservations-calendar');
            wp_enqueue_style('DOPBSP-css-backend-settings');
            wp_enqueue_style('DOPBSP-css-backend-smses');
            wp_enqueue_style('DOPBSP-css-backend-tools');
            wp_enqueue_style('DOPBSP-css-backend-translation');
        }

        /*
         * Get plugin's CSS files.
         */
        function getStyles(){
            global $DOPBSP;

            $HTML = array();

            /*
             * Register styles.
             */
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'libraries/css/jquery.dop.Select.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'libraries/css/pinpoint-businesses.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend.css">';

            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend-coupons.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend-dashboard.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend-discounts.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend-emails.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend-extras.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend-forms.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend-locations.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend-pro.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend-reservations.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/jquery.dop.backend.BSPReservationsAdd.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/jquery.dop.backend.BSPReservationsCalendar.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend-settings.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend-smses.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend-tools.css">';
            $HTML[] = '<link rel="stylesheet" href="'.$DOPBSP->paths->url.'assets/gui/css/backend-translation.css">';

            return $HTML;
        } // to add

        /*
         * Add admin JavaScript files.
         */
        function addWPAdminScripts(){
            global $DOPBSP;

            /*
             * Register JavaScript.
             */
            wp_register_script('DOPBSP-js-backend-shortcodes',
                               $DOPBSP->paths->url.'assets/js/shortcodes/backend-shortcodes.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Enqueue JavaScript.
             */
            if (!wp_script_is('jquery',
                              'queue')){
                wp_enqueue_script('jquery');
            }

            /*
             * Enqueue JavaScript.
             */
            wp_enqueue_script('DOPBSP-js-backend-shortcodes');
        }

        /*
         * Add widget JavaScript files.
         */
        function addWidgetScripts(){
            global $DOPBSP;

            /*
             * Register JavaScript.
             */
            wp_register_script('DOPBSP-js-backend-widget',
                               $DOPBSP->paths->url.'assets/js/widgets/backend-widgets.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Enqueue JavaScript.
             */
            if (!wp_script_is('jquery',
                              'queue')){
                wp_enqueue_script('jquery');
            }

            wp_enqueue_script('DOPBSP-js-backend-widget');
        }

        /*
         * Add plugin's JavaScript files.
         */
        function addScripts(){
            global $DOT;
            global $DOPBSP;

            /*
             * Register JavaScript.
             */

            /*
             * Libraries.
             */
            wp_register_script('DOP-js-prototypes',
                               $DOPBSP->paths->url.'libraries/js/dop-prototypes.js',
                               array('jquery'),
                               DOT_VERSION);
            wp_register_script('DOP-Google-Calendar',
                               $DOPBSP->paths->url.'libraries/js/dop-google-calendar.js',
                               array('jquery'),
                               DOT_VERSION);
            wp_register_script('DOP-js-jquery-dopselect',
                               $DOPBSP->paths->url.'libraries/js/jquery.dop.Select.js',
                               array('jquery'),
                               DOT_VERSION);
            wp_register_script('DOPBSP-js-isotope',
                               $DOPBSP->paths->url.'libraries/js/isotope.pkgd.min.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Back end.
             */
            wp_register_script('DOPBSP-js-backend',
                               $DOPBSP->paths->url.'assets/js/backend.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Front end.
             */
            wp_register_script('DOPBSP-js-frontend',
                               $DOPBSP->paths->url.'assets/js/frontend.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * API
             */
            wp_register_script('DOPBSP-js-backend-api',
                               $DOPBSP->paths->url.'assets/js/api/backend-api.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Calendars
             */
            wp_register_script('DOPBSP-js-jquery-backend-calendar',
                               $DOPBSP->paths->url.'assets/js/jquery.dop.backend.BSPCalendar.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-calendars',
                               $DOPBSP->paths->url.'assets/js/calendars/backend-calendars.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-calendar',
                               $DOPBSP->paths->url.'assets/js/calendars/backend-calendar.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Coupons
             */
            wp_register_script('DOPBSP-js-backend-coupons',
                               $DOPBSP->paths->url.'assets/js/coupons/backend-coupons.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-coupon',
                               $DOPBSP->paths->url.'assets/js/coupons/backend-coupon.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Dashboard
             */
            wp_register_script('DOPBSP-js-backend-dashboard',
                               $DOPBSP->paths->url.'assets/js/dashboard/backend-dashboard.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Deposit
             */
            wp_register_script('DOPBSP-js-frontend-deposit',
                               $DOPBSP->paths->url.'assets/js/deposit/frontend-deposit.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Discounts
             */
            wp_register_script('DOPBSP-js-backend-discounts',
                               $DOPBSP->paths->url.'assets/js/discounts/backend-discounts.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-discount',
                               $DOPBSP->paths->url.'assets/js/discounts/backend-discount.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-discount-items',
                               $DOPBSP->paths->url.'assets/js/discounts/backend-discount-items.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-discount-item',
                               $DOPBSP->paths->url.'assets/js/discounts/backend-discount-item.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-discount-item-rules',
                               $DOPBSP->paths->url.'assets/js/discounts/backend-discount-item-rules.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-discount-item-rule',
                               $DOPBSP->paths->url.'assets/js/discounts/backend-discount-item-rule.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-frontend-discounts',
                               $DOPBSP->paths->url.'assets/js/discounts/frontend-discounts.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Emails
             */
            wp_register_script('DOPBSP-js-backend-emails',
                               $DOPBSP->paths->url.'assets/js/emails/backend-emails.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-email',
                               $DOPBSP->paths->url.'assets/js/emails/backend-email.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Extras
             */
            wp_register_script('DOPBSP-js-backend-extras',
                               $DOPBSP->paths->url.'assets/js/extras/backend-extras.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-extra',
                               $DOPBSP->paths->url.'assets/js/extras/backend-extra.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-extra-groups',
                               $DOPBSP->paths->url.'assets/js/extras/backend-extra-groups.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-extra-group',
                               $DOPBSP->paths->url.'assets/js/extras/backend-extra-group.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-extra-group-items',
                               $DOPBSP->paths->url.'assets/js/extras/backend-extra-group-items.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-extra-group-item',
                               $DOPBSP->paths->url.'assets/js/extras/backend-extra-group-item.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Fees
             */
            wp_register_script('DOPBSP-js-backend-fees',
                               $DOPBSP->paths->url.'assets/js/fees/backend-fees.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-fee',
                               $DOPBSP->paths->url.'assets/js/fees/backend-fee.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-frontend-fees',
                               $DOPBSP->paths->url.'assets/js/fees/frontend-fees.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Forms
             */
            wp_register_script('DOPBSP-js-backend-forms',
                               $DOPBSP->paths->url.'assets/js/forms/backend-forms.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-form',
                               $DOPBSP->paths->url.'assets/js/forms/backend-form.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-form-fields',
                               $DOPBSP->paths->url.'assets/js/forms/backend-form-fields.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-form-field',
                               $DOPBSP->paths->url.'assets/js/forms/backend-form-field.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-form-field-select-options',
                               $DOPBSP->paths->url.'assets/js/forms/backend-form-field-select-options.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-form-field-select-option',
                               $DOPBSP->paths->url.'assets/js/forms/backend-form-field-select-option.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Languages
             */
            wp_register_script('DOPBSP-js-backend-languages',
                               $DOPBSP->paths->url.'assets/js/languages/backend-languages.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-language',
                               $DOPBSP->paths->url.'assets/js/languages/backend-language.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Locations
             */
            wp_register_script('DOPBSP-js-backend-locations',
                               $DOPBSP->paths->url.'assets/js/locations/backend-locations.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-location',
                               $DOPBSP->paths->url.'assets/js/locations/backend-location.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-location-map',
                               $DOPBSP->paths->url.'assets/js/locations/backend-location-map.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-location-map-hints',
                               $DOPBSP->paths->url.'assets/js/locations/backend-location-map-hints.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-location-map-marker',
                               $DOPBSP->paths->url.'assets/js/locations/backend-location-map-marker.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Reservations
             */
            wp_register_script('DOPBSP-js-jquery-backend-reservations-add',
                               $DOPBSP->paths->url.'assets/js/jquery.dop.backend.BSPReservationsAdd.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-jquery-backend-reservations-calendar',
                               $DOPBSP->paths->url.'assets/js/jquery.dop.backend.BSPReservationsCalendar.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-reservations',
                               $DOPBSP->paths->url.'assets/js/reservations/backend-reservations.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-reservations-add',
                               $DOPBSP->paths->url.'assets/js/reservations/backend-reservations-add.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-reservations-calendar',
                               $DOPBSP->paths->url.'assets/js/reservations/backend-reservations-calendar.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-reservations-list',
                               $DOPBSP->paths->url.'assets/js/reservations/backend-reservations-list.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-reservation',
                               $DOPBSP->paths->url.'assets/js/reservations/backend-reservation.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-reservation-form',
                               $DOPBSP->paths->url.'assets/js/reservations/backend-reservation-form.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Rules
             */
            wp_register_script('DOPBSP-js-backend-rules',
                               $DOPBSP->paths->url.'assets/js/rules/backend-rules.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-rule',
                               $DOPBSP->paths->url.'assets/js/rules/backend-rule.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-frontend-rules',
                               $DOPBSP->paths->url.'assets/js/rules/frontend-rules.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Search
             */
            wp_register_script('DOPBSP-js-backend-searches',
                               $DOPBSP->paths->url.'assets/js/search/backend-searches.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-search',
                               $DOPBSP->paths->url.'assets/js/search/backend-search.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Settings
             */
            wp_register_script('DOPBSP-js-backend-settings',
                               $DOPBSP->paths->url.'assets/js/settings/backend-settings.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-settings-calendar',
                               $DOPBSP->paths->url.'assets/js/settings/backend-settings-calendar.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('Google-Calendar',
                               'https://apis.google.com/js/client.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-settings-licences',
                               $DOPBSP->paths->url.'assets/js/settings/backend-settings-licences.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-settings-notifications',
                               $DOPBSP->paths->url.'assets/js/settings/backend-settings-notifications.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-settings-payment-gateways',
                               $DOPBSP->paths->url.'assets/js/settings/backend-settings-payment-gateways.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-settings-search',
                               $DOPBSP->paths->url.'assets/js/settings/backend-settings-search.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-settings-users',
                               $DOPBSP->paths->url.'assets/js/settings/backend-settings-users.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * SMSes
             */
            wp_register_script('DOPBSP-js-backend-smses',
                               $DOPBSP->paths->url.'assets/js/smses/backend-smses.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-sms',
                               $DOPBSP->paths->url.'assets/js/smses/backend-sms.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Tools
             */
            wp_register_script('DOPBSP-js-backend-tools',
                               $DOPBSP->paths->url.'assets/js/tools/backend-tools.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-tools-repair-calendars-settings',
                               $DOPBSP->paths->url.'assets/js/tools/backend-tools-repair-calendars-settings.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-tools-repair-database-text',
                               $DOPBSP->paths->url.'assets/js/tools/backend-tools-repair-database-text.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('DOPBSP-js-backend-tools-repair-search-settings',
                               $DOPBSP->paths->url.'assets/js/tools/backend-tools-repair-search-settings.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Translation
             */
            wp_register_script('DOPBSP-js-backend-translation',
                               $DOPBSP->paths->url.'assets/js/translation/backend-translation.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Framework
             */
            wp_register_script('dot-js',
                               $DOT->paths->url.'/application/assets/js/dot.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('dot-js-calendar',
                               $DOT->paths->url.'/application/assets/js/calendars/calendar.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('dot-js-calendar-availability',
                               $DOT->paths->url.'/application/assets/js/calendars/calendar-availability.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('dot-js-calendar-days',
                               $DOT->paths->url.'/application/assets/js/calendars/calendar-days.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('dot-js-calendar-day',
                               $DOT->paths->url.'/application/assets/js/calendars/calendar-day.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);
            wp_register_script('dot-js-calendar-schedule',
                               $DOT->paths->url.'/application/assets/js/calendars/calendar-schedule.js',
                               array('jquery'),
                               DOT_VERSION,
                               true);

            /*
             * Enqueue JavaScript.
             */

            /*
             * Libraries.
             */
            if (!wp_script_is('jquery',
                              'queue')){
                wp_enqueue_script('jquery');
            }

            if (!wp_script_is('jquery-effects-core',
                              'queue')){
                wp_enqueue_script('jquery-effects-core');
            }

            if (!wp_script_is('jquery-ui-datepicker',
                              'queue')){
                wp_enqueue_script('jquery-ui-datepicker');
            }

            if (!wp_script_is('jquery-ui-sortable',
                              'queue')){
                wp_enqueue_script('jquery-ui-sortable');
            }

            wp_enqueue_script('DOP-js-prototypes');
            wp_enqueue_script('DOP-Google-Calendar');
            wp_enqueue_script('DOP-js-jquery-dopselect');
            wp_enqueue_script('DOPBSP-js-isotope');

            /*
             * Back end.
             */
            wp_enqueue_script('DOPBSP-js-backend');

            /*
             * Front end.
             */
            wp_enqueue_script('DOPBSP-js-frontend');

            /*
             * API
             */
            wp_enqueue_script('DOPBSP-js-backend-api');

            /*
             * Calendars
             */
            wp_enqueue_script('DOPBSP-js-jquery-backend-calendar');
            wp_enqueue_script('DOPBSP-js-backend-calendars');
            wp_enqueue_script('DOPBSP-js-backend-calendar');

            /*
             * Coupons
             */
            wp_enqueue_script('DOPBSP-js-backend-coupons');
            wp_enqueue_script('DOPBSP-js-backend-coupon');

            /*
             * Dashboard
             */
            wp_enqueue_script('DOPBSP-js-backend-dashboard');

            /*
             * Deposit
             */
            wp_enqueue_script('DOPBSP-js-frontend-deposit');

            /*
             * Discounts
             */
            wp_enqueue_script('DOPBSP-js-backend-discounts');
            wp_enqueue_script('DOPBSP-js-backend-discount');
            wp_enqueue_script('DOPBSP-js-backend-discount-items');
            wp_enqueue_script('DOPBSP-js-backend-discount-item');
            wp_enqueue_script('DOPBSP-js-backend-discount-item-rules');
            wp_enqueue_script('DOPBSP-js-backend-discount-item-rule');
            wp_enqueue_script('DOPBSP-js-frontend-discounts');

            /*
             * Emails
             */
            wp_enqueue_script('DOPBSP-js-backend-emails');
            wp_enqueue_script('DOPBSP-js-backend-email');

            /*
             * Extras
             */
            wp_enqueue_script('DOPBSP-js-backend-extras');
            wp_enqueue_script('DOPBSP-js-backend-extra');
            wp_enqueue_script('DOPBSP-js-backend-extra-groups');
            wp_enqueue_script('DOPBSP-js-backend-extra-group');
            wp_enqueue_script('DOPBSP-js-backend-extra-group-items');
            wp_enqueue_script('DOPBSP-js-backend-extra-group-item');

            /*
             * Fees
             */
            wp_enqueue_script('DOPBSP-js-backend-fees');
            wp_enqueue_script('DOPBSP-js-backend-fee');
            wp_enqueue_script('DOPBSP-js-frontend-fees');

            /*
             * Forms
             */
            wp_enqueue_script('DOPBSP-js-backend-forms');
            wp_enqueue_script('DOPBSP-js-backend-form');
            wp_enqueue_script('DOPBSP-js-backend-form-fields');
            wp_enqueue_script('DOPBSP-js-backend-form-field');
            wp_enqueue_script('DOPBSP-js-backend-form-field-select-options');
            wp_enqueue_script('DOPBSP-js-backend-form-field-select-option');

            /*
             * Languages
             */
            wp_enqueue_script('DOPBSP-js-backend-languages');
            wp_enqueue_script('DOPBSP-js-backend-language');

            /*
             * Locations
             */
            wp_enqueue_script('DOPBSP-js-backend-locations');
            wp_enqueue_script('DOPBSP-js-backend-location');
            wp_enqueue_script('DOPBSP-js-backend-location-map');
            wp_enqueue_script('DOPBSP-js-backend-location-map-hints');
            wp_enqueue_script('DOPBSP-js-backend-location-map-marker');

            /*
             * Reservations
             */
            wp_enqueue_script('DOPBSP-js-jquery-backend-reservations-add');
            wp_enqueue_script('DOPBSP-js-jquery-backend-reservations-calendar');
            wp_enqueue_script('DOPBSP-js-backend-reservations');
            wp_enqueue_script('DOPBSP-js-backend-reservations-add');
            wp_enqueue_script('DOPBSP-js-backend-reservations-calendar');
            wp_enqueue_script('DOPBSP-js-backend-reservations-list');
            wp_enqueue_script('DOPBSP-js-backend-reservation');
            wp_enqueue_script('DOPBSP-js-backend-reservation-form');

            /*
             * Rules
             */
            wp_enqueue_script('DOPBSP-js-backend-rules');
            wp_enqueue_script('DOPBSP-js-backend-rule');
            wp_enqueue_script('DOPBSP-js-frontend-rules');

            /*
             * Search
             */
            wp_enqueue_script('DOPBSP-js-backend-searches');
            wp_enqueue_script('DOPBSP-js-backend-search');

            /*
             * Settings
             */
            wp_enqueue_script('DOPBSP-js-backend-settings');
            wp_enqueue_script('DOPBSP-js-backend-settings-calendar');
            wp_enqueue_script('Google-Calendar');
            wp_enqueue_script('DOPBSP-js-backend-settings-licences');
            wp_enqueue_script('DOPBSP-js-backend-settings-notifications');
            wp_enqueue_script('DOPBSP-js-backend-settings-payment-gateways');
            wp_enqueue_script('DOPBSP-js-backend-settings-search');
            wp_enqueue_script('DOPBSP-js-backend-settings-users');

            /*
             * SMSes
             */
            wp_enqueue_script('DOPBSP-js-backend-smses');
            wp_enqueue_script('DOPBSP-js-backend-sms');

            /*
             * Tools
             */
            wp_enqueue_script('DOPBSP-js-backend-tools');
            wp_enqueue_script('DOPBSP-js-backend-tools-repair-calendars-settings');
            wp_enqueue_script('DOPBSP-js-backend-tools-repair-database-text');
            wp_enqueue_script('DOPBSP-js-backend-tools-repair-search-settings');

            /*
             * Translation
             */
            wp_enqueue_script('DOPBSP-js-backend-translation');

            /*
             * Framework
             */
            wp_enqueue_script('dot-js');
            wp_enqueue_script('dot-js-calendar');
            wp_enqueue_script('dot-js-calendar-availability');
            wp_enqueue_script('dot-js-calendar-days');
            wp_enqueue_script('dot-js-calendar-day');
            wp_enqueue_script('dot-js-calendar-schedule');
        }

        /*
         * Initialize plugin back end.
         */
        function init(){
            global $DOPBSP;

            $DOPBSP->classes->database->init();

            /*
             * Reset database translation.
             */
            if (DOPBSP_CONFIG_REPAIR_TRANSLATION_DATABASE){
                $DOPBSP->classes->translation->reset();
            }

            if (is_admin()){
                $DOPBSP->classes->translation->set();
            }
        }

        /*
         * Check if current back end page is a plugin page.
         *
         * @get action (string): wp post action
         * @get post_type (string): wp post type
         * @get page (string): wp page type
         *
         * @return true/false
         */
        function validPage(){
            global $DOT;

            if ($DOT->get('page')){
                $page = $DOT->get('page');

                /*
                 * Verify if current page is a plugin page.
                 */
                if ($page == 'dopbsp'
                        || $page == 'dopbsp-calendars'
                        || $page == 'dopbsp-coupons'
                        || $page == 'dopbsp-discounts'
                        || $page == 'dopbsp-emails'
                        || $page == 'dopbsp-extras'
                        || $page == 'dopbsp-fees'
                        || $page == 'dopbsp-forms'
                        || $page == 'dopbsp-locations'
                        || $page == 'dopbsp-models'
                        || $page == 'dopbsp-reservations'
                        || $page == 'dopbsp-rules'
                        || $page == 'dopbsp-search'
                        || $page == 'dopbsp-settings'
                        || $page == 'dopbsp-smses'
                        || $page == 'dopbsp-templates'
                        || $page == 'dopbsp-tools'
                        || $page == 'dopbsp-translation'){
                    return true;
                }
                else{
                    return false;
                }
            }
            elseif ($DOT->get('post_type')){
                /*
                 * Verify if current page is a custom post page.
                 */
                if ($DOT->get('post_type') == DOPBSP_CONFIG_CUSTOM_POSTS_SLUG){
                    return true;
                }
                else{
                    return false;
                }
            }
            elseif ($DOT->get('action')){
                /*
                 * Verify if current page is a custom post edit page.
                 */
                if ($DOT->get('action') == 'edit'){
                    return true;
                }
                else{
                    return false;
                }
            }
            else{
                return false;
            }
        }

        function rating(){
            global $wpdb;
            global $DOPBSP;
            global $DOT;

            /*
             * Verify page.
             */
            if (!$this->validPage()){
                return false;
            }

            /*
             * Get option.
             */
            $request_rating = get_option('DOPBSP_request_rating');
            $request_rating == ''
                    ? add_option('DOPBSP_request_rating',
                                 'true')
                    : '';
            $request_rating == ''
                    ? $request_rating = 'true'
                    : '';

            /*
             * Verify close.
             */
            if (isset($_GET['dopbsp_request_rating_close'])){
                update_option('DOPBSP_request_rating',
                              'false');
                return false;
            }

            /*
             * Display message.
             */
            if ($request_rating === 'true'){
                update_option('DOPBSP_request_rating',
                              'true');

                //phpcs:ignore WordPress.DB.DirectDatabaseQuery
                $install_date = $wpdb->get_var('SELECT create_time FROM INFORMATION_SCHEMA.TABLES
                                                    WHERE table_schema = "'.$wpdb->dbname.'"
                                                    AND table_name = "'.$DOPBSP->tables->calendars.'"');

                if (time()-strtotime($install_date)>5259486){
                    $error = array();

                    $url = (isset($_SERVER['HTTPS'])
                                    ? 'https://'
                                    : 'http://')
                            .$_SERVER['HTTP_HOST']
                            .$_SERVER['REQUEST_URI'];

                    $error[] = '<div id="DOPBSP-rating-remove" class="updated notice dopbsp-notice">';
                    $error[] = '  <p>';
                    $error[] = '    Thank you for using Pinpoint Booking System. If you enjoy our plugin, please give us a 5 star rating';
                    $error[] = '    <a href="https://wordpress.org/support/plugin/booking-system/reviews?utm_source=WordPress&utm_medium=Plugin%20PRO" target="_blank"> here</a>. ';
                    $error[] = '  </p>';
                    $error[] = '  <a href="'.$url.'&dopbsp_request_rating_close=true" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></a>';
                    $error[] = '</div>';

                    $DOT->echo(implode('',
                                       $error),
                               'content',
                               [
                                       'a'   => ['href'   => [],
                                                 'target' => []],
                                       'div' => ['class' => [],
                                                 'id'    => []],
                                       'p'   => []
                               ]);
                }
            }

            return true;
        }
    }
}