<script src="includes/js/dropzone.js"></script>
<link href="includes/js/dropzone.css" rel="stylesheet" type="text/css" />
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="includes/js/bootstrap-select-1.12.4/dist/css/bootstrap-select.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="includes/js/bootstrap-select-1.12.4/dist/js/bootstrap-select.min.js"></script>
<!-- Component TicketTemplate begin -->
<script language="JavaScript" src="modules/tickettemplate/javascript/tickettemplate.js" type="text/JavaScript"></script>
<script type="text/javascript" src="includes/js/jquery-ui-timepicker-addon.js"></script>
<link rel="stylesheet" type="text/css" href="styles/[% $CSSTEMPLATE %]/css/jquery-ui-timepicker-addon.css" media="screen" />
<script type="text/javascript" src="includes/js/jquery-ui-timepicker-addon.js"></script>

<link rel="stylesheet" type="text/css" href="includes/js/select2/css/select2.min.css"/>
<script type="text/javascript" src="includes/js/select2/js/select2.full.min.js"></script>
<script type="text/javascript" src="includes/js/select2/js/i18n/de.js"></script>
<style>
    #alertModal {
        z-index: 8014;
    }
    .multiselect-container {
      width: 100%;
    }
</style>

<form action="" method="post" name="hm" id="hm-TicketTemplateForm" enctype="multipart/form-data" class="form-horizontal form-label-left" >

    <input type="hidden" name="pos" id="pos" value="[% $pos %]" />
    <input type="hidden" name="sort" id="sort" value="[% $sort %]" />
    <input type="hidden" name="type_id" value="[% if $type.type_id %][% $type.type_id %][% else %]0[% /if %]" />
    <input type="hidden" name="sortorder" id="sortorder" value="[% $sortorder %]" />
    <input type="hidden" name="action" value="save" id="action" />
    [% if $template.tickettemplateid > 0 %]
        <input type="hidden" name="TicketTemplateID" value="[% $template.tickettemplateid %]" />
    [% /if %]


    <div class="card panel-fcs-border shadow-sm">
        <div class="card-header">
            <span class="fcs-card-title h2">[% $user->gettext('Ticketvorlagen') %][% if $type.type_id %]: [% $type.type_name %][% /if %]</span>
        </div>
        <div class="card-body">
            <div class="card panel-info shadow-sm rounded">
                <div class="card-header">
                    <div class="row">
                        <div class="col-lg-6">
                            <span class="fcs-card-title h3">
                        [% if $template.tickettemplateid > 0 %][% $user->gettext('Vorlage bearbeiten') %][% else %][% $user->gettext('Neue Vorlage anlegen') %][% /if %]
                    </span>
                </div>
                <div class="col-lg-6 text-end" style="padding-top: 10px">
                    <div class="btn-group">
                        <input type="button" value="[% $user->gettext('Speichern') %]" class="btn btn-outline-primary" onclick="ValidateForm(0);" />
                        [% if $template.tickettemplateid > 0 %]
                            <input type="button" value="[% $user->gettext('Kopieren') %]" class="btn btn-outline-primary" onclick="document.location.href = 'index.php?module=tickettemplate&event=copyTemplate&tid=[% $template.tickettemplateid %]';" />
                        [% /if %]
                        [% if $template.tickettemplateid > 0 %]
                            <input type="button" value="[% $user->gettext('L&ouml;schen') %]" class="btn btn-outline-primary" onclick="if (confirm('[% $user->gettext('Vorlage wirklich entfernen?') %]')) {
                                        document.location.href = 'index.php?module=tickettemplate&event=remove&id=[% $template.tickettemplateid %]';
                                    }" />
                        [% /if %]
                        <input type="button" value="[% $user->gettext('Liste') %]" class="btn btn-outline-secondary" onclick="document.location.href = 'index.php?module=tickettemplate&event=listTemplates';" />
                    </div>
                </div>
            </div>
        </div>
        <div class="card-body">
            <div class="alert alert-danger alert-dismissible" id="errorbox" role="alert" style="display:none;">
                <a type="button" class=" float-end" data-dismiss="alert" aria-label="Close" style="color: #333;"><span style="font-size: 28px !important;" aria-hidden="true">&times;</span></a>
                <h3>[% $user->gettext('Fehler') %]</h3>
                <div id="errorres"></div>
            </div>

            <div class="row" style="padding: 10px">
                <div class="col-md-6" style="padding-top: 10px">
                    <div class="form-group row mb-3">
                        <label class="col-lg-4 control-label">[% $user->gettext('Tickettyp') %]</label>
                        <div class="col-lg-8">
                            <select id="type_id" name="typeid" class="form-control"   style="width: 100%;">
                                <option value="0" [% if $standard_type %]selected="selected"[% /if %]>[% $smarty.const.STANDARD_NAME %] </option>
                                [% foreach from = $ticket_types item=$t %]
                                    <option value="[% $t.type_id %]" [% if $t.type_id == $type.type_id %]selected="selected"[% /if %]>[% $t.type_name %]</option>
                                [% /foreach %]
                            </select>
                        </div>
                    </div>
                    <div class="form-group row mb-3">
                        <label class="col-lg-4  control-label">
                            [% $user->gettext('Icon') %]:
                        </label>
                        <div class="col-lg-8">
                            <select name="Icon" style="min-width:100px;" id="icon" class="form-control">
                                <option value="0">Keine</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group row mb-3" id="TitleField">
                        <label class="col-lg-4 control-label">[% $user->gettext('Titel der Ticketvorlage') %] *</label>
                        <div class="col-lg-8">
                            <input type="text" class="form-control required" required="required" id="Title" name="title" value="[% $template.title %]" placeholder="[% $user->gettext('Titel der Vorlage') %]"/>
                            <span class="help-block">[% $user->gettext('Fügen Sie der Vorlage einen Titel und eine Beschreibung hinzu.<br/>Diese werden in der Vorlagenauswahl angezeigt.') %]</span>

                        </div>
                    </div>

                    <div class="form-group row mb-3">
                        <label class="col-lg-4 control-label">[% $user->gettext('Beschreibung der Ticketvorlage') %]</label>
                        <div class="col-lg-8">
                            <textarea class="form-control" name="TemplateDescr" placeholder="[% $user->gettext('Beschreibung der Vorlage') %]">[% $template.templatedescr %]</textarea>
                        </div>
                    </div>
                    <div class="form-group mb-3 row">
                                    <label class="col-lg-4 col-form-label">[% $user->gettext('Mandant') %]</label>
                                    <div class="col-lg-8">
                                            <select name="MandantenID" id="MandantenID" class="form-control" style="width: 100%;">
                                                    [% foreach from=$Mandanten item=Mandant key=MandantenID %]
                                                            <option value="[% $MandantenID %]" [% if $template.mandantenid == $MandantenID  %]selected="selected"[% /if %]>[% $Mandant %]</option>
                                                    [% /foreach %]
                                            </select>
                                    </div>
                                </div>
                    <div class="form-group row mb-3">
                        <label class="col-lg-4 control-label">[% $user->gettext('Kontakt') %]</label>
                        <div class="col-lg-8">
                            <div class="input-group">
                                <input type="hidden" name="contact_id" id="contact_id" value="[% $template.contactid %]">
                                <select id="contact" class="form-control" >
                                    <option value="[% $template.contactid %]" selected="selected">[% $template.contactname %] </option>
                                </select>
                                <span class="input-group-text">
                                    <span class="fa fa-times" title="[% $user->gettext('Kontakt entfernen') %]" id="removeContact"></span>
                                </span>
                            </div>
                        </div>
                    </div>

                    <div class="form-group row mb-3" id="ShortDescrField">
                        <label id="TicketShortDescription" class="col-lg-4 control-label">[% $user->gettext('Kurzbeschreibung (Titel)') %][% if $repeat_mode != "none" %] *[% /if %]</label>

                        <div class="col-lg-8">
                            <input type="text" maxlength="255" name="ShortDescr" id="ShortDescr" class="form-control"  value="[% $template.shortdescr %]"/>
                        </div>
                    </div>

                    <div class="form-group row mb-3" [% if ($type.type_name && !$Tools->FCS_InArray('priority', $show))%]style="display:none;"[% /if %]>
                        <label class="col-lg-4 control-label">[% $user->gettext('Priorit&auml;t') %]</label>
                        <div class="col-lg-8">
                            <select size="1" name="PrioID" class="form-control multiple">
                                <option value="">- [% $user->gettext('Standard') %] -</option>
                                [% foreach from=$prios item=prio %]
                                    <option value="[% $prio.ticketprioid %]" [% if $prio.ticketprioid == $template.prioid %]selected="selected"[% /if %]>[% $prio.descr %]</option>
                                [% /foreach %]
                            </select>
                        </div>
                    </div>

                    <div class="form-group row mb-3">
                        <label class="col-lg-4 control-label">[% $user->gettext('Ticketbeschreibung') %]</label>
                        <div class="col-lg-8">
                            <div id="quillEditor">
                                [% $user->getQuillToolbar() %]
                                <div id="editor" style="min-height: 200px;">

                                </div>
                            </div>
                            <textarea id="LongDescr" name="LongDescr" class="form-control" style="height: 0px; visibility:hidden;">[% $template.longdescr %]</textarea>
                        </div>
                    </div>

                    <div class="form-group row mb-3" id="TemplateTagsField">
                        <label id="TemplateTagsDescription" class="col-lg-4 control-label" for="TemplateTags">[% $user->gettext('Suchbegriff in Vorlagensuche') %]</label>
                        <div class="col-lg-8">
                            <input type="text" name="TemplateTags" id="TemplateTags" class="form-control"  value="[% $template.templatetags %]"/>
                        </div>
                    </div>

                    <div class="form-group row mb-3" id="OrderNoInSelectlistField">
                        <label id="OrderNoInSelectlistDescription" class="col-lg-4 control-label" for="OrderNoInSelectlist">[% $user->gettext('Reihenfolge in der Ticketauswahl') %]</label>
                        <div class="col-lg-8">
                            <input type="number" name="OrderNoInSelectlist" id="OrderNoInSelectlist" class="form-control"  value="[% $template.ordernoinselectlist %]"/>
                            <span class="help-block">[% $user->gettext('Je höher die Nummer, desto weiter vorne steht die Vorlage in der Auswahlliste im Ticket') %]</span>
                        </div>
                    </div>

                </div>

                <div class="col-md-6" style="padding-top: 10px">

                    <div class="card panel-info shadow-sm rounded">

                        <div class="card-header">
                            <h3 class="card-title">[%$user->gettext('Sichtbarkeit')%]</h3>
                        </div>
                        <div class="card-body">


                            <div class="form-group row mb-3">
                                <label class="control-label col-4" for="isActive">[% $user->gettext('Vorlage aktiv') %]</label>
                                <div class="col-8">
                                    <div class="form-check">
                                        <input class="form-check-input" type="checkbox" id="isActive" name="isActive" value="1"
                                            [% if $template.isactive %]checked[% /if  %]>
                                        <label class="form-check-label" for="isActive">
                                            [% $user->gettext('Aktiv') %]
                                        </label>
                                    </div>
                                    <span class="help-block">
                                        [% $user->gettext('Nur aktive Vorlagen stehen Benutzern zur Auswahl oder werden automatisch angelegt.') %]
                                    </span>
                                </div>
                            </div>


                            <div class="form-group row mb-3" id="VisibleForGroupsField">
                                <label class="col-lg-4 control-label" for="visibleforgroups">[% $user->gettext("Vorlage wählbar für Gruppen") %]</label>
                                <div class="col-lg-8">
                                    <select name="group_ids[]" id="visibleforgroups" class="form-control multiple2"  multiple="multiple" style="width:100%" data-actions-box="true">
                                        [% html_options options=$TemplateGroups selected=$template.visibleforgroups %]
                                    </select>
                                    <div>
                                        <label><input type="checkbox" value="-1" id="chkNoGroups" name="NoGroups"/> [% $user->gettext("Keine Gruppe") %]</label>&nbsp;
                                        <label><input type="checkbox" value="0" id="chkAllGroups" name="AllGroups"/> [% $user->gettext("Alle Gruppen") %]</label>&nbsp;
                                    </div>
                                    <span class="help-block">
                                        [% $user->gettext('Ohne Wiederholung sind die Vorlagen bei der manuellen Ticketerstellung verfügbar.<br/>Wählen Sie hier die Gruppen, für deren Benutzer die Vorlage sichtbar sein soll.') %]
                                        <br/>
                                        [% $user->gettext('Ist keine Gruppe gewählt, ist die Vorlage für alle Benutzer die Tickets aus Vorlagen erstellen können sichtbar.') %]

                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>

                    [% if !$user->hasRight(235) %]
                        <div class="card panel-info shadow-sm rounded" id="InterestItem" [% if ($type.type_name && !$Tools->FCS_InArray('interest', $show)) %]style="display:none;"[% /if %] >
                            <div class="card-header" role="tab" id="">
                                <div class="row">
                                    <div class="col-lg-11">
                                        <div class="row">
                                            <div class="col-4">
                                                <h4 class="card-title" id="">
                                                    [% if $hmcompany|strpos:"STADT HILDESHEIM" === false %]
                                                        [% $user->gettext('Interessierter Kreis') %]
                                                    [% else %]
                                                        [% $user->gettext('Ticketverantwortlicher') %]
                                                    [% /if %]
                                                </h4>
                                            </div>
                                            <div class="col-8">

                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-1 text-end">
                                        <a role="button" data-toggle="collapse" data-parent="#DEACTIVEleftAccordion" class="collapsed" href="#addInterestPanel" id="collapse_InterestItem" onclick="toggleCollapseIcon('collapse_InterestItem');" aria-expanded="false" aria-controls="collapseContact"><span class="fa fa-chevron-down" id="icon_collapse_InterestItem"></span></a>
                                    </div>
                                </div>
                            </div>
                            <div id="addInterestPanel" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingDevices">
                                <div class="card-body">
                                    <div  class="form-group row mb-3">
                                        <label class="control-label col-2" >[% $user->gettext('Benutzer') %]</label>
                                        <div class="col-10">
                                            <select [% if ($type.type_name && $Tools->FCS_InArray('interest', $require)) %]required[% /if %] name="InterestUserIDs[]" id="InterestSelect2" class="form-control"   style="width: 100%;" multiple="multiple">
                                                [% foreach from=$UsersForInterestCircle item=u %]
                                                    <option value="[% $u.user_id %]" [% if $Tools->FCS_InArray($u.user_id, $SelectedInterest) %]selected="selected"[% /if%]>[% $u.name %]</option>
                                                [% /foreach %]
                                            </select>
                                        </div>
                                    </div>


                                    <div  class="form-group row mb-3">
                                        <label class="control-label col-2" >[% $user->gettext('Gruppe') %]</label>
                                        <div class="col-10">
                                            <select name="InterestGroupIDs[]" id="InterestGroupSelect2" class="form-control"   style="width: 100%;" multiple="multiple">
                                                [% foreach from=$GroupsForInterestCircle item=g %]
                                                    <option value="[% $g.id %]" [% if $Tools->FCS_InArray($g.id, $SelectedGroupInterest) %]selected="selected"[% /if%]>[% $g.name %]</option>
                                                [% /foreach %]
                                            </select>
                                        </div>
                                    </div>


                                </div>
                            </div>
                        </div>
                    [% /if %]


                    <div class="card panel-info shadow-sm rounded" id="Template_Defaults">

                        <div class="card-header">
                            <h3 class="card-title">[% $user->gettext('Ticketzuordnung') %]</h3>
                        </div>
                        <div class="card-body" id="Template_Defaults_inner">

                    <div class="form-group row mb-3" [% if ($type.type_name && !$Tools->FCS_InArray('group', $show))%]style="display:none;"[% /if %]>
                        <label class="col-lg-4 control-label">[% $user->gettext('Gruppe') %]</label>
                        <div class="col-lg-8">
                            <select size="1" name="GroupIDs[]" id="group_id" class="form-control multiple2"  multiple="multiple" onchange="showSupporter(this);" style="width:25em;">
                                [% html_options options=$groups selected=$template.groups.ids %]
                            </select>
                        </div>
                    </div>


                    <div class="form-group row mb-3" [% if ($type.type_name && !$Tools->FCS_InArray('supporter', $show))%]style="display:none;"[% /if %]>
                        <label class="col-lg-4 control-label">[% $user->gettext('Supporter') %]</label>
                        <div class="col-lg-8">
                            <select name="SupporterIDs[]" id="user_id" class="form-control multiple2" multiple="multiple" style="width:100%;">
                                [% html_options options=$supporter selected=$template.supporters.ids %]
                            </select>
                        </div>
                    </div>

                    <div class="form-group row mb-3" [% if ($type.type_name && !$Tools->FCS_InArray('category', $show))%]style="display:none;"[% /if %]>
                        <label class="col-lg-4 control-label">[% $user->gettext('Kategorie 1') %]</label>
                        <div class="col-lg-8">
                            <div class="input-group">
                                <input type="hidden" name="CategoryID1" id="CategoryID1" value="[% $template.category1id %]">
                                <input type="text" class="form-control" size="30" maxlength="50" id="CategoryDescr1" readonly="readonly" value="[% $template.category1name %]">
                                <a href="JavaScript:void(0);" onclick="openCategory(1);" class="btn btn-outline-secondary"><span class="fa fa-pencil" title="[% $user->gettext('Kategorie ausw&auml;hlen') %]"></span></a>
                            </div>
                        </div>
                    </div>

                    <div class="form-group row mb-3" [% if ($type.type_name && !$Tools->FCS_InArray('category2', $show))%]style="display:none;"[% /if %]>
                        <label class="col-lg-4 control-label">[% $user->gettext('Kategorie 2') %]</label>
                        <div class="col-lg-8">
                            <div class="input-group">
                                <input type="hidden" name="CategoryID2" id="CategoryID2" value="[% $template.category2id %]">
                                <input type="text" class="form-control" size="30" maxlength="50" id="CategoryDescr2" readonly="readonly" value="[% $template.category2name %]">
                                <a href="JavaScript:void(0);" onclick="openCategory(2);" class="btn btn-outline-secondary"><span class="fa fa-pencil" title="[% $user->gettext('Kategorie ausw&auml;hlen') %]"></span></a>
                            </div>
                        </div>
                    </div>

                    <div class="form-group row mb-3">
                        <label class="col-lg-4 control-label">[% $user->gettext('Asset') %] </label>
                        <div class="col-lg-8">
                            <select id="SelectDeviceID" name="SelectDeviceIDs[]" class="form-control" multiple="multiple" style="width: 100%;">
                                [% foreach $assets as $asset %]
                                    <option selected="selected" value="[% $asset.deviceid %]">[% $asset.typename%] > [% $asset.devicename %]</option>
                                [% /foreach %]
                            </select>
                        </div>
                    </div>
                    <div class="form-group row mb-3">
                        <label class="col-lg-4 control-label">[% $user->gettext('Schlagworte') %] </label>
                        <div class="col-lg-8">
                            <select id="TagIDs" name="TagIDs[]" class="form-control" multiple="multiple" style="width: 100%;">
                                [% foreach $tags as $tag %]
                                    <option value="[% $tag.id %]"   [% if isset($TicketTemplateTags) %] [% if in_array($tag.id, $TicketTemplateTags) %] selected="selected" [% /if %][% /if %]>[% $tag.tag%]</option>
                                [% /foreach %]
                            </select>
                        </div>
                    </div>

                        <div class="form-group row mb-3 align-items-center">
                            <!-- Incident Impact -->

                            <div class="col-md-5 mb-2">


                                <label for="incident_impact_id" class="col-form-label">
                                    [% $user->gettext('Auswirkung') %]
                                </label>
                                <select name="incident_impact_id" id="incident_impact_id" class="form-control">
                                    <option value="" data-score="0">-- [% $user->gettext('Auswirkung wählen') %] --</option>
                                    [% foreach from=$IncidentImpacts item=impact %]
                                        <option value="[% $impact.ID %]" data-score="[% $impact.Score %]" [% if $template.incidentimpactid == $impact.ID %]selected[% /if %] title="[% $impact.Description %]">
                                            [% $impact.Score %] - [% $impact.Name %] <small>([% $impact.Description %])</small>
                                        </option>
                                    [% /foreach %]
                                </select>
                            </div>

                            <!-- Incident Urgency -->
                            <div class="col-md-5 mb-2">
                                <label for="incident_urgency_id" class="col-form-label">
                                    [% $user->gettext('Dringlichkeit') %]
                                </label>
                                <select name="incident_urgency_id" id="incident_urgency_id" class="form-control">
                                    <option value="" data-score="0">-- [% $user->gettext('Dringlichkeit wählen') %] --</option>
                                    [% foreach from=$IncidentUrgencies item=urgency %]
                                        <option value="[% $urgency.ID %]"  data-score="[% $urgency.Score %]" [% if $template.incidenturgencyid == $urgency.ID %]selected[% /if %] title="[% $urgency.Description %]">
                                            [% $urgency.Score %] - [% $urgency.Name %]
                                        </option>
                                    [% /foreach %]
                                </select>
                            </div>

                            <!-- Calculated Priority -->
                            <div class="col-md-2 mb-2">
                                <label for="incident_prio" class="col-form-label">
                                    [% $user->gettext('Berechnete Priorität') %]
                                </label>
                                <input type="text" name="incident_prio" id="incident_prio_display" class="form-control" value="[% $ticket.incidentprio %]" readonly />
                            </div>
                        </div>




                            </div>
                        </div>
                    [% if $Tools->FCS_Count($definedDefFields) %]
                        <div class="card panel-info shadow-sm rounded">
                            <div class="card-header" role="tab" id="headingDefData">
                                <a class="collapsed" role="button" data-toggle="collapse" data-parent="#DEACTIVEleftAccordion" href="#DefDataPanel" aria-expanded="false" aria-controls="">
                                    <div class="row">
                                        <div class="col-5">
                                            <h4 class="card-title">
                                                [% $user->gettext('Benutzerdefinierte Auswahllisten und Felder') %]
                                            </h4>
                                        </div>
                                        <div class="col-7">

                                        </div>
                                    </div>
                                </a>
                            </div>
                            <div id="DefDataPanel" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingDefData">
                                <div class="card-body">


[% foreach from=$finalFieldList item=field %]
                                                [% if !$field.UDF %]
                                                    <div class="mb-3 row">
                                                        <label class="col-sm-4 col-form-label" style="word-break: break-all;">
                                                            <span data-toggle="tooltip" data-bs-placement="bottom" data-bs-original-title="[% $field.comment %]">
                                                            [% if $field.field_type!='select' && $field.field_type!='radio' %][% $field.field_name %][% if $field.required == 1 %]<span style="color:red;">*</span>[% /if %][% /if %]
                                                        </span>
                                                    </label>
                                                    <div class="col-sm-8">
                                                        [% if $field.field_type=='text' %]

                                                            <input [% if $ticket.ticketstatusid == 3 %] readonly="readonly" disabled [% /if %][% if $field.field_validation.check=='dmY' %]value='[% if $field.value && $field.value != '' && $field.value != '1900-01-01' %][% $field.value|date_format:"%d.%m.%Y" %][% /if %]'[% elseif $field.field_validation.check=='dmYhm' %]value='[% if $field.value && $field.value != '' %][%$field.value|date_format:"%d.%m.%Y %H:%M" %][% /if %]'[% else %]value='[%$field.value %]'[% /if %] class="form-control [% if $field.field_validation.check=='dmY' %]datepicker[% elseif $field.field_validation.check=='dmYhm' %]datetimepicker[% /if %]" type="[% if $field.field_validation.check=='int' %]number[% elseif $field.password %]password[% else %]text[% /if %]"  name="field[[% $field.field_id %]]" id="field_[% $field.field_id %]" [% if $field.required == 1 %]required[% /if %]>
                                                        [% elseif $field.field_type == 'textarea' %]
                                                            <textarea [% if $ticket.ticketstatusid == 3 %] readonly="readonly" [% /if %] style="min-height: 160px;" class="form-control" id="textarea_[% $field.field_id %]" name="field[[% $field.field_id %]]" >[% $field.value %]</textarea>
                                                        [% elseif $field.field_type == 'radio' %]

                                                        [% elseif $field.field_type == 'checkbox' %]
                                                            <input type="checkbox" name="field[[% $field.field_id %]]" id="field_[% $field.field_id %]" [% if $field.value == 1 %]checked[% /if %]>[% $option %]<br>
                                                        [% elseif $field.field_type == 'select' %]

                                                        [% /if %]
                                                    </div>
                                                </div>
                                            [% else %]
                                                <div class="mb-3 row">
                                                    <label class="col-sm-4 col-form-label" style="word-break: break-all;">
                                                        <span data-toggle="tooltip" data-bs-placement="bottom" data-bs-original-title="[% $field.fielddescription %]">
                                                            [% $field.fieldname %][% if $field.required == 1 %] * [% /if %]
                                                        </span>
                                                    </label>
                                                    <div class="col-sm-8">
                                                        [% if $field.showasradio != 1 %]
                                                            <select data-live-search="true"data-show-subtext="true"  [% if $ticket.ticketstatusid == 3 %] disabled [% /if %] name="DefField_[% $field.userdeffieldid %][% if $field.multiple %][][% /if %]" id="userfield_[% $field.userdeffieldid %]" class="form-control  selectpicker" [% if $field.multiple %] multiple [% /if %] [% if $field.required %]required[% /if %]>
                                                                <option value="0" >[% $user->gettext('Keine') %]</option>
                                                                [% foreach from=$field.fieldvalues item=$value %]
                                                                    <option [% if $value.valuedescription %] data-subtext="[% $value.valuedescription %]"[% /if %] value="[% $value.userdeffieldvalueid %]" [% if $Tools->FCS_InArray($value.userdeffieldvalueid, $field.selectedvalue)  %]selected="selected"[% /if %]>[% $value.value %]</option>
                                                                [% /foreach %]
                                                            </select>
                                                        [% else %]
                                                            [% foreach from=$field.fieldvalues item=$value  name=userdefradio %]

                                                                <label><input type="radio" id="userfield_[% $field.userdeffieldid %]_[% $smarty.foreach.userdefradio.index %]" name="DefField_[% $field.userdeffieldid %]" value="[% $value.userdeffieldvalueid %]" [% if $Tools->FCS_InArray($value.userdeffieldvalueid, $field.selectedvalue)%]checked[% /if %]  [% if $ticket.ticketstatusid == 3 %] disabled [% /if %] > [% $value.value %]</label><br>

                                                            [% /foreach %]
                                                        [% /if %]
                                                    </div>
                                                </div>
                                            [% /if %]
                                        [% /foreach %]
[%*
                                    [% foreach from=$definedDefFields item=$field %]
                                        <div class="form-group row mb-3">
                                            <label class="col-sm-2 control-label">
                                                [% $field.fieldname %] [% if $field.required %] * [% /if %]
                                            </label>
                                            <div class="col-sm-10">
                                                <select name="DefField_[% $field.userdeffieldid %][% if $field.multiple %][][% /if %]" class="form-control [% if $field.multiple %]selectpicker[% /if %]" [% if $field.multiple %]multiple[% /if %]>
                                                    <option value="0">[% $user->gettext('Keine')%]</option>
                                                    [% foreach from=$field.fieldvalues item=$value %]
                                                        <option value="[% $value.userdeffieldvalueid %]"  [% if $Tools->FCS_InArray($value.userdeffieldvalueid, $field.selectedvalue)  %]selected="selected"[% /if %] [% if $value.valuedescription %]title="[%  $value.valuedescription %]"[% /if %]>[% $value.value %]</option>
                                                    [% /foreach %]
                                                </select>
                                            </div>
                                        </div>
                                    [% /foreach %]
*%]
                                </div>
                            </div>
                        </div>
                    [% /if %]
                    <div class="card panel-info shadow-sm rounded" id="cal_repeat">

                        <div class="card-header">
                            <h3 class="card-title">[%$user->gettext('Wiederholung')%]</h3>
                        </div>
                        <div class="card-body" id="repeat_form_inner">

                            <div class="form-group row mb-3">
                                <label class="col-lg-4 control-label">[% $user->gettext('Wiederholungsmodus') %]</label>
                                <div class="col-lg-8">
                                    <select size="1" onchange="ToggleTicketTitleRequired();
                                            show_cal_repeat(this[this.selectedIndex].value);" id="RepeatMode" name="RepeatMode" class="form-control multiple" style="width:100%">
                                        <option value="none" [% if $repeat_mode == "none" %]selected="selected"[% /if %]>[% $user->gettext("Keine Wiederholung") %]</option>
                                        <option value="one" [% if $repeat_mode == "one" %]selected="selected"[% /if %]>[% $user->gettext("Einmaliger Termin") %]</option>
                                        <option value="daily" [% if $repeat_mode == "daily" %]selected="selected"[% /if %]>[% $user->gettext("T&auml;glich") %]</option>
                                        <option value="weekly" [% if $repeat_mode == "weekly" %]selected="selected"[% /if %]>[% $user->gettext("W&ouml;chentlich") %]</option>
                                        <option value="monthly" [% if $repeat_mode == "monthly" %]selected="selected"[% /if %]>[% $user->gettext("Monatlich") %]</option>
                                        <option value="yearly" [% if $repeat_mode == "yearly" %]selected="selected"[% /if %]>[% $user->gettext("J&auml;hrlich") %]</option>
                                        <option value="everyxdays" [% if $repeat_mode == "everyxdays" %]selected="selected"[% /if %]>[% $user->gettext("Alle X Tage") %]</option>
                                    </select>
                                </div>
                            </div>




                            <div class="form-group row mb-3" id="repeat_form_interval">
                                <label class="col-lg-4 control-label">[% $user->gettext("Startzeit um") %]</label>
                                <div class="col-lg-8">
                                    <div class="input-group">
                                        <input type="text" class="form-control timepicker" maxlength="5" name="StartTimePoint" id="StartTimePoint" value="[% $template.starttimepoint %]" />
                                        <span class="input-group-text"> [% $user->gettext("Uhr") %]</span>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group row mb-3" id="repeat_form_one">
                                <label class="col-lg-4 control-label">[% $user->gettext("Ausf&uuml;hren am") %]</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control datetimepicker" maxlength="16" id="expires" name="expires" value="[% $template.onetimepoint|date_format:"%d.%m.%Y %H:%M" %]" />
                                </div>
                            </div>

                            <div class="form-group row mb-3" id="repeat_form_weekday">
                                <label class="col-lg-4 control-label">[% $user->gettext("Wiederholen am") %]</label>
                                <div class="col-lg-8">
                                    <label><input type="checkbox" value="1" name="Weekdays[1]" [% if $weekdays[1] == 1 %]checked="checked" [% /if %]/> [% $user->gettext("Mo") %]</label>&nbsp;
                                    <label><input type="checkbox" value="1" name="Weekdays[2]" [% if $weekdays[2] == 1 %]checked="checked" [% /if %] /> [% $user->gettext("Di") %]</label>&nbsp;
                                    <label><input type="checkbox" value="1" name="Weekdays[3]" [% if $weekdays[3] == 1 %]checked="checked" [% /if %] /> [% $user->gettext("Mi") %]</label>&nbsp;
                                    <label><input type="checkbox" value="1" name="Weekdays[4]" [% if $weekdays[4] == 1 %]checked="checked" [% /if %] /> [% $user->gettext("Do") %]</label>&nbsp;
                                    <label><input type="checkbox" value="1" name="Weekdays[5]" [% if $weekdays[5] == 1 %]checked="checked" [% /if %] /> [% $user->gettext("Fr") %]</label>&nbsp;
                                    <label><input type="checkbox" value="1" name="Weekdays[6]" [% if $weekdays[6] == 1 %]checked="checked" [% /if %] /> [% $user->gettext("Sa") %]</label>&nbsp;
                                    <label><input type="checkbox" value="1" name="Weekdays[0]" [% if $weekdays[0] == 1 %]checked="checked" [% /if %] /> [% $user->gettext("So") %]</label>&nbsp;
                                </div>
                            </div>

                            <div class="form-group row mb-3" id="repeat_form_month">
                                <label class="col-lg-4 control-label">[% $user->gettext("Wiederholen am") %]</label>
                                <div class="col-lg-8">

                                    <select size="1" name="DayOfMonth" id="DayOfMonth" class="form-control multiple" style="width: 100%">
                                        <option value="99" [% if $template.dayofmonth == 99 %]selected="selected"[% /if %]>[% $user->gettext("Letzten des Monats") %]</option>
                                        [% foreach from=$days item=day %]<option value="[% $day.daynumber %]" [% if $day.daynumber == $template.dayofmonth %]selected="selected"[% /if %]>[% $day.daynumber %]. des Monats</option>[% /foreach %]
                                    </select>
                                </div>
                            </div>

                            <div class="form-group row mb-3" id="repeat_form_year">
                                <label class="col-lg-4 control-label">[% $user->gettext("Im Monat") %]</label>
                                <div class="col-lg-8">
                                    <select size="1" name="MonthOfYear" id="MonthOfYear" class="form-control multiple" style="width: 100%">
                                        <option value="1" [% if 1 == $template.monthofyear %]selected="selected"[% /if %]>[% $user->gettext("Januar") %]</option>
                                        <option value="2" [% if 2 == $template.monthofyear %]selected="selected"[% /if %]>[% $user->gettext("Februar") %]</option>
                                        <option value="3" [% if 3 == $template.monthofyear %]selected="selected"[% /if %]>[% $user->gettext("M&auml;rz") %]</option>
                                        <option value="4" [% if 4 == $template.monthofyear %]selected="selected"[% /if %]>[% $user->gettext("April") %]</option>
                                        <option value="5" [% if 5 == $template.monthofyear %]selected="selected"[% /if %]>[% $user->gettext("Mai") %]</option>
                                        <option value="6" [% if 6 == $template.monthofyear %]selected="selected"[% /if %]>[% $user->gettext("Juni") %]</option>
                                        <option value="7" [% if 7 == $template.monthofyear %]selected="selected"[% /if %]>[% $user->gettext("Juli") %]</option>
                                        <option value="8" [% if 8 == $template.monthofyear %]selected="selected"[% /if %]>[% $user->gettext("August") %]</option>
                                        <option value="9" [% if 9 == $template.monthofyear %]selected="selected"[% /if %]>[% $user->gettext("September") %]</option>
                                        <option value="10" [% if 10 == $template.monthofyear %]selected="selected"[% /if %]>[% $user->gettext("Oktober") %]</option>
                                        <option value="11" [% if 11 == $template.monthofyear %]selected="selected"[% /if %]>[% $user->gettext("November") %]</option>
                                        <option value="12" [% if 12 == $template.monthofyear %]selected="selected"[% /if %]>[% $user->gettext("Dezember") %]</option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group row mb-3" id="repeat_form_everyxdays">
                                <label class="col-lg-4 control-label">[% $user->gettext("Wiederholen alle") %]</label>
                                <div class="col-lg-3">
                                    <div class="input-group">
                                        <input type="text" name="repeatdays" id="repeatdays" class="form-control" maxlength="5" value="[% $template.repeatdays %]">
                                        <span class="input-group-text"> [% $user->gettext("Tage") %]</span>
                                    </div>
                                </div>
                                <div class="col-lg-5">

                                    <div class="input-group">
                                        <span class="input-group-text"> [% $user->gettext("Nächste Ausführung am") %]</span>
                                        <input type="text" name="firstexecutiondate" id="firstexecutiondate" class="form-control datetimepicker" maxlength="16" size="16" value="[% $template.firstexecutiondate %]">
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>

                <div class="col-md-12">
                <div class="card panel-info shadow-sm rounded" id="Template_Documents">

                    <div class="card-header">
                        <h3 class="card-title">[%$user->gettext('Dokumente')%]</h3>
                    </div>
                    <div class="card-body">

                            <!--525-->
                            [% if $user->hasRight(10) %]
                                <div class="col-sm-12" [% if ($fields && !$Tools->FCS_InArray('document', $fields.show)) %]style="display:none;"[% /if %]>
                                    <div class="form-group row mb-3">
                                        <label  class="control-label col-sm-2" for="UploadFile">[% $user->gettext('Dokument zufügen') %]:</label>
                                        <div class="col-sm-10">
                                            <div id="TemplateDropzoneField" class="well" style="padding:0px; border: solid 1px; border-color:cornflowerblue">
                                                <div class="dz-message">
                                                    <h4>  [% $user->gettext('Dateien zum Upload hier hereinziehen oder klicken zur Dateiauswahl') %]</h4>
                                                </div>
                                                <div class="fallback">
                                                    <input name="UploadFile" id="UploadFile" type="file" [% if $sessions.uploadfile %]value="[% $sessions.uploadfile %]"[% /if %] style="width:100%; height:5em;"/>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-sm-12">
                                            <img id="thumbnail" style="width:12em"/>
                                        </div>
                                        <div id="TemplateAttachmentList" class="col-sm-12">

                                        </div>
                                    </div>
                                </div>
                            [% /if %]

                    </div>
                </div>
                    </div>


            </div>
        </div>
    </div>
</div>
</div>
</form>





<div id="dialog-category" style="display:none;" width="500" hight="500"></div>
[%*
<div id="comboboxlist">
<div id="comboboxres"></div>
<div id="comboboxstatus">&nbsp;</div>
</div>

<div id="comboboxlist2" style="height:100px !important;">
<div id="comboboxres2" style="height:74px !important;"></div>
<div id="comboboxstatus2">&nbsp;</div>
</div>


*%]
<script>
    $(document).ready(function ()
    {
        var selectedOptions = $("#visibleforgroups :selected").length;
        var allOptions = $("#visibleforgroups option").length;

        if (selectedOptions == allOptions)
        {
            $("#chkAllGroups").prop('checked', true);
            $("#chkNoGroups").prop('checked', false);
            $("#chkAllGroups").prop('disabled', true);
        } else if (selectedOptions == 0)
        {
            $("#chkAllGroups").prop('checked', false);
            $("#chkNoGroups").prop('checked', true);
            $("#chkNoGroups").prop('disabled', true);
        } else
        {
            $("#chkAllGroups").prop('checked', false);
            $("#chkNoGroups").prop('checked', false);
            $("#chkAllGroups").prop('disabled', false);
            $("#chkNoGroups").prop('disabled', false);
        }

        $.get('index.php?module=tickettype&event=getIconsAsJSON', function (data) {
            console.log(data);
            $('#icon').select2({theme: 'bootstrap-5',
                data: JSON.parse(data),
                templateResult: formatIcon,
                templateSelection: formatIcon
            });
            $('#icon').val("[% $template.iconid %]").trigger('change');
        });
        $("#TemplateAttachmentList").load("index.php?module=upload&event=showAttachmentsForTemplate&tickettemplateid=[% $template.tickettemplateid %]");
    });
    $('.selectpicker').selectpicker();
    NoSupporter = "[% $user->gettext('Keine Supporter gefunden') %]";
    NoContact = "[% $user->gettext('Kein Kontakt angegeben') %]";
    ShortDescrErr = "[% $user->gettext("Es wurde keine Kurzbeschreibung angegeben(min. 4 Zeichen)") %]";
    TitleErr = "[% $user->gettext("Für die Vorlage wurde kein Titel angegeben") %]";
    var StartTimePointErr = "[% $user->gettext("Bitte geben sie die Uhrzeit in einem gültigen Format (HH:MM o. HHMM) an.") %]";

    //groups        = [[% foreach from=$groups item=group key=groupkey %][[% $groupkey %], '[% $group %]'],[% /foreach %]];

    var groups = new Array();
    [% foreach from=$groups item=group key=groupkey %]
    groups.push(
            new Array([% $groupkey %], '[% $group %]')
            );
    [% /foreach %]

    strEmptyGroup = "[% $user->gettext('Keine Gruppe ausgew&auml;hlt') %]";


    show_cal_repeat("[% $repeat_mode %]");

    function openCategory(nr) {
        var url = "index.php?module=category&class=select&id=" + nr + "&cid=" + $("#CategoryID" + nr).val() + "&tickettype=" + $("#type_id").val();
        $("#dialog-category").fancybox({
            title: 'Kategorie wählen',
            href: url,
            type: 'ajax',
            minWidth: 300,
            minHeight: 200,
            autoResize: true
        }).trigger("click");
    }

    $("#chkNoGroups").click(function (e)
    {
        if (this.checked)
        {
            $("#chkAllGroups").prop('checked', false);
            $('#visibleforgroups option').prop('selected', false);
            $("#chkNoGroups").prop('disabled', true);
            $("#chkAllGroups").prop('disabled', false);
        }

        $('#visibleforgroups').multiselect("refresh");
    });

    $("#chkAllGroups").click(function (e)
    {
        if (this.checked)
        {
            $("#chkNoGroups").prop('checked', false);
            $('#visibleforgroups option').prop('selected', true);
            $("#chkAllGroups").prop('disabled', true);
            $("#chkNoGroups").prop('disabled', false);
        }
        $('#visibleforgroups').multiselect("refresh");
    });

    $('#visibleforgroups').on('change', function (e) {
        var selectedOptions = $("#visibleforgroups :selected").length;
        var allOptions = $("#visibleforgroups option").length;

        if (selectedOptions == allOptions)
        {
            $("#chkAllGroups").prop('checked', true);
            $("#chkNoGroups").prop('checked', false);
            $("#chkAllGroups").prop('disabled', true);
        } else if (selectedOptions == 0)
        {
            $("#chkAllGroups").prop('checked', false);
            $("#chkNoGroups").prop('checked', true);
            $("#chkNoGroups").prop('disabled', true);
        } else
        {
            $("#chkAllGroups").prop('checked', false);
            $("#chkNoGroups").prop('checked', false);
            $("#chkAllGroups").prop('disabled', false);
            $("#chkNoGroups").prop('disabled', false);
        }

    });



    $("#group_id, #visibleforgroups").multiselect({
        buttonClass: 'form-select',
        buttonWidth: '100%',
        templates: {
            button: '<button type="button" class="multiselect dropdown-toggle" data-bs-toggle="dropdown"><span class="multiselect-selected-text"></span></button>',
        },
        selectedList: 2,
        nonSelectedText: '[% $user->gettext("Gruppen wählen") %]',
        selectedText: '# [% $user->gettext("Gruppen gewählt") %]',
        checkAllText: '[% $user->gettext("Alle") %]',
        uncheckAllText: '[% $user->gettext("Keine") %]',
        header: true,
        multiple: true,
        enableCaseInsensitiveFiltering: true
    });
        $("#user_id").multiselect({
        enableCaseInsensitiveFiltering: true,
        buttonWidth: '100%',
        buttonClass: 'form-select',
        templates: {
            button: '<button type="button" class="multiselect dropdown-toggle" data-bs-toggle="dropdown"><span class="multiselect-selected-text"></span></button>',
        },
        selectedList: 2,
        nonSelectedText: '[% $user->gettext("Supporter wählen") %]',
        selectedText: '# [% $user->gettext("Supporter gewählt") %]',
        checkAllText: '[% $user->gettext("Alle") %]',
        uncheckAllText: '[% $user->gettext("Keine") %]',
        header: true,
        multiple: true
    });


    $(".datetimepicker").datetimepicker({
        currentText: 'Jetzt',
        closeText: 'OK',
        timeText: 'Zeit',
        hourText: 'Stunde'
    });

    $('.timepicker').timepicker({
        currentText: 'Jetzt',
        closeText: 'OK',
        timeText: 'Zeit',
        hourText: 'Stunde'
    });
    $(".dialog_contactlist")
            .fancybox({
                type: 'iframe',
                autoSize: false,
                autoResize: true,
                autoCenter: true,
                beforeLoad: function () {
                    this.width = 1300;
                    this.height = 600;
                }
            });


    function buildSupporterList(xmldoc)
    {
        var el = document.getElementById("user_id");
        if (el) {

            //var UserID = el.options[el.options.selectedIndex].value;
            var UserID = [];
            UserID = $('#user_id').val();
            el.length = 0;
            var users = xmldoc.getElementsByTagName("user");
            if (users.length > 0) {
                for (i = 0; i < users.length; i++) {
                    //if (users[i].getAttribute('id') == UserID) {
                    if (UserID != null && UserID.indexOf(users[i].getAttribute('id')) >= 0) {
                        NewEntry = new Option(users[i].getAttribute('name'), users[i].getAttribute('id'), false, true);
                    } else {
                        NewEntry = new Option(users[i].getAttribute('name'), users[i].getAttribute('id'), false, false);
                    }
                    el.options[el.length] = NewEntry;
                }
            }
            $("#user_id").multiselect("destroy").multiselect({
                enableCaseInsensitiveFiltering: true,
                buttonWidth: '100%',
                buttonClass: 'form-select',
                templates: {
                    button: '<button type="button" class="multiselect dropdown-toggle" data-bs-toggle="dropdown"><span class="multiselect-selected-text"></span></button>',
                },
                nonSelectedText: '[% $user->gettext("Supporter wählen") %]',
                selectedText: '# [% $user->gettext("Supporter gewählt") %]',
                checkAllText: '[% $user->gettext("Alle") %]',
                uncheckAllText: '[% $user->gettext("Keine") %]',
                selectedList: 2,
                header: true,
                multiple: true
            });
        }
    }
    function showSupporter(el)
    {
        var GroupIDs = $(el).val();
        makeHttpRequest("index.php?module=user&event=AJAXSupporterList&gid=" + GroupIDs, "buildSupporterList", true);
    }

    $("#removeContact").on("click", function (e) {
        $("#contact").val(null).trigger('change');
        $("#contact_id").val('');
    });

function initSelect2Contact(){
    $('#contact').select2({theme: 'bootstrap-5',
        language: ts_lang,
        ajax: {
            url: "index.php?module=contact&event=getJsonContacts",
            dataType: 'json',
            delay: 250,
            data: function (params) {
                return {
                    q: params.term, // search term
                    page: params.page,
                    cid: $("#contact_id").val()
                };
            },
            processResults: function (data) {
                return {
                    results: data.items
                };
            }
        },
        escapeMarkup: function (markup) {
            return markup;
        }
    }).on("select2:select", function (e) {
        var data = e.params.data;
        if (data && data.id != $("#contact_id").val()) {
            $("#contact_id").val(data.id);

        }
    });
}

function initSelect2Assets(){

    $("#SelectDeviceID").select2({
        theme: 'bootstrap-5',
        language: ts_lang,
        minimumInputLength: 2,
        ajax: {
            url: "index.php?module=tickettemplate&event=getDeviceJSON&[% if $template.tickettemplateid %]tid=[% $template.tickettemplateid %][% else %]tid=0[% /if %]",
            dataType: 'json',
            delay: 250,
            data: function (params) {
                return {
                    q: params.term, // search term
                    page: params.page
                };
            },
            processResults: function (data) {
                //console.log(data);
                return {
                    results: data.results
                };
            }
        }
    });


}

$(document).ready(function () {
    let tries = 0;
    const timer = setInterval(function () {
        const $contact = $('#contact');
        const $SelectDeviceID = $('#SelectDeviceID');

        if ($contact.length && $contact.is(':visible') && $SelectDeviceID.length && $SelectDeviceID.is(':visible')) {
            initSelect2Contact();
            initSelect2Assets();
            clearInterval(timer);
        }

        tries++;
        if (tries > 20) {
            clearInterval(timer);
        }
    }, 100);
});






// Re-init Select2 only when the interest block becomes visible

// If the panel is already visible on page load (class="in" or style visible)
if ($('#addInterestPanel').hasClass('in') || $('#InterestItem').is(':visible')) {
    setTimeout(function() {
        $('#addInterestPanel').trigger('shown.bs.collapse');
    }, 300); // small delay helps after DOM settle
}

    function formatIcon(icon) {

        if (!icon.id || icon.id == 0) {
            return icon.text;
        }

        var $icon = $(
                '<span><img src="index.php?module=upload&class=download&event=ShowImage&name=' + icon.path + '" style="max-width:22px;"  /> ' + icon.text + '</span>'
                );

        return $icon;
    }




    Dropzone.options.myDropzone = {

        init: function () {

            this.on("queuecomplete", function (file) {
                this.removeAllFiles();
                $("#TemplateAttachmentList").load("index.php?module=upload&event=showAttachmentsForTemplate&tickettemplateid=[% $template.tickettemplateid %]");
            });
        }
    };

    $("div#TemplateDropzoneField").dropzone({
        url: "index.php?module=upload&event=uploadDocs&tickettemplateid=[% $template.tickettemplateid %]&fortemplate=1",
        init: function () {
            this.on("queuecomplete", function (file) {
                this.removeAllFiles();
                $("#TemplateAttachmentList").load("index.php?module=upload&event=showAttachmentsForTemplate&tickettemplateid=[% $template.tickettemplateid %]");
            });
        }
    });
    function RemoveAttachment(id) {
        $.get("index.php?module=upload&event=AJAXUploadList&tickettemplateid=[% $template.tickettemplateid %]&id=" + id);
        $("#TemplateAttachmentList").load("index.php?module=upload&event=showAttachmentsForTemplate&tickettemplateid=[% $template.tickettemplateid %]");
    }
</script>
 <script  src="includes/js/quill2.0.3/hm-quill.js"></script>
<script>


    $(".dialog_ticketlist").fancybox({
        type: 'iframe',
        autoSize: false,
        autoResize: true,
        autoCenter: true,
        beforeLoad: function () {
            this.width = 1300;
            this.height = 600;
        }
    });


$(document).ready(function () {
    function updatePrio() {
        let impactScore = parseInt($('#incident_impact_id option:selected').data('score')) || 0;
        let urgencyScore = parseInt($('#incident_urgency_id option:selected').data('score')) || 0;

        let prio = Math.floor((impactScore + urgencyScore) / 2);

        $('#incident_prio_display').val(prio || '');
    }


    $('#incident_impact_id, #incident_urgency_id').on('change', updatePrio);

    // Initialberechnung bei bereits gesetzten Werten (z. B. bei Edit-Formularen)
    updatePrio();

        $("#InterestSelect2").select2({theme: 'bootstrap-5'});
    $("#InterestGroupSelect2").select2({theme: 'bootstrap-5'});
    $("#TagIDs").select2({theme: 'bootstrap-5'});


});
</script>

<!-- Component Ticket end -->
