<?php
/**
 * DACdb Plus Committee Leaders Display Function
 *
 * Retrieves and displays committee leadership information from DACdb based on specified role keys.
 * Supports multiple display styles and filtering by committee roles.
 *
 * @package    DACdbPlus
 * @subpackage Display
 * @author     Member Minder Pro, LLC
 * @link       https://memberminderpro.com
 * @since      1.0.0
 */

if (!defined('ABSPATH')) {
    exit;
}

/**
 * Display committee leaders based on specified attributes
 *
 * @param array $atts {
 *     Optional. Array of attributes for configuring the display.
 *
 *     @type string $style    Display style number (default: 1)
 *     @type string $rolekeys Committee role keys to filter by (default: 'DLT')
 * }
 * @return string HTML formatted string containing committee leader information
 */
function dacdb_committee_leaders($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    // SECTION: Initialize Variables
    $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 = '';

    // SECTION: Debug Output
    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>";
    }

    // SECTION: Data Retrieval
    $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;
    }

    // SECTION: Display Processing
    $cnt = 0;
    $records = count($xml->dlc);
    $members .= dacdb_DisplayMembers($xml, $style, $atts);    // Process display using specified style

    return $members;
}