过滤器未在excel导出中应用

时间:2012-08-07 18:01:21

标签: php mysql

我有一个脚本根据用户输入过滤器(贷款人员,状态,排序等)输出数据,默认为“无过滤器”。当用户添加过滤器时,数据会按预期显示(过滤掉正确的记录),但是当用户将这些结果导出到Excel电子表格时,过滤器不会被应用并显示所有记录。

我做错了什么? (P.S.我没有写剧本,这就是为什么我有点迷路)

require_once('../../header.inc.php');

ob_end_clean();
header('Pragma: public');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Expires: 0"); // Date in the past
header("Content-Disposition: attachment; filename=download_" . date('Y_m_d_H_i_s') . ".csv");
header('Content-Transfer-Encoding: binary');
header("Content-type: application/vnd.ms-excel");

$DB = DB::getCon();
$filename = 'c:/php_temp/download_' . preg_replace('/[^a-z0-9]/i', '_', $DB->cleanString($_GET['custcodes'])) . '.csv';

$CSVExport = new CSVExport($filename);
//error_log(print_r($_GET,true));
if (isset($_GET['custcode']) &&
    isset($_GET['borrower']) &&
    isset($_GET['address']) &&
    isset($_GET['tax_search_loan_officer_id']) &&
    isset($_GET['loan_identifier'])
    ) {
    $sql = "
        SELECT
            tslo.pick_userid as website_userid,
            tsl.loan_identifier,
            tslo.name as loan_officer,
            tsl.tax_search_loan_id,
            tsl.branch,
            tsl.borrower,
            tsl.address,
            tsl.city,
            states.abbreviation as state_abbreviation,
            tsl.zip,
            tsl.parcel,
            tsl.block,
            tsl.lot,
            tsl.notes,
            tsr.delinquency_status,
            tsr.quarter_data,
            tsr.additional_info,
            tsr.liens,
            tsr.tax_sales,
        FROM
            tax_search_loans tsl
        LEFT JOIN
            tax_searches ts
        ON
            (tsl.tax_search_loan_id = ts.tax_search_loan_id)
        LEFT JOIN
            tax_search_results tsr
        ON
            (tsr.tax_search_id = ts.tax_search_id)
        LEFT JOIN
            states
        ON
            (tsl.state_id = states.state_id)
        LEFT JOIN
            tax_search_loan_officers tslo
        ON
            (tslo.tax_search_loan_officer_id = tsl.tax_search_loan_officer_id)
        WHERE
            tsl.active = 'Y' AND
            tslo.active = 'Y' AND
            tslo.customer_code IN ('" . implode("','", explode(',', $DB->cleanString($_GET['custcodes']))) . "') AND
            tsl.borrower = ($_GET['borrower']) AND
            (ts.active IS NULL OR ts.active = 'Y') AND
            (tsr.active IS NULL OR tsr.active = 'Y')
            ";
    if ('' != $_GET['borrower'])
        $sql .= "AND tsl.borrower like '%" . $DB->cleanString($_GET['borrower']) . "%' ";
    if ('' != $_GET['address'])
        $sql .= "AND tsl.address like '%" . $DB->cleanString($_GET['address']) . "%' ";
    if ('' != $_GET['loan_identifier'])
        $sql .= "AND tsl.loan_identifier like '%" . $DB->cleanString($_GET['loan_identifier']) . "%' ";
    if ('' != $_GET['tax_search_loan_officer_id'])
        $sql .= "AND tsl.tax_search_loan_officer_id like '%" . $DB->cleanString($_GET['tax_search_loan_officer_id']) . "%' ";
} elseif (isset($_GET['custcode']) &&
    isset($_GET['limit_by_status']) &&
    isset($_GET['tax_search_loan_officer_id']) &&
    isset($_GET['sort_by'])
    ) {

    $sql = "
        SELECT
            tslo.pick_userid as website_userid,
            tsl.loan_identifier,
            tslo.name as loan_officer,
            tsl.tax_search_loan_id,
            tsl.borrower,
            tsl.branch,
            tsl.address,
            tsl.city,
            states.abbreviation as state_abbreviation,
            tsl.zip,
            tsl.parcel,
            tsl.block,
            tsl.lot,
            tsl.notes,
            tsr.delinquency_status,
            tsr.quarter_data,
            tsr.additional_info,
            tsr.liens,
            tsr.tax_sales,
        FROM
            tax_search_loans tsl
        LEFT JOIN
            tax_searches ts
        ON
            (tsl.tax_search_loan_id = ts.tax_search_loan_id)
        LEFT JOIN
            tax_search_results tsr
        ON
            (tsr.tax_search_id = ts.tax_search_id)
        LEFT JOIN
            states
        ON
            (tsl.state_id = states.state_id)
        LEFT JOIN
            tax_search_loan_officers tslo
        ON
            (tslo.tax_search_loan_officer_id = tsl.tax_search_loan_officer_id)
        WHERE
            tsl.active = 'Y' AND
            tslo.active = 'Y' AND
            tslo.customer_code IN ('" . implode("','", explode(',', $DB->cleanString($_GET['custcodes']))) . "') AND
            tsl.borrower = ($_GET['borrower']) AND
            (ts.active IS NULL OR ts.active = 'Y') AND
            (tsr.active IS NULL OR tsr.active = 'Y')
            ";        
    if ('' != $_GET['limit_by_status']) {

        if ('current' == $_GET['limit_by_status'] || 'delinquent' == $_GET['limit_by_status']) {
            $sql .= "
                AND tsr.delinquency_status " . ('current' == $_GET['limit_by_status'] ? '' : "!") . "= 'Current'
                ";
        } else {
            $sql .= "
                AND tsr.tax_sales IS NOT NULL
                AND tsr.tax_sales != ''
                ";
        }
    }   
    if ('' != $_GET['tax_search_loan_officer_id']) {
        $sql .= "
            AND tsl.tax_search_loan_officer_id = '" . $DB->cleanString($_GET['tax_search_loan_officer_id']) . "'
            ";
    }    
    $sql .= "
        ORDER BY
            " . $DB->cleanString($_GET['sort_by']) . "
        ";    
} else {
    $sql = "
        SELECT
            tslo.pick_userid as website_userid,
            tsl.loan_identifier,
            tslo.name as loan_officer,
            tsl.tax_search_loan_id,
            tsl.borrower,
            tsl.branch,
            tsl.address,
            tsl.city,
            states.abbreviation as state_abbreviation,
            tsl.zip,
            tsl.parcel,
            tsl.block,
            tsl.lot,
            tsl.notes,
            tsr.delinquency_status,
            tsr.quarter_data,
            tsr.additional_info,
            tsr.liens,
            tsr.tax_sales,
        FROM
            tax_search_loans tsl
        LEFT JOIN
            tax_searches ts
        ON
            (tsl.tax_search_loan_id = ts.tax_search_loan_id)
        LEFT JOIN
            tax_search_results tsr
        ON
            (tsr.tax_search_id = ts.tax_search_id)
        LEFT JOIN
            states
        ON
            (tsl.state_id = states.state_id)
        LEFT JOIN
            tax_search_loan_officers tslo
        ON
            (tslo.tax_search_loan_officer_id = tsl.tax_search_loan_officer_id)
        WHERE
            tsl.active = 'Y' AND
            tslo.active = 'Y' AND
            tslo.customer_code IN ('" . implode("','", explode(',', $DB->cleanString($_GET['custcodes']))) . "') AND
            tsl.borrower = ($_GET['borrower']) AND
            (ts.active IS NULL OR ts.active = 'Y') AND
            (tsr.active IS NULL OR tsr.active = 'Y')
        ";
}
$rows = $DB->getRows($sql);
if (count($rows)) {
    // header row
    $CSVExport->writeHeader($rows[0]);
    $row_cnt = count($rows);
    enter code here
    // write data from the rest of the rows
    for ($i=0; $i < $row_cnt; $i++)
         $CSVExport->writeRow($rows[$i]);
}
unset($CSVExport); // closes the file handle
$output = file_get_contents($filename);
header('Content-length: ' . strlen($output));
echo $output;

0 个答案:

没有答案