<script>

    function saveConnection(tid, OnHoldFlag) {

        document.getElementById('ConnectionTicketID').value = tid;
        document.getElementById('save').value = 1;
        $("#Export").val("none");

        if (OnHoldFlag) {
            document.getElementById('OnHoldFlag').value = 1;
        }

        document.getElementById('HM-Form-Ticketconn').submit();
    }

    function closing() {
        self.parent.location.href = "index.php?module=ticket&event=show&id=[% $tid %]";
        self.parent.$.fancybox.close();
    }

</script>


<body id="PopUpForm" [% if $closing && $Connection %]onload="closing();"[% /if %]>


    <form action="index.php?module=ticketlist&event=connectTicket&ConnTicketID=[% $tid %]" target="_self" method="post" id="HM-Form-Ticketconn" >

        <input type="hidden" name="save" id="save" value="0" />
        <input type="hidden" name="ConnectionTicketID" id="ConnectionTicketID" value="" />
        <input type="hidden" name="OnHoldFlag" id="OnHoldFlag" value="0" />

        <div class="card panel-info shadow-sm rounded">
            <div class="card-header">
                <h3 class="card-title">[% $user->gettext('Ticket verknüpfen') %]</h3>
            </div>
            <div class="card-body">

                <div class="card panel-info shadow-sm rounded">               
                    <div class="card-body">
                        <a href="#SearchBox" class="btn btn-outline-primary dialog NotForSmallScreens" id="showSearchBox" ><span>[% $user->gettext('Suchformular') %]</span></a>
                    </div>
                </div>  

                <div class="card panel-info shadow-sm rounded">
                    <div class="card-header">
                        <h3 class="card-title"></h3>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-striped table-hover table-sm">
                                <thead>

                                    <tr class="fields">
                                        <th data-hide="phone,tablet"> [% $user->gettext('Verknüpfen') %] </th>
                                        <th data-hide="phone,tablet" style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "Status" %]
                            'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                    'sort'
                                    ).value = 'Status'
                                            [% /if %];submitForm2();">
                                            [% $user->gettext('Status') %] 
                                            [% if $sort == "Status" %]&nbsp;<img src="images/sort[% if $sortorder == "DESC" %]desc[% else %]asc[% /if %].gif" width="11" height="11" border="0" alt=""  />[% /if %]
                                        </th>
                                        <th data-hide="phone,tablet" width="16">&nbsp;</th>
                                        <th data-toggle="true" style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "Ticketdescr" %]
                            'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                    'sort'
                                    ).value = 'Ticketdescr'
                                            [% /if %];
                                    submitForm2();">
                                            [% $user->gettext('Kurzbeschreibung (Titel)') %] 
                                            [% if $sort == "Ticketdescr" %]&nbsp;<img src="images/sort[% if $sortorder == "DESC" %]desc[% else %]asc[% /if %].gif" width="11" height="11" border="0" alt=""  />[% /if %]
                                        </th>
                                        <th data-hide="phone,tablet" style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "Escalation" %]
                            'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                    'sort').value = 'Escalation'
                                            [% /if %];submitForm2();">
                                            [% $user->gettext('Eskalation') %] 
                                            [% if $sort == "Escalation" %]&nbsp;<img src="images/sort[% if $sortorder == "DESC" %]desc[% else %]asc[% /if %].gif" width="11" height="11" border="0" alt=""  />[% /if %]
                                        </th>
                                        <th data-toggle="true" style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "ID" %]
                            'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                    'sort').value = 'ID'
                                            [% /if %];
                                    submitForm2();">
                                            [% $user->gettext('Ticket-Nr.') %] 
                                            [% if $sort == "ID" %]&nbsp;<img src="images/sort[% if $sortorder == "DESC" %]desc[% else %]asc[% /if %].gif" width="11" height="11" border="0" alt=""  />[% /if %]
                                        </th>
                                        <th data-hide="phone,tablet" style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "Company" %]
                            'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                    'sort'
                                    ).value = 'Company'
                                            [% /if %];submitForm2();">
                                            [% $user->gettext('Firma') %]
                                            [% if $sort == "Company" %]&nbsp;<img src="images/sort[% if $sortorder == "DESC" %]desc[% else %]asc[% /if %].gif" width="11" height="11" border="0" alt=""  />[% /if %]
                                        </th>
                                        <th data-hide="phone,tablet" style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "Contact" %]
                            'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                    'sort'
                                    ).value = 'Contact'
                                            [% /if %];
                                    submitForm2();">
                                            [% $user->gettext('Kontakt') %]
                                            [% if $sort == "Contact" %]&nbsp;<img src="images/sort[% if $sortorder == "DESC" %]desc[% else %]asc[% /if %].gif" width="11" height="11" border="0" alt=""  />[% /if %]
                                        </th>
                                        <th data-hide="phone,tablet" style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "Gruppe" %]
                            'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                    'sort'
                                    ).value = 'Gruppe'
                                            [% /if %];
                                    submitForm2();">
                                            [% $user->gettext('Gruppe') %] 
                                            [% if $sort == "Gruppe" %]&nbsp;<img src="images/sort[% if $sortorder == "DESC" %]desc[% else %]asc[% /if %].gif" width="11" height="11" border="0" alt=""  />[% /if %]
                                        </th>
                                        <th data-hide="phone,tablet" style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "Supporter" %]
                            'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                    'sort').value = 'Supporter'
                                            [% /if %];
                                    submitForm2();">
                                            [% $user->gettext('Supporter') %] 
                                            [% if $sort == "Supporter" %]&nbsp;<img src="images/sort[% if $sortorder == "DESC" %]desc[% else %]asc[% /if %].gif" width="11" height="11" border="0" alt=""  />[% /if %]
                                        </th>
                                        <th data-hide="phone,tablet" style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "DesireDate" %]
                            'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                    'sort').value = 'DesireDate'
                                            [% /if %];submitForm2();">

                                            [% if $hmcompany|strpos:"AVAG HOLDING" !== false %]
                                                [% $user->gettext('Wiedervorlage am') %]
                                            [% else %]
                                                [% $user->gettext('F&auml;llig am') %]
                                            [% /if %]

                                            [% if $sort == "DesireDate" %]&nbsp;<img src="images/sort[% if $sortorder == "DESC" %]desc[% else %]asc[% /if %].gif" width="11" height="11" border="0" alt=""  />[% /if %]
                                        </th>
                                        [% if $display == "UpdateDate" %]
                                            <th data-hide="phone,tablet" style="cursor:pointer;" onclick="document.getElementById(
                                                [% if $sort == "UpdateDate" %]
                                'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                                [% else %]
                                        'sort'
                                        ).value = 'UpdateDate'
                                                [% /if %];submitForm2();">
                                        [% if $hmcompany|strpos:"AVAG HOLDING" !== false %][% $user->gettext('Zuletzt ge&auml;ndert am') %][% else %][% $user->gettext('Letzte &Auml;nderung am') %][% /if %] 
                                        [% if $sort == "UpdateDate" %]&nbsp;<img src="images/sort[% if $sortorder == "DESC" %]desc[% else %]asc[% /if %].gif" width="11" height="11" border="0" alt=""  />[% /if %]
                                    </th>
                                [% else %]
                                    <th data-hide="phone,tablet" style="cursor:pointer;" onclick="document.getElementById(
                                        [% if $sort == "CreateDate" %]
                                'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                        [% else %]
                                        'sort').value = 'CreateDate'
                                        [% /if %];submitForm2();">
                                        [% $user->gettext('Erstellt am') %] 
                                        [% if $sort == "CreateDate" %]&nbsp;<img src="images/sort[% if $sortorder == "DESC" %]desc[% else %]asc[% /if %].gif" width="11" height="11" border="0" alt=""  />[% /if %]
                                    </th>
                                [% /if %]
                                [% if $cathep && !$user->hasRight(51) %]
                                    <th data-hide="phone,tablet" style="cursor:pointer;" onclick="document.getElementById(
                                        [% if $sort == "Category2" %]
                                'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                        [% else %]
                                        'sort').value = 'Category2'
                                        [% /if %];
                                        submitForm2();">
                                        [% $user->gettext('Kategorie') %]
                                        [% if $sort == "Category2" %]&nbsp;<img src="images/sort[% if $sortorder == "DESC" %]desc[% else %]asc[% /if %].gif" width="11" height="11" border="0" alt=""  />[% /if %]
                                    </th>
                                [% /if %]
                                <th data-hide="phone,tablet" style="cursor:pointer;" onclick="document.getElementById(
                                    [% if $sort == "OnHold" %]
                    'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                    [% else %]
                            'sort').value = 'OnHold'
                                    [% /if %];submitForm2();">
                                    [% $user->gettext('Zur&uuml;ckgestellt') %]
                                    [% if $sort == "OnHold" %]&nbsp;<img src="images/sort[% if $sortorder == "DESC" %]desc[% else %]asc[% /if %].gif" width="11" height="11" border="0" alt=""  />[% /if %]
                                </th>

                            </tr>
                        </thead>
                        </tbody>
                        [% foreach from=$tickets item=ticket %]
                            <tr style="cursor:pointer;">
                                <td>
                                    <a href="javascript:void(0);" class="btn btn-outline-primary btn-sm" onclick="saveConnection([% $ticket.id %], false);" style="width:150px;white-space:nowrap;display:block;"> [% $user->gettext('Ohne Zurückstellung') %] </a>
                                    [% if $ticket.ticketstatusid  != 3 %]
                                        <a href="javascript:void(0);" class="btn btn-outline-primary btn-sm" onclick="saveConnection([% $ticket.id %], true);" style="width:150px;white-space:nowrap;display:block;"> [% $user->gettext('Mit Zurückstellung') %] </a>
                                    [% /if %]
                                </td>

                                <td nowrap="nowrap" style="text-align:center !important;" class="[% if $ticket.diffonhold > 0 %]onhold[% else %]prio[% if $hmcompany != "HOLIDAY CARS" || $user->hasRight(26) %][% $ticket.ticketprioid %][% else %][% $ticket.ticketuserprioid %][% /if %][% /if %]">[% $user->gettext($ticket.tstatus) %]</td>
                                <td width="16">
                                    [% if $ticket.isproblem == 1 %]
                                        <img src="images/isproblem.gif" width="16" height="16"  alt="[% $user->gettext('Problem') %]" title="[% $user->gettext('Problem') %]" />
                                    [% else %]
                                        <img src="images/isincident.gif" width="16" height="16"  alt="[% $user->gettext('Vorfall') %]" title="[% $user->gettext('Vorfall') %]" />
                                    [% /if %]
                                    [% if $ticket.important == 1 %]<img src="images/important.gif" width="16" height="16"  alt="[% $user->gettext('Kontakt mit Priorität') %]" title="[% $user->gettext('Kontakt mit Priorität') %]" />[% /if %]
                                    [% if $ticket.master %]<img src="images/master.gif" width="16" height="16"  alt="[% $user->gettext('Masterticket') %]" title="[% $user->gettext('Masterticket') %] ([% $ticket.master %])" />[% /if %]
                                    [% if $ticket.ticketreferenzid > 0 %]<img src="images/slave.gif" width="16" height="16"  alt="[% $user->gettext('Abh&auml;ngiges Ticket') %]" title="[% $user->gettext('Abh&auml;ngiges Ticket') %]" />[% /if %]
                                    [% if $ticket.attachments > 0 %]<img src="images/attachment.gif" width="16" height="16"  alt="[% $user->gettext('Dokumente vorhanden') %]" title="[% $user->gettext('Dokumente vorhanden') %]" />[% /if %]
                                    [% if $ticket.important != 1 && !$ticket.master && $ticket.attachements <= 0 %]&nbsp;[% /if %]
                                </td>
                                <td nowrap="nowrap" title="[% $ticket.ticketdescr %]">&nbsp;[% $ticket.ticketdescr|truncate:50:"...":true %]&nbsp;</td>
                                <td><img src="images/escalation[% if $ticket.escalationlevel > 0 %][% $ticket.escalationlevel %][% else %]0[% /if %].gif" width="57" height="13" alt="" title="[% $user->gettext('Eskalation') %]: -[% if $ticket.escalationlevel > 0 %][% $ticket.escalationlevel %][% else %]0[% /if %]-" /></td>
                                <td nowrap="nowrap">[% $ticket.id %]&nbsp;</td>
                                <td nowrap="nowrap">[% $ticket.company|truncate:20:"...":false %]&nbsp;</td>
                                <td nowrap="nowrap">[% $ticket.contact %]&nbsp;</td>
                                <td nowrap="nowrap">[% $ticket.groupdescr %]&nbsp;</td>
                                <td nowrap="nowrap">[% $ticket.supporter %]&nbsp;</td>
                                <td nowrap="nowrap">[% $ticket.ticketdesiredate|date_format:"%d.%m.%Y %H:%M" %]&nbsp;</td>
                                [% if $display == "UpdateDate" %]
                                    <td nowrap="nowrap">[% $ticket.updatedate|date_format:"%d.%m.%Y %H:%M" %]&nbsp;</td>
                                [% else %]
                                    <td nowrap="nowrap">[% $ticket.createdate|date_format:"%d.%m.%Y %H:%M" %]&nbsp;</td>
                                [% /if %]
                                [% if $catdep && !$user->hasRight(51) %]<td nowrap="nowrap">[% $ticket.category2 %]&nbsp;</td>[% /if %]
                                <td>
                                    [% if $ticket.OnHoldFrom != '' %]
                                        [% $user->gettext('Durch Ticket(s)') %]: [% $ticket.OnHoldFrom %]
                                    [% else %]
                                        [% $ticket.onhold|date_format:"%d.%m.%Y %H:%M" %]&nbsp;
                                    [% /if %]
                                </td>
                            </tr>
                        [% foreachelse %]
                            [% if $user->Security->Projects %]
                                <td colspan="[% if $catdep && !$user->hasRight(51) %]14[% else %]13[% /if %]">[% $user->gettext('Keine Tickets gefunden') %]</td>
                            [% else %]
                                <td colspan="[% if $catdep && !$user->hasRight(51) %]13[% else %]12[% /if %]">[% $user->gettext('Keine Tickets gefunden') %]</td>
                            [% /if %]
                        [% /foreach %]
                        [% if $pages > 1 %]
                            <tr>
                                <td colspan="12">
                                    <div class="navigation" style="float:left !important;margin-top:3px;">
                                        <ul>
                                            <li>[% $user->gettext('Seite') %]:</li>
                                            <li><a href="#" onclick="switchPage([% $pos-1 %])" class="button button-grey"><span>&laquo;</span></a></li>
                                            <li><href="#" onclick="switchPage(0)" class="button button-[% if 0 == $pos %]green[% else %]grey[% /if %]"><span>1</span></a></li>
                                                [% if $pages gt 1 %]
                                                    <li><a href="#" onclick="switchPage(1)" class="button button-[% if 1 == $pos %]green[% else %]grey[% /if %]"><span>2</span></a></li>
                                                    [% /if %]
                                                    [% if $pages gt 2 %]
                                                    <li><a href="#" onclick="switchPage(2)" class="button button-[% if 2 == $pos %]green[% else %]grey[% /if %]"><span>3</span></a></li>
                                                    [% /if %]
                                                    [% if $pages gt 3 %]
                                                    <li><a href="#" onclick="switchPage(3)" class="button button-[% if 3 == $pos %]green[% else %]grey[% /if %]"><span>4</span></a></li>
                                                    [% /if %]
                                                    [% if $pages gt 4 %]
                                                    <li><a href="#" onclick="switchPage(4)" class="button button-[% if 4 == $pos %]green[% else %]grey[% /if %]"><span>5</span></a></li>
                                                    [% /if %]
                                                    [% if $pages gt 5 %]
                                                    <li>...</li>
                                                    <li><a href="#" onclick="switchPage([% $pages-1 %])" class="button button-[% if $pages == $pos %]green[% else %]grey[% /if %]"><span>[% $pages-1 %]</span></a></li>
                                                            [% /if %]
                                                <li><a href="#" onclick="switchPage([% $pos+1 %])" class="button button-grey"><span>&raquo;</span></a></li>
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                        [% /if %]
                        </tbody>
                    </table>
                </div>
            </div>
        </div>                         
    </div>
</div>             

<!-- Component Ticket begin -->


<div id="SearchBox" style="display:none;">
    [% include file=$modulePath|cat:"/searchform.tpl" %]
</div>


<script>
    function switchPage(page) {
        var el = document.getElementById("Export");
        if (el)
            el.value = "none";
        document.getElementById("pos").value = page;
        submitForm2();
    }

    $("#showSearchBox").on("click", function () {
        addMultiselect();
    })
    $(".dialog").fancybox({
        maxWidth: 800,
        maxHeight: 700,
        closeClick: false
    })

</script>
<!-- Component Ticket end -->
