<?php
/**
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the GNU General Public License (GPL 3)
 * that is bundled with this package in the file LICENSE.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Payone_Core to newer
 * versions in the future. If you wish to customize Payone_Core for your
 * needs please refer to http://www.payone.de for more information.
 *
 * @category        Payone
 * @package         design_frontend_base_default
 * @subpackage      template
 * @copyright       Copyright (c) 2013 <info@noovias.com> - www.noovias.com
 * @author          Alexander Dite <info@noovias.com>
 * @license         <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
 * @link            http://www.noovias.com
 */
?>
<?php
/** @var $this Payone_Core_Block_Payment_Method_Form_SafeInvoice_Klarna */
/** @var string $country */
$country = $this->getCountry();
/** @var Mage_Sales_Model_Quote $quote */
$quote = $this->getQuote();
/** @var Payone_Core_Model_Config_Payment_Method_Interface $paymentMethodConfig */
$paymentMethodConfig = $this->getPaymentMethodConfig();
?>
<?php if ($this->canShowAdditionalFields()): ?>
    <div id="payone_klarna_invoice_terms_div">
        <span id="payone_klarna_invoice_terms"></span>
    </div>
    <div id="payone_klarna_additional_fields">
        <ul>
            <?php if ($this->isDobRequired()): ?>
                <li class="fields">
                    <div class="field">
                        <label for="payone_klarna_additional_fields_customer_dob_month"
                               class="required"><em>*</em><?php echo $this->__('Date of birth (DD MM YYYY)') ?>
                        </label>
                        <br class="clear"/>
                        <select id="payone_klarna_additional_fields_customer_dob_day" class="required-entry"
                                style="width: 60px;" onchange="payoneKlarnaCustomerDobInput('payone_klarna_additional_fields_customer_dob_full')">
                            <option value="">--</option>
                            <?php for ($x = 1; $x <= 31; $x++): ?>
                                <option value="<?php echo sprintf('%02d', $x); ?>">
                                    <?php echo sprintf('%02d', $x); ?>
                                </option>
                            <?php endfor; ?>
                        </select>
                        <select id="payone_klarna_additional_fields_customer_dob_month" class="required-entry"
                                style="width: 60px;" onchange="payoneKlarnaCustomerDobInput('payone_klarna_additional_fields_customer_dob_full')">
                            <option value="">--</option>
                            <?php for ($x = 1; $x <= 12; $x++) : ?>
                                <option value="<?php echo sprintf('%02d', $x); ?>">
                                    <?php echo sprintf('%02d', $x); ?>
                                </option>
                            <?php endfor; ?>
                        </select>
                        <select id="payone_klarna_additional_fields_customer_dob_year" class="required-entry"
                                style="width: 60px;" onchange="payoneKlarnaCustomerDobInput('payone_klarna_additional_fields_customer_dob_full')">
                            <option value="">----</option>
                            <?php for ($x = date('Y'); $x > (date('Y') - 100); $x--) : ?>
                                <option value="<?php echo $x; ?>">
                                    <?php echo $x; ?>
                                </option>
                            <?php endfor; ?>
                        </select>

                        <div class="dob-full" style="display:none;">
                            <input type="hidden" id="payone_klarna_additional_fields_customer_dob_full"
                                   name="payment[payone_customer_dob]">
                        </div>
                    </div>
                </li>
            <?php endif;
            if ($this->isGenderRequired()) : ?>
                <li class="fields">
                    <div class="field">
                        <label for="payone_klarna_additional_fields_customer_gender" class="required">
                            <em>*</em> <?php echo $this->__('Gender') ?>
                        </label>
                        <br class="clear"/>
                        <select id="payone_klarna_additional_fields_customer_gender" class="required-entry"
                                name="payment[payone_customer_gender]">
                            <?php $genderOptions = $this->getGenderOptions();
                            foreach ($genderOptions as $genderOption): ?>
                                <option value="<?php echo $genderOption['value'] ?>">
                                    <?php echo $this->__($genderOption['label']) ?>
                                </option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </li>
            <?php endif;
            if ($this->isPersonalidRequired()) : ?>
                <li class="fields">
                    <div class="field">
                        <label for="payone_klarna_additional_fields_customer_personalid" class="required">
                            <em>*</em> <?php echo $this->__('Personal-ID') ?>
                        </label>
                        <br class="clear"/>
                        <input type="text" name="payment[payone_customer_personalid]"
                               id="payone_klarna_additional_fields_customer_personalid"
                               class="input-text required-entry"/>
                    </div>
                </li>
            <?php endif;
            if ($this->isBillingAddressAdditionRequired()) : ?>
                <li class="fields">
                    <div class="field">
                        <label for="payone_klarna_additional_fields_billing_addressaddition" class="required">
                            <em>*</em> <?php echo $this->__('House number extension (billing address)') ?>
                        </label>
                        <br class="clear"/>
                        <input type="text" name="payment[payone_billing_addressaddition]"
                               id="payone_klarna_additional_fields_billing_addressaddition"
                               class="input-text required-entry"/>
                    </div>
                </li>
            <?php endif;
            if ($this->isShippingAddressAdditionRequired()) : ?>
                <li class="fields">
                    <div class="field">
                        <label for="payone_klarna_additional_fields_shipping_addressaddition" class="required">
                            <em>*</em> <?php echo $this->__('House number extension (shipping address)') ?>
                        </label>
                        <br class="clear"/>
                        <input type="text" name="payment[payone_shipping_addressaddition]"
                               id="payone_klarna_additional_fields_shipping_addressaddition"
                               class="input-text required-entry"/>
                    </div>
                </li>
            <?php endif;
            if ($this->isTelephoneRequired()) : ?>
                <li class="fields">
                    <div class="field">
                        <label for="payone_klarna_additional_fields_customer_telephone" class="required">
                            <em>*</em><?php echo $this->__('Telephone') ?>
                        </label>
                        <br class="clear"/>
                        <input type="text" name="payment[payone_customer_telephone]"
                               id="payone_klarna_additional_fields_customer_telephone"
                               class="input-text required-entry"/>
                    </div>
                </li>
            <?php endif;
            if ($this->isAgreementCheckboxRequired()): ?>
                <li class="fields">
                    <div class="field">
                        <input type="checkbox" id="payone_klarna_additional_fields_agreement_checkbox"
                               class="checkbox required-entry"/>
                        <label for="payone_klarna_additional_fields_agreement_checkbox" class="required"
                               style="float:none;">
                            <?php if ($this->getCountry() == 'DE'): ?>
                                Mit der &Uuml;bermittlung der für die Abwicklung der gew&auml;hlten Klarna Zahlungsmethode und einer Identit&auml;ts- und Bonit&auml;tspr&uuml;fung
                                                                                                                                                                               erforderlichen Daten an Klarna bin ich einverstanden. Meine
                                <a href="https://cdn.klarna.com/1.0/shared/content/legal/terms/<?php echo $this->getKlarnaStoreId() ?>/de_de/consent"
                                   target="_blank">Einwilligung</a>
                                kann ich jederzeit mit Wirkung f&uuml;r die Zukunft
                                                                      widerrufen. Es gelten die AGB des H&auml;ndlers.
                            <?php endif; ?>
                            <?php if ($this->getCountry() == 'AT'): ?>
                                Mit der Datenverarbeitung der f&uuml;r die Abwicklung des Rechnungskaufes und einer Identit&auml;ts- und Bonit&auml;tspr&uuml;fung erforderlichen Daten durch Klarna
                                                                                                                                                              bin ich einverstanden. Meine
                                <a href="https://cdn.klarna.com/1.0/shared/content/legal/terms/<?php echo $this->getKlarnaStoreId() ?>/de_at/consent"
                                   target="_blank">Einwilligung</a>
                                kann ich jederzeit mit Wirkung f&uuml;r die Zukunft widerrufen. Es gelten die AGB des H&auml;ndlers.
                            <?php endif; ?>
                            <em style="float:none; position:relative;">*</em>
                        </label>
                    </div>
                </li>
            <?php endif; ?>
        </ul>
    </div>
    <?php if ($this->getKlarnaStoreId() and $this->getCountry()): ?>
        <script type="text/javascript">
            var terms = new Klarna.Terms.Invoice({
                el: $('payone_klarna_invoice_terms'),
                eid: '<?php echo $this->getKlarnaStoreId() ?>',  // Your merchant ID
                country: '<?php echo strtolower($this->getCountry()) ?>',
                charge: 0
            });
        </script>
    <?php endif;
endif; ?>
