<?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
 * @package     base_default
 * @copyright   Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
/* @var $this Mage_Shipping_Block_Tracking_Popup */
?>
<?php  $_results = $this->getTrackingInfo() ?>
<div class="page-title title-buttons">
    <h1><?php echo $this->__('Tracking Information'); ?></h1>
    <button class="button" onclick="window.close(); window.opener.focus();"><span><span><?php echo $this->__('Close Window') ?></span></span></button>
</div>
<?php if(sizeof($_results)>0): ?>
<?php foreach($_results as $shipid => $_result): ?>
    <?php if($shipid): ?>
    <h2 class="sub-title"><?php echo $this->__('Shipment #').$shipid; ?></h2>
    <?php endif; ?>
    <?php if(sizeof($_result)>0): ?>
        <?php $rowCount = sizeof($_result); $counter = 1; ?>
        <?php $_id = 0; foreach($_result as $track): ?>
            <table class="tracking-table-popup data-table" id="tracking-table-popup-<?php echo $_id ?>">
                <col width="15%" />
                <col />
                <tbody>
                <?php if(is_object($track)): ?>
                    <tr>
                        <th class="label"><?php echo $this->__('Tracking Number:'); ?></th>
                        <td class="value"><?php echo $track->getTracking(); ?></td>
                    </tr>
                    <?php if ($track->getCarrierTitle()): ?>
                    <tr>
                        <th class="label"><?php echo $this->__('Carrier:'); ?></th>
                        <td class="value"><?php echo $track->getCarrierTitle(); ?></td>
                    </tr>
                    <?php endif; ?>
                    <?php if($track->getErrorMessage()): ?>
                    <tr>
                        <th class="label"><?php echo $this->__('Error:'); ?></th>
                        <td class="error"><?php echo $this->__('Tracking information is currently not available. Please '); if ($this->getContactUsEnabled()) : ?><a href="<?php echo $this->getContactUs() ?>" title="<?php echo $this->__('contact us') ?>" onclick="this.target='_blank'"><?php echo $this->__('contact us') ?></a><?php echo $this->__(' for more information or '); endif; echo $this->__('email us at '); ?><a href="mailto:<?php echo $this->getStoreSupportEmail() ?>"><?php echo $this->getStoreSupportEmail() ?></a></td>
                    </tr>
                    <?php elseif($track->getTrackSummary()): ?>
                    <tr>
                        <th class="label"><?php echo $this->__('Info:'); ?></th>
                        <td class="value"><?php echo $track->getTrackSummary(); ?></td>
                    </tr>
                    <?php elseif($track->getUrl()): ?>
                    <tr>
                        <th class="label"><?php echo $this->__('Track:'); ?></th>
                        <td class="value"><a href="<?php echo $track->getUrl(); ?>" onclick="this.target='_blank'"><?php echo $track->getUrl(); ?></a></td>
                    </tr>
                    <?php else: ?>
                        <?php if ($track->getStatus()): ?>
                        <tr>
                            <th class="label"><?php echo $this->__('Status:'); ?></th>
                            <td class="value"><?php echo $track->getStatus(); ?></td>
                        </tr>
                        <?php endif; ?>

                        <?php if ($track->getDeliverydate()): ?>
                        <tr>
                            <th class="label"><?php echo $this->__('Delivered on:'); ?></th>
                            <td class="value"><?php echo $this->formatDeliveryDateTime($track->getDeliverydate(),$track->getDeliverytime()); ?></td>
                        </tr>
                        <?php endif; ?>

                        <?php if ($track->getSignedby()): ?>
                        <tr>
                            <th class="label"><?php echo $this->__('Signed by:'); ?></th>
                            <td class="value"><?php echo $track->getSignedby(); ?></td>
                        </tr>
                        <?php endif; ?>

                        <?php if ($track->getDeliveryLocation()): ?>
                        <tr>
                            <th class="label"><?php echo $this->__('Delivered to:'); ?></th>
                            <td class="value"><?php echo $track->getDeliveryLocation(); ?></td>
                        </tr>
                        <?php endif; ?>

                        <?php if ($track->getShippedDate()): ?>
                        <tr>
                            <th class="label"><?php echo $this->__('Shipped or billed on:'); ?></th>
                            <td class="value"><?php echo $track->getShippedDate(); ?></td>
                        </tr>
                        <?php endif; ?>

                        <?php if ($track->getService()): ?>
                        <tr>
                            <th class="label"><?php echo $this->__('Service Type:'); ?></th>
                            <td class="value"><?php echo $track->getService(); ?></td>
                        </tr>
                        <?php endif; ?>

                        <?php if ($track->getWeight()): ?>
                        <tr>
                            <th class="label"><?php echo $this->__('Weight:'); ?></th>
                            <td class="value"><?php echo $track->getWeight(); ?></td>
                        </tr>
                        <?php endif; ?>
                    <?php endif; ?>
                <?php elseif(isset($track['title']) && isset($track['number']) && $track['number']): ?>
                    <!--if the tracking is custom value-->
                    <tr>
                        <th class="label"><?php echo ($track['title'] ? $this->escapeHtml($track['title']) : $this->__('N/A')); ?>:</th>
                        <td class="value"><?php echo (isset($track['number']) ? $this->escapeHtml($track['number']) : ''); ?></td>
                    </tr>
                <?php endif; ?>
                </tbody>
            </table>
            <script type="text/javascript">decorateTable('tracking-table-popup-<?php echo $_id++ ?>');</script>
            <?php if (is_object($track) && sizeof($track->getProgressdetail())>0): ?>
                <br />
                <table class="data-table" id="track-history-table-<?php echo $track->getTracking(); ?>">
                    <col />
                    <col width="1" />
                    <col width="1" />
                    <col />
                    <thead>
                        <tr>
                            <th><?php echo $this->__('Location') ?></th>
                            <th><?php echo $this->__('Date') ?></th>
                            <th><?php echo $this->__('Local Time') ?></th>
                            <th><?php echo $this->__('Description') ?></th>
                        </tr>
                   </thead>
                   <tbody>
                   <?php foreach($track->getProgressdetail() as $_detail): ?>
                    <?php $_detailDate = (isset($_detail['deliverydate']) ? $this->formatDeliveryDate($_detail['deliverydate']) : '') ?>
                    <?php $_detailTime = (isset($_detail['deliverytime']) ? $this->formatDeliveryTime($_detail['deliverytime'], $_detail['deliverydate']) : '') ?>
                        <tr>
                            <td><?php echo (isset($_detail['deliverylocation']) ? $_detail['deliverylocation'] : ''); ?></td>
                            <td><span class="nobr"><?php echo $_detailDate ?></span></td>
                            <td><span class="nobr"><?php echo $_detailTime ?></span></td>
                            <td><?php echo (isset($_detail['activity']) ? $_detail['activity'] : '') ?></td>
                        </tr>
                   <?php endforeach; ?>
                   </tbody>
                </table>
                <script type="text/javascript">decorateTable('track-history-table-<?php echo $track->getTracking(); ?>');</script>
            <?php endif; ?>
            <div class="divider"></div>
            <?php if($counter!=$rowCount): ?>
            <?php endif; ?>
            <?php $counter++; ?>
        <!--end for each tracking information-->
        <?php endforeach; ?>
    <?php else: ?>
        <p><?php echo $this->__('There is no tracking available for this shipment.'); ?></p>
    <?php endif; ?>

<?php endforeach; ?>
<?php else: ?>
    <p><?php echo $this->__('There is no tracking available.'); ?></p>
<?php endif; ?>
<div class="buttons-set">
    <button type="button" title="<?php echo $this->__('Close Window') ?>" class="button" onclick="window.close(); window.opener.focus();"><span><span><?php echo $this->__('Close Window') ?></span></span></button>
</div>
