[% USE raw %]
[% USE Koha %]
[% USE KohaDates %]
[% USE AdditionalContents %]
[% 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>Your consents &rsaquo; [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog</title>
[% INCLUDE 'doc-head-close.inc' %]
[% BLOCK cssinclude %][% END %]
</head>
[% INCLUDE 'bodytag.inc' bodyid='opac-patron-consent' %]
[% INCLUDE 'masthead.inc' %]

<div 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">
                        <input type="hidden" name="op" value="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 have read the <a target="_blank" href="[% Koha.Preference('PrivacyPolicyURL') | url %]">privacy policy</a> and agree with your processing of my personal data as outlined therein.</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 %]
                                    <input type="radio" name="check_[% consent_type | html %]" value="1" checked="checked"> Yes<br>
                                    <input type="radio" name="check_[% consent_type | html %]" value="0"> No
                                [% ELSIF consent.refused_on %]
                                    <input type="radio" name="check_[% consent_type | html %]" value="1"> Yes<br>
                                    <input type="radio" name="check_[% consent_type | html %]" value="0" checked="checked"> No
                                [% ELSE %]
                                    <input type="radio" name="check_[% consent_type | html %]" value="1"> Yes<br>
                                    <input type="radio" name="check_[% consent_type | html %]" value="0"> No
                                [% 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>

                    [% IF Koha.Preference('CookieConsent') %]
                        <h2>Cookie consents</h2>
                        <button id="viewCookieConsents" type="button" class="btn btn-success">View your cookie consents</button>
                    [% END %]

                </div> <!-- / #patronconsents -->
            </div> <!-- / .col-lg-10 -->
        </div> <!-- / .row -->
    </div> <!-- / .container-fluid -->
</div> <!-- / .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 %]
