$site_trail->add(NAVBAR_TITLE_DELETE_ENTRY, xos_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'delete=' . $_GET['delete'], 'SSL'));
 } else {
     $site_trail->add(NAVBAR_TITLE_ADD_ENTRY, xos_href_link(FILENAME_ADDRESS_BOOK_PROCESS, '', 'SSL'));
 }
 require DIR_WS_INCLUDES . 'html_header.php';
 require DIR_WS_INCLUDES . 'boxes.php';
 require DIR_WS_INCLUDES . 'header.php';
 require DIR_WS_INCLUDES . 'footer.php';
 if ($messageStack->size('addressbook') > 0) {
     $smarty->assign('message_stack', $messageStack->output('addressbook'));
     $smarty->assign('message_stack_error', $messageStack->output('addressbook', 'error'));
     $smarty->assign('message_stack_warning', $messageStack->output('addressbook', 'warning'));
     $smarty->assign('message_stack_success', $messageStack->output('addressbook', 'success'));
 }
 if (isset($_GET['delete'])) {
     $smarty->assign(array('delete_address' => true, 'address_label' => xos_address_label($_SESSION['customer_id'], $_GET['delete'], true, ' ', '<br />'), 'link_filename_address_book' => xos_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'), 'link_filename_address_book_process_delete' => xos_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'delete=' . $_GET['delete'] . '&action=deleteconfirm&formid=' . md5($_SESSION['sessiontoken']), 'SSL')));
 } elseif (isset($_GET['edit']) && is_numeric($_GET['edit'])) {
     $smarty->assign(array('edit_address' => true, 'form_begin' => xos_draw_form('addressbook', xos_href_link(FILENAME_ADDRESS_BOOK_PROCESS, isset($_GET['edit']) ? 'edit=' . $_GET['edit'] : '', 'SSL'), 'post', 'onsubmit="return true;"', true), 'link_filename_address_book' => xos_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'), 'hidden_field_update' => xos_draw_hidden_field('action', 'update'), 'hidden_field_edit' => xos_draw_hidden_field('edit', $_GET['edit']), 'form_end' => '</form>'));
     include DIR_WS_MODULES . 'address_book_details.php';
 } else {
     if (sizeof($_SESSION['navigation']->snapshot) > 0) {
         $back_link = xos_href_link($_SESSION['navigation']->snapshot['page'], xos_array_to_query_string($_SESSION['navigation']->snapshot['get'], array(xos_session_name())), $_SESSION['navigation']->snapshot['mode']);
     } else {
         $back_link = xos_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL');
     }
     $smarty->assign(array('form_begin' => xos_draw_form('addressbook', xos_href_link(FILENAME_ADDRESS_BOOK_PROCESS, isset($_GET['edit']) ? 'edit=' . $_GET['edit'] : '', 'SSL'), 'post', 'onsubmit="return true;"', true), 'link_back' => $back_link, 'hidden_field_process' => xos_draw_hidden_field('action', 'process'), 'form_end' => '</form>'));
     include DIR_WS_MODULES . 'address_book_details.php';
 }
 $smarty->configLoad('languages/' . $_SESSION['language'] . '.conf', 'address_book_process');
 $output_address_book_process = $smarty->fetch(SELECTED_TPL . '/address_book_process.tpl');
 $smarty->assign('central_contents', $output_address_book_process);
     $smarty->assign('more_tax_groups', true);
 }
 if ($order->info['comments']) {
     $smarty->assign('order_comments', xos_db_output($order->info['comments']));
 }
 if ($order->content_type != 'virtual') {
     $smarty->assign('delivery_address', xos_address_label($_SESSION['customer_id'], $_SESSION['sendto'], 0, '', "\n"));
 }
 if (is_object(${$_SESSION['payment']})) {
     $payment_class = ${$_SESSION['payment']};
     $smarty->assign('payment_method', $order->info['payment_method']);
     if ($payment_class->email_footer) {
         $smarty->assign('payment_email_footer', $payment_class->email_footer);
     }
 }
 $smarty->assign(array('html_params' => HTML_PARAMS, 'xhtml_lang' => XHTML_LANG, 'charset' => CHARSET, 'link_invoice' => xos_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $insert_id, 'SSL', false, false), 'default_address' => xos_address_label($_SESSION['customer_id'], $_SESSION['customer_default_address_id'], 0, '', "\n"), 'billing_address' => xos_address_label($_SESSION['customer_id'], $_SESSION['billto'], 0, '', "\n"), 'store_name' => STORE_NAME, 'store_name_address' => STORE_NAME_ADDRESS, 'order_id' => $insert_id, 'date_ordered' => xos_date_format(DATE_FORMAT_LONG), 'order_products' => $order_products_array, 'order_totals' => $order_totals_array, 'src_embedded_shop_logo' => 'cid:shop_logo', 'src_shop_logo' => HTTP_SERVER . DIR_WS_CATALOG . DIR_WS_IMAGES . (is_file(DIR_FS_CATALOG . 'images/email_shop_logo/' . EMAIL_SHOP_LOGO) ? 'email_shop_logo/' : 'catalog/templates/' . SELECTED_TPL . '/') . EMAIL_SHOP_LOGO));
 $smarty->configLoad('languages/' . $_SESSION['language'] . '_email.conf', 'order_email_html');
 $output_order_email_html = $smarty->fetch(SELECTED_TPL . '/includes/email/order_email_html.tpl');
 $smarty->configLoad('languages/' . $_SESSION['language'] . '_email.conf', 'order_email_text');
 $output_order_email_text = $smarty->fetch(SELECTED_TPL . '/includes/email/order_email_text.tpl');
 $email_to_customer = new mailer($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], sprintf(EMAIL_TEXT_SUBJECT_CUSTOMER, $insert_id, xos_date_format(DATE_FORMAT_SHORT)), $output_order_email_html, $output_order_email_text, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SHOP_LOGO);
 if (!$email_to_customer->send()) {
     $messageStack->add_session('header', sprintf(ERROR_PHPMAILER, $email_to_customer->ErrorInfo));
 }
 // send emails to other people
 if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
     $send_extra_order_emails_to = SEND_EXTRA_ORDER_EMAILS_TO;
     $decoded_send_extra_order_emails_to = html_entity_decode($send_extra_order_emails_to, ENT_QUOTES, 'UTF-8');
     $recipients = explode(',', $decoded_send_extra_order_emails_to);
     for ($i = 0, $n = count($recipients); $i < $n; $i++) {
         $address = '';
 $site_trail->add(NAVBAR_TITLE_2, xos_href_link(FILENAME_CHECKOUT_PAYMENT_ADDRESS, '', 'SSL'));
 $addresses_count = xos_count_customer_address_book_entries();
 $add_header = '<script type="text/javascript">' . "\n" . '/* <![CDATA[ */' . "\n" . 'var selected;' . "\n\n" . 'function selectRowEffect(object, buttonSelect) {' . "\n" . '  if (!selected) {' . "\n" . '    if (document.getElementById) {' . "\n" . '      selected = document.getElementById("default-selected");' . "\n" . '    } else {' . "\n" . '      selected = document.all["default-selected"];' . "\n" . '    }' . "\n" . '  }' . "\n\n" . '  if (selected) selected.className = "module-row";' . "\n" . '  object.className = "module-row-selected";' . "\n" . '  selected = object;' . "\n\n" . '// one button is not an array' . "\n" . '  if (document.checkout_address.address[0]) {' . "\n" . '    document.checkout_address.address[buttonSelect].checked=true;' . "\n" . '  } else {' . "\n" . '    document.checkout_address.address.checked=true;' . "\n" . '  }' . "\n" . '}' . "\n\n" . 'function rowOverEffect(object) {' . "\n" . '  if (object.className == "module-row") object.className = "module-row-over";' . "\n" . '}' . "\n\n" . 'function rowOutEffect(object) {' . "\n" . '  if (object.className == "module-row-over") object.className = "module-row";' . "\n" . '}' . "\n\n" . '/* ]]> */' . "\n" . '</script> ' . "\n";
 require DIR_WS_INCLUDES . 'html_header.php';
 require DIR_WS_INCLUDES . 'boxes.php';
 require DIR_WS_INCLUDES . 'header.php';
 require DIR_WS_INCLUDES . 'footer.php';
 require DIR_WS_MODULES . 'checkout_new_address.php';
 if ($messageStack->size('checkout_address') > 0) {
     $smarty->assign('message_stack', $messageStack->output('checkout_address'));
     $smarty->assign('message_stack_error', $messageStack->output('checkout_address', 'error'));
     $smarty->assign('message_stack_warning', $messageStack->output('checkout_address', 'warning'));
     $smarty->assign('message_stack_success', $messageStack->output('checkout_address', 'success'));
 }
 if ($process == false) {
     $smarty->assign('address_label', xos_address_label($_SESSION['customer_id'], $_SESSION['billto'], true, ' ', '<br />'));
     if ($addresses_count > 1) {
         $radio_buttons = 0;
         $addresses_query = xos_db_query("select address_book_id, entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int) $_SESSION['customer_id'] . "'");
         $addresses_array = array();
         while ($addresses = xos_db_fetch_array($addresses_query)) {
             $format_id = xos_get_address_format_id($addresses['country_id']);
             $addresses['address_book_id'] == $_SESSION['billto'] ? $actual_address = true : ($actual_address = false);
             $addresses_array[] = array('radio_field' => xos_draw_radio_field('address', $addresses['address_book_id'], $addresses['address_book_id'] == $_SESSION['billto'], 'id="address_' . $radio_buttons . '"'), 'actual_address' => $actual_address, 'address_name' => xos_output_string_protected($addresses['firstname'] . ' ' . $addresses['lastname']), 'full_address' => xos_address_format($format_id, $addresses, true, ' ', ', '), 'radio_select' => $radio_buttons);
             $radio_buttons++;
         }
         $smarty->assign(array('several_addresses' => true, 'addresses' => $addresses_array));
     }
 }
 if ($addresses_count < MAX_ADDRESS_BOOK_ENTRIES) {
     $smarty->assign('not_max_address_book_entries', true);
            for ($i = 0, $n = sizeof($quotes); $i < $n; $i++) {
                if (!isset($quotes[$i]['error'])) {
                    $shipping_modules_methods_array = array();
                    for ($j = 0, $n2 = sizeof($quotes[$i]['methods']); $j < $n2; $j++) {
                        // set the radio button to be checked if it is the method chosen
                        $checked = $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $_SESSION['shipping']['id'] ? true : false;
                        $checked == true || $n == 1 && $n2 == 1 ? $actual_method = true : ($actual_method = false);
                        if ($n > 1 || $n2 > 1) {
                            $several_methods = true;
                            $cost = $currencies->format(xos_add_tax($currencies->currencies[$_SESSION['currency']]['value'] * $quotes[$i]['methods'][$j]['cost'], isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0));
                        } else {
                            $several_methods = false;
                            $cost = $currencies->format(xos_add_tax($currencies->currencies[$_SESSION['currency']]['value'] * $quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax']));
                        }
                        $shipping_modules_methods_array[] = array('radio_field' => xos_draw_radio_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'], $checked, 'id="shipping_' . $radio_buttons . '"'), 'several_methods' => $several_methods, 'hidden_field' => xos_draw_hidden_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'], 'id="shipping_' . $radio_buttons . '"'), 'cost' => $cost, 'actual_method' => $actual_method, 'title' => $quotes[$i]['methods'][$j]['title'], 'radio_select' => $radio_buttons);
                        $radio_buttons++;
                    }
                }
                $shipping_modules_array[] = array('name' => $quotes[$i]['module'], 'icon' => $quotes[$i]['icon'], 'error' => $quotes[$i]['error'], 'methods' => $shipping_modules_methods_array);
                unset($shipping_modules_methods_array);
            }
        }
        $smarty->assign(array('shipping_modules' => true, 'shipping_modules_array' => $shipping_modules_array));
    }
    $smarty->assign(array('form_begin' => xos_draw_form('checkout_address', xos_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'post', '', true), 'hidden_field' => xos_draw_hidden_field('action', 'process'), 'form_end' => '</form>', 'link_filename_checkout_shipping_address' => MAX_ADDRESS_BOOK_ENTRIES > 1 ? xos_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, '', 'SSL') : xos_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'address_label' => xos_address_label($_SESSION['customer_id'], $_SESSION['sendto'], true, ' ', '<br />'), 'textarea' => xos_draw_textarea_field('comments', '60', '5', $_SESSION['comments'], 'class="form-control" id="checkout_shipping_comments"')));
    $smarty->configLoad('languages/' . $_SESSION['language'] . '.conf', 'checkout_shipping');
    $output_checkout_shipping = $smarty->fetch(SELECTED_TPL . '/checkout_shipping.tpl');
    $smarty->assign('central_contents', $output_checkout_shipping);
    $smarty->display(SELECTED_TPL . '/frame.tpl');
    require DIR_WS_INCLUDES . 'application_bottom.php';
}
        } elseif (isset($selection[$i]['fields']) && is_array($selection[$i]['fields'])) {
            $fields = true;
            $selection_fields_array = array();
            for ($j = 0, $n2 = sizeof($selection[$i]['fields']); $j < $n2; $j++) {
                $selection_fields_array[] = array('title' => $selection[$i]['fields'][$j]['title'], 'field' => $selection[$i]['fields'][$j]['field']);
            }
        }
        $payment_modules_array[] = array('radio_field' => $radio_field, 'actual_payment_method' => $actual_payment_method, 'loaded_modules' => $modules, 'module_error_text' => $module_error_text, 'module_error' => $module_error, 'fields' => $fields, 'selection_fields' => $selection_fields_array, 'radio_select' => $radio_buttons);
        unset($selection_fields_array);
        $radio_buttons++;
    }
    if (sizeof($selection) > 0) {
        $smarty->assign('payment_modules', true);
    }
    if (sizeof($selection) > 1) {
        $smarty->assign('several_payment_modules', true);
    }
    if (isset($_GET['payment_error']) && is_object(${$_GET['payment_error']}) && ($error = ${$_GET['payment_error']}->get_error())) {
        $smarty->assign(array('payment_error' => true, 'payment_error_title' => xos_output_string($error['title']), 'payment_error_sting' => xos_output_string($error['error'])));
    }
    if (MUST_ACCEPT_CONDITIONS == 'true') {
        $smarty->assign('checkbox_accept_conditions', xos_draw_checkbox_field('accept_conditions', '1', false, 'id="accept_conditions"'));
    }
    $popup_status_query = xos_db_query("select status from " . TABLE_CONTENTS . "  where type = 'system_popup' and status = '1' and content_id = '8' LIMIT 1");
    $smarty->assign(array('form_begin' => xos_draw_form('checkout_payment', xos_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL'), 'post', 'onsubmit="return check_form();"', true), 'form_end' => '</form>', 'link_filename_popup_content_8' => xos_db_num_rows($popup_status_query) ? xos_href_link(FILENAME_POPUP_CONTENT, 'co=8', $request_type) : '', 'link_filename_checkout_payment_address' => MAX_ADDRESS_BOOK_ENTRIES > 1 ? xos_href_link(FILENAME_CHECKOUT_PAYMENT_ADDRESS, '', 'SSL') : xos_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'), 'link_filename_checkout_shipping' => xos_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'address_label' => xos_address_label($_SESSION['customer_id'], $_SESSION['billto'], true, ' ', '<br />'), 'payment_modules' => $payment_modules_array, 'textarea' => xos_draw_textarea_field('comments', '60', '5', $_SESSION['comments'], 'class="form-control" id="checkout_payment_comments"')));
    $smarty->configLoad('languages/' . $_SESSION['language'] . '.conf', 'checkout_payment');
    $output_checkout_payment = $smarty->fetch(SELECTED_TPL . '/checkout_payment.tpl');
    $smarty->assign('central_contents', $output_checkout_payment);
    $smarty->display(SELECTED_TPL . '/frame.tpl');
    require DIR_WS_INCLUDES . 'application_bottom.php';
}
    }
    require DIR_FS_SMARTY . 'catalog/languages/' . $_SESSION['language'] . '/' . FILENAME_ADDRESS_BOOK;
    $site_trail->add(NAVBAR_TITLE_1, xos_href_link(FILENAME_ACCOUNT, '', 'SSL'));
    $site_trail->add(NAVBAR_TITLE_2, xos_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'));
    $add_header = '<script type="text/javascript">' . "\n" . '/* <![CDATA[ */' . "\n" . 'function rowOverEffect(object) {' . "\n" . '  if (object.className == "module-row") object.className = "module-row-over";' . "\n" . '}' . "\n\n" . 'function rowOutEffect(object) {' . "\n" . '  if (object.className == "module-row-over") object.className = "module-row";' . "\n" . '}' . "\n" . '/* ]]> */' . "\n" . '</script> ' . "\n";
    require DIR_WS_INCLUDES . 'html_header.php';
    require DIR_WS_INCLUDES . 'boxes.php';
    require DIR_WS_INCLUDES . 'header.php';
    require DIR_WS_INCLUDES . 'footer.php';
    $addresses_query = xos_db_query("select address_book_id, entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int) $_SESSION['customer_id'] . "' order by firstname, lastname");
    $addresses_array = array();
    while ($addresses = xos_db_fetch_array($addresses_query)) {
        $format_id = xos_get_address_format_id($addresses['country_id']);
        $addresses_array[] = array('name' => xos_output_string_protected($addresses['firstname'] . ' ' . $addresses['lastname']), 'primary_address' => $addresses['address_book_id'] == $_SESSION['customer_default_address_id'] ? true : false, 'link_filename_address_book_process_edit' => xos_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'edit=' . $addresses['address_book_id'], 'SSL'), 'link_filename_address_book_process_delete' => xos_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'delete=' . $addresses['address_book_id'], 'SSL'), 'format_address' => xos_address_format($format_id, $addresses, true, ' ', '<br />'), 'order_total' => $orders['order_total']);
    }
    if (xos_count_customer_address_book_entries() < MAX_ADDRESS_BOOK_ENTRIES) {
        $smarty->assign('link_filename_address_book_process', xos_href_link(FILENAME_ADDRESS_BOOK_PROCESS, '', 'SSL'));
    }
    if ($messageStack->size('addressbook') > 0) {
        $smarty->assign('message_stack', $messageStack->output('addressbook'));
        $smarty->assign('message_stack_error', $messageStack->output('addressbook', 'error'));
        $smarty->assign('message_stack_warning', $messageStack->output('addressbook', 'warning'));
        $smarty->assign('message_stack_success', $messageStack->output('addressbook', 'success'));
    }
    $smarty->assign(array('addresses' => $addresses_array, 'primary_address_label' => xos_address_label($_SESSION['customer_id'], $_SESSION['customer_default_address_id'], true, ' ', '<br />'), 'link_filename_account' => xos_href_link(FILENAME_ACCOUNT, '', 'SSL'), 'max_address_book_entries' => MAX_ADDRESS_BOOK_ENTRIES));
    $smarty->configLoad('languages/' . $_SESSION['language'] . '.conf', 'address_book');
    $output_address_book = $smarty->fetch(SELECTED_TPL . '/address_book.tpl');
    $smarty->assign('central_contents', $output_address_book);
    $smarty->display(SELECTED_TPL . '/frame.tpl');
    require DIR_WS_INCLUDES . 'application_bottom.php';
}