<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   design_default
 * @package    Mage_Bundle
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * @see Mage_Bundle_Block_Adminhtml_Sales_Order_View_Items_Renderer
 */
?>

<?php $_item = $this->getItem() ?>
<?php $items = array_merge(array($_item), $_item->getChildrenItems()); ?>
<?php $_count = count ($items) ?>
<?php $_index = 0 ?>

<?php $_prevOptionId = '' ?>

<?php if($this->getOrderOptions() || $_item->getDescription() || $this->canDisplayGiftmessage()): ?>
    <?php $_showlastRow = true ?>
<?php else: ?>
    <?php $_showlastRow = false ?>
<?php endif; ?>

<?php foreach ($items as $_item): ?>
    <?php $this->setPriceDataObject($_item) ?>
    <?php $attributes = $this->getSelectionAttributes($_item) ?>
    <?php if ($_item->getParentItem()): ?>
        <?php if ($_prevOptionId != $attributes['option_id']): ?>
        <tr>
            <td><div class="option-label"><?php echo $attributes['option_label'] ?></div></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td class="last">&nbsp;</td>
        </tr>
        <?php $_prevOptionId = $attributes['option_id'] ?>
        <?php endif; ?>
    <?php endif; ?>
    <tr<?php echo (++$_index==$_count && !$_showlastRow)?' class="border"':'' ?>>
        <?php if (!$_item->getParentItem()): ?>
        <td>
            <h5 class="title"><?php echo $this->htmlEscape($_item->getName()) ?></h5>
            <div>
                <strong><?php echo $this->helper('sales')->__('SKU') ?>:</strong>
                <?php echo implode('<br />', Mage::helper('catalog')->splitSku($_item->getSku())); ?>
            </div>
        </td>
        <?php else: ?>
        <td><div class="option-value"><?php echo $this->getValueHtml($_item)?></div></td>
        <?php endif; ?>
        <td class="a-center">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php echo $_item->getStatus() ?>
            <?php else: ?>
                &nbsp;
            <?php endif; ?>
        </td>
        <td class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php echo $this->displayPriceAttribute('original_price') ?>
            <?php else: ?>
                &nbsp;
            <?php endif; ?>
        </td>
        <td class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
                    <span class="price-excl-tax">
                                            <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                          <span class="label"><?php echo $this->helper('tax')->__('Excl. Tax'); ?>:</span>
                      <?php endif; ?>
                      <?php echo $this->displayPriceAttribute('price') ?>
                    </span>
                <?php endif; ?>
                <?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
                    <span class="price-incl-tax">
                                            <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                          <span class="label"><?php echo $this->helper('tax')->__('Incl. Tax'); ?>:</span>
                      <?php endif; ?>
                      <?php echo $this->displayPriceInclTax($_item); ?>
                    </span>
                <?php endif; ?>
                <?php else: ?>
                    &nbsp;
            <?php endif; ?>
        </td>
        <td>
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <table cellspacing="0" class="qty-table">
                    <tr>
                        <td><?php echo Mage::helper('sales')->__('Ordered') ?></td>
                        <td><strong><?php echo $_item->getQtyOrdered()*1 ?></strong></td>
                    </tr>
                    <?php if ((float) $_item->getQtyInvoiced()): ?>
                    <tr>
                        <td><?php echo Mage::helper('sales')->__('Invoiced') ?></td>
                        <td><strong><?php echo $_item->getQtyInvoiced()*1 ?></strong></td>
                    </tr>
                    <?php endif; ?>
                    <?php if ((float) $_item->getQtyShipped() && $this->isShipmentSeparately($_item)): ?>
                    <tr>
                        <td><?php echo Mage::helper('sales')->__('Shipped') ?></td>
                        <td><strong><?php echo $_item->getQtyShipped()*1 ?></strong></td>
                    </tr>
                    <?php endif; ?>
                    <?php if ((float) $_item->getQtyRefunded()): ?>
                    <tr>
                        <td><?php echo Mage::helper('sales')->__('Refunded') ?></td>
                        <td><strong><?php echo $_item->getQtyRefunded()*1 ?></strong></td>
                    </tr>
                    <?php endif; ?>
                    <?php if ((float) $_item->getQtyCanceled()): ?>
                    <tr>
                        <td><?php echo Mage::helper('sales')->__('Canceled') ?></td>
                        <td><strong><?php echo $_item->getQtyCanceled()*1 ?></strong></td>
                    </tr>
                    <?php endif; ?>
                </table>
            <?php elseif ($this->isShipmentSeparately($_item)): ?>
                <table cellspacing="0" class="qty-table">
                    <tr>
                        <td><?php echo Mage::helper('sales')->__('Ordered') ?></td>
                        <td><strong><?php echo $_item->getQtyOrdered()*1 ?></strong></td>
                    </tr>
                    <?php if ((float) $_item->getQtyShipped()): ?>
                    <tr>
                        <td><?php echo Mage::helper('sales')->__('Shipped') ?></td>
                        <td><strong><?php echo $_item->getQtyShipped()*1 ?></strong></td>
                    </tr>
                    <?php endif; ?>
                </table>
            <?php else: ?>
                &nbsp;
            <?php endif; ?>
        </td>
        <td class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
                    <span class="price-excl-tax">
                                            <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                          <span class="label"><?php echo $this->helper('tax')->__('Excl. Tax'); ?>:</span>
                      <?php endif; ?>
                      <?php echo $this->displayPriceAttribute('row_total') ?>
                    </span>
                <?php endif; ?>
                <?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
                    <span class="price-incl-tax">
                                            <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                          <span class="label"><?php echo $this->helper('tax')->__('Incl. Tax'); ?>:</span>
                      <?php endif; ?>
                      <?php echo $this->displaySubtotalInclTax($_item); ?>
                    </span>
                <?php endif; ?>
            <?php else: ?>
                &nbsp;
            <?php endif; ?>
        </td>
        <td class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php echo $this->displayPriceAttribute('tax_amount') ?>
            <?php else: ?>
                &nbsp;
            <?php endif; ?>
        </td>

        <td class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php echo $this->displayTaxPercent($_item) ?>
            <?php else: ?>
                &nbsp;
            <?php endif; ?>
        </td>
        <td class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php echo $this->displayPriceAttribute('discount_amount') ?>
            <?php else: ?>
                &nbsp;
            <?php endif; ?>
        </td>
        <td class="a-right last">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php echo $this->displayPrices(
                    $_item->getBaseRowTotal() - $_item->getBaseDiscountAmount() + $_item->getBaseTaxAmount(),
                    $_item->getRowTotal() - $_item->getDiscountAmount() + $_item->getTaxAmount()
                ); ?>
            <?php else: ?>
                &nbsp;
            <?php endif; ?>
        </td>
    </tr>
<?php endforeach; ?>
<?php if($_showlastRow): ?>
    <tr<?php if (!$this->canDisplayGiftmessage()) echo ' class="border"' ?>>
        <td>
                        <?php if ($this->getOrderOptions()): ?>
                <dl class="item-options">
                <?php foreach ($this->getOrderOptions() as $option): ?>
                    <dt><?php echo $option['label'] ?>:</dt>
                    <dd>
                        <?php echo $this->htmlEscape(Mage::helper('core/string')->truncate($option['value'], 55, '', $_remainder));?>
                        <?php if ($_remainder):?>
                            ... <span id="<?php echo $_id = 'id' . uniqid()?>"><?php echo $this->htmlEscape($_remainder) ?></span>
                            <script type="text/javascript">
                            $('<?php echo $_id ?>').hide();
                            $('<?php echo $_id ?>').up().observe('mouseover', function(){$('<?php echo $_id ?>').show();});
                            $('<?php echo $_id ?>').up().observe('mouseout',  function(){$('<?php echo $_id ?>').hide();});
                            </script>
                        <?php endif;?>
                    </dd>
                <?php endforeach; ?>
                </dl>
            <?php else: ?>
                &nbsp;
            <?php endif; ?>
            <?php echo $_item->getDescription() ?>
        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td class="last">&nbsp;</td>
    </tr>
    <?php if ($this->canDisplayGiftmessage()): ?>
    <tr class="border">
        <td class="giftmessage-single-item">
            <?php if ($this->canDisplayContainer()): ?>
            <div id="<?php echo $this->getHtmlId() ?>" class="item-container">
            <?php endif; ?>
            <div class="item-text">
                <a class="action-link" href="#" onclick="return giftMessagesController.toogleGiftMessage('<?php echo $this->getHtmlId() ?>')">
                <span class="default-text">
                    <span class="add"<?php if($this->getMessage()->getId()): ?> style="display:none;"<?php endif;?>><?php echo $this->helper('sales')->__('Add Gift Messsage') ?></span>
                    <span class="edit"<?php if(!$this->getMessage()->getId()): ?> style="display:none;"<?php endif;?>><?php echo $this->helper('sales')->__('Edit Gift Messsage') ?></span></span><span class="close-text" style="display:none;"><?php echo $this->helper('sales')->__('Save and Close Message') ?></span></a>
            </div>
            <div class="gift-form" style="display:none;" id="<?php echo $this->getFieldId('edit') ?>">
            <form id="<?php echo $this->getFieldId('form') ?>" action="<?php echo $this->getSaveUrl() ?>">
                <div class="entry-edit">
                    <fieldset>
                        <input type="hidden" id="<?php echo $this->getFieldId('type') ?>" name="<?php echo $this->getFieldName('type') ?>" value="order_item"/>
                        <span class="field-row">
                            <label for="<?php echo $this->getFieldId('sender') ?>"><?php echo $this->helper('sales')->__('From Name') ?></label><br />
                            <input class="input-text" type="text" id="<?php echo $this->getFieldId('sender') ?>" name="<?php echo $this->getFieldName('sender') ?>" value="<?php echo $this->htmlEscape($this->getMessage()->getSender()) ?>"/>
                        </span>
                        <span class="field-row">
                            <label for="<?php echo $this->getFieldId('recipient') ?>"><?php echo $this->helper('sales')->__('To Name') ?></label><br />
                            <input class="input-text" type="text" id="<?php echo $this->getFieldId('recipient') ?>" name="<?php echo $this->getFieldName('recipient') ?>"  value="<?php echo $this->htmlEscape($this->getMessage()->getRecipient()) ?>"/>
                        </span>
                        <div class="clear"></div>
                        <span class="field-row last">
                            <label for="<?php echo $this->getFieldId('message') ?>"><?php echo $this->helper('sales')->__('Gift Message') ?></label><br />
                            <textarea id="<?php echo $this->getFieldId('message') ?>" onchange="giftMessagesController.toogleRequired('<?php echo $this->getFieldId('message') ?>', ['<?php echo $this->getFieldId('sender') ?>','<?php echo $this->getFieldId('recipient') ?>']);" name="<?php echo $this->getFieldName('message') ?>" rows="3" cols="5"><?php echo $this->htmlEscape($this->getMessage()->getMessage()) ?></textarea>
                        </span>
                    </fieldset>
                </div>
            </form>
            </div>
            <?php if ($this->canDisplayContainer()): ?>
            </div>
            <?php endif ?>
        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td class="last">&nbsp;</td>
    </tr>
    <?php endif; ?>
<?php endif; ?>
