}
}
// Order History
$history_block = '';
//DokuMan - 2010-09-18 - set undefined variable
$statuses_query = xtc_db_query("-- /account_history_info.php\n                                SELECT os.orders_status_name,\n                                       osh.date_added,\n                                       osh.comments,\n                                       osh.comments_sent\n                                FROM " . TABLE_ORDERS_STATUS . " os,\n                                     " . TABLE_ORDERS_STATUS_HISTORY . " osh\n                                WHERE osh.orders_id = '" . $order->info['order_id'] . "'\n                                  AND osh.customer_notified = 1\n                                  AND osh.orders_status_id = os.orders_status_id\n                                  AND os.language_id = '" . (int) $_SESSION['languages_id'] . "'\n                                ORDER BY osh.date_added");
while ($statuses = xtc_db_fetch_array($statuses_query)) {
    $history_block .= xtc_date_short($statuses['date_added']) . '&nbsp;<strong>' . $statuses['orders_status_name'] . '</strong>&nbsp;' . (empty($statuses['comments']) || empty($statuses['comments_sent']) ? '&nbsp;' : nl2br(encode_htmlspecialchars($statuses['comments']))) . '<br />';
}
$smarty->assign('HISTORY_BLOCK', $history_block);
// Download-Products
if (DOWNLOAD_ENABLED == 'true') {
    include DIR_WS_MODULES . 'downloads.php';
}
require_once DIR_FS_INC . 'xtc_get_tracking_link.php';
$smarty->assign('TRACKING_LINKS', xtc_get_tracking_link($order->info['order_id']));
// --- bof -- ipdfbill --------
require 'admin/includes/ipdfbill/pdfbill_lib.php';
// pdfbill
$pdffile = 'admin/' . PDFBILL_FOLDER . PDFBILL_PREFIX . ($_GET['order_id'] . '.pdf');
if (file_exists($pdffile)) {
    $pdflink = xtc_href_link(FILENAME_PDFBILL_DISPLAY, 'oID=' . $_GET['order_id']);
    $pdflink = sprintf('<a href="%s">' . PDFBILL_DOWNLOAD_INVOICE . '</a>', $pdflink);
    $smarty->assign('IPDFBILL_INVOICE_DOWNLOAD', $pdflink);
}
// --- eof -- ipdfbill --------
// Stuff
$smarty->assign('ORDER_NUMBER', $order->info['order_id']);
//DokuMan - 2011-08-31 - fix order_id assignment
$smarty->assign('ORDER_DATE', xtc_date_long($order->info['date_purchased']));
$smarty->assign('ORDER_STATUS', $order->info['orders_status']);
    $history_query_raw = "select o.orders_id, \n                                 o.date_purchased,\n                                 o.delivery_name,\n                                 o.billing_name,\n                                 ot.text as order_total,\n                                 s.orders_status_name\n                        from " . TABLE_ORDERS . " o,\n                             " . TABLE_ORDERS_TOTAL . " ot,\n                             " . TABLE_ORDERS_STATUS . " s \n                        where o.customers_id = " . (int) $_SESSION['customer_id'] . "\n                        and o.orders_id = ot.orders_id\n                        and ot.class = 'ot_total'\n                        and o.orders_status = s.orders_status_id\n                        and s.language_id = " . (int) $_SESSION['languages_id'] . "\n                        order by orders_id DESC";
    $history_split = new splitPageResults($history_query_raw, isset($_GET['page']) ? $_GET['page'] : 0, MAX_DISPLAY_ORDER_HISTORY);
    $history_query = xtc_db_query($history_split->sql_query);
    while ($history = xtc_db_fetch_array($history_query)) {
        $products_query = xtc_db_query("select count(*) as count from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . $history['orders_id'] . "'");
        $products = xtc_db_fetch_array($products_query);
        if (xtc_not_null($history['delivery_name'])) {
            $order_type = TEXT_ORDER_SHIPPED_TO;
            $order_name = $history['delivery_name'];
        } else {
            $order_type = TEXT_ORDER_BILLED_TO;
            $order_name = $history['billing_name'];
        }
        $module_content[] = array('ORDER_ID' => $history['orders_id'], 'ORDER_STATUS' => $history['orders_status_name'], 'ORDER_DATE' => xtc_date_long($history['date_purchased']), 'ORDER_PRODUCTS' => $products['count'], 'ORDER_TOTAL' => strip_tags($history['order_total']), 'ORDER_BUTTON' => '<a href="' . xtc_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'page=' . (empty($_GET['page']) ? "1" : (int) $_GET['page']) . '&order_id=' . $history['orders_id'], 'SSL') . '">' . xtc_image_button('small_view.gif', SMALL_IMAGE_BUTTON_VIEW) . '</a>');
        require_once DIR_FS_INC . 'xtc_get_tracking_link.php';
        $module_content[count($module_content) - 1]['TRACKING_LINKS'] = xtc_get_tracking_link($history['orders_id']);
    }
}
if ($orders_total > 0) {
    $smarty->assign('SPLIT_BAR', '
	          <div class="smallText" style="clear:both;"><div style="float:left;">' . $history_split->display_count(TEXT_DISPLAY_NUMBER_OF_ORDERS) . '</div>
              <div align="right">' . TEXT_RESULT_PAGE . ' ' . $history_split->display_links(MAX_DISPLAY_PAGE_LINKS, xtc_get_all_get_params(array('page', 'info', 'x', 'y'))) . '</div>
              </div>');
}
$smarty->assign('order_content', $module_content);
$smarty->assign('language', $_SESSION['language']);
$smarty->assign('BUTTON_BACK', '<a href="' . xtc_href_link(FILENAME_ACCOUNT, '', 'SSL') . '">' . xtc_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>');
$smarty->caching = 0;
$main_content = $smarty->fetch(CURRENT_TEMPLATE . '/module/account_history.html');
$smarty->assign('language', $_SESSION['language']);
$smarty->assign('main_content', $main_content);
    $i++;
}
$order_content = '';
if (xtc_count_customer_orders() > 0) {
    $orders_query = xtc_db_query("select\n\t                                  o.orders_id,\n\t                                  o.date_purchased,\n\t                                  o.delivery_name,\n\t                                  o.delivery_country,\n\t                                  o.billing_name,\n\t                                  o.billing_country,\n\t                                  ot.text as order_total,\n\t                                  s.orders_status_name\n\t                              from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_TOTAL . "\n\t                                  ot, " . TABLE_ORDERS_STATUS . " s\n\t                              where o.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\t                              and o.orders_id = ot.orders_id\n\t                              and ot.class = 'ot_total'\n\t                              and o.orders_status = s.orders_status_id\n\t                              and s.language_id = '" . (int) $_SESSION['languages_id'] . "'\n\t                              order by orders_id desc limit 3");
    while ($orders = xtc_db_fetch_array($orders_query)) {
        if (xtc_not_null($orders['delivery_name'])) {
            $order_name = $orders['delivery_name'];
            $order_country = $orders['delivery_country'];
        } else {
            $order_name = $orders['billing_name'];
            $order_country = $orders['billing_country'];
        }
        $order_content[] = array('ORDER_ID' => $orders['orders_id'], 'ORDER_DATE' => xtc_date_short($orders['date_purchased']), 'ORDER_STATUS' => $orders['orders_status_name'], 'ORDER_TOTAL' => $orders['order_total'], 'ORDER_LINK' => xtc_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'], 'SSL'), 'ORDER_BUTTON' => '<a href="' . xtc_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'], 'SSL') . '">' . xtc_image_button('small_view.gif', SMALL_IMAGE_BUTTON_VIEW) . '</a>');
        require_once DIR_FS_INC . 'xtc_get_tracking_link.php';
        $order_content[count($order_content) - 1]['TRACKING_LINKS'] = xtc_get_tracking_link($orders['orders_id']);
    }
}
$smarty->assign('LINK_EDIT', xtc_href_link(FILENAME_ACCOUNT_EDIT, '', 'SSL'));
$smarty->assign('LINK_ADDRESS', xtc_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'));
$smarty->assign('LINK_PASSWORD', xtc_href_link(FILENAME_ACCOUNT_PASSWORD, '', 'SSL'));
//BOF - Dokuman - 2009-08-21 - Added 'delete account' functionality for customers
//Link_Delete button will not work for Admin (ID1) or not logged in users
if (isset($_SESSION['customer_id']) && $_SESSION['customer_id'] != '1') {
    $smarty->assign('LINK_DELETE', xtc_href_link(FILENAME_ACCOUNT_DELETE, '', 'SSL'));
}
//EOF - Dokuman - 2009-08-21 - Added 'delete account' functionality for customers
if (!isset($_SESSION['customer_id'])) {
    $smarty->assign('LINK_LOGIN', xtc_href_link(FILENAME_LOGIN, '', 'SSL'));
}
$smarty->assign('LINK_ORDERS', xtc_href_link(FILENAME_ACCOUNT_HISTORY, '', 'SSL'));