<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=reporting&amp;class=advance" method="POST" name="reportform" class="form-label-left form-horizontal">

    <input type="hidden" name="Pos" value="[% $pos %]" id="reportform[pos]" />
    <input type="hidden" name="export" value="" id="reportexport" />

    <script type="text/javascript" language="javascript">
        function switchPage(pos) {
            document.getElementById("reportform[pos]").value = pos;
            reloadPage("");
        }


        function reloadPage(str) {
            document.getElementById("reportexport").value = str;
            document.reportform.submit();
        }

        [% if $Tools->FCS_Count($Headers) %]
        function SelectAll() {
            var obj = document.getElementById("SelectedFields");
            for (i = 0; i < obj.options.length; i++)
                obj.options[i].selected = true;
        }

        function SelectNone() {
            var obj = document.getElementById("SelectedFields");
            for (i = 0; i < obj.options.length; i++)
                obj.options[i].selected = false;
        }

        function SelectInvert() {
            var obj = document.getElementById("SelectedFields");
            for (i = 0; i < obj.options.length; i++)
                obj.options[i].selected = (obj.options[i].selected) ? false : true;
        }
        [% /if %]
        $(document).ready(function () {
            $(".datetimepicker").datetimepicker({
                currentText: 'Jetzt',
                closeText: 'OK',
                timeText: 'Zeit',
                hourText: 'Stunde'
            });

            $(".multiple").multiselect({
                buttonClass: 'form-select',
    templates: {
        button: '<button type="button" class="multiselect dropdown-toggle" data-bs-toggle="dropdown"><span class="multiselect-selected-text"></span></button>',
    },
                checkAllText: '[% $user->gettext("Alle") %]',
                uncheckAllText: '[% $user->gettext("Keine") %]',
                noneSelectedText: '[% $user->gettext("Wählen Sie") %]',
                selectedText: '# [% $user->gettext("gewählt") %]',
                selectedList: 1,
                header: true,
                multiple: false
            });

            $(".multiple_small").multiselect({
                buttonClass: 'form-select',
    templates: {
        button: '<button type="button" class="multiselect dropdown-toggle" data-bs-toggle="dropdown"><span class="multiselect-selected-text"></span></button>',
    },
                selectedList: 1,
                header: false,
                multiple: false,
                minWidth: 50,
                height: 'auto'
            });

            $(".multiple2").multiselect({
                buttonClass: 'form-select',
    templates: {
        button: '<button type="button" class="multiselect dropdown-toggle" data-bs-toggle="dropdown"><span class="multiselect-selected-text"></span></button>',
    },
                checkAllText: '[% $user->gettext("Alle") %]',
                uncheckAllText: '[% $user->gettext("Keine") %]',
                noneSelectedText: '[% $user->gettext("Wählen Sie") %]',
                selectedText: '# [% $user->gettext("gewählt") %]',
                selectedList: 1,
                header: true,
                multiple: true
            });

        })

    </script>

    <div class="card panel-fcs-border shadow-sm">
        <div class="card-header">
            <span class="fcs-card-title h2">
                [% $user->gettext('Reporting') %]
            </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">
                            <div class="form-group">
                                <label class="control-label col-lg-4">
                                    [% $user->gettext('Report') %]:
                                </label>
                                <div class="col-lg-8">
                                    <select name="ReportID" size="1" onchange="document.getElementById('reportform[pos]').value = 0;reloadPage('');" class="form-control multiple">
                                        <option value="0">[% $user->gettext('-- Bitte wählen Sie --') %]</option>
                                        [% foreach from=$reports item=report %]
                                            <option value="[% $report.reportid %]" [% if $ReportID == $report.reportid %]selected="selected"[% /if %]>[% $report.reportname %]</option>
                                        [% /foreach %]
                                    </select>
                                </div>
                            </div>
                            [% if $Tools->FCS_Count($Headers) %]

                                <div class="form-group">
                                    <label class="control-label col-lg-4">
                                        [% $user->gettext('Sortierung') %]:
                                    </label>
                                    <div class="col-lg-8">
                                        <select name="OrderBy" size="1" class="form-control multiple">
                                            <option value="0">[% $user->gettext('-- unsortiert --') %]</option>
                                            [% foreach from=$Headers item=head %]
                                                <option value="[% $head.field %]" [% if $OrderBy == $head.field %]selected="selected"[% /if %]>[% $head.field %]</option>
                                            [% /foreach %]
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-lg-4">
                                        [% $user->gettext('Absteigend') %]:
                                    </label>
                                    <div class="col-lg-8">
                                        <input type="checkbox" name="Ordering" value="DESC" [% if $Ordering == "DESC" %]checked="checked"[% /if %]/>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-lg-4">
                                        [% $user->gettext('Zeige folgende Felder') %]:
                                    </label>
                                    <div class="col-lg-8">
                                        <select size="1" name="SelectedFields[]" multiple="multiple" id="SelectedFields" class="form-control multiple2">
                                            [% foreach from=$Headers item=header %]
                                                [% html_options output=$header.field values=$header.field selected=$SelectedFields %]
                                            [% /foreach %]
                                        </select>
                                    </div>
                                </div>

                            [% /if %]
                        </div>
                        <div class="col-lg-6">
                            <div class="form-group">
                                <label class="control-label col-lg-4">
                                    [% $user->gettext('Einträge pro Seite') %]:
                                </label>
                                <div class="col-lg-8">
                                    <select s name="EntriesPerPage" onchange="document.reportform.submit();" class="form-control multiple_small">
                                        <option value="5" [% if $entries_per_page == 5 %]selected="selected"[% /if %]>5</option>
                                        <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>
                                </div>
                            </div>
                            [% if $Tools->FCS_Count($Headers) %]
                                <div class="form-group form-inline">
                                    <label class="control-label col-lg-4">
                                        [% $user->gettext('Suche') %]:
                                    </label>
                                    <div class="col-lg-8">
                                        [% if $Tools->FCS_Count($char_fields) %]
                                            <select name="CharField" size="1" class="form-control multiple">
                                                <option value="0">[% $user->gettext('-- Alle Textfelder --') %]</option>
                                                [% foreach from=$char_fields item=field %]
                                                    <option value="[% $field.field %]" [% if $CharField == $field.field %]selected="selected"[% /if %]>[% $field.field %]</option>
                                                [% /foreach %]
                                            </select>
                                            <select name="CharPattern" size="1" class="textbox multiple">
                                                <option value="=" [% if $CharPattern == "=" %]selected="selected"[% /if %]>[% $user->gettext('gleich') %]</option>
                                                <option value="<>" [% if $CharPattern == "<>" %]selected="selected"[% /if %]>[% $user->gettext('nicht gleich') %]</option>
                                                <option value="LIKE" [% if $CharPattern == "LIKE" %]selected="selected"[% /if %]>[% $user->gettext('wie') %]</option>
                                                <option value="NOT LIKE" [% if $CharPattern == "NOT LIKE" %]selected="selected"[% /if %]>[% $user->gettext('nicht wie') %]</option>
                                            </select>
                                            <input type="text" class="form-control" name="CharText" size="20" maxlength="100" value="[% $CharText %]" /> <br><br>

                                            <select name="CharField2" size="1" class="form-control multiple">
                                                <option value="0">[% $user->gettext('-- Alle Textfelder --') %]</option>
                                                [% foreach from=$char_fields item=field %]
                                                    <option value="[% $field.field %]" [% if $CharField2 == $field.field %]selected="selected"[% /if %]>[% $field.field %]</option>
                                                [% /foreach %]
                                            </select>
                                            <select name="CharPattern2" size="1" class="textbox multiple">
                                                <option value="=" [% if $CharPattern2 == "=" %]selected="selected"[% /if %]>[% $user->gettext('gleich') %]</option>
                                                <option value="<>" [% if $CharPattern2 == "<>" %]selected="selected"[% /if %]>[% $user->gettext('nicht gleich') %]</option>
                                                <option value="LIKE" [% if $CharPattern2 == "LIKE" %]selected="selected"[% /if %]>[% $user->gettext('wie') %]</option>
                                                <option value="NOT LIKE" [% if $CharPattern2 == "NOT LIKE" %]selected="selected"[% /if %]>[% $user->gettext('nicht wie') %]</option>
                                            </select>
                                            <input type="text" class="form-control" name="CharText2" size="20" maxlength="100" value="[% $CharText2 %]" /> <br><br>
                                            <select name="CharField3" size="1" class="form-control multiple">
                                                <option value="0">[% $user->gettext('-- Alle Textfelder --') %]</option>
                                                [% foreach from=$char_fields item=field %]
                                                    <option value="[% $field.field %]" [% if $CharField3 == $field.field %]selected="selected"[% /if %]>[% $field.field %]</option>
                                                [% /foreach %]
                                            </select>
                                            <select name="CharPattern3" size="1" class="textbox multiple">
                                                <option value="=" [% if $CharPattern3 == "=" %]selected="selected"[% /if %]>[% $user->gettext('gleich') %]</option>
                                                <option value="<>" [% if $CharPattern3 == "<>" %]selected="selected"[% /if %]>[% $user->gettext('nicht gleich') %]</option>
                                                <option value="LIKE" [% if $CharPattern3 == "LIKE" %]selected="selected"[% /if %]>[% $user->gettext('wie') %]</option>
                                                <option value="NOT LIKE" [% if $CharPattern3 == "NOT LIKE" %]selected="selected"[% /if %]>[% $user->gettext('nicht wie') %]</option>
                                            </select>
                                            <input type="text" class="form-control" name="CharText3" size="20" maxlength="100" value="[% $CharText3 %]" /> 
                                        [% /if %]
                                        [% if $Tools->FCS_Count($numeric_fields) %]
                                            <select name="NumericFrom" size="1" class="form-control multiple">
                                                <option value="0">[% $user->gettext('-- Alle Zahlenfelder --') %]</option>
                                                [% foreach from=$numeric_fields item=field %]
                                                    <option value="[% $field.field %]" [% if $NumericFrom == $field.field %]selected="selected"[% /if %]>[% $field.field %]</option>
                                                [% /foreach %]
                                            </select>

                                            <select name="NumericFromPattern" size="1" class="form-control multiple">
                                                <option value="=" [% if $NumericFromPattern == "=" %]selected="selected"[% /if %]>[% $user->gettext('gleich') %]</option>
                                                <option value="<>" [% if $NumericFromPattern == "<>" %]selected="selected"[% /if %]>[% $user->gettext('nicht gleich') %]</option>
                                                <option value=">" [% if $NumericFromPattern == ">" %]selected="selected"[% /if %]>[% $user->gettext('größer') %]</option>
                                                <option value="<" [% if $NumericFromPattern == "<" %]selected="selected"[% /if %]>[% $user->gettext('kleiner') %]</option>
                                            </select>

                                            <input type="text" class="form-control" name="NumericFromText" size="10" maxlength="50" value="[% $NumericFromText %]" /><br><br>

                                            <select name="NumericTo" size="1" class="form-control multiple">
                                                <option value="0">[% $user->gettext('-- Alle Zahlenfelder --') %]</option>
                                                [% foreach from=$numeric_fields item=field %]
                                                    <option value="[% $field.field %]" [% if $NumericTo == $field.field %]selected="selected"[% /if %]>[% $field.field %]</option>
                                                [% /foreach %]
                                            </select>

                                            <select name="NumericToPattern" size="1" class="form-control multiple">
                                                <option value="=" [% if $NumericToPattern == "=" %]selected="selected"[% /if %]>[% $user->gettext('gleich') %]</option>
                                                <option value="<>" [% if $NumericToPattern == "<>" %]selected="selected"[% /if %]>[% $user->gettext('nicht gleich') %]</option>
                                                <option value=">" [% if $NumericToPattern == ">" %]selected="selected"[% /if %]>[% $user->gettext('größer') %]</option>
                                                <option value="<" [% if $NumericToPattern == "<" %]selected="selected"[% /if %]>[% $user->gettext('kleiner') %]</option>
                                            </select>
                                            <input type="text" class="form-control" name="NumericToText" size="10" maxlength="50" value="[% $NumericToText %]" />

                                        [% /if %]
                                        [% if $Tools->FCS_Count($datetime_fields) %]
                                            <select name="DateTimeFrom" size="1" class="form-control multiple">
                                                <option value="0">[% $user->gettext('-- Alle Datumsfelder --') %]</option>
                                                [% foreach from=$datetime_fields item=field %]
                                                    <option value="[% $field.field %]" [% if $DateTimeFrom == $field.field %]selected="selected"[% /if %]>[% $field.field %]</option>
                                                [% /foreach %]
                                            </select>

                                            <select name="DateTimeFromPattern" size="1" class="form-control multiple">
                                                <option value="=" [% if $DateTimeFromPattern == "=" %]selected="selected"[% /if %]>[% $user->gettext('gleich') %]</option>
                                                <option value=">" [% if $DateTimeFromPattern == ">" %]selected="selected"[% /if %]>[% $user->gettext('größer') %]</option>
                                                <option value="<" [% if $DateTimeFromPattern == "<" %]selected="selected"[% /if %]>[% $user->gettext('kleiner') %]</option>
                                            </select>

                                            <input type="text" class="form-control datetimepicker" name="DateTimeFromText" id="DateTimeFromText" size="19" maxlength="19" value="[% $DateTimeFromText %]" /><br><br>
                                            <select name="DateTimeTo" size="1" class="form-control multiple">
                                                <option value="0">[% $user->gettext('-- Alle Datumsfelder --') %]</option>
                                                [% foreach from=$datetime_fields item=field %]
                                                    <option value="[% $field.field %]" [% if $DateTimeTo == $field.field %]selected="selected"[% /if %]>[% $field.field %]</option>
                                                [% /foreach %]
                                            </select>

                                            <select name="DateTimeToPattern" size="1" class="form-control multiple">
                                                <option value="=" [% if $DateTimeToPattern == "=" %]selected="selected"[% /if %]>[% $user->gettext('gleich') %]</option>
                                                <option value=">" [% if $DateTimeToPattern == ">" %]selected="selected"[% /if %]>[% $user->gettext('größer') %]</option>
                                                <option value="<" [% if $DateTimeToPattern == "<" %]selected="selected"[% /if %]>[% $user->gettext('kleiner') %]</option>
                                            </select>
                                            <input type="text" class="form-control datetimepicker" name="DateTimeToText" id="DateTimeToText" size="19" maxlength="19" value="[% $DateTimeToText %]" />

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

                    <div class="row">
                        <div class="col-lg-12 text-end">
                            <div class="btn-group">
                                <input type="button" value="Filter" class="btn btn-outline-primary" onclick="reloadPage('');" />
                                [% if $Tools->FCS_Count($Headers) && $Tools->FCS_Count($Rows) %]
                                    [% if $download == true %]
                                        [% if $xml == true %]<input type="button" value="XML" class="btn btn-outline-primary" onclick="reloadPage('xml');" />[% /if %]
                                        <input type="button" value="HTML" class="btn btn-outline-primary" onclick="reloadPage('html');" />
                                        <input type="button" value="CSV" class="btn btn-outline-primary" onclick="reloadPage('csv');" />
                                    [% /if %]
                                    [% if $xls == true %]<input type="button" value="XLS" class="btn btn-outline-primary" onclick="reloadPage('xls');" />[% /if %]
                                [% /if %]
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            [% if $Tools->FCS_Count($Rows) %]

                <div class="card panel-info shadow-sm rounded">
                    <div class="card-header">
                        <span class="fcs-card-title h3">
                        [% if $ReportName != "" %] [% $ReportName %] ( [% $Entries %] [% if $Entries != 1 %][% $user->gettext('Einträge gefunden') %][% else %][% $user->gettext('Eintrag gefunden') %][% /if %] )
                        [% else %]
                            [% $user->gettext ('Result')%]
                        [% /if %]
                    </span>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>

                                [% foreach from=$Rows item=row name=hits %]
                                    [% if $smarty.foreach.hits.iteration == 1 %]
                                        <tr class="fields">
                                            [% foreach from=$row item=col key=head %]
                                                <td>&nbsp;[% $head %]</td>
                                            [% /foreach %]
                                        </tr>
                                    </thead><tbody>
                                    [% /if %]
                                    <tr>
                                        [% foreach from=$row item=col key=head %]
                                            <td>&nbsp;[% $col|htmlspecialchars %]&nbsp;</td>
                                        [% /foreach %]
                                    </tr>
                                [% /foreach %]
                            </tbody>
                        </table>
                        <div class="text-center">[% $Paging %]</div>
                    </div>
                </div>
            </div>
        [% /if %]


    </div>
</div>


</form>