<?php
//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('admin_menu', array($this, 'add_plugin_page'));
        add_action('admin_init', array($this, 'page_init'));
        add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles_and_scripts'));
    }

    /**
     * Enqueues styles and scripts for admin pages using defined constants for paths.
     */
    public function enqueue_admin_styles_and_scripts()
    {
        // Admin Styles
        wp_enqueue_style('dacdb-admin-css', MMPDB_PLUGIN_URL . 'css/admin.css', array(), MMPDB_PLUGIN_VERSION);

        // Admin Scripts
        wp_enqueue_script('dacdb-admin-js', MMPDB_PLUGIN_URL . 'js/admin.js', array('jquery'), MMPDB_PLUGIN_VERSION, true);
    }

    public function add_plugin_page()
    {
        // This page will be under "Settings"
        add_options_page('Settings Admin', 'DACdb Plus', 'manage_options', 'mmp-settings', array($this, 'create_admin_page'));

        // Hook into the admin footer
        add_action('in_admin_footer', array($this, 'custom_admin_footer'));

        // Enqueue admin styles and scripts
        add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles_and_scripts'));
    }

    /**
     * Creates the admin page for the plugin.
     * Displays the plugin configuration settings and options.
     */
    public function create_admin_page()
    {

        // Set class property
        $this->options = get_mmp_options();
        ?>

        <div id="mmp-plugin-container" class="wrap">
            <div class="mmp-settings">
                <form method="post" action="options.php">
                    <div class="mmp-masthead">
                        <div class="logo-container">
                            <a href="https://memberminderpro.com" target="_blank"><img
                                    src="https://plus.dacdb.org/wp-content/uploads/2023/07/mmp-icon_512.png"
                                    title="Member Minder Pro — Powering DACdb and iMembersDB" alt="Logo"></a>
                        </div>
                        <div class="title-container">
                            <h1>DACdb<strong>Plus</strong> Settings <span
                                    style="font-size: 12px">v<?php echo MMPDB_PLUGIN_VERSION ?></span></h1>
                            <h2>Need help? Open a support ticket on <a href="https://www.dacdbsupport.com/new-ticket"
                                    title="Open a support ticket on DACdb" target="_blank"><strong>DAC</strong>db</a> or <a
                                    href="https://www.imemberssupport.com/new-ticket"
                                    title="Open a support ticket on iMembersDB" target="_blank">i<strong>Members</strong>db</a>.
                            </h2>

                        </div>
                        <div class="save-container">
                            <?php submit_button(); ?>
                        </div>
                    </div>


                    <?php
                    // This prints out all hidden setting fields
                    settings_fields('my_option_group');
                    do_settings_sections('mmp-settings');
                    submit_button();
                    ?>
                </form>
            </div>
            <script type="text/javascript">
                (function ($) {
                    $(document).ready(function () {
                        var domains = {
                            'dacdb': 'www.IsMyRotaryClub.org',
                            'imembersdb': 'www.eMembersDB.com'
                        };

                        function fetchAndDisplayData(apiDomain) {
                            j$.getJSON("https://" + apiDomain + "/wp_api_1-2/Lookup/EventCategory.cfm?AccountID=<?php echo $this->options['dacdb_district']; ?>", function (data, textStatus, jqxhr) {
                                var ids1 = '';
                                j$(".EventCatIDDiv").empty(); // Clear previous entries
                                for (var 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);
                            });

                            j$.getJSON("https://" + apiDomain + "/wp_api_1-2/Lookup/MemberType.cfm?AccountID=<?php echo $this->options['dacdb_district']; ?>", function (data, textStatus, jqxhr) {
                                var ids2 = '';
                                j$(".MemberTypeIDDiv").empty(); // Clear previous entries
                                for (var 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);
                            });
                        }

                        function updateApiDomain() {
                            var systemValue = j$('#dacdb_system').val().toLowerCase();
                            var apiDomain = domains[systemValue];
                            console.log('System:', systemValue); // Debugging line
                            console.log('API Domain:', apiDomain); // Debugging line
                            fetchAndDisplayData(apiDomain);
                        }

                        j$ = jQuery.noConflict();

                        // Set the initial domain and fetch data on page load
                        updateApiDomain();

                        // Update the domain and fetch data when the system select value changes
                        j$('#dacdb_system').change(updateApiDomain);
                    });
                })(jQuery);
            </script>
        </div>

        <?php
    }

    public function custom_admin_footer()
    {
        // Check if we are on the specific admin page
        $screen = get_current_screen();
        if ($screen->id === 'settings_page_mmp-settings') {
            // Output custom footer content
            echo '<div id="mmp-admin-footer">
            <p>Copyright &copy; 2003-' . date('Y') . ' <a href="https://memberminderpro.com/" target="_blank"><strong>Member Minder Pro, LLC</strong></a> — Powering <a href="https://www.dacdbsupport.com/new-ticket" title="Open a support ticket on DACdb" target="_blank"><strong>DAC</strong>db</a> &amp; <a href="https://www.imemberssupport.com/new-ticket" title="Open a support ticket on iMembersDB" target="_blank">i<strong>Members</strong>db</a></p>
                  </div>';
        }
    }

    //ANCHOR - Settings Sections and Fields
    /**
     * Register and add settings
     */
    public function page_init()
    {
        setDataPath();   // SHortCode DACdb or iMembersDB paths

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

        // Plugin Settings    ID               Title                   Callback                                    Page              Section
        add_settings_section('setting_section_main', 'Plugin Settings ', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('dacdb_district', 'Account/District #', array($this, 'dacdb_district_callback'), 'mmp-settings', 'setting_section_main');
        add_settings_field('dacdb_club', 'Club/Chapter/Region', array($this, 'dacdb_club_callback'), 'mmp-settings', 'setting_section_main');
        add_settings_field('dacdb_system', 'System', array($this, 'dacdb_system_callback'), 'mmp-settings', 'setting_section_main');

        // Third Party API/Widget Integration
        add_settings_section('setting_section_third_party_integration', 'Third Party API/Widget Integration', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('map_api', 'Google Maps API Key', array($this, 'map_api_callback'), 'mmp-settings', 'setting_section_third_party_integration');
        add_settings_field('ua_tracking_id', 'Google Analytics Tracking ID', array($this, 'ua_tracking_id_callback'), 'mmp-settings', 'setting_section_third_party_integration');
        add_settings_field('userway_data_account', '<a href="https://userway.org/" target="_blank" rel="noreferrer noopener">Userway.org</a> Data-Account', array($this, 'userway_widget_callback'), 'mmp-settings', 'setting_section_third_party_integration');

        // Story Settings
        add_settings_section('setting_section_stories', 'Story Settings', array($this, 'print_section_null'), 'mmp-settings');
        // add_settings_field('story_output', 'Output Style', array($this, 'story_output_callback'), 'mmp-settings', 'setting_section_stories');
        add_settings_field('story_summary', 'Story Summary', array($this, 'story_summary_callback'), 'mmp-settings', 'setting_section_stories');
        add_settings_field('story_sep', 'Story Separator', array($this, 'story_sep_callback'), 'mmp-settings', 'setting_section_stories');
        add_settings_field('story_image', 'Story Image Position', array($this, 'story_image_callback'), 'mmp-settings', 'setting_section_stories');
        add_settings_field('story_open', 'Read More Link', array($this, 'story_open_callback'), 'mmp-settings', 'setting_section_stories');
        add_settings_field('story_share', 'Email and Permalinks', array($this, 'story_share_callback'), 'mmp-settings', 'setting_section_stories');
        add_settings_field('story_social', 'Social Media Share', array($this, 'story_social_callback'), 'mmp-settings', 'setting_section_stories');
        add_settings_field('story_limit', 'Limit Stories', array($this, 'story_limit_callback'), 'mmp-settings', 'setting_section_stories');

        // Events Global Settings
        add_settings_section('setting_section_events_global', 'Events Global Settings', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('events_global_date', 'Show Date/Time First', array($this, 'events_global_date_callback'), 'mmp-settings', 'setting_section_events_global');
        // Club Events
        add_settings_section('setting_section_club_events', 'Club Event Settings for Pages and Widgets', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('club_events_months', 'Page - Months', array($this, 'club_events_months_callback'), 'mmp-settings', 'setting_section_club_events');
        add_settings_field('club_events_types_page', 'Page - Event CategoryIDs', array($this, 'club_events_types_page_callback'), 'mmp-settings', 'setting_section_club_events');
        add_settings_field('club_events_show_speakers', 'Page - Show Speakers', array($this, 'club_events_show_speakers_callback'), 'mmp-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'), 'mmp-settings', 'setting_section_club_events');
        add_settings_field('club_events_months_side', 'Widget - Months', array($this, 'club_events_months_side_callback'), 'mmp-settings', 'setting_section_club_events');
        add_settings_field('club_events_types_side', 'Widget - Event CategoryIDs', array($this, 'club_events_types_side_callback'), 'mmp-settings', 'setting_section_club_events');
        add_settings_field('club_events_show_speakers_side', 'Widget - Show Speakers', array($this, 'club_events_show_speakers_side_callback'), 'mmp-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'), 'mmp-settings', 'setting_section_club_events');

        // Account  Events
        add_settings_section('setting_section_district_events', 'Account Event Settings for Pages and Widgets', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('district_events_months', 'Page - Months', array($this, 'district_events_months_callback'), 'mmp-settings', 'setting_section_district_events');
        add_settings_field('district_events_types_page', 'Page - Event CategoryIDs', array($this, 'district_events_types_page_callback'), 'mmp-settings', 'setting_section_district_events');
        add_settings_field('district_events_months_side', 'Widget - Months', array($this, 'district_events_months_side_callback'), 'mmp-settings', 'setting_section_district_events');
        add_settings_field('district_events_types_side', 'Widget - Event CategoryIDs', array($this, 'district_events_types_side_callback'), 'mmp-settings', 'setting_section_district_events');

        // Event Speakers
        add_settings_section('setting_section_speakers', 'Event Speaker Settings', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('speakers_months', '# Months to Pull', array($this, 'speakers_months_callback'), 'mmp-settings', 'setting_section_speakers');
        add_settings_field('speaker_cats', 'Event Category IDs', array($this, 'speaker_cats_callback'), 'mmp-settings', 'setting_section_speakers');
        add_settings_field('speaker_page_full', 'Full Info On Page', array($this, 'speaker_page_full_callback'), 'mmp-settings', 'setting_section_speakers');

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

        // Club Presidents
        add_settings_section('setting_section_club_presidents', 'Club Presidents', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('club_presidents_per_row', 'Club Presidents Per Row', array($this, 'club_presidents_per_row_callback'), 'mmp-settings', 'setting_section_club_presidents');

        // District Leaders
        add_settings_section('setting_section_leaders', 'Account/District Leadership Settings', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('leaders_per_row', 'Leaders Per Row', array($this, 'leaders_per_row_callback'), 'mmp-settings', 'setting_section_leaders');
        add_settings_field('leader_pics', 'Show Leadership Pictures', array($this, 'leader_pics_callback'), 'mmp-settings', 'setting_section_leaders');
        add_settings_field('leaders_contact_link', 'Allow Leadership to be Contacted', array($this, 'leaders_contact_link_callback'), 'mmp-settings', 'setting_section_leaders');

        // Bulletins
        add_settings_section('setting_section_bulletins', 'Newsletter Settings for Pages and Widgets', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('newsletters_weeks_page', 'Page - # Weeks', array($this, 'newsletters_weeks_page_callback'), 'mmp-settings', 'setting_section_bulletins');
        add_settings_field('newsletters_show_folders_page', 'Page - Show Folders', array($this, 'newsletters_show_folders_page_callback'), 'mmp-settings', 'setting_section_bulletins');
        add_settings_field('newsletters_order_folders_page', 'Page - Order Folders', array($this, 'newsletters_order_folders_page_callback'), 'mmp-settings', 'setting_section_bulletins');
        add_settings_field('newsletters_weeks_widget', 'Widget - # Weeks', array($this, 'newsletters_weeks_widget_callback'), 'mmp-settings', 'setting_section_bulletins');


        // Commitee Global Settings
        add_settings_section('setting_section_committee_global', 'Commitee Settings', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('committee_global_name', 'Show Commitee Name', array($this, 'committee_global_name_callback'), 'mmp-settings', 'setting_section_committee_global');
        add_settings_field('committee_global_description', 'Show Commitee Description', array($this, 'committee_global_description_callback'), 'mmp-settings', 'setting_section_committee_global');
        add_settings_field('committee_show_members', 'Show Committee Members', array($this, 'committee_show_members_callback'), 'mmp-settings', 'setting_section_committee_global');
        // committee members
        add_settings_section('setting_section_committee_members', 'Committee Members Settings', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('committee_members_per_row', 'Committee Members Per Row', array($this, 'committee_members_per_row_callback'), 'mmp-settings', 'setting_section_committee_members');
        add_settings_field('committee_members_pics', 'Show Committee Members Pictures', array($this, 'committee_members_pics_callback'), 'mmp-settings', 'setting_section_committee_members');
        add_settings_field('committee_members_contact_link', 'Allow Committee Members to be Contacted', array($this, 'committee_members_contact_link_callback'), 'mmp-settings', 'setting_section_committee_members');
        add_settings_field('committee_members_committeeposition', 'Show Committee Member Position', array($this, 'committee_members_committeeposition_callback'), 'mmp-settings', 'setting_section_committee_members');
        add_settings_field('committee_members_busposition', 'Show Committee Member Business Position', array($this, 'committee_members_busposition_callback'), 'mmp-settings', 'setting_section_committee_members');
        add_settings_field('committee_members_classification', 'Show Committee Member Classification', array($this, 'committee_members_classification_callback'), 'mmp-settings', 'setting_section_committee_members');
        add_settings_field('committee_org_data', 'Organization Data Display', array($this, 'committee_org_data_callback'), 'mmp-settings', 'setting_section_committee_members');

        // Account Committee Chairs
        add_settings_section('setting_section_dcc', 'Account Committee Chairs', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field(
            'dcc_per_row',
            'DCC Per Row',
            array($this, 'dcc_per_row_callback'),
            'mmp-settings',
            'setting_section_dcc'
        );
        // College of GOVs
        add_settings_section('setting_section_cog', 'College of Governors', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('cog_per_row', 'COG Per Row', array($this, 'cog_per_row_callback'), 'mmp-settings', 'setting_section_cog');

        // Where Clubs Meet  -- Fold into Club Meetings!
        add_settings_section('setting_section_wcm', 'Where Clubs Meet', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('wcm_show_title', 'Show Page Title', array($this, 'wcm_show_title_callback'), 'mmp-settings', 'setting_section_wcm');
        add_settings_field('wcm_show_layout', 'Show Page Layout', array($this, 'wcm_show_layout_callback'), 'mmp-settings', 'setting_section_wcm');

        // Calendar
        add_settings_section('setting_calendar', 'Calendar Settings', array($this, 'print_section_null'), 'mmp-settings');
        add_settings_field('cal_display', 'Calendar Default View', array($this, 'cal_display_callback'), 'mmp-settings', 'setting_calendar');
        add_settings_field('cal_limit', 'Calendar Limit', array($this, 'cal_limit_callback'), 'mmp-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',
            'story_output_style' => 'absint',
            'story_summary' => 'absint',
            'story_sep' => 'absint',
            'story_image' => 'absint',
            'story_open' => 'absint',
            'story_share' => 'absint',
            'story_social' => 'absint',
            'story_limit' => 'absint',
            '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',
            'ua_tracking_id' => 'sanitize_text_field',
            'userway_data_account' => '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',
            'committee_show_members' => 'sanitize_text_field',
            'committee_org_data_entity' => 'absint',
            'committee_org_data_account' => 'absint',
            '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;
    }

    //SECTION - Callbacks for each setting field
    public function print_section_null()
    {
        //print '<hr>';
    }
    public function dacdb_district_callback()
    {
        printf(
            '<input type="text" id="dacdb_district" name="mmp_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="mmp_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="mmp_plus_options[dacdb_system]" required>';
        $html .= '<option value="DACdb"' . selected($dacdb_system, 'DACdb', false) . '>DACdb</option>';
        $html .= '<option value="iMembersDB"' . selected($dacdb_system, 'iMembersDB', false) . '>iMembersDB</option>';
        $html .= '</select><div class="description">Which <strong>Member Minder Pro</strong> system platform do you log into?</div>';

        echo $html;
    }
    public function story_output_callback()
    {
        $story_output_style = isset($this->options['story_output_style']) ? $this->options['story_output_style'] : '0';
        $html = '<select id="story_output_style" name="mmp_plus_options[story_output_style]">';
        $html .= '<option value="0"' . selected($story_output_style, '0', false) . '>Legacy';
        $html .= '<option value="1"' . selected($story_output_style, '1', false) . '>Modern';
        $html .= '</select>';
        echo $html;
    }
    public function story_summary_callback()
    {
        $html = '<div class="story_summary">';
        $html .= '<h4>How should your story summary appear when the full story is viewed?</h4>';

        // Concatenate the radio options to $html
        $html .= $this->create_radio_option('story_summary', 'story_content', 0, 'As story content', 'The summary will appear at the top as the first part of the total story content, such as a lead paragraph. The full story will continue naturally after.');
        $html .= $this->create_radio_option('story_summary', 'story_subhead', 1, 'As a subhead', 'The summary will be wrapped in an h2 tag and used as a subhead above the story.');
        $html .= $this->create_radio_option('story_summary', 'caption', 2, 'As an image caption', 'The summary will be used as a caption for the main image (the images saved with your story in EZ Stories). If no main image is attached to the story, nothing will appear.');
        $html .= $this->create_radio_option('story_summary', 'hidden', 3, 'Hidden', 'The summary will not appear in the full story view. It will still be visible on the story list and in metadata for SEO and social media sharing purposes.');

        $html .= '</div>';

        echo $html;
    }

    public function story_sep_callback()
    {
        $story_sep = $this->options['story_sep'] ?? '0';
        $styles = [
            '0' => 'Default: No style added',
            '1' => 'One: Gradient Line',
            '2' => 'Two: Dark Gradient Line',
            '3' => 'Three: Light Dashed Line',
            '4' => 'Four: Drop Shadow',
            '5' => 'Five: Blurred Shadow',
            '6' => 'Six: Embossed',
            '7' => 'Seven: Rounded Corners',
            '8' => 'Eight: Formal Document',
            '9' => 'Hidden'
        ];

        echo '<div class="story-separator-settings">';
        echo '<select id="story_sep" name="mmp_plus_options[story_sep]" onchange="getStoryval(this);">';
        foreach ($styles as $value => $class) {
            echo '<option value="' . $value . '"' . selected($story_sep, $value, false) . '>' . ($class ? $class : 'No styling added') . '</option>';
        }
        echo '</select><p>This sets a horizontal line between items in the stories list.</p>';

        echo '<div class="preview-area">';
        echo '<hr class="' . ($styles[$story_sep] ?? '') . '">';
        echo '</div>';
        echo '<p>To apply your own custom styles, select <strong>Default</strong> from the list above, then target the <code>.mmp-stories > article > hr.default</code> selector in your custom css.</p>';
        echo '</div>';
    }
    public function story_image_callback()
    {
        $story_image = isset($this->options['story_image']) ? $this->options['story_image'] : '0';
        $html = '<select id="story_image" name="mmp_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()
    {
        $html = '<div class="story_open">';
        $html .= '<h4>How should your readers access your full story?</h4>';

        // Concatenate the radio options to $html
        $html .= $this->create_radio_option('story_open', 'expand_on_page', 0, 'Expand on page', 'Clicking "Read more" will expand the page to show the full version of the story immediately below the summary in the story list.');
        $html .= $this->create_radio_option('story_open', 'open_story', 1, 'Full page', 'Clicking "Read more" will reload the page with only the full version of the selected story loaded.');
        $html .= $this->create_radio_option('story_open', 'open_story_new_window', 2, 'New tab', 'As above, but in a new browser tab.');

        $html .= '</div>';

        echo $html;
    }
    public function story_share_callback()
    {
        $html = '<div class="story_share">';
        $html .= $this->create_toggle_switch('story_share', 'On (Permalink and Email sharing links are visible)', 'Off (Permalink and Email sharing links are hidden)', 'This selection controls whether the permalink and email share options are shown in each story header. <strong>NOTE:</strong> Including the permalink to each story increases both accessibility and SEO value for your website.');
        $html .= '</div>';

        echo $html;
    }
    public function story_social_callback()
    {
        $html = '<div class="story_social">';
        $html .= $this->create_toggle_switch('story_social', 'On (Social media sharing links are visible)', 'Off (Social media sharing links are hidden)', 'This selection controls whether the social media share links are shown in each story header. Individual social media platforms may be selected <em>per-story</em> in the EZStories editor on DACdb and iMembersDB.');
        $html .= '</div>';

        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="mmp_plus_options[story_limit]" value="' . $story_limit . '" size="3" maxlength="4" /><br><small>Default (0 or empty): Show all stories.</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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_plus_options[pagnationposition]">';
        $html .= '<option value="Left"' . selected($pagnationposition, 'Left', false) . '>Left</option>';
        $html .= '<option value="Center"' . selected($pagnationposition, 'Center', false) . '>Center</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="mmp_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 .= '<option value="Both"' . selected($pagnationposition_tb, 'Both', false) . '>Both</option>';
        $html .= '</select>';
        echo $html;
    }
    public function membertypes_callback()
    {
        $membertypes = isset($this->options['membertypes']) ? $this->options['membertypes'] : '';
        $html = '<input type="text" id="membertypes" name="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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="mmp_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 committee_org_data_callback()
    {
        $html = '<div class="committee_org_data">';
        $html .= '<h4>Organization Data Display Settings</h4>';

        // Entity/Club/Lodge toggle
        $html .= '<div class="toggle">';
        $html .= '<div class="switch">';
        $html .= '<input type="checkbox" id="committee_org_data_entity" name="mmp_plus_options[committee_org_data_entity]" value="1"' .
            checked($this->options['committee_org_data_entity'] ?? '0', '1', false) .
            ' data-true-label="Show Club/Entity/Lodge name" data-false-label="Hide Club/Entity/Lodge name">';
        $html .= '<label class="slider" for="committee_org_data_entity"></label>';
        $html .= '</div>';
        $html .= '<label class="option-label" id="label_committee_org_data_entity" for="committee_org_data_entity">' .
            ($this->options['committee_org_data_entity'] ?? '0' == '1' ? 'Show Club/Entity/Lodge name' : 'Hide Club/Entity/Lodge name') .
            '</label>';
        $html .= '</div>';
        $html .= '<div class="description">Controls whether the club/entity/lodge name is displayed on member cards.</div>';

        // Account/District/Grand Lodge toggle
        $html .= '<div class="toggle">';
        $html .= '<div class="switch">';
        $html .= '<input type="checkbox" id="committee_org_data_account" name="mmp_plus_options[committee_org_data_account]" value="1"' .
            checked($this->options['committee_org_data_account'] ?? '0', '1', false) .
            ' data-true-label="Show Account/District/Grand Lodge name" data-false-label="Hide Account/District/Grand Lodge name">';
        $html .= '<label class="slider" for="committee_org_data_account"></label>';
        $html .= '</div>';
        $html .= '<label class="option-label" id="label_committee_org_data_account" for="committee_org_data_account">' .
            ($this->options['committee_org_data_account'] ?? '0' == '1' ? 'Show Account/District/Grand Lodge name' : 'Hide Account/District/Grand Lodge name') .
            '</label>';
        $html .= '</div>';
        $html .= '<div class="description">Controls whether the account/district/grand lodge name is displayed on member cards.</div>';

        $html .= '</div>';
        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="mmp_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="mmp_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="mmp_plus_options[map_api]" value="' . $map_api . '" size="40" placeholder="Enter Google map API Key" /><br/>';
        echo $html;
    }

    public function ua_tracking_id_callback()
    {
        $ua_tracking_id = isset($this->options['ua_tracking_id']) ? $this->options['ua_tracking_id'] : '';
        $html = '<input type="text" id="ua_tracking_id" name="mmp_plus_options[ua_tracking_id]" value="' . $ua_tracking_id . '" size="40" placeholder="Enter Google Analytics UA Tracking ID" /><br/>';
        echo $html;
    }

    public function userway_widget_callback()
    {
        $userway_data_account = isset($this->options['userway_data_account']) ? $this->options['userway_data_account'] : '';
        $html = '<input type="text" id="userway_data_account" name="mmp_plus_options[userway_data_account]" value="' . $userway_data_account . '" size="40" placeholder="Userway.org Data-Account" /><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="mmp_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="mmp_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_show_members_callback()
    {
        $html = '<div class="committee_show_members">';
        $html .= '<h4>How should your committee members be displayed?</h4>';

        // Add each radio option using the existing create_radio_option helper
        $html .= $this->create_radio_option(
            'committee_show_members',
            'none',
            '0',
            'No members shown',
            'No members will be displayed at all and the button will be hidden.'
        );

        $html .= $this->create_radio_option(
            'committee_show_members',
            'leaders_only',
            '1',
            'Leaders only',
            'Only committee leaders (members with a committee position other than <em>Member</em>) will be displayed.'
        );

        $html .= $this->create_radio_option(
            'committee_show_members',
            'all_members',
            '2',
            'All members',
            'All members will be displayed.'
        );

        $html .= '</div>';
        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="mmp_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="mmp_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="mmp_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'], '9', 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="mmp_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="mmp_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 .= '<option value="address"' . selected($this->options['wcm_show_layout'], 'address', false) . '>Address</option>';
        $html .= '</select>';
        $html .= '<div class="description">Use Default if you\'re using sort in the shortcode.</div>';
        echo $html;
    }
    public function create_toggle_switch($option_key, $true_label, $false_label, $description = '')
    {
        // Make sure you are accessing the correct option and it's cast or compared properly
        $options = get_option('mmp_plus_options');
        $option_value = isset($options[$option_key]) && $options[$option_key] == '1' ? '1' : '0';

        $html = '<div class="toggle">';
        $html .= '<div class="switch">';
        $html .= '<input type="checkbox" id="' . $option_key . '" name="mmp_plus_options[' . $option_key . ']" value="1" ' .
            ($option_value === '1' ? 'checked' : '') . ' data-true-label="' . $true_label . '" data-false-label="' . $false_label . '">';
        $html .= '<label class="slider" for="' . $option_key . '"></label>';
        $html .= '</div>';
        $html .= '<label class="option-label" id="label_' . $option_key . '" for="' . $option_key . '">' . ($option_value === '1' ? $true_label : $false_label) . '</label>';
        $html .= '</div>';
        $html .= !empty($description) ? '<div class="description">' . $description . '</div>' : '';

        return $html;
    }

    public function create_radio_option($option_key, $display_option, $option_value, $option_label, $description = '')
    {
        $value = (isset($this->options[$option_key]) && $this->options[$option_key] != '0') ? $this->options[$option_key] : '0';
        $html = '<div class="item radio-group">';
        $html .= '<div class="button-container">';
        $html .= '<input id="' . $display_option . '" type="radio" name="mmp_plus_options[' . $option_key . ']" value="' . $option_value . '" ' . checked($value, $option_value, false) . '>';
        $html .= '<label for="' . $display_option . '">' . $option_label . '</label>';
        $html .= '</div>';
        $html .= !empty($description) ? '<p>' . $description . '</p>' : '';
        $html .= '</div>';

        return $html;
    }


    public function render_twitter_account_field()
    {
        $twitter_account = isset($this->options['twitter_account']) ? $this->options['twitter_account'] : '';
        $story_share = isset($this->options['story_share']) ? $this->options['story_share'] : '0';

        $html = '<div id="twitter_account_wrapper" style="margin-top: 10px;' . ($story_share === '1' ? '' : ' display: none;') . '">';
        $html .= '<label for="twitter_account">Twitter Account:</label>';
        $html .= '<input type="text" id="twitter_account" name="mmp_plus_options[twitter_account]" value="' . esc_attr($twitter_account) . '" />';
        $html .= '</div>';

        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();

    add_action('admin_init', 'check_dacdb_settings');

    function check_dacdb_settings()
    {
        if (!is_admin()) {
            return; // Exit if not in admin panel
        }

        // Get the current settings
        $options = get_option('dacdb_settings'); // Assuming 'dacdb_settings' is where your options are stored

        // Trigger the error messages function if any settings are missing
        if (empty($options['dacdb_district']) || empty($options['dacdb_club']) || empty($options['dacdb_system'])) {
            add_action('admin_notices', 'dacdb_missing_settings');
        }
    }

    function dacdb_missing_settings()
    {
        global $pagenow;
        $settings_url = admin_url('options-general.php?page=mmp-settings');
        $support_url = 'https://www.dacdbsupport.com';
        $messages = array();

        $options = get_mmp_options();

        // Check for valid district setting
        if (!isset($options['dacdb_district']) || !is_numeric($options['dacdb_district'])) {
            $messages[] = __('A valid district, grand lodge, or account number is required.', 'dacdbplus');
        }

        // Check for valid club setting
        if (!isset($options['dacdb_club']) || !is_numeric($options['dacdb_club'])) {
            $messages[] = __('A valid club, lodge, or entity number is required.', 'dacdbplus');
        }

        // Check for valid system selection
        if (empty($options['dacdb_system'])) {
            $messages[] = __('System selection is missing or invalid.', 'dacdbplus');
        }

        // Display errors if any
        if (!empty($messages)) {
            foreach ($messages as $error_message) {
                if ($pagenow !== 'options-general.php' || !isset($_GET['page']) || $_GET['page'] !== 'mmp-settings') {
                    printf(
                        '<div class="notice notice-error is-dismissible" style="display: flex; justify-content: space-between; align-items: center;">
                            <p style="margin: 0;"><span class="dashicons dashicons-warning"></span> <strong><a href="%s">DACdb Plus</a>:</strong> %s</p>
                            <div>
                                <a href="%s" class="button button-primary" style="margin: 10px;">%s</a>
                                <a href="%s" class="button button-secondary" style="margin: 10px 0;">%s</a>
                            </div>
                        </div>',
                        esc_url($settings_url),
                        esc_html($error_message),
                        esc_url($settings_url),
                        esc_html__('Go to Settings', 'dacdbplus'),
                        esc_url($support_url),
                        esc_html__('Get Support', 'dacdbplus')
                    );
                } else {
                    printf(
                        '<div class="notice notice-error is-dismissible">
                            <p><span class="dashicons dashicons-warning"></span> <strong>DACdb Plus:</strong> %s</p>
                        </div>',
                        esc_html($error_message)
                    );
                }
            }
        }
    }

    /**
     * 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)
    {
        global $options;
        $options = get_mmp_options();  // Added missing semicolon

        // Settings link
        $settings_link = '<a href="options-general.php?page=mmp-settings">Settings</a>';

        // Support link
        $dacdb_support_link = '<a href="https://www.dacdbsupport.com/" target="_mmpsupport">DACdb Support</a>';

        // Support link
        $imembersdb_support_link = '<a href="https://www.imemberssupport.com/new-ticket" target="_mmpsupport">iMembersDB Support</a>';

        if (empty($options['dacdb_system'])) {
            // Insert at specific positions: If there are no settings, insert the support link first
            array_splice($links, 0, 0, $settings_link);
            array_splice($links, 1, 0, $dacdb_support_link);
            array_splice($links, 2, 0, $imembersdb_support_link);
        } elseif ($options['dacdb_system'] == 'DACdb') {  // Corrected 'elsif' to 'elseif'
            // Insert at specific positions: If the system is DACdb, insert the support link first
            array_splice($links, 0, 0, $dacdb_support_link);
            array_splice($links, 1, 0, $settings_link);
        } elseif ($options['dacdb_system'] == 'iMembersDB') {  // Corrected 'elsif' to 'elseif'
            // Insert at specific positions: If the system is iMembersDB, insert the support link first
            array_splice($links, 0, 0, $imembersdb_support_link);
            array_splice($links, 1, 0, $settings_link);
        }

        return $links;
    }

    /**
     * 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');
}
