diff --git a/public_html/wp-content/plugins/camptix/camptix.php b/public_html/wp-content/plugins/camptix/camptix.php
index 1e9325906..f1400a2d7 100644
--- a/public_html/wp-content/plugins/camptix/camptix.php
+++ b/public_html/wp-content/plugins/camptix/camptix.php
@@ -68,6 +68,7 @@ function __construct() {
require( dirname( __FILE__ ) . '/inc/class-camptix-addon.php' );
require( dirname( __FILE__ ) . '/inc/class-camptix-payment-method.php' );
require( dirname( __FILE__ ) . '/inc/class-camptix-badges.php' );
+ require( dirname( __FILE__ ) . '/inc/class-camptix-admin.php' );
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once( dirname( __FILE__ ) . '/inc/class-wp-cli-commands.php' );
@@ -122,9 +123,6 @@ function init() {
// Stuff that might need to redirect, thus not in [camptix] shortcode.
add_action( 'template_redirect', array( $this, 'template_redirect' ), 9 ); // earlier than the others.
- add_action( 'admin_init', array( $this, 'admin_init' ) );
- add_action( 'admin_menu', array( $this, 'admin_menu' ) );
- add_action( 'admin_head', array( $this, 'admin_menu_fix' ) );
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
// Handle meta for our post types.
@@ -151,7 +149,6 @@ function init() {
$this->add_resend_notices();
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
// Sort of admin_init but on the Tickets > Tools page only.
add_action( 'load-tix_ticket_page_camptix_tools', array( $this, 'summarize_extra_fields' ) );
@@ -449,7 +446,7 @@ function notify_shortcode_ticket_url( $atts ) {
* grabs all the available tickets questions and adds them to Summarize.
*/
function summarize_extra_fields() {
- if ( 'summarize' != $this->get_tools_section() )
+ if ( 'summarize' != Camptix_Admin::get_tools_section() )
return;
// Adds all questions to Summarize and register the callback that counts all the things.
@@ -511,59 +508,6 @@ function enqueue_scripts() {
) );
}
- function admin_enqueue_scripts() {
- global $wp_query;
-
- if ( ! $wp_query->query_vars ) { // only on singular admin pages
- if ( 'tix_ticket' == get_post_type() || 'tix_coupon' == get_post_type() ) {
- }
- }
-
- // Let's see whether to include admin.css and admin.js
- if ( is_admin() ) {
- $screen = get_current_screen();
- $post_types = array( 'tix_ticket', 'tix_coupon', 'tix_email', 'tix_attendee' );
- $pages = array( 'camptix_options', 'camptix_tools' );
- $screen_ids = array( 'dashboard' );
- if (
- ( in_array( get_post_type(), $post_types ) ) ||
- ( in_array( $screen->id, $screen_ids ) ) ||
- ( isset( $_REQUEST['post_type'] ) && in_array( $_REQUEST['post_type'], $post_types ) ) ||
- ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $pages ) )
- ) {
- wp_enqueue_script( 'jquery-ui-datepicker' );
- wp_enqueue_style(
- 'jquery-ui',
- plugins_url( '/external/jquery-ui.css', __FILE__ ),
- array(),
- filemtime( __DIR__ . '/external/jquery-ui.css' )
- );
-
- wp_enqueue_style(
- 'camptix-admin',
- plugins_url( '/admin.css', __FILE__ ),
- array(),
- filemtime( __DIR__ . '/admin.css' )
- );
-
- wp_enqueue_script(
- 'camptix-admin',
- plugins_url( '/admin.js', __FILE__ ),
- array( 'jquery', 'jquery-ui-datepicker', 'backbone' ),
- filemtime( __DIR__ . '/admin.js' )
- );
-
- wp_dequeue_script( 'autosave' );
- }
- }
-
- $screen = get_current_screen();
- if ( 'tix_ticket_page_camptix_options' == $screen->id ) {
- wp_enqueue_script( 'jquery-ui-datepicker' );
- wp_enqueue_style( 'jquery-ui', plugins_url( '/external/jquery-ui.css', __FILE__ ), array(), $this->version );
- }
- }
-
/**
* Filters column fields for our new post types, adds extra columns
* and registers callback actions to render column callback.
@@ -1556,121 +1500,7 @@ protected function run_upgrade_parts( $from ) {
return $this->version;
}
- /**
- * Runs during admin_init, mainly for Settings API things.
- */
- function admin_init() {
- register_setting( 'camptix_options', 'camptix_options', array( $this, 'validate_options' ) );
-
- // Add settings fields
- $this->menu_setup_controls();
-
- // Let's add some help tabs.
- require_once dirname( __FILE__ ) . '/help.php';
- }
-
- function menu_setup_controls() {
- wp_enqueue_script( 'jquery-ui' );
- $section = $this->get_setup_section();
-
- add_action( 'admin_notices', array( $this, 'admin_notice_supported_currencies' ) );
-
- switch ( $section ) {
- case 'general':
- add_settings_section( 'general', __( 'General Configuration', 'wordcamporg' ), array( $this, 'menu_setup_section_general' ), 'camptix_options' );
- $this->add_settings_field_helper( 'event_name', __( 'Event Name', 'wordcamporg' ), 'field_text' );
- $this->add_settings_field_helper( 'currency', __( 'Currency', 'wordcamporg' ), 'field_currency' );
-
- $this->add_settings_field_helper( 'refunds_enabled', __( 'Enable Refunds', 'wordcamporg' ), 'field_enable_refunds', false,
- __( "This will allows your customers to refund their tickets purchase by filling out a simple refund form.", 'wordcamporg' )
- );
-
- break;
- case 'payment':
- foreach ( $this->get_available_payment_methods() as $key => $payment_method ) {
- $payment_method_obj = $this->get_payment_method_by_id( $key );
-
- add_settings_section( 'payment_' . $key, $payment_method_obj->name, array( $payment_method_obj, '_camptix_settings_section_callback' ), 'camptix_options' );
- add_settings_field( 'payment_method_' . $key . '_enabled', __( 'Enabled', 'wordcamporg' ), array( $payment_method_obj, '_camptix_settings_enabled_callback' ), 'camptix_options', 'payment_' . $key, array(
- 'name' => "camptix_options[payment_methods][{$key}]",
- 'value' => isset( $this->options['payment_methods'][$key] ) ? (bool) $this->options['payment_methods'][ $key ] : false,
- ) );
-
- $payment_method_obj->payment_settings_fields();
- }
- break;
- case 'email-templates':
- add_settings_section( 'general', __( 'E-mail Templates', 'wordcamporg' ), array( $this, 'menu_setup_section_email_templates' ), 'camptix_options' );
- $this->add_settings_field_helper( 'email_template_single_purchase', __( 'Single purchase', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_multiple_purchase', __( 'Multiple purchase', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_multiple_purchase_receipt', __( 'Multiple purchase (receipt)', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_pending_succeeded', __( 'Pending Payment Succeeded', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_pending_failed', __( 'Pending Payment Failed', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_single_refund', __( 'Single Refund', 'wordcamporg' ), 'field_textarea' );
- $this->add_settings_field_helper( 'email_template_multiple_refund', __( 'Multiple Refund', 'wordcamporg' ), 'field_textarea' );
-
- foreach ( apply_filters( 'camptix_custom_email_templates', array() ) as $key => $template ) {
- $this->add_settings_field_helper( $key, $template['title'], $template['callback_method'] );
- }
-
- // Add a reset templates button
- add_action( 'camptix_setup_buttons', array( $this, 'setup_buttons_reset_templates' ) );
- break;
- case 'beta':
-
- if ( ! $this->beta_features_enabled )
- break;
-
- add_settings_section( 'general', __( 'Beta Features', 'wordcamporg' ), array( $this, 'menu_setup_section_beta' ), 'camptix_options' );
-
- $this->add_settings_field_helper( 'reservations_enabled', __( 'Enable Reservations', 'wordcamporg' ), 'field_yesno', false,
- __( "Reservations is a way to make sure that a certain group of people, can always purchase their tickets, even if you sell out fast.", 'wordcamporg' )
- );
-
- if ( current_user_can( $this->caps['refund_all'] ) ) {
- $this->add_settings_field_helper( 'refund_all_enabled', __( 'Enable Refund All', 'wordcamporg' ), 'field_yesno', false,
- __( "Allows to refund all purchased tickets by an admin via the Tools menu.", 'wordcamporg' )
- );
- }
-
- $this->add_settings_field_helper( 'archived', __( 'Archived Event', 'wordcamporg' ), 'field_yesno', false,
- __( "Archived events are read-only.", 'wordcamporg' )
- );
- break;
- default:
- do_action( 'camptix_menu_setup_controls', $section );
- break;
- }
- }
-
- function menu_setup_section_beta() {
- echo '
' . __( 'Beta features are things that are being worked on in CampTix, but are not quite finished yet. You can try them out, but we do not recommend doing that in a live environment on a real event. If you have any kind of feedback on any of the beta features, please let us know.', 'wordcamporg' ) . '
';
- }
- function menu_setup_section_email_templates() {
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
- ' . __( 'General configuration.', 'wordcamporg' ) . '';
- }
/**
* I don't like repeating code, so here's a helper for simple fields.
@@ -2027,255 +1857,6 @@ function format_name_string( $name_string, $given_name, $surname ) {
return $name_string;
}
- /**
- * Oh the holy admin menu!
- */
- function admin_menu() {
- add_submenu_page( 'edit.php?post_type=tix_ticket', __( 'Tools', 'wordcamporg' ), __( 'Tools', 'wordcamporg' ), $this->caps['manage_tools'], 'camptix_tools', array( $this, 'menu_tools' ) );
- add_submenu_page( 'edit.php?post_type=tix_ticket', __( 'Setup', 'wordcamporg' ), __( 'Setup', 'wordcamporg' ), $this->caps['manage_options'], 'camptix_options', array( $this, 'menu_setup' ) );
- add_submenu_page( 'edit.php?post_type=tix_ticket', __( 'Profile Badges', 'wordcamporg' ), __( 'Profile Badges', 'wordcamporg' ), $this->caps['manage_options'], 'camptix_badges', 'Camptix\Profile_Badges\menu_badges' );
- remove_submenu_page( 'edit.php?post_type=tix_ticket', 'post-new.php?post_type=tix_ticket' );
- }
-
- /**
- * When squeezing several custom post types under one top-level menu item, WordPress
- * tends to get confused which menu item is currently active, especially around post-new.php.
- * This function runs during admin_head and hacks into some of the global variables that are
- * used to construct the menu.
- */
- function admin_menu_fix() {
- global $self, $parent_file, $submenu_file, $plugin_page, $pagenow, $typenow;
-
- // Make sure Coupons is selected when adding a new coupon
- if ( 'post-new.php' == $pagenow && 'tix_coupon' == $typenow )
- $submenu_file = 'edit.php?post_type=tix_coupon';
-
- // Make sure Attendees is selected when adding a new attendee
- if ( 'post-new.php' == $pagenow && 'tix_attendee' == $typenow )
- $submenu_file = 'edit.php?post_type=tix_attendee';
-
- // Make sure Tickets is selected when creating a new ticket
- if ( 'post-new.php' == $pagenow && 'tix_ticket' == $typenow )
- $submenu_file = 'edit.php?post_type=tix_ticket';
- }
-
- /**
- * The Tickets > Setup screen, uses the Settings API.
- */
- function menu_setup() {
- ?>
-
-
-
-
menu_setup_tabs(); ?>
-
-
- Tools? This tells
- * us which tab is currently active.
- */
- function get_setup_section() {
- if ( isset( $_REQUEST['tix_section'] ) )
- return strtolower( $_REQUEST['tix_section'] );
-
- return 'general';
- }
-
- /**
- * Tabs for Tickets > Tools, outputs the markup.
- */
- function menu_setup_tabs() {
- $current_section = $this->get_setup_section();
- $sections = array(
- 'general' => __( 'General', 'wordcamporg' ),
- 'payment' => __( 'Payment', 'wordcamporg' ),
- 'email-templates' => __( 'E-mail Templates', 'wordcamporg' ),
- );
-
- if ( $this->beta_features_enabled )
- $sections['beta'] = __( 'Beta', 'wordcamporg' );
-
- $sections = apply_filters( 'camptix_setup_sections', $sections );
-
- foreach ( $sections as $section_key => $section_caption ) {
- $active = $current_section === $section_key ? 'nav-tab-active' : '';
- $url = add_query_arg( 'tix_section', $section_key );
- echo '' . esc_html( $section_caption ) . '';
- }
- }
-
- /**
- * The Tickets > Tools screen, doesn't use the settings API, but does use tabs.
- */
- function menu_tools() {
- ?>
-
-
-
- menu_tools_tabs(); ?>
- get_tools_section();
- if ( $section == 'summarize' )
- $this->menu_tools_summarize();
- elseif ( $section == 'revenue' )
- $this->menu_tools_revenue();
- elseif ( $section == 'export' )
- $this->menu_tools_export();
- elseif ( $section == 'notify' )
- $this->menu_tools_notify();
- elseif ( $section == 'refund' && ! $this->options['archived'] )
- $this->menu_tools_refund();
- else
- do_action( 'camptix_menu_tools_' . $section );
- ?>
-
- Tools? This tells
- * us which tab is currently active.
- */
- function get_tools_section() {
- if ( isset( $_REQUEST['tix_section'] ) )
- return strtolower( $_REQUEST['tix_section'] );
-
- return 'summarize';
- }
-
- /**
- * Tabs for Tickets > Tools, outputs the markup.
- */
- function menu_tools_tabs() {
- $current_section = $this->get_tools_section();
- $sections = apply_filters( 'camptix_menu_tools_tabs', array(
- 'summarize' => __( 'Summarize', 'wordcamporg' ),
- 'revenue' => __( 'Revenue', 'wordcamporg' ),
- 'export' => __( 'Export', 'wordcamporg' ),
- 'notify' => __( 'Notify', 'wordcamporg' ),
- ) );
-
- if ( current_user_can( $this->caps['refund_all'] ) && ! $this->options['archived'] && $this->options['refund_all_enabled'] )
- $sections['refund'] = __( 'Refund', 'wordcamporg' );
-
- foreach ( $sections as $section_key => $section_caption ) {
- $active = $current_section === $section_key ? 'nav-tab-active' : '';
- $url = add_query_arg( 'tix_section', $section_key );
- echo '' . esc_html( $section_caption ) . '';
- }
- }
-
- /**
- * Tools > Summarize, the screen that outputs the summary tables,
- * provides an export option, powered by the summarize_admin_init method,
- * hooked (almost) at admin_init, because of additional headers. Doesn't use
- * the Settings API so check for nonces/referrers and caps.
- * @see summarize_admin_init()
- */
- function menu_tools_summarize() {
- $summarize_by = isset( $_POST['tix_summarize_by'] ) ? $_POST['tix_summarize_by'] : 'ticket';
- ?>
-
-
- get_available_summary_fields() ) ) : ?>
- get_available_summary_fields();
- $summary = $this->get_summary( $summarize_by );
- $summary_title = $fields[ $summarize_by ];
- $alt = '';
-
- $rows = array();
- foreach ( $summary as $entry )
- $rows[] = array(
- esc_html( $summary_title ) => esc_html( $entry['label'] ),
- __( 'Count', 'wordcamporg' ) => esc_html( $entry['count'] )
- );
-
- // Render the widefat table.
- $this->table( $rows, 'widefat tix-summarize' );
- ?>
-
-
- caps['manage_tools'] ) || 'summarize' != $this->get_tools_section() )
- return;
-
- if ( isset( $_POST['tix_export_summary'], $_POST['tix_summarize_by'] ) && check_admin_referer( 'tix_summarize' ) ) {
- $summarize_by = $_POST['tix_summarize_by'];
- if ( ! array_key_exists( $summarize_by, $this->get_available_summary_fields() ) )
- return;
-
- $fields = $this->get_available_summary_fields();
- $summary = $this->get_summary( $summarize_by );
- $summary_title = $fields[ $summarize_by ];
- $filename = sprintf( 'camptix-summary-%s-%s.csv', sanitize_title_with_dashes( $summary_title ), date( 'Y-m-d' ) );
-
- header( 'Content-Type: text/csv' );
- header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
- header( "Cache-control: private" );
- header( 'Pragma: private' );
- header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
-
- $stream = fopen( "php://output", 'w' );
-
- $headers = array( $summary_title, __( 'Count', 'wordcamporg' ) );
- fputcsv( $stream, self::esc_csv( $headers ) );
- foreach ( $summary as $entry ) {
- fputcsv( $stream, self::esc_csv( $entry ), ',', '"' );
- }
-
- fclose( $stream );
- die();
- }
- }
-
/**
* Returns a summary of all attendees. A lot of @magic here and
* watch out for actions and filters.
@@ -2767,7 +2348,7 @@ function menu_tools_export() {
function export_admin_init() {
global $post;
- if ( ! current_user_can( $this->caps['manage_tools'] ) || 'export' != $this->get_tools_section() )
+ if ( ! current_user_can( $this->caps['manage_tools'] ) || 'export' != Camptix_Admin::get_tools_section() )
return;
if ( isset( $_POST['tix_export_submit'], $_POST['tix_export_to'] ) && check_admin_referer( 'tix_export' ) ) {
@@ -3663,7 +3244,7 @@ function menu_tools_refund() {
* Runs before the page markup is printed so can add settings errors.
*/
function menu_tools_refund_admin_init() {
- if ( ! current_user_can( $this->caps['refund_all'] ) || 'refund' != $this->get_tools_section() )
+ if ( ! current_user_can( $this->caps['refund_all'] ) || 'refund' != Camptix_Admin::get_tools_section() )
return;
// Display results of completed refund-all job
@@ -8215,49 +7796,6 @@ function shutdown() {
$this->flush_tickets_page_seriously();
}
- /**
- * Helper function to create admin tables, give me a
- * $rows array and I'll do the rest.
- */
- function table( $rows, $classes='widefat' ) {
-
- if ( ! is_array( $rows ) || ! isset( $rows[0] ) )
- return;
-
- $alt = '';
- ?>
-
-
-
-
-
-
-
- |
-
-
-
-
-
-
-
-
-
- $value ) : ?>
-
-
- |
-
-
-
-
-
- caps['manage_tools'], 'camptix_tools', array( $this, 'menu_tools' ) );
+ add_submenu_page( 'edit.php?post_type=tix_ticket', __( 'Setup', 'wordcamporg' ), __( 'Setup', 'wordcamporg' ), $this->caps['manage_options'], 'camptix_options', array( $this, 'menu_setup' ) );
+ add_submenu_page( 'edit.php?post_type=tix_ticket', __( 'Badges', 'wordcamporg' ), __( 'Badges', 'wordcamporg' ), $this->caps['manage_options'], 'camptix_badges', array( $this, 'menu_badges' ) );
+ add_submenu_page( 'edit.php?post_type=tix_ticket', __( 'Profile Badges', 'wordcamporg' ), __( 'Profile Badges', 'wordcamporg' ), $this->caps['manage_options'], 'camptix_badges', 'Camptix\Profile_Badges\menu_badges' );
+ remove_submenu_page( 'edit.php?post_type=tix_ticket', 'post-new.php?post_type=tix_ticket' );
+ }
+
+ /**
+ * When squeezing several custom post types under one top-level menu item, WordPress
+ * tends to get confused which menu item is currently active, especially around post-new.php.
+ * This function runs during admin_head and hacks into some of the global variables that are
+ * used to construct the menu.
+ */
+ public function admin_menu_fix() {
+ global $self, $parent_file, $submenu_file, $plugin_page, $pagenow, $typenow;
+
+ // Make sure Coupons is selected when adding a new coupon.
+ if ( 'post-new.php' == $pagenow && 'tix_coupon' == $typenow ) {
+ add_filter( 'submenu_file',
+ function () {
+ return 'edit.php?post_type=tix_coupon';
+ }
+ );
+ }
+
+ // Make sure Attendees is selected when adding a new attendee.
+ if ( 'post-new.php' == $pagenow && 'tix_attendee' == $typenow ) {
+ add_filter( 'submenu_file',
+ function () {
+ return 'edit.php?post_type=tix_attendee';
+ }
+ );
+ }
+
+ // Make sure Tickets is selected when creating a new ticket.
+ if ( 'post-new.php' == $pagenow && 'tix_ticket' == $typenow ) {
+ add_filter( 'submenu_file',
+ function () {
+ return 'edit.php?post_type=tix_ticket';
+ }
+ );
+ }
+ }
+
+ /**
+ * The Tickets > Setup screen, uses the Settings API.
+ */
+ public function menu_setup() {
+ ?>
+
+
+
+
menu_setup_tabs(); ?>
+
+
+ Tools, outputs the markup.
+ */
+ public function menu_setup_tabs() {
+ $current_section = $this->get_setup_section();
+ $sections = array(
+ 'general' => __( 'General', 'wordcamporg' ),
+ 'payment' => __( 'Payment', 'wordcamporg' ),
+ 'email-templates' => __( 'E-mail Templates', 'wordcamporg' ),
+ );
+
+ if ( $this->beta_features_enabled ) {
+ $sections['beta'] = __( 'Beta', 'wordcamporg' );
+ }
+
+ $sections = apply_filters( 'camptix_setup_sections', $sections );
+
+ foreach ( $sections as $section_key => $section_caption ) {
+ $active = $current_section === $section_key ? 'nav-tab-active' : '';
+ $url = add_query_arg( 'tix_section', $section_key );
+ echo '' . esc_html( $section_caption ) . '';
+ }
+ }
+
+ /**
+ * The Tickets > Tools screen, doesn't use the settings API, but does use tabs.
+ */
+ public function menu_tools() {
+ ?>
+
+
+
+ menu_tools_tabs(); ?>
+ get_tools_section();
+ if ( 'summarize' == $section ) {
+ $this->menu_tools_summarize();
+ } elseif ( 'revenue' == $section ) {
+ $this->menu_tools_revenue();
+ } elseif ( 'export' == $section ) {
+ $this->menu_tools_export();
+ } elseif ( 'notify' == $section ) {
+ $this->menu_tools_notify();
+ } elseif ( 'refund' == $section && ! $this->options['archived'] ) {
+ $this->menu_tools_refund();
+ } else {
+ do_action( 'camptix_menu_tools_' . $section );
+ }
+ ?>
+
+ Tools? This tells
+ * us which tab is currently active.
+ */
+ public function get_setup_section() {
+ if ( isset( $_REQUEST['tix_section'] ) ) {
+ return strtolower( $_REQUEST['tix_section'] );
+ }
+
+ return 'general';
+ }
+
+ /**
+ * Remember the tabs in Tickets > Tools? This tells
+ * us which tab is currently active.
+ */
+ public function get_tools_section() {
+ if ( isset( $_REQUEST['tix_section'] ) ) {
+ return strtolower( $_REQUEST['tix_section'] );
+ }
+
+ return 'summarize';
+ }
+
+ /**
+ * Tabs for Tickets > Tools, outputs the markup.
+ */
+ public function menu_tools_tabs() {
+ $current_section = $this->get_tools_section();
+ $sections = apply_filters( 'camptix_menu_tools_tabs',
+ array(
+ 'summarize' => __( 'Summarize', 'wordcamporg' ),
+ 'revenue' => __( 'Revenue', 'wordcamporg' ),
+ 'export' => __( 'Export', 'wordcamporg' ),
+ 'notify' => __( 'Notify', 'wordcamporg' ),
+ )
+ );
+
+ if ( current_user_can( $this->caps['refund_all'] ) && ! $this->options['archived'] && $this->options['refund_all_enabled'] ) {
+ $sections['refund'] = esc_html__( 'Refund', 'wordcamporg' );
+ }
+
+ foreach ( $sections as $section_key => $section_caption ) {
+ $active = $current_section === $section_key ? 'nav-tab-active' : '';
+ $url = add_query_arg( 'tix_section', $section_key );
+ echo '' . esc_html( $section_caption ) . '';
+ }
+ }
+
+ /**
+ * Tools > Summarize, the screen that outputs the summary tables,
+ * provides an export option, powered by the summarize_admin_init method,
+ * hooked (almost) at admin_init, because of additional headers. Doesn't use
+ * the Settings API so check for nonces/referrers and caps.
+ *
+ * @see summarize_admin_init()
+ */
+ public function menu_tools_summarize() {
+ if ( isset( $_POST['tix_summarize_submit'] ) && wp_verify_nonce( $_POST['_wp_nonce'], 'tix_summarize' ) ) {
+ $summarize_by = isset( $_POST['tix_summarize_by'] ) ? $_POST['tix_summarize_by'] : 'ticket';
+ if ( ! array_key_exists( $summarize_by, $this->get_available_summary_fields() ) ) {
+ return;
+ }
+ $fields = $this->get_available_summary_fields();
+ $summary = $this->get_summary( $summarize_by );
+ $summary_title = $fields[ $summarize_by ];
+ $alt = '';
+
+ $rows = array();
+ foreach ( $summary as $entry ) {
+ $rows[] = array(
+ esc_html( $summary_title ) => esc_html( $entry['label'] ),
+ esc_html__( 'Count', 'wordcamporg' ) => esc_html( $entry['count'] ),
+ );
+ }
+ // Render the widefat table.
+ $this->table( $rows, 'widefat tix-summarize' );
+ }
+ ?>
+
+ caps['manage_tools'] ) || 'summarize' != $this->get_tools_section() ) {
+ return;
+ }
+
+ if ( isset( $_POST['tix_export_summary'], $_POST['tix_summarize_by'] ) && check_admin_referer( 'tix_summarize' ) ) {
+ $summarize_by = $_POST['tix_summarize_by'];
+ if ( ! array_key_exists( $summarize_by, $this->get_available_summary_fields() ) ) {
+ return;
+ }
+
+ $fields = $this->get_available_summary_fields();
+ $summary = $this->get_summary( $summarize_by );
+ $summary_title = $fields[ $summarize_by ];
+ $filename = sprintf( 'camptix-summary-%s-%s.csv', sanitize_title_with_dashes( $summary_title ), gmdate( 'Y-m-d' ) );
+
+ header( 'Content-Type: text/csv' );
+ header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
+ header( 'Cache-control: private' );
+ header( 'Pragma: private' );
+ header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
+
+ $stream = fopen( 'php://output', 'w' );
+
+ $headers = array( $summary_title, __( 'Count', 'wordcamporg' ) );
+ fputcsv( $stream, self::esc_csv( $headers ) );
+ foreach ( $summary as $entry ) {
+ fputcsv( $stream, self::esc_csv( $entry ), ',', '"' );
+ }
+
+ fclose( $stream );
+ die();
+ }
+ }
+
+ /**
+ * Helper function to create admin tables, give me a
+ * $rows array and I'll do the rest.
+ */
+ public function table( $rows, $classes = 'widefat' ) {
+
+ if ( ! is_array( $rows ) || ! isset( $rows[0] ) ) {
+ return;
+ }
+
+ $alt = '';
+ ?>
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+ $value ) : ?>
+
+
+ |
+
+
+
+
+
+ id, $screen_ids ) ) ||
+ ( isset( $_REQUEST['post_type'] ) && in_array( $_REQUEST['post_type'], $post_types ) ) ||
+ ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $pages ) )
+ ) {
+ wp_enqueue_script( 'jquery-ui-datepicker' );
+ wp_enqueue_style(
+ 'jquery-ui',
+ plugins_url( '/external/jquery-ui.css', __FILE__ ),
+ array(),
+ filemtime( __DIR__ . '/external/jquery-ui.css' )
+ );
+
+ wp_enqueue_style(
+ 'camptix-admin',
+ plugins_url( '/admin.css', __FILE__ ),
+ array(),
+ filemtime( __DIR__ . '/admin.css' )
+ );
+
+ wp_enqueue_script(
+ 'camptix-admin',
+ plugins_url( '/admin.js', __FILE__ ),
+ array( 'jquery', 'jquery-ui-datepicker', 'backbone' ),
+ filemtime( __DIR__ . '/admin.js' )
+ );
+
+ wp_dequeue_script( 'autosave' );
+ }
+ }
+
+ $screen = get_current_screen();
+ if ( 'tix_ticket_page_camptix_options' == $screen->id ) {
+ wp_enqueue_script( 'jquery-ui-datepicker' );
+ wp_enqueue_style( 'jquery-ui', plugins_url( '/external/jquery-ui.css', __FILE__ ), array(), $this->version );
+ }
+ }
+
+ /**
+ * Runs during admin_init, mainly for Settings API things.
+ */
+ public function admin_init() {
+ register_setting( 'camptix_options', 'camptix_options', array( $this, 'validate_options' ) );
+
+ // Add settings fields.
+ $this->menu_setup_controls();
+
+ // Let's add some help tabs.
+ require_once __DIR__ . '/help.php';
+ }
+
+ /**
+ * Menu Setup general section.
+ */
+ public function menu_setup_controls() {
+ wp_enqueue_script( 'jquery-ui' );
+ $section = $this->get_setup_section();
+
+ add_action( 'admin_notices', array( $this, 'admin_notice_supported_currencies' ) );
+
+ switch ( $section ) {
+ case 'general':
+ add_settings_section( 'general', __( 'General Configuration', 'wordcamporg' ), array( $this, 'menu_setup_section_general' ), 'camptix_options' );
+ $this->add_settings_field_helper(
+ 'event_name',
+ __( 'Event Name', 'wordcamporg' ),
+ 'field_text'
+ );
+ $this->add_settings_field_helper(
+ 'currency',
+ __( 'Currency', 'wordcamporg' ),
+ 'field_currency'
+ );
+
+ $this->add_settings_field_helper(
+ 'refunds_enabled',
+ __( 'Enable Refunds', 'wordcamporg' ),
+ 'field_enable_refunds',
+ false,
+ esc_html__( 'This will allows your customers to refund their tickets purchase by filling out a simple refund form.', 'wordcamporg' )
+ );
+
+ break;
+ case 'payment':
+ foreach ( $this->get_available_payment_methods() as $key => $payment_method ) {
+ $payment_method_obj = $this->get_payment_method_by_id( $key );
+
+ add_settings_section( 'payment_' . $key, $payment_method_obj->name, array( $payment_method_obj, '_camptix_settings_section_callback' ), 'camptix_options' );
+ add_settings_field(
+ 'payment_method_' . $key . '_enabled',
+ __( 'Enabled', 'wordcamporg' ),
+ array(
+ $payment_method_obj,
+ '_camptix_settings_enabled_callback',
+ ),
+ 'camptix_options',
+ 'payment_' . $key,
+ array(
+ 'name' => "camptix_options[payment_methods][{$key}]",
+ 'value' => isset( $this->options['payment_methods'][ $key ] ) ? (bool) $this->options['payment_methods'][ $key ] : false,
+ )
+ );
+
+ $payment_method_obj->payment_settings_fields();
+ }
+ break;
+ case 'email-templates':
+ add_settings_section( 'general', __( 'E-mail Templates', 'wordcamporg' ), array( $this, 'menu_setup_section_email_templates' ), 'camptix_options' );
+ $this->add_settings_field_helper( 'email_template_single_purchase', esc_html__( 'Single purchase', 'wordcamporg' ), 'field_textarea' );
+ $this->add_settings_field_helper( 'email_template_multiple_purchase', esc_html__( 'Multiple purchase', 'wordcamporg' ), 'field_textarea' );
+ $this->add_settings_field_helper( 'email_template_multiple_purchase_receipt', esc_html__( 'Multiple purchase (receipt)', 'wordcamporg' ), 'field_textarea' );
+ $this->add_settings_field_helper( 'email_template_pending_succeeded', esc_html__( 'Pending Payment Succeeded', 'wordcamporg' ), 'field_textarea' );
+ $this->add_settings_field_helper( 'email_template_pending_failed', esc_html__( 'Pending Payment Failed', 'wordcamporg' ), 'field_textarea' );
+ $this->add_settings_field_helper( 'email_template_single_refund', esc_html__( 'Single Refund', 'wordcamporg' ), 'field_textarea' );
+ $this->add_settings_field_helper( 'email_template_multiple_refund', esc_html__( 'Multiple Refund', 'wordcamporg' ), 'field_textarea' );
+
+ foreach ( apply_filters( 'camptix_custom_email_templates', array() ) as $key => $template ) {
+ $this->add_settings_field_helper( $key, $template['title'], $template['callback_method'] );
+ }
+
+ // Add a reset templates button.
+ add_action( 'camptix_setup_buttons', array( $this, 'setup_buttons_reset_templates' ) );
+ break;
+ case 'beta':
+ if ( ! $this->beta_features_enabled ) {
+ break;
+ }
+
+ add_settings_section( 'general', esc_html__( 'Beta Features', 'wordcamporg' ), array( $this, 'menu_setup_section_beta' ), 'camptix_options' );
+
+ $this->add_settings_field_helper(
+ 'reservations_enabled',
+ esc_html__( 'Enable Reservations', 'wordcamporg' ),
+ 'field_yesno',
+ false,
+ esc_html__( 'Reservations is a way to make sure that a certain group of people, can always purchase their tickets, even if you sell out fast.', 'wordcamporg' )
+ );
+
+ if ( current_user_can( $this->caps['refund_all'] ) ) {
+ $this->add_settings_field_helper(
+ 'refund_all_enabled',
+ esc_html__( 'Enable Refund All', 'wordcamporg' ),
+ 'field_yesno',
+ false,
+ esc_html__( 'Allows to refund all purchased tickets by an admin via the Tools menu.', 'wordcamporg' )
+ );
+ }
+
+ $this->add_settings_field_helper(
+ 'archived',
+ esc_html__( 'Archived Event', 'wordcamporg' ),
+ 'field_yesno',
+ false,
+ esc_html__( 'Archived events are read-only.', 'wordcamporg' )
+ );
+ break;
+ default:
+ do_action( 'camptix_menu_setup_controls', $section );
+ break;
+ }
+ }
+
+ /**
+ * Menu Setup Beta section.
+ */
+ public function menu_setup_section_beta() {
+ echo '' . esc_html__( 'Beta features are things that are being worked on in CampTix, but are not quite finished yet. You can try them out, but we do not recommend doing that in a live environment on a real event. If you have any kind of feedback on any of the beta features, please let us know.', 'wordcamporg' ) . '
';
+ }
+
+ /**
+ * Menu Setup Email template section.
+ */
+ public function menu_setup_section_email_templates() {
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ' . esc_html__( 'General configuration.', 'wordcamporg' ) . '';
+ }
+}
+
+new Camptix_Admin();
\ No newline at end of file