<?php
/**
 * Maho
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-2024 The OpenMage Contributors (https://openmage.org)
 * @copyright   Copyright (c) 2024 Maho (https://mahocommerce.com)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php /** @var Mage_Adminhtml_Block_Sales_Order_Shipment_View_Tracking $this */ ?>
<div class="field-row grid" id="shipment_tracking_info">
<table cellspacing="0" class="data">
    <col width="100" />
    <col />
    <col />
    <col width="80" />
    <thead>
        <tr class="headings">
            <th><?= Mage::helper('sales')->__('Carrier') ?></th>
            <th><?= Mage::helper('sales')->__('Title') ?></th>
            <th><?= Mage::helper('sales')->__('Number') ?></th>
            <th class="last"><?= Mage::helper('sales')->__('Action') ?></th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <td>
                <select name="carrier" class="select" style="width:110px" onchange="selectCarrier(this)">
                    <?php foreach ($this->getCarriers() as $_code=>$_name): ?>
                    <option value="<?= $_code ?>"><?= $this->escapeHtml($_name) ?></option>
                    <?php endforeach ?>
                </select>
            </td>
            <td><input class="input-text" type="text" id="tracking_title" name="title" value="" /></td>
            <td><input class="input-text" type="text" id="tracking_number" name="number" value="" /></td>
            <td class="last"><?= $this->getSaveButtonHtml() ?></td>
        </tr>
    </tfoot>
<?php if($_tracks = $this->getShipment()->getAllTracks()): ?>
    <tbody>
    <?php $i=0;foreach ($_tracks as $_track):$i++ ?>
        <tr class="<?= ($i%2==0)?'even':'odd' ?>">
            <td><?= $this->escapeHtml($this->getCarrierTitle($_track->getCarrierCode())) ?></td>
            <td><?= $this->escapeHtml($_track->getTitle()) ?></td>
            <td>
                <?php if ($_track->isCustom()): ?>
                <?= $this->escapeHtml($_track->getNumber()) ?>
                <?php else: ?>
                <a href="#" onclick="popWin('<?= $this->helper('shipping')->getTrackingPopupUrlBySalesModel($_track) ?>','trackorder','width=800,height=600,resizable=yes,scrollbars=yes')"><?= $this->escapeHtml($_track->getNumber()) ?></a>
                <div id="shipment_tracking_info_response_<?= $_track->getId() ?>"></div>
                <?php endif ?>
            </td>
            <td class="last"><a href="#" onclick="deleteTrackingNumber('<?= $this->getRemoveUrl($_track) ?>'); return false;"><?= Mage::helper('sales')->__('Delete') ?></a></td>
        </tr>
    <?php endforeach ?>
    </tbody>
<?php endif ?>
</table>
</div>
<script type="text/javascript">
//<![CDATA[
function selectCarrier(elem) {
    var option = elem.options[elem.selectedIndex];
    $('tracking_title').value = option.value && option.value != 'custom' ? option.text : '';
}

function deleteTrackingNumber(url) {
    if (confirm('<?= Mage::helper('core')->jsQuoteEscape(Mage::helper('sales')->__('Are you sure?')) ?>')) {
        submitAndReloadArea($('shipment_tracking_info').parentNode, url)
    }
}
//]]>
</script>
