<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 
/**
* @version $Id: order.order_print.php,v 1.8 2005/01/27 19:34:02 soeren_nb Exp $
* @package mambo-phpShop
* @subpackage HTML
* Contains code from PHPShop(tm):
* 	@copyright (C) 2000 - 2004 Edikon Corporation (www.edikon.com)
*	Community: www.phpshop.org, forums.phpshop.org
* Conversion to Mambo and the rest:
* 	@copyright (C) 2004-2005 Soeren Eberhardt
*
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* mambo-phpShop is Free Software.
* mambo-phpShop comes with absolute no warranty.
*
* www.mambo-phpshop.net
*/
mm_showMyFileName( __FILE__ );

require_once(CLASSPATH.'ps_product.php');
$ps_product = new ps_product;

if (!is_numeric($_REQUEST['order_id']))
    die ('Please provide a valid Order ID!');
else
    $order_id = $_REQUEST['order_id'];
    
$q = "SELECT * FROM #__pshop_orders WHERE order_id='$order_id'";
$db->query($q);
$db->next_record();

$navi_db = new ps_DB;

$navigation = "<br /><center>\n<strong>\n";
$q = "SELECT order_id FROM #__pshop_orders WHERE ";
$q .= "order_id < '$order_id' ORDER BY order_id DESC";
$navi_db->query($q);
$navi_db->next_record();
if ($navi_db->f("order_id")) {
   $url = $_SERVER['PHP_SELF'] . "?page=$modulename.order_print&order_id=";
   $url .= $navi_db->f("order_id");
   $navigation .= "<a class=\"pagenav\" href=\"" . $sess->url($url) . "\">" ._ITEM_PREVIOUS."</a> | ";
} else
   $navigation .= "<span class=\"pagenav\">" ._ITEM_PREVIOUS." | </span>";

$q = "SELECT order_id FROM #__pshop_orders WHERE ";
$q .= "order_id > '$order_id' ORDER BY order_id";
$navi_db->query($q);
$navi_db->next_record();
if ($navi_db->f("order_id")) {
   $url = $_SERVER['PHP_SELF'] . "?page=$modulename.order_print&order_id=";
   $url .= $navi_db->f("order_id");
   $navigation .= "<a class=\"pagenav\" href=\"" . $sess->url($url) ."\">". _ITEM_NEXT."</a>";
} else
   $navigation .= "<span class=\"pagenav\">"._ITEM_NEXT."</span>";

$navigation .= "\n<strong>\n</center>\n";
echo $navigation;
?>

<div align="center"><br />
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="1">
  <tr> 
    <td height="118"> 
      <table width="100%" border="0" cellspacing="0" cellpadding="1">
        <tr class="sectiontableheader"> 
          <th width="26%"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_PO_LBL ?></th>
          <th width="74%"><strong>&nbsp;</strong></th
        </tr>
        <tr> 
          <td width="26%"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_PO_NUMBER ?>:</strong></td>
          <td width="74%"><?php printf("%08d", $db->f("order_id"));?></td>
        </tr>
        <tr> 
          <td width="26%"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_PO_DATE ?>:</strong></td>
          <td width="74%"><?php echo date("d-M-Y:H:i", $db->f("cdate"));?></td>
        </tr>
        <tr> 
          <td width="26%"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_PO_STATUS ?>:</strong></td>
          <td width="74%">
            <form method="post" action="<?php echo SECUREURL ?>administrator/index2.php"><?php 
            $ps_order_status->list_order_status($db->f("order_status")); ?>
              <input type="submit" class="button" name="Submit" value="Update Status" />
              <input type="hidden" name="page" value="order.order_print" />
              <input type="hidden" name="func" value="orderStatusSet" />
              <input type="hidden" name="option" value="com_phpshop" />
              <input type="hidden" name="order_id" value="<?php echo $order_id ?>" />
            </form>
          </td>
        </tr>
        <tr>
        <td width="26%"><strong>IP-ADDRESS:</strong></td>
        <td width="74%"><?php $db->p("ip_address"); ?></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr> 
    <td>&nbsp; </td>
  </tr><?php
    $user_id = $db->f("user_id");
    $dbt = new ps_DB;
    $qt = "SELECT * from #__pshop_order_user_info WHERE user_id='$user_id' ORDER BY address_type ASC"; 
    $dbt->query($qt);
    $dbt->next_record();
 ?> 
  <tr> 
    <td> 
      <table width="100%" border="0" cellspacing="0" cellpadding="1">
        <tr class="sectiontableheader"> 
          <th colspan="2"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_CUST_INFO_LBL ?></th>
        </tr>
        <tr class="sectiontableheader"> 
          <th width="48%" valign="top"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_BILL_TO_LBL ?></th>
          <th width="52%" valign="top"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_SHIP_TO_LBL ?></th>
        </tr>
        <tr> 
          <td width="48%" valign="top">
            <table width="100%" border="0" cellspacing="0" cellpadding="1">
              <tr> 
                <td width="35%" align="right">&nbsp;<?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_NAME ?>:</td>
                <td width="65%"><?php
                    if ($dbt->f("title")) {
                      echo $dbt->f("title") . " ";
                    }
                    echo $dbt->f("first_name") . " ";
                    if ($dbt->f("middle_name")) {
                      echo $dbt->f("middle_name") . " ";
                    }
                    echo $dbt->f("last_name");?>
                </td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_COMPANY ?>:</strong></td>
                <td width="65%"><?php
                    echo $dbt->p("company");
                    ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_ADDRESS_1 ?>:</strong></td>
                <td width="65%"><?php
                    echo $dbt->p("address_1");
                    ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_ADDRESS_2 ?>:</strong></td>
                <td width="65%"><?php
                    echo $dbt->p("address_2");
                    ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_CITY ?>:</strong></td>
                <td width="65%"><?php
                    echo $dbt->p("city");
                    ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_STATE ?>:</strong></td>
                <td width="65%"><?php
                    echo $dbt->p("state");
                    ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_ZIP ?>:</strong></td>
                <td width="65%"><?php
                    echo $dbt->p("zip");
                    ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_COUNTRY ?>:</strong></td>
                <td width="65%"><?php
                    echo $dbt->p("country");
                    ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_PHONE ?>:</strong></td>
                <td width="65%"><?php
                    echo $dbt->p("phone_1");
                    ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_FAX ?>:</strong></td>
                <td width="65%"><?php
                    echo $dbt->p("fax");
                    ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_EMAIL ?>:</strong></td>
                <td width="65%"><?php
                    echo $dbt->p("email");
                    ?></td>
              </tr>
            </table>
          </td>
          <td width="52%" valign="top">
<?php
// Get Ship To Address
$dbt->next_record();
?> 
            <table width="100%" border="0" cellspacing="0" cellpadding="1">
              <tr> 
                <td width="35%" align="right">&nbsp;<?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_NAME ?>:</td>
                <td width="65%"><?php
                    if ($dbt->f("title")) {
                      echo $dbt->f("title") . " ";
                    }
                    echo $dbt->f("first_name") . " ";
                    if ($dbt->f("middle_name")) {
                      echo $dbt->f("middle_name") . " ";
                    }
                    echo $dbt->f("last_name");
                ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_COMPANY ?>:</strong></td>
                <td width="65%"><?php
                    echo $dbt->p("company");
                    ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_ADDRESS_1 ?>:</strong></td>
                <td width="65%"><?php $dbt->p("address_1") ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_ADDRESS_2 ?>:</strong></td>
                <td width="65%"><?php $dbt->p("address_2")  ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_CITY ?>:</strong></td>
                <td width="65%"><?php $dbt->p("city") ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_STATE ?>:</strong></td>
                <td width="65%"><?php $dbt->p("state") ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_ZIP ?>:</strong></td>
                <td width="65%"><?php $dbt->p("zip") ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_COUNTRY ?>:</strong></td>
                <td width="65%"><?php $dbt->p("country") ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_PHONE ?>:</strong></td>
                <td width="65%"><?php $dbt->p("phone_1") ?></td>
              </tr>
              <tr> 
                <td width="35%" align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_FAX ?>:</strong></td>
                <td width="65%"><?php $dbt->p("fax") ?></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
  </tr>
  <?php 
  if( $db->f("ship_method_id") ) { ?>
  <tr>
      <td>
        <table width="100%">
          <tr class="sectiontableheader"> 
            <th ><?php 
                    $details = explode( "|", $db->f("ship_method_id"));
                    echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_SHIPPING_LBL ?>
            </th>
            <th><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_CUSTOMER_NOTE ?>
            </th>
          </tr>
          <tr> 
            <td width="50%">
                <?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_SHIPPING_CARRIER_LBL ?>: 
                <?php  echo $details[0]; ?>&nbsp;</td>
                
            <td valign="top" width="50%" rowspan="4"><?php
              if( $db->f("customer_note") ) {
                echo nl2br( $db->f("customer_note") );
              }
              else
                echo " ./. ";
                  
              ?>&nbsp;
            </td>
          </tr>
          <tr>
            <td width="50%"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_SHIPPING_MODE_LBL ?>: 
              <?php echo $details[1]; ?></td>
            
          </tr>
          <tr>
            <td width="50%"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_SHIPPING_PRICE_LBL ?>: 
            <?php echo $CURRENCY_DISPLAY->getFullValue($details[2]); ?>
            </td>

            </tr>
            </td>
        </tr>
      </table>
    </td>
  </tr>
  <?php
  }
  ?>
  <tr> 
    <td>&nbsp;</td>
  </tr>
  <tr class="sectiontableheader"> 
    <th align="center"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_ITEMS_LBL ?></th>
  </tr>
  <tr> 
    <td> 
      <table  class="adminlist">
        <tr > 
          <th width="5%"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_QUANTITY ?></th>
          <th width="42%"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_NAME ?></th>
          <th width="9%"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_SKU ?></th>
          <th width="12%"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_PRICE ?></th>
          <th width="19%"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_TOTAL ?></th>
        </tr>
        <?php
        $dbt = new ps_DB;
        $qt  = "SELECT * from #__pshop_order_item ";
        $qt .= "WHERE #__pshop_order_item.order_id='$order_id' ";
        $dbt->query($qt);
        $i = 0;
        
        while ($dbt->next_record()){
          if ($i++ % 2) 
             $bgcolor=SEARCH_COLOR_1;
          else
            $bgcolor=SEARCH_COLOR_2;
        ?><tr bgcolor="<?php echo $bgcolor; ?>" valign="top"> 
          <td width="5%"> <?php $dbt->p("product_quantity") ?></td>
          <td width="42%"><?php 
            
            $dbt->p("order_item_name"); 
            echo "<br /><font size=\"-2\">" . $dbt->f("product_attribute") . "</font>"; 

            ?></td>
            <td width="9%"><?php  $dbt->p("order_item_sku") ?>&nbsp;</td>
            <td width="12%" align="right"> <?php 
                $price_info = $ps_product->get_price($dbt->f("product_id"));
                echo $CURRENCY_DISPLAY->getFullValue($dbt->f("product_item_price"));
                ?> 
            </td>
            <td width="19%"><?php 
                $t = $dbt->f("product_quantity") * $dbt->f("product_item_price");
                echo $CURRENCY_DISPLAY->getFullValue($t); ?>
            </td>
        </tr>
        <?php 
        } 
        ?> 
        <tr> 
          <td colspan="5">&nbsp; </td>
        </tr>
        <tr> 
          <td width="5%">&nbsp;</td>
          <td width="42%">&nbsp;</td>
          <td colspan="2"><div align="right"><strong> <?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_SUBTOTAL ?>: </strong></div></td>
          <td width="19%"><div align="right"><?php echo $CURRENCY_DISPLAY->getFullValue($db->f("order_subtotal")); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></td>
        </tr>
<?php
        /* COUPON DISCOUNT */
      $coupon_discount = $db->f("coupon_discount");
      

      if( PAYMENT_DISCOUNT_BEFORE == '1') {
        if ($db->f("order_discount") != 0) {
?>
        <tr>
           <td width="5%">&nbsp;</td>
          <td width="42%">&nbsp;</td>
          <td colspan="2"><div  align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_PAYMENT_METHOD_LIST_DISCOUNT ?>:</div></strong></td>
          <td width="19%"><div  align="right"><?php
                if ($db->f("order_discount") > 0 )
               echo "-" . $CURRENCY_DISPLAY->getFullValue(abs($db->f("order_discount")));
          elseif ($db->f("order_discount") < 0 )
               echo "+" . $CURRENCY_DISPLAY->getFullValue(abs($db->f("order_discount"))); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
            </td>
        </tr>
        
        <?php 
        } 
        if( $coupon_discount > 0 || $coupon_discount < 0) {
?>
        <tr>
          <td colspan="4"><div align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_COUPON_DISCOUNT ?>:</div>
          </td> 
          <td><div align="right"><?php
            echo "- ".$CURRENCY_DISPLAY->getFullValue( $coupon_discount ); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
          </td>
        </tr>
        <?php
        }
      }
?>
        
        <tr> 
          <td width="5%">&nbsp;</td>
          <td width="42%">&nbsp;</td>
          <td colspan="2"><div align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_TOTAL_TAX ?>: </div></strong></td>
          <td width="19%"><div align="right"><?php echo $CURRENCY_DISPLAY->getFullValue($db->f("order_tax")) ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></td>
        </tr>
        <tr> 
          <td width="5%">&nbsp;</td>
          <td width="42%">&nbsp;</td>
          <td colspan="2"><div align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_SHIPPING ?>: </div></strong></td>
          <td width="19%"><div align="right"><?php echo $CURRENCY_DISPLAY->getFullValue($db->f("order_shipping")) ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></td>
        </tr>
        <tr> 
          <td width="5%">&nbsp;</td>
          <td width="42%">&nbsp;</td>
          <td colspan="2"><div align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_SHIPPING_TAX ?>: </div></strong></td>
          <td width="19%"><div align="right"><?php echo $CURRENCY_DISPLAY->getFullValue($db->f("order_shipping_tax")) ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></td>
        </tr>
<?php
      if( PAYMENT_DISCOUNT_BEFORE != '1') {
        if ($db->f("order_discount") != 0) {
?>
        <tr> 
          <td width="5%">&nbsp;</td>
          <td width="42%">&nbsp;</td>
          <td colspan="2"><div align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_PAYMENT_METHOD_LIST_DISCOUNT ?>:</div></strong></td>
          <td width="19%"><div align="right"><?php
                if ($db->f("order_discount") > 0 )
               echo "-" . $CURRENCY_DISPLAY->getFullValue(abs($db->f("order_discount")));
          elseif ($db->f("order_discount") < 0 )
               echo "+" . $CURRENCY_DISPLAY->getFullValue(abs($db->f("order_discount"))); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
            </td>
        </tr>
        
        <?php 
        } 
        if( $coupon_discount > 0 || $coupon_discount < 0) {
?>
        <tr> 
          <td width="5%">&nbsp;</td>
          <td width="42%">&nbsp;</td>
          <td colspan="2"><div align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_COUPON_DISCOUNT ?>:</div></strong>
          </td> 
          <td><div align="right"><?php
            echo "- ".$CURRENCY_DISPLAY->getFullValue( $coupon_discount ); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
          </td>
        </tr>
        <?php
        }
      }
?>
        <tr>
          <td width="5%">&nbsp;</td>
          <td width="42%">&nbsp;</td>
          <td colspan="2"><div align="right"><strong><?php echo $PHPSHOP_LANG->_PHPSHOP_CART_TOTAL ?>:</div> </strong></td>
          <td width="19%"><div align="right"><strong><?php echo $CURRENCY_DISPLAY->getFullValue($db->f("order_total")); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></strong>
            </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
  </tr>
  <tr> 
    <td> 
      <table width="100%" border="0" cellspacing="0" cellpadding="1">
        <tr class="sectiontableheader"> 
          <th width="13%"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_PAYMENT_LBL ?></th>
          <th width="40%"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_ACCOUNT_NAME ?></th>
          <th width="30%"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_ACCOUNT_NUMBER;
              $dbpm = new ps_DB;
              $q  = "SELECT * FROM #__pshop_payment_method, #__pshop_order_payment WHERE #__pshop_order_payment.order_id='$order_id' ";
              $q .= "AND #__pshop_payment_method.payment_method_id=#__pshop_order_payment.payment_method_id";
              $dbpm->query($q);
              $dbpm->next_record();
             
              // DECODE Account Number
              $dbaccount = new ps_DB;
             $q = "SELECT DECODE(order_payment_number,'".ENCODE_KEY."') 
                  as account_number from #__pshop_order_payment  
                  where order_id='".$order_id."'";
              $dbaccount->query($q);
              $dbaccount->next_record();
            ?> 
            </th>
          <th width="17%"><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_EXPIRE_DATE ?></th>
        </tr>
        <tr> 
          <td width="13%"><?php $dbpm->p("payment_method_name");?> </td>
          <td width="40%"><?php $dbpm->p("order_payment_name");?></td>
          <td width="30%"><?php $dbaccount->p("account_number");?></td>
          <td width="17%"><?php echo date("M-Y", $dbpm->f("order_payment_expire")); ?></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
  </tr>
    <tr> 
    <td>&nbsp;</td>
  </tr>
  <tr class="sectiontableheader"> 
    <th><?php echo $PHPSHOP_LANG->_PHPSHOP_ORDER_PRINT_PAYMENT_LOG_LBL ?></th>
  </tr>
  <tr> 
    <td><?php $dbpm->p("order_payment_log"); ?></td>
  </tr>
</table>
