} else {
    $eMon = 1;
}
if (isset($_GET['endY']) && oos_is_not_null($_GET['endY'])) {
    $eYear = $_GET['endY'];
    $endDateG = 1;
} else {
    $eYear = date("Y");
}
if ($endDateG) {
    $endDate = mktime(0, 0, 0, $eMon, $eDay + 1, $eYear);
} else {
    $endDate = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"));
}
require 'includes/classes/class_sales_report2.php';
$sr = new sales_report($srView, $startDate, $endDate, $srSort, $srStatus, $srFilter);
$startDate = $sr->startDate;
$endDate = $sr->endDate;
if ($srExp < 2) {
    // not for csv export
    ?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php 
    echo HTML_PARAMS;
    ?>
>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=<?php 
    echo CHARSET;
    ?>
">
}
/**/
if ($HTTP_GET_VARS['separator'] && smn_not_null($HTTP_GET_VARS['separator'])) {
    $srSeparator = $HTTP_GET_VARS['separator'];
}
if ($HTTP_GET_VARS['billing'] && smn_not_null($HTTP_GET_VARS['billing'])) {
    $srBilling = $HTTP_GET_VARS['billing'];
}
if ($HTTP_GET_VARS['delivery'] && smn_not_null($HTTP_GET_VARS['delivery'])) {
    $srDelivery = $HTTP_GET_VARS['delivery'];
}
if ($HTTP_GET_VARS['customer'] && smn_not_null($HTTP_GET_VARS['customer'])) {
    $srCustomer = $HTTP_GET_VARS['customer'];
}
require DIR_WS_CLASSES . FILENAME_ORDERS_TRACKING;
$sr = new sales_report($srView, $startDate, $endDate, $srSort, $srStatus, $srFilter);
$startDate = $sr->startDate;
$endDate = $sr->endDate;
if ($srExp == 2) {
    $file_created = $sr->DownloadFile($srStatus, $startDate, $endDate, $srDownload, $srCustomer, $srDelivery, $srSeparator, $srBilling);
    if ($file_created == 'true') {
        header('Content-type: application/x-octet-stream');
        header('Content-disposition: attachment; filename=orders.csv');
        readfile(DIR_FS_ADMIN . 'orders.csv');
        unlink(DIR_FS_ADMIN . 'orders.csv');
    }
} elseif ($srExp == 3) {
    $OrderFilterString = 'order by date, orders_id, store_id';
    $StatusFilterString = '';
    $file_created = $sr->DownloadOrdersFile($srStatus, $startDate, $endDate, $srDownload, $StatusFilterString, $OrderFilterString);
    if ($file_created == 'true') {
    $li_sort_order_a = $_GET['li_sort_order_a'] != '' ? $_GET['li_sort_order_a'] : false;
    $li_sort_b = $_GET['li_sort_b'] != '' ? $_GET['li_sort_b'] : false;
    $li_sort_order_b = $_GET['li_sort_order_b'] != '' ? $_GET['li_sort_order_b'] : false;
    $auto_print = $_GET['auto_print'] != '' ? true : false;
    $csv_header = $_GET['csv_header'] != '' ? true : false;
    // if any required field is empty, cancel the report and alert the user
    // JavaScript checks should usually catch these, this is "just in case"
    if (!$start_date || !$end_date || !$date_target || !$detail_level || !$output_format) {
        $messageStack->add_session(ERROR_MISSING_REQ_INFO . '<br />' . $_GET['start_date'] . '<br />' . $_GET['end_date'], 'error');
        zen_redirect(zen_href_link(FILENAME_STATS_SALES_REPORT, zen_get_all_get_params(array('output_format')), 'NONSSL'));
    }
    // build the report array
    if ($output_format != 'none') {
        require DIR_WS_CLASSES . 'sales_report.php';
        //  (* = required)
        $sr = new sales_report($timeframe, $start_date, $end_date, $date_target, $date_status, $payment_method, $current_status, $manufacturer, $detail_level, $output_format);
        //* how to display the results
        if ($output_format == 'csv') {
            mb_http_output('SJIS');
            ob_start('mb_output_handler');
            // we have to pass the sorting values of the form since
            // the class instantiation does not require them
            $sr->output_csv($csv_header, $timeframe_sort, $li_sort_a, $li_sort_order_a, $li_sort_b, $li_sort_order_b);
            exit;
        }
    }
    // END if ($output_format != 'none')
}
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php