[% USE raw %]
[% USE Asset %]
[% USE Koha %]
[% USE KohaDates %]
[% USE Branches %]
[% USE ItemTypes %]
[% USE Price %]
[% USE AuthorisedValues %]
[% 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 OpacMySummaryNote = AdditionalContents.get( location => "OpacMySummaryNote", lang => lang, library => branchcode ) %]

[% SET borrower_club_enrollments = logged_in_user.get_club_enrollments %]
[% SET borrower_enrollable_clubs = logged_in_user.get_enrollable_clubs(1) %] <!-- 1 => OPAC -->

[% INCLUDE 'doc-head-open.inc' %]
<title>Your library home &rsaquo; [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog</title>
[% INCLUDE 'doc-head-close.inc' %]
[% Asset.css("css/overdrive.css") | $raw %]
[% BLOCK cssinclude %][% END %]
</head>
[% INCLUDE 'bodytag.inc' bodyid='opac-user' bodyclass='scrollto' %]
[% INCLUDE 'masthead.inc' %]

[% IF Koha.Preference('AmazonAssocTag') %]
    [% AmazonAssocTag = '?tag=' _ Koha.Preference('AmazonAssocTag') %]
[% ELSE %]
    [% AmazonAssocTag = '' %]
[% END %]

<div class="main">
    [% WRAPPER breadcrumbs %]
        [% WRAPPER breadcrumb_item %]
            <a href="/cgi-bin/koha/opac-user.pl">[% INCLUDE 'patron-title.inc' patron = logged_in_user %]</a>
        [% END %]
        [% WRAPPER breadcrumb_item bc_active= 1 %]
            <span>Your summary</span>
        [% END %]
    [% END #/ WRAPPER breadcrumbs %]

    <div class="container-fluid">
        <div class="row">
            <div class="col col-lg-2 order-2 order-lg-1">
                <div id="navigation">
                    [% INCLUDE 'navigation.inc' IsPatronPage=1 %]
                </div>
            </div>
            <div class="col-md-12 col-lg-10 order-1 order-lg-2">
                <div id="userdetails" class="maincontent">

                    <h1>Your summary</h1>

                    [% INCLUDE 'opac-note.inc' %]

                    <p>Hello, [% INCLUDE 'patron-title.inc' patron = logged_in_user %]
                    <br />
                    <a href="/cgi-bin/koha/opac-main.pl?logout.x=1">Click here if you're not [% INCLUDE 'patron-title.inc' patron = logged_in_user %]</a></p>

                    [% IF ( patronupdate ) %]<div class="alert alert-info"><h2>Thank you!</h2><p>Your corrections have been submitted to the library, and a staff member will update your record as soon as possible.</p></div>[% END %]

                    [% IF failed_holds %]
                        <div class="alert alert-info">
                            <h2>Notice:</h2>
                            <p>One or more holds were not placed due to following errors:</p>
                            <ul>
                            [% FOREACH fail IN failed_holds.split('\|') %]
                                <li>
                                [% SWITCH fail %]
                                [% CASE 'damaged' %]
                                    <span>Item is damaged</span>
                                [% CASE 'ageRestricted' %]
                                    <span>The record and its items are age restricted</span>
                                [% CASE 'tooManyHoldsForThisRecord' %]
                                    <span>You have exceeded the number of concurrent holds for this record</span>
                                [% CASE 'tooManyReservesToday' %]
                                    <span>You've reached your daily holds limit</span>
                                [% CASE 'tooManyReserves' %]
                                    <span>You have too many holds already</span>
                                [% CASE 'notReservable' %]
                                    <span>Not holdable</span>
                                [% CASE 'cannotReserveFromOtherBranches' %]
                                    <span>You are from a different library</span>
                                [% CASE 'branchNotInHoldGroup' %]
                                    <span>Holds are not allowed from your library</span>
                                [% CASE 'itemAlreadyOnHold' %]
                                    <span>You already have a hold for this item</span>
                                [% CASE 'cannotBeTransferred' %]
                                    <span>Cannot be transferred to pickup library</span>
                                [% CASE 'pickupNotInHoldGroup' %]
                                    <span>The chosen pickup location is not allowed</span>
                                [% CASE 'noReservesAllowed' %]
                                    <span>No holds are allowed on this item</span>
                                [% CASE 'libraryNotPickupLocation' %]
                                    <span>Library is not a valid pickup location</span>
                                [% CASE 'no_valid_pickup_location' %]
                                    <span>No valid pickup location</span>
                                [% CASE 'notforloan' %]
                                    <span>Not for loan</span>
                                [% CASE 'items_available' %]
                                    <span>There are items available in the library, please visit to check them out</span>
                                [% CASE 'not_placed' %]
                                    <span>Error when placing hold, please report this to the library</span>
                                [% CASE %]
                                    <span>Error: [% fail | html %]</span>
                                [% END %]
                                </li>
                            [% END %]
                            </ul>
                        </div>
                    [% END %]

                    [% IF ( borrower.blockedonfines && Koha.Preference('OPACHoldRequests') ) %]
                        <div class="alert alert-warning" id="blockedonfines">
                            <strong>Please note:</strong><span> Your account has outstanding fees & charges of [% amountoutstanding | $Price %]. Holds are blocked because your fine balance is over the limit.</span>
                        </div>
                    [% END %]

                    [% IF ( borrower.warndeparture ) %]
                        <div class="alert alert-warning" id="warndeparture">
                            <strong>Please note:</strong><span> Your library card will expire on <span id="warndeparture_date">[% borrower.warndeparture | $KohaDates %]</span>. Please contact the library for more information.</span>
                                [% IF ( borrower.returnbeforeexpiry ) %]<span id="warndeparture_returnbeforeexpiry"> Also note that you must return all checked out items before your library card expires.</span>[% END %]
                        </div>
                    [% END %]

                    [% IF ( borrower.warnexpired ) %]
                        <div class="alert alert-warning" id="warnexpired">
                            <strong>Please note: </strong><span>Your account has expired as of [% borrower.warnexpired | $KohaDates %]. Please contact the library if you wish to renew your account.</span>
                        </div>
                    [% END %]

                    [% IF ( RENEW_ERROR ) %]
                        <div class="alert alert-warning">
                            <strong>Please note:</strong>
                                Your loan renewal failed because of the following reason(s):
                                <ul>
                                    [% FOREACH error IN RENEW_ERROR.split('\|') %]
                                        [% IF error == 'card_expired' %]
                                            <li>Your account has expired. Please contact the library for more information.</li>
                                        [% ELSIF error == 'too_many' %]
                                            <li>You have renewed this item the maximum number of times allowed.</li>
                                        [% ELSIF error == 'too_unseen' %]
                                            <li>You have renewed this item the maximum number of consecutive times without it being seen by the library.</li>
                                        [% ELSIF error == 'too_soon' %]
                                            <li>It is too soon after the checkout date for this item to be renewed.</li>
                                        [% ELSIF error == 'on_reserve' %]
                                            <li>This item is on hold for another patron.</li>
                                        [% ELSIF error == 'item_denied_renewal' %]
                                            <li>Item renewal is not allowed.</li>
                                        [% ELSIF error == 'item_issued_to_other_patron'%]
                                            <li>This item is already checked out to another patron.</li>
                                        [% ELSIF error == 'auto_too_soon' %]
                                            <li>This item is scheduled for auto renewal.</li>
                                        [% END %]
                                    [% END %]
                                </ul>
                        </div>
                    [% END %]

                    [% IF ( patron_flagged ) %]
                        <div class="alert alert-warning">
                            <ul>
                                [% IF ( userdebarred ) %]
                                    [% IF ( discharge_available ) %]
                                        <li id="discharged">
                                            <strong>Please note:</strong> Your account is frozen because it has been discharged. <a href="/cgi-bin/koha/opac-discharge.pl?op=get">Get your discharge</a>
                                        </li>
                                    [% ELSE %]
                                        <li id="userdebarred"><strong>Please note:</strong> Your account has been frozen.
                                        [% IF ( borrower.debarredcomment ) %]
                                            Comment:
                                            <span id="userdebarred_comment">
                                                <strong>
                                                    [% IF borrower.debarredcomment.search('OVERDUES_PROCESS') %]
                                                        Restriction added by overdues process [% borrower.debarredcomment.remove('OVERDUES_PROCESS ') | html_line_break %]
                                                    [% ELSE %]
                                                        [% borrower.debarredcomment | html_line_break %]
                                                    [% END %]
                                                </strong>
                                            </span>
                                        [% END %]
                                        [% IF ( borrower.userdebarreddate && debarred_date != '9999-12-31' ) %]
                                            End date:
                                            <span id="userdebarred_date">[% borrower.userdebarreddate | $KohaDates %]</span>
                                        [% END %]

                                        <em>Usually the reason for freezing an account is old overdues or damage fees. If your account shows to be clear, please contact the library.</em> <a href="/cgi-bin/koha/opac-account.pl">Go to your account page</a></li>
                                    [% END %]
                                [% END %]
                                [% IF ( borrower.gonenoaddress ) %]
                                    <li id="gonenoaddress"><strong>Please note:</strong> According to our records, we don't have up-to-date contact information. Please contact the library.
                                <a href="/cgi-bin/koha/opac-memberentry.pl">[% IF ( Koha.Preference('OPACPatronDetails') ) %]<span>Update your contact information</span>[% ELSE %]<span>Go to your contact information</span>[% END %]</a>
                                [% IF ( Koha.Preference('OPACPatronDetails') ) %]<em>(Please note: there may be a delay in restoring your account if you submit online.)</em>[% END %]
                                    </li>
                                [% END %]
                                [% IF ( borrower.lost ) %]
                                    <li id="lost"><strong>Please note: </strong> Your library card has been marked as lost or stolen. <em>If this is an error, please contact the library.</em></li>
                                [% END %]
                                [% IF ( renewal_blocked_fines.defined ) && ( OpacRenewalAllowed ) %]
                                    <li id="renewal_blocked_fines"><strong>Please note: </strong>You cannot renew your books online. Reason: [% IF ( renewal_blocked_fines ) > 0  %]Your fines exceed <span id="renewal_blocked_fines_amount">[% renewal_blocked_fines | $Price %]</span>.[% ELSE %]You have fines.[% END %]
                                [% END %]
                            </ul>
                        </div>
                    [% END # / IF patron_flagged %]

                    [% IF savings %]
                        <div class="alert alert-info" id="savings">
                            Congratulations, you have saved a total of [% savings | $Price with_symbol => 1 %] by using the library.
                        </div>
                    [% END %]

                    <div class="alert alert-info" id="notesaved" style="display:none;"></div>
                    [% IF ( OpacMySummaryNote ) %]
                        [% PROCESS koha_news_block news => OpacMySummaryNote %]
                    [% END %]

                    [% IF Koha.Preference('AllowPatronToControlAutorenewal') %]
                    <form id="autorenewal_option" action="/cgi-bin/koha/opac-user.pl" method="post">
                        <legend class="sr-only">Auto-renewal</legend>
                            <label for="yes-autorenew_checkouts">
                                Allow auto-renewal:
                            </label>
                                [% IF ( borrower.autorenew_checkouts ) %]
                                    <label class="radio inline" for="yes-autorenew_checkouts">
                                        Yes
                                        <input type="radio" id="yes-autorenew_checkouts" name="borrower_autorenew_checkouts" value="1" checked="checked" />
                                    </label>

                                    <label class="radio inline" for="no-autorenew_checkouts">
                                        No
                                        <input type="radio" id="no-autorenew_checkouts" name="borrower_autorenew_checkouts" value="0" />
                                    </label>
                                [% ELSE %]
                                    <label class="radio inline" for="yes-autorenew_checkouts">
                                        Yes
                                        <input type="radio" id="yes-autorenew_checkouts" name="borrower_autorenew_checkouts" value="1" />
                                    </label>
                                    <label class="radio inline" for="no-autorenew_checkouts">
                                        No
                                        <input type="radio" id="no-autorenew_checkouts" name="borrower_autorenew_checkouts" value="0" checked="checked" />
                                    </label>
                                [% END %]
                        <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
                        <input type="hidden" name="update_arc" value="1" />
                        <input type="submit" value="Update auto-renewal preference" />
                    </form>
                    [% END %]

                    [% WRAPPER tabs id= "opac-user-views" %]
                        [% WRAPPER tabs_nav %]
                            [% WRAPPER tab_item tabname= "opac-user-checkouts" %]
                                <span>Checked out ([% issues_count | html %])</span>
                            [% END %]
                            [% IF relatives %]
                                [% WRAPPER tab_item tabname= "opac-user-relative-issues" %]
                                    <span>Relatives' checkouts</span>
                                [% END %]
                            [% END %]
                            [% IF ( overdues_count ) %]
                                [% WRAPPER tab_item tabname= "opac-user-overdues" %]
                                    <span>Overdue ([% overdues_count | html %])</span>
                                [% END %]
                            [% END %]
                            [% IF ( OPACFinesTab ) %]
                                [% IF ( amountoutstanding > 0 ) %]
                                    [% WRAPPER tab_item tabname= "opac-user-fines" %]
                                        <span>Charges ([% amountoutstanding | $Price %])</span>
                                    [% END %]
                                [% END %]
                                [% IF ( amountoutstanding < 0 ) %]
                                    [% WRAPPER tab_item tabname= "opac-user-fines" %]
                                        <span>Credits ([% amountoutstanding * -1 | $Price %])</span>
                                    [% END %]
                                [% END %]
                                [% IF relatives_with_fines %]
                                    [% WRAPPER tab_item tabname= "opac-user-relative-fines" %]
                                        <span>Relatives' charges</span>
                                    [% END %]
                                [% END %]
                            [% END %]

                            [% IF borrower_club_enrollments.count || borrower_enrollable_clubs.count %]
                                [% WRAPPER tab_item tabname= "opac-user-clubs" %]
                                    <span>Clubs ([% borrower_club_enrollments.count || 0 | html %]/[% borrower_enrollable_clubs.count || 0 | html %])</span>
                                [% END %]
                            [% END %]

                            [% IF ( RESERVES.count ) %]
                                [% WRAPPER tab_item tabname= "opac-user-holds" %]
                                    <span>Holds ([% RESERVES.count | html %])</span>
                                [% END %]
                            [% END %]
                            [% IF Koha.Preference('UseRecalls') && RECALLS.count %]
                                [% WRAPPER tab_item tabname= "opac-user-recalls" %]
                                    <span>Recalls ([% RECALLS.count | html %])</span>
                                [% END %]
                            [% END %]
                            [% IF Koha.Preference('ArticleRequests') %]
                                [% WRAPPER tab_item tabname= "opac-user-article-requests" %]
                                    <span>Article requests ([% current_article_requests.size || 0 | html %])</span>
                                [% END %]
                            [% END %]
                            [% IF ( OverDriveCirculation ) %]
                                [% WRAPPER tab_item tabname= "opac-user-overdrive" %]
                                    <span>OverDrive account</span>
                                [% END %]
                            [% END %]
                        [% END # /WRAPPER tabs_nav %]

                        [% WRAPPER tab_panels %]
                            [% IF ( OverDriveCirculation ) %]
                                [% WRAPPER tab_panel tabname="opac-user-overdrive" %]
                                [% END # /tab_panel#opac-user-overdrive %]
                            [% END %]
                            [% WRAPPER tab_panel tabname="opac-user-checkouts" %]
                                [% IF ( issues_count ) %]
                                    <form id="renewselected" action="/cgi-bin/koha/opac-renew.pl" method="post">
                                        <legend class="sr-only">Renew selected</legend>
                                        <input type="hidden" name="borrowernumber" value="[% borrowernumber | html %]">
                                        <input type="hidden" name="from" value="opac_user" />
                                        <table id="checkoutst" class="table table-bordered table-striped">
                                            <caption>[% issues_count | html %] Item(s) checked out</caption>
                                            <thead>
                                                <tr>
                                                    [% IF ( JacketImages ) %]<th class="nosort">&nbsp;</th>[% END %]
                                                    <th class="all anti-the">Title</th>
                                                    <th>Author</th>
                                                    <th class="psort">Due</th>
                                                    [% UNLESS ( item_level_itypes ) %]
                                                        <th>Item type</th>
                                                    [% END %]
                                                    [% IF ( show_barcode ) %]
                                                        <th>Barcode</th>
                                                    [% END %]
                                                        <th>Call number</th>
                                                    [% IF ( OpacRenewalAllowed && !( logged_in_user.is_expired && logged_in_user.category.effective_BlockExpiredPatronOpacActions ) ) %]
                                                        <th>Renew</th>
                                                    [% END %]
                                                    [% IF ( OPACFinesTab ) %]
                                                        <th>Fines</th>
                                                    [% END %]
                                                    [% IF Koha.Preference('OPACMySummaryHTML') %]
                                                        <th class="nosort">Links</th>
                                                    [% END %]
                                                    [% IF ( Koha.Preference('AllowCheckoutNotes') ) %]
                                                        <th class="hidden">Checkout note</th>
                                                        <th id="checkout-notes" class="nosort noExport" title="Use this to report any problems with your currently checked out items">Report a problem</th>
                                                    [% END %]
                                                    <th></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                [% FOREACH ISSUE IN ISSUES %]
                                                    [% IF ( ISSUE.overdue ) %]<tr class="overdue">[% ELSE %]<tr>[% END %]
                                                    [% IF ( JacketImages ) %]
                                                        <td class="jacketcell">
                                                            [% IF ( OPACAmazonCoverImages ) %]
                                                                [% IF ( ISSUE.normalized_isbn ) %]
                                                                    <a href="http://www.amazon.com/gp/reader/[% ISSUE.normalized_isbn | uri %][% AmazonAssocTag | uri %]#reader-link" title="View on Amazon.com"><img src="https://images-na.ssl-images-amazon.com/images/P/[% ISSUE.normalized_isbn | html %].01.THUMBZZZ.jpg" alt="View on Amazon.com" class="item-thumbnail"/></a>
                                                                [% ELSE %]
                                                                    <a href="#"><span class="no-image">No cover image available</span></a>
                                                                [% END %]
                                                            [% END %]

                                                            [% IF ( GoogleJackets ) %]
                                                                [% IF ( ISSUE.normalized_isbn ) %]
                                                                    <div style="display:block;" title="Click to view in Google Books" class="[% ISSUE.normalized_isbn | html %]" id="gbs-thumbnail[% loop.count | html %]"></div>
                                                                [% ELSE %]
                                                                    <a href="http://books.google.com/books?q=[% ISSUE.title |url %]"><span class="no-image">No cover image available</span></a>
                                                                [% END %]
                                                            [% END %]

                                                            [% IF ( BakerTaylorEnabled ) %]
                                                                [% bt_id = ( ISSUE.normalized_upc || ISSUE.normalized_isbn ) %]
                                                                [% IF ( bt_id ) %]
                                                                    <a href="https://[% BakerTaylorBookstoreURL | uri %][% bt_id | uri %]"><img alt="See Baker &amp; Taylor" src="[% BakerTaylorImageURL | html %][% bt_id | html %]" /></a>
                                                                [% ELSE %]
                                                                    <span class="no-image">No cover image available</span><!-- BakerTaylor needs normalized_upc or normalized_isbn! -->
                                                                [% END %]
                                                            [% END %]

                                                            [% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %]
                                                                [% SET custom_cover_image_url = ISSUE.biblio_object.custom_cover_image_url %]
                                                                [% IF custom_cover_image_url %]
                                                                    <a class="custom_cover_image" href="[% custom_cover_image_url | url %]"><img alt="Cover image" src="[% custom_cover_image_url | url %]" /></a>
                                                                [% END %]
                                                            [% END %]

                                                            [% IF ( SyndeticsEnabled && SyndeticsCoverImages ) %]
                                                                <img src="https://secure.syndetics.com/index.aspx?isbn=[% ISSUE.normalized_isbn | html %]/[% SyndeticsCoverImageSize | uri %].GIF&amp;client=[% SyndeticsClientCode | html %]&amp;type=xw10&amp;upc=[% ISSUE.normalized_upc | html %]&amp;oclc=[% ISSUE.normalized_oclc | html %]" alt="" class="item-thumbnail" />
                                                            [% END %]
                                                        </td>
                                                    [% END # / IF JacketImages %]

                                                    <td class="title">
                                                        [% INCLUDE 'biblio-title.inc' biblio=ISSUE link=> 1 %]
                                                        [% IF ( ISSUE.enumchron ) %] [% ISSUE.enumchron | html %][% END %]

                                                        [% IF ( ISSUE.onsite_checkout ) %] <em class="onsite_checkout">(On-site checkout)</em>[% END %]

                                                        [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %]
                                                            [% INCLUDE 'user-star-ratings.inc' item=ISSUE %]
                                                        [% END %]

                                                        [% IF ( ISSUE.recall ) %]<br><i>This item has been recalled. Please return by the new due date.</i>[% END %]
                                                    </td>

                                                    <td class="author">[% ISSUE.author | html %]</td>
                                                    [% IF ( ISSUE.overdue ) %]
                                                        <td class="date_due overdue" data-order="[% ISSUE.date_due | html %]">
                                                            <span class="tdlabel">Date due:</span>
                                                            [% ISSUE.date_due | $KohaDates as_due_date => 1 %]
                                                        </td>
                                                    [% ELSE %]
                                                        <td class="date_due" data-order="[% ISSUE.date_due | html %]">
                                                            <span class="tdlabel">Date due:</span>
                                                            [% ISSUE.date_due | $KohaDates as_due_date => 1 %]
                                                        </td>
                                                    [% END %]
                                                    [% UNLESS ( item_level_itypes ) %]
                                                        <td class="itype">
                                                            <span class="tdlabel">Item type:</span>
                                                            [% IF ( ISSUE.imageurl && !Koha.Preference('OpacNoItemTypeImages') ) %]
                                                                <img src="[% ISSUE.imageurl | html %]" title="[% ISSUE.description | html %]" alt="[% ISSUE.description | html %]" />
                                                                [% END %] <span class="itypetext">[% ISSUE.description | html %]</span>
                                                        </td>
                                                    [% END %]
                                                    [% IF ( show_barcode ) %]
                                                        <td class="barcode">
                                                            <span class="tdlabel">Barcode:</span>
                                                            [% ISSUE.barcode | html %]
                                                        </td>
                                                    [% END %]
                                                    <td class="call_no">
                                                        <span class="tdlabel">Call number:</span>
                                                        [% ISSUE.itemcallnumber | html %]
                                                    </td>
                                                    [% IF ( OpacRenewalAllowed && !( logged_in_user.is_expired && logged_in_user.category.effective_BlockExpiredPatronOpacActions ) ) %]
                                                        [% IF ( ISSUE.status && canrenew ) %]
                                                            <td class="renew" data-order="[% ISSUE.renewsleft | html %]">
                                                        [% ELSE %]
                                                            <td class="renew" data-order="0">
                                                        [% END %]
                                                        [% IF ISSUE.renewed %]<span class="blabel label-success">Renewed!</span><br />[% END %]
                                                        [% IF ( ISSUE.status ) %]
                                                            [% IF ( canrenew ) %]
                                                                <input type="checkbox" name="issue" value="[% ISSUE.issue_id | uri %]"/> <a href="/cgi-bin/koha/opac-renew.pl?from=opac_user&amp;issue=[% ISSUE.issue_id | uri %]&amp;borrowernumber=[% ISSUE.borrowernumber | uri %]">Renew</a>
                                                            [% END %]
                                                            [% IF ISSUE.renewalfee > 0 %]
                                                                <span class="renewalfee label label-warning">Fee for item type '[% ItemTypes.GetDescription( ISSUE.renewalitemtype) | html %]': [% ISSUE.renewalfee | $Price %]</span>
                                                            [% END %]
                                                            [% IF ISSUE.itemtype_object.rentalcharge_daily > 0 %]
                                                                <span class="renewalfee label label-warning">[% ISSUE.itemtype_object.rentalcharge_daily | $Price %] per day</span>
                                                            [% END %]
                                                            [% IF ISSUE.itemtype_object.rentalcharge_hourly > 0 %]
                                                                <span class="renewalfee label label-warning">[% ISSUE.itemtype_object.rentalcharge_hourly | $Price %] per hour</span>
                                                            [% END %]
                                                            <span class="renewals">(
                                                                [% ISSUE.renewsleft | html %] of [% ISSUE.renewsallowed | html %] renewals remaining
                                                                [% IF Koha.Preference('UnseenRenewals') && ISSUE.unseenallowed %]
                                                                    / [% ISSUE.unseenleft | html %] of [% ISSUE.unseenallowed | html %] renewals left before the item must be seen by the library
                                                                [% END %]
                                                            )</span>
                                                        [% ELSIF ( ISSUE.on_reserve ) %]
                                                            <span class="usr-msg no-renew-hold">Not renewable <span class="renewals">(on hold)</span></span>
                                                        [% ELSIF ( ISSUE.too_many ) %]
                                                            <span class="usr-msg no-renew-too-many">Not renewable</span>
                                                        [% ELSIF ( ISSUE.too_unseen ) %]
                                                            <span class="usr-msg no-renew-unseen">Item must be renewed at the library. [% ISSUE.renewsleft | html %] renewals remaining</span>
                                                        [% ELSIF ( ISSUE.norenew_overdue ) %]
                                                            <span class="usr-msg no-renew-overdue">Not allowed <span class="renewals">(overdue)</span></span>
                                                        [% ELSIF ( ISSUE.auto_too_late ) %]
                                                            <span class="usr-msg no-renew-too-late">No longer renewable</span>
                                                        [% ELSIF ISSUE.auto_too_much_oweing %]
                                                            <span class="usr-msg auto-renew-fines">Automatic renewal failed, you have unpaid fines.</span>
                                                            <span class="renewals">(
                                                                [% ISSUE.renewsleft | html %] of [% ISSUE.renewsallowed | html %] renewals remaining
                                                                [% IF Koha.Preference('UnseenRenewals') && ISSUE.unseenallowed %]
                                                                    / [% ISSUE.unseenleft | html %] of [% ISSUE.unseenallowed | html %] renewals left before the item must be seen by the library
                                                                [% END %]
                                                            )</span>
                                                        [% ELSIF ISSUE.auto_account_expired %]
                                                            <span class="usr-msg auto-renew-expired">Automatic renewal failed, your account is expired.</span>
                                                            <span class="renewals">(
                                                                [% ISSUE.renewsleft | html %] of [% ISSUE.renewsallowed | html %] renewals remaining
                                                                [% IF Koha.Preference('UnseenRenewals') && ISSUE.unseenallowed %]
                                                                    / [% ISSUE.unseenleft | html %] of [% ISSUE.unseenallowed | html %] renewals left before the item must be seen by the library
                                                                [% END %]
                                                            )</span>
                                                        [% ELSIF ( ISSUE.too_soon ) %]
                                                            <span class="usr-msg no-renewal-before">No renewal before [% ISSUE.soonestrenewdate | $KohaDates  as_due_date => 1 %]</span>
                                                            <span class="renewals">(
                                                                [% ISSUE.renewsleft | html %] of [% ISSUE.renewsallowed | html %] renewals remaining
                                                                [% IF Koha.Preference('UnseenRenewals') && ISSUE.unseenallowed %]
                                                                    / [% ISSUE.unseenleft | html %] of [% ISSUE.unseenallowed | html %] renewals left before the item must be seen by the library
                                                                [% END %]
                                                            )</span>
                                                        [% ELSIF ( ISSUE.item_denied_renewal ) %]
                                                            Renewal not allowed
                                                        [% END %]
                                                        [% IF ( ISSUE.auto_renew || ISSUE.auto_too_soon ) %]
                                                            <br><span class="usr-msg automatic-renewal">This item is scheduled for auto renewal.</span>
                                                        [% END %]
                                                        </td>
                                                    [% END %]
                                                    [% IF ( OPACFinesTab ) %]
                                                        <td class="fines">
                                                            <span class="tdlabel">Fines:</span>
                                                            [% IF ( ISSUE.charges ) %]
                                                                <span>Yes (Item overdue or lost)</span>
                                                            [% ELSIF ( ISSUE.rentalfines ) %]
                                                                <span>Yes (Rental fees)</span>
                                                            [% ELSE %]
                                                                <span>No</span>
                                                            [% END %]
                                                        </td>
                                                    [% END %]
                                                    [% IF Koha.Preference('OPACMySummaryHTML') %]
                                                        <td class="links">[% ISSUE.biblio_object.opac_summary_html| $raw %]</td>
                                                    [% END %]
                                                    [% IF ( Koha.Preference('AllowCheckoutNotes') ) %]
                                                        <td>
                                                            [% ISSUE.note | html %]
                                                        </td>
                                                        <td class="note">
                                                            <div id="viewnote_[% ISSUE.issue_id | html %]">
                                                                [% ISSUE.note | html %]
                                                            </div>
                                                            <a id="save_[% ISSUE.issue_id | html %]" href="/cgi-bin/koha/opac-issue-note.pl?issue_id=[% ISSUE.issue_id | html %]" class="btn btn-primary btn-sm btn-add-note noprint" data-title="[% ISSUE.title | html %] [% FOREACH subtitle IN ISSUE.subtitle.split(' \| ') %][% IF Koha.Preference('marcflavour')=='UNIMARC' %],[% END %][% subtitle | html %][% END %]" data-issueid="[% ISSUE.issue_id | html %]" id="save_[% ISSUE.issue_id | html %]">
                                                                [% IF ( ISSUE.note ) -%]
                                                                    <span>Edit note</span>
                                                                [% ELSE -%]
                                                                    <span>Add note</span>
                                                                [% END %]
                                                            </a>
                                                            <input type="hidden" id="note_[% ISSUE.issue_id | html %]" name="note" value="[% ISSUE.note | html %]" data-origvalue="[% ISSUE.note | html %]" />
                                                        </td>
                                                    [% END %]
                                                    <td></td>
                                                    </tr>
                                                [% END # /FOREACH ISSUES %]
                                            </tbody>
                                        </table>
                                        [% IF ( canrenew && !userdebarred && OpacRenewalAllowed && !( logged_in_user.is_expired && logged_in_user.category.effective_BlockExpiredPatronOpacActions ) ) %]
                                            <input type="submit" class="btn btn-primary" value="Renew selected" />
                                            <button type="button" id="renewall_js" class="btn btn-primary">Renew all</button>
                                        [% END %]
                                    </form>

                                    [% IF ( canrenew && !userdebarred && OpacRenewalAllowed && !( logged_in_user.is_expired && logged_in_user.category.effective_BlockExpiredPatronOpacActions ) ) %]
                                        <form id="renewall" class="js-hide" action="/cgi-bin/koha/opac-renew.pl" method="post">
                                            <legend class="sr-only">Renew</legend>
                                            <input type="hidden" name="from" value="opac_user" />
                                            <input type="hidden" name="borrowernumber" value="[% borrowernumber | html %]" />
                                            [% FOREACH ISSUE IN ISSUES %]
                                                [% IF ISSUE.status %]
                                                    <input type="hidden" name="issue" value="[% ISSUE.issue_id | html %]" />
                                                [% END %]
                                            [% END %]
                                            <input type="submit" class="btn btn-primary" value="Renew all" />
                                        </form>
                                    [% END %]
                                [% ELSE %]
                                    <table class="table table-bordered table-striped">
                                        <caption class="sr-only">Checked out</caption>
                                        <tr><td>You have nothing checked out</td></tr>
                                    </table>
                                [% END # IF issues_count %]

                                <!-- Add note modal -->
                                <div class="modal" id="addNoteModal" tabindex="-1" aria-labelledby="addNoteLabel" aria-hidden="true">
                                    <div class="modal-dialog">
                                        <form action="#" id="addNoteForm">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <h5 class="modal-title" id="addNoteLabel">Report a problem</h5>
                                                    <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close">
                                                        <span aria-hidden="true">&times;</span>
                                                    </button>
                                                </div>
                                                <div class="modal-body" id="addNoteBody">
                                                    <h6 id="addNoteTitle"></h6>
                                                    <input type="hidden" id="addNoteIssueId" name="issue_id" value="" />
                                                    <textarea name="note" id="addNote" rows="4"></textarea>
                                                    <div class="hint">Your note will be shown to the librarian when the item is checked in.</div>
                                                </div>
                                                <div class="modal-footer">
                                                    <button type="submit" class="btn btn-primary">Submit note</button>
                                                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            [% END # /tab_panel#opac-user-checkouts %]

                            [% IF borrower_club_enrollments.count || borrower_enrollable_clubs.count %]
                                [% WRAPPER tab_panel tabname="opac-user-clubs" %]
                                    Loading...
                                [% END # /tab_panel#opac-user-clubs %]
                            [% END %]

                            [% IF ( OPACFinesTab ) %]
                                <!-- FINES BOX -->
                                [% IF ( amountoutstanding > 0 ) %]
                                    [% WRAPPER tab_panel tabname="opac-user-fines" %]
                                        <table class="table table-bordered table-striped">
                                            <caption>Charges</caption>
                                            <thead><tr><th colspan="2">Amount</th></tr></thead>
                                            <tbody>
                                                <tr>
                                                    <td>You currently owe fines and charges amounting to:</td>
                                                    <td><a href="/cgi-bin/koha/opac-account.pl">[% amountoutstanding | $Price %]</a></td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    [% END # /tab_panel#opac-user-fines %]
                                [% END %]

                                [% IF ( amountoutstanding < 0 ) %]
                                    [% WRAPPER tab_panel tabname="opac-user-fines" %]
                                        <table class="table table-bordered table-striped">
                                            <caption>Credits</caption>
                                            <thead><tr><th colspan="2">Amount</th></tr></thead>
                                            <tbody>
                                                <tr>
                                                    <td>You have a credit of:</td><td><a href="/cgi-bin/koha/opac-account.pl">[% amountoutstanding * -1 | $Price %]</a></td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    [% END # /tab_panel#opac-user-fines %]
                                [% END %]

                                [% IF relatives_with_fines %]
                                    [% WRAPPER tab_panel tabname="opac-user-relative-fines" %]
                                        <table class="table table-bordered table-striped">
                                            <caption>Fines and charges</caption>
                                            <thead>
                                                <tr>
                                                    <th colspan="2">Amount</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                [% FOREACH r IN relatives_with_fines %]
                                                <tr>
                                                    <td>[% r.firstname | html %] [% r.surname | html %] currently owes fines and charges amounting to:</td>
                                                    <td><a href="/cgi-bin/koha/opac-account.pl#g[% r.id | uri %]">[% r.account.balance | $Price %]</a></td>
                                                </tr>
                                                [% END %]
                                            </tbody>
                                        </table>
                                    [% END # /tab_panel#opac-user-relative-fines %]
                                [% END %]
                            [% END # / OPACFinesTab %]

                            [% IF relatives %]
                                [% WRAPPER tab_panel tabname="opac-user-relative-issues" %]
                                    <table id="opac-user-relative-issues-table" class="table table-bordered table-striped">
                                        <caption class="sr-only">Relatives' checkouts</caption>
                                        <thead>
                                            <tr>
                                                <th class="all anti-the">Title</th>
                                                <th>Due</th>
                                                <th>Barcode</th>
                                                <th>Call number</th>
                                                <th class="psort">Relative</th>
                                                <th></th>
                                            </tr>
                                        </thead>

                                        <tbody>
                                            [% FOREACH r IN relatives %]
                                                [% FOREACH c IN r.checkouts %]
                                                    <tr>
                                                        <td>
                                                            <a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% c.item.biblio.biblionumber | uri %]">
                                                                [% c.item.biblio.title | html %][% IF ( c.item.enumchron ) %] [% c.item.enumchron | html %][% END %]
                                                            </a>
                                                        </td>

                                                        <td>
                                                            [% c.date_due | $KohaDates %]
                                                        </td>

                                                        <td>
                                                            [% c.item.barcode | html %]
                                                        </td>

                                                        <td>
                                                            [% c.item.itemcallnumber | html %]
                                                        </td>

                                                        <td>
                                                            [% r.firstname | html %] [% r.surname | html %]
                                                        </td>
                                                        <td></td>
                                                    </tr>
                                                [% END %]
                                            [% END %]
                                        </tbody>
                                    </table>
                                [% END # /tab_panel#opac-user-relative-issues %]
                            [% END %]

                            [% IF ( overdues_count ) %]
                                [% WRAPPER tab_panel tabname="opac-user-overdues" %]
                                    <table id="overduest" class="table table-bordered table-striped">
                                        <caption>Overdues <span class="count">([% overdues_count | html %] total)</span></caption>
                                        <!-- OVERDUES TABLE ROWS -->
                                        <thead>
                                            <tr>
                                                [% IF ( JacketImages ) %]<th class="nosort">&nbsp;</th>[% END %]
                                                <th class="all anti-the">Title</th>
                                                [% UNLESS ( item_level_itypes ) %]<th>Item type</th> [% END %]
                                                [% IF ( show_barcode ) %]<th>Barcode</th>[% END %]
                                                <th>Call number</th>
                                                <th class="psort">Due</th>
                                                [% IF ( OpacRenewalAllowed ) %]
                                                    <th class="nosort">Renew</th>
                                                [% END %]
                                                [% IF ( OPACFinesTab ) %]
                                                    <th>Fines</th>
                                                [% END %]
                                                <th></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            [% FOREACH OVERDUE IN OVERDUES %]
                                                <tr>
                                                    [% IF ( JacketImages ) %]
                                                        <td class="jacketcell">
                                                        [% IF ( OPACAmazonCoverImages ) %]
                                                            [% IF ( OVERDUE.normalized_isbn ) %]
                                                                <a href="http://www.amazon.com/gp/reader/[% OVERDUE.normalized_isbn | uri %][% AmazonAssocTag | uri %]#reader-link" title="View on Amazon.com"><img src="https://images-na.ssl-images-amazon.com/images/P/[% OVERDUE.normalized_isbn | html %].01.THUMBZZZ.jpg" alt="View on Amazon.com" class="item-thumbnail" /></a>
                                                            [% ELSE %]
                                                                <a href="#"><span class="no-image">No cover image available</span></a>
                                                            [% END %]
                                                        [% END %]

                                                        [% IF ( GoogleJackets ) %]
                                                            [% IF ( OVERDUE.normalized_isbn ) %]
                                                                <div style="display:block;" title="Click to view in Google Books" class="[% OVERDUE.normalized_isbn | html %]" id="gbs-thumbnail[% loop.count | html %]"></div>
                                                            [% ELSE %]
                                                                <a href="http://books.google.com/books?q=[% OVERDUE.title |url %]"><span class="no-image">No cover image available</span></a>
                                                            [% END %]
                                                        [% END %]

                                                        [% IF ( BakerTaylorEnabled ) %]
                                                            [% bt_id = ( OVERDUE.normalized_upc || OVERDUE.normalized_isbn ) %]
                                                            [% IF ( bt_id ) %]
                                                                <a href="https://[% BakerTaylorBookstoreURL | uri %][% bt_id | uri %]"><img alt="See Baker &amp; Taylor" src="[% BakerTaylorImageURL | html %][% bt_id | html %]" /></a>
                                                            [% ELSE %]
                                                                <span class="no-image">No cover image available</span><!-- BakerTaylor needs normalized_upc or normalized_isbn! -->
                                                            [% END %]
                                                        [% END %]

                                                        [% IF ( SyndeticsCoverImages ) %]
                                                            <img src="https://secure.syndetics.com/index.aspx?isbn=[% OVERDUE.normalized_isbn | html %]/[% SyndeticsCoverImageSize | uri %].GIF&amp;client=[% SyndeticsClientCode | html %]&amp;upc=[% OVERDUE.normalized_upc | html %]&amp;oclc=[% OVERDUE.normalized_oclc | html %]&amp;type=xw10" alt="" class="item-thumbnail" />
                                                        [% END %]
                                                        </td>
                                                    [% END # /IF jacketcell %]

                                                    <td>
                                                        [% INCLUDE 'biblio-title.inc' biblio=OVERDUE link=> 1 %]
                                                        <span class="item-details">[% OVERDUE.author | html %]</span>
                                                    </td>

                                                    [% UNLESS ( item_level_itypes ) %]
                                                        <td>
                                                            [% IF ( OVERDUE.imageurl  && !Koha.Preference('OpacNoItemTypeImages') ) %]
                                                                <img src="[% OVERDUE.imageurl | html %]" title="[% OVERDUE.description | html %]" alt="[% OVERDUE.description | html %]" />
                                                            [% END %] [% OVERDUE.description | html %]
                                                        </td>
                                                    [% END %]
                                                    [% IF ( show_barcode ) %]
                                                        <td>
                                                            <span class="tdlabel">Barcode:</span>
                                                            [% OVERDUE.barcode | html %]
                                                        </td>
                                                    [% END %]
                                                    <td>
                                                        <span class="tdlabel">Call number:</span>
                                                        [% OVERDUE.itemcallnumber | html %]
                                                    </td>
                                                    <td data-order="[% OVERDUE.date_due | html %]">
                                                        <span class="tdlabel">Date due:</span>
                                                        [% OVERDUE.date_due | $KohaDates as_due_date => 1 %]
                                                    </td>
                                                    [% IF ( OpacRenewalAllowed ) %]
                                                        <td>
                                                            [% IF ( OVERDUE.debarred ) %]
                                                                Account frozen
                                                            [% ELSIF ( OVERDUE.status ) %]
                                                                [% IF ( canrenew ) %]
                                                                    <a href="/cgi-bin/koha/opac-renew.pl?from=opac_user&amp;item=[% OVERDUE.itemnumber | uri %]&amp;bornum=[% OVERDUE.borrowernumber | uri %]">Renew</a>
                                                                [% END %]
                                                                    <span class="renewals">(
                                                                        [% OVERDUE.renewsleft | html %] of [% OVERDUE.renewsallowed | html %] renewals remaining
                                                                        [% IF Koha.Preference('UnseenRenewals') && ISSUE.unseenallowed %]
                                                                            / [% OVERDUE.unseenleft | html %] of [% OVERDUE.unseenallowed | html %] renewals left before the item must be seen by the library
                                                                        [% END %]
                                                                    )</span>
                                                            [% ELSIF ( OVERDUE.norenew_overdue ) %]
                                                                Not allowed <span class="renewals">(overdue)</span>
                                                            [% ELSIF ( OVERDUE.onreserve ) %]
                                                                <span>On hold</span>
                                                            [% ELSE %]
                                                               <span>No renewals left</span>
                                                            [% END %]
                                                        </td>
                                                    [% END %]
                                                    [% IF ( OPACFinesTab ) %]
                                                        <td>
                                                            <span class="tdlabel">Fines:</span>
                                                            [% IF ( OVERDUE.charges ) %]
                                                                <span>Yes</span>
                                                            [% ELSE %]
                                                                <span>No</span>
                                                            [% END %]
                                                        </td>
                                                    [% END %]
                                                    <td></td>
                                                </tr>
                                            [% END %]
                                        </tbody>
                                    </table>
                                [% END # /tab_panel#opac-user-overdues %]
                            [% END # /overdues_count %]

                            [% IF ( RESERVES.count ) %]
                                [% WRAPPER tab_panel tabname="opac-user-holds" %]
                                    [% PROCESS 'holds-table.inc' HOLDS = RESERVES, SuspendHoldsOpac = SuspendHoldsOpac, showpriority = showpriority, AutoResumeSuspendedHolds = AutoResumeSuspendedHolds %]
                                [% END # /tab_panel#opac-user-holds %]
                            [% END # / #RESERVES.count %]

                            [% IF Koha.Preference('UseRecalls') && RECALLS.count %]
                                [% WRAPPER tab_panel tabname="opac-user-recalls" %]
                                    <table id="recalls-table" class="table table-bordered table-striped">
                                        <caption>Recalls <span class="count">([% RECALLS.count | html %])</span></caption>
                                        <thead>
                                            <tr>
                                                <th class="all anti-the">Title</th>
                                                <th class="psort">Placed on</th>
                                                <th>Expires on</th>
                                                <th>Pickup location</th>
                                                <th>Status</th>
                                                <th class="nosort">&nbsp;</th>
                                                <th></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            [% FOREACH RECALL IN RECALLS %]
                                            <tr>
                                                <td class="title">
                                                    [% INCLUDE 'biblio-title.inc' biblio=RECALL.biblio link=> 1 %]
                                                    [% IF RECALL.item_level %]<p class="hint">Item recalled: [% RECALL.item.barcode | html %]</p>[% END %]
                                                </td>
                                                <td class="recalldate" data-order="[% RECALL.created_date | html %]">
                                                    <span title="[% RECALL.created_date | html %]">
                                                        <span class="tdlabel">Recall date:</span>
                                                        [% RECALL.created_date | $KohaDates %]
                                                    </span>
                                                </td>
                                                <td class="expirationdate" data-order="[% RECALL.expiration_date | html %]">
                                                    [% IF ( RECALL.expiration_date ) %]
                                                        <span title="[% RECALL.expiration_date | html %]">
                                                            <span class="tdlabel">Expiration:</span>
                                                            [% RECALL.expiration_date | $KohaDates %]
                                                        </span>
                                                    [% ELSE %]
                                                        <span title="0000-00-00">
                                                            <span class="tdlabel">Expiration:</span>
                                                            Never expires
                                                        </span>
                                                    [% END %]
                                                </td>
                                                <td class="branch">
                                                    <span class="tdlabel">Pick up location:</span>
                                                    [% RECALL.library.branchname | html %]
                                                </td>
                                                <td class="status">
                                                    <span class="tdlabel">Status:</span>
                                                    [% IF ( RECALL.requested ) %]
                                                        <span>Requested</span>
                                                    [% ELSIF ( RECALL.overdue ) %]
                                                        <span>Overdue to be returned</span>
                                                    [% ELSIF ( RECALL.in_transit ) %]
                                                        <span>In transit to [% RECALL.library.branchname | html %]</span>
                                                    [% ELSIF ( RECALL.waiting ) %]
                                                        <span>Ready for pickup</span>
                                                    [% END %]
                                                </td>
                                                <td class="cancelrecall">
                                                    [% IF ( RECALL.requested or RECALL.overdue ) %]
                                                        <form action="/cgi-bin/koha/opac-recall.pl" method="post">
                                                            <input type="hidden" name="op" value="cancel">
                                                            <input type="hidden" name="recall_id" value="[% RECALL.id | html %]">
                                                            <input type="hidden" name="biblionumber" value="[% RECALL.biblio_id | html %]">
                                                            <button type="submit" name="submit" class="btn btn-sm btn-danger cancel_recall"><i class="fa fa-times" aria-hidden="true"></i> Cancel</button>
                                                        </form>
                                                    [% END %]
                                                </td>
                                            [% END %]
                                            <td></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                [% END # /tab_panel#opac-user-recalls %]
                            [% END # / # RECALLS.count %]

                            [% IF Koha.Preference('ArticleRequests') %]
                                [% WRAPPER tab_panel tabname="opac-user-article-requests" %]
                                    [% IF current_article_requests.size %]
                                        <table id="article-requests-table" class="table table-bordered table-striped">
                                            <caption>Article requests <span class="count"></span></caption>
                                            <thead>
                                                <tr>
                                                    <th class="all anti-the article-request-record-title">Record title</th>
                                                    <th class="psort article-request-created-on">Placed on</th>
                                                    <th class="anti-the article-request-title">Title</th>
                                                    <th class="article-request-author">Author</th>
                                                    <th class="article-request-volume">Volume</th>
                                                    <th class="article-request-issue">Issue</th>
                                                    <th class="article-request-date">Date</th>
                                                    <th class="article-request-toc" title="Table of contents">TOC</th>
                                                    <th class="article-request-pages">Pages</th>
                                                    <th class="article-request-chapters">Chapters</th>
                                                    <th class="article-request-patron-notes">Notes</th>
                                                    <th class="article-request-format">Format</th>
                                                    <th class="article-request-status">Status</th>
                                                    <th class="article-request-branchcode">Pickup library</th>
                                                    <th class="nosort article-request-cancel">&nbsp;</th>
                                                    <th></th>
                                                </tr>
                                            </thead>

                                            <tbody>
                                                    [% FOREACH ar IN current_article_requests %]
                                                        <tr>
                                                            <td class="article-request-record-title">
                                                                [% INCLUDE 'biblio-title.inc' biblio=ar.biblio link=> 1 %]
                                                                [% ar.item.enumchron | html %]
                                                                [% ar.biblio.author | html %]
                                                                [% IF ar.itemnumber %] <em>(only [% ar.item.barcode | html %])</em>[% END %]
                                                            </td>

                                                            <td class="article-request-created_on">
                                                                [% ar.created_on | $KohaDates %]
                                                            </td>

                                                            <td class="article-request-title">
                                                                [% ar.title | html %]
                                                            </td>

                                                            <td class="article-request-author">
                                                                [% ar.author | html %]
                                                            </td>

                                                            <td class="article-request-volume">
                                                                [% ar.volume | html %]
                                                            </td>

                                                            <td class="article-request-issue">
                                                                [% ar.issue | html %]
                                                            </td>

                                                            <td class="article-request-date">
                                                                [% ar.date | html %]
                                                            </td>

                                                            <td class="article-request-toc">
                                                                [% IF ar.toc_request %]Yes[% END %]
                                                            </td>

                                                            <td class="article-request-pages">
                                                                [% ar.pages | html %]
                                                            </td>

                                                            <td class="article-request-chapters">
                                                                [% ar.chapters | html %]
                                                            </td>

                                                            <td class="article-request-patron-notes">
                                                                [% ar.patron_notes | html %]
                                                            </td>

                                                            <td class="article-request-format">[% IF ar.format == 'PHOTOCOPY' %]<span>Copy</span>[% ELSIF ar.format == 'SCAN' %]<span>Scan</span>[% END %]</td>

                                                            <td class="article-request-status">
                                                                [% IF ar.status == 'PENDING' %]
                                                                    <span>Pending</span>
                                                                [% ELSIF ar.status == 'PROCESSING' %]
                                                                    <span>Processing</span>
                                                                [% ELSIF ar.status == 'REQUESTED' %]
                                                                    <span>New</span>
                                                                [% ELSIF ar.status == 'COMPLETED' %]
                                                                    <span>Completed</span>
                                                                [% ELSIF ar.status == 'CANCELED' %]
                                                                    <span>Canceled</span>
                                                                [% END %]
                                                            </td>

                                                            <td class="article-request-branchcode">
                                                                [% ar.branch.branchname | html %]
                                                            </td>

                                                            <td class="article-request-cancel">
                                                                <button data-title="[% ar.biblio.title | html %] [% ar.item.enumchron | html %]" data-article-request_id="[% ar.id | html %]" class="btn btn-sm btn-danger btn-delete-article-request"><i class="fa fa-times" aria-hidden="true"></i> Cancel</button>
                                                            </td>
                                                            <td></td>
                                                        </tr>
                                                    [% END %]
                                            </tbody>
                                        </table>
                                    [% ELSE %]
                                        <table class="table table-bordered table-striped">
                                            <caption class="sr-only">Article requests</caption>
                                            <tr><td>You have no article requests currently.</td></tr>
                                        </table>
                                    [% END # IF current_article_requests.size %]
                                [% END # /tab_panel#opac-user-article-requests %]
                            [% END %]
                        [% END # /WRAPPER tab_panels %]
                    [% END # /WRAPPER tabs#opac-user-views %]
                </div> <!-- /#userdetails -->
            </div> <!-- /.col-10 -->
        </div> <!-- /.row -->
    </div> <!-- /.container-fluid -->
</div> <!-- /#main -->

[% # hold suspend modal form %]
<div id="suspendHoldModal" class="modal" tabindex="-1" role="dialog" aria-labelledby="suspendModalLabel" aria-hidden="true" data-focus="false">
    <div class="modal-dialog">
        <div class="modal-content">
            <form action="/cgi-bin/koha/opac-modrequest-suspend.pl" method="post">
                <div class="modal-header">
                    [% IF HOLD.suspend %]
                        <h5 class="modal-title" id="suspendModalLabel">Resume hold</h5>
                    [% ELSE %]
                        <h5 class="modal-title" id="suspendModalLabel">Suspend hold</h5>
                    [% END %]
                    <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">x</span>
                    </button>
                </div>
                <div class="modal-body">
                    <h6 id="suspendHoldTitle"></h6>
                    <input type="hidden" name="reserve_id" id="suspendHoldReserveId" value="" />
                    <label for="suspend_untilDate">Suspend until:</label>
                    <input type="text" name="suspend_until" id="suspend_untilDate" size="10" />
                    [% INCLUDE 'date-format.inc' %]
                    <p><a href="#" class="clear-flatpickr" data-fp="suspend_untilDate">Clear date to suspend indefinitely</a></p>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-primary"><i class="fa fa-check" aria-hidden="true"></i> Suspend</button>
                    <button data-dismiss="modal" class="btn btn-secondary"><i class="fa fa-times" aria-hidden="true"></i> Do not suspend</button>
                </div>
            </form>
        </div> <!-- /.modal-content -->
    </div> <!-- /.modal-dialog -->
</div>  <!-- /#suspendModal -->

[% IF ( OverDriveCirculation ) %]
    [% INCLUDE 'overdrive-checkout.inc' %]
    [% IF ( Koha.Preference('OverDrivePasswordRequired') ) %]
        [% INCLUDE 'overdrive-login.inc' %]
    [% END %]
[% END %]

[% INCLUDE 'opac-bottom.inc' %]
[% BLOCK jsinclude %]
    [% INCLUDE 'calendar.inc' %]
    [% INCLUDE 'datatables.inc' %]
    <script>
        var AR_CAPTION_COUNT = _("(%s total)");


        function tableInit( tableId ){
            if( tableId == "checkoutst" ){
                $(".dt-buttons").append("<button type=\"button\" class=\"dt-button buttons-ical\" id=\"buttons-ics\">iCal</button> ");
                [% IF ( OpacRenewalAllowed && canrenew && !userdebarred ) %]
                    $(".dt-buttons").append("<button id=\"renewselected_link\" class=\"dt-button buttons-renew\"><i class=\"fa fa-check\" aria-hidden=\"true\"></i> "+_("Renew selected")+"</button> <button id=\"renewall_link\" class=\"dt-button buttons-renewall\"><span class=\"fa-stack\"><i class=\"fa fa-check fa-stack-1x\" aria-hidden=\"true\"></i><i class=\"fa fa-check fa-stack-1x\" aria-hidden=\"true\"></i></span> "+_("Renew all")+"</button>");
                [% END %]
            }
        }
        $(document).ready(function(){
            [% IF ( opac_user_holds ) %]
                $("#opac-user-views a[href='#opac-user-holds_panel']").tab("show");
            [% END %]
            [% IF ( opac_user_article_requests ) %]
                $("#opac-user-views a[href='#opac-user-article-requests_panel']").tab("show");
            [% END %]
            $('#opac-user-article-requests caption .count').html(AR_CAPTION_COUNT.format('[% current_article_requests.size | html %]'));

            $(".modal-nojs").addClass("modal").addClass("hide").removeClass("modal-nojs");

            $(".btn-delete-hold").on("click", function(e){
                e.preventDefault();
                var hold_title = $(this).data("title");
                var reserve_id = $(this).data("reserve_id");
                confirmModal( hold_title, _("Are you sure you want to cancel this hold?"), _("Yes, cancel hold"), _("No, do not cancel hold"), function( result ){
                        $("#bootstrap-confirm-box-modal").remove()
                        if( result ){
                            $("#delete_hold_" + reserve_id ).submit();
                        }
                    }
                );
            });

            $(".btn-req-delete-hold").on("click", function(e){
                e.preventDefault();
                var hold_title = $(this).data("title");
                var reserve_id = $(this).data("reserve_id");
                confirmModal( hold_title, _("Are you sure you want to request cancelling this hold?"), _("Yes"), _("No"), function( result ){
                        $("#bootstrap-confirm-box-modal").remove()
                        if( result ){
                            $("#req_cancel_hold_" + reserve_id ).submit();
                        }
                    }
                );
            });

            $(".btn-delete-article-request").on("click", function(e){
                e.preventDefault();
                var article_request = $(this).data("title");
                var article_request_id = $(this).data("article-request_id");
                (function(row){
                    var doCancel = function( result ){
                        $("#bootstrap-confirm-box-modal").remove();
                        if( result ){
                            $.ajax({
                                type: "DELETE",
                                url: '/api/v1/public/patrons/'+borrowernumber+'/article_requests/'+article_request_id+'?cancellation_reason=OPAC',
                                success: function( data ) {
                                    row.parents('tr').hide({
                                        duration: 'slow',
                                        complete: function() {
                                            var ar_tab = $('a[href="#opac-user-article-requests"');
                                            var ar_table = $('#article-requests-table');
                                            var ar_length = $('tbody tr:visible', ar_table).length;
                                            var ar_count = $('caption .count', ar_table);

                                            ar_tab.html(ar_tab.html().replace(/\(\d+\)/, '('+ar_length+')'));
                                            ar_count.html(AR_CAPTION_COUNT.format(ar_length));
                                        }
                                    });
                                }
                            });
                        }
                    };
                    confirmModal( article_request, _("Are you sure you want to cancel this article request?"), _("Yes, cancel article request"), _("No, do not cancel article request"), doCancel);
                })($(this))
            });

            /* We initiate this flatpickr instance here so that we can use the variable later */
            var suspend_until_date = $("#suspend_untilDate").flatpickr({
                minDate: "today"
            });

            $(document).on("click", ".suspend_hold", function(e){
                e.preventDefault();
                var title = $(this).data("title");
                var reserve_id = $(this).data("reserve_id");
                $("#suspendHoldReserveId").val( reserve_id );
                $("#suspendHoldTitle").html( "<em>" + title + "</em>" );
                $("#suspendHoldModal").modal("show");
            });

            $("#suspendHoldModal").on("hidden.bs.modal", function(){
                $("#suspendHoldTitle").html("");
                $("#suspendHoldReserveId").val("");
                suspend_until_date.clear();
            });

            $("#suspend_all_submit").on("click", function(e){
                e.preventDefault();
                var title = _("Are you sure you want to suspend all holds?");
                var body = _("All holds will be suspended.");
                confirmModal( body, title, _("Yes, suspend all holds"), "", function( result ){
                        $("#bootstrap-confirm-box-modal").remove()
                        if( result ){
                            $("#suspend_all_holds").submit();
                        }
                    }
                );
            });

            $("#resume_all_submit").on("click", function(e){
                e.preventDefault();
                var title = _("Are you sure you want to resume all suspended holds?");
                var body = _("All holds will resume.");
                confirmModal( body, title, _("Yes, resume all holds"), _("No, do not resume holds"), function( result ){
                        $("#bootstrap-confirm-box-modal").remove()
                        if( result ){
                            $("#resume_all_holds").submit();
                        }
                    }
                );
            });

            var dTables = $("#checkoutst,#holdst,#overduest,#opac-user-relative-issues-table");
            dTables.each(function(){
                var thIndex = $(this).find("th.psort").index();
                $(this).on("init.dt", function() {
                        tableInit( $(this).attr("id") );
                    })
                    .dataTable($.extend(true, {}, dataTablesDefaults, {
                    "sorting" : [[ thIndex, 'asc' ]],
                    "dom": '<"top"<"table_entries"><"table_controls"fB>>t',
                    "columnDefs": [
                        { "targets": [ "nosort" ],"sortable": false,"searchable": false },
                        { "type": "anti-the", "targets" : [ "anti-the" ] },
                        { "visible": false, "targets" : [ "hidden" ] },
                        { "className": 'dtr-control', "orderable": false, "targets": -1 }
                    ],
                    "language": {
                        "search": "_INPUT_",
                        "searchPlaceholder": _("Search")
                    },
                    "autoWidth": false,
                    "responsive": {
                        details: {
                            type: 'column',
                            target: -1
                        }
                    },
                    buttons: [
                        /* Override default button set so that we can extend the options of print and csv */
                        'clearFilter', 'copy',
                        {
                            extend: "print",
                            exportOptions: {
                                /* Print view should show all columns (even invisible ones) unless they are .noExport */
                                columns: ":not(.noExport)"
                            }
                        },
                        {
                            extend: "csv",
                            exportOptions: {
                                /* CSV export should include all columns (even invisible ones) unless they are .noExport */
                                columns: ":not(.noExport)"
                            }
                        }
                    ]
                }));
            });

            var dataTables = $("#recalls-table,#article-requests-table");
            dataTables.each(function(){
                $(this).dataTable($.extend(true, {}, dataTablesDefaults, {
                    "searching": false,
                    "paging": false,
                    "info": false,
                    "autoWidth": false,
                    "responsive": {
                        "details": { "type": 'column',"target": -1 }
                    },
                    "columnDefs": [
                        { "className": 'dtr-control', "orderable": false, "targets": -1 }
                    ],
                }));
            });
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (event) {
                dTables.DataTable().responsive.recalc();
                dataTables.DataTable().responsive.recalc();
            } );

            $("body").on("click", "#buttons-ics", function(){
                location.href="/cgi-bin/koha/opac-ics.pl";
            });

            [% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %]
            [% IF ( OpacRenewalAllowed && canrenew && !userdebarred ) %]
                $("#renewselected").submit(function(){
                    valid = false;
                    $("input[type=checkbox]").each(function(){
                        if($(this).is(':checked')){
                            valid = true;
                        }
                    });
                    if(!valid){
                        alert(_("Nothing has been selected. Check the box for each item you want to renew"));
                    }
                    return valid;
                });
                $("body").on("click","#renewselected_link",function(e){
                    e.preventDefault();
                    $("#renewselected").submit();
                });
                $("body").on("click","#renewall_link, #renewall_js",function(e){
                    e.preventDefault();
                    $("#renewall").submit();
                });
            [% END # /IF ( OpacRenewalAllowed && canrenew && !userdebarred ) %]

            [% IF ( Koha.Preference('AllowCheckoutNotes') ) %]

                /* If JS enabled, show button, otherwise show link to redirect to a page where note can be submitted */
                $(".nonjs_submitnote").hide();

                $("input[name='note']").prop('readonly', false);
                $("input[name='note']").keypress(function(e){
                    /* prevent submitting of renewselected form */
                    if(e.which == 13)
                        e.preventDefault();
                });

                $("input[name='note']").keyup(function(e){
                    var $btn_save = $('#save_'+$(this).data('issue_id'));
                    var origvalue = $(this).data('origvalue');
                    var value = $(this).val();

                    if(origvalue != value) {
                        if(origvalue != "")
                            $btn_save.text(_("Submit changes"));
                        else
                            $btn_save.text(_("Submit note"));
                        $btn_save.show();
                    } else {
                        $btn_save.hide();
                    }
                });

            [% END %]

            $(".change_pickup").on("click", function(){
                var hold_id = $(this).data("hold-id");
                $(this).hide();
                $("#change-pickup-location" + hold_id ).show();
            });

            if ( $('#opac-user-clubs_panel').length ) {
                $('#opac-user-clubs-tab').on('click', function() {
                    $('#opac-user-clubs_panel').text(_("Loading..."));
                    $('#opac-user-clubs_panel').load('/cgi-bin/koha/clubs/clubs-tab.pl?borrowernumber=[% borrowernumber | html %]');
                });
            }

            $(".cancel_recall").click(function(e){
                return confirmDelete(_("Are you sure you want to remove this recall?"));
            });

            $("body").on("click", ".btn-add-note", function(e){
                e.preventDefault();
                var title = $(this).data("title");
                var issue_id = $(this).data("issueid");
                var note = $("#note_" + issue_id ).val();
                var origvalue = $("#note_" + issue_id ).data("origvalue");
                $("#addNote").val( note );
                $("#addNoteIssueId").val( issue_id );
                $("#addNoteTitle").text( title );
                $("#addNoteModal").modal("show");
            });

            $("#addNoteForm").on("submit", function(e){
                e.preventDefault();
                var title = $("#addNoteTitle").text();
                var issue_id = $("#addNoteIssueId").val();
                var note = $("#addNote").val();
                submitNote( title, issue_id, note );
            });

            $("#addNoteModal").on("hidden.bs.modal", function(){
                $("#addNoteTitle").text("");
                $("#addNote").val("");
            });

            $(".dismiss-message-button").click(function(e){
                return confirmDelete(_("Are you sure you want to dismiss this message?"));
            });

            if( $("#opac-user-views .tab-pane.active").length < 1 ){
                $("#opac-user-views a:first").tab("show");
            }
        });

        function submitNote( title, issue_id, note ){
            var self = $("#addNoteModal");
            var notebutton = $("#save_" + issue_id );
            var noteinput = $("#note_" + issue_id );

            var ajaxData = {
                'action': 'issuenote',
                'issue_id': issue_id,
                'note': note
            };

            $.ajax({
                url: '/cgi-bin/koha/svc/checkout_notes/',
                type: 'POST',
                dataType: 'json',
                data: ajaxData,
            })
            .done(function(data) {
                var message = "";
                if(data.status == 'saved') {
                    $("#notesaved").removeClass("alert-error");
                    $("#notesaved").addClass("alert-info");
                    noteinput.data('origvalue', data.note)
                        .val(data.note);
                    notebutton.text( _("Edit note" ) );
                    $("#viewnote_" + issue_id ).text( data.note );
                    message = "<p>" + _("Your note about %s has been saved and sent to the library.").format( em(title) ) + "</p>";
                    message += "<p class=\"checkout_note\">" + data.note;
                    message += "<a href=\"/cgi-bin/koha/opac-issue-note.pl?issue_id=" + issue_id + "\" class=\"btn btn-link btn-sm btn-add-note\" data-title=\"" + title + "\" data-issueid=\"" + issue_id + "\"><i class=\"fa fa-pencil\" aria-hidden=\"true\"></i> " + _("Edit note") + "</a>";
                    message += "</p>";
                } else if(data.status == 'removed') {
                    $("#notesaved").removeClass("alert-error");
                    $("#notesaved").addClass("alert-info");
                    noteinput.data('origvalue', "")
                        .val("")
                    notebutton.text( _("Add note") );
                    $("#viewnote_" + issue_id ).text( data.note );
                    message = "<p>" + _("Your note about %s was removed.").format( em(title) ) + "</p>";
                } else {
                    $("#notesaved").removeClass("alert-info");
                    $("#notesaved").addClass("alert-error");
                    message =  "<p>" + _("Your note about %s could not be saved.").format( em(title) ) + "</p>";
                    notebutton.text( _("Add note") );
                    $("#viewnote_" + issue_id ).text( data.note );
                    message += "<p style=\"font-weight:bold;\">" + _("Something went wrong. The note has not been saved") + "</p>";
                }
                $("#notesaved").html(message);
            })
            .fail(function(data) {
                $("#notesaved").removeClass("alert-info");
                $("#notesaved").addClass("alert-error");
                var message = "<p style=\"font-weight:bold;\">" + _("Something went wrong. The note has not been saved") + "</p>";
                $("#notesaved").html(message);
            })
            .always(function() {
                self.modal("hide");
                $("#notesaved").show();
            });
        }

        function em( title ){
            return "<em>" + title + "</em>";
        }

        var borrowernumber = "[% borrowernumber | html %]";
    </script>
    [% IF ( Koha.Preference('OpacStarRatings') == 'all' ) %]
        [% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %]
        [% Asset.js("js/ratings.js") | $raw %]
    [% END %]
    [% IF Koha.Preference('OverDriveCirculation') %]
    [% Asset.js("js/overdrive.js") | $raw %]
    <script>
    [%- IF Koha.Preference('OverDrivePasswordRequired') -%]
        var OD_password_required = 1;
    [%- ELSE -%]
        var OD_password_required = 0;
    [%- END -%]
    $(document).ready(function() {
        [% IF ( overdrive_error ) %]
            KOHA.OverDriveCirculation.display_error("#opac-user-overdrive_panel", "[% overdrive_error.dquote | html %]");
        [% END %]

        [% IF ( overdrive_tab ) %]
            $("#opac-user-views a[href='#opac-user-overdrive_panel']").tab("show");
        [% END %]

        $("#opac-user-overdrive_panel").each( function() {
            KOHA.OverDriveCirculation.display_account_details(this);
        } );
    });
    </script>
    [% END %]
[% END %]
