}
$order_total_text = 'order_total';
if (!class_exists($order_total_text)) {
    require_once ADMIN_PATH_PREFIX . DIR_WS_CLASSES . $order_total_text . PHP;
}
if (!is_object($order_total_modules)) {
    $order_total_modules = new order_total();
}
if (!is_array($order_totals)) {
    $order_totals = $order_total_modules->process();
}
// BMC CC Mod Start
if (strtolower(CC_ENC) == TRUE_STRING_S) {
    $key = changeme;
    $plain_data = $order->info['cc_number'];
    $order->info['cc_number'] = changedatain($plain_data, $key);
}
// BMC CC Mod End
if (CUSTOMER_SHOW_OT_DISCOUNT) {
    $discount = CUSTOMER_DISCOUNT;
} else {
    $discount = '0.00';
}
$ip = $_SESSION['CUSTOMERS_IP'];
if (!$ip) {
    $ip = $_SERVER['REMOTE_ADDR'];
}
$customer_email_address = $order->customer['email_address'];
//	W. Kaiser - eMail-type by customer
$sql_data_array = array('customers_id' => $customers_id, 'customers_name' => trim($order->customer['firstname'] . BLANK . $order->customer['lastname']), 'customers_cid' => $order->customer['csID'], 'customers_company' => $order->customer['company'], 'customers_status' => $order->customer['status'], 'customers_status_name' => $_SESSION['customers_status']['customers_status_name'], 'customers_status_image' => $order->customer['status_image'], 'customers_status_discount' => $discount, 'customers_status' => $customer_status_value['customers_status'], 'customers_street_address' => $order->customer['street_address'], 'customers_suburb' => $order->customer['suburb'], 'customers_city' => $order->customer['city'], 'customers_postcode' => $order->customer['postcode'], 'customers_state' => $order->customer['state'], 'customers_country' => $order->customer['country']['title'], 'customers_telephone' => $order->customer['telephone'], 'customers_email_address' => $customer_email_address, 'customers_email_type' => $order->customer['email_type'], 'customers_address_format_id' => $order->customer['format_id'], 'delivery_name' => trim($order->delivery['firstname'] . BLANK . $order->delivery['lastname']), 'delivery_firstname' => $order->delivery['firstname'], 'delivery_lastname' => $order->delivery['lastname'], 'delivery_company' => $order->delivery['company'], 'delivery_street_address' => $order->delivery['street_address'], 'delivery_suburb' => $order->delivery['suburb'], 'delivery_city' => $order->delivery['city'], 'delivery_postcode' => $order->delivery['postcode'], 'delivery_state' => $order->delivery['state'], 'delivery_country' => $order->delivery['country']['title'], 'delivery_country_iso_code_2' => $order->delivery['country']['iso_code_2'], 'delivery_address_format_id' => $order->delivery['format_id'], 'payment_method' => $order->info['payment_method'], 'payment_class' => $order->info['payment_class'], 'shipping_method' => $order->info['shipping_method'], 'shipping_class' => $order->info['shipping_class'], 'cc_type' => $order->info['cc_type'], 'cc_owner' => $order->info['cc_owner'], 'cc_number' => $order->info['cc_number'], 'cc_expires' => $order->info['cc_expires'], 'cc_start' => $order->info['cc_start'], 'cc_cvv' => $order->info['cc_cvv'], 'cc_issue' => $order->info['cc_issue'], 'date_purchased' => 'now()', 'orders_status' => $order->info['order_status'], 'currency' => $order->info['currency'], 'currency_value' => $order->info['currency_value'], 'customers_ip' => $ip, 'language' => $_SESSION['language_name'], 'customers_order_reference' => $order->info['customers_order_reference'], 'orders_discount' => $order->info['orders_discount'], 'comments' => $order->info['comments']);
if ($_SESSION['credit_covers'] != '1') {
if (isset($_SESSION['tmp_oID']) && is_int($_SESSION['tmp_oID'])) {
    $tmp = false;
    $insert_id = $_SESSION['tmp_oID'];
} else {
    // check if tmp order need to be created
    if (isset(${$_SESSION}['payment']->form_action_url) && ${$_SESSION}['payment']->tmpOrders) {
        $tmp = true;
        $tmp_status = ${$_SESSION}['payment']->tmpStatus;
    } else {
        $tmp = false;
        $tmp_status = $order->info['order_status'];
    }
    // BMC CC Mod Start
    if (strtolower(CC_ENC) == 'true') {
        $plain_data = $order->info['cc_number'];
        $order->info['cc_number'] = changedatain($plain_data, CC_KEYCHAIN);
    }
    // BMC CC Mod End
    if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
        $discount = $order->customer['personal_discount'] ? $order->customer['personal_discount'] : $_SESSION['customers_status']['customers_status_ot_discount'];
    } else {
        $discount = '0.00';
    }
    if ($_SERVER["HTTP_X_FORWARDED_FOR"]) {
        $customers_ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
    } else {
        $customers_ip = $_SERVER["REMOTE_ADDR"];
    }
    if ($_SESSION['credit_covers'] != '1') {
        $sql_data_array = array('customers_id' => $_SESSION['customer_id'], 'customers_name' => $order->customer['firstname'] . ' ' . $order->customer['secondname'] . ' ' . $order->customer['lastname'], 'customers_firstname' => $order->customer['firstname'], 'customers_secondname' => $order->customer['secondname'], 'customers_lastname' => $order->customer['lastname'], 'customers_cid' => $order->customer['csID'], 'customers_vat_id' => $_SESSION['customer_vat_id'], 'customers_company' => $order->customer['company'], 'customers_status' => $_SESSION['customers_status']['customers_status_id'], 'customers_status_name' => $_SESSION['customers_status']['customers_status_name'], 'customers_status_image' => $_SESSION['customers_status']['customers_status_image'], 'customers_status_discount' => $discount, 'customers_street_address' => $order->customer['street_address'], 'customers_suburb' => $order->customer['suburb'], 'customers_city' => $order->customer['city'], 'customers_postcode' => $order->customer['postcode'], 'customers_state' => $order->customer['state'], 'customers_country' => $order->customer['country']['title'], 'customers_telephone' => $order->customer['telephone'], 'customers_email_address' => $order->customer['email_address'], 'customers_address_format_id' => $order->customer['format_id'], 'delivery_name' => $order->delivery['firstname'] . ' ' . $order->delivery['secondname'] . ' ' . $order->delivery['lastname'], 'delivery_firstname' => $order->delivery['firstname'], 'delivery_secondname' => $order->delivery['secondname'], 'delivery_lastname' => $order->delivery['lastname'], 'delivery_company' => $order->delivery['company'], 'delivery_street_address' => $order->delivery['street_address'], 'delivery_suburb' => $order->delivery['suburb'], 'delivery_city' => $order->delivery['city'], 'delivery_postcode' => $order->delivery['postcode'], 'delivery_state' => $order->delivery['state'], 'delivery_country' => $order->delivery['country']['title'], 'delivery_country_iso_code_2' => $order->delivery['country']['iso_code_2'], 'delivery_address_format_id' => $order->delivery['format_id'], 'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['secondname'] . ' ' . $order->billing['lastname'], 'billing_firstname' => $order->billing['firstname'], 'billing_secondname' => $order->billing['secondname'], 'billing_lastname' => $order->billing['lastname'], 'billing_company' => $order->billing['company'], 'billing_street_address' => $order->billing['street_address'], 'billing_suburb' => $order->billing['suburb'], 'billing_city' => $order->billing['city'], 'billing_postcode' => $order->billing['postcode'], 'billing_state' => $order->billing['state'], 'billing_country' => $order->billing['country']['title'], 'billing_country_iso_code_2' => $order->billing['country']['iso_code_2'], 'billing_address_format_id' => $order->billing['format_id'], 'payment_method' => $order->info['payment_method'], 'payment_class' => $order->info['payment_class'], 'shipping_method' => $order->info['shipping_method'], 'shipping_class' => $order->info['shipping_class'], 'cc_type' => $order->info['cc_type'], 'cc_owner' => $order->info['cc_owner'], 'cc_number' => $order->info['cc_number'], 'cc_expires' => $order->info['cc_expires'], 'cc_start' => $order->info['cc_start'], 'cc_cvv' => $order->info['cc_cvv'], 'cc_issue' => $order->info['cc_issue'], 'date_purchased' => 'now()', 'orders_status' => $tmp_status, 'currency' => $order->info['currency'], 'currency_value' => $order->info['currency_value'], 'customers_ip' => $customers_ip, 'language' => $_SESSION['language'], 'comments' => $order->info['comments'], 'orig_reference' => $order->customer['orig_reference'], 'login_reference' => $order->customer['login_reference']);
    } else {