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 832-837 Using this account is not recommended because some parts of Koha will not functi Link Here
832
[% IF ( OverDriveCirculation ) %]
837
[% IF ( OverDriveCirculation ) %]
833
[% INCLUDE 'overdrive-checkout.inc' %]
838
[% INCLUDE 'overdrive-checkout.inc' %]
834
[% END %]
839
[% END %]
840
[% IF ( OneClickDigitalCirculation ) %]
841
[% INCLUDE 'oneclick-checkout.inc' %]
842
[% END %]
835
843
836
[% INCLUDE 'opac-bottom.inc' %]
844
[% INCLUDE 'opac-bottom.inc' %]
837
845
Lines 897-902 Using this account is not recommended because some parts of Koha will not functi Link Here
897
        //]]>
905
        //]]>
898
    </script>
906
    </script>
899
    <script type="text/javascript" src="[% interface %]//[% theme %]/js/overdrive.js"></script>
907
    <script type="text/javascript" src="[% interface %]//[% theme %]/js/overdrive.js"></script>
908
    <script type="text/javascript" src="[% interface %]//[% theme %]/js/oneclickdigital.js"></script>
900
    <script type="text/JavaScript">
909
    <script type="text/JavaScript">
901
    $(document).ready(function() {
910
    $(document).ready(function() {
902
    [% IF ( overdrive_error ) %]
911
    [% IF ( overdrive_error ) %]
Lines 908-913 Using this account is not recommended because some parts of Koha will not functi Link Here
908
        $("#opac-user-overdrive").each( function() {
917
        $("#opac-user-overdrive").each( function() {
909
            KOHA.OverDriveCirculation.display_account_details(this);
918
            KOHA.OverDriveCirculation.display_account_details(this);
910
        } );
919
        } );
920
921
    [% IF ( oneclickdigital_error ) %]
922
        KOHA.OneClickDigital.display_error("#opac-user-oneclickdigital", "[% oneclickdigital_error.dquote %]");
923
    [% END %]
924
    [% IF ( oneclickdigital_tab ) %]
925
        $("#opac-user-views").tabs("select", "#opac-user-oneclickdigital");
926
    [% END %]
927
        $("#opac-user-oneclickdigital").each( function() {
928
            KOHA.OneClickDigital.display_account_details(this);
929
        } );
911
    });
930
    });
912
    </script>
931
    </script>
913
[% END %]
932
[% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/oneclickdigital.js (+274 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
        return $.ajax({
80
            method: method,
81
            dataType: "json",
82
            url: svc_url,
83
            data: params,
84
            success: function (data) {
85
                if (data.error) {
86
                    display_error(data.error);
87
                }
88
                success_callback(data);
89
            },
90
            error: function(jqXHR, textStatus, errorThrown) {
91
                display_error(errorThrown);
92
            }
93
        });
94
    }
95
96
    function load_account_details ( callback ) {
97
        svc_ajax('get', { action: "account" }, function(data) {
98
            details = data;
99
            callback(data);
100
        });
101
    }
102
103
    function item_action (params, el) {
104
        var isbn = params.isbn;
105
        svc_ajax('post', params, function(data) {
106
            if (data.checkouts) {
107
                details.checkouts = data.checkouts;
108
            }
109
            if (data.holds) {
110
                details.holds = data.holds;
111
            }
112
            display_actions(el, isbn);
113
        });
114
    }
115
116
    function item_is_checked_out (isbn) {
117
        if ( !(details && details.checkouts) ) {
118
            return null;
119
        }
120
        var isbn_uc = isbn.toUpperCase();
121
        var items = details.checkouts.items;
122
        for (var i = 0; i < items.length; i++) {
123
            if ( items[i].isbn.toUpperCase() == isbn_uc ) {
124
                return items[i];
125
            }
126
        }
127
        return null;
128
    }
129
130
    function item_is_on_hold (isbn) {
131
        if ( !(details && details.holds) ) {
132
            return false;
133
        }
134
        var isbn_uc = isbn.toUpperCase();
135
        var items = details.holds.items;
136
        for (var i = 0; i < items.length; i++) {
137
            if ( items[i].isbn.toUpperCase() == isbn_uc ) {
138
                return items[i];
139
            }
140
        }
141
        return null;
142
    }
143
144
    function display_actions(el, isbn) {
145
        $(el).empty();
146
        if (is_identified()) {
147
148
            var item = item_is_checked_out(isbn);
149
            if (item) {
150
                var expires = new Date(item.expires);
151
                $('<span class="oneclickdigital-item-status">')
152
                    .text(_("Checked out until") + " " + expires.toLocaleString())
153
                    .appendTo(el);
154
                $(el).append(" ");
155
156
                if (item.url) {
157
                    var download = $('<a href="'+item.url+'">').appendTo(el);
158
                    decorate_button(download, _("Download"));
159
                    $(el).append(" ");
160
                }
161
162
                $(el).append( ajax_button(_("Check in"), function() {
163
                    if( confirm(_("Are you sure you want to return this item?")) ) {
164
                        item_action({action: "return", isbn: isbn}, el);
165
                    }
166
                }) );
167
168
                return item;
169
            }
170
171
            item = item_is_on_hold(isbn);
172
            if (item) {
173
                $('<span class="oneclickdigital-status">')
174
                    .text(_("On hold"))
175
                    .appendTo(el);
176
                $(el).append(" ");
177
            }
178
179
            if(checkout_popup) {
180
                $(el).append( ajax_button(_("Check out"), function() {
181
                    if( confirm(_("Are you sure you want to checkout this item?")) ) {
182
                        svc_ajax('post', {action: "checkout", isbn: isbn}, function(data) {
183
                            if (data.checkouts) {
184
                                details.checkouts = data.checkouts;
185
                            }
186
                            if (data.holds) {
187
                                details.holds = data.holds;
188
                            }
189
                            item = display_actions(el, isbn);
190
                        });
191
                    }
192
                }) );
193
            }
194
            if (!item) {
195
                $(el).append( ajax_button(_("Place hold"), function() {
196
                    item_action({action: "place_hold", isbn: isbn}, el);
197
                }) );
198
            }
199
200
            if (item) {
201
                $(el).append( ajax_button(_("Cancel"), function() {
202
                    if( confirm(_("Are you sure you want to cancel this hold?")) ) {
203
                        item_action({action: "return", isbn: isbn}, el);
204
                    }
205
                }) );
206
            }
207
            return item;
208
        }
209
    }
210
211
    function ajax_button(label, on_click) {
212
        var button = $('<a href="#">')
213
            .click(function(e) {
214
                e.preventDefault();
215
                on_click();
216
            });
217
        decorate_button(button, label);
218
        return button;
219
    }
220
221
    function decorate_button(button, label) {
222
        $(button)
223
            .addClass("btn btn-primary btn-mini")
224
            .css("color","white")
225
            .text(label);
226
    }
227
228
    this.with_account_details = function( el, callback ) {
229
        $(el).append(error_div);
230
        load_account_details( callback );
231
    }
232
233
    this.display_account_details = function( el ) {
234
        $(el).empty().append(error_div);
235
        load_account_details(function(data) {
236
            display_account(el, data);
237
        });
238
    };
239
240
    this.display_error = function( el, error ) {
241
        $(el).empty().append(error_div);
242
        display_error(error);
243
    };
244
245
    this.is_identified = is_identified;
246
247
    this.add_actions = function(el, isbn) {
248
        var actions = $('<span class="actions">');
249
        display_actions(actions, isbn);
250
        $('<div id="action_'+isbn+'" class="actions-menu">')
251
            .append(actions)
252
            .appendTo(el);
253
    };
254
255
    this.search = function( q, page_size, page, callback ) {
256
        svc_ajax('get', { action: "search", q: q, page_size: page_size, page: page }, function (data) {
257
            error = data.error;
258
            if (!data.is_identified && !error) error = _("Invalid account");
259
260
            var results;
261
            if (data.results) {
262
                results = data.results;
263
                if (!results.total) {
264
                    var total = results.items.length;
265
                    if ( total == result.page_size ) total = total + "+";
266
                    results.total = total;
267
                }
268
            }
269
            else results = {};
270
            results.error = error;
271
            callback(results);
272
        });
273
    };
274
}
(-)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 992-1000 $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksRe Link Here
992
$template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
992
$template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
993
$template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
993
$template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
994
994
995
if ($offset == 0 && IsOverDriveEnabled()) {
995
if ($offset == 0) {
996
    $template->param(OverDriveEnabled => 1);
996
    if (IsOverDriveEnabled()) {
997
    $template->param(OverDriveLibraryID => C4::Context->preference('OverDriveLibraryID'));
997
        $template->param(OverDriveEnabled => 1);
998
        $template->param(OverDriveLibraryID => C4::Context->preference('OverDriveLibraryID'));
999
    }
1000
    $template->param(OneClickDigitalEnabled => C4::Context->preference( 'OneClickDigitalClientSecret' ) && C4::Context->preference( 'OneClickDigitalLibraryID' ));
998
}
1001
}
999
1002
1000
    $template->param( borrowernumber    => $borrowernumber);
1003
    $template->param( borrowernumber    => $borrowernumber);
(-)a/opac/opac-user.pl (+1 lines)
Lines 306-311 if (C4::Context->preference("OPACAmazonCoverImages") or Link Here
306
306
307
$template->param(
307
$template->param(
308
    OverDriveCirculation => C4::Context->preference('OverDriveCirculation') || 0,
308
    OverDriveCirculation => C4::Context->preference('OverDriveCirculation') || 0,
309
    OneClickDigitalCirculation => C4::Context->preference('OneClickDigitalClientSecret') && C4::Context->preference('OneClickDigitalLibraryID'),
309
    overdrive_error      => $query->param('overdrive_error') || undef,
310
    overdrive_error      => $query->param('overdrive_error') || undef,
310
    overdrive_tab        => $query->param('overdrive_tab') || 0,
311
    overdrive_tab        => $query->param('overdrive_tab') || 0,
311
);
312
);
(-)a/opac/svc/oneclickdigital (-1 / +109 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 $res = $ocd->search({
51
            query => $cgi->param('q'),
52
            page  => $cgi->param('page'),
53
            page_size => $cgi->param('page_size'),
54
            sort => $cgi->param('sort'),
55
        });
56
        $data{results} = $res;
57
        last;
58
    };
59
60
    $action eq 'account' && do {
61
        $data{account} = $ocd->patron;
62
        $data{checkouts} = $ocd->checkouts;
63
        $data{holds} = $ocd->holds;
64
        last;
65
    };
66
67
    $action eq 'checkout' && do {
68
        my $isbn = $cgi->param('isbn')
69
          or response_bad_request("No 'isbn' specified");
70
        my $format = $cgi->param('format');
71
        $data{action} = $ocd->checkout($isbn, $format);
72
        $data{checkouts} = $ocd->checkouts;
73
        $data{holds} = $ocd->holds;
74
        last;
75
    };
76
77
    $action eq 'place_hold' && do {
78
        my $isbn = $cgi->param('isbn')
79
          or response_bad_request("No 'isbn' specified");
80
        $data{action} = $ocd->place_hold($isbn);
81
        $data{holds} = $ocd->holds;
82
        last;
83
    };
84
85
    $action eq 'return' && do {
86
        my $isbn = $cgi->param('isbn')
87
          or response_bad_request("No 'isbn' specified");
88
        $data{action} = $ocd->return($isbn);
89
        $data{checkouts} = $ocd->checkouts;
90
        $data{holds} = $ocd->holds;
91
        last;
92
    };
93
94
    response_bad_request("Invalid 'action': $action");
95
}
96
97
response(\%data);
98
99
100
sub response_bad_request {
101
    my ($error) = @_;
102
    response({error => $error}, "400 $error");
103
}
104
sub response {
105
    my ($data, $status_line) = @_;
106
    $status_line ||= "200 OK";
107
    output_with_http_headers $cgi, undef, encode_json($data), 'json', $status_line;
108
    exit;
109
}

Return to bug 17602