View | Details | Raw Unified | Return to bug 17602
Collapse All | Expand All

(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/oneclick-checkout.inc (+15 lines)
Line 0 Link Here
1
<div id="oneclickdigital-checkout" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="oneclickdigital-checkout-label" aria-hidden="true">
2
    <div class="modal-header">
3
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
4
        <h3 id="oneclickdigital-checkout-label">Checkout</h3>
5
    </div>
6
    <form action="#" method="post" id="oneclickdigital-checkout-form">
7
        <div class="modal-body">
8
                <input type="hidden" name="id" value="" />
9
        </div>
10
        <div class="modal-footer">
11
            <input type="submit" class="btn btn-primary oneclickdigital-checkout-submit" value="Checkout" />
12
            <a href="#" data-dismiss="modal" aria-hidden="true" class="cancel">Cancel</a>
13
        </div>
14
    </form> <!-- /#oneclickdigital-checkout-form -->
15
</div>  <!-- /#oneclickdigital-checkout  -->
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-oneclick-search.tt (+165 lines)
Line 0 Link Here
1
[% USE Koha %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
<title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; OneClickDigital search for '[% q | html %]'</title>
4
[% INCLUDE 'doc-head-close.inc' %]
5
[% BLOCK cssinclude %]
6
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/jquery.rating.css" />
7
<style>
8
.actions a.addtocart {
9
    display: inline;
10
}
11
</style>
12
[% END %]
13
</head>
14
[% INCLUDE 'bodytag.inc' bodyid='oneclickdigital-results-page' bodyclass='scrollto' %]
15
[% INCLUDE 'masthead.inc' %]
16
17
    <div class="main">
18
        <ul class="breadcrumb">
19
            <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">&rsaquo;</span></li>
20
            <li><a href="#">OneClickDigital search for '[% q | html %]'</a></li>
21
        </ul>
22
23
        <div class="container-fluid">
24
            <div class="row-fluid">
25
                <div class="span2">
26
                    [% IF ( OpacNav || OpacNavBottom ) %]
27
                        [% INCLUDE 'navigation.inc' %]
28
                    [% END %]
29
                </div>
30
                <div class="span10">
31
                    <div id="oneclickdigital-results-content" class="maincontent searchresults">
32
                        <h1>OneClickDigital search for '[% q | html %]'</h1>
33
                            <div id="breadcrumbs">
34
                                <p></p>
35
                            </div>
36
37
                            <div id="top-pages">
38
                                <div class="pagination pagination-small">
39
                                </div>
40
                            </div>
41
42
                            <table id="oneclickdigital-results-list" class="table table-striped">
43
                                <tbody>
44
                                </tbody>
45
                            </table>
46
47
                            <div id="bottom-pages">
48
                                <div class="pagination pagination-small">
49
                                </div>
50
                            </div>
51
52
                    </div> <!-- / #oneclickdigital-results-content -->
53
                </div> <!-- / .span10 -->
54
            </div> <!-- / .row-fluid -->
55
        </div> <!-- / .container-fluid -->
56
    </div> <!-- / .main -->
57
58
[% INCLUDE 'oneclick-checkout.inc' %]
59
60
[% INCLUDE 'opac-bottom.inc' %]
61
[% BLOCK jsinclude %]
62
<script type="text/javascript" src="[% interface %]/[% theme %]/js/oneclickdigital.js"></script>
63
<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.rating.js"></script>
64
<script type="text/javascript">
65
var querystring = "[% q |replace( "'", "\'" ) |replace( '\n', '\\n' ) |replace( '\r', '\\r' ) |html %]";
66
var results_per_page = [% OPACnumSearchResults || 20 %];
67
68
function search( page ) {
69
    $( '#oneclickdigital-status' ).html( _("Searching OneClickDigital...") + ' <img class="throbber" src="[% interface %]/lib/jquery/plugins/themes/classic/throbber.gif" /></span>' );
70
71
    KOHA.OneClickDigital.search( querystring, results_per_page, page, function( data ) {
72
        if ( data.error ) {
73
            $( '#oneclickdigital-status' ).html( '<strong class="unavailable">' + _("Error searching OneClickDigital collection") + ': ' + data.error + '</strong>' );
74
            return;
75
        }
76
77
        if ( !data.total ) {
78
            $( '#oneclickdigital-status' ).html( '<strong>' + _("No results found in the library's OneClickDigital collection.") + '</strong>' );
79
            return;
80
        }
81
82
        $( '#oneclickdigital-results-list tbody' ).empty();
83
84
        $( '#oneclickdigital-status' ).html( '<strong>' + _("Found") + ' ' + data.total + ' ' + _("results in the library's OneClickDigital collection.") + '</strong>' );
85
86
        for ( var i = 0; data.items[i]; i++ ) {
87
            var prod = data.items[i];
88
            var results = [];
89
90
            results.push( '<tr>' );
91
92
            results.push( '<td class="info"><span class="title">' );
93
            results.push( prod.title );
94
            results.push( '</span>' );
95
            results.push( '<p>' + _("by") + ' ', prod.author, '</p>' );
96
            results.push( '<span class="results_summary mediatype"><span class="label">' + _("Type:") + ' </span>', prod.media, '</span>' );
97
98
            results.push( '</td>' );
99
100
            results.push( '<td>' );
101
            if ( prod.images && prod.images.medium ) {
102
                results.push( '<a href="', "XXX", '">' );
103
                results.push( '<img class="thumbnail" src="', prod.images.medium, '" />' );
104
                results.push( '</a>' );
105
            }
106
            results.push( '</td>' );
107
108
            results.push( '</tr>' );
109
            var $tr = $( results.join( '' ));
110
            $( '#oneclickdigital-results-list tbody' ).append( $tr );
111
112
            $tr.find( '.info' ).each(function() {
113
                KOHA.OneClickDigital.add_actions(this, prod.isbn);
114
            });
115
        }
116
117
        $( '#oneclickdigital-results-list tr:odd' ).addClass( 'highlight' );
118
119
        var pages = [];
120
121
        var max_page = Math.floor( data.total / results_per_page );
122
        if (data.total == page*results_per_page) max_page++;
123
124
        if ( page != 1 ) {
125
            pages.push( '<li><a class="od-nav" href="#" data-page="' + (page - 1) + '">&laquo; ' + _("Previous") + '</a></li>' );
126
        }
127
128
        for ( var p = Math.max( 0, page - 9 ); p <= Math.min( max_page, p + 9 ); p++ ) {
129
            if ( p == page ) {
130
                pages.push( ' <li class="active"><a href="#">' + ( p + 1 ) + '</a></li>' );
131
            } else {
132
                pages.push( ' <li><a class="od-nav" href="#" data-page="' +  p + '">' + p + '</a></li>' );
133
            }
134
        }
135
136
        if ( page < max_page ) {
137
            pages.push( ' <li><a class="od-nav" href="#" data-page="' + (page + 1) + '">' + _("Next") + ' &raquo;</a></li>' );
138
        }
139
140
        if ( pages.length > 1 ) $( '#top-pages, #bottom-pages' ).find( '.pagination' ).html( '<ul>' + pages.join( '' ) + '</ul>');
141
142
        $( '#oneclickdigital-results-list input.star' ).rating();
143
    } );
144
}
145
146
$( document ).ready( function() {
147
    $( '#breadcrumbs p' )
148
        .append( ' ' )
149
        .append( '<span id="oneclickdigital-status"></span>' );
150
151
    $( document ).on( 'click', 'a.od-nav', function() {
152
        search( $( this ).data( 'page' ) );
153
        return false;
154
    });
155
156
    [% IF ( loggedinusername ) %]
157
    KOHA.OneClickDigital.with_account_details("#breadcrumbs", function() {
158
        search( 1 );
159
    });
160
    [% ELSE %]
161
        search( 1 );
162
    [% END %]
163
} );
164
</script>
165
[% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt (+18 lines)
Lines 590-595 Link Here
590
[% END %]
590
[% END %]
591
[% IF ( OpacStarRatings == 'all' || Koha.Preference('Babeltheque') ) %]<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.rating.js"></script>[% END %]
591
[% IF ( OpacStarRatings == 'all' || Koha.Preference('Babeltheque') ) %]<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.rating.js"></script>[% END %]
592
[% IF ( OverDriveEnabled ) %]<script type="text/javascript" src="[% interface %]/[% theme %]/js/overdrive.js"></script>[% END %]
592
[% IF ( OverDriveEnabled ) %]<script type="text/javascript" src="[% interface %]/[% theme %]/js/overdrive.js"></script>[% END %]
593
[% IF ( OneClickDigitalEnabled ) %]<script type="text/javascript" src="[% interface %]/[% theme %]/js/oneclickdigital.js"></script>[% END %]
593
<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
594
<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
594
[% IF ( OpacHighlightedWords ) %]<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.highlight-3.js"></script>
595
[% IF ( OpacHighlightedWords ) %]<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.highlight-3.js"></script>
595
[% END %]<script type="text/javascript">
596
[% END %]<script type="text/javascript">
Lines 901-906 $(document).ready(function(){ Link Here
901
            }
902
            }
902
        } );
903
        } );
903
    [% END %]
904
    [% END %]
905
    [% IF ( OneClickDigitalEnabled ) %]
906
        var $oneclick_results = $( '<div id="oneclick-results">' + _( 'Searching OneClickDigital...' ) + ' <img class="throbber" src="[% interface %]/lib/jquery/plugins/themes/classic/throbber.gif" /></div>' );
907
        $( '#numresults' ) .append( ' ' )
908
            .append( $oneclick_results );
909
        KOHA.OneClickDigital.search( querystring, [% OPACnumSearchResults || "null" %], null, function( data ) {
910
            if ( data.error ) {
911
                $oneclick_results.html( _( 'Error searching OneClickDigital collection' ) );
912
                return;
913
            }
914
915
            if ( data.total > 0 ) {
916
                $oneclick_results.html( _( 'Found' ) + ' <a href="/cgi-bin/koha/opac-oneclick-search.pl?q=' + escape( querystring ) + '">' + data.total + ' ' + _( 'results' ) + '</a> ' + _( 'in OneClickDigital collection' ) );
917
            } else {
918
                $oneclick_results.remove();
919
            }
920
        } );
921
    [% END %]
904
    [% IF ( OpenLibrarySearch ) %]
922
    [% IF ( OpenLibrarySearch ) %]
905
        var $openlibrary_results = $( '<div id="openlibrary-results">' + _( 'Searching Open Library...' ) + ' <img class="throbber" src="[% interface %]/lib/jquery/plugins/themes/classic/throbber.gif" /></div>' );
923
        var $openlibrary_results = $( '<div id="openlibrary-results">' + _( 'Searching Open Library...' ) + ' <img class="throbber" src="[% interface %]/lib/jquery/plugins/themes/classic/throbber.gif" /></div>' );
906
        $( '#numresults' ) .append( ' ' )
924
        $( '#numresults' ) .append( ' ' )
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt (+19 lines)
Lines 138-147 Using this account is not recommended because some parts of Koha will not functi Link Here
138
                            [% IF ( OverDriveCirculation ) %]
138
                            [% IF ( OverDriveCirculation ) %]
139
                            <li><a href="#opac-user-overdrive">OverDrive Account</a></li>
139
                            <li><a href="#opac-user-overdrive">OverDrive Account</a></li>
140
                            [% END %]
140
                            [% END %]
141
                            [% IF ( OneClickDigitalCirculation ) %]
142
                            <li><a href="#opac-user-oneclickdigital">OneClickDigital Account</a></li>
143
                            [% END %]
141
                        </ul>
144
                        </ul>
142
145
143
                        <div id="opac-user-overdrive">
146
                        <div id="opac-user-overdrive">
144
                        </div>
147
                        </div>
148
                        <div id="opac-user-oneclickdigital">
149
                        </div>
145
                        <div id="opac-user-checkouts">
150
                        <div id="opac-user-checkouts">
146
                            [% IF ( issues_count ) %]
151
                            [% IF ( issues_count ) %]
147
                                <form id="renewselected" action="/cgi-bin/koha/opac-renew.pl" method="post">
152
                                <form id="renewselected" action="/cgi-bin/koha/opac-renew.pl" method="post">
Lines 834-839 Using this account is not recommended because some parts of Koha will not functi Link Here
834
[% IF ( OverDriveCirculation ) %]
839
[% IF ( OverDriveCirculation ) %]
835
[% INCLUDE 'overdrive-checkout.inc' %]
840
[% INCLUDE 'overdrive-checkout.inc' %]
836
[% END %]
841
[% END %]
842
[% IF ( OneClickDigitalCirculation ) %]
843
[% INCLUDE 'oneclick-checkout.inc' %]
844
[% END %]
837
845
838
[% INCLUDE 'opac-bottom.inc' %]
846
[% INCLUDE 'opac-bottom.inc' %]
839
847
Lines 900-905 Using this account is not recommended because some parts of Koha will not functi Link Here
900
    </script>
908
    </script>
901
    [% IF Koha.Preference('OverDriveCirculation') %]
909
    [% IF Koha.Preference('OverDriveCirculation') %]
902
    <script type="text/javascript" src="[% interface %]//[% theme %]/js/overdrive.js"></script>
910
    <script type="text/javascript" src="[% interface %]//[% theme %]/js/overdrive.js"></script>
911
    <script type="text/javascript" src="[% interface %]//[% theme %]/js/oneclickdigital.js"></script>
903
    <script type="text/JavaScript">
912
    <script type="text/JavaScript">
904
    $(document).ready(function() {
913
    $(document).ready(function() {
905
        [% IF ( overdrive_error ) %]
914
        [% IF ( overdrive_error ) %]
Lines 913-918 Using this account is not recommended because some parts of Koha will not functi Link Here
913
        $("#opac-user-overdrive").each( function() {
922
        $("#opac-user-overdrive").each( function() {
914
            KOHA.OverDriveCirculation.display_account_details(this);
923
            KOHA.OverDriveCirculation.display_account_details(this);
915
        } );
924
        } );
925
926
    [% IF ( oneclickdigital_error ) %]
927
        KOHA.OneClickDigital.display_error("#opac-user-oneclickdigital", "[% oneclickdigital_error.dquote %]");
928
    [% END %]
929
    [% IF ( oneclickdigital_tab ) %]
930
        $("#opac-user-views").tabs("select", "#opac-user-oneclickdigital");
931
    [% END %]
932
        $("#opac-user-oneclickdigital").each( function() {
933
            KOHA.OneClickDigital.display_account_details(this);
934
        } );
916
    });
935
    });
917
    </script>
936
    </script>
918
    [% END %]
937
    [% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/oneclickdigital.js (+278 lines)
Line 0 Link Here
1
if ( typeof KOHA == "undefined" || !KOHA ) {
2
    var KOHA = {};
3
}
4
5
KOHA.OneClickDigital = new function() {
6
    var svc_url = '/cgi-bin/koha/svc/oneclickdigital';
7
8
    var error_div = $('<div class="oneclickdigital-error">');
9
    function display_error ( error ) {
10
        error_div.text(error);
11
    }
12
13
    var details = null;
14
15
    function is_identified() {
16
        return details ? details.is_identified : false;
17
    }
18
19
    var checkout_popup = null;
20
    $( document ).ready(function() {
21
        checkout_popup = $("#oneclickdigital-checkout");
22
    });
23
24
    function display_account (container, data) {
25
        if (!data.is_identified) {
26
            return;
27
        }
28
29
        if (data.checkouts) {
30
            var checkouts_div = $('<div class="oneclickdigital-div">').html('<h3>' + _("Checkouts") + '</h3>');
31
            var checkouts_list = $('<ul class="oneclickdigital-list">');
32
            data.checkouts.items.forEach(function(item) {
33
                item_line(checkouts_list, item);
34
            });
35
            checkouts_div.append(checkouts_list);
36
            $(container).append(checkouts_div);
37
        }
38
39
        if (data.holds) {
40
            var holds_div = $('<div class="oneclickdigital-div">').html('<h3>' + _("Holds") + '</h3>');
41
            var holds_list = $('<ul class="oneclickdigital-list">');
42
            data.holds.items.forEach(function(item) {
43
                item_line(holds_list, item);
44
            });
45
            holds_div.append(holds_list);
46
            $(container).append(holds_div);
47
        }
48
    }
49
50
    function item_line(ul_el, item) {
51
        var line = $('<li class="oneclickdigital-item">');
52
        if (item.images) {
53
            var thumb_url = item.images.thumbnail;
54
            if (thumb_url) {
55
                $('<img class="oneclickdigital-item-thumbnail">')
56
                    .attr("src", thumb_url)
57
                    .appendTo(line);
58
            }
59
        }
60
        $('<div class="oneclickdigital-item-title">')
61
            .text(item.title)
62
            .appendTo(line);
63
        $('<div class="oneclickdigital-item-subtitle">')
64
            .text(item.subtitle)
65
            .appendTo(line);
66
        $('<div class="oneclickdigital-item-author">')
67
            .text(item.author)
68
            .appendTo(line);
69
        var actions = $('<span class="actions">');
70
        display_actions(actions, item.isbn);
71
        $('<div id="action_'+item.isbn+'" class="actions-menu">')
72
            .append(actions)
73
            .appendTo(line);
74
75
        $(ul_el).append(line);
76
    }
77
78
    function svc_ajax ( method, params, success_callback ) {
79
        // remove when jquery is upgraded
80
        for (var key in params) {
81
            if (params[key] === null) delete params[key];
82
        }        
83
        return $.ajax({
84
            method: method,
85
            dataType: "json",
86
            url: svc_url,
87
            data: params,
88
            success: function (data) {
89
                if (data.error) {
90
                    display_error(data.error);
91
                }
92
                success_callback(data);
93
            },
94
            error: function(jqXHR, textStatus, errorThrown) {
95
                display_error(errorThrown);
96
            }
97
        });
98
    }
99
100
    function load_account_details ( callback ) {
101
        svc_ajax('get', { action: "account" }, function(data) {
102
            details = data;
103
            callback(data);
104
        });
105
    }
106
107
    function item_action (params, el) {
108
        var isbn = params.isbn;
109
        svc_ajax('post', params, function(data) {
110
            if (data.checkouts) {
111
                details.checkouts = data.checkouts;
112
            }
113
            if (data.holds) {
114
                details.holds = data.holds;
115
            }
116
            display_actions(el, isbn);
117
        });
118
    }
119
120
    function item_is_checked_out (isbn) {
121
        if ( !(details && details.checkouts) ) {
122
            return null;
123
        }
124
        var isbn_uc = isbn.toUpperCase();
125
        var items = details.checkouts.items;
126
        for (var i = 0; i < items.length; i++) {
127
            if ( items[i].isbn.toUpperCase() == isbn_uc ) {
128
                return items[i];
129
            }
130
        }
131
        return null;
132
    }
133
134
    function item_is_on_hold (isbn) {
135
        if ( !(details && details.holds) ) {
136
            return false;
137
        }
138
        var isbn_uc = isbn.toUpperCase();
139
        var items = details.holds.items;
140
        for (var i = 0; i < items.length; i++) {
141
            if ( items[i].isbn.toUpperCase() == isbn_uc ) {
142
                return items[i];
143
            }
144
        }
145
        return null;
146
    }
147
148
    function display_actions(el, isbn) {
149
        $(el).empty();
150
        if (is_identified()) {
151
152
            var item = item_is_checked_out(isbn);
153
            if (item) {
154
                var expires = new Date(item.expires);
155
                $('<span class="oneclickdigital-item-status">')
156
                    .text(_("Checked out until") + " " + expires.toLocaleString())
157
                    .appendTo(el);
158
                $(el).append(" ");
159
160
                if (item.url) {
161
                    var download = $('<a href="'+item.url+'">').appendTo(el);
162
                    decorate_button(download, _("Download"));
163
                    $(el).append(" ");
164
                }
165
166
                $(el).append( ajax_button(_("Check in"), function() {
167
                    if( confirm(_("Are you sure you want to return this item?")) ) {
168
                        item_action({action: "return", isbn: isbn}, el);
169
                    }
170
                }) );
171
172
                return item;
173
            }
174
175
            item = item_is_on_hold(isbn);
176
            if (item) {
177
                $('<span class="oneclickdigital-status">')
178
                    .text(_("On hold"))
179
                    .appendTo(el);
180
                $(el).append(" ");
181
            }
182
183
            if(checkout_popup) {
184
                $(el).append( ajax_button(_("Check out"), function() {
185
                    if( confirm(_("Are you sure you want to checkout this item?")) ) {
186
                        svc_ajax('post', {action: "checkout", isbn: isbn}, function(data) {
187
                            if (data.checkouts) {
188
                                details.checkouts = data.checkouts;
189
                            }
190
                            if (data.holds) {
191
                                details.holds = data.holds;
192
                            }
193
                            item = display_actions(el, isbn);
194
                        });
195
                    }
196
                }) );
197
            }
198
            if (!item) {
199
                $(el).append( ajax_button(_("Place hold"), function() {
200
                    item_action({action: "place_hold", isbn: isbn}, el);
201
                }) );
202
            }
203
204
            if (item) {
205
                $(el).append( ajax_button(_("Cancel"), function() {
206
                    if( confirm(_("Are you sure you want to cancel this hold?")) ) {
207
                        item_action({action: "return", isbn: isbn}, el);
208
                    }
209
                }) );
210
            }
211
            return item;
212
        }
213
    }
214
215
    function ajax_button(label, on_click) {
216
        var button = $('<a href="#">')
217
            .click(function(e) {
218
                e.preventDefault();
219
                on_click();
220
            });
221
        decorate_button(button, label);
222
        return button;
223
    }
224
225
    function decorate_button(button, label) {
226
        $(button)
227
            .addClass("btn btn-primary btn-mini")
228
            .css("color","white")
229
            .text(label);
230
    }
231
232
    this.with_account_details = function( el, callback ) {
233
        $(el).append(error_div);
234
        load_account_details( callback );
235
    }
236
237
    this.display_account_details = function( el ) {
238
        $(el).empty().append(error_div);
239
        load_account_details(function(data) {
240
            display_account(el, data);
241
        });
242
    };
243
244
    this.display_error = function( el, error ) {
245
        $(el).empty().append(error_div);
246
        display_error(error);
247
    };
248
249
    this.is_identified = is_identified;
250
251
    this.add_actions = function(el, isbn) {
252
        var actions = $('<span class="actions">');
253
        display_actions(actions, isbn);
254
        $('<div id="action_'+isbn+'" class="actions-menu">')
255
            .append(actions)
256
            .appendTo(el);
257
    };
258
259
    this.search = function( q, page_size, page, callback ) {
260
        svc_ajax('get', { action: "search", q: q, page_size: page_size, page: page }, function (data) {
261
            error = data.error;
262
            if (!data.is_identified && !error) error = _("Invalid account");
263
264
            var results;
265
            if (data.results) {
266
                results = data.results;
267
                if (!results.total) {
268
                    var total = results.items.length;
269
                    if ( total == result.page_size ) total = total + "+";
270
                    results.total = total;
271
                }
272
            }
273
            else results = {};
274
            results.error = error;
275
            callback(results);
276
        });
277
    };
278
}
(-)a/opac/opac-oneclick-search.pl (+41 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2013 ByWater
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use strict;
21
use warnings;
22
23
use CGI qw ( -utf8 );
24
25
use C4::Auth qw(:DEFAULT);
26
use C4::Output;
27
28
my $cgi = new CGI;
29
30
# Getting the template and auth
31
my ($template, $loggedinuser, $cookie)
32
= get_template_and_user({template_name => "opac-oneclick-search.tt",
33
                                query => $cgi,
34
                                type => "opac",
35
                                debug => 1,
36
                                });
37
38
$template->{'VARS'}->{'q'} = $cgi->param('q');
39
$template->{'VARS'}->{'limit'} = C4::Context->preference('OPACnumSearchResults');
40
41
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/opac/opac-search.pl (-3 / +6 lines)
Lines 988-996 $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksRe Link Here
988
$template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
988
$template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
989
$template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
989
$template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
990
990
991
if ($offset == 0 && IsOverDriveEnabled()) {
991
if ($offset == 0) {
992
    $template->param(OverDriveEnabled => 1);
992
    if (IsOverDriveEnabled()) {
993
    $template->param(OverDriveLibraryID => C4::Context->preference('OverDriveLibraryID'));
993
        $template->param(OverDriveEnabled => 1);
994
        $template->param(OverDriveLibraryID => C4::Context->preference('OverDriveLibraryID'));
995
    }
996
    $template->param(OneClickDigitalEnabled => C4::Context->preference( 'OneClickDigitalClientSecret' ) && C4::Context->preference( 'OneClickDigitalLibraryID' ));
994
}
997
}
995
998
996
    $template->param( borrowernumber    => $borrowernumber);
999
    $template->param( borrowernumber    => $borrowernumber);
(-)a/opac/opac-user.pl (+1 lines)
Lines 308-313 if (C4::Context->preference("OPACAmazonCoverImages") or Link Here
308
308
309
$template->param(
309
$template->param(
310
    OverDriveCirculation => C4::Context->preference('OverDriveCirculation') || 0,
310
    OverDriveCirculation => C4::Context->preference('OverDriveCirculation') || 0,
311
    OneClickDigitalCirculation => C4::Context->preference('OneClickDigitalClientSecret') && C4::Context->preference('OneClickDigitalLibraryID'),
311
    overdrive_error      => $query->param('overdrive_error') || undef,
312
    overdrive_error      => $query->param('overdrive_error') || undef,
312
    overdrive_tab        => $query->param('overdrive_tab') || 0,
313
    overdrive_tab        => $query->param('overdrive_tab') || 0,
313
);
314
);
(-)a/opac/svc/oneclickdigital (-1 / +131 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2016 Catalyst IT
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# Koha is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
use Modern::Perl;
20
use CGI qw ( -utf8 );
21
use JSON qw(encode_json);
22
use C4::Auth qw(checkauth);
23
use C4::Output;
24
use Koha::Logger;
25
use Koha::ExternalContent::OneClickDigital;
26
27
our $cgi = new CGI;
28
my $logger = Koha::Logger->get({ interface => 'opac' });
29
my $page_url = $cgi->referer();
30
31
my ( $user, $cookie, $sessionID, $flags ) = checkauth( $cgi, 1, {}, 'opac' );
32
$user && $sessionID or response_bad_request("User not logged in");
33
34
my $action = $cgi->param('action') or response_bad_request("No 'action' specified");
35
36
local $@;
37
my $ocd = eval { Koha::ExternalContent::OneClickDigital->new({ koha_session_id => $sessionID }) };
38
unless ($ocd) {
39
    $logger->error($@) if $@;
40
    response({
41
        is_identified => JSON::false,
42
    });
43
}
44
45
my %data = (
46
    is_identified => JSON::true,
47
);
48
{
49
    $action eq 'search' && do {
50
        my $query = $cgi->param('q');
51
        my $page  = $cgi->param('page');
52
        my $page_size = $cgi->param('page_size');
53
        my $sort = $cgi->param('sort');
54
        my $res = $ocd->search({
55
            query => $query,
56
            page  => $page,
57
            page_size => $page_size,
58
            sort => $sort,
59
        });
60
        $data{results} = $res;
61
        last;
62
    };
63
64
    $action eq 'account' && do {
65
        eval {
66
            $data{account} = $ocd->patron;
67
            $data{checkouts} = $ocd->checkouts;
68
            $data{holds} = $ocd->holds;
69
        };
70
        response_bad_request($ocd->error_message($@)) if $@;
71
        last;
72
    };
73
74
    $action eq 'checkout' && do {
75
        my $isbn = $cgi->param('isbn')
76
          or response_bad_request("No 'isbn' specified");
77
        my $format = $cgi->param('format');
78
        $data{action} = eval {  $ocd->checkout($isbn, $format) };
79
        response_bad_request($ocd->error_message($@)) if $@;
80
81
        eval {
82
            $data{checkouts} = $ocd->checkouts;
83
            $data{holds} = $ocd->holds;
84
        };
85
        $data{error} = $ocd->error_message($@) if $@;
86
        last;
87
    };
88
89
    $action eq 'place_hold' && do {
90
        my $isbn = $cgi->param('isbn')
91
          or response_bad_request("No 'isbn' specified");
92
        $data{action} = eval { $ocd->place_hold($isbn) };
93
        response_bad_request($ocd->error_message($@)) if $@;
94
95
        eval {
96
            $data{holds} = $ocd->holds;
97
        };
98
        $data{error} = $ocd->error_message($@) if $@;
99
        last;
100
    };
101
102
    $action eq 'return' && do {
103
        my $isbn = $cgi->param('isbn')
104
          or response_bad_request("No 'isbn' specified");
105
        $data{action} = eval { $ocd->return($isbn) };
106
        response_bad_request($ocd->error_message($@)) if $@;
107
108
        eval {
109
            $data{checkouts} = $ocd->checkouts;
110
            $data{holds} = $ocd->holds;
111
        };
112
        $data{error} = $ocd->error_message($@) if $@;
113
        last;
114
    };
115
116
    response_bad_request("Invalid 'action': $action");
117
}
118
119
response(\%data);
120
121
122
sub response_bad_request {
123
    my ($error) = @_;
124
    response({error => $error}, "400 $error");
125
}
126
sub response {
127
    my ($data, $status_line) = @_;
128
    $status_line ||= "200 OK";
129
    output_with_http_headers $cgi, undef, encode_json($data), 'json', $status_line;
130
    exit;
131
}

Return to bug 17602