/* last Changes 9.4.2020 inl snvWebServices 20.4.3 */ var tmp_files = new Array(); function disableBrowserContextMenu() { document.oncontextmenu = function() { return false; } } function getUploadFileCount() { if (typeof(tmp_files) == "undefined") return 0 else return tmp_files.length; } function getINLsnvToken() { if (typeof(inlSNVToken) == "undefined") return '' else return inlSNVToken; } function addZero(i) { if (i < 10) { i = "0" + i; } return i; } function ConvertDateTime(d) { if (d == null) { return '-' } return addZero(d.getDate()) + '.' + addZero(d.getMonth() +1) + '.' + addZero(d.getFullYear()) + ' ' + addZero(d.getHours()) + ':' + addZero(d.getMinutes()); // + ':' + addZero(d.getSeconds()); } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function consolelog(log) { console.log(log) } function getUploadFilesAsJSONDataset() { var s = ''; for (var i=0; i < tmp_files.length; i++) { if (s !== '') s += ','; s += '{ ' + '"name":"' + tmp_files[i].name + '",' + '"size":"' + byteToSizeString(tmp_files[i].size) + '",' + '"lastmodified":"' + ConvertDateTime(tmp_files[i].lastModifiedDate) + '",' + '"icon":"document",' + '"idx":"' + i + '"' + ' }'; } return '{"rows": [' + s + ']}'; } function deleteUploadFileByIndex(idx) { // idx=-1 löscht alle Einträge if (idx == -1) tmp_files.splice(0, tmp_files.length) else tmp_files.splice(idx, 1); } function getUploadFilename(idx) { return tmp_files[idx].name; } function getUploadFileSizeText(idx) { var size=0; if (idx = -1) { for (var i=0; i < tmp_files.length; i++) { size += tmp_files[i].size; } } else { size = tmp_files[idx].size; } return byteToSizeString(size); } function getFileIndexByName(filename) { var res = -1; for (var i=0; i < tmp_files.length; i++) { if (filename == tmp_files[i].name) { res = i; break; } } return res; } // DropZone(s) für Dateiuploads einschalten function enableFileDropZone(__DropZoneName, __onDropFileSuccess) { var onDropFile = __onDropFileSuccess; var handleUploadFiles = function(files) { //input must be FileList for (var i=0; i < files.length; i++) { var idx = getFileIndexByName(files[i].name); if (idx >= 0) { tmp_files.splice(idx, 1); } tmp_files.push( files[i] ); } onDropFile(files.length); } var handleDragDrop = function(evt) { evt.stopPropagation(); evt.preventDefault(); handleUploadFiles(evt.dataTransfer.files); } this.handleDragOver = function(evt) { evt.stopPropagation(); evt.preventDefault(); evt.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy. } var dropZone = document.getElementById(__DropZoneName); dropZone.addEventListener('dragover', this.handleDragOver, false); dropZone.addEventListener('drop', handleDragDrop, false); } function enableSelectFileElement(__SelectZoneName, __onSelectFileSuccess, __pdfOnly) { var onSelectFile = __onSelectFileSuccess; var handleUploadFiles = function(files) { //input must be FileList //alert ( files[0].name ); for (var i=0; i < files.length; i++) { var idx = getFileIndexByName(files[i].name); if (idx >= 0) { tmp_files.splice(idx, 1); } tmp_files.push( files[i] ); } onSelectFile(files.length); } var handleFileSelect = function(evt) { handleUploadFiles(evt.target.files); } this.click = function(evt) { var inputControl = document.createElement("INPUT"); //if (getOsInfo(true) == 'iOS' || getOsInfo(true) == 'Mac OS X') { if (getOsInfo(true) == 'iOS') { inputControl.style.width = 0; inputControl.style.height = 0; document.body.appendChild(inputControl); } inputControl.setAttribute("multiple", "multiple"); inputControl.setAttribute("type", "file"); // Nur PDF-Dateien zulasssen if (__pdfOnly == true) { inputControl.setAttribute("accept", ".pdf"); } inputControl.addEventListener('change',handleFileSelect,false); inputControl.click(); } var selectZone = document.getElementById(__SelectZoneName); selectZone.addEventListener('click', this.click, false); selectZone.addEventListener('touchend', this.click, false); } function uploadFiles(__onUploadStatus, __onUploadProgress) { for (var i=0; i < tmp_files.length; i++) { uploadSingleFile(i, __onUploadStatus, __onUploadProgress); } } function uploadSingleFile(idx, __onUploadStatus, __onUploadProgress) { file = tmp_files[idx]; var onUploadProgress = __onUploadProgress; var onUploadStatus = __onUploadStatus; // Stati // 0=unknown // 1=upload running // 2=canceled by user // 3=no permission if(!XMLHttpRequest.prototype.sendAsBinary){ XMLHttpRequest.prototype.sendAsBinary = function(datastr) { function byteValue(x) { return x.charCodeAt(0) & 0xff; } var ords = Array.prototype.map.call(datastr, byteValue); var ui8a = new Uint8Array(ords); try{ this.send(ui8a); }catch(e){ this.send(ui8a.buffer); } }; } if (FileReader.prototype.readAsBinaryString === undefined) { FileReader.prototype.readAsBinaryString = function (fileData) { var binary = ""; var pt = this; var reader = new FileReader(); reader.onload = function (e) { var bytes = new Uint8Array(reader.result); var length = bytes.byteLength; for (var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); } //pt.result - readonly so assign content to another property pt.content = binary; pt.onload(); // thanks to @Denis comment } reader.readAsArrayBuffer(fileData); } } var loaded = 0; var step = (1024*1024); // *10; // ChunkSize var total = file.size; var start = 0; var chunk = 0; var chunkmax = Math.floor(total/step); var doCancelUpload = false; var state = 0; // 0=unknown, 1=Transfer startet, 2=Transfer success var errorcode = 0; // Destinationfilename aus Cookie lesen var uploadfilename = readCookie("uploadfilename"); if (uploadfilename == "") {uploadfilename = file.name}; if (total % step > 0) {chunkmax ++} var transferID = Math.floor((Math.random() * 100000) + 1); var url = window.location.protocol + "//" + window.location.host + readCookie("uploadurl"); // UploadCancelButton var cancel = document.getElementById('CancelUpload'); function detach() { // remove listeners after they become irrelevant cancel.removeEventListener('click', canceling, false); } function canceling() { detach(); console.log('CANCEL'); doCancelUpload = true; } cancel.addEventListener('click', canceling, false); var reader = new FileReader(); console.log("url:" + window.location.protocol + "//" + window.location.host + readCookie("uploadurl") ); reader.onload = function(e){ var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ // Done if (xhr.readyState == 4) { console.log(xhr.status); // 403 - No Permission // 412 - Precondition failed // 201 - success if (xhr.status == 403 || xhr.status == 412) { errorcode = xhr.status; doCancelUpload = true; } else if (xhr.status == 201 && total == 0) { // Eintrag löschen deleteUploadFileByIndex(idx); onUploadStatus(100); console.log('Transfer successfully stopped'); } } } var upload = xhr.upload; // load upload.addEventListener('load',function(evt){ loaded += step; if(loaded <= total){ blob = file.slice(loaded,loaded+step); // Recursiver Aufruf für Chunk-Updates console.log('start next chunk (' + chunk + '/' + chunkmax + ')' ); reader.readAsBinaryString(blob); //reader.readAsText(blob); //reader.readAsArrayBuffer(blob); } else { loaded = total; if (errorcode > 0) { onUploadStatus(errorcode); console.log('Transfer stopped with error'); } else { if (doCancelUpload == true) { onUploadStatus(2); console.log('Transfer stopped by user'); } else { // Eintrag löschen deleteUploadFileByIndex(idx); onUploadStatus(100); console.log('Transfer successfully stopped'); } } } //console.log('Event Load '); },false); // progress upload.addEventListener('progress',function(evt){ var progress = Math.ceil(((loaded + evt.loaded) / total) * 100); // Event console.log( 'progress: ' + progress ); onUploadProgress(progress); // CancelUpload - Bei Abbruch wird loaded auf Total gesetzt, damit auch bei einem ChunkUpload unterbrochen wird if (doCancelUpload) { console.log('CancelUpload detected'); loaded = total; xhr.abort; } },false); // Error upload.addEventListener("error", function(evt){ console.log('Event Error'); },false); // Abort upload.addEventListener("abort", function(evt){ console.log('Event Abort'); },false); if (chunkmax > 1){ //xhr.open("PUT", url + file.name + "-chunking-" + transferID + "-" + chunkmax + "-" + chunk); xhr.open("PUT", url + uploadfilename + "-chunking-" + transferID + "-" + chunkmax + "-" + chunk); xhr.setRequestHeader("OC-Chunked","1"); xhr.setRequestHeader("OC-Total-Length",total); } else { //xhr.open("PUT", url + file.name); xhr.open("PUT", url + uploadfilename); } xhr.overrideMimeType("application/octet-stream"); // ADDED CODE if (!e) { var data = reader.content; } else { var data = e.target.result; } //xhr.sendAsBinary(e.target.result); xhr.sendAsBinary(data); chunk++; }; var blob = file.slice(start,step); onUploadStatus(1); console.log('Transfer startet'); reader.readAsBinaryString(blob); //reader.readAsText(blob); //reader.readAsArrayBuffer(blob); } function uploadFile(file){ var loaded = 0; var step = (1024*1024)*5; // ChunkSize var total = file.size; var start = 0; var chunk = 0; var chunkmax = Math.floor(total/step); if (total % step > 0) {chunkmax ++} var transferID = Math.floor((Math.random() * 100000) + 1); //var url = window.location.protocol + "//" + window.location.host + sessionStorage.getItem("uploadurl"); var url = window.location.protocol + "//" + window.location.host + readCookie("uploadurl"); var reader = new FileReader(); //console.log("Test " + file.name); //console.log("url:" + window.location.protocol + "//" + window.location.host + sessionStorage.getItem("uploadurl") ); console.log("url:" + window.location.protocol + "//" + window.location.host + readCookie("uploadurl") ); reader.onload = function(e){ // ADDED CODE if (!e) { var data = reader.content; } else { var data = e.target.result; } var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if (xhr.readyState == 4) { console.log(xhr.status)}; } var upload = xhr.upload; upload.addEventListener('load',function(){ loaded += step; //progress.value = Math.round( (loaded/total) * 100); if(loaded <= total){ blob = file.slice(loaded,loaded+step); reader.readAsBinaryString(blob); //reader.readAsText(blob); //reader.readAsArrayBuffer(blob); } else { loaded = total; } },false); if (chunkmax > 1){ xhr.open("PUT", url + file.name + "-chunking-" + transferID + "-" + chunkmax + "-" + chunk); xhr.setRequestHeader("OC-Chunked","1"); xhr.setRequestHeader("OC-Total-Length",total); } else { xhr.open("PUT", url + file.name); } xhr.overrideMimeType("application/octet-stream"); xhr.sendAsBinary(e.target.result); chunk++; }; var blob = file.slice(start,step); reader.readAsBinaryString(blob); //reader.readAsText(blob); //reader.readAsArrayBuffer(blob); } function getBrowserInfo(){ var browser = ''; var version = ''; var idString = ''; //alert( navigator.userAgent ); var ua = navigator.userAgent; var tem = []; var M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i); if (M == null) { browser = 'Unbekannt'; version = '0.0'; } //IE will be identified as 'Trident' and a different version number. The name must be corrected to 'Internet Explorer' and the correct version identified. //ie correction else if(/trident/i.test(M[1])) { tem = /\brv[ :]+(\d+.?\d*)/g.exec(ua) || []; browser = 'Internet Explorer'; version = tem[1]; } //firefox else if(/firefox/i.test(M[1])) { tem = /\brv[ :]+(\d+.?\d*)/g.exec(ua) || []; browser = 'Firefox'; version = tem[1]; } //safari else if(/safari/i.test(M[1])) { tem = ua.match(/\bVersion\/(\d+.?\d*\s*\w+)/); browser = 'Safari'; // Achtung! Version kann bei iOS bei den Browser (Firefox + Chrome nicht ermittelt werden) if (tem !== null) { version = tem[1]; } else { // Chrome auf iOS? if (ua.match(/CriOS/gi) !== null) { browser = 'Chrome'; version = 'unbekannt'; } // Firefox auf iOS if (ua.match(/FxiOS/gi) !== null) { browser = 'Firefox'; version = 'unbekannt'; } } } //If 'Chrome' is found, it may be another browser. else if(M[1] === 'Chrome') { //opera var temOpr = ua.match(/\b(OPR)\/(\d+.?\d*.?\d*.?\d*)/); //edge var temEdge = ua.match(/\b(Edge)\/(\d+.?\d*)/); //chrome var temChrome = ua.match(/\b(Chrome)\/(\d+.?\d*.?\d*.?\d*)/); //a genuine 'Chrome' reading will result from ONLY temChrome not being null. var genuineChrome = temOpr == null && temEdge == null && temChrome != null; if(temOpr != null) { browser = temOpr[1].replace('OPR', 'Opera'); version = temOpr[2]; } if(temEdge != null) { browser = temEdge[1]; version = temEdge[2]; } if(genuineChrome) { browser = temChrome[1]; version = temChrome[2]; } } //There will be some odd balls, so if you wish to support those browsers, add functionality to display those browsers as well. if(browser == '' || version == '') { idString = 'Browser kann nicht ermittelt werden'; } else { idString = browser + ' version ' + version; } return idString; } function getOsInfo(osOnly){ var nAgt = navigator.userAgent; var nVer = navigator.appVersion; var os = '-'; var clientStrings = [ {s:'Windows 10', r:/(Windows 10.0|Windows NT 10.0)/}, {s:'Windows 8.1', r:/(Windows 8.1|Windows NT 6.3)/}, {s:'Windows 8', r:/(Windows 8|Windows NT 6.2)/}, {s:'Windows 7', r:/(Windows 7|Windows NT 6.1)/}, {s:'Windows Vista', r:/Windows NT 6.0/}, {s:'Windows Server 2003', r:/Windows NT 5.2/}, {s:'Windows XP', r:/(Windows NT 5.1|Windows XP)/}, {s:'Windows 2000', r:/(Windows NT 5.0|Windows 2000)/}, {s:'Windows ME', r:/(Win 9x 4.90|Windows ME)/}, {s:'Windows 98', r:/(Windows 98|Win98)/}, {s:'Windows 95', r:/(Windows 95|Win95|Windows_95)/}, {s:'Windows NT 4.0', r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/}, {s:'Windows CE', r:/Windows CE/}, {s:'Windows 3.11', r:/Win16/}, {s:'Android', r:/Android/}, {s:'Open BSD', r:/OpenBSD/}, {s:'Sun OS', r:/SunOS/}, {s:'Linux', r:/(Linux|X11)/}, {s:'iOS', r:/(iPhone|iPad|iPod)/}, {s:'Mac OS X', r:/Mac OS X/}, {s:'Mac OS', r:/(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/}, {s:'QNX', r:/QNX/}, {s:'UNIX', r:/UNIX/}, {s:'BeOS', r:/BeOS/}, {s:'OS/2', r:/OS\/2/}, {s:'Search Bot', r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/} ]; for (var id in clientStrings) { var cs = clientStrings[id]; if (cs.r.test(nAgt)) { os = cs.s; break; } } var osVersion = '-'; if (/Windows/.test(os)) { osVersion = /Windows (.*)/.exec(os)[1]; os = 'Windows'; } switch (os) { case 'Mac OS X': if (nAgt.includes('Mac OS X 11')) { osVersion = /Mac OS X (11[\.\_\d]+)/.exec(nAgt)[1]; osVersion = osVersion.replaceAll('_', '.'); } else if (nAgt.includes('Mac OS X 10')) { osVersion = /Mac OS X (10[\.\_\d]+)/.exec(nAgt)[1]; osVersion = osVersion.replaceAll('_', '.'); } else { osVersion = ''; } break; case 'Android': osVersion = /Android ([\.\_\d]+)/.exec(nAgt)[1]; break; case 'iOS': osVersion = /OS (\d+)_(\d+)_?(\d+)?/.exec(nVer); osVersion = osVersion[1] + '.' + osVersion[2] + '.' + (osVersion[3] | 0); break; default: osVersion = ''; break; } if (osOnly == true) { return os; } else { return os + ' ' + osVersion; } } function isMobile() { ///Detecting whether the browser is a mobile browser or desktop browser ///A boolean value indicating whether the browser is a mobile browser or not if (sessionStorage.desktop) // desktop storage return false; // else if (localStorage.mobile) // mobile storage // return true; // alternative var mobile = ['iphone','ipad','android','blackberry','nokia','opera mini','windows mobile','windows phone','iemobile']; for (var i in mobile) if (navigator.userAgent.toLowerCase().indexOf(mobile[i].toLowerCase()) > 0) return true; // nothing found.. assume desktop return false; } /* function checkServerStatus() { setServerStatus("unknown"); var img = document.body.appendChild(document.createElement("img")); img.onload = function() { setServerStatus("online"); }; img.onerror = function() { setServerStatus("offline"); }; img.src = "http://myserver.com/ping.gif"; } */ function byteToSizeString(ABytes) { /* ONEBYTE = 1; ONEKB = 1024; ONEMB = 1048576; ONEGB = 1073741824; ONETB = 1099511627776; */ var res = '-'; if (ABytes >= 1099511627776) { res = Math.round(ABytes / 1099511627776) + " TB"; } else if (ABytes >= 1073741824) { res = Math.round(ABytes / 1073741824) + " GB"; } else if (ABytes >= 1048576) { res = Math.round(ABytes / 1048576) + " MB"; } else if (ABytes >= 1024) { res = Math.round(ABytes / 1024) + " KB"; } else if (ABytes >= 1) { res = ABytes + " B"; } return res; } var Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function(input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; //input = Base64._utf8_encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; }, decode: function(input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } //output = Base64._utf8_decode(output); return output; }, _utf8_encode: function(string) { string = string.replace(/\r\n/g, "\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, _utf8_decode: function(utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while (i < utftext.length) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if ((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i + 1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i + 1); c3 = utftext.charCodeAt(i + 2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } } function Encode(AString) { return Base64.encode(AString); } function Decode(AString) { return Base64.decode(AString); } function closeMe() { var win = window.open("","_self"); /* url = "" or "about:blank"; target="_self" */ win.close(); }