<?php

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;
<?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;
    });
});
<?php

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;
<?php

birch_ns('birchschedule.view.locations', 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'));
        birch_defmethod($birchschedule->view, 'load_page_edit', 'birs_location', $ns->load_page_edit);
        birch_defmethod($birchschedule->view, 'enqueue_scripts_edit', 'birs_location', $ns->enqueue_scripts_edit);
        birch_defmethod($birchschedule->view, 'save_post', 'birs_location', $ns->save_post);
    });
    birch_defn($ns, 'wp_init', function () use($ns) {
        $ns->register_post_type();
    });
    birch_defn($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);
    });
    birch_defn($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);
    });
    birch_defn($ns, 'register_post_type', function () use($ns) {
        register_post_type('birs_location', $ns->get_register_options());
    });
    birch_defn($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');
<?php

birch_ns('birchschedule.gsettings.upgrader', function ($ns) {
    global $birchschedule;
    $default_options_1_0 = array('currency' => 'USD', 'default_calendar_view' => 'agendaWeek');
    $default_options_1_1 = $default_options_1_0;
    $default_options_1_1['version'] = '1.1';
    $default_options = $default_options_1_1;
    birch_defn($ns, 'init', function () use(&$default_options, $ns, $birchschedule) {
        $options = get_option('birchschedule_options');
        if ($options === false) {
            add_option('birchschedule_options', $default_options);
        }
        birch_defmethod($birchschedule, 'upgrade_module', 'gsettings', $ns->upgrade_module);
    });
    birch_defn($ns, 'upgrade_module', function () use($ns) {
        $ns->init();
        $ns->upgrade_1_0_to_1_1();
    });
    birch_defn($ns, 'get_db_version_options', function () {
        $options = get_option('birchschedule_options');
        if (isset($options['version'])) {
            return $options['version'];
        } else {
            return '1.0';
        }
    });
    birch_defn($ns, 'upgrade_1_0_to_1_1', function () use($ns) {
        $version = $ns->get_db_version_options();
        if ($version !== '1.0') {
            return;
<?php

birch_ns('birchschedule.model.cpt.service', function ($ns) {
    global $birchschedule;
    birch_defn($ns, 'init', function () use($ns, $birchschedule) {
        birch_defmethod($birchschedule->model, 'pre_save', 'birs_service', $ns->pre_save);
        birch_defmethod($birchschedule->model, 'post_get', 'birs_service', $ns->post_get);
    });
    birch_defn($ns, 'pre_save', function ($service, $config) {
        if (isset($service['_birs_service_pre_payment_fee'])) {
            $service['_birs_service_pre_payment_fee'] = serialize($service['_birs_service_pre_payment_fee']);
        }
        if (isset($service['_birs_assigned_staff'])) {
            $service['_birs_assigned_staff'] = serialize($service['_birs_assigned_staff']);
        }
        return $service;
    });
    birch_defn($ns, 'post_get', function ($service) {
        birch_assert(is_array($service) && isset($service['post_type']));
        if (isset($service['_birs_service_pre_payment_fee'])) {
            $service['_birs_service_pre_payment_fee'] = unserialize($service['_birs_service_pre_payment_fee']);
            if (!$service['_birs_service_pre_payment_fee']) {
                $service['_birs_service_pre_payment_fee'] = array();
            }
        }
        if (isset($service['_birs_assigned_staff'])) {
            $service['_birs_assigned_staff'] = unserialize($service['_birs_assigned_staff']);
            if (!$service['_birs_assigned_staff']) {
                $service['_birs_assigned_staff'] = array();
            }
        }
<?php

birch_ns('birchschedule.view.services', 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'));
        birch_defmethod($birchschedule->view, 'load_page_edit', 'birs_service', $ns->load_page_edit);
        birch_defmethod($birchschedule->view, 'enqueue_scripts_edit', 'birs_service', $ns->enqueue_scripts_edit);
        birch_defmethod($birchschedule->view, 'save_post', 'birs_service', $ns->save_post);
    });
    birch_defn($ns, 'wp_init', function () use($ns) {
        $ns->register_post_type();
    });
    birch_defn($ns, 'wp_admin_init', function () use($ns) {
        add_filter('manage_edit-birs_service_columns', array($ns, 'get_edit_columns'));
        add_action('manage_birs_service_posts_custom_column', array($ns, 'render_custom_columns'), 2);
    });
    birch_defn($ns, 'register_post_type', function () use($ns) {
        register_post_type('birs_service', array('labels' => array('name' => __('Services', 'birchschedule'), 'singular_name' => __('Service', 'birchschedule'), 'add_new' => __('Add Service', 'birchschedule'), 'add_new_item' => __('Add New Service', 'birchschedule'), 'edit' => __('Edit', 'birchschedule'), 'edit_item' => __('Edit Service', 'birchschedule'), 'new_item' => __('New Service', 'birchschedule'), 'view' => __('View Service', 'birchschedule'), 'view_item' => __('View Service', 'birchschedule'), 'search_items' => __('Search Services', 'birchschedule'), 'not_found' => __('No Services found', 'birchschedule'), 'not_found_in_trash' => __('No Services found in trash', 'birchschedule'), 'parent' => __('Parent Service', 'birchschedule')), 'description' => __('This is where services are stored.', 'birchschedule'), 'public' => false, 'show_ui' => true, 'capability_type' => 'birs_service', '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', 'editor'), 'has_archive' => false));
    });
    birch_defn($ns, 'get_edit_columns', function ($columns) {
        $columns = array();
        $columns["cb"] = "<input type=\"checkbox\" />";
        $columns["title"] = __("Service Name", 'birchschedule');
        $columns["description"] = __("Description", 'birchschedule');
        return $columns;
    });
    birch_defn($ns, 'render_custom_columns', function ($column) {
        global $post;
        if ($column == 'description') {
<?php

birch_ns('birchschedule.view.staff', 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'));
        birch_defmethod($birchschedule->view, 'load_page_edit', 'birs_staff', $ns->load_page_edit);
        birch_defmethod($birchschedule->view, 'enqueue_scripts_edit', 'birs_staff', $ns->enqueue_scripts_edit);
        birch_defmethod($birchschedule->view, 'save_post', 'birs_staff', $ns->save_post);
        birch_defmethod($birchschedule->view, 'pre_save_post', 'birs_staff', $ns->pre_save_post);
    });
    birch_defn($ns, 'wp_init', function () use($ns) {
        $ns->register_post_type();
    });
    birch_defn($ns, 'wp_admin_init', function () use($ns) {
        add_action('wp_ajax_birchschedule_view_staff_new_schedule', array($ns, 'ajax_new_schedule'));
        add_filter('manage_edit-birs_staff_columns', array($ns, 'get_edit_columns'));
        add_action('manage_birs_staff_posts_custom_column', array($ns, 'render_custom_columns'), 2);
    });
    birch_defn($ns, 'register_post_type', function () {
        register_post_type('birs_staff', array('labels' => array('name' => __('Providers', 'birchschedule'), 'singular_name' => __('Provider', 'birchschedule'), 'add_new' => __('Add Provider', 'birchschedule'), 'add_new_item' => __('Add New Provider', 'birchschedule'), 'edit' => __('Edit', 'birchschedule'), 'edit_item' => __('Edit Provider', 'birchschedule'), 'new_item' => __('New Provider', 'birchschedule'), 'view' => __('View Provider', 'birchschedule'), 'view_item' => __('View Provider', 'birchschedule'), 'search_items' => __('Search Providers', 'birchschedule'), 'not_found' => __('No Providers found', 'birchschedule'), 'not_found_in_trash' => __('No Providers found in trash', 'birchschedule'), 'parent' => __('Parent Provider', 'birchschedule')), 'description' => __('This is where provider are stored.', 'birchschedule'), 'public' => false, 'show_ui' => true, 'capability_type' => 'birs_staff', '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', 'editor'), 'has_archive' => false));
    });
    birch_defn($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'));
    });
    birch_defn($ns, 'enqueue_scripts_edit', function ($arg) use($ns) {
        global $birchschedule;
        $birchschedule->view->register_3rd_scripts();
        $birchschedule->view->register_3rd_styles();