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 addSelRecords(valSel) { // function for adding a selection of biblios to the basket
163 // from the results list
164 var arrayRecords = valSel.split("/");
167 for (i=0;i<arrayRecords.length;i++) {
168 if (arrayRecords[i]) {
169 nbAdd += addRecord(arrayRecords[i], 1);
179 msg = nbAdd+" "+MSG_NRECORDS_ADDED+", "+(i-nbAdd)+" "+MSG_NRECORDS_IN_BASKET;
182 msg = nbAdd+" "+MSG_NRECORDS_ADDED;
187 msg = MSG_NO_RECORD_SELECTED;
190 msg = MSG_NO_RECORD_ADDED+" ("+MSG_NRECORDS_IN_BASKET+") !";
197 function selRecord(num, status) {
198 var str = document.myform.records.value
203 str = delRecord(num, str);
206 document.myform.records.value = str;
209 function delSelRecords() {
212 var nameCookie = "bib_list";
213 var valCookie = readCookie(nameCookie, 1);
216 var str = document.myform.records.value;
219 var str2 = valCookie;
221 s = str.indexOf("/");
223 num = str.substring(0, s)
224 str = delRecord(num,str);
225 str2 = delRecord(num,str2);
231 if (str2.length == 0) { // equivalent to emptying the basket
233 rep = confirm(MSG_CONFIRM_DEL_BASKET);
235 delCookie(nameCookie);
236 document.location = "about:blank";
237 updateBasket(0,top.opener.document);
243 writeCookie(nameCookie, str2, 1);
250 var nameCookie = "bib_list";
251 var valCookie = readCookie(nameCookie, 1);
252 strCookie = nameCookie + "=" + valCookie;
253 var arrayRecords = valCookie.split("/");
254 updateBasket(arrayRecords.length-1,top.opener.document);
255 document.location = CGIBIN + "opac-basket.pl?" + strCookie;
258 alert(MSG_NO_RECORD_SELECTED);
262 function delRecord (n, s) {
269 pos = aux.indexOf(n, pos+1);
270 var charAfter = aux.charAt(pos+n.length); // character right after the researched string
271 if (charAfter.match(re)) { // record number inside another one
274 else { // good record number
275 aux = s.substring(0, pos)+ s.substring(pos+n.length+1, s.length);
285 function delBasket() {
286 var nameCookie = "bib_list";
289 rep = confirm(MSG_CONFIRM_DEL_BASKET);
291 delCookie(nameCookie);
292 document.location = "about:blank";
293 updateBasket(0,top.opener.document);
300 if (document.myform.records.value) {
302 rep = confirm(MSG_CONFIRM_DEL_RECORDS);
307 updateBasket(arrayRecords.length-1,top.opener.document);
311 function sendBasket() {
312 var nameCookie = "bib_list";
313 var valCookie = readCookie(nameCookie);
314 var strCookie = nameCookie + "=" + valCookie;
316 var loc = CGIBIN + "opac-sendbasket.pl?" + strCookie;
318 var optWin="dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100";
319 var win_form = open(loc,"win_form",optWin);
322 function printBasket() {
323 var loc = document.location + "&print=1";
324 document.location = loc;
327 function showMore() {
330 var nameCookie = "bib_list";
331 var valCookie = readCookie(nameCookie);
333 strCookie = nameCookie + "=" + valCookie;
335 var loc = CGIBIN + "opac-basket.pl?" + strCookie + "&verbose=1";
336 document.location = loc;
339 function showLess() {
342 var nameCookie = "bib_list";
343 var valCookie = readCookie(nameCookie);
345 strCookie = nameCookie + "=" + valCookie;
347 var loc = CGIBIN + "opac-basket.pl?" + strCookie + "&verbose=0";
348 document.location = loc;
351 function updateBasket(updated_value,target) {
352 if(typeof document.getElementById != "undefined") {
353 target.getElementById('basket').innerHTML = " ("+updated_value+")";
354 } else if (typeof document.layers != "undefined") {
355 target.layers['basket'].open();
356 target.layers['basket'].write(" ("+updated_value+")");
357 target.layers['basket'].close();
358 } else if(typeof document.all != "undefined" && typeof
359 document.getElementById == "undefined") {
360 target.all['basket'].innerHTML = " ("+updated_value+")";
364 function openBiblio(dest,biblionumber) {
365 openerURL=dest+"?biblionumber="+biblionumber;
366 opener.document.location = openerURL;
370 function addSelToShelf() {
371 var items = document.getElementById('records').value;
372 document.location = "/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber="+items;
375 /// vShelfAdd() builds url string for multiple-biblio adds.
377 function vShelfAdd() {
379 if(document.bookbag_form.biblionumber.length > 0) {
380 for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
381 if (document.bookbag_form.biblionumber[i].checked) {
382 bibs.push("biblionumber=" + document.bookbag_form.biblionumber[i].value);
385 return bibs.join("&");