// Licensed Materials - Property of IBM // // IBM Cognos Products: ps // // (C) Copyright IBM Corp. 2005, 2019 // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. // Define the limit for max No. of characters that we want to store in a browser cookie. Cognos customers can "potentially" modify this in this file. // Use ~ 80% of actual browser limit of 4094 bytes. This limit should be checked when setting cookies that could potentially exceed the limit. var g_iMaxAllowableCookieSize = 3275; var g_cc_state = "cc_state"; function setCookie(name, value, expires, path, domain, secure) { // We could be very strict and prevent the cookie size from going over the limit right here but that would penalize small cookies too. // if ((document.cookie.length + value.length) > g_iMaxAllowableCookieSize) { // return; // } if (!path) { path = getPath(); } if (!domain) { domain = getDomain(); } if (!secure) { secure = getSecure(); } document.cookie = name + "=" + value + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); } function delCookie(name, path, domain) { if (path == null) { path = getPath(); } if (!domain) { domain = getDomain(); } var expires = new Date(); if (getCookie(name)) { document.cookie = name + "=" + ("; expires=" + expires.toGMTString()) + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : ""); } } function getCookie(name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { return getCookieVal(j); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) { break; } } return null; } function getCookieVal(offset) { var endstr = document.cookie.indexOf(";", offset); if (endstr == -1) { endstr = document.cookie.length; } return document.cookie.substring(offset, endstr); } function setExpireDate(nOffset) { if (!nOffset) { nOffset = 0; } var expdate = new Date(); expdate.setTime(expdate.getTime() + nOffset); return expdate; } function getPath() { if (typeof sCookiePath != 'undefined' && sCookiePath != "") { return sCookiePath; } else { return location.pathname.substring(0, location.pathname.lastIndexOf("/")); } } function getDomain() { if (typeof sCookieDomain != 'undefined') { return sCookieDomain; } return null; } function getSecure() { if ((typeof sCookieSecure != 'undefined') && (sCookieSecure === 'true')) { return true; } return null; } function getSessionString() { var sSession = getCookie(g_cc_state); if (sSession != null) { var indexOfFirstQuote = sSession.indexOf('"'); if (indexOfFirstQuote == 0) { var newSession = sSession.substring(1, sSession.length - 1); sSession = newSession; } } return sSession; } function setStateValue(sName, sValue) { var sSession = getSessionString(); //-- If we have no session or it is empty or the name is invalid then return. if (!(sName == "" || sName == null)) { var sNewSession = ""; if (sSession == "" || sSession == "null" || sSession == null) { sNewSession = sName + sNameValueDelimiter + sValue; } else { var aSession = []; var bParameterExists = false; // unpack the session aSession = sSession.split(sParamDelimiter); var n = aSession.length; // update the specified parameter for (var i = 0; i < n; i++) { if (aSession[i].indexOf(sName) == 0) { aSession[i] = sName + sNameValueDelimiter + sValue; bParameterExists = true; break; } } // if a value was updated in the existing session then repack the session, otherwise just append the new param at the end. if (!bParameterExists) { sNewSession = sSession + sParamDelimiter + sName + sNameValueDelimiter + sValue; } else { // pack the updated session sNewSession = aSession.join(sParamDelimiter); } } // Save the new session ...(since cc_state always has a : we must quote it setCookie(g_cc_state, "\"" + sNewSession + "\"", 0, getPath()); } return; } function clearSessionEntry(sNames) { var sSession = getSessionString(); if (sSession != "" && sSession != "null" && sSession != null) { var newSession = sSession; var aName = []; // Unpack the elements passed in to remove from the cc_state. // The format of sNames is the same as what is used for the cc_state cookie [[separator ]...]) aName = sNames.split(sParamDelimiter); var n = aName.length; for (var i = 0; i < n; i++) { var sName = aName[i]; // index in the session of the named entry. var iStart = newSession.indexOf(sName); if (iStart != -1) { var frontEnd = null; var backEnd = null; // index in the session after the named entry. var iEnd = iStart + sName.length + sNameValueDelimiter.length; // Get the info from the session before the named entry. if (--iStart > 0) { frontEnd = newSession.substring(0, iStart); } if (iEnd < newSession.length) { // Get the info from the session after the named entry - including the parameter delimiter. backEnd = newSession.substring(iEnd); iEnd = backEnd.indexOf(sParamDelimiter); if (iEnd != -1) { backEnd = backEnd.substring(++iEnd); } else { backEnd = null; } } // Put the info together again - without the named entry if (backEnd != null && frontEnd != null) { newSession = frontEnd + sParamDelimiter + backEnd; } else { if (backEnd == null) { newSession = frontEnd; } else { if (frontEnd == null) { newSession = backEnd; } } } } } // Save the new session ...(since cc_state always has a : we must quote it setCookie(g_cc_state, "\"" + newSession + "\"", 0, getPath()); } } function getSessionValue(sName) { // Get the current session var sSession = getSessionString(); var sRetValue = null; // If we have no session or it is empty then return null. if (sSession != "" && sSession != "null" && sSession != null) { var aSession = []; aSession = sSession.split(sParamDelimiter); var n = aSession.length; // unpack the session and update the specified parameter for (var i = 0; i < n; i++) { if (aSession[i].indexOf(sName) == 0) { sRetValue = aSession[i].substring(aSession[i].indexOf(sNameValueDelimiter) + sNameValueDelimiter.length, aSession[i].length); break; } } } return sRetValue; } function resetStateParam(sName) { // If we have no session or it is empty then return null. var sCurrentValue = getSessionValue(sName); if (sCurrentValue) { setStateValue(sName, ""); } } function updateSession() { // Updates the browser session to control caching. var currentValue = parseInt(getSessionValue("us"), 10); var newValue = isNaN(currentValue) ? 0 : (currentValue + 1); setStateValue("us", newValue); }