if ($order->billing['country']['iso_code_2'] != EMPTY_STRING) {
    $_SESSION['delivery_zone'] = $order->billing['country']['iso_code_2'];
}
// load all enabled payment modules
require_once DIR_WS_CLASSES . 'payment.php';
$payment_modules = new payment();
$breadcrumb->add(NAVBAR_TITLE_1_CHECKOUT_PAYMENT, olc_href_link(FILENAME_CHECKOUT_SHIPPING, EMPTY_STRING, SSL));
$breadcrumb->add(NAVBAR_TITLE_2_CHECKOUT_PAYMENT, olc_href_link(FILENAME_CHECKOUT_PAYMENT, EMPTY_STRING, SSL));
//W. Kaiser - AJAX
$checkout_payment_text = 'checkout_payment';
$smarty->assign('FORM_ACTION', olc_draw_form($checkout_payment_text, olc_href_link(FILENAME_CHECKOUT_CONFIRMATION, EMPTY_STRING, SSL), 'post', 'onsubmit="return check_form_payment(\'' . $checkout_payment_text . '\');"'));
//W. Kaiser - AJAX
//---PayPal WPP Modification START ---//--
if (!$ec_enabled || $_GET['ec_cancel'] || !($_SESSION['paypal_ec_payer_id'] || $_SESSION['paypal_ec_payer_info'])) {
    //---PayPal WPP Modification END ---//--
    $smarty->assign('ADDRESS_LABEL', olc_address_label($_SESSION['customer_id'], $_SESSION['billto'], true, BLANK, HTML_BR));
    $smarty->assign('BUTTON_ADDRESS', HTML_A_START . olc_href_link(FILENAME_CHECKOUT_PAYMENT_ADDRESS, EMPTY_STRING, SSL) . '">' . olc_image_button('button_change_address.gif', IMAGE_BUTTON_CHANGE_ADDRESS) . HTML_A_END);
    $smarty->assign('BUTTON_CONTINUE', olc_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE));
    require DIR_WS_INCLUDES . 'header.php';
    if (isset($_GET['payment_error']) && is_object(${$_GET['payment_error']}) && ($error = ${$_GET['payment_error']}->get_error())) {
        $smarty->assign('error', '<table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBoxNotice">
          <tr class="infoBoxNoticeContents">
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td class="main" width="100%" valign="top">' . htmlspecialchars($error['error']) . '</td>
              </tr>
            </table></td>
          </tr>
        </table>');
    }
    $payment_block .= '
                $back_link = $address_book_link;
            }
            $smarty->assign('BUTTON_BACK', HTML_A_START . $back_link . '">' . olc_image_button('button_back.gif', IMAGE_BUTTON_BACK) . HTML_A_END);
            $smarty->assign('BUTTON_UPDATE', olc_draw_hidden_field('action', 'process') . olc_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE));
        }
    }
    $submit_routine_trailer = '_new';
} else {
    // if no shipping destination address was selected, use their own address as default
    if (!isset($_SESSION[$checkout_id_text])) {
        $_SESSION[$checkout_id_text] = $_SESSION['customer_default_address_id'];
    }
    if (!$process) {
        require_once DIR_FS_INC . 'olc_draw_radio_field.inc.php';
        $checkout_id = $_SESSION[$checkout_id_text];
        $smarty->assign('ADDRESS_LABEL', olc_address_label(CUSTOMER_ID, $checkout_id, true, BLANK, HTML_BR));
        if ($addresses_count > 1) {
            $radio_buttons = 0;
            $addresses_query = olc_db_query("select address_book_id, entry_firstname as firstname, entry_lastname as lastname,\n\t\tentry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city,\n\t\tentry_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 = '" . CUSTOMER_ID . APOS);
            $address_content = '
						<table border="0" width="100%" cellspacing="0" cellpadding="0">';
            while ($addresses = olc_db_fetch_array($addresses_query)) {
                $format_id = olc_get_address_format_id($address['country_id']);
                $address_content .= '
							<tr>
                <td width="10">&nbsp;</td>
                <td>
                	<table border="0" width="100%" cellspacing="0" cellpadding="2">
';
                $address_book_id = $addresses['address_book_id'];
                if ($address_book_id == $checkout_id) {
require_once DIR_FS_INC . 'olc_address_label.inc.php';
require_once DIR_FS_INC . 'olc_get_country_name.inc.php';
require_once DIR_FS_INC . 'olc_image_button.inc.php';
require_once DIR_FS_INC . 'olc_count_customer_address_book_entries.inc.php';
if (!isset($_SESSION['customer_id'])) {
    olc_redirect(olc_href_link(FILENAME_LOGIN, EMPTY_STRING, SSL));
}
$breadcrumb->add(NAVBAR_TITLE_1_ADDRESS_BOOK, olc_href_link(FILENAME_ACCOUNT, EMPTY_STRING, SSL));
$breadcrumb->add(NAVBAR_TITLE_2_ADDRESS_BOOK, olc_href_link(FILENAME_ADDRESS_BOOK, EMPTY_STRING, SSL));
require DIR_WS_INCLUDES . 'header.php';
if (is_object($messageStack)) {
    if ($messageStack->size('addressbook') > 0) {
        $smarty->assign('error', $messageStack->output('addressbook'));
    }
}
$smarty->assign('ADDRESS_DEFAULT', olc_address_label($_SESSION['customer_id'], $_SESSION['customer_default_address_id'], true, BLANK, HTML_BR));
$addresses_data = array();
$addresses_query = olc_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");
$customer_default_address_id = $_SESSION['customer_default_address_id'];
while ($addresses = olc_db_fetch_array($addresses_query)) {
    $format_id = olc_get_address_format_id($addresses['country_id']);
    $address_book_id = $addresses['address_book_id'];
    $primary = $address_book_id == $customer_default_address_id;
    $addresses_data[] = array('NAME' => trim($addresses['firstname'] . BLANK . $addresses['lastname']), 'BUTTON_EDIT' => HTML_A_START . olc_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'edit=' . $address_book_id, SSL) . '">' . olc_image_button('small_edit.gif', SMALL_IMAGE_BUTTON_EDIT) . HTML_A_END, 'BUTTON_DELETE' => HTML_A_START . olc_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'delete=' . $address_book_id, SSL) . '">' . olc_image_button('small_delete.gif', SMALL_IMAGE_BUTTON_DELETE) . HTML_A_END, 'ADDRESS' => olc_address_format($format_id, $addresses, true, BLANK, HTML_BR), 'PRIMARY' => $primary);
}
$smarty->assign('addresses_data', $addresses_data);
$smarty->assign('BUTTON_BACK', HTML_A_START . olc_href_link(FILENAME_ACCOUNT, EMPTY_STRING, SSL) . '">' . olc_image_button('button_back.gif', IMAGE_BUTTON_BACK) . HTML_A_END);
if (olc_count_customer_address_book_entries() < MAX_ADDRESS_BOOK_ENTRIES) {
    $smarty->assign('BUTTON_NEW', HTML_A_START . olc_href_link(FILENAME_ADDRESS_BOOK_PROCESS, EMPTY_STRING, SSL) . '">' . olc_image_button('button_add_address.gif', IMAGE_BUTTON_ADD_ADDRESS) . HTML_A_END);
}
$smarty->assign('ADDRESS_COUNT', sprintf(TEXT_MAXIMUM_ENTRIES, MAX_ADDRESS_BOOK_ENTRIES));
if ($ec_checkout && $ec_enabled) {
    $paypal_ec_payer_info = $_SESSION['paypal_ec_payer_info'];
    $address_label = trim($paypal_ec_payer_info['payer_firstname'] . BLANK . $paypal_ec_payer_info['payer_lastname']) . HTML_BR;
    $payer_business = $paypal_ec_payer_info['payer_business'];
    if ($payer_business) {
        $address_label .= $payer_business . HTML_BR;
    }
    $address_label .= $paypal_ec_payer_info['ship_street_1'] . HTML_BR;
    $ship_street_2 = $paypal_ec_payer_info['ship_street_2'];
    if ($ship_street_2) {
        $address_label .= $ship_street_2 . HTML_BR;
    }
    $address_label .= $paypal_ec_payer_info['ship_city'] . COMMA_BLANK . $paypal_ec_payer_info['ship_state'] . BLANK . $paypal_ec_payer_info['ship_postal_code'] . HTML_BR;
    $address_label .= $paypal_ec_payer_info['ship_country_name'];
} else {
    $address_label = olc_address_label(CUSTOMER_ID, $sendto, true, BLANK, HTML_BR);
}
//---PayPal WPP Modification END ---//--
$smarty->assign('ADDRESS_LABEL', $address_label);
//---PayPal WPP Modification START ---//--
if ($ec_checkout && $ec_enabled) {
    $link = olc_href_link(FILENAME_EC_PROCESS, 'clearSess=1', SSL);
} else {
    $link = olc_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, EMPTY_STRING, SSL);
}
//---PayPal WPP Modification END ---//--
$smarty->assign('BUTTON_ADDRESS', HTML_A_START . $link . '">' . olc_image_button('button_change_address.gif', IMAGE_BUTTON_CHANGE_ADDRESS) . HTML_A_END);
$smarty->assign('BUTTON_CONTINUE', olc_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE));
if ($shipping_modules_count > 0) {
    //---PayPal WPP Modification START ---//--
    if ($ec_enabled) {
 function notifyCustomer(&$order)
 {
     $customer_notification = SEND_EMAILS == TRUE_STRING_S ? '1' : '0';
     olc_db_query(INSERT_INTO . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified) values ('" . (int) $this->orderID . "', '" . MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID . "', now(), '" . $customer_notification . "')");
     // lets start with the email confirmation
     include $this->checkoutProcessLanguageFile;
     $email_order = STORE_NAME . NEW_LINE . EMAIL_SEPARATOR . NEW_LINE . EMAIL_TEXT_ORDER_NUMBER . ' ' . $this->orderID . NEW_LINE . EMAIL_TEXT_INVOICE_URL . ' ' . $this->accountHistoryInfoURL . NEW_LINE . EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
     $customerComments = $this->getCustomerComments();
     if ($customerComments) {
         $email_order .= olc_db_output($customerComments) . "\n\n";
     }
     $email_order .= EMAIL_TEXT_PRODUCTS . NEW_LINE . EMAIL_SEPARATOR . NEW_LINE . $this->products_ordered . EMAIL_SEPARATOR . NEW_LINE;
     for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
         $email_order .= strip_tags($order->totals[$i]['title']) . ' ' . strip_tags($order->totals[$i]['text']) . NEW_LINE;
     }
     if ($this->contentType != 'virtual') {
         $email_order .= NEW_LINE . EMAIL_TEXT_DELIVERY_ADDRESS . NEW_LINE . EMAIL_SEPARATOR . NEW_LINE . olc_address_label($order->customer['id'], $this->sendTo, 0, '', NEW_LINE) . NEW_LINE;
     }
     $email_order .= NEW_LINE . EMAIL_TEXT_BILLING_ADDRESS . NEW_LINE . EMAIL_SEPARATOR . NEW_LINE . olc_address_label($order->customer['id'], $this->billTo, 0, '', NEW_LINE) . "\n\n";
     $email_order .= EMAIL_TEXT_PAYMENT_METHOD . NEW_LINE . EMAIL_SEPARATOR . NEW_LINE;
     $email_order .= $this->paymentTitle . "\n\n";
     olc_mail($order->customer['name'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     // send emails to other people
     if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
         olc_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     }
 }