// BOF - Tomcraft - 2009-10-03 - Paypal Express Modul
        //xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
        xtc_redirect(xtc_href_link($link_checkout_shipping, $params, 'SSL'));
        // EOF - Tomcraft - 2009-10-03 - Paypal Express Modul
    }
}
// if no shipping destination address was selected, use their own address as default
if (!isset($_SESSION['sendto'])) {
    $_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
}
// BOF - Tomcraft - 2009-10-03 - Paypal Express Modul
//$breadcrumb->add(NAVBAR_TITLE_1_CHECKOUT_SHIPPING_ADDRESS, xtc_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
$breadcrumb->add(NAVBAR_TITLE_1_CHECKOUT_SHIPPING_ADDRESS, xtc_href_link($link_checkout_shipping, $params, 'SSL'));
// EOF - Tomcraft - 2009-10-03 - Paypal Express Modul
$breadcrumb->add(NAVBAR_TITLE_2_CHECKOUT_SHIPPING_ADDRESS, xtc_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, $params, 'SSL'));
$addresses_count = xtc_count_customer_address_book_entries();
require DIR_WS_INCLUDES . 'header.php';
$smarty->assign('FORM_ACTION', xtc_draw_form('checkout_address', xtc_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, $params, 'SSL'), 'post', 'onsubmit="return check_form_optional(checkout_address);"'));
if ($messageStack->size('checkout_address') > 0) {
    $smarty->assign('error', $messageStack->output('checkout_address'));
}
if ($process == false) {
    $smarty->assign('ADDRESS_LABEL', xtc_address_label($_SESSION['customer_id'], $_SESSION['sendto'], true, ' ', '<br />'));
    include DIR_WS_MODULES . 'checkout_address_layout.php';
}
if ($addresses_count < MAX_ADDRESS_BOOK_ENTRIES) {
    require DIR_WS_MODULES . 'checkout_new_address.php';
}
$smarty->assign('BUTTON_CONTINUE', xtc_draw_hidden_field('action', 'submit') . xtc_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE));
if ($process == true) {
    $smarty->assign('BUTTON_BACK', '<a href="' . xtc_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, $params, 'SSL') . '">' . xtc_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>');
                     $contents[] = array('align' => 'left', 'text' => TEXT_INFO_DELETE_DEFAULT);
                     $contents[] = array('text' => '<br/>');
                     $contents[] = array('align' => 'left', 'text' => '<a class="btn btn-default" href="' . xtc_href_link(FILENAME_CUSTOMERS, xtc_get_all_get_params(array('cID', 'delete')) . 'cID=' . $cInfo->customers_id) . '">' . BUTTON_BACK . '</a>');
                     $contents[] = array('text' => '<br/>');
                 }
             }
         } else {
             $contents[] = array('text' => '<br/>');
             $contents[] = array('text' => '<table style="font-size:11px; margin-left:20px;"><tr><td>' . xtc_address_format($format_id, $addresses, true, ' ', '<br />') . '</td></tr></table>');
             $contents[] = array('text' => '<br/>');
             $contents[] = array('align' => 'left', 'text' => '<a class="btn btn-default" onclick="this.blur();" href="' . xtc_href_link(FILENAME_CUSTOMERS, xtc_get_all_get_params(array('cID', 'action', 'edit')) . 'cID=' . $cInfo->customers_id . '&action=edit&edit=' . $addresses['address_book_id']) . '">' . BUTTON_EDIT . '</a>&nbsp;<a class="btn btn-default" onclick="this.blur();" href="' . xtc_href_link(FILENAME_CUSTOMERS, xtc_get_all_get_params(array('cID', 'action', 'delete', 'edit')) . 'cID=' . $cInfo->customers_id . '&action=address_book&delete=' . $addresses['address_book_id']) . '">' . BUTTON_DELETE . '</a>' . ($cInfo->customers_default_address_id != $addresses['address_book_id'] ? '&nbsp;<a class="btn btn-default" onclick="this.blur();" href="' . xtc_href_link(FILENAME_CUSTOMERS, xtc_get_all_get_params(array('cID', 'action', 'delete', 'default')) . 'cID=' . $cInfo->customers_id . '&action=update_default_adressbook&default=' . $addresses['address_book_id']) . '">' . TEXT_SET_DEFAULT . '</a>' : ''));
             $contents[] = array('text' => '<hr size="1"/>');
         }
     }
     if (!isset($_GET['delete'])) {
         $contents[] = array('align' => 'right', 'text' => xtc_count_customer_address_book_entries() < MAX_ADDRESS_BOOK_ENTRIES ? '<a class="btn btn-default" onclick="this.blur();" href="' . xtc_href_link(FILENAME_CUSTOMERS, xtc_get_all_get_params(array('cID', 'action', 'edit')) . 'cID=' . $cInfo->customers_id . '&action=edit&edit=0') . '">' . BUTTON_INSERT . '</a>&nbsp;<a class="btn btn-default" href="' . xtc_href_link(FILENAME_CUSTOMERS, xtc_get_all_get_params(array('cID', 'action', 'delete')) . 'cID=' . $cInfo->customers_id) . '">' . BUTTON_CANCEL . '</a>' : '<a class="btn btn-default" href="' . xtc_href_link(FILENAME_CUSTOMERS, xtc_get_all_get_params(array('cID', 'action', 'delete')) . 'cID=' . $cInfo->customers_id) . '">' . BUTTON_CANCEL . '</a>');
         $contents[] = array('text' => '<br/>');
     }
     break;
 case 'editstatus':
     if ($_GET['cID'] != 1) {
         $customers_history_query = xtc_db_query("SELECT new_value, old_value, date_added, customer_notified FROM " . TABLE_CUSTOMERS_STATUS_HISTORY . " WHERE customers_id = '" . xtc_db_input($_GET['cID']) . "' order by customers_status_history_id desc");
         $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_STATUS_CUSTOMER . '</b>');
         $contents = array('form' => xtc_draw_form('customers', FILENAME_CUSTOMERS, xtc_get_all_get_params(array('cID', 'action')) . 'cID=' . $cInfo->customers_id . '&action=statusconfirm'));
         $contents[] = array('text' => '<br />' . xtc_draw_pull_down_menu('status', $customers_statuses_array, $cInfo->customers_status));
         $contents[] = array('text' => '<table nowrap border="0" cellspacing="0" cellpadding="0"><tr><td style="border-bottom: 1px solid; border-color: #000000;" nowrap class="smallText" align="center"><b>' . TABLE_HEADING_NEW_VALUE . ' </b></td><td style="border-bottom: 1px solid; border-color: #000000;" nowrap class="smallText" align="center"><b>' . TABLE_HEADING_DATE_ADDED . '</b></td></tr>');
         if (xtc_db_num_rows($customers_history_query)) {
             while ($customers_history = xtc_db_fetch_array($customers_history_query)) {
                 $contents[] = array('text' => '<tr>' . "\n" . '<td class="smallText">' . $customers_statuses_id_array[$customers_history['new_value']]['text'] . '</td>' . "\n" . '<td class="smallText" align="center">' . xtc_datetime_short($customers_history['date_added']) . '</td>' . "\n" . '<td class="smallText" align="center">');
                 // web28 - 2011-10-31 - change  $customers_statuses_array  to $customers_statuses_id_array
                 $contents[] = array('text' => '</tr>' . "\n");
    $smarty->assign('error', $messageStack->output('addressbook'));
}
$smarty->assign('ADDRESS_DEFAULT', xtc_address_label($_SESSION['customer_id'], $_SESSION['customer_default_address_id'], true, ' ', '<br />'));
$addresses_data = array();
$addresses_query = xtc_db_query("select address_book_id,\n                                        entry_firstname as firstname,\n                                        entry_lastname as lastname,\n                                        entry_company as company,\n                                        entry_street_address as street_address,\n                                        entry_suburb as suburb,\n                                        entry_city as city,\n                                        entry_postcode as postcode,\n                                        entry_state as state,\n                                        entry_zone_id as zone_id,\n                                        entry_country_id as country_id \n                                 from " . TABLE_ADDRESS_BOOK . " \n                                 where customers_id = '" . (int) $_SESSION['customer_id'] . "'\n                                 order by firstname, lastname");
while ($addresses = xtc_db_fetch_array($addresses_query)) {
    $format_id = xtc_get_address_format_id($addresses['country_id']);
    if ($addresses['address_book_id'] == $_SESSION['customer_default_address_id']) {
        $primary = 1;
    } else {
        $primary = 0;
    }
    $addresses_data[] = array('NAME' => $addresses['firstname'] . ' ' . $addresses['lastname'], 'BUTTON_EDIT' => '<a href="' . xtc_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'edit=' . $addresses['address_book_id'], 'SSL') . '">' . xtc_image_button('small_edit.gif', SMALL_IMAGE_BUTTON_EDIT) . '</a>', 'BUTTON_DELETE' => '<a href="' . xtc_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'delete=' . $addresses['address_book_id'], 'SSL') . '">' . xtc_image_button('small_delete.gif', SMALL_IMAGE_BUTTON_DELETE) . '</a>', 'ADDRESS' => xtc_address_format($format_id, $addresses, true, ' ', '<br />'), 'PRIMARY' => $primary);
}
$smarty->assign('addresses_data', $addresses_data);
$smarty->assign('BUTTON_BACK', '<a href="' . xtc_href_link(FILENAME_ACCOUNT, '', 'SSL') . '">' . xtc_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>');
if (xtc_count_customer_address_book_entries() < MAX_ADDRESS_BOOK_ENTRIES) {
    $smarty->assign('BUTTON_NEW', '<a href="' . xtc_href_link(FILENAME_ADDRESS_BOOK_PROCESS, '', 'SSL') . '">' . xtc_image_button('button_add_address.gif', IMAGE_BUTTON_ADD_ADDRESS) . '</a>');
}
$smarty->assign('ADDRESS_COUNT', sprintf(TEXT_MAXIMUM_ENTRIES, MAX_ADDRESS_BOOK_ENTRIES));
$smarty->assign('language', $_SESSION['language']);
$smarty->caching = 0;
$main_content = $smarty->fetch(CURRENT_TEMPLATE . '/module/address_book.html');
$smarty->assign('language', $_SESSION['language']);
$smarty->assign('main_content', $main_content);
$smarty->caching = 0;
if (!defined('RM')) {
    $smarty->load_filter('output', 'note');
}
$smarty->display(CURRENT_TEMPLATE . '/index.html');
include 'includes/application_bottom.php';