<?php
/*
  www.oscGold.com (C) Kamelia-Net Jacek Krysiak
  modul oscGold wer 4.0
*/
?>

<table border="0" width="100%" cellspacing="0" cellpadding="0">

 <!-- Naglowek BOF -->
 <tr>
  <td>
   <?php
   $info_box_contents = array();
   $info_box_contents[] = array('text' => sprintf(HEADING_TITLE));
   new contentBoxHeading($info_box_contents);
   ?>
  </td>
 </tr>
 <tr>
  <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '1'); ?></td>
 </tr>
 <!-- Naglowek EOF -->

 <tr>
  <td>
    <fieldset>
    <legend><?php echo sprintf(HEADING_ORDER_NUMBER, $HTTP_GET_VARS['order_id']) . ' <small>(' . $order->info['orders_status'] . ')</small>'; ?></b></legend>
      <table border="0" width="100%" cellspacing="1" cellpadding="2">
        <tr>
          <td class="smallText"><?php echo HEADING_ORDER_DATE . ' ' . tep_date_long($order->info['date_purchased']); ?></td>
          <td class="smallText" align="right"><?php echo HEADING_ORDER_TOTAL . ' ' . $order->info['total']; ?></td>
        </tr>
      </table>
    </fieldset>
  </td>
 </tr>
 <tr>
  <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '3'); ?></td>
 </tr>

 <tr>
  <td>
    <fieldset>
      <table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
        <tr class="infoBoxContents">
          <?php
          if ($order->delivery != false) {
            ?>
            <td valign="top" width="50%">
              <table border="0" width="100%" cellspacing="0" cellpadding="2">
                <tr>
                  <td class="main"><b><?php echo HEADING_DELIVERY_ADDRESS; ?></b></td>
                </tr>
                <tr>
                 <td class="main"><?php echo tep_address_format($order->delivery['format_id'], $order->delivery, 1, ' ', '<br>'); ?></td>
                </tr>

               <?php
               if (tep_not_null($order->info['shipping_method'])) {
                ?>
                <tr>
                  <td class="main"><b><?php echo HEADING_SHIPPING_METHOD; ?></b></td>
                </tr>
                <tr>
                  <td class="main"><?php echo $order->info['shipping_method']; ?></td>
                </tr>
                <?php
               }
               ?>
              </table>
            </td>
            <?php
          }
          ?>
          <td valign="top" width="<?php echo (($order->delivery != false) ? '50%' : '100%'); ?>">
            <table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td class="main"><b><?php echo HEADING_BILLING_ADDRESS; ?></b></td>
              </tr>
              <tr>
                <td class="main"><?php echo tep_address_format($order->billing['format_id'], $order->billing, 1, ' ', '<br>'); ?></td>
              </tr>
              <tr>
                <td class="main"><b><?php echo HEADING_PAYMENT_METHOD; ?></b></td>
              </tr>
              <tr>
                <td class="main"><?php echo $order->info['payment_method']; ?></td>
              </tr>
            </table>
          </td>
        </tr>
        <tr class="infoBoxContents">

          <td <?php echo (($order->delivery != false) ? 'colspan="2"' : ''); ?> width="100%" valign="top">
            <table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr>
                <td>
                  <table border="0" width="100%" cellspacing="0" cellpadding="2">
                    <?php
                    if (sizeof($order->info['tax_groups']) > 1) {
                      ?>
                      <tr>
                        <td class="main" colspan="2"><b><?php echo HEADING_PRODUCTS; ?></b></td>
                        <td class="smallText" align="right"><b><?php echo HEADING_TAX; ?></b></td>
                        <td class="smallText" align="right"><b><?php echo HEADING_TOTAL; ?></b></td>
                      </tr>
                      <?php
                    } else {
                      ?>
                      <tr>
                        <td class="main" colspan="3"><b><?php echo HEADING_PRODUCTS; ?></b></td>
                      </tr>
                      <?php
                    }

                    for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
                      echo '          <tr>' . "\n" .
                              '           <td class="main" align="right" valign="top" width="30">' . $order->products[$i]['qty'] . '&nbsp;x</td>' . "\n" .
                              '           <td class="main" valign="top" nowrap>' . $order->products[$i]['name'];

                      if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
                        for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
                          echo '<br><small>&nbsp;<i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'] . '</i></small>';
                        }
                      }

                      // denuz text attr  /////////////////////////////////// DODATKOWE POLA - CECHY TEKSTOWE
                      $attr_q = tep_db_query("select ota.*, pta.products_text_attributes_name from orders_text_attributes as ota, products_text_attributes as pta where ota.orders_id = " . $HTTP_GET_VARS['order_id'] . " and ota.products_id = " . $order->products[$i]['orders_products_id'] . " and pta.products_text_attributes_id = ota.products_text_attributes_id");
                      while ($attr = tep_db_fetch_array($attr_q)) {
                        echo '<br><small>&nbsp;<i> - ' . $attr['products_text_attributes_name'] . ': ' . stripslashes($attr['products_text_attributes_text']);
                        echo '</i></small>';
                      }
                      // eof denuz text attr /////////////////////////////////// DODATKOWE POLA - CECHY TEKSTOWE

                      echo '           </td>' . "\n";

                      if (sizeof($order->info['tax_groups']) > 1) {
                        echo '          <td class="main" valign="top" align="right">' . tep_display_tax_value($order->products[$i]['tax']) . '%</td>' . "\n";
                      }

                      echo '           <td class="main" align="right" valign="top">' . $currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . '</td>' . "\n" .'          </tr>' . "\n";
                    }
                    ?>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>

        <tr class="infoBoxContents">
          <td <?php echo (($order->delivery != false) ? 'colspan="2"' : ''); ?> width="100%" valign="top">
            <table border="0" width="100%" cellspacing="0" cellpadding="2">
              <?php
              for ($i=0, $n=sizeof($order->totals); $i<$n; $i++) {
                 echo '              <tr>' . "\n" .
                         '               <td class="main" align="right" width="100%">' . $order->totals[$i]['title'] . '</td>' . "\n" .
                         '               <td class="main" align="right" nowrap>' . $order->totals[$i]['text'] . '</td>' . "\n" .
                         '              </tr>' . "\n";
              }
              ?>
            </table>
          </td>
        </tr>
      </table>
    </fieldset>
  </td>
 </tr>

 <tr>
  <td>
        <fieldset>
        <legend><?php echo HEADING_ORDER_HISTORY; ?></legend>
          <table border="0" width="100%" cellspacing="1" cellpadding="2">
            <tr>
              <td valign="top">
                <table border="0" width="100%" cellspacing="0" cellpadding="2">
                  <?php
                  $statuses_query = tep_db_query("select os.orders_status_name, osh.date_added, osh.comments from " . TABLE_ORDERS_STATUS . " os, " . TABLE_ORDERS_STATUS_HISTORY . " osh where osh.orders_id = '" . (int)$HTTP_GET_VARS['order_id'] . "' and osh.orders_status_id = os.orders_status_id and os.language_id = '" . (int)$languages_id . "' and os.public_flag = '1' order by osh.date_added");

                  while ($statuses = tep_db_fetch_array($statuses_query)) {
                     echo '              <tr>' . "\n" .
                             '               <td class="main" valign="top" width="70">' . tep_date_short($statuses['date_added']) . '</td>' . "\n" .
                             '               <td class="main" valign="top" width="170">' . $statuses['orders_status_name'] . '</td>' . "\n" .
                             '               <td class="main" valign="top">' . (empty($statuses['comments']) ? '&nbsp;' : nl2br(tep_output_string_protected($statuses['comments']))) . '</td>' . "\n" .
                             '              </tr>' . "\n";
                  }
                  ?>
                </table>
              </td>
            </tr>
          </table>
        </fieldset>
   </td>
 </tr>

 <tr>
   <td>
     <fieldset>
     <legend><?php echo PDF_INVOICE; ?></legend>
       <table border="0" width="100%" cellspacing="1" cellpadding="2">
          <tr>
            <td  class="main">
              <?php echo '' . PDF_DOWNLOAD_LINK . ' <a href="' . tep_href_link(FILENAME_CUSTOMER_PDF, 'order_id=' . $HTTP_GET_VARS['order_id']) . '" target="_blank"> ' . tep_image(DIR_WS_TEMPLATES.'images/misc/icons/pdf.png') . '</a>'; ?>
            </td>
          </tr>
       </table>
     </fieldset>
  </td>
 </tr>

	<?php
// }
 ?>
 <!-- end pdf //-->

  <?php if ($language == 'polish') { ?>
  <?php
  if (CUSTOMER_PROFORMA == 'true' && $order->info['currency'] == 'PLN') {
    ?>
    <tr>
      <td>
        <fieldset>
        <legend><?php echo ICON_PDF_PROFORMA_INVOICE; ?></legend>
          <table border="0" width="100%" cellspacing="1" cellpadding="2">
            <tr>
              <td  class="main">
                <?php echo PDF_PROFORMA_INVOICE .' ';
				// obliczanie unikalnego ID
				$nr_zamow = (int)$_GET['order_id'];
				$nr_klienta = (int)$customer_id;
				$oblicz_id = ($nr_zamow+489)+(($nr_klienta*3)+511)+tep_date_unix($order->info['date_purchased']);
				//				
				if (file_exists('administracja/'.POLISH_INVOICE_PDF_ARCHIVE.'faktura_zam_'.$oblicz_id.'_proforma.pdf')) {
				  echo '<a href="administracja/'.POLISH_INVOICE_PDF_ARCHIVE.'faktura_zam_'.$oblicz_id.'_proforma.pdf" TARGET="_blank">' . tep_image(DIR_WS_TEMPLATES . '/images/misc/icons/faktura_f_pdf.gif', ICON_PDF_PROFORMA_INVOICE) . '</a>&nbsp;';
				 } else {		  
				  echo '<a href="' . tep_href_link('pdffaktura_customer.php', 'type=3&order_id=' .(int)$_GET['order_id']) . '" TARGET="_blank">' . tep_image(DIR_WS_TEMPLATES . '/images/misc/icons/faktura_f_pdf.gif', ICON_PDF_PROFORMA_INVOICE) . '</a>';
				}
				?>
              </td>
            </tr>
          </table>
        </fieldset>
      </td>
    </tr>
  <?php } } ?>

 <?php
 if (DOWNLOAD_ENABLED == 'true') {
   include(DIR_WS_MODULES . 'downloads.php');
 } ?>
 <tr>
  <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '3'); ?></td>
 </tr>

 <!-- Przyciski BOF -->
 <tr>
  <td>
    <fieldset>
      <table border="0" width="100%" cellspacing="0" cellpadding="0">
        <tr>
          <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
          <td><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY, tep_get_all_get_params(array('order_id')), 'SSL') . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?></td>
          <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
        </tr>
      </table>
    </fieldset>
  </td>
 </tr>
 <!-- Przyciski EOF -->

</table>