function removeLoadStatus(elemId){ document.getElementById(elemId).classList.remove('btnLoading'); } function chkBoxToggle(elem){ if(elem.checked == true){ elem.value = 'on'; } else { elem.value = 'off'; } } function addLinkNotif(){ changeCSS(document.getElementById('adminLinkNotif'), 'hidden', 'add'); } function btnLoad(clsList){ if(clsList.contains('btnLoading') == true){ setTimeout(function(){ clsList.remove('btnLoading'); }, 250, clsList); } else { clsList.add('btnLoading'); } } function prepForNurse(params, callbackId, url, action, target, srcElemId){ //console.log('params' + ' : ' + params); //console.log('callbackId' + ' : ' + callbackId); //console.log('url' + ' : ' + url); //console.log('action' + ' : ' + action); //console.log('target' + ' : ' + target); //console.log('srcElemId' + ' : ' + srcElemId); if (url == '') { //url is optional var url = 'inv/jarvisPFCortex.php'; } if (typeof target === 'undefined') { //target is optional var target = ''; } if (typeof srcElemId === 'undefined') { //srcElemId is optional, but useful if you want something else to be the source element - like an element in a div inherits the onclick, but you want the container div to be the source element if (typeof event !== 'undefined') { if(typeof event.target.id !== 'undefined'){ if(event.target.id == ''){ alert('need to set an ID on the element that called the event'); var srcElem = ''; } else { var srcElemId = event.target.id; } } } } if (typeof action === 'undefined') { action = ''; } else if(action == 'btnSubmit'){ var srcElem = document.getElementById(srcElemId); if(srcElem.nodeName == 'BUTTON'){ changeCSS(srcElem, 'btnLoading', 'add'); } else { alert('didn\'t pass a button ID'); } } //---------------------constructor---------------------- var obj = {}; obj.url = url; //defaults to inv/jarvisPFCortex.php. obj.params = params; //alla värden obj.srcId = srcElemId; //vad som skickade det obj.targetId = target; //vart innehållet ska hamna obj.callbackId = callbackId; //vad transaktionen ska heta obj.action = action; //action name obj.params = 'callbackId=' + callbackId + '&' + obj.params; if(obj.action != ''){ obj.params = obj.params + '&action=' + obj.action; } sendToSOM(obj); } function sendToSOM(obj){ //console.log(obj); if (window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); } else { xmlHttp=new ActiveXObject('Microsoft.XMLHTTP'); } console.log(obj.url); xmlHttp.open('POST', obj.url, true); xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200){ // console.log('url: ' + obj.url + ' state: ' + xmlHttp.readyState + ' status: ' + xmlHttp.status); if(obj.action == 'feedback'){ obj.msg = xmlHttp.responseText; jarvix.responseOBJ = obj; jarvix.bgTasks.status = 'processing'; prepForJarvis('&name='+obj.callbackId, 'doorman', '', 'doorman'); } else if(obj.action == 'doorman'){ jarvix.bgTasks.status = 'finalizing'; } else { loadSuccess(obj.callbackId, obj.action, xmlHttp.responseText, obj.srcId, obj.targetId); } } else if (xmlHttp.status == 403) { onlyChangeClassIfTrue(document.getElementById('reLoginModal').classList, 'hiddenModal', true); } else if (xmlHttp.status == 500) { alert('something didn\'t go as planned'); } } } xmlHttp.send(obj.params); } function sendSingleFile(fileElemId, savePath, userId, callbackId, url, target, params){ var formData = new FormData(); formData.append('file', document.getElementById(fileElemId).files[0]); formData.append('savePath', savePath); formData.append('userId', userId); formData.append('callbackId', callbackId); console.log(params); for(var i = 0; i < params.length; i++){ formData.append('param'+i, params[i]); } var xhr = new XMLHttpRequest(); xhr.open('POST', url); xhr.onreadystatechange = function() { if(xhr.readyState == 4) { if(xhr.status == 200){ loadSuccess(callbackId, 'fileUpload', xhr.responseText, '', target); } else if (xhr.status == 403) { onlyChangeClassIfTrue(document.getElementById('reLoginModal').classList, 'hiddenModal', true); } else if (xhr.status == 500) { alert('something didnt go as planned'); } } } xhr.send(formData); } function loadSuccess(callbackId, action, msg, srcId, targetId){ //----------------------checking data-------------------- //----------------------limit to section specific-------------------- console.log('callbackId: '+ callbackId); console.log('action: '+ action); console.log('msg: '+ msg); console.log('from: '+ srcId); console.log('target: '+ targetId); var targetElem = document.getElementById(targetId); if(targetId != ''){ targetElem.innerHTML = msg; } if(callbackId == 'addChatFiles'){ if(msg != 'error'){ document.getElementById('customModal').innerHTML = msg; } } if(callbackId == 'editZeDoc'){ if(msg != 'error'){ document.getElementById('customModal').innerHTML = ''; changeCSS(document.getElementById('customModal'), 'hiddenModal', 'add'); document.getElementById('fileContainer').innerHTML = msg; } } if(callbackId == 'UploadProfile' || callbackId == 'UploadMentorProfile'){ if(msg != ''){ document.getElementById('profileImg').style.backgroundImage = 'url('+msg+')'; document.getElementById('pressoImgBig').style.backgroundImage = 'url('+msg+')'; } } if(callbackId == 'chkEmailQueue'){ if(msg != 'too recent'){ document.getElementById('emailQueue').innerHTML = msg; } } if(callbackId == 'sendAsSom'){ setTimeout(function() { removeLoadStatus('sendEmailButton'); }, 500); if(msg != 'too recent'){ document.getElementById('emailQueue').innerHTML = msg; } } if(callbackId == 'saveProfile'){ if(msg == 'complete'){ document.getElementById('incompletePresso').style.display = 'none'; document.getElementById('chatto').style.display = ''; } } if(callbackId == 'saveMentorProfile'){ if(msg == 'complete'){ document.getElementById('incompletePresso').style.display = 'none'; document.getElementById('fankoo').style.display = ''; } } if(callbackId == 'register'){ if(msg == 'Invalid email format' || msg == 'email allready registered'){ alert(msg); } else { if(msg == 'ok1'){ window.location.href = 'mentee.php'; } if(msg == 'ok2'){ window.location.href = 'mentor.php'; } } } if(callbackId == 'rememberPassw'){ document.getElementById('customModal').innerHTML = msg; } if(callbackId == 'prepLogin'){ if(msg != 'error'){ document.getElementById('customModal').innerHTML = msg; } } if(callbackId == 'getChatMsg'){ if(msg != ''){ var obj = JSON.parse(msg); if(obj[1] != 'noNew'){ if(obj[1] != 'noMessages'){ console.log(document.getElementById('orgNotesDiv').innerHTML); if(document.getElementById('orgNotesDiv').innerHTML == 'To start chatting, please write your message in the text box below'){ document.getElementById('orgNotesDiv').innerHTML =''; } var txt = ''; for(var i = 0; i < obj[1].length; i++){ txt = txt + obj[1][i]; } document.getElementById('orgNotesDiv').innerHTML = document.getElementById('orgNotesDiv').innerHTML + txt; document.getElementById('orgNotesDiv').scrollTop = document.getElementById('orgNotesDiv').scrollHeight; document.getElementById('postsCount').value = obj[0]; console.log(obj); var sharedCollection = document.getElementsByClassName('sharedFilesFromChat'); var sharedFilesHTML = ''; for(var i = 0; i < sharedCollection.length; i++){ sharedFilesHTML = sharedFilesHTML + ''; } document.getElementById('fileSharLib').innerHTML = sharedFilesHTML; updateFilesAndLinks(); } } } } if(callbackId == 'selectMentor'){ if(msg != 'error'){ window.location.href = 'mentee.php'; } } if(callbackId == 'editFile'){ document.getElementById('customModal').innerHTML = msg; changeCSS(document.getElementById('customModal'), 'hiddenModal', 'remove') } if(callbackId == 'UploadDocument'){ document.getElementById(targetId).innerHTML = msg; changeCSS(document.getElementById('customModal'), 'hiddenModal', 'add'); changeCSS(document.getElementById('adminLinkNotif'), 'hidden', 'remove'); setTimeout(function() { addLinkNotif(); }, 3000); } if(callbackId == 'delFile'){ document.getElementById('fileContainer').innerHTML = msg; } if(callbackId == 'approveFile'){ document.getElementById('fileContainer').innerHTML = msg; } if(callbackId == 'newMentee'){ document.getElementById('chatScreen').style.display = 'none'; document.getElementById('fankoo').style.display = 'none'; document.getElementById('newMenteeScreen').innerHTML = msg; document.getElementById('newMenteeScreen').style.display = 'initial'; } if(callbackId == 'acceptMentee'){ document.getElementById('scriptHoler').innerHTML = msg; prepForNurse('&pid=' + document.getElementById('hiddenMenteeThatYouSelected').value, 'acceptMenteeNi', 'inv/cortex.php'); } if(callbackId == 'acceptMenteeNi'){ document.getElementById('chatScreen').style.display = 'initial'; document.getElementById('newMenteeScreen').style.display = 'none'; document.getElementById('leftMentorMenuCortex').innerHTML = msg; document.getElementById('menteeListDiv').innerHTML = document.getElementById('scriptHoler').innerHTML; document.getElementById('scriptHoler').innerHTML = ''; } if(callbackId == 'selMentee' || callbackId == 'adminChat'){ document.getElementById('postsCount').value = 0; document.getElementById('orgNotesDiv').innerHTML = ''; document.getElementById('leftMentorMenuCortex').innerHTML = msg; sendChatMsg(); // updateFilesAndLinks(); } if(callbackId == 'screenMentors'){ document.getElementById('customModal').innerHTML = msg; changeCSS(document.getElementById('customModal'), 'hiddenModal', 'remove'); } if(callbackId == 'fancyDisplay'){ document.getElementById('customModal').innerHTML = msg; changeCSS(document.getElementById('customModal'), 'hiddenModal', 'remove'); } if(callbackId == 'addselectOption'){ var optField = srcId.substr(0, 6)+'Name'+srcId.substr(6); document.getElementById(optField).value = ''; toggleCSS(document.getElementById(srcId), 'hidden'); } if(callbackId == 'downFile'){ document.getElementById('downfile').src = msg; } if(callbackId == 'saveAvailability'){ var data = JSON.parse(msg); console.log(data.length); var calCol = document.getElementsByClassName('calDay'); for(var i = 0; i < calCol.length; i++){ var addBlock = 'yes'; for(var j = 0; j < data.length; j++){ if(calCol[i].id == data[j]){ var addBlock = 'no'; } } // if(calCol[i].classList.contains('calDayBlocked') == false && addBlock == 'yes'){ // calCol[i].classList.add('calDayBlocked'); // } } onlyChangeClassIfTrue(document.getElementById('customModal').classList, 'hiddenModal', false); } if(action == 'modalDone' || callbackId == 'deleteLink'){ document.getElementById('customModal').innerHTML = ''; changeCSS(document.getElementById('customModal'), 'hiddenModal', 'add'); document.getElementById('linkContainerContent').innerHTML = msg; } if(callbackId == 'AddLink'){ document.getElementById('linkContainerContent').innerHTML = msg; changeCSS(document.getElementById('adminLinkNotif'), 'hidden', 'remove'); setTimeout(function() { addLinkNotif(); }, 3000); } if(callbackId == 'approveLink'){ document.getElementById('linkContainerContent').innerHTML = msg; } if(callbackId == 'toggleBlockCal' && msg != ''){ if(msg != ''){ document.getElementById('customModal').innerHTML = msg; } } if(action == 'refreshAddon'){ document.getElementById('customModal').innerHTML = msg; changeCSS(document.getElementById('customModal'), 'hiddenModal', 'remove'); } if(callbackId == 'pwrem'){ if(msg == 'not found'){ document.getElementById('errorNote').style.display = 'block'; } else if(msg = 'Message has been sent'){ prepForNurse('&email=' + document.getElementById('emailremind').value, 'cngPwConfirm', 'inv/login.php'); } } if(callbackId == 'pwconf'){ if(msg == 'not found'){ document.getElementById('errorNote').style.display = 'block'; } else { document.getElementById('customModal').innerHTML = msg; } } if(callbackId == 'emailUpdate'){ document.getElementById('customModal').innerHTML = ''; changeCSS(document.getElementById('customModal'), 'hiddenModal', 'add'); document.getElementById('emailDiv').innerHTML = msg; } if(callbackId == 'approveMentor'){ document.getElementById('approvalDiv').innerHTML = msg; } if(callbackId == 'editEmail'){ document.getElementById('customModal').innerHTML = msg; changeCSS(document.getElementById('customModal'), 'hiddenModal', 'remove'); } if(callbackId == 'cngPwConfirm'){ if(msg == 'not found'){ document.getElementById('errorNote').style.display = 'block'; } else { document.getElementById('customModal').innerHTML = msg; } } if(action == 'pagination'){ var str = window.location.search; const urlParams = new URLSearchParams(str); if(urlParams.get('page') == null){ str = str + '?page=' + msg; } else { var repString = '&page=' + urlParams.get('page'); str = str.replace(repString, '&page=' + msg); } window.location.href = str; } if(action == 'playVideo'){ var data = JSON.parse(msg); var src = decodeURIComponent(data.vidReqName); var vidSource = document.getElementById('vidSrc'); var vidplayer = vidSource.parentElement; var loopData = data.dbVidSettings; for (var key in loopData) { if (loopData.hasOwnProperty(key)) { if(key.substr(0, 4) == 'opt_'){ var tarElem = document.getElementById(key); if(tarElem.nodeName == 'INPUT'){ tarElem.value = loopData[key]; if(tarElem.type == 'checkbox'){ if(loopData[key] == 'on'){ tarElem.checked = true; } else { tarElem.checked = false; } } } if(tarElem.nodeName == 'SELECT'){ for(var i = 0; i < tarElem.length; i++){ tarElem.options[i].selected = false; if(tarElem.options[i].value == loopData[key]){ tarElem.options[i].selected = true; } } } } } } document.getElementById('vidName').innerHTML = src; vidSource.setAttribute('src', data.vidReqFolder + data.vidReqId + '.mp4'); vidSource.setAttribute('type', 'video/mp4'); vidplayer.load(); vidplayer.play(); } if(callbackId == 'logOut'){ window.location.replace('index.php'); } if(callbackId == 'writeChatMsg'){ if(document.getElementById('postsCount').value == 0){ document.getElementById('orgNotesDiv').innerHTML = ''; } console.log(msg.replaceAll(/<div>/g,'
')); document.getElementById('orgNotesDiv').innerHTML = document.getElementById('orgNotesDiv').innerHTML + msg; document.getElementById('admOrgNotes').value = ''; document.getElementById('postsCount').value = parseInt(document.getElementById('postsCount').value) + 1; document.getElementById('orgNotesDiv').scrollTop = document.getElementById('orgNotesDiv').scrollHeight; updateFilesAndLinks(); } if(callbackId == 'setVideoColumns' || callbackId == 'setVideoRows'){ document.getElementById('poes').innerHTML = msg; } if(callbackId == 'changeMentor'){ window.location.replace('change.php'); } if(callbackId == 'login' || callbackId == 'cngPw'){ if(msg == 'a'){ window.location.href = 'mentor.php'; } if(msg == 'b'){ window.location.href = 'mentee.php'; } if(msg == 'c'){ window.location.href = 'admin.php'; } if(msg == 'no such username'){ document.getElementById('errorNote').innerHTML = 'The email or password is incorrect.'; } } } function onlyChangeClassIfTrue(clsLst, className, bolTrueFalse){ if(bolTrueFalse == true){ if(clsLst.contains(className) == true){ setTimeout(function(){ clsLst.remove(className); }, 100, clsLst); } } else { clsLst.add(className); } } var unblockingTime = 'off'; function draggin(elem){ if(elem.classList.contains('selectedTime') == true){ unblockingTime = 'blocking'; } else { unblockingTime = 'unblocking'; } } function stoppin(){ unblockingTime = 'off'; if (window.getSelection) { if (window.getSelection().empty) { // Chrome window.getSelection().empty(); } else if (window.getSelection().removeAllRanges) { // Firefox window.getSelection().removeAllRanges(); } } else if (document.selection) { // IE? document.selection.empty(); } } function freein(elem){ if(unblockingTime == 'unblocking' && elem.classList.contains('selectedTime') == false){ elem.classList.add('selectedTime'); } else if(unblockingTime == 'blocking' && elem.classList.contains('selectedTime') == true) { elem.classList.remove('selectedTime'); } } function changeCSS(elem, className, action){ var clsLst = elem.classList; if(action == 'remove' && clsLst.contains(className) == true){ clsLst.remove(className); } else if (action == 'add' && clsLst.contains(className) == false) { clsLst.add(className); } } function getValuesFromClass(cssClass) { var addArr = document.getElementsByClassName(cssClass); var str = ''; for(var i = 0; i < addArr.length; i++){ str = str + '&' + addArr[i].id + '=' + addArr[i].value; } return str; } function resetAndSetClass(elem, cssClass) { var addArr = document.getElementsByClassName(cssClass); console.log(addArr); for(var i = 0; i < addArr.length; i++){ addArr[i].classList.remove(cssClass); } elem.classList.add(cssClass); } function jumpToElem(elem){ var top = document.getElementById(elem).offsetTop; window.scrollTo(0, top); } //-------------------------------------validate input-------------------------------------- function clearRequiredInput(elem, className){ if(elem.offsetParent != null){ if(elem.classList.contains(className) == true){ elem.classList.remove(className); } } } function validateRequiredInput(elem, className){ //console.log(elem.offsetParent); if(elem.value == '' && elem.offsetParent != null){ if(elem.classList.contains(className) == false){ elem.classList.add(className); } } } function validateInputFields(elem, className){ if(elem.offsetParent != null){ if(elem.type == 'email'){ if(validateEmail(elem.value) == false){ elem.classList.add(className); } } } } function somValidate(){ //clear input var validateReqElems = document.getElementsByClassName('somRequired'); var validateInpElems = document.getElementsByClassName('somValidate'); for(var i = 0; i < validateReqElems.length; i++){ clearRequiredInput(validateReqElems[i], 'somInvalidInput'); } for(var i = 0; i < validateInpElems.length; i++){ clearRequiredInput(validateInpElems[i], 'somInvalidInput'); } //validate input for(var i = 0; i < validateReqElems.length; i++){ validateRequiredInput(validateReqElems[i], 'somInvalidInput'); } for(var i = 0; i < validateInpElems.length; i++){ validateInputFields(validateInpElems[i], 'somInvalidInput'); } //return if it passed var retBool = false; var isValidationOk = document.getElementsByClassName('somInvalidInput'); if(isValidationOk.length == 0){ retBool = true; } else { // console.log(isValidationOk); } return retBool; } function isURL(string) { var res = string.match(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g); return (res !== null) } function validateEmail(email) { var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; if( !emailReg.test( email ) ) { return false; } else { return true; } } function back_2nd_form(){ document.getElementById('sginpone').style.display = 'none'; document.getElementById('sginptwo').style.display = 'block'; document.getElementById('sigupPartOne').style.display = 'block'; document.getElementById('sigupPartTwo').style.display = 'none'; document.getElementById('signupTitleH3').innerHTML = 'Signup (2 of 3)'; } function toggleCSS(elem, CSSclass){ if(elem.classList.contains(CSSclass) == true){ elem.classList.remove(CSSclass); } else { elem.classList.add(CSSclass); } } function uploadCsv(upldFile, callb){ csvCallBack = callb; var reader = new FileReader(); reader.readAsText(upldFile); reader.onload = uploadCSVHandler; } function uploadCSVHandler(event) { processCSVData(event.target.result, csvCallBack); } function processCSVData(upldFile){ upldFile = upldFile.split(/\r?\n|\r/g); var sendStr = ''; var arr = new Array(); for(var i = 1; i < upldFile.length; i++){ if(upldFile[i] != ''){ var repString = ''; var strTracer = ''; for(var j = 0; j < upldFile[i].length; j++){ if(upldFile[i][j] == '"'){ if(strTracer == ''){ strTracer = 'start'; } else { strTracer = ''; } } if(upldFile[i][j] == ',' && strTracer == 'start'){ repString = repString + '|'; } else { repString = repString + upldFile[i][j]; } } for(var j = 0; j < 5; j++){ //removes up to 5 blank spaces near the new seperator repString = repString.replace(' |', '|'); repString = repString.replace('| ', '|'); } arr[arr.length] = repString.split(','); } } for(var i = 0; i < arr.length; i++){ for(var j = 0; j < arr[i].length; j++){ if(arr[i][j].substr(0,1) == '"'){ arr[i][j] = arr[i][j].substr(1,arr[i][j].length - 2); } sendStr = sendStr + '&i' + i + '_j' + j + '=' + arr[i][j]; } } prepForSOM('&i=' + arr.length + '&j=' + arr[0].length + sendStr, csvCallBack, 'inv/dbData.php'); } function toggleCalBlock(elem){ // var eid = elem.parentElement.parentElement.id; if(elem.classList.contains('calDayBlocked') == true){ elem.classList.remove('calDayBlocked'); } else { elem.classList.add('calDayBlocked'); } } function updateFilesAndLinks(){ var files = document.getElementsByClassName('sharedFilesFromChat'); var arr = new Array(); var txt = ''; for(i = 0; i < files.length; i++){ arr[i] = files[i].href; } files = arr.filter((item, index) => arr.indexOf(item) === index); for(i = 0; i < files.length; i++){ txt = txt + ''; } document.getElementById('fileSharLib').innerHTML = txt; var links = document.getElementsByClassName('chatLink'); var arr = new Array(); var txt = ''; for(i = 0; i < links.length; i++){ arr[i] = links[i].href; } links = arr.filter((item, index) => arr.indexOf(item) === index); for(i = 0; i < links.length; i++){ var linkTekst = links[i]; if(links[i].length > 40){ linkTekst = linkTekst.substr(0, 40) + '...'; } txt = txt + '
' + linkTekst + '
'; } document.getElementById('linksSharLib').innerHTML = txt; } function addToHidden(idCode){ var str = ''; var idCol = document.getElementsByClassName('chkBox'+idCode); for(var i = 0; i < idCol.length; i++){ if(idCol[i].checked == true){ if(str != ''){ str = str + '|'; } str = str + idCol[i].value; } } document.getElementById(idCode).value = str; }