<?php 
function dacdb_birthdays($atts)
{
    global $fDebug, $data_path, $options;
    $options = get_mmp_options();

    // Enqueue the birthday styles
    wp_enqueue_style('dacdb-birthdays', MMPDB_PLUGIN_URL . 'css/show-birthdays.css', array(), MMPDB_PLUGIN_VERSION);

    $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 && dacdb_is_admin()) {
        $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>";
    }

    $birthdays_url = $data_path . 'wp_birthdays.cfm?AccountID=' . $options['dacdb_district'] . '&ClubID=' . $options['dacdb_club'] . '&R=' . rand();
    $xml = dacdb_load_xml($birthdays_url, 'birthdays');
    
    if ($xml === false || 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">';
        if ($birthday->image == '') {
            $members .= '<div class="birthday-image-container"><img class="birthday-image" src="' . MMPDB_PLUGIN_URL . 'img/avatar.svg" width="' . $thumbnail_width . '"></div>';
        } else {
            $members .= '<div class="birthday-image-container"><img class="birthday-image" src="' . $birthday->image . '" width="' . $thumbnail_width . '"></div>';
        }
        $members .= '<strong>' . $birthday->membername . '</strong><br>';
        if ($birthday->clubid == 0)
            $members .= $birthday->clubname . '<br />';
        $members .= $birthday->birthday . '<br>';
        $members .= '</div>';
        $counter = $counter + 1;
    }
    $members .= '</div>';
    return $members;
}