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

(-)a/basket/basket.pl (-3 / +10 lines)
Lines 18-23 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
use JSON qw( to_json );
21
use C4::Koha;
22
use C4::Koha;
22
use C4::Biblio;
23
use C4::Biblio;
23
use C4::Items;
24
use C4::Items;
Lines 55-61 if (C4::Context->preference('TagsEnabled')) { Link Here
55
	}
56
	}
56
}
57
}
57
58
58
59
foreach my $biblionumber ( @bibs ) {
59
foreach my $biblionumber ( @bibs ) {
60
    $template->param( biblionumber => $biblionumber );
60
    $template->param( biblionumber => $biblionumber );
61
61
Lines 116-122 foreach my $biblionumber ( @bibs ) { Link Here
116
116
117
my $resultsarray = \@results;
117
my $resultsarray = \@results;
118
118
119
# my $itemsarray=\@items;
119
# Rebuild the bib_list (in case some records have been deleted)
120
my @biblionumber = map { int($_->{biblionumber}) } @results;
121
my $cookie_bib_list = $query->cookie(
122
    -name     => 'intranet_bib_list',
123
    -value    => to_json( \@biblionumber ),
124
    -HttpOnly => 0,
125
    -secure   => ( C4::Context->https_enabled() ? 1 : 0 ),
126
);
120
127
121
$template->param(
128
$template->param(
122
    BIBLIO_RESULTS => $resultsarray,
129
    BIBLIO_RESULTS => $resultsarray,
Lines 124-127 $template->param( Link Here
124
    bib_list => $bib_list,
131
    bib_list => $bib_list,
125
);
132
);
126
133
127
output_html_with_http_headers $query, $cookie, $template->output;
134
output_html_with_http_headers $query, [$cookie, $cookie_bib_list], $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/js/basket.js (-101 / +52 lines)
Lines 9-64 var CGIBIN = "/cgi-bin/koha/"; Link Here
9
9
10
var nameCookie = "intranet_bib_list";
10
var nameCookie = "intranet_bib_list";
11
var nameParam = "bib_list";
11
var nameParam = "bib_list";
12
var valCookie = readCookie(nameCookie);
12
var bib_list = readCookie(nameCookie);
13
var basketcount;
13
var basketcount = bib_list && bib_list.length > 0 ? bib_list.length : "";
14
14
15
if(valCookie){
15
function writeCookie(name, val) {
16
    var arrayRecords = valCookie.split("/");
16
    var str = JSON.stringify(val);
17
    if(arrayRecords.length > 0){
17
    Cookies.set(name, str, { path: '/' });
18
        basketcount = arrayRecords.length-1;
19
    } else {
20
        basketcount = "";
21
    }
22
} else {
23
    basketcount = "";
24
}
25
26
function writeCookie(name, val, wd) {
27
    if (wd) {
28
        parent.opener.document.cookie = name + "=" + val + "; path=/";
29
    }
30
    else {
31
        parent.document.cookie = name + "=" + val + "; path=/";
32
    }
33
}
18
}
34
19
35
function readCookie(name, wd) {
20
function readCookie(name) {
36
    var str_name = name + "=";
21
    var r = Cookies.get(name);
37
    var str_cookie = "";
22
    if ( r ) {
38
    if (wd) {
23
        return JSON.parse(r);
39
        str_cookie = parent.opener.document.cookie;
40
    }
41
    else {
42
        str_cookie = parent.document.cookie;
43
    }
44
    // fixed - getting the part of the basket that is bib_list
45
    var cookie_parts = str_cookie.split(";");
46
    for(var i=0;i < cookie_parts.length;i++) {
47
        var c = cookie_parts[i];
48
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
49
        if(c.indexOf(str_name) === 0) return c.substring(str_name.length,c.length);
50
    }
24
    }
51
    return null;
25
    r = new Array();
26
    return r;
52
}
27
}
53
28
54
function delCookie(name) {
29
function removeCookie(name) {
55
    var exp = new Date();
30
    Cookies.remove(name);
56
    exp.setTime(exp.getTime()-1);
57
    if(parent.opener){
58
        parent.opener.document.cookie = name + "=null; path=/; expires=" + exp.toGMTString();
59
    } else {
60
        document.cookie = name + "=null; path=/; expires=" + exp.toGMTString();
61
    }
62
}
31
}
63
32
64
///////////////////////////////////////////////////////////////////
33
///////////////////////////////////////////////////////////////////
Lines 67-75 function delCookie(name) { Link Here
67
36
68
function openBasket() {
37
function openBasket() {
69
    var strCookie = "";
38
    var strCookie = "";
70
    var valCookie = readCookie(nameCookie);
39
    var arrayRecords = readCookie(nameCookie);
71
    if ( valCookie ) {
40
    if ( arrayRecords.length ) {
72
        strCookie = nameParam + "=" + valCookie;
41
        strCookie = nameParam + "=" + arrayRecords.join("/");
73
    }
42
    }
74
43
75
    if ( strCookie ) {
44
    if ( strCookie ) {
Lines 85-126 function openBasket() { Link Here
85
    }
54
    }
86
}
55
}
87
56
57
function unique(array) {
58
    return $.grep(array, function(el, index) {
59
        return index === $.inArray(el, array);
60
    });
61
}
62
88
function addRecord(val, selection,NoMsgAlert) {
63
function addRecord(val, selection,NoMsgAlert) {
89
    var valCookie = readCookie(nameCookie);
90
    var write = 0;
91
64
92
    if ( ! valCookie ) { // empty basket
65
    var bib_list = readCookie(nameCookie);
93
        valCookie = val + '/';
66
94
        write = 1;
67
    if ($.inArray(val, bib_list) != -1) {
95
        updateBasket(1);
68
        if (selection) {
96
    }
69
            return 0;
97
    else {
98
        // is this record already in the basket ?
99
        var found = false;
100
        var arrayRecords = valCookie.split("/");
101
        for (var i = 0; i < valCookie.length - 1; i++) {
102
            if (val == arrayRecords[i]) {
103
                found = true;
104
                break;
105
            }
106
        }
107
        if ( found ) {
108
            if (selection) {
109
                return 0;
110
            }
111
            if (! NoMsgAlert ) {
112
                showCartUpdate( __("This item is already in your cart") );
113
            }
114
        }
70
        }
115
        else {
71
        if (! NoMsgAlert ) {
116
            valCookie += val + '/';
72
            showCartUpdate( __("This item is already in your cart") );
117
            write = 1;
118
            updateBasket(arrayRecords.length);
119
        }
73
        }
120
    }
74
    } else {
75
        bib_list.push(val);
121
76
122
    if (write) {
77
        writeCookie(nameCookie, bib_list);
123
        writeCookie(nameCookie, valCookie);
78
        updateBasket(bib_list.length);
124
        if (selection) { // when adding a selection of records
79
        if (selection) { // when adding a selection of records
125
            updateLink(val,"add");
80
            updateLink(val,"add");
126
            return 1;
81
            return 1;
Lines 154-190 function SelectAll(){ Link Here
154
function addMultiple(biblist){
109
function addMultiple(biblist){
155
    var c_value = "";
110
    var c_value = "";
156
    var i = 0;
111
    var i = 0;
112
    var new_bibs = [];
157
    if( biblist && biblist.length > 0 ) {
113
    if( biblist && biblist.length > 0 ) {
158
        for ( i=0; i < biblist.length; i++ ) {
114
        for ( i=0; i < biblist.length; i++ ) {
159
            if (biblist[i].checked) {
115
            if (biblist[i].checked) {
160
                c_value = c_value + biblist[i].value + "/";
116
                new_bibs.push(biblist[i].value);
161
            }
117
            }
162
        }
118
        }
163
    } else {
119
    } else {
164
        var bibnums = getContextBiblioNumbers();
120
        var bibnums = getContextBiblioNumbers();
165
        if ( bibnums.length > 0 ) {
121
        if ( bibnums.length > 0 ) {
166
            for ( i = 0 ; i < bibnums.length ; i++ ) {
122
            for ( i = 0 ; i < bibnums.length ; i++ ) {
167
                c_value = c_value + bibnums[i] + "/";
123
                new_bibs.push(bibnums[i]);
168
            }
124
            }
169
        } else {
125
        } else {
170
            if(document.bookbag_form.biblionumber.length > 0) {
126
            if(document.bookbag_form.biblionumber.length > 0) {
171
                for ( i=0; i < document.bookbag_form.biblionumber.length; i++ ) {
127
                for ( i=0; i < document.bookbag_form.biblionumber.length; i++ ) {
172
                    if (document.bookbag_form.biblionumber[i].checked) {
128
                    if (document.bookbag_form.biblionumber[i].checked) {
173
                        c_value = c_value + document.bookbag_form.biblionumber[i].value + "/";
129
                        new_bibs.push(document.bookbag_form.biblionumber[i].value);
174
                    }
130
                    }
175
                }
131
                }
176
            } else {
132
            } else {
177
                c_value = c_value + document.bookbag_form.biblionumber.value + "/";
133
                new_bibs.push(document.bookbag_form.biblionumber.value);
178
            }
134
            }
179
        }
135
        }
180
    }
136
    }
181
    addSelRecords(c_value);
137
    addSelRecords(new_bibs);
182
}
138
}
183
139
184
/* function for adding a selection of biblios to the basket
140
/* function for adding a selection of biblios to the basket
185
   from the results list */
141
   from the results list */
186
function addSelRecords(valSel) {
142
function addSelRecords(arrayRecords) {
187
    var arrayRecords = valSel.split("/");
188
    var i = 0;
143
    var i = 0;
189
    var nbAdd = 0;
144
    var nbAdd = 0;
190
    for (i=0;i<arrayRecords.length;i++) {
145
    for (i=0;i<arrayRecords.length;i++) {
Lines 242-253 function selRecord(num, status) { Link Here
242
}
197
}
243
198
244
function delSingleRecord(biblionumber){
199
function delSingleRecord(biblionumber){
245
    var valCookie = readCookie(nameCookie);
200
    var arrayRecords = readCookie(nameCookie);
246
    var arrayRecords = valCookie.split("/");
247
    var pos = jQuery.inArray(biblionumber,arrayRecords);
201
    var pos = jQuery.inArray(biblionumber,arrayRecords);
248
    arrayRecords.splice(pos,1);
202
    arrayRecords.splice(pos,1);
249
    valCookie = arrayRecords.join("/");
203
    writeCookie( nameCookie, arrayRecords );
250
    writeCookie( nameCookie, valCookie );
251
    updateBasket( arrayRecords.length-1 );
204
    updateBasket( arrayRecords.length-1 );
252
    updateLink(biblionumber,"del");
205
    updateLink(biblionumber,"del");
253
    showCartUpdate(__("The item has been removed from your cart"));
206
    showCartUpdate(__("The item has been removed from your cart"));
Lines 256-268 function delSingleRecord(biblionumber){ Link Here
256
function delSelRecords() {
209
function delSelRecords() {
257
    var recordsSel = 0;
210
    var recordsSel = 0;
258
    var end = 0;
211
    var end = 0;
259
    var valCookie = readCookie(nameCookie, 1);
212
    var arrayRecords = readCookie(nameCookie);
260
    var s;
213
    var s;
261
    if (valCookie) {
214
    if (arrayRecords.length) {
262
        var str = document.myform.records.value;
215
        var str = document.myform.records.value;
263
        if (str.length > 0){
216
        if (str.length > 0){
264
            recordsSel = 1;
217
            recordsSel = 1;
265
            var str2 = valCookie;
218
            var str2 = arrayRecords.join('/');
266
            while (!end){
219
            while (!end){
267
                s = str.indexOf("/");
220
                s = str.indexOf("/");
268
                if (s>0){
221
                if (s>0){
Lines 279-285 function delSelRecords() { Link Here
279
                var rep = false;
232
                var rep = false;
280
                rep = confirm(__("Are you sure you want to empty your cart?"));
233
                rep = confirm(__("Are you sure you want to empty your cart?"));
281
                if (rep) {
234
                if (rep) {
282
                    delCookie(nameCookie);
235
                    removeCookie(nameCookie);
283
                    document.location = "about:blank";
236
                    document.location = "about:blank";
284
                    updateBasket(0,top.opener);
237
                    updateBasket(0,top.opener);
285
                    window.close();
238
                    window.close();
Lines 287-302 function delSelRecords() { Link Here
287
                    return;
240
                    return;
288
                }
241
                }
289
            } else {
242
            } else {
290
                writeCookie(nameCookie, str2, 1);
243
                var new_arrayRecords = str2.split('/');
244
                writeCookie(nameCookie, new_arrayRecords);
291
            }
245
            }
292
        }
246
        }
293
    }
247
    }
294
248
295
    if (recordsSel) {
249
    if (recordsSel) {
296
        var strCookie = "";
250
        var arrayRecords = readCookie(nameCookie);
297
        valCookie = readCookie(nameCookie, 1);
251
        var strCookie = nameParam + "=" + arrayRecords.join("/");
298
        strCookie = nameParam + "=" + valCookie;
299
        var arrayRecords = valCookie.split("/");
300
        updateBasket(arrayRecords.length-1,top.opener);
252
        updateBasket(arrayRecords.length-1,top.opener);
301
        document.location = CGIBIN + "basket/basket.pl?" + strCookie;
253
        document.location = CGIBIN + "basket/basket.pl?" + strCookie;
302
    }
254
    }
Lines 333-345 function delBasket(context,rep) { Link Here
333
    }
285
    }
334
    if (rep) {
286
    if (rep) {
335
        if(context == "popup"){
287
        if(context == "popup"){
336
            delCookie(nameCookie);
288
            removeCookie(nameCookie);
337
            updateAllLinks(top.opener);
289
            updateAllLinks(top.opener);
338
            document.location = "about:blank";
290
            document.location = "about:blank";
339
            updateBasket(0,top.opener);
291
            updateBasket(0,top.opener);
340
            window.close();
292
            window.close();
341
        } else {
293
        } else {
342
            delCookie(nameCookie);
294
            removeCookie(nameCookie);
343
            updateBasket(0,top.opener);
295
            updateBasket(0,top.opener);
344
        }
296
        }
345
    }
297
    }
346
- 

Return to bug 27767