1 //////////////////////////////////////////////////////////////////////////////
2 // BASIC FUNCTIONS FOR COOKIE MANGEMENT //
3 //////////////////////////////////////////////////////////////////////////////
5 var CGIBIN = "/cgi-bin/koha/";
8 var nameCookie = "bib_list";
9 var valCookie = readCookie(nameCookie);
12 var arrayRecords = valCookie.split("/");
13 if(arrayRecords.length > 0){
14 var basketcount = " ("+(arrayRecords.length-1)+")";
22 function writeCookie(name, val, wd) {
24 parent.opener.document.cookie = name + "=" + val;
27 parent.document.cookie = name + "=" + val;
31 function readCookieValue (str, val_beg) {
32 var val_end = str.indexOf(";", val_end);
35 return str.substring(val_beg, val_end);
38 function readCookie(name, wd) {
39 var str_name = name + "=";
40 var str_len = str_name.length;
43 str_cookie = parent.opener.document.cookie;
46 str_cookie = parent.document.cookie;
48 // fixed - getting the part of the basket that is bib_list
49 var cookie_parts = str_cookie.split(";");
50 for(var i=0;i < cookie_parts.length;i++) {
51 var c = cookie_parts[i];
52 while (c.charAt(0)==' ') c = c.substring(1,c.length);
53 if(c.indexOf(str_name) == 0) return c.substring(str_name.length,c.length);
58 function delCookie(name) {
60 exp.setTime(exp.getTime()-1);
61 parent.opener.document.cookie = name + "=null; expires=" + exp.toGMTString();
64 ///////////////////////////////////////////////////////////////////
65 // SPECIFIC FUNCTIONS USING COOKIES //
66 ///////////////////////////////////////////////////////////////////
68 function openBasket() {
70 var nameCookie = "bib_list";
71 var valCookie = readCookie(nameCookie);
73 strCookie = nameCookie + "=" + valCookie;
79 var optWin = "dependant=yes,status=yes,scrollbars=yes,resizable=yes,toolbar=no,adressbar=no,height="+iH+",width="+iW;
80 var loc = CGIBIN + "opac-basket.pl?" + strCookie;
81 var basket = open(loc, "basket", optWin);
82 if (window.focus) {basket.focus()}
85 alert(MSG_BASKET_EMPTY);
89 function addRecord(val, selection,NoMsgAlert) {
90 var nameCookie = "bib_list";
91 var valCookie = readCookie(nameCookie);
94 if ( ! valCookie ) { // empty basket
95 valCookie = val + '/';
97 updateBasket(1,document);
100 // is this record already in the basket ?
102 var arrayRecords = valCookie.split("/");
103 for (var i = 0; i < valCookie.length - 1; i++) {
104 if (val == arrayRecords[i]) {
114 alert(MSG_RECORD_IN_BASKET);
118 valCookie += val + '/';
120 updateBasket(arrayRecords.length,document);
125 writeCookie(nameCookie, valCookie);
126 if (selection) { // when adding a selection of records
130 alert(MSG_RECORD_ADDED);
135 function SelectAll(){
136 if(document.bookbag_form.biblionumber.length > 0) {
137 for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
138 if (document.bookbag_form.select_all.checked) {
139 document.bookbag_form.biblionumber[i].checked=true;
141 document.bookbag_form.biblionumber[i].checked=false;
147 function addMultiple(){
149 if(document.bookbag_form.biblionumber.length > 0) {
150 for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
151 if (document.bookbag_form.biblionumber[i].checked) {
152 c_value = c_value + document.bookbag_form.biblionumber[i].value + "/";
155 addSelRecords(c_value);
157 c_value = c_value + document.bookbag_form.biblionumber.value + "/";
158 addSelRecords(c_value);
162 function addSelToShelf() {
163 var items = document.getElementById('records').value;
164 document.location = "/cgi-bin/koha/opac-addbookbybiblionumber.pl?biblionumber="+items;
167 function addSelRecords(valSel) { // function for adding a selection of biblios to the basket
168 // from the results list
169 var arrayRecords = valSel.split("/");
172 for (i=0;i<arrayRecords.length;i++) {
173 if (arrayRecords[i]) {
174 nbAdd += addRecord(arrayRecords[i], 1);
184 msg = nbAdd+" "+MSG_NRECORDS_ADDED+", "+(i-nbAdd)+" "+MSG_NRECORDS_IN_BASKET;
187 msg = nbAdd+" "+MSG_NRECORDS_ADDED;
192 msg = MSG_NO_RECORD_SELECTED;
195 msg = MSG_NO_RECORD_ADDED+" ("+MSG_NRECORDS_IN_BASKET+") !";
202 function selRecord(num, status) {
203 var str = document.myform.records.value
208 str = delRecord(num, str);
211 document.myform.records.value = str;
214 function delSelRecords() {
217 var nameCookie = "bib_list";
218 var valCookie = readCookie(nameCookie, 1);
221 var str = document.myform.records.value;
224 var str2 = valCookie;
226 s = str.indexOf("/");
228 num = str.substring(0, s)
229 str = delRecord(num,str);
230 str2 = delRecord(num,str2);
236 if (str2.length == 0) { // equivalent to emptying the basket
238 rep = confirm(MSG_CONFIRM_DEL_BASKET);
240 delCookie(nameCookie);
241 document.location = "about:blank";
242 updateBasket(0,top.opener.document);
248 writeCookie(nameCookie, str2, 1);
255 var nameCookie = "bib_list";
256 var valCookie = readCookie(nameCookie, 1);
257 strCookie = nameCookie + "=" + valCookie;
258 var arrayRecords = valCookie.split("/");
259 updateBasket(arrayRecords.length-1,top.opener.document);
260 document.location = CGIBIN + "opac-basket.pl?" + strCookie;
263 alert(MSG_NO_RECORD_SELECTED);
267 function delRecord (n, s) {
274 pos = aux.indexOf(n, pos+1);
275 var charAfter = aux.charAt(pos+n.length); // character right after the researched string
276 if (charAfter.match(re)) { // record number inside another one
279 else { // good record number
280 aux = s.substring(0, pos)+ s.substring(pos+n.length+1, s.length);
290 function delBasket() {
291 var nameCookie = "bib_list";
294 rep = confirm(MSG_CONFIRM_DEL_BASKET);
296 delCookie(nameCookie);
297 document.location = "about:blank";
298 updateBasket(0,top.opener.document);
305 if (document.myform.records.value) {
307 rep = confirm(MSG_CONFIRM_DEL_RECORDS);
312 updateBasket(arrayRecords.length-1,top.opener.document);
316 function sendBasket() {
317 var nameCookie = "bib_list";
318 var valCookie = readCookie(nameCookie);
319 var strCookie = nameCookie + "=" + valCookie;
321 var loc = CGIBIN + "opac-sendbasket.pl?" + strCookie;
323 var optWin="dependant=yes,scrollbars=no,resizable=no,height=300,width=400,top=50,left=100";
324 var win_form = open(loc,"win_form",optWin);
327 function printBasket() {
328 var loc = document.location + "&print=1";
329 document.location = loc;
332 function showMore() {
335 var nameCookie = "bib_list";
336 var valCookie = readCookie(nameCookie);
338 strCookie = nameCookie + "=" + valCookie;
340 var loc = CGIBIN + "opac-basket.pl?" + strCookie + "&verbose=1";
341 document.location = loc;
344 function showLess() {
347 var nameCookie = "bib_list";
348 var valCookie = readCookie(nameCookie);
350 strCookie = nameCookie + "=" + valCookie;
352 var loc = CGIBIN + "opac-basket.pl?" + strCookie + "&verbose=0";
353 document.location = loc;
356 function updateBasket(updated_value,target) {
357 if(typeof document.getElementById != "undefined") {
358 target.getElementById('basket').innerHTML = " ("+updated_value+")";
359 } else if (typeof document.layers != "undefined") {
360 target.layers['basket'].open();
361 target.layers['basket'].write(" ("+updated_value+")");
362 target.layers['basket'].close();
363 } else if(typeof document.all != "undefined" && typeof
364 document.getElementById == "undefined") {
365 target.all['basket'].innerHTML = " ("+updated_value+")";
369 function openBiblio(dest,biblionumber) {
370 openerURL=dest+"?biblionumber="+biblionumber;
371 opener.document.location = openerURL;