<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

  if (!tep_session_is_registered('customer_id')) {
    $navigation->set_snapshot();
    tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  }

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ADDRESS_BOOK);

  $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
  $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'));

  require(DIR_WS_INCLUDES . 'template_top.php');
?>

<?php echo tep_draw_content_top();?>

<?php echo tep_draw_heading_top();?>
<h2><?php echo HEADING_TITLE; ?></h2>
<?php echo tep_draw_heading_bottom();?>
<?php
  if ($messageStack->size('addressbook') > 0) {
    echo $messageStack->output('addressbook');
  }
?>

<div class="contentContainer page_account">
  <div class="contentBlock">
  <h4><?php echo PRIMARY_ADDRESS_TITLE; ?></h4>

  <div class="contentText">
    <div class="infoBoxContainer contentInner">
      <div class="infoBoxHeading"><?php echo PRIMARY_ADDRESS_TITLE; ?></div>
			<div class="infoBoxContents"><?php echo tep_draw_box_content_top();?>
        <?php echo tep_address_label($customer_id, $customer_default_address_id, true, ' ', '<br />'); ?>
      <?php echo tep_draw_box_content_bottom();?></div>
      </div>

    <?php echo PRIMARY_ADDRESS_DESCRIPTION; ?>
  </div>  

  <div style="clear: both;"></div>

  <h4><?php echo ADDRESS_BOOK_TITLE; ?></h4>

  <div class="contentText">

<?php
  $addresses_query = tep_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)$customer_id . "' order by firstname, lastname");
  while ($addresses = tep_db_fetch_array($addresses_query)) {
    $format_id = tep_get_address_format_id($addresses['country_id']);
?>

    <div>
      <div class="buttonSet right"><?php echo tep_draw_button2_top();?><?php echo tep_draw_button(SMALL_IMAGE_BUTTON_EDIT, 'document', tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'edit=' . $addresses['address_book_id'], 'SSL')) .  tep_draw_button2_bottom().'<br /><br />'.tep_draw_button2_top() . tep_draw_button(SMALL_IMAGE_BUTTON_DELETE, 'trash', tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'delete=' . $addresses['address_book_id'], 'SSL')); ?><?php echo tep_draw_button2_bottom();?></div>
      <p><strong><?php echo tep_output_string_protected($addresses['firstname'] . ' ' . $addresses['lastname']); ?></strong><?php if ($addresses['address_book_id'] == $customer_default_address_id) echo '&nbsp;<small><i>' . PRIMARY_ADDRESS . '</i></small>'; ?></p>
      <p style="padding-left: 20px;"><?php echo tep_address_format($format_id, $addresses, true, ' ', '<br />'); ?></p>
    </div>

<?php
  }
?>

  </div>

  <div class="buttonSet">
<?php
  if (tep_count_customer_address_book_entries() < MAX_ADDRESS_BOOK_ENTRIES) {
?>  
    <span class="button_left"><?php echo tep_draw_button1_top();?><?php echo tep_draw_button(IMAGE_BUTTON_ADD_ADDRESS, 'home', tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS, '', 'SSL'), 'primary'); ?><?php echo tep_draw_button1_bottom();?></span>
    <span class="button_right"><?php echo tep_draw_button2_top();?><?php echo tep_draw_button(IMAGE_BUTTON_BACK, 'triangle-1-w', tep_href_link(FILENAME_ACCOUNT, '', 'SSL')); ?><?php echo tep_draw_button2_bottom();?></span>
<?php
  }
?>
  </div>


  <p><?php echo sprintf(TEXT_MAXIMUM_ENTRIES, MAX_ADDRESS_BOOK_ENTRIES); ?></p>
  </div>
</div>
<?php echo tep_draw_content_bottom();?>
<?php
  require(DIR_WS_INCLUDES . 'template_bottom.php');
  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
