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 AllAreChecked(s){
136 if (! s.length) { return false;}
138 for (var i=0; i < l; i++) {
139 if(! s[i].checked) { return false; }
144 function SelectAll(){
145 if(document.bookbag_form.biblionumber.length > 0) {
146 var checky = AllAreChecked(document.bookbag_form.biblionumber);
147 var l = document.bookbag_form.biblionumber.length;
148 for (var i=0; i < l; i++) {
149 document.bookbag_form.biblionumber[i].checked = (checky) ? false : true;
154 function addMultiple(){
156 if(document.bookbag_form.biblionumber.length > 0) {
157 for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
158 if (document.bookbag_form.biblionumber[i].checked) {
159 c_value = c_value + document.bookbag_form.biblionumber[i].value + "/";
162 addSelRecords(c_value);
164 c_value = c_value + document.bookbag_form.biblionumber.value + "/";
165 addSelRecords(c_value);
169 function addSelRecords(valSel) { // function for adding a selection of biblios to the basket
170 // from the results list
171 var arrayRecords = valSel.split("/");
174 for (i=0;i<arrayRecords.length;i++) {
175 if (arrayRecords[i]) {
176 nbAdd += addRecord(arrayRecords[i], 1);
186 msg = nbAdd+" "+MSG_NRECORDS_ADDED+", "+(i-nbAdd)+" "+MSG_NRECORDS_IN_BASKET;
189 msg = nbAdd+" "+MSG_NRECORDS_ADDED;
194 msg = MSG_NO_RECORD_SELECTED;
197 msg = MSG_NO_RECORD_ADDED+" ("+MSG_NRECORDS_IN_BASKET+") !";
204 function selRecord(num, status) {
205 var str = document.myform.records.value
210 str = delRecord(num, str);
213 document.myform.records.value = str;
216 function delSelRecords() {
219 var nameCookie = "bib_list";
220 var valCookie = readCookie(nameCookie, 1);
223 var str = document.myform.records.value;
226 var str2 = valCookie;
228 s = str.indexOf("/");
230 num = str.substring(0, s)
231 str = delRecord(num,str);
232 str2 = delRecord(num,str2);
238 if (str2.length == 0) { // equivalent to emptying the basket
240 rep = confirm(MSG_CONFIRM_DEL_BASKET);
242 delCookie(nameCookie);
243 document.location = "about:blank";
244 updateBasket(0,top.opener.document);
250 writeCookie(nameCookie, str2, 1);
257 var nameCookie = "bib_list";
258 var valCookie = readCookie(nameCookie, 1);
259 strCookie = nameCookie + "=" + valCookie;
260 var arrayRecords = valCookie.split("/");
261 updateBasket(arrayRecords.length-1,top.opener.document);
262 document.location = CGIBIN + "opac-basket.pl?" + strCookie;
265 alert(MSG_NO_RECORD_SELECTED);
269 function delRecord (n, s) {
276 pos = aux.indexOf(n, pos+1);
277 var charAfter = aux.charAt(pos+n.length); // character right after the researched string
278 if (charAfter.match(re)) { // record number inside another one
281 else { // good record number
282 aux = s.substring(0, pos)+ s.substring(pos+n.length+1, s.length);
292 function delBasket() {
293 var nameCookie = "bib_list";
296 rep = confirm(MSG_CONFIRM_DEL_BASKET);
298 delCookie(nameCookie);
299 document.location = "about:blank";
300 updateBasket(0,top.opener.document);
307 if (document.myform.records.value) {
309 rep = confirm(MSG_CONFIRM_DEL_RECORDS);
314 updateBasket(arrayRecords.length-1,top.opener.document);
318 function sendBasket() {
319 var nameCookie = "bib_list";
320 var valCookie = readCookie(nameCookie);
321 var strCookie = nameCookie + "=" + valCookie;
323 var loc = CGIBIN + "opac-sendbasket.pl?" + strCookie;
325 var optWin="dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100";
326 var win_form = open(loc,"win_form",optWin);
329 function printBasket() {
330 var loc = document.location + "&print=1";
331 document.location = loc;
334 function showMore() {
337 var nameCookie = "bib_list";
338 var valCookie = readCookie(nameCookie);
340 strCookie = nameCookie + "=" + valCookie;
342 var loc = CGIBIN + "opac-basket.pl?" + strCookie + "&verbose=1";
343 document.location = loc;
346 function showLess() {
349 var nameCookie = "bib_list";
350 var valCookie = readCookie(nameCookie);
352 strCookie = nameCookie + "=" + valCookie;
354 var loc = CGIBIN + "opac-basket.pl?" + strCookie + "&verbose=0";
355 document.location = loc;
358 function updateBasket(updated_value,target) {
359 if(typeof document.getElementById != "undefined") {
360 if(target.getElementById('basket')){
361 target.getElementById('basket').innerHTML = "<div>"+updated_value+"</div>";
363 if(target.getElementById('cartDetails')){
364 target.getElementById('cartDetails').innerHTML = _("Your cart contains ")+updated_value+_(" items");
366 } else if (typeof document.layers != "undefined") {
367 target.layers['basket'].open();
368 target.layers['basket'].write(" ("+updated_value+")");
369 target.layers['basket'].close();
370 } else if(typeof document.all != "undefined" && typeof
371 document.getElementById == "undefined") {
372 target.all['basket'].innerHTML = " ("+updated_value+")";
374 var basketcount = updated_value;
377 function openBiblio(dest,biblionumber) {
378 openerURL=dest+"?biblionumber="+biblionumber;
379 opener.document.location = openerURL;
383 function addSelToShelf() {
384 var items = document.getElementById('records').value;
385 document.location = "/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber="+items;
388 /// vShelfAdd() builds url string for multiple-biblio adds.
390 function vShelfAdd() {
392 if(document.bookbag_form.biblionumber.length > 0) {
393 for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
394 if (document.bookbag_form.biblionumber[i].checked) {
395 bibs.push("biblionumber=" + document.bookbag_form.biblionumber[i].value);
398 return bibs.join("&");