var confModal = null; function prepForAcpohe(params, callbackId, url, action, target, srcElemId, fileObjId){ if (url == '') { //url is optional var url = 'inv/jarvisPFCortex.php'; } if (typeof target === 'undefined') { //target is optional var target = ''; } var file = ''; if (typeof fileObjId === 'undefined') { //file is optional var target = ''; } else { var fileInput = document.getElementById(fileObjId); var file = fileInput.files[0]; // get the first selected file - expand for multiple files? if (!file) { alert('Please select a file'); } } 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.file = file; //file 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); var formData = new FormData(); if(obj.file !== ''){ formData.append('uploadedFile', obj.file); } var qs = obj.params; if (qs.charAt(0) === '?') { qs = qs.substring(1); } var params = new URLSearchParams(qs); for (var pair of params.entries()) { var key = pair[0]; var value = pair[1]; formData.append(key, value); } formData.append('callbackId', obj.callbackId); formData.append('action', obj.action); if (window.XMLHttpRequest){ xmlHttp = new XMLHttpRequest(); } else { xmlHttp=new ActiveXObject('Microsoft.XMLHTTP'); } 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){ 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 { // console.log('urly: ' + obj.url + ' state: ' + xmlHttp.readyState + ' status: ' + xmlHttp.status + ' obj.action: ' + obj.action); cortexCb(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(formData); // xmlHttp.send(obj.params); } function cortexCb(callbackId, action, msg, srcId, targetId){ //----------------------checking data-------------------- //----------------------limit to section specific-------------------- console.log('callbackId: '+ callbackId); console.log('msg: '+ msg); console.log('from: '+ srcId); console.log('target: '+ targetId); var targetElem = document.getElementById(targetId); if(targetId != ''){ targetElem.innerHTML = msg; } if(callbackId === 'loadScormCourseData'){ alert(msg); /* var rawPairs = msg.split(';'); var i; for (i = 0; i < rawPairs.length; i = i + 1) { var pair = rawPairs[i].split('='); if (pair.length == 2) { var key = pair[0]; var value = unescape(pair[1]); Utils.API.data[key] = value; } } msg = 'cmi.core._children=student_id%2Cstudent_name%2Clesson_status%2Clesson_location%2Clesson_mode%2Cscore%2Ccredit%2Centry%2Cexit%2Csession_time%2Ctotal_time;cmi.core.score._children=raw;cmi.core.student_id=joe_student_001;cmi.core.student_name=Joe%20Student;cmi.core.lesson_status=incomplete;cmi.core.score.raw=0;cmi.core.session_time=0000%3A02%3A20.54;cmi.core.credit=credit;cmi.core.entry=ab-initio;cmi.core.lesson_mode=normal;cmi.objectives.0.id=An_essential_knowledge_of_Employment_law_and_Health_and_Safety_Legislation_to_practice_as_an_OH_Phys_de38904d-2854-4560-a910-8115d28b3ab0;cmi.objectives.0.status=passed;cmi.objectives.0.score.raw=100;cmi.objectives.1.id=Understanding_the_legal_foundations_for_the_health_and_safety_responsibilities__2d0c3b86-66df-4359-b341-c0a92c387678;cmi.objectives.1.status=not%20attempted;cmi.objectives.1.score.raw=0;cmi.objectives.2.id=Understanding_of_Employment_Law_and_Disability_d77263e7-a534-419d-ae2e-9bdcad3423da;cmi.objectives.2.status=not%20attempted;cmi.objectives.2.score.raw=0;cmi.objectives.3.id=Employment_Law_Across_Borders_358d9372-7efa-418e-9e8c-a6b95a95e0c2;cmi.objectives.3.status=not%20attempted;cmi.objectives.3.score.raw=0;cmi.objectives.4.id=Data_Protection__Consent_and_control_of_patient_information_regulations_c1cf53be-c73f-4709-a145-748348c3928b;cmi.objectives.4.status=not%20attempted;cmi.objectives.4.score.raw=0;cmi.objectives.5.id=Professional_duties_and_ethical_standards_applicable_to_you_as_an_OH_Physiotherapist_in_Occupational_7a52ac91-9ab2-4ee8-9f9f-db129eb3c436;cmi.objectives.5.status=not%20attempted;cmi.objectives.5.score.raw=0;cmi.objectives.6.id=Workplace_Risk_Assessment_80ccc3e8-862a-4a87-8083-d7fe49baf3d2;cmi.objectives.6.status=not%20attempted;cmi.objectives.6.score.raw=0;cmi.objectives.7.id=RIDDOR_8a80335e-af07-488c-b58d-a4f48100a7b3;cmi.objectives.7.status=not%20attempted;cmi.objectives.7.score.raw=0;cmi.objectives.8.id=Whistleblowing_e3c554a1-a08b-4652-855f-2984a674a12a;cmi.objectives.8.status=not%20attempted;cmi.objectives.8.score.raw=0;cmi.objectives.9.id=Occupational_Health_Audit_bcddf304-8380-4a3c-bb18-a98313125251;cmi.objectives.9.status=not%20attempted;cmi.objectives.9.score.raw=0;cmi.objectives.10.id=Module_3_Exam___f96f5db5-5391-4364-bb85-0012454d3288;cmi.objectives.10.status=not%20attempted;cmi.objectives.10.score.raw=0;cmi.objectives.11.id=Bibliography__References_and_Additional_Resources_4ea4e26d-8407-4c4e-9b78-8debc786587a;cmi.objectives.11.status=not%20attempted;cmi.objectives.11.score.raw=0;cmi.interactions.0.id=Think_of_a_work_injury_or_incident__Can_you_list_the_Criminal_and_Civil_elements_to_it__0b1efbaf-f185-4b51-8936-e78100e5c049;cmi.interactions.0.type=fill-in;cmi.interactions.0.student_response=fan;cmi.interactions.0.objectives.0.id=An_essential_knowledge_of_Employment_law_and_Health_and_Safety_Legislation_to_practice_as_an_OH_Phys_de38904d-2854-4560-a910-8115d28b3ab0;cmi.interactions.1.id=Based_on_the_principles_of_OH_Law__what_is_the_appropriate_response__66529ba1-5339-40a0-93aa-3c0de0b9780e;cmi.interactions.1.type=choice;cmi.interactions.1.student_response=a;cmi.interactions.1.result=wrong;cmi.interactions.1.objectives.0.id=An_essential_knowledge_of_Employment_law_and_Health_and_Safety_Legislation_to_practice_as_an_OH_Phys_de38904d-2854-4560-a910-8115d28b3ab0;cmi.interactions.1.correct_responses.0.pattern=c;cmi.interactions.2.id=Based_on_the_principles_of_OH_Law__what_is_the_appropriate_response__66529ba1-5339-40a0-93aa-3c0de0b9780e;cmi.interactions.2.type=choice;cmi.interactions.2.student_response=c;cmi.interactions.2.result=correct;cmi.interactions.2.objectives.0.id=An_essential_knowledge_of_Employment_law_and_Health_and_Safety_Legislation_to_practice_as_an_OH_Phys_de38904d-2854-4560-a910-8115d28b3ab0;cmi.interactions.2.correct_responses.0.pattern=c;cmi.interactions.3.id=Under_the_Health_and_Safety_at_Work_Act__employers_must_take_measures_to_control_risks__7f5b519b-e711-44bb-8730-c7837802c802;cmi.interactions.3.type=choice;cmi.interactions.3.student_response=a;cmi.interactions.3.result=wrong;cmi.interactions.3.objectives.0.id=Understanding_the_legal_foundations_for_the_health_and_safety_responsibilities__2d0c3b86-66df-4359-b341-c0a92c387678;cmi.interactions.3.correct_responses.0.pattern=b;cmi.interactions.4.id=Under_the_Health_and_Safety_at_Work_Act__employers_must_take_measures_to_control_risks__7f5b519b-e711-44bb-8730-c7837802c802;cmi.interactions.4.type=choice;cmi.interactions.4.student_response=b;cmi.interactions.4.result=correct;cmi.interactions.4.objectives.0.id=Understanding_the_legal_foundations_for_the_health_and_safety_responsibilities__2d0c3b86-66df-4359-b341-c0a92c387678;cmi.interactions.4.correct_responses.0.pattern=b;'; */ } if(callbackId === 'fu' || callbackId === 'courseSearchResults'){ const obj = JSON.parse(msg); var elem = document.getElementById('emailSuggestions'); elem.innerHTML = ''; function addCell(row, text) { var td = document.createElement('td'); td.appendChild(document.createTextNode(text)); td.style.padding = '6px'; row.appendChild(td); } function selectUser(id, name, email) { document.getElementById('user_id').value = id; document.getElementById('name').value = name; document.getElementById('emailSuggestions').innerHTML = ''; } var table = document.createElement('table'); table.style.width = '100%'; table.style.borderCollapse = 'collapse'; table.style.cursor = 'pointer'; // ----- header ----- var thead = document.createElement('thead'); var hRow = document.createElement('tr'); ['ID', 'Name', 'Email'].forEach(function (text) { var th = document.createElement('th'); th.appendChild(document.createTextNode(text)); th.style.borderBottom = '1px solid #ccc'; th.style.textAlign = 'left'; th.style.padding = '6px'; hRow.appendChild(th); }); thead.appendChild(hRow); table.appendChild(thead); // ----- body ----- var tbody = document.createElement('tbody'); for (var i = 0; i < obj.length; i++) { (function (user) { var tr = document.createElement('tr'); tr.onmouseover = function () { this.style.background = '#f0f0f0'; }; tr.onmouseout = function () { this.style.background = ''; }; tr.onclick = function () { selectUser(user.ID, user.name, user.email); this.style.background = '#e0e0ff'; }; addCell(tr, user.ID); addCell(tr, user.name); addCell(tr, user.email); tbody.appendChild(tr); })(obj[i]); } table.appendChild(tbody); elem.appendChild(table); } if (callbackId === 'editCourseFilesDropDown') { var obj = JSON.parse(msg); var sel = document.getElementById(obj.selid); var modules = obj.modules; var i; sel.innerHTML = ''; if (modules.length === 0) { sel.innerHTML = ''; return; } var firstOpt = document.createElement('option'); firstOpt.value = ''; firstOpt.textContent = '-- Select a module --'; sel.appendChild(firstOpt); for (i = 0; i < modules.length; i = i + 1) { var m = modules[i]; var opt = document.createElement('option'); opt.value = m.ID; opt.textContent = m.title; sel.appendChild(opt); } } if(callbackId === 'loadCourseDropDownModules'){ const obj = JSON.parse(msg); // { selid: 'moduleSelect5', modules: [...] } var targetSelId = obj.selid; var modules = obj.modules; var sel = document.getElementById(targetSelId); sel.innerHTML = ''; if(!Array.isArray(modules) || modules.length === 0){ sel.innerHTML = ''; return; } var firstOpt = document.createElement('option'); firstOpt.value = ''; firstOpt.textContent = '-- Select a module --'; sel.appendChild(firstOpt); for(var i = 0; i < modules.length; i++){ var m = modules[i]; var opt = document.createElement('option'); opt.value = m.ID; opt.textContent = m.title; sel.appendChild(opt); } } if(callbackId === 'changeCourseAndLoadModules'){ const obj = JSON.parse(msg); // expect: { selid: 'moduleSelect7', modules: [ ... ] } var targetSelId = obj.selid; var modules = obj.modules; var sel = document.getElementById(targetSelId); sel.innerHTML = ''; if(!Array.isArray(modules) || modules.length === 0){ sel.innerHTML = ''; return; } var firstOpt = document.createElement('option'); firstOpt.value = ''; firstOpt.textContent = '-- Select a module --'; sel.appendChild(firstOpt); for(var i = 0; i < modules.length; i++){ var m = modules[i]; var opt = document.createElement('option'); opt.value = m.ID; opt.textContent = m.title; sel.appendChild(opt); } } if(callbackId === 'login'){ if(msg === 'not ok'){ var errMsgs = document.getElementsByClassName('wrongPw'); for(var i = 0; i < errMsgs.length; i++){ changeCSS(errMsgs[i], 'noPw', 'remove'); } } else if(msg === 'ok'){ window.location.href = 'welcome.php'; } } else if (callbackId === 'setProfileImg') { if (msg != 'Error') { if (msg == 'newpp.png') { document.getElementById('profImg').style.backgroundImage = "url('images/" + msg + "')"; } else { } } } else if(callbackId === 'uploadProfileImg'){ const obj = JSON.parse(msg); document.getElementById('profImg').src = obj.file; var allProfImgs = document.getElementsByClassName('activeProfileImg'); for(i = 0; i < allProfImgs.length; i++){ allProfImgs[i].classList.remove('activeProfileImg'); } const oncl = "document.getElementById('profImg').src = this.src;" + "document.getElementById('selProfImg').value = '"+obj.file+"';" + "var allProfImgs = document.getElementsByClassName('activeProfileImg'); " + "for (i = 0; i < allProfImgs.length; i++) { allProfImgs[i].classList.remove('activeProfileImg'); }" + "this.classList.add('activeProfileImg');" + "prepForAcpohe(prepCortexParams('kom_profImg'), 'setProfileImg', 'inv/cortex.php');"; const newImg = document.createElement('img'); newImg.src = obj.file; newImg.style.borderRadius = '5px'; newImg.style.margin = '5px'; newImg.classList.add('activeProfileImg'); newImg.height = 100; newImg.id = 'img' + Math.floor(Math.random() * 10000000) + 100; //lazy way of doing it - can secure it with a counter later. But it's an edge case of 1 in 10 mil, so not a prio right now newImg.setAttribute('onclick', oncl); document.getElementById('profImgContainer').appendChild(newImg); } else if(callbackId === 'updateAccountSettings' || callbackId === 'delAuthor' || callbackId === 'addAuthor' || callbackId === 'saveBannerOrder' || callbackId === 'addBanner' || callbackId === 'delBanner' || callbackId === 'editBanner' || callbackId === 'editToolkits' || callbackId === 'editVideos' || callbackId === 'editToolkitFile' || callbackId === 'editResourceFile' || callbackId === 'editVideosFile' || callbackId === 'addtoolkits' || callbackId === 'addvideos' || callbackId === 'deltoolkits' || callbackId === 'delvideos' || callbackId === 'editFolder' || callbackId === 'addFolder' || callbackId === 'delFolders' || callbackId === 'editFiles' || callbackId === 'addFile' || callbackId === 'delFiles' || callbackId === 'addUser' || callbackId === 'delUser' || callbackId === 'editUser' || callbackId === 'addUsersFromCsv' || callbackId === 'editCoursePayments' || callbackId === 'editCourse' || callbackId === 'delCourse' || callbackId === 'addCourse' || callbackId === 'editModule' || callbackId === 'delModule' || callbackId === 'addModule' || callbackId === 'delCourseDate' || callbackId === 'addCourseDate' || callbackId === 'delCoursePayment' || callbackId === 'editCourseFiles' || callbackId === 'editCourseFilesDropDown' || callbackId === 'delCourseFiles' || callbackId === 'addCourseFiles' || callbackId === 'cngGrade' || callbackId === 'cngGradeComment' || callbackId === 'cngGFinalComment' || callbackId === 'updRevStatus'){ const obj = JSON.parse(msg); if(obj.status !== 'ok'){ showModal(obj.confirmationText, obj.status); } else { showModal(obj.confirmationText, obj.status); if(callbackId === 'delAuthor'){ document.getElementById('author' + obj.delId).remove(); refreshRowColors(); } else if(callbackId === 'addUsersFromCsv'){ if(obj.status == 'ok'){ setTimeout(function() {location.reload();}, 3000); } } else if(callbackId === 'editCoursePayments'){ document.getElementById('courseInfo' + obj.id).remove(); } else if(callbackId === 'delUser'){ document.getElementById('user' + obj.delId).remove(); refreshRowColors(); } else if(callbackId === 'delFolders'){ document.getElementById('fileView' + obj.delId).remove(); document.getElementById('folder' + obj.delId).remove(); // refreshRowColors(); } else if(callbackId === 'editFolder'){ if(obj.name != ''){ document.getElementById('fileView' + obj.id).children[1].innerHTML = obj.name; } if(obj.locked != 'off'){ document.getElementById('fileView' + obj.id).children[0].style.opacity = '0.4'; } else if(obj.locked != 'on'){ document.getElementById('fileView' + obj.id).children[0].style.opacity = '1'; } } else if(callbackId === 'editFiles'){ if(obj.displayName != ''){ document.getElementById('fileView' + obj.id).children[1].innerHTML = obj.displayName; } if(obj.locked != 'off'){ document.getElementById('fileView' + obj.id).children[0].style.opacity = '0.4'; } else if(obj.locked != 'on'){ document.getElementById('fileView' + obj.id).children[0].style.opacity = '1'; } } else if(callbackId === 'delCourseDate'){ document.getElementById('eventOverview_' + obj.delId).remove(); document.getElementById('eventDetails_' + obj.delId).remove(); } else if(callbackId === 'delCoursePayment'){ document.getElementById('payment' + obj.id).remove(); refreshRowColors(); } else if(callbackId === 'delCourseFiles'){ document.getElementById('courseFile' + obj.delId).remove(); refreshRowColors(); } else if(callbackId === 'delFiles'){ document.getElementById('file' + obj.delId).remove(); document.getElementById('fileView' + obj.delId).remove(); refreshTblColors('trHover'); } else if(callbackId === 'delModule'){ document.getElementById('module' + obj.delId).remove(); refreshRowColors(); } else if(callbackId === 'delCourse'){ document.getElementById('course' + obj.delId).remove(); refreshRowColors(); } else if(callbackId === 'deltoolkits'){ document.getElementById('toolkits' + obj.delId).remove(); refreshRowColors(); } else if(callbackId === 'delvideos'){ document.getElementById('videos' + obj.delId).remove(); refreshRowColors(); } else if(obj.extra === 'closeIframe'){ console.log(obj); if(callbackId === 'editBanner'){ var targ = 'bannerImg' + obj.id; } else if(callbackId === 'editToolkits'){ var targ = 'imageType' + obj.id; } else if(callbackId === 'editVideos'){ var targ = 'imageType' + obj.id; } else if(callbackId === 'editToolkitFile'){ var targ = 'filetype' + obj.id; } else if(callbackId === 'editToolkitFile'){ var targ = 'filetype' + obj.id; } else if(callbackId === 'editVideosFile'){ var targ = 'filePath' + obj.id; } else if(callbackId === 'editResourceFile'){ var targ = 'filetype' + obj.id; } else if(callbackId === 'editCourseFiles'){ var targ = 'newFileType' + obj.id; } var parElem = window.parent.document.getElementById(targ); console.log(parElem); if(callbackId === 'editBanner' || callbackId === 'editToolkits' || callbackId === 'editVideos'){ window.parent.document.getElementById(targ).src = obj.img; } else if(callbackId === 'editToolkitFile' || callbackId === 'editVideosFile' || callbackId === 'editResourceFile' || callbackId === 'editCourseFiles'){ window.parent.document.getElementById(targ).innerHTML = obj.file; } if(callbackId === 'editResourceFile'){ window.parent.document.getElementById('fileView' + obj.id).href = obj.folderPath + obj.file; var newExt = obj.file.substring(obj.file.lastIndexOf('.') + 1); newExt = newExt.toLowerCase(); if(newExt == 'pdf'){ window.parent.document.getElementById('fileView' + obj.id).children[0].style.backgroundImage = 'url(\'images/pdf2.png\')'; } else if(newExt == 'dotx'){ window.parent.document.getElementById('fileView' + obj.id).children[0].style.backgroundImage = 'url(\'images/dotx2.png\')'; } else if(newExt == 'docx'){ window.parent.document.getElementById('fileView' + obj.id).children[0].style.backgroundImage = 'url(\'images/docx2.png\')'; } else { window.parent.document.getElementById('fileView' + obj.id).children[0].style.backgroundImage = 'url(\''+obj.folderPath + obj.file+'\')'; } } window.parent.document.getElementById('customModal').classList.add('hiddenModal'); window.parent.document.getElementById('custModalContent').innerHTML = ''; } else if(callbackId === 'delBanner'){ document.getElementById(obj.delId).remove(); refreshTblColors('zebraMe'); } else if(callbackId === 'addCourseFiles'){ var tbl = document.getElementById('courseFilesTbl').getElementsByTagName('tbody')[0]; var tr = document.createElement('tr'); tr.id = 'courseFile' + obj.id; tr.className = 'trHover'; // --- Name --- var tdName = document.createElement('td'); tdName.style.width = '250px'; var taName = document.createElement('textarea'); taName.className = 'kom_login tdVisuals'; taName.style.height = '80px'; taName.style.width = '250px'; taName.style.resize = 'none'; taName.id = 'name' + obj.id; taName.value = obj.name || ''; taName.setAttribute('onchange', "prepForAcpohe('&tbl=course_files&id=" + obj.id + "&name=' + encodeURIComponent(this.value), 'editCourseFiles', 'inv/cortex.php');"); tdName.appendChild(taName); tr.appendChild(tdName); // --- Type (fileCat) --- var tdType = document.createElement('td'); var selType = document.createElement('select'); selType.id = 'fileCat' + obj.id; selType.className = 'kom_login'; selType.setAttribute( 'onchange', "prepForAcpohe('&tbl=course_files&id=" + obj.id + "&fileCat=' + encodeURIComponent(this.value), 'editCourseFiles', 'inv/cortex.php');" ); var typeOptions = [ { v: 'scorm', t: 'SCORM file' }, { v: 'video', t: 'Video' }, { v: 'coursemat', t: 'Course Material' } ]; var i; for (i = 0; i < typeOptions.length; i++) { var oType = document.createElement('option'); oType.value = typeOptions[i].v; oType.textContent = typeOptions[i].t; if (obj.fileCat === typeOptions[i].v) { oType.selected = true; } selType.appendChild(oType); } tdType.appendChild(selType); tr.appendChild(tdType); // --- File --- var tdFile = document.createElement('td'); var divFile = document.createElement('div'); divFile.className = 'kom_login tdVisuals'; divFile.style.height = '140px'; divFile.style.width = '200px'; divFile.style.cursor = 'pointer'; divFile.style.wordWrap = 'break-word'; divFile.id = 'newFileType' + obj.id; divFile.textContent = (obj.path && obj.path !== '') ? obj.path : 'Please select file'; divFile.setAttribute( 'onclick', "showImageModal('courseFile', '" + obj.id + "', 'files/modules/files/" + obj.moduleId + "/');" ); tdFile.appendChild(divFile); tr.appendChild(tdFile); // --- Course --- var tdCourse = document.createElement('td'); var selCourse = document.createElement('select'); selCourse.id = 'courseSelect' + obj.id; selCourse.className = 'kom_login'; selCourse.setAttribute( 'onchange', "prepForAcpohe('&tbl=course_files&id=" + obj.id + "&courseId=' + encodeURIComponent(this.value) + '&selid=moduleSelect" + obj.id + "', 'editCourseFilesDropDown', 'inv/cortex.php');" ); var optCourseDefault = document.createElement('option'); optCourseDefault.value = ''; optCourseDefault.textContent = '-- Select a course --'; selCourse.appendChild(optCourseDefault); if (obj.courses && obj.courses.length) { for (i = 0; i < obj.courses.length; i++) { var c = obj.courses[i]; var optCourse = document.createElement('option'); optCourse.value = c.ID; optCourse.textContent = c.title; if (c.ID == obj.courseId) { optCourse.selected = true; } selCourse.appendChild(optCourse); } } tdCourse.appendChild(selCourse); tr.appendChild(tdCourse); // --- Module --- var tdModule = document.createElement('td'); var selModule = document.createElement('select'); selModule.id = 'moduleSelect' + obj.id; selModule.className = 'kom_login'; selModule.setAttribute( 'onchange', "prepForAcpohe('&tbl=course_files&id=" + obj.id + "&moduleId=' + encodeURIComponent(this.value), 'editCourseFiles', 'inv/cortex.php');" ); var optModuleDefault = document.createElement('option'); optModuleDefault.value = ''; optModuleDefault.textContent = '-- Select a module --'; selModule.appendChild(optModuleDefault); if (obj.modules && obj.modules.length) { for (i = 0; i < obj.modules.length; i++) { var m = obj.modules[i]; var optModule = document.createElement('option'); optModule.value = m.ID; optModule.textContent = m.title; if (m.ID == obj.moduleId) { optModule.selected = true; } selModule.appendChild(optModule); } } tdModule.appendChild(selModule); tr.appendChild(tdModule); // --- Delete --- var tdDel = document.createElement('td'); tdDel.style.textAlign = 'right'; tdDel.style.width = '70px'; tdDel.style.paddingRight = '10px'; var btnDel = document.createElement('button'); btnDel.id = 'delBtn' + obj.id; btnDel.type = 'button'; btnDel.className = 'actionButton ani150'; btnDel.textContent = 'Delete'; btnDel.setAttribute( 'onclick', "prepForAcpohe('&id=" + obj.id + "&tbl=course_files', 'delCourseFiles', 'inv/cortex.php');" ); tdDel.appendChild(btnDel); tr.appendChild(tdDel); // ----- attach to table BODY (this was the key bit) ----- var rows = tbl.getElementsByTagName('tr'); if (rows.length > 0) { var insertIndex = rows.length - 2; tbl.insertBefore(tr, rows[insertIndex]); } else { tbl.appendChild(tr); } if (typeof refreshRowColors === 'function') { refreshRowColors(); } } else if(callbackId === 'addCourseDate'){ var id = obj.id; // course_dates.id from backend var tblBody = document.getElementById('eventsTblBody'); if (!tblBody) return; // ----- Get course & module names from current "Add new event" selects ----- var courseSel = document.getElementById('new_course'); var moduleSel = document.getElementById('new_module'); var courseName = ''; if (courseSel && courseSel.value === obj.courseId) { courseName = courseSel.options[courseSel.selectedIndex].text.trim(); } var moduleName = ''; if (moduleSel && moduleSel.value === obj.moduleId) { moduleName = moduleSel.options[moduleSel.selectedIndex].text.trim(); } // Fallback if selects changed: try courseModulesMap if (!moduleName && typeof courseModulesMap !== 'undefined' && courseModulesMap[obj.courseId]) { var mods = courseModulesMap[obj.courseId]; for (var i = 0; i < mods.length; i++) { if (String(mods[i].id) === String(obj.moduleId)) { moduleName = mods[i].title; break; } } } // Header text like existing cards: "Course: Module" var headerText = courseName || ('Event ' + id); if (moduleName) { headerText += ': ' + moduleName; } // ----- Availability / spots / attendees summary ----- var isAlways = (!obj.date || obj.spots_open === '99999'); var dateText = isAlways ? 'Always available' : (obj.date && obj.date !== '0000-00-00' ? obj.date : '—'); var spots = obj.spots_open ? parseInt(obj.spots_open, 10) : 0; var attendeesCount = 0; // new event => 0 var attendeesSpotsText; if (isAlways) { attendeesSpotsText = attendeesCount + ' / no limit'; } else if (spots > 0) { attendeesSpotsText = attendeesCount + ' / ' + spots; } else { attendeesSpotsText = String(attendeesCount); } // ========================= // 1) OVERVIEW ROW // ========================= var tr = document.createElement('tr'); tr.id = 'eventOverview_' + id; tr.className = 'event-row'; tr.innerHTML = '' + (courseName || '') + '' + '' + (moduleName || '') + '' + '' + dateText + '' + '' + attendeesSpotsText + '' + ''; // ========================= // 2) DETAILS ROW + CARD // ========================= var detailsTr = document.createElement('tr'); detailsTr.id = 'eventDetails_' + id; detailsTr.className = 'event-details-row'; var detailsTd = document.createElement('td'); detailsTd.colSpan = 5; var card = document.createElement('div'); card.className = 'course-date-card'; card.id = 'event' + id; var discountVal = obj.discount || '0.00'; var hasDiscount = parseFloat(discountVal) > 0; var duRaw = obj.discount_valid_until || ''; var duVal = duRaw ? duRaw.replace(' ', 'T') : ''; card.innerHTML = // Header '
' + headerText + '
' + // Row 1: Always / Date / Start / End '
' + '
' + '
Always available
' + '' + '
' + '
' + '
Date
' + '' + '
' + '
' + '
Start time
' + '' + '
' + '
' + '
End time
' + '' + '
' + '
' + // Row 2: Location / Spots / Attendees / Email promo '
' + '
' + '
Location
' + '' + '
' + '
' + '
Spots to fill
' + '' + '
' + '
' + '
Attendees
' + '
0 attendees">' + '0 attendees' + '
' + '
' + '
' + '
Email promo
' + '' + '
' + '
' + // Row 3: Price / Discount toggle / Discount % / Until '
' + '
' + '
Price
' + '' + '
' + '
' + '
Discount active
' + '
' + '' + '
' + '
' + '
' + '
Discount percentage
' + '' + '
' + '
' + '
Discount valid until
' + '' + '
' + '
' + // Row 4: Delete button '
' + '
' + '
' + '
 
' + '
' + '' + '
' + '
' + '
'; detailsTd.appendChild(card); detailsTr.appendChild(detailsTd); // Append rows to table tblBody.appendChild(tr); tblBody.appendChild(detailsTr); // ----- Toggle expand on click ----- tr.addEventListener('click', function () { var open = detailsTr.classList.contains('open'); if (open) { detailsTr.classList.remove('open'); tr.classList.remove('expanded'); } else { detailsTr.classList.add('open'); tr.classList.add('expanded'); } }); // ----- Apply initial visual states ----- if (typeof applyAlwaysAvailableState === 'function' && isAlways) { applyAlwaysAvailableState(id, true); } if (typeof applyDiscountState === 'function') { var dt = document.getElementById('discountToggle_' + id); if (dt) applyDiscountState(id, dt.checked); } // ----- Clear "add new" inputs ----- var addFields = document.getElementsByClassName('adddate'); for (var i = 0; i < addFields.length; i++) { addFields[i].value = ''; } } else if(callbackId === 'addModule'){ var tbl = document.getElementById('modulesTbl').getElementsByTagName('tbody')[0]; var tr = document.createElement('tr'); tr.id = 'module' + obj.id; tr.className = 'trHover'; // --- Course (label only) --- var tdCourse = document.createElement('td'); tdCourse.style.width = '160px'; tdCourse.style.padding = '10px 15px'; tdCourse.style.verticalAlign = 'top'; tdCourse.textContent = obj.course_title || ''; tr.appendChild(tdCourse); // --- Title (textarea) --- var tdTitle = document.createElement('td'); tdTitle.style.width = '180px'; var taTitle = document.createElement('textarea'); taTitle.className = 'kom_login tdVisuals moduleLongText'; taTitle.style.height = '80px'; taTitle.id = 'title' + obj.id; taTitle.value = obj.title || ''; taTitle.setAttribute( 'onchange', "prepForAcpohe('&tbl=course_modules&id=" + obj.id + "&title=' + encodeURIComponent(this.value), 'editModule', 'inv/cortex.php');"); tdTitle.appendChild(taTitle); tr.appendChild(tdTitle); // --- Description (textarea) --- var tdDesc = document.createElement('td'); tdDesc.style.width = '260px'; var taDesc = document.createElement('textarea'); taDesc.className = 'kom_login tdVisuals moduleLongText'; taDesc.style.height = '80px'; taDesc.id = 'description' + obj.id; taDesc.value = obj.description || ''; taDesc.setAttribute('onchange', "prepForAcpohe('&tbl=course_modules&id=" + obj.id + "&description=' + encodeURIComponent(this.value), 'editModule', 'inv/cortex.php');"); tdDesc.appendChild(taDesc); tr.appendChild(tdDesc); // --- Member paywall (toggle) --- var tdMember = document.createElement('td'); tdMember.style.width = '75px'; var lblMember = document.createElement('label'); lblMember.className = 'switch'; var chkMember = document.createElement('input'); chkMember.id = 'member_paywall' + obj.id; chkMember.className = 'notifSetting'; chkMember.type = 'checkbox'; chkMember.value = 1; if (obj.member_paywall === 'yes' || obj.member_paywall === '1' || obj.member_paywall === true) { chkMember.checked = true; } chkMember.setAttribute('onchange',"chkBoxToggleIO(this); prepForAcpohe('&tbl=course_modules&id=" + obj.id + "&member_paywall=' + encodeURIComponent(this.value), 'editModule', 'inv/cortex.php');"); var spanMember = document.createElement('span'); spanMember.className = 'sliderRound'; lblMember.appendChild(chkMember); lblMember.appendChild(spanMember); tdMember.appendChild(lblMember); tr.appendChild(tdMember); // --- Free paywall (toggle) --- var tdFree = document.createElement('td'); tdFree.style.width = '75px'; var lblFree = document.createElement('label'); lblFree.className = 'switch'; var chkFree = document.createElement('input'); chkFree.id = 'free_paywall' + obj.id; chkFree.className = 'notifSetting'; chkFree.type = 'checkbox'; chkFree.value = 1; if (obj.free_paywall === 'yes' || obj.free_paywall === '1' || obj.free_paywall === true) { chkFree.checked = true; } chkFree.setAttribute('onchange', "chkBoxToggleIO(this); prepForAcpohe('&tbl=course_modules&id=" + obj.id + "&free_paywall=' + encodeURIComponent(this.value), 'editModule', 'inv/cortex.php');"); var spanFree = document.createElement('span'); spanFree.className = 'sliderRound'; lblFree.appendChild(chkFree); lblFree.appendChild(spanFree); tdFree.appendChild(lblFree); tr.appendChild(tdFree); // --- CPD (number input) --- var tdCPD = document.createElement('td'); tdCPD.style.width = '70px'; tdCPD.style.paddingRight = '10px'; var inpCPD = document.createElement('input'); inpCPD.type = 'number'; inpCPD.className = 'kom_login tdVisuals'; inpCPD.style.height = '40px'; inpCPD.style.width = '100%'; inpCPD.style.margin = '0'; inpCPD.id = 'cpd' + obj.id; inpCPD.value = obj.cpd || 0; inpCPD.setAttribute('onchange', "prepForAcpohe('&tbl=course_modules&id=" + obj.id + "&cpd=' + encodeURIComponent(this.value), 'editModule', 'inv/cortex.php');"); tdCPD.appendChild(inpCPD); tr.appendChild(tdCPD); // --- Dates (status + link) --- var tdDates = document.createElement('td'); tdDates.style.width = '110px'; tdDates.style.padding = '10px 15px'; tdDates.style.verticalAlign = 'top'; var spanDot = document.createElement('span'); spanDot.className = 'statusDot'; spanDot.style.backgroundColor = obj.has_dates ? 'green' : 'red'; var aLink = document.createElement('a'); aLink.href = 'admin.php?bit=courseDate&moduleId=' + obj.id; aLink.style.color = obj.has_dates ? 'green' : 'red'; aLink.textContent = obj.has_dates ? 'View dates' : 'No dates'; tdDates.appendChild(spanDot); tdDates.appendChild(document.createTextNode(' ')); tdDates.appendChild(aLink); tr.appendChild(tdDates); // --- Delete button --- var tdDel = document.createElement('td'); tdDel.style.textAlign = 'right'; tdDel.style.width = '80px'; tdDel.style.paddingRight = '0'; var btnDel = document.createElement('button'); btnDel.id = 'delModuleBtn' + obj.id; btnDel.type = 'button'; btnDel.className = 'actionButton ani150'; btnDel.textContent = 'Delete'; btnDel.setAttribute('onclick', "prepForAcpohe('&id=" + obj.id + "&tbl=course_modules', 'delModule', 'inv/cortex.php');"); tdDel.appendChild(btnDel); tr.appendChild(tdDel); var rows = tbl.getElementsByTagName('tr'); var insertIndex = rows.length - 1; tbl.insertBefore(tr, rows[insertIndex]); // --- Refresh alternating row colors (if used) --- if (typeof refreshRowColors === 'function') refreshRowColors(); // --- Clear add-module fields --- var elems = document.getElementsByClassName('addmodule'); for (var i = 0; i < elems.length; i++) { var el = elems[i]; var tag = el.tagName.toLowerCase(); if (tag === 'select') el.selectedIndex = 0; else el.value = ''; } } else if(callbackId === 'addCourse'){ var tbl = document.getElementById('coursesTbl').getElementsByTagName('tbody')[0]; var tr = document.createElement('tr'); tr.id = 'course' + obj.id; tr.className = 'trHover'; // --- Title --- var td1 = document.createElement('td'); td1.style.width = '220px'; var titleTa = document.createElement('textarea'); titleTa.className = 'kom_login tdVisuals courseLongText'; titleTa.id = 'title'; titleTa.style.height = '150px'; titleTa.value = obj.title || ''; titleTa.setAttribute( 'onchange', "prepForAcpohe('&tbl=courses&id=" + obj.id + "&title=' + encodeURIComponent(this.value), 'editCourse', 'inv/cortex.php');" ); td1.appendChild(titleTa); tr.appendChild(td1); // --- Description --- var td2 = document.createElement('td'); td2.style.width = '260px'; var descTa = document.createElement('textarea'); descTa.className = 'kom_login tdVisuals courseLongText'; descTa.id = 'description'; descTa.style.height = '150px'; descTa.value = obj.description || ''; descTa.setAttribute( 'onchange', "prepForAcpohe('&tbl=courses&id=" + obj.id + "&description=' + encodeURIComponent(this.value), 'editCourse', 'inv/cortex.php');" ); td2.appendChild(descTa); tr.appendChild(td2); // --- Summary --- var td3 = document.createElement('td'); td3.style.width = '260px'; var sumTa = document.createElement('textarea'); sumTa.className = 'kom_login tdVisuals courseLongText'; sumTa.id = 'summary'; sumTa.style.height = '150px'; sumTa.value = obj.summary || ''; sumTa.setAttribute( 'onchange', "prepForAcpohe('&tbl=courses&id=" + obj.id + "&summary=' + encodeURIComponent(this.value), 'editCourse', 'inv/cortex.php');" ); td3.appendChild(sumTa); tr.appendChild(td3); // --- Modules (none on creation) --- var td4 = document.createElement('td'); td4.style.width = '120px'; td4.style.verticalAlign = 'top'; td4.style.padding = '10px 15px'; var spanNoMods = document.createElement('span'); spanNoMods.style.color = '#777'; spanNoMods.textContent = 'No modules'; td4.appendChild(spanNoMods); tr.appendChild(td4); // --- Face to face --- var td5 = document.createElement('td'); td5.style.width = '80px'; td5.style.paddingRight = '10px'; var selF2F = document.createElement('select'); selF2F.className = 'kom_login tdVisuals'; selF2F.style.height = '40px'; selF2F.style.width = '100%'; selF2F.style.margin = '0'; selF2F.id = 'face_to_face' + obj.id; selF2F.setAttribute( 'onchange', "prepForAcpohe('&tbl=courses&id=" + obj.id + "&face_to_face=' + encodeURIComponent(this.value), 'editCourse', 'inv/cortex.php');" ); var optYesF2F = document.createElement('option'); optYesF2F.value = 'yes'; optYesF2F.text = 'yes'; var optNoF2F = document.createElement('option'); optNoF2F.value = 'no'; optNoF2F.text = 'no'; selF2F.appendChild(optYesF2F); selF2F.appendChild(optNoF2F); if (obj.face_to_face === 'no') { optNoF2F.selected = true; } else { optYesF2F.selected = true; } td5.appendChild(selF2F); tr.appendChild(td5); // --- Online --- var td6 = document.createElement('td'); td6.style.width = '80px'; td6.style.paddingRight = '10px'; var selOnline = document.createElement('select'); selOnline.className = 'kom_login tdVisuals'; selOnline.style.height = '40px'; selOnline.style.width = '100%'; selOnline.style.margin = '0'; selOnline.id = 'online' + obj.id; selOnline.setAttribute( 'onchange', "prepForAcpohe('&tbl=courses&id=" + obj.id + "&online=' + encodeURIComponent(this.value), 'editCourse', 'inv/cortex.php');" ); var optYesOn = document.createElement('option'); optYesOn.value = 'yes'; optYesOn.text = 'yes'; var optNoOn = document.createElement('option'); optNoOn.value = 'no'; optNoOn.text = 'no'; selOnline.appendChild(optYesOn); selOnline.appendChild(optNoOn); if (obj.online === 'no') { optNoOn.selected = true; } else { optYesOn.selected = true; } td6.appendChild(selOnline); tr.appendChild(td6); // --- Delete --- var td7 = document.createElement('td'); td7.style.textAlign = 'right'; td7.style.width = '80px'; td7.style.paddingRight = '0'; var delBtn = document.createElement('button'); delBtn.id = 'delCourseBtn' + obj.id; delBtn.type = 'button'; delBtn.className = 'actionButton ani150'; delBtn.innerHTML = 'Delete'; delBtn.setAttribute( 'onclick', "prepForAcpohe('&id=" + obj.id + "&tbl=courses', 'delCourse', 'inv/cortex.php');" ); td7.appendChild(delBtn); tr.appendChild(td7); var rows = tbl.getElementsByTagName('tr'); // last rows are: spacer row + add-new row -> insert before spacer var insertIndex = rows.length - 2; tbl.insertBefore(tr, rows[insertIndex]); // Re-zebra rows refreshRowColors(); // Clear addcourse inputs var elems = document.getElementsByClassName('addcourse'); for (var i = 0; i < elems.length; i++) { var el = elems[i]; var tag = el.tagName.toLowerCase(); if (tag === 'select') { for (var j = 0; j < el.options.length; j++) { if (el.options[j].value === 'no') { el.selectedIndex = j; } } } else { el.value = ''; } } } else if(callbackId === 'addUser'){ console.log(); prepForAcpohe('&uid=' + obj.id + '&usrName=' + obj.first_name + '&usrEmail=' + obj.email, 'addyUsare', 'test.php', '', 'a'); var tbl = document.getElementById('usersTbl').getElementsByTagName('tbody')[0]; var tr = document.createElement('tr'); tr.id = 'user' + obj.id; tr.className = 'trHover'; var td1 = document.createElement('td'); var input1 = document.createElement('input'); input1.className = 'kom_login tdVisuals'; input1.style.height = '40px'; input1.style.width = '100%'; input1.id = 'first_name'; input1.type = 'text'; input1.value = obj.first_name; input1.setAttribute('onchange', "prepForAcpohe('&tbl=account&id=" + obj.id + "&first_name=' + encodeURIComponent(this.value), 'editUser', 'inv/cortex.php');"); td1.appendChild(input1); tr.appendChild(td1); var td2 = document.createElement('td'); var input2 = document.createElement('input'); input2.className = 'kom_login tdVisuals'; input2.style.height = '40px'; input2.style.width = '100%'; input2.id = 'last_name'; input2.type = 'text'; input2.value = obj.last_name; input2.setAttribute('onchange', "prepForAcpohe('&tbl=account&id=" + obj.id + "&last_name=' + encodeURIComponent(this.value), 'editUser', 'inv/cortex.php');"); td2.appendChild(input2); tr.appendChild(td2); var td3 = document.createElement('td'); var input3 = document.createElement('input'); input3.className = 'kom_login tdVisuals'; input3.style.height = '40px'; input3.style.width = '100%'; input3.id = 'email'; input3.type = 'text'; input3.value = obj.email; input3.setAttribute('onchange', "prepForAcpohe('&tbl=account&id=" + obj.id + "&email=' + encodeURIComponent(this.value), 'editUser', 'inv/cortex.php');"); td3.appendChild(input3); tr.appendChild(td3); var td4 = document.createElement('td'); td4.style.padding = '0px 10px 0px 0px'; var select = document.createElement('select'); select.className = 'kom_login tdVisuals'; select.style.height = '40px'; select.style.width = '100%'; select.style.margin = '0px'; select.id = 'access_level' + obj.id; select.setAttribute('onchange', "prepForAcpohe('&tbl=account&id=" + obj.id + "&access_level=' + encodeURIComponent(this.value), 'editUser', 'inv/cortex.php');"); var optAdmin = document.createElement('option'); optAdmin.value = 'admin'; optAdmin.text = 'Admin'; select.appendChild(optAdmin); var optMember = document.createElement('option'); optMember.value = 'member'; optMember.text = 'Member'; select.appendChild(optMember); if (obj.access_level == 'member') { optMember.selected = true; } else if (obj.access_level == 'admin') { optAdmin.selected = true; } td4.appendChild(select); tr.appendChild(td4); var td5 = document.createElement('td'); td5.className = 'courseCell'; var divNone = document.createElement('div'); divNone.className = 'kom_login tdVisuals'; divNone.style.height = '40px'; divNone.style.padding = '10px 0px'; divNone.innerHTML = ''; td5.appendChild(divNone); tr.appendChild(td5); var td6 = document.createElement('td'); td6.style.textAlign = 'right'; td6.style.paddingRight = '0px'; var delBtn = document.createElement('button'); delBtn.id = 'delBtn' + obj.id; delBtn.type = 'button'; delBtn.className = 'actionButton ani150'; delBtn.innerHTML = 'Delete'; delBtn.setAttribute('onclick', "prepForAcpohe('&id=" + obj.id + "&tbl=account','delUser','inv/cortex.php');"); td6.appendChild(delBtn); tr.appendChild(td6); // Insert before the add row (last row) var rows = tbl.getElementsByTagName('tr'); var insertIndex = rows.length - 2; tbl.insertBefore(tr, rows[insertIndex]); refreshRowColors(); var elems = document.getElementsByClassName('adduser'); for (var i = 0; i < elems.length; i = i + 1) { var el = elems[i]; var tag = el.tagName.toLowerCase(); if (tag == 'select') { for (var j = 0; j < el.options.length; j = j + 1) { if (el.options[j].value == 'member') { el.selectedIndex = j; } } } else { el.value = ''; } } } else if(callbackId === 'addFile'){ var tr = document.createElement('tr'); tr.id = 'file' + obj.id; tr.className = 'trHover trVisualsOdd'; // ----- Display Name ----- var tdName = document.createElement('td'); var taName = document.createElement('textarea'); taName.className = 'kom_login tdVisuals'; taName.style.height = '140px'; taName.style.width = '100%'; taName.style.resize = 'none'; taName.id = 'displayName'; taName.textContent = 'Please select a display name'; taName.setAttribute( 'onchange', "prepForAcpohe('&tbl=files&id=" + obj.id + "&displayName=' + encodeURIComponent(this.value), 'editFiles', 'inv/cortex.php');" ); tdName.appendChild(taName); tr.appendChild(tdName); // ----- Tags ----- var tdTags = document.createElement('td'); var taTags = document.createElement('textarea'); taTags.className = 'kom_login tdVisuals'; taTags.style.height = '140px'; taTags.style.width = '140px'; taTags.style.resize = 'none'; taTags.id = 'tags'; taTags.setAttribute( 'onchange', "prepForAcpohe('&tbl=files&id=" + obj.id + "&tags=' + encodeURIComponent(this.value), 'editFiles', 'inv/cortex.php');" ); tdTags.appendChild(taTags); tr.appendChild(tdTags); // ----- Locked (checkbox) ----- var tdLock = document.createElement('td'); tdLock.style.width = '165px'; tdLock.style.textAlign = 'center'; var labelLock = document.createElement('label'); labelLock.className = 'switch'; var chkLock = document.createElement('input'); chkLock.id = 'fileLocked' + obj.id; chkLock.className = 'notifSetting'; chkLock.type = 'checkbox'; chkLock.checked = true; chkLock.value = 'on'; chkLock.setAttribute( 'onchange', "chkBoxToggleOO(this); prepForAcpohe('&tbl=files&id=" + obj.id + "&locked=' + encodeURIComponent(this.value), 'editFiles', 'inv/cortex.php');" ); var spanLock = document.createElement('span'); spanLock.className = 'sliderRound'; labelLock.appendChild(chkLock); labelLock.appendChild(spanLock); tdLock.appendChild(labelLock); tr.appendChild(tdLock); // ----- File Selector ----- var tdFile = document.createElement('td'); tdFile.style.width = '200px'; var divFile = document.createElement('div'); divFile.className = 'kom_login tdVisuals'; divFile.style.height = '140px'; divFile.style.width = '200px'; divFile.style.cursor = 'pointer'; divFile.style.wordWrap = 'break-word'; divFile.id = 'filetype' + obj.id; divFile.textContent = 'Please select a file'; if(obj.folderPath.indexOf('library') !== -1){ divFile.setAttribute( 'onclick', "showImageModal('adminLibraryFile', '" + obj.id + "', '" + obj.folderPath + "');" ); } else { divFile.setAttribute( 'onclick', "showImageModal('adminResourceFile', '" + obj.id + "', '" + obj.folderPath + "');" ); } tdFile.appendChild(divFile); tr.appendChild(tdFile); // ----- Delete Button ----- var tdDel = document.createElement('td'); tdDel.style.textAlign = 'right'; tdDel.style.width = '165px'; var btnDel = document.createElement('button'); btnDel.id = 'fileDelBtn' + obj.id; btnDel.type = 'button'; btnDel.className = 'actionButton ani150'; btnDel.textContent = 'Delete'; btnDel.setAttribute( 'onclick', "prepForAcpohe('&id=" + obj.id + "&tbl=files&filePath=' + encodeURIComponent('" + obj.filePath + "' + document.getElementById('fileView' + " + obj.id + ").children[1].innerHTML + '/'),'delFiles','inv/cortex.php');" ); tdDel.appendChild(btnDel); tr.appendChild(tdDel); // ----- Append the row ----- var table = document.getElementById('filesTbl'); var tbody = table.tBodies[0] || table; var rows = tbody.getElementsByTagName('tr'); var beforeNode = null; if(rows.length >= 2){ beforeNode = rows[rows.length - 2]; } tbody.insertBefore(tr, beforeNode); refreshTblColors('trHover'); var filesTab = document.getElementById('filesTab'); // Create the anchor var link = document.createElement('a'); link.href = 'images/please select a file2.png'; link.id = 'fileView' + obj.id; link.className = 'folderBlock'; link.setAttribute('download', ''); // Create the inner div (the image preview) var divIcon = document.createElement('div'); divIcon.className = 'ani folderIcon'; divIcon.style.backgroundImage = 'url("images/please select a file2.png")'; divIcon.style.opacity = '0.4'; divIcon.style.backgroundSize = '100%'; divIcon.onmouseover = function() { this.style.backgroundSize = '125%'; }; divIcon.onmouseout = function() { this.style.backgroundSize = '100%'; }; // Create the span (the label) var span = document.createElement('span'); span.style.color = '#000'; span.style.fontSize = '95%'; span.style.textAlign = 'center'; span.textContent = 'Please select a display name'; // Build the structure link.appendChild(divIcon); link.appendChild(span); filesTab.appendChild(link); } else if(callbackId === 'addFolder'){ const a = document.createElement('a'); a.setAttribute('href', 'admin.php?bit=guidence&parId=' + obj.id); a.setAttribute('id', 'fileView' + obj.id); a.setAttribute('class', 'folderBlock'); // ----- Folder icon ----- const iconDiv = document.createElement('div'); iconDiv.setAttribute('class', 'ani folderIcon'); iconDiv.setAttribute('onmouseover', "this.style.backgroundSize = '125%';"); iconDiv.setAttribute('onmouseout', "this.style.backgroundSize = '100%';"); iconDiv.setAttribute('style', 'background-size: 100%;'); a.appendChild(iconDiv); // ----- Folder name ----- const span = document.createElement('span'); span.setAttribute('style', 'color:#000; font-size:95%; text-align:center;'); span.textContent = obj.name; a.appendChild(span); // ----- Append it ----- const container = document.getElementById('filesTab'); if(container.children[0].innerHTML == 'No files or folders found in this location.'){ container.children[0].remove(); } container.appendChild(a); //do the thingy for the table too const tr = document.createElement('tr'); tr.id = 'folder' + obj.id; tr.className = 'trHover'; // ----- First ----- const td1 = document.createElement('td'); const input1 = document.createElement('input'); input1.className = 'kom_login tdVisuals'; input1.id = 'name'; input1.type = 'text'; input1.value = obj.name; input1.setAttribute('onchange', "prepForAcpohe('&tbl=folders&id=" + obj.id + "&name=' + encodeURIComponent(this.value) + '&folderPath=' + encodeURIComponent('" + obj.folderPath + "' + document.getElementById('fileView' + " + obj.id + ").children[1].innerHTML + '/'), 'editFolder', 'inv/cortex.php');"); td1.appendChild(input1); tr.appendChild(td1); // ----- Second (checkbox) ----- const td2 = document.createElement('td'); td2.style.width = '165px'; td2.style.textAlign = 'center'; const label = document.createElement('label'); label.className = 'switch'; const checkbox = document.createElement('input'); checkbox.id = 'locked' + obj.id; checkbox.className = 'notifSetting'; checkbox.type = 'checkbox'; checkbox.value = 'on'; if (obj.locked === true) { checkbox.checked = true; } checkbox.setAttribute('onchange', "chkBoxToggleOO(this); prepForAcpohe('&tbl=folders&id=" + obj.id + "&locked=' + encodeURIComponent(this.value), 'editFolder', 'inv/cortex.php');"); const spanner = document.createElement('span'); spanner.className = 'sliderRound'; label.appendChild(checkbox); label.appendChild(spanner); td2.appendChild(label); tr.appendChild(td2); // ----- Third (button) ----- const td3 = document.createElement('td'); td3.style.textAlign = 'right'; td3.style.width = '165px'; const button = document.createElement('button'); button.id = 'delBtn' + obj.id; button.type = 'button'; button.className = 'actionButton ani150'; button.textContent = 'Delete'; button.setAttribute('onclick', "prepForAcpohe('&id=" + obj.id + "&folderPath=' + encodeURIComponent('" + obj.folderPath + "' + document.getElementById('fileView' + " + obj.id + ").children[1].innerHTML + '/') + '&tbl=folders', 'delFolders', 'inv/cortex.php');"); td3.appendChild(button); tr.appendChild(td3); // ----- Append the row ----- const table = document.getElementById('foldersTbl'); table.appendChild(tr); const tbody = table.getElementsByTagName('tbody')[0]; const addRow = document.querySelector('.addFolder').closest('tr'); tbody.insertBefore(tr, addRow.previousElementSibling); // Refresh the visuals refreshTblColors('tdVisuals'); // Clear all the input fields in the addFolder row var addFields = document.getElementsByClassName('addFolder'); console.log(addFields); for (var i = 0; i < addFields.length; i++) { addFields[i].value = ''; } } else if(callbackId === 'addtoolkits'){ var tr = document.createElement('tr'); tr.id = 'toolkits' + obj.id; tr.className = 'trHover'; // NAME var tdName = document.createElement('td'); tdName.style.width = '200px'; var taName = document.createElement('textarea'); taName.className = 'kom_login tdVisuals'; taName.style.cssText = 'height:140px;width:200px;resize:none;'; taName.id = 'name'; taName.value = obj.name; taName.setAttribute('onchange', "prepForAcpohe('&tbl=toolkits&id=" + obj.id + "&name=' + encodeURIComponent(this.value), 'editToolkits', 'inv/cortex.php');" ); tdName.appendChild(taName); tr.appendChild(tdName); // DESCRIPTION var tdDesc = document.createElement('td'); var taDesc = document.createElement('textarea'); taDesc.className = 'kom_login tdVisuals'; taDesc.style.cssText = 'height:140px;resize:none;'; taDesc.id = 'description'; taDesc.value = obj.description; taDesc.setAttribute('onchange', "prepForAcpohe('&tbl=toolkits&id=" + obj.id + "&description=' + encodeURIComponent(this.value), 'editToolkits', 'inv/cortex.php');" ); tdDesc.appendChild(taDesc); tr.appendChild(tdDesc); // IMAGE var tdImg = document.createElement('td'); tdImg.style.width = '140px'; var img = document.createElement('img'); img.src = obj.imageSrc; img.className = 'kom_login tdVisuals'; img.style.cssText = 'width:140px;'; img.id = 'imageType' + obj.id; img.setAttribute('onclick', "showImageModal('adminToolkit', '" + obj.id + "');"); tdImg.appendChild(img); tr.appendChild(tdImg); // FILE var tdFile = document.createElement('td'); tdFile.style.width = '200px'; var divFile = document.createElement('div'); divFile.className = 'kom_login tdVisuals'; divFile.style.cssText = 'height:140px;width:200px;cursor:pointer;word-wrap:break-word;'; divFile.id = 'filetype' + obj.id; divFile.textContent = obj.filePath; divFile.setAttribute('onclick', "showImageModal('adminToolkitFile', '" + obj.id + "');"); tdFile.appendChild(divFile); tr.appendChild(tdFile); // STATUS (checkbox) var tdStatus = document.createElement('td'); tdStatus.style.width = '75px'; var label = document.createElement('label'); label.className = 'switch'; var input = document.createElement('input'); input.id = 'status' + obj.id; input.className = 'notifSetting'; input.type = 'checkbox'; input.value = '1'; if (status === '1' || status === true) input.checked = true; input.setAttribute('onchange', "chkBoxToggleIO(this); prepForAcpohe('&tbl=toolkits&id=" + obj.id + "&status=' + encodeURIComponent(this.value), 'editToolkits', 'inv/cortex.php');" ); var span = document.createElement('span'); span.className = 'sliderRound'; label.appendChild(input); label.appendChild(span); tdStatus.appendChild(label); tr.appendChild(tdStatus); // DELETE BUTTON var tdDel = document.createElement('td'); tdDel.style.cssText = 'text-align:right;width:50px;padding-right:10px;'; var btn = document.createElement('button'); btn.id = 'delBtn' + obj.id; btn.type = 'button'; btn.className = 'actionButton ani150'; btn.textContent = 'Delete'; btn.setAttribute('onclick', "prepForAcpohe('&id=" + obj.id + "&tbl=toolkits','deltoolkits','inv/cortex.php');" ); tdDel.appendChild(btn); tr.appendChild(tdDel); // Add to table var tbody = document.getElementById('toolkitsTbl').getElementsByTagName('tbody')[0]; tbody.insertBefore(tr, tbody.rows[tbody.rows.length - 2]); var elems = document.getElementsByClassName('clearAfterInsert'); for(var i = 0; i < elems.length; i++){ elems[i].value = ''; } refreshRowColors(); } else if(callbackId === 'addvideos'){ // expected obj: { id, title, description, imageType, filePath, status } var tbl = document.getElementById('videosTbl'); if(!tbl){ return; } var tbody = tbl.getElementsByTagName('tbody')[0] || tbl; var tr = document.createElement('tr'); tr.id = 'videos' + obj.id; tr.className = 'trHover'; // --- Title (textarea) --- var tdTitle = document.createElement('td'); tdTitle.style.width = '200px'; var taTitle = document.createElement('textarea'); taTitle.className = 'kom_login tdVisuals'; taTitle.style.height = '140px'; taTitle.style.width = '200px'; taTitle.style.resize = 'none'; taTitle.id = 'title'; taTitle.value = obj.title || ''; taTitle.setAttribute('onchange', "prepForAcpohe('&tbl=videos&id=" + obj.id + "&title=' + encodeURIComponent(this.value), 'editVideos', 'inv/cortex.php');"); tdTitle.appendChild(taTitle); tr.appendChild(tdTitle); // --- Description (textarea) --- var tdDesc = document.createElement('td'); var taDesc = document.createElement('textarea'); taDesc.className = 'kom_login tdVisuals'; taDesc.style.height = '140px'; taDesc.style.resize = 'none'; taDesc.id = 'description'; taDesc.value = obj.description || ''; taDesc.setAttribute('onchange', "prepForAcpohe('&tbl=videos&id=" + obj.id + "&description=' + encodeURIComponent(this.value), 'editVideos', 'inv/cortex.php');"); tdDesc.appendChild(taDesc); tr.appendChild(tdDesc); // --- Image (preview) --- var tdImg = document.createElement('td'); tdImg.style.width = '140px'; var img = document.createElement('img'); img.src = obj.imageType || ''; img.className = 'kom_login tdVisuals'; img.style.width = '140px'; img.id = 'imageType' + obj.id; img.setAttribute('onclick', "showImageModal('adminVideos', '" + obj.id + "');"); tdImg.appendChild(img); tr.appendChild(tdImg); // --- File path (click to choose file) --- var tdFile = document.createElement('td'); tdFile.style.width = '200px'; var divFile = document.createElement('div'); divFile.className = 'kom_login tdVisuals'; divFile.style.height = '140px'; divFile.style.width = '200px'; divFile.style.cursor = 'pointer'; divFile.style.wordWrap = 'break-word'; divFile.id = 'filePath' + obj.id; divFile.textContent = obj.filePath || ''; divFile.setAttribute('onclick', "showImageModal('adminVideosFile', '" + obj.id + "');"); tdFile.appendChild(divFile); tr.appendChild(tdFile); // --- Status (checkbox) --- var tdStatus = document.createElement('td'); tdStatus.style.width = '75px'; var label = document.createElement('label'); label.className = 'switch'; var input = document.createElement('input'); input.id = 'status' + obj.id; input.className = 'notifSetting'; input.type = 'checkbox'; input.value = '1'; if (obj.status === '1' || obj.status === 1 || obj.status === true) { input.checked = true; } input.setAttribute('onchange', "chkBoxToggleIO(this); prepForAcpohe('&tbl=videos&id=" + obj.id + "&status=' + encodeURIComponent(this.value), 'editVideos', 'inv/cortex.php');"); var span = document.createElement('span'); span.className = 'sliderRound'; label.appendChild(input); label.appendChild(span); tdStatus.appendChild(label); tr.appendChild(tdStatus); // --- Delete button --- var tdDel = document.createElement('td'); tdDel.style.textAlign = 'right'; tdDel.style.width = '50px'; tdDel.style.paddingRight = '10px'; var btn = document.createElement('button'); btn.id = 'delBtn' + obj.id; btn.type = 'button'; btn.className = 'actionButton ani150'; btn.textContent = 'Delete'; btn.setAttribute('onclick', "prepForAcpohe('&id=" + obj.id + "&tbl=videos','delvideos','inv/cortex.php');"); tdDel.appendChild(btn); tr.appendChild(tdDel); // --- Insert before final input row if present (keeps input/spacer at bottom) --- var rows = tbody.getElementsByClassName('trHover'); if (tbody.rows && tbody.rows.length >= 2) { tbody.insertBefore(tr, tbody.rows[tbody.rows.length - 1]); // before the last row (usually the add/input row) } else if (rows.length >= 1) { tbody.insertBefore(tr, rows[rows.length - 1].nextSibling); } else { tbody.appendChild(tr); } var elems = document.getElementsByClassName('clearAfterInsert'); for(var i = 0; i < elems.length; i++){ elems[i].value = ''; } refreshRowColors(); } else if(callbackId === 'addBanner'){ var newId = obj.id; var defaultName = 'New banner'; var defaultLink = ''; var defaultImg = 'images/bannerPlaceholder.png'; var infirm = document.getElementById('infirm'); var existing = document.getElementsByClassName('bannerTbl'); var newTblIdx = existing.length; // unique DOM id suffix // ----- table ----- var tbl = document.createElement('table'); tbl.className = 'bannerTbl'; tbl.id = 'bannerTbl' + newTblIdx; var tbody = document.createElement('tbody'); tbl.appendChild(tbody); // ----- row ----- var tr = document.createElement('tr'); tr.className = 'zebraMe'; tr.style.border = '1px solid #ddd'; // ----- left cell (arrows) ----- var tdLeft = document.createElement('td'); tdLeft.setAttribute('width', '10%'); tdLeft.style.textAlign = 'center'; // up svg var svgUp = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); svgUp.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); svgUp.setAttribute('viewBox', '0 0 320 512'); svgUp.setAttribute('width', '50'); var pathUp = document.createElementNS('http://www.w3.org/2000/svg', 'path'); pathUp.setAttribute('class', 'bannerMove'); pathUp.setAttribute('d', 'M279 224H41c-21.4 0-32.1-25.9-17-41L143 64c9.4-9.4 24.6-9.4 33.9 0l119 119c15.2 15.1 4.5 41-16.9 41z'); pathUp.setAttribute('onclick', "bannerMoveUp('" + tbl.id + "');"); pathUp.id = 'moveUp' + newTblIdx; svgUp.appendChild(pathUp); // br spacing var br1 = document.createElement('br'); var br2 = document.createElement('br'); var br3 = document.createElement('br'); var br4 = document.createElement('br'); // down svg var svgDown = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); svgDown.setAttribute('fill', '#bbb'); svgDown.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); svgDown.setAttribute('viewBox', '0 0 320 512'); svgDown.setAttribute('width', '50'); var pathDown = document.createElementNS('http://www.w3.org/2000/svg', 'path'); pathDown.setAttribute('class', 'bannerMove'); pathDown.setAttribute('d', 'M41 288h238c21.4 0 32.1 25.9 17 41L177 448c-9.4 9.4-24.6 9.4-33.9 0L24 329c-15.1-15.1-4.4-41 17-41z'); pathDown.setAttribute('onclick', "bannerMoveDown('" + tbl.id + "');"); pathDown.id = 'moveDown' + newTblIdx; svgDown.appendChild(pathDown); tdLeft.appendChild(svgUp); tdLeft.appendChild(br1); tdLeft.appendChild(br2); tdLeft.appendChild(br3); tdLeft.appendChild(br4); tdLeft.appendChild(svgDown); // ----- right cell (content) ----- var tdRight = document.createElement('td'); tdRight.setAttribute('width', '90%'); var block = document.createElement('div'); block.id = 'bannerBlock'; block.style.padding = '15px'; var img = document.createElement('img'); img.src = defaultImg; img.id = 'bannerImg' + newId; // DB id in element id img.style.width = 'calc(100%)'; img.setAttribute('onclick', "showImageModal('bannerImg', '" + newId + "');"); var brImg = document.createElement('br'); var brImg2 = document.createElement('br'); // Title field var wrapTitle = document.createElement('div'); wrapTitle.style.display = 'inline-block'; wrapTitle.style.width = 'calc(40%)'; var labelTitle = document.createElement('label'); labelTitle.appendChild(document.createTextNode('Title:')); var inputTitle = document.createElement('input'); inputTitle.type = 'text'; inputTitle.id = 'bannerText' + newId; inputTitle.style.width = 'calc(100%)'; inputTitle.value = defaultName; inputTitle.setAttribute('onchange', "prepForAcpohe('&tbl=banners&id=" + newId + "&name=' + encodeURIComponent(this.value), 'editBanner', 'inv/cortex.php');"); // Link field var wrapLink = document.createElement('div'); wrapLink.style.display = 'inline-block'; wrapLink.style.width = 'calc(40%)'; var labelLink = document.createElement('label'); labelLink.appendChild(document.createTextNode('Link to:')); var inputLink = document.createElement('input'); inputLink.type = 'text'; inputLink.id = 'bannerLink' + newId; inputLink.style.width = 'calc(100%)'; inputLink.value = defaultLink; inputLink.setAttribute('onchange', "prepForAcpohe('&tbl=banners&id=" + newId + "&link=' + encodeURIComponent(this.value), 'editBanner', 'inv/cortex.php');"); // Checkbox var wrapChk = document.createElement('div'); wrapChk.style.display = 'inline-block'; wrapChk.style.width = 'calc(10% - 10px)'; var labelChk = document.createElement('label'); labelChk.appendChild(document.createTextNode('Open in new tab:')); var labelSwitch = document.createElement('label'); labelSwitch.className = 'switch'; var inputChk = document.createElement('input'); inputChk.id = 'webinarchat'; inputChk.className = 'notifSetting'; inputChk.type = 'checkbox'; inputChk.setAttribute('onchange', "chkBoxToggle(this); prepForAcpohe('&tbl=banners&id=" + newId + "&open_new_tab=' + encodeURIComponent(this.value), 'editBanner', 'inv/cortex.php');"); inputChk.value = 'on'; inputChk.checked = true; var spanRound = document.createElement('span'); spanRound.className = 'sliderRound'; labelSwitch.appendChild(inputChk); labelSwitch.appendChild(spanRound); // Delete button var wrapBtn = document.createElement('div'); wrapBtn.style.display = 'inline-block'; wrapBtn.style.width = 'calc(10% - 10px)'; var btnDel = document.createElement('button'); btnDel.id = 'delBtn' + newTblIdx; btnDel.className = 'delEvent btn btn-danger btn-sm'; btnDel.style.float = 'right'; btnDel.setAttribute('onclick', "poofBanner('" + tbl.id + "');"); btnDel.appendChild(document.createTextNode('Delete')); // assemble right side wrapTitle.appendChild(labelTitle); wrapTitle.appendChild(inputTitle); wrapLink.appendChild(labelLink); wrapLink.appendChild(inputLink); wrapChk.appendChild(labelChk); wrapChk.appendChild(labelSwitch); wrapBtn.appendChild(btnDel); block.appendChild(img); block.appendChild(brImg); block.appendChild(brImg2); block.appendChild(wrapTitle); block.appendChild(wrapLink); block.appendChild(wrapChk); block.appendChild(wrapBtn); tdRight.appendChild(block); // assemble row/table tr.appendChild(tdLeft); tr.appendChild(tdRight); tbody.appendChild(tr); // prepend to top of list if (infirm.firstChild) { infirm.insertBefore(tbl, infirm.firstChild); } else { infirm.appendChild(tbl); } // re-stripe and persist new order refreshTblColors('zebraMe'); saveBannerOrder(); } else if(callbackId === 'addAuthor'){ var nameVal = document.getElementById('name').value; var presVal = document.getElementById('presentation').value; var newId = obj.id; // ---------- CREATE ELEMENTS ---------- var tr = document.createElement('tr'); tr.id = 'author' + newId; tr.className = 'trHover'; // --- Name cell --- var tdName = document.createElement('td'); var inputName = document.createElement('input'); inputName.className = 'kom_login tdVisuals'; inputName.id = 'name'; inputName.type = 'text'; inputName.value = obj.name; inputName.setAttribute( 'onchange', "prepForAcpohe('&tbl=author&id=" + newId + "&name=' + encodeURIComponent(this.value), 'editAuthor', 'inv/cortex.php');" ); tdName.appendChild(inputName); // --- Presentation cell --- var tdPres = document.createElement('td'); var inputPres = document.createElement('input'); inputPres.className = 'kom_login tdVisuals'; inputPres.id = 'presentation'; inputPres.type = 'text'; inputPres.value = obj.title; inputPres.setAttribute( 'onchange', "prepForAcpohe('&tbl=author&id=" + newId + "&presentation=' + encodeURIComponent(this.value), 'editAuthor', 'inv/cortex.php');" ); tdPres.appendChild(inputPres); // --- Actions cell --- var tdAct = document.createElement('td'); tdAct.style.textAlign = 'right'; var btnDel = document.createElement('button'); btnDel.id = 'delBtn' + newId; btnDel.type = 'button'; btnDel.className = 'actionButton ani150'; btnDel.textContent = 'Delete'; btnDel.setAttribute( 'onclick', "prepForAcpohe('&id=" + newId + "&tbl=author', 'delAuthor', 'inv/cortex.php');" ); tdAct.appendChild(btnDel); // ---------- ASSEMBLE ROW ---------- tr.appendChild(tdName); tr.appendChild(tdPres); tr.appendChild(tdAct); // ---------- INSERT INTO TABLE ---------- var table = document.getElementById('authorTbl'); var tbody = table.getElementsByTagName('tbody')[0]; var addRow = document.querySelector('.addAuthor').closest('tr'); tbody.insertBefore(tr, addRow.previousElementSibling); // ---------- CLEAR INPUT FIELDS ---------- var addFields = document.getElementsByClassName('addAuthor'); for (var i = 0; i < addFields.length; i++) { addFields[i].value = ''; } refreshRowColors(); } } } if(callbackId == 'editEmail'){ document.getElementById('cortexModal').innerHTML = msg; changeCSS(document.getElementById('cortexModal'), 'hiddenModal', 'remove'); changeCSS(document.getElementById('cortexModal'), 'modalCorrect', 'add'); } if(callbackId == 'sendReminderEmail'){ changeCSS(document.getElementById('alert'), 'hidden', 'remove'); if(msg == 'email sent'){ changeCSS(document.getElementById('step_one'), 'hidden', 'add'); changeCSS(document.getElementById('step_two'), 'hidden', 'remove'); } else { document.getElementById('alert').style.display = ''; } } if(callbackId == 'confirmResetCode'){ changeCSS(document.getElementById('conf_alert'), 'hidden', 'remove'); if(msg == 'gokaku'){ changeCSS(document.getElementById('step_two'), 'hidden', 'add'); changeCSS(document.getElementById('step_three'), 'hidden', 'remove'); } else { document.getElementById('conf_alert').style.display = ''; } } if(callbackId == 'setNewPw'){ changeCSS(document.getElementById('step_three'), 'hidden', 'add'); changeCSS(document.getElementById('step_four'), 'hidden', 'remove'); setTimeout(goToFrontPage, 3000); } } function goToFrontPage() { window.location.replace('https://acpohelms.co.uk/login.php'); } function chkBoxToggleIO(elem){ if(elem.checked == true){ elem.value = '1'; } else { elem.value = '0'; } } function chkBoxToggle(elem){ if(elem.checked == true){ elem.value = 'Yes'; } else { elem.value = 'No'; } } function chkBoxToggleOO(elem){ if(elem.checked == true){ elem.value = 'on'; } else { elem.value = 'off'; } } function filterTableProper(elem){ var rowLen = elem.rows.length; for(var i = 2; i < rowLen; i++){ var chkBoxId = 'user_id_check_' + elem.rows[i].cells[0].innerHTML; var UnlChkBox = document.getElementById(chkBoxId); var hideUnlocked = document.getElementById('filter_unlocked').value; elem.rows[i].removeAttribute('style'); if(UnlChkBox.checked == false && hideUnlocked == 'on'){ elem.rows[i].style.display = 'none'; } } } function toggleCSS(elem, CSSclass){ if(elem.classList.contains(CSSclass) == true){ elem.classList.remove(CSSclass); } else { elem.classList.add(CSSclass); } } function btnLoad(clsList){ if(clsList.contains('btnLoading') == true){ setTimeout(function(){ clsList.remove('btnLoading'); }, 250, clsList); } else { clsList.add('btnLoading'); } } 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 alreadyExistAlert(){ document.getElementById('alreadyExistAlert').style.display = 'none'; location.replace('admin_thingy.php?bit=user'); } function prepCortexParams(targClass){ var str = ''; var elems = document.getElementsByClassName(targClass); for(var i = 0; i < elems.length; i++){ str = str + '&' + elems[i].id + '=' + encodeURIComponent(elems[i].value); } return str; } function __hideNotificationModalOnTop() { var d = window.document; var m = d.getElementById('notificationModal'); if (m && m.classList.contains('hiddenModal') === false) { m.classList.add('hiddenModal'); window.modalNotification = ''; } } function showModal(txt, status) { if (window !== window.top) { window.top.showModal(txt, status); return; } var modal = document.getElementById('notificationModal'); var modalMsg = document.getElementById('modalMsg'); modalMsg.innerHTML = txt; if (status === 'ok') { modal.style.background = 'linear-gradient(315deg, #0d264e 0%, #081f45 100%)'; modal.children[0].children[1].innerHTML = 'Notification'; } else { modal.style.background = 'linear-gradient(315deg, #711313 0%, #450808 100%)'; modal.children[0].children[1].innerHTML = 'Error!'; } if (window.modalNotification === 'wait') { window.clearTimeout(window.confModal); } if (modal.classList.contains('hiddenModal') === true) { modal.classList.remove('hiddenModal'); } window.confModal = window.setTimeout(window.__hideNotificationModalOnTop, 3000); window.modalNotification = 'wait'; } function oldshowModal(txt, status){ if (window.self !== window.top) { var modal = window.parent.document.getElementById('notificationModal'); var modalMsg = window.parent.document.getElementById('modalMsg'); window.parent.modalNotification = ''; } else { var modal = document.getElementById('notificationModal'); var modalMsg = document.getElementById('modalMsg'); modalNotification = ''; } modalMsg.innerHTML = txt; if(status == 'ok'){ modal.style.background = 'linear-gradient(315deg, #0d264e 0%, #081f45 100%)'; modal.children[0].children[1].innerHTML = 'Notification'; } else { modal.style.background = 'linear-gradient(315deg, #711313 0%, #450808 100%)'; modal.children[0].children[1].innerHTML = 'Error!'; } if (window.self !== window.top) { if(window.parent.modalNotification == 'wait'){ clearTimeout(window.parent.confModal); } } else { if(modalNotification == 'wait'){ clearTimeout(confModal); } } if(modal.classList.contains('hiddenModal') === true){ modal.classList.remove('hiddenModal'); } confModal = setTimeout(function() { if(modal.classList.contains('hiddenModal') === false){ modal.classList.add('hiddenModal'); modalNotification = ''; } }, 3000); modalNotification = 'wait'; } function refreshTblColors(classId) { var rows = document.getElementsByClassName(classId); for (var i = 0; i <= rows.length - 1; i++) { if(rows[i].classList.contains('trVisualsOdd')) { rows[i].classList.remove('trVisualsOdd'); } if(i % 2 === 1) { rows[i].classList.add('trVisualsOdd'); } } } function showImageModal(cb, id, folderPath){ if (!folderPath) { folderPath = ''; } if(cb == 'bannerImg'){ document.getElementById('custModal').style.width = 80 + '%'; document.getElementById('custModal').style.height = 80 + '%'; ifr = document.createElement('iframe'); ifr.id = 'custIframe'; ifr.name = 'custIframe'; ifr.setAttribute('frameborder', '0'); ifr.setAttribute('scrolling', 'no'); ifr.style.width = '100%'; ifr.style.height = '100%'; ifr.style.overflow = 'hidden'; document.getElementById('custModalContent').appendChild(ifr); document.getElementById('LoginmodalTitle').innerHTML = 'Banner images'; document.getElementById('custIframe').src = 'iframe_img.php?custModalCb='+cb+'&custModalId=' + id; } else if(cb == 'courseTerms'){ document.getElementById('custModal').style.width = 80 + '%'; document.getElementById('custModal').style.height = 80 + '%'; ifr = document.createElement('iframe'); ifr.id = 'custIframe'; ifr.name = 'custIframe'; ifr.setAttribute('frameborder', '0'); ifr.setAttribute('scrolling', 'yes'); ifr.style.width = '100%'; ifr.style.height = '100%'; ifr.style.overflow = 'hidden'; document.getElementById('custModalContent').appendChild(ifr); document.getElementById('LoginmodalTitle').innerHTML = 'Terms and Conditions of Use – Online Courses'; document.getElementById('custIframe').src = 'iframe_terms.php?frm='+cb+'&custModalId=' + id; } else if(cb == 'modAssign'){ document.getElementById('custModal').style.width = 80 + '%'; document.getElementById('custModal').style.height = 80 + '%'; ifr = document.createElement('iframe'); ifr.id = 'custIframe'; ifr.name = 'custIframe'; ifr.setAttribute('frameborder', '0'); ifr.setAttribute('scrolling', 'auto'); ifr.style.width = '100%'; ifr.style.height = '100%'; ifr.style.overflow = 'hidden'; document.getElementById('custModalContent').appendChild(ifr); document.getElementById('LoginmodalTitle').innerHTML = 'Assignment Questions'; document.getElementById('custIframe').src = 'iru.php#' + id; } else if(cb == 'adminToolkit'){ document.getElementById('custModal').style.width = 80 + '%'; document.getElementById('custModal').style.height = 80 + '%'; ifr = document.createElement('iframe'); ifr.id = 'custIframe'; ifr.name = 'custIframe'; ifr.setAttribute('frameborder', '0'); ifr.setAttribute('scrolling', 'no'); ifr.style.width = '100%'; ifr.style.height = '100%'; ifr.style.overflow = 'hidden'; document.getElementById('custModalContent').appendChild(ifr); document.getElementById('LoginmodalTitle').innerHTML = 'Toolkit images'; document.getElementById('custIframe').src = 'iframe_img.php?custModalCb='+cb+'&custModalId=' + id; } else if(cb == 'adminLibraryFile'){ document.getElementById('custModal').style.width = 80 + '%'; document.getElementById('custModal').style.height = 80 + '%'; ifr = document.createElement('iframe'); ifr.id = 'custIframe'; ifr.name = 'custIframe'; ifr.setAttribute('frameborder', '0'); ifr.setAttribute('scrolling', 'no'); ifr.style.width = '100%'; ifr.style.height = '100%'; ifr.style.overflow = 'hidden'; document.getElementById('custModalContent').appendChild(ifr); document.getElementById('LoginmodalTitle').innerHTML = 'Resource Library files'; document.getElementById('custIframe').src = 'iframe_files.php?custModalCb=adminResourceFile&custModalId=' + id + '&folderPath=' + folderPath; } else if(cb == 'courseFile'){ document.getElementById('custModal').style.width = 80 + '%'; document.getElementById('custModal').style.height = 80 + '%'; ifr = document.createElement('iframe'); ifr.id = 'custIframe'; ifr.name = 'custIframe'; ifr.setAttribute('frameborder', '0'); ifr.setAttribute('scrolling', 'no'); ifr.style.width = '100%'; ifr.style.height = '100%'; ifr.style.overflow = 'hidden'; document.getElementById('custModalContent').appendChild(ifr); document.getElementById('LoginmodalTitle').innerHTML = 'Module files'; document.getElementById('custIframe').src = 'iframe_files.php?custModalCb=adminCourseFile&custModalId=' + id + '&folderPath=' + folderPath; } else if(cb == 'assignReviewer'){ document.getElementById('custModal').style.width = 80 + '%'; document.getElementById('custModal').style.height = 80 + '%'; ifr = document.createElement('iframe'); ifr.id = 'custIframe'; ifr.name = 'custIframe'; ifr.setAttribute('frameborder', '0'); ifr.setAttribute('scrolling', 'no'); ifr.style.width = '100%'; ifr.style.height = '100%'; ifr.style.overflow = 'hidden'; document.getElementById('custModalContent').appendChild(ifr); document.getElementById('LoginmodalTitle').innerHTML = 'Assign marker'; document.getElementById('custIframe').src = 'iframe_marker.php?custModalCb=adminMarker&studentId=' + id + '&lmsId=' + folderPath; } else if(cb == 'adminResourceFile'){ document.getElementById('custModal').style.width = 80 + '%'; document.getElementById('custModal').style.height = 80 + '%'; ifr = document.createElement('iframe'); ifr.id = 'custIframe'; ifr.name = 'custIframe'; ifr.setAttribute('frameborder', '0'); ifr.setAttribute('scrolling', 'no'); ifr.style.width = '100%'; ifr.style.height = '100%'; ifr.style.overflow = 'hidden'; document.getElementById('custModalContent').appendChild(ifr); document.getElementById('LoginmodalTitle').innerHTML = 'ACPOHE Guidance Documents'; document.getElementById('custIframe').src = 'iframe_files.php?custModalCb='+cb+'&custModalId=' + id + '&folderPath=' + folderPath; } else if(cb == 'adminToolkitFile'){ document.getElementById('custModal').style.width = 80 + '%'; document.getElementById('custModal').style.height = 80 + '%'; ifr = document.createElement('iframe'); ifr.id = 'custIframe'; ifr.name = 'custIframe'; ifr.setAttribute('frameborder', '0'); ifr.setAttribute('scrolling', 'no'); ifr.style.width = '100%'; ifr.style.height = '100%'; ifr.style.overflow = 'hidden'; document.getElementById('custModalContent').appendChild(ifr); document.getElementById('LoginmodalTitle').innerHTML = 'Toolkit files'; document.getElementById('custIframe').src = 'iframe_files.php?custModalCb='+cb+'&custModalId=' + id; } else if(cb == 'adminVideos'){ document.getElementById('custModal').style.width = 80 + '%'; document.getElementById('custModal').style.height = 80 + '%'; ifr = document.createElement('iframe'); ifr.id = 'custIframe'; ifr.name = 'custIframe'; ifr.setAttribute('frameborder', '0'); ifr.setAttribute('scrolling', 'no'); ifr.style.width = '100%'; ifr.style.height = '100%'; ifr.style.overflow = 'hidden'; document.getElementById('custModalContent').appendChild(ifr); document.getElementById('LoginmodalTitle').innerHTML = 'Video images'; document.getElementById('custIframe').src = 'iframe_img.php?custModalCb='+cb+'&custModalId=' + id; } else if(cb == 'adminVideosFile'){ document.getElementById('custModal').style.width = 80 + '%'; document.getElementById('custModal').style.height = 80 + '%'; ifr = document.createElement('iframe'); ifr.id = 'custIframe'; ifr.name = 'custIframe'; ifr.setAttribute('frameborder', '0'); ifr.setAttribute('scrolling', 'no'); ifr.style.width = '100%'; ifr.style.height = '100%'; ifr.style.overflow = 'hidden'; document.getElementById('custModalContent').appendChild(ifr); document.getElementById('LoginmodalTitle').innerHTML = 'Video files'; document.getElementById('custIframe').src = 'iframe_files.php?custModalCb='+cb+'&custModalId=' + id; } document.getElementById('customModal').classList.remove('hiddenModal'); }