//echo $query_sql;
    do {
        $brewerFirstName = strtr($row_sql['brewerFirstName'], $html_remove);
        $brewerLastName = strtr($row_sql['brewerLastName'], $html_remove);
        $brewerAddress = strtr($row_sql['brewerAddress'], $html_remove);
        $brewerCity = strtr($row_sql['brewerCity'], $html_remove);
        if ($go == "tab") {
            $assignment = $row_sql['brewerNickname'];
        } else {
            $assignment = brewer_assignment($row_sql['uid'], "1");
        }
        if ($row_sql['brewerCountry'] == "United States") {
            $phone = format_phone_us($row_sql['brewerPhone1']);
        } else {
            $phone = $row_sql['brewerPhone1'];
        }
        $a[] = array($brewerFirstName, $brewerLastName, $brewerAddress, $brewerCity, $row_sql['brewerState'], $row_sql['brewerZip'], $row_sql['brewerCountry'], $phone, $row_sql['brewerEmail'], $row_sql['brewerClubs'], judge_entries($row_sql['uid'], 0), $assignment, $row_sql['brewerJudgeID'], str_replace(",", ", ", $row_sql['brewerJudgeRank']), style_convert($row_sql['brewerJudgeLikes'], '6'), style_convert($row_sql['brewerJudgeDislikes'], '6'));
    } while ($row_sql = mysql_fetch_assoc($sql));
    $filename = ltrim(filename($contest) . "_Participants" . filename($date) . $loc . $extension, "_");
    header('Content-type: application/x-msdownload');
    header('Content-Disposition: attachment;filename="' . $filename . '"');
    header('Pragma: no-cache');
    header('Expires: 0');
    $fp = fopen('php://output', 'w');
    foreach ($a as $fields) {
        fputcsv($fp, $fields, $separator);
    }
    fclose($fp);
} else {
    echo "<p>Not Available</p>";
}
         $output_datatables_body .= "<td class='dataList'>" . $display_rank;
         if ($row_brewer['brewerJudgeMead'] == "Y") {
             $output_datatables_body .= "<br />Certified Mead Judge";
         }
         if (!empty($bjcp_rank[1])) {
             $output_datatables_body .= designations($row_brewer['brewerJudgeRank'], $bjcp_rank[0]);
         }
         $output_datatables_body .= "</td>";
     }
     if ($filter == "judges") {
         $output_datatables_body .= "<td class='dataList'>" . rtrim($table_assign_judge, ",&nbsp;") . "</td>";
     }
     if ($filter == "stewards") {
         $output_datatables_body .= "<td class='dataList'>" . rtrim($table_assign_steward, ",&nbsp;") . "</td>";
     }
     $output_datatables_body .= "<td class='dataList'>" . judge_entries($row_brewer['uid'], 1) . "</td>";
 }
 $output_datatables_body .= "<td class='dataList' nowrap='nowrap'>" . date_created($row_brewer['uid'], $_SESSION['prefsDateFormat'], $_SESSION['prefsTimeFormat'], $_SESSION['prefsTimeZone'], $dbTable) . "</td>";
 if ($action != "print" && $dbTable == "default") {
     // build_action_link($icon,$base_url,$section,$go,$action,$filter,$id,$dbTable,$alt_title) {
     $output_datatables_add_link = build_action_link("book_add", $base_url, "brew", "entries", "add", $row_brewer['uid'], "default", "default", "Add an entry for " . $row_brewer['brewerFirstName'] . " " . $row_brewer['brewerLastName']);
     $output_datatables_edit_link = build_action_link("pencil", $base_url, "brewer", "admin", "edit", $row_brewer['uid'], $row_brewer['id'], $dbTable, "Edit the user record for " . $row_brewer['brewerFirstName'] . " " . $row_brewer['brewerLastName']);
     if ($row_brewer['brewerEmail'] != $_SESSION['loginUsername']) {
         $output_datatables_delete_link = build_action_link("bin_closed", $base_url, "admin", "participants", "delete", $row_brewer['uid'], $row_brewer['uid'], $brewer_db_table, "Are you sure you want to delete the participant " . $row_brewer['brewerFirstName'] . " " . $row_brewer['brewerLastName'] . "? ALL entries for this participant WILL BE DELETED as well. This cannot be undone.");
     } else {
         $output_datatables_delete_link = "<span class='icon'><img src='" . $base_url . "images/bin_closed_fade.png' title='You cannot delete yourself!'></span>";
     }
     if ($user_info[1] <= "1") {
         $change_icon = "lock_open";
     } else {
         $change_icon = "lock_edit";
         $output_datatables_body .= "<td>" . $display_rank;
         if ($row_brewer['brewerJudgeMead'] == "Y") {
             $output_datatables_body .= "<br />Certified Mead Judge";
         }
         if (!empty($bjcp_rank[1])) {
             $output_datatables_body .= designations($row_brewer['brewerJudgeRank'], $bjcp_rank[0]);
         }
         $output_datatables_body .= "</td>";
     }
     if ($filter == "judges") {
         $output_datatables_body .= "<td>" . rtrim($table_assign_judge, ",&nbsp;") . "</td>";
     }
     if ($filter == "stewards") {
         $output_datatables_body .= "<td>" . rtrim($table_assign_steward, ",&nbsp;") . "</td>";
     }
     $output_datatables_body .= "<td class=\"" . $output_hide_print . "\">" . judge_entries($row_brewer['uid'], 1) . "</td>";
 }
 $output_datatables_body .= "<td class=\"" . $output_hide_print . "\" data-sort='" . date_created_timestamp($row_brewer['uid'], $dbTable) . "'>" . date_created($row_brewer['uid'], $_SESSION['prefsDateFormat'], $_SESSION['prefsTimeFormat'], $_SESSION['prefsTimeZone'], $dbTable) . "</td>";
 if ($action != "print" && $dbTable == "default") {
     // build_action_link($icon,$base_url,$section,$go,$action,$filter,$id,$dbTable,$alt_title) {
     $output_datatables_add_link = build_action_link("fa-beer", $base_url, "brew", "entries", "add", $row_brewer['uid'], "default", "default", "Add an entry for " . $row_brewer['brewerFirstName'] . " " . $row_brewer['brewerLastName']);
     $output_datatables_edit_link = build_action_link("fa-pencil", $base_url, "brewer", "admin", "edit", $row_brewer['uid'], $row_brewer['id'], $dbTable, "Edit the user record for " . $row_brewer['brewerFirstName'] . " " . $row_brewer['brewerLastName']);
     if ($row_brewer['brewerEmail'] != $_SESSION['loginUsername']) {
         $output_datatables_delete_link = build_action_link("fa-trash-o", $base_url, "admin", "participants", "delete", $row_brewer['uid'], $row_brewer['uid'], $brewer_db_table, "Are you sure you want to delete the participant " . $row_brewer['brewerFirstName'] . " " . $row_brewer['brewerLastName'] . "? ALL entries for this participant WILL BE DELETED as well. This cannot be undone.");
     } else {
         $output_datatables_delete_link = "<span class=\"fa fa-trash-o text-muted\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"Silly, you cannot delete yourself, " . $_SESSION['brewerFirstName'] . "!\"></span>";
     }
     if ($row_brewer['brewerEmail'] != $_SESSION['loginUsername']) {
         $output_datatables_other_link = build_action_link("fa-lock", $base_url, "admin", "make_admin", "default", "default", $row_brewer['uid'], "default", "Change " . $row_brewer['brewerFirstName'] . " " . $row_brewer['brewerLastName'] . "&rsquo;s User Level");
     } else {
         $output_datatables_other_link = "<span class=\"fa fa-lock text-muted\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"You cannot change your own user level, " . $_SESSION['brewerFirstName'] . ".\"></span>";
                if ($filter == "judges" || $filter == "bos") {
                    $bjcp_rank = explode(",", $row_brewer['brewerJudgeRank']);
                    $display_rank = bjcp_rank($bjcp_rank[0], 1);
                    $output_datatables_body .= "<td class=\"hidden-xs hidden-sm\">" . strtoupper($row_brewer['brewerJudgeID']) . "</td>";
                    $output_datatables_body .= "<td>" . $display_rank;
                    if ($row_brewer['brewerJudgeMead'] == "Y") {
                        $output_datatables_body .= "<br /><em>Certified Mead Judge</em>";
                    }
                    if (!empty($bjcp_rank[1])) {
                        $output_datatables_body .= "<em>" . designations($row_brewer['brewerJudgeRank'], $bjcp_rank[0]) . "</em>";
                    }
                    $output_datatables_body .= "</td>";
                }
                if ($filter == "judges" || $filter == "stewards") {
                    $output_datatables_body .= "<td class=\"hidden-xs hidden-sm\">" . $output_location . "</td>";
                    $output_datatables_body .= "<td class=\"hidden-xs hidden-sm\">" . judge_entries($row_brewer['uid'], 1) . "</td>";
                }
                $output_datatables_body .= "</tr>";
            } while ($row_brewer = mysql_fetch_assoc($brewer));
        }
        // end if ($totalRows_brewer > 0)
    }
    // end if (($totalRows_brewer > 0) && ((($action == "update") && ($filter != "default") && ($bid != "default")) || ($action == "assign")))
}
// *****************************************************************************
// ---------------------- Add/Edit Judging Locations ---------------------------
// *****************************************************************************
if ($action == "add" || $action == "edit" || $section == "step5") {
    $output_add_edit = TRUE;
    if ($section == "step5") {
        $action = "add";
            $brewerCity = strtr($row_sql['brewerCity'], $html_remove);
            if ($row_sql['brewerCountry'] == "United States") {
                $phone = format_phone_us($row_sql['brewerPhone1']);
            } else {
                $phone = $row_sql['brewerPhone1'];
            }
        }
        $judge_avail = judge_steward_availability($row_sql['brewerJudgeLocation'], 2);
        $steward_avail = judge_steward_availability($row_sql['brewerStewardLocation'], 2);
        if ($filter == "judges" || $filter == "avail_judges") {
            $a[] = array($brewerFirstName, $brewerLastName, $row_sql['brewerEmail'], str_replace(",", ", ", $row_sql['brewerJudgeRank']), strtoupper(strtr($row_sql['brewerJudgeID'], $bjcp_num_replace)), $judge_avail, style_convert($row_sql['brewerJudgeLikes'], '6'), style_convert($row_sql['brewerJudgeDislikes'], '6'), judge_entries($row_sql['uid'], 0));
        } elseif ($filter == "stewards" || $filter == "avail_stewards") {
            $a[] = array($brewerFirstName, $brewerLastName, $row_sql['brewerEmail'], $steward_avail, judge_entries($row_sql['uid'], 0));
        } elseif ($filter == "staff") {
            $a[] = array($brewerFirstName, $brewerLastName, $row_sql['brewerEmail'], judge_entries($row_sql['uid'], 0));
        } else {
            $a[] = array($brewerFirstName, $brewerLastName, $row_sql['brewerEmail'], $brewerAddress, $brewerCity, $row_sql['brewerState'], $row_sql['brewerZip'], $row_sql['brewerCountry'], $phone, $row_sql['brewerClubs'], judge_entries($row_sql['uid'], 0));
        }
    } while ($row_sql = mysql_fetch_assoc($sql));
    header('Content-type: application/x-msdownload');
    header('Content-Disposition: attachment;filename="' . $filename . '"');
    header('Pragma: no-cache');
    header('Expires: 0');
    $fp = fopen('php://output', 'w');
    foreach ($a as $fields) {
        fputcsv($fp, $fields, $separator);
    }
    fclose($fp);
} else {
    echo "<p>Not available.</p>";
}