[% USE raw %]
[% USE Koha %]
[% USE KohaDates %]
[% USE AdditionalContents %]
[% PROCESS 'i18n.inc' %]
[% PROCESS 'html_helpers.inc' %]
[% SET OpacNav = AdditionalContents.get( location => "OpacNav", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %]
[% SET OpacNavBottom = AdditionalContents.get( location => "OpacNavBottom", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %]
[% SET consentview = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
<title
    >[% FILTER collapse %]
        [% t("Your consents") | html %]
        &rsaquo; [% PROCESS 'library_name_title' %]
    [% END %]</title
>
[% INCLUDE 'doc-head-close.inc' %]
[% BLOCK cssinclude %]
[% END %]
</head>
[% INCLUDE 'bodytag.inc' bodyid='opac-patron-consent' %]
[% INCLUDE 'masthead.inc' %]

<main class="main">
    [% WRAPPER breadcrumbs %]
        [% WRAPPER breadcrumb_item %]
            <a href="/cgi-bin/koha/opac-user.pl">[% patron.firstname | html %] [% patron.surname | html %]</a>
        [% END %]
        [% WRAPPER breadcrumb_item bc_active= 1 %]
            <span>Your consents</span>
        [% END %]
    [% END #/ WRAPPER breadcrumbs %]

    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-2">
                <div id="navigation"> [% INCLUDE 'navigation.inc' IsPatronPage=1 %] </div>
            </div>
            <div class="col-lg-10 order-first order-md-first order-lg-2">
                <div id="patronconsents" class="maincontent">
                    <form action="/cgi-bin/koha/opac-patron-consent.pl" method="post">
                        [% INCLUDE 'csrf-token.inc' %]
                        <input type="hidden" name="op" value="cud-save" />
                        <input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" />
                        <h1>Your consents</h1>
                        [% FOREACH consent IN consents %]
                            [% SET consent_type = consent.type %]
                            [% IF consent_type == 'GDPR_PROCESSING' %]
                                <legend><h2>Privacy policy consent</h2></legend>
                                <div class="alert alert-warning">
                                    <p>In order to keep you logged in, we need your consent to process personal data as specified in the privacy policy linked below.</p>
                                    <p>If you choose to withdraw your consent we will <strong>remove your account</strong> within a reasonable time and you should log out now.</p>
                                </div>
                                <p>I agree with your processing of my personal data as outlined in the <a target="_blank" href="[% Koha.Preference('PrivacyPolicyURL') | url %]">privacy policy</a>.</p>
                            [% ELSIF consent_types.$consent_type %]
                                [% SET consent_title = ( consent_types.$consent_type.title.$lang || consent_types.$consent_type.title.en ) %]
                                [% SET consent_desc  = ( consent_types.$consent_type.description.$lang || consent_types.$consent_type.description.en ) %]
                                <legend><h2>[% consent_title | html %]</h2></legend>
                                <p>[% consent_desc | html %]</p>
                                <p>Do you agree?</p>
                            [% ELSE %]
                                <legend><h2>Consent for [% consent_type | html %]</h2></legend>
                                <p>Do you agree?</p>
                            [% END %]
                            <fieldset>
                                [% IF consent.given_on %]
                                    <label><input type="radio" name="check_[% consent_type | html %]" value="1" checked="checked" /> Yes</label><br />
                                    <label><input type="radio" name="check_[% consent_type | html %]" value="0" /> No</label>
                                [% ELSIF consent.refused_on %]
                                    <label> <input type="radio" name="check_[% consent_type | html %]" value="1" /> Yes</label><br />
                                    <label><input type="radio" name="check_[% consent_type | html %]" value="0" checked="checked" /> No </label>
                                [% ELSE %]
                                    <label><input type="radio" name="check_[% consent_type | html %]" value="1" /> Yes</label><br />
                                    <label><input type="radio" name="check_[% consent_type | html %]" value="0" /> No</label>
                                [% END %]
                                [% IF consent.given_on %]
                                    <p class="consent_info"><strong>Your consent was registered on [% consent.given_on | html %].</strong></p>
                                [% ELSIF consent.refused_on %]
                                    <p class="dissent_info"><strong>We registered that you did not consent on [% consent.refused_on | html %].</strong></p>
                                [% END %]
                            </fieldset>
                        [% END %]
                        <fieldset class="action">
                            <input id="saveconsent" type="submit" value="Save" class="btn btn-primary" />
                        </fieldset>
                    </form>
                </div>
                <!-- / #patronconsents -->
            </div>
            <!-- / .col-lg-10 -->
        </div>
        <!-- / .row -->
    </div>
    <!-- / .container-fluid -->
</main>
<!-- / .main -->

[% INCLUDE 'opac-bottom.inc' %]
[% BLOCK jsinclude %]
    <script>
        $(document).ready(function () {
            // Initially no choice is made or no change, so disable button
            $("#saveconsent").prop("disabled", true);

            $("input[type='radio']").click(function () {
                $("#saveconsent").prop("disabled", false);
                var v = $(this).val();
                // If former registration info present, toggle
                if (v == 1) {
                    $(this).siblings(".consent_info").show();
                    $(this).siblings(".dissent_info").hide();
                } else {
                    $(this).siblings(".consent_info").hide();
                    $(this).siblings(".dissent_info").show();
                }
            });
        });
    </script>
[% END %]
