<?php 
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;"><strong><a href="' . $wcm->cluburl . '" target="new">' . $wcm->clubbadgename . '</a></strong>';
        } else {
            $meetings .= '<div style="width:200px;float:left;"><strong>' . $wcm->clubbadgename . '</strong>';
        }
        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;"><strong>Where: </strong> ' . $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 .=        '<strong>When:</strong> ' . $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;
}
