<script type="text/javascript" src="includes/js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="includes/js/script.js"></script>
<link rel="stylesheet" type="text/css" href="styles/[% $CSSTEMPLATE %]/css/jquery-ui-timepicker-addon.css" />
<form action="[% $action %]" method="post" name="hm" onsubmit="return false;" id="hm" enctype="multipart/form-data" class="form-horizontal form-label-left">

    <input type="hidden" name="save" value="1" />
    <input type="hidden" name="close" value="0" id="close" />
    <input type="hidden" name="done" value="0" id="done" />
    <input type="hidden" name="take" value="0" id="take" />
    <input type="hidden" name="ActivityID" value="[% $Activity->ActivityID %]" id="ActivityID" />

    <input type="hidden" name="oldstatus" value="[% $status %]" />

    <div class="row">

        <div class="col-lg-12   sticky-top" id="UpperRow" style="z-index: 1;">
            <div class="card panel-fcs-content shadow-sm MovableItems" id="ActionItem" >
                <div class="card-header movable">
                    <div class="row">
                        <div class="col-11">
                            [% $user->gettext('Aktionen') %]
                        </div>
                        <div class="col-1 text-end">
                            <span class="fa fa-chevron-up" id="ActionItemIcon" onclick="ToggleItem('ActionItem');"></span>
                        </div>
                    </div>

                </div>
                <div class="card-body " id="ActionItemBody">
                    <div class="btn-group">
                        <input type="button" class="btn btn-outline-primary" value="[% $user->gettext('Zur&uuml;ck') %]" onclick="saveForm(true);" />
                        [% if $ticket.ticketstatusid != 3 && $ticket.ticketstatusid != 11 && $Activity->TaskType != 5 %]

                            [% if $hmcompany != 'VERSORGUNGSBETRIEBE HOYERSWERDA GMBH' || $user->hasRight(703) %]
                                <input id="btnActivityNotPossible" type="button" class="btn btn-outline-primary" value="[% if $hmcompany == 'VERSORGUNGSBETRIEBE HOYERSWERDA GMBH' %][% $user->gettext('Abbrechen') %][% else %][% $user->gettext('Aktivität nicht möglich') %][% /if %]" onclick="saveForm(false);
                                        $('#ActivityImposibleLink').click();"  />
                                <a href="index.php?module=ticket&event=event&tid=[% $ticket.id %]&activity=1&impos=1"  data-fancybox-type="iframe" class="dialog" id="ActivityImposibleLink" style="display:none;">[% $user->gettext('Nicht möglich') %]</a>
                            [% /if %]

                            <input id="btnActivitySuccess" type="button" class="btn btn-outline-success-full" value="[% if $hmcompany == 'VERSORGUNGSBETRIEBE HOYERSWERDA GMBH' %][% $user->gettext('OK') %][% else %][% $user->gettext('Aktivität erledigt') %][% /if %]" onclick="
                                   [% if $Activity->TaskType == 2 %]
                                    var formcheck = validateForm();
                                    if (formcheck) {
                                        $('#activityForm').submit();
                                        bootbox.confirm('[% $user->gettext('Aktivität wirklich erledigt?') %]', function (result) {
                                            if (result) {
                                                document.getElementById('close').value = 1;
                                                submitForm();
                                            }
                                        })
                                    }
                                   [% else %]
                                    bootbox.confirm('[% $user->gettext('Aktivität wirklich erledigt?') %]', function (result) {
                                        if (result) {
                                            document.getElementById('close').value = 1;
                                            submitForm();
                                        }
                                    })
                                   [% /if %]"
                                   />

                            [% if $Activity->StartConID == 1 && $user->hasRight(703) %]
                                <input id="btnActivityEnd" type="button" class="btn btn-outline-danger" value="[% $user->gettext('Workflow beenden') %]" onclick="
                                    bootbox.confirm('[% $user->gettext('Möchten Sie den Workflow wirklich abbrechen?') %]', function (result) {
                                        if (result) {
                                            window.location.replace('index.php?module=workflow&event=stopWorkflow&showtid=[%$ticket.id %]&id=[% $Activity->WFIID %]');
                                        }
                                    })"  />
                            [% /if %]

                        [% /if %]
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-6 SortableContainer" id="LeftCol">
            <div class="card panel-info shadow-sm rounded MovableItems" id="FormDataItem">
                <div class="card-header movable">
                    <div class="row">
                        <div class="col-11">
                            [% $user->gettext('Formular') %]
                        </div>
                        <div class="col-1 text-end">
                            <span class="fa fa-chevron-up" id="FormDataItemIcon" onclick="ToggleItem('FormDataItem');"></span>
                        </div>
                    </div>

                </div>
                <div class="card-body" id="FormDataItemBody">
                    [% if $Activity->TaskType == 2 %]
                        <!-- Formulartabelle -->
                        <div class="holds-the-iframeaa">
                            <div id="Formular_[% $Activity->ActivityID %]">
                                <img src="images/ajax-loader.gif" alt="loading..."/>
                            </div>
                        </div>
                        <!-- Formulartabelle Ende-->
                    [% elseif $Activity->TaskType == 5 %]
                        [% $WFInfoText %]

                        <h2>[% $user->gettext('Aktivitäten') %]</h2>
                        <table class="table">
                            <tr>
                                <th>[% $user->gettext('Kurzbeschreibung (Titel)') %]</th>
                                <th>[% $user->gettext('Status') %]</th>
                                <th>[% $user->gettext('Adressat') %]</th>

                                <th>[% $user->gettext('Formulardaten') %]</th>
                            </tr>
                            [% foreach from=$startedWFI.aGantt item=Activity %]
                                <tr>
                                    <td>[% $Activity.Descr %] (<a href="index.php?module=ticket&event=show&id=[% $Activity.ticketid %]" target="_blank">(#[% $Activity.ticketid %])</a>)</td>
                                    <td> [% $user->gettext($Activity.Status) %]</td>
                                    [% if $Activity.O->TargetType == 1 || $Activity.O->TargetType == 3 %]
                                        <td>[% $Activity.O->TargetUsers %] </td>
                                    [% elseif $Activity.O->TargetType == 2 %]
                                        <td>[% $user->gettext('Gruppe') %]: [% $Activity.O->TargetGroups %]</td>
                                    [% /if %]

                                    <td> [% $Activity.O->FormClass->showVisibleFormContent() %]</td>
                                </tr>
                            [% /foreach %]
                        </table>
                    [% else %]
                        [% $Activity->TaskText %]
                    [% /if %]
                </div>
            </div>

            [% if $isStartedByWF && ($startActivity->ShowOtherInformations || $startActivity->ShowDirectPrevActivity)%]
                <div class="card panel-info shadow-sm rounded MovableItems" id="PreviousActivityItem">
                    <div class="card-header movable">
                        <div class="row">
                            <div class="col-11">
                                [% $user->gettext('Daten von Vorgänger-WF') %] <strong>[% $startActivity->WFIDescr %]</strong> 
                            </div>
                            <div class="col-1 text-end">
                                <span class="fa fa-chevron-up" id="PreviousActivityItemIcon" onclick="ToggleItem('PreviousActivityItem');"></span>
                            </div>
                        </div>
                    </div>

                    <div class="card-body" id="PreviousActivityItemBody">

                        [% foreach from=$startActivity->FormClass->getPreviusForms([% $startActivity->ShowDirectPrevActivity %]) item=Form key=key %]
                            [% foreach from=$Form item=PrevForm key=key %]
                                <div class="well well-sm" [% $user->gettext('Daten aus Vorgänger-WF') %] <strong>[% $key %]:</strong></div>

                                [% $PrevForm.FormData %]

                                [% if $Tools->FCS_Count($PrevForm.Attachments) %]

                                    [% if $Tools->FCS_Count($PrevForm.Attachments) == 1 %]
                                        <b>[% $user->gettext('Dokument') %]</b>'[% $key %]'
                                    [% else %]
                                        <b>[% $user->gettext('Dokumente') %]</b>'[% $key %]'
                                    [% /if %]:

                                    [% foreach from=$PrevForm.Attachments item=attachment %]

                                        [% if $attachment.attachmenttypid != 2 %]
                                            <a href="index.php?module=upload&event=ShowImage&name=[% $attachment.changedfilename %]" class="dialog" target="top">
                                            [% else %]
                                                <a href="[% $attachment.url %]" target="top">
                                                [% /if %]
                                                <img src="[% if $attachment.thumbnail != '' %]index.php?module=upload&event=ShowImage&name=[% $attachment.thumbnail %][% else %][% $attachment.mimetyp %][% /if %]"
                                                     width="20" height="20" border="0" title="[% $attachment.shortdescr %][% if $attachment.attachmenttypid == 2%]: [% $attachment.url %][% /if %]"  />
                                            </a>
                                        [% /foreach %]
                                    [% /if %]
                                [% /foreach %]
                            [% /foreach %]
                    </div>
                </div>
            [% /if %]

            [% if $Activity->ShowOtherInformations || $Activity->ShowDirectPrevActivity %]
                <div class="card panel-info shadow-sm rounded MovableItems"  id="PreviousActivityItem2">
                    <div class="card-header movable">
                        <div class="row">
                            <div class="col-11">
                                [% $user->gettext('Daten von Vorgängern') %]
                            </div>
                            <div class="col-1 text-end">
                                <span class="fa fa-chevron-up" id="PreviousActivityItem2Icon" onclick="ToggleItem('PreviousActivityItem2');"></span>
                            </div>
                        </div>
                    </div>

                    <div class="card-body" id="PreviousActivityItem2Body">
                        [% foreach from=$Activity->FormClass->getPreviusForms([% $Activity->ShowDirectPrevActivity %]) item=Form key=key %]
                            [% foreach from=$Form item=PrevForm key=key %]
                                <div class="well well-sm" [% $user->gettext('Daten aus Vorgängeraktivität') %] <strong>[% $key %]:</strong></div>

                                [% $PrevForm.FormData %]

                                [% if $Tools->FCS_Count($PrevForm.Attachments) %]

                                    [% if $Tools->FCS_Count($PrevForm.Attachments) == 1 %]
                                        <b>[% $user->gettext('Dokument') %]</b>'[% $key %]'
                                    [% else %]
                                        <b>[% $user->gettext('Dokumente') %]</b>'[% $key %]'
                                    [% /if %]:

                                    [% foreach from=$PrevForm.Attachments item=attachment %]

                                        [% if $attachment.attachmenttypid != 2 %]

                                            <a href="index.php?module=upload&event=ShowImage&name=[% $attachment.changedfilename %]" class="dialog" target="top">

                                            [% else %]
                                                <a href="[% $attachment.url %]" target="top">
                                                [% /if %]
                                                <img src="[% if $attachment.thumbnail != '' %]index.php?module=upload&event=ShowImage&name=[% $attachment.thumbnail %][% else %][% $attachment.mimetyp %][% /if %]"
                                                     width="20" height="20" border="0" title="[% $attachment.shortdescr %][% if $attachment.attachmenttypid == 2%]: [% $attachment.url %][% /if %]"  />
                                            </a>
                                        [% /foreach %]
                                    [% /if %]
                                [% /foreach %]
                            [% /foreach %]
                    </div>
                </div>
            [% /if %]

        </div> <!--Ende Linke Spalte -->

        <div class="col-md-6 SortableContainer" id="RightCol">
            <div class="card panel-info shadow-sm rounded MovableItems" id="WFInfoItem">
                <div class="card-header movable">
                    <div class="row">
                        <div class="col-11">
                            [% $user->gettext('Allgemeine Daten') %]
                        </div>
                        <div class="col-1 text-end">
                            <span class="fa fa-chevron-up" id="WFInfoItemIcon" onclick="ToggleItem('WFInfoItem');"></span>
                        </div>
                    </div>
                </div>
                <div class="card-body" id="WFInfoItemBody">
                    <div class="form-group row mb-3">
                        <label class="col-lg-3 control-label">[% $user->gettext('Initiator') %]</label>
                        <div class="col-lg-9">
                            <p class="form-control-static">[% $Activity->IUsername %] ([% $Activity->IName %])</p>
                        </div>
                    </div>

                    <div class="form-group row mb-3">
                        <label class="col-lg-3 control-label">[% $user->gettext('Adressaten') %]</label>
                        <div class="col-lg-7">
                            [% if $Activity->TargetType != 2 %]
                                <p class="form-control-static">
                                    [% $user->gettext('Benutzer') %]:
                                    [% $Activity->TargetUsers %] 
                                </p>
                            [% else %]
                                <p class="form-control-static">
                                    [% $user->gettext('Gruppe') %]:
                                    [% $Activity->TargetGroups %]
                                </p>
                            [% /if %]
                            <div class="col-lg-2">
                                [% if $Activity->TargetType == 2 && $ticket.ticketstatusid != 3 && $ticket.ticketstatusid != 11 %]
                                    <a href ="JavaScript:void(0);" onclick="saveForm(false);
                                            document.getElementById('take').value = 1;
                                            submitForm();" class="btn btn-outline-primary" title="[% $user->gettext('Aktivität übernehmen: Benutzer wird statt der Gruppe als Adressat der Aktivität eingetragen.') %]" >
                                        <span class="fa fa-user" id="TicketTakeOverIcon"></span>
                                        [% $user->gettext('Aktivität übernehmen') %]
                                    </a>
                                [% /if %]
                            </div>
                        </div>
                    </div>

                    <div class="form-group row mb-3">
                        <label class="col-lg-3 control-label">[% $user->gettext('Dauer') %]</label>
                        <div class="col-lg-9">
                            <p class="form-control-static">
                                [% $Activity->Duration %]
                                [% $user->gettext('Tage') %]
                            </p>
                        </div>
                    </div>
                    <div class="form-group row mb-3">
                        <label class="col-lg-3 control-label">[% $user->gettext('Fällig') %]</label>
                        <div class="col-lg-9">
                            <p class="form-control-static">[% $ticket.desiredate|date_format:"%d.%m.%Y %H:%M" %]</p>
                        </div>
                    </div>

                    [% if $project_id > 0 %]
                        <div class="form-group row mb-3">
                            <label class="col-lg-4 control-label">[% $user->gettext('Projekt') %]</label>
                            <div class="col-lg-8">
                                [% $projects[$project_id] %]
                            </div>
                        </div>
                    [% /if %]

                    [% if ($Activity->NotificationType == 2 && $Activity->NGroupName != '') || ($Activity->NotificationType == 1 && $Activity->NUsername != '') %]
                        <div class="form-group row mb-3">
                            <label class="col-lg-3 control-label">[% $user->gettext('Benachrichtigung') %]</label>
                            <div class="col-lg-9">
                                [% if $Activity->NotificationType != 2 %]
                                    [% $user->gettext('Benutzer') %]:
                                    [% $Activity->NUsername %] ([% $Activity->NName %])
                                [% else %]
                                    [% $user->gettext('Gruppe') %]:
                                    [% $Activity->NGroupName %]
                                [% /if %]
                            </div>
                        </div>
                    [% /if %]
                </div>
            </div>
            <div class="card panel-info shadow-sm rounded MovableItems" id="OnHoldItem">
                <div class="card-header movable">
                    <div class="row">
                        <div class="col-11">
                            [% $user->gettext('Zurückstellung') %]
                        </div>
                        <div class="col-1 text-end">
                            <span class="fa fa-chevron-up" id="OnHoldItemIcon" onclick="ToggleItem('OnHoldItem');"></span>
                        </div>
                    </div>
                </div>
                <div class="card-body" id="OnHoldItemBody">
                    <div class='form-group row mb-3'>
                        <label class='control-label col-lg-3'>[% $user->gettext('Zurückgestellt bis')%]</label>
                        <div class='col-lg-3'>
                            <input type='text' class='form-control datetimepicker' id='OnHold' value="[% $ticket.onhold %]">

                        </div>
                        <div class='col-lg-3'>
                            <a href='javascript: setOnholdDate();' class='btn btn-outline-primary'>[% $user->gettext('Zurückstellen')%]</a>

                        </div>
                    </div>
                </div>
            </div>
            <div class="card panel-info shadow-sm rounded MovableItems" id="EventItem">
                <div class="card-header movable">

                    <div class="row">
                        <div class="col-sm-4"><h3 class="card-title">[% $user->gettext('Bearbeitungen') %]</h3></div>
                        <div class="col-sm-7 text-end">
                            <div class="btn-group">
                                [% if $ticket.ticketstatusid != 3 && $ticket.ticketstatusid != 11 %]
                                    <a href="index.php?module=ticket&event=event&tid=[%$ticket.id%]&activity=1" onclick="saveForm(false);" class="btn btn-outline-primary btn-sm openInBigIFrameModal">[% $user->gettext('Neuer Kommentar') %]</a>
                                [% /if %]
                                [% if !$user->hasRight(243) %]
                                    <span class="btn btn-outline-secondary btn-sm" data-toggle="button" aria-pressed="false" autocomplete="off" title="[% $user->gettext('Protokolleintr&auml;ge anzeigen') %]" onclick="$('.protokoll').toggleClass('hidden');">[% $user->gettext('Protokolleintr&auml;ge anzeigen') %]</span>
                                [% /if %]
                            </div>
                        </div>
                        <div class="col-sm-1 text-end">
                            <span class="fa fa-chevron-up" id="EventItemIcon" onclick="ToggleItem('EventItem');"></span>
                        </div>
                    </div>
                </div>
                <div class="card-body" id="EventItemBody">
                    [% include file=$modulePath|cat:"/details.includeHistory.tpl" %]
                </div>
            </div>
                [% if $user->hasRight(1020) %]
            <div class="card panel-info shadow-sm rounded MovableItems" id="NotDisplayItem">
                <div class="card-header movable">

                    <div class="row">
                        <div class="col-sm-11"><h3 class="card-title">[% $user->gettext('Nicht angezeigte Objekte') %]</h3></div>

                        <div class="col-sm-1 text-end">
                            <span class="fa fa-chevron-up" id="NotDisplayItemIcon" onclick="ToggleItem('NotDisplayItem');"></span>
                        </div>
                    </div>
                </div>
                <div class="card-body SortableContainer" id="NotDisplayItemBody">

                </div>
            </div>
                        [% /if %]
        </div><!--Ende rechte Spalte -->
    </div>
</form>
<script>

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

    /**
     * setOnholdDate
     */
    function setOnholdDate() {
        var onhold = $("#OnHold").val();
        //console.log(onhold);
        if (onhold !== '') {
            $.post('index.php?module=ticket&event=RESTUpdateTicketOnHoldDate&id=[% $ticket.id %]', {"OnHoldDate": onhold}, function (data) {
                if (!data.error) {
                    noty({
                        text: data.message[0],
                        //layout: 'top',
                        //theme: 'defaultTheme', // or 'relax'
                        //closeWith: ['click', 'hover'],
                        type: 'success',
                        timeout: notifyTimeout
                    });
                } else {
                    noty({
                        text: data.message[0],
                        //layout: 'top',
                        //theme: 'defaultTheme', // or 'relax'
                        //closeWith: ['click', 'hover'],
                        type: 'error',
                        timeout: notifyTimeout
                    });
                }
            });
        } else {
            $.ajax({
                type: "POST",
                url: "index.php?module=ticket&event=setOnHold",
                data: {tid: [% $ticket.id %], save: 1, remove: 1, OnHoldDate: ''}
            }).done(function (msg) {
                if (1 != msg) {
                    $("#OnHold").addClass("textboxerror");
                    $("#OnHold").before('<p>' + msg + '</p>');
                } else {
                    noty({
                        text: "[% $user->gettext('OnHold Datum entfernt!') %]",
                        //layout: 'top',
                        //theme: 'defaultTheme', // or 'relax'
                        //closeWith: ['click', 'hover'],
                        type: 'success',
                        timeout: notifyTimeout
                    });
                }
            });
        }
    }

    function ToggleItem(ItemID) {
    }
</script>
