<!-- Component active_wf_form begin -->

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


<form action="index.php?module=workflow&amp;event=activate&amp;wfdid=[% $wf.WFDID %]" method="post" name="wfDef" class="form-horizontal form-label-left">

    [% if $popup %]
        <input type="hidden" name="popup" value="1" />
        <input type="hidden" name="ticketid" value="[% $TicketID %]" />
    [% /if %]

    [% if !$showactive %]
        <input type="hidden" name="DateType" value="[% $wf.DateType %]">
        <input type="hidden" name="WFDDescr" value="[% $wf.Descr %]">
    [% /if %]

    [% if $startWFForm %]
        <input type="hidden" name="StartDate" value="[% $wf.StartDate|date_format:"%d.%m.%Y %H:%M" %]" />
        <input type="hidden"  id="EndDateHidden" name="EndDate1" value="[% $wf.EndDate|date_format:"%d.%m.%Y %H:%M" %]" />
        <input type="hidden" name="Duration_total" value="[% $wf.duration_total %]" />
    [% /if %]
    <!-- ###CONTENT### begin -->
    <div class="card panel-fcs-border shadow-sm">
        <div class="card-header">
            <span class="fcs-card-title h2">
                [%$user->gettext('Workflow')%]
            </span>
        </div>
        <div class="card-body">
            <div class="[% if $startWFForm %]col-lg-6 offset-md-3[% else %]col-lg-10 offset-md-1[% /if %]">

                [% if $Tools->FCS_Count($wf.Errors) %]
                    [% foreach from=$wf.Errors item=Error %]
                        <div class="alert alert-danger" role="alert">
                            <strong>[%$user->gettext('Fehler')%]</strong>: [% $user->gettext($Error) %]
                        </div>
                    [% /foreach %]
                [% /if %]

                [% if $Tools->FCS_Count($Errors) %]
                    [% foreach from=$Errors item=Error %]
                        <div class="alert alert-danger" role="alert">
                            <strong>[%$user->gettext('Fehler')%]</strong>: [% $user->gettext($Error) %]
                        </div>
                    [% /foreach %]
                [% /if %]

                <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 $id > 0 %][% $user->gettext('Workflow bearbeiten') %][% else %][% if $showactive %][% $user->gettext('Aktiver Workflow') %][% else %][% $user->gettext('Workflow starten') %][% /if %][% /if %]
                </span>
            </div>
            <div class="col-lg-6 text-end">
                <div class="btn-group">
                    [% if $showactive %]
                        <a href="index.php?module=workflow&event=PDFexport&wfiid=[% $wf.ID %]"   class="btn btn-outline-secondary" >[% $user->gettext('PDF') %]</a>
                        <a href="index.php?module=workflow&amp;event=mailReport&wfiid=[% $wf.ID %]" title="[% $user->gettext('Per Mail senden') %]" data-fancybox-type="iframe" class="btn btn-outline-primary dialog" >[% $user->gettext('Per Mail senden') %] </a>


                        <a href="index.php?module=workflow&amp;event=showReport&amp;wfiid=[% $wf.ID %]" title="[% $user->gettext('Bericht') %]" data-fancybox-type="iframe" class="btn btn-outline-primary dialog" >[% $user->gettext('Bericht') %] </a>
                        [% if $fromDetailReport %]
                            <a href="index.php?module=workflow&event=report"   class="btn btn-outline-secondary" >[% $user->gettext('Zurück') %]</a>
                        [% else %]
                            <a href="index.php?module=workflow&event=active"   class="btn btn-outline-secondary" >[% $user->gettext('Zurück') %]</a>
                        [% /if %]
                    [% else %]
                        <input type="submit" class="btn btn-outline-primary" name="activate" value="[% $user->gettext('Starten') %]" />
                        <a href="index.php?module=workflow&event=selectwf" class="btn btn-outline-secondary" >[% $user->gettext('Zurück') %]</a>
                    [% /if %]
                </div>
            </div>
        </div>
    </div>
    <div class="card-body">
        <div class="row">

            <div class="[% if $startWFForm %]col-sm-12[% else %]col-lg-6[% /if %]">
                <div class="form-group row mb-3">

                    <label class="control-label col-lg-4">
                        [% $user->gettext('Workflow-Definition') %]
                    </label>
                    <div class="col-lg-8">
                        <span id="lblWorkflowName" class="form-control-static">[% $wf.WFDDescr %]</span>
                    </div>

                </div>
                <div class="form-group row mb-3">
                    <label class="control-label col-lg-4">
                        [% $user->gettext('Name') %]*
                    </label>
                    <div class="col-lg-8">
                        [% if $showactive %]
                            <span class="form-control-static">[% $wf.Descr %]</span>
                        [% else %]
                            <div class="input-group">
                                <div class="input-group-text"><span>[% $wf.Descr %]</span></div>
                                <input type="text" size="15" required="required" maxlength="[% $DescrLength %]" [% if $showactive %]readonly[% /if %] name="InstanzDescr" class="form-control" value="" />
                            </div>
                        [% /if %]

                    </div>
                </div>               
                <div class="form-group row mb-3">
                    <label class="control-label col-lg-4"  title="[% $user->gettext('Person, die den Workflow startet.') %]">
                        [% $user->gettext('Initiator') %]
                    </label>
                    <div class="col-lg-8">
                        [% if $showactive %]
                            <p class="form-control-static">[% $wf.Username %] ([% $wf.Name %])</p>
                        [% else %]
                            <select name="InitiatorID" id="InitiatorID" class="form-control userSelect" style="width: 100%">
                                <option value="0" [% if !$wf.InitiatorID || $wf.InitiatorID == 0 %]selected="selected"[% /if %]>-- [% $user->gettext('Bitte wählen') %] --</option>
                                [% html_options options=$users selected=$wf.InitiatorID %]
                            </select>
                        [% /if %]
                    </div>
                </div>
                [% if $user->hasRight(205) %]
                    <div class="form-group row mb-3">
                        <label class="control-label col-lg-4"  title="[% $user->gettext('Vertreter der Person, die den Workflow startet.') %]">
                            [% $user->gettext('Vertreter') %]
                        </label>
                        <div class="col-lg-8">
                            [% if $showactive %]
                                <p class="form-control-static">[% $wf.sUsername %] ([% $wf.sName %])</p>
                            [% else %]
                                <select name="SubstitudeID" id="SubstitudeID" class="form-control userSelect" style="width: 100%">
                                    <option value="0" [% if !$wf.SubstitudeID || $wf.SubstitudeID == 0 %]selected="selected"[% /if %]>-- [% $user->gettext('Bitte wählen') %] --</option>
                                    [% html_options options=$users selected=$wf.SubstitudeID %]
                                </select>
                            [% /if %]
                        </div>
                    </div>
                [% /if %]
                
                [% if $user->hasRight(206) %]
                    <input type="hidden" value="[% $user->ContactID %]" name="ContactID">
                [% else%]
                    <div class="form-group row mb-3">
                        <label class="control-label col-lg-4">
                            [% $user->gettext('Kontakt') %]
                        </label>
                        <div class="col-lg-8">
                            [% if $showactive %]
                                <p class="form-control-static">[% $wf.ContactName %]</p>
                            [% else %]
                                <select size="1" name="ContactID" id="ContactID" class="form-control contactSelect"  style="width: 100%">
                                    <option value="0" [% if !$wf.ContactID || $wf.ContactID == 0 %]selected="selected"[% /if %]>-- [% $user->gettext('Bitte wählen') %] --</option>
                                    [% html_options options=$Contacts selected=$wf.ContactID %]
                                </select>
                            [% /if %]
                        </div>
                    </div>
                [% /if %]

                [% if $user->Security->Projects %]

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

                            [% if $showactive %]
                                [% $Projects[$wf.ProjectID] %]
                            [% else %]
                                <select name="ProjectID" id="ProjectID" class="form-control multiple">
                                    <option value="0" [% if !$wf.ProjectID || $wf.ProjectID == 0 %]selected="selected"[% /if %]>-- [% $user->gettext('Bitte wählen') %] --</option>
                                    [% html_options options=$Projects selected=$wf.ProjectID %]
                                </select>
                            [% /if %]


                        </div>
                    </div>

                    <div class="form-group row mb-3" style="display: none;">
                        <label class="control-label col-lg-4">
                            [% $user->gettext('Kostenstelle') %]
                        </label>
                        <div class="col-lg-8">
                            <select name="RefLvl2ID" id="RefLvl2ID" class="form-control multiple">
                                <option value="0" >-- [% $user->gettext('Bitte wählen') %] --</option>
                            </select>
                        </div>
                    </div>

                [% /if %]
                [% if $startWFForm && !$user->hasRight(204) %]
                    <div class="form-group row mb-3">
                        <label class="control-label col-lg-4">
                            [% $user->gettext('Enddatum manuell eingeben') %]
                        </label>
                        <div class="col-lg-8">
                            <input type="checkbox" id="EndDateToggle"  onclick="toggleEnddatum();"  />
                        </div>
                    </div>
                    <div class="form-group row mb-3"  id="EndDateText" style="display:none;">
                        <label class="control-label col-lg-4">
                            [% $user->gettext('Enddatum') %]
                        </label>
                        <div class="col-lg-8">
                            <input type="text" name="EndDate"  id ="EndDateTextForm" style="display:none;" class="form-control datetimepicker" value="" />
                            <p>[% $user->gettext('Das Enddatum darf nicht vor dem') %] [% $wf.EndDate|date_format:"%d.%m.%Y %H:%M" %] [% $user->gettext('liegen') %]</p>
                        </div>
                        <div class="col-lg-12">
                            <span class="help-block">
                                [% $user->gettext('Durch diese Funktion werden die Fälligkeitszeiten der Aktivitäten entsprechend der definierten Dauer der nachfolgenden Aktivitäten berechnet.') %]
                                [% $user->gettext('Dadurch erhalten die letzten Aktivitäten den Zeitpunkt des gewünschten Enddatums als Fälligkeitsdatum.') %]
                            </span>
                        </div>
                    </div>
                [% /if %]
            </div>
            [% if !$startWFForm %]
                <div class="col-lg-6">
                    <div class="form-group row mb-3">
                        <label class="control-label col-lg-4">
                            [% if FALSE && !$showactive %]
                                <input type="radio" name="DateType" id="DateType" value="1" [% if $wf.DateType == 1 %]checked="checked"[% /if %] >
                            [% /if %]
                            [% $user->gettext('Startdatum') %]
                        </label>
                        <div class="col-lg-8">
                            <input type="text" name="StartDate" id="StartDate" class="form-control [% if false && !$showactive %]datetimepicker[% /if %]" value="[% $wf.StartDate|date_format:"%d.%m.%Y %H:%M" %]" [% if true || $showactive %]readonly="readonly"[% else %]onBlur="sndReq('StartDate');"[% /if %] />
                        </div>
                    </div>

                    <div class="form-group row mb-3">
                        <label class="control-label col-lg-4">
                            [% if FALSE && !$showactive %]
                                <input type="radio" name="DateType" id="DateType" value="1" [% if $wf.DateType == 1 %]checked="checked"[% /if %] >
                            [% /if %]
                            [% $user->gettext('Enddatum') %]
                        </label>
                        <div class="col-lg-8">
                            <input type="text"  name="EndDate" id="EndDate" class="form-control [% if false && !$showactive %]datetimepicker[% /if %]" value="[% $wf.EndDate|date_format:"%d.%m.%Y %H:%M" %]" [% if true || $showactive %]readonly="readonly"[% else %]onBlur="sndReq('EndDate');"[% /if %] />
                        </div>
                    </div>

                    <div class="form-group row mb-3">
                        <label class="control-label col-lg-4">
                            [% $user->gettext('Dauer') %]:
                        </label>
                        <div class="col-lg-8">
                            <p class="form-control-static">[% $wf.duration_total %] [% $user->gettext('Tage') %] [% if $wf.StatusID != 3 %] ([% $user->gettext(' bis zu') %] [% $wf.Duration_total_plus %] [% $user->gettext('Tage') %])[% /if %]</p>

                            <input type="hidden" name="Duration_total" value="[% $wf.duration_total %]" />
                        </div>
                    </div>
                    [% if $wf.TicketID %]
                        <div class="form-group row mb-3">
                            <label class="control-label col-lg-4">
                                [% $user->gettext('Gestartet aus Ticket') %]:
                            </label>
                            <div class="col-lg-8">
                                <p class="form-control-static"><a href='index.php?module=ticket&event=show&id=[% $wf.TicketID %]'>(#[% $wf.TicketID %]) [% $wf.TicketDescr %]</a></p>
                            </div>
                        </div>
                    [% /if %]

                </div>


            [% /if %]

        </div>
    </div>

</div>
[% if $id > 0 || $showactive %]
    <div class="card panel-info shadow-sm rounded">
        <div class="card-header">
            <div class="row">
                <div class="col-lg-4">
                    <span class="fcs-card-title h3">[% $user->gettext('Aktivitäten') %]</span>
                </div>
                <div class="col-lg-8">
                    <div class="form-check form-check-inline m-0 p-0 align-middle">
                        <input class="form-check-input" type="checkbox" id="filterSkipped" />
                        <label class="form-check-label small" for="filterSkipped">[% $user->gettext('ÜBERSPRUNGENE anzeigen') %]</label>
                    </div>
                </div>
                <div class="col-lg-6 text-end">
                    <div class="btn-group">
                        [% if $showactive %]
                            [%*
                            Keine zusätzlichen Aktivitäten in laufende  WFs
                            <input type="button" onclick="window.open('index.php?module=workflow&event=createai&[% if $wf.ID > 0%]wfiid=[% $wf.ID %][% else %]sid=1[% /if %]', 'NewActivity');" value="[% $user->gettext('Neue Aktivität') %]" class="btn btn-outline-primary" />
                            *%]
                        [% else %]
                            [% if $wf.WFDID %]
                                <input type="button" onclick="[% if $wf.WFDID > 0%]window.open('index.php?module=workflow&amp;event=createActivityDef&wfdid=[% $wf.WFDID %]', 'NewActivity')[% else %]document.getElementById('opennewact').value = 1; document.wfDef.submit()[% /if %];" value="[% $user->gettext('Neue Aktivität') %]" class="btn btn-outline-primary" />
                            [% /if %]
                        [% /if %]
                    </div>
                </div>
            </div>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered">
                    <thead>

                        <tr class="fields">
                            <td>
                                &nbsp;[% $user->gettext('#') %]&nbsp;
                            </td>
                            [% if $showactive %]
                                <td>
                                    [% $user->gettext('Status') %]
                                </td>
                            [% /if %]
                            <td>
                                [% $user->gettext('Aktivität') %]
                            </td>
                            <td>
                                [% $user->gettext('Adressaten') %]
                            </td>

                            <td>
                                &nbsp;[% $user->gettext('Voraussetzung <br />&nbsp;(Aktivität oder Datum)') %]&nbsp;
                            </td>
                            <td>
                                &nbsp;&nbsp;[% $user->gettext('Dauer <br />&nbsp;(in Tagen)') %]&nbsp;
                            </td>
                            [% if $showactive %]
                                <td>
                                    &nbsp;&nbsp;[% $user->gettext('tats. Dauer <br />&nbsp;(in Tagen)') %]&nbsp;
                                </td>
                            [% /if %]
                            <td>
                                &nbsp;
                            </td>
                            <td>
                                &nbsp;[% $user->gettext('Aktion') %]
                            </td>
                        </tr>
                    </thead>
                    <tbody>
                        [% foreach from=$wf.aGantt item=Activity key=pos %]
                            <tr class="ActThread_[% $Activity.ThreadID2 %] Activity_[% $Activity.aiid %] [% if $Activity.StatusID == 15 %]skipped[% /if %]" [% if $Activity.StatusID == 15 %]style="display: none;"[% /if %]>
                                <td>
                                    &nbsp;([% $pos %])&nbsp;
                                </td>
                                [% if $showactive %]
                                    <td>
                                        [% $user->gettext($Activity.Status) %]&nbsp;&nbsp;&nbsp;
                                    </td>
                                [% /if %]
                                <td>
                                    [% $Activity.Descr %]
                                    [% if $Activity.StartWFDID %]
                                        <strong><br/>[% $user->gettext('Startet Workflow') %] [% $Activity.startWFDescr %]</strong>
                                        [% /if %]
                                </td>
                                <td>

                                    [% if $Activity.targettype == 1 %]

                                        <b>[% $user->gettext('Benutzer') %]: </b>[% $Activity.TargetUsers %]

                                    [% /if %]
                                    [% if $Activity.targettype == 2 %]
                                        <b>[% $user->gettext('Gruppe') %]: </b>[% $Activity.TargetGroups %]
                                    [% /if %]

                                    [% if $Activity.targettype == 3 %]
                                        [% $user->gettext('Initiator') %]
                                    [% /if %]
                                    [% if $Activity.targettype == 4 %]
                                        [% $user->gettext('Aus vorhergehender Aktivität') %]
                                    [% /if %]

                                    [% if $Activity.Warning.ContactWarning %]
                                        <div class="alert alert-danger">
                                            [% $user->gettext('Adressat fehlt') %]
                                        </div>
                                    [% /if %]
                                    &nbsp;&nbsp;&nbsp;
                                </td>
                                <td>
                                    ([% $Activity.condition %])
                                    <span id="DefActsFor_[% $Activity.aid %]">
                                        [% if $useWFDGantt %]
                                            [% foreach from=$Activity.O.DepActivitys item=DepAct %]
                                                <strong>[% $DepAct.Descr %]</strong>
                                                [% if $DepAct.Field %]
                                                    - [% $DepAct.Field %]: [% $DepAct.Value %]
                                                [% /if %]
                                                <br/>
                                            [% /foreach %]
                                        [% else %]
                                            [% foreach from=$Activity.O->getDepActivityInstances() item=DepAct %]
                                                <strong>[% $DepAct.Descr %]</strong>
                                                [% if $DepAct.Field %]
                                                    - [% $DepAct.Field %]: [% $DepAct.Value %]
                                                [% /if %]
                                                <br/>
                                            [% /foreach %]
                                        [% /if %]

                                    </span>

                                    [% if $Activity.Warning.AktivityDateWarning %]
                                        <div class="alert alert-danger">
                                            [% $user->gettext('Fälligkeitszeit vor FEZ') %]
                                        </div>
                                    [% /if %]
                                </td>
                                <td>
                                    [% $Activity.Duration %] (+ [% $Activity.O->ActivityDate %])
                                </td>
                                [% if $showactive %]
                                    <td>
                                    [% if $Activity.StatusID != 10 %][% $Activity.calcDuration %][% /if %]
                                </td>
                            [% /if %]
                            <td>[% if $Activity.cp && $Activity.Puffer <= 0 %]&nbsp;<span style="color:red;" title="[% $user->gettext('Kritischer Pfad - Gibt es in diesen Aktivitäten Verzögerungen, verzögert sich evtl. der ganze Workflow') %]"> [% $user->gettext('K') %] </span>&nbsp;[% /if %]</td>
                            <td>
                                <div style="text-align:center;">
                                    [% if $Activity.aid > 0 %]

                                        [% if $user->hasRight(704) %]
                                            <a class="btn btn-outline-secondary" href="index.php?module=workflow&amp;event=removeActivityDef&aid=[% $Activity.aid %]" onclick="return confirm('[% $Activity.Descr %] \n[% $user->gettext('wirklich l&ouml;schen?') %]');">
                                                <span class="fa fa-trash" title="[% $user->gettext('L&ouml;schen') %]"></span></a>
                                            [% else %]

                                        [% /if %]
                                        [% if $user->hasRight(704) %]
                                            <a class="btn btn-outline-secondary" href="index.php?module=workflow&amp;event=editActivityDef&amp;aid=[% $Activity.aid %]">
                                                <span class="fa fa-pencil" title="[% $user->gettext('Bearbeiten') %]"></span></a>
                                            [% /if %]

                                        <a class="btn btn-outline-secondary" href="index.php?module=workflow&amp;event=editActivityDef&aid=[% $Activity.aiid %]">
                                            <span class="fa fa-search"title="[% $user->gettext('Anzeigen') %]"></span></a>

                                    [% else %]
                                        [% if $Activity.StatusID != 3 %]
                                            [% if $user->hasRight(703) %]
                                                <a class="btn btn-outline-secondary" href="index.php?module=workflow&amp;event=removeAI&amp;aiid=[% $Activity.aiid %]" onclick="return confirm('[% $Activity.Descr %] \n[% $user->gettext('wirklich l&ouml;schen?') %]');">
                                                    <span class="fa fa-trash" title="[% $user->gettext('L&ouml;schen') %]"></span></a>
                                                [% else %]
                                                [% /if %]
                                                [% if $user->hasRight(703) %]
                                                <a class="btn btn-outline-secondary" href="index.php?module=workflow&amp;event=editAI&amp;aiid=[% $Activity.aiid %]">
                                                    <span class="fa fa-pencil" title="[% $user->gettext('Bearbeiten') %]"></span></a>
                                                [% /if %]
                                            [% /if %]
                                        <a class="btn btn-outline-secondary" href="index.php?module=workflow&amp;event=showAI&amp;aiid=[% $Activity.aiid %]">
                                            <span class="fa fa-search"title="[% $user->gettext('Anzeigen') %]"></span></a>
                                        [% /if %]
                            </td>
                        </tr>
                        [% if $Activity.O->StartedWFIID  %]
                            <tr >
                                <td colspan="9">
                                    <span onclick="showWFInstanz([% $Activity.O->StartedWFIID  %]);" class="btn btn-outline-secondary btn-block">[% $user->gettext('Aktivitäten von Workflow ') %]<strong>[% $Activity.startWFDescr %]</strong> <span id="toggle_[% $Activity.O->StartedWFIID  %]">[% $user->gettext('anzeigen') %]</span></span>
                                    <div id="RowForWFDef_[% $Activity.O->StartedWFIID  %]" style="display:none;">

                                    </div>
                                </td>
                            </tr>
                        [% /if %]
                    [% /foreach %]
                </tbody>
            </table>
        </div>
    </div>
</div>
[% /if %]
[% if $id > 0 || $showactive %]
    <div class="card panel-info shadow-sm rounded">
        <div class="card-header">
            <span class="fcs-card-title h3">[%$user->gettext('Graph')%]</span>
        </div>
        <div class="card-body">
            <div id="cy"></div>
        </div>
    </div>

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

<style>
    #cy {
        width: 90%;
        min-height: [% $DiagramHight|default:600 %]px;
        display: block;
    }
</style>

<script type="text/javascript" language="JavaScript">

    function ChangeDate(DateField)
    {
        DateFrom = (DateField == 'EndDate') ? 'StartDate' : 'EndDate';

        var datum = document.getElementById(DateFrom).value;


        var zeit;

        //(Schritt 1) Fehlerbehandlung
        if (!datum)
            return false;
        datum = datum.toString();

        // Schritt 2) In Zeit und Datum aufteilen
        datum = datum.split(" ");
        if (datum.length > 1) {
            if (datum[0].indexOf(".") != -1) {
                zeit = datum[1];
                datum = datum[0];
            } else {
                zeit = datum[0];
                datum = datum[1];
            }
        } else {
            zeit = "";
            datum = datum[0];
        }

        //(Schritt 3) Aufspaltung des Datums
        datum = datum.split(".");
        if (datum.length != 3)
            return false;

        //(Schritt 4) Entfernung der fuehrenden Nullen und Anpassung des Monats
        datum[0] = parseInt(datum[0], 10);
        datum[1] = parseInt(datum[1], 10) - 1;

        //(Schritt 5) Behandlung Jahr nur zweistellig
        if (datum[2].length == 2)
            datum[2] = "20" + datum[2];

        //(Schritt 6) Erzeugung eines neuen Dateobjektes
        var kontrolldatum = new Date(datum[2], datum[1], datum[0]);

        //(Schritt 7) Vergleich, ob das eingegebene Datum gleich dem JS-Datum ist
        if (kontrolldatum.getDate() == datum[0] &&
                kontrolldatum.getMonth() == datum[1] &&
                kontrolldatum.getFullYear() == datum[2]) {

            //(Schritt 8) Ueberpruefung der Zeitangabe
            if (zeit.length > 0) {

                //(Schritt 9) Aufsplatung der Zeitangabe
                zeit = zeit.split(":");
                if (zeit.length != 2)
                    return false;

                //(Schritt 10) Entfernung der fuehrenden Nullen
                zeit[0] = parseInt(zeit[0], 10);
                zeit[1] = parseInt(zeit[1], 10);

                //(Schritt 11) Zeitangabe liegt im gueltigen Bereich
                if (zeit[0] > 23 || zeit[0] < 0 || zeit[1] > 59 || zeit[1] < 0) {
                    return false;
                }
            }

            // Alle Angaben sind in Ordnung
            if (DateField == 'EndDate')
            {
                var newdate = new Date(datum[2], datum[1], datum[0], zeit[0] + ([% $wf.duration_total|default:0 %] * 24), zeit[1]);
            } else {
                var newdate = new Date(datum[2], datum[1], datum[0], zeit[0] - ([% $wf.duration_total|default:0 %] * 24), zeit[1]);
            }
            var datestring = dtDatum(newdate);
            document.getElementById(DateField).value = datestring;
            return true;

        } else
            return false;
    }

    function dtDatum(datum)
    {
        var monat = datum.getMonth() + 1;
        var jahr = datum.getFullYear();
        var tag = datum.getDate();
        var stunde = datum.getHours();
        var minute = datum.getMinutes();

        monat = monat + '';
        tag = tag + '';
        stunde = stunde + '';
        if (monat.length == 1)
            monat = '0' + monat;
        if (tag.length == 1)
            tag = '0' + tag;
        if (stunde.length == 1)
            stunde = '0' + stunde;
        if (String(minute).length == 1)
            minute = '0' + minute;
        var dt = tag + '.' + monat + '.' + jahr + ' ' + stunde + ':' + minute;
        return dt;
    }



    function createRequestObject() {
        var ro;
        var browser = navigator.appName;
        if (browser == "Microsoft Internet Explorer") {
            ro = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            ro = new XMLHttpRequest();
        }
        return ro;
    }

    var http = createRequestObject();

    function sndReq(DateType) {

        var Date = document.getElementById(DateType).value;
        if (gueltigesDatum(Date)) {

            if (DateType == 'StartDate') {
                var DateAdd = "&add=1";
            } else {
                var DateAdd = "&add=0";
            }

            var url = 'index.php?module=workflow&event=getDesireTime&Date=' + Date + DateAdd + '&days=[% $wf.duration_total %]';
            http.open('get', url);
            if (DateType == 'StartDate') {
                http.onreadystatechange = changeEndDate;
            } else {
                http.onreadystatechange = changeStartDate;
            }

            http.send(null);

        } else {
            alert(Date + " [% $user->gettext('ist kein gültiges Datum') %]!");
        }
    }

    function changeEndDate() {
        if (http.readyState == 4) {
            var response = http.responseText;

            if (document.getElementById("EndDate")) {
                document.getElementById("EndDate").value = response;
            }
        }
    }

    function changeStartDate() {
        if (http.readyState == 4) {
            var response = http.responseText;

            if (document.getElementById("StartDate")) {
                document.getElementById("StartDate").value = response;
            }
        }
    }

    function gueltigesDatum(datum) {

        var zeit;

        //(Schritt 1) Fehlerbehandlung
        if (!datum)
            return false;
        datum = datum.toString();

        // Schritt 2) In Zeit und Datum aufteilen
        datum = datum.split(" ");
        if (datum.length > 1) {
            if (datum[0].indexOf(".") != -1) {
                zeit = datum[1];
                datum = datum[0];
            } else {
                zeit = datum[0];
                datum = datum[1];
            }
        } else {
            zeit = "";
            datum = datum[0];
        }

        //(Schritt 3) Aufspaltung des Datums
        datum = datum.split(".");
        if (datum.length != 3)
            return false;

        //(Schritt 4) Entfernung der fuehrenden Nullen und Anpassung des Monats
        datum[0] = parseInt(datum[0], 10);
        datum[1] = parseInt(datum[1], 10) - 1;

        //(Schritt 5) Behandlung Jahr nur zweistellig
        if (datum[2].length == 2)
            datum[2] = "20" + datum[2];

        //(Schritt 6) Erzeugung eines neuen Dateobjektes
        var kontrolldatum = new Date(datum[2], datum[1], datum[0]);

        //(Schritt 7) Vergleich, ob das eingegebene Datum gleich dem JS-Datum ist
        if (kontrolldatum.getDate() == datum[0] &&
                kontrolldatum.getMonth() == datum[1] &&
                kontrolldatum.getFullYear() == datum[2]) {

            //(Schritt 8) Ueberpruefung der Zeitangabe
            if (zeit.length > 0) {

                //(Schritt 9) Aufsplatung der Zeitangabe
                zeit = zeit.split(":");
                if (zeit.length != 2)
                    return false;

                //(Schritt 10) Entfernung der fuehrenden Nullen
                zeit[0] = parseInt(zeit[0], 10);
                zeit[1] = parseInt(zeit[1], 10);

                //(Schritt 11) Zeitangabe liegt im gueltigen Bereich
                if (zeit[0] > 23 || zeit[0] < 0 || zeit[1] > 59 || zeit[1] < 0) {
                    return false;
                }
            }

            // Alle Angaben sind in Ordnung
            return true;

        } else
            return false;
    }

    $(document).ready(function () {

        $(".dialog").fancybox({
            maxWidth: 1200,
            maxHeight: 800,
            closeClick: false
        });

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

    $("#ProjectID").on("change", function (e) {

        var ProjectID = $("#ProjectID").val();

        $.getJSON("index.php?module=workflow&event=getProjectRefLvl2&ProjectID=" + ProjectID, function (result) {
            if (!$.isEmptyObject(result)) {
                $("#RefLvl2IDSelect").show();
                var $secondChoice = $("#RefLvl2ID");
                $secondChoice.empty();
                $secondChoice.append('<option value="0">[% $user->gettext('-- Kostenstelle wählen --') %]</option>');
                $.each(result, function (index, value) {
                    $secondChoice.append($("<option />").val(index).text(value));
                });
            }
        });
    });
    [% if $id > 0 || $showactive %]
    var cy = cytoscape({

        container: document.getElementById('cy'), // container to render in

        userZoomingEnabled: false,
        userPanningEnabled: false,

        elements: [% $CYElements %],

        style: [// the stylesheet for the graph
            {
                selector: 'node',
                style: {
                    'label': 'data(title)',
                    'content': 'data(title)',
                    'shape': 'rectangle',
                    'width': 'label',
                    'height': 'label',
                    'text-valign': 'center',
                    'text-halign': 'center',
                    'text-wrap': 'wrap'
                }
            },

            {
                selector: '.status_2', //Activ
                style: {
                    'background-color': 'green'
                }
            },
            {
                selector: '.status_6', //Reopened
                style: {
                    'background-color': 'green'
                }
            },
            {
                selector: '.status_3', //Closed
                style: {
                    'background-color': 'grey'
                }
            },
            {
                selector: '.status_10', //WAITING
                style: {
                    'background-color': 'yellow'
                }
            },
            {
                selector: '.status_14', //CANCELED
                style: {
                    'background-color': 'lightgray'
                }
            },
            {
                selector: '.status_15', //SKIPPED
                style: {
                    'background-color': 'lightgray'
                }
            },

            {
                selector: 'edge',
                style: {
                    'width': 4,
                    'target-arrow-shape': 'triangle',
                    'target-arrow-color': 'grey',
                    'curve-style': 'bezier',
                    'line-color': 'grey',
                    'content': 'data(label)',
                    'text-rotation': 'none',
                    'source-text-offset': '5',
                    'target-text-offset': '5',
                    'font-size': '0.8em'
                }
            },
            {
                selector: '.edgestatus_2', //ACTIVE
                style: {
                    'line-color': 'green',
                    'target-arrow-color': 'green',
                    'line-style': 'solid'
                }
            },
            {
                selector: '.edgestatus_3', //OPEN
                style: {
                    'line-color': 'grey',
                    'target-arrow-color': 'grey',
                    'line-style': 'solid'
                }
            },
            {
                selector: '.edgestatus_15', //SKIPPED
                style: {
                    'line-color': 'lightgray',
                    'target-arrow-color': 'lightgray',
                    'line-style': 'dashed'
                }
            },
            {
                selector: '.OrCondition', //ODER
                style: {
                    'line-style': 'dotted'
                }
            },
            {
                selector: '.startsWF',
                style: {
                    'shape': 'diamond'
                }
            }
        ],

        layout: {
            name: 'breadthfirst',
            directed: true,
            spacingFactor: 0.25,
            padding: 3
        }

    }).on('tap', 'node', function (evt) {
        var node = evt.target;

        if (node.data().StartedWFIID > 0) {
            window.open('index.php?module=workflow&event=showactivewf&wfiid=' + node.data().StartedWFIID, '_blank');
        } else {
            window.open('index.php?module=workflow&event=showAI&aiid=' + node.id(), '_top');
        }


    }).on('mouseover', 'node', function (evt) {
        var node = evt.target;
//  console.log( 'Maus auf Element ' + node.id() );
        $(".Activity_" + node.id()).addClass('trhover');
    }).on('mouseout ', 'node', function (evt) {
        var node = evt.target;
//  console.log( 'Maus verlässt Element ' + node.id() );
        $(".Activity_" + node.id()).removeClass('trhover');
    });
    [% /if %]




    function showWFInstanz(WFIID) {


        if ($("#RowForWFDef_" + WFIID).is(":visible") == true) {
            $("#toggle_" + WFIID).html("[% $user->gettext('anzeigen') %]");
            $("#RowForWFDef_" + WFIID).html("").hide();
        } else {
            $("#toggle_" + WFIID).html("[% $user->gettext('ausblenden') %]");
            $("#RowForWFDef_" + WFIID).load("index.php?module=workflow&event=showWFInstanceActivities&wfiid=" + WFIID).show();
        }

    }

    /**
     * toggleEnddatum
     */
    function toggleEnddatum() {
        if ($("#EndDateToggle").is(':checked')) {
            $("#EndDateText").show();
            $("#EndDateTextForm").show();
            $("#EndDateHidden").hide();
        } else {
            $("#EndDateText").hide();
            $("#EndDateTextForm").hide();
            $("#EndDateHidden").show();
        }
    }



    $(document).ready(function () {
        $(".contactSelect").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
                    };
                },
                processResults: function (data) {
                    return {
                        results: data.items
                    };
                }
            },
            escapeMarkup: function (markup) {
                return markup;
            }
        });

        $('.userSelect').select2({
            theme: 'bootstrap-5',
            language: ts_lang,
            ajax: {
                url: 'index.php?module=user&event=getAllUsersJSON&WithUsername=1',
                processResults: function (data) {
                    return {
                        results: data.items
                    };
                }
            }
        });	
    })


$(document).ready(function () {
    $('#filterSkipped').on('change', function () {
        if ($(this).is(':checked')) {
            $('.skipped').fadeIn();
        } else {
            $('.skipped').fadeOut();
        }
    });
});

</script>
<!-- Component active_wf_form end -->
