<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>


<div class="card panel-info shadow-sm rounded" style="min-height: 10em;">
    <div class="card-header">
        <h3 class="card-title">[% $user->gettext('Mailempfänger wählen') %]</h3>
    </div>
    <div class="card-body">
        <form action="index.php?module=ticket&event=emaillist&tid=[% $tid %]" method="post" id="hm" class="form form-horizontal" name="hm">
            <input type="hidden" name="tid" value="[% $tid %]" />
            <input type="hidden" name="action" value="show" id="action" />

            <div class="form-group row mb-3">

                <select name="eMailcontact[]" class="form-control" id="eMailcontact" multiple="multiple" >
                    [% foreach from=$Contacts item=contact %]
                        <option value="[% $contact.contact_id %]">[% $contact.name %] &lt;[% $contact.email %]&gt; [%* [% if $contact.lastusedate %]([% $contact.lastusedate|date_format:"%d.%m.%Y" %])[% /if %] [% if $contact.countuses%]([% $contact.countuses %])[% /if %] *%]</option>
                    [% /foreach %]
                </select>

            </div>


            <input type="button" class="btn btn-outline-primary" value="[% $user->gettext('Senden') %]" onclick="confirmSending();
                    window.parent.$('#myIFrameModal').modal('hide');" />
            <input type="button" class="btn btn-outline-secondary" value="[% $user->gettext('Abbrechen') %]" onclick="window.parent.$('#myIFrameModal').modal('hide');" />

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


<script>


    function confirmSending() {
        var Text = "[% $user->gettext('Ticketdaten per eMail an folgende Adresse(n) senden?') %]";
        if (document.hm.eMailcontact) {
            var List = document.hm.eMailcontact;

            var count = 0;
            var i1 = 0;
            var iAnz = 0;
            for (var i = 0; i <= List.length - 1; i++)
            {
                i1 = i + 1;
                if (List.options[i].selected == true)
                {
                    count++;
                    Text += "\n";
                    Text += List.options[i].text;
                    iAnz++;
                }
            }
            if (count) {
                //bootbox.confirm(Text, function (result) {
                //    if (result) {
                document.getElementById('action').value = 'sentto';
                document.getElementById('hm').submit();
                $('#myIFrameModal').modal('hide');
                //    }
                //})
            } else {
                alert("[% $user->gettext('Keine Empfänger ausgewählt!') %]");
            }

        }
    }

    $('#eMailcontact').select2({theme: 'bootstrap-5'});

</script>

