<?php
/**
 * OpenMage
 *
 * 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@magento.com so we can send you a copy immediately.
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
 ?>
<?php
$shippingMethod = $this->getShipment()->getOrder()->getShippingMethod();
$sizeSource = Mage::getModel('usa/shipping_carrier_usps_source_size')->toOptionArray();
$girthEnabled = Mage::helper('usa')->displayGirthValue($shippingMethod) && $this->isGirthAllowed() ? 1 : 0;
?>
<script type="text/javascript">
//<![CDATA[
document.observe("dom:loaded", function() {
    packaging = new Packaging(<?php echo $this->getConfigDataJson() ?>);
    packaging.changeContainerType($$('select[name=package_container]')[0]);
    packaging.checkSizeAndGirthParameter(
        $$('select[name=package_container]')[0],
        <?php echo $girthEnabled; ?>
    );
});
//]]>
</script>
<div id="popup-window-mask" style="display:none;"></div>
<div id="packaging_window" class="packaging-window" style="display:none;">
    <div class="entry-edit">
        <div class="entry-edit-head">
            <button type="button" class="scalable AddPackageBtn" onclick="packaging.newPackage();">
                <span><span><span><?php echo Mage::helper('sales')->__('Add Package') ?></span></span></span>
            </button>
            <h4 class="icon-head fieldset-legend"><?php echo Mage::helper('sales')->__('Create Packages') ?></h4>
        </div>
        <div class="packaging-content">
            <div class="messages" style="display:none;"></div>
            <div id="package_template" style="display:none;">
                <div class="package-number"><?php echo Mage::helper('sales')->__('Package') ?><span></span></div>
                <table class="package-options" cellspacing="0">
                    <thead>
                        <th><?php echo Mage::helper('sales')->__('Type') ?></th>
                        <?php if ($girthEnabled == 1): ?>
                            <th><?php echo Mage::helper('sales')->__('Size') ?></th>
                            <th><?php echo Mage::helper('sales')->__('Girth') ?></th>
                            <th>&nbsp;</th>
                        <?php endif ?>
                        <th <?php echo $this->displayCustomsValue() ? '' : 'style="display: none;"' ?>>
                            <?php echo Mage::helper('sales')->__('Customs Value') ?>
                        </th>
                        <th><?php echo Mage::helper('sales')->__('Total Weight') ?></th>
                        <th><?php echo Mage::helper('sales')->__('Length') ?></th>
                        <th><?php echo Mage::helper('sales')->__('Width') ?></th>
                        <th><?php echo Mage::helper('sales')->__('Height') ?></th>
                        <th>&nbsp;</th>
                        <?php if ($this->getDeliveryConfirmationTypes()): ?>
                            <th><?php echo Mage::helper('sales')->__('Signature Confirmation') ?></th>
                        <?php endif ?>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                    </thead>
                    <tbody>
                        <td>
                            <?php $containers = $this->getContainers(); ?>
                            <select name="package_container" onchange="packaging.changeContainerType(this);packaging.checkSizeAndGirthParameter(this, <?php echo  $girthEnabled ?>);"<?php if (empty($containers)):?>
                                title="<?php echo Mage::helper('sales')->__('Package types are disregarded for USPS domestic shipments.') ?>"
                                disabled="" class="disabled"
                            <?php endif ?>>
                                <?php foreach ($this->getContainers() as $key => $value): ?>
                                    <option value="<?php echo $key ?>" >
                                        <?php echo $value ?>
                                    </option>
                                <?php endforeach ?>
                            </select>
                        </td>
                        <?php if ($girthEnabled == 1): ?>
                            <td>
                                <select name="package_size" onchange="packaging.checkSizeAndGirthParameter(this, <?php echo  $girthEnabled ?>);">
                                    <?php foreach ($sizeSource as $key => $value): ?>
                                    <option value="<?php echo $sizeSource[$key]['value'] ?>">
                                        <?php echo $sizeSource[$key]['label'] ?>
                                    </option>
                                    <?php endforeach ?>
                                </select>
                            </td>
                            <td><input type="text" class="input-text validate-greater-than-zero" name="container_girth" /></td>
                            <td>
                                <select name="container_girth_dimension_units" class="options-units-dimensions measures" onchange="packaging.changeMeasures(this);">
                                    <option value="<?php echo Zend_Measure_Length::INCH ?>" selected="selected" ><?php echo Mage::helper('sales')->__('in') ?></option>
                                    <option value="<?php echo Zend_Measure_Length::CENTIMETER ?>" ><?php echo Mage::helper('sales')->__('cm') ?></option>
                                </select>
                            </td>
                        <?php endif ?>
                        <?php
                            if ($this->displayCustomsValue()) {
                                $customsValueDisplay = '';
                                $customsValueValidation = ' validate-zero-or-greater ';
                            } else {
                                $customsValueDisplay = ' style="display: none;" ';
                                $customsValueValidation = '';
                            }
                        ?>
                        <td <?php echo $customsValueDisplay ?>>
                            <input type="text" class="customs-value input-text <?php echo $customsValueValidation ?>" name="package_customs_value" />
                            <span class="customs-value-currency">[<?php echo $this->getCustomValueCurrencyCode(); ?>]</span>
                        </td>
                        <td>
                            <input type="text" class="options-weight input-text required-entry validate-greater-than-zero" name="container_weight" />
                            <select name="container_weight_units" class="options-units-weight measures" onchange="packaging.changeMeasures(this);">
                                <option value="<?php echo Zend_Measure_Weight::POUND ?>" selected="selected"  ><?php echo Mage::helper('sales')->__('lb') ?></option>
                                <option value="<?php echo Zend_Measure_Weight::KILOGRAM ?>" ><?php echo Mage::helper('sales')->__('kg') ?></option>
                            </select>
                        </td>
                        <td>
                            <input type="text" class="input-text validate-greater-than-zero" name="container_length" />
                        </td>
                        <td>
                            <input type="text" class="input-text validate-greater-than-zero" name="container_width" />
                        </td>
                        <td>
                            <input type="text" class="input-text validate-greater-than-zero" name="container_height" />
                        </td>
                        <td>
                            <select name="container_dimension_units" class="options-units-dimensions measures" onchange="packaging.changeMeasures(this);">
                                <option value="<?php echo Zend_Measure_Length::INCH ?>" selected="selected" ><?php echo Mage::helper('sales')->__('in') ?></option>
                                <option value="<?php echo Zend_Measure_Length::CENTIMETER ?>" ><?php echo Mage::helper('sales')->__('cm') ?></option>
                            </select>
                        </td>
                        <?php if ($this->getDeliveryConfirmationTypes()): ?>
                        <td>
                            <select name="delivery_confirmation_types">
                                <?php foreach ($this->getDeliveryConfirmationTypes() as $key => $value): ?>
                                    <option value="<?php echo $key ?>" >
                                        <?php echo $value ?>
                                    </option>
                                <?php endforeach ?>
                            </select>
                        </td>
                        <?php endif ?>
                        <td>
                            <button type="button" class="scalable AddItemsBtn" onclick="packaging.getItemsForPack(this);">
                                <span><span><span><?php echo Mage::helper('sales')->__('Add Products') ?></span></span></span>
                            </button>
                        </td>
                        <td>
                            <button type="button" class="scalable DeletePackageBtn" onclick="packaging.deletePackage(this);">
                                <span><span><span><?php echo Mage::helper('sales')->__('Delete Package') ?></span></span></span>
                            </button>
                        </td>
                    </tbody>
                </table>

                <?php if ($this->getContentTypes()): ?>
                <table class="package-options package-options-contents" cellspacing="0">
                    <colgroup>
                        <col width="150">
                        <col width="*">
                    </colgroup>
                    <thead>
                        <th><?php echo Mage::helper('sales')->__('Contents') ?></th>
                        <th><?php echo Mage::helper('sales')->__('Explanation') ?></th>
                    </thead>
                    <tbody>
                        <td>
                            <select name="content_type" onchange="packaging.changeContentTypes(this);">
                                <?php foreach ($this->getContentTypes() as $key => $value): ?>
                                    <option value="<?php echo $key ?>" >
                                        <?php echo $value ?>
                                    </option>
                                <?php endforeach ?>
                            </select>
                        </td>
                        <td>
                            <input name="content_type_other" type="text" class="input-text options-content-type disabled" disabled="disabled" />
                        </td>
                    </tbody>
                </table>
                <?php endif ?>

                <div class="package-add-products">
                    <div class="package_prapare" style="display:none">
                        <div class="entry-edit-head">
                            <button type="button" class="scalable AddSelectedBtn" onclick="packaging.packItems(this);">
                                <span><span><span><?php echo Mage::helper('sales')->__('Add Selected Product(s) to Package') ?></span></span></span>
                            </button>
                            <h4><?php echo Mage::helper('sales')->__('Please Select Products to Add') ?></h4>
                        </div>
                        <div class="grid_prepare"></div>
                    </div>
                </div>
            </div>
            <div id="packages_content"></div>
        </div>
        <div class="buttons-set a-right">
            <button type="button" class="scalable disabled SavePackagesBtn" disabled="disabled" onclick="packaging.confirmPackaging();" title="<?php echo Mage::helper('sales')->__('Products should be added to package(s)')?>">
                <span><span><span><?php echo Mage::helper('sales')->__('OK') ?></span></span></span>
            </button>
            <button type="button" class="scalable" onclick="packaging.cancelPackaging();">
                <span><span><span><?php echo Mage::helper('sales')->__('Cancel') ?></span></span></span>
            </button>
        </div>
    </div>
</div>
