a:1:{s:19:"c_17620207123954750";a:5:{s:4:"type";s:6:"script";s:5:"title";s:6394:"// Fetch tickets from zammad-external-data

// Store a unique marker in the script itself, then find it (couldn’t find a better way to place the table in the DOM)
var currentScript = document.currentScript || (function() {
    var scripts = document.getElementsByTagName('script');
    for (var i = 0; i < scripts.length; i++) {
        if (scripts[i].textContent.indexOf('UNIQUE_MARKER_12345') > -1) {
            return scripts[i];
        }
    }
    return scripts[scripts.length - 1];
})();
var container = currentScript.parentElement;

// Configuration
var proxyUrl = 'https://itsmcloud.bludenz.at/i-doit/zammad-external-data'; // Replace with your actual proxy URL
var zammadBaseURL = 'https://zammad.bludenz.at'; // Replace with your actual zammad URL

// Get object ID from URL parameter
var objectID = new URLSearchParams(window.location.search).get('objID')

// Show loading message
container.innerHTML = '<p style="padding: 10px;">Loading tickets...</p>';

// Fetch tickets through proxy
var xhr = new XMLHttpRequest();
xhr.open('GET', proxyUrl + '/zammad/tickets?query=idoit_organization.value:' + objectID, true);

xhr.onload = function() {
    if (xhr.status >= 200 && xhr.status < 300) {
        var response = JSON.parse(xhr.responseText);

        // Clear loading message
        container.innerHTML = '';

        // Check for errors
        if (response.error) {
            container.innerHTML = '<p style="color: red; padding: 10px;">Error: ' + response.error + '</p>';
            return;
        }

        // Response is directly an array of tickets
        var tickets = Array.isArray(response) ? response : [];

        // Check if we have tickets
        if (tickets.length === 0) {
            container.innerHTML = '<p style="padding: 10px;">No tickets found for this organisation.</p>';
            return;
        }

        // Create wrapper div for margin
        var wrapper = document.createElement('div');
        wrapper.style.margin = '10px 20px';

        // Create table
        var table = document.createElement('table');
        table.style.width = '100%';
        table.style.borderCollapse = 'collapse';

        // Create header
        var thead = document.createElement('thead');
        var headerRow = document.createElement('tr');

        var headers = ['Subject', 'State', 'Owner', 'Created at', 'Updated at', 'Priority', "Group", ""];
        headers.forEach(function(headerText) {
            var th = document.createElement('th');
            th.textContent = headerText;
            th.style.border = '1px solid #ddd';
            th.style.padding = '8px';
            th.style.backgroundColor = '#f2f2f2';
            th.style.textAlign = 'left';
            th.style.fontWeight = 'bold';
            headerRow.appendChild(th);
        });

        thead.appendChild(headerRow);
        table.appendChild(thead);

        // Create body with ticket data
        var tbody = document.createElement('tbody');

        tickets.forEach(function(ticket, index) {
            var tr = document.createElement('tr');
            if (index % 2 === 0) {
                tr.style.backgroundColor = '#f9f9f9';
            }

            // Title
            var tdTitle = document.createElement('td');
            tdTitle.textContent = ticket.title || '-';
            tdTitle.style.border = '1px solid #ddd';
            tdTitle.style.padding = '8px';
            tr.appendChild(tdTitle);

            // State
            var tdState = document.createElement('td');
            tdState.textContent = ticket.state || '-';
            tdState.style.border = '1px solid #ddd';
            tdState.style.padding = '8px';
            tr.appendChild(tdState);

            // Owner
            var tdOwner = document.createElement('td');
            tdOwner.textContent = ticket.owner || '-';
            tdOwner.style.border = '1px solid #ddd';
            tdOwner.style.padding = '8px';
            tr.appendChild(tdOwner);

            // created at 
            var tdCreatedAt = document.createElement('td');
            tdCreatedAt.textContent = ticket.created_at || '-';
            tdCreatedAt.style.border = '1px solid #ddd';
            tdCreatedAt.style.padding = '8px';
            tr.appendChild(tdCreatedAt);

            // created at 
            var tdUpdatedAt = document.createElement('td');
            tdUpdatedAt.textContent = ticket.updated_at || '-';
            tdUpdatedAt.style.border = '1px solid #ddd';
            tdUpdatedAt.style.padding = '8px';
            tr.appendChild(tdUpdatedAt);



            // Priority
            var tdPriority = document.createElement('td');
            tdPriority.textContent = ticket.priority || '-';
            tdPriority.style.border = '1px solid #ddd';
            tdPriority.style.padding = '8px';
            tr.appendChild(tdPriority);
            
            // Group
            var tdGroup = document.createElement('td');
            tdGroup.textContent = ticket.group || '-';
            tdGroup.style.border = '1px solid #ddd';
            tdGroup.style.padding = '8px';
            tr.appendChild(tdGroup);

            // Link to ticket (https://zammad.panic.at/#ticket/zoom/id)
            var tdLink = document.createElement('td');
            tdLink.style.border = '1px solid #ddd';
            tdLink.style.padding = '8px';

            var link = document.createElement('a');
            link.href = zammadBaseURL + '/#ticket/zoom/' + ticket.id;
            link.className = 'btn';
            link.target = '_blank';

            var img = document.createElement('img');
            img.src = 'images/axialis/basic/link.svg';
            img.alt = '';

            var span = document.createElement('span');
            span.textContent = 'Open in Zammad';

            link.appendChild(img);
            link.appendChild(span);
            tdLink.appendChild(link);
            tr.appendChild(tdLink);

            tbody.appendChild(tr);
        });

        table.appendChild(tbody);
        wrapper.appendChild(table);
        container.appendChild(wrapper);

    } else {
        container.innerHTML = '<p style="color: red; padding: 10px;">Error loading tickets: ' + xhr.status + '</p>';
    }
};

xhr.onerror = function() {
    container.innerHTML = '<p style="color: red; padding: 10px;">Network error occurred while loading tickets</p>';
};

xhr.send();";s:10:"visibility";s:7:"visible";s:12:"show_in_list";b:0;s:11:"show_inline";b:0;}}