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

    [% if $servicelvl.id > 0 %]
        <input type="hidden" name="id" value="[% $servicelvl.id %]" />
    [% /if %]

    <div class="card panel-fcs-border shadow-sm">
        <div class="panel card-header">
            <span class="fcs-card-title h2">[% $user->gettext('Servicelevel')%]</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 $servicelvl.id > 0 %][% $user->gettext('Servicelevel bearbeiten') %][% else %][% $user->gettext('Servicelevel anlegen') %][% /if %]</span>
                        </div>
                        <div class="col-lg-6 text-end">
                            <div class="btn-group">
                                <input type="submit" value="[% $user->gettext('Speichern') %]" class="btn btn-outline-primary" />
                                <input type="button" value="[% $user->gettext('Zur&uuml;ck') %]" class="btn btn-outline-secondary" onclick="document.location.href = 'index.php?module=services&amp;class=servicelvl';" />
                                [% if $servicelvl.id > 0 %]
                                    <input type="button" value="[% $user->gettext('Kopieren') %]" class="btn btn-outline-secondary" onclick="document.location.href = 'index.php?module=services&amp;class=servicelvl&amp;event=copy&amp;id=[% $servicelvl.id %]';" />
                                [% /if %]
                            </div>
                        </div>
                    </div>
                </div>

                <div class="card-body">
                    <div class="form-group row mb-3">
                        <label class="control-label col-lg-2" for="title">
                            [% $user->gettext('Titel') %]
                        </label>
                        <div class="col-lg-10">
                            <input type="text" name="title" id="title" class="form-control" required value="[% $servicelvl.title %]">       
                        </div>
                    </div>

                    <div class="form-group row mb-3">
                        <label class="control-label col-lg-2" for="prioid">
                            [% $user->gettext('Priorit&auml;t') %]
                        </label>
                        <div class="col-lg-4">
                            <select name="prioid" class=" form-group row mb-3 select2" style="width: 40%;">
                                [% foreach from=$Priorities item=Priority key=PrioID %]
                                    <option value="[% $PrioID %]" [% if $PrioID == $servicelvl.prioid %]selected="selected"[% /if %] >[% $Priority %]</option>
                                [% /foreach %]
                            </select>  
                        </div>
                        <label class="control-label col-lg-2" for="desiretime">
                            [%$user->gettext('Fälligkeitszeit')%]
                        </label>
                        <div class="col-lg-4">
                            <div class="input-group" style="width:75%;">
                                <input type="number" name="desiretime" id="desiretime" class="form-control" required value="[% $servicelvl.desiretime %]">
                                <div class="input-group-text">[%$user->gettext('Std. nach Ticketerstellung')%]</div>
                            </div>
                        </div>
                    </div>

                    <div class="form-group row mb-3">
                        <label class="col-lg-2 control-label">
                            [% $user->gettext('Eskalation') %]<br>
                            [% $user->gettext('Stunden nach Ticketerstellung') %]
                        </label>
                        <div class="col-lg-10">
                            <div class="form-group row mb-3">
                                <label class="col-lg-1 control-label" for="esclvl_1_output">
                                    [% $user->gettext('Stufe') %] 1
                                </label>
                                <div class="col-lg-11">
                                    <div class="col-lg-1">
                                        <input name="esclvl_1_output" class="SliderOutput form-control" data-forid="esclvl_1" id="esclvl_1_output" value='[% $servicelvl.esclvl_1 %]'  />
                                    </div>
                                    <div class="col-lg-11">
                                        <input type="range" min='0' data-forid="esclvl_1_output" max="[% math equation='x * y' x=$servicelvl.desiretime|default:0 y=120 %]" id="esclvl_1" name="esclvl_1" required value="[% $servicelvl.esclvl_1 %]" style="width: 26%;" />    
                                    </div>
                                </div>
                            </div>

                            <div class="form-group row mb-3">
                                <label class="col-lg-1 control-label" for="esclvl_2_output">
                                    [% $user->gettext('Stufe') %] 2
                                </label>
                                <div class="col-lg-11">
                                    <div class="col-lg-1">
                                        <input name="esclvl_2_output" class="SliderOutput form-control" data-forid="esclvl_2" id="esclvl_2_output" value='[% $servicelvl.esclvl_2 %]'  />
                                    </div>
                                    <div class="col-lg-11">
                                        <input type="range" min='0' data-forid="esclvl_2_output" max="[% math equation='x * y' x=$servicelvl.desiretime|default:0 y=120 %]" id="esclvl_2" name="esclvl_2" required value="[% $servicelvl.esclvl_2 %]" style="width: 26%;" />    
                                    </div>
                                </div>
                            </div>

                            <div class="form-group row mb-3">
                                <label class="col-lg-1 control-label" for="esclvl_3_output">
                                    [% $user->gettext('Stufe') %] 3
                                </label>
                                <div class="col-lg-11">
                                    <div class="col-lg-1">
                                        <input name="esclvl_3_output" class="SliderOutput form-control" data-forid="esclvl_3" id="esclvl_3_output" value='[% $servicelvl.esclvl_3 %]'  />
                                    </div>
                                    <div class="col-lg-11">
                                        <input type="range" min='0' data-forid="esclvl_3_output" max="[% math equation='x * y' x=$servicelvl.desiretime|default:0 y=120 %]" id="esclvl_3" name="esclvl_3" required value="[% $servicelvl.esclvl_3 %]" style="width: 26%;" />    
                                    </div>
                                </div>
                            </div>

                            <div class="form-group row mb-3">
                                <label class="col-lg-1 control-label" for="esclvl_4_output">
                                    [% $user->gettext('Stufe') %] 4
                                </label>
                                <div class="col-lg-11">
                                    <div class="col-lg-1">
                                        <input name="esclvl_4_output" class="SliderOutput form-control" data-forid="esclvl_4" id="esclvl_4_output" value='[% $servicelvl.esclvl_4 %]'  />
                                    </div>
                                    <div class="col-lg-11">
                                        <input type="range" min='0' data-forid="esclvl_4_output" max="[% math equation='x * y' x=$servicelvl.desiretime|default:0 y=120 %]" id="esclvl_4" name="esclvl_4" required value="[% $servicelvl.esclvl_4 %]" style="width:26%;" />    
                                    </div>
                                </div>
                            </div>

                            <div class="form-group row mb-3">
                                <label class="col-lg-1 control-label" for="esclvl_5_output">
                                    [% $user->gettext('Stufe') %] 5
                                </label>
                                <div class="col-lg-11">
                                    <div class="col-lg-1">
                                        <input name="esclvl_5_output" class="SliderOutput form-control" data-forid="esclvl_5" id="esclvl_5_output" value='[% $servicelvl.esclvl_5 %]'   />
                                    </div>
                                    <div class="col-lg-11">
                                        <input type="range" min='0' data-forid="esclvl_5_output" max="[% math equation='x * y' x=$servicelvl.desiretime|default:0 y=120 %]" id="esclvl_5" name="esclvl_5" required value="[% $servicelvl.esclvl_5 %]" style="width:26%;" />    
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="form-group row mb-3">
                        <label class="col-lg-2 control-label" >[% $user->gettext('Supportzeiten') %]</label>
                        <div class="col-lg-10">
                            <div class="card panel-info shadow-sm rounded">
                                <table class="table table-bordered table-striped">
                                    <tr>
                                        <td><label>[% $user->gettext('Wochentage') %]:</label></td>
                                        <td [% if $Errors.Mon %]class="error" title="[% $SupporttimeErrors[0] %]"[% /if %]>[% $user->gettext('Mo') %]</td>
                                        <td [% if $Errors.Tue %]class="error" title="[% $SupporttimeErrors[1] %]"[% /if %]>[% $user->gettext('Di') %]</td>
                                        <td [% if $Errors.Wed %]class="error" title="[% $SupporttimeErrors[2] %]"[% /if %]>[% $user->gettext('Mi') %]</td>
                                        <td [% if $Errors.Thu %]class="error" title="[% $SupporttimeErrors[3] %]"[% /if %]>[% $user->gettext('Do') %]</td>
                                        <td [% if $Errors.Fri %]class="error" title="[% $SupporttimeErrors[4] %]"[% /if %]>[% $user->gettext('Fr') %]</td>
                                        <td [% if $Errors.Sat %]class="error" title="[% $SupporttimeErrors[5] %]"[% /if %]>[% $user->gettext('Sa') %]</td>
                                        <td [% if $Errors.Sun %]class="error" title="[% $SupporttimeErrors[6] %]"[% /if %]>[% $user->gettext('So') %]</td>
                                    </tr>
                                    <tr>
                                        <td>[% $user->gettext('Ist Supporttag') %]</td>
                                        <td><input type="checkbox" name="mon" value="1" [% if $servicelvl.mon %]checked="checked"[% /if %]/></td>
                                        <td><input type="checkbox" name="tue" value="1" [% if $servicelvl.tue %]checked="checked"[% /if %] /></td>
                                        <td><input type="checkbox" name="wed" value="1" [% if $servicelvl.wed %]checked="checked"[% /if %] /></td>
                                        <td><input type="checkbox" name="thu" value="1" [% if $servicelvl.thu %]checked="checked"[% /if %] /></td>
                                        <td><input type="checkbox" name="fri" value="1" [% if $servicelvl.fri %]checked="checked"[% /if %] /></td>
                                        <td><input type="checkbox" name="sat" value="1" [% if $servicelvl.sat %]checked="checked"[% /if %] /></td>
                                        <td><input type="checkbox" name="sun" value="1" [% if $servicelvl.sun %]checked="checked"[% /if %] /></td>
                                    </tr>
                                    <tr>
                                        <td><label>[% $user->gettext('Uhrzeit') %] [% $user->gettext('von') %]:</label></td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="MonFrom1" value="[% $servicelvl.monfrom1 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="TueFrom1" value="[% $servicelvl.tuefrom1 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="WedFrom1" value="[% $servicelvl.wedfrom1 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="ThuFrom1" value="[% $servicelvl.thufrom1 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="FriFrom1" value="[% $servicelvl.frifrom1 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="SatFrom1" value="[% $servicelvl.satfrom1 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="SunFrom1" value="[% $servicelvl.sunfrom1 %]" class="textbox" />
                                        </td>
                                    </tr>
                                    <tr class="addPause" id="PauseStart" >
                                        <td><label>[% $user->gettext('Pause') %] [% $user->gettext('ab') %]:</label></td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="MonUntil1" value="[% $servicelvl.monuntil1 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="TueUntil1" value="[% $servicelvl.tueuntil1 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="WedUntil1" value="[% $servicelvl.weduntil1 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="ThuUntil1" value="[% $servicelvl.thuuntil1 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="FriUntil1" value="[% $servicelvl.friuntil1 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="SatUntil1" value="[% $servicelvl.satuntil1 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="SunUntil1" value="[% $servicelvl.sununtil1 %]" class="textbox" />
                                        </td>
                                    </tr>

                                    <tr class=" addPause" id="PauseEnde" >
                                        <td><label>[% $user->gettext('Pause') %] [% $user->gettext('bis') %]:</label></td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="MonFrom2" value="[% $servicelvl.monfrom2 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="TueFrom2" value="[% $servicelvl.tuefrom2 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="WedFrom2" value="[% $servicelvl.wedfrom2 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="ThuFrom2" value="[% $servicelvl.thufrom2 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="FriFrom2" value="[% $servicelvl.frifrom2 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="SatFrom2" value="[% $servicelvl.satfrom2 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="SunFrom2" value="[% $servicelvl.sunfrom2 %]" class="textbox" />
                                        </td>     
                                    </tr>

                                    <tr class="">
                                        <td><label>[% $user->gettext('Uhrzeit') %] [% $user->gettext('bis') %]:</label></td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="MonUntil2" value="[% $servicelvl.monuntil2 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="TueUntil2" value="[% $servicelvl.tueuntil2 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="WedUntil2" value="[% $servicelvl.weduntil2 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="ThuUntil2" value="[% $servicelvl.thuuntil2 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="FriUntil2" value="[% $servicelvl.friuntil2 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="SatUntil2" value="[% $servicelvl.satuntil2 %]" class="textbox" />
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" size="5" maxlength="5" name="SunUntil2" value="[% $servicelvl.sununtil2 %]" class="textbox" />
                                        </td>                   

                                    </tr>     
                                </table>
                            </div>

                        </div>
                    </div>


                </div>
            </div>
        </div>
    </div>
    <!-- ###CONTENT### begin -->

</form>

<div id="dialog-category" style="display:none;" width="500" hight="500"></div>


<script>

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

    $(document).ready(function () {
        $(".select2").select2({theme: 'bootstrap-5',
            language: "[% $user->language_type %]"
        })

        $("#desiretime").on("change", function (e) {
            var val = $("#desiretime").val();
            val = val * 120;
            $('input[type=range]').attr('max', val);
        });
    });

    $("input[type=range]").on("change", function (e) {
        $("#" + $(this).data('forid')).val(convertMinsToHrsMins($(this).val()));
    });

    $(".SliderOutput").on("change", function (e) {
        $("#" + $(this).data('forid')).val(HrsMinsToMinutes($(this).val()));
    });


    function convertMinsToHrsMins(minutes) {
        var h = Math.floor(minutes / 60);
        var m = minutes % 60;
        h = h < 10 ? '0' + h : h;
        m = m < 10 ? '0' + m : m;
        return h + ':' + m;
    }


    function HrsMinsToMinutes(hm) {
        var a = hm.split(':');
        return (+a[0]) * 60 + (+a[1]);
    }

    $(".SliderOutput").each(function () {
        $(this).val(convertMinsToHrsMins($(this).val()));
    })

</script>

<!-- Component Ticket end -->
