<?php

check_user_security("my_orders");
$orders_currency = get_setting_value($settings, "orders_currency", 0);
$html_template = get_setting_value($block, "html_template", "block_user_orders.html");
$t->set_file("block_body", $html_template);
$t->set_var("user_orders_href", get_custom_friendly_url("user_orders.php"));
$t->set_var("user_order_href", get_custom_friendly_url("user_order.php"));
$t->set_var("user_home_href", get_custom_friendly_url("user_home.php"));
$t->set_var("user_order_payment_href", get_custom_friendly_url("user_order_payment.php"));
$t->set_var("user_invoice_pdf_href", get_custom_friendly_url("user_invoice_pdf.php"));
$t->set_var("user_invoice_html_href", get_custom_friendly_url("user_invoice_html.php"));
$s = new VA_Sorter($settings["templates_dir"], "sorter_img.html", get_custom_friendly_url("user_orders.php"));
$s->set_default_sorting(1, "desc");
$s->set_sorter(ORDER_NUMBER_COLUMN, "sorter_id", "1", "order_id");
$s->set_sorter(ORDER_ADDED_COLUMN, "sorter_date", "2", "order_placed_date");
$s->set_sorter(STATUS_MSG, "sorter_status", "3", "order_status");
$s->set_sorter(ORDER_TOTAL_COLUMN, "sorter_total", "4", "order_total");
$n = new VA_Navigator($settings["templates_dir"], "navigator.html", get_custom_friendly_url("user_orders.php"));
// set up variables for navigator
$sql = " SELECT COUNT(*) FROM " . $table_prefix . "orders o ";
$sql .= " WHERE o.user_id=" . $db->tosql(get_session("session_user_id"), INTEGER);
if (isset($site_id)) {
    $sql .= " AND o.site_id=" . $db->tosql($site_id, INTEGER, true, false);
} else {
    $sql .= " AND o.site_id=1";
}
$db->query($sql);
$db->next_record();
$total_records = $db->f(0);
$records_per_page = 25;
                    if (!strlen($small_image_alt)) {
                        $small_image_alt = $item_name;
                    }
                    $t->set_var("alt", htmlspecialchars($small_image_alt));
                    $t->set_var("src", htmlspecialchars($small_image));
                    if (is_array($image_size)) {
                        $t->set_var("width", "width=\"" . $image_size[0] . "\"");
                        $t->set_var("height", "height=\"" . $image_size[1] . "\"");
                    } else {
                        $t->set_var("width", "");
                        $t->set_var("height", "");
                    }
                    $t->parse("small_image", false);
                } else {
                    $t->set_var("small_image", "");
                }
                $t->parse("records", true);
            } while ($db->next_record());
        } else {
            $t->set_var("sorters", "");
            $t->set_var("records", "");
            $t->set_var("navigator", "");
            $t->parse("no_records", false);
            $t->set_var("wishlist_message", "");
        }
        $block_parsed = true;
        $t->parse("block_body", false);
    } else {
        check_user_security("my_wishlist");
    }
}