<script type="text/javascript">

    function switchPage(pos) {
    document.getElementById("pos").value = pos;
    submitForm();
    }

</script> 

<style>
    .table th{
        cursor: pointer;
    }
</style>
[% if $message %]
    <script>
        noty({
        text: "[% $message %]",
        type: 'success',
        timeout: notifyTimeout
        });
    </script>
[% /if %]
<form action="" method="post" name="hm" onsubmit="return false" id="hm" enctype="multipart/form-data" class="form-horizontal form-label-left" >
    <input type="hidden" id="sort" name="sort" value="[% $sort %]" />
    <input type="hidden" id="sortorder" name="sortorder" value="[% $sortorder %]" />
    <input type="hidden" id="message" name="message" value="0" />
    <div class="card panel-fcs-border shadow-sm">
        <div class="card-header">
            <span class="fcs-card-title h2">[% $user->gettext('Tickettyp') %]</span>
        </div>
        <div class="card-body">
            <div class="card panel-info shadow-sm rounded">
                <div class="card-body">
                    <div class="row">
                        <div class="col-lg-6" style="padding-left: 30px;">
                            <div class="form-group row mb-3">
                                <label class="control-label col-sm-2">
                                    [% $user->gettext('Eintr&auml;ge pro Seite') %]
                                </label>
                                <div class="col-sm-10">
                                    <select  name="entries_per_page" style="width:10%;" onchange="document.hm.submit();" class="form-control">
                                        <option value="10" [% if $entries_per_page == 10 %]selected="selected"[% /if %]>10</option>
                                        <option value="20" [% if $entries_per_page == 20 %]selected="selected"[% /if %]>20</option>
                                        <option value="50" [% if $entries_per_page == 50 %]selected="selected"[% /if %]>50</option>
                                        <option value="100" [% if $entries_per_page == 100 %]selected="selected"[% /if %]>100</option>
                                    </select>&nbsp;&nbsp;&nbsp;
                                    <input type="hidden" name="pos" value="[% $pos %]" id="pos">
                                </div>

                            </div>
                        </div>
                        <div class="col-lg-6 text-end">
                            [% if $user->Security->TicketTemplate && ($user->hasRight(36) || $user->hasRight(810)) %]
                                <div class="btn-group">
                                    <a class="btn btn-outline-primary"  href="index.php?module=tickettype&event=create" >[% $user->gettext('Neuer Tickettyp') %]</a>
                                </div>
                            [% /if %]         
                        </div>
                    </div>
                </div>
            </div>

            <div class="card panel-info shadow-sm rounded">
                <div class="card-header">
                    <span class="fcs-card-title h3">
                        [% $user->gettext('Standard Tickettyp')%] <span class="fa fa-info" title="[% $user->gettext('Diese Tickettypen sind im System miteinbezogen und können nicht gelöscht werden')%]"></span>
                    </span>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                                <tr class="fields>">
                                    <th class="" id="">[% $user->gettext('Icon') %]</th>
                        <th class="sort" id="">[% $user->gettext('Name') %]</th>
                        <th></th>
                        </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><img title="[% $user->gettext('Standard Ticket') %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STANDARD_ICON %]"  height="16"></td>
                                <td>[% $smarty.const.STANDARD_NAME %]</td>                                  
                                <td style="text-align:center !important;">                                                                               
                                    <a href="index.php?module=tickettype&event=updateStandard&type=ticket" class="btn btn-outline-secondary"><span class="fa fa-pencil" title="[% $user->gettext('Bearbeiten') %]"></span></a>
                                </td>
                            </tr>

                            <tr>
                                <td><img title="[% $user->gettext('Workflow Aktivität') %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.WF_ICON %]"  height="16"></td>
                                <td>[% $smarty.const.WF_NAME %]</td>
                                <td style="text-align:center !important;">
                                    <a href="index.php?module=tickettype&event=updateStandard&type=workflow" class="btn btn-outline-secondary"><span class="fa fa-pencil" title="[% $user->gettext('Bearbeiten') %]"></span></a>
                                </td>
                            </tr>

                            <tr>
                                <td><img title="[% $user->gettext('Ticketentwurf') %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.TICKETDRAFT_ICON %]"  height="16"></td>
                                <td>[% $smarty.const.TICKETDRAFT_NAME %]</td>
                                <td style="text-align:center !important;">
                                    <a href="index.php?module=tickettype&event=updateStandard&type=ticketdraft" class="btn btn-outline-secondary"><span class="fa fa-pencil" title="[% $user->gettext('Bearbeiten') %]"></span></a>
                                </td>
                            </tr>
                            <tr>
                                <td><img title="[% $user->gettext('Story') %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STORY_ICON %]"  height="16"></td>
                                <td>[% $smarty.const.STORY_NAME %]</td>
                                <td style="text-align:center !important;">
                                    <a href="index.php?module=tickettype&event=updateStandard&type=story" class="btn btn-outline-secondary"><span class="fa fa-pencil" title="[% $user->gettext('Bearbeiten') %]"></span></a>
                                </td>
                            </tr>

                        </tbody>
                        </table>
                </div>
            </div>
        </div>
        <div class="card panel-info shadow-sm rounded">
            <div class="card-header">
                <span class="fcs-card-title h3">
                    [% $entries %]
                    [% if $entries > 1 %] 
                        [% $user->gettext('Tickettypen') %]
                    [% else %]
                        [% $user->gettext('Tickettyp') %]
                    [% /if %]
                    [% $user->gettext('gefunden') %]
                </span>
            </div>

            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                            <tr class="fields>">
                                <th class="" id="">[% $user->gettext('Icon') %]</th>
                                <th class="sort" id="typename">[% $user->gettext('Name') %]</th>
                                <th class="sort" id="typedescription">[% $user->gettext('Beschreibung') %]</th>
                                <th class="sort" id="typecreateddate">[% $user->gettext('Erstellt am') %]</th>
                                <th class="sort" id="typecreateduser">[% $user->gettext('Ersteller') %]</th>
                                <th class="sort" id="typeupdateddate">[% $user->gettext('Letzte Änderung am') %]</th>
                                <th class="sort" id="typeupdateduser">[% $user->gettext('Letzter Bearbeiter') %]</th>
                                <th class="sort" id="numberofticket" title="[% $user->gettext('Anzahl Tickets mit diesem Type')%]">[% $user->gettext('Anzahl Tickets') %]</th>
                                    <th>[% $user->gettext('Aktiv') %]</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                [% foreach from=$typeList item=type %]
                                    <tr [% if $type.type_id == $smarty.const.STANDARDTICKETTYPE %]style="background-color:yellow;"[% /if%]>
                                <td>[% if !$type.icon_path %]<img title="[% $user->gettext('Typ ist noch kein Icon zugewiesen') %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.NO_ICON %]"  height="16">[% else %]<img title="[% $icon.icon_path %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $type.icon_path %]"  height="16">[% /if %]</td>
                                <td>[% $type.type_name %][% if $type.type_id == $smarty.const.STANDARDTICKETTYPE %] (Standard Tickettyp)[% /if%]</td>
                                <td>[% $type.type_description %]</td>
                                <td>[% $type.created_date|date_format:"%d.%m.%Y %H:%M" %]</td>
                                <td>[% $type.created_name %]</td>
                                <td>[% $type.updated_date|date_format:"%d.%m.%Y %H:%M" %]</td>
                                <td>[% $type.updated_name %]</td>
                                <td>
                                    [% $type.ticketnum %]

                                </td>
                                <td> 
                                    [% if $type.active %]
                                        <span class="fa fa-check" style="color:green;"></span>
                                    [% else %]
                                        <span class="fa fa-times" style="color:red;"></span>
                                    [% /if %]
                                </td>

                                        <td style="text-align:center !important;">
                                            [% if $form.isempty %]
                                                <a href="javascript:removeForm('[% $form.formid %]');" class="btn btn-outline-secondary"><span class="fa fa-trash" title="[% $user->gettext('L&ouml;schen') %]"></span></a>
                                    [% elseif $form.published == 1 %]                            
                                        <a href="javascript:disableForm('[% $form.formid %]');" class="btn btn-outline-secondary"><span class="fa fa-times" title="[% $user->gettext('Das Formular enthält Daten - Deaktivieren') %]"></span></a>
                                            [% /if %]                            
                                            [%*
                                            <a href="index.php?module=formwizard&event=displayForm&formid=[% $form.form_id %]" class="btn btn-outline-secondary openInLargeModal"><span class="fa fa-search" title="[% $user->gettext('Vorschau') %]"></span></a>
                                            *%]
                                            [% if $type.hasTicket != 1%]
                                            <a href="index.php?module=tickettype&event=update&id=[% $type.type_id %]" class="btn btn-outline-secondary"><span class="fa fa-pencil" title="[% $user->gettext('Bearbeiten') %]"></span></a>
                                            <a href="javascript:deleteType([% $type.type_id %])" class="btn btn-outline-secondary"><span class="fa fa-trash" title="[% $user->gettext('Löschen') %]"></span></a>
                                            [% else %]
                                                <a href="index.php?module=tickettype&event=update&id=[% $type.type_id %]" class="btn btn-outline-secondary"><span class="fa fa-pencil" title="[% $user->gettext('Bearbeiten') %]"></span></a>
                                                    [% /if %]
                                                </td>
                                            </tr>
                                            [% foreachelse %]
                                                <tr class="even">
                                                    <td colspan="9" style="text-align:center !important">[% $user->gettext('Es wurde keine Tickettypen gefunden...') %]</td>
                                                </tr>
                                                [% /foreach %]
                                                    </tbody>
                                            </table>

                                        </div>
                                        <div class="col-lg-12 col-sm-12 hidden-sm hidden-xs">
                                            <div class="col-lg-6 col-sm-6"></div>
                                            <div class="col-lg-6 col-sm-6 text-end">
                                                [% $Paging %]
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div> 
                        </div>
                    </form>

                    <script>
                        var current_sort = $("#sort").val();
                        var current_sortorder = $("#sortorder").val();
                        showSortIcon();
                        $(".sort").on("click", function (e) {
                        var sort = $(this).attr('id');
                        var sortorder = 'asc';
                        if (current_sort === sort) {
                        if (current_sortorder === 'asc') {
                        sortorder = 'desc';
                        } else {
                        sortorder = 'asc';
                        }
                        }
                        $("#sort").val(sort);
                        $("#sortorder").val(sortorder);
                        submitForm();
                        })

                                function deleteType(id){
                                bootbox.confirm("[% $user->gettext('Tickettyp wirklich löschen?') %]", function(result){
                                if(result){
                                    $.post('index.php?module=tickettype&event=deleteType&id='+id, function(data){
                                        if(data == 1){
                                            window.location.href = window.location.href;
                                        }
                                    })
                                }
                            })
                         }

                        function showSortIcon() {
                            var content = $("#" + current_sort).html();
                           
                            if (current_sortorder == 'desc') {
                                content += '<span class="fa fa-chevron-down"></span>';

                            } else {
                                content += '<span class="fa fa-chevron-up"></span>';
                            }
                            $("#" + current_sort).html(content);
                        }
    /*
                        function setActive(ticketID){
                            var isChecked = 0;
                            if($('#checbox_active_' + ticketID).is(":checked")){ isChecked = 1};
                            $.post('index.php?module=tickettype&event=setTypeAsActive', {id: ticketID, active: isChecked}, function(data){
                                 noty({
                                     text: "[% $user->gettext('Tickettyp aktualisiert.') %]",
                                     type: 'success',
                                     timeout: notifyTimeout
                                });
                                })
                        }
                        */
                    </script>
