<?php
/**
 * Plugin Name: DACdb Plus
 * Version: 3.1.18
 * Author: DACdb - A Member Minder Pro, LLC company
 * Author URI: https://memberminderpro.com
 * Description: This plugin allows you to display your club/district data (stories, events, members, leaders, speakers, birthdays, and bulletins), within your wordpress pages and sidebar widgets.
 */

//SECTION - Global Variable Definitions

/*
 * Plugin version.
 * @var string
 */
$plugin_version = '3.1.18';

/**
 * Debug mode flag.
 *
 * @var bool
 */
$fDebug = false;

/**
 * Data path.
 *
 * @var string
 */
$data_path = '';

/**
 * Data file.
 *
 * @var string
 */
$data_file = '';

/**
 * Public Path.
 *
 * @var string
 */
$public_path = '';

/**
 * Option
 *
 * @var string
 */
$option = '';

/**
 * Category ID
 *
 * @var string
 */
$catid = '';

//SECTION - Required Files and Libraries

require 'plugin-update-checker/plugin-update-checker.php';
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
    'https://wordpress.dacdb.com/plugins/dacdbplus/dacdbplus.json',
    __FILE__,
    'dacdbplus'
);

/**
 * Echoes out the CSS stylesheets required by the DACdb Plus plugin.
 *
 * This function outputs multiple <link> tags that link to CSS stylesheets needed by the DACdb Plus plugin.
 * The stylesheets include bootstrap.css, dacdb-plus.css, custom.css, and fullcalendar.css.
 * The URLs of the stylesheets are generated using the `plugins_url` function and include the plugin version for cache-busting.
 * The function is called by the WordPress action `wp_head`.
 *
 * @return $output - A string containing the HTML <link> tags that link to the CSS stylesheets.
 */
function Dacdb_css()
{
    $output = '';

    $output .= '<link rel="stylesheet" id="dacdb-bs" href="' . plugins_url('bootstrap/bootstrap.css?ver=' . $GLOBALS['plugin_version'],  __FILE__) . '" type="text/css" media="all" />';
    $output .= '<link rel="stylesheet" id="dacdb-css" href="' . plugins_url('css/dacdb-plus.css?ver=' . $GLOBALS['plugin_version'], __FILE__) . '" type="text/css" media="all" />';
    $output .= '<link rel="stylesheet" id="dacdb-custom-css" href="' . plugins_url('css/custom.css?ver=' . $GLOBALS['plugin_version'], __FILE__) . '" type="text/css" media="all" />';
    // $output .= '<link rel="stylesheet" id="dacdb-fullcalendar" href="' . plugins_url('css/fullcalendar.css?ver=' . $GLOBALS['plugin_version'], __FILE__) . '" type="text/css" media="all" />';
	$output .= '<link rel="stylesheet" id="dacdb-fullcalendar" href="' . plugins_url('css/tooltip.css?ver=' . $GLOBALS['plugin_version'], __FILE__) . '" type="text/css" media="all" />';
	$output .= '<link rel="stylesheet" id="dacdb-sm" href="' . plugins_url('css/sm.css?ver=' . $GLOBALS['plugin_version'], __FILE__) . '" type="text/css" media="all" />';
	$output .= '<link rel="stylesheet" id="dacdb-fontawesome" href="' . plugins_url('/css/Font-Awesome6/css/all.css?ver=' . $GLOBALS['plugin_version'], __FILE__) . '" type="text/css" media="all" />';

    echo $output;
}

add_action('wp_head', 'Dacdb_css');

/**
 * Returns the JavaScript code required by the DACdb Plus plugin.
 *
 * This function outputs JavaScript that includes a function called `showdiv`.
 * The `showdiv` function is used to toggle the visibility of a specified HTML element,
 * display additional content, and update button text.
 * The function uses jQuery to select and manipulate DOM elements.
 * The function is called by the WordPress action `wp_footer`.
 *
 * @return $script - A string containing the JavaScript code.
 */

 // storyscript does this work
 /*
function Dacdb_js()
{
    $script = '
    <script defer type="text/javascript">
		function showdiv(divid) {
            console.log("showdiv=" + divid);
            $("#description-" + divid).toggle();
            console.log($("#more-" + divid).html());
            var t = $("#more-" + divid).html();
            if (t == "Read More")
                $("#more-" + divid).html("Less");
            else
                $("#more-" + divid).html("Read More");
            return false;
        }
    </script>';
    return $script;
}
*/

/**
 * Adds a "Settings" link to the action links of the DACdb Plus plugin.
 *
 * This function is a callback for the WordPress filter `plugin_action_links_{plugin_file}`.
 * It adds a "Settings" link to the existing action links of the DACdb Plus plugin displayed on the WordPress plugins page.
 *
 * @param array $links - An array of existing action links.
 *
 * @return array - An array of modified action links with the "Settings" link added at the beginning.
 */
function Dacdb_Plus_Settings_link($links)
{
    // Add a link to the settings page
    $settings_link = '<a href="options-general.php?page=dacdb-settings">Settings</a>';
    array_unshift($links, $settings_link);
    return $links;
}
/**
 * Retrieve the basename of the current plugin's main file.
 *
 * The `plugin_basename()` function is a WordPress function that takes a file path as its parameter and returns
 * the basename of that file. Here, it is used to retrieve the basename of the current plugin's main file and store
 * it in the variable `$plugin` for future reference.
 *
 * @var string $plugin The basename of the current plugin's main file.
 */
$plugin = plugin_basename(__FILE__);

//SECTION - Error Handling

/**
 * Displays an error message indicating that the DACdb plugin account number is missing.
 *
 * This function outputs an error message in a div container with appropriate styling.
 * The error message states that the DACdb plugin account number is required and prompts the user to enter their account number.
 * The text of the error message is translated using the `__()` or `_e()` function with the text domain 'dacdbplus'.
 */

function dacdb_missing_district()
{
    ?>
        <div class="updated settings-error error is-dismissible">
            <h2><?php _e('The DACdb plugin Account number is required, please enter your account number.', 'dacdbplus'); ?></h2>
        </div>
    <?php
}

/**
 * Displays an error message indicating that the DACdb plugin club number is missing.
 *
 * This function outputs an error message in a div container with appropriate styling.
 * The error message states that the DACdb plugin club number is required and provides instructions on what to enter.
 * If the club number is for an account, the user is instructed to enter 0.
 * The text of the error message is translated using the `__()` or `_e()` function with the text domain 'dacdbplus'.
 */
function dacdb_missing_club()
{
    ?>
        <div class="updated settings-error error is-dismissible">
            <h2><?php _e('The DACdb plugin Club number is required, if this is for an account please enter 0', 'dacdbplus'); ?></h2>
        </div>
    <?php
}

/**
 * Displays an error message indicating that the DACdb plugin system selection is required.
 *
 * This function outputs an error message in a div container with appropriate styling.
 * The error message states that the DACdb plugin system selection is required and prompts the user to make the selection and save.
 * The text of the error message is translated using the `__()` or `_e()` function with the text domain 'dacdbplus'.
 */
function dacdb_missing_system()
{
    ?>
        <div class="updated settings-error error is-dismissible">
            <h2><?php _e('The DACdb plugin System selection is required, please make this selection an SAVE.', 'dacdbplus'); ?></h2>
        </div>
    <?php
}

/**
 * Displays an error message indicating that the DACdb plugin subscription is required.
 *
 * This function outputs an error message in a div container with appropriate styling.
 * The error message states that the DACdb plugin subscription is required and prompts the user to contact support.
 * The text of the error message is translated using the `__()` or `_e()` function with the text domain 'dacdbplus'.
 */
function dacdb_missing_subscription()
{
    ?>
        <div class="updated settings-error error is-dismissible">
            <h2><?php _e('The DACdb plugin subscription is required, please contact support.', 'dacdbplus'); ?></h2>
        </div>
    <?php
}
//!SECTION - Error Handling

//SECTION - Shortcode Assets
/**
 * Adds a custom shortcode button to the WordPress editor.
 *
 * This function adds a custom shortcode button to the WordPress editor using the `QTags.addButton()` function.
 * The button is added if the "quicktags" script is loaded.
 * When the button is clicked, it inserts the "[dacdb_plus show='']" shortcode into the editor content.
 */
function shortcode_button_script()
{
    if (wp_script_is("quicktags")) {
    ?>
        <script type="text/javascript">
            QTags.addButton(
                "dacdb_shortcode",
                "DACdb",
                callback
            );

            function callback() {
                QTags.insertContent("[dacdb_plus show=\"\"]");
            }
        </script>
    <?php
    }
}

//!SECTION - Shortcode Assets
//SECTION - Class DACdbSetting

class DACdbSetting
{
    /**
     * Holds the values to be used in the fields callbacks
     */
    public $options;

    /**
     * Class Constructor.
     *
     * Initializes the object and registers actions for adding an admin menu page
     * and initializing the plugin's settings.
     */
    public function __construct()
    {
        /**
         * Add action hook for the 'admin_menu' event.
         * Registers the add_plugin_page() method as the callback function.
         *
         * @param string   $hook     The unique identifier of the 'admin_menu' event.
         * @param callable $callback The method to be executed when the event occurs.
         */
        add_action('admin_menu', array($this, 'add_plugin_page'));

        /**
         * Add action hook for the 'admin_init' event.
         * Registers the page_init() method as the callback function.
         *
         * @param string   $hook     The unique identifier of the 'admin_init' event.
         * @param callable $callback The method to be executed when the event occurs.
         */
        add_action('admin_init', array($this, 'page_init'));
    }

    /**
     * Adds the plugin page to the admin menu.
     * This page will be located under the "Settings" menu.
     */
    public function add_plugin_page()
    {
        // This page will be under "Settings"
        add_options_page('Settings Admin', 'DACdb', 'manage_options', 'dacdb-settings', array($this, 'create_admin_page'));
    }


    /**
     * Creates the admin page for the plugin.
     * Displays the plugin configuration settings and options.
     */
    public function create_admin_page()
    {
        global $plugin_version;
        // Set class property
        $this->options = get_option('dacdb_plus_options');
    ?>
        <div class="wrap">
            <h2 style="margin: 0px;">Plugin Configuration <span style="font-size: 12px">v<?php echo $plugin_version ?></span></h2>
            <p style="margin: 0px;">Copyright&copy; 2003-<?php echo date('Y') ?> DACdb - A Member Minder Pro, LLC company</p>
            <form method="post" action="options.php">
                <?php
                // This prints out all hidden setting fields
                settings_fields('my_option_group');
                do_settings_sections('dacdb-settings');
                submit_button();
                ?>
            </form>
			<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="  crossorigin="anonymous"></script>
            <script type="text/javascript">
                $(document).ready(function() {
                    // alert("ready")

                    j$ = jQuery.noConflict();
					var ids1 = '';
                    j$.getJSON("https://www.IsMyRotaryClub.org/wp_api_1-2/Lookup/EventCategory.cfm?AccountID=<?php echo $this->options['dacdb_district']; ?>", function(data, textStatus, jqxhr) {
                        for (i = 0; i < data.results.length; i++) {
                            j$(".EventCatIDDiv").append("<div class=checkboxwrap>- " + data.results[i].text + "</div>");
							ids1 = ids1.concat (data.results[i].id,  ( i <  data.results.length-1 ) ? "," : "" );
                        }
						j$(".EventCatIDDivList").append( "List: " + ids1 );
                    });
					var ids2 = '';
                    j$.getJSON("https://www.IsMyRotaryClub.org/wp_api_1-2/Lookup/MemberType.cfm?AccountID=<?php echo $this->options['dacdb_district']; ?>", function(data, textStatus, jqxhr) {
                        for (i = 0; i < data.results.length; i++) {
                            j$(".MemberTypeIDDiv").append("<div class=checkboxwrap>- " + data.results[i].text + "</div>");
							ids2 = ids2.concat (data.results[i].id,  ( i <  data.results.length-1 ) ? "," : "" );
                        }
						j$(".MemberTypeIDDivList").append( "List: " + ids2 );
                    });
                });
            </script>
        </div>
    <?php
    }
    /**
     * Register and add settings
     */
    public function page_init()
    {
        setDataPath();   // SHortCode DACdb or iMembersDB paths

        register_setting('my_option_group', 'dacdb_plus_options', array($this, 'sanitize'));

        // Plugin Settings    ID               Title                   Callback                                    Page              Section
        add_settings_section('setting_section_main', '<hr class="style-four">Plugin Settings ', array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('dacdb_district',                       'Account/District #',                       array($this, 'dacdb_district_callback'),                     'dacdb-settings',   'setting_section_main');
        add_settings_field('dacdb_club',                           'Club/Chapter/Region',                      array($this, 'dacdb_club_callback'),                         'dacdb-settings',   'setting_section_main');
        add_settings_field('dacdb_system',                         'System',                                   array($this, 'dacdb_system_callback'),                       'dacdb-settings',   'setting_section_main');
        add_settings_field('dacdb_apikey',                         'API Key',                                  array( $this, 'dacdb_apikey_callback' ),                       'dacdb-settings',   'setting_section_main');

        // Story Settings
        add_settings_section('setting_section_stories', '<hr class="style-four">Story Settings', array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('story_sep',                             'Story Separator',                          array($this, 'story_sep_callback'),                           'dacdb-settings',   'setting_section_stories');
        add_settings_field('story_image',                           'Story Image Position',                     array($this, 'story_image_callback'),                         'dacdb-settings',   'setting_section_stories');
        add_settings_field('story_open',                            'Read More Link',                           array($this, 'story_open_callback'),                          'dacdb-settings',   'setting_section_stories');
        add_settings_field('story_share',                           'Social Media Share',                       array($this, 'story_share_callback'),                         'dacdb-settings',   'setting_section_stories');
        add_settings_field('story_limit',                           'Limit Stories',                            array($this, 'story_limit_callback'),                         'dacdb-settings',   'setting_section_stories');
        // The user has no idea what URL to do to -- remove this option
        // add_settings_field('story_url',                             'All Stories URL',                       array( $this, 'story_url_callback' ),                           'dacdb-settings',   'setting_section_stories');

        // Club Events
        add_settings_section('setting_section_club_events', '<hr class="style-four">Club Event Settings for Pages and Widgets', array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('club_events_months',                    'Page - Months',                            array($this, 'club_events_months_callback'),                  'dacdb-settings',   'setting_section_club_events');
        add_settings_field('club_events_types_page',                'Page - Event CategoryIDs',                 array($this, 'club_events_types_page_callback'),              'dacdb-settings',   'setting_section_club_events');
        add_settings_field('club_events_show_speakers',             'Page - Show Speakers',                     array($this, 'club_events_show_speakers_callback'),           'dacdb-settings',   'setting_section_club_events');
        add_settings_field('club_events_show_speakers_info',        'Page - Show Speakers Info',                array($this, 'club_events_show_speakers_info_callback'),      'dacdb-settings',   'setting_section_club_events');
        add_settings_field('club_events_months_side',               'Widget - Months',                          array($this, 'club_events_months_side_callback'),             'dacdb-settings',   'setting_section_club_events');
        add_settings_field('club_events_types_side',                'Widget - Event CategoryIDs',               array($this, 'club_events_types_side_callback'),              'dacdb-settings',   'setting_section_club_events');
        add_settings_field('club_events_show_speakers_side',        'Widget - Show Speakers',                   array($this, 'club_events_show_speakers_side_callback'),      'dacdb-settings',   'setting_section_club_events');
        add_settings_field('club_events_show_speakers_side_info',   'Widget - Show Speakers Info',              array($this, 'club_events_show_speakers_side_info_callback'), 'dacdb-settings',   'setting_section_club_events');

        // Account  Events
        add_settings_section('setting_section_district_events', '<hr class="style-four">Account Event Settings for Pages and Widgets',  array($this, 'print_section_null'),   'dacdb-settings');
        add_settings_field('district_events_months',                'Page - Months',                            array($this, 'district_events_months_callback'),              'dacdb-settings',   'setting_section_district_events');
        add_settings_field('district_events_types_page',            'Page - Event CategoryIDs',                 array($this, 'district_events_types_page_callback'),          'dacdb-settings',   'setting_section_district_events');
        add_settings_field('district_events_months_side',           'Widget - Months',                          array($this, 'district_events_months_side_callback'),         'dacdb-settings',   'setting_section_district_events');
        add_settings_field('district_events_types_side',            'Widget - Event CategoryIDs',               array($this, 'district_events_types_side_callback'),          'dacdb-settings',   'setting_section_district_events');

        // Members
        add_settings_section('setting_section_members', '<hr class="style-four">Member Settings / Clubs Only',  array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('mem_per_page',                          'Members per page',                         array($this, 'mem_per_page_callback'),                        'dacdb-settings',   'setting_section_members');
        add_settings_field('pagnationposition',                     'Pagination Position',                      array($this, 'pagnationposition_callback'),                   'dacdb-settings',   'setting_section_members');
        add_settings_field('pagnationposition_tb',                   '',                                        array($this, 'pagnationposition_tb_callback'),                'dacdb-settings',   'setting_section_members');
        add_settings_field('membertypes',                           'Club Members Types',                       array($this, 'membertypes_callback'),                         'dacdb-settings',   'setting_section_members');
        add_settings_field('members_per_row',                       'Members Per Row',                          array($this, 'members_per_row_callback'),                     'dacdb-settings',   'setting_section_members');
        add_settings_field('member_pics',                           'Show Member Pictures',                     array($this, 'member_pics_callback'),                         'dacdb-settings',   'setting_section_members');
        add_settings_field('thumbnail_width',                       'Width of photo in pixels',                 array($this, 'thumbnail_width_callback'),                     'dacdb-settings',   'setting_section_members');
        add_settings_field('member_club_pos',                       'Show Club Position',                       array($this, 'member_club_pos_callback'),                     'dacdb-settings',   'setting_section_members');
        add_settings_field('member_bus_name',                       'Show Member Business Name',                array($this, 'member_bus_name_callback'),                     'dacdb-settings',   'setting_section_members');
        add_settings_field('member_bus_pos',                        'Show Member Position',                     array($this, 'member_bus_pos_callback'),                      'dacdb-settings',   'setting_section_members');
        add_settings_field('member_bus_url',                        'Link Member Business Website',             array($this, 'member_bus_url_callback'),                      'dacdb-settings',   'setting_section_members');
        add_settings_field('member_class',                          'Show Member Classification',               array($this, 'member_class_callback'),                        'dacdb-settings',   'setting_section_members');
        add_settings_field('members_contact_link',                  'Allow Members to be Contacted',            array($this, 'members_contact_link_callback'),                'dacdb-settings',   'setting_section_members');
        add_settings_field('members_since',                         'Show Member Since',                        array($this, 'members_since_callback'),                       'dacdb-settings',   'setting_section_members');
        add_settings_field('members_since_format',                  'Member Since Date Format',                 array($this, 'members_since_format_callback'),                'dacdb-settings',   'setting_section_members');

        // Club Presidents
        add_settings_section('setting_section_club_presidents', '<hr class="style-four">Club Presidents', array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('club_presidents_per_row',               'Club Presidents Per Row',                  array($this, 'club_presidents_per_row_callback'),             'dacdb-settings',   'setting_section_club_presidents');

        // District Leaders
        add_settings_section('setting_section_leaders', '<hr class="style-four">Account/District Leadership Settings', array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('leaders_per_row',                       'Leaders Per Row',                          array($this, 'leaders_per_row_callback'),                     'dacdb-settings',   'setting_section_leaders');
        add_settings_field('leader_pics',                           'Show Leadership Pictures',                 array($this, 'leader_pics_callback'),                         'dacdb-settings',   'setting_section_leaders');
        add_settings_field('leaders_contact_link',                  'Allow Leadership to be Contacted',         array($this, 'leaders_contact_link_callback'),                'dacdb-settings',   'setting_section_leaders');

        // Bulletins
        add_settings_section('setting_section_bulletins', '<hr class="style-four">Newsletter Settings for Pages and Widgets', array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('newsletters_weeks_page',                'Page - # Weeks',                           array($this, 'newsletters_weeks_page_callback'),              'dacdb-settings',   'setting_section_bulletins');
        add_settings_field('newsletters_show_folders_page',         'Page - Show Folders',                      array($this, 'newsletters_show_folders_page_callback'),       'dacdb-settings',   'setting_section_bulletins');
        add_settings_field('newsletters_order_folders_page',        'Page - Order Folders',                     array($this, 'newsletters_order_folders_page_callback'),      'dacdb-settings',   'setting_section_bulletins');
        add_settings_field('newsletters_weeks_widget',              'Widget - # Weeks',                         array($this, 'newsletters_weeks_widget_callback'),            'dacdb-settings',   'setting_section_bulletins');

        // Speakers
        add_settings_section('setting_section_speakers', '<hr class="style-four">Speakers Settings', array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('speakers_months',                       '# Months to Pull',                         array($this, 'speakers_months_callback'),                     'dacdb-settings',   'setting_section_speakers');
        add_settings_field('speaker_cats',                          'Event Category IDs',                       array($this, 'speaker_cats_callback'),                        'dacdb-settings',   'setting_section_speakers');
        add_settings_field('speaker_page_full',                     'Full Info On Page',                        array($this, 'speaker_page_full_callback'),                   'dacdb-settings',   'setting_section_speakers');

        // Map
        add_settings_section('setting_section_map', '<hr class="style-four">Account Map', array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('map_api',                               'Google Maps API Key',                      array($this, 'map_api_callback'),                             'dacdb-settings',   'setting_section_map');


        // committee members
        add_settings_section('setting_section_committee_members',   '<hr class="style-four">Commitee Members Settings',    array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('committee_members_per_row',             'Commitee Members Per Row',                 array($this, 'committee_members_per_row_callback'),           'dacdb-settings',   'setting_section_committee_members');
        add_settings_field('committee_members_pics',                'Show Commitee Members Pictures',           array($this, 'committee_members_pics_callback'),              'dacdb-settings',   'setting_section_committee_members');
        add_settings_field('committee_members_contact_link',        'Allow Commitee Members to be Contacted',   array($this, 'committee_members_contact_link_callback'),      'dacdb-settings',   'setting_section_committee_members');
        add_settings_field('committee_members_committeeposition',   'Show Commitee Member Position',            array($this, 'committee_members_committeeposition_callback'), 'dacdb-settings',   'setting_section_committee_members');
        add_settings_field('committee_members_busposition',         'Show Commitee Member Business Position',   array($this, 'committee_members_busposition_callback'),       'dacdb-settings',   'setting_section_committee_members');
        add_settings_field('committee_members_classification',      'Show Commitee Member Classification',      array($this, 'committee_members_classification_callback'),    'dacdb-settings',   'setting_section_committee_members');

        // College of GOVs
        add_settings_section('setting_section_cog', '<hr class="style-four">College of Governors', array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('cog_per_row',                           'COG Per Row',                              array($this, 'cog_per_row_callback'),                         'dacdb-settings',    'setting_section_cog');

        // Account Committee Chairs
        add_settings_section('setting_section_dcc', '<hr class="style-four">Account Committee Chairs', array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('dcc_per_row',                           'DCC Per Row',                              array($this, 'dcc_per_row_callback'),                         'dacdb-settings',    'setting_section_dcc');

        // Commitee Global Settings
        add_settings_section('setting_section_committee_global',  '<hr class="style-four">Commitee Global Settings', array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('committee_global_name',                 'Show Commitee Name',                       array($this, 'committee_global_name_callback'),               'dacdb-settings',     'setting_section_committee_global');
        add_settings_field('committee_global_description',          'Show Commitee Description',                array($this, 'committee_global_description_callback'),        'dacdb-settings',     'setting_section_committee_global');
        add_settings_field('committee_global_show_district_number', 'Show Member Account Number',               array($this, 'committee_global_show_district_number_callback'), 'dacdb-settings',    'setting_section_committee_global');

        // Events Global Settings
        add_settings_section('setting_section_events_global', '<hr class="style-four">Events Global Settings', array($this, 'print_section_null'),  'dacdb-settings');
        add_settings_field('events_global_date',                    'Show Date/Time First',                     array($this, 'events_global_date_callback'),                  'dacdb-settings',       'setting_section_events_global');

        // Where Clubs Meet  -- Fold into Club Meetings!
        add_settings_section('setting_section_wcm', '<hr class="style-four">Where Clubs Meet', array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('wcm_show_title',                        'Show Page Title',                          array($this, 'wcm_show_title_callback'),                      'dacdb-settings',       'setting_section_wcm');
        add_settings_field('wcm_show_layout',                       'Show Page Layout',                         array($this, 'wcm_show_layout_callback'),                     'dacdb-settings',       'setting_section_wcm');

        // Calendar
        add_settings_section('setting_calendar', '<hr class="style-four">Calendar Settings', array($this, 'print_section_null'), 'dacdb-settings');
        add_settings_field('cal_display',                           'Calendar Default View',            		array($this, 'cal_display_callback'),                          'dacdb-settings',      'setting_calendar');
        add_settings_field('cal_limit',                             'Calendar Limit',                           array($this, 'cal_limit_callback'),                            'dacdb-settings',      'setting_calendar');
    }

    /**
     * Sanitize and SAVE each setting field as needed  - Each new field must be included below
     *
     * @param array $input Contains all settings fields as array keys
     */
    public function sanitize($input)
    {
        $sanitized_input = array();

        $field_mappings = array(
            'dacdb_club' => 'sanitize_text_field',
            'dacdb_district' => 'sanitize_text_field',
            'dacdb_system' => 'sanitize_text_field',
            'dacdb_apikey' => 'sanitize_text_field',
            'story_sep' => 'absint',
            'story_image' => 'absint',
            'story_open' => 'absint',
            'story_share' => 'absint',
            'story_limit' => 'absint',
            'story_url' => 'sanitize_text_field',
            'club_events_show_speakers' => 'absint',
            'club_events_show_speakers_info' => 'absint',
            'club_events_show_speakers_side' => 'absint',
            'club_events_show_speakers_side_info' => 'absint',
            'club_events_months' => 'absint',
            'club_events_months_side' => 'absint',
            'club_events_types_page' => 'sanitize_text_field',
            'club_events_types_side' => 'sanitize_text_field',
            'district_events_months' => 'absint',
            'district_events_months_side' => 'absint',
            'district_events_types_page' => 'sanitize_text_field',
            'district_events_types_side' => 'sanitize_text_field',
            'mem_per_page' => 'absint',
            'pagnationposition' => 'sanitize_text_field',
            'pagnationposition_tb' => 'sanitize_text_field',
            'membertypes' => 'sanitize_text_field',
            'members_per_row' => 'sanitize_text_field',
            'member_pics' => 'sanitize_text_field',
            'member_bus_name' => 'sanitize_text_field',
            'member_bus_pos' => 'sanitize_text_field',
            'member_club_pos' => 'sanitize_text_field',
            'member_bus_url' => 'sanitize_text_field',
            'member_class' => 'sanitize_text_field',
            'members_contact_link' => 'sanitize_text_field',
            'members_since' => 'sanitize_text_field',
            'members_since_format' => 'sanitize_text_field',
            'newsletters_weeks_page' => 'sanitize_text_field',
            'newsletters_show_folders_page' => 'sanitize_text_field',
            'newsletters_order_folders_page' => 'sanitize_text_field',
            'newsletters_weeks_widget' => 'sanitize_text_field',
            'speakers_months' => 'sanitize_text_field',
            'speaker_cats' => 'sanitize_text_field',
            'speaker_page_full' => 'sanitize_text_field',
            'speakers_in_events' => 'sanitize_text_field',
            'leaders_per_row' => 'sanitize_text_field',
            'leader_pics' => 'sanitize_text_field',
            'leaders_contact_link' => 'sanitize_text_field',
            'map_api' => 'sanitize_text_field',
            'club_presidents_per_row' => 'sanitize_text_field',
            'cog_per_row' => 'sanitize_text_field',
            'dcc_per_row' => 'sanitize_text_field',
            'committee_members_per_row' => 'sanitize_text_field',
            'committee_members_pics' => 'sanitize_text_field',
            'committee_members_contact_link' => 'sanitize_text_field',
            'committee_members_committeeposition' => 'sanitize_text_field',
            'committee_members_busposition' => 'sanitize_text_field',
            'committee_members_classification' => 'sanitize_text_field',
            'committee_global_name' => 'sanitize_text_field',
            'committee_global_description' => 'sanitize_text_field',
            'committee_global_show_district_number' => 'sanitize_text_field',
            'events_global_date' => 'sanitize_text_field',
            'cal_display' => 'sanitize_text_field',
            'cal_limit' => 'sanitize_text_field',
            'wcm_show_title' => 'sanitize_text_field',
            'wcm_show_layout' => 'sanitize_text_field',
            'title' => 'sanitize_text_field',
            'thumbnail_width' => 'sanitize_text_field',
        );

        foreach ($field_mappings as $field => $sanitization_function) {
            if (isset($input[$field])) {
                $sanitized_input[$field] = call_user_func($sanitization_function, $input[$field]);
            }
        }

        return $sanitized_input;
    }


    public function print_section_null()
    {
        //print '<hr>';
    }
    public function dacdb_district_callback()
    {
        printf(
            '<input type="text" id="dacdb_district" name="dacdb_plus_options[dacdb_district]" value="%s" size="8" />',
            isset($this->options['dacdb_district']) ? esc_attr($this->options['dacdb_district']) : ''
        );
    }
    public function dacdb_club_callback()
    {
        printf(
            '<input type="text" id="dacdb_club" name="dacdb_plus_options[dacdb_club]" value="%s" size="6" />',
            isset($this->options['dacdb_club']) ? esc_attr($this->options['dacdb_club']) : ''
        );
    }

    public function dacdb_system_callback() {
        $dacdb_system = isset($this->options['dacdb_system']) ? $this->options['dacdb_system'] : 'DACdb';

        $html = '<select id="dacdb_system" name="dacdb_plus_options[dacdb_system]">';
        $html .=    '<option value="DACdb"'      . selected($dacdb_system, 'DACdb',      false) . '>DACdb</option>';
        $html .=    '<option value="iMembersDB"' . selected($dacdb_system, 'iMembersDB', false) . '>iMembersDB</option>';
        $html .= '</select><br><small>This selection is required </small>';

        echo $html;
    }

    public function dacdb_apikey_callback()
        {
        $dacdb_apikey = isset($this->options['dacdb_apikey']) ? $this->options['dacdb_apikey'] : '';

        $html = '<input type="text" id="dacdb_apikey" name="dacdb_plus_options[dacdb_apikey]" value="'.$dacdb_apikey.'" size="40" /><br><small>APIKey will be required in a future release</small>';
        echo $html;
        }

    public function story_sep_callback()
    {
        $story_sep = isset($this->options['story_sep']) ? $this->options['story_sep'] : '0';
        $html = '<select id="story_sep" name="dacdb_plus_options[story_sep]" onchange="getStoryval(this);">';
        $html .= '<option value="0"' . selected($story_sep, '0', false) . '>No Style</option>';
        $html .= '<option value="1"' . selected($story_sep, '1', false) . '>Version 1</option>';
        $html .= '<option value="2"' . selected($story_sep, '2', false) . '>Version 2</option>';
        $html .= '<option value="3"' . selected($story_sep, '3', false) . '>Version 3</option>';
        $html .= '<option value="4"' . selected($story_sep, '4', false) . '>Version 4</option>';
        $html .= '<option value="5"' . selected($story_sep, '5', false) . '>Version 5</option>';
        $html .= '<option value="6"' . selected($story_sep, '6', false) . '>Version 6</option>';
        $html .= '<option value="7"' . selected($story_sep, '7', false) . '>Version 7</option>';
        $html .= '<option value="8"' . selected($story_sep, '8', false) . '>Version 8</option>';
        $html .= '</select>';
        switch ($story_sep) {
            case "1":
                $hrstyle = 'style-one';
                break;
            case "2":
                $hrstyle = 'style-two';
                break;
            case "3":
                $hrstyle = 'style-three';
                break;
            case "4":
                $hrstyle = 'style-four';
                break;
            case "5":
                $hrstyle = 'style-five';
                break;
            case "6":
                $hrstyle = 'style-six';
                break;
            case "7":
                $hrstyle = 'style-seven';
                break;
            case "8":
                $hrstyle = 'style-eight';
                break;
            default:
                $hrstyle = '';
        }
        $html .= '<br>Preview: <hr id="hrsep" class="' . $hrstyle . '">';
        $html .= "
                <script>
                function getStoryval(sel)
                {
                    if ( sel.value == 0) {
                        document.getElementById('hrsep').className = '';
                    }
                    if ( sel.value == 1) {
                        document.getElementById('hrsep').className = 'style-one';
                    }
                    if ( sel.value == 2) {
                        document.getElementById('hrsep').className = 'style-two';
                    }
                    if ( sel.value == 3) {
                        document.getElementById('hrsep').className = 'style-three';
                    }
                    if ( sel.value == 4) {
                        document.getElementById('hrsep').className = 'style-four';
                    }
                    if ( sel.value == 5) {
                        document.getElementById('hrsep').className = 'style-five';
                    }
                    if ( sel.value == 6) {
                        document.getElementById('hrsep').className = 'style-six';
                    }
                    if ( sel.value == 7) {
                        document.getElementById('hrsep').className = 'style-seven';
                    }
                    if ( sel.value == 8) {
                        document.getElementById('hrsep').className = 'style-eight';
                    }
                }
                </script>";
        echo $html;
    }
    public function story_image_callback()
    {
        $story_image = isset($this->options['story_image']) ? $this->options['story_image'] : '0';
        $html = '<select id="story_image" name="dacdb_plus_options[story_image]">';
        $html .= '<option value="0"' . selected($story_image, '0', false) . '>Alternating</option>';
        $html .= '<option value="1"' . selected($story_image, '1', false) . '>Left Side</option>';
        $html .= '<option value="2"' . selected($story_image, '2', false) . '>Right Side</option>';
        $html .= '</select>';
        echo $html;
    }

    public function story_open_callback()
    {

        $story_open = isset($this->options['story_open']) ? $this->options['story_open'] : '0';
        $html = '<select id="story_open" name="dacdb_plus_options[story_open]">';
        $html .= '<option value="0"' . selected($story_open, '0', false) . '>Expand on page</option>';
        $html .= '<option value="1"' . selected($story_open, '1', false) . '>Open story alone</option>';
        $html .= '<option value="2"' . selected($story_open, '2', false) . '>Open story in new window</option>';
        $html .= '</select><br><small>"Expand on page" will open the read more to show the rest of the story with out loading a new page. "Open story alone" will open the story all by it\'s self.</small>';
        echo $html;
    }

    public function story_share_callback()
    {
        $story_share = isset($this->options['story_share']) ? $this->options['story_share'] : '0';
        $html = '<select id="story_share" name="dacdb_plus_options[story_share]">';
        $html .= '<option value="0"' . selected($story_share, '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($story_share, '1', false) . '>Yes</option>';
        $html .= '</select><br><small>This selection controls whether the share options are shown. This must be Yes and the specific social media selections must be checked on!</small>';
        echo $html;
    }

    public function story_limit_callback()
    {
        $story_limit = isset($this->options['story_limit']) ? $this->options['story_limit'] : '999';
        $html = '<input type="text" id="story_limit" name="dacdb_plus_options[story_limit]" value="'.$story_limit.'" size="3" maxlength="4" /><br><small>Default: 999</small>';
        echo $html;
    }


    public function story_url_callback()
    {
        $story_url = isset($this->options['story_url']) ? $this->options['story_url'] : '';
        $html = '<input type="text" id="story_url" name="dacdb_plus_options[story_url]" value="'.$story_url.'" size="80" maxlength="80" /><br><small>Create a page that has all your stories and add the complete URL here.</small>';
        echo $html;
    }

    public function club_events_show_speakers_callback()
    {
        $club_events_show_speakers = isset($this->options['club_events_show_speakers']) ? $this->options['club_events_show_speakers'] : '0';


        $html = '<select id="club_events_show_speakers" name="dacdb_plus_options[club_events_show_speakers]">';
        $html .= '<option value="0"' . selected($club_events_show_speakers, '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($club_events_show_speakers, '1', false) . '>Yes</option>';
        $html .= '</select>';
        $html .= '<small><br>Will display speaker events on your event page.</small>';
        echo $html;
    }

    public function club_events_show_speakers_info_callback()
    {
        $club_events_show_speakers_info = isset($this->options['club_events_show_speakers_info']) ? $this->options['club_events_show_speakers_info'] : '0';
        $html = '<select id="club_events_show_speakers_info" name="dacdb_plus_options[club_events_show_speakers_info]">';
        $html .= '<option value="0"' . selected($club_events_show_speakers_info, '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($club_events_show_speakers_info, '1', false) . '>Yes</option>';
        $html .= '</select>';
        $html .= '<small><br>Only if "Show Speakers is checked"</small>';
        echo $html;
    }

    public function club_events_months_callback()
    {
        $club_events_months = isset($this->options['club_events_months']) ? $this->options['club_events_months'] : '1';
        $html = '<select id="club_events_months" name="dacdb_plus_options[club_events_months]">';
        $html .= '<option value="1"' . selected($club_events_months, '1', false) . '>1</option>';
        $html .= '<option value="2"' . selected($club_events_months, '2', false) . '>2</option>';
        $html .= '<option value="3"' . selected($club_events_months, '3', false) . '>3</option>';
        $html .= '<option value="4"' . selected($club_events_months, '4', false) . '>4</option>';
        $html .= '<option value="5"' . selected($club_events_months, '5', false) . '>5</option>';
        $html .= '<option value="6"' . selected($club_events_months, '6', false) . '>6</option>';
        $html .= '<option value="7"' . selected($club_events_months, '7', false) . '>7</option>';
        $html .= '<option value="8"' . selected($club_events_months, '8', false) . '>8</option>';
        $html .= '<option value="9"' . selected($club_events_months, '9', false) . '>9</option>';
        $html .= '<option value="10"' . selected($club_events_months, '10', false) . '>10</option>';
        $html .= '<option value="11"' . selected($club_events_months, '11', false) . '>11</option>';
        $html .= '<option value="12"' . selected($club_events_months, '12', false) . '>12</option>';
        $html .= '<option value="18"' . selected($club_events_months, '18', false) . '>18</option>';
        $html .= '<option value="24"' . selected($club_events_months, '24', false) . '>24</option>';
        $html .= '</select>';
        $html .= '<br><small>How many months of events to show.</small>';
        echo $html;
    }
    public function club_events_months_side_callback()
    {
        $selectedMonth = isset($this->options['selectedMonth']) ? $this->options['selectedMonth'] : '1';
        $html = '<select id="club_events_months_side" name="dacdb_plus_options[club_events_months_side]">';
        for ($month = 1; $month <= 12; $month++) {
            $selected = selected($selectedMonth, (string)$month, false);
            $html .= "<option value=\"$month\" $selected>$month</option>";
        }

        $html .= '</select>';
        $html .= '<br><small>How many months of events to show.</small>';
        echo $html;
    }

    public function club_events_show_speakers_side_callback()
    {
        $club_events_show_speakers_side = isset($this->options['club_events_show_speakers_side']) ? $this->options['club_events_show_speakers_side'] : '0';
        $html = '<select id="club_events_show_speakers_side" name="dacdb_plus_options[club_events_show_speakers_side]">';
        $html .= '<option value="0"' . selected($club_events_show_speakers_side, '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($club_events_show_speakers_side, '1', false) . '>Yes</option>';
        $html .= '</select>';
        $html .= '<small><br>Will display speaker events on your event widget.</small>';
        echo $html;
    }

    public function club_events_show_speakers_side_info_callback()
    {
        $club_events_show_speakers_side_info = isset($this->options['club_events_show_speakers_side_info']) ? $this->options['club_events_show_speakers_side_info'] : '0';

        $html = '<select id="club_events_show_speakers_side_info" name="dacdb_plus_options[club_events_show_speakers_side_info]">';
        $html .= '<option value="0"' . selected($club_events_show_speakers_side_info, '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($club_events_show_speakers_side_info, '1', false) . '>Yes</option>';
        $html .= '</select>';
        $html .= '<small><br>Only if "Widget - Show Speakers is checked"</small>';
        echo $html;
    }


    public function club_events_types_page_callback()
    {
        $club_events_types_page = isset($this->options['club_events_types_page']) ? $this->options['club_events_types_page'] : '3,4,5';
        // New approach
        $html = '';

        $html .= '<input type="text" id="club_events_types_page" name="dacdb_plus_options[club_events_types_page]" value="'.$club_events_types_page.'" size="60" placeholder="Enter Event Category ID list from list below (e.g., 1,2,3)" /><br/>';
        $html .= '<p class="EventCatIDDivList"></p>';
        $html .= '<p class="EventCatIDDiv" style="width:100%"></p>';
        echo $html;
    }

    public function club_events_types_side_callback()
    {
        $club_events_types_side = isset($this->options['club_events_types_side']) ? $this->options['club_events_types_side'] : '3,4,5';

        $html = '';
        $html .= '<input type="text" id="club_events_types_side" name="dacdb_plus_options[club_events_types_side]" value="' . $club_events_types_side . '" size="60" placeholder="Enter Event Category ID list from list below (e.g., 1,2,3)" /><br/>';
        $html .= '<p class="EventCatIDDivList"></p>';
        $html .= '<p class="EventCatIDDiv" style="width:100%"></p>';
        echo $html;
    }

    public function district_events_months_callback()
    {
        $district_events_months = isset($this->options['district_events_months']) ? $this->options['district_events_months'] : '1';

        $html = '<select id="district_events_months" name="dacdb_plus_options[district_events_months]">';
        for ($i = 1; $i <= 12; $i++) {
            $html .= '<option value="' . $i . '"' . selected($district_events_months, (string) $i, false) . '>' . $i . '</option>';
        }
        $html .= '<option value="18"' . selected($district_events_months, '18', false) . '>18</option>';
        $html .= '<option value="24"' . selected($district_events_months, '24', false) . '>24</option>';
        $html .= '</select>';
        $html .= '<br><small>How many months of events to show.</small>';
        echo $html;
    }

    public function district_events_months_side_callback()
    {
        $district_events_months_side = isset($this->options['district_events_months_side']) ? $this->options['district_events_months_side'] : '1';
        $html = '<select id="district_events_months_side" name="dacdb_plus_options[district_events_months_side]">';
        for ($i = 1; $i <= 12; $i++) {
            $html .= '<option value="' . $i . '"' . selected($district_events_months_side, (string) $i, false) . '>' . $i . '</option>';
        }
        $html .= '</select>';
        $html .= '<br><small>How many months of events to show.</small>';
        echo $html;
    }

    public function district_events_types_page_callback()
    {
        $district_events_types_page = isset($this->options['district_events_types_page']) ? $this->options['district_events_types_page'] : '1,2,123';
        $html .= '<input type="text" id="district_events_types_page" name="dacdb_plus_options[district_events_types_page]" value="' . $district_events_types_page . '" size="60" placeholder="Enter Event Category ID list from list below (e.g., 1,2,3)" /><br/>';
        $html .= '<p class="EventCatIDDivList"></p>';
        $html .= '<p class="EventCatIDDiv" style="width:100%"></p>';
        echo $html;

    }

    public function district_events_types_side_callback()
    {
        $district_events_types_side = isset($this->options['district_events_types_side']) ? $this->options['district_events_types_side'] : '1,2';
        $html = '<input type="text" id="district_events_types_side" name="dacdb_plus_options[district_events_types_side]" value="' .$district_events_types_side . '" size="60" placeholder="Enter Event Category ID list from list below (e.g., 1,2,3)" /><br/>';
        $html .= '<p class="EventCatIDDivList"></p>';
        $html .= '<p class="EventCatIDDiv" style="width:100%"></p>';
        echo $html;
    }

    public function newsletters_weeks_page_callback()
    {
        $newsletters_weeks_page = isset($this->options['newsletters_weeks_page']) ? $this->options['newsletters_weeks_page'] : '16';
        $html = '<input type="text" id="newsletters_weeks_page" name="dacdb_plus_options[newsletters_weeks_page]" value="' .$newsletters_weeks_page . '" size="60" placeholder="Enter Event Category ID list from list below (e.g., 1,2,3)" /><br/><small>Default: 16</small>';
        echo $html;
    }
    public function newsletters_show_folders_page_callback()
    {
        $newsletters_show_folders_page = isset($this->options['newsletters_show_folders_page']) ? $this->options['newsletters_show_folders_page'] : '0';

        $html = '<select id="newsletters_show_folders_page" name="dacdb_plus_options[newsletters_show_folders_page]">';
        $html .= '<option value="0"' . selected($this->options['newsletters_show_folders_page'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['newsletters_show_folders_page'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        $html .= '<small><br>Will display folders below.</small>';
        echo $html;
    }

    public function newsletters_order_folders_page_callback()
    {
        $newsletters_order_folders_page = isset($this->options['newsletters_order_folders_page']) ? $this->options['newsletters_order_folders_page'] : '0';
        $html = '<select id="newsletters_order_folders_page" name="dacdb_plus_options[newsletters_order_folders_page]">';
        $html .= '  <option value="0"' . selected($this->options['newsletters_order_folders_page'], '0', false) . '>Date</option>';
        $html .= '  <option value="1"' . selected($this->options['newsletters_order_folders_page'], '1', false) . '>Name</option>';
        $html .= '</select>';
        echo $html;
    }

    public function newsletters_weeks_widget_callback()
    {
        $newsletters_weeks_widget = isset($this->options['newsletters_weeks_widget']) ? $this->options['newsletters_weeks_widget'] : '12';
        $html = '<input type="text" id="newsletters_weeks_widget" name="dacdb_plus_options[newsletters_weeks_widget]" value="' .$newsletters_weeks_widget . '" size="3" /><br/><small>Default: 12</small>';
        echo $html;
    }
    public function speakers_months_callback()
    {
        $speakers_months = isset($this->options['speakers_months']) ? $this->options['speakers_months'] : '6';
        $html = '<input type="text" id="speakers_months" name="dacdb_plus_options[speakers_months]" value="' .$speakers_months . '" size="3" /><br/><small>Default: 6</small>';
        echo $html;
    }
    public function speaker_cats_callback()
    {
        $speaker_cats = isset($this->options['speaker_cats']) ? $this->options['speaker_cats'] : '1,2,3,4,5,6,7';
        $html = '<input type="text" id="speaker_cats" name="dacdb_plus_options[speaker_cats]" value="' .$speaker_cats . '" size="60" placeholder="Enter Event Category ID list from list below (e.g., 1,2,3)" /><br/><small>';
        $html .= '<p class="EventCatIDDiv" style="width:100%"></p>';
        echo $html;
    }

    public function speaker_page_full_callback()
    {
        $speaker_page_full = isset($this->options['speaker_page_full']) ? $this->options['speaker_page_full'] : '0';
        $html = '<select id="speaker_page_full" name="dacdb_plus_options[speaker_page_full]">';
        $html .= '<option value="0"' . selected($this->options['speaker_page_full'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['speaker_page_full'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        $html .= '<small><br>This will display all the speaker info on the speaker page.</small>';
        echo $html;
    }

    public function mem_per_page_callback()
    {
        $mem_per_page = isset($this->options['mem_per_page']) ? $this->options['mem_per_page'] : '12';
        $html = '<select id="mem_per_page" name="dacdb_plus_options[mem_per_page]">';
        $html .= '<option value="12"' . selected($mem_per_page, '12', false) . '>12</option>';
        $html .= '<option value="24"' . selected($mem_per_page, '24', false) . '>24</option>';
        $html .= '<option value="36"' . selected($mem_per_page, '36', false) . '>36</option>';
        $html .= '<option value="48"' . selected($mem_per_page, '48', false) . '>30</option>';
        $html .= '<option value="60"' . selected($mem_per_page, '60', false) . '>60</option>';
        $html .= '<option value="5000"' . selected($mem_per_page, '5000', false) . '>ALL</option>';
        $html .= '</select>';
        $html .= '<br><small>Number of members to show per page.</small>';
        echo $html;
    }


    public function pagnationposition_callback()
    {
        $pagnationposition = isset($this->options['pagnationposition']) ? $this->options['pagnationposition'] : 'Left';
        $html = '<select id="pagnationposition" name="dacdb_plus_options[pagnationposition]">';
        $html .= '<option value="Left"' . selected($pagnationposition, 'Left', false) . '>Left</option>';
        $html .= '<option value="Right"' . selected($pagnationposition, 'Right', false) . '>Right</option>';
        $html .= '</select>';
        echo $html;
    }
    public function pagnationposition_tb_callback()
    {
        $pagnationposition_tb = isset($this->options['pagnationposition_tb']) ? $this->options['pagnationposition_tb'] : 'Top';
        $html = '<select id="pagnationposition_tb" name="dacdb_plus_options[pagnationposition_tb]">';
        $html .= '<option value="Top"' . selected($pagnationposition_tb, 'Top', false) . '>Top</option>';
        $html .= '<option value="Bottom"' . selected($pagnationposition_tb, 'Bottom', false) . '>Bottom</option>';
        $html .= '</select>';
        echo $html;
    }
    public function membertypes_callback()
    {
        $membertypes = isset($this->options['membertypes']) ? $this->options['membertypes'] : '0,1,2,5';
        $html = '<input type="text" id="membertypes" name="dacdb_plus_options[membertypes]" value="' .$membertypes . '" size="60" plaxeholder="Enter Member Type ID list from list below (e.g., 1,2,3)" /><br/>';
        $html .= '<p class="MemberTypeIDDivList"></p>';
        $html .= '<p class="MemberTypeIDDiv"></p>';
        echo $html;
    }
    public function members_per_row_callback()
    {
        $members_per_row = isset($this->options['members_per_row']) ? $this->options['members_per_row'] : '1';
        $html = '<select id="members_per_row" name="dacdb_plus_options[members_per_row]">';
        $html .= '<option value="1"' . selected($this->options['members_per_row'], '1', false) . '>1</option>';
        $html .= '<option value="2"' . selected($this->options['members_per_row'], '2', false) . '>2</option>';
        $html .= '<option value="3"' . selected($this->options['members_per_row'], '3', false) . '>3</option>';
        $html .= '<option value="4"' . selected($this->options['members_per_row'], '4', false) . '>4</option>';
        $html .= '</select>';
        $html .= '<small><br>4 per row should only be used with no sidebars. </small>';
        echo $html;
    }
    public function member_pics_callback()
    {
        $member_pics = isset($this->options['member_pics']) ? $this->options['member_pics'] : '1';
        $html = '<select id="member_pics" name="dacdb_plus_options[member_pics]">';
        $html .= '<option value="0"' . selected($this->options['member_pics'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['member_pics'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }

    public function thumbnail_width_callback()
    {
        $thumbnail_width = isset($this->options['thumbnail_width']) ? $this->options['thumbnail_width'] : '150';
        $html = '<input type="text" id="thumbnail_width" name="dacdb_plus_options[thumbnail_width]" value="' .$thumbnail_width . '" size="4"';
        echo $html;
    }

    public function member_club_pos_callback()
    {
        $member_club_pos = isset($this->options['member_club_pos']) ? $this->options['member_club_pos'] : '0';
        $html = '<select id="member_club_pos" name="dacdb_plus_options[member_club_pos]">';
        $html .= '<option value="0"' . selected($this->options['member_club_pos'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['member_club_pos'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function member_bus_name_callback()
    {
        $member_bus_name = isset($this->options['member_bus_name']) ? $this->options['member_bus_name'] : '1';
        $html = '<select id="member_bus_name" name="dacdb_plus_options[member_bus_name]">';
        $html .= '<option value="0"' . selected($this->options['member_bus_name'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['member_bus_name'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function member_bus_pos_callback()
    {
        $member_bus_pos = isset($this->options['member_bus_pos']) ? $this->options['member_bus_pos'] : '1';
        $html = '<select id="member_bus_pos" name="dacdb_plus_options[member_bus_pos]">';
        $html .= '<option value="0"' . selected($this->options['member_bus_pos'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['member_bus_pos'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function member_bus_url_callback()
    {
        $member_bus_url = isset($this->options['member_bus_url']) ? $this->options['member_bus_url'] : '1';
        $html = '<select id="member_bus_url" name="dacdb_plus_options[member_bus_url]">';
        $html .= '<option value="0"' . selected($this->options['member_bus_url'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['member_bus_url'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function member_class_callback()
    {
        $member_class = isset($this->options['member_class']) ? $this->options['member_class'] : '1';
        $html = '<select id="member_class" name="dacdb_plus_options[member_class]">';
        $html .= '<option value="0"' . selected($this->options['member_class'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['member_class'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function members_contact_link_callback()
    {
        $members_contact_link = isset($this->options['members_contact_link']) ? $this->options['members_contact_link'] : '1';
        $html = '<select id="members_contact_link" name="dacdb_plus_options[members_contact_link]">';
        $html .= '<option value="0"' . selected($this->options['members_contact_link'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['members_contact_link'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function members_since_callback()
    {
        $members_since = isset($this->options['members_since']) ? $this->options['members_since'] : '0';
        $html = '<select id="members_since" name="dacdb_plus_options[members_since]">';
        $html .= '<option value="0"' . selected($this->options['members_since'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['members_since'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function members_since_format_callback()
    {
        $members_since_format = isset($this->options['members_since_format']) ? $this->options['members_since_format'] : '0';
        $html = '<select id="members_since_format" name="dacdb_plus_options[members_since_format]">';
        $html .= '<option value="0"' . selected($this->options['members_since_format'], '0', false) . '>Year</option>';
        $html .= '<option value="1"' . selected($this->options['members_since_format'], '1', false) . '>M/D/YYYY</option>';
        $html .= '<option value="2"' . selected($this->options['members_since_format'], '2', false) . '>M/YYYY</option>';
        $html .= '</select>';
        echo $html;
    }
    public function leaders_per_row_callback()
    {
        $leaders_per_row = isset($this->options['leaders_per_row']) ? $this->options['leaders_per_row'] : '1';
        $html = '<select id="leaders_per_row" name="dacdb_plus_options[leaders_per_row]">';
        $html .= '<option value="1"' . selected($this->options['leaders_per_row'], '1', false) . '>1</option>';
        $html .= '<option value="2"' . selected($this->options['leaders_per_row'], '2', false) . '>2</option>';
        $html .= '<option value="3"' . selected($this->options['leaders_per_row'], '3', false) . '>3</option>';
        $html .= '<option value="4"' . selected($this->options['leaders_per_row'], '4', false) . '>4</option>';
        $html .= '</select>  Note: ShortCode override available';
        $html .= '<small><br>4 per row should only be used with no sidebars. </small>';
        echo $html;
    }
    public function club_presidents_per_row_callback()
    {
        $club_presidents_per_row = isset($this->options['club_presidents_per_row']) ? $this->options['club_presidents_per_row'] : '1';
        $html = '<select id="club_presidents_per_row" name="dacdb_plus_options[club_presidents_per_row]">';
        $html .= '<option value="1"' . selected($this->options['club_presidents_per_row'], '1', false) . '>1</option>';
        $html .= '<option value="2"' . selected($this->options['club_presidents_per_row'], '2', false) . '>2</option>';
        $html .= '<option value="3"' . selected($this->options['club_presidents_per_row'], '3', false) . '>3</option>';
        $html .= '<option value="4"' . selected($this->options['club_presidents_per_row'], '4', false) . '>4</option>';
        $html .= '</select>';
        $html .= '<small><br>4 per row should only be used with no sidebars. </small>';
        echo $html;
    }
    public function cog_per_row_callback()
    {
        $cog_per_row = isset($this->options['cog_per_row']) ? $this->options['cog_per_row'] : '1';
        $html = '<select id="cog_per_row" name="dacdb_plus_options[cog_per_row]">';
        $html .= '<option value="1"' . selected($this->options['cog_per_row'], '1', false) . '>1</option>';
        $html .= '<option value="2"' . selected($this->options['cog_per_row'], '2', false) . '>2</option>';
        $html .= '<option value="3"' . selected($this->options['cog_per_row'], '3', false) . '>3</option>';
        $html .= '<option value="4"' . selected($this->options['cog_per_row'], '4', false) . '>4</option>';
        $html .= '</select>';
        $html .= '<small><br>4 per row should only be used with no sidebars. </small>';
        echo $html;
    }
    public function dcc_per_row_callback()
    {
        $dcc_per_row = isset($this->options['dcc_per_row']) ? $this->options['dcc_per_row'] : '1';
        $html = '<select id="dcc_per_row" name="dacdb_plus_options[dcc_per_row]">';
        $html .= '<option value="1"' . selected($this->options['dcc_per_row'], '1', false) . '>1</option>';
        $html .= '<option value="2"' . selected($this->options['dcc_per_row'], '2', false) . '>2</option>';
        $html .= '<option value="3"' . selected($this->options['dcc_per_row'], '3', false) . '>3</option>';
        $html .= '<option value="4"' . selected($this->options['dcc_per_row'], '4', false) . '>4</option>';
        $html .= '</select>';
        $html .= '<small><br>4 per row should only be used with no sidebars. </small>';
        echo $html;
    }
    public function committee_members_per_row_callback()
    {
        $committee_members_per_row = isset($this->options['committee_members_per_row']) ? $this->options['committee_members_per_row'] : '1';
        $html = '<select id="committee_members_per_row" name="dacdb_plus_options[committee_members_per_row]">';
        $html .= '<option value="1"' . selected($this->options['committee_members_per_row'], '1', false) . '>1</option>';
        $html .= '<option value="2"' . selected($this->options['committee_members_per_row'], '2', false) . '>2</option>';
        $html .= '<option value="3"' . selected($this->options['committee_members_per_row'], '3', false) . '>3</option>';
        $html .= '<option value="4"' . selected($this->options['committee_members_per_row'], '4', false) . '>4</option>';
        $html .= '</select>';
        $html .= '<small><br>4 per row should only be used with no sidebars. </small>';
        echo $html;
    }
    public function committee_members_pics_callback()
    {
        $committee_members_pics = isset($this->options['committee_members_pics']) ? $this->options['committee_members_pics'] : '1';
        $html = '<select id="committee_members_pics" name="dacdb_plus_options[committee_members_pics]">';
        $html .= '<option value="0"' . selected($this->options['committee_members_pics'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['committee_members_pics'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function committee_members_contact_link_callback()
    {
        $committee_members_contact_link = isset($this->options['committee_members_contact_link']) ? $this->options['committee_members_contact_link'] : '1';
        $html = '<select id="committee_members_contact_link" name="dacdb_plus_options[committee_members_contact_link]">';
        $html .= '<option value="0"' . selected($this->options['committee_members_contact_link'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['committee_members_contact_link'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function committee_members_committeeposition_callback()
    {
        $committee_members_committeeposition = isset($this->options['committee_members_committeeposition']) ? $this->options['committee_members_committeeposition'] : '1';
        $html = '<select id="committee_members_committeeposition" name="dacdb_plus_options[committee_members_committeeposition]">';
        $html .= '<option value="0"' . selected($this->options['committee_members_committeeposition'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['committee_members_committeeposition'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function committee_members_busposition_callback()
    {
        $committee_members_busposition = isset($this->options['committee_members_busposition']) ? $this->options['committee_members_busposition'] : '1';
        $html = '<select id="committee_members_busposition" name="dacdb_plus_options[committee_members_busposition]">';
        $html .= '<option value="0"' . selected($this->options['committee_members_busposition'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['committee_members_busposition'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function committee_members_classification_callback()
    {
        $committee_members_classification = isset($this->options['committee_members_classification']) ? $this->options['committee_members_classification'] : '1';
        $html = '<select id="committee_members_classification" name="dacdb_plus_options[committee_members_classification]">';
        $html .= '<option value="0"' . selected($this->options['committee_members_classification'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['committee_members_classification'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function leader_pics_callback()
    {
        $leader_pics = isset($this->options['leader_pics']) ? $this->options['leader_pics'] : '1';
        $html = '<select id="leader_pics" name="dacdb_plus_options[leader_pics]">';
        $html .= '<option value="0"' . selected($this->options['leader_pics'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['leader_pics'], '1', false) . '>Yes</option>';
        $html .= '</select> Note: ShortCode override available';
        echo $html;
    }
    public function leaders_contact_link_callback()
    {
        $leaders_contact_link = isset($this->options['leaders_contact_link']) ? $this->options['leaders_contact_link'] : '1';
        $html = '<select id="leaders_contact_link" name="dacdb_plus_options[leaders_contact_link]">';
        $html .= '<option value="0"' . selected($this->options['leaders_contact_link'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['leaders_contact_link'], '1', false) . '>Yes</option>';
        $html .= '</select> note: ShortCode override available';
        echo $html;
    }
    public function map_api_callback()
    {
        $map_api = isset($this->options['map_api']) ? $this->options['map_api'] : '';
        $html = '<input type="text" id="map_api" name="dacdb_plus_options[map_api]" value="' .$map_api . '" size="40" placeholder="Enter Google map API Key" /><br/>';
        echo $html;
    }

    public function committee_global_name_callback()
    {
        $committee_global_name = isset($this->options['committee_global_name']) ? $this->options['committee_global_name'] : '1';
        $html = '<select id="committee_global_name" name="dacdb_plus_options[committee_global_name]">';
        $html .= '<option value="0"' . selected($this->options['committee_global_name'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['committee_global_name'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function committee_global_description_callback()
    {
        $committee_global_description = isset($this->options['committee_global_description']) ? $this->options['committee_global_description'] : '1';
        $html = '<select id="committee_global_description" name="dacdb_plus_options[committee_global_description]">';
        $html .= '<option value="0"' . selected($this->options['committee_global_description'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['committee_global_description'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function committee_global_show_district_number_callback()
    {
        $committee_global_show_district_number = isset($this->options['committee_global_show_district_number']) ? $this->options['committee_global_show_district_number'] : '0';
        $html  = '<select id="committee_global_show_district_number" name="dacdb_plus_options[committee_global_show_district_number]">';
        $html .= '<option value="0"' . selected($this->options['committee_global_show_district_number'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['committee_global_show_district_number'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }

    public function events_global_date_callback()
    {
        $events_global_date = isset($this->options['events_global_date']) ? $this->options['events_global_date'] : '0';
        $html  = '<select id="events_global_date" name="dacdb_plus_options[events_global_date]">';
        $html .= '<option value="0"' . selected($this->options['events_global_date'], '0', false) . '>No</option>';
        $html .= '<option value="1"' . selected($this->options['events_global_date'], '1', false) . '>Yes</option>';
        $html .= '</select>';
        $html .= '<small><br>Will display the date and time then the title of the event, this will update all events/speakers to the same format.</small>';
        echo $html;
    }

    public function cal_display_callback()
    {
		$html = '<select id="cal_display" name="dacdb_plus_options[cal_display]">';
        $html .= '<option value="dayGridMonth"'  . selected($this->options['cal_display'], 'dayGridMonth', false) . '>  Month</option>';
        $html .= '<option value="listMonth"'	 . selected($this->options['cal_display'], 'listMonth', false) . 	'>	List</option>';
        $html .= '</select>';
		echo $html;
    }

    public function cal_limit_callback()
    {
        $cal_limit = isset($this->options['cal_limit']) ? $this->options['cal_limit'] : '4';
        $html = '<select id="cal_limit" name="dacdb_plus_options[cal_limit]">';
        $html .= '<option value="1"' . selected($this->options['cal_limit'], '1', false) . '>1</option>';
        $html .= '<option value="2"' . selected($this->options['cal_limit'], '2', false) . '>2</option>';
        $html .= '<option value="3"' . selected($this->options['cal_limit'], '3', false) . '>3</option>';
        $html .= '<option value="4"' . selected($this->options['cal_limit'], '4', false) . '>4</option>';
        $html .= '<option value="5"' . selected($this->options['cal_limit'], '5', false) . '>5</option>';
        $html .= '<option value="6"' . selected($this->options['cal_limit'], '6', false) . '>6</option>';
        $html .= '<option value="7"' . selected($this->options['cal_limit'], '7', false) . '>7</option>';
        $html .= '<option value="8"' . selected($this->options['cal_limit'], '8', false) . '>8</option>';
        $html .= '<option value="9"' . selected($this->options['cal_limit'], '8', false) . '>9</option>';
        $html .= '</select>';
        $html .= '<small><br>Number of events shown on any one day in Month view.</small>';
        echo $html;
    }

    public function wcm_show_title_callback()
    {
        $wcm_show_title = isset($this->options['wcm_show_title']) ? $this->options['wcm_show_title'] : '1';
        $html = '<select id="wcm_show_title" name="dacdb_plus_options[wcm_show_title]">';
        $html .= '<option value="No"'  . selected($this->options['wcm_show_title'], 'No', false) . '>No</option>';
        $html .= '<option value="Yes"' . selected($this->options['wcm_show_title'], 'Yes', false) . '>Yes</option>';
        $html .= '</select>';
        echo $html;
    }
    public function wcm_show_layout_callback()
    {
        $wcm_show_layout = isset($this->options['wcm_show_layout']) ? $this->options['wcm_show_layout'] : 'default';
        $html = '<select id="wcm_show_layout" name="dacdb_plus_options[wcm_show_layout]">';
        $html .= '<option value="default"'  . selected($this->options['wcm_show_layout'], 'default', false) . '>Default</option>';
        $html .= '<option value="area"'     . selected($this->options['wcm_show_layout'], 'area', false) . '>Area</option>';
        $html .= '<option value="date"'     . selected($this->options['wcm_show_layout'], 'date', false) . '>Date</option>';
        $html .= '<option value="detail"'   . selected($this->options['wcm_show_layout'], 'detail', false) . '>Detail</option>';
        $html .= '<option value="club"'     . selected($this->options['wcm_show_layout'], 'club', false) . '>Club</option>';
        $html .= '<option value="officers"' . selected($this->options['wcm_show_layout'], 'officers', false) . '>Club Officers</option>';
        $html .= '</select>';
        $html .= '<small><br>Use Default if your using sort in the shortcode.</small>';
        echo $html;
    }
}
//!SECTION - Class DACdbSetting

//ANCHOR - Initialize the Plugin
//ANCHOR - Performs actions for administrators.
if (is_admin()) {

    /**
     * Settings page for DACdb.
     *
     * @var DACdbSetting $my_settings_page The DACdb settings page.
     */
    $my_settings_page = new DACdbSetting();

    /**
     * Adds shortcode button script to the admin footer.
     *
     * @see shortcode_button_script()
     */
    add_action("admin_print_footer_scripts", "shortcode_button_script");

    /**
     * Retrieves the DACdb plus options.
     *
     * @var array $options The DACdb plus options.
     */
    $options = get_option('dacdb_plus_options', array());

    /**
     * Checks if the 'dacdb_club' option is empty and displays a notice if true.
     *
     * @see dacdb_missing_club()
     */
    if (isset($options['dacdb_club']))
    {
        $club_id = $options['dacdb_club'];
    } else {
        add_action('admin_notices', 'dacdb_missing_club');
    }

    /**
     * Checks if the 'dacdb_district' option is empty and displays a notice if true.
     *
     * @see dacdb_missing_district()
     */
    if (isset($options['dacdb_district']))
    {
        $account_id = $options['dacdb_district'];
    } else {
        add_action('admin_notices', 'dacdb_missing_district');
    }

    /**
     * Checks if the 'dacdb_system' option is empty and displays a notice if true.
     *
     * @see dacdb_missing_system()
     */
    if (isset($options['dacdb_system']))
    {
        $this_system = $options['dacdb_system'];
    } else {
        add_action('admin_notices', 'dacdb_missing_system');
    }

    /**
     * Checks if the 'dacdb_apikey' option is empty and displays a notice if true.
     *
     * @see dacdb_missing_system()
     */
    //if (isset($options['dacdb_apikey']))
    //{
    //    $this_system = $options['dacdb_apikey'];
    //} else {
    //    add_action('admin_notices', 'dacdb_apikey');
    //}

    /**
     * Adds a filter to modify plugin action links.
     *
     * @param string $plugin The plugin file.
     *
     * @see Dacdb_Plus_Settings_Link()
     */
    add_filter("plugin_action_links_$plugin", 'Dacdb_Plus_Settings_Link');

    /**
     * Adds CSS to the admin head.
     *
     * @see Dacdb_css()
     */
    add_action('admin_head', 'Dacdb_css');
}

class InvalidShortcodeException extends Exception
{
}

//SECTION - Class dacdb_plus

if (!class_exists('dacdb_plus')) {
    /**
     * Class dacdb_plus
     *
     * Description: This class defines a plugin called 'dacdb_plus' with various methods and functions.
     */
    class dacdb_plus
    {

        /**
         * Constructor method.
         *
         * Registers the plugin, adds a shortcode, and enqueues JavaScript files.
         */

        function dacdb_plus_register()
        {
            register_widget('DACDB_Plus_Widget');
        }

        function __construct()
        {
            //Register Plugin
            add_action('widgets_init', array($this, 'dacdb_plus_register'));
            //Add Core Functionality Shortcode
            add_shortcode('dacdb_plus', array($this, 'dacdb_plus_function'));
            //Add JavaScript Files
            add_action('wp_footer', array($this, 'dacdb_plus_js'));
            add_action('wp_footer', array($this, 'pagination'));
            add_action('wp_footer', array($this, 'moment2'));
            add_action('wp_footer', array($this, 'fullcalendar'));
            //add_action('wp_footer', 'Dacdb_js');   //storyscript calls the js needed.
        }

        /**
         * Activate method.
         *
         * Does nothing as the plugin doesn't use WordPress classes or functions.
         */
        public static function activate()
        {
            // Do nothing plug in does not use Wordpress classes or functions
        }
        /**
         * Deactivate method.
         *
         * Does nothing as the plugin doesn't use WordPress classes or functions.
         */
        public static function deactivate()
        {
            // Do nothing plug in does not use Wordpress classes or functions
        }
        /**
         * Enqueues the 'dacdb-plus-js' JavaScript file.
         */
        public function dacdb_plus_js()
        {
            wp_enqueue_script('dacdb-plus-js', plugins_url('js/dacdb_plus.js', __FILE__), '', $GLOBALS['plugin_version']);
        }
        /**
         * Enqueues the 'pagination' JavaScript file.
         */
        public function pagination()
        {
            wp_enqueue_script('pagination', plugins_url('js/pagination.js', __FILE__), '', $GLOBALS['plugin_version']);
        }

        /**
         * Enqueues the 'moment2' JavaScript file.
         */
        public function moment2()
        {
            wp_enqueue_script('moment2', plugins_url('js/moment.min.js', __FILE__), '', $GLOBALS['plugin_version']);
        }
        /**
         * Enqueues the 'fullcalendar' JavaScript file.
         */
        public function fullcalendar()
        {
            // wp_enqueue_script('fullcalendar', plugins_url('js/fullcalendar.min.js', __FILE__), '', $GLOBALS['plugin_version']);
            wp_enqueue_script('fullcalendar', plugins_url('js/index.global.min.js', __FILE__), '', $GLOBALS['plugin_version']);
        }

        //ANCHOR - Process Shortcode
        //FIXME - This is the main function that processes the shortcode
        /**
         * Processes the 'dacdb_plus' shortcode.
         *
         * @param array $atts An associative array of shortcode attributes.
         *
         *        Supported attributes:
         *        - 'show' (string): The type of content to display.
         *        - 'storyid' (string): The ID of the story.
         *        - 'catid' (string): The ID of the category.
         *        - 'catids' (string): Comma-separated IDs of categories.
         *        - 'separator' (string): The separator for displayed items.
         *        - 'imgwidth' (string): The pixel width of the thumbnail image in member galleries.
         *        - 'org' (string): Deprecated attribute (organization).
         *        - 'orgyear' (string): The year of the organization.
         *        - 'description' (string): The description of the content.
         *        - 'folder' (string): The folder for documents.
         *        - 'sort' (string): The sorting order for clubs.
         *        - 'cid' (string): The ID of the committee.
         *        - 'row' (string): The number of rows to display.
         *        - 'style' (string): The style of the content.
         *        - 'icon' (int): Whether to display icons (1 for true, 0 for false).
         *        - 'size' (int): The size of the content.
         *        - 'date' (int): Whether to display dates (1 for true, 0 for false).
         *        - 'club_id' (string): The ID of the club.
         *
         * @return string The accumulated output of the shortcode processing.
         */
        public function dacdb_plus_function($atts)
        {
            global $plugin_version, $fDebug, $data_path, $file_path, $options;
            //NOTE - Handle Shortcode Attributes
            extract(
                shortcode_atts(
                    array(
                        'show' => '',
                        'storyid' => '',
                        'catid' => '',
                        'catids' => '',
                        'separator' => '',
                        'display' => '',            //NOTE -  removed
                        'pagetitle' => '',          //NOTE -  removed
                        'org' => '',                //NOTE -  depreciated
                        'orgyear' => '',
                        'description' => '',
                        'imgwidth' => '',
                        'folder' => '',             //NOTE -  for documents
                        'sort' => '',               //NOTE -  where clubs meet
                        // committee                //REVIEW - not used
                        'cid' => '',
                        'row' => '',
                        'style' => '',              //NOTE -  New
                        // documents                //REVIEW - not used
                        'icon' => 1,
                        'size' => 1,
                        'date' => 1,
                        'club_id' => '',
                    ),
                    $atts,
                    'dacdb_plus'
                )
            );

            $pagedata = "";     //NOTE -  output for short code need to be returned.  so this variable accumulates the output.  Each short code does their own
            //NOTE -  get the settings here - update widgets at bottom if this changes!!!
            $options = get_option('dacdb_plus_options', array());
            setDataPath();   //NOTE - ShortCode DACdb or iMembersDB paths

            if ($data_path == '') {
                $pagedata .= "=================================================================<BR>";
                $pagedata .=  "Missing System selection under Plugin Settings!<BR>";
                $pagedata .=  "data_path=" . $data_path;
                $pagedata .=  "=================================================================<BR>";
                $pagedata .=  "<BR>";
            }

            //REVIEW - $subscription = file_get_contents($data_path.'wp_subscription.cfm?AccountID='.$options['dacdb_district'].'&ClubID='.$options['dacdb_club']);
            $xml = simplexml_load_file($data_path . 'wp_subscription2.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club']);
            if ($xml->status != '1') {
                $pagedata .= "=================================================================<BR>";
                $pagedata .=  "&nbsp; &nbsp;  Missing subscription record. System=" . $options['dacdb_system'] . ", AccountID=" . $options['dacdb_district'] . ", ClubID=" . $options['dacdb_club'] . "<BR>";
                $pagedata .=  "&nbsp; &nbsp;  Please contact: support@dacdb.com<BR>";
                $pagedata .=  "data_path=" . $data_path . "<br>";
                $pagedata .=  "subscription=" . $xml->status . "<br>";
                $pagedata .=  "ip_server=" . $_SERVER['SERVER_ADDR'] . "<br>";
                $pagedata .=  "php version=" . phpversion() . "<br>";
                if ($fDebug) {
                    $pagedata .=  "&nbsp; &nbsp;  url=" . $data_path . 'wp_subscription2.cfm?AccountId=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . "<BR>";
                }
                $pagedata .=  "=================================================================<BR>";
                $pagedata .=  "<BR>";
            }

            if ($fDebug) {
                $pagedata .=  "=================================================================<BR>";
                $pagedata .=  "Version=" . $plugin_version . "<br>";
                $pagedata .=  "Show=" . $show . "<br>";
                $pagedata .=  "CatID=" . $GLOBALS['catid'] . "<br>";
                $pagedata .=  "System=" . $options['dacdb_system'] . "<BR>";
                $pagedata .=  "data_path=" . $data_path . "<BR>";
                $pagedata .=  "file_path=" . $file_path . "<BR>";
                $pagedata .=  "public_path=" . $public_path . "<BR>";
                $pagedata .=  "subscription=" . $xml->status . "<BR>";
                $pagedata .=  "ip_server=" . $_SERVER['SERVER_ADDR'] . "<br>";
                $pagedata .=  "php version=" . phpversion() . "<br>";
                $pagedata .=  "=================================================================<BR>";
                print("<div><strong>XML Data:</strong><pre>" . print_r($xml, true) . "</pre></div>");
                //print("<div><strong>GLOBALS:</strong><pre>".var_dump($GLOBALS)."</pre></div>");
                print("<div class=\"info-msg\"><strong>Options: </strong><pre>" . var_dump($options) . "</pre></div>");
                print("<div class=\"info-msg\"><strong>Show:</strong> <pre>" . var_dump($show) . "</pre></div>");
            }
            try {
                //NOTE - wcm master, club_meetings and meeting_info deprecated
                $show = strtolower(str_replace(' ', '', $show));
                switch ($show) {
                    case 'areas':
                        $pagedata .=  dacdb_areas($atts);
                        break;
                    case 'birthdays':
                        $pagedata .=  dacdb_birthdays($atts);
                        break;
                    case 'calendar':
                        $pagedata .= dacdb_calendar($atts);
                        break;
                    case 'cog':
                        $pagedata .=  dacdb_cog($atts);
                        break;
                    case 'club_meetings':
                        $pagedata .=  dacdb_club_meetings($atts);
                        break;
                    case 'club_presidents':
                        $pagedata .=  dacdb_club_presidents($atts);
                        break;
                    case 'clubleaders':
                        $pagedata .=  dacdb_clubleaders($atts);
                        break;
                    case 'committee':
                        $pagedata .=  dacdb_committee($atts);
                        break;
                    case 'committee_leaders':
                        $pagedata .=  dacdb_committee_leaders($atts);
                        break;
                    case 'committees':
                        $pagedata .=  dacdb_committees($atts);
                        break;
                    case 'events':
                    case 'd_events':
                        $pagedata .=  dacdb_events($atts);
                        break;
                    case 'd_leaders':
                        $pagedata .=  dacdb_d_leaders($atts);
                        break;
                    case 'dcc':
                        $pagedata .=  dacdb_dcc($atts);
                        break;
                    case 'documents':
                        $pagedata .=  dacdb_documents($atts);
                        break;
                    case 'leaders':
                        $pagedata .=  dacdb_leaders($atts);
                        break;
                    case 'map':
                        $pagedata .=  dacdb_map($atts);
                        break;
                    case 'meeting_info':
                        $pagedata .=  dacdb_meeting_info($atts);
                        break;
                    case 'members':
                        $pagedata .=  dacdb_members($atts);
                        break;
                    case 'newsletter':
                    case 'newsletters':
                        $pagedata .=  dacdb_newsletter($atts);
                        break;
                    case 'sponsors':
                        $pagedata .=  dacdb_sponsors($atts);
                        break;
                    case 'speakers':
                        $pagedata .=  dacdb_speakers($atts);
                        break;
                    case 'stories':
                        $pagedata .= dacdb_stories($atts);
                        break;
                    case 'wcm':
                        $pagedata .=  dacdb_wcm($atts);
                        break;
                    case 'jsonclubleaders':
                        $pagedata .=  dacdb_jsonclubleaders($atts);
                        break;

                    default:
                        throw new InvalidShortcodeException("Invalid shortcode 'show' value encountered: <em>{$show}</em>");
                        //NOTE - wcm master, club_meetings and meeting_info deprecated
                }
            } catch (InvalidShortcodeException $e) {
                // Handle the exception, such as logging the error or displaying a user-friendly message
                $pagedata .= "<div class=\"error-msg\"><i class=\"fa fa-times-circle\"></i>{$e->getMessage()}</div>";
            }

            return $pagedata;
        }
    }
}

//!SECTION - Class dacdb_plus

//SECTION Process Shortcode Functions

//ANCHOR - Show Areas
function dacdb_areas($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $areas = '';

    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];
    $thumbnail_width = isset($options['thumbnail_width']) && $options['thumbnail_width'] > 0 ? $options['thumbnail_width'] : (isset($atts['imgwidth']) && $atts['imgwidth'] > 0 ? $atts['imgwidth'] : 150);
    $rolekeys   = isset($atts['rolekeys']) ? $atts['rolekeys'] : 'AG';
    $region     = isset($atts['region']) ? $atts['region'] : '0';
    $style      = isset($atts['style']) ? $atts['style'] : '1';

    if ($fDebug) {
        $areas .= "=================================================================<BR>";
        $areas .= "function dacdb_areas called<br>";
        $areas .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $areas .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $areas .= "imgWidth=" . $thumbnail_width . "<br>";
        $areas .= "RoleKeys=" . $rolekeys . "<br>";
        $areas .= "Style=" . $style . "<br>";
        $areas .= "Thumbnail Width =" . $options['thumbnail_width'] . "<br>";
        $areas .= "url=" . $data_path . 'wp_areav2.cfm?AccountID=' . $options['dacdb_district'] . '&rolekeys=' . $rolekeys . '&Region=' . $region . "<br>";
        $areas .= "=================================================================<BR>";
    }

    $xml = simplexml_load_file($data_path . 'wp_areav2.cfm?AccountID=' . $options['dacdb_district'] . '&rolekeys=' . $rolekeys . '&Region=' . $region . '&R=' . rand());
    if (strlen($xml) == 0) {
        $areas .= 'There are no areas/regions to display at this time.';
        return $areas;
    }


	// Display areas based on the provided style
	switch ($style) {

		case '0':   // linear list of AGs (1 column)
		case '1':   // linear list of AGs (1 column)
			$counter = 1;
			$areas .= '<table  style="vertical-align: top;padding:0;border:0 !important;">';
			foreach ($xml->area as $area) {
				$officer_total = count($area->officers);
				if ($officer_total > 0) {
					foreach ($area->officers->officer as $officer) {
						$areas .= '<tr><td style="padding-right:15px;width:150px;vertical-align: top;padding:5px;border:0 !important;"><img src="' . $officer->imgpath . '' . $officer->image . '" style="aspect-ratio: 4 / 5; width: ' . $thumbnail_width  . 'px; object-fit: cover;" width="' . $thumbnail_width  . '"></td>';
						$areas .= '<td valign="top" style="vertical-align: top;padding:0;border:0 !important;">';
						$areas .= '<b>'. $officer->areaposition . ' ' .  $area->regionlabel . ' ' . $area->area . '</b><br>' . $officer->membername . '';
						$areas .= '<br><b>Club:</b> ' . $officer->clubname . '<br><b>Area ' . $area->area . ' Clubs:</b> ' . $area->areaclubs . '';
						$areas .= '<br><br><a href="' . $data_path . 'R_Emailer.cfm?UserID=' . $officer->userid . '" name="dlc-inline-link-' . $counter . '" class="iframe3 cboxElement">Contact</a>';
						$areas .= '</td></tr>';
						$areas .= '<tr><td colspan="2" style="vertical-align: top;padding:0;border:0 !important;"><hr></td></tr>';
						$counter = $counter + 1;
					}
				}
			}
			$areas .= '</table>';
			return $areas;
			break;

		case '2':    // areas grouped
			$counter = 1;
			foreach ($xml->area as $area) {
				$areas .= '<h3>'. $area->regionlabel . ' ' . $area->area . '</h3><br>';
				$areas .= '<table  style="border:0 !important; vertical-align: top;padding:0;border:5 !important;" width="100%">';
				$areas .= '	<tr>';
				$areas .= '		<td style="border:0 !important;vertical-align: top; padding:0;" >';

				$officer_total = count($area->officers);
				if ($officer_total > 0) {
					$areas .= '			<table style="width: 400px; vertical-align: top;padding:0; border:0">';
					foreach ($area->officers->officer as $officer) {
						$areas .= '			<tr>';
						$areas .= '				<td style="padding-right:15px;width:150px;vertical-align: top;padding:5px; border:0 !important;"><img src="' . $officer->imgpath . '' . $officer->image . '" style="aspect-ratio: 4 / 5; width: ' . $thumbnail_width  . 'px; object-fit: cover;" width="' . $thumbnail_width  . '"></td>';
						$areas .= '				<td valign="top" style="width: 250px; vertical-align: top;padding:0;border:0 !important;">';
						$areas .= '					<b>'. $officer->areaposition . '</b><br/>';
						$areas .= '					'. $officer->membername . '<br/>';
						$areas .= '					<b>Club:</b> ' . $officer->clubname . '<br/>';
						$areas .= '					<a href="' . $data_path . 'R_Emailer.cfm?UserID=' . $officer->userid . '" name="dlc-inline-link-' . $counter . '" class="iframe3 cboxElement">Contact</a>';
						$areas .= '				</td>';
						$areas .= '			</tr>';
						$counter = $counter + 1;
					}
					$areas .= '		</table>';
				}
				$areas .= '		</td>';
				$areas .= '		<td style="border:0 !important;vertical-align: top; padding:0;">';
				$areas .= '			<b>Area ' . $area->area . ' Clubs:</b> <br />';
				$areas .= '			' . $area->areaclubs . '<br />';
				$areas .= '		</td>';
				$areas .= '	</tr>';
				$areas .= '<tr><td colspan="2" style="vertical-align: top;padding:0;border:0 !important;"><hr></td></tr>';
				$areas .= '</table>';
			}
			return $areas;
			break;

			case '3':    // areas grouped - list clubs
				$counter = 1;
				foreach ($xml->area as $area) {
					$clubs = explode(', ', $area->areaclubs);

					$areas .= '<h3>'. $area->regionlabel . ' ' . $area->area . '</h3><br>';
					$areas .= '<table  style="vertical-align: top;padding:0;border: 0 !important;">';
					$areas .= '	<tr>';
					$areas .= '		<td style="border:0 !important; vertical-align: top; padding:0; width: 400px;" >';

					$officer_total = count($area->officers);
					if ($officer_total > 0) {
						$areas .= '			<table style="vertical-align: top;padding:0; border:0 ">';
						foreach ($area->officers->officer as $officer) {
							$areas .= '			<tr>';
							$areas .= '				<td style="padding-right:15px;width:150px;vertical-align: top;padding:5px; border:0 !important;"><img src="' . $officer->imgpath . '' . $officer->image . '" style="aspect-ratio: 4 / 5; width: ' . $thumbnail_width  . 'px; object-fit: cover;" width="' . $thumbnail_width  . '"></td>';
							$areas .= '				<td valign="top" style="width: 250px; vertical-align: top;padding:0;border:0 !important;">';
							$areas .= '					<b>'. $officer->areaposition . '</b><br/>';
							$areas .= '					'. $officer->membername . '<br/>';
							$areas .= '					<b>Club:</b> ' . $officer->clubname . '<br/>';
							$areas .= '					<a href="' . $data_path . 'R_Emailer.cfm?UserID=' . $officer->userid . '" name="dlc-inline-link-' . $counter . '" class="iframe3 cboxElement">Contact</a>';
							$areas .= '				</td>';
							$areas .= '			</tr>';
							$counter = $counter + 1;
						}
						$areas .= '		</table>';
					}
					$areas .= '		</td>';
					$areas .= '		<td align="left" style="border: 0!important;vertical-align: top; padding:0;">';
					$areas .= '			<b>Area ' . $area->area . ' Clubs:</b> <br />';
					$areas .= '			<UL>';
					foreach ($clubs as $Club) {
						$areas .= '			<LI>' .  $Club . '</LI>';
					  }
					$areas .= '			</UL>';
					$areas .= '		</td>';
					$areas .= '	</tr>';
					$areas .= '<tr><td colspan="2" style="vertical-align: top;padding:0;border:0 !important;"><hr></td></tr>';
					$areas .= '</table>';
				}
				return $areas;
				break;
		default:
			$areas .= "=================================================================<BR>";
			$areas .= "&nbsp;&nbsp;&nbsp;Invalid style selected [" . $style . "]<BR>";
			$areas .= "=================================================================<BR>";
			return $areas;
			break;
	}
	return $areas;
}


//ANCHOR - Show Birthdays
function dacdb_birthdays($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $members = '';
    $thumbnail_width = isset($options['thumbnail_width']) && $options['thumbnail_width'] > 0 ? $options['thumbnail_width'] : (isset($atts['imgwidth']) && isset($atts['imgwidth']) > 0 ? $atts['imgwidth'] : 150);

    if ($fDebug) {
        $members .= '<div class="info-msg"><i class="fa fa-info-circle"></i>Debug Mode is On</div>';
        $members .= '<div class="debug">function <em>dacdb_birthdays</em> called<br>';
        $members .= 'AccountID: ' . $options['dacdb_district'] . '<br>';
        $members .= 'ClubID: ' . $options['dacdb_club'] . '<br>';
        $members .= 'URL: <a href="' . $data_path . 'wp_birthdays.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '" target="DEBUG">' . $data_path . 'wp_birthdays.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '</a><br>';
        $members .= "</div>";
    }

    $xml = simplexml_load_file($data_path . 'wp_birthdays.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&R=' . rand());
    if (strlen($xml) == 0) {
        $members .= 'There are no upcoming birthdays at this time.';
        return $members;
    }

    $counter = 1;
    $members .= '<div class="grid">';
    foreach ($xml->birthday as $birthday) {
        $members .= '<div class="dac-col-6-12" style="overflow:hidden;margin-bottom:20px;">';
        if ($birthday->image == '') {
            $members .= '<div style="width:200px; float:left; min-height: 100px;"><img src=' . plugins_url('img/no_image.jpg', __FILE__) . '" style="aspect-ratio: 4 / 5; width: ' . $thumbnail_width  . 'px; object-fit: cover;" width="' . $thumbnail_width  . '"></div>';
        } else {
            $members .= '<div style="width:200px; float:left; min-height: 100px;"><img src="' . $birthday->image . '" style="aspect-ratio: 4 / 5; width: ' . $thumbnail_width  . 'px; object-fit: cover;" width="' . $thumbnail_width  . '"></div>';
        }
        $members .= '<b>' . $birthday->membername . '</b><br>';
        if ($birthday->clubid > 0)
            $members .= $birthday->clubname . '<br />';
        $members .= $birthday->birthday . '<br>';
        $members .= '</div>';
        $counter = $counter + 1;
    }
    $members .= '</div>';
    return $members;
}

//ANCHOR - Show Leaders
/**
 * Generates and displays a list of leaders for a club, chapter, or branch.
 *
 * @param array $atts An associative array of attributes for the function.
 * @return string The HTML markup for displaying the list of leaders.
 */
function dacdb_leaders($atts)
{
    global $fDebug, $data_path, $file_path, $options;
    $members = ''; // Initialize the variable to store the generated HTML markup for leaders

    $account_id = $options['dacdb_district']; // Retrieve the AccountID from options
    $club_id    = $options['dacdb_club']; // Retrieve the ClubID from options

    // Set leaders_per_row attribute or use default value from options if not specified
    // If leaders_per_row is not set, use the default from the options, or 1 if options is empty.

    if (isset($atts['leaders_per_row']) && $atts['leaders_per_row'] == '') {
        if (isset($options['leaders_per_row']) && $options['leaders_per_row'] != '') {
            $atts['leaders_per_row'] = $options['leaders_per_row'];
        } else {
            $atts['leaders_per_row'] = 1;
        }
    }

    // Set default value for leaders_per_row if not specified in options
    if (isset($options['leaders_per_row']) && $options['leaders_per_row'] == '')
        $atts['leaders_per_row'] = 1;

    // Set leader_pics attribute or use default value from options if not specified
    if (isset($atts['leader_pics']) && $atts['leader_pics'] == '')
        $atts['leader_pics'] = $options['leader_pics'];

    // Set default value for leader_pics if not specified in options
    if (isset($atts['leader_pics']) && $options['leader_pics'] == '')
        $atts['leader_pics'] = 1;

    // Set leaders_contact_link attribute or use default value from options if not specified
    if (isset($atts['leaders_contact_link']) && $atts['leaders_contact_link'] == '')
        $atts['leaders_contact_link'] = $options['leaders_contact_link'];

    // Set default value for leaders_contact_link if not specified in options
    if (isset($atts['leaders_contact_link']) && $options['leaders_contact_link'] == '')
        $atts['leaders_contact_link'] = 1;

    // Set flex attribute or use 'N' as default value if not specified
    if (isset($atts['flex']) && $atts['flex'] == '')
        $atts['flex'] = 'N';

    // Check if the ClubID is 0, and return an error message if so
    if ($club_id == 0) {
        $members .= "=================================================================<BR>";
        $members .= "Error: This function can only be used to display club, chapter, branch leaders. The ClubID configured is  0.<br>";
        $members .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $members .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $members .= "=================================================================<BR>";
        return $members;
    }

    // If debug mode is enabled, generate a debug message with function information
    if ($fDebug) {
        $members .= "=================================================================<BR>";
        $members .= "function dacdb_leaders called<br>";
        $members .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $members .= "data_file=" . $data_file . "<br>";
        $members .= "data_path=" . $data_path . "<br>";
        $members .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $members .= "leaders_per_row=" . $options['leaders_per_row'] . "<br>";
        $members .= "leaders_per_row override=" . $atts['leaders_per_row'] . "<br>";
        $members .= "leader_pics=" . $options['leader_pics'] . "<br>";
        $members .= "leader_pics override=" . $atts['leader_pics'] . "<br>";
        $members .= "flex=" . $atts['flex'] . "<br>";
        $members .= "URL=" . $data_path . 'wp_leaders.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $club_id . '<br>';
        $members .= "=================================================================<BR>";
    }

    // Load the XML data containing leaders information
    $xml = simplexml_load_file($data_path . 'wp_leaders.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $club_id . '&R=' . rand());

    // If XML is empty, return a message indicating no leaders to display
    if (strlen($xml) == 0) {
        $members .= 'There are no club leaders to display at this time.';
        return $members;
    }

    // Loop through each leader and generate HTML markup for their information
    $counter = 1;
    $lastCounter = count($xml->leader);
    $grid_counter = 0;
    foreach ($xml->leader as $leader) {
        $grid_counter = $grid_counter + 1;

        // Force single row if leaders_per_row is set to 1
        if ($options['leaders_per_row'] == 1) {
            $grid_counter = 1;
        }

        // Open a new row div if it's the first leader in the row
        if ($grid_counter == 1) {
            $members .= '<div class="dac-row">';
        }

        // Set the width of div and image based on leaders_per_row value
        $setDivWidth = 160;
        $setImgWidth = 150;

        // Adjust div and image width for different leaders_per_row values
        if ($options['leaders_per_row'] == 4) {
            $members .= '<div class="members dac-col-xs-12 dac-col-sm-6 dac-col-md-3 dac-col-lg-3">';
            $setDivWidth = 120;
            $setImgWidth = 110;
        } else if ($options['leaders_per_row'] == 3) {
            $members .= '<div class="members dac-col-xs-12 dac-col-sm-12 dac-col-md-4">';
        } else if ($options['leaders_per_row'] == 2) {
            $members .= '<div class="members dac-col-xs-12 dac-col-sm-6">';
        } else {
            $members .= '<div class="members dac-col-xs-12">';
        }

        // Generate HTML markup for leader information and append it to $members variable
        if ($options['leader_pics'] == 1) {
            if ($leader->image == '') {
                $members .= '<table style="vertical-align: top;padding:0;border:0 !important;"><tr><td style="border:0 !important;vertical-align: top;padding:0;max-width:' . $setDivWidth . 'px;width:' . $setDivWidth . 'px"><img src="' . plugins_url('img/no_image.jpg', __FILE__) . '" style="max-width:' . $setImgWidth . 'px; aspect-ratio: 4 / 5; width: 160px; height: 200px; object-fit: cover;" class="leadership_image portrait"></td>';
            } else {
                $members .= '<table style="vertical-align: top;padding:0;border:0 !important;"><tr><td style="border:0 !important;vertical-align: top;padding:0;max-width:' . $setDivWidth . 'px;width:' . $setDivWidth . 'px"><img src="' . $leader->imgpath . '' . $leader->image . '" style="max-width:' . $setImgWidth . 'px; aspect-ratio: 4 / 5; width: 160px; height: 200px; object-fit: cover;" class="leadership_image portrait"></td>';
            }
        }
        $members .= '<td style="border:0 !important;max-width:1px;width:1px;padding:0;">&nbsp;</td><td style="border:0 !important;vertical-align: top;padding:0;"><b>' . $leader->username . '</b><br>' . $leader->clubposition . '<br>';

        // Append contact link if leaders_contact_link is enabled
        if ($options['leaders_contact_link'] == 1) {
            $members .= '<a href="' . $data_path . 'R_Emailer.cfm?UserID=' . $leader->userid . '" name="dlc-inline-link-' . $counter . '" class="iframe3 cboxElement">Contact</a>';
        }

        $members .= '</td></tr></table></div>';

        // Close the row div if it's the last leader in the row
        if ($grid_counter == $options['leaders_per_row']) {
            $members .= '</div>';
            $grid_counter = 0;
        }

        $counter = $counter + 1;
    }

    // Append a comment with counter values for debugging purposes
    $members .= '<!-- ' . $lastCounter . '-' . $counter . '-' . $grid_counter . ' -->';

    // Close any remaining open divs
    if ($grid_counter > 0) {
        $members .= '</div><!-- end  -->';
    }

    // Calculate the total number of leaders
    $leader_total = count($xml->leader);

    // If there are no leaders, append a message indicating so
    if ($leader_total == 0) {
        $members .= 'There are no leaders to display at this time.';
    }

    // Return the generated HTML markup for leaders
    return $members;
}

//ANCHOR - Show Club Leaders
/**
 * Retrieves and displays club leaders' information.
 *
 * @param array $atts An array of attributes (optional).
 *
 * @return string The HTML representation of club leaders' information.
 */
function dacdb_clubleaders($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $members = '';

    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];
    $rolekeys   = isset($atts['rolekeys']) ? $atts['rolekeys'] : 'P,S';
    $style      = isset($atts['style']) ? $atts['style'] : 1;

    // Debug information
    if ($fDebug) {
        $members .= "=================================================================<BR>";
        $members .= "function dacdb_clubleaders called <br>";
        $members .= "AccountID=" . $account_id . "<br>";
        $members .= "ClubID=" . $club_id . "<br>";
        $members .= "Style=" . $style . "<br>";
        $members .= "RoleKeys=" . $rolekeys . "<br>";
        $members .= "URL=" . $data_path . 'wp_clubleaders.cfm?AccountID=' . $account_id . '&ClubID=' . $club_id . '&rolekeys=' . $rolekeys . "<br>";
        $members .= "=================================================================<BR>";
    }

    // Retrieve XML data from the data source
    $xml = simplexml_load_file($data_path . 'wp_clubleaders.cfm?AccountID=' . $account_id . '&ClubID=' . $club_id . '&rolekeys=' . $rolekeys . '&R=' . rand());

    // Check if the XML data is empty or loading failed
    if (empty($xml)) {
        $members .= 'There are no club leaders to display at this time.';
        return $members;
    }
    // Generate the HTML representation of club leaders' information
    $members .= dacdb_DisplayClub($xml, $style, $atts); // <clubs><club>...<officers /></club?</clubs>

    return $members;
}

//ANCHOR - Show JSON club leaders
/**
 * Retrieves information about club leaders from the DACdb API.
 *
 * @param array $atts An array of attributes passed to the function.
 *
 * @return string The information about club leaders.
 */
function dacdb_jsonclubleaders($atts)
{
    // Global variables
    global $fDebug, $data_path, $file_path, $options;

    // Initialize the members variable
    $members = '';

    // Retrieve the district and club IDs from the options
    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];

    // API endpoint URL for retrieving club leaders filtered by DG, DGE, and DGN roles
    $url = "https://dacdb.net:9400/API/v1.0/Zone/Leaders?api_key=630a8ae797094e3dbf63baac4a8850ea&filter=DG%2CDGE%2CDGN";

    // Debug mode: append debug information to $members
    if ($fDebug) {
        $members .= "=================================================================<BR>";
        $members .= "function dacdb_jsonclubleaders called <br>";
        $members .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $members .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $members .= "Style=" . $style . "<br>";
        $members .= "RoleKeys=" . $rolekeys . "<br>";
        $members .= $url . "<br />";
        $members .= "=================================================================<BR>";
    }

    // Retrieve the data from the API using file_get_contents
    $result = file_get_contents($url);

    // Output the URL and result for debugging
    var_dump($url);
    echo "<br />";
    var_dump($result);

    // Alternatively, use cURL to retrieve the data
    $s = curl_init();
    curl_setopt($s, CURLOPT_URL, $url);
    curl_setopt($s, CURLOPT_HEADER, true);
    $result = curl_exec($s);

    // Return the information about club leaders
    return $members . "<br />" . $result;
}

//ANCHOR - Show Map
/**
 * Generates a map HTML and JavaScript code.
 *
 * @param array $atts An array of attributes.
 *
 * @return string The generated map HTML and JavaScript code.
 */
function dacdb_map($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $map = '';

    // Retrieve global variables
    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];
    $style      = isset($atts['style']) ? $atts['style'] : 1;

    // Append debug information if debugging is enabled
    if ($fDebug) {
        $map .= "=================================================================<BR>";
        $map .= "function dacdb_map called<br>";
        $map .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $map .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $map .= "ApiKey=" . $options['map_api'] . "<br>";
        $map .= "Style=" . $style . "<br>";
        $map .= "URL=" . $data_path . 'MapClub.cfm?AccountID=' . $options['dacdb_district'] . '&xsl=ClubData.xsl&callback=showPopUpData&zlevel=0' . "<br>";
        $map .= "URL=" . $data_path . 'MapPopUp.cfm?AccountID=' . $options['dacdb_district'] . '&xsl=ClubData.xsl&callback=showPopUpData&zlevel=0' . "<br>";
        $map .= "=================================================================<BR>";
    } else {
        // Display a message if the Google Map API key is missing
        if ($options['map_api'] == '') {
            $map .= "<div class=\"error-msg\"><i class=\"fa fa-times-circle\"></i>Google Map API Key missing</div>";
        }
    }

    // Generate HTML and JavaScript code for the map
    $map .= '
        <div id="Map"></div>
        <div id="map_canvas" style="min-height:600px;"></div>
        <div id="MapData" style="display:none;"></div>
        <script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="  crossorigin="anonymous"></script>
        <script defer type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=' . $options['map_api'] . '"></script>

        <script type="text/javascript">
            var temp = "";
            function showMap(json) {
                console.log(json);
                temp = json.text;
            }
            function showPopUpData(json) {
                document.getElementById(\'MapData\').innerHTML = json.text;
            }
            $(document).ready(function() {
                eval(temp);
                $("#Map").hide();
                $("#MapData").hide();
            });
        </script>
        <script src="' . $data_path . 'MapClub.cfm?AccountID=' . $options['dacdb_district'] . '&xsl=ClubInteractive2.xsl&callback=showMap&zlevel=0" type="text/javascript"></script>
        <script src="' . $data_path . 'MapPopUp.cfm?AccountID=' . $options['dacdb_district'] . '&xsl=ClubData.xsl&callback=showPopUpData&zlevel=0" type="text/javascript"></script>
    ';

    return $map;
}

//ANCHOR - Show Committee Members
/**
 * Generates and displays a committee's members.
 *
 * @param array $atts An array of attributes passed to the function.
 *
 * @return string The HTML markup for displaying the committee members.
 */
function dacdb_committee($atts)
{
    // Global variables used within the function
    // Global variables used within the function
    global $fDebug, $data_path, $file_path, $options;

    // Retrieve attribute values from the $atts array
    $account_id = $options['dacdb_district'];
    $club_id = $options['dacdb_club'];
    $cid = isset($atts['cid']) ? strtolower($atts['cid']) : ""; // Committee ID obtained from the shortcode (always lowercase)
    $members = ""; // HTML markup for displaying the committee members
    // Check if Committee ID is missing
    if (empty($cid)) {
        return "<div class=\"error-msg\"><i class=\"fa fa-times-circle\"></i>CommitteeID (cid=) is missing</div>";
    }

    // Set default values for committee members per row if not specified in options
    $options['committee_members_per_row'] = $options['committee_members_per_row'] ?? 1;

    // Handle deprecated attribute values (rows and row)
    $options['committee_members_per_row'] = $atts['rows'] ?? $atts['row'] ?? $options['committee_members_per_row'];

    // Set committee members per row based on the provided attribute value (cols)
    $options['committee_members_per_row'] = $atts['cols'] ?? $options['committee_members_per_row'];

    // Set committee members' committee position based on the provided attribute value (committeeposition)
    $options['committee_members_committeeposition'] = $atts['committeeposition'] ?? $options['committee_members_committeeposition'];

    // Set show club position based on the provided attribute value (clubposition)
    $ShowClubPos = $atts['clubposition'] ?? 0;

    // Set global show district number based on the provided attribute value (district)
    $options['committee_global_show_district_number'] = $atts['district'] ?? $options['committee_global_show_district_number'];

    // Retrieve additional options
    $cols = $options['committee_members_per_row'];

    // Debugging information
    if ($fDebug) {
        $members .= "=================================================================<BR>";
        $members .= "function dacdb_committee called<br>";
        $members .= "AccountID=" . $account_id . "<br>";
        $members .= "ClubID=" . $club_id . "<br>";
        $members .= "cid=" . $cid . "<br>";
        $members .= "URL=" . $data_path . 'wp_ByID.cfm?AccountID=' . $account_id . '&ClubID=' . $$club_id . '&id=' . $cid . "<br>";
        $members .= "cols=" . $cols . "<br>";
        $members .= "Pics=" . $options['committee_members_pics'] . "<br>";
        $members .= "CommitteeName=" . $options['committee_global_name'] . "<br>";
        $members .= "Description=" . $options['committee_global_description'] . "<br>";
        $members .= "Committeeposition=" . $ShowCommPos . "<br>";
        $members .= "Clubposition=" . $ShowClubPos . "<br>";
        $members .= "DistrictNumber=" . $options['committee_global_show_district_number'] . "<br>";
        $members .= "BusPos=" . $options['committee_members_busposition'] . "<br>";
        $members .= "Classification=" . $options['committee_members_classification'] . "<br>";
        $members .= "Contact=" . $options['leaders_contact_link'] . "<br>";
        $members .= "=================================================================<BR>";
    }

    // Load XML data from the specified URL
    $xml = simplexml_load_file($data_path . 'wp_ById.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&id=' . $cid . '&R=' . rand());

    // Check if XML data is empty
    if (strlen($xml) == 0) {
        $members .= 'There are no committee members to display at this time.';
        return $members;
    }

    // Set the div and image widths based on the number of columns
    $setDivWidth = 160;
    $setImgWidth = 150;
    $div = '<div class="col">';

    if ($cols == 1) {
        $div = '<div class="members dac-col-xs-12">';
        $setDivWidth = 155;
        $setImgWidth = 150;
    } else if ($cols == 2) {
        $div = '<div class="members dac-col-xs-12 dac-col-sm-6">';
        $setDivWidth = 140;
        $setImgWidth = 135;
    } else if ($cols == 3) {
        $div = '<div class="members dac-col-xs-12 dac-col-sm-12 dac-col-md-4">';
        $setDivWidth = 125;
        $setImgWidth = 120;
    } else if ($cols == 4) {
        $div = '<div class="members dac-col-xs-12 dac-col-sm-6 dac-col-md-3 dac-col-lg-3">';
        $setDivWidth = 110;
        $setImgWidth = 105;
    }
    $thumbnail_width = isset($options['thumbnail_width']) && $options['thumbnail_width'] > 0 ? $options['thumbnail_width'] : (isset($atts['imgwidth']) && isset($atts['imgwidth']) > 0 ? $atts['imgwidth'] : 150);
    // Counter for tracking members
    $counter = 0;

    // Display committee name if enabled
    if ($options['committee_global_name'] == 1) {
        $members .= '<div class="dac-row">';
        $members .= '   <div class="dac-col-xs-12">';
        $members .= '       <style>h1.entry-title { display:none !important; }</style>';
        $members .= '       <h1>' . $xml->committeemembers->committeename . ' Committee Members</h1>';
        $members .= '   </div>'; // dac-col-xs-12
        $members .= '</div>'; // dac-row
    }

    // Display committee description if enabled
    if ($options['committee_global_description'] == 1) {
        $members .= '<div class="dac-row">';
        $members .= '    <div class="dac-col-xs-12">';
        $members .=         $xml->committeemembers->description . '<br><br>';
        $members .= '   </div>'; // dac-col-xs-12
        $members .= '</div>'; // dac-row
    }

    // Display committee members
    $members .= '<div class="dac-row">';

    foreach ($xml->committeemembers as $member) {
        $members .= $div; // members dac-col-xs-12 dac-col-sm-6 dac-col-md-3 dac-col-lg-3

        $members .= '<table border="0" cellpadding="0" cellspacing="0">';
        $members .= '<tr>';

        if ($options['committee_members_pics'] == 1) {
            $members .=   '<td style="border:0 !important;vertical-align: top; padding:0; width:' . $setDivWidth . 'px;">';

            if ($member->image == '') {
                $members .= '<div style="width:' . $setDivWidth . 'px;"><img src="' . plugins_url('img/no_image.jpg', __FILE__) . '"  style="aspect-ratio: 4 / 5; width: ' . $setImgWidth . 'px; object-fit: cover;" width="' . $setImgWidth . '"></div>';
            } else {
                $members .= '<div style="width:' . $setDivWidth . 'px;"><img src="' . $member->image . '"  style="aspect-ratio: 4 / 5; width: ' . $setImgWidth . 'px; object-fit: cover;" width="' . $setImgWidth . '"></div>';
            }

            $members .=   '</td>';
        }

        $members .='    <td style="border:0 !important; text-align: left; vertical-align: top; padding:0;">';
        $members .= '       <b>' . $member->membername . '</b><BR>';
		if ( $member->cluburl = '')
        	$members .= '       ' . $member->clubname . '<br>';
		else
			$members .= '       <a href="' . $member->cluburl . '" target="new">' . $member->clubname . '</a><br>';

        if ($options['committee_global_show_district_number'] == 1) {
            if ($member->accountid != '') {
                $members .= 'District ' . $member->accountid . '<br />';
            }
        }

        if ($options['committee_members_committeeposition'] == 1) {
            if ($member->committeeposition != '') {
                $members .= $member->committeeposition . '<br />';
            }
        }

        if ($ShowClubPos == 1) {
            if ($member->clubposition != '') {
                $members .= $member->clubposition . ' club position<br />';
            }
        }

        if ($options['committee_members_busposition'] == 1) {
            if ($member->busposition != '') {
                $members .= $member->busposition . '<br />';
            }
        }

        if ($options['committee_members_classification'] == 1) {
            if ($member->classification != '') {
                $members .= $member->classification . '<br />';
            }
        }

        if ($options['leaders_contact_link'] == 1) {
            $members .= '<a href="' . $data_path . 'R_Emailer.cfm?UserID=' . $member->userid . '" name="dlc-inline-link-' . $counter . '" class="iframe3 cboxElement">Contact</a>';
        }

        $members .=   '</td>';
        $members .= '</tr>';
        $members .= '</table>';
        $members .= '</div>'; // members dac-col-xs-12 dac-col-sm-6 dac-col-md-3 dac-col-lg-3
        $counter = $counter + 1;
    }

    $members .= '</div>'; // dac-row
    return $members;
}

//ANCHOR - Show Committees
/**
 * Generates a list of committees based on attributes and options.
 *
 * @param array $atts An associative array of attributes.
 * @return string The generated list of committees.
 */
function dacdb_committees($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $committees = ''; // Initialize an empty string to store the generated list of committees.

    $account_id = $options['dacdb_district']; // Retrieve the district account ID from options.
    $club_id    = $options['dacdb_club']; // Retrieve the club ID from options.

    $description = isset($atts['description']) ? $atts['description'] : ''; // Retrieve the "description" attribute from the function arguments.
    $orgyear = isset($atts['orgyear']) ? $atts['orgyear'] : ''; // Retrieve the "orgyear" attribute from the function arguments.
    $members = isset($_GET["members"]) ? $_GET["members"] : ''; // Get the "members" value from the query string parameters.

    $options['committee_members_per_row'] ??= 1;
    $current_url = "";

    if ($fDebug) {
        // Generate debug information if debugging is enabled.
        $committees .= "=================================================================<BR>";
        $committees .= "function dacdb_committees called<br>";
        $committees .= "AccountID=" . $account_id . "<br>";
        $committees .= "ClubID=" . $club_id . "<br>";
        $committees .= "description=" . $description . "<br>";
        $committees .= "orgyear=" . $orgyear . "<br>";
        $committees .= "members=" . $members . "<br>";
        if ($members)
            $committees .= "URL=" . $data_path . 'wp_ById2.cfm?AccountID=' .$account_id . '&ClubID=' . $club_id . '&id=' . $members . '&RoleKey=' . "<br>";
        else
            $committees .= "URL=" . $data_path . 'wp_committees.cfm?AccountID=' . $account_id . '&ClubID=' . $club_id . "<br>";
        $committees .= "=================================================================<BR>";
    }

    if ($members) {
        // List members on the selected committee.
        $counter = 1;
        $grid_counter = 0;

        $xml = simplexml_load_file($data_path . 'wp_ById2.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&id=' . $members . '&R=' . rand());

        if (strlen($xml) == 0) {
            $committees .= 'There are no committee members to display at this time.';
            return $committees;
        }

        $committees .= '<style>h1.entry-title { display:none !important; }</style>';
        $lastCounter = count($xml->committeemembers);

        foreach ($xml->committeemembers as $member) {
            if ($counter == 1) {
                if ($options['committee_global_name'] == 1) {
                    $committees .= '<div style="overflow: auto;margin-bottom:10px;"><h1>' . $member->committeename . ' Committee Members</h1></div>';
                }
                $url = strtok($_SERVER["REQUEST_URI"], '?');

                if ($options['committee_global_description'] == 1) {
                    $committees .= '<div style="overflow: auto;">' . $member->description . '</div><br><br>';
                }
                $counter = 2;
            }

            $grid_counter = $grid_counter + 1;

            if ($options['committee_members_per_row'] == 1) {
                $grid_counter = 1;
            }

            if ($grid_counter == 1) {
                $committees .= '<div class="dac-row"><!-- ' . $grid_counter . ' -->';
            }

            // Set the width for the committee member div and image based on the number of members per row.
            $setDivWidth = 150;
            $setImgWidth = 140;

            if ($options['committee_members_per_row'] == 1) {
                $committees .= '<div class="members dac-col-xs-12">';
            } else if ($options['committee_members_per_row'] == 2) {
                $committees .= '<div class="members dac-col-xs-12 dac-col-sm-6">';
            } else if ($options['committee_members_per_row'] == 3) {
                $committees .= '<div class="members dac-col-xs-12 dac-col-sm-12 dac-col-md-4">';
            } else if ($options['committee_members_per_row'] == 4) {
                $committees .= '<div class="members dac-col-xs-12 dac-col-sm-6 dac-col-md-3 dac-col-lg-3">';
                $setDivWidth = 120;
                $setImgWidth = 110;
            }

            if ($options['committee_members_pics'] == 0) {
                $committees .= '<table style="vertical-align: top;padding:0;border:0 !important;"><tr>';
            } else {
                if ($member->image == '') {
                    $committees .= '<table style="vertical-align: top;padding:0;border:0 !important;"><tr><td style="border:0 !important;vertical-align: top;padding:0;max-width:' . $setDivWidth . 'px;width:' . $setDivWidth . 'px"><img src="' . plugins_url('img/no_image.jpg', __FILE__) . '" width="' . $setImgWidth . '"></td>';
                } else {
                    $committees .= '<table style="vertical-align: top;padding:0;border:0 !important;"><tr><td style="border:0 !important;vertical-align: top;padding:0;max-width:' . $setDivWidth . 'px;width:' . $setDivWidth . 'px"><img src="' . $member->imgpath . '' . $member->image . '" width="' . $setImgWidth . '"></td>';
                }
            }

            if ($options['committee_members_contact_link'] == 1) {
                $committees .= '<td style="border:0 !important;max-width:1px;width:1px;padding:0;">&nbsp;</td><td style="border:0 !important;vertical-align: top;padding:0;"><a href="' . $data_path . 'R_Emailer.cfm?UserID=' . $member->userid . '" class="iframe3 cboxElement"><b>' . $member->username . '</b></a>';
            } else {
                $committees .= '<td style="border:0 !important;max-width:1px;width:1px;padding:0;">&nbsp;</td><td style="border:0 !important;vertical-align: top;padding:0;"><b>' . $member->username . '</b>';
            }

            // Display additional information based on the configured options.
            if ($options['committee_members_committeeposition'] == 1) {
                if ($member->committeeposition != '') {
                    $committees .= '<br>' . $member->committeeposition . '';
                }
            }
			$committees .= '        <br><a href="' . $member->cluburl . '" target="new">' . $member->clubname . '</a><br>';

            if ($options['committee_global_show_district_number'] == 1) {
                if ($member->accountid != '') {
                    $committees .= '<br>District ' . $member->accountid . '';
                }
            }
            if ($options['committee_members_busposition'] == 1) {
                if ($member->busposition != '') {
                    $committees .= '<br>' . $member->busposition . '';
                }
            }
            if ($options['committee_members_classification'] == 1) {
                if ($member->classification != '') {
                    $committees .= '<br>' . $member->classification . '';
                }
            }
            if ($options['committee_members_contact_link'] == 1) {
                $committees .= '<br><a href="' . $data_path . 'R_Emailer.cfm?UserID=' . $member->userid . '" class="iframe3 cboxElement">Contact</a>';
            }

            $committees .= '</td></tr></table>';
            $committees .= '</div>';

            if ($grid_counter == $options['committee_members_per_row']) {
                $committees .= '</div><!--even-->';
                $grid_counter = 0;
            }
        }

        if ($grid_counter > 0) {
            $committees .= '</div><!--end-->';
        }
    } else {
        // List all committees - Club or District.
        $xml = simplexml_load_file($data_path . 'wp_committees.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&R=' . rand());

        if (strlen($xml) == 0) {
            $committees .= 'There are no committees to display at this time.';
            return $committees;
        }

        $counter = 1;
        $committees .= '<table width="100%" class="dcc" style="vertical-align: top;padding:0;">';

        foreach ($xml->committee as $committee) {
            $pad = "";
            // level is being returned as 0 right now.
            //if ( $committee->level > 0 ) {
            //    $w = $committee->level*30;
            //    $pad = 'style="padding-left:$wpx;"';
            //}

            if ($committee->gdg == "Y") {
                $committees .= '<tr><td ' . $pad . ' style="vertical-align: top;padding:0;"><span style="color:red"><b>' . $committee->name . '</b></span></td>';
            } else {
                $committees .= '<tr><td ' . $pad . ' style="vertical-align: top;padding:0;"><a href="' . $current_url . '?members=' . $committee->committeeid . '"><b>' . $committee->name . '</b></a></td>';
            }

            if ($orgyear == 1 || strtoupper($orgyear) == 'Y') {
                $committees .= '<td style="vertical-align: top; padding:0; width: 100px">' . $committee->year . '</td>';
            }

            $committees .= '</tr>';

            if ($description == 1 || strtoupper($description) == 'Y') {
                if (strlen(trim($committee->description)))
                    $committees .= '<tr><td>' . trim($committee->description) . '</td></tr>';
            }

            $counter = $counter + 1;
        }

        $committees .= '</table>';
        $committee_total = count($xml->committee);
    }

    return $committees; // Return the generated list of committees.
}

//ANCHOR - Show DCC
/**
 * Generate HTML code for displaying DCC officers.
 *
 * @param array $atts Array of attributes.
 * @return string HTML code representing DCC officers display.
 */
function dacdb_dcc($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $dccs = ''; // Stores the generated HTML code for DCC officers

    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];
    $thumbnail_width = isset($options['thumbnail_width']) && $options['thumbnail_width'] > 0 ? $options['thumbnail_width'] : (isset($atts['imgwidth']) && isset($atts['imgwidth']) > 0 ? $atts['imgwidth'] : 150);

    if ($fDebug) {
        // Debug information
        $dccs .= "=================================================================<BR>";
        $dccs .= "function dacdb_dcc called<br>";
        $dccs .= "AccountID=" . $account_id . "<br>";
        $dccs .= "ClubID=" . $club_id . "<br>";
        $dccs .= "URL=" . $data_path . 'wp_dcc.cfm?AccountID=' . $account_id . "<br>";
        $dccs .= "=================================================================<BR>";
    }

    $xml = simplexml_load_file($data_path . 'wp_dcc.cfm?AccountID=' . $account_id . '&R=' . rand());

    if (strlen($xml) == 0) {
        $dccs .= 'There are no DCC officers to display at this time.';
        return $dccs;
    }

    $counter = 1; // Counter for tracking iterations
    $grid_counter = 0; // Counter for tracking grid positions
    $lastCounter = count($xml->dcc); // Total number of DCC officers

    foreach ($xml->dcc as $dcc) {
        $grid_counter = $grid_counter + 1;

        if ($options['dcc_per_row'] == 1) {
            $grid_counter = 1; // Force single row if dcc_per_row is 1
        }

        if ($grid_counter == 1) {
            $dccs .= '<div class="dac-row"><!-- start -->'; // Start a new row
        }

        $setDivWidth = 160; // Width of table cell
        $setImgWidth = 150; // Width of image

        if ($options['dcc_per_row'] == 1) {
            $dccs .= '<div class="members dac-col-xs-12">'; // One column per row
        } else if ($options['dcc_per_row'] == 2) {
            $dccs .= '<div class="members dac-col-xs-12 dac-col-sm-6">'; // Two columns per row
        } else if ($options['dcc_per_row'] == 3) {
            $dccs .= '<div class="members dac-col-xs-12 dac-col-sm-12 dac-col-md-4">'; // Three columns per row
        } else if ($options['dcc_per_row'] == 4) {
            $dccs .= '<div class="members dac-col-xs-12 dac-col-sm-6 dac-col-md-3 dac-col-lg-3">'; // Four columns per row
            $setDivWidth = 120; // Adjusted table cell width for four columns
            $setImgWidth = 110; // Adjusted image width for four columns
        }

        if ($dcc->image == '') {
            // Display default image if officer's image is empty
            $dccs .= '<table style="vertical-align: top;padding-right:0;border:0 !important;"><tr><td style="border:0 !important;vertical-align: top;padding:0;max-width:' . $setDivWidth . 'px;width:' . $setDivWidth . 'px"><img src="' . plugins_url('img/no_image.jpg', __FILE__) . '"  style="aspect-ratio: 4 / 5; width: ' . $thumbnail_width  . 'px; object-fit: cover;" width="' . $thumbnail_width  . '"></td>';
        } else {
            // Display officer's image
            $dccs .= '<table style="vertical-align: top;padding:0;border:0 !important;"><tr><td style="border:0 !important;vertical-align: top;padding:0;max-width:' . $setDivWidth . 'px;width:' . $setDivWidth . 'px"><img src="' . $dcc->imgpath . '' . $dcc->image . '"  style="aspect-ratio: 4 / 5; width: ' . $thumbnail_width  . 'px; object-fit: cover;" width="' . $thumbnail_width  . '"></td>';
        }

        $dccs .= '<td style="border:0 !important;max-width:1px;width:1px;padding:0;">&nbsp;</td><td style="border:0 !important;vertical-align: top;padding:0;"><b>' . $dcc->committeename . '</b><br><b>' . $dcc->membername . '</b>';
        $dccs .= '<br>' . $dcc->committeeposition . '<br>';
        $dccs .= '</td>';
        $dccs .= '</tr></table></div>';

        if ($grid_counter == $options['dcc_per_row']) {
            $dccs .= '</div>'; // Close the row
            $grid_counter = 0; // Reset grid counter
        }

        $counter = $counter + 1;
    }

    if ($grid_counter > 0) {
        $dccs .= '</div><!-- end  -->'; // Close the last row if incomplete
    }

    return $dccs; // Return the generated HTML code for DCC officers
}

//ANCHOR - Show COG
function dacdb_cog($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $cogs = '';

    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];

    if ($fDebug) {
        $cogs .= "=================================================================<BR>";
        $cogs .= "function dacdb_cog called<br>";
        $cogs .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $cogs .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $cogs .= "URL=" . $data_path . 'wp_cog.cfm?AccountID=' . $options['dacdb_district'] . "<br>";
        $cogs .= "=================================================================<BR>";
    }

    $xml = simplexml_load_file($data_path . 'wp_cog.cfm?AccountID=' . $options['dacdb_district'] . '&R=' . rand());
    if (strlen($xml) == 0) {
        $cogs .= 'There are no COGs to display at this time.';
        return $cogs;
    }

    $counter = 1;
    $grid_counter = 0;
    foreach ($xml->cog as $cog) {
        $grid_counter = $grid_counter + 1;
        if ($options['cog_per_row'] == 1) {
            $grid_counter = 1; // force single row
        }
        if ($grid_counter == 1) {
            $cogs .= '<div class="dac-row"><!-- start -->';
        }

        $setDivWidth = 160;
        $setImgWidth = 150;

        if ($options['cog_per_row'] == 1) {
            $cogs .= '<div class="members dac-col-xs-12">';
        } else if ($options['cog_per_row'] == 2) {
            $cogs .= '<div class="members dac-col-xs-12 dac-col-sm-6">';
        } else if ($options['cog_per_row'] == 3) {
            $cogs .= '<div class="members dac-col-xs-12 dac-col-sm-12 dac-col-md-4">';
        } else if ($options['cog_per_row'] == 4) {
            $cogs .= '<div class="members dac-col-xs-12 dac-col-sm-6 dac-col-md-3 dac-col-lg-3">';
            $setDivWidth = 120;
            $setImgWidth = 110;
        }
        if ($cog->image == '') {
            $cogs .= '<table style="vertical-align: top;padding:0;border:0 !important;"><tr><td style="border:0 !important;vertical-align: top;padding:0;max-width:' . $setDivWidth . 'px;width:' . $setDivWidth . 'px"><img src="' . plugins_url('img/no_image.jpg', __FILE__) . '" style="max-width:' . $setImgWidth . 'px"></td>';
        } else {
            $cogs .= '<table style="vertical-align: top;padding:0;border:0 !important;"><tr><td style="border:0 !important;vertical-align: top;padding:0;max-width:' . $setDivWidth . 'px;width:' . $setDivWidth . 'px"><img src="' . $cog->imgpath . '' . $cog->image . '" style="max-width:' . $setImgWidth . 'px"></td>';
        }
        $cogs .= '<td style="border:0 !important;max-width:1px;width:1px;padding:0;">&nbsp;</td><td style="border:0 !important;vertical-align: top;padding:0;"><b>' . $cog->membername . '</b>';

        $cogs .= '<br><b>Year of Service:</b> ' . $cog->yos . '<br>';
        $cogs .= '<br>' . $cog->clubname . '<br><br></td>';
        $cogs .= '</tr></table></div>';
        if ($grid_counter == $options['cog_per_row']) {
            $cogs .= '</div>';
            $grid_counter = 0;
        }
        $counter = $counter + 1;
    }
    if ($grid_counter > 0) {
        $cogs .= '</div><!-- end  -->';
    }

    return $cogs;
}


//ANCHOR - Show Documents
function dacdb_documents($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $documents = '';
    $account_id = isset($options['dacdb_district']) ? $options['dacdb_district'] : '';
    $club_id = isset($options['dacdb_club']) ? $options['dacdb_club'] : '';
    $icon = isset($atts['icon']) ? $atts['icon'] : '0';
    $size = isset($atts['size']) ? $atts['size'] : '0';
    $date = isset($atts['date']) ? $atts['date'] : '0';
    $folder = isset($_GET['folder']) ? $_GET['folder'] : (isset($atts['folder']) ? $atts['folder'] : '');
    $folder2 = isset($_GET['folder2']) ? isset($_GET['folder2']) : (isset($atts['folder2']) ? isset($atts['folder2']) : '');
    $level = isset($folder) ? 1 : 0;
    $sort = "";
    $current_url = "";

    if ($fDebug) {
        $documents .= "=================================================================<BR>";
        $documents .= "function dacdb_documents called<br>";
        $documents .= "AccountID=" . (isset($options['dacdb_district']) ? $options['dacdb_district'] : '') . "<br>";
        $documents .= "ClubID=" . (isset($options['dacdb_club']) ? $options['dacdb_club'] : '') . "<br>";
        $documents .= "folder=" . (isset($folder) ? $folder : '') . "<br>";
        $documents .= "icon=" . (isset($icon) ? $icon : '') . "<br>";
        $documents .= "size=" . (isset($size) ? $size : '') . "<br>";
        $documents .= "date=" . (isset($date) ? $date : '') . "<br>";
        $documents .= "current_url=" . (isset($current_url) ? $current_url : '') . "<br>";
        $documents .= "path=" . (isset($file_path) ? $file_path : '') . "<br>";
        $documents .= "url=" . (isset($data_path) ? $data_path : '') . 'documents.php?AccountID=' . (isset($options['dacdb_district']) ? $options['dacdb_district'] : '') . '&ClubID=' . (isset($options['dacdb_club']) ? $options['dacdb_club'] : '') . '&folder=' . (isset($folder) ? $folder : '') . '&folder2=' . (isset($folder2) ? $folder2 : '') . '&sort=' . (isset($sort) ? $sort : '') . "<br>";
        $documents .= "=================================================================<BR>";
    }


    $xml = simplexml_load_file((isset($data_path) ? $data_path : '') . 'documents.php?AccountID=' . (isset($options['dacdb_district']) ? $options['dacdb_district'] : '') . '&ClubID=' . (isset($options['dacdb_club']) ? $options['dacdb_club'] : '') . '&Folder=' . (isset($folder) ? $folder : '') . '&Folder2=' . (isset($folder2) ? $folder2 : '') . '&sort=' . (isset($sort) ? $sort : '') . '&R=' . rand());
    if ($xml->count() == 0) {
        $documents .= 'There are no documents to display at this time.';
        return $documents;
    }


    $counter = 1;
    //
    // Breadcrumbs
    //
    $documents .= '<div class="breadcrumbs"> ';
    if ($level == 1) {
        if ($folder && $folder2 ==  '') {
            $documents .= '' . $folder;
        } elseif ($folder2) {
            $documents .= '
            <a href="' . $current_url . '?folder=' . $folder . '">' . $folder . '</a> > ' . $folder2 . '';
        }
    } else {
        if ($folder && $folder2 ==  '') {
            $documents .= '<a href="' . $file_path . '">Documents</a> > ' . $folder;
        } elseif ($folder2) {
            $documents .= '
            <a href="' . $file_path . '&">Documents</a> >
            <a href="' . $file_path . '&folder=' . $folder . '">' . $folder . '</a> > ' . $folder2 . '';
        }
    }
    $documents .= '</ul></div>';

    //
    // Process all the documents returned
    //

    $icon_header = ($icon == 1) ? '<th width="36">&nbsp;</th>' : '';
    $size_header = ($size == 1) ? '<th data-sort="int">Size</th>' : '';
    $date_header = ($date == 1) ? '<th data-sort="int">Modified</th>' : '';

    $documents .= '<div class="row">
        <div class="dac-col-md-12">
        <table class="table">
            <thead>
            <tr>
            ' . $icon_header . '
            <th data-sort="string">File Name</th>
            ' . $size_header . '
            ' . $date_header . '
            </tr>
            </thead>
            <tbody>';

    if (!empty($xml->document)) {
        foreach ($xml->document as $document) {
            $name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $document->name);

            if ($document->type == 0) {
                if ($folder && $folder2) {
                    // do nothing
                } else {
                    $documents .= '<tr>';
                    if ($icon == 1) {
                        if ($folder) {
                            $documents .= '<td><img src="' . plugins_url('img/folder.png', __FILE__) . '" width="32" style="max-width: 32px !important; width: 32px !important;"></td><td><a href="' . $current_url . '?folder=' . $folder . '&folder2=' . $document->name . '">' . $name . '</a>' . $current_url . '</td>';
                        } else {
                            $documents .= '<td><img src="' . plugins_url('img/folder.png', __FILE__) . '" width="32" style="max-width: 32px !important; width: 32px !important;"></td><td><a href="' . $current_url . '?folder=' . $name . '">' . $name . '</a></td>';
                        }
                    } else {
                        if ($folder) {
                            $documents .= '<td><a href="' . $current_url . '?folder=' . $folder . '&folder2=' . $document->name . '">' . trim($name) . '</a></td>';
                        } else {
                            $documents .= '<td><a href="' . $current_url . '?folder=' . $name . '">' . trim($name) . '</a></td>';
                        }
                    }

                    if ($size == 1) {
                        $documents .= '<td>-</td>';
                    }

                    if ($date == 1) {
                        $documents .= '<td>-</td>';
                    }
                    $documents .= '</tr>';
                    $counter = $counter + 1;
                }
            } else {
                $extension = substr(strrchr($document->name, '.'), 1);
                if ($extension == '') {
                    $extension = '__blank';
                }
                if ($icon == 1) {
                    $documents .= '<tr><td><img src="' . plugins_url('img/16px/' . $extension . '.png', __FILE__) . '" width="32" style="max-width: 32px !important; width: 32px !important;">' . $lastDotPos . '</td>';
                } else {
                    $documents .= '<tr>';
                }
                // $documents .= '<td><a href="'.$file_path.'.$options['dacdb_district'].'/Downloads/'.$options['dacdb_club'].'/'.$document->name.'" target="__blank">'.$document->name.'</a></td>';

                if ($extension == 'URL') {

                    // $docName = str_replace(" ", "%20",$document->name);

                    if ($folder && $folder2 ==  '') {
                        $getURL = file_get_contents($file_path . $options['dacdb_district'] . '/Downloads/' . rawurlencode($options['dacdb_club']) . '/' . rawurlencode($folder) . '/' . rawurlencode($document->name));
                    } elseif ($folder && $folder2) {
                        $getURL = file_get_contents($file_path . $options['dacdb_district'] . '/Downloads/' . rawurlencode($options['dacdb_club']) . '/' . rawurlencode($folder) . '/' . rawurlencode($folder2) . '/' . rawurlencode($document->name));
                    } else {
                        $getURL = file_get_contents($file_path . $options['dacdb_district'] . '/Downloads/' . rawurlencode($options['dacdb_club']) . '/' . rawurlencode($document->name));
                    }
                    if (strpos($getURL, "http://") === false && strpos($getURL, "https://") === false) {
                        $getURL = 'https://' . $getURL;
                    }
                } else {
                    if ($folder && $folder2 ==  '') {
                        $getURL = $file_path . $options['dacdb_district'] . '/Downloads/' . $options['dacdb_club'] . '/' . $folder . '/' . $document->name;
                    } elseif ($folder && $folder2) {
                        $getURL = $file_path . $options['dacdb_district'] . '/Downloads/' . $options['dacdb_club'] . '/' . $folder . '/' . $folder2 . '/' . $document->name;
                    } else {
                        $getURL = $file_path . $options['dacdb_district'] . '/Downloads/' . $options['dacdb_club'] . '/' . trim($document->name);
                    }
                }

                $documents .= '<td><a href="' . $getURL . '" target="__blank">' . $document->name . '</a></td>';
                if ($size == 1) {
                    $documents .= '<td>' . $document->size . '</td>';
                }
                if ($date == 1) {
                    $documents .= '<td>' . $document->modded . '</td>';
                }
                $documents .= '</tr>';
                $counter = $counter + 1;
            }
        }
    } else {
        $documents .= '<tr><td colspan="4"><strong>There are no documents available at this time.<strong></td></tr>';
    }
    $documents .= '</tbody></table></div></div>';
    return $documents;
}

//ANCHOR - Show Newsletter
function dacdb_newsletter($atts)
{
    global $fDebug, $data_path, $file_path, $options, $wp;


    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];
    $icon   = isset($atts['icon']) ? $atts['icon'] : '0';
    $size   = isset($atts['size']) ? $atts['size'] : '0';
    $date   = isset($atts['date']) ? $atts['date'] : '0';
    $documents = '';
    $folder = isset($_GET["folder"]) ? $_GET["folder"] : '';

    if ($options['dacdb_club'] == 0) {
        $location = 'Newsletter';
    } else {
        $location = 'Bulletins';
    }

    if ($fDebug) {
        $documents .= "=================================================================<BR>";
        $documents .= "function dacdb_newsletter called<br>";
        $documents .= "AccountID=" . $account_id . "<br>";
        $documents .= "ClubID=" . $club_id . "<br>";
        $documents .= "location=" . $location . "<br>";
        $documents .= "newsletters_show_folders_page=" . $options['newsletters_show_folders_page'] . "<br>";
        $documents .= "folder=" . $folder . "<br>";
        $documents .= "icon=" . $icon . "<br>";
        $documents .= "size=" . $size . "<br>";
        $documents .= "date=" . $date . "<br>";
        $documents .= "file_path" . $file_path . "<br>";
        $documents .= "URL=" . $data_path . 'wp_newsletters.cfm?AccountID=' . $account_id . '&ClubID=' . $club_id . '&type=' . $location . '&Weeks=' . $options['newsletters_weeks_page'] . "<br>";
        $documents .= "=================================================================<BR>";
    }

    if ($club_id == 0) {
        $xml = simplexml_load_file($data_path . 'wp_newsletters.cfm?AccountID=' . $account_id . '&ClubID=' . $club_id . '&type=newsletters&Weeks=' . $options['newsletters_weeks_page'] . '&R=' . rand());
        if (strlen($xml) == 0) {
            $documents .= 'There are no newsletters to display at this time.';
            return $documents;
        }
    } else {
        $xml = simplexml_load_file($data_path . 'wp_newsletters.cfm?AccountID=' . $account_id . '&ClubID=' . $club_id . '&type=bulletins&Weeks=' . $options['newsletters_weeks_page'] . '&R=' . rand());
        if (strlen($xml) == 0) {
            $documents .= 'There are no  newsletters to display at this time.';
            return $documents;
        }
    }

    $documents .= '<div class="row">
        <div class="dac-col-md-12">
        <table class="table">
            <tbody>';

    $counter = 1;
    if (empty($_GET["folder"])) { //

        foreach ($xml->newsletter as $document) {
            $name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $document->name);

            $extension = substr(strrchr($document->name, '.'), 1);

            $documents .= '<tr>';
            if ($document->type == 'Dir') {
                $documents .= '<td  width="5%"><img src="' . plugins_url('img/folder.png', __FILE__) . '" width="32" style="max-width: 32px !important; width: 32px !important;"></td><td><a href="' . $current_url . '?folder=' . $folder . '&folder2=' . $document->name . '">' . trim($name) . '</a>' . $current_url . '</td>';
            } else {
                if ($icon == 1) {
                    $documents .= '<td width="5%"><img src="' . plugins_url('img/16px/' . $extension . '.png', __FILE__) . '" width="32" style="max-width: 32px !important; width: 32px !important;"></td><td><a href="' . $document->path . '?folder=' . $name . '">' . trim($name) . '</a></td>';
                } else {
                    $documents .= '<td><a href="' . $document->path . '?folder=' . $name . '">' . trim($name) . '</a></td>';
                }
            }
            if ($size == 1) {
                $documents .= '<td width="20%">' . FileSizeConvert($document->size) . '</td><td  width="20%" align=right>' . $document->datelastmodified . '</td>';
            }
            if ($date == 1) {
                $documents .= '<td  width="20%" align=right>' . $document->datelastmodified . '</td>';
            }
            $documents .= '</tr>';
            $counter = $counter + 1;
        }
    }

    // get folders here
    if ($options['newsletters_show_folders_page'] == 1) {
        $page_title = esc_html(get_the_title());

        if ($folder) {
            $level = 1;
        } else {
            $level = 0;
        }

        $current_url = add_query_arg($wp->query_string, '', home_url($wp->request));

        if ($folder) {
            $documents .= '<div class="breadcrumbs" style="text-align:right;">';
            $documents .= '<a href="' . $current_url . '">' . $page_title . '</a> > ' . $folder;
            $documents .= '</div><br>';
        }

        try {
            if ($folder) {
                $nfxml = @simplexml_load_file($data_path . 'newsletter_folders.php?AccountID=' . $account_id . '&ClubID=' . $club_id . '&Folder=' . $folder . '&Sort=' . $options['newsletters_order_folders_page'] . '&R=' . rand());
            } else {
                $nfxml = @simplexml_load_file($data_path . 'newsletter_folders.php?AccountID=' . $account_id . '&ClubID=' . $club_id . '&Folder=&Sort=' . $options['newsletters_order_folders_page'] . '&R=' . rand());
            }
        } catch (Exception $e) {
            $nfxml = '';
        }

        if ($nfxml != NULL) {

            foreach ($nfxml->document as $document) {
                $name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $document->name);
                if ($document->type == 0) {

                    if (!$folder) {
                        if (is_front_page()) {
                            $documents .= '<div><b><a href="' . $current_url . '?folder=' . $document->name . '">' . $document->name . '</a></b><span class="pull-right" style="float:right;">-</span></div>';
                        } else {
                            $documents .= '<div><b><a href="' . $current_url . '&folder=' . $document->name . '">' . $document->name . '</a></b><span class="pull-right" style="float:right;">-</span></div>';
                        }
                        $documents .= '<hr>';
                    }
                } else {
                    $extension = substr(strrchr($document->name, '.'), 1);
                    if ($extension == '') {
                        $extension = '__blank';
                    }

                    if ($folder) {
                        $getURL = $file_path;
                        echo $getURL . "<br>";
                        $documents .= '<div><b><a href="' . $getURL . '" target="__blank">' . $document->name . '</a></b> - ' . $document->size . '<span class="pull-right" style="float:right;">' . $document->modded . '</span></div>';
                        $documents .= '<hr>';
                    } else {
                        if ($extension == 'pdf') {
                        }
                    }
                    $counter = $counter + 1;
                }
            }
        }
    }
    $documents .= '</tbody></table></div></div>';
    return $documents;
}

//ANCHOR - Show Sponsors
function dacdb_sponsors($atts)
{
    global $fDebug, $data_path, $file_path, $options;
    global $wp;

    $sponsors = '';

    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];
    if ($fDebug) {
        $sponsors .= "=================================================================<BR>";
        $sponsors .= "function dacdb_xxxxx called<br>";
        $sponsors .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $sponsors .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $sponsors .= "URL=" . $data_path . 'wp_sponsor.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $club_id . '&N=9999&SortBy=random' . "<br>";
        $sponsors .= "=================================================================<BR>";
    }

    $xml = simplexml_load_file($data_path . 'wp_sponsor.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $club_id . '&N=9999&SortBy=random' . '&R=' . rand());
    if (strlen($xml) == 0) {
        $sponsors .= 'There are no sponsors to display at this time.';
        return $sponsors;
    }

    $counter = 0;
    $sponsors .= '<div class="dac-row">';
    foreach ($xml->sponsor as $sponsor) {
        if (strcmp($cat, $sponsor->category)) {
            $cat = $sponsor->category;
        }
        $sponsors .= '<div class="dac-col-xs-12 dac-col-sm-12 dac-col-md-6">';
        if ($sponsor->image == '') {
            $sponsors .= '<a href="' . $data_path . 'SponsorPop.cfm?SponsorID=' . $sponsor->sponsorid . '" target="_blank" class="iframe3 cboxElement">' . $sponsor->sponsorname . '</a><br><br>';
        } else {
            $sponsors .= '<a href="' . $data_path . 'SponsorPop.cfm?SponsorID=' . $sponsor->sponsorid . '" target="_blank" class="iframe3 cboxElement"><img src="' . $sponsor->imagepath . '' . $sponsor->image . '"></a><br><br>';
        }
        $sponsors .= '</div>';
    }
    $sponsors .= '</div>';
    return $sponsors;
}

//ANCHOR - Show WCM
function dacdb_wcm($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $meetings = '';
    $sort = 'club';
    if ($options['wcm_show_layout'] == 'default') {
        $sort = 'club';
    } elseif ($options['wcm_show_layout'] == 'area') {
        $sort = 'area';
    } elseif ($options['wcm_show_layout'] == 'date') {
        $sort = 'date';
    } elseif ($options['wcm_show_layout'] == 'detail') {
        $sort = 'detail';
    } elseif ($options['wcm_show_layout'] == 'club') {
        $sort = 'club';
    } elseif ($options['wcm_show_layout'] == 'officers') {
        $sort = 'officers';
    }

    if ($fDebug) {
        $meetings .= "==================================================================<BR>";
        $meetings .= "function dacdb_wcm called<br>";
        $meetings .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $meetings .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $meetings .= "sort=" . $sort . "<br>";
        $meetings .= "URL=" . $data_path . 'wp_club_meetings.cfm?AccountID=' . $options['dacdb_district'] . '&SortBy=' . $sort . '<br>';
        $meetings .= "==================================================================<BR>";
    }

    $xml = simplexml_load_file($data_path . 'wp_club_meetings.cfm?AccountID=' . $options['dacdb_district'] . '&SortBy=' . $sort . '&R=' . rand());
    if (strlen($xml) == 0) {
        $meetings .= 'There are no club meetings to display at this time.';
        return $meetings;
    }

    if ($options['wcm_show_title'] == 'No') {
        $meetings .= '<style>h1.entry-title { display:none !important; }</style>';
        $meetings .= '<style>.entry-header { display:none !important; }</style>';
    }

    $meetings .= '<table width="100%" class="table" style="border:0;">';
    if ($sort == 'area') {
        $meetings .= '<tr style="background-color:#cccccc;"><td><strong>Day</strong></td>';
        $meetings .= '<td><strong>Time</strong></td>';
        $meetings .= '<td><strong>Club</strong></td>';
        $meetings .= '<td><strong>Meeting Place</strong></td></tr>';
    }
    if ($sort == 'date') {
        $meetings .= '<tr style="background-color:#cccccc;"><td><strong>Time</strong></td>';
        $meetings .= '<td><strong>Club</strong></td>';
        $meetings .= '<td><strong>Meeting Place</strong></td>';
        $meetings .= '<td><strong>City</strong></td></tr>';
    }

    $this_area = '';
    $this_day = '';
    $counter = 1;

    foreach ($xml->meeting as $wcm) {

        if ($sort == 'area') {
            if (intval($wcm->region) == $this_area) {
            } else {
                $meetings .= '<tr><td style="background-color:#e3e3e3;" colspan="4">AREA ' . $wcm->region . '</td></tr>';
                $this_area = $wcm->region;
            }
            $meetings .= '<tr>';
            $meetings .= '<td valign="top">' . $wcm->meetingday . '</td>';
            $meetings .= '<td valign="top" nowrap>' . $wcm->meetingtime . '</td>';
            if ($wcm->cluburl != '') {
                $meetings .= '<td valign="top"><a href="' . $wcm->cluburl . '" target="new">' . $wcm->clubname . '</a></td>';
            } else {
                $meetings .= '<td valign="top">' . $wcm->clubname . '</td>';
            }
            $meetings .= '<td valign="top">' . $wcm->meetingplace . '</td>';
            $meetings .= '</tr>';
        } elseif ($sort == 'date') {
            if (trim($wcm->meetingday) === $this_day) {
            } else {
                $meetings .= '<tr><td style="background-color:#e3e3e3;" colspan="4">' . $wcm->meetingday . '</td></tr>';
                $this_day = trim($wcm->meetingday);
            }
            $meetings .= '<tr>';
            $meetings .= '<td valign="top" nowrap>' . $wcm->meetingtime . '</td>';
            if ($wcm->cluburl != '') {
                $meetings .= '<td valign="top"><a href="' . $wcm->cluburl . '" target="new">' . $wcm->clubname . '</a></td>';
            } else {
                $meetings .= '<td valign="top">' . $wcm->clubname . '</td>';
            }
            $meetings .= '<td valign="top">' . $wcm->meetingplace . '</td>';
            $meetings .= '<td valign="top">' . $wcm->meetingcity . '</td>';
            $meetings .= '</tr>';
        } elseif ($sort == 'detail') {

            $meetings .= '<tr>';
            $meetings .= '<td valign="top" colspan="4" style="border:0;">';
            $meetings .= '
                <a href="' . $wcm->cluburl . '" target="new"><b>' . $wcm->clubname . '</b></a><br>
                <i>' . $wcm->clubaddress . '<br>
                ' . $wcm->clubcity . ', ' . $wcm->clubstatecode . '</i><br>
                <b>Where We Meet </b><br>
                ' . $wcm->meetingplace . '<br>';
            if ($wcm->meetingaddress != '') {
                $meetings .= '' . $wcm->meetingaddress . '<br>';
            }
            $meetings .= '' . $wcm->meetingcity . ', ' . $wcm->meetingstatecode . ' ' . $wcm->meetingpostalcode . '<br>
                <b>When</b><br>
                ' . $wcm->meetingday . ' at ' . $wcm->meetingtime . '';
            $meetings .= '<span style="float: right;"><a href="http://maps.google.com/maps?q=' . $wcm->latitude . ',' . $wcm->longitude . '" target="new">Map It</a></span>';
            $meetings .= '<hr style="margin:10px 0 5px 0;"></td></tr>';
        } elseif ($sort == 'officers') {
            $setDivWidth = 100;
            $setImgWidth = 95;

            $meetings .= '<tr>';
            $meetings .= '<td valign="top" align="left" width="40%">';
            $officer_total = count($wcm->officers);

            if ($officer_total > 0) {
                $meetings .= '<table border="1" cellpadding="0" cellspacing="0">';
                foreach ($wcm->officers->officer as $wcmofficer) {
                    $meetings .= '<tr>';
                    $meetings .= '<td style="border:0 !important;vertical-align: top; padding:0; width:' . $setDivWidth . 'px;">';
                    if ($wcmofficer->image == '') {
                        $meetings .= '<div style="width:' . $setDivWidth . 'px;"><img src="' . plugins_url('img/no_image.jpg', __FILE__) . '" width="' . $setImgWidth . '"></div>';
                    } else {
                        $meetings .= '<div style="width:' . $setDivWidth . 'px;"><img src="' . $wcmofficer->image . '" width="' . $setImgWidth . '"></div>';
                    }
                    $meetings .= '</td>';
                    $meetings .= '<td style="border:0 !important; text-align: left; vertical-align: top; padding:0;">';
                    $meetings .= '<b>' . $wcmofficer->username . '</b><BR>';
                    $meetings .= $wcmofficer->clubposition . '<BR>';
                    $meetings .= '</td>';
                    $meetings .= '</tr>';
                }
                $meetings .= '</table>';
            }
            $meetings .= '</td>';

            $meetings .= '<td valign="top" width="60%">';
            $meetings .= '
		                            <a href="' . $wcm->cluburl . '" target="new"><b>' . $wcm->clubname . '</b></a><br>
		                            <i>' . $wcm->clubaddress . '<br>
		                            ' . $wcm->clubcity . ', ' . $wcm->clubstatecode . '</i><br>
		                            <b>Where We Meet </b><br>
		                            ' . $wcm->meetingplace . '<br>';
            if ($wcm->meetingaddress != '') {
                $meetings .= '' . $wcm->meetingaddress . '<br>';
            }
            $meetings .= '' . $wcm->meetingcity . ', ' . $wcm->meetingstatecode . ' ' . $wcm->meetingpostalcode . '<br>
		                            <b>When</b><br>
		                            ' . $wcm->meetingday . ' at ' . $wcm->meetingtime . '';
            $meetings .= '<span style="float: right;"><a href="https://maps.google.com/maps?q=' . $wcm->latitude . ',' . $wcm->longitude . '" target="new">Map It</a></span>';

            $meetings .= '</td>';
            $meetings .= '</tr>';
            $meetings .= '<tr><td colspan="2"><hr style="margin:10px 0 5px 0;"></td></tr>';
        } else {

            $meetings .= '<tr><td valign="top">';
            if ($wcm->cluburl != '') {
                $meetings .= '<a href="' . $wcm->cluburl . '" target="new">' . $wcm->clubname . '</a> - Area ';
            } else {
                $meetings .= '' . $wcm->clubname . ' - Area ';
            }
            $meetings .= '' . $wcm->region . ' ';
            $meetings .= '' . $wcm->meetingday . ' ';
            $meetings .= '' . $wcm->meetingplace . ' ';
            $meetings .= '</td></tr>';
        }
        $counter = $counter + 1;
    }
    $meetings .= '</table>';
    return $meetings;
}

//ANCHOR - Show Meeting Info
function dacdb_meeting_info($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $meetings = '';

    $club_id = $options['dacdb_club'];

    if ($fDebug) {
        $meetings .= "=================================================================<BR>";
        $meetings .= "function dacdb_meeting_info called<br>";
        $meetings .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $meetings .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $meetings .= "URL=" . $data_path . 'wp_club_meetings.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '<br>';
        $meetings .= "=================================================================<BR>";
    }

    $xml = simplexml_load_file($data_path . 'wp_club_meetings.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&R=' . rand());
    if (strlen($xml) == 0) {
        $meetings .= 'There are no club meetings to display at this time.';
        return $meetings;
    }

    $counter = 1;
    $div  = '<div class="col">';
    foreach ($xml->meeting as $wcm) {
		$meetings .= '<div class="dac-row">';
		$meetings .= '	<div class="col">';
		$meetings .= '		<h4>' . $wcm->clubname . '</h4>';
		$meetings .= '	</div>';
		$meetings .= '</div>';

		$meetings .= '<div class="dac-row">';
		$meetings .= '  <div class="col">';
        $meetings .= '		<b>Where We Meet </b><br />';
        $meetings .= '       <div style="padding-left: 10px;">';
        if ($wcm->clubaddress != "") {
            $meetings .=    '<i>' . $wcm->clubaddress . '<br />' . $wcm->clubcity . ', ' . $wcm->clubstatecode . ' ' . $wcm->clubpostalzip . '</i>';
        }
        $meetings .= '        </div>';
        $meetings .= '      <b>Where We Meet </b><br/>';
        $meetings .= '      <div style="padding-left: 10px;">';
        $meetings .=        	$wcm->meetingplace .'<br />';
        $meetings .=        	$wcm->meetingaddress . '<br />' . $wcm->meetingcity . ', ' . $wcm->meetingstatecode . ' ' . $wcm->meetingpostalcode;
        $meetings .= '      </div>';

		$meetings .= '      <b>When</b><br />';
        $meetings .= '      <div style="padding-left: 10px;">';
		$meetings .=    		$wcm->meetingday . 's at ' . $wcm->meetingtime . '';
        if ($wcm->latlng != "") {
            $meetings .=        '<span style="float:right;"><a href="' . $wcm->latlng . '" target="new">Map It</a></span>';
        }
        $meetings .= '      </div>';
        $meetings .= '  </div>';
        $meetings .= '</div>';
        $meetings .= '<hr>';
        $counter = $counter + 1;
    }
    return $meetings;
}

//ANCHOR - Show Club Meetings
function dacdb_club_meetings($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $meetings = '';

    if ($fDebug) {
        $meetings .= "=================================================================<BR>";
        $meetings .= "function dacdb_club_meetings called<br>";
        $meetings .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $meetings .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $meetings .= "URL=" . $data_path . 'wp_club_meetings.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '<br>';
        $meetings .= "=================================================================<BR>";
    }

    $xml = simplexml_load_file($data_path . 'wp_club_meetings.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&R=' . rand());
    if (strlen($xml) == 0) {
        $meetings .= 'There are no club meetings to display at this time.';
        return $meetings;
    }
    $counter = 1;
    foreach ($xml->meeting as $wcm) {
        $meetings .= '<div style="overflow:hidden;margin-bottom:20px;border:">';
        if ($wcm->cluburl != "") {
            $meetings .= '<div style="width:200px;float:left;"><b><a href="' . $wcm->cluburl . '" target="new">' . $wcm->clubbadgename . '</a></b>';
        } else {
            $meetings .= '<div style="width:200px;float:left;"><b>' . $wcm->clubbadgename . '</b>';
        }
        if ($wcm->clubaddress != "") {
            $meetings .=    '<br><i>' . $wcm->clubaddress . '</i><br>';
            if ($wcm->clubaddress2 != "")
                $meetings .=    '<i>' . $wcm->clubaddress2 . '</i><br>';
            if ($wcm->clubaddress3 != "")
                $meetings .=    '<i>' . $wcm->clubaddress3 . '</i><br>';
            $meetings .=    '<i>' . $wcm->clubcity . ', ' . $wcm->clubstatecode . ' &nbsp; ' . $wcm->clubpostalzip . '</i><br />';
        }

        $meetings .=    '</div>';
        $meetings .=    '<div style="overflow:hidden;padding-left: 40px;"><b>Where: </b> ' . $wcm->meetingplace;
        if ($wcm->meetingaddress != "") {
            $meetings .=    '<br><i>' . $wcm->meetingaddress . '</i><br>';
            if ($wcm->meetingaddress2 != "")
                $meetings .=    '<i>' . $wcm->meetingaddress2 . '</i><br>';
            if ($wcm->meetingaddress3 != "")
                $meetings .=    '<i>' . $wcm->meetingaddress3 . '</i><br>';
            $meetings .=    '<i>' . $wcm->meetingcity . ', ' . $wcm->meetingstatecode . ' &nbsp; ' . $wcm->meetingpostalzip . '</i><br />';
        }

        $meetings .=        '<b>When:</b> ' . $wcm->meetingday . 's at ' . $wcm->meetingtime . '';
        if ($wcm->latlng != "") {
            $meetings .=        '<span style="float:right; padding-right: 20px;"><a href="' . $wcm->latlng . '" target="new">Map It</a></span>';
        }
        $meetings .=    '</div>';
        $meetings .= '</div>';
        $meetings .= '<hr>';
        $counter = $counter + 1;
    }
    return $meetings;
}

//ANCHOR - Show Members
function dacdb_members($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $members = '';

    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];
    $thumbnail_width = isset($options['thumbnail_width']) && $options['thumbnail_width'] > 0 ? $options['thumbnail_width'] : (isset($atts['imgwidth']) && isset($atts['imgwidth']) > 0 ? $atts['imgwidth'] : 150);
    if ($fDebug) {
        $members .= "=================================================================<BR>";
        $members .= "function dacdb_members called<br>";
        $members .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $members .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $members .= "Membertypes=" . $options['membertypes'] . "<br>";
        $members .= "URL=" . $data_path . 'wp_club_members.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&MemberTypeIDs=' . $options['membertypes'] . '<br>';
        $members .= "=================================================================<BR>";
    }

    $xml = simplexml_load_file($data_path . 'wp_club_members.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&MemberTypeIDs=' . $options['membertypes'] . '&R=' . rand());
    if (strlen($xml) == 0) {
        $members .= 'There are no members to display at this time.';
        return $members;
    }

    $counter = 1;
    $lastCounter = count($xml->member);
    $pag_total = count($xml->member);
    $pag_pages = $pag_total / $options['mem_per_page'];
    $pag_pages = round_down($pag_pages, 0);
    $temp_pag_pages = ($pag_pages * $options['mem_per_page']);
    if ($temp_pag_pages > 0) {
        $pag_pages = $pag_pages + 1;
    }

    $members .= '<script>mypagenumber = ' . $pag_pages . ';</script>';
    $pagcounter = $options['mem_per_page'];
    $pagcountersec = 1;

    // check member cound start pagnation

    add_action('wp_footer', 'myscript', 200);
    if ($pag_pages != 0) {
        if ($options['pagnationposition_tb'] == 'Top') {
            if ($options['pagnationposition'] == 'Right') {
                $members .= '<div style="text-align:right;"><div class="pagination-dac-right" style="display:inline-block;"><ul id="pagination-dacdb" class="pagination-dac pagination"></ul></div></div>';
            } else {
                $members .= '<div><ul id="pagination-dacdb" class="pagination-dac pagination"></ul></div>';
            }
        }
    }

    $members .= '<div id="page-wrapper">';
    $grid_counter = 0;
    foreach ($xml->member as $member) {
        if ($pagcounter == $options['mem_per_page']) {
            $members .= '<div class="page-content"  id="pagsec' . $pagcountersec . '">';
            $pagcountersec = $pagcountersec + 1;
        } else {
            if ($pagcounter % $options['mem_per_page'] == 0) {
                $members .= '<div class="page-content"  id="pagsec' . $pagcountersec . '" style="display:none;">';
                $pagcountersec = $pagcountersec + 1;
            }
        }
        $grid_counter = $grid_counter + 1;
        if ($options['members_per_row'] == 1) {
            $grid_counter = 1; // force single row
        }
        if ($grid_counter == 1) {
            $members .= '<div class="dac-row">';
        }

        $setDivWidth = 150;
        $setImgWidth = 140;

        if ($options['members_per_row'] == 1) {
            $members .= '<div class="members dac-col-xs-12">';
        } else if ($options['members_per_row'] == 2) {
            $members .= '<div class="members dac-col-xs-12 dac-col-sm-6">';
        } else if ($options['members_per_row'] == 3) {
            $members .= '<div class="members dac-col-xs-12 dac-col-sm- dac-col-md-4">';
        } else if ($options['members_per_row'] == 4) {
            $members .= '<div class="members dac-col-xs-12 dac-col-sm-6 dac-col-md-3 dac-col-lg-3">';
            $setDivWidth = 120;
            $setImgWidth = 110;
        }

        if ($options['member_pics'] == 1) {
            if ($member->image == '') {
                $members .= '<table style="vertical-align: top;padding:0;border:0 !important;"><tr><td style="border:0 !important;vertical-align: top;padding:0;max-width:' . $setDivWidth . 'px;width:' . $setDivWidth . 'px"><img src="' . plugins_url('img/no_image.jpg', __FILE__) . '" style="aspect-ratio: 4 / 5; width: ' . $setImgWidth  . 'px; object-fit: cover;" width="' . $setImgWidth  . '"></td>';
            } else {
                $members .= '<table style="vertical-align: top;padding:0;border:0 !important;"><tr><td style="border:0 !important;vertical-align: top;padding:0;max-width:' . $setDivWidth . 'px;width:' . $setDivWidth . 'px"><img src="' . $member->image . '" style="aspect-ratio: 4 / 5; width: ' . $setImgWidth  . 'px; object-fit: cover;" width="' . $setImgWidth  . '"></td>';
            }
        }

        $members .= '<td style="border:0 !important;max-width:1px;width:1px;padding:0;">&nbsp;</td><td style="border:0 !important;vertical-align: top;padding:0;"><b>' . $member->username . '</b><br>';

        if ($options['member_club_pos'] == 1) {
            if ($member->clubposition != '') {
                $members .= '(' . $member->clubposition . ')<br>';
            }
        }
        if ($options['members_since'] == 1) {
            $startdate = strtotime($member->startdate);
            if ($options['members_since_format'] == 1) {
                $newformat = date('n/j/Y', $startdate);
            } elseif ($options['members_since_format'] == 2) {
                $newformat = date('n/Y', $startdate);
            } else {
                $newformat = date('Y', $startdate);
            }
            $members .= 'Member Since: ' . $newformat . '<br>';
        }
        if ($options['member_bus_name'] == 1) {
            if ($member->busweb != '') {
                if (strpos($member->busweb, "http://") == false) {
                    $newURL = 'http://' . $member->busweb;
                }
                $members .= '<a href="' . $newURL . '" target="_blank">' . $member->busname . '</a><br>';
            } else {
                $members .= $member->busname . '<br>';
            }
        }
        if ($options['member_bus_name'] == 0 && $options['member_bus_url'] == 1) {
            if ($member->busweb != '') {
                if (strpos($member->busweb, "http://") == false) {
                    $newURL = 'http://' . $member->busweb;
                }
                $members .= '<a href="' . $newURL . '" target="_blank">' . $member->busweb . '</a><br>';
            }
        }

        if ($options['member_bus_pos'] == 1) {
            if ($member->busposition != '') {
                $members .= $member->busposition . '<br>';
            }
        }

        if ($options['member_class'] == 1) {
            if ($member->classification != '') {
                $members .= $member->classification . '<br>';
            }
        }

        if ($options['members_contact_link'] == 1) {
            $members .= '<a href="' . $data_path . 'R_Emailer.cfm?UserID=' . $member->userid . '" name="cmc-inline-link-' . $counter . '" class="iframe3 cboxElement">Contact</a>';
        }
        $members .= '</td></tr></table></div>';
        $counter = $counter + 1;
        $pagcounter = $pagcounter + 1;

        if ($pagcounter % $options['mem_per_page'] == 0) {
            $members .= '</div>';
        }

        if ($grid_counter == $options['members_per_row']) {
            $members .= '</div>';
            $grid_counter = 0;
        }
    }
    $members .= '<!-- ' . $lastCounter . '-' . $counter . '-' . $grid_counter . ' -->';
    if ($grid_counter > 0) {
        $members .= '</div><!-- end  -->';
    }
    $members .= '</div>';
    $members .= '</div>';

    if ($pag_pages != 0) {
        if ($options['pagnationposition_tb'] == 'Bottom') {
            if ($options['pagnationposition'] == 'Right') {
                $members .= '<div style="text-align:right;"><div class="pagination-dac-right" style="display:inline-block;"><ul id="pagination-dacdb" class="pagination-dac pagination"></ul></div></div>';
            } else {
                $members .= '<div><ul id="pagination-dacdb" class="pagination-dac pagination"></ul></div>';
            }
        }
    }
    return $members;
}

//ANCHOR - Show Club Presidents
/**
 * Generate HTML content for displaying club presidents.
 *
 * @param array $atts The attributes passed to the function (none used in this case).
 * @return string The HTML content for displaying club presidents.
 */
function dacdb_club_presidents($atts)
{
    global $fDebug, $data_path, $options;

    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];
    $leaders = '';

    if ($fDebug) {
        $leaders .= "=================================================================<BR>";
        $leaders .= "function dacdb_club_presidents called<br>";
        $leaders .= "AccountID=" . $account_id . "<br>";
        $leaders .= "leaders_contact_link=" . $options['leaders_contact_link'] . "<br>";
        $leaders .= "data_path=" . $data_path . "<br>";
        $leaders .= "ClubID=" . $club_id . "<br>";
        $leaders .= "URL=" . $data_path . 'wp_leaders.cfm?AccountID=' . $account_id . '&ClubID=' . $club_id . '<br>';
        $leaders .= "=================================================================<BR>";
    }
    try {
        $xml = simplexml_load_file($data_path . 'wp_ccp.cfm?AccountID=' . $account_id . '&RoleKey=P&SortBy=C' . '&R=' . rand());
        if (strlen($xml) == 0) {
            $leaders .= 'There are no club presidents to display at this time.';
            return $leaders;
        }
    } catch (Exception $e) {
        return 'Error: ' . $e->getMessage();
    }
    $counter = 1;
    $cnt = 0;
    $lastCounter = count($xml->ccp);
    foreach ($xml->ccp as $ccp) {
        $grid_counter = isset($grid_counter) ? $grid_counter + 1 : 1;

        $presidentsPerRow = isset($options['club_presidents_per_row']) ? $options['club_presidents_per_row'] : 1;

        if ($presidentsPerRow == 1) {
            $grid_counter = 1; // force single row
        }

        if ($grid_counter == 1) {
            $leaders .= '<div class="dac-row">';
        }

        $presidentClasses = [
            1 => 'members dac-col-xs-12',
            2 => 'members dac-col-xs-12 dac-col-sm-6',
            3 => 'members dac-col-xs-12 dac-col-sm-12 dac-col-md-4',
            4 => 'members dac-col-xs-12 dac-col-sm-6 dac-col-md-3 dac-col-lg-3'
        ];

        $leaders .= '<div class="' . ($presidentClasses[$presidentsPerRow] ?? 'members') . '">';

        // Adjust div and image widths based on number of presidents per row
        $setDivWidth = ($presidentsPerRow == 4) ? 120 : 150;
        $setImgWidth = ($presidentsPerRow == 4) ? 110 : 140;

        if (
            $ccp->image == ''
        ) {
            $leaders .= '<table style="vertical-align: top;padding:0;border:0 !important;"><tr><td style="border:0 !important;vertical-align: top;padding:0;max-width:' . $setDivWidth . 'px;width:' . $setDivWidth . 'px"><img src="' . plugins_url('img/no_image.jpg', __FILE__) . '" style="aspect-ratio: 4 / 5; width: ' . $setImgWidth  . 'px; object-fit: cover;" width="' . $setImgWidth  . '"></td>';
        } else {
            $leaders .= '<table style="vertical-align: top;padding:0;border:0 !important;"><tr><td style="border:0 !important;vertical-align: top;padding:0;max-width:' . $setDivWidth . 'px;width:' . $setDivWidth . 'px"><img src="' . $ccp->imgpath . '' . $ccp->image . '" style="aspect-ratio: 4 / 5; width: ' . $setImgWidth  . 'px; object-fit: cover;" width="' . $setImgWidth  . '"></td>';
        }
        $leaders .= '<td style="border:0 !important;max-width:1px;width:1px;padding:0;">&nbsp;</td>';
        $leaders .= '<td style="border:0 !important;vertical-align: top;padding:0;">';
        $leaders .= '<b>' . $ccp->membername . '</b><br>' . $ccp->clubname . '<br>';
        if ($options['leaders_contact_link'] == 1) {
            $leaders .= '       <a href="' . $data_path . 'R_Emailer.cfm?UserID=' . $ccp->userid . '" name="dlc-inline-link-' . $cnt . '" class="iframe3 cboxElement">Contact</a>';
        }
        $leaders .= '</td>';


        $leaders .= '</tr></table></div>';
        $cnt++;
        if ($grid_counter == $options['club_presidents_per_row']) {
            $leaders .= '</div>';
            $grid_counter = 0;
        }
    }
    if ($grid_counter > 0) {
        $leaders .= '</div><!-- end  -->';
    }
    return $leaders;
}

//ANCHOR - Show Speakers
function dacdb_speakers($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $speakers = '';

    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];

    $N = 0;
    if (isset($atts['n'])) {            // No of Speakers
        $N = $atts['n'];
    }

    if ($fDebug) {
        $speakers .= "=================================================================<BR>";
        $speakers .= "function dacdb_speakers called<br>";
        $speakers .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $speakers .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $speakers .= "CatIDs=" . $options['speaker_cats'] . "<br>";
        $speakers .= "Mo=" . $options['speakers_months'] . "<br>";
        $speakers .= "N=" . $N . "<br>";
        $speakers .= $data_path . 'wp_speakers.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $club_id . '&CatIDs=' . $options['speaker_cats'] . '&Mo=' . $options['speakers_months'] . "<br>";
        $speakers .= "=================================================================<BR>";
    }
    $xml = simplexml_load_file($data_path . 'wp_speakers.cfm?AccountID=' . $options['dacdb_district'] . '&Mo=' . $options['speakers_months'] . '&CatIDs=' . $options['speaker_cats'] . '&ClubID=' . $options['dacdb_club'] . '&R=' . rand());
    if (strlen($xml) == 0) {
        $speakers .= 'There are no speakers at this time.';
        return  $speakers;
    }

    $counter = 0;
    foreach ($xml->speakerinfo as $speakerinfo) {
        $speakers .= '<div class="dacdb_plus_event">';

        if ($options['events_global_date'] == 1) {
            $speakers .= date("F jS Y", strtotime($speakerinfo->eventdate)) . ' at ' . date("g:i a", strtotime($speakerinfo->eventdate));
            $speakers .= '<br>';
        }
        $speakers .= '<strong>' . $speakerinfo->eventname . '</strong>';
        if ($options['speaker_page_full'] == 0) {
            $speakers .= '<br><strong>Speaker: ' . $speakerinfo->speaker . '</strong>';
            $speakers .= '<br>' . $speakerinfo->topic;
        }

        $speakers .= '<br>';
        if ($options['events_global_date'] == 0) {
            $speakers .= date("F jS Y", strtotime($speakerinfo->eventdate)) . ' at ' . date("g:i a", strtotime($speakerinfo->eventdate));
            $speakers .= '<br>';
        }
        if ($options['speaker_page_full'] == 1) {
            $speakers .= '' . $speakerinfo->description;
        } else {
            $speakers .= '<a class="iframe cboxElement" href="' . $data_path . 'R_Event.cfm?EventID=' . $speakerinfo->eventid . '">More info</a>';
        }
        $speakers .= '</div>';
        $speakers .= '<hr>';
        $counter = $counter + 1;
        if ($N > 0 and $counter >= $N) {
            return $speakers;
        }
    }
    return $speakers;
}

//ANCHOR - Show Events
function dacdb_events($atts)
{
    global $fDebug, $data_path, $file_path, $options;
    $events = '';
    $showTZ = 0;
    $showGMT = 0;
    $wk = 0;

    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];

    if (isset($atts['wk'])) {
        $wk = $atts['wk'];
    }
    if ($club_id == 0) {
        if (isset($atts['catids'])) {
            $options['district_events_types_page'] = $atts['catids'];
        }
        $categoryids = $options['district_events_types_page'];
        $mo = $options['district_events_months'];
    } else {
        if (isset($atts['catids'])) {
            $options['club_events_types_page'] = $atts['catids'];
        }
        $categoryids = $options['club_events_types_page'];
        $mo          = $options['club_events_months'];
    }
    if (isset($atts['showTZ']) && $atts['showTZ'] == '1') {
        $showGMT = $atts['showTZ'];
    }
    if (isset($atts['showgmt']) && $atts['showgmt'] == '1') {
        $showGMT = $atts['showGMT'];
    }

    if ($fDebug) {
        $events .= "=================================================================<BR>";
        $events .= "function dacdb_events called<br>";
        $events .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $events .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $events .= "Mo=" . $options['club_events_months'] . "<br>";
        $events .= "categoryids=" . $categoryids . "<br>";
        $events .= "showTZ=" . $showTZ . "<br>";
        $events .= "showGMT=" . $showGMT . "<br>";
        if ($wk > 0)
            $events .= $data_path . 'wp_event.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $club_id . '&CatIDs=' . $categoryids . '&wk=' . $wk . "<br>";
        else
            $events .= $data_path . 'wp_event.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $club_id . '&CatIDs=' . $categoryids . '&Mo=' . $mo . "<br>";
        $events .= "=================================================================<BR>";
    }

    if ($wk > 0)
        $xml = simplexml_load_file($data_path . 'wp_event.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&CatIDs=' . $categoryids . '&wk=' . $wk . '&R=' . rand());
    else
        $xml = simplexml_load_file($data_path . 'wp_event.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&CatIDs=' . $categoryids . '&Mo=' . $mo . '&R=' . rand());

    if (strlen($xml) == 0) {
        $events .= 'There are no events at this time.';
        return  $events;
    }

    $counter = 1;
    foreach ($xml->event as $event) {

        $events .= '<div class="dacdb_plus_event">';
        if ($options['events_global_date'] == 1) {
            if (date("Y-m-d", strtotime($event->startdate)) == date("Y-m-d", strtotime($event->enddate))) {
                $events .= date("F jS Y", strtotime($event->startdate)) . ' at ' . date("g:i a", strtotime($event->startdate));
            } else {
                if (date("Y-m-d", strtotime($event->startdate)) > date("Y-m-d", strtotime($event->enddate))) {
                    $events .= date("F jS Y", strtotime($event->startdate)) . ' at ' . date("g:i a", strtotime($event->startdate));
                } else {
                    $events .= date("F jS", strtotime($event->startdate)) . ' - ' . date("F jS Y", strtotime($event->enddate)) . ' at ' . date("g:i a", strtotime($event->startdate));
                }
            }
            if ($showTZ)
                $events .= ' ' . $event->tz;
            if ($showGMT)
                $events .= ' ' . $event->gmtoffset;
            $events .= '<br>';
        }
        $events .= '<strong>' . $event->eventname . '</strong>';
        if ($event->description != '') {
            $events .= '<br>' . $event->description . '';
        }
        if ($options['club_events_show_speakers_info'] == 1) {
            if ($event->speaker != '') {
                $events .= '<br><strong>Speaker: ' . $event->speaker . '</strong>';
            }
            if ($event->topic != '') {
                $events .= '<br>Topic: ' . $event->topic;
            }
        }
        if ($options['events_global_date'] == 0) {
            $events .= '<br>';
            if (date("Y-m-d", strtotime($event->startdate)) == date("Y-m-d", strtotime($event->enddate))) {
                $events .= date("F jS Y", strtotime($event->startdate)) . ' at ' . date("g:i a", strtotime($event->startdate));
            } else {
                if (date("Y-m-d", strtotime($event->startdate)) > date("Y-m-d", strtotime($event->enddate))) {
                    $events .= date("F jS Y", strtotime($event->startdate)) . ' at ' . date("g:i a", strtotime($event->startdate));
                } else {
                    $events .= date("F jS", strtotime($event->startdate)) . ' - ' . date("F jS Y", strtotime($event->enddate)) . ' at ' . date("g:i a", strtotime($event->startdate));
                }
            }
            if ($showTZ)
                $events .= ' ' . $event->tz;
            if ($showGMT)
                $events .= ' ' . $event->gmtoffset;
        }
        $events .= '<br>';
        $events .= '<a class="iframe cboxElement" sandbox="allow-top-navigation" href="' . $data_path . 'R_Event.cfm?EventID=' . $event->eventid . '">More info</a>';
        $events .= '<br></div>';
        $events .= '<hr class="dacdb_plus_event_hr">';
        $counter = $counter + 1;
    }
    return $events;
}

//ANCHOR - Show Committee Leaders
function dacdb_committee_leaders($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];

    $style      = isset($atts['style']) ? $atts['style'] : 1;
    $rolekeys   = isset($atts['rolekeys']) ? $atts['rolekeys'] : 'DLT';
    $members = '';

    if ($fDebug) {
        $members .= "=================================================================<BR>";
        $members .= "function dacdb_d_leaders called<br>";
        $members .= "AccountID=" . $account_id . "<br>";
        $members .= "data_file=" . $data_file . "<br>";
        $members .= "data_path=" . $data_path . "<br>";
        $members .= "ClubID=" . $club_id . "<br>";
        $members .= "RoleKey=" . $rolekeys . "<br>";
        $members .= "Style=" . $style . "<br>";
        $members .= "URL=" . $data_path . 'wp_committeeleaders.cfm?AccountID=' . $account_id . '&rolekey=' . $rolekeys . '<br>';
        $members .= "=================================================================<BR>";
    }

    $xml = simplexml_load_file($data_path . 'wp_committeeleaders.cfm?AccountID=' . $account_id . '&rolekey=' . $rolekeys . '&R=' . rand());
    if (strlen($xml) == 0) {
        $members .= 'There are no committee leaders to display at this time.';
        return $members;
    }

    $cnt = 0;
    $records = count($xml->dlc);
    $members .= dacdb_DisplayMembers($xml, $style, $atts);    // hard coded style=2 Kees' flag
    return $members;
}

//ANCHOR - Show District Leaders
function dacdb_d_leaders($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $leaders = '';

    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];
    if (isset($atts['leaders_per_row']) && $atts['leaders_per_row'] !== '') {
        $atts['leaders_per_row'] = $atts['leaders_per_row'];
    } elseif (isset($options['leaders_per_row']) && $options['leaders_per_row'] !== '') {
        $atts['leaders_per_row'] = $options['leaders_per_row'];
    } else {
        $atts['leaders_per_row'] = 1;
    }

    if (isset($atts['leader_pics']) && $atts['leader_pics'] !== '') {
        $atts['leader_pics'] = $atts['leader_pics'];
    } elseif (isset($options['leader_pics']) && $options['leader_pics'] !== '') {
        $atts['leader_pics'] = $options['leader_pics'];
    } else {
        $atts['leader_pics'] = 1;
    }


    if ($fDebug) {
        $leaders .= "=================================================================<BR>";
        $leaders .= "function dacdb_d_leaders called<br>";
        $leaders .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $leaders .= "data_file=" . $data_file . "<br>";
        $leaders .= "data_path=" . $data_path . "<br>";
        $leaders .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $leaders .= "leaders_per_row=" . $options['leaders_per_row'] . "<br>";
        $leaders .= "leaders_per_row override=" . $atts['leaders_per_row'] . "<br>";
        $leaders .= "URL=" . $data_path . 'wp_dlc.cfm?AccountID=' . $options['dacdb_district'] . '<br>';
        $leaders .= "=================================================================<BR>";
    }

    $xml = simplexml_load_file($data_path . 'wp_dlc.cfm?AccountID=' . $options['dacdb_district'] . '&R=' . rand());
    if (strlen($xml) == 0) {
        $leaders .= 'There are no district leaders to display at this time.';
        return $leaders;
    }

    $cnt = 0;
    $records = count($xml->dlc);
    //$leaders .= 'cols='. $cols.'<br />';
    //$leaders .= 'count='. $records.'<br />';

    $leaders .= '<div class="dac-row">';

    foreach ($xml->dlc as $member) {

        $cols = $atts['leaders_per_row'];
        if ($options['leaders_per_row'] == 1) {
            $leaders .= '<div class="members dac-col-xs-12">';
            $setDivWidth = 155;
            $setImgWidth = 150;
        } else if ($options['leaders_per_row'] == 2) {
            $leaders .= '<div class="members dac-col-xs-12 dac-col-sm-6">';
            $setDivWidth = 140;
            $setImgWidth = 135;
        } else if ($options['leaders_per_row'] == 3) {
            $leaders .= '<div class="members dac-col-xs-12 dac-col-sm-12 dac-col-md-4">';
            $setDivWidth = 125;
            $setImgWidth = 120;
        } else if ($options['leaders_per_row'] == 4) {
            $leaders .= '<div class="members dac-col-xs-12 dac-col-sm-6 dac-col-md-3 dac-col-lg-3">';
            $setDivWidth = 110;
            $setImgWidth = 105;
        }

        // $leaders .= $member->membername.'<br />';
        $leaders .= '<table style="vertical-align: top; padding:0;  !important;">';
        $leaders .=  '  <tr>';
        if ($atts['leader_pics'] == 1) {
            $leaders .=  '      <td style="vertical-align: top; padding:0; max-width:' . $setDivWidth . 'px; width:' . $setDivWidth . 'px">';
            if ($member->image == '') {
                $leaders .= '       <img src="' . plugins_url('img/no_image.jpg', __FILE__) . '" width="' . $setImgWidth . '" style="border:1; max-width:' . $setImgWidth . 'px">';
            } else {
                $leaders .= '       <img src="' . $member->imgpath . '' . $member->image . '" width="' . $setImgWidth . '" style="border:1; max-width:' . $setImgWidth . 'px">';
            }
            $leaders .=  '      </td>';
        }

        $leaders .= '       <td style="vertical-align: top;  max-width: 150px; padding: 0;">';
        $leaders .= '           <b>' . $member->membername . '</b><br>';
		if ( $member->cluburl = '')
			$leaders .= '       ' . $member->clubname . '<br>';
		else
			$leaders .= '           <a href="' . $member->cluburl . '" target="new">' . $member->clubname . '</a><br>';
		$leaders .= '           ' . $member->committeeposition . '<br>';

		if ($options['leaders_contact_link'] == 1) {
            $leaders .= '       <a href="' . $data_path . 'R_Emailer.cfm?UserID=' . $member->userid . '" name="dlc-inline-link-' . $cnt . '" class="iframe3 cboxElement">Contact</a>';
        }

        $leaders .=  '      </td>';
        $leaders .=  '  </tr>';
        $leaders .=  '</table>';
        $leaders .= '</div>'; // <!-- col -->

        $cnt++;
        if (($cnt % $cols) == 0  & $cnt < $records) {
            $leaders .= '</div><div class="dac-row">';
        }
    }

    $leaders .= '</div>'; //<!-- dac-row  -->
    return $leaders;

    /*
    $counter = 1;
    $grid_counter = 0;
    foreach($xml->dlc as $member) {
        $grid_counter = $grid_counter + 1;
        if ($options['leaders_per_row'] == 1) {
            $grid_counter = 1; // force single row
        }
        if ( $grid_counter == 1 ) {
            $leaders .= '<div class="dac-row">';
        }
        if ($options['leader_pics'] == 1) {
            if ( $dlc->image == '' ) {
                $leaders .= '<div class="dac-col-6-12" style="width:'.$setDivWidth.'px; float:left;"><img src="'. plugins_url( 'img/no_image.jpg', __FILE__ ) .'" width="'.$setImgWidth.'"></div>';
            } else {
                $leaders .= '<div class="dac-col-6-12" style="width:'.$setDivWidth.'px; float:left;"><img src="'.$dlc->imgpath.''.$dlc->image.'" width="'.$setImgWidth.'"></div>';
            }
        }
        $leaders .= '<td style="border:0 !important;max-width:1px;width:1px;padding:0;"></td><td style="border:0 !important;vertical-align: top;padding:0;"><b>'.$dlc->membername.'</b><br>'.$dlc->committeeposition;
        $leaders .= '<br>Club: <a href="'.$dlc->cluburl.'" target="new">'.$dlc->clubname.'</a><br><br>';
        if ($options['leaders_contact_link'] == 1) {
            $leaders .= '<a href="'.$data_path.'R_Emailer.cfm?UserID='.$dlc->userid.'" name="dlc-inline-link-'.$counter.'" class="iframe3 cboxElement">Contact</a>';
        }
        $leaders .= '</td></tr></table>';
        $leaders .= '</div>';
        if ( $grid_counter == $options['leaders_per_row'] ) {
            $leaders .= '</div>';
            $grid_counter = 0;
        }
        $counter = $counter + 1;
    }
    return $leaders;
*/
}

//ANCHOR - Show Stories
//TODO - STORIES: Refactor this to simplify functional responsibility
/**
 * Returns a string containing stories
 *
 * @param array $atts
 * @return int
 * @throws Exception If element in array is not an integer
 */
function dacdb_stories($atts)
{
    global $fDebug, $data_path, $file_path, $options;
    $stories = '';
    $share = 'Y';
    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];
    $share      = $options['story_share'];
    $smstyle    = 1;

	if (isset($atts['catid'])) {            // URL
        $catid = $atts['catid'];
    } elseif (isset($_GET['storyid'])) {
        $catid = $_GET['storyid'];
    } else {
        $catid = "";
    }
    if (isset($_GET['storyid'])) {            // URL
        $storyid = $_GET['storyid'];
    } elseif (isset($atts['storyid'])) {        // Shortcut code
        $storyid = $atts['storyid'];
    } else {
        $storyid = 0;
    }

	if (isset($_GET['share'])) {           	// New share Y|N
        $share = $_GET['share'];
    } elseif (isset($atts['share'])) {
        $share = $atts['share'];
    } else {
        $share = 'Y';
    }

	if (isset($_GET['smstyle'])) {           // New smstyle 1|linear-default, 2|icon, 3|dropdown
        $smstyle = $_GET['smstyle'];
    } elseif (isset($atts['smstyle'])) {
        $smstyle = $atts['smstyle'];
    } else {
        $smstyle = 1;
    }

	if ($fDebug) {
        $stories .= "=================================================================<BR>";
        $stories .= "function dacdb_stories called<br>";
        $stories .= "Attributes Passed to function:" . var_dump($atts) . "<br>";
        $stories .= "storyid=" . $storyid . "<br>";
        $stories .= "catid=" . $catid . "<br>";
        $stories .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $stories .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $stories .= "open=" . $options['story_open'] . " &nbsp; (0=expand, 1=In Window, 2=New Window)<br>";
        $stories .= "limit=" . $options['story_limit'] . "<br>";
        $stories .= "Share Setting=" . $options['story_share'] . "<br>";
        $stories .= "share=" . $share . "<br>";
        $stories .= "smstyle=" . $smstyle . "<br>";
        $stories .= "url=" . $data_path . 'wp_stories.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $club_id . '&StoryID=' . $storyid . '&CatIDs=' . $catid . '&N=' . $options['story_limit'] . "<br>";
        $stories .= "=================================================================<BR>";
    }

    $xml = simplexml_load_file($data_path . 'wp_stories.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $club_id . '&StoryID=' . $storyid . '&CatIDs=' . $catid . '&N=' . $options['story_limit'] . '&R=' . rand());
    if (strlen($xml) == 0) {
        $stories .= 'There are no stories at this time.';
        return $stories;
    }

	$counter = 1;
    foreach ($xml->story as $story) {
        $stories .= '<div class="" style="overflow:hidden; padding: 10px; margin-bottom: 20px;">';
        $stories .= '	<div class="row" style="width:100%; margin: 0 auto;">';
		$stories .= '		<div style="width: 75%; float: left; text-align: left;"> ';
		$stories .= '			<h1 class="dacdb-story-header">' . $story->headline . '</h1>';
		$stories .= '		</div>';

		$stories .= '		<div style="width: 25%; float: right; text-align: right; "> ';
		//$stories .= ' id='. $story->storyid;
		$stories .= 			dacdb_SMIcons($share, $smstyle, $story->smsoptions, $story->storyid, $story->headline );    //SM ICONS HER
		$stories .= '		</div>';
		$stories .= '	</div>';

        if ($story->bitstorydate == 1) {
			$stories .= '<div class="row" style="margin-left: 0px; margin-bottom: 20px; >';
            $stories .= '	<span class="posted-on">';
            $stories .=			 $story->storydate;
            $stories .= '	</span>';
			$stories .= '</div> ';
        }
        if ($story->bitbyline == 1) {
            $stories .= ' <span class="posted-by">';
            if ($story->biteditedby == 1) {
                $stories .= 'By: ' . $story->modifiedby;
            } else {
                $stories .= 'By: ' . $story->submittedby;
            }
            $stories .= '</span><br/>';
        }

        // if ($_GET["storyid"]) {
        /* old way not needed any more?
			if ($storyid > 0) {
            $stories .= '<span style="float:right !important;">
            <a target="_new" href="https://www.facebook.com/sharer/sharer.php?u=' . urlencode(get_permalink()) . '" class="btn btn-sm btn-facebook"><img style="width:20px;" src="' . plugins_url('img/fb.png', __FILE__) . '"></a>
            <a target="_new" href="https://twitter.com/home?status=' . urlencode(get_permalink()) . '" class="btn btn-sm btn-twitter"><img style="width:20px;" src="' . plugins_url('img/tw.png', __FILE__) . '"></a>
            <!---<a target="_new" href="https://plus.google.com/share?url=' . urlencode(get_permalink()) . '" class="btn btn-sm btn-google"><img style="width:20px;" src="' . plugins_url('img/gp.png', __FILE__) . '"></a>--->
            <a target="_new" href="https://www.linkedin.com/shareArticle?mini=true&amp;url=' . urlencode(get_permalink()) . '&amp;title=' . $story->headline . '&amp;summary=&amp;source=" class="btn btn-sm btn-linkedin"><img style="width:20px;" src="' . plugins_url('img/li.png', __FILE__) . '"></a></span>';
        }
		*/
        if ($story->image != '') {
            if ($options['story_image'] == 2) {
                $stories .= '<img src="' . $story->image . '" align="right" width="150" style="padding-left:10px;width:150px;">';
            } elseif ($options['story_image'] == 1) {
                $stories .= '<img src="' . $story->image . '" align="left"  width="150" style="float:left;padding-right:10px;width:150px;">';
            } else {
                if ($counter % 2 == 0) {
                    $stories .= '<img src="' . $story->image . '" align="right" width="150" style="padding-left:10px;width:150px;">';
                } else {
                    $stories .= '<img src="' . $story->image . '" align="left" width="150" style="float:left;padding-right:10px;width:150px;">';
                }
                $counter++;
            }
        }
        $stories .= $story->summary;
        if (trim($story->description) != '') {
            if ($storyid && $display == 'Y') {
                $stories .= $story->summary;
            } else {
                $stories .= '<div id="description-' . $story->storyid . '" class="stories-summary" style="display:none;">' . $story->description . '</div>';
                if ($options['story_open'] == 0) {
                    $stories .= '<br><br><a href="#" onclick="return showdiv(' . $story->storyid . ')" id="more-' . $story->storyid . '">Read More</a>';
                } elseif ($options['story_open'] == 1) {
                    $stories .= '<br><br><a href="?storyid=' . $story->storyid . '"  id="more-' . $story->storyid . '">Read More</a>';
                } elseif ($options['story_open'] == 2) {
                    $stories .= '<br><br><a href="?storyid=' . $story->storyid . '"  id="more-' . $story->storyid . '" target="_blank">Read More</a>';
                }
            }
        }
        //if ($options['story_share']) {
        //    $stories .= '<span style="float: right!important;"><a href="?storyid=' . $story->storyid . '">Share</a></span>';
        //}
        // if ($_GET["storyid"]) {
        //if ($storyid) {
        //    $stories .= '<style>h1.entry-title { display:none !important; }</style>';
        //    $stories .= '<style>.entry-header { display:none !important; }</style>';
        //}

        //if ( $pagetitle == 'N') {
        //    $stories .= '<style>h1.entry-title { display:none !important; }</style>';
        //}

        $stories .= '</div>';
        $separator = isset($options['story_sep']) ? $options['story_sep'] : 'no';
        if (!$storyid && $separator != 'no') {
            if ($story->bitinchr == 1 && isset($options['story_sep'])) {
                $hrstyles = array(
                    "1" => 'style-one',
                    "2" => 'style-two',
                    "3" => 'style-three',
                    "4" => 'style-four',
                    "5" => 'style-five',
                    "6" => 'style-six',
                    "7" => 'style-seven',
                    "8" => 'style-eight'
                );
                $hrstyle = isset($hrstyles[$options['story_sep']]) ? $hrstyles[$options['story_sep']] : '';
                $stories .= '<hr class="' . $hrstyle . '">';
            }
        }
    }
    storyscript();  // only exec once after all stories (was in loop)
    return $stories;
    // add_action( 'wp_footer', 'storyscript', 201 );  //Removed not sure this is needed.

}  // dacdb_stories

//ANCHOR - Show Calendar
/**
 * Generates the HTML markup for a FullCalendar.
 *
 * @param array $atts An associative array of attributes
 *
 * @return string The generated calendar HTML.
 */
function dacdb_calendar($atts){
    global $fDebug, $data_path, $file_path, $options;
    $calendar = "";
	$sector = "";  //There is no option for sector, it is only a shortcode attribute
	$views = "dayGridMonth,listMonth";  //There is no option for sector, it is only a shortcode attribute

    // plugin parameters
    // Use the Setttings and then ShortCode Override if there
    if ( $options['dacdb_club'] == 0 ) {
        $eids = $options['district_events_types_page'];
    }
    else {
        $eids = $options['club_events_types_page'];
    }

    if ( $options['cal_display'] != '' )           // check if no one saved this value
        $view  =$options['cal_display'];
    else
        $view = 'dayGridMonth';

	if ( $options['cal_limit'] != '' )             // check if no one saved this value
        $callimit  =$options['cal_limit'];
    else
        $callimit = 5;

	// add in shortcode overridres per page
	if (isset($_GET['catids'])) {           	// New url catids parameter added
        $eids = $_GET['catids'];
    } elseif (isset($atts['catids'])) {
        $eids = $atts['catids'];
    }

	if (isset($_GET['view'])) {           		// New url view parameter added
        $view = $_GET['view'];
    } elseif (isset($atts['view'])) {
        $view = $atts['view'];
    }

	if (isset($_GET['views'])) {           		// New url views parameter added
        $views = $_GET['views'];
    } elseif (isset($atts['views'])) {
        $views = $atts['views'];
    }

	if (isset($_GET['callimit'])) {           		// New url callimit parameter added
        $callimit = $_GET['callimit'];
    } elseif (isset($atts['callimit'])) {
        $callimit = $atts['callimit'];
    }

	if (isset($_GET['sector'])) {           		// New sector and url sector parameter added
        $sector = $_GET['sector'];
    } elseif (isset($atts['sector'])) {
        $sector = $atts['sector'];
    }

	if ( $view == 'month')
		$view = 'dayGridMonth';

    if ( $fDebug )  {
        $calendar .= "=================================================================<BR>";
        $calendar .= "function dacdb_calendar called<br>";
        $calendar .= "AccountID=".$options['dacdb_district']."<br>";
        $calendar .= "ClubID=".$options['dacdb_club']."<br>";
        $calendar .= "view=".$view."<br>";
        $calendar .= "views=".$views."<br>";
        $calendar .= "limit=".$callimit."<br>";
        $calendar .= "sector=".$sector."<br>";
        $calendar .= "data_path=".$data_path."<br>";
        if ( $options['dacdb_club'] == 0 ) {
            $calendar .= "District EventCategoryIDs view=".$eids."<br>";
            $calendar .= "District URL=".$data_path."R_GetEventsb2.cfm?AccountID=".$options['dacdb_district']."&ClubID=".$options['dacdb_club']."&EventCategoryIDs=".$eids."&Sector=".$sector."<br>";
        }
        else {
            $calendar .= "Club EventCategoryIDs view=".$eids."<br>";
            $calendar .= "Club URL=".$data_path."R_GetEventsV2.cfm?AccountID=".$options['dacdb_district']."&ClubID=".$options['dacdb_club']."&EventCategoryIDs=".$eids."&Sector=".$sector."<br>";
        }
        $calendar .= "EventCategoryIDs=".$data_path."wp_eventcategory.cfm?D=" .$options['dacdb_district']."<br>";
        $calendar .= "=================================================================<BR>";
    }

	$calendar .= "<style>.entry-content tr td {padding: 4px 4px !important;}</style>";		// override a style to reduce the cell padding
	$calendar .= "<div id='Calendar' style='width=90% max-width: 950px;'></div>";
    $calendar .= "<div id='colorKey'></div>";

	/* version 6.1.8 full calendar */
	$calendar .= "<script src='https://unpkg.com/popper.js/dist/umd/popper.min.js'></script> ";
	$calendar .= "<script src='https://unpkg.com/tooltip.js/dist/umd/tooltip.min.js' ></script> ";
	$calendar .= "<script src='https://code.jquery.com/jquery-3.7.1.min.js' integrity='sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo='  crossorigin='anonymous' defer></script>";
	$calendar .= "<script type='text/javascript'>
		const isMobile = window.matchMedia('only screen and (max-width: 760px)').matches;
		jQuery(function($) {
			//document.addEventListener('DOMContentLoaded', function() {
			$.getJSON('".$data_path."wp_eventcategory.cfm?D=" .$options['dacdb_district']."', function( data ) {
				console.log ( data );
				showColorKey( data );
			});

			var calendarEl = document.getElementById('Calendar');
			var calendar = new FullCalendar.Calendar(calendarEl, {
				height: 'auto',
				slotMinTime: '08:00',
				slotMaxTime: '20:00',
				// stickyHeaderDates: false, // for disabling
				headerToolbar:
				{
					left: 'prev,next today',
					center: 'title',
					right: '" .$views. "'
				},

				views: {
					listDay: { buttonText: 'list day' },
					listWeek: { buttonText: 'list week' }
				},

				initialView: 	isMobile ? '".'listMonth'."' : '".$view. "',
				navLinks: 		true, 		// can click day/week names to navigate views
				businessHours: 	true, 		// display business hours
				editable: 		true,
				selectable: 	true,
				nowIndicator: 	true,
				dayMaxEvents:	false,

				eventDidMount: function(info) {
					var tooltip = new Tooltip(info.el, {
						title: info.event.title,
						placement: 'top',
						trigger: 'hover',
						container: 'body'
					});
				}
				,eventSources: [
				{
					url: '".$data_path."R_GetEventsV2.cfm?r'+Math.random(),
					method: 'GET',
					extraParams:
					{
						AccountID:'"		.$options['dacdb_district']."',
						ClubID:'"			.$options['dacdb_club']."',
						EventCategoryIDs:'"	.$eids."'
					}

				}
				]

				,eventClick: function(info) {	 // open in new window on a phone
					if ( !isMobile ) {
						info.jsEvent.preventDefault();					//prevent the browser from navigating to the click
						$.colorbox({ width:'90%', height:'905', iframe:true, href:info.event.url });
					}
				}
			});
			calendar.render();
		});
	";

/* Full Calendar v3.0 old code
    $calendar .= "<script type='text/javascript'>";
	$calendar .= "var j$ = jQuery.noConflict();";
    $calendar .= "var date = new Date();";
    $calendar .= "var d = date.getDate();";
    $calendar .= "var m = date.getMonth();";
    $calendar .= "var y = date.getFullYear();";
    $calendar .= " jQuery(function($) {";
    $calendar .= " var calendar = jQuery('#Calendar').fullCalendar({";
    $calendar .= "  header: {";
    $calendar .= "      left: 'prev,next today',";
    $calendar .= "      center: 'title',";
    $calendar .= "      right: 'month,listMonth'";
    $calendar .= "  },";
    if ( $view == 'listMonth' or $view == 'list'  ) {
        $calendar .= "  defaultView: 'listMonth',";
    } else {
        $calendar .= "  defaultView: 'month',";
    }

    $calendar .= "  firstDay: 0,";
    $calendar .= "viewRender: function(currentView){";
    $calendar .= "    var minDate = moment();";
    $calendar .= "    if (minDate >= currentView.start && minDate <= currentView.end) {";
    $calendar .= "        $('.fc-prev-button').prop('disabled', true); ";
    $calendar .= "        $('.fc-prev-button').addClass('fc-state-disabled'); ";
    $calendar .= "    } else {";
    $calendar .= "        $('.fc-prev-button').removeClass('fc-state-disabled'); ";
    $calendar .= "        $('.fc-prev-button').prop('disabled', false); ";
    $calendar .= "    }";
    $calendar .= " },";

    $calendar .= "  editable: false,";
    $calendar .= "  scrollTime: '07:00:00',";
    $calendar .= "  minTime:    '07:00:00',";
    $calendar .= "  maxTime:    '20:00:00',";
    $calendar .= "  height: 'auto',";
    $calendar .= "  eventLimit: ".$callimit.",";
    $calendar .= "  eventLimitText: 'More',";
    $calendar .= "
        eventMouseover: function(calEvent, jsEvent) {
            if ( calEvent.Location != '' ) {
                showLocation = \"<br /><b>Location:</b> \" + calEvent.Location;
            } else {
                showLocation = '';
            }
            if (calEvent.Speaker != '') {
                if (calEvent.Topic == '') {
                    var tooltip = \"<div class='tooltipevent' style='position:absolute;z-index:10001;'><b>\" + calEvent.title + \"</b>\"+showLocation+\"<br>Speaker: \"+calEvent.Speaker+\"</div>\";
                } else {
                    var tooltip = \"<div class='tooltipevent' style='position:absolute;z-index:10001;'><b>\" + calEvent.title + \"</b>\"+showLocation+\"<br>Speaker: \"+calEvent.Speaker+\"<br>Topic: \"+calEvent.Topic+\"</div>\";
                }
            } else {
                var tooltip = \"<div class='tooltipevent' style='position:absolute;z-index:10001;'><b>\" + calEvent.title + \"</b>\"+showLocation+\"</div>\";
            }

            $('body').append(tooltip);
            $(this).mouseover(function(e) {
                $(this).css('z-index', 10000);
                $('.tooltipevent').fadeIn('500');
                $('.tooltipevent').fadeTo('10', 1.9);
            }).mousemove(function(e) {
                $('.tooltipevent').css('top', e.pageY + 10);
                $('.tooltipevent').css('left', e.pageX + 20);
            });
        },
        eventMouseout: function(calEvent, jsEvent) {
             $(this).css('z-index', 8);
             $('.tooltipevent').remove();
        },
    ";

    $calendar .= "  events: function (start, end, timezone, callback) {";
    $calendar .= "      $.getJSON('".$data_path."wp_eventcategory.cfm?D=" .$options['dacdb_district']."', function( data ) { console.log (data);  showColorKey( data ) } );";
    $calendar .= "      $.getJSON('".$data_path."R_GetEvents.cfm?AccountID=".$options['dacdb_district']."&ClubID=".$options['dacdb_club']."&EventCategoryIDs=".$eids."', function(data, textStatus, jqxhr ) {";
    $calendar .= "          var events = [];";
    $calendar .= "          $.each( data, function( key, val ) {";
    $calendar .= "              events.push( val );";
    $calendar .= "          });";
    $calendar .= "          callback(events);";
    $calendar .= "      });";
    $calendar .= "  },";
    $calendar .= "  eventClick: function(event) {";
	$calendar .= "      $.colorbox({width:'90%', height:'905', iframe:true, href:event.url});";
    $calendar .= "  	return false; ";
    $calendar .= "      }";
    $calendar .= "  });";
    $calendar .= "});";
*/
	//$calendar .= "$.getJSON('".$data_path."wp_eventcategory.cfm?D=" .$options['dacdb_district']."', function( data ) { console.log (data);  showColorKey( data ) } );";
	$calendar .= "function showColorKey(json) {
                        var statusHTML = [];
                        console.log (json.length);
                            for (var i=0; i<json.length; i++)
                            {
                                var p = json[i];
                                console.log (p);
                                var catDisplay = p.EVENTCATEGORY.trim();
                                console.log (catDisplay);
                                statusHTML.push('<div style=\"display:inline-block;margin-right:10px;\"><span class=\"dac-label\" style=\"background-color:'+p.BGCOLOR+';color:'+p.FGCOLOR+';font-weight:normal;border: 1px solid #3a87ad;\">'+catDisplay+'</span></div>');
                            }
                        console.log (statusHTML);
                        if ( $('#colorKey').length ) {
                            document.getElementById('colorKey').innerHTML = statusHTML.join('');
                        }
                    }";
   $calendar .= "</script>";
   return $calendar;
}  // eoCalendar

//!SECTION Process Shortcode Functions

//ANCHOR - Global variables
/**
 * Sets the data and file paths based on the given conditions.
 *
 * @global bool   $fDebug         Flag indicating whether debug mode is enabled.
 * @global string $data_path      The data path URL.
 * @global string $file_path      The file path URL.
 * @global array  $options        An array of options.
 *
 * @return void
 */

//SECTION - JavaScript Functions
function setDataPath()
{
    global $fDebug, $data_path, $file_path, $options;

    // default to DACdb
    $data_path = 'https://www.IsMyRotaryClub.org/wp_api_1-2/';
    $file_path = 'https://www.dacdb.com/Accounts/';
    $image_path = 'https://www.dacdb.com/images/';				// future, was caded but fa had the icon needed

    if (isset($options['dacdb_system']) && ($options['dacdb_system'] == 'iMembersDB')) {
        $data_path   = 'https://www.emembersdb.com/wp_api_1-2/';
        $file_path   = 'https://www.imembersdb.com/Accounts/';
		$public_path = 'https://www.emembersdb.com/';
        $acct_label  = 'Account';
    }
    if (isset($options['dacdb_system']) && ($options['dacdb_system'] == 'DACdb')) {
        $data_path 	 = 'https://www.IsMyRotaryClub.org/wp_api_1-2/';
        $file_path 	 = 'https://www.dacdb.com/Accounts/';
		$public_path = 'https://www.IsMyRotaryClub.com/';
        $acct_label  = 'District';
    }
    $data_path = trim($data_path);
    if (isset($_GET['debug'])) {
        $fDebug = True;
    }
    return;
} // setDataPath

//ANCHOR - Javascript storyscript
/**
 * Generates a JavaScript script to handle the show/hide functionality for a specific element.
 *
 * This function checks if the jQuery script has been loaded and executed.
 * If the jQuery script is loaded, it generates a JavaScript script containing a function called "showdiv".
 * The "showdiv" function toggles the visibility of a specified element and updates the content of another element accordingly.
 *
 * @return void
 */

function storyscript()
{
    //if (wp_script_is('jquery', 'done')) {		// jquery is loaded and stories have been rendered
    ?>
        <script defer type="text/javascript">
            /**
             * Toggles the visibility of an element and updates the content of another element.
             *
             * @param {string} divid - The ID of the element to toggle.
             * @return {boolean} - Returns false to prevent default behavior.
             */
            function showdiv(divid) {
                console.log("showdiv=" + divid);
                $("#description-" + divid).toggle();
                console.log($("#more-" + divid).html());
                var t = $("#more-" + divid).html();
                if (t == 'Read More')
                    $("#more-" + divid).html("Less");
                else
                    $("#more-" + divid).html("Read More");
                return false;
            }
        </script>
    <?php
    //}
}

//ANCHOR - JavaScript Pagination
/**
 * Outputs a JavaScript code block that initializes the twbsPagination plugin for pagination.
 *
 * This function checks if the jQuery script is loaded and executed before outputting the JavaScript code.
 * The twbsPagination plugin creates a pagination element with specified total pages, visible pages, and other options.
 * When a page is clicked, the corresponding page content is shown and the current page content is hidden.
 *
 * @since 1.0.0
 */
function myscript()
{
    if (wp_script_is('jquery', 'done')) {
    ?>
        <script defer type="text/javascript">
            (function($) {
                $('#pagination-dacdb').twbsPagination({
                    totalPages: mypagenumber,
                    visiblePages: "7",
                    hideOnlyOnePage: true,
                    onPageClick: function(event, page) {
                        $('.page-content').hide();
                        $('#pagsec' + page).show();
                    }
                });
            })(jQuery);
        </script>
    <?php
    }
}
//!SECTION - JavaScript Functions

//ANCHOR - Plugin Registration Functions
if (class_exists('dacdb_plus')) {
    // Installation and uninstallation hooks
    register_activation_hook(__FILE__, array('dacdb_plus', 'activate'));
    register_deactivation_hook(__FILE__, array('dacdb_plus', 'deactivate'));
    // instantiate the plugin class
    $dacdb_plus = new dacdb_plus();
}

// DO WIDGETS
class dacdb_plus_widget extends WP_Widget
{
    function __construct()
    {
        parent::__construct(
            // Base ID of your widget
            'dacdb_plus_widget',
            // Widget name will appear in UI
            __('DACdb Plus', 'dacdb_plus_widget'),
            // Widget description
            array('description' => __('Allows you to display your DACdb Plus Wigets in your sidebars', 'dacdb_plus_widget'),)
        );
    }
    // Creating widget front-end
    // This is where the action happens
    public function widget($args, $instance)
    {
        global $fDebug, $data_path, $file_path, $options;

        $title = apply_filters('widget_title', $instance['title']);

        $show = $instance['show'];
        $count = $instance['count'];
        $club_id = $instance['club_id'];
        $options = get_option('dacdb_plus_options', array());

        setDataPath();   // ShortCode DACdb or iMembersDB paths

        if ($data_path == '') {
            $pagedata .= "=================================================================<BR>";
            $pagedata .=  "Missing System selction under Plugin Settings!<BR>";
            $pagedata .=  "=================================================================<BR>";
            $pagedata .=  "<BR>";
        }

        // $subscription = file_get_contents($data_path.'wp_subscription.cfm?AccountId='.$options['dacdb_district'].'&ClubID='.$options['dacdb_club']);
        $xml = simplexml_load_file($data_path . 'wp_subscription2.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&R=' . rand());
        //  if ( $subscription != '1' )  {
        if ($xml->status != '1') {
            $pagedata .= "=================================================================<BR>";
            $pagedata .=  "&nbsp; &nbsp;  Missing subscription record. System=" . $options['dacdb_system'] . ", AccountID=" . $options['dacdb_district'] . ", ClubID=" . $options['dacdb_club'] . "<BR>";
            $pagedata .=  "&nbsp; &nbsp;  Please contact: support@dacdb.com<BR>";
            $pagedata .=  "subscription=" . $xml->status . "<br>";
            if ($fDebug) {
                $pagedata .=  "&nbsp; &nbsp;  url=" . $data_path . 'wp_subscription2.cfm?AccountId=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . "<BR>";
            }
            $pagedata .=  "=================================================================<BR>";
            $pagedata .=  "<BR>";
        }

        if ($fDebug) {
            $pagedata .=  "=================================================================<BR>";
            $pagedata .=  "Version=" . $plugin_version . "<br>";
            $pagedata .=  "Show=" . $show . "<br>";
            $pagedata .=  "CatID=" . $catid . "<br>";
            $pagedata .=  "System=" . $options['dacdb_system'] . "<BR>";
            $pagedata .=  "data_path=" . $data_path . "<BR>";
            $pagedata .=  "file_path=" . $file_path . "<BR>";
            $pagedata .=  "subscription=" . $xml->status . "<BR>";
            $pagedata .=  "=================================================================<BR>";
        }

        // before and after widget arguments are defined by themes
        echo $args['before_widget'];
        if (!empty($title))

            echo $args['before_title'] . $title . $args['after_title'];
        $show_stories = 0;
        $show_events = 0;
        $show_speakers = 0;
        $show_leaders = 0;
        $show_members = 0;
        $show_birthdays = 0;
        $show_club_meetings = 0;
        $show_newsletters = 0;
        $show_sponsors = 0;
        //            $subscription = file_get_contents($data_path.'wp_conf.cfm?AccountId='.$options['dacdb_district'].'&ClubID='.$options['dacdb_club']);
        //Handle Shortcode story show
        if ($show == 'stories') {
            $show_stories = 1;
        } elseif ($show == 2) {
            $show_events = 1;
        } elseif ($show == 3) {
            $show_d_events = 1;
        } elseif ($show == 7) {
            $show_speakers = 1;
        } elseif ($show == 5) {
            $show_leaders = 1;
        } elseif ($show == 4) {
            $show_birthdays = 1;
        } elseif ($show == 1) {
            $show_meeting_info = 1;
        } elseif ($show == 6) {
            $show_newsletters = 1;
        } elseif ($show == 8) {
            $show_sponsors = 1;
        }

        if (isset($show_meeting_info) && $show_meeting_info == 1) {
            if (!$club_id) {
                $club_id = $options['dacdb_club'];
            }

            if ($fDebug) {
                $meetings = "";
                $meetings .= "=======================<BR>";
                $meetings .= "function widget show_meeting_info<br>";
                $meetings .= "AccountID=" . $options['dacdb_district'] . "<br>";
                $meetings .= "ClubID=" . $options['dacdb_club'] . "<br>";
                // $meetings .= "sort=".$sort."<br>";
                $meetings .= "URL=" . $data_path . 'wp_club_meetings.cfm?AccountID=' . $options['dacdb_district'] . '&SortBy=' . $sort . '<br>';
                $meetings .= "=======================<BR>";
                echo $meetings;
            }
            $xml = simplexml_load_file($data_path . 'wp_club_meetings.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $club_id . '&R=' . rand());
            $meetings = array();
            $counter = 1;
            foreach ($xml->meeting as $wcm) {
                echo '<div class="side-meeting-info">';
                echo '<span class="side-meeting-info-dt">' . $wcm->meetingday . 's at ' . $wcm->meetingtime . '</span><br/>';
                echo '<b>' . $wcm->meetingplace . '</b><br>';
                echo $wcm->meetingaddress . '<br>';
                echo $wcm->meetingcity . ', ' . $wcm->meetingstatecode . ' ' . $wcm->meetingpostalcode . '<br/>';
                if ($wcm->latlng != "") {
                    echo '<span style="float:right;"><a href="' . $wcm->latlng . '" target="new">Map It</a></span>';
                }
                echo '<br></div>';
                $counter = $counter + 1;
            }
            $meet_total = count($xml->meeting);
            if ($meet_total == 0) {
                echo 'There are no club meetings to display at this time.';
            }
        }

        if (isset($show_events) && $show_events == 1) {
            if (!$club_id) {
                $club_id = $options['dacdb_club'];
            } else {
                $byShowSpeaker = 1;
            }

            if ($club_id == 0) {
                $categoryids = $options['district_events_types_page'];
                $mo = $options['district_events_months_side'];
            } else {
                $categoryids = $options['club_events_types_page'];
                $mo = $options['club_events_months_side'];
            }

            if ($fDebug) {
                $events = "";
                $events .= "=======================<BR>";
                $events .= "function widget show_events<br>";
                $events .= "AccountID=" . $options['dacdb_district'] . "<br>";
                $events .= "ClubID=" . $options['dacdb_club'] . "<br>";
                $events .= "Mo=" . $options['club_events_months'] . "<br>";
                $events .= "categoryids=" . $categoryids . "<br>";
                $events .= $data_path . 'wp_event.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&CatIDs=' . $categoryids . '&Mo=' . $mo . '<br />';
                $events .= "=======================<BR>";
                echo $events;
            }

            $xml = simplexml_load_file($data_path . 'wp_event.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&CatIDS=' . $categoryids . '&Mo=' . $mo . '&R=' . rand());
            //                if ( $options['club_events_types_side'] == '') {
            //                    $xml = simplexml_load_file($data_path.'wp_event.cfm?AccountID='.$options['dacdb_district'].'&ClubID='.$club_id.'&Cat=3,5,4&Mo='.$options['club_events_months_side'].'&R='.rand());
            //                } else {
            //                    $xml = simplexml_load_file($data_path.'wp_event.cfm?AccountID='.$options['dacdb_district'].'&ClubID='.$club_id.'&Cat='.$options['club_events_types_side'].'&Mo='.$options['club_events_months_side'].'&R='.rand());
            //                }
            $events = array();
            $counter = 1;
            $showEvent = 1;

            $event_total = count($xml->event);
            foreach ($xml->event as $event) {
                if ($options['club_events_show_speakers_side'] == 0 && $event->speaker != '') {
                    $showEvent = 0;
                } else if ($options['club_events_show_speakers_side'] == 0 && $event->speaker == '') {
                    $showEvent = 1;
                }

                if ($byShowSpeaker = 1 && $event->speaker == '') {
                    $showEvent = 1;
                }

                if ($showEvent == 1) {
                    if ($count >= $counter) {
                        echo '<div class="side-club-event" style="line-height:1.5;">';
                        if ($options['events_global_date'] == 1) {
                            if (date("Y-m-d", strtotime($event->startdate)) == date("Y-m-d", strtotime($event->enddate))) {
                                echo date("F jS Y", strtotime($event->startdate)) . ' ' . date("g:i a", strtotime($event->startdate));
                            } else {
                                echo date("M jS", strtotime($event->startdate)) . ' - ' . date("M jS Y", strtotime($event->enddate)) . ' ' . date("g:i a", strtotime($event->startdate));
                            }
                            echo '<br>';
                        }

                        echo '<b>' . $event->eventname . '</b>';

                        if ($options['club_events_show_speakers_side_info'] == 1) {
                            if ($event->speaker != "") {
                                echo '<br><strong>Speaker: ' . $event->speaker . '</strong>';
                            }
                            if ($event->topic != "") {
                                echo '<br>Topic: ' . $event->topic;
                            }
                        }

                        if ($options['events_global_date'] == 0) {
                            echo '<br>';
                            if (date("Y-m-d", strtotime($event->startdate)) == date("Y-m-d", strtotime($event->enddate))) {
                                echo date("F jS Y", strtotime($event->startdate)) . ' ' . date("g:i a", strtotime($event->startdate));
                            } else {
                                echo date("M jS", strtotime($event->startdate)) . ' - ' . date("M jS Y", strtotime($event->enddate)) . ' ' . date("g:i a", strtotime($event->startdate));
                            }
                        }

                        echo '<br>';
                        echo '<a class="iframe2 cboxElement" href="' . $data_path . 'R_Event.cfm?EventID=' . $event->eventid . '" style="float:right;">More info</a>';
                        echo '<br>';
                        if ($count > $counter && $counter < $event_total) {
                            echo '<hr>';
                        }
                        $counter = $counter + 1;
                        echo '</div>';
                    }
                }
            }
            if ($event_total == 0) {
                echo 'There are no events at this time.';
            }
        }
        if (isset($show_d_events) && $show_d_events == 1) {

            if ($club_id == 0) {
                $categoryids = $options['district_events_types_page'];
                $mo = $options['district_events_months_side'];
            } else {
                $categoryids = $options['club_events_types_page'];
                $mo = $options['club_events_months_side'];
            }

            if ($fDebug) {
                $events = "";
                $events .= "=======================<BR>";
                $events .= "function widget show_d_events<br>";
                $events .= "AccountID=" . $options['dacdb_district'] . "<br>";
                $events .= "ClubID=" . $options['dacdb_club'] . "<br>";
                $events .= "Mo=" . $options['district_events_months'] . "<br>";
                $events .= "categoryids=" . $categoryids . "<br>";
                $events .= $data_path . 'wp_event.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&CatIDs=' . $categoryids . '&Mo=' . $mo . '<br />';
                $events .= "=======================<BR>";
                echo $events;
            }

            $xml = simplexml_load_file($data_path . 'wp_event.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&CatIDs=' . $categoryids . '&Mo=' . $mo . '&R=' . rand());
            //                if ( $options['district_events_types_side'] == '') {
            //                    $xml = simplexml_load_file($data_path.'wp_event.cfm?AccountID='.$options['dacdb_district'].'&ClubID='.$options['dacdb_club'].'&CatIDS,2,123&Mo='.$options['district_events_months_side'].'&R='.rand());
            //                } else {
            //                    $xml = simplexml_load_file($data_path.'wp_event.cfm?AccountID='.$options['dacdb_district'].'&ClubID='.$options['dacdb_club'].'&CatIDs='.$options['district_events_types_side'].'&Mo='.$options['district_events_months_side'].'&R='.rand());
            //                }
            $events = array();
            $counter = 1;
            $event_total = count($xml->event);
            foreach ($xml->event as $event) {
                if ($count >= $counter) {
                    echo '<div class="side-district-event" style="line-height:1.5;">';


                    if ($options['events_global_date'] == 1) {
                        if (date("Y-m-d", strtotime($event->startdate)) == date("Y-m-d", strtotime($event->enddate))) {
                            echo date("F jS Y", strtotime($event->startdate)) . ' ' . date("g:i a", strtotime($event->startdate));
                        } else {
                            echo date("M jS", strtotime($event->startdate)) . ' - ' . date("M jS Y", strtotime($event->enddate)) . ' ' . date("g:i a", strtotime($event->startdate));
                        }
                        echo '<br>';
                    }

                    echo '<b>' . $event->eventname . '</b>';

                    if ($options['events_global_date'] == 0) {
                        echo '<br>';
                        if (date("Y-m-d", strtotime($event->startdate)) == date("Y-m-d", strtotime($event->enddate))) {
                            echo date("F jS Y", strtotime($event->startdate));
                        } else {
                            echo date("M jS", strtotime($event->startdate)) . ' - ' . date("M jS Y", strtotime($event->enddate));
                        }
                    }
                    echo '<br>';
                    echo '<a class="iframe2 cboxElement" href="' . $data_path . 'R_Event.cfm?EventID=' . $event->eventid . '" style="float:right;">More info</a>';
                    echo '<br>';
                    if ($count > $counter && $counter < $event_total) {
                        echo '<hr>';
                    }
                    echo '</div>';
                }
                $counter = $counter + 1;
            }
            if ($event_total == 0) {
                echo 'There are no events at this time.';
            }
        }

        if ($show_birthdays == 1) {

            if ($fDebug) {
                $events = "";
                $events .= "=======================<BR>";
                $events .= "function widget show_birthdays<br>";
                $events .= "AccountID=" . $options['dacdb_district'] . "<br>";
                $events .= "ClubID=" . $options['dacdb_club'] . "<br>";
                $events .= $data_path . 'wp_birthdays.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '<br />';
                $events .= "=======================<BR>";
                echo $events;
            }

            $xml = simplexml_load_file($data_path . 'wp_birthdays.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&R=' . rand());
            $birthdays = array();
            $birthday_total = count($xml->birthday);
            $counter = 1;
            echo '<div class="side-birthdays">';
            foreach ($xml->birthday as $birthday) {
                echo '<div style=""><b>' . $birthday->membername . '</b><br>' . $birthday->birthday . '<br><br></div>';
                if ($counter < $birthday_total) {
                    echo '<hr>';
                }
                $counter = $counter + 1;
            }
            if ($birthday_total == 0) {
                echo 'There are no upcoming birthdays at this time.';
            }
            echo '</div>';
        }
        if ($show_leaders == 1) {

            if ($fDebug) {
                $events = "";
                $events .= "=======================<BR>";
                $events .= "function widget show_leaders<br>";
                $events .= "AccountID=" . $options['dacdb_district'] . "<br>";
                $events .= $data_path . 'wp_leaders.cfm?AccountID=' . $options['dacdb_district'] . '<br />';
                $events .= "=======================<BR>";
                echo $events;
            }

            if (!$club_id) {
                $club_id = $options['dacdb_club'];
            }

            echo '<div class="side-leaders">';
            if ($options['dacdb_club'] == 0) {
                $xml = simplexml_load_file($data_path . 'wp_leaders.cfm?AccountID=' . $options['dacdb_district'] . '&R=' . rand());
                $leaders = array();
                $counter = 1;
                $leader_total = count($xml->leader);
                foreach ($xml->leader as $leader) {
                    echo '<div class="row col-1-1" style="overflow:hidden;margin-bottom:20px;">';
                    echo '<div style="width:60px;float:left;"><img src="' . $leader->imgpath . '' . $leader->image . '" width="50"></div>';
                    echo '<div style=""><b><a class="iframe cboxElement" href="' . $data_path . 'R_Emailer.cfm?UserID=' . $leader->userid . '">' . $leader->username . '</a></b><br>' . $leader->clubposition . '</div>';
                    echo '</div>';
                }
                if ($leader_total == 0) {
                    echo 'There are no leaders to display at this time.';
                }
            } else {
                $xml = simplexml_load_file($data_path . 'wp_leaders.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $club_id . '&R=' . rand());
                $leaders = array();
                $counter = 1;
                $leader_total = count($xml->leader);
                foreach ($xml->leader as $leader) {
                    echo '<div class="row col-1-1" style="overflow:hidden;margin-bottom:20px;">';
                    echo '<div style="width:60px;float:left;"><img src="' . $leader->imgpath . '' . $leader->image . '" width="50"></div>';
                    echo '<div style=""><b><a class="iframe cboxElement" href="' . $data_path . 'R_Emailer.cfm?UserID=' . $leader->userid . '">' . $leader->username . '</a></b><br>' . $leader->clubposition . '</div>';
                    echo '</div>';
                }
                if ($leader_total == 0) {
                    echo 'There are no leaders to display at this time.';
                }
            }
            echo '</div>';
        }
        if ($show_newsletters == 1) {

            $count = $options['newsletters_weeks_widget'];

            if ($fDebug) {
                $newsletters = "";
                $newsletters .= "=======================<BR>";
                $newsletters .= "function widget show_newsletters<br>";
                $newsletters .= "AccountID=" . $options['dacdb_district'] . "<br>";
                $newsletters .= "ClubID=" . $options['dacdb_club'] . "<br>";
                $newsletters .= "ClubID=" . $options['dacdb_club'] . "<br>";
                $newsletters .= $data_path . 'wp_newsletters.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&Weeks=' . $options['newsletters_weeks_widget'] . '<br />';
                $newsletters .= "=======================<BR>";
                echo $newsletters;
            }

            $xml = simplexml_load_file($data_path . 'wp_newsletters.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&Weeks=' . $options['newsletters_weeks_widget'] . '&R=' . rand());

            $newsletters = array();
            $counter = 1;
            $newsletter_total = count($xml->newsletter);
            echo '<div class="side-newsletters">';
            foreach ($xml->newsletter as $newsletter) {
                if ($counter <= $count) {
                    echo '<span class="side-newsletters-link"><a href="' . $newsletter->path . '" target="new">' . $newsletter->name . '</a> </span>';
                    echo '<span class="pull-right" style="float:right;">' . $newsletter->datelastmodified . '</span>';
                    echo '<hr>';
                }
                $counter = $counter + 1;
            }
            if ($newsletter_total == 0) {
                echo 'There are no newsletters to display at this time.';
            }
            echo '</div>';
        }

        if ($show_speakers == 1) {

            if ($fDebug) {
                $speakers = "";
                $speakers .= "=======================<BR>";
                $speakers .= "function widget show_speakers<br>";
                $speakers .= "AccountID=" . $options['dacdb_district'] . "<br>";
                $speakers .= "ClubID=" . $options['dacdb_club'] . "<br>";
                $speakers .= "CatIDs=" . $options['speaker_cats'] . "<br>";
                $speakers .= $data_path . 'wp_speakers.cfm?AccountID=' . $options['dacdb_district'] . '&Mo=' . $options['speakers_months'] . '&CatIDs=' . $options['speaker_cats'] . '&ClubID=' . $options['dacdb_club'] . '<br/>';
                $speakers .= "=======================<BR>";
                echo $events;
            }

            $xml = simplexml_load_file($data_path . 'wp_speakers.cfm?AccountID=' . $options['dacdb_district'] . '&Mo=' . $options['speakers_months'] . '&CatIDs=' . $options['speaker_cats'] . '&ClubID=' . $options['dacdb_club'] . '&R=' . rand());
            $speakers = array();
            $speaker_counter = 1;
            foreach ($xml->speakerinfo as $speakerinfo) {
                if ($count >= $speaker_counter) {
                    echo '<div class="side-speakers" style="line-height:1.5;">';

                    if ($options['events_global_date'] == 1) {
                        echo '' . date("M jS Y", strtotime($speakerinfo->eventdate)) . ' ' . date("g:i a", strtotime($speakerinfo->eventdate));
                        echo '<br>';
                    }
                    if ($speakerinfo->speaker != '')
                        echo '<b>' . $speakerinfo->speaker . '</b><br />';
                    if ($speakerinfo->topic != '')
                        echo $speakerinfo->topic . '<br/>';


                    if ($options['events_global_date'] == 0) {
                        echo '' . date("M jS Y", strtotime($speakerinfo->eventdate)) . ' ' . date("g:i a", strtotime($speakerinfo->eventdate)) . '<br />';
                    }
                    echo '<a class="iframe cboxElement" href="' . $data_path . 'R_Event.cfm?EventID=' . $speakerinfo->eventid . '" style="float:right;">More info</a><br />';
                    if ($count > $speaker_counter) {
                        echo '<hr>';
                    }
                    $speaker_counter = $speaker_counter + 1;
                    echo '</div>';
                }
            }
            $speakerinfo_total = count($xml->speakerinfo);
            if ($speakerinfo_total == 0) {
                echo '<div class="side-speakers">';
                echo 'There are no speakers at this time.';
                echo '</div">';
            }
        }

        if ($show_sponsors == 1) {

            if ($fDebug) {
                $sponsors = "";
                $sponsors .= "=======================<BR>";
                $sponsors .= "function widget show_sponsors<br>";
                $sponsors .= "AccountID=" . $options['dacdb_district'] . "<br>";
                $sponsors .= "ClubID=" . $options['dacdb_club'] . "<br>";
                $sponsors .= $data_path . 'wp_sponsor.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '<br />';
                $sponsors .= "=======================<BR>";
                echo $sponsors;
            }

            $xml = simplexml_load_file($data_path . 'wp_sponsor.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&R=' . rand());
            $sponsors = array();
            $counter = 1;
            foreach ($xml->sponsor as $sponsor) {
                echo '<div><center>';
                echo '<a href="' . $sponsor->website . '" target="_blank"><img src="' . $sponsor->imagepath . '' . $sponsor->image . '"></a><br><br>';
                echo '</center></div>';
                $counter = $counter + 1;
            }
            //echo '<small>Click on browser refresh tab to see more sponsors</small>';
            $sponsor_total = count($xml->sponsor);
            if ($sponsor_total == 0) {
                echo '<div class="side-sponsors">';
                echo 'There are no sponsors to display at this time.';
                echo '</div>';
            }
        }
        echo $args['after_widget'];
    }

    // Widget Backend
    public function form($instance)
    {
        if (isset($instance['title'])) {
            $options = get_option('dacdb_plus_options', array());
            $title = $instance['title'];
            $show = $instance['show'];
            $club_id = $instance['club_id'];
            $count = $instance['count'];
        } else {
            $options = get_option('dacdb_plus_options', array());
            $title = __('', 'dacdb_plus_widget');
        }
    ?>
        <p>
            <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($title); ?>">
            <label for="<?php echo $this->get_field_id('club_id'); ?>"><?php _e('^Club ID:'); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id('club_id'); ?>" name="<?php echo $this->get_field_name('club_id'); ?>" value="<?php echo esc_attr($club_id); ?>">
            <label for="<?php echo $this->get_field_id('show'); ?>"><?php _e('Show:'); ?></label>
            <select class="widefat" id="<?php echo $this->get_field_id('show'); ?>" name="<?php echo $this->get_field_name('show'); ?>">
                <option value="<?php echo $show; ?>">
                    <?php if ($show == '1') {
                        echo 'Meeting Info';
                    } elseif ($show == '2') {
                        echo 'Events';
                    } elseif ($show == '3') {
                        echo 'District Events';
                    } elseif ($show == '4') {
                        echo 'Birthdays';
                    } elseif ($show == '5') {
                        echo 'Leadership';
                    } elseif ($show == '6') {
                        echo 'Newsletters';
                    } elseif ($show == '7') {
                        echo 'Speakers';
                    } elseif ($show == '8') {
                        echo 'Sponsors';
                    } else {
                        echo 'Select One';
                    } ?></option>
                <?php if ($options['dacdb_club'] == 0) { ?>
                    <option value="3">*District Events</option>
                    <option value="6">*Newsletters</option>
                    <option value="7">*Speakers</option>
                    <option value="8">Sponsors</option>
                <?php } else { ?>
                    <option value="1">^ Meeting Info</option>
                    <option value="5">^ Leadership</option>
                    <option value="4">Birthdays</option>
                    <option value="8">^ Sponsors</option>
                    <option value="2">*^ Events</option>
                    <option value="3">*District Events</option>
                    <option value="6">*Newsletters</option>
                    <option value="7">*Speakers</option>
                <?php } ?>
            </select>
            <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('*Number of items to display:'); ?></label>
            <select class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>">
                <option></option>
                <option value="1" <?php if ($count == '1') {
                                        echo 'selected';
                                    } ?>>1</option>
                <option value="2" <?php if ($count == '2') {
                                        echo 'selected';
                                    } ?>>2</option>
                <option value="3" <?php if ($count == '3') {
                                        echo 'selected';
                                    } ?>>3</option>
                <option value="4" <?php if ($count == '4') {
                                        echo 'selected';
                                    } ?>>4</option>
                <option value="5" <?php if ($count == '5') {
                                        echo 'selected';
                                    } ?>>5</option>
                <option value="6" <?php if ($count == '6') {
                                        echo 'selected';
                                    } ?>>6</option>
                <option value="7" <?php if ($count == '7') {
                                        echo 'selected';
                                    } ?>>7</option>
                <option value="8" <?php if ($count == '8') {
                                        echo 'selected';
                                    } ?>>8</option>
                <option value="9" <?php if ($count == '9') {
                                        echo 'selected';
                                    } ?>>9</option>
                <option value="10" <?php if ($count == '10') {
                                        echo 'selected';
                                    } ?>>10</option>
                <option value="11" <?php if ($count == '11') {
                                        echo 'selected';
                                    } ?>>11</option>
                <option value="12" <?php if ($count == '12') {
                                        echo 'selected';
                                    } ?>>12</option>
                <option value="13" <?php if ($count == '13') {
                                        echo 'selected';
                                    } ?>>13</option>
                <option value="14" <?php if ($count == '14') {
                                        echo 'selected';
                                    } ?>>14</option>
                <option value="15" <?php if ($count == '15') {
                                        echo 'selected';
                                    } ?>>15</option>
                <option value="16" <?php if ($count == '16') {
                                        echo 'selected';
                                    } ?>>16</option>
                <option value="17" <?php if ($count == '17') {
                                        echo 'selected';
                                    } ?>>17</option>
                <option value="18" <?php if ($count == '18') {
                                        echo 'selected';
                                    } ?>>18</option>
                <option value="19" <?php if ($count == '19') {
                                        echo 'selected';
                                    } ?>>19</option>
                <option value="20" <?php if ($count == '20') {
                                        echo 'selected';
                                    } ?>>20</option>
            </select>
        </p>
<?php
    }
    // Updating widget replacing old instances with new
    public function update($new_instance, $old_instance)
    {
        $instance = array();
        $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
        $instance['show'] = (!empty($new_instance['show'])) ? strip_tags($new_instance['show']) : '';
        $instance['count'] = (!empty($new_instance['count'])) ? strip_tags($new_instance['count']) : '';
        $instance['club_id'] = (!empty($new_instance['club_id'])) ? strip_tags($new_instance['club_id']) : '';
        return $instance;
    }
}

//SECTION - Display Functions

function dacdb_SMIcons($share, $smstyle, $smOpt, $StoryID, $title)
{
	global $fDebug, $data_path, $file_path, $public_path, $options;

	$url = $public_path . 'sms.cfm?StoryID='. $StoryID;

	$icons = '';
    switch ($smstyle) {
		case '1':   		// 1-dropdown
		case 'dropdown':    // 1-dropdown
				$icons .= '<div class="dropdown" style="width: 80px;">';
				$icons .= '	<button class="dropbtn">Share <i class="fa-regular fa-circle-caret-down"></i></button>';
				$icons .= '		<div class="dropdown-content">';
					if ( strpos ($smOpt,'FB') >= 0) {
						$icons .= '<a href="https://www.facebook.com/sharer/sharer.php?u='.$url.'&amp;display=popup&amp;t='.$title.'&amp;" class="fa-brands fa-facebook facebook linear" style=" font-size: 10px !important;"> Facebook</a>';
					}
					if ( strpos ($smOpt,'TW') >= 0) {
						$icons .= '<a href="https://twitter.com/intent/tweet?text='.$url.'&amp;text='.$title.'" class="fa-brands fa-twitter twitter linear" style=" font-size: 10px !important;"> Twitter</a>';
					}
					if ( strpos ($smOpt,'LI') >= 0) {
						$icons .= '<a href="https://www.linkedin.com/shareArticle?mini=true&amp;url='.$url.'&amp;title='.$title.'" class="fa-brands fa-linkedin linkedin linear" style=" font-size: 10px !important;"> Linkedin</a>';
					}
					if ( strpos ($smOpt,'TU') >= 0) {
						$icons .= '<a href="https://www.tumblr.com/share?v=3&amp;u='.$url.'&amp;t='.$title.'" class="fa-brands fa-tumblr tumblr linear" style=" font-size: 10px !important;"> Tumblr</a>';
					}
					if ( strpos ($smOpt,'RE') >= 0) {
						$icons .= '<a href="http://www.reddit.com/submit?url='.$url.'&amp;title='.$title.'" class="fa-brands fa-reddit reddit linear" style=" font-size: 10px !important;"> Reddit</a>';
					}
					if ( strpos ($smOpt,'PT') >= 0) {
						$icons .= '<a href="https://www.Pinterest.com/?url='.$url.'" class="fa-brands fa-pinterest pinterest linear" style=" font-size: 10px !important;"> Pinterest</a>';
					}
					if ( strpos ($smOpt,'PF') >= 0) {
						$icons .= '<a href="http://www.printfriendly.com/print?url='.$url.'&amp;title='.$title.'" class="fa-regular fa-print print linear" style=" font-size: 10px !important;"> PrintFriendly</a>';
					}
					if ( strpos ($smOpt,'EN') >= 0) {
						$icons .= '<a href="https://www.evernote.com/clip.action?url='.$url.'&amp;title='.$title.'" class="fa-brands fa-evernote evernote linear" style="font-size: 10px !important;"> EverNote</a>';
					}
					if ( strpos ($smOpt,'GO') >= 0) {
						$icons .= '<a href="https://plus.google.com/share?url='.$url.'&amp;title='.$title.'" class="fa-brands fa-google google linear" alt="Google" title="Google" style=" font-size: 10px !important;"> Google</a>';
					}
						$icons .= '</div>';
					$icons .= '</div>';
				break;
		case '2':   		// 2-ICONS
		case 'icons':   	// 2-ICONS
			if ( strpos ($smOpt,'FB') >= 0) {
				$icons .= '<a target="event" href="https://www.facebook.com/sharer/sharer.php?u='.$url.'&amp;display=popup&amp;t='.$title.'" rel="nofollow" alt="FaceBook" title="FaceBook"><span style="color: #3B5998 !important"><i class="fa-brands fa-facebook fa-2x"></i></span></a>&nbsp;';
			}
			if ( strpos ($smOpt,'TW') >= 0) {
				$icons .= '<a target="event" href="https://twitter.com/intent/tweet?text='.$url.'&amp;text='.$title.'"  alt="Twitter" title="Twitter" ><span style="color: #55ACEE !important"><i class="fa-brands fa-x-twitter fa-2x"></i></span></a>&nbsp;';
			}
			if ( strpos ($smOpt,'LI') >= 0) {
				$icons .= '<a target="event" href="https://www.linkedin.com/shareArticle?mini=true&amp;url='.$url.'&amp;title='.$title.'"   alt="LinkedIn" title="LinkedIn"><span style="color: #007bb5 !important"><i class="fa-brands fa-linkedin fa-2x"></i></span></a>&nbsp;';
			}
			if ( strpos ($smOpt,'TU') >= 0) {
				$icons .= '<a target="event" href="https://www.tumblr.com/share?v=3&amp;u='.$url.'&amp;t='.$title.'"   alt="tumblr" title="Tumnlr"><span style="color: #2c4762 !important"><i class="fa-brands fa-tumblr fa-2x"></i></span></a>&nbsp;';
			}
			if ( strpos ($smOpt,'RE') >= 0) {
				$icons .= '<a target="event" href="http://www.reddit.com/submit?url='.$url.'&amp;title='.$title.'"   alt="Reddit" title="Reddit"><span style="color: #ff5700 !important"><i class="fa-brands fa-reddit fa-2x"></i></a>&nbsp;';
			}
			if ( strpos ($smOpt,'PT') >= 0) {
				$icons .= '<a target="event" href="https://www.Pinterest.com/?url='.$url.'"   alt="Pinterest" title="Pinterest" alt="ReddPinterestit" title="Pinterest"><span style="color: #cb2027 !important"><i class="fa-brands fa-pinterest fa-2x"></i></a>&nbsp;';
			}
			if ( strpos ($smOpt,'PF') >= 0) {
				$icons .= '<a target="event" href="http://www.printfriendly.com/print?url='.$url.'&amp;title='.$title.'"   alt="PrintFriendly" title="PrintFriendly"><span style="color: #75AA33 !important"><i class="fa-regular fa-print fa-2x"></i></a>&nbsp;';
			}
			if ( strpos ($smOpt,'EN') >= 0) {
				$icons .= '<a target="event" href="https://www.evernote.com/clip.action?url='.$url.'&amp;title='.$title.'" alt="EverNote" title="EverNote"> <span style="color: #FC4242 !important"><i class="fa-brands fa-evernote fa-2x"></i></a>&nbsp;';
			}
			if ( strpos ($smOpt,'GO') >= 0) {
				$icons .= '<a target="event" href="https://plus.google.com/share?url='.$url.'&amp;title='.$title.'" alt="Google" title="Google" <span style="color: #dd4b39 !important"><i class="fa-brands fa-google fa-2x"></i></span></a>';
			}
            break;
		case '3':    		// 3-Linear
		case 'linear':    	// 3-Linear
					if ( strpos ($smOpt,'FB') >= 0) {
						$icons .= '<a href="https://www.facebook.com/sharer/sharer.php?u='.$url.'&amp;display=popup&amp;t='.$title.'" alt="FaceBook" title="FaceBook" class="fa-brands fa-facebook facebook linear"></a>';
					}
					if ( strpos ($smOpt,'TW') >= 0) {
						$icons .= '<a href="https://twitter.com/intent/tweet?text='.$url.'&amp;text='.$title.'" alt="Twitter" title="Twitter" class="fa-brands fa-twitter twitter linear"></a>';
					}
					if ( strpos ($smOpt,'LI') >= 0) {
						$icons .= '<a href="https://www.linkedin.com/shareArticle?mini=true&amp;url='.$url.'&amp;title='.$title.'" alt="LinkedIn" title="LinkedIn" class="fa-brands fa-linkedin linkedin linear"></a>';
					}
					if ( strpos ($smOpt,'TU') >= 0) {
						$icons .= '<a href="https://www.tumblr.com/share?v=3&amp;u='.$url.'&amp;t='.$title.'" alt="tumblr" title="Tumnlr" class="fa-brands fa-tumblr tumblr linear"></a>';
					}
					if ( strpos ($smOpt,'RE') >= 0) {
						$icons .= '<a href="http://www.reddit.com/submit?url='.$url.'&amp;title='.$title.'" alt="Reddit" title="Reddit"class="fa-brands fa-reddit reddit linear"></a>';
					}
					if ( strpos ($smOpt,'PT') >= 0) {
						$icons .= '<a href="https://www.Pinterest.com/?url='.$url.'" alt="ReddPinterestit" title="Pinterest" class="fa-brands fa-pinterest pinterest linear"></a>';
					}
					if ( strpos ($smOpt,'PF') >= 0) {
						$icons .= '<a href="http://www.printfriendly.com/print?url='.$url.'&amp;title='.$title.'" alt="PrintFriendly" title="PrintFriendly" class="fa-regular fa-print print linear"></a>';
					}
					if ( strpos ($smOpt,'EN') >= 0) {
						$icons .= '<a href="https://www.evernote.com/clip.action?url='.$url.'&amp;title='.$title.'" alt="EverNote" title="EverNote" class="fa-brands fa-evernote evernote linear"></a>';
					}
					if ( strpos ($smOpt,'GO') >= 0) {
						$icons .= '<a href="https://plus.google.com/share?url='.$url.'&amp;title='.$title.'" alt="EveGooglerNote" title="Google" class="fa-brands fa-google google linear"></a>';
					}
					break;
		}
        return $icons;
}

//ANCHOR - Display Members
/**
 * Display member data in various styles
 *
 * @param SimpleXMLElement $xml    The XML data containing member information
 * @param int $style               The style to display the members, valid options are 0, 1, 3
 * @param array $atts              An associative array with keys 'cols' and 'pics' indicating the number of columns to display and whether to display pictures respectively
 *
 * @global bool $fDebug            A flag to indicate whether debug mode is on
 * @global string $data_path       A path used for data operations
 * @global string $file_path       A file path used for file operations
 * @global array $options          An array of options affecting the behavior and output of the function
 *
 * @return string                  An HTML string displaying member data
 */
function dacdb_DisplayMembers($xml, $style, $atts)
{
    global $fDebug, $data_path, $file_path, $options;

    // Initialize some variables
    $ldiv = "";
    $members = "";
    $cols = "1";
    $pics = "1";

    // Set defaults for 'cols' and 'pics' if not set
    if ($atts['cols'] == '')
        $atts['cols']  = 1;

    if ($atts['pics'] == '')
        $atts['pics']  = 1;

    // Add debug info if debug mode is enabled
    if ($fDebug) {
        $members .= "=================================================================<BR>";
        $members .= "function dacdb_DisplayMembers called<br>";
        $members .= "cols=" . $atts['cols'] . "<br>";
        $members .= "pics=" . $atts['pics'] . "<br>";
        $members .= "=================================================================<BR>";
    }

    // Display members based on the provided style
    switch ($style) {

        case '0':   // Test Mode
            foreach ($xml->club as $member) {
                echo $member->clubname . "<br/>";
                echo count($member->officers->officer) . "<br>";
                foreach ($member->officers->officer as $officer) {
                    echo $officer->username . "<br/>";
                }
            }
            break;

        case '1':    // d_leaders, leaders
            $members .= '<div class="dac-row">';
            foreach ($xml->dlc as $member) {
                // Additional code with further complexity omitted for brevity
                // You would continue to add explanatory comments here as necessary
            }
            $members .= '</div>'; //<!-- dac-row  -->
            return $members;
            break;

        case '3':   // Kees Flag Display
            $cnt = 0;
            $records = count($xml->leader);
            // Additional code with further complexity omitted for brevity
            // You would continue to add explanatory comments here as necessary
            return $members;
            break;

        default:
            $members .= "=================================================================<BR>";
            $members .= "&nbsp;&nbsp;&nbsp;Invalid style selected [" . $style . "]<BR>";
            $members .= "=================================================================<BR>";
            break;
    }
    return $members;
}

//ANCHOR - Display Club
/**
 * Displays club information based on the provided XML data.
 *
 * @param SimpleXMLElement $xml   The XML data containing club information.
 * @param int|string       $style The style of display to use (0, 1, 3).
 * @param array            $atts  Additional attributes for customization.
 *
 * @return string The generated HTML for displaying club information.
 */
function dacdb_DisplayClub($xml, $style, $atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $ldiv = "";
    $members = "";
    $counter = 1;

    // Set default values for optional attributes
    $cols = isset($atts['leaders_per_row']) ? $atts['leaders_per_row'] : 1;
    $leader_pics = isset($atts['leader_pics']) ? $atts['leader_pics'] : 1;
    $leaders_per_row = isset($atts['leaders_per_row']) ? $atts['leaders_per_row'] : 1;
    $flex = isset($atts['leader_pics']) ? $atts['leader_pics'] : 1;
    $thumbnail_width = isset($options['thumbnail_width']) && $options['thumbnail_width'] > 0 ? $options['thumbnail_width'] : (isset($atts['imgwidth']) && isset($atts['imgwidth']) > 0 ? $atts['imgwidth'] : 150);

    if ($fDebug) {
        // Debug information
        $members .= "=================================================================<BR>";
        $members .= "function dacdb_DisplayClubs called 2<br>";
        $members .= "cols=" . $leaders_per_row . "<br>";
        $members .= "leader_pics=" . $leader_pics . "<br>";
        $members .= "flex=" . $flex . "<br>";
        $members .= "style=" . $style . "<br>";
        $members .= "cols=" . $cols . "<br>";
        $members .= "imgWidth=" . $thumbnail_width . "<br>";
        $members .= "Thumbnail Width =" . $options['thumbnail_width'] . "<br>";
        $members .= "=================================================================<BR>";
    }

    switch ($style) {

        case '0':   // Test Mode
            foreach ($xml->club as $club) {
                // Display club and officer information
                echo $club->clubname . "<br/>";
                echo count($club->officers->officer) . "<br>";
                foreach ($club->officers->officer as $officer) {
                    echo $officer->username . "<br/>";
                }
            }
            break;

        case '1': //  dacdb_leaders display Aligned Columns
            $setDivWidth = 160;
            $setImgWidth = 150;

            $div  = '<div class="col">';
            if ($cols == 1) {
                $div = '<div class="members dac-col-xs-12">';
                $setDivWidth = 155;
                $setImgWidth = 150;
            } else if ($cols == 2) {
                $div = '<div class="members dac-col-xs-12 dac-col-sm-6">';
                $setDivWidth = 140;
                $setImgWidth = 135;
            } else if ($cols == 3) {
                $div = '<div class="members dac-col-xs-12 dac-col-sm-12 dac-col-md-4">';
                $setDivWidth = 125;
                $setImgWidth = 120;
            } else if ($cols == 4) {
                $div = '<div class="members dac-col-xs-12 dac-col-sm-6 dac-col-md-3 dac-col-lg-3">';
                $setDivWidth = 110;
                $setImgWidth = 105;
            }

            $counter = 0;
            $records = count($xml->club);

            foreach ($xml->club as $club) {
                if ($records > 1) {
                    // if more than one club, show the club name
                    $members .= '<div class="dac-row">';
					$members .= $div;
                    $members .=   '<h4>' . $club->clubname . '</h4>';
					$members .= $div;
                    $members .= '</div>';
                }

                $members .= '<div class="dac-row">';
                foreach ($club->officers->officer as $officer) {
                    $members .= $div;  // members dac-col-xs-12 dac-col-sm-6 dac-col-md-3 dac-col-lg-3
                    $members .= '<table border="0" cellpadding="0" cellspacing="0">';
                    $members .= '<tr>';
                    if ($leader_pics == 1) {
                        $members .=   '<td style="border:0 !important;vertical-align: top; padding:0; width:' . $setDivWidth . 'px;">';
                        if ($officer->image == '') {
                            $members .= '<div style="width:' . $setDivWidth . 'px;"><img src="' . plugins_url('img/no_image.jpg', __FILE__) . '" style="aspect-ratio: 4 / 5; width: ' . $setImgWidth  . 'px; object-fit: cover;" width="' . $setImgWidth  . '"></div>';
                        } else {
                            $members .= '<div style="width:' . $setDivWidth . 'px;"><img src="' . $officer->image . '" style="aspect-ratio: 4 / 5; width: ' . $setImgWidth . '; object-fit: cover;"  width="' . $setImgWidth . '"></div>';
                        }
                        $members .=   '</td>';
                    }
                    $members .=   '<td style="border:0 !important; text-align: left; vertical-align: top; padding:0;">';
                    $members .=       '<b>' . $officer->membername . '</b><BR>';
                    $members .=    $officer->clubposition . '<BR>';
                    if ($options['leaders_contact_link'] == 1) {
                        $members .= '<a href="' . $data_path . 'R_Emailer.cfm?UserID=' . $officer->userid . '" name="dlc-inline-link-' . $counter . '" class="iframe3 cboxElement">Contact</a>';
                    }
                    $members .=   '</td>';
                    $members .= '</tr>';
                    $members .= '</table>';
                    $members .= '</div>';   // <div class="col">
                    $counter = $counter + 1;
                }
                $members .= '</div>';  // dac-row
            }

            $members .= '</div>'; // dac-cols...
            return $members;
            break;

        case '3':       //  New 2 colums
            $setDivWidth = 100;
            $setImgWidth = 95;
            $members .= '<div class="dac-row">';
            $members .= '<table border="5" cellpadding="3" cellspacing="0">';
            foreach ($xml->club as $club) {

                $members .= '<tr>';
                $members .= '<td valign="top" align="left" width="40%">';
                $members .= '<table border="1" cellpadding="3" cellspacing="0">';

                foreach ($club->officers->officer as $officer) {
                    $members .= '<tr>';
                    if ($atts['leader_pics'] == 1) {
                        $members .= '<td style="border:0 !important;vertical-align: top; padding:0; width:' . $setDivWidth . 'px;">';
                        if ($officer->image == '') {
                            $members .= '<div style="width:' . $setDivWidth . 'px;"><img src="' . plugins_url('img/no_image.jpg', __FILE__) . '" style="aspect-ratio: 4 / 5; width: ' . $setImgWidth . '; object-fit: cover;" width="' . $setImgWidth . '"></div>';
                        } else {
                            $members .= '<div style="width:' . $setDivWidth . 'px;"><img src="' . $officer->image . '" style="aspect-ratio: 4 / 5; width: ' . $setImgWidth . '; object-fit: cover;" width="' . $setImgWidth . '"></div>';
                        }
                        $members .= '</td>';
                    }
                    $members .= '<td style="border:0 !important; text-align: left; vertical-align: top; padding:0;">';
                    $members .= '<b>' . $officer->username . '</b><BR>';
                    $members .= $officer->clubposition . '<BR>';

                    if ($options['leaders_contact_link'] == 1) {
                        $members .= '<a href="' . $data_path . 'R_Emailer.cfm?UserID=' . $officer->userid . '" name="dlc-inline-link-' . $counter . '" class="iframe3 cboxElement">Contact</a>';
                    }

                    $members .= '</td>';
                    $members .= '</tr>';
                    $counter = $counter + 1;
                }
                $members .= '</table>';
                $members .= '</td>';
                $members .= '<td valign="top" width="60%">';
                $members .= '<a href="' . $club->cluburl . '" target="new"><b>' . $club->clubname . '</b></a><br>';
                $members .= '<i>' . $club->clubaddress . '<br>';
                if ($club->clubcity != '')
                    $members .= '' . $club->clubcity . ', ' . $club->clubstatecode . ' ' . $club->clubpostalzip . '</i><br>';
                else
                    $members .= '' . $club->clubstatecode . ' ' . $club->clubpostalzip . '</i><br>';
                $members .= '<b>Where We Meet </b><br>';
                $members .= '' . $club->meetingplace . '<br>';

                if ($club->meetingaddress != '') {
                    $members .= '' . $club->meetingaddress . '<br>';
                }
                if ($club->meetingcity != '')
                    $members .= '' . $club->meetingcity . ', ' . $club->meetingstatecode . ' ' . $club->meetingpostalcode . '<br>';
                else
                    $members .= '' . $club->meetingstatecode . ' ' . $club->meetingpostalcode . '<br>';

                $members .= '<b>When</b><br>';
                $members .= '' . $club->meetingday . ' at ' . $club->meetingtime . '';
                $members .= '<span style="float: right;"><a href="https://maps.google.com/maps?q=' . $club->latitude . ',' . $club->longitude . '" target="new">Map It</a></span>';
                $members .= '</td>';
                $members .= '</tr>';
                $members .= '<tr><td colspan="2"><hr style="margin:10px 0 5px 0;"></td></tr>';
            }
            $members .= '</table>';
            $members .= '</div>'; // <!-- dac-row -->

            break;
        default:
            $members .= "<div class=\"error-msg\"><i class=\"fa fa-times-circle\"></i>Invalid style selected: <pre>" . $style . "</pre></div>";

            break;
    }
    return $members;
}

//ANCHOR - DISTRICT EVENTS
/**
 * Fetches and formats district event data.
 *
 * This function fetches XML data from a remote service, parses that data, and
 * then formats it into a specific HTML structure for display. It handles both
 * district events and club events depending on the value of `$club_id`.
 *
 * @param array $atts An associative array of attributes.
 * @global bool $fDebug A flag indicating whether debugging is enabled.
 * @global string $data_path The base path or URL for data files.
 * @global string $file_path The base path or URL for other files.
 * @global array $options An associative array of options.
 *
 * @return string A string of formatted HTML representing the events.
 */
function dacdb_d_events($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $d_events = '';

    if ($club_id == 0) {
        $categoryids = $options['district_events_types_page'];
        $mo = $options['district_events_months'];
    } else {
        $categoryids = $options['club_events_types_page'];
        $mo = $options['club_events_months'];
    }

    if ($fDebug) {
        $events .= "=================================================================<BR>";
        $events .= "function dacdb_d_events called<br>";
        $events .= "AccountID=" . $options['dacdb_district'] . "<br>";
        $events .= "ClubID=" . $options['dacdb_club'] . "<br>";
        $events .= "Mo=" . $options['club_events_months'] . "<br>";
        $events .= "categoryids=" . $categoryids . "<br>";
        $events .= $data_path . 'wp_event.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $club_id . '&CatIDs=' . $categoryids . '&Mo=' . $mo . "<br>";
        $events .= "=================================================================<BR>";
    }

    $xml = simplexml_load_file($data_path . 'wp_event.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&CatIDs=' . $categoryids . '&Mo=' . $mo . '&R=' . rand());
    if (strlen($xml) == 0) {
        $events .= 'There are no events at this time.';
        return  $events;
    }

    $counter = 1;
    foreach ($xml->event as $event) {
        $d_events .= '<div class="dacdb_plus_d_event">';

        if ($options['events_global_date'] == 1) {
            if (date("Y-m-d", strtotime($event->startdate)) == date("Y-m-d", strtotime($event->enddate))) {
                $d_events .= date("F jS Y", strtotime($event->startdate)) . ' at ' . date("g:i a", strtotime($event->startdate));
            } else {
                $d_events .= date("F jS", strtotime($event->startdate)) . ' - ' . date("F jS Y", strtotime($event->enddate)) . ' at ' . date("g:i a", strtotime($event->startdate));
            }
            $d_events .= '<br>';
        }
        $d_events .= '<strong>' . $event->eventname . '</strong>';
        if ($event->eventreg == 'Y') {
            // $d_events .= '<br><small>Requires Registration</small>';
        }
        if ($options['events_global_date'] == 0) {
            $d_events .= '<br>';
            if (date("Y-m-d", strtotime($event->startdate)) == date("Y-m-d", strtotime($event->enddate))) {
                $d_events .= date("F jS Y", strtotime($event->startdate));
            } else {
                $d_events .= date("F jS", strtotime($event->startdate)) . ' - ' . date("F jS Y", strtotime($event->enddate));
            }
        }
        $d_events .= '<br>';
        // $d_events .= '<br>';
        // $d_events .= ''.$event->eventdesc.'';
        $d_events .= '<a class="iframe cboxElement" href="' . $data_path . 'R_Event.cfm?EventID=' . $event->eventid . '">More info</a>';
        $d_events .= '<br></div>';
        $d_events .= '<hr class="dacdb_plus_d_event_hr">';
        $counter = $counter + 1;
    }
    $event_total = count($xml->event);
    if ($event_total == 0) {
        $d_events .= 'There are no events at this time.';
    }
    return $d_events;
}
//!SECTION - Display Functions

//SECTION - Utility Functions

//ANCHOR - Round Down
/**
 * Rounds a number down to a specified precision level.
 *
 * @param float $number The number that needs to be rounded down.
 * @param int $precision (Optional) The number of decimal places to which the number should be rounded down. Default is 2.
 * @return float The rounded down number.
 */
function round_down($number, $precision = 2)
{
    $fig = (int) str_pad('1', $precision, '0');
    return (floor($number * $fig) / $fig);
}

//ANCHOR - Strip HTML
/**
 * Strips HTML tags from a string.
 *
 * @param string $tag The HTML tag or tags to be stripped. Multiple tags can be provided as a comma-separated string.
 * @param string $string The input string from which the HTML tags should be removed.
 * @return string The modified string with the specified HTML tags removed.
 */
function strip_html($tag, $string)
{
    $string = preg_replace('/<' . $tag . '[^>]*>/i', '', $string);
    $string = preg_replace('/<\/' . $tag . '>/i', '', $string);
    return $string;
}

//ANCHOR - File Size Convert
/**
 * Converts a file size in bytes to a more human-readable format.
 *
 * @param float $bytes The file size in bytes to be converted.
 * @return string The converted file size with the appropriate unit.
 */
function FileSizeConvert($bytes)
{
    $bytes = floatval($bytes);
    $arBytes = array(
        0 => array(
            "UNIT" => "TB",
            "VALUE" => pow(1024, 4)
        ),
        1 => array(
            "UNIT" => "GB",
            "VALUE" => pow(1024, 3)
        ),
        2 => array(
            "UNIT" => "MB",
            "VALUE" => pow(1024, 2)
        ),
        3 => array(
            "UNIT" => "KB",
            "VALUE" => 1024
        ),
        4 => array(
            "UNIT" => "B",
            "VALUE" => 1
        ),
    );
    foreach ($arBytes as $arItem) {
        if ($bytes >= $arItem["VALUE"]) {
            $result = $bytes / $arItem["VALUE"];
            $result = str_replace(".", ".", strval(round($result, 0))) . " " . $arItem["UNIT"];
            break;
        }
    }
    return $result;
}
//!SECTION - Utility Functions
