Esempio n. 1
0
birch_ns('birchschedule.model.cpt.staff', function ($ns) {
    global $birchschedule;
    $ns->init = function () use($ns, $birchschedule) {
        $birchschedule->model->pre_save->when($ns->is_model_staff, $ns->pre_save);
        $birchschedule->model->post_get->when($ns->is_model_staff, $ns->post_get);
    };
    $ns->is_model_staff = function ($model) {
        return $model['post_type'] === 'birs_staff';
    };
    $ns->pre_save = function ($staff, $config) {
        birch_assert(is_array($staff) && isset($staff['post_type']));
        if (isset($staff['_birs_assigned_services'])) {
            $staff['_birs_assigned_services'] = serialize($staff['_birs_assigned_services']);
        }
        if (isset($staff['_birs_staff_schedule'])) {
            $staff['_birs_staff_schedule'] = serialize($staff['_birs_staff_schedule']);
        }
        return $staff;
    };
    $ns->post_get = function ($staff) {
        birch_assert(is_array($staff) && isset($staff['post_type']));
        if (isset($staff['post_title'])) {
            $staff['_birs_staff_name'] = $staff['post_title'];
        }
        if (isset($staff['_birs_assigned_services'])) {
            $assigned_services = $staff['_birs_assigned_services'];
            $assigned_services = unserialize($assigned_services);
            $assigned_services = $assigned_services ? $assigned_services : array();
            $staff['_birs_assigned_services'] = $assigned_services;
        }
        if (isset($staff['_birs_staff_schedule'])) {
            $schedule = $staff['_birs_staff_schedule'];
            if (!isset($schedule)) {
                $schedule = array();
            } else {
                $schedule = unserialize($schedule);
            }
            $schedule = $schedule ? $schedule : array();
            $staff['_birs_staff_schedule'] = $schedule;
        }
        if (isset($staff['post_content'])) {
            $staff['_birs_staff_description'] = $staff['post_content'];
        }
        return $staff;
    };
});
<?php

birch_ns('birchschedule.model.cpt.payment', function ($ns) {
    global $birchschedule;
    birch_defn($ns, 'init', function () use($ns, $birchschedule) {
        birch_defmethod($birchschedule->model, 'pre_save', 'birs_payment', $ns->pre_save);
        birch_defmethod($birchschedule->model, 'post_get', 'birs_payment', $ns->post_get);
    });
    birch_defn($ns, 'pre_save', function ($payment, $config) {
        birch_assert(is_array($payment) && isset($payment['post_type']));
        if (isset($payment['_birs_payment_amount'])) {
            $payment['_birs_payment_amount'] = floatval($payment['_birs_payment_amount']);
        }
        return $payment;
    });
    birch_defn($ns, 'post_get', function ($payment) {
        birch_assert(is_array($payment) && isset($payment['post_type']));
        $payment['_birs_payment_amount'] = floatval($payment['_birs_payment_amount']);
        return $payment;
    });
});
birch_ns('birchschedule.model.cpt.client', function ($ns) {
    global $birchschedule;
    birch_defn($ns, 'init', function () use($ns, $birchschedule) {
        birch_defmethod($birchschedule->model, 'pre_save', 'birs_client', $ns->pre_save);
        birch_defmethod($birchschedule->model, 'save', 'birs_client', $ns->save);
        birch_defmethod($birchschedule->model, 'post_get', 'birs_client', $ns->post_get);
    });
    birch_defn($ns, 'pre_save', function ($client, $config) {
        birch_assert(is_array($client) && isset($client['post_type']));
        $name_first = '';
        $name_last = '';
        if (isset($client['_birs_client_name_first'])) {
            $name_first = $client['_birs_client_name_first'];
        }
        if (isset($client['_birs_client_name_last'])) {
            $name_last = $client['_birs_client_name_last'];
        }
        $client['post_title'] = $name_first . ' ' . $name_last;
        return $client;
    });
    birch_defn($ns, 'save', function ($client, $config) use($ns, $birchschedule) {
        return $birchschedule->model->save->fns['_root']($client, $config);
    });
    birch_defn($ns, 'post_get', function ($client) {
        birch_assert(is_array($client) && isset($client['post_type']));
        if (isset($client['_birs_client_name_first']) && isset($client['_birs_client_name_last'])) {
            $client['_birs_client_name'] = $client['_birs_client_name_first'] . ' ' . $client['_birs_client_name_last'];
        }
        return $client;
    });
});
Esempio n. 4
0
<?php

birch_ns('birchschedule.model.cpt.payment', function ($ns) {
    global $birchschedule;
    $ns->init = function () use($ns, $birchschedule) {
        $birchschedule->model->pre_save->when($ns->is_model_payment, $ns->pre_save);
        $birchschedule->model->post_get->when($ns->is_model_payment, $ns->post_get);
    };
    $ns->is_model_payment = function ($model) {
        return $model['post_type'] === 'birs_payment';
    };
    $ns->pre_save = function ($payment, $config) {
        birch_assert(is_array($payment) && isset($payment['post_type']));
        if (isset($payment['_birs_payment_amount'])) {
            $payment['_birs_payment_amount'] = floatval($payment['_birs_payment_amount']);
        }
        return $payment;
    };
    $ns->post_get = function ($payment) {
        birch_assert(is_array($payment) && isset($payment['post_type']));
        $payment['_birs_payment_amount'] = floatval($payment['_birs_payment_amount']);
        return $payment;
    };
});
birch_ns('birchschedule.view.appointments.edit', function ($ns) {
    global $birchschedule;
    birch_defn($ns, 'init', function () use($ns, $birchschedule) {
        add_action('admin_init', array($ns, 'wp_admin_init'));
        add_action('init', array($ns, 'wp_init'));
        add_action('birchschedule_view_register_common_scripts_after', array($ns, 'register_scripts'));
        birch_defmethod($birchschedule->view, 'load_post_edit', 'birs_appointment', $ns->load_post_edit);
        birch_defmethod($birchschedule->view, 'enqueue_scripts_post_edit', 'birs_appointment', $ns->enqueue_scripts_post_edit);
    });
    birch_defn($ns, 'wp_init', function () use($ns) {
        global $birchschedule;
        $birchschedule->view->register_script_data_fn('birchschedule_view_appointments_edit', 'birchschedule_view_appointments_edit', array($ns, 'get_script_data_fn_view_appointments_edit'));
    });
    birch_defn($ns, 'wp_admin_init', function () use($ns) {
    });
    birch_defn($ns, 'get_script_data_fn_view_appointments_edit', function () use($ns) {
        return array('services_staff_map' => $ns->get_services_staff_map(), 'locations_map' => $ns->get_locations_map(), 'services_map' => $ns->get_services_map(), 'locations_staff_map' => $ns->get_locations_staff_map(), 'locations_services_map' => $ns->get_locations_services_map(), 'locations_order' => $ns->get_locations_listing_order(), 'staff_order' => $ns->get_staff_listing_order(), 'services_order' => $ns->get_services_listing_order());
    });
    birch_defn($ns, 'register_scripts', function () use($ns) {
        global $birchschedule;
        $version = $birchschedule->get_product_version();
        wp_register_script('birchschedule_view_appointments_edit', $birchschedule->plugin_url() . '/assets/js/view/appointments/edit/base.js', array('birchschedule_view_admincommon', 'birchschedule_view', 'jquery-ui-datepicker'), "{$version}");
    });
    birch_defn($ns, 'get_locations_map', function () {
        global $birchschedule;
        return $birchschedule->model->get_locations_map();
    });
    birch_defn($ns, 'get_services_map', function () {
        global $birchschedule;
        return $birchschedule->model->get_services_map();
    });
    birch_defn($ns, 'get_locations_staff_map', function () {
        global $birchschedule;
        return $birchschedule->model->get_locations_staff_map();
    });
    birch_defn($ns, 'get_locations_services_map', function () {
        global $birchschedule;
        return $birchschedule->model->get_locations_services_map();
    });
    birch_defn($ns, 'get_services_staff_map', function () {
        global $birchschedule;
        return $birchschedule->model->get_services_staff_map();
    });
    birch_defn($ns, 'get_services_locations_map', function () {
        global $birchschedule;
        return $birchschedule->model->get_services_locations_map();
    });
    birch_defn($ns, 'get_locations_listing_order', function () {
        global $birchschedule;
        return $birchschedule->model->get_locations_listing_order();
    });
    birch_defn($ns, 'get_staff_listing_order', function () {
        global $birchschedule;
        return $birchschedule->model->get_staff_listing_order();
    });
    birch_defn($ns, 'get_services_listing_order', function () {
        global $birchschedule;
        return $birchschedule->model->get_services_listing_order();
    });
    birch_defn($ns, 'load_post_edit', function ($arg) use($ns) {
        add_action('add_meta_boxes', array($ns, 'add_meta_boxes'));
    });
    birch_defn($ns, 'enqueue_scripts_post_edit', function ($arg) {
        global $birchschedule;
        $birchschedule->view->register_3rd_scripts();
        $birchschedule->view->register_3rd_styles();
        $birchschedule->view->enqueue_scripts(array('birchschedule_view_appointments_edit'));
        $birchschedule->view->enqueue_styles(array('birchschedule_appointments_edit'));
    });
    birch_defn($ns, 'add_meta_boxes', function () use($ns) {
        add_meta_box('meta_box_birs_appointment_edit_info', __('Appointment Info', 'birchschedule'), array($ns, 'render_appointment_info'), 'birs_appointment', 'normal', 'high');
        add_meta_box('meta_box_birs_appointment_edit_actions', __('Actions', 'birchschedule'), array($ns, 'render_actions'), 'birs_appointment', 'side', 'high');
    });
    birch_defn($ns, 'get_back_to_calendar_url', function () use($ns) {
        global $birchschedule;
        $back_url = admin_url('admin.php?page=birchschedule_calendar');
        $hash_string = $birchschedule->view->get_query_string($_GET, array('calview', 'locationid', 'staffid', 'currentdate'));
        if ($hash_string) {
            $back_url = $back_url . '#' . $hash_string;
        }
        return $back_url;
    });
    birch_defn($ns, 'render_actions', function ($post) use($ns) {
        $back_url = $ns->get_back_to_calendar_url();
        ?>
                <div class="submitbox">
                    <div style="float:left;">
                        <a href="<?php 
        echo $back_url;
        ?>
">
                            <?php 
        _e('Back to Calendar', 'birchschedule');
        ?>
                        </a>
                    </div>
                    <div class="clear"></div>
                </div>
<?php 
    });
    birch_defn($ns, 'render_appointment_info', function ($post) use($ns) {
        global $birchschedule;
        $location_id = 0;
        $staff_id = 0;
        $appointment_id = 0;
        $client_id = 0;
        $appointment_id = $post->ID;
        $back_url = $ns->get_back_to_calendar_url();
        ?>
                <div>
<?php 
        echo $ns->get_appointment_info_html($appointment_id);
        ?>
                    <ul>
                        <li>
                            <label>
                                &nbsp;
                            </label>
                            <div>
                            </div>
                        </li>
                    </ul>
                </div>
<?php 
    });
    birch_defn($ns, 'get_appointment_info_html', function ($appointment_id) use($ns) {
        global $birchpress, $birchschedule;
        $appointment = $birchschedule->model->get($appointment_id, array('base_keys' => array(), 'meta_keys' => $birchschedule->model->get_appointment_fields()));
        $options = $birchpress->util->get_time_options(5);
        if ($appointment) {
            $location_id = $appointment['_birs_appointment_location'];
            $location = $birchschedule->model->get($location_id, array('keys' => array('post_title')));
            $location_name = $location ? $location['post_title'] : '';
            $service_id = $appointment['_birs_appointment_service'];
            $service = $birchschedule->model->get($service_id, array('keys' => array('post_title')));
            $service_name = $service ? $service['post_title'] : '';
            $staff_id = $appointment['_birs_appointment_staff'];
            $staff = $birchschedule->model->get($staff_id, array('keys' => array('post_title')));
            $staff_name = $staff ? $staff['post_title'] : '';
            $timestamp = $birchpress->util->get_wp_datetime($appointment['_birs_appointment_timestamp']);
            $date4picker = $timestamp->format(get_option('date_format'));
            $date = $timestamp->format('m/d/Y');
            $time = $timestamp->format(get_option('time_format'));
        }
        ob_start();
        ?>
                <input type="hidden" name="birs_appointment_id" id="birs_appointment_id" value="<?php 
        echo $appointment_id;
        ?>
">
                <ul>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Location', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <label><?php 
        echo $location_name;
        ?>
</label> 
                        </div>
                    </li>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Service', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <label><?php 
        echo $service_name;
        ?>
</label>
                        </div>
                    </li>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Provider', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <label><?php 
        echo $staff_name;
        ?>
</label>
                        </div>
                    </li>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Date', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <div id="birs_appointment_view_datepicker"
                                style="pointer-events: none;"
                                data-date-value="<?php 
        echo $date;
        ?>
"></div>
                        </div>
                    </li>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Time', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <label>
                                <?php 
        echo $time;
        ?>
                            </label>
                        </div>
                    </li>
                </ul>
<?php 
        return ob_get_clean();
    });
});
birch_ns('birchpress.view', function ($ns) {
    $scripts_data = array();
    $enqueued_scripts = array();
    $localized_scripts = array();
    $printed_scripts = array();
    birch_defn($ns, 'init', function () use($ns) {
        add_action('init', array($ns, 'wp_init'));
        add_action('admin_init', array($ns, 'wp_admin_init'));
    });
    birch_defn($ns, 'wp_init', function () use($ns) {
        if (!defined('DOING_AJAX')) {
            $ns->register_core_scripts();
            add_action('wp_print_scripts', array($ns, 'localize_scripts'));
            if (is_admin()) {
                add_action('admin_print_footer_scripts', array($ns, 'localize_scripts'), 9);
                add_action('admin_print_footer_scripts', array($ns, 'post_print_scripts'), 11);
            } else {
                add_action('wp_print_footer_scripts', array($ns, 'localize_scripts'), 9);
                add_action('wp_print_footer_scripts', array($ns, 'post_print_scripts'), 11);
            }
        }
    });
    birch_defn($ns, 'wp_admin_init', function () use($ns) {
        add_action('load-post.php', function () use($ns) {
            $post_type = $ns->get_current_post_type();
            $ns->load_post_edit(array('post_type' => $post_type));
        });
        add_action('load-post-new.php', function () use($ns) {
            $post_type = $ns->get_current_post_type();
            $ns->load_post_new(array('post_type' => $post_type));
        });
        add_action('admin_enqueue_scripts', function ($hook) use($ns) {
            $post_type = $ns->get_current_post_type();
            if ($hook == 'post-new.php') {
                $ns->enqueue_scripts_post_new(array('post_type' => $post_type));
            }
            if ($hook == 'post.php') {
                $ns->enqueue_scripts_post_edit(array('post_type' => $post_type));
            }
            if ($hook == 'edit.php' && isset($_GET['post_type'])) {
                $post_type = $_GET['post_type'];
                $ns->enqueue_scripts_post_list(array('post_type' => $post_type));
            }
        });
        add_action('save_post', function ($post_id, $post) use($ns) {
            if (!isset($_POST['action']) || $_POST['action'] !== 'editpost') {
                return;
            }
            if (empty($post_id) || empty($post) || empty($_POST)) {
                return;
            }
            if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
                return;
            }
            if (is_int(wp_is_post_revision($post))) {
                return;
            }
            if (is_int(wp_is_post_autosave($post))) {
                return;
            }
            $post_a = (array) $post;
            $ns->save_post($post_a);
        }, 10, 2);
        add_filter('wp_insert_post_data', function ($post_data, $post_attr) use($ns) {
            if (!isset($_POST['action']) || $_POST['action'] !== 'editpost') {
                return $post_data;
            }
            if ($post_data['post_status'] == 'auto-draft') {
                return $post_data;
            }
            return $ns->pre_save_post($post_data, $post_attr);
        }, 10, 2);
    });
    birch_defn($ns, 'get_post_type_lookup_config', function () {
        return array('key' => 'post_type', 'lookup_table' => array());
    });
    birch_defmulti($ns, 'enqueue_scripts_post_new', $ns->get_post_type_lookup_config, function ($arg) {
    });
    birch_defmulti($ns, 'enqueue_scripts_post_edit', $ns->get_post_type_lookup_config, function ($arg) {
    });
    birch_defmulti($ns, 'enqueue_scripts_post_list', $ns->get_post_type_lookup_config, function ($arg) {
    });
    birch_defmulti($ns, 'load_post_edit', $ns->get_post_type_lookup_config, function ($arg) {
    });
    birch_defmulti($ns, 'load_post_new', $ns->get_post_type_lookup_config, function ($arg) {
    });
    birch_defmulti($ns, 'save_post', $ns->get_post_type_lookup_config, function ($post_a) {
    });
    birch_defmulti($ns, 'pre_save_post', $ns->get_post_type_lookup_config, function ($post_data, $post_attr) {
        return $post_data;
    });
    birch_defn($ns, 'get_wp_screen', function ($hook_name) use($ns) {
        if (substr($hook_name, -4) !== '.php') {
            $hook_name = $hook_name . '.php';
        }
        $screen = WP_Screen::get($hook_name);
        return $screen;
    });
    birch_defn($ns, 'register_3rd_scripts', function () use($ns) {
        global $birchpress;
        wp_register_script('underscore_string', $birchpress->get_framework_url() . '/lib/assets/js/underscore/underscore.string.min.js', array('underscore'), '2.3.0');
    });
    birch_defn($ns, 'register_core_scripts', function () use($ns) {
        global $birchpress;
        $version = $birchpress->get_version();
        wp_register_script('birchpress', $birchpress->get_framework_url() . '/assets/js/birchpress/base.js', array('underscore', 'underscore_string'), "{$version}");
        wp_register_script('birchpress_util', $birchpress->get_framework_url() . '/assets/js/birchpress/util/base.js', array('birchpress'), "{$version}");
    });
    birch_defn($ns, 'get_current_post_type', function () {
        global $current_screen;
        if ($current_screen && $current_screen->post_type) {
            return $current_screen->post_type;
        }
        return '';
    });
    birch_defn($ns, 'register_script_data_fn', function ($handle, $data_name, $fn) use($ns, &$scripts_data) {
        if (isset($scripts_data[$handle])) {
            $scripts_data[$handle][$data_name] = $fn;
        } else {
            $scripts_data[$handle] = array($data_name => $fn);
        }
    });
    birch_defn($ns, 'enqueue_scripts', function ($scripts) use($ns, &$enqueued_scripts) {
        if (is_string($scripts)) {
            $scripts = array($scripts);
        }
        foreach ($scripts as $script) {
            wp_enqueue_script($script);
        }
        $enqueued_scripts = array_merge($enqueued_scripts, $scripts);
        $enqueued_scripts = array_unique($enqueued_scripts);
    });
    birch_defn($ns, 'enqueue_styles', function ($styles) use($ns) {
        if (is_string($styles)) {
            wp_enqueue_style($styles);
            return;
        }
        if (is_array($styles)) {
            foreach ($styles as $style) {
                if (is_string($style)) {
                    wp_enqueue_style($style);
                }
            }
        }
    });
    birch_defn($ns, 'localize_scripts', function () use($ns, &$enqueued_scripts, &$printed_scripts) {
        global $wp_scripts;
        $wp_scripts->all_deps($enqueued_scripts, true);
        $all_scripts = $wp_scripts->to_do;
        foreach ($all_scripts as $script) {
            $ns->localize_script($script);
        }
        $printed_scripts = $all_scripts;
    });
    birch_defn($ns, 'localize_script', function ($script) use($ns, &$scripts_data, &$localized_scripts) {
        if (isset($scripts_data[$script]) && !in_array($script, $localized_scripts)) {
            foreach ($scripts_data[$script] as $data_name => $data_fn) {
                $data = call_user_func($data_fn);
                wp_localize_script($script, $data_name, $data);
            }
            $localized_scripts[] = $script;
            $localized_scripts = array_unique($localized_scripts);
        }
    });
    birch_defn($ns, 'post_print_scripts', function () use($ns, &$printed_scripts) {
        foreach ($printed_scripts as $script) {
            $ns->post_print_script($script);
        }
    });
    birch_defn($ns, 'post_print_script', function ($script) {
    });
    birch_defn($ns, 'get_screen', function ($hook_name) use($ns) {
        return $ns->get_wp_screen($hook_name);
    });
    birch_defn($ns, 'get_query_array', function ($query, $keys) {
        $source = array();
        $result = array();
        if (is_string($query)) {
            wp_parse_str($query, $source);
        } else {
            if (is_array($query)) {
                $source = $query;
            }
        }
        foreach ($keys as $key) {
            if (isset($source[$key])) {
                $result[$key] = $source[$key];
            }
        }
        return $result;
    });
    birch_defn($ns, 'get_query_string', function ($query, $keys) use($ns) {
        return http_build_query($ns->get_query_array($query, $keys));
    });
    birch_defn($ns, 'render_ajax_success_message', function ($success) {
        ?>
                <div id="birs_success" code="<?php 
        echo $success['code'];
        ?>
">
                    <?php 
        echo $success['message'];
        ?>
                </div>
<?php 
        exit;
    });
    birch_defn($ns, 'render_ajax_error_messages', function ($errors) {
        global $birchpress;
        if ($birchpress->util->is_error($errors)) {
            $error_arr = array();
            $codes = $birchpress->util->get_error_codes($errors);
            foreach ($codes as $code) {
                $error_arr[$code] = $birchpress->util->get_error_message($errors, $code);
            }
        } else {
            $error_arr = $errors;
        }
        ?>
                <div id="birs_errors">
                    <?php 
        foreach ($error_arr as $error_id => $message) {
            ?>
                        <div id="<?php 
            echo $error_id;
            ?>
"><?php 
            echo $message;
            ?>
</div>
                    <?php 
        }
        ?>
                </div>
<?php 
        exit;
    });
    birch_defn($ns, 'render_meta_boxes', function ($config) use($ns) {
        $assert_criteria = is_array($config) && isset($config['screen']);
        birch_assert($assert_criteria);
        $default_config = array('cols' => 1, 'callback_arg' => '');
        $config = array_merge($default_config, $config);
        if ($config['cols'] === 2) {
            ?>
                <div id="poststuff">
                    <div id="post-body" class="metabox-holder columns-2">
                        <div id="postbox-container-1" class="postbox-container">
                            <?php 
            do_meta_boxes($config['screen'], 'side', $config['callback_arg']);
            ?>
                        </div>
                        <div id="postbox-container-2" class="postbox-container">
                            <?php 
            do_meta_boxes($config['screen'], 'normal', $config['callback_arg']);
            ?>
                        </div>
                    </div>
                    <br class="clear" />
                </div>
<?php 
        } else {
            ?>
                <div id="poststuff">
                    <div id="post-body" class="metabox-holder columns-1">
                        <div id="postbox-container-1" class="postbox-container">
                            <?php 
            do_meta_boxes($config['screen'], 'normal', $config['callback_arg']);
            ?>
                        </div>
                    </div>
                    <br class="clear" />
                </div>
<?php 
        }
    });
});
Esempio n. 7
0
birch_ns('birchschedule.model.schedule', function ($ns) {
    $_ns_data = new stdClass();
    $ns->init = function () use($ns, $_ns_data) {
        $_ns_data->step_length = 5;
    };
    $ns->get_staff_calculated_schedule_by_location = function ($staff_id, $location_id) use($ns) {
        global $birchschedule;
        $location_schedule = $birchschedule->model->get_staff_schedule_by_location($staff_id, $location_id);
        $new_schedules = array();
        if (isset($location_schedule['schedules'])) {
            $schedules = $location_schedule['schedules'];
            for ($week_day = 0; $week_day < 7; $week_day++) {
                $new_schedules[] = array();
            }
            foreach ($schedules as $schedule_id => $schedule) {
                $schedule_date_start = $birchschedule->model->schedule->get_staff_schedule_date_start($staff_id, $location_id, $schedule_id);
                $schedule_date_end = $birchschedule->model->schedule->get_staff_schedule_date_end($staff_id, $location_id, $schedule_id);
                foreach ($new_schedules as $week_day => $new_schedule) {
                    if (isset($schedule['weeks'][$week_day])) {
                        $new_schedules[$week_day][] = array('minutes_start' => $schedule['minutes_start'], 'minutes_end' => $schedule['minutes_end'], 'date_start' => $schedule_date_start, 'date_end' => $schedule_date_end);
                    }
                }
            }
        }
        $location_schedule['schedules'] = $new_schedules;
        return $location_schedule;
    };
    $ns->get_staff_calculated_schedule = function ($staff_id) use($ns) {
        global $birchschedule;
        $staff = $birchschedule->model->get($staff_id, array('base_keys' => array(), 'meta_keys' => array('_birs_staff_schedule')));
        $staff_schedule = $staff['_birs_staff_schedule'];
        $new_all_schedule = array();
        foreach ($staff_schedule as $location_id => $schedule) {
            $new_all_schedule[$location_id] = $birchschedule->model->schedule->get_staff_calculated_schedule_by_location($staff_id, $location_id);
        }
        return $new_all_schedule;
    };
    $ns->get_all_calculated_schedule = function () use($ns) {
        global $birchschedule;
        $staff = $birchschedule->model->query(array('post_type' => 'birs_staff'));
        $allschedule = array();
        foreach ($staff as $thestaff) {
            $schedule = $birchschedule->model->schedule->get_staff_calculated_schedule($thestaff['ID']);
            $allschedule[$thestaff['ID']] = $schedule;
        }
        return $allschedule;
    };
    $ns->get_staff_schedule_date_start = function ($staff_id, $location_id, $schedule_id) {
        return '';
    };
    $ns->get_staff_schedule_date_end = function ($staff_id, $location_id, $schedule_id) {
        return '';
    };
    $ns->get_staff_exception_date_start = function ($staff_id, $location_id, $exception_id) {
        return '';
    };
    $ns->get_staff_exception_date_end = function ($staff_id, $location_id, $exception_id) {
        return '';
    };
    $ns->get_avaliable_schedules_by_date = function ($schedules, $date) use($ns) {
        global $birchpress;
        $new_schedules = array();
        $mysql_format = 'Y-m-d';
        foreach ($schedules as $schedule) {
            if ($schedule['date_start']) {
                $date_start = $birchpress->util->get_wp_datetime(array('date' => $schedule['date_start'], 'time' => 0))->format($mysql_format);
            } else {
                $date_start = "";
            }
            if ($schedule['date_end']) {
                $date_end = $birchpress->util->get_wp_datetime(array('date' => $schedule['date_end'], 'time' => 0))->format($mysql_format);
            } else {
                $date_end = 'a';
            }
            $current_date = $date->format($mysql_format);
            if ($date_start <= $current_date && $date_end >= $current_date) {
                $new_schedules[] = array('minutes_start' => $schedule['minutes_start'], 'minutes_end' => $schedule['minutes_end']);
            }
        }
        return $new_schedules;
    };
    $ns->get_exceptions_blocks = function ($exceptions) use($ns, $_ns_data) {
        $exceptions_blocks = array();
        $min_blocks = array();
        foreach ($exceptions as $exception) {
            $start = $exception['minutes_start'];
            $end = $exception['minutes_end'];
            if ($end - $start === $_ns_data->step_length) {
                $min_blocks[] = $start;
            } else {
                $exception_blocks = array();
                for ($i = $start + $_ns_data->step_length; $i < $end; $i += $_ns_data->step_length) {
                    $exception_blocks[] = $i;
                }
                $exceptions_blocks = array_unique(array_merge($exceptions_blocks, $exception_blocks));
            }
        }
        sort($exceptions_blocks);
        $new_min_blocks = array();
        foreach ($min_blocks as $min_block) {
            if (!in_array($min_block, $exceptions_blocks) && !in_array($min_block + $_ns_data->step_length, $exceptions_blocks)) {
                $new_min_blocks[] = $min_block;
            }
        }
        return array('min' => $new_min_blocks, 'others' => $exceptions_blocks);
    };
    $ns->get_schedules_blocks = function ($schedules) use($ns, $_ns_data) {
        $schedules_blocks = array();
        foreach ($schedules as $schedule) {
            $start = $schedule['minutes_start'];
            $end = $schedule['minutes_end'];
            $schedule_blocks = array();
            for ($i = $start; $i <= $end; $i += $_ns_data->step_length) {
                $schedule_blocks[] = $i;
            }
            $schedules_blocks = array_unique(array_merge($schedules_blocks, $schedule_blocks));
        }
        sort($schedules_blocks);
        return $schedules_blocks;
    };
    $ns->merge_schedules = function ($schedules, $exceptions) use($ns, $_ns_data) {
        $schedules_blocks = $ns->get_schedules_blocks($schedules);
        $exceptions_blocks = $ns->get_exceptions_blocks($exceptions);
        $min_exceptions_blocks = $exceptions_blocks['min'];
        $other_exceptions_blocks = $exceptions_blocks['others'];
        $all_blocks = array();
        $max_step = 1440 / $_ns_data->step_length;
        for ($i = 0; $i < $max_step; $i++) {
            $block = $i * $_ns_data->step_length;
            if (in_array($block, $schedules_blocks)) {
                $all_blocks[$block] = true;
            } else {
                $all_blocks[$block] = false;
            }
            if (in_array($block, $min_exceptions_blocks)) {
                $all_blocks[$block] = 'min';
            }
            if (in_array($block, $other_exceptions_blocks)) {
                $all_blocks[$block] = false;
            }
        }
        $all_blocks[1440] = false;
        $merged = array();
        $started = false;
        foreach ($all_blocks as $block => $block_value) {
            if ($started === false) {
                if ($block_value === true) {
                    $new_schedule = array('minutes_start' => $block, 'minutes_end' => $block);
                    $started = true;
                }
                if ($block_value === 'min') {
                    $started = 'min';
                }
            }
            if ($started === true) {
                if ($block_value === true) {
                    $new_schedule['minutes_end'] = $block;
                }
                if ($block_value === false) {
                    $started = false;
                    $merged[] = $new_schedule;
                }
                if ($block_value === 'min') {
                    $new_schedule['minutes_end'] = $block;
                    $merged[] = $new_schedule;
                    $started = 'min';
                }
            }
            if ($started === 'min') {
                if ($block_value === true) {
                    $new_schedule = array('minutes_start' => $block, 'minutes_end' => $block);
                    $started = true;
                }
                if ($block_value === false) {
                    $started = false;
                }
            }
        }
        return $merged;
    };
    $ns->get_staff_busy_time = function ($staff_id, $location_id, $date) use($ns) {
        global $birchschedule, $birchpress;
        $timestamp = $date->format('U');
        $criteria = array('start' => $timestamp, 'end' => $timestamp + 3600 * 24, 'location_id' => -1, 'staff_id' => $staff_id);
        $appointments = $birchschedule->model->booking->query_appointments($criteria, array('appointment_keys' => array('_birs_appointment_timestamp', '_birs_appointment_duration', '_birs_appointment_service', '_birs_appointment_padding_before', '_birs_appointment_padding_after')));
        $appointments_time = array();
        foreach ($appointments as $appointment) {
            $busy_time = $appointment['_birs_appointment_timestamp'];
            $datetime = $birchpress->util->get_wp_datetime($busy_time);
            $busy_time = $birchpress->util->get_day_minutes($datetime) - $appointment['_birs_appointment_padding_before'];
            $appointment_duration = $appointment['_birs_appointment_duration'] + $appointment['_birs_appointment_padding_before'] + $appointment['_birs_appointment_padding_after'];
            $appointments_time[] = array('busy_time' => $busy_time, 'duration' => $appointment_duration, 'type' => 'appointment');
        }
        return $appointments_time;
    };
    $ns->convert_busy_times_to_exceptions = function ($busy_times) use($ns) {
        $exceptions = array();
        foreach ($busy_times as $busy_time) {
            $minutes_start = $busy_time['busy_time'];
            if ($minutes_start % 5 !== 0) {
                $minutes_start = floor($minutes_start / 5) * 5;
            }
            $minutes_end = $busy_time['busy_time'] + $busy_time['duration'];
            if ($minutes_end % 5 !== 0) {
                $minutes_end = (floor($minutes_end / 5) + 1) * 5;
            }
            $exceptions[] = array('minutes_start' => $minutes_start, 'minutes_end' => $minutes_end);
        }
        return $exceptions;
    };
    $ns->get_avaliable_time_options = function ($schedule, $service_id) use($ns) {
        global $birchpress, $birchschedule;
        $timeslot = $birchschedule->model->get_service_timeslot($service_id);
        $padding_before = $birchschedule->model->get_service_padding_before($service_id);
        $service_length = $birchschedule->model->get_service_length($service_id);
        $padding_after = $birchschedule->model->get_service_padding_after($service_id);
        $capacity = $birchschedule->model->get_service_capacity($service_id);
        $time_options = array();
        $start = $schedule['minutes_start'];
        $end = $schedule['minutes_end'];
        if ($timeslot % 5 != 0) {
            $timeslot = (floor($timeslot / 5) + 1) * 5;
        }
        if ($padding_before % 5 != 0) {
            $padding_before = (floor($padding_before / 5) + 1) * 5;
        }
        for ($i = $start + $padding_before; $i < $end; $i += $timeslot) {
            if ($i + $service_length + $padding_after <= $end) {
                $avaliable = true;
            } else {
                $avaliable = false;
            }
            $time_options[$i] = array('text' => $birchpress->util->convert_mins_to_time_option($i), 'avaliable' => $avaliable, 'capacity' => $capacity);
        }
        return $time_options;
    };
    $ns->get_staff_avaliable_time = function ($staff_id, $location_id, $service_id, $date) use($ns) {
        global $birchschedule;
        $wday = $date->format('w');
        $staff_schedule = $birchschedule->model->schedule->get_staff_calculated_schedule_by_location($staff_id, $location_id);
        if (isset($staff_schedule['schedules'][$wday])) {
            $day_schedules = $staff_schedule['schedules'][$wday];
        } else {
            return array();
        }
        if (isset($staff_schedule['exceptions'][$wday])) {
            $day_exceptions = $staff_schedule['exceptions'][$wday];
        } else {
            $day_exceptions = array();
        }
        $avaliable_schedules = $ns->get_avaliable_schedules_by_date($day_schedules, $date);
        $busy_times = $birchschedule->model->schedule->get_staff_busy_time($staff_id, $location_id, $date);
        $avaliable_exceptions = $ns->get_avaliable_schedules_by_date($day_exceptions, $date);
        $busy_exceptions = $ns->convert_busy_times_to_exceptions($busy_times);
        $avaliable_exceptions = array_merge($avaliable_exceptions, $busy_exceptions);
        $merged_schedules = $ns->merge_schedules($avaliable_schedules, $avaliable_exceptions);
        $all_time_options = array();
        foreach ($merged_schedules as $merged_schedule) {
            $time_options = $ns->get_avaliable_time_options($merged_schedule, $service_id);
            $all_time_options = $all_time_options + $time_options;
        }
        return $all_time_options;
    };
    $ns->get_fully_booked_days = function () use($ns) {
        return get_option('birchschedule_schedule_fully_booked', array());
    };
    $ns->clean_past_fully_booked = function ($fully_booked) use($ns) {
        global $birchschedule, $birchpress;
        $result = array();
        foreach ($fully_booked as $date_text => $value) {
            $today = $birchpress->util->get_wp_datetime(time());
            $today_text = $today->format('Y-m-d');
            if (strcmp($date_text, $today_text) >= 0) {
                $result[$date_text] = $value;
            }
        }
        return $result;
    };
    $ns->mark_fully_booked_day = function ($staff_id, $location_id, $service_id, $date_text) use($ns) {
        global $birchschedule;
        $fully_booked = $birchschedule->model->schedule->get_fully_booked_days();
        $fully_booked = $birchschedule->model->schedule->clean_past_fully_booked($fully_booked);
        if ($staff_id != -1) {
            $fully_booked[$date_text][$staff_id][$location_id][$service_id] = true;
        }
        update_option('birchschedule_schedule_fully_booked', $fully_booked);
    };
    $ns->unmark_fully_booked_day = function ($staff_id, $location_id, $service_id, $date_text) use($ns) {
        global $birchschedule;
        $fully_booked = $birchschedule->model->schedule->get_fully_booked_days();
        $fully_booked = $birchschedule->model->schedule->clean_past_fully_booked($fully_booked);
        if ($staff_id != -1) {
            if (isset($fully_booked[$date_text]) && isset($fully_booked[$date_text][$staff_id]) && isset($fully_booked[$date_text][$staff_id][$location_id]) && isset($fully_booked[$date_text][$staff_id][$location_id][$service_id])) {
                unset($fully_booked[$date_text][$staff_id][$location_id][$service_id]);
            }
        }
        update_option('birchschedule_schedule_fully_booked', $fully_booked);
    };
});
Esempio n. 8
0
birch_ns('birchpress.util', function ($ns) {
    $_ns_data = new stdClass();
    $ns->init = function () use($ns, $_ns_data) {
        $_ns_data->request_actions = array();
        add_filter('http_api_transports', array($ns, 'http_api_transports'), 20);
        add_action('init', array($ns, 'call_request_function'), 100);
    };
    $ns->http_api_transports = function ($transports) {
        return array('streams', 'curl');
    };
    $ns->call_request_function = function () use($ns, $_ns_data) {
        $action = empty($_GET['birchpress_action']) ? '' : $_GET['birchpress_action'];
        if (!empty($action)) {
            $args = empty($_REQUEST['args']) ? '[]' : $_REQUEST['args'];
            $args = json_decode(stripslashes_deep($args), true);
            if (isset($_ns_data->request_actions[$action])) {
                $fn = $_ns_data->request_actions[$action];
                call_user_func_array($fn, $args);
            }
            die;
        }
    };
    $ns->get_remote_call_url = function ($action) use($ns) {
        $url = add_query_arg(array('birchpress_action' => $action), home_url('/index.php'));
        return $url;
    };
    $ns->async_run_task = function ($task) use($ns) {
        $url = $ns->get_remote_call_url($task['action']);
        wp_remote_post($url, array('timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters('https_local_ssl_verify', true), 'body' => array('args' => json_encode($task['args']))));
    };
    $ns->enable_remote_call = function ($fn) use($ns, $_ns_data) {
        if (!is_a($fn, 'Birch_Fn')) {
            return;
        }
        $fn_name = $fn->get_full_name();
        $_ns_data->request_actions[$fn_name] = $fn;
    };
    $ns->get_wp_screen = function ($hook_name) use($ns) {
        if (substr($hook_name, -4) !== '.php') {
            $hook_name = $hook_name . '.php';
        }
        $screen = WP_Screen::get($hook_name);
        return $screen;
    };
    $ns->has_shortcode = function ($shortcode = NULL) use($ns) {
        $post_to_check = get_post(get_the_ID());
        $found = false;
        if (!$shortcode) {
            return $found;
        }
        if (stripos($post_to_check->post_content, '[' . $shortcode) !== FALSE && stripos($post_to_check->post_content, '[[' . $shortcode) == FALSE) {
            $found = TRUE;
        }
        return $found;
    };
    $ns->render_html_options = function ($options, $selection = false, $default = false) use($ns) {
        if ($selection == false && $default != false) {
            $selection = $default;
        }
        foreach ($options as $val => $text) {
            if ($selection == $val) {
                $selected = ' selected="selected" ';
            } else {
                $selected = '';
            }
            echo "<option value='{$val}' {$selected}>{$text}</option>";
        }
    };
    $ns->get_first_day_of_week = function () use($ns) {
        return get_option('start_of_week', 0);
    };
    $ns->starts_with = function ($haystack, $needle) {
        return !strncmp($haystack, $needle, strlen($needle));
    };
    $ns->ends_with = function ($haystack, $needle) {
        $length = strlen($needle);
        if ($length == 0) {
            return true;
        }
        return substr($haystack, -$length) === $needle;
    };
    $ns->current_page_url = function () use($ns) {
        $pageURL = 'http';
        if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
            $pageURL .= "s";
        }
        $pageURL .= "://";
        if ($_SERVER["SERVER_PORT"] != "80") {
            $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
        } else {
            $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
        }
        return $pageURL;
    };
    $ns->new_error = function ($code = '', $message = '', $data = '') use($ns) {
        return new WP_Error($code, $message, $data);
    };
    $ns->add_error_item = function ($errors, $code, $message, $data = '') use($ns) {
        $errors->add($code, $message, $data);
        return $errors;
    };
    $ns->get_error_codes = function ($errors) use($ns) {
        return $errors->get_error_codes();
    };
    $ns->get_error_code = function ($errors) use($ns) {
        return $errors->get_error_code();
    };
    $ns->get_error_message = function ($errors, $code) use($ns) {
        return $errors->get_error_message($code);
    };
    $ns->is_error = function ($errors) use($ns) {
        return is_wp_error($errors);
    };
    $ns->merge_errors = function () use($ns) {
        $errors = $ns->new_error();
        $args = func_get_args();
        foreach ($args as $arg) {
            if ($ns->is_error($arg)) {
                $codes = $ns->get_error_codes();
                foreach ($codes as $code) {
                    $message = $ns->get_error_message($code);
                    $ns->add_error_item($errors, $code, $message);
                }
            } else {
                if (is_array($arg)) {
                    foreach ($arg as $code => $message) {
                        $ns->add_error_item($errors, $code, $message);
                    }
                }
            }
        }
        return $errors;
    };
    $ns->urlencode = function ($arg) use($ns) {
        if (is_array($arg)) {
            $new_array = array();
            foreach ($arg as $field_name => $field_value) {
                $new_array[$field_name] = $ns->urlencode($field_value);
            }
            return $new_array;
        }
        if (is_string($arg)) {
            return urlencode($arg);
        } else {
            return $arg;
        }
    };
    require 'i18n.php';
});
Esempio n. 9
0
<?php

birch_ns('birchpress.view', function ($ns) {
    $ns->init = function () use($ns) {
        add_action('init', array($ns, 'wp_init'));
        add_action('admin_init', array($ns, 'wp_admin_init'));
    };
    $ns->wp_init = function () use($ns) {
    };
    $ns->wp_admin_init = function () use($ns) {
    };
    $ns->register_3rd_scripts = function () use($ns) {
        global $birchpress;
        wp_register_script('underscore.string', $birchpress->get_framework_url() . '/lib/assets/js/underscore.string/underscore.string.js', array('underscore'), '2.3.0');
        wp_register_script('react-with-addons', $birchpress->get_framework_url() . '/lib/assets/js/react/react-with-addons.js', array(), '0.13.3');
        wp_register_script('react', $birchpress->get_framework_url() . '/lib/assets/js/react/react.js', array(), '0.13.3');
        wp_register_script('immutable', $birchpress->get_framework_url() . '/lib/assets/js/immutable/immutable.js', array(), '3.7.4');
        wp_register_script('jquery.datatables', $birchpress->get_framework_url() . '/lib/assets/js/datatables/media/js/jquery.dataTables.js', array('jquery'), '1.10.8');
    };
    $ns->register_3rd_styles = function () use($ns) {
        global $birchpress;
        wp_register_style('jquery.datatables', $birchpress->get_framework_url() . '/lib/assets/js/datatables/media/css/jquery.dataTables.css', array(), '1.10.8');
    };
    $ns->register_core_scripts = function () use($ns) {
        global $birchpress;
        $version = $birchpress->get_version();
        wp_register_script('birchpress', $birchpress->get_framework_url() . '/assets/js/birchpress/index.bundle.js', array('underscore', 'underscore.string', 'jquery', 'react-with-addons', 'immutable'), "{$version}");
    };
});
Esempio n. 10
0
<?php

birch_ns('birchschedule.model.cpt', function ($ns) {
});
Esempio n. 11
0
birch_ns('birchschedule.view.appointments.edit.clientlist.edit', function ($ns) {
    global $birchschedule;
    birch_defn($ns, 'init', function () use($ns) {
        add_action('admin_init', array($ns, 'wp_admin_init'));
        add_action('birchschedule_view_register_common_scripts_after', array($ns, 'register_scripts'));
    });
    birch_defn($ns, 'wp_admin_init', function () use($ns, $birchschedule) {
        add_action('wp_ajax_birchschedule_view_appointments_edit_clientlist_edit_save', array($ns, 'ajax_save'));
        add_action('birchschedule_view_enqueue_scripts_post_edit_after', array($ns, 'enqueue_scripts_post_edit'));
        add_action('birchschedule_view_appointments_edit_clientlist_render_more_rows_after', array($ns, 'render_row'), 20, 3);
        add_filter('birchschedule_view_appointments_edit_clientlist_get_item_actions', array($ns, 'add_item_action'), 20, 2);
    });
    birch_defn($ns, 'register_scripts', function () use($birchschedule) {
        $version = $birchschedule->get_product_version();
        wp_register_script('birchschedule_view_appointments_edit_clientlist_edit', $birchschedule->plugin_url() . '/assets/js/view/appointments/edit/clientlist/edit/base.js', array('birchschedule_view_admincommon', 'birchschedule_view'), "{$version}");
    });
    birch_defn($ns, 'enqueue_scripts_post_edit', function ($arg) {
        if ($arg['post_type'] != 'birs_appointment') {
            return;
        }
        global $birchschedule;
        $birchschedule->view->register_3rd_scripts();
        $birchschedule->view->register_3rd_styles();
        $birchschedule->view->enqueue_scripts(array('birchschedule_view_appointments_edit_clientlist_edit'));
    });
    birch_defn($ns, 'add_item_action', function ($item_actions, $item) {
        $action_html = '<a href="javascript:void(0);" data-item-id="%s">%s</a>';
        $item_actions['edit'] = sprintf($action_html, $item['ID'], __('Edit', 'birchschedule'));
        return $item_actions;
    });
    birch_defn($ns, 'render_row', function ($wp_list_table, $item, $row_class) use($ns) {
        $client_id = $item['ID'];
        $appointment_id = $wp_list_table->appointment_id;
        $column_count = $wp_list_table->get_column_count();
        $edit_html = $ns->get_client_edit_html($appointment_id, $client_id);
        ?>
                <tr class="<?php 
        echo $row_class;
        ?>
 birs_row_edit"
                    id="birs_client_list_row_edit_<?php 
        echo $client_id;
        ?>
"
                    data-item-id = "<?php 
        echo $client_id;
        ?>
"
                    data-edit-html = "<?php 
        echo esc_attr($edit_html);
        ?>
">

                    <td colspan = "<?php 
        echo $column_count;
        ?>
">
                    </td>
                </tr>
<?php 
    });
    birch_defn($ns, 'ajax_save', function () use($ns) {
        global $birchpress, $birchschedule;
        $appointment1on1_errors = $ns->validate_appointment1on1_info();
        $client_errors = $ns->validate_client_info();
        $email_errors = $ns->validate_duplicated_email();
        $errors = array_merge($appointment1on1_errors, $client_errors, $email_errors);
        if ($errors) {
            $birchschedule->view->render_ajax_error_messages($errors);
        }
        $client_config = array('base_keys' => array(), 'meta_keys' => $_POST['birs_client_fields']);
        $client_info = $birchschedule->view->merge_request(array(), $client_config, $_POST);
        $client_info['ID'] = $_POST['birs_client_id'];
        $client_id = $birchschedule->model->booking->save_client($client_info);
        if (isset($_POST['birs_appointment_fields'])) {
            $appointment1on1s_fields = $_POST['birs_appointment_fields'];
        } else {
            $appointment1on1s_fields = array();
        }
        $appointment1on1s_config = array('base_keys' => array(), 'meta_keys' => $appointment1on1s_fields);
        $appointment1on1s_info = $birchschedule->view->merge_request(array(), $appointment1on1s_config, $_POST);
        $appointment1on1s_info['_birs_client_id'] = $_POST['birs_client_id'];
        $appointment1on1s_info['_birs_appointment_id'] = $_POST['birs_appointment_id'];
        $appointment1on1s_info['_birs_appointment_fields'] = $appointment1on1s_fields;
        $birchschedule->model->booking->change_appointment1on1_custom_info($appointment1on1s_info);
        $birchschedule->view->render_ajax_success_message(array('code' => 'success', 'message' => ''));
    });
    birch_defn($ns, 'validate_duplicated_email', function () {
        global $birchschedule;
        $errors = array();
        $client_id = $_POST['birs_client_id'];
        if (!isset($_POST['birs_client_email'])) {
            return $errors;
        }
        $email = $_POST['birs_client_email'];
        if ($birchschedule->model->booking->if_email_duplicated($client_id, $email)) {
            $errors['birs_client_email'] = __('Email already exists.', 'birchschedule') . ' (' . $email . ')';
        }
        return $errors;
    });
    birch_defn($ns, 'validate_client_info', function () {
        $errors = array();
        if (!$_POST['birs_client_name_first']) {
            $errors['birs_client_name_first'] = __('This field is required', 'birchschedule');
        }
        if (!$_POST['birs_client_name_last']) {
            $errors['birs_client_name_last'] = __('This field is required', 'birchschedule');
        }
        if (!$_POST['birs_client_email']) {
            $errors['birs_client_email'] = __('Email is required', 'birchschedule');
        } else {
            if (!is_email($_POST['birs_client_email'])) {
                $errors['birs_client_email'] = __('Email is incorrect', 'birchschedule');
            }
        }
        if (!$_POST['birs_client_phone']) {
            $errors['birs_client_phone'] = __('This field is required', 'birchschedule');
        }
        return $errors;
    });
    birch_defn($ns, 'validate_appointment1on1_info', function () {
        return array();
    });
    birch_defn($ns, 'get_client_edit_actions', function () {
        ?>
                <ul>
                    <li class="birs_form_field">
                        <label>
                            &nbsp;
                        </label>
                        <div class="birs_field_content">
                            <input name="birs_appointment_client_edit_save"
                                id="birs_appointment_client_edit_save"
                                type="button" class="button-primary"
                                value="<?php 
        _e('Save', 'birchschedule');
        ?>
" />
                            <a href="javascript:void(0);"
                                id="birs_appointment_client_edit_cancel"
                                style="padding: 4px 0 0 4px; display: inline-block;">
                                <?php 
        _e('Cancel', 'birchschedule');
        ?>
                            </a>
                        </div>
                    </li>
                </ul>
<?php 
    });
    birch_defn($ns, 'get_client_edit_html', function ($appointment_id, $client_id) use($ns) {
        ob_start();
        ?>
                <div style="overflow:hidden;">
                    <h4><?php 
        _e('Edit Client', 'birchschedule');
        ?>
</h4>
                    <?php 
        echo $ns->get_client_info_html($client_id);
        ?>
                    <input type="hidden" name="birs_client_id" id="birs_client_id" value="<?php 
        echo $client_id;
        ?>
" />
                    <div style="border-bottom: 1px solid #EEEEEE;"></div>
                    <?php 
        echo $ns->get_appointment1on1_info_html($appointment_id, $client_id);
        ?>
                    <?php 
        echo $ns->get_client_edit_actions();
        ?>
                </div>
<?php 
        return ob_get_clean();
    });
    birch_defn($ns, 'get_appointment1on1_info_html', function ($appointment_id, $client_id) use($ns) {
        global $birchschedule;
        $appointment1on1s = $birchschedule->model->query(array('post_type' => 'birs_appointment1on1', 'meta_query' => array(array('key' => '_birs_client_id', 'value' => $client_id), array('key' => '_birs_appointment_id', 'value' => $appointment_id))), array('base_keys' => array(), 'meta_keys' => array('_birs_appointment_notes')));
        $notes = '';
        if ($appointment1on1s) {
            $appointment1on1s = array_values($appointment1on1s);
            $appointment_ext = $appointment1on1s[0];
            if (isset($appointment_ext['_birs_appointment_notes'])) {
                $notes = $appointment_ext['_birs_appointment_notes'];
            }
        }
        ob_start();
        ?>
                <ul>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Notes', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <textarea id="birs_appointment_notes" name="birs_appointment_notes"><?php 
        echo $notes;
        ?>
</textarea>
                            <input type="hidden" name="birs_appointment_fields[]" value="_birs_appointment_notes" />
                        </div>
                    </li>
                </ul>
<?php 
        $content = ob_get_clean();
        return $content;
    });
    birch_defn($ns, 'get_client_info_html', function ($client_id) use($ns) {
        global $birchpress, $birchschedule;
        $client_titles = $birchpress->util->get_client_title_options();
        $client_title = get_post_meta($client_id, '_birs_client_title', true);
        $first_name = get_post_meta($client_id, '_birs_client_name_first', true);
        $last_name = get_post_meta($client_id, '_birs_client_name_last', true);
        $addresss1 = get_post_meta($client_id, '_birs_client_address1', true);
        $addresss2 = get_post_meta($client_id, '_birs_client_address2', true);
        $email = get_post_meta($client_id, '_birs_client_email', true);
        $phone = get_post_meta($client_id, '_birs_client_phone', true);
        $city = get_post_meta($client_id, '_birs_client_city', true);
        $zip = get_post_meta($client_id, '_birs_client_zip', true);
        $state = get_post_meta($client_id, '_birs_client_state', true);
        $country = get_post_meta($client_id, '_birs_client_country', true);
        if (!$country) {
            $country = $birchschedule->model->get_default_country();
        }
        $states = $birchpress->util->get_states();
        $countries = $birchpress->util->get_countries();
        if (isset($states[$country])) {
            $select_display = "";
            $text_display = "display:none;";
        } else {
            $select_display = "display:none;";
            $text_display = "";
        }
        ob_start();
        ?>
                <ul>
                    <li class="birs_form_field birs_client_title">
                        <label for="birs_client_title"><?php 
        _e('Title', 'birchschedule');
        ?>
</label>
                        <div class="birs_field_content">
                            <select name="birs_client_title" id="birs_client_title">
                                <?php 
        $birchpress->util->render_html_options($client_titles, $client_title);
        ?>
                            </select>
                            <input type="hidden" name="birs_client_fields[]" value="_birs_client_title">
                        </div>
                        <div class="birs_error" id="birs_client_title_error">
                        </div>
                    </li>
                    <li class="birs_form_field birs_client_name_first">
                        <label for="birs_client_name_first"><?php 
        _e('First Name', 'birchschedule');
        ?>
</label>
                        <div class="birs_field_content">
                            <input type="text" name="birs_client_name_first" id="birs_client_name_first" value="<?php 
        echo esc_attr($first_name);
        ?>
">
                            <input type="hidden" name="birs_client_fields[]" value="_birs_client_name_first">
                        </div>
                        <div class="birs_error" id="birs_client_name_first_error">
                        </div>
                    </li>
                        <li class="birs_form_field birs_client_name_last">
                        <label for="birs_client_name_last"><?php 
        _e('Last Name', 'birchschedule');
        ?>
</label>
                        <div class="birs_field_content">
                            <input type="text" name="birs_client_name_last" id="birs_client_name_last" value="<?php 
        echo esc_attr($last_name);
        ?>
">
                            <input type="hidden" name="birs_client_fields[]" value="_birs_client_name_last">
                        </div>
                        <div class="birs_error" id="birs_client_name_last_error">
                        </div>
                    </li>
                        <li class="birs_form_field birs_client_email">
                        <label for="birs_client_email"><?php 
        _e('Email', 'birchschedule');
        ?>
</label>
                        <div class="birs_field_content">
                            <input type="text" name="birs_client_email" id="birs_client_email" value="<?php 
        echo esc_attr($email);
        ?>
">
                            <input type="hidden" name="birs_client_fields[]" value="_birs_client_email">
                        </div>
                        <div class="birs_error" id="birs_client_email_error">
                        </div>
                    </li>
                    <li class="birs_form_field birs_client_phone">
                        <label for="birs_client_phone"><?php 
        _e('Phone', 'birchschedule');
        ?>
</label>
                        <div class="birs_field_content">
                            <input type="text" name="birs_client_phone" id="birs_client_phone" value="<?php 
        echo esc_attr($phone);
        ?>
">
                            <input type="hidden" name="birs_client_fields[]" value="_birs_client_phone">
                        </div>
                        <div class="birs_error" id="birs_client_phone_error">
                        </div>
                    </li>
                    <li class="birs_form_field birs_client_address">
                        <label for="birs_client_address1"><?php 
        _e('Address', 'birchschedule');
        ?>
</label>
                        <div class="birs_field_content">
                            <input type="text" name="birs_client_address1" id="birs_client_address1" style="display: block;" value="<?php 
        echo esc_attr($addresss1);
        ?>
">
                            <input type="text" name="birs_client_address2" id="birs_client_address2" value="<?php 
        echo esc_attr($addresss2);
        ?>
">
                            <input type="hidden" name="birs_client_fields[]" value="_birs_client_address1">
                            <input type="hidden" name="birs_client_fields[]" value="_birs_client_address2">
                        </div>
                        <div class="birs_error" id="birs_client_address_error">
                        </div>
                    </li>
                    <li class="birs_form_field birs_client_city">
                        <label for="birs_client_city"><?php 
        _e('City', 'birchschedule');
        ?>
</label>
                        <div class="birs_field_content">
                            <input type="text" name="birs_client_city" id="birs_client_city" value="<?php 
        echo esc_attr($city);
        ?>
">
                            <input type="hidden" name="birs_client_fields[]" value="_birs_client_city">
                        </div>
                        <div class="birs_error" id="birs_client_city_error">
                        </div>
                    </li>
                    <li class="birs_form_field birs_client_state">
                        <label for="birs_client_state"><?php 
        _e('State/Province', 'birchschedule');
        ?>
</label>
                        <div class="birs_field_content">
                            <select name="birs_client_state_select" id ="birs_client_state_select" style="<?php 
        echo $select_display;
        ?>
">
<?php 
        if (isset($states[$country])) {
            $birchpress->util->render_html_options($states[$country], $state);
        }
        ?>
                            </select>
                            <input type="text" name="birs_client_state" id="birs_client_state" value="<?php 
        echo esc_attr($state);
        ?>
" style="<?php 
        echo $text_display;
        ?>
" />
                            <input type="hidden" name="birs_client_fields[]" value="_birs_client_state">
                        </div>
                        <div class="birs_error" id="birs_client_state_error">
                        </div>
                    </li>
                    <li class="birs_form_field birs_client_country">
                        <label for="birs_client_country"><?php 
        _e('Country', 'birchschedule');
        ?>
</label>
                        <div class="birs_field_content">
                            <select name="birs_client_country" id="birs_client_country">
                                <?php 
        $birchpress->util->render_html_options($countries, $country);
        ?>
                            </select>
                            <input type="hidden" name="birs_client_fields[]" value="_birs_client_country">
                        </div>
                        <div class="birs_error" id="birs_client_country_error">
                        </div>
                    </li>
                    <li class="birs_form_field birs_client_zip">
                        <label for="birs_client_zip"><?php 
        _e('Zip Code', 'birchschedule');
        ?>
</label>
                        <div class="birs_field_content">
                            <input type="text" name="birs_client_zip" id="birs_client_zip" value="<?php 
        echo esc_attr($zip);
        ?>
">
                            <input type="hidden" name="birs_client_fields[]" value="_birs_client_zip">
                        </div>
                        <div class="birs_error" id="birs_client_zip_error">
                        </div>
                    </li>
                </ul>
<?php 
        return ob_get_clean();
    });
});
Esempio n. 12
0
birch_ns('birchschedule.view.help', function ($ns) {
    global $birchschedule;
    $_ns_data = new stdClass();
    birch_defn($ns, 'init', function () use($ns, $_ns_data) {
        $_ns_data->RUN_ACTION_NAME = "birchschedule_help_action_run";
        add_action('admin_init', array($ns, 'wp_admin_init'));
    });
    birch_defn($ns, 'wp_admin_init', function () use($ns, $_ns_data) {
        if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'birchschedule_help') {
            $php_code = get_transient('birchschedule_help_php_code');
            $ns->run_php_code($php_code);
            delete_transient('birchschedule_help_php_code');
            $ns->load_page();
        }
        add_action('birchschedule_view_render_help_page_after', array($ns, 'render_admin_page'));
        add_action('admin_post_' . $_ns_data->RUN_ACTION_NAME, array($ns, 'cache_code'));
    });
    birch_defn($ns, 'run_php_code', function ($code) {
        if (!$code) {
            return;
        } else {
            ob_start();
            eval($code);
            ob_end_clean();
        }
    });
    birch_defn($ns, 'get_screen', function () use($ns) {
        global $birchschedule;
        $hook_name = $birchschedule->view->get_page_hook('help');
        $screen = $birchschedule->view->get_screen($hook_name);
        return $screen;
    });
    birch_defn($ns, 'load_page', function () use($ns) {
        $screen = $ns->get_screen();
        add_meta_box('birs_help_general', __('Help and Support', 'birchschedule'), array($ns, 'render_help_general'), $screen, 'main', 'default');
        add_meta_box('birs_help_version', __('Versions', 'birchschedule'), array($ns, 'render_help_version'), $screen, 'main', 'default');
        if (current_user_can('manage_options')) {
            add_meta_box('birs_help_run_scripts', __('Tools', 'birchschedule'), array($ns, 'render_run_scripts'), $screen, 'main', 'default');
        }
    });
    birch_defn($ns, 'render_help_version', function () use($ns) {
        global $birchschedule, $wp_version, $wpdb;
        $version = $birchschedule->get_product_version();
        $product_name = $birchschedule->get_product_name();
        ?>
                <div class="wrap">
                    <table class="form-table">
                        <tbody>
                            <tr>
                                <th><?php 
        echo "{$product_name}";
        ?>
</th>
                                <td><?php 
        echo "{$version}";
        ?>
</td>
                            </tr>
                            <tr>
                                <th><?php 
        echo "WordPress";
        ?>
</th>
                                <td><?php 
        echo "{$wp_version}";
        ?>
</td>
                            </tr>
                            <tr>
                                <th><?php 
        echo "PHP";
        ?>
</th>
                                <td><?php 
        echo phpversion();
        ?>
</td>
                            </tr>
                            <tr>
                                <th><?php 
        echo "MySQL";
        ?>
</th>
                                <td><?php 
        echo $wpdb->db_version();
        ?>
</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
<?php 
    });
    birch_defn($ns, 'render_help_general', function () {
        ?>
                <div class="padding">
                    <p>If you have any questions, please refer to <a target="_blank" href="http://www.birchpress.com/support/documentation">documentation</a> first.</p>
                    <p>If you are using a <a target="_blank" href="http://www.birchpress.com/">premium edition</a>, please submit a ticket <a target="_blank" href="http://www.birchpress.com/support/submit-a-ticket/">here</a>.</p>
                    <p>If you are using a free version, please submit your question through our <a target="_blank" href="http://www.birchpress.com/support/forums">support forum</a>.</p>
                    <p>If you find our product helpful, please <a target="_blank" href="http://wordpress.org/extend/plugins/birchschedule">rate it!</a></p>
                </div>
<?php 
    });
    birch_defn($ns, 'render_run_scripts', function () use($ns, $birchschedule, $_ns_data) {
        ?>
    <p>
        <a href="javascript:void(0);" id="birs_help_button_toggle_run"><?php 
        _e('Run PHP scripts. This is only for advanced users.');
        ?>
</a>
    </p>
    <div id="birs_help_panel_run_scripts" style="display:none;">
        <form method="post" action="<?php 
        echo admin_url('admin-post.php');
        ?>
">
            <?php 
        wp_nonce_field($_ns_data->RUN_ACTION_NAME);
        ?>
            <input type="hidden" name="action" value="<?php 
        echo $_ns_data->RUN_ACTION_NAME;
        ?>
" />
            <textarea name="birchschedule_help_php_code" style="width:99%;display:block;margin:6px 0;" rows="10"></textarea>
            <input type="submit" class="button-primary" value="<?php 
        _e('Run', 'birchschedule');
        ?>
" />
        </form>
    </div>
    <script type="text/javascript">
        jQuery(function($){
            $('#birs_help_button_toggle_run').click(function(){
                $('#birs_help_panel_run_scripts').toggle();
            });
        });
    </script>
<?php 
    });
    birch_defn($ns, 'cache_code', function () use($ns, $birchschedule, $_ns_data) {
        check_admin_referer($_ns_data->RUN_ACTION_NAME);
        if (isset($_POST['birchschedule_help_php_code'])) {
            $php_code = stripslashes_deep($_POST['birchschedule_help_php_code']);
            set_transient("birchschedule_help_php_code", $php_code, 60);
        }
        $orig_url = $_POST['_wp_http_referer'];
        wp_redirect($orig_url);
        exit;
    });
    birch_defn($ns, 'render_admin_page', function () use($ns) {
        global $birchschedule;
        $screen = $ns->get_screen();
        $birchschedule->view->show_notice();
        ?>
                <div id="birchschedule_help" class="wrap">
                    <div id="poststuff">
                        <div id="post-body" class="metabox-holder columns-1">
                            <div id="postbox-container-1" class="postbox-container">
                                <?php 
        do_meta_boxes($screen, 'main', array());
        ?>
                            </div>
                        </div>
                        <br class="clear" />
                    </div>
                </div>
<?php 
    });
});
Esempio n. 13
0
birch_ns('birchschedule.model.booking', function ($ns) {
    global $birchschedule;
    birch_defn($ns, 'init', function () use($ns, $birchschedule) {
        add_action('birchschedule_model_schedule_get_staff_avaliable_time_after', array($ns, 'record_fully_booked_day'), 20, 5);
        add_action('admin_post_birchschedule_model_booking_recheck_fully_booked_days', array($ns, 'admin_post_recheck_fully_booked_days'), 20);
        add_action('admin_post_nopriv_birchschedule_model_booking_recheck_fully_booked_days', array($ns, 'admin_post_recheck_fully_booked_days'), 20);
        add_action('birchschedule_model_booking_actions_check_if_fully_booked_for', array($ns, 'check_if_fully_booked_for'), 20, 1);
        add_action('birchschedule_model_booking_do_change_appointment1on1_status_after', array($ns, 'enqueue_checking_if_fully_booked'), 20, 1);
        add_action('birchschedule_model_booking_do_reschedule_appointment1on1_after', array($ns, 'enqueue_checking_if_fully_booked'), 20, 1);
        add_action('birchschedule_model_booking_cancel_appointment1on1_after', array($ns, 'enqueue_checking_if_fully_booked'), 20, 1);
        add_action('birchschedule_model_booking_do_change_appointment1on1_status_after', array($birchschedule, 'spawn_cron'), 200);
        add_action('birchschedule_model_booking_do_reschedule_appointment1on1_after', array($birchschedule, 'spawn_cron'), 200);
        add_action('birchschedule_model_booking_cancel_appointment1on1_after', array($birchschedule, 'spawn_cron'), 200);
    });
    birch_defn($ns, 'get_appointment_title', function ($appointment) use($ns) {
        global $birchschedule;
        $service = $birchschedule->model->get($appointment['_birs_appointment_service'], array('base_keys' => array('post_title'), 'meta_keys' => array()));
        $appointment1on1s = $appointment['appointment1on1s'];
        if (sizeof($appointment1on1s) > 1) {
            $title = $service['post_title'] . ' - ' . sprintf(__('%s Clients', 'birchschedule'), sizeof($appointment1on1s));
        } else {
            if (sizeof($appointment1on1s) == 1) {
                $appointment1on1s = array_values($appointment1on1s);
                $appointment1on1 = $appointment1on1s[0];
                $title = $service['post_title'] . ' - ' . $appointment1on1['_birs_client_name'];
            } else {
                $title = $service['post_title'];
            }
        }
        return $title;
    });
    birch_defn($ns, 'get_appointment1on1s_by_appointment', function ($appointment_id, $config = array()) use($ns) {
        $config = array_merge(array('status' => 'any'), $config);
        $appointments = $ns->query_appointments(array('status' => $config['status'], 'appointment_id' => $appointment_id), $config);
        if ($appointments) {
            $appointment1on1s = $appointments[$appointment_id]['appointment1on1s'];
        } else {
            $appointment1on1s = array();
        }
        return $appointment1on1s;
    });
    birch_defn($ns, 'get_appointment1on1', function ($appointment_id, $client_id, $config = array()) use($ns) {
        global $birchschedule;
        if (!$config) {
            $fields = $birchschedule->model->get_appointment1on1_custom_fields();
            $fields = array_merge($fields, array('_birs_client_id', '_birs_appointment_id', 'post_status'));
            $config = array('appointment1on1_keys' => $fields);
        }
        $config = array_merge(array('status' => 'any'), $config);
        $appointments = $ns->query_appointments(array('client_id' => $client_id, 'appointment_id' => $appointment_id, 'status' => $config['status']), $config);
        if ($appointments) {
            $appointment1on1s = $appointments[$appointment_id]['appointment1on1s'];
            $appointment1on1s = array_values($appointment1on1s);
            return $appointment1on1s[0];
        } else {
            return false;
        }
    });
    birch_defn($ns, 'query_appointments', function ($criteria, $config = array()) use($ns) {
        global $birchschedule;
        if (!is_array($criteria)) {
            $criteria = array();
        }
        $default = array('appointment_id' => -1, 'client_id' => -1, 'start' => time(), 'end' => time() + 24 * 60 * 60, 'location_id' => -1, 'staff_id' => -1, 'service_id' => -1, 'status' => 'publish', 'cache_results' => false);
        $criteria = array_merge($default, $criteria);
        $start = $criteria['start'];
        $end = $criteria['end'];
        $location_id = $criteria['location_id'];
        $staff_id = $criteria['staff_id'];
        $service_id = $criteria['service_id'];
        $status = $criteria['status'];
        $cache_results = $criteria['cache_results'];
        if (!is_array($config) || !$config) {
            $config = array();
        }
        if (isset($config['appointment_keys'])) {
            $appointment_keys = $config['appointment_keys'];
        } else {
            $appointment_keys = array();
        }
        if (isset($config['appointment1on1_keys'])) {
            $appointment1on1_keys = $config['appointment1on1_keys'];
        } else {
            $appointment1on1_keys = array();
        }
        if (isset($config['client_keys'])) {
            $client_keys = $config['client_keys'];
        } else {
            $client_keys = array();
        }
        $appointments_criteria = array('post_type' => 'birs_appointment', 'post_status' => 'publish', 'meta_query' => array(array('key' => '_birs_appointment_timestamp', 'value' => $start, 'compare' => '>=', 'type' => 'SIGNED'), array('key' => '_birs_appointment_timestamp', 'value' => $end, 'compare' => '<=', 'type' => 'SIGNED')), 'cache_results' => $cache_results);
        if ($location_id != -1) {
            if (!is_array($location_id)) {
                $appointments_criteria['meta_query'][] = array('key' => '_birs_appointment_location', 'value' => $location_id, 'type' => 'UNSIGNED');
            } else {
                $appointments_criteria['meta_query'][] = array('key' => '_birs_appointment_location', 'value' => $location_id, 'compare' => 'IN', 'type' => 'UNSIGNED');
            }
        }
        if ($staff_id != -1) {
            if (!is_array($staff_id)) {
                $appointments_criteria['meta_query'][] = array('key' => '_birs_appointment_staff', 'value' => $staff_id, 'type' => 'UNSIGNED');
            } else {
                $appointments_criteria['meta_query'][] = array('key' => '_birs_appointment_staff', 'value' => $staff_id, 'compare' => 'IN', 'type' => 'UNSIGNED');
            }
        }
        if ($service_id != -1) {
            if (!is_array($service_id)) {
                $appointments_criteria['meta_query'][] = array('key' => '_birs_appointment_service', 'value' => $service_id, 'type' => 'UNSIGNED');
            } else {
                $appointments_criteria['meta_query'][] = array('key' => '_birs_appointment_service', 'value' => $service_id, 'compare' => 'IN', 'type' => 'UNSIGNED');
            }
        }
        $appointment_id = $criteria['appointment_id'];
        if ($appointment_id != -1) {
            unset($appointments_criteria['meta_query']);
            if (!is_array($appointment_id)) {
                $appointments_criteria[] = array('p' => $appointment_id);
            } else {
                $appointments_criteria[] = array('post__in' => $appointment_id);
            }
        }
        if ($appointment_id == -1 || $appointment_keys) {
            $appointments = $birchschedule->model->query($appointments_criteria, array('keys' => $appointment_keys));
            $appointment_ids = array_keys($appointments);
        } else {
            $appointment_ids = (array) $appointment_id;
            $appointments = array();
            foreach ($appointment_ids as $appointment_id) {
                $appointments[$appointment_id] = array('appointment1on1s' => array());
            }
        }
        $appointment1on1_keys = array_merge($appointment1on1_keys, array('_birs_appointment_id', '_birs_client_id', 'post_status'));
        $appointment1on1s_critera = array('post_type' => 'birs_appointment1on1', 'post_status' => $status, 'meta_query' => array(array('key' => '_birs_appointment_id', 'value' => array_merge($appointment_ids, array(0)), 'compare' => 'IN', 'type' => 'UNSIGNED')), 'cache_results' => $cache_results);
        $client_id = $criteria['client_id'];
        if ($client_id != -1) {
            if (!is_array($client_id)) {
                $appointment1on1s_critera['meta_query'][] = array('key' => '_birs_client_id', 'value' => $client_id, 'type' => 'UNSIGNED');
            } else {
                $appointment1on1s_critera['meta_query'][] = array('key' => '_birs_client_id', 'value' => array_merge($client_id, array(0)), 'compare' => 'IN', 'type' => 'UNSIGNED');
            }
        }
        $appointment1on1s = $birchschedule->model->query($appointment1on1s_critera, array('keys' => $appointment1on1_keys));
        $new_appointments = array();
        foreach ($appointment1on1s as $appointment1on1_id => $appointment1on1) {
            $client_id = $appointment1on1['_birs_client_id'];
            if ($client_keys) {
                $client = $birchschedule->model->get($client_id, array('keys' => $client_keys));
                if (!$client) {
                    $client = array();
                }
            } else {
                $client = array();
            }
            if (!$client) {
                $client = array();
            }
            $appointment1on1 = array_merge($client, $appointment1on1);
            if (!isset($client['_birs_client_name']) && isset($client['post_title'])) {
                $appointment1on1['_birs_client_name'] = $client['post_title'];
            }
            $appointment_id = $appointment1on1['_birs_appointment_id'];
            if (isset($new_appointments[$appointment_id])) {
                $appointment = $new_appointments[$appointment_id];
            } else {
                $appointment = $appointments[$appointment_id];
            }
            if (!isset($appointment['appointment1on1s'])) {
                $appointment['appointment1on1s'] = array($appointment1on1_id => $appointment1on1);
            } else {
                $appointment['appointment1on1s'][$appointment1on1_id] = $appointment1on1;
            }
            $new_appointments[$appointment_id] = $appointment;
        }
        return $new_appointments;
    });
    birch_defn($ns, 'if_cancel_appointment_outoftime', function ($appointment_id) use($ns) {
        global $birchpress, $birchschedule;
        $time_before_cancel = $birchschedule->model->get_time_before_cancel();
        $appointment = $birchschedule->model->get($appointment_id, array('base_keys' => array(), 'meta_keys' => array('_birs_appointment_timestamp')));
        if (!$appointment) {
            return $birchpress->util->new_error('appointment_nonexist', __('The appointment does not exist.', 'birchschedule'));
        }
        if ($appointment['_birs_appointment_timestamp'] - time() > $time_before_cancel * 60 * 60) {
            return true;
        } else {
            return false;
        }
    });
    birch_defn($ns, 'if_reschedule_appointment_outoftime', function ($appointment_id) use($ns) {
        global $birchpress, $birchschedule;
        $time_before_reschedule = $birchschedule->model->get_time_before_reschedule();
        $appointment = $birchschedule->model->get($appointment_id, array('base_keys' => array(), 'meta_keys' => array('_birs_appointment_timestamp')));
        if (!$appointment) {
            return $birchpress->util->new_error('appointment_nonexist', __('The appointment does not exist.', 'birchschedule'));
        }
        if ($appointment['_birs_appointment_timestamp'] - time() > $time_before_reschedule * 60 * 60) {
            return true;
        } else {
            return false;
        }
    });
    birch_defn($ns, 'if_appointment_cancelled', function ($appointment_id) use($ns) {
        $appointment1on1s = $ns->get_appointment1on1s_by_appointment($appointment_id, array('status' => 'publish'));
        if ($appointment1on1s) {
            return false;
        } else {
            return true;
        }
    });
    birch_defn($ns, 'if_appointment1on1_cancelled', function ($appointment1on1_id) use($ns) {
        global $birchpress, $birchschedule;
        $appointment1on1 = $birchschedule->model->get($appointment1on1_id, array('base_keys' => array('post_status'), 'meta_keys' => array('_birs_appointment_id')));
        if (!$appointment1on1) {
            return $birchpress->util->new_error('appointment_nonexist', __('The appointment does not exist.', 'birchschedule'));
        }
        if ($appointment1on1['post_status'] == 'cancelled') {
            return true;
        } else {
            return false;
        }
    });
    birch_defn($ns, 'if_email_duplicated', function ($client_id, $email) use($ns) {
        global $birchschedule;
        $clients = $birchschedule->model->query(array('post_type' => 'birs_client', 'meta_query' => array(array('key' => '_birs_client_email', 'value' => $email))), array('base_keys' => array(), 'meta_keys' => array()));
        if (sizeof($clients) > 1) {
            return true;
        } elseif (sizeof($clients) === 1) {
            $client_ids = array_keys($clients);
            $exist_client_id = array_shift($client_ids);
            return $client_id != $exist_client_id;
        } else {
            return false;
        }
    });
    birch_defn($ns, 'save_client', function ($client_info) use($ns) {
        global $birchschedule;
        if (isset($client_info['_birs_client_fields'])) {
            $fields = $client_info['_birs_client_fields'];
        } else {
            $fields = $birchschedule->model->get_client_fields();
        }
        $config = array('meta_keys' => $fields, 'base_keys' => array('post_title'));
        if (isset($client_info['_birs_client_email']) && !isset($client_info['ID'])) {
            $email = $client_info['_birs_client_email'];
            $client = $birchschedule->model->get_client_by_email($email, array('base_keys' => array(), 'meta_keys' => array()));
            if ($client) {
                $client_info['ID'] = $client['ID'];
            }
        }
        $client_info['post_type'] = 'birs_client';
        $client_id = $birchschedule->model->save($client_info, $config);
        return $client_id;
    });
    birch_defn($ns, 'get_user_by_staff', function ($staff_id) use($ns) {
        global $birchschedule;
        $staff = $birchschedule->model->get($staff_id, array('base_keys' => array(), 'meta_keys' => array('_birs_staff_email')));
        if (!$staff) {
            return false;
        }
        $user = get_user_by('email', $staff['_birs_staff_email']);
        return $user;
    });
    birch_defn($ns, 'get_appointment_capacity', function ($appointment_id) use($ns) {
        global $birchschedule;
        $appointment = $birchschedule->model->get($appointment_id, array('meta_keys' => array('_birs_appointment_capacity')));
        if (isset($appointment['_birs_appointment_capacity'])) {
            $capacity = intval($appointment['_birs_appointment_capacity']);
            if ($capacity < 1) {
                $capacity = 1;
            }
        } else {
            $capacity = 1;
        }
        return $capacity;
    });
    birch_defn($ns, 'make_appointment', function ($appointment_info) use($ns) {
        birch_assert(isset($appointment_info['_birs_appointment_location']));
        birch_assert(isset($appointment_info['_birs_appointment_service']));
        birch_assert(isset($appointment_info['_birs_appointment_staff']));
        birch_assert(isset($appointment_info['_birs_appointment_timestamp']));
        global $birchschedule;
        $appointments = $birchschedule->model->query(array('post_type' => 'birs_appointment', 'post_status' => array('publish'), 'meta_query' => array(array('key' => '_birs_appointment_location', 'value' => $appointment_info['_birs_appointment_location']), array('key' => '_birs_appointment_service', 'value' => $appointment_info['_birs_appointment_service']), array('key' => '_birs_appointment_staff', 'value' => $appointment_info['_birs_appointment_staff']), array('key' => '_birs_appointment_timestamp', 'value' => $appointment_info['_birs_appointment_timestamp']))), array('base_keys' => array(), 'meta_keys' => array()));
        if ($appointments) {
            $appointment_ids = array_keys($appointments);
            return $appointment_ids[0];
        } else {
            $appointment_info['_birs_appointment_uid'] = uniqid(rand(), true);
            if (!isset($appointment_info['_birs_appointment_capacity'])) {
                $appointment_info['_birs_appointment_capacity'] = $birchschedule->model->get_service_capacity($appointment_info['_birs_appointment_service']);
            }
            if (!isset($appointment_info['_birs_appointment_duration'])) {
                $appointment_info['_birs_appointment_duration'] = $birchschedule->model->get_service_length($appointment_info['_birs_appointment_service']);
            }
            if (!isset($appointment_info['_birs_appointment_padding_before'])) {
                $appointment_info['_birs_appointment_padding_before'] = $birchschedule->model->get_service_padding_before($appointment_info['_birs_appointment_service']);
            }
            if (!isset($appointment_info['_birs_appointment_padding_after'])) {
                $appointment_info['_birs_appointment_padding_after'] = $birchschedule->model->get_service_padding_after($appointment_info['_birs_appointment_service']);
            }
        }
        $base_keys = array();
        $user = $ns->get_user_by_staff($appointment_info['_birs_appointment_staff']);
        if ($user) {
            $appointment_info['post_author'] = $user->ID;
            $base_keys[] = 'post_author';
        }
        $config = array('base_keys' => $base_keys, 'meta_keys' => $birchschedule->model->get_appointment_fields());
        $appointment_info['post_type'] = 'birs_appointment';
        $appointment_id = $birchschedule->model->save($appointment_info, $config);
        $ns->remove_auto_draft_appointments();
        return $appointment_id;
    });
    birch_defn($ns, 'remove_appointment_if_empty', function ($appointment_id) use($ns) {
        global $birchschedule;
        $appointment1on1s = $ns->get_appointment1on1s_by_appointment($appointment_id);
        if (!$appointment1on1s) {
            $birchschedule->model->delete($appointment_id);
        }
    });
    birch_defn($ns, 'remove_auto_draft_appointments', function () use($ns) {
        global $birchpress;
        $appointments = $birchpress->db->query(array('post_type' => 'birs_appointment', 'post_status' => 'auto-draft'), array('base_keys' => array(), 'meta_keys' => array()));
        foreach ($appointments as $appointment) {
            $birchpress->db->delete($appointment['ID']);
        }
    });
    birch_defn($ns, 'make_appointment1on1', function ($appointment1on1_info, $status = 'draft') use($ns) {
        birch_assert(isset($appointment1on1_info['_birs_client_id']), 'no client id');
        global $birchschedule;
        if (isset($appointment1on1_info['_birs_appointment_id'])) {
            $appointment_id = $appointment1on1_info['_birs_appointment_id'];
            $appointment = $birchschedule->model->get($appointment_id, array('meta_keys' => array('_birs_appointment_service')));
            $appointment1on1_info['_birs_appointment_service'] = $appointment['_birs_appointment_service'];
        } else {
            birch_assert(isset($appointment1on1_info['_birs_appointment_location']), 'no location');
            birch_assert(isset($appointment1on1_info['_birs_appointment_service']), 'no service');
            birch_assert(isset($appointment1on1_info['_birs_appointment_staff']), 'no staff');
            birch_assert(isset($appointment1on1_info['_birs_appointment_timestamp']), 'no timestamp');
            $appointment_id = $ns->make_appointment($appointment1on1_info);
            $appointment1on1_info['_birs_appointment_id'] = $appointment_id;
        }
        $client_id = $appointment1on1_info['_birs_client_id'];
        $appointment1on1 = $ns->get_appointment1on1($appointment_id, $client_id);
        if ($appointment1on1) {
            return $appointment1on1['ID'];
        }
        $appointment1on1_info['_birs_appointment1on1_uid'] = uniqid(rand(), true);
        if (!isset($appointment1on1_info['_birs_appointment1on1_price'])) {
            $appointment1on1_info['_birs_appointment1on1_price'] = $birchschedule->model->get_service_price($appointment1on1_info['_birs_appointment_service']);
        }
        $appointment1on1_info['_birs_appointment1on1_payment_status'] = 'not-paid';
        $appointment1on1_info['post_status'] = $status;
        if (isset($appointment1on1_info['_birs_appointment_fields'])) {
            $custom_fields = $appointment1on1_info['_birs_appointment_fields'];
        } else {
            $custom_fields = $birchschedule->model->get_appointment1on1_custom_fields();
        }
        $std_fields = $birchschedule->model->get_appointment1on1_fields();
        $all_fields = array_merge($std_fields, $custom_fields);
        $appointment1on1_info['post_type'] = 'birs_appointment1on1';
        $base_keys = array('post_status');
        $appointment1on1_id = $birchschedule->model->save($appointment1on1_info, array('base_keys' => $base_keys, 'meta_keys' => $all_fields));
        return $appointment1on1_id;
    });
    birch_defn($ns, 'change_appointment1on1_status', function ($appointment1on1_id, $status) use($ns) {
        global $birchpress, $birchschedule;
        $appointment1on1_info = array('ID' => $appointment1on1_id, 'post_status' => $status, 'post_type' => 'birs_appointment1on1');
        $config = array('base_keys' => array('post_status'), 'meta_keys' => array());
        $appointment1on1 = $birchschedule->model->get($appointment1on1_id, $config);
        if (!$appointment1on1) {
            return $birchpress->util->new_error('appointment1on1_nonexist', __('The appointment does not exist.', 'birchschedule'));
        }
        $old_status = $appointment1on1['post_status'];
        $birchschedule->model->save($appointment1on1_info, $config);
        $ns->do_change_appointment1on1_status($appointment1on1_id, $status, $old_status);
        return true;
    });
    birch_defn($ns, 'do_change_appointment1on1_status', function ($appointment1on1_id, $new_status, $old_status) {
    });
    birch_defn($ns, 'change_appointment1on1_custom_info', function ($appointment1on1_info) use($ns) {
        global $birchpress, $birchschedule;
        $assertion = isset($appointment1on1_info['ID']) || isset($appointment1on1_info['_birs_appointment_id']) && isset($appointment1on1_info['_birs_client_id']);
        birch_assert($assertion, 'ID or (_birs_appointment_id and _birs_client_id) should be in the info.');
        if (isset($appointment1on1_info['_birs_appointment_fields'])) {
            $custom_fields = $appointment1on1_info['_birs_appointment_fields'];
        } else {
            $custom_fields = $birchschedule->model->get_appointment1on1_custom_fields();
        }
        if (!isset($appointment1on1_info['ID'])) {
            $appointment1on1 = $ns->get_appointment1on1($appointment1on1_info['_birs_appointment_id'], $appointment1on1_info['_birs_client_id']);
            if (!$appointment1on1) {
                return $birchpress->util->new_error('appointment1on1_nonexist', __('The appointment does not exist.', 'birchschedule'));
            } else {
                $appointment1on1_info['ID'] = $appointment1on1['ID'];
            }
        }
        $appointment1on1_info['post_type'] = 'birs_appointment1on1';
        $appointment1on1_id = $birchschedule->model->save($appointment1on1_info, array('base_keys' => array(), 'meta_keys' => $custom_fields));
        return $appointment1on1_id;
    });
    birch_defn($ns, 'reschedule_appointment', function ($appointment_id, $appointment_info) use($ns) {
        birch_assert(isset($appointment_info['_birs_appointment_staff']) || isset($appointment_info['_birs_appointment_timestamp']));
        global $birchpress, $birchschedule;
        $appointment1on1s = $ns->get_appointment1on1s_by_appointment($appointment_id, array('status' => 'publish'));
        if ($appointment1on1s) {
            foreach ($appointment1on1s as $appointment1on1_id => $appointment1on1) {
                $ns->reschedule_appointment1on1($appointment1on1_id, $appointment_info);
            }
        }
    });
    birch_defn($ns, 'do_reschedule_appointment1on1', function ($appointment1on1_id, $appointment_info) {
    });
    birch_defn($ns, 'reschedule_appointment1on1', function ($appointment1on1_id, $appointment_info) use($ns) {
        global $birchpress, $birchschedule;
        birch_assert(isset($appointment_info['_birs_appointment_staff']) || isset($appointment_info['_birs_appointment_timestamp']));
        $appointment1on1 = $birchschedule->model->get($appointment1on1_id, array('base_keys' => array(), 'meta_keys' => array('_birs_appointment_id', '_birs_client_id')));
        if (!$appointment1on1) {
            return $birchpress->util->new_error('appointment1on1_nonexist', __('The appointment does not exist.', 'birchschedule'));
        }
        $appointment = $birchschedule->model->get($appointment1on1['_birs_appointment_id'], array('base_keys' => array(), 'meta_keys' => array('_birs_appointment_location', '_birs_appointment_service', '_birs_appointment_staff', '_birs_appointment_timestamp', '_birs_appointment_duration', '_birs_appointment_padding_before', '_birs_appointment_padding_after')));
        if (!$appointment) {
            return $birchpress->util->new_error('appointment_nonexist', __('The appointment does not exist.', 'birchschedule'));
        }
        if (!isset($appointment_info['_birs_appointment_staff'])) {
            $appointment_info['_birs_appointment_staff'] = $appointment['_birs_appointment_staff'];
        }
        if (!isset($appointment_info['_birs_appointment_timestamp'])) {
            $appointment_info['_birs_appointment_timestamp'] = $appointment['_birs_appointment_timestamp'];
        }
        if (!isset($appointment_info['_birs_appointment_location'])) {
            $appointment_info['_birs_appointment_location'] = $appointment['_birs_appointment_location'];
        }
        if (!isset($appointment_info['_birs_appointment_service'])) {
            $appointment_info['_birs_appointment_service'] = $appointment['_birs_appointment_service'];
        }
        if ($appointment['_birs_appointment_staff'] === $appointment_info['_birs_appointment_staff'] && $appointment['_birs_appointment_timestamp'] === $appointment_info['_birs_appointment_timestamp'] && $appointment['_birs_appointment_location'] === $appointment_info['_birs_appointment_location'] && $appointment['_birs_appointment_service'] === $appointment_info['_birs_appointment_service']) {
            return false;
        }
        $appointment['_birs_appointment_staff'] = $appointment_info['_birs_appointment_staff'];
        $appointment['_birs_appointment_timestamp'] = $appointment_info['_birs_appointment_timestamp'];
        $appointment['_birs_appointment_location'] = $appointment_info['_birs_appointment_location'];
        $appointment['_birs_appointment_service'] = $appointment_info['_birs_appointment_service'];
        unset($appointment['ID']);
        $appointment_id = $ns->make_appointment($appointment);
        $orig_appointment_id = $appointment1on1['_birs_appointment_id'];
        $appointment1on1['_birs_appointment_id'] = $appointment_id;
        $birchschedule->model->save($appointment1on1, array('base_keys' => array(), 'meta_keys' => array('_birs_appointment_id')));
        $payments = $birchschedule->model->query(array('post_type' => 'birs_payment', 'meta_query' => array(array('key' => '_birs_payment_appointment', 'value' => $orig_appointment_id), array('key' => '_birs_payment_client', 'value' => $appointment1on1['_birs_client_id']))), array('meta_keys' => array(), 'base_keys' => array()));
        foreach ($payments as $payment) {
            $payment['_birs_payment_appointment'] = $appointment_id;
            $birchschedule->model->save($payment, array('base_keys' => array(), 'meta_keys' => array('_birs_payment_appointment')));
        }
        $ns->remove_appointment_if_empty($orig_appointment_id);
        $ns->do_reschedule_appointment1on1($appointment1on1_id, $appointment_info);
        return true;
    });
    birch_defn($ns, 'cancel_appointment', function ($appointment_id) use($ns) {
        $appointment1on1s = $ns->get_appointment1on1s_by_appointment($appointment_id, array('status' => 'publish'));
        if ($appointment1on1s) {
            foreach ($appointment1on1s as $appointment1on1_id => $appointment1on1) {
                $ns->cancel_appointment1on1($appointment1on1_id);
            }
        }
    });
    birch_defn($ns, 'cancel_appointment1on1', function ($appointment1on1_id) use($ns) {
        global $birchschedule;
        $appointment1on1 = $birchschedule->model->mergefields->get_appointment1on1_merge_values($appointment1on1_id);
        if (!$appointment1on1) {
            return false;
        } else {
            $appointment_id = $appointment1on1['_birs_appointment_id'];
            if ($appointment1on1['post_status'] == 'cancelled') {
                return false;
            }
            $new_appointment1on1 = array('post_status' => 'cancelled', 'post_type' => 'birs_appointment1on1', 'ID' => $appointment1on1_id);
            $birchschedule->model->save($new_appointment1on1, array('base_keys' => array('post_status'), 'meta_keys' => array()));
            return $appointment1on1;
        }
    });
    birch_defn($ns, 'get_payments_by_appointment1on1', function ($appointment_id, $client_id) use($ns) {
        global $birchschedule;
        $payments = $birchschedule->model->query(array('post_type' => 'birs_payment', 'meta_query' => array(array('key' => '_birs_payment_appointment', 'value' => $appointment_id), array('key' => '_birs_payment_client', 'value' => $client_id))), array('meta_keys' => $birchschedule->model->get_payment_fields(), 'base_keys' => array()));
        return $payments;
    });
    birch_defn($ns, 'make_payment', function ($payment_info) use($ns) {
        global $birchpress, $birchschedule;
        $appointment_id = $payment_info['_birs_payment_appointment'];
        $client_id = $payment_info['_birs_payment_client'];
        $appointment1on1 = $ns->get_appointment1on1($appointment_id, $client_id);
        if (!$appointment1on1) {
            return $birchpress->util->new_error('appointment1on1_nonexist', __('The appointment does not exist.', 'birchschedule'));
        }
        $config = array('meta_keys' => $birchschedule->model->get_payment_fields(), 'base_keys' => array());
        $payment_info['post_type'] = 'birs_payment';
        $payment_id = $birchschedule->model->save($payment_info, $config);
        $appointment_price = $appointment1on1['_birs_appointment1on1_price'];
        $all_payments = $ns->get_payments_by_appointment1on1($appointment_id, $client_id);
        $paid = 0;
        foreach ($all_payments as $the_payment_id => $payment) {
            $paid += $payment['_birs_payment_amount'];
        }
        $payment_status = 'not-paid';
        if ($paid > 0 && $appointment_price - $paid >= 0.01) {
            $payment_status = 'partially-paid';
        }
        if ($paid > 0 && $appointment_price - $paid < 0.01) {
            $payment_status = 'paid';
        }
        $appointment1on1['_birs_appointment1on1_payment_status'] = $payment_status;
        $birchschedule->model->save($appointment1on1, array('base_keys' => array(), 'meta_keys' => array('_birs_appointment1on1_payment_status')));
        return $payment_id;
    });
    birch_defn($ns, 'get_payment_types', function () {
        return array('credit_card' => __('Credit Card', 'birchschedule'), 'cash' => __('Cash', 'birchschedule'));
    });
    birch_defn($ns, 'delete_appointment1on1', function ($appointment1on1_id) use($ns) {
        global $birchschedule;
        $fields = $birchschedule->model->get_appointment1on1_fields();
        $custom_fields = $birchschedule->model->get_appointment1on1_custom_fields();
        $fields = array_merge($fields, $custom_fields);
        foreach ($fields as $field) {
            delete_post_meta($appointment1on1_id, $field);
        }
        wp_delete_post($appointment1on1_id, true);
    });
    birch_defn($ns, 'delete_appointment', function ($appointment_id) use($ns) {
        global $birchschedule;
        $appointment1on1s = $ns->get_appointment1on1s_by_appointment($appointment_id, array('status' => 'any'));
        foreach ($appointment1on1s as $appointment1on1_id => $appointment1on1) {
            $ns->delete_appointment1on1($appointment1on1_id);
        }
        $fields = $birchschedule->model->get_appointment_fields();
        foreach ($fields as $field) {
            delete_post_meta($appointment_id, $field);
        }
        wp_delete_post($appointment_id, true);
    });
    birch_defn($ns, 'delete_appointments', function ($start, $end, $location_id, $staff_id) use($ns) {
        $criteria = array('start' => $start, 'end' => $end, 'location_id' => $location_id, 'staff_id' => $staff_id);
        $appointments = $ns->query_appointments($criteria);
        foreach ($appointments as $appointment_id => $appointment) {
            $ns->delete_appointment($appointment_id);
        }
    });
    birch_defn($ns, 'record_fully_booked_day', function ($staff_id, $location_id, $service_id, $date, $time_options) use($ns) {
        global $birchschedule;
        $empty = true;
        foreach ($time_options as $key => $value) {
            if ($value['avaliable']) {
                $empty = false;
                break;
            }
        }
        $date_text = $date->format('Y-m-d');
        if ($empty) {
            $birchschedule->model->schedule->mark_fully_booked_day($staff_id, $location_id, $service_id, $date_text);
        } else {
            $birchschedule->model->schedule->unmark_fully_booked_day($staff_id, $location_id, $service_id, $date_text);
        }
    });
    birch_defn($ns, 'enqueue_checking_if_fully_booked', function ($appointment1on1_id) use($ns) {
        wp_schedule_single_event(time(), 'birchschedule_model_booking_actions_check_if_fully_booked_for', array('appointment1on1_id' => $appointment1on1_id));
    });
    birch_defn($ns, 'check_if_fully_booked_for', function ($appointment1on1_id) use($ns, $birchschedule) {
        global $birchpress;
        $appointment1on1 = $birchschedule->model->mergefields->get_appointment1on1_merge_values($appointment1on1_id);
        $staff_id = $appointment1on1['_birs_appointment_staff'];
        $timestamp = $appointment1on1['_birs_appointment_timestamp'];
        $date = $birchpress->util->get_wp_datetime($timestamp);
        $date_text = $date->format('Y-m-d');
        $ns->check_if_fully_booked($staff_id, $date_text);
    });
    birch_defn($ns, 'check_if_fully_booked', function ($staff_id, $date_text) use($ns) {
        global $birchpress, $birchschedule;
        $services = $birchschedule->model->get_services_by_staff($staff_id);
        $locations = $birchschedule->model->get_locations_listing_order();
        foreach ($services as $service_id => $value) {
            foreach ($locations as $location_id) {
                $date = $birchpress->util->get_wp_datetime("{$date_text} 00:00:00");
                $time_options = $birchschedule->model->schedule->get_staff_avaliable_time($staff_id, $location_id, $service_id, $date);
            }
        }
    });
    birch_defn($ns, 'async_recheck_fully_booked_days', function () use($ns) {
        wp_remote_post(admin_url('admin-post.php'), array('method' => 'POST', 'timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters('https_local_ssl_verify', true), 'body' => array('action' => 'birchschedule_model_booking_recheck_fully_booked_days')));
    });
    birch_defn($ns, 'admin_post_recheck_fully_booked_days', function () use($ns) {
        global $birchschedule;
        $fully_booked = $birchschedule->model->schedule->get_fully_booked_days();
        foreach ($fully_booked as $date_text => $staff_arr) {
            foreach ($staff_arr as $staff_id => $arr) {
                $ns->check_if_fully_booked($staff_id, $date_text);
            }
        }
    });
});
Esempio n. 14
0
birch_ns('birchschedule.view.calendar', function ($ns) {
    $ns->init = function () use($ns) {
        global $birchschedule;
        add_action('admin_init', array($ns, 'wp_admin_init'));
        $birchschedule->view->register_script_data_fn('birchschedule_view_calendar', 'birchschedule_view_calendar', array($ns, 'get_script_data_fn_view_calendar'));
    };
    $ns->wp_admin_init = function () use($ns) {
        global $birchschedule;
        add_action('admin_enqueue_scripts', function ($hook) {
            global $birchschedule;
            if ($birchschedule->view->get_page_hook('calendar') !== $hook) {
                return;
            }
            $birchschedule->view->calendar->enqueue_scripts();
        });
        add_action('wp_ajax_birchschedule_view_calendar_query_appointments', array($ns, 'ajax_query_appointments'));
        add_action('birchschedule_view_render_calendar_page_after', array($ns, 'render_admin_page'));
    };
    $ns->get_script_data_fn_view_calendar = function () use($ns) {
        return array('default_calendar_view' => $ns->get_default_view(), 'location_map' => $ns->get_locations_map(), 'location_staff_map' => $ns->get_locations_staff_map(), 'location_order' => $ns->get_locations_listing_order(), 'staff_order' => $ns->get_staff_listing_order(), 'slot_minutes' => 15, 'first_hour' => 9);
    };
    $ns->enqueue_scripts = function () use($ns) {
        global $birchschedule;
        $birchschedule->view->register_3rd_scripts();
        $birchschedule->view->register_3rd_styles();
        $birchschedule->view->enqueue_scripts(array('birchschedule_view_calendar', 'birchschedule_view', 'birchschedule_view_admincommon', 'birchschedule_model'));
        $birchschedule->view->enqueue_styles(array('fullcalendar_birchpress', 'birchschedule_admincommon', 'birchschedule_calendar', 'select2', 'jgrowl'));
    };
    $ns->get_default_view = function () {
        return 'agendaWeek';
    };
    $ns->query_appointments = function ($start, $end, $location_id, $staff_id) use($ns) {
        global $birchschedule, $birchpress;
        $criteria = array('start' => $start, 'end' => $end, 'location_id' => $location_id, 'staff_id' => $staff_id);
        $appointments = $birchschedule->model->booking->query_appointments($criteria, array('appointment_keys' => array('_birs_appointment_duration', '_birs_appointment_price', '_birs_appointment_timestamp', '_birs_appointment_service'), 'client_keys' => array('post_title')));
        $apmts = array();
        foreach ($appointments as $appointment) {
            $title = $birchschedule->model->booking->get_appointment_title($appointment);
            $appointment['post_title'] = $title;
            $duration = intval($appointment['_birs_appointment_duration']);
            $price = $appointment['_birs_appointment_price'];
            $time_start = $appointment['_birs_appointment_timestamp'];
            $time_end = $time_start + $duration * 60;
            $time_start = $birchpress->util->get_wp_datetime($time_start)->format('c');
            $time_end = $birchpress->util->get_wp_datetime($time_end)->format('c');
            $apmt = array('id' => $appointment['ID'], 'title' => $appointment['post_title'], 'start' => $time_start, 'end' => $time_end, 'allDay' => false, 'editable' => true);
            $apmts[] = $apmt;
        }
        return $apmts;
    };
    $ns->get_locations_map = function () use($ns) {
        global $birchschedule;
        $i18n_msgs = $birchschedule->view->get_frontend_i18n_messages();
        $locations_map = $birchschedule->model->get_locations_map();
        $locations_map[-1] = array('post_title' => $i18n_msgs['All Locations']);
        return $locations_map;
    };
    $ns->get_locations_staff_map = function () use($ns) {
        global $birchschedule;
        $i18n_msgs = $birchschedule->view->get_frontend_i18n_messages();
        $map = $birchschedule->model->get_locations_staff_map();
        $allstaff = $birchschedule->model->query(array('post_type' => 'birs_staff'), array('meta_keys' => array(), 'base_keys' => array('post_title')));
        $new_allstaff = array('-1' => $i18n_msgs['All Providers']);
        foreach ($allstaff as $staff_id => $staff) {
            $new_allstaff[$staff_id] = $staff['post_title'];
        }
        $map[-1] = $new_allstaff;
        return $map;
    };
    $ns->get_locations_services_map = function () {
        global $birchschedule;
        return $birchschedule->model->get_locations_services_map();
    };
    $ns->get_services_staff_map = function () {
        global $birchschedule;
        return $birchschedule->model->get_services_staff_map();
    };
    $ns->get_locations_listing_order = function () {
        global $birchschedule;
        $locations = $birchschedule->model->get_locations_listing_order();
        $locations = array_merge(array(-1), $locations);
        return $locations;
    };
    $ns->get_staff_listing_order = function () {
        global $birchschedule;
        return $birchschedule->model->get_staff_listing_order();
    };
    $ns->get_services_listing_order = function () {
        global $birchschedule;
        return $birchschedule->model->get_services_listing_order();
    };
    $ns->get_services_prices_map = function () {
        global $birchschedule;
        return $birchschedule->model->get_services_prices_map();
    };
    $ns->get_services_duration_map = function () {
        global $birchschedule;
        return $birchschedule->model->get_services_duration_map();
    };
    $ns->ajax_query_appointments = function () use($ns) {
        global $birchschedule, $birchpress;
        $start = $_GET['birs_time_start'];
        $start = $birchpress->util->get_wp_datetime($start)->format('U');
        $end = $_GET['birs_time_end'];
        $end = $birchpress->util->get_wp_datetime($end)->format('U');
        $location_id = $_GET['birs_location_id'];
        $staff_id = $_GET['birs_staff_id'];
        $apmts = $birchschedule->view->calendar->query_appointments($start, $end, $location_id, $staff_id);
        ?>
        <div id="birs_response">
<?php 
        echo json_encode($apmts);
        ?>
        </div>
<?php 
        exit;
    };
    $ns->render_admin_page = function () use($ns) {
        global $birchschedule;
        $birchschedule->view->show_notice();
        $ns->render_calendar_scene();
    };
    $ns->render_calendar_scene = function () {
        ?>
        <div class="birs_scene" id="birs_calendar_scene">
            <h2 style="display:none;"></h2>
            <div id="birs_calendar_menu">
                <div class="birs_group">
                    <button type="button" class="button"
                        id="birs_add_appointment">
                        <?php 
        _e('New Appointment', 'birchschedule');
        ?>
                    </button>
                    <button type="button" class="button"
                        id="birs_calendar_refresh">
                           <span class="dashicons dashicons-update"></span>
                    </button>
                </div>
                <div class="birs_group">
                    <button type="button" class="button"
                        id="birs_calendar_today">
                        <?php 
        _e('Today', 'birchschedule');
        ?>
                    </button>
                </div>
                <div class="birs_group birs_radio_group">
                    <label>
                        <input type="radio" name="birs_calendar_view_choice" value="month">
                        <?php 
        _e('Month', 'birchschedule');
        ?>
                    </label>
                    <label>
                        <input type="radio" name="birs_calendar_view_choice" value="agendaWeek">
                        <?php 
        _e('Week', 'birchschedule');
        ?>
                    </label>
                    <label>
                        <input type="radio" name="birs_calendar_view_choice" value="agendaDay">
                        <?php 
        _e('Day', 'birchschedule');
        ?>
                    </label>
                    <input type="hidden" name="birs_calendar_view" />
                    <input type="hidden" name="birs_calendar_current_date" />
                </div>
                <div class="birs_group">
                    <select id="birs_calendar_location">
                    </select>
                    <select id="birs_calendar_staff">
                    </select>
                </div>
                <div style="clear: both;"></div>
            </div>
            <div id="birs_calendar_header">
                <table class="fc-header" style="width:100%">
                    <tbody>
                        <tr>
                            <td class="fc-header-left">
                                <button type="button" class="button">
                                    <span class="dashicons dashicons-arrow-left-alt2"></span>
                                </button>
                            </td>
                            <td class="fc-header-center">
                                <span class="fc-header-title">
                                    <h2></h2>
                                </span>
                            </td>
                            <td class="fc-header-right">
                                <button type="button" class="button">
                                    <span class="dashicons dashicons-arrow-right-alt2"></span>
                                </button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div id="birs_calendar">
            </div>
        </div>
<?php 
    };
});
Esempio n. 15
0
birch_ns('birchschedule.view.locations', function ($ns) {
    global $birchschedule;
    $ns->init = function () use($ns, $birchschedule) {
        add_action('admin_init', array($ns, 'wp_admin_init'));
        add_action('init', array($ns, 'wp_init'));
        $birchschedule->view->load_page_edit->when($ns->is_post_type_location, $ns->load_page_edit);
        $birchschedule->view->enqueue_scripts_edit->when($ns->is_post_type_location, $ns->enqueue_scripts_edit);
        $birchschedule->view->enqueue_scripts_list->when($ns->is_post_type_location, $ns->enqueue_scripts_list);
        $birchschedule->view->save_post->when($ns->is_post_type_location, $ns->save_post);
    };
    $ns->wp_init = function () use($ns) {
        $ns->register_post_type();
    };
    $ns->wp_admin_init = function () use($ns) {
        add_filter('manage_edit-birs_location_columns', array($ns, 'get_edit_columns'));
        add_action('manage_birs_location_posts_custom_column', array($ns, 'render_custom_columns'), 2);
    };
    $ns->is_post_type_location = function ($post) {
        return $post['post_type'] === 'birs_location';
    };
    $ns->get_register_options = function () {
        return array('labels' => array('name' => __('Locations', 'birchschedule'), 'singular_name' => __('Location', 'birchschedule'), 'add_new' => __('Add Location', 'birchschedule'), 'add_new_item' => __('Add New Location', 'birchschedule'), 'edit' => __('Edit', 'birchschedule'), 'edit_item' => __('Edit Location', 'birchschedule'), 'new_item' => __('New Location', 'birchschedule'), 'view' => __('View Location', 'birchschedule'), 'view_item' => __('View Location', 'birchschedule'), 'search_items' => __('Search Locations', 'birchschedule'), 'not_found' => __('No Locations found', 'birchschedule'), 'not_found_in_trash' => __('No Locations found in trash', 'birchschedule'), 'parent' => __('Parent Location', 'birchschedule')), 'description' => __('This is where locations are stored.', 'birchschedule'), 'public' => false, 'show_ui' => true, 'capability_type' => 'birs_location', 'map_meta_cap' => true, 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_in_menu' => 'edit.php?post_type=birs_appointment', 'hierarchical' => false, 'show_in_nav_menus' => false, 'rewrite' => false, 'query_var' => true, 'supports' => array('title'), 'has_archive' => false);
    };
    $ns->register_post_type = function () use($ns) {
        register_post_type('birs_location', $ns->get_register_options());
    };
    $ns->get_edit_columns = function ($columns) {
        $columns = array();
        $columns["cb"] = "<input type=\"checkbox\" />";
        $columns["title"] = __("Location Name", 'birchschedule');
        $columns["birs_location_address"] = __("Address", 'birchschedule');
        $columns["birs_location_city"] = __("City", 'birchschedule');
        $columns["birs_location_state"] = __("State/Province", 'birchschedule');
        return $columns;
    };
    $ns->get_updated_messages = function ($messages) {
        global $post, $post_ID;
        $messages['birs_location'] = array(0 => '', 1 => __('Location updated.', 'birchschedule'), 2 => __('Custom field updated.', 'birchschedule'), 3 => __('Custom field deleted.', 'birchschedule'), 4 => __('Location updated.', 'birchschedule'), 5 => isset($_GET['revision']) ? sprintf(__('Location restored to revision from %s', 'birchschedule'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => __('Location updated.', 'birchschedule'), 7 => __('Location saved.', 'birchschedule'), 8 => __('Location submitted.', 'birchschedule'), 9 => sprintf(__('Location scheduled for: <strong>%1$s</strong>.', 'birchschedule'), date_i18n('M j, Y @ G:i', strtotime($post->post_date))), 10 => __('Location draft updated.', 'birchschedule'));
        return $messages;
    };
    $ns->render_custom_columns = function ($column) {
        global $post, $birchpress;
        if ($column === 'birs_location_address') {
            $address1 = get_post_meta($post->ID, '_birs_location_address1', true);
            $address2 = get_post_meta($post->ID, '_birs_location_address2', true);
            $value = $address1 . '<br>' . $address2;
        } else {
            $value = get_post_meta($post->ID, '_' . $column, true);
        }
        if ($column === 'birs_location_state') {
            $states = $birchpress->util->get_us_states();
            if (isset($states[$value])) {
                $value = $states[$value];
            } else {
                $value = '';
            }
        }
        echo $value;
    };
    $ns->load_page_edit = function ($arg) use($ns) {
        add_action('add_meta_boxes', array($ns, 'add_meta_boxes'));
        add_filter('post_updated_messages', array($ns, 'get_updated_messages'));
    };
    $ns->enqueue_scripts_edit = function ($arg) use($ns) {
        global $birchschedule;
        $birchschedule->view->register_3rd_scripts();
        $birchschedule->view->register_3rd_styles();
        $birchschedule->view->enqueue_scripts(array('birchschedule_view_locations_edit', 'birchschedule_model', 'birchschedule_view_admincommon', 'birchschedule_view'));
        $birchschedule->view->enqueue_styles(array('birchschedule_admincommon', 'birchschedule_locations_edit'));
    };
    $ns->enqueue_scripts_list = function ($arg) use($ns, $birchschedule) {
        $birchschedule->view->enqueue_styles('birchschedule_admincommon');
    };
    $ns->save_post = function ($post) use($ns) {
        global $birchschedule;
        $config = array('meta_keys' => array('_birs_location_phone', '_birs_location_address1', '_birs_location_address2', '_birs_location_city', '_birs_location_state', '_birs_location_country', '_birs_location_zip'), 'base_keys' => array());
        $post_data = $birchschedule->view->merge_request($post, $config, $_REQUEST);
        $birchschedule->model->save($post_data, $config);
    };
    $ns->add_meta_boxes = function () use($ns) {
        remove_meta_box('slugdiv', 'birs_location', 'normal');
        remove_meta_box('postcustom', 'birs_location', 'normal');
        add_meta_box('birchschedule-location-info', __('Location Details', 'birchschedule'), array($ns, 'render_location_info'), 'birs_location', 'normal', 'high');
    };
    $ns->render_location_info = function ($post) use($ns) {
        global $birchpress, $birchschedule;
        $post_id = $post->ID;
        $addresss1 = get_post_meta($post_id, '_birs_location_address1', true);
        $addresss2 = get_post_meta($post_id, '_birs_location_address2', true);
        $phone = get_post_meta($post_id, '_birs_location_phone', true);
        $city = get_post_meta($post_id, '_birs_location_city', true);
        $zip = get_post_meta($post_id, '_birs_location_zip', true);
        $state = get_post_meta($post_id, '_birs_location_state', true);
        $country = get_post_meta($post_id, '_birs_location_country', true);
        if (!$country) {
            $country = $birchschedule->model->get_default_country();
        }
        $countries = $birchpress->util->get_countries();
        $all_states = $birchpress->util->get_states();
        if (isset($all_states[$country])) {
            $select_display = "";
            $text_display = "display:none;";
            $states = $all_states[$country];
        } else {
            $select_display = "display:none;";
            $text_display = "";
            $states = array();
        }
        ?>
        <div class="panel-wrap birchschedule">
            <table class="form-table">
                <tr class="form-field">
                    <th><label><?php 
        _e('Phone Number', 'birchschedule');
        ?>
 </label>
                    </th>
                    <td><input type="text" name="birs_location_phone"
                               id="birs_location_phone" value="<?php 
        echo esc_attr($phone);
        ?>
">
                    </td>
                </tr>
                <tr class="form-field">
                    <th><label><?php 
        _e('Address', 'birchschedule');
        ?>
 </label>
                    </th>
                    <td><input type="text" name="birs_location_address1"
                               id="birs_location_address1"
                               value="<?php 
        echo esc_attr($addresss1);
        ?>
"> <br> <input type="text"
                               name="birs_location_address2" id="birs_location_address2"
                               value="<?php 
        echo esc_attr($addresss2);
        ?>
">
                    </td>
                </tr>
                <tr class="form-field">
                    <th><label><?php 
        _e('City', 'birchschedule');
        ?>
 </label>
                    </th>
                    <td><input type="text" name="birs_location_city"
                               id="birs_location_city" value="<?php 
        echo esc_attr($city);
        ?>
">
                    </td>
                </tr>
                <tr class="form-field">
                    <th><label><?php 
        _e('State/Province', 'birchschedule');
        ?>
 </label>
                    </th>
                    <td>
                        <select name="birs_location_state_select" id="birs_location_state_select" style="<?php 
        echo $select_display;
        ?>
">
                            <?php 
        $birchpress->util->render_html_options($states, $state);
        ?>
                        </select>
                        <input type="text" name="birs_location_state" id="birs_location_state" value="<?php 
        echo esc_attr($state);
        ?>
" style="<?php 
        echo $text_display;
        ?>
">
                    </td>
                </tr>
                <tr class="form-field">
                    <th><label><?php 
        _e('Country', 'birchschedule');
        ?>
</label></th>
                    <td>
                        <select name="birs_location_country" id="birs_location_country">
                            <?php 
        $birchpress->util->render_html_options($countries, $country);
        ?>
                        </select>
                    </td>
                </tr>
                <tr class="form-field">
                    <th><label><?php 
        _e('Zip Code', 'birchschedule');
        ?>
 </label>
                    </th>
                    <td><input type="text" name="birs_location_zip"
                               id="birs_location_zip" value="<?php 
        echo esc_attr($zip);
        ?>
">
                    </td>
                </tr>
            </table>
        </div>
<?php 
    };
});
Esempio n. 16
0
birch_ns('birchschedule.model', function ($ns) {
    global $birchschedule;
    $ns->init = function () use($ns) {
        add_filter('birchbase_db_get_essential_post_columns', array($ns, 'add_more_essential_columns'), 20, 2);
    };
    $ns->save = function ($model, $config = false) {
        global $birchschedule, $birchpress;
        $model = $birchschedule->model->pre_save($model, $config);
        return $birchpress->db->save($model, $config);
    };
    $ns->pre_save = function ($model, $config) {
        return $model;
    };
    $ns->post_get = function ($model) {
        return $model;
    };
    $ns->is_valid_id = function ($id) {
        global $birchpress;
        return $birchpress->db->is_valid_id($id);
    };
    $ns->add_more_essential_columns = function ($columns, $post_type) {
        if ($post_type == 'birs_staff') {
            $columns[] = 'post_title';
            $columns[] = 'post_content';
        }
        if ($post_type == 'birs_service') {
            $columns[] = 'post_title';
            $columns[] = 'post_content';
        }
        return $columns;
    };
    $ns->get_service_pre_payment_fee = function ($service_id) {
        global $birchschedule;
        if (!$birchschedule->model->is_valid_id($service_id)) {
            return 0;
        }
        $service = $birchschedule->model->get($service_id, array('base_keys' => array(), 'meta_keys' => array('_birs_service_pre_payment_fee', '_birs_service_price')));
        $is_prepayment_enabled = $birchschedule->model->is_prepayment_enabled($service_id);
        if (!$is_prepayment_enabled) {
            return 0;
        }
        $service_pre_payment_fee = $service['_birs_service_pre_payment_fee'];
        if ($service_pre_payment_fee) {
            if ($service_pre_payment_fee['pre_payment_type'] == 'fixed') {
                return floatval($service_pre_payment_fee['fixed']);
            } else {
                if ($service_pre_payment_fee['pre_payment_type'] == 'percent') {
                    return $service_pre_payment_fee['percent'] * 0.01 * $service['_birs_service_price'];
                } else {
                    return 0;
                }
            }
        } else {
            return 0;
        }
    };
    $ns->get_service_padding = function ($service_id, $type) {
        global $birchschedule;
        birch_assert($birchschedule->model->is_valid_id($service_id));
        birch_assert($type === 'before' || $type === 'after');
        $service = $birchschedule->model->get($service_id, array('meta_keys' => array('_birs_service_padding', '_birs_service_padding_type'), 'base_keys' => array()));
        $padding_type = $service['_birs_service_padding_type'];
        if ($padding_type === 'before-and-after' || $padding_type === $type) {
            $padding = $service['_birs_service_padding'];
        } else {
            $padding = 0;
        }
        return $padding;
    };
    $ns->get_service_padding_before = function ($service_id) use($ns) {
        return $ns->get_service_padding($service_id, 'before');
    };
    $ns->get_service_padding_after = function ($service_id) use($ns) {
        return $ns->get_service_padding($service_id, 'after');
    };
    $ns->get_service_length = function ($service_id) {
        global $birchschedule;
        birch_assert($birchschedule->model->is_valid_id($service_id));
        $service = $birchschedule->model->get($service_id, array('meta_keys' => array('_birs_service_length', '_birs_service_length_type'), 'base_keys' => array()));
        $length = $service['_birs_service_length'];
        $length_type = $service['_birs_service_length_type'];
        if ($length_type == 'hours') {
            $length = $length * 60;
        }
        return $length;
    };
    $ns->get_service_length_with_paddings = function ($service_id) use($ns) {
        return $ns->get_service_length($service_id) + $ns->get_service_padding_before($service_id) + $ns->get_service_padding_after($service_id);
    };
    $ns->get_service_price = function ($service_id) {
        global $birchschedule;
        $service = $birchschedule->model->get($service_id, array('base_keys' => array(), 'meta_keys' => array('_birs_service_price')));
        if (isset($service['_birs_service_price'])) {
            return floatval($service['_birs_service_price']);
        } else {
            return 0;
        }
    };
    $ns->get_service_timeslot = function ($service_id) {
        return 15;
    };
    $ns->get_service_capacity = function ($service_id) {
        return 1;
    };
    $ns->get = function ($post, $config = false) {
        global $birchpress, $birchschedule;
        $model = $birchpress->db->get($post, $config);
        if ($model) {
            return $birchschedule->model->post_get($model);
        } else {
            return false;
        }
    };
    $ns->delete = function ($id) {
        global $birchpress;
        return $birchpress->db->delete($id);
    };
    $ns->query = function ($criteria, $config = false) use($ns) {
        global $birchschedule, $birchpress;
        if (!is_array($config)) {
            $config = array();
        }
        $config['fn_get'] = array($ns, 'get');
        $models = $birchpress->db->query($criteria, $config);
        return $models;
    };
    $ns->get_staff_schedule_by_location = function ($staff_id, $location_id) {
        global $birchschedule;
        $schedules = array();
        $staff = $birchschedule->model->get($staff_id, array('base_keys' => array(), 'meta_keys' => array('_birs_staff_schedule')));
        $staff_schedule = $staff['_birs_staff_schedule'];
        if (isset($staff_schedule[$location_id])) {
            $location_schedule = $staff_schedule[$location_id];
        } else {
            $location_schedule = array();
        }
        return $location_schedule;
    };
    $ns->get_default_country = function () {
        return 'US';
    };
    $ns->get_default_state = function () {
        return false;
    };
    $ns->update_model_relations = function ($source_id, $source_key, $target_type, $target_key) {
        global $birchschedule;
        $assigned_targets = get_post_meta($source_id, $source_key, true);
        if ($assigned_targets) {
            $assigned_targets = unserialize($assigned_targets);
        }
        if (!$assigned_targets) {
            $assigned_targets = array();
        }
        $targets = $birchschedule->model->query(array('post_type' => $target_type), array('base_keys' => array(), 'meta_keys' => array()));
        foreach ($targets as $target) {
            $assigned_sources = get_post_meta($target['ID'], $target_key, true);
            $assigned_sources = unserialize($assigned_sources);
            if (array_key_exists($target['ID'], $assigned_targets)) {
                $assigned_sources[$source_id] = 'on';
            } else {
                unset($assigned_sources[$source_id]);
            }
            update_post_meta($target['ID'], $target_key, serialize($assigned_sources));
        }
    };
    $ns->is_prepayment_enabled = function ($service_id) {
        global $birchschedule;
        $service = $birchschedule->model->get($service_id, array('meta_keys' => array('_birs_service_enable_pre_payment'), 'base_keys' => array()));
        if (isset($service['_birs_service_enable_pre_payment'])) {
            return $service['_birs_service_enable_pre_payment'];
        } else {
            return false;
        }
    };
    $ns->check_password = function ($email, $password) {
        $user = get_user_by('email', $email);
        if (!$user) {
            return false;
        }
        return wp_check_password($password, $user->user_pass, $user->ID);
    };
    $ns->get_appointment_fields = function () {
        $meta_keys = array('_birs_appointment_service', '_birs_appointment_staff', '_birs_appointment_location', '_birs_appointment_timestamp', '_birs_appointment_uid', '_birs_appointment_duration', '_birs_appointment_padding_before', '_birs_appointment_padding_after', '_birs_appointment_capacity');
        return $meta_keys;
    };
    $ns->get_appointment1on1_fields = function () {
        return array('_birs_appointment_id', '_birs_client_id', '_birs_appointment1on1_payment_status', '_birs_appointment1on1_reminded', '_birs_appointment1on1_price', '_birs_appointment1on1_uid');
    };
    $ns->get_appointment1on1_custom_fields = function () {
        return array('_birs_appointment_notes');
    };
    $ns->get_client_by_email = function ($email, $config) {
        global $birchschedule;
        $criteria = array('post_type' => 'birs_client', 'post_status' => 'publish', 'meta_query' => array(array('key' => '_birs_client_email', 'value' => $email)));
        $clients = $birchschedule->model->query($criteria, $config);
        if (sizeof($clients) > 0) {
            $clients_values = array_values($clients);
            $client = array_shift($clients_values);
            return $client;
        }
        return false;
    };
    $ns->get_client_fields = function () {
        $client_meta_keys = array('_birs_client_name_first', '_birs_client_name_last', '_birs_client_email', '_birs_client_phone', '_birs_client_address1', '_birs_client_address2', '_birs_client_city', '_birs_client_state', '_birs_client_province', '_birs_client_country', '_birs_client_zip');
        return $client_meta_keys;
    };
    $ns->get_payment_fields = function () {
        return array('_birs_payment_appointment', '_birs_payment_client', '_birs_payment_amount', '_birs_payment_type', '_birs_payment_trid', '_birs_payment_notes', '_birs_payment_timestamp', '_birs_payment_currency', '_birs_payment_3rd_txn_id');
    };
    $ns->get_meta_key_label = function ($meta_key) {
        return '';
    };
    $ns->get_services_by_location = function ($location_id) {
        global $birchschedule;
        birch_assert($birchschedule->model->is_valid_id($location_id));
        $location = array('ID' => $location_id);
        $services = $birchschedule->model->query(array('post_type' => 'birs_service', 'order' => 'ASC', 'orderby' => 'title'), array('meta_keys' => array('_birs_service_assigned_locations'), 'base_keys' => array('post_title')));
        $assigned_services = array();
        foreach ($services as $service) {
            $assigned_locations = $service['_birs_service_assigned_locations'];
            if ($assigned_locations) {
                if (isset($assigned_locations[$location_id])) {
                    $assigned_services[$service['ID']] = $service['post_title'];
                }
            }
        }
        return $assigned_services;
    };
    $ns->get_staff_by_location = function ($location_id) {
        global $birchschedule;
        $staff = $birchschedule->model->query(array('post_type' => 'birs_staff', 'order' => 'ASC', 'orderby' => 'title'), array('meta_keys' => array('_birs_staff_schedule'), 'base_keys' => array('post_title')));
        $assigned_staff = array();
        foreach ($staff as $the_staff) {
            $staff_schedule = $the_staff['_birs_staff_schedule'];
            if (isset($staff_schedule[$location_id])) {
                $location_schedule = $staff_schedule[$location_id];
            } else {
                $location_schedule = array();
            }
            if (isset($location_schedule['schedules']) && sizeof($location_schedule['schedules']) > 0) {
                $assigned_staff[$the_staff['ID']] = $the_staff['post_title'];
            }
        }
        return $assigned_staff;
    };
    $ns->get_services_by_staff = function ($staff_id) {
        $assigned_services = get_post_meta($staff_id, '_birs_assigned_services', true);
        $assigned_services = unserialize($assigned_services);
        if ($assigned_services === false) {
            $assigned_services = array();
        }
        return $assigned_services;
    };
    $ns->get_staff_by_service = function ($service_id) {
        $assigned_staff = get_post_meta($service_id, '_birs_assigned_staff', true);
        $assigned_staff = unserialize($assigned_staff);
        if ($assigned_staff === false) {
            $assigned_staff = array();
        }
        return $assigned_staff;
    };
    $ns->get_locations_map = function () {
        global $birchschedule;
        $locations = $birchschedule->model->query(array('post_type' => 'birs_location', 'order' => 'ASC', 'orderby' => 'title'), array('base_keys' => array('post_title'), 'meta_keys' => array()));
        return $locations;
    };
    $ns->get_services_map = function () {
        global $birchschedule;
        $services = $birchschedule->model->query(array('post_type' => 'birs_service', 'order' => 'ASC', 'orderby' => 'title'), array('base_keys' => array('post_title'), 'meta_keys' => array()));
        return $services;
    };
    $ns->get_locations_services_map = function () {
        global $birchschedule;
        $map = array();
        $locations = $birchschedule->model->query(array('post_type' => 'birs_location'), array('base_keys' => array(), 'meta_keys' => array()));
        $services = $birchschedule->model->query(array('post_type' => 'birs_service', 'order' => 'ASC', 'orderby' => 'title'), array('base_keys' => array('post_title'), 'meta_keys' => array()));
        $services_map = array();
        foreach ($services as $service_id => $service) {
            $services_map[$service_id] = $service['post_title'];
        }
        foreach ($locations as $location) {
            $map[$location['ID']] = $services_map;
        }
        return $map;
    };
    $ns->get_locations_staff_map = function () {
        global $birchschedule;
        $map = array();
        $locations = $birchschedule->model->query(array('post_type' => 'birs_location'), array('base_keys' => array(), 'meta_keys' => array()));
        foreach ($locations as $location) {
            $map[$location['ID']] = $birchschedule->model->get_staff_by_location($location['ID']);
        }
        return $map;
    };
    $ns->get_services_staff_map = function () {
        global $birchschedule;
        $map = array();
        $services = $birchschedule->model->query(array('post_type' => 'birs_service'), array('meta_keys' => array('_birs_assigned_staff'), 'base_keys' => array()));
        foreach ($services as $service) {
            $assigned_staff_ids = $service['_birs_assigned_staff'];
            $staff = $birchschedule->model->query(array('post_type' => 'birs_staff'), array('base_keys' => array('post_title'), 'meta_keys' => array()));
            $assigned_staff = array();
            foreach ($staff as $thestaff) {
                if (array_key_exists($thestaff['ID'], $assigned_staff_ids)) {
                    $assigned_staff[$thestaff['ID']] = $thestaff['post_title'];
                }
                $map[$service['ID']] = $assigned_staff;
            }
        }
        return $map;
    };
    $ns->get_services_locations_map = function () {
        global $birchschedule;
        $map = array();
        $services = $birchschedule->model->query(array('post_type' => 'birs_service'), array('base_keys' => array(), 'meta_keys' => array()));
        $locations = $birchschedule->model->query(array('post_type' => 'birs_location', 'order' => 'ASC', 'orderby' => 'title'), array('base_keys' => array('post_title'), 'meta_keys' => array()));
        $locations_map = array();
        foreach ($locations as $location_id => $location) {
            $locations_map[$location_id] = $location['post_title'];
        }
        foreach ($services as $service) {
            $map[$service['ID']] = $locations_map;
        }
        return $map;
    };
    $ns->get_locations_listing_order = function () {
        global $birchschedule;
        $locations = $birchschedule->model->query(array('post_type' => 'birs_location', 'order' => 'ASC', 'orderby' => 'title'), array('base_keys' => array('post_title'), 'meta_keys' => array()));
        $locations_order = array_keys($locations);
        return $locations_order;
    };
    $ns->get_staff_listing_order_type = function () {
        return 'by_title';
    };
    $ns->get_staff_listing_order = function () {
        global $birchschedule;
        $staff = $birchschedule->model->query(array('post_type' => 'birs_staff', 'order' => 'ASC', 'orderby' => 'title'), array('base_keys' => array('post_title'), 'meta_keys' => array()));
        $staff_order = array_keys($staff);
        return $staff_order;
    };
    $ns->get_services_listing_order = function () {
        global $birchschedule;
        $services = $birchschedule->model->query(array('post_type' => 'birs_service', 'order' => 'ASC', 'orderby' => 'title'), array('base_keys' => array('post_title'), 'meta_keys' => array()));
        return array_keys($services);
    };
    $ns->get_services_prices_map = function () use($ns, $birchschedule) {
        $services = $birchschedule->model->query(array('post_type' => 'birs_service'), array('meta_keys' => array('_birs_service_price', '_birs_service_price_type'), 'base_keys' => array()));
        $price_map = array();
        foreach ($services as $service) {
            $pre_payment_fee = $ns->get_service_pre_payment_fee($service['ID']);
            $formatted_pre_payment_fee = $ns->format_price($pre_payment_fee);
            $price = (double) $service['_birs_service_price'];
            $formatted_price = $ns->format_price($price);
            $price_map[$service['ID']] = array('price' => $price, 'formatted_price' => $formatted_price, 'price_type' => $service['_birs_service_price_type'], 'pre_payment_fee' => $pre_payment_fee, 'formatted_pre_payment_fee' => $formatted_pre_payment_fee);
        }
        return $price_map;
    };
    $ns->get_services_duration_map = function () {
        global $birchschedule;
        $services = $birchschedule->model->query(array('post_type' => 'birs_service'), array('meta_keys' => array('_birs_service_length', '_birs_service_length_type'), 'base_keys' => array()));
        $duration_map = array();
        foreach ($services as $service) {
            $duration_map[$service['ID']] = array('duration' => $birchschedule->model->get_service_length($service['ID']));
        }
        return $duration_map;
    };
    $ns->format_price = function ($price) use($ns) {
        $currency_code = $ns->get_currency_code();
        $formatted_number = $ns->number_format($price);
        $formatted_price = $ns->apply_currency_symbol($formatted_number, $currency_code);
        return $formatted_price;
    };
    $ns->apply_currency_symbol = function ($val, $curreny_code) {
        global $birchpress;
        $currencies = $birchpress->util->get_currencies();
        $currency = $currencies[$curreny_code];
        $symbol = $currency['symbol_right'];
        if ('' === $symbol) {
            $symbol = $currency['symbol_left'];
        }
        if ($currency['symbol_right']) {
            $val .= $symbol;
        } else {
            $val = $symbol . $val;
        }
        return $val;
    };
    $ns->get_currency_code = function () {
        return 'USD';
    };
    $ns->get_cut_off_time = function ($staff_id = -1, $location_id = -1, $service_id = -1) {
        return 1;
    };
    $ns->get_future_time = function () {
        return 360;
    };
    $ns->get_time_before_cancel = function () {
        return 24;
    };
    $ns->get_time_before_reschedule = function () {
        return 24;
    };
    $ns->get_staff_daysoff = function ($staff_id) {
        global $birchschedule;
        $staff = $birchschedule->model->get($staff_id, array('base_keys' => array(), 'meta_keys' => array('_birs_staff_dayoffs')));
        $daysoff = json_encode(array());
        if ($staff['_birs_staff_dayoffs']) {
            $daysoff = $staff['_birs_staff_dayoffs'];
        }
        return $daysoff;
    };
    $ns->get_all_daysoff = function () {
        global $birchschedule;
        $staff = $birchschedule->model->query(array('post_type' => 'birs_staff'), array('meta_keys' => array(), 'base_keys' => array()));
        $dayoffs = array();
        foreach (array_values($staff) as $thestaff) {
            $dayoffs[$thestaff['ID']] = $birchschedule->model->get_staff_daysoff($thestaff['ID']);
        }
        return $dayoffs;
    };
    $ns->get_user_by_staff = function ($staff_id) {
        global $birchschedule;
        $staff = $birchschedule->model->get($staff_id, array('base_keys' => array(), 'meta_keys' => array('_birs_staff_email')));
        if ($staff) {
            $user = WP_User::get_data_by('email', $staff['_birs_staff_email']);
            return $user;
        } else {
            return false;
        }
    };
    $ns->get_staff_by_user = function ($user, $config = array()) {
        global $birchschedule;
        $email = $user->user_email;
        $staff = $birchschedule->model->query(array('post_type' => 'birs_staff', 'meta_query' => array(array('key' => '_birs_staff_email', 'value' => $email))), $config);
        if ($staff) {
            return array_values($staff);
        } else {
            return false;
        }
    };
    $ns->merge_data = function ($model, $config, $data) {
        if (!is_array($config)) {
            $config = array();
        }
        if (!isset($config['base_keys'])) {
            $config['base_keys'] = array();
        }
        if (!isset($config['meta_keys'])) {
            $config['meta_keys'] = array();
        }
        foreach ($config['base_keys'] as $key) {
            if (isset($data[$key])) {
                $model[$key] = $data[$key];
            } else {
                $model[$key] = null;
            }
        }
        foreach ($config['meta_keys'] as $key) {
            $req_key = substr($key, 1);
            if (isset($data[$key])) {
                $model[$key] = $data[$key];
            } else {
                if (isset($data[$req_key])) {
                    $model[$key] = $data[$req_key];
                } else {
                    $model[$key] = null;
                }
            }
        }
        return $model;
    };
    $ns->number_format = function ($number, $currency_code = false) use($ns) {
        global $birchpress;
        if (!$currency_code) {
            $currency_code = $ns->get_currency_code();
        }
        $currencies = $birchpress->util->get_currencies();
        $currency = $currencies[$currency_code];
        return number_format((double) $number, $currency['decimal_places'], $currency['decimal_point'], $currency['thousands_point']);
    };
});
Esempio n. 17
0
birch_ns('birchpress.db', function ($ns) {
    birch_defn($ns, 'get_base_keys', function ($keys) {
        global $birchpress;
        $base_keys = array();
        foreach ($keys as $key) {
            if (!$birchpress->util->starts_with($key, '_')) {
                $base_keys[] = $key;
            }
        }
        return $base_keys;
    });
    birch_defn($ns, 'get_meta_keys', function ($keys) {
        global $birchpress;
        $meta_keys = array();
        foreach ($keys as $key) {
            if ($birchpress->util->starts_with($key, '_')) {
                $meta_keys[] = $key;
            }
        }
        return $meta_keys;
    });
    birch_defn($ns, '_preprocess_config', function ($config) use($ns) {
        if (!is_array($config)) {
            $config = array();
        }
        if (!isset($config['base_keys'])) {
            $config['base_keys'] = array();
        }
        if (!isset($config['meta_keys'])) {
            $config['meta_keys'] = array();
        }
        if (isset($config['keys'])) {
            $keys = $config['keys'];
            $config['base_keys'] = array_merge($config['base_keys'], $ns->get_base_keys($keys));
            $config['meta_keys'] = array_merge($config['meta_keys'], $ns->get_meta_keys($keys));
            unset($config['keys']);
        }
        return $config;
    });
    birch_defn($ns, 'get', function ($post, $config) use($ns) {
        global $birchpress;
        $config = $ns->_preprocess_config($config);
        if (is_a($post, 'WP_Post')) {
            $id = $post->ID;
        } else {
            $id = $post;
            if (!$ns->is_valid_id($id)) {
                return false;
            }
            $post = get_post($id);
            if ($post === null) {
                return false;
            }
        }
        $model = array('ID' => $id);
        $base_keys = array_merge(array('post_type'), $config['base_keys']);
        foreach ($base_keys as $key) {
            if (isset($post->{$key})) {
                $model[$key] = $post->{$key};
            }
        }
        $meta_keys = $config['meta_keys'];
        foreach ($meta_keys as $key) {
            $model[$key] = get_post_meta($id, $key, true);
        }
        return $model;
    });
    birch_defn($ns, 'is_valid_id', function ($id) use($ns) {
        return (string) (int) $id == $id && $id > 0;
    });
    birch_defn($ns, 'delete', function ($id) use($ns) {
        birch_assert($ns->is_valid_id($id));
        return wp_delete_post($id);
    });
    birch_defn($ns, 'save', function ($model, $config) use($ns) {
        birch_assert(is_array($model), 'Model should be an array.');
        birch_assert(isset($model['post_type']), 'Model should have post_type field.');
        global $birchpress;
        $config = $ns->_preprocess_config($config);
        $base_keys = $config['base_keys'];
        $meta_keys = $config['meta_keys'];
        $id = 0;
        if (isset($model['ID'])) {
            if ($ns->is_valid_id($model['ID'])) {
                $id = $model['ID'];
            } else {
                unset($model['ID']);
            }
        }
        $model_fields = array_keys($model);
        foreach ($model_fields as $field) {
            if (!in_array($field, $base_keys) && !in_array($field, $meta_keys) && $field != 'ID' && $field != 'post_type') {
                unset($model[$field]);
            }
        }
        if ($base_keys || !$id) {
            if (!isset($model['post_status'])) {
                $model['post_status'] = 'publish';
            }
            $id = wp_insert_post($model);
        }
        if (!$id) {
            return false;
        }
        foreach ($meta_keys as $key) {
            if (isset($model[$key])) {
                update_post_meta($id, $key, $model[$key]);
            }
        }
        return $id;
    });
    birch_defn($ns, 'get_post_columns', function () {
        return array('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'guid', 'menu_order', 'post_type', 'post_mime_type', 'comment_count');
    });
    birch_defn($ns, 'get_essential_post_columns', function ($post_type) {
        return array('post_author', 'post_date_gmt', 'post_status', 'post_modified_gmt', 'post_type');
    });
    birch_defn($ns, 'query', function ($criteria, $config = array()) use($ns) {
        $config = $ns->_preprocess_config($config);
        $criteria = array_merge(array('nopaging' => true, 'post_status' => 'publish', 'cache_results' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false), $criteria);
        if ($criteria['nopaging']) {
            $criteria['no_found_rows'] = true;
        }
        if (isset($config['fn_get'])) {
            $fn_get = $config['fn_get'];
            unset($config['fn_get']);
        } else {
            $fn_get = array($ns, 'get');
        }
        $fn_filter_posts_fields = function ($fields, $query) use($ns, &$config) {
            global $wpdb;
            $new_fields = "{$wpdb->posts}.ID";
            $post_columns = $ns->get_post_columns();
            foreach ($config['base_keys'] as $key) {
                if (in_array($key, $post_columns)) {
                    $new_fields .= ", {$wpdb->posts}.{$key}";
                }
            }
            return $new_fields;
        };
        $query = new WP_Query();
        $models = array();
        if ($config['base_keys'] || $config['meta_keys']) {
            if (isset($criteria['post_type'])) {
                $post_type = $criteria['post_type'];
            } else {
                $post_type = 'any';
            }
            $essential_keys = $ns->get_essential_post_columns($post_type);
            if ($criteria['cache_results']) {
                $config['base_keys'] = array_merge($essential_keys, $config['base_keys']);
            } else {
                $config['base_keys'] = array_merge(array('post_type'), $config['base_keys']);
            }
            $criteria['fields'] = 'custom';
            add_filter('posts_fields', $fn_filter_posts_fields, 20, 2);
            $posts = $query->query($criteria);
            remove_filter('posts_fields', $fn_filter_posts_fields, 20, 2);
            foreach ($posts as $post) {
                $model = call_user_func($fn_get, $post, $config);
                $models[$post->ID] = $model;
            }
        } else {
            $criteria['fields'] = 'ids';
            $post_ids = $query->query($criteria);
            foreach ($post_ids as $post_id) {
                $models[$post_id] = array('ID' => $post_id);
            }
        }
        return $models;
    });
});
Esempio n. 18
0
<?php

birch_ns('birchschedule.view.appointments', function ($ns) {
    birch_defn($ns, 'init', function () use($ns) {
        add_action('admin_init', array($ns, 'wp_admin_init'));
        add_action('init', array($ns, 'wp_init'));
    });
    birch_defn($ns, 'wp_init', function () use($ns) {
        $ns->register_post_type();
    });
    birch_defn($ns, 'wp_admin_init', function () use($ns) {
        add_filter('post_updated_messages', array($ns, 'get_updated_messages'));
    });
    birch_defn($ns, 'register_post_type', function () use($ns) {
        register_post_type('birs_appointment', array('labels' => array('name' => __('Appointments', 'birchschedule'), 'singular_name' => __('Appointment', 'birchschedule'), 'add_new' => __('New Appointment', 'birchschedule'), 'add_new_item' => __('New Appointment', 'birchschedule'), 'edit' => __('Edit', 'birchschedule'), 'edit_item' => __('Edit Appointment', 'birchschedule'), 'new_item' => __('New Appointment', 'birchschedule'), 'view' => __('View Appointment', 'birchschedule'), 'view_item' => __('View Appointment', 'birchschedule'), 'search_items' => __('Search Appointments', 'birchschedule'), 'not_found' => __('No Appointments found', 'birchschedule'), 'not_found_in_trash' => __('No Appointments found in trash', 'birchschedule'), 'parent' => __('Parent Appointment', 'birchschedule')), 'description' => __('This is where appointments are stored.', 'birchschedule'), 'public' => false, 'show_ui' => true, 'menu_icon' => 'dashicons-calendar', 'capability_type' => 'birs_appointment', 'map_meta_cap' => true, 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_in_menu' => true, 'hierarchical' => false, 'show_in_nav_menus' => false, 'rewrite' => false, 'query_var' => true, 'supports' => array(''), 'has_archive' => false));
        register_post_type('birs_appointment1on1', array('labels' => array('name' => __('One-on-one appointments', 'birchschedule'), 'singular_name' => __('One-on-one appointment', 'birchschedule'), 'add_new' => __('New One-on-one Appointment', 'birchschedule'), 'add_new_item' => __('New One-on-one Appointment', 'birchschedule'), 'edit' => __('Edit', 'birchschedule'), 'edit_item' => __('Edit One-on-one Appointment', 'birchschedule'), 'new_item' => __('New One-on-one Appointment', 'birchschedule'), 'view' => __('View One-on-one Appointment', 'birchschedule'), 'view_item' => __('View One-on-one Appointment', 'birchschedule'), 'search_items' => __('Search One-on-one Appointments', 'birchschedule'), 'not_found' => __('No One-on-one Appointments found', 'birchschedule'), 'not_found_in_trash' => __('No One-on-one Appointments found in trash', 'birchschedule'), 'parent' => __('Parent One-on-one Appointment', 'birchschedule')), 'description' => __('This is where one-on-one appointments are stored.', 'birchschedule'), 'public' => false, 'show_ui' => false, 'menu_icon' => 'dashicons-calendar', 'capability_type' => 'birs_appointment', 'map_meta_cap' => true, 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_in_menu' => false, 'hierarchical' => false, 'show_in_nav_menus' => false, 'rewrite' => false, 'query_var' => true, 'supports' => array(''), 'has_archive' => false));
    });
    birch_defn($ns, 'get_updated_messages', function ($messages) {
        global $post, $post_ID;
        $messages['birs_appointment'] = array(0 => '', 1 => __('Appointment updated.', 'birchschedule'), 2 => __('Custom field updated.', 'birchschedule'), 3 => __('Custom field deleted.', 'birchschedule'), 4 => __('Appointment updated.', 'birchschedule'), 5 => isset($_GET['revision']) ? sprintf(__('Appointment restored to revision from %s', 'birchschedule'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => __('Appointment updated.', 'birchschedule'), 7 => __('Appointment saved.', 'birchschedule'), 8 => __('Appointment submitted.', 'birchschedule'), 9 => sprintf(__('Appointment scheduled for: <strong>%1$s</strong>.', 'birchschedule'), date_i18n('M j, Y @ G:i', strtotime($post->post_date))), 10 => __('Appointment draft updated.', 'birchschedule'));
        return $messages;
    });
});
Esempio n. 19
0
birch_ns('birchschedule.model.cpt.staff', function ($ns) {
    global $birchschedule;
    birch_defn($ns, 'init', function () use($ns, $birchschedule) {
        birch_defmethod($birchschedule->model, 'pre_save', 'birs_staff', $ns->pre_save);
        birch_defmethod($birchschedule->model, 'post_get', 'birs_staff', $ns->post_get);
    });
    birch_defn($ns, 'pre_save', function ($staff, $config) {
        birch_assert(is_array($staff) && isset($staff['post_type']));
        if (isset($staff['_birs_assigned_services'])) {
            $staff['_birs_assigned_services'] = serialize($staff['_birs_assigned_services']);
        }
        if (isset($staff['_birs_staff_schedule'])) {
            $staff['_birs_staff_schedule'] = serialize($staff['_birs_staff_schedule']);
        }
        return $staff;
    });
    birch_defn($ns, 'post_get', function ($staff) {
        birch_assert(is_array($staff) && isset($staff['post_type']));
        if (isset($staff['post_title'])) {
            $staff['_birs_staff_name'] = $staff['post_title'];
        }
        if (isset($staff['_birs_assigned_services'])) {
            $assigned_services = $staff['_birs_assigned_services'];
            $assigned_services = unserialize($assigned_services);
            $assigned_services = $assigned_services ? $assigned_services : array();
            $staff['_birs_assigned_services'] = $assigned_services;
        }
        if (isset($staff['_birs_staff_schedule'])) {
            $schedule = $staff['_birs_staff_schedule'];
            if (!isset($schedule)) {
                $schedule = array();
            } else {
                $schedule = unserialize($schedule);
            }
            $schedule = $schedule ? $schedule : array();
            $staff['_birs_staff_schedule'] = $schedule;
        }
        if (isset($staff['post_content'])) {
            $staff['_birs_staff_description'] = $staff['post_content'];
        }
        return $staff;
    });
});
Esempio n. 20
0
<?php

birch_ns('birchschedule.model.cpt.location', function ($ns) {
    global $birchschedule;
    $ns->init = function () use($ns, $birchschedule) {
        $birchschedule->model->pre_save->when($ns->is_model_location, $ns->pre_save);
        $birchschedule->model->post_get->when($ns->is_model_location, $ns->post_get);
    };
    $ns->is_model_location = function ($model) {
        return $model['post_type'] === 'birs_location';
    };
    $ns->pre_save = function ($location, $config) {
        birch_assert(is_array($location) && isset($location['post_type']));
        return $location;
    };
    $ns->post_get = function ($location) {
        birch_assert(is_array($location) && isset($location['post_type']));
        if (isset($location['post_title'])) {
            $location['_birs_location_name'] = $location['post_title'];
        }
        if (isset($location['post_content'])) {
            $location['_birs_location_description'] = $location['post_content'];
        }
        return $location;
    };
});
Esempio n. 21
0
birch_ns('birchschedule.view', function ($ns) {
    $scripts_data = array();
    $enqueued_scripts = array();
    $localized_scripts = array();
    $printed_scripts = array();
    $_ns_data = new stdClass();
    $ns->init = function () use($ns, $_ns_data) {
        global $birchschedule;
        $_ns_data->page_hooks = array();
        add_action('init', array($ns, 'wp_init'));
        add_action('admin_init', array($ns, 'wp_admin_init'));
        add_action('admin_menu', array($ns, 'create_admin_menus'));
        add_action('custom_menu_order', array($ns, 'if_change_custom_menu_order'), 100);
        add_action('menu_order', array($ns, 'change_admin_menu_order'), 100);
        add_action('plugins_loaded', array($ns, 'load_i18n'));
    };
    $ns->wp_init = function () use($ns) {
        global $birchpress;
        if (!defined('DOING_AJAX')) {
            $birchpress->view->register_core_scripts();
            $ns->register_common_scripts();
            $ns->register_common_scripts_data_fns();
            $ns->register_3rd_styles();
            $ns->register_common_styles();
            add_action('wp_print_scripts', array($ns, 'localize_scripts'));
            if (is_admin()) {
                add_action('admin_print_footer_scripts', array($ns, 'localize_scripts'), 9);
                add_action('admin_print_footer_scripts', array($ns, 'post_print_scripts'), 11);
            } else {
                add_action('wp_print_footer_scripts', array($ns, 'localize_scripts'), 9);
                add_action('wp_print_footer_scripts', array($ns, 'post_print_scripts'), 11);
            }
        }
    };
    $ns->wp_admin_init = function () use($ns) {
        add_action('load-post.php', array($ns, 'on_load_post'));
        add_action('load-post-new.php', array($ns, 'on_load_post_new'));
        add_action('admin_enqueue_scripts', array($ns, 'on_admin_enqueue_scripts'));
        add_action('save_post', array($ns, 'on_save_post'), 10, 2);
        add_filter('wp_insert_post_data', array($ns, 'on_wp_insert_post_data'), 10, 2);
    };
    $ns->localize_scripts = function () use($ns, &$enqueued_scripts, &$printed_scripts) {
        global $wp_scripts;
        $wp_scripts->all_deps($enqueued_scripts, true);
        $all_scripts = $wp_scripts->to_do;
        foreach ($all_scripts as $script) {
            $ns->localize_script($script);
        }
        $printed_scripts = $all_scripts;
    };
    $ns->localize_script = function ($script) use($ns, &$scripts_data, &$localized_scripts) {
        if (isset($scripts_data[$script]) && !in_array($script, $localized_scripts)) {
            foreach ($scripts_data[$script] as $data_name => $data_fn) {
                $data = call_user_func($data_fn);
                wp_localize_script($script, $data_name, $data);
            }
            $localized_scripts[] = $script;
            $localized_scripts = array_unique($localized_scripts);
        }
    };
    $ns->post_print_scripts = function () use($ns, &$printed_scripts) {
        foreach ($printed_scripts as $script) {
            $ns->post_print_script($script);
        }
    };
    $ns->post_print_script = function ($script) {
    };
    $ns->on_load_post = function () use($ns) {
        $post_type = $ns->get_current_post_type();
        $ns->load_post_edit(array('post_type' => $post_type));
        $ns->load_page_edit(array('post_type' => $post_type));
    };
    $ns->on_load_post_new = function () use($ns) {
        $post_type = $ns->get_current_post_type();
        $ns->load_post_new(array('post_type' => $post_type));
        $ns->load_page_edit(array('post_type' => $post_type));
    };
    $ns->on_admin_enqueue_scripts = function ($hook) use($ns) {
        $post_type = $ns->get_current_post_type();
        if ($hook == 'post-new.php') {
            $ns->enqueue_scripts_post_new(array('post_type' => $post_type));
            $ns->enqueue_scripts_edit(array('post_type' => $post_type));
        }
        if ($hook == 'post.php') {
            $ns->enqueue_scripts_post_edit(array('post_type' => $post_type));
            $ns->enqueue_scripts_edit(array('post_type' => $post_type));
        }
        if ($hook == 'edit.php' && isset($_GET['post_type'])) {
            $post_type = $_GET['post_type'];
            $ns->enqueue_scripts_list(array('post_type' => $post_type));
        }
    };
    $ns->on_save_post = function ($post_id, $post) use($ns) {
        if (!isset($_POST['action']) || $_POST['action'] !== 'editpost') {
            return;
        }
        if (empty($post_id) || empty($post) || empty($_POST)) {
            return;
        }
        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return;
        }
        if (is_int(wp_is_post_revision($post))) {
            return;
        }
        if (is_int(wp_is_post_autosave($post))) {
            return;
        }
        $post_a = (array) $post;
        $ns->save_post($post_a);
    };
    $ns->on_wp_insert_post_data = function ($post_data, $post_attr) use($ns) {
        if (!isset($_POST['action']) || $_POST['action'] !== 'editpost') {
            return $post_data;
        }
        if ($post_data['post_status'] == 'auto-draft') {
            return $post_data;
        }
        return $ns->pre_save_post($post_data, $post_attr);
    };
    $ns->enqueue_scripts_post_new = function ($arg) {
    };
    $ns->enqueue_scripts_post_edit = function ($arg) {
    };
    $ns->enqueue_scripts_edit = function ($arg) {
    };
    $ns->enqueue_scripts_list = function ($arg) {
    };
    $ns->load_page_edit = function ($arg) {
    };
    $ns->load_post_edit = function ($arg) {
    };
    $ns->load_post_new = function ($arg) {
    };
    $ns->save_post = function ($post_a) {
    };
    $ns->pre_save_post = function ($post_data, $post_attr) {
        return $post_data;
    };
    $ns->get_current_post_type = function () {
        global $current_screen;
        if ($current_screen && $current_screen->post_type) {
            return $current_screen->post_type;
        }
        return '';
    };
    $ns->enqueue_scripts = function ($scripts) use($ns, &$enqueued_scripts) {
        if (is_string($scripts)) {
            $scripts = array($scripts);
        }
        foreach ($scripts as $script) {
            wp_enqueue_script($script);
        }
        $enqueued_scripts = array_merge($enqueued_scripts, $scripts);
        $enqueued_scripts = array_unique($enqueued_scripts);
    };
    $ns->enqueue_styles = function ($styles) use($ns) {
        if (is_string($styles)) {
            wp_enqueue_style($styles);
            return;
        }
        if (is_array($styles)) {
            foreach ($styles as $style) {
                if (is_string($style)) {
                    wp_enqueue_style($style);
                }
            }
        }
    };
    $ns->merge_request = function ($model, $config, $request) {
        global $birchschedule;
        return $birchschedule->model->merge_data($model, $config, $request);
    };
    $ns->apply_currency_to_label = function ($label, $currency_code = false) {
        global $birchpress, $birchschedule;
        if ($currency_code === false) {
            $currency_code = $birchschedule->model->get_currency_code();
        }
        $currencies = $birchpress->util->get_currencies();
        $currency = $currencies[$currency_code];
        $symbol = $currency['symbol_right'];
        if ($symbol == '') {
            $symbol = $currency['symbol_left'];
        }
        return $label = $label . ' (' . $symbol . ')';
    };
    $ns->render_errors = function () use($ns) {
        $errors = $ns->get_errors();
        if ($errors && sizeof($errors) > 0) {
            echo '<div id="birchschedule_errors" class="error fade">';
            foreach ($errors as $error) {
                echo '<p>' . $error . '</p>';
            }
            echo '</div>';
            update_option('birchschedule_errors', '');
        }
    };
    $ns->get_errors = function () {
        return get_option('birchschedule_errors');
    };
    $ns->has_errors = function () use($ns) {
        $errors = $ns->get_errors();
        if ($errors && sizeof($errors) > 0) {
            return true;
        } else {
            return false;
        }
    };
    $ns->save_errors = function ($errors) {
        update_option('birchschedule_errors', $errors);
    };
    $ns->get_screen = function ($hook_name) {
        global $birchpress;
        return $birchpress->util->get_wp_screen($hook_name);
    };
    $ns->show_notice = function () {
    };
    $ns->add_page_hook = function ($key, $hook) use($ns, $_ns_data) {
        $_ns_data->page_hooks[$key] = $hook;
    };
    $ns->get_page_hook = function ($key) use($ns, $_ns_data) {
        if (isset($_ns_data->page_hooks[$key])) {
            return $_ns_data->page_hooks[$key];
        } else {
            return '';
        }
    };
    $ns->get_custom_code_css = function ($shortcode) {
        return '';
    };
    $ns->get_shortcodes = function () {
        return array();
    };
    $ns->get_languages_dir = function () {
        return 'birchschedule/languages';
    };
    $ns->load_i18n = function () use($ns) {
        $lan_dir = $ns->get_languages_dir();
        load_plugin_textdomain('birchschedule', false, $lan_dir);
    };
    $ns->create_admin_menus = function () use($ns) {
        $ns->create_menu_scheduler();
        $ns->reorder_submenus();
    };
    $ns->if_change_custom_menu_order = function () {
        return true;
    };
    $ns->change_admin_menu_order = function ($menu_order) {
        $custom_menu_order = array();
        $client_menu = array_search('edit.php?post_type=birs_client', $menu_order);
        foreach ($menu_order as $index => $item) {
            if ('edit.php?post_type=birs_appointment' == $item) {
                $custom_menu_order[] = $item;
                $custom_menu_order[] = 'edit.php?post_type=birs_client';
                unset($menu_order[$client_menu]);
            } else {
                if ('edit.php?post_type=birs_client' != $item) {
                    $custom_menu_order[] = $item;
                }
            }
        }
        return $custom_menu_order;
    };
    $ns->create_menu_scheduler = function () use($ns) {
        $page_hook_calendar = add_submenu_page('edit.php?post_type=birs_appointment', __('Calendar', 'birchschedule'), __('Calendar', 'birchschedule'), 'edit_birs_appointments', 'birchschedule_calendar', array($ns, 'render_calendar_page'));
        $ns->add_page_hook('calendar', $page_hook_calendar);
        $page_hook_settings = add_submenu_page('edit.php?post_type=birs_appointment', __('BirchPress Scheduler Settings', 'birchschedule'), __('Settings', 'birchschedule'), 'manage_birs_settings', 'birchschedule_settings', array($ns, 'render_settings_page'));
        $ns->add_page_hook('settings', $page_hook_settings);
        $page_hook_help = add_submenu_page('edit.php?post_type=birs_appointment', __('Help', 'birchschedule'), __('Help', 'birchschedule'), 'read', 'birchschedule_help', array($ns, 'render_help_page'));
        $ns->add_page_hook('help', $page_hook_help);
    };
    $ns->render_calendar_page = function () {
    };
    $ns->render_settings_page = function () {
    };
    $ns->render_help_page = function () {
    };
    $ns->reorder_submenus = function () use($ns) {
        global $submenu;
        $sub_items =& $submenu['edit.php?post_type=birs_appointment'];
        $location = $ns->get_submenu($sub_items, 'location');
        $staff = $ns->get_submenu($sub_items, 'staff');
        $service = $ns->get_submenu($sub_items, 'service');
        $settings = $ns->get_submenu($sub_items, 'settings');
        $help = $ns->get_submenu($sub_items, 'help');
        $calendar = $ns->get_submenu($sub_items, 'calendar');
        $new_appointment = $ns->get_submenu($sub_items, 'post-new.php?post_type=birs_appointment');
        $sub_items = array($calendar, $new_appointment, $location, $staff, $service, $settings, $help);
    };
    $ns->get_submenu = function ($submenus, $name) use($ns) {
        foreach ($submenus as $submenu) {
            $pos = strpos($submenu[2], $name);
            if ($pos || $pos === 0) {
                return $submenu;
            }
        }
        return false;
    };
    $ns->register_script_data_fn = function ($handle, $data_name, $fn) use($ns, &$scripts_data) {
        if (isset($scripts_data[$handle])) {
            $scripts_data[$handle][$data_name] = $fn;
        } else {
            $scripts_data[$handle] = array($data_name => $fn);
        }
    };
    $ns->get_admin_i18n_messages = function () {
        global $birchschedule;
        return $birchschedule->view->get_frontend_i18n_messages();
    };
    $ns->get_frontend_i18n_messages = function () {
        return array('Loading...' => __('Loading...', 'birchschedule'), 'Loading appointments...' => __('Loading appointments...', 'birchschedule'), 'Saving...' => __('Saving...', 'birchschedule'), 'Save' => __('Save', 'birchschedule'), 'Please wait...' => __('Please wait...', 'birchschedule'), 'Schedule' => __('Schedule', 'birchschedule'), 'Are you sure you want to cancel this appointment?' => __('Are you sure you want to cancel this appointment?', 'birchschedule'), 'Your appointment has been cancelled successfully.' => __('Your appointment has been cancelled successfully.', 'birchschedule'), "The appointment doesn't exist or has been cancelled." => __("The appointment doesn't exist or has been cancelled.", 'birchschedule'), 'Your appointment has been rescheduled successfully.' => __('Your appointment has been rescheduled successfully.', 'birchschedule'), 'Your appointment can not be cancelled now according to our booking policies.' => __('Your appointment can not be cancelled now according to our booking policies.', 'birchschedule'), 'Your appointment can not be rescheduled now according to our booking policies.' => __('Your appointment can not be rescheduled now according to our booking policies.', 'birchschedule'), 'There are no available times.' => __('There are no available times.', 'birchschedule'), '(Deposit)' => __('(Deposit)', 'birchschedule'), 'Reschedule' => __('Reschedule', 'birchschedule'), 'Change' => __('Change', 'birchschedule'), 'No Preference' => __('No Preference', 'birchschedule'), 'All Locations' => __('All Locations', 'birchschedule'), 'All Providers' => __('All Providers', 'birchschedule'));
    };
    $ns->render_ajax_success_message = function ($success) {
        ?>
        <div id="birs_success" code="<?php 
        echo $success['code'];
        ?>
">
            <?php 
        echo $success['message'];
        ?>
        </div>
<?php 
        exit;
    };
    $ns->render_ajax_error_messages = function ($errors) {
        global $birchpress;
        if ($birchpress->util->is_error($errors)) {
            $error_arr = array();
            $codes = $birchpress->util->get_error_codes($errors);
            foreach ($codes as $code) {
                $error_arr[$code] = $birchpress->util->get_error_message($errors, $code);
            }
        } else {
            $error_arr = $errors;
        }
        ?>
        <div id="birs_errors">
            <?php 
        foreach ($error_arr as $error_id => $message) {
            ?>
                <div id="<?php 
            echo $error_id;
            ?>
"><?php 
            echo $message;
            ?>
</div>
            <?php 
        }
        ?>
        </div>
<?php 
        exit;
    };
    $ns->get_query_array = function ($query, $keys) {
        $source = array();
        $result = array();
        if (is_string($query)) {
            wp_parse_str($query, $source);
        } else {
            if (is_array($query)) {
                $source = $query;
            }
        }
        foreach ($keys as $key) {
            if (isset($source[$key])) {
                $result[$key] = $source[$key];
            }
        }
        return $result;
    };
    $ns->get_query_string = function ($query, $keys) use($ns) {
        return http_build_query($ns->get_query_array($query, $keys));
    };
    $ns->get_script_data_fn_model = function () {
        global $birchschedule, $birchpress;
        return array('admin_url' => admin_url(), 'ajax_url' => admin_url('admin-ajax.php'), 'all_schedule' => $birchschedule->model->schedule->get_all_calculated_schedule(), 'all_daysoff' => $birchschedule->model->get_all_daysoff(), 'gmt_offset' => $birchpress->util->get_gmt_offset(), 'future_time' => $birchschedule->model->get_future_time(), 'cut_off_time' => $birchschedule->model->get_cut_off_time(), 'fully_booked_days' => $birchschedule->model->schedule->get_fully_booked_days());
    };
    $ns->get_script_data_fn_view = function () use($ns) {
        global $birchpress, $birchschedule;
        return array('datepicker_i18n_options' => $birchpress->util->get_datepicker_i18n_params(), 'fc_i18n_options' => $birchpress->util->get_fullcalendar_i18n_params(), 'i18n_messages' => $ns->get_frontend_i18n_messages(), 'i18n_countries' => $birchpress->util->get_countries(), 'i18n_states' => $birchpress->util->get_states(), 'plugin_url' => $birchschedule->plugin_url());
    };
    $ns->get_script_data_fn_admincommon = function () use($ns) {
        return array('i18n_messages' => $ns->get_admin_i18n_messages());
    };
    $ns->register_common_scripts_data_fns = function () use($ns) {
        $ns->register_script_data_fn('birchschedule_model', 'birchschedule_model', array($ns, 'get_script_data_fn_model'));
        $ns->register_script_data_fn('birchschedule_view', 'birchschedule_view', array($ns, 'get_script_data_fn_view'));
        $ns->register_script_data_fn('birchschedule_view_admincommon', 'birchschedule_view_admincommon', array($ns, 'get_script_data_fn_admincommon'));
    };
    $ns->register_3rd_scripts = function () {
        global $birchpress, $birchschedule;
        $version = $birchschedule->get_product_version();
        $birchpress->view->register_3rd_scripts();
        wp_register_script('moment', $birchschedule->plugin_url() . '/lib/assets/js/moment/moment.min.js', array(), '1.7.0');
        wp_register_script('jgrowl', $birchschedule->plugin_url() . '/lib/assets/js/jgrowl/jquery.jgrowl.js', array('jquery'), '1.4.0');
        wp_register_script('jscolor', $birchschedule->plugin_url() . '/lib/assets/js/jscolor/jscolor.js', array(), '1.4.0');
        wp_deregister_script('select2');
        wp_register_script('select2', $birchschedule->plugin_url() . '/lib/assets/js/select2/select2.min.js', array('jquery'), '3.4.2');
        wp_register_script('fullcalendar_birchpress', $birchschedule->plugin_url() . '/lib/assets/js/fullcalendar/fullcalendar_birchpress.js', array('jquery-ui-draggable', 'jquery-ui-resizable', 'jquery-ui-dialog', 'jquery-ui-datepicker', 'jquery-ui-tabs', 'jquery-ui-autocomplete'), '1.6.4');
        wp_register_script('filedownload_birchpress', $birchschedule->plugin_url() . '/lib/assets/js/filedownload/jquery.fileDownload.js', array('jquery'), '1.4.0');
    };
    $ns->register_3rd_styles = function () {
        global $birchschedule;
        $version = $birchschedule->get_product_version();
        wp_register_style('fullcalendar_birchpress', $birchschedule->plugin_url() . '/lib/assets/js/fullcalendar/fullcalendar.css', array(), '1.5.4');
        wp_register_style('jquery-ui-bootstrap', $birchschedule->plugin_url() . '/lib/assets/css/jquery-ui-bootstrap/jquery-ui-1.9.2.custom.css', array(), '0.22');
        wp_register_style('jquery-ui-no-theme', $birchschedule->plugin_url() . '/lib/assets/css/jquery-ui-no-theme/jquery-ui-1.9.2.custom.css', array(), '1.9.2');
        wp_register_style('jquery-ui-smoothness', $birchschedule->plugin_url() . '/lib/assets/css/jquery-ui-smoothness/jquery-ui-1.9.2.custom.css', array(), '1.9.2');
        wp_deregister_style('select2');
        wp_register_style('select2', $birchschedule->plugin_url() . '/lib/assets/js/select2/select2.css', array(), '3.4.2');
        wp_register_style('jgrowl', $birchschedule->plugin_url() . '/lib/assets/js/jgrowl/jquery.jgrowl.css', array(), '1.4.0');
    };
    $ns->register_common_scripts = function () {
        global $birchschedule;
        $version = $birchschedule->get_product_version();
        wp_register_script('birchschedule', $birchschedule->plugin_url() . '/assets/js/base.js', array('jquery', 'birchpress'), "{$version}");
        wp_register_script('birchschedule_model', $birchschedule->plugin_url() . '/assets/js/model/base.js', array('jquery', 'birchpress', 'birchschedule'), "{$version}");
        wp_register_script('birchschedule_view', $birchschedule->plugin_url() . '/assets/js/view/base.js', array('jquery', 'birchpress', 'birchschedule', 'birchschedule_model'), "{$version}");
        wp_register_script('birchschedule_view_admincommon', $birchschedule->plugin_url() . '/assets/js/view/admincommon/base.js', array('jquery', 'birchpress', 'birchschedule', 'jgrowl'), "{$version}");
        wp_register_script('birchschedule_view_clients_edit', $birchschedule->plugin_url() . '/assets/js/view/clients/edit/base.js', array('birchschedule_view_admincommon', 'birchschedule_view'), "{$version}");
        wp_register_script('birchschedule_view_locations_edit', $birchschedule->plugin_url() . '/assets/js/view/locations/edit/base.js', array('birchschedule_view_admincommon', 'birchschedule_view'), "{$version}");
        wp_register_script('birchschedule_view_services_edit', $birchschedule->plugin_url() . '/assets/js/view/services/edit/base.js', array('birchschedule_view_admincommon', 'birchschedule_view'), "{$version}");
        wp_register_script('birchschedule_view_staff_edit', $birchschedule->plugin_url() . '/assets/js/view/staff/edit/base.js', array('birchschedule_view_admincommon', 'birchschedule_view', 'jscolor'), "{$version}");
        wp_register_script('birchschedule_view_calendar', $birchschedule->plugin_url() . '/assets/js/view/calendar/base.js', array('birchschedule_view_admincommon', 'birchschedule_view', 'fullcalendar_birchpress', 'moment'), "{$version}");
        wp_register_script('birchschedule_view_bookingform', $birchschedule->plugin_url() . '/assets/js/view/bookingform/base.js', array('jquery-ui-datepicker', 'birchschedule_view'), "{$version}");
    };
    $ns->register_common_styles = function () {
        global $birchschedule;
        $version = $birchschedule->get_product_version();
        wp_register_style('birchschedule_admincommon', $birchschedule->plugin_url() . '/assets/css/admincommon/base.css', array('jgrowl', 'select2'), "{$version}");
        wp_register_style('birchschedule_calendar', $birchschedule->plugin_url() . '/assets/css/calendar/base.css', array('jgrowl'), "{$version}");
        wp_register_style('birchschedule_appointments_common', $birchschedule->plugin_url() . '/assets/css/appointments/common/base.css', array('jquery-ui-no-theme', 'birchschedule_admincommon'), "{$version}");
        wp_register_style('birchschedule_appointments_edit', $birchschedule->plugin_url() . '/assets/css/appointments/edit/base.css', array('jquery-ui-no-theme', 'birchschedule_appointments_common'), "{$version}");
        wp_register_style('birchschedule_appointments_new', $birchschedule->plugin_url() . '/assets/css/appointments/new/base.css', array('jquery-ui-no-theme', 'birchschedule_appointments_common'), "{$version}");
        wp_register_style('birchschedule_services_edit', $birchschedule->plugin_url() . '/assets/css/services/edit/base.css', array(), "{$version}");
        wp_register_style('birchschedule_staff_edit', $birchschedule->plugin_url() . '/assets/css/staff/edit/base.css', array(), "{$version}");
        wp_register_style('birchschedule_locations_edit', $birchschedule->plugin_url() . '/assets/css/locations/edit/base.css', array(), "{$version}");
        wp_register_style('birchschedule_bookingform', $birchschedule->plugin_url() . '/assets/css/bookingform/base.css', array('jquery-ui-no-theme'), "{$version}");
    };
});
Esempio n. 22
0
birch_ns('birchschedule.view.bookingform', function ($ns) {
    $_ns_data = new stdClass();
    birch_defn($ns, 'init', function () use($ns) {
        $ns->init_data();
        add_action('init', array($ns, 'wp_init'));
        add_filter('birchschedule_view_get_shortcodes', array($ns, 'add_shortcode'));
    });
    birch_defn($ns, 'init_data', function () use($_ns_data) {
        $_ns_data->SC_BOOKING_FORM_LEGACY = 'bp-scheduler-bookingform';
        $_ns_data->SC_BOOKING_FORM = 'bpscheduler_booking_form';
        $_ns_data->temp_data = array();
        $_ns_data->sc_attrs = false;
    });
    birch_defn($ns, 'wp_init', function () use($ns, $_ns_data) {
        global $birchschedule, $birchpress;
        add_shortcode($_ns_data->SC_BOOKING_FORM, array($ns, 'get_shortcode_content'));
        add_shortcode($_ns_data->SC_BOOKING_FORM_LEGACY, array($ns, 'get_shortcode_content'));
        add_filter('the_content', array($ns, 'replace_shortcode_id_with_html'), 1000);
        add_filter('widget_text', 'do_shortcode', 11);
        add_filter('widget_text', array($ns, 'replace_shortcode_id_with_html'), 1000);
        add_action('wp_ajax_nopriv_birchschedule_view_bookingform_schedule', array($ns, 'ajax_schedule'));
        add_action('wp_ajax_birchschedule_view_bookingform_schedule', array($ns, 'ajax_schedule'));
        add_action('wp_ajax_nopriv_birchschedule_view_bookingform_get_avaliable_time', array($ns, 'ajax_get_avaliable_time'));
        add_action('wp_ajax_birchschedule_view_bookingform_get_avaliable_time', array($ns, 'ajax_get_avaliable_time'));
        $birchschedule->view->register_script_data_fn('birchschedule_view_bookingform', 'birchschedule_view_bookingform', array($ns, 'get_script_data_fn_view_bookingform'));
        $birchschedule->view->register_script_data_fn('birchschedule_view_bookingform', 'birchschedule_view_bookingform_sc_attrs', array($ns, 'get_script_data_fn_view_bookingform_sc_attrs'));
        if ($ns->is_time_slots_select_field()) {
            add_action('birchschedule_view_bookingform_ajax_get_avaliable_time_before', array($ns, 'ajax_get_avaliable_time2'), 20);
        }
    });
    birch_defn($ns, 'get_script_data_fn_view_bookingform', function () use($ns) {
        global $birchschedule, $birchpress;
        return array('services_prices_map' => $ns->get_services_prices_map(), 'services_duration_map' => $ns->get_services_duration_map(), 'services_staff_map' => $ns->get_services_staff_map(), 'locations_map' => $ns->get_locations_map(), 'locations_staff_map' => $ns->get_locations_staff_map(), 'locations_services_map' => $ns->get_locations_services_map(), 'staff_order' => $ns->get_staff_listing_order(), 'services_order' => $ns->get_services_listing_order(), 'locations_order' => $ns->get_locations_listing_order());
    });
    birch_defn($ns, 'is_sc_attrs_empty', function () use($ns, $_ns_data) {
        return !$_ns_data->sc_attrs;
    });
    birch_defn($ns, 'set_sc_attrs', function ($attrs) use($ns, $_ns_data) {
        $_ns_data->sc_attrs = $attrs;
    });
    birch_defn($ns, 'get_script_data_fn_view_bookingform_sc_attrs', function () use($ns, $_ns_data) {
        return $_ns_data->sc_attrs;
    });
    birch_defn($ns, 'add_shortcode', function ($shortcodes) use($ns, $_ns_data) {
        $shortcodes[] = $_ns_data->SC_BOOKING_FORM;
        return $shortcodes;
    });
    birch_defn($ns, 'enqueue_scripts', function () {
        global $birchschedule, $birchpress;
        $birchschedule->view->enqueue_scripts(array('birchschedule_view_bookingform'));
    });
    birch_defn($ns, 'enqueue_styles', function () {
        global $birchschedule;
        $birchschedule->view->enqueue_styles('birchschedule_bookingform');
    });
    birch_defn($ns, 'get_all_schedule', function () {
        global $birchschedule;
        return $birchschedule->model->schedule->get_all_calculated_schedule();
    });
    birch_defn($ns, 'get_all_daysoff', function () {
        global $birchschedule;
        return $birchschedule->model->get_all_daysoff();
    });
    birch_defn($ns, 'get_locations_map', function () {
        global $birchschedule;
        return $birchschedule->model->get_locations_map();
    });
    birch_defn($ns, 'get_locations_staff_map', function () {
        global $birchschedule;
        return $birchschedule->model->get_locations_staff_map();
    });
    birch_defn($ns, 'get_locations_services_map', function () {
        global $birchschedule;
        return $birchschedule->model->get_locations_services_map();
    });
    birch_defn($ns, 'get_services_staff_map', function () {
        global $birchschedule;
        return $birchschedule->model->get_services_staff_map();
    });
    birch_defn($ns, 'get_locations_listing_order', function () {
        global $birchschedule;
        return $birchschedule->model->get_locations_listing_order();
    });
    birch_defn($ns, 'get_staff_listing_order', function () {
        global $birchschedule;
        return $birchschedule->model->get_staff_listing_order();
    });
    birch_defn($ns, 'get_services_listing_order', function () {
        global $birchschedule;
        return $birchschedule->model->get_services_listing_order();
    });
    birch_defn($ns, 'get_services_prices_map', function () {
        global $birchschedule;
        return $birchschedule->model->get_services_prices_map();
    });
    birch_defn($ns, 'get_services_duration_map', function () {
        global $birchschedule;
        return $birchschedule->model->get_services_duration_map();
    });
    birch_defn($ns, 'validate_appointment_info', function () {
        global $birchpress;
        $errors = array();
        if (!isset($_POST['birs_appointment_staff']) || !isset($_POST['birs_appointment_service'])) {
            $errors['birs_appointment_service'] = __('Please select a service and a provider', 'birchschedule');
        }
        if (!isset($_POST['birs_appointment_date']) || !$_POST['birs_appointment_date']) {
            $errors['birs_appointment_date'] = __('Date is required', 'birchschedule');
        }
        if (!isset($_POST['birs_appointment_time']) || !$_POST['birs_appointment_time']) {
            $errors['birs_appointment_time'] = __('Time is required', 'birchschedule');
        }
        if (isset($_POST['birs_appointment_date']) && $_POST['birs_appointment_date'] && isset($_POST['birs_appointment_time']) && $_POST['birs_appointment_time']) {
            $datetime = array('date' => $_POST['birs_appointment_date'], 'time' => $_POST['birs_appointment_time']);
            $datetime = $birchpress->util->get_wp_datetime($datetime);
            if (!$datetime) {
                $errors['birs_appointment_datetime'] = __('Date & time is incorrect', 'birchschedule');
            }
        }
        return $errors;
    });
    birch_defn($ns, 'validate_client_info', function () {
        $errors = array();
        if (!$_POST['birs_client_name_first']) {
            $errors['birs_client_name_first'] = __('First name is required', 'birchschedule');
        }
        if (!$_POST['birs_client_name_last']) {
            $errors['birs_client_name_last'] = __('Last name is required', 'birchschedule');
        }
        if (!$_POST['birs_client_email']) {
            $errors['birs_client_email'] = __('Email is required', 'birchschedule');
        } else {
            if (!is_email($_POST['birs_client_email'])) {
                $errors['birs_client_email'] = __('Email is incorrect', 'birchschedule');
            }
        }
        if (!$_POST['birs_client_phone']) {
            $errors['birs_client_phone'] = __('Phone is required', 'birchschedule');
        }
        return $errors;
    });
    birch_defn($ns, 'validate_booking_time', function () {
        global $birchschedule;
        $errors = array();
        if (!isset($_POST['birs_appointment_time']) || !$_POST['birs_appointment_time']) {
            $errors['birs_appointment_time'] = __('Time is required', 'birchschedule');
            return $errors;
        }
        $avaliable_times = $birchschedule->view->bookingform->get_avaliable_time();
        $time = $_POST['birs_appointment_time'];
        $valid = array_key_exists($time, $avaliable_times) && $avaliable_times[$time]['avaliable'];
        if (!$valid) {
            $errors = array_merge(array('birs_appointment_time' => __('Time is unavailable', 'birchschedule')), $errors);
        }
        return $errors;
    });
    birch_defn($ns, 'validate_appointment1on1_info', function () {
        return array();
    });
    birch_defn($ns, 'validate_booking_info', function () {
        global $birchschedule;
        $appointment_errors = $birchschedule->view->bookingform->validate_appointment_info();
        $client_errors = $birchschedule->view->bookingform->validate_client_info();
        $appointment1on1_errors = $birchschedule->view->bookingform->validate_appointment1on1_info();
        return array_merge($appointment_errors, $client_errors, $appointment1on1_errors);
    });
    birch_defn($ns, 'validate_wp_nonce', function () {
        return check_ajax_referer("birs_save_appointment-0", '_wpnonce', false);
    });
    birch_defn($ns, 'get_avaliable_time', function () {
        global $birchschedule, $birchpress;
        $staff_id = $_POST['birs_appointment_staff'];
        $location_id = $_POST['birs_appointment_location'];
        $service_id = $_POST['birs_appointment_service'];
        $date_text = $_POST['birs_appointment_date'];
        $date = $birchpress->util->get_wp_datetime(array('date' => $date_text, 'time' => 0));
        $time_options = $birchschedule->model->schedule->get_staff_avaliable_time($staff_id, $location_id, $service_id, $date);
        return $time_options;
    });
    birch_defn($ns, 'get_success_message', function ($appointment1on1_id) {
        global $birchschedule;
        $appointment1on1 = $birchschedule->model->mergefields->get_appointment1on1_merge_values($appointment1on1_id);
        $duration_str = __('Duration', 'birchschedule') . __('mins', 'birchschedule');
        ob_start();
        ?>
        <h3><?php 
        _e('Your appointment has been booked successfully.', 'birchschedule');
        ?>
</h3>
        <div>
            <ul>
                <li>
                    <h4><?php 
        _e('Location', 'birchschedule');
        ?>
</h4>
                    <p><?php 
        echo $appointment1on1['_birs_location_name'];
        ?>
</p>
                </li>
                <li>
                    <h4><?php 
        _e('Service', 'birchschedule');
        ?>
</h4>
                    <p><?php 
        echo $appointment1on1['_birs_service_name'];
        ?>
</p>
                </li>
                <li>
                    <h4><?php 
        _e('Time', 'birchschedule');
        ?>
</h4>
                    <p><?php 
        echo $appointment1on1['_birs_appointment_datetime'];
        ?>
</p>
                </li>
            </ul>
        </div>
        <?php 
        $message = ob_get_clean();
        $success = array('code' => 'text', 'message' => $message);
        return $success;
    });
    birch_defn($ns, 'save_client', function () {
        global $birchschedule;
        $client_config = array('base_keys' => array(), 'meta_keys' => $_POST['birs_client_fields']);
        $client_info = $birchschedule->view->merge_request(array(), $client_config, $_POST);
        unset($client_info['ID']);
        $client_id = $birchschedule->model->booking->save_client($client_info);
        return $client_id;
    });
    birch_defn($ns, 'schedule', function () use($ns) {
        global $birchpress, $birchschedule;
        $client_id = $ns->save_client();
        $appointment1on1_config = array('base_keys' => array(), 'meta_keys' => array_merge($birchschedule->model->get_appointment_fields(), $birchschedule->model->get_appointment1on1_fields(), $birchschedule->model->get_appointment1on1_custom_fields()));
        $appointment1on1_info = $birchschedule->view->merge_request(array(), $appointment1on1_config, $_POST);
        $datetime = array('date' => $_POST['birs_appointment_date'], 'time' => $_POST['birs_appointment_time']);
        $datetime = $birchpress->util->get_wp_datetime($datetime);
        $timestamp = $datetime->format('U');
        $appointment1on1_info['_birs_appointment_timestamp'] = $timestamp;
        $appointment1on1_info['_birs_client_id'] = $client_id;
        unset($appointment1on1_info['ID']);
        unset($appointment1on1_info['_birs_appointment_id']);
        $appointment1on1_id = $birchschedule->model->booking->make_appointment1on1($appointment1on1_info);
        $ns->change_appointment1on1_status($appointment1on1_id);
        return $appointment1on1_id;
    });
    birch_defn($ns, 'change_appointment1on1_status', function ($appointment1on1_id) {
        global $birchschedule;
        $birchschedule->model->booking->change_appointment1on1_status($appointment1on1_id, 'publish');
    });
    birch_defn($ns, 'ajax_schedule', function () use($ns) {
        global $birchschedule;
        $ns = $birchschedule->view->bookingform;
        $permitted = $ns->validate_wp_nonce();
        $appointment_id = 0;
        if ($permitted) {
            $errors = $ns->validate_booking_info();
            if ($errors) {
                $birchschedule->view->render_ajax_error_messages($errors);
            } else {
                $appointment1on1_id = $ns->schedule();
                $success = $ns->get_success_message($appointment1on1_id);
                $birchschedule->view->render_ajax_success_message($success);
            }
        } else {
            $errors = array('birs_booking' => __('Please refresh the page and book again.', 'birchschedule'));
            $birchschedule->view->render_ajax_error_messages($errors);
        }
    });
    birch_defn($ns, 'is_time_slots_select_field', function () {
        return false;
    });
    birch_defn($ns, 'ajax_get_avaliable_time', function () use($ns) {
        global $birchschedule;
        $ns = $birchschedule->view->bookingform;
        $i18n_messages = $birchschedule->view->get_frontend_i18n_messages();
        ?>
        <input id="birs_appointment_time" name="birs_appointment_time" type="hidden" />
        <div id="birs_appointment_timeoptions">
        <?php 
        $time_options = $ns->get_avaliable_time();
        $empty = true;
        foreach ($time_options as $key => $value) {
            if ($value['avaliable']) {
                $text = $value['text'];
                $alternative_staff = '';
                if (isset($value['alternative_staff'])) {
                    $alternative_staff = implode(',', $value['alternative_staff']);
                }
                ?>
                <span><a class='birs_option'
                        data-time='<?php 
                echo $key;
                ?>
'
                        data-alternative-staff="<?php 
                echo $alternative_staff;
                ?>
"
                        href='javascript:void(0);'><?php 
                echo $text;
                ?>
</a></span>
                <?php 
                $empty = false;
            }
        }
        if ($empty) {
            echo "<p>" . $i18n_messages['There are no available times.'] . "</p>";
        }
        ?>
        </div>
        <?php 
        exit;
    });
    birch_defn($ns, 'ajax_get_avaliable_time2', function () {
        global $birchschedule;
        $ns = $birchschedule->view->bookingform;
        $i18n_messages = $birchschedule->view->get_frontend_i18n_messages();
        ?>
        <select id="birs_appointment_timeoptions">
            <option class='birs_option'
                      data-time=''
                      data-alternative-staff="" ><?php 
        _e('Please select time...', 'birchschedule');
        ?>
</option>
            <?php 
        $time_options = $ns->get_avaliable_time();
        foreach ($time_options as $key => $value) {
            if ($value['avaliable']) {
                $text = $value['text'];
                $alternative_staff = '';
                if (isset($value['alternative_staff'])) {
                    $alternative_staff = implode(',', $value['alternative_staff']);
                }
                ?>
            <option class='birs_option'
                      data-time='<?php 
                echo $key;
                ?>
'
                      data-alternative-staff="<?php 
                echo $alternative_staff;
                ?>
" ><?php 
                echo $text;
                ?>
</option>
<?php 
            }
        }
        ?>
        </select>
        <input id="birs_appointment_time" name="birs_appointment_time" type="hidden" />
<?php 
        exit;
    });
    birch_defn($ns, 'replace_shortcode_id_with_html', function ($content) use($ns, $_ns_data) {
        global $birchschedule;
        if (!isset($_ns_data->temp_data['shortcodes'])) {
            return $content;
        }
        $shortcodes = $_ns_data->temp_data['shortcodes'];
        foreach ($shortcodes as $uid => $html) {
            $content = str_replace($uid, $html, $content);
        }
        return $content;
    });
    birch_defn($ns, 'get_shortcode_html', function ($attr) use($ns) {
        global $birchschedule, $birchpress;
        ob_start();
        ?>
                <div class="birchschedule" id="birs_booking_box">
                    <form id="birs_appointment_form">
                        <input type="hidden" id="birs_appointment_price" name="birs_appointment_price" />
                        <input type="hidden" id="birs_appointment_duration" name="birs_appointment_duration" />
                        <input type="hidden" id="birs_appointment_alternative_staff" name="birs_appointment_alternative_staff" value="" />
                        <input type="hidden" id="birs_shortcode_page_url" name="birs_shortcode_page_url" value="<?php 
        echo esc_attr($birchpress->util->current_page_url());
        ?>
" />
                        <div>
                            <?php 
        wp_nonce_field("birs_save_appointment-0");
        ?>
                            <?php 
        echo $birchschedule->view->bookingform->get_fields_html();
        ?>
                        </div>
                    </form>
                </div>
                <div id="birs_booking_success">
                </div>
<?php 
        $html = ob_get_clean();
        $html = $ns->minify_html($html);
        return $html;
    });
    birch_defn($ns, 'minify_html', function ($buffer) {
        $search = array('/\\>[^\\S ]+/s', '/[^\\S ]+\\</s', '/(\\s)+/s', '/\\>\\s+\\</s');
        $replace = array('>', '<', '\\1', '><');
        $buffer = preg_replace($search, $replace, $buffer);
        return $buffer;
    });
    birch_defn($ns, 'get_shortcode_uid', function ($attr) use($ns, $_ns_data) {
        global $birchschedule;
        $uid = 'birchpress_shortcode_' . uniqid();
        $html = $birchschedule->view->bookingform->get_shortcode_html($attr);
        $_ns_data->temp_data['shortcodes'][$uid] = $html;
        return $uid;
    });
    birch_defn($ns, 'get_shortcode_attrs', function ($attr) {
        return array();
    });
    birch_defn($ns, 'get_thankyou_content', function ($appointment1on1_id) {
        global $birchschedule;
        $appointment1on1 = $birchschedule->model->mergefields->get_appointment1on1_merge_values($appointment1on1_id);
        if (!$appointment1on1) {
            return '';
        }
        if ($appointment1on1['post_status'] != 'publish') {
            return "<p>" . __('Your appointment has not been booked successfully due to some errors.', 'birchschedule') . '</p>';
        }
        ob_start();
        ?>
        <div id="birs_booking_success" style="display:block;">
            <h3><?php 
        _e('Your appointment has been booked successfully.', 'birchschedule');
        ?>
</h3>
            <div>
                <ul>
                    <li>
                        <h4><?php 
        _e('Location', 'birchschedule');
        ?>
</h4>
                        <p><?php 
        echo $appointment1on1['_birs_location_name'];
        ?>
</p>
                    </li>
                    <li>
                        <h4><?php 
        _e('Service', 'birchschedule');
        ?>
</h4>
                        <p><?php 
        echo $appointment1on1['_birs_service_name'];
        ?>
</p>
                    </li>
                    <li>
                        <h4><?php 
        _e('Time', 'birchschedule');
        ?>
</h4>
                        <p><?php 
        echo $appointment1on1['_birs_appointment_datetime'];
        ?>
</p>
                    </li>
                </ul>
            </div>
        </div>
        <?php 
        return ob_get_clean();
    });
    birch_defn($ns, 'get_shortcode_content', function ($attr) use($ns, $_ns_data) {
        global $birchschedule;
        $a = $birchschedule->view->bookingform->get_shortcode_attrs($attr);
        if ($ns->is_sc_attrs_empty()) {
            $ns->set_sc_attrs($a);
        }
        $birchschedule->view->register_3rd_styles();
        $birchschedule->view->bookingform->enqueue_styles();
        $birchschedule->view->register_3rd_scripts();
        $birchschedule->view->bookingform->enqueue_scripts();
        ob_start();
        ?>
        <style type="text/css">
        <?php 
        echo $birchschedule->view->get_custom_code_css($_ns_data->SC_BOOKING_FORM);
        ?>
        </style>
        <?php 
        $content = ob_get_clean();
        if (isset($_GET['thankyou']) && $_GET['thankyou'] == 'yes' && isset($_GET['apt1on1_id'])) {
            return $content . $ns->get_thankyou_content($_GET['apt1on1_id']);
        }
        if (isset($a['nowrap']) && $a['nowrap'] == 'yes') {
            return $content . $ns->get_shortcode_uid($a);
        } else {
            return $content . $birchschedule->view->bookingform->get_shortcode_html($a);
        }
    });
    birch_defn($ns, 'get_fields_labels', function () {
        return array('location' => __('Location', 'birchschedule'), 'service' => __('Service', 'birchschedule'), 'service_provider' => __('Provider', 'birchschedule'), 'date' => __('Date', 'birchschedule'), 'time' => __('Time', 'birchschedule'), 'appointment_notes' => __('Notes', 'birchschedule'), 'client_name_first' => __('First Name', 'birchschedule'), 'client_name_last' => __('Last Name', 'birchschedule'), 'client_email' => __('Email', 'birchschedule'), 'client_phone' => __('Phone', 'birchschedule'));
    });
    birch_defn($ns, 'get_fields_html', function () {
        global $birchschedule;
        $labels = $birchschedule->view->bookingform->get_fields_labels();
        ob_start();
        ?>
                <ul>
                <li class="birs_form_field birs_appointment_section">
                    <h2 class="birs_section"><?php 
        _e('Appointment Info', 'birchschedule');
        ?>
</h2>
                </li>
                <li class="birs_form_field birs_appointment_location">
                    <label><?php 
        echo $labels['location'];
        ?>
</label>
                    <div class="birs_field_content">
                        <select id="birs_appointment_location" name="birs_appointment_location">
                        </select>
                    </div>
                </li>
                <li class="birs_form_field birs_appointment_service">
                    <label><?php 
        echo $labels['service'];
        ?>
</label>
                    <div class="birs_field_content">
                        <select id="birs_appointment_service" name="birs_appointment_service">
                        </select>
                    </div>
                </li>
                <li class="birs_form_field birs_appointment_staff">
                    <label><?php 
        echo $labels['service_provider'];
        ?>
</label>
                    <div class="birs_field_content">
                        <select id="birs_appointment_staff" name="birs_appointment_staff">
                        </select>
                        <input type="hidden" id="birs_appointment_avaliable_staff" name="birs_appointment_avaliable_staff" />
                    </div>
                    <div class="birs_error" id="birs_appointment_service_error"></div>
                </li>
                <li class="birs_form_field birs_appointment_date">
                    <label><?php 
        echo $labels['date'];
        ?>
</label>
                    <input id="birs_appointment_date" name="birs_appointment_date" type="hidden">
                    <div  class="birs_field_content">
                        <div id="birs_appointment_datepicker">
                        </div>
                    </div>
                    <div class="birs_error" id="birs_appointment_date_error"></div>
                </li>
                <li class="birs_form_field birs_appointment_time">
                    <label><?php 
        echo $labels['time'];
        ?>
</label>
                    <div class="birs_field_content">
                    </div>
                    <div class="birs_error" id="birs_appointment_time_error"></div>
                </li>
                <li class="birs_form_field birs_appointment_notes">
                    <label><?php 
        echo $labels['appointment_notes'];
        ?>
</label>
                    <div class="birs_field_content birs_field_paragraph">
                        <textarea id="birs_appointment_notes" name="birs_appointment_notes"></textarea>
                        <input type="hidden" name="birs_appointment_fields[]" value="_birs_appointment_notes" />
                    </div>
                </li>
                <li class="birs_form_field birs_client_section">
                    <h2 class="birs_section"><?php 
        _e('Your Info', 'birchschedule');
        ?>
</h2>
                </li>
                <li class="birs_form_field birs_client_name_first">
                    <label><?php 
        echo $labels['client_name_first'];
        ?>
</label>
                    <div class="birs_field_content">
                        <input id="birs_client_name_first" name="birs_client_name_first" type="text">
                        <input type="hidden" name="birs_client_fields[]" value="_birs_client_name_first" />
                    </div>
                    <div class="birs_error" id="birs_client_name_first_error"></div>
                </li>
                <li class="birs_form_field birs_client_name_last">
                    <label><?php 
        echo $labels['client_name_last'];
        ?>
</label>
                    <div class="birs_field_content">
                        <input id="birs_client_name_last" name="birs_client_name_last" type="text">
                        <input type="hidden" name="birs_client_fields[]" value="_birs_client_name_last" />
                    </div>
                    <div class="birs_error" id="birs_client_name_last_error"></div>
                </li>
                <li class="birs_form_field birs_client_email">
                    <label><?php 
        echo $labels['client_email'];
        ?>
</label>
                    <div class="birs_field_content">
                        <input id="birs_client_email" name="birs_client_email" type="text">
                        <input type="hidden" name="birs_client_fields[]" value="_birs_client_email" />
                    </div>
                    <div class="birs_error" id="birs_client_email_error"></div>
                </li>
                <li class="birs_form_field birs_client_phone">
                    <label><?php 
        echo $labels['client_phone'];
        ?>
</label>
                    <div class="birs_field_content">
                        <input id="birs_client_phone" name="birs_client_phone" type="text">
                        <input type="hidden" name="birs_client_fields[]" value="_birs_client_phone" />
                    </div>
                    <div class="birs_error" id="birs_client_phone_error"></div>
                </li>
                <li class="birs_footer">
                    <div class="birs_error" id="birs_booking_error"></div>
                    <div style="display:none;" id="birs_please_wait"><?php 
        _e('Please wait...', 'birchschedule');
        ?>
</div>
                    <div class="birs_field_content">
                        <input type="button" value="<?php 
        _e('Submit', 'birchschedule');
        ?>
" class="button" id="birs_book_appointment">
                    </div>
                </li>
                </ul>

<?php 
        $html = ob_get_clean();
        return $html;
    });
});
Esempio n. 23
0
birch_ns('birchschedule.view.appointments.new', function ($ns) {
    global $birchschedule;
    $ns->init = function () use($ns, $birchschedule) {
        add_action('admin_init', array($ns, 'wp_admin_init'));
        add_action('init', array($ns, 'wp_init'));
        add_action('birchschedule_view_register_common_scripts_after', array($ns, 'register_scripts'));
        $birchschedule->view->load_post_new->when($birchschedule->view->appointments->is_post_type_appointment, $ns->load_post_new);
        $birchschedule->view->enqueue_scripts_post_new->when($birchschedule->view->appointments->is_post_type_appointment, $ns->enqueue_scripts_post_new);
    };
    $ns->wp_init = function () use($ns) {
        global $birchschedule;
        $birchschedule->view->register_script_data_fn('birchschedule_view_appointments_new', 'birchschedule_view_appointments_new', array($ns, 'get_script_data_fn_view_appointments_new'));
    };
    $ns->wp_admin_init = function () use($ns) {
        add_action('wp_ajax_birchschedule_view_appointments_new_schedule', array($ns, 'ajax_schedule'));
    };
    $ns->get_script_data_fn_view_appointments_new = function () use($ns) {
        return array('services_staff_map' => $ns->get_services_staff_map(), 'services_prices_map' => $ns->get_services_prices_map(), 'services_duration_map' => $ns->get_services_duration_map(), 'locations_map' => $ns->get_locations_map(), 'locations_staff_map' => $ns->get_locations_staff_map(), 'locations_services_map' => $ns->get_locations_services_map(), 'locations_order' => $ns->get_locations_listing_order(), 'staff_order' => $ns->get_staff_listing_order(), 'services_order' => $ns->get_services_listing_order());
    };
    $ns->get_locations_map = function () {
        global $birchschedule;
        return $birchschedule->model->get_locations_map();
    };
    $ns->get_locations_staff_map = function () {
        global $birchschedule;
        return $birchschedule->model->get_locations_staff_map();
    };
    $ns->get_locations_services_map = function () {
        global $birchschedule;
        return $birchschedule->model->get_locations_services_map();
    };
    $ns->get_services_staff_map = function () {
        global $birchschedule;
        return $birchschedule->model->get_services_staff_map();
    };
    $ns->get_locations_listing_order = function () {
        global $birchschedule;
        return $birchschedule->model->get_locations_listing_order();
    };
    $ns->get_staff_listing_order = function () {
        global $birchschedule;
        return $birchschedule->model->get_staff_listing_order();
    };
    $ns->get_services_listing_order = function () {
        global $birchschedule;
        return $birchschedule->model->get_services_listing_order();
    };
    $ns->get_services_prices_map = function () {
        global $birchschedule;
        return $birchschedule->model->get_services_prices_map();
    };
    $ns->get_services_duration_map = function () {
        global $birchschedule;
        return $birchschedule->model->get_services_duration_map();
    };
    $ns->load_post_new = function ($arg) use($ns) {
        add_action('add_meta_boxes', array($ns, 'add_meta_boxes'));
    };
    $ns->register_scripts = function () {
        global $birchschedule;
        $version = $birchschedule->get_product_version();
        wp_register_script('birchschedule_view_appointments_new', $birchschedule->plugin_url() . '/assets/js/view/appointments/new/base.js', array('birchschedule_view_admincommon', 'birchschedule_view', 'jquery-ui-datepicker'), "{$version}");
    };
    $ns->enqueue_scripts_post_new = function ($arg) {
        global $birchschedule;
        $birchschedule->view->register_3rd_scripts();
        $birchschedule->view->register_3rd_styles();
        $birchschedule->view->enqueue_scripts(array('birchschedule_view_appointments_new'));
        $birchschedule->view->enqueue_styles(array('birchschedule_appointments_new'));
    };
    $ns->add_meta_boxes = function () use($ns) {
        add_meta_box('meta_box_birs_appointment_new_booking', __('Appointment Info', 'birchschedule'), array($ns, 'render_booking_info'), 'birs_appointment', 'normal', 'high');
        add_meta_box('meta_box_birs_appointment_new_actions', __('Actions', 'birchschedule'), array($ns, 'render_actions'), 'birs_appointment', 'side', 'high');
    };
    $ns->get_time_options = function ($time) {
        global $birchpress;
        $options = $birchpress->util->get_time_options(5);
        ob_start();
        $birchpress->util->render_html_options($options, $time);
        return ob_get_clean();
    };
    $ns->get_appointment_info_html = function () use($ns) {
        global $birchpress;
        if (isset($_GET['apttimestamp'])) {
            $timestamp = $birchpress->util->get_wp_datetime($_GET['apttimestamp']);
            $date = $timestamp->format('m/d/Y');
            $time = $timestamp->format('H') * 60 + $timestamp->format('i');
        } else {
            $date = '';
            $time = 540;
        }
        $location_id = 0;
        $service_id = 0;
        $staff_id = 0;
        if (isset($_GET['locationid']) && $_GET['locationid'] != -1) {
            $location_id = $_GET['locationid'];
        }
        if (isset($_GET['staffid']) && $_GET['staffid'] != -1) {
            $staff_id = $_GET['staffid'];
        }
        ob_start();
        ?>
        <ul>
            <li class="birs_form_field birs_appointment_location">
                <label>
                    <?php 
        _e('Location', 'birchschedule');
        ?>
                </label>
                <div class="birs_field_content">
                    <select id="birs_appointment_location" name="birs_appointment_location"
                        data-value="<?php 
        echo $location_id;
        ?>
">
                    </select>
                </div>
            </li>
            <li class="birs_form_field birs_appointment_service">
                <label>
                    <?php 
        _e('Service', 'birchschedule');
        ?>
                </label>
                <div class="birs_field_content">
                    <select id="birs_appointment_service" name="birs_appointment_service"
                        data-value="<?php 
        echo $service_id;
        ?>
">
                    </select>
                </div>
            </li>
            <li class="birs_form_field birs_appointment_staff">
                <label>
                    <?php 
        _e('Provider', 'birchschedule');
        ?>
                </label>
                <div class="birs_field_content">
                    <select id="birs_appointment_staff" name="birs_appointment_staff"
                        data-value="<?php 
        echo $staff_id;
        ?>
">
                    </select>
                </div>
                <div class="birs_error" id="birs_appointment_service_error"></div>
            </li>
            <li class="birs_form_field birs_appointment_date">
                <label>
                    <?php 
        _e('Date', 'birchschedule');
        ?>
                </label>
                <input id="birs_appointment_date" name="birs_appointment_date" type="hidden" value="<?php 
        echo $date;
        ?>
">
                <div  class="birs_field_content">
                    <div id="birs_appointment_datepicker">
                    </div>
                </div>
                <div class="birs_error" id="birs_appointment_date_error"></div>
            </li>
            <li class="birs_form_field birs_appointment_time">
                <label>
                    <?php 
        _e('Time', 'birchschedule');
        ?>
                </label>
                <div class="birs_field_content">
                    <select id="birs_appointment_time" name="birs_appointment_time" size='1'>
                        <?php 
        echo $ns->get_time_options($time);
        ?>
                    </select>
                </div>
                <div class="birs_error" id="birs_appointment_time_error"></div>
            </li>
        </ul>
<?php 
        return ob_get_clean();
    };
    $ns->get_client_info_html = function () {
        global $birchschedule;
        return $birchschedule->view->appointments->edit->clientlist->edit->get_client_info_html(0);
    };
    $ns->get_appointment1on1_info_html = function () {
        global $birchschedule;
        return $birchschedule->view->appointments->edit->clientlist->edit->get_appointment1on1_info_html(0, 0);
    };
    $ns->render_client_info_header = function () {
        ?>
		<h3 class="birs_section"><?php 
        _e('Client Info', 'birchschedule');
        ?>
</h3>
<?php 
    };
    $ns->render_booking_info = function ($post) use($ns) {
        echo $ns->get_appointment_info_html();
        ?>
		<input type="hidden" id="birs_appointment_duration" name="birs_appointment_duration" />
<?php 
        $ns->render_client_info_header();
        ?>
		<div id="birs_client_info_container">
<?php 
        echo $ns->get_client_info_html();
        ?>
		</div>
		<h3 class="birs_section"><?php 
        _e('Additional Info', 'birchschedule');
        ?>
</h3>
<?php 
        echo $ns->get_appointment1on1_info_html();
        ?>
                <ul>
                    <li class="birs_form_field birs_please_wait" style="display:none;">
                        <label>
                            &nbsp;
                        </label>
                        <div class="birs_field_content">
                            <div><?php 
        _e('Please wait...', 'birchschedule');
        ?>
</div>
                        </div>
                    </li>
                    <li class="birs_form_field">
                        <label>
                            &nbsp; test
                        </label>
                        <div class="birs_field_content">
                            <input type="button" id="birs_appointment_actions_schedule" class="button-primary" value="<?php 
        _e('Schedule', 'birchschedule');
        ?>
" />
                        </div>
                    </li>
                </ul>
<?php 
    };
    $ns->render_actions = function () {
        global $birchschedule;
        $back_url = $birchschedule->view->appointments->edit->get_back_to_calendar_url();
        ?>
                <div class="submitbox">
                    <div style="float:left;">
                        <a href="<?php 
        echo $back_url;
        ?>
">
                            <?php 
        _e('Back to Calendar', 'birchschedule');
        ?>
                        </a>
                    </div>
                    <div class="clear"></div>
                </div>
<?php 
    };
    $ns->validate_appointment_info = function () {
        global $birchpress;
        $errors = array();
        if (!isset($_POST['birs_appointment_staff']) || !isset($_POST['birs_appointment_service'])) {
            $errors['birs_appointment_service'] = __('Please select a service and a provider', 'birchschedule');
        }
        if (!isset($_POST['birs_appointment_date']) || !$_POST['birs_appointment_date']) {
            $errors['birs_appointment_date'] = __('Date is required', 'birchschedule');
        }
        if (!isset($_POST['birs_appointment_time']) || !$_POST['birs_appointment_time']) {
            $errors['birs_appointment_time'] = __('Time is required', 'birchschedule');
        }
        if (isset($_POST['birs_appointment_date']) && $_POST['birs_appointment_date'] && isset($_POST['birs_appointment_time']) && $_POST['birs_appointment_time']) {
            $datetime = array('date' => $_POST['birs_appointment_date'], 'time' => $_POST['birs_appointment_time']);
            $datetime = $birchpress->util->get_wp_datetime($datetime);
            if (!$datetime) {
                $errors['birs_appointment_datetime'] = __('Date & time is incorrect', 'birchschedule');
            }
        }
        return $errors;
    };
    $ns->validate_client_info = function () {
        $errors = array();
        if (!$_POST['birs_client_name_first']) {
            $errors['birs_client_name_first'] = __('This field is required', 'birchschedule');
        }
        if (!$_POST['birs_client_name_last']) {
            $errors['birs_client_name_last'] = __('This field is required', 'birchschedule');
        }
        if (!$_POST['birs_client_email']) {
            $errors['birs_client_email'] = __('Email is required', 'birchschedule');
        } else {
            if (!is_email($_POST['birs_client_email'])) {
                $errors['birs_client_email'] = __('Email is incorrect', 'birchschedule');
            }
        }
        if (!$_POST['birs_client_phone']) {
            $errors['birs_client_phone'] = __('This field is required', 'birchschedule');
        }
        return $errors;
    };
    $ns->validate_appointment1on1_info = function () {
        return array();
    };
    $ns->ajax_schedule = function () use($ns) {
        global $birchpress, $birchschedule;
        $appointment_errors = $ns->validate_appointment_info();
        $appointment1on1_errors = $ns->validate_appointment1on1_info();
        $client_errors = $ns->validate_client_info();
        $errors = array_merge($appointment_errors, $appointment1on1_errors, $client_errors);
        if ($errors) {
            $birchschedule->view->render_ajax_error_messages($errors);
        }
        $client_config = array('base_keys' => array(), 'meta_keys' => $_POST['birs_client_fields']);
        $client_info = $birchschedule->view->merge_request(array(), $client_config, $_POST);
        unset($client_info['ID']);
        $client_id = $birchschedule->model->booking->save_client($client_info);
        $appointment1on1_config = array('base_keys' => array(), 'meta_keys' => array_merge($birchschedule->model->get_appointment_fields(), $birchschedule->model->get_appointment1on1_fields(), $birchschedule->model->get_appointment1on1_custom_fields()));
        $appointment1on1_info = $birchschedule->view->merge_request(array(), $appointment1on1_config, $_POST);
        $datetime = array('date' => $_POST['birs_appointment_date'], 'time' => $_POST['birs_appointment_time']);
        $datetime = $birchpress->util->get_wp_datetime($datetime);
        $timestamp = $datetime->format('U');
        $appointment1on1_info['_birs_appointment_timestamp'] = $timestamp;
        $appointment1on1_info['_birs_client_id'] = $client_id;
        unset($appointment1on1_info['ID']);
        unset($appointment1on1_info['_birs_appointment_id']);
        $appointment1on1_id = $birchschedule->model->booking->make_appointment1on1($appointment1on1_info);
        $birchschedule->model->booking->change_appointment1on1_status($appointment1on1_id, 'publish');
        if ($appointment1on1_id) {
            $cal_url = admin_url('admin.php?page=birchschedule_calendar');
            $refer_query = parse_url(wp_get_referer(), PHP_URL_QUERY);
            $hash_string = $birchschedule->view->get_query_string($refer_query, array('calview', 'locationid', 'staffid', 'currentdate'));
            if ($hash_string) {
                $cal_url = $cal_url . '#' . $hash_string;
            }
            $birchschedule->view->render_ajax_success_message(array('code' => 'success', 'message' => json_encode(array('url' => htmlentities($cal_url)))));
        }
    };
});
Esempio n. 24
0
birch_ns('birchschedule.view.appointments.edit.clientlist.payments', function ($ns) {
    birch_defn($ns, 'init', function () use($ns) {
        add_action('admin_init', array($ns, 'wp_admin_init'));
        $ns->register_post_type();
        add_action('birchschedule_view_register_common_scripts_after', array($ns, 'register_scripts'));
    });
    birch_defn($ns, 'wp_admin_init', function () use($ns) {
        add_action('birchschedule_view_enqueue_scripts_post_edit_after', array($ns, 'enqueue_scripts_post_edit'));
        add_action('birchschedule_view_appointments_edit_clientlist_render_more_rows_after', array($ns, 'render_row'), 30, 3);
        add_filter('birchschedule_view_appointments_edit_clientlist_get_item_actions', array($ns, 'add_item_action'), 30, 2);
        add_action('wp_ajax_birchschedule_view_appointments_edit_clientlist_payments_add_new_payment', array($ns, 'ajax_add_new_payment'));
        add_action('wp_ajax_birchschedule_view_appointments_edit_clientlist_payments_make_payments', array($ns, 'ajax_make_payments'));
    });
    birch_defn($ns, 'register_post_type', function () {
        register_post_type('birs_payment', array('labels' => array('name' => __('Payments', 'birchschedule'), 'singular_name' => __('Appointment', 'birchschedule'), 'add_new' => __('Add Payment', 'birchschedule'), 'add_new_item' => __('Add New Payment', 'birchschedule'), 'edit' => __('Edit', 'birchschedule'), 'edit_item' => __('Edit Payment', 'birchschedule'), 'new_item' => __('New Payment', 'birchschedule'), 'view' => __('View Payment', 'birchschedule'), 'view_item' => __('View Payment', 'birchschedule'), 'search_items' => __('Search Payments', 'birchschedule'), 'not_found' => __('No Payments found', 'birchschedule'), 'not_found_in_trash' => __('No Payments found in trash', 'birchschedule'), 'parent' => __('Parent Payment', 'birchschedule')), 'description' => __('This is where payments are stored.', 'birchschedule'), 'public' => false, 'show_ui' => false, 'capability_type' => 'birs_payment', 'map_meta_cap' => true, 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_in_menu' => 'birchschedule_schedule', 'hierarchical' => false, 'show_in_nav_menus' => false, 'rewrite' => false, 'query_var' => true, 'supports' => array('custom-fields'), 'has_archive' => false));
    });
    birch_defn($ns, 'register_scripts', function () use($ns) {
        global $birchschedule;
        $version = $birchschedule->get_product_version();
        wp_register_script('birchschedule_view_appointments_edit_clientlist_payments', $birchschedule->plugin_url() . '/assets/js/view/appointments/edit/clientlist/payments/base.js', array('birchschedule_view_admincommon', 'birchschedule_view'), "{$version}");
    });
    birch_defn($ns, 'enqueue_scripts_post_edit', function ($arg) {
        if ($arg['post_type'] != 'birs_appointment') {
            return;
        }
        global $birchschedule;
        $birchschedule->view->register_3rd_scripts();
        $birchschedule->view->register_3rd_styles();
        $birchschedule->view->enqueue_scripts(array('birchschedule_view_appointments_edit_clientlist_payments'));
    });
    birch_defn($ns, 'get_payment_types', function () {
        global $birchschedule;
        return $birchschedule->model->booking->get_payment_types();
    });
    birch_defn($ns, 'add_item_action', function ($item_actions, $item) {
        $action_html = '<a href="javascript:void(0);" data-item-id="%s">%s</a>';
        $item_actions['payments'] = sprintf($action_html, $item['ID'], __('Payments', 'birchschedule'));
        return $item_actions;
    });
    birch_defn($ns, 'ajax_make_payments', function () {
        global $birchschedule;
        $appointment_id = $_POST['birs_appointment_id'];
        $client_id = $_POST['birs_client_id'];
        $appointment1on1_config = array('appointment1on1_keys' => array('_birs_appointment1on1_price'));
        $appointment1on1 = $birchschedule->model->booking->get_appointment1on1($appointment_id, $client_id, $appointment1on1_config);
        $appointment1on1['_birs_appointment1on1_price'] = $_POST['birs_appointment1on1_price'];
        $birchschedule->model->save($appointment1on1, $appointment1on1_config);
        $payments = array();
        if (isset($_POST['birs_appointment_payments'])) {
            $payments = $_POST['birs_appointment_payments'];
        }
        $config = array('meta_keys' => $birchschedule->model->get_payment_fields(), 'base_keys' => array());
        foreach ($payments as $payment_trid => $payment) {
            $payment_info = $birchschedule->view->merge_request(array(), $config, $payment);
            $payment_info['_birs_payment_appointment'] = $appointment_id;
            $payment_info['_birs_payment_client'] = $client_id;
            $payment_info['_birs_payment_trid'] = $payment_trid;
            $payment_info['_birs_payment_currency'] = $birchschedule->model->get_currency_code();
            $birchschedule->model->booking->make_payment($payment_info);
        }
        $birchschedule->view->render_ajax_success_message(array('code' => 'success', 'message' => ''));
    });
    birch_defn($ns, 'render_row', function ($wp_list_table, $item, $row_class) use($ns) {
        $client_id = $item['ID'];
        $appointment_id = $wp_list_table->appointment_id;
        $column_count = $wp_list_table->get_column_count();
        $payments_html = $ns->get_payments_details_html($appointment_id, $client_id);
        ?>
                <tr class="<?php 
        echo $row_class;
        ?>
 birs_row_payments"
                    id="birs_client_list_row_payments_<?php 
        echo $item['ID'];
        ?>
"
                    data-item-id = "<?php 
        echo $item['ID'];
        ?>
"
                    data-payments-html = "<?php 
        echo esc_attr($payments_html);
        ?>
">

                    <td colspan = "<?php 
        echo $column_count;
        ?>
"></td>
                </tr>
<?php 
    });
    birch_defn($ns, 'get_payments_details_html', function ($appointment_id, $client_id) use($ns) {
        global $birchschedule, $birchpress;
        $price = 0;
        $payment_types = $ns->get_payment_types();
        $payments = array();
        if ($appointment_id) {
            $appointment1on1 = $birchschedule->model->booking->get_appointment1on1($appointment_id, $client_id, array('appointment1on1_keys' => array('_birs_appointment1on1_price'), 'base_keys' => array()));
            $price = $appointment1on1['_birs_appointment1on1_price'];
            $payments = $birchschedule->model->booking->get_payments_by_appointment1on1($appointment_id, $client_id);
        }
        ob_start();
        ?>
                <ul>
                    <li class="birs_form_field">
                        <label>
<?php 
        $currency_code = $birchschedule->model->get_currency_code();
        echo $birchschedule->view->apply_currency_to_label(__('Price', 'birchschedule'), $currency_code);
        ?>
                        </label>
                        <div class="birs_field_content">
                            <input type="text" id="birs_appointment1on1_price"
                                name="birs_appointment1on1_price"
                                value="<?php 
        echo $price;
        ?>
">
                        </div>
                    </li>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Paid', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <span class="birs_money"
                                id="birs_appointment1on1_paid"></span>
                        </div>
                    </li>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Due', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <span class="birs_money"
                                id="birs_appointment1on1_due"></span>
                        </div>
                    </li>
                </ul>
                <div class="splitter"></div>
                <ul>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Amount to Pay', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <input type="text" id="birs_appointment1on1_amount_to_pay"
                                name="birs_payment_amount"
                                value="" >
                        </div>
                    </li>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Payment Type', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <select name="birs_payment_type">
                                <?php 
        $birchpress->util->render_html_options($payment_types);
        ?>
                            </select>
                        </div>
                    </li>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Payment Notes', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <textarea name="birs_payment_notes"></textarea>
                        </div>
                    </li>
                    <li class="birs_form_field">
                        <label>
                            &nbsp;
                        </label>
                        <div class="birs_field_content">
                            <a id="birs_add_payment"
                               class="button" href="javascript:void(0);">
                                <?php 
        _e('Add Payment', 'birchschedule');
        ?>
                            </a>
                        </div>
                    </li>
                </ul>
                <div class="splitter"></div>
                <ul>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Payment History', 'birchschedule');
        ?>
                        </label>
                    </li>
                </ul>
                <table class="wp-list-table fixed widefat" id="birs_payments_table">
                    <thead>
                        <tr>
                            <th><?php 
        _e('Date', 'birchschedule');
        ?>
</th>
                            <th class="column-author"><?php 
        _e('Amount', 'birchschedule');
        ?>
</th>
                            <th class="column-author"><?php 
        _e('Type', 'birchschedule');
        ?>
</th>
                            <th><?php 
        _e('Notes', 'birchschedule');
        ?>
</th>
                        </tr>
                    </thead>
                    <tbody>
<?php 
        foreach ($payments as $payment_id => $payment) {
            $payment_datetime = $birchpress->util->convert_to_datetime($payment['_birs_payment_timestamp']);
            $amount = $payment['_birs_payment_amount'];
            ?>
                        <tr data-payment-amount="<?php 
            echo $amount;
            ?>
">
                            <td><?php 
            echo $payment_datetime;
            ?>
</td>
                            <td>
                                <?php 
            echo $birchschedule->model->apply_currency_symbol($payment['_birs_payment_amount'], $payment['_birs_payment_currency']);
            ?>
                            </td>
                            <td>
                                <?php 
            echo $payment_types[$payment['_birs_payment_type']];
            ?>
                            </td>
                            <td>
                                <?php 
            echo $payment['_birs_payment_notes'];
            ?>
                            </td>
                        </tr>
<?php 
        }
        ?>
                    </tbody>
                </table>
                <input type="hidden" name="birs_client_id" id="birs_client_id" value="<?php 
        echo $client_id;
        ?>
" />
                <ul>
                    <li class="birs_form_field">
                        <label>
                            &nbsp;
                        </label>
                        <div class="birs_field_content">
                            <input name="birs_appointment_client_payments_save"
                                id="birs_appointment_client_payments_save"
                                type="button" class="button-primary"
                                value="<?php 
        _e('Save', 'birchschedule');
        ?>
" />
                            <a href="javascript:void(0);"
                                id="birs_appointment_client_payments_cancel"
                                style="padding: 4px 0 0 4px; display: inline-block;">
                                <?php 
        _e('Cancel', 'birchschedule');
        ?>
                            </a>
                        </div>
                    </li>
                </ul>
<?php 
        $content = ob_get_clean();
        return $content;
    });
    birch_defn($ns, 'ajax_add_new_payment', function () use($ns) {
        global $birchpress, $birchschedule;
        $payment_types = $ns->get_payment_types();
        $timestamp = time();
        $amount = 0;
        if (isset($_POST['birs_payment_amount'])) {
            $amount = floatval($_POST['birs_payment_amount']);
        }
        $payment_type = $_POST['birs_payment_type'];
        if (isset($_POST['birs_payment_notes'])) {
            $payment_notes = $_POST['birs_payment_notes'];
        }
        $payment_trid = uniqid();
        ?>
                <tr data-payment-amount="<?php 
        echo $amount;
        ?>
"
                    data-payment-trid="<?php 
        echo $payment_trid;
        ?>
" >
                    <td>
                        <?php 
        echo $birchpress->util->convert_to_datetime($timestamp);
        ?>
                        <input type="hidden"
                             name="birs_appointment_payments[<?php 
        echo $payment_trid;
        ?>
][birs_payment_timestamp]"
                             value="<?php 
        echo $timestamp;
        ?>
" />
                        <div class="row-actions">
                            <span class="delete">
                                <a href="javascript:void(0);"
                                    data-payment-trid="<?php 
        echo $payment_trid;
        ?>
">
                                    <?php 
        _e('Delete', 'birchschedule');
        ?>
                                </a>
                            </span>
                        </div>
                    </td>
                    <td>
<?php 
        $currency_code = $birchschedule->model->get_currency_code();
        echo $birchschedule->model->apply_currency_symbol($amount, $currency_code);
        ?>
                        <input type="hidden"
                             name="birs_appointment_payments[<?php 
        echo $payment_trid;
        ?>
][birs_payment_amount]"
                             value="<?php 
        echo $amount;
        ?>
" />
                    </td>
                    <td>
                        <?php 
        echo $payment_types[$payment_type];
        ?>
                        <input type="hidden"
                             name="birs_appointment_payments[<?php 
        echo $payment_trid;
        ?>
][birs_payment_type]"
                             value="<?php 
        echo $payment_type;
        ?>
" />
                    </td>
                    <td>
                        <?php 
        echo $payment_notes;
        ?>
                        <input type="hidden"
                             name="birs_appointment_payments[<?php 
        echo $payment_trid;
        ?>
][birs_payment_notes]"
                             value="<?php 
        echo $payment_notes;
        ?>
" />
                    </td>
                </tr>
<?php 
        die;
    });
});
Esempio n. 25
0
birch_ns('birchschedule.view.appointments.edit.clientlist.cancel', function ($ns) {
    birch_defn($ns, 'init', function () use($ns) {
        add_action('admin_init', array($ns, 'wp_admin_init'));
        add_action('birchschedule_view_register_common_scripts_after', array($ns, 'register_scripts'));
    });
    birch_defn($ns, 'wp_admin_init', function () use($ns) {
        add_action('wp_ajax_birchschedule_view_appointments_edit_clientlist_cancel_cancel', array($ns, 'ajax_cancel'));
        add_action('birchschedule_view_enqueue_scripts_post_edit_after', array($ns, 'enqueue_scripts_post_edit'));
        add_filter('birchschedule_view_appointments_edit_clientlist_get_item_actions', array($ns, 'add_item_action'), 40, 2);
    });
    birch_defn($ns, 'register_scripts', function () {
        global $birchschedule;
        $version = $birchschedule->get_product_version();
        wp_register_script('birchschedule_view_appointments_edit_clientlist_cancel', $birchschedule->plugin_url() . '/assets/js/view/appointments/edit/clientlist/cancel/base.js', array('birchschedule_view_admincommon', 'birchschedule_view'), "{$version}");
    });
    birch_defn($ns, 'add_item_action', function ($item_actions, $item) {
        $action_html = '<a href="javascript:void(0);" data-item-id="%s">%s</a>';
        $item_actions['cancel'] = sprintf($action_html, $item['ID'], __('Cancel', 'birchschedule'));
        return $item_actions;
    });
    birch_defn($ns, 'enqueue_scripts_post_edit', function ($arg) {
        if ($arg['post_type'] != 'birs_appointment') {
            return;
        }
        global $birchschedule;
        $birchschedule->view->register_3rd_scripts();
        $birchschedule->view->register_3rd_styles();
        $birchschedule->view->enqueue_scripts(array('birchschedule_view_appointments_edit_clientlist_cancel'));
    });
    birch_defn($ns, 'ajax_cancel', function () use($ns) {
        global $birchschedule;
        $client_id = $_POST['birs_client_id'];
        $appointment_id = $_POST['birs_appointment_id'];
        $appointment1on1 = $birchschedule->model->booking->get_appointment1on1($appointment_id, $client_id);
        $success = array('code' => 'reload', 'message' => '');
        if ($appointment1on1) {
            $birchschedule->model->booking->cancel_appointment1on1($appointment1on1['ID']);
            $cancelled = $birchschedule->model->booking->if_appointment_cancelled($appointment_id);
            if ($cancelled) {
                $cal_url = admin_url('admin.php?page=birchschedule_calendar');
                $refer_query = parse_url(wp_get_referer(), PHP_URL_QUERY);
                $hash_string = $birchschedule->view->get_query_string($refer_query, array('calview', 'locationid', 'staffid', 'currentdate'));
                if ($hash_string) {
                    $cal_url = $cal_url . '#' . $hash_string;
                }
                $success = array('code' => 'redirect_to_calendar', 'message' => json_encode(array('url' => htmlentities($cal_url))));
            }
        }
        $birchschedule->view->render_ajax_success_message($success);
    });
});
Esempio n. 26
0
birch_ns('birchschedule.eadmin', function ($ns) {
    global $birchschedule;
    birch_defn($ns, 'init', function () use($ns) {
        add_action('admin_init', array($ns, 'wp_admin_init'));
        add_action('birchschedule_view_register_common_scripts_after', array($ns, 'register_scripts'));
    });
    birch_defn($ns, 'wp_admin_init', function () use($ns) {
        add_action('birchschedule_view_appointments_new_enqueue_scripts_post_new_after', array($ns, 'enqueue_scripts'));
        add_action('birchschedule_view_appointments_edit_enqueue_scripts_post_edit_after', array($ns, 'enqueue_scripts'));
        add_action('wp_ajax_birchschedule_eadmin_load_selected_client', array($ns, 'ajax_load_selected_client'));
        add_action('wp_ajax_birchschedule_eadmin_search_clients', array($ns, 'ajax_search_clients'));
        add_action('birchschedule_view_appointments_new_render_client_info_header_after', array($ns, 'render_client_selector'), 20);
        add_action('birchschedule_gbooking_render_client_info_header_after', array($ns, 'render_client_selector'), 20);
        add_action('birchschedule_view_appointments_edit_add_meta_boxes_after', array($ns, 'add_metabox_change_duration'));
        add_action('wp_ajax_birchschedule_eadmin_change_appointment_duration', array($ns, 'ajax_change_appointment_duration'));
        add_filter('birchschedule_model_booking_get_appointment_title', array($ns, 'get_calendar_appointment_title'), 20, 2);
    });
    birch_defn($ns, 'register_scripts', function () use($ns, $birchschedule) {
        $version = $birchschedule->get_product_version();
        wp_register_script('birchschedule_eadmin', $birchschedule->plugin_url() . '/modules/eadmin/assets/js/base.js', array('jquery-ui-autocomplete'), "{$version}");
    });
    birch_defn($ns, 'enqueue_scripts', function () use($ns, $birchschedule) {
        $birchschedule->view->enqueue_scripts(array('birchschedule_eadmin'));
    });
    birch_defn($ns, 'title_like_where', function ($where) use($ns, $birchschedule) {
        global $wpdb;
        if (isset($_REQUEST['term'])) {
            $post_title_like = $_REQUEST['term'];
            $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql(like_escape($post_title_like)) . '%\'';
        }
        return $where;
    });
    birch_defn($ns, 'ajax_load_selected_client', function () use($ns, $birchschedule) {
        if (isset($_REQUEST['birs_client_id'])) {
            $client_id = $_REQUEST['birs_client_id'];
        } else {
            $client_id = 0;
        }
        echo $birchschedule->view->appointments->edit->clientlist->edit->get_client_info_html($client_id);
        ?>
        <script type="text/javascript">
            jQuery(function($) {
                birchschedule.eadmin.initClientInfo();
            });
        </script>
        <?php 
        exit;
    });
    birch_defn($ns, 'ajax_search_clients', function () use($ns, $birchschedule) {
        add_filter('posts_where', array($ns, 'title_like_where'), 10);
        $clients = $birchschedule->model->query(array('post_type' => 'birs_client', 'orderby' => 'title', 'order' => 'asc'), array('base_keys' => array('post_title'), 'meta_keys' => array('_birs_client_name_first', '_birs_client_name_last')));
        remove_filter('posts_where', array($ns, 'title_like_where'), 10);
        $results = array();
        foreach ($clients as $client) {
            $el = array('id' => $client['ID'], 'label' => $client['post_title'], 'value' => $client['post_title']);
            $results[] = $el;
        }
        $success = array('code' => 'success', 'message' => json_encode($results));
        $birchschedule->view->render_ajax_success_message($success);
    });
    birch_defn($ns, 'render_client_selector', function () use($ns, $birchschedule) {
        $ui_anim_url = $birchschedule->plugin_url() . "/assets/images/ui-anim_basic_16x16.gif";
        $placeholder = __('Search for an existing client', 'birchschedule');
        ?>
        <ul>
            <li class="birs_form_field">
                <label>&nbsp;</label>
                <div class="birs_field_content">
                    <input id="birs_client_selector" type="text" placeholder="<?php 
        echo $placeholder;
        ?>
">
                </div>
            </li>
        </ul>
        <style type="text/css">
            .ui-autocomplete-loading {
                background: white url('<?php 
        echo $ui_anim_url;
        ?>
') right center no-repeat;
            }
            .ui-autocomplete {
                max-height: 100px;
                overflow-y: auto;
                /* prevent horizontal scrollbar */
                overflow-x: hidden;
            }
        </style>
        <?php 
    });
    birch_defn($ns, 'add_metabox_change_duration', function () use($ns) {
        add_meta_box('birs_metabox_appointment_change_duration', __('Duration', 'birchschedule'), array($ns, 'render_change_appointment_duration'), 'birs_appointment', 'side', 'high');
    });
    birch_defn($ns, 'ajax_change_appointment_duration', function () use($ns, $birchschedule) {
        $appointment = array('post_type' => 'birs_appointment');
        $appointment['_birs_appointment_duration'] = $_POST['birs_appointment_duration'];
        $appointment['ID'] = $_POST['birs_appointment_id'];
        $birchschedule->model->save($appointment, array('meta_keys' => array('_birs_appointment_duration')));
        $birchschedule->view->render_ajax_success_message(array('code' => 'success', 'message' => ''));
    });
    birch_defn($ns, 'render_change_appointment_duration', function ($post) use($ns, $birchschedule) {
        $appointment = $birchschedule->model->get($post->ID, array('meta_keys' => array('_birs_appointment_duration')));
        $duration = $appointment['_birs_appointment_duration'];
        ?>
        <ul>
            <li class="birs_form_field">
                <div class="birs_field_content">
                    <input type="text" name="birs_appointment_duration"
                        id="birs_appointment_duration"
                        value="<?php 
        echo $duration;
        ?>
"
                        style="width:80%;" />
                    <?php 
        _e('mins', 'birchschedule');
        ?>
                </div>
            </li>
            <li class="birs_form_field">
                <div class="birs_field_content">
                    <input type="button" class="button-primary"
                        id="birs_appointment_actions_change_duration"
                        name="birs_appointment_actions_change_duration"
                        value="<?php 
        _e('Change', 'birchschedule');
        ?>
" />
                </div>
            </li>
        </ul>
        <?php 
    });
    birch_defn($ns, 'get_calendar_appointment_title_template', function () {
        return false;
    });
    birch_defn($ns, 'get_calendar_appointment_title', function ($appointment_title, $appointment) use($ns, $birchschedule) {
        $template = $ns->get_calendar_appointment_title_template();
        if ($template === false) {
            return $appointment_title;
        }
        $seperator = "\n";
        $description = '';
        $appointment1on1s = $appointment['appointment1on1s'];
        $index = 0;
        foreach ($appointment1on1s as $appointment1on1) {
            $appointment1on1_values = $birchschedule->model->mergefields->get_appointment1on1_merge_values($appointment1on1['ID']);
            $appointment1on1_description = $birchschedule->model->mergefields->apply_merge_fields($template, $appointment1on1_values);
            if ($index !== 0) {
                $description .= $seperator . $appointment1on1_description;
            } else {
                $description .= $appointment1on1_description;
            }
            $index++;
        }
        return $description;
    });
});
Esempio n. 27
0
birch_ns('birchschedule.gsettings', function ($ns) {
    $update_info = array();
    birch_defn($ns, 'init', function () use($ns) {
        add_action('init', array($ns, 'wp_init'));
        add_action('admin_init', array($ns, 'wp_admin_init'));
    });
    birch_defn($ns, 'wp_init', function () use($ns) {
        add_action('birchschedule_view_show_notice', array($ns, 'show_update_notice'));
        add_filter('site_transient_update_plugins', array($ns, 'get_update_info'), 20);
        add_filter('birchschedule_view_settings_get_tabs', array($ns, 'add_tab'));
        add_filter('birchschedule_model_get_currency_code', array($ns, 'get_option_currency'));
        add_filter('birchschedule_view_calendar_get_default_view', array($ns, 'get_option_default_calendar_view'));
    });
    birch_defn($ns, 'wp_admin_init', function () use($ns) {
        register_setting('birchschedule_options', 'birchschedule_options', array($ns, 'sanitize_input'));
        $ns->add_settings_sections();
    });
    birch_defn($ns, 'add_tab', function ($tabs) use($ns) {
        $tabs['general'] = array('title' => __('General', 'birchschedule'), 'action' => array($ns, 'render_page'), 'order' => 0);
        return $tabs;
    });
    birch_defn($ns, 'add_settings_sections', function () use($ns) {
        add_settings_section('birchschedule_general', __('General Options', 'birchschedule'), array($ns, 'render_section_general'), 'birchschedule_settings');
        $ns->add_settings_fields();
    });
    birch_defn($ns, 'add_settings_fields', function () use($ns) {
        add_settings_field('birchschedule_timezone', __('Timezone'), array($ns, 'render_timezone'), 'birchschedule_settings', 'birchschedule_general');
        add_settings_field('birchschedule_date_time_format', __('Date Format, Time Format', 'birchschedule'), array($ns, 'render_date_time_format'), 'birchschedule_settings', 'birchschedule_general');
        add_settings_field('birchschedule_start_of_week', __('Week Starts On', 'birchschedule'), array($ns, 'render_start_of_week'), 'birchschedule_settings', 'birchschedule_general');
        add_settings_field('birchschedule_currency', __('Currency', 'birchschedule'), array($ns, 'render_currency'), 'birchschedule_settings', 'birchschedule_general');
        add_settings_field('birchschedule_default_calendar_view', __('Default Calendar View', 'birchschedule'), array($ns, 'render_default_calendar_view'), 'birchschedule_settings', 'birchschedule_general');
    });
    birch_defn($ns, 'get_option_currency', function () use($ns) {
        $options = $ns->get_options();
        return $options['currency'];
    });
    birch_defn($ns, 'get_option_default_calendar_view', function () use($ns) {
        $options = $ns->get_options();
        return $options['default_calendar_view'];
    });
    birch_defn($ns, 'render_section_general', function () {
        echo '';
    });
    birch_defn($ns, 'get_options', function () use($ns) {
        $options = get_option('birchschedule_options');
        return $options;
    });
    birch_defn($ns, 'render_timezone', function () {
        $timezone_url = admin_url('options-general.php');
        echo sprintf(__("<label>Timezone settings are located <a href='%s'>here</a>.</label>", 'birchschedule'), $timezone_url);
    });
    birch_defn($ns, 'render_date_time_format', function () {
        $timezone_url = admin_url('options-general.php');
        echo sprintf(__("<label>Date format, time format settings are located <a href='%s'>here</a>.</label>", 'birchschedule'), $timezone_url);
    });
    birch_defn($ns, 'render_start_of_week', function () {
        $timezone_url = admin_url('options-general.php');
        echo sprintf(__("<label>First day of week setting is located <a href='%s'>here</a>.</label>", 'birchschedule'), $timezone_url);
    });
    birch_defn($ns, 'map_currencies', function ($currency) {
        if ($currency['symbol_right'] != '') {
            return $currency['title'] . ' (' . $currency['symbol_right'] . ')';
        } else {
            return $currency['title'] . ' (' . $currency['symbol_left'] . ')';
        }
    });
    birch_defn($ns, 'render_currency', function () use($ns) {
        global $birchpress;
        $currencies = $birchpress->util->get_currencies();
        $currencies = array_map(array($ns, 'map_currencies'), $currencies);
        $currency = $ns->get_option_currency();
        echo '<select id="birchschedule_currency" name="birchschedule_options[currency]">';
        $birchpress->util->render_html_options($currencies, $currency);
        echo '</select>';
    });
    birch_defn($ns, 'render_default_calendar_view', function () use($ns) {
        global $birchpress;
        $views = $birchpress->util->get_calendar_views();
        $default_view = $ns->get_option_default_calendar_view();
        echo '<select id="birchschedule_default_calenar_view" name="birchschedule_options[default_calendar_view]">';
        $birchpress->util->render_html_options($views, $default_view);
        echo '</select>';
    });
    birch_defn($ns, 'render_page', function () use($ns) {
        $options = $ns->get_options();
        $version = $options['version'];
        settings_errors();
        ?>
                <form action="options.php" method="post">
                    <input type='hidden' name='birchschedule_options[version]' value='<?php 
        echo $version;
        ?>
'>
                    <?php 
        settings_fields('birchschedule_options');
        ?>
                    <?php 
        do_settings_sections('birchschedule_settings');
        ?>
                    <p class="submit">
                        <input name="Submit" type="submit" class="button-primary"
                               value="<?php 
        _e('Save changes', 'birchschedule');
        ?>
" />
                    </p>
                </form>
<?php 
    });
    birch_defn($ns, 'sanitize_input', function ($input) {
        return $input;
    });
    birch_defn($ns, 'get_update_info', function ($checked_data) use(&$update_info) {
        $plugin_slug = "birchschedule";
        $slug_str = $plugin_slug . '/' . $plugin_slug . '.php';
        if (isset($checked_data->response[$slug_str])) {
            $update_info = $checked_data->response[$slug_str];
            $update_info = array('version' => $update_info->new_version);
        }
        return $checked_data;
    });
    birch_defn($ns, 'show_update_notice', function () use(&$update_info) {
        global $birchschedule;
        $product_name = $birchschedule->get_product_name();
        $update_url = admin_url('update-core.php');
        $update_text = "%s %s is available! <a href='{$update_url}'>Please update now</a>.";
        if ($update_info) {
            ?>
                <div class="updated inline">
                    <p><?php 
            echo sprintf($update_text, $product_name, $update_info['version']);
            ?>
</p>
                </div>
<?php 
        }
    });
});
Esempio n. 28
0
<?php

birch_ns('birchschedule.model.cpt.location', function ($ns) {
    global $birchschedule;
    birch_defn($ns, 'init', function () use($ns, $birchschedule) {
        birch_defmethod($birchschedule->model, 'pre_save', 'birs_location', $ns->pre_save);
        birch_defmethod($birchschedule->model, 'post_get', 'birs_location', $ns->post_get);
    });
    birch_defn($ns, 'pre_save', function ($location, $config) {
        birch_assert(is_array($location) && isset($location['post_type']));
        return $location;
    });
    birch_defn($ns, 'post_get', function ($location) {
        birch_assert(is_array($location) && isset($location['post_type']));
        if (isset($location['post_title'])) {
            $location['_birs_location_name'] = $location['post_title'];
        }
        if (isset($location['post_content'])) {
            $location['_birs_location_description'] = $location['post_content'];
        }
        return $location;
    });
});
Esempio n. 29
0
birch_ns('birchschedule.view.appointments.edit.clientlist.reschedule', function ($ns) {
    global $birchschedule;
    birch_defn($ns, 'init', function () use($ns) {
        add_action('admin_init', array($ns, 'wp_admin_init'));
        add_action('birchschedule_view_register_common_scripts_after', array($ns, 'register_scripts'));
    });
    birch_defn($ns, 'wp_admin_init', function () use($ns, $birchschedule) {
        add_action('birchschedule_view_enqueue_scripts_post_edit_after', array($ns, 'enqueue_scripts_post_edit'));
        add_action('birchschedule_view_appointments_edit_clientlist_render_more_rows_after', array($ns, 'render_row'), 20, 3);
        add_filter('birchschedule_view_appointments_edit_clientlist_get_item_actions', array($ns, 'add_item_action'), 35, 2);
        add_action('wp_ajax_birchschedule_view_appointments_edit_clientlist_reschedule', array($ns, 'ajax_reschedule'));
    });
    birch_defn($ns, 'register_scripts', function () use($birchschedule) {
        $version = $birchschedule->get_product_version();
        wp_register_script('birchschedule_view_appointments_edit_clientlist_reschedule', $birchschedule->plugin_url() . '/assets/js/view/appointments/edit/clientlist/reschedule/base.js', array('birchschedule_view_admincommon', 'birchschedule_view'), "{$version}");
    });
    birch_defn($ns, 'enqueue_scripts_post_edit', function ($arg) {
        if ($arg['post_type'] != 'birs_appointment') {
            return;
        }
        global $birchschedule;
        $birchschedule->view->register_3rd_scripts();
        $birchschedule->view->register_3rd_styles();
        $birchschedule->view->enqueue_scripts(array('birchschedule_view_appointments_edit_clientlist_reschedule'));
    });
    birch_defn($ns, 'add_item_action', function ($item_actions, $item) {
        $action_html = '<a href="javascript:void(0);" data-item-id="%s">%s</a>';
        $item_actions['reschedule'] = sprintf($action_html, $item['ID'], __('Reschedule', 'birchschedule'));
        return $item_actions;
    });
    birch_defn($ns, 'render_row', function ($wp_list_table, $item, $row_class) use($ns) {
        $client_id = $item['ID'];
        $appointment_id = $wp_list_table->appointment_id;
        $column_count = $wp_list_table->get_column_count();
        $reschedule_html = $ns->get_reschedule_html($appointment_id, $client_id);
        ?>
                <tr class="<?php 
        echo $row_class;
        ?>
 birs_row_reschedule"
                    id="birs_client_list_row_reschedule_<?php 
        echo $client_id;
        ?>
"
                    data-item-id = "<?php 
        echo $client_id;
        ?>
"
                    data-reschedule-html = "<?php 
        echo esc_attr($reschedule_html);
        ?>
" >

                    <td colspan = "<?php 
        echo $column_count;
        ?>
">
                    </td>
                </tr>
<?php 
    });
    birch_defn($ns, 'validate_reschedule_info', function () {
        global $birchpress;
        $errors = array();
        if (!isset($_POST['birs_appointment_staff'])) {
            $errors['birs_appointment_staff'] = __('Please select a provider', 'birchschedule');
        }
        if (!isset($_POST['birs_appointment_date']) || !$_POST['birs_appointment_date']) {
            $errors['birs_appointment_date'] = __('Date is required', 'birchschedule');
        }
        if (!isset($_POST['birs_appointment_time']) || !$_POST['birs_appointment_time']) {
            $errors['birs_appointment_time'] = __('Time is required', 'birchschedule');
        }
        if (isset($_POST['birs_appointment_date']) && $_POST['birs_appointment_date'] && isset($_POST['birs_appointment_time']) && $_POST['birs_appointment_time']) {
            $datetime = array('date' => $_POST['birs_appointment_date'], 'time' => $_POST['birs_appointment_time']);
            $datetime = $birchpress->util->get_wp_datetime($datetime);
            if (!$datetime) {
                $errors['birs_appointment_datetime'] = __('Date & time is incorrect', 'birchschedule');
            }
        }
        return $errors;
    });
    birch_defn($ns, 'ajax_reschedule', function () use($ns) {
        global $birchpress, $birchschedule;
        $errors = $ns->validate_reschedule_info();
        if ($errors) {
            $birchschedule->view->render_ajax_error_messages($errors);
        }
        $appointment_info = array();
        $datetime = array('date' => $_POST['birs_appointment_date'], 'time' => $_POST['birs_appointment_time']);
        $datetime = $birchpress->util->get_wp_datetime($datetime);
        $timestamp = $datetime->format('U');
        $appointment_info['_birs_appointment_timestamp'] = $timestamp;
        $appointment_info['_birs_appointment_staff'] = $_POST['birs_appointment_staff'];
        $appointment_info['_birs_appointment_location'] = $_POST['birs_appointment_location'];
        $appointment_info['_birs_appointment_service'] = $_POST['birs_appointment_service'];
        $appointment_id = $_POST['birs_appointment_id'];
        $client_id = $_POST['birs_client_id'];
        $appointment1on1 = $birchschedule->model->booking->get_appointment1on1($appointment_id, $client_id);
        $birchschedule->model->booking->reschedule_appointment1on1($appointment1on1['ID'], $appointment_info);
        $cal_url = admin_url('admin.php?page=birchschedule_calendar');
        $refer_query = parse_url(wp_get_referer(), PHP_URL_QUERY);
        $hash_string = $birchschedule->view->get_query_string($refer_query, array('calview', 'locationid', 'staffid', 'currentdate'));
        if ($hash_string) {
            $cal_url = $cal_url . '#' . $hash_string;
        }
        $birchschedule->view->render_ajax_success_message(array('code' => 'success', 'message' => json_encode(array('url' => htmlentities($cal_url)))));
    });
    birch_defn($ns, 'get_reschedule_html', function ($appointment_id, $client_id) use($ns) {
        ob_start();
        ?>
                <div style="overflow:hidden;">
                    <h4><?php 
        _e('Reschedule', 'birchschedule');
        ?>
</h4>
                    <input type="hidden" name="birs_client_id" id="birs_client_id" value="<?php 
        echo $client_id;
        ?>
" />
                    <?php 
        echo $ns->get_appointment_info_html($appointment_id);
        ?>
                    <?php 
        echo $ns->get_actions_html();
        ?>
                </div>
<?php 
        return ob_get_clean();
    });
    birch_defn($ns, 'get_actions_html', function () {
        ?>
                <ul>
                    <li class="birs_form_field">
                        <label>
                            &nbsp;
                        </label>
                        <div class="birs_field_content">
                            <input name="birs_appointment_reschedule"
                                id="birs_appointment_reschedule"
                                type="button" class="button-primary"
                                value="<?php 
        _e('Reschedule', 'birchschedule');
        ?>
" />
                            <a href="javascript:void(0);"
                                id="birs_appointment_reschedule_cancel"
                                style="padding: 4px 0 0 4px; display: inline-block;">
                                <?php 
        _e('Cancel', 'birchschedule');
        ?>
                            </a>
                        </div>
                    </li>
                </ul>
<?php 
    });
    birch_defn($ns, 'get_appointment_info_html', function ($appointment_id) use($ns, $birchschedule) {
        global $birchpress, $birchschedule;
        $appointment = $birchschedule->model->get($appointment_id, array('base_keys' => array(), 'meta_keys' => $birchschedule->model->get_appointment_fields()));
        $options = $birchpress->util->get_time_options(5);
        if ($appointment) {
            $location_id = $appointment['_birs_appointment_location'];
            $service_id = $appointment['_birs_appointment_service'];
            $staff_id = $appointment['_birs_appointment_staff'];
            $timestamp = $birchpress->util->get_wp_datetime($appointment['_birs_appointment_timestamp']);
            $date4picker = $timestamp->format(get_option('date_format'));
            $date = $timestamp->format('m/d/Y');
            $time = $timestamp->format('H') * 60 + $timestamp->format('i');
        }
        ob_start();
        ?>
                <ul>
                    <li class="birs_form_field birs_appointment_location">
                        <label>
                            <?php 
        _e('Location', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <select id="birs_appointment_location" name="birs_appointment_location"
                                data-value="<?php 
        echo $location_id;
        ?>
">
                            </select>
                        </div>
                        <div class="birs_error" id="birs_appointment_location_error"></div>
                    </li>
                    <li class="birs_form_field birs_appointment_service">
                        <label>
                            <?php 
        _e('Service', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <select id="birs_appointment_service" name="birs_appointment_service"
                                data-value="<?php 
        echo $service_id;
        ?>
">
                            </select>
                        </div>
                        <div class="birs_error" id="birs_appointment_service_error"></div>
                    </li>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Provider', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <select id="birs_appointment_staff" name="birs_appointment_staff"
                                data-value="<?php 
        echo $staff_id;
        ?>
">
                            </select>
                        </div>
                        <div class="birs_error" id="birs_appointment_staff_error"></div>
                    </li>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Date', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <div id="birs_appointment_datepicker"></div>
                            <input id="birs_appointment_date" name="birs_appointment_date" type="hidden" value="<?php 
        echo $date;
        ?>
">
                        </div>
                        <div class="birs_error" id="birs_appointment_date_error"></div>
                    </li>
                    <li class="birs_form_field">
                        <label>
                            <?php 
        _e('Time', 'birchschedule');
        ?>
                        </label>
                        <div class="birs_field_content">
                            <select id="birs_appointment_time" name="birs_appointment_time" size="1">
                                <?php 
        $birchpress->util->render_html_options($options, $time);
        ?>
                            </select>
                        </div>
                        <div class="birs_error" id="birs_appointment_time_error"></div>
                    </li>
                </ul>
<?php 
        return ob_get_clean();
    });
});
Esempio n. 30
0
birch_ns('birchschedule.view.settings', function ($ns) {
    $_ns_data = new stdClass();
    birch_defn($ns, 'init', function () use($ns, $_ns_data) {
        $_ns_data->active_tab = '';
        $_ns_data->tabs = array();
        add_action('admin_init', array($ns, 'wp_admin_init'));
        $ns->init_capabilities();
    });
    birch_defn($ns, 'wp_admin_init', function () use($ns, $_ns_data) {
        if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'birchschedule_settings') {
            if (isset($_GET['tab'])) {
                $_ns_data->active_tab = $_GET['tab'];
            } else {
                $_ns_data->active_tab = 'general';
            }
            $_ns_data->tabs = $ns->get_tabs();
            $ns->init_tab(array('tab' => $_ns_data->active_tab));
            add_action('birchschedule_view_render_settings_page', array($ns, 'render_admin_page'));
            add_action('admin_enqueue_scripts', array($ns, 'enqueue_scripts'));
        }
    });
    birch_defn($ns, 'enqueue_scripts', function ($hook) use($ns) {
        global $birchschedule;
        if ($birchschedule->view->get_page_hook('settings') !== $hook) {
            return;
        }
        $birchschedule->view->register_3rd_scripts();
        $birchschedule->view->register_3rd_styles();
        $birchschedule->view->enqueue_scripts(array('birchschedule_view_admincommon'));
    });
    birch_defn($ns, 'get_tabs', function () {
        return array();
    });
    birch_defn($ns, 'get_tab_lookup_config', function () {
        return array('key' => 'tab', 'lookup_table' => array());
    });
    birch_defmulti($ns, 'init_tab', $ns->get_tab_lookup_config, function ($arg) {
    });
    birch_defn($ns, 'compare_tab_order', function ($a, $b) {
        if ($a['order'] == $b['order']) {
            return 0;
        }
        return $a['order'] < $b['order'] ? -1 : 1;
    });
    birch_defn($ns, 'render_admin_page', function () use($ns, $_ns_data) {
        global $birchschedule;
        $setting_page_url = admin_url("admin.php") . "?page=birchschedule_settings";
        uasort($_ns_data->tabs, array($ns, 'compare_tab_order'));
        $birchschedule->view->show_notice();
        ?>
        <div class="wrap">
            <h2 class="nav-tab-wrapper">
<?php 
        if (is_array($_ns_data->tabs)) {
            foreach ($_ns_data->tabs as $tab_name => $tab) {
                $active_class = "";
                if ($_ns_data->active_tab == $tab_name) {
                    $active_class = "nav-tab-active";
                }
                ?>
                        <a href='<?php 
                echo $setting_page_url . "&tab={$tab_name}";
                ?>
' class="nav-tab <?php 
                echo $active_class;
                ?>
"><?php 
                echo $tab['title'];
                ?>
</a>
<?php 
            }
        }
        ?>
            </h2>
<?php 
        if (isset($_ns_data->tabs[$_ns_data->active_tab])) {
            $_ns_data->active_tab = $_ns_data->tabs[$_ns_data->active_tab];
            if ($_ns_data->active_tab) {
                call_user_func($_ns_data->active_tab['action']);
            }
        }
        ?>
        </div>
<?php 
    });
    birch_defn($ns, 'get_tab_metabox_category', function ($tab_name) {
        return $tab_name . '_main';
    });
    birch_defn($ns, 'get_tab_page_hook', function ($tab_name) {
        return 'birchschedule_page_settings_tab_' . $tab_name;
    });
    birch_defn($ns, 'get_tab_save_action_name', function ($tab_name) {
        return 'birchschedule_save_options_' . $tab_name;
    });
    birch_defn($ns, 'get_tab_options_name', function ($tab_name) {
        return 'birchschedule_options_' . $tab_name;
    });
    birch_defn($ns, 'get_tab_transient_message_name', function ($tab_name) {
        return "birchschedule_" . $tab_name . "_info";
    });
    birch_defn($ns, 'save_tab_options', function ($tab_name, $message) use($ns) {
        $save_action_name = $ns->get_tab_save_action_name($tab_name);
        check_admin_referer($save_action_name);
        $options_name = $ns->get_tab_options_name($tab_name);
        if (isset($_POST[$options_name])) {
            $options = stripslashes_deep($_POST[$options_name]);
            update_option($options_name, $options);
        }
        $transient_name = $ns->get_tab_transient_message_name($tab_name);
        set_transient($transient_name, $message, 60);
        $orig_url = $_POST['_wp_http_referer'];
        wp_redirect($orig_url);
        exit;
    });
    birch_defn($ns, 'render_tab_page', function ($tab_name) use($ns) {
        global $birchschedule;
        $page_hook = $ns->get_tab_page_hook($tab_name);
        $screen = $birchschedule->view->get_screen($page_hook);
        $save_action_name = $ns->get_tab_save_action_name($tab_name);
        $options_name = $ns->get_tab_options_name($tab_name);
        $options = get_option($options_name);
        if ($options && isset($options['version'])) {
            $version = $options['version'];
        } else {
            $version = false;
        }
        $block_id = "birchschedule_" . $tab_name;
        ?>
        <style type="text/css">
            #notification_main-sortables .hndle {
                cursor: pointer;
            }
            #notification_main-sortables .wp-tab-panel {
                max-height: 500px;
            }
        </style>
        <div id="<?php 
        echo $block_id;
        ?>
" class="wrap">
            <form method="post" action="<?php 
        echo admin_url('admin-post.php');
        ?>
">
                <?php 
        wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
        ?>
                <?php 
        wp_nonce_field($save_action_name);
        ?>
                <input type="hidden" name="action" value="<?php 
        echo $save_action_name;
        ?>
" />
                <?php 
        if ($version) {
            ?>
                    <input type="hidden" name="<?php 
            echo $options_name . '[version]';
            ?>
" value="<?php 
            echo $version;
            ?>
" />
                <?php 
        }
        ?>
                <div id="poststuff">
                    <div id="post-body" class="metabox-holder columns-1">
                        <div id="postbox-container-1" class="postbox-container">
                            <?php 
        do_meta_boxes($screen, $ns->get_tab_metabox_category($tab_name), array());
        ?>
                        </div>
                    </div>
                    <br class="clear" />
                </div>
                <input type="submit" name="submit"
                    value="<?php 
        _e('Save changes', 'birchschedule');
        ?>
"
                    class="button-primary" />
            </form>
        </div>
        <script type="text/javascript">
            //<![CDATA[
            jQuery(document).ready( function($) {
                postboxes.init = function() {};
                postboxes.add_postbox_toggles('<?php 
        echo $ns->get_tab_page_hook($tab_name);
        ?>
');
<?php 
        $info_key = $ns->get_tab_transient_message_name($tab_name);
        $info = get_transient($info_key);
        if (false !== $info) {
            ?>
                $.jGrowl('<?php 
            echo esc_js($info);
            ?>
', {
                        life: 1000,
                        position: 'center',
                        header: '<?php 
            _e('&nbsp', 'birchschedule');
            ?>
'
                    });
<?php 
            delete_transient($info_key);
        }
        ?>
            });
            //]]>
        </script>
<?php 
    });
    birch_defn($ns, 'get_post_types', function () {
        return array('birs_appointment', 'birs_client', 'birs_location', 'birs_staff', 'birs_service', 'birs_payment');
    });
    birch_defn($ns, 'get_core_capabilities', function () use($ns) {
        $capabilities = array();
        $capabilities['birs_core'] = array("manage_birs_settings");
        $capability_types = $ns->get_post_types();
        foreach ($capability_types as $capability_type) {
            $capabilities[$capability_type] = array("edit_{$capability_type}", "read_{$capability_type}", "delete_{$capability_type}", "edit_{$capability_type}s", "edit_others_{$capability_type}s", "publish_{$capability_type}s", "read_private_{$capability_type}s", "delete_{$capability_type}s", "delete_private_{$capability_type}s", "delete_published_{$capability_type}s", "delete_others_{$capability_type}s", "edit_private_{$capability_type}s", "edit_published_{$capability_type}s");
        }
        return $capabilities;
    });
    birch_defn($ns, 'init_capabilities', function () use($ns) {
        global $wp_roles, $birchschedule;
        if (class_exists('WP_Roles')) {
            if (!isset($wp_roles)) {
                $wp_roles = new WP_Roles();
            }
        }
        if (is_object($wp_roles)) {
            $capabilities = $ns->get_core_capabilities();
            foreach ($capabilities as $cap_group) {
                foreach ($cap_group as $cap) {
                    $wp_roles->add_cap('administrator', $cap);
                }
            }
        }
    });
});