<?php 
function dacdb_birthdays($atts)
{
    global $fDebug, $data_path, $options;
    $options = get_mmp_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="' . MMPDB_PLUGIN_URL . 'img/avatar.svg" 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 .= '<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;
}