jQuery(document).ready(()=>{ const { __, _x, _n, sprintf } = wp.i18n; let system = {code:0 /* public ticket number */, nonce:'', data:null /* retrieved data */, redeemed_successfully:false, img_pfad:'', last_scanned_ticket:{code:'', timestamp:0, auto_redeem:false, data:null}, last_nonce_check:0, status:'ready' /* ready, retrieved, redeemed */ }; let myAjax; if (typeof IS_PRETTY_PERMALINK_ACTIVATED === "undefined") { IS_PRETTY_PERMALINK_ACTIVATED = false; } let rest_route = '/event-tickets-with-ticket-scanner/ticket/scanner/'; let pre_route = '../../../../..'; if (typeof Ajax_sasoEventtickets != "undefined" && Ajax_sasoEventtickets.wcTicketCompatibilityModeRestURL != '') { pre_route = Ajax_sasoEventtickets.wcTicketCompatibilityModeRestURL.trim(); } if (typeof Ajax_sasoEventtickets === "undefined") { myAjax = { url: pre_route + '/wp-json'+rest_route }; system.nonce = NONCE; } else { myAjax = Ajax_sasoEventtickets; system.nonce = myAjax.nonce; if (Ajax_sasoEventtickets.wcTicketCompatibilityModeRestURL != "") { myAjax.url = Ajax_sasoEventtickets.wcTicketCompatibilityModeRestURL.trim()+'/wp-json'+rest_route; } else { myAjax.url = myAjax._siteUrl+'/wp-json'+rest_route; } IS_PRETTY_PERMALINK_ACTIVATED = myAjax.IS_PRETTY_PERMALINK_ACTIVATED; } myAjax.rest_route = rest_route; myAjax.non_pretty_permalink_url = pre_route+'/?rest_route='+myAjax.rest_route; system.INPUTFIELD; system.AUTHTOKENREMOVEBUTTON; system.ADDITIONBUTTONS; system.TIMEAREA; function toBool(v) { if (!v) return false; if (v == "1") return true; if (v == 1) return true; if (v.toLowerCase() == "yes") return true; return v == true; } var ticket_scanner_operating_option = { redeem_auto: false, distract_free: false, distract_free_show_short_desc: false, speak: false, vibrate: false, auth:"", ticketScannerDontRememberCamChoice:toBool(myAjax.ticketScannerDontRememberCamChoice), ticketScannerStartCamWithoutButtonClicked:false, ticketScannerDontShowOptionControls:toBool(myAjax.ticketScannerDontShowOptionControls), ticketScannerDontShowBtnPDF:toBool(myAjax.ticketScannerDontShowBtnPDF), ticketScannerDontShowBtnBadge:toBool(myAjax.ticketScannerDontShowBtnBadge) }; var loadingticket = false; var div_ticket_info_area = null; var div_order_info_area = null; function addStyleCode(content, media) { let c = document.createElement('style'); if (media) c.setAttribute("media", media); c.innerHTML = content; document.getElementsByTagName("head")[0].appendChild(c); } function onScanFailure(error) { // handle scan failure, usually better to ignore and keep scanning. // for example: //console.warn(`Code scan error = ${error}`); } var html5QrcodeScanner = null; var qrScanner = null; function setStartCamWithoutButtonClicked(value) { if (typeof value != "undefined") { ticket_scanner_operating_option.ticketScannerStartCamWithoutButtonClicked = value; } else { ticket_scanner_operating_option.ticket_scanner_operating_option.ticketScannerStartCamWithoutButtonClicked = !ticket_scanner_operating_option.ticketScannerStartCamWithoutButtonClicked; } _storeValue("ticket_scanner_operating_option.ticketScannerStartCamWithoutButtonClicked", ticket_scanner_operating_option.ticketScannerStartCamWithoutButtonClicked ? 1 : 0); } function setRedeemImmediately(value) { if (typeof value != "undefined") { ticket_scanner_operating_option.redeem_auto = value; } else { ticket_scanner_operating_option.redeem_auto = !ticket_scanner_operating_option.redeem_auto; } _storeValue("ticket_scanner_operating_option.redeem_auto", ticket_scanner_operating_option.redeem_auto ? 1 : 0); } function setDistractFree(value) { if (typeof value != "undefined") { ticket_scanner_operating_option.distract_free = value; } else { ticket_scanner_operating_option.distract_free = !ticket_scanner_operating_option.distract_free; } _storeValue("ticket_scanner_operating_option.distract_free", ticket_scanner_operating_option.distract_free ? 1 : 0); } function setSpeakCheckbox(value) { if (typeof value != "undefined") { ticket_scanner_operating_option.speak = value; } else { ticket_scanner_operating_option.speak = !ticket_scanner_operating_option.speak; } _storeValue("ticket_scanner_operating_option.speak", ticket_scanner_operating_option.speak ? 1 : 0); } function setVibrate(value) { if (typeof value != "undefined") { ticket_scanner_operating_option.vibrate = value; } else { ticket_scanner_operating_option.vibrate = !ticket_scanner_operating_option.vibrate; } _storeValue("ticket_scanner_operating_option.vibrate", ticket_scanner_operating_option.vibrate ? 1 : 0); } function setDistractFreeShowShortDesc(value) { if (typeof value != "undefined") { ticket_scanner_operating_option.distract_free_show_short_desc = value; } else { ticket_scanner_operating_option.distract_free_show_short_desc = !ticket_scanner_operating_option.distract_free_show_short_desc; } _storeValue("ticket_scanner_operating_option.distract_free_show_short_desc", ticket_scanner_operating_option.distract_free_show_short_desc ? 1 : 0); } function initAuthToken() { let text = _loadValue("ticket_scanner_operating_option.auth"); if (system.PARA.auth) { text = system.PARA.auth.trim(); } if (text != "") { try { let json = JSON.parse(text); setAuthToken(json, true); } catch (e) { alert(e); } } } function setAuthToken(token, doNotUpdateScanOption) { // {"type":"auth","time":"2023-07-10 20:07:24","name":"saso","code":"AHR0CHM6LY92ZXJ3AWNRBHVUZY5KZS93B3JKCHJLC3M=_0C3C7AF3DCCD805F56EF02BEB9E39FFC","areacode":"ticketscanner","url":"https://verwicklung.de/wordpress/wp-content/plugins/event-tickets-with-ticket-scanner/ticket/"} if (typeof token != "undefined" && typeof token.type != "undefined" && token.type == "auth") { //ticket_scanner_operating_option.auth = token; } else { token = ""; } ticket_scanner_operating_option.auth = token; _storeValue("ticket_scanner_operating_option.auth", JSON.stringify(token)); if (!doNotUpdateScanOption) showScanOptions(); } function onScanSuccess(decodedText, decodedResult) { //if (decodedText) decodedText = decodedText.trim(); if (system.last_scanned_ticket.code == decodedText && system.last_scanned_ticket.timestamp + 10 > time()) { return; } if (loadingticket) return; loadingticket = true; system.last_scanned_ticket = {code: decodedText, timestamp: time()}; updateLastScanTime(); if (qrScanner != null) { //qrScanner.stop(); // faster if not executed } // store setting to cookies / or browser storage if (!ticket_scanner_operating_option.ticketScannerDontRememberCamChoice && html5QrcodeScanner != null) { _storeValue("ticketScannerCameraId", html5QrcodeScanner.persistedDataManager.data.lastUsedCameraId, 365); } updateTicketScannerInfoArea("
"+sprintf(/* translators: %s: ticket number */__("found %s", 'event-tickets-with-ticket-scanner'), decodedText)+'
'); // handle the scanned code as you like, for example: //console.log(`Code matched = ${decodedText}`, decodedResult); $("#reader_output").html(__("...loading...", 'event-tickets-with-ticket-scanner')); //window.location.href = "?code="+encodeURIComponent(decodedText) + (ticket_scanner_operating_option.redeem_auto ? "&redeemauto=1" : ""); let token = null; try { token = JSON.parse(decodedText); } catch(e) {} if (token != null && typeof token == "object") { if (token.type && token.type == "auth") { setAuthToken(token); clearAreas(); $("#reader_output").html(''); updateTicketScannerInfoArea('

'+__("Auth Token Set", 'event-tickets-with-ticket-scanner')+'

'); window.setTimeout(()=>{ showScanNextTicketButton(); }, 350); } else { renderInfoBox(__("Scan error", 'event-tickets-with-ticket-scanner'), __("QR code content unknown. Can not extract data correctly. Please try a QR code of a ticket.", 'event-tickets-with-ticket-scanner'), showScanNextTicketButton); } } else { /* // not working with QRScanner? or the other scanner. Somehow content is not recognized correctly or not send. maybe a config value to be set. Because with text in it, the scanner is returning an empty string // extract the public ticket number from the token. format is CRC32(TIMESTAMP)-ORDERID-TICKETNUMBER. // the public ticket number can be part of text in the qr code, so we need to extract it. if (decodedText.length > 12) { debugger; // format: NUMBER-NUMBER-TICKETNUMBER , TICKETNUMBER can be text and numbers // example: 2523448324-671-ticket_2025052808_dc_XYJBSSAZGZBHENY reg = /\b\d+-\d+-[A-Za-z0-9_]+\b/g; console.log("decodedText: "+decodedText); let matches = decodedText.match(reg); if (matches && matches.length > 3) { decodedText = matches[0]; // the ticket number is the third match } console.log("extracted ticket number from QR code: "+decodedText); retrieveTicket(decodedText); } else { if (decodedText != "") { renderInfoBox(__("Scan error", 'event-tickets-with-ticket-scanner'), "Cannot find the public ticket number in the QR code. Please try a QR code of a ticket.", showScanNextTicketButton); } } */ if (decodedText != "") { retrieveTicket(decodedText); } else { renderInfoBox(__("Scan error", 'event-tickets-with-ticket-scanner'), __("Cannot find the public ticket number in the QR code. Please try a QR code of a ticket.", 'event-tickets-with-ticket-scanner'), showScanNextTicketButton); } } if (html5QrcodeScanner != null) { window.setTimeout(()=>{ html5QrcodeScanner.clear().then((ignore) => { // QR Code scanning is stopped. // reload the page with the ticket info and redeem button //console.log("stop success"); }).catch((err) => { // Stop failed, handle it. //console.log("stop failed"); }); }, 250); } } function startScanner() { if (!ticket_scanner_operating_option.redeem_auto) updateTicketScannerInfoArea(""); $("#reader_output").html(""); loadingticket = false; if (system.PARA.useoldticketscanner) { startScanner_html5QrcodeSCanner(); } else { startScanner_QRScanner(); } } function startScanner_QRScanner() { let deviceId = _loadValue("ticketScannerCameraId"); let v_id = 'saso_eventtickets_qr-video'; let camlist_id = 'saso_eventtickets_camList'; let start_cam = false; if (document.getElementById(v_id) == null) { $("#reader").html(""); start_cam = true; $('#reader').append(''); $('').appendTo($('#reader')).on("change", event=>{ _storeValue("ticketScannerCameraId", event.target.value, 365); qrScanner.setCamera(event.target.value);//.then(updateFlashAvailability); }); let btn = $('').on('click', function() { overlay.remove(); }).appendTo(header); modal.append(header); // Content area let content = $('
'); // Seat info banner let seatBanner = $('
'); seatBanner.html('' + (ret.seat_label_text || _x('Seat', 'label', 'event-tickets-with-ticket-scanner')) + ': ' + ret.seat_label + (ret.seat_category ? ' (' + ret.seat_category + ')' : '')); content.append(seatBanner); // Plan description if available if (ret.seating_plan_description) { let descDiv = $('
').text(ret.seating_plan_description); content.append(descDiv); } // Venue image let imgContainer = $('
'); let img = $('').attr('src', ret.seating_plan_image_url).attr('alt', ret.seating_plan_name || 'Venue'); imgContainer.append(img); content.append(imgContainer); modal.append(content); // Footer with close button let footer = $('