/*
 * jquery.userCheck.js v1.2 (created: 2007/12/12)
 * 
 * Company: Statusfirm
 * Coded by: Chesley Brown
 * Contact: c.brown@statusfirm.com
 * 
 * ***Description***
 * Used to constantly check to ensure the user is only logged in once
 * ******
 * 
 * *****Requires*****
 * jquery.js (tested with v1.2)
 * firebugx.js (if using showErrors without useAlerts)
 * _jsonUserCheck.php
 * bo_usercheck.php
 * do_usercheck.php
 * customAlert.css
 * ******
 * 
 */
function customAlertCountdown() { var countdownTime = document.getElementById('customAlertCountdown').innerHTML; if (countdownTime > 0) { var newCountdownTime = countdownTime - 1; document.getElementById('customAlertCountdown').innerHTML = newCountdownTime; setTimeout('customAlertCountdown();', 1000);}
}
function customAlert(title, content, redirectTime, redirectLocation) { var customAlertContainer = document.createElement('div'); customAlertContainer.className = 'customAlertContainer'; var customAlertTitle = document.createElement('div'); customAlertTitle.className = 'customAlertTitle'; customAlertTitle.innerHTML = title; var customAlertContent = document.createElement('div'); customAlertContent.className = 'customAlertContent'; customAlertContent.innerHTML = content; if (redirectTime != '') { var redirectMsg = "You will be redirected in <b id='customAlertCountdown'>" + redirectTime + "</b> seconds."; customAlertContent.innerHTML = customAlertContent.innerHTML + " " + redirectMsg;}
customAlertContainer.appendChild(customAlertTitle); customAlertContainer.appendChild(customAlertContent); document.body.appendChild(customAlertContainer); scroll(0,0); if (redirectTime != '') { setTimeout("window.location = '" + redirectLocation + "';", redirectTime * 1000); customAlertCountdown();}
}
function classjQueryUserCheck(objParam) { if (document.getElementsByTagName('base')[0]) { this.baseHREF = document.getElementsByTagName('base')[0].href;} else { this.baseHREF = '';}
this.ajaxLocation = 'users/_jsonUserCheck.php'; this.ajaxMethod = 'post'; this.ajaxCache = false; this.ajaxDataType = 'json'; this.ajaxTimeout = 20000; this.ajaxData = null; this.checkInterval = 2; this.redirectTime = 10; this.redirectLocation = this.baseHREF; this.useAlerts = false; this.showErrors = false; this.onLoad = true; this.ignoreNoLogin = false; this.removeDisplayContainer = false; this.displayContainerID = 'videoPlayerContainer'; this.msgAlert = { 'DoubleLoginTitle': 'Warning: Double Login Detected', 'DoubleLoginContent': 'You have logged into another location.', 'NoIPTitle': 'Error: Your IP Was Not Detected', 'NoIPContent': 'Server was unable to read your ip address. You have been logged out.', 'NoLoginTitle': 'Warning: No Login Detected', 'NoLoginContent': 'You are no longer logged in.'
}; this.msgRedirect = { 'DoubleLogin': '?msg=doublelogin', 'NoIP': '?msg=noip', 'NoLogin': '?msg=nologin'
}; this.msgError = { 'unknown': 'unknown!', 'timeout': 'timeout!', 'pagenotfound': 'page not found!', 'missingid': 'id="%i" cannot be found!', 'required': 'required="%i" is missing or empty'
}; this.start = startjQueryUserCheck; this.remove = removejQueryUserCheck; this.modify = modifyjQueryUserCheck; this.modify(objParam); var self = this; if (this.onLoad) { $().ready(function() { self.start();});}
}
function startjQueryUserCheck() { var self = this; var opt = { url: this.baseHREF + this.ajaxLocation, type: this.ajaxMethod, dataType: this.ajaxDataType, cache: this.ajaxCache, timeout: this.ajaxTimeout, data: this.data, success: function(data) { var sessionStatus = 'nologin'; if ($(data)[0] != null) { self.jsonData = $(data)[0]; if (self.jsonData['header']) { sessionStatus = self.jsonData['header']['sessionStatus'];}
}
if (sessionStatus == 'doublelogin') { customAlert(self.msgAlert['DoubleLoginTitle'], self.msgAlert['DoubleLoginContent'], self.redirectTime, self.baseHREF + self.redirectLocation + self.msgRedirect['DoubleLogin']); self.remove();}
else if (sessionStatus == 'noip') { customAlert(self.msgAlert['NoIPTitle'], self.msgAlert['NoIPContent'], self.redirectTime, self.baseHREF + self.redirectLocation + self.msgRedirect['NoIP']); self.remove();}
else if (sessionStatus == 'nologin' && !self.ignoreNoLogin) { customAlert(self.msgAlert['NoLoginTitle'], self.msgAlert['NoLoginContent'], self.redirectTime, self.baseHREF + self.redirectLocation + self.msgRedirect['NoLogin']); self.remove();}
else { setTimeout( function() { self.start();}, self.checkInterval * 60 * 1000);}
}, error: function(data, status) { if (self.showErrors) { if (status == 'timeout') { if (self.useAlerts) { alert(self.jsName + self.msgError['timeout']);} else { console.error(self.jsName + self.msgError['timeout']);}
} else { if (data.status == 404) { if (self.useAlerts) { alert(self.jsName + self.msgError['pagenotfound']);} else { console.error(self.jsName + self.msgError['pagenotfound']);}
}
else { if (self.useAlerts) { alert(self.jsName + self.msgError['unknown']);} else { console.error(self.jsName + self.msgError['unknown']);}
}
}
}
}
}
$.ajax(opt);}
function removejQueryUserCheck() { if (this.removeDisplayContainer) { if (document.getElementById(this.displayContainerID)) { $('#' + this.displayContainerID).remove();}
}
}
function modifyjQueryUserCheck(objParam) { if (objParam) { if (typeof(objParam.baseHREF) != 'undefined') { this.baseHREF = objParam.baseHREF;}
if (typeof(objParam.ajaxMethod) != 'undefined') { this.ajaxMethod = objParam.ajaxMethod;}
if (typeof(objParam.ajaxCache) != 'undefined') { this.ajaxCache = objParam.ajaxCache;}
if (typeof(objParam.ajaxDataType) != 'undefined') { this.ajaxDataType = objParam.ajaxDataType;}
if (typeof(objParam.ajaxTimeout) != 'undefined') { this.ajaxTimeout = objParam.ajaxTimeout;}
if (typeof(objParam.ajaxLocation) != 'undefined') { this.ahahLocation = objParam.ajaxLocation;}
if (typeof(objParam.checkInterval) != 'undefined') { this.checkInterval = objParam.checkInterval;}
if (typeof(objParam.redirectTime) != 'undefined') { this.redirectTime = objParam.redirectTime;}
if (typeof(objParam.redirectLocation) != 'undefined') { this.redirectLocation = objParam.redirectLocation;}
if (typeof(objParam.useAlerts) != 'undefined') { this.useAlerts = objParam.useAlerts;}
if (typeof(objParam.showErrors) != 'undefined') { this.showErrors = objParam.showErrors;}
if (typeof(objParam.onLoad) != 'undefined') { this.onLoad = objParam.onLoad;}
if (typeof(objParam.ignoreNoLogin) != 'undefined') { this.ignoreNoLogin = objParam.ignoreNoLogin;}
if (typeof(objParam.removeDisplayContainer) != 'undefined') { this.removeDisplayContainer = objParam.removeDisplayContainer;}
if (typeof(objParam.displayContainerID) != 'undefined') { this.displayContainerID = objParam.displayContainerID;}
if (typeof(objParam.msgAlert) != 'undefined') { if (typeof(objParam.msgAlert['DoubleLoginTitle']) != 'undefined') { this.msgAlert['DoubleLoginTitle'] = objParam.msgAlert['DoubleLoginTitle'];}
if (typeof(objParam.msgAlert['DoubleLoginContent']) != 'undefined') { this.msgAlert['DoubleLoginContent'] = objParam.msgAlert['DoubleLoginContent'];}
if (typeof(objParam.msgAlert['NoIPTitle']) != 'undefined') { this.msgAlert['NoIPTitle'] = objParam.msgAlert['NoIPTitle'];}
if (typeof(objParam.msgAlert['NoIPContent']) != 'undefined') { this.msgAlert['NoIPContent'] = objParam.msgAlert['NoIPContent'];}
if (typeof(objParam.msgAlert['NoLoginTitle']) != 'undefined') { this.msgAlert['NoLoginTitle'] = objParam.msgAlert['NoLoginTitle'];}
if (typeof(objParam.msgAlert['NoLoginContent']) != 'undefined') { this.msgAlert['NoLoginContent'] = objParam.msgAlert['NoLoginContent'];}
}
if (typeof(objParam.msgRedirect) != 'undefined') { if (typeof(objParam.msgRedirect['DoubleLogin']) != 'undefined') { this.msgRedirect['DoubleLogin'] = objParam.msgRedirect['DoubleLogin'];}
if (typeof(objParam.msgRedirect['NoIP']) != 'undefined') { this.msgRedirect['NoIP'] = objParam.msgRedirect['NoIP'];}
if (typeof(objParam.msgRedirect['NoLogin']) != 'undefined') { this.msgRedirect['NoLogin'] = objParam.msgRedirect['NoLogin'];}
}
if (typeof(objParam.msgError) != 'undefined') { if (typeof(objParam.msgError['unknown']) != 'undefined') { this.msgError['unknown'] = objParam.msgError['unknown'];}
if (typeof(objParam.msgError['timeout']) != 'undefined') { this.msgError['timeout'] = objParam.msgError['timeout'];}
if (typeof(objParam.msgError['pagenotfound']) != 'undefined') { this.msgError['pagenotfound'] = objParam.msgError['pagenotfound'];}
if (typeof(objParam.msgError['missingid']) != 'undefined') { this.msgError['missingid'] = objParam.msgError['missingid'];}
if (typeof(objParam.msgError['required']) != 'undefined') { this.msgError['required'] = objParam.msgError['required'];}
}
}
}
myUserCheck = new classjQueryUserCheck({ 'redirectLocation': 'sharing.php'
});