}
    } else {
        # HEADER ROW
        $row = $rows[0];
        $csv_row = "";
        foreach ($row as $key => $value) {
            # Replace double quotes with two double quotes
            $csv_field = str_replace('"', '""', $key);
            $csv_row .= '"' . $csv_field . '",';
        }
        $csv .= substr($csv_row, 0, -1) . "" . NEWLINE;
        # DATA ROWS
        foreach ($rows as $row) {
            $csv_row = "";
            foreach ($row as $key => $value) {
                $csv_field = str_replace('"', '""', util_unhtmlentities(util_strip_html_tags($value)));
                $csv_row .= '"' . $csv_field . '",';
            }
            $csv .= substr($csv_row, 0, -1) . "" . NEWLINE;
        }
    }
    # OUTPUT
    header("Content-Type: text/csv");
    header("Content-Length: " . strlen($csv));
    header("Content-Disposition: attachment; filename=\"{$_GET['table']}.csv\"");
    echo $csv;
}
# ------------------------------------
# $Log: csv_export.php,v $
# Revision 1.5  2007/03/14 17:22:23  gth2
# adding additional varibable to filter function now that we've added priority
function html_FCKeditor($name, $width, $height, $value = "")
{
    # Set minimum height and width of the FCKeditor
    if ($width < 510) {
        $width = 510;
    }
    if ($height < 120) {
        $height = 120;
    }
    # if using FCKeditor
    if (session_use_FCKeditor()) {
        $FCKeditor = new FCKeditor($name);
        $FCKeditor->BasePath = FCK_EDITOR_BASEPATH;
        $FCKeditor->Config['SkinPath'] = $FCKeditor->BasePath . 'editor/skins/office2003/';
        $FCKeditor->ToolbarSet = "RTH";
        $FCKeditor->Width = $width . "px";
        $FCKeditor->Height = $height . "px";
        $FCKeditor->Value = $value;
        $FCKeditor->Create();
        # if not using FCKeditor
    } else {
        # work out number of rols and cols for the text area.
        # this is ~ 8 pixels per character and 20 pixels per row
        $cols = round($width / 8);
        $rows = round($height / 20);
        $value = util_strip_html_tags($value);
        print "<textarea rows={$rows} cols={$cols} name='{$name}'>{$value}</textarea>";
    }
}