/* ********************************************************************************************************************* * B I B L I O T E K A W S P Ó L N A * * VER 4.0.1 - 07/12/2024 * * * * Sierpień 2021 VER 3.0 Rozdzielne sesje * * Grudzień 2024 VER 4.0 Wspólna biblioteka dla systemu w assets * * (C) 2024 AKK Time for Chopin * ************************************************************************************************************************/ //-----------------------------Rozsterowanie menu głównego z wywołaniem stron ----------------------- function menu_TFC_Koncerty (e, str, menu_item) { if (str != 0) {if (!zapisano_rec()) { return;}} retriveSession("./index.php"); switch (menu_item) { case 'rez-nrez': case 'rez-disp': location = "TFC_Koncerty_REZ.php?" + menu_item + "&SID="+encodeURIComponent(ses_sid); break; case 'knc-nknc': case 'knc-mddl': case 'knc-disp': case 'knc-live': location = "TFC_Koncerty_KNC.php?" + menu_item + "&SID="+encodeURIComponent(ses_sid); break; case 'rdn-prck': case 'rdn-morp': case 'rdn-wyrp': case 'rdn-kfrd': case 'rdn-rgot': location = "TFC_Koncerty_RDN.php?" + menu_item + "&SID="+encodeURIComponent(ses_sid); break; case 'fvk-rfvk': case 'fvk-wyfk': location = "TFC_Koncerty_RFV.php?" + menu_item + "&SID="+encodeURIComponent(ses_sid); break; } } function menu_TFC_Finanse (e, str, menu_item) { if (str != 0) {if (!zapisano_rec()) { return;}} retriveSession("./index.php"); switch (menu_item) { case 'wyn-osms': case 'wyn-osro': case 'wyn-afms': case 'wyn-afro': case 'wyn-afko': location = "TFC_Finanse_WYN.php?" + menu_item + "&SID="+encodeURIComponent(ses_sid); break; case 'rap-opod': case 'rap-rgot': case 'rap-fkos': case 'rap-fprz': case 'rap-plac': location = "TFC_Finanse_RAP.php?" + menu_item + "&SID="+encodeURIComponent(ses_sid); break; case 'kal-konc': case 'kal-ceny': case 'kal-sale': location = "TFC_Finanse_KAL.php?" + menu_item + "&SID="+encodeURIComponent(ses_sid); break; case 'prs-prac': case 'prs-list': location = "TFC_Finanse_PRC.php?" + menu_item + "&SID="+encodeURIComponent(ses_sid); break; case 'pla-rokr': case 'pla-staw': case 'pla-list': case 'pla-hote': location = "TFC_Finanse_ROK.php?" + menu_item + "&SID="+encodeURIComponent(ses_sid); break; case 'fvp-wyfv': case 'fvp-mofv': case 'fvp-list': case 'fvp-kont': case 'fvp-koli': location = "TFC_Finanse_FWY.php?" + menu_item + "&SID="+encodeURIComponent(ses_sid); break; } } /* ----------------------------------- CHANGE PSSWD --------------------------------------------------*/ function changePwd(args) { console.log(args); var psenc = encodeURIComponent(ses_sid); let prog = "login/change-pwd.php?"+"SID="+psenc+"&"+args; location.replace(prog); } /* -------------------------------------- LOG OUT ----------------------------------------------------*/ function logOut(args) { var psenc = encodeURIComponent(ses_sid); let prog = "login/logout.php?"+"SID="+psenc+"&"+args; console.log(prog); location.replace(prog); } /* ----------------------------------- SESSION RETRIVE -----------------------------------------------*/ function retriveSession(indx) { zadanie = {"ster":777, "SID":ses_sid}; zadanie_s = JSON.stringify(zadanie); // console.log(zadanie_s); xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { // console.log(this.responseText); var resp = JSON.parse(this.responseText); if (resp.SID == "407") { // Sesja nie istnieje - zaloguj ponownie location.replace(indx); } } //this.readyState }; //onreadystatechange xmlhttp.open("POST", "TFC_Konc_PST.php", false); //Wystrzel zapytanie do serwera xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send("x=" + zadanie_s); } /* ------------------------------- FUNKCJE OBSŁUGI COOKIES --------------------------------------------*/ function setCookie(cname,cvalue,exmins) { // SET COOKIE var d = new Date(); d.setTime(d.getTime() + (exmins*60*1000)); var expires = "expires=" + d.toUTCString(); // console.log(cname + "=" + cvalue + ";" + expires + ";path=/"); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } function getCookie(cname) { // GET COOKIE var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { // console.log(c.substring(name.length, c.length)); return c.substring(name.length, c.length); } } return ""; } function destroyCookie(cname){ setCookie(cname,"",0); } function checkCookie() { // CHECK COOKIE var user=getCookie("username"); if (user != "") { alert("Welcome again " + user); } else { user = prompt("Please enter your name:",""); if (user != "" && user != null) { setCookie("username", user, 30); } } } /* -------------------------------------- DO PDF -----------------------------------------------------*/ function zapisz_PDF(div_id){ return (isIOS() ? printSelection : printDiv)(div_id); //return printDiv(div_id); //Tu wywołanie zrzutu do PDF - na razie drukowanie //Do PDF } //-----------------------------------PRINT PAGE-------------------------------------------- //Funkcja drukuje zawartość wybranego kontenera div id=printpage /* Domyślnie stopka ukryta (na ekranie) */ function printDiv(printpage) { printcolor = '#116211;'; printcolor = '#000000;'; var contents = document.getElementById(printpage).innerHTML; var frame1 = document.createElement('iframe'); frame1.name = "frame1"; frame1.style.position = "absolute"; frame1.style.top = "-1000000px"; frame1.style.fontFamily = "11px Helvetica"; frame1.className = "rez_data_title"; hd1 = document.getElementById('fv_poz_hdr'); // hd1.className = "fv_data_hdr"; document.body.appendChild(frame1); var frameDoc = (frame1.contentWindow) ? frame1.contentWindow : (frame1.contentDocument.document) ? frame1.contentDocument.document : frame1.contentDocument; frameDoc.document.open(); // frameDoc.document.write(''); frameDoc.document.write(''); frameDoc.document.write(''); // frameDoc.document.write(''); frameDoc.document.write(''); frameDoc.document.write(''); // frameDoc.style.backgroundColor = "#EAF6ED"; // frameDoc.document.write('') frameDoc.document.write('Time for Chopin'); frameDoc.document.write(''); frameDoc.document.write(contents); frameDoc.document.write(''); frameDoc.document.close(); setTimeout(function () { window.frames["frame1"].focus(); frame1.style.fontFamily = "11px Helvetica"; window.frames["frame1"].print(); document.body.removeChild(frame1); }, 500); return false; } /* ----------------------------------------- druk na IOS --------------------------------- */ function isIOS() { return /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1); } /* Na iOS drukujemy bieżące okno, ukrywając cały świat poza klonem wybranej sekcji */ function printSelectionIOS(printpage) { // jeśli nie iOS – idź starą ścieżką if (!isIOS()) return printdiv(printpage); const src = document.getElementById(printpage); if (!src) { alert('Nie znaleziono elementu: ' + printpage); return false; } // 1) Zrób portal z klonem drukowanego fragmentu const portal = document.createElement('div'); portal.id = 'PRINT_PORTAL'; const clone = src.cloneNode(true); // jeśli root był ukryty inline (display:none/visibility/opacity) – zdejmij TYLKO z KORZENIA clone.removeAttribute('hidden'); const inline = clone.getAttribute('style') || ''; if (/display\s*:\s*none/i.test(inline)) clone.style.removeProperty('display'); if (/visibility\s*:\s*hidden/i.test(inline)) clone.style.removeProperty('visibility'); if (/opacity\s*:\s*0(?:;|$)/i.test(inline)) clone.style.removeProperty('opacity'); portal.appendChild(clone); document.body.appendChild(portal); // 2) Schowaj WSZYSTKO inne (inline !important – przebija CSS) const siblings = Array.from(document.body.children); const backups = []; siblings.forEach(el => { if (el !== portal) { backups.push([el, el.getAttribute('style')]); el.style.setProperty('display', 'none', 'important'); } }); // 3) Daj przeglądarce klatkę na przeliczenie layoutu i odpal druk const restore = () => { siblings.forEach((el, i) => { if (el !== portal) { const prev = backups.shift(); if (prev[1] === null) el.removeAttribute('style'); else el.setAttribute('style', prev[1]); } }); portal.remove(); window.removeEventListener('afterprint', restore); }; window.addEventListener('afterprint', restore); // pod iOS warto dać dwa rAF/krótki timeout, żeby styl „chwycił” requestAnimationFrame(() => { requestAnimationFrame(() => { window.print(); // awaryjne sprzątanie, gdyby iOS nie wywołał afterprint setTimeout(restore, 2000); }); }); return false; } /* ------------------------------------ divToPDF ---------------------------------------- */ const mmToPx = mm => mm * 96 / 25.4; function divToPDF(divId, filename = 'dokument.pdf') { const el = document.getElementById(divId); if (!el) { console.error('Brak elementu:', divId); return; } // Jeśli ukryty (display:none), pokaż na czas renderu const wasHidden = getComputedStyle(el).display === 'none'; const prevDisplay = el.style.display; if (wasHidden) el.style.display = 'block'; const opt = { // A4 portrait, treść 200 mm = margines 5 mm z każdej strony margin: 5, // w mm filename: filename, image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2, useCORS: true, backgroundColor: '#ffffff', // podpowiedz szerokość okna = naturalna szerokość elementu windowWidth: el.scrollWidth || el.offsetWidth || el.clientWidth }, jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }, pagebreak: { mode: ['css', 'legacy'] } }; html2pdf().set(opt).from(el).save().finally(() => { if (wasHidden) el.style.display = prevDisplay || 'none'; }); } /* async function divToPDF(divId, filename = 'dokument.pdf', marginMm = 10, shiftRightMm = 25) { const src = document.getElementById(divId); if (!src) { console.error('Nie znaleziono elementu:', divId); return; } // SANDBOX na (0,0), białe tło const sandbox = document.createElement('div'); Object.assign(sandbox.style, { position: 'fixed', left: '0', top: '0', zIndex: '2147483647', background: '#fff', width: '100vw', padding: '0', margin: '0', overflow: 'visible' }); document.body.appendChild(sandbox); // KOPIA elementu do sandboxa const clone = src.cloneNode(true); clone.removeAttribute('id'); sandbox.appendChild(clone); // Poczekaj na layout/fonty await new Promise(r => requestAnimationFrame(r)); if (document.fonts && document.fonts.ready) { try { await document.fonts.ready; } catch(_){} } // Szerokość treści A4 (po odjęciu marginesów) const contentPx = mmToPx(210 - 2 * marginMm); // Naturalna szerokość klona const naturalWidth = clone.scrollWidth || clone.offsetWidth || clone.clientWidth || contentPx; // Skala, by zmieścić się w A4 portrait const scale = naturalWidth > 0 ? Math.min(1, contentPx / naturalWidth) : 1; // PRZESUNIĘCIE W PRAWO (w px) const shiftPx = mmToPx(shiftRightMm); // Zastosuj przesunięcie + skalę (kolejność: translateX potem scale) clone.style.transformOrigin = 'top left'; clone.style.transform = `translateX(${shiftPx}px) scale(${scale})`; // Szerokość okna renderu (po skali + przesunięcie) const windowWidth = Math.ceil(naturalWidth * scale + shiftPx); const opt = { // możesz też podać tablicę marginesów: [góra, lewo, dół, prawo] margin: marginMm, filename, image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2, useCORS: true, backgroundColor: '#ffffff', scrollX: 0, scrollY: 0, windowWidth // informujemy h2c o szerszym obszarze przez przesuw }, jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }, pagebreak: { mode: ['css', 'legacy'] } }; try { await html2pdf().set(opt).from(clone).save(); } finally { document.body.removeChild(sandbox); } } */ /* async function divToPDF(divId, filename = 'rozliczenie.pdf', marginMm = 10) { const src = document.getElementById(divId); if (!src) { console.error('Nie znaleziono elementu:', divId); return; } // 1) Niewidoczny iframe daje izolację od stylów strony const frame = document.createElement('iframe'); Object.assign(frame.style, { position:'fixed', left:'0', top:'0', width:'0', height:'0', border:'0' }); document.body.appendChild(frame); const doc = frame.contentDocument; doc.open(); doc.write(''); doc.close(); // 2) Skopiuj CSS (opcjonalnie – jeśli potrzebujesz klas z