Copyright (c) 2008 Doba

  Released under the GNU General Public License
*/
require 'includes/application_top.php';
$downloaded = true;
require_once 'doba/DobaOrders.php';
require_once 'doba/DobaInteraction.php';
require_once 'doba/DobaLog.php';
include_once 'doba/DobaApi.php';
$api = new DobaApi();
$msg = '';
if (isset($_POST['ordergroup'])) {
    require_once 'doba/DobaOrderFile.php';
    $ordergroup = trim($_POST['ordergroup']);
    $objDobaOrders = DobaInteraction::loadOrders($ordergroup);
    $now = time();
    if ($_POST['act'] == 'download') {
        if (is_a($objDobaOrders, 'DobaOrders')) {
            $filename = 'orders_' . date('YmdHis', $now) . '.tab';
            // make this header replace previous headers
            header('Content-Type: application/octet-stream', true);
            header('Content-Disposition: attachment; ' . 'filename="' . $filename . '"');
            $objDobaOrderFile = new DobaOrderFile();
            $objDobaOrderFile->processData($objDobaOrders);
            if ($ordergroup == 'new') {
                DobaLog::logOrderDownload($objDobaOrders, $filename, $now);
            }
            exit;
        }
        $downloaded = false;