<form action="" method="post" name="hm" onsubmit="return false" id="hm" enctype="multipart/form-data" style="margin:0;padding:0;">
    <input type="hidden" name="pos" id="pos" value="[% $pos %]" />
    <input type="hidden" name="Activate" id="Activate" value="0" />
    <input type="hidden" name="sort" id="sort" value="[% $sort %]" />
    <input type="hidden" name="sortorder" id="sortorder" value="[% $sortorder %]" />

    <!-- ###CONTENT### begin -->
    <div class="card panel-fcs-border shadow-sm">
        <div class="card-header">
            <span class="fcs-card-title h2">
                [% $user->gettext('Beitragsfreigabe')%]
            </span>
        </div>
        <div class="card-body">
            [% if $FAQEntries && false %]
                <div class="card panel-info shadow-sm rounded">
                    <div class="card-body">
                        <div class="row text-center">
                            <input type="button" value="[% $user->gettext('Freigeben') %]" onclick="document.getElementById('Activate').value = 1;
                    submitForm();" class="btn btn-outline-primary" />
                        </div>
                    </div>
                </div>
            [% /if %]
            <div class="card panel-info shadow-sm rounded">
                <div class="card panel-info shadow-sm rounded">
                    <div class="card-header">
                        <div class="row">
                            <div class="col-sm-4">
                                <span class="fcs-card-title h3">[% $user->gettext('Liste')%]</span> 

                            </div>
                            <div class="col-sm-8 text-end">
                                 [% if $FAQEntries %]
                                  <input type="button" value="[% $user->gettext('Ausgewählte Beiträge freigeben') %]" onclick="document.getElementById('Activate').value = 1;
                    submitForm();" class="btn btn-outline-primary" />
                                  [% /if %]
                            </div>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr class="fields">
                                        <td><input type="checkbox" id="CheckAll" onclick="checkAll(this);" /></td>
                                        <td style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "ShortDescription" %]
                                          'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                                  'sort'
                                                  ).value = 'ShortDescription'
                                            [% /if %];
                                                  submitForm();">
                                            [% $user->gettext('Beschreibung') %]
                                            [% if $sort == "ShortDescription" %]&nbsp;<span class="fa fa-chevron-[% if $sortorder == "DESC" %]down[% else %]up[% /if %]"></span>[% /if %]
                                        </td>
                                        <td style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "CreateDate" %]
                                          'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                                  'sort').value = 'CreateDate'
                                            [% /if %];
                                                  submitForm();">
                                            [% $user->gettext('Erstellt am') %]
                                            [% if $sort == "CreateDate" %]&nbsp;<span class="fa fa-chevron-[% if $sortorder == "DESC" %]down[% else %]up[% /if %]"></span>[% /if %]
                                        </td>
                                        <td style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "CreateUser" %]
                                          'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                                  'sort'
                                                  ).value = 'CreateUser'
                                            [% /if %];submitForm();">
                                            [% $user->gettext('Erstellt von') %]
                                            [% if $sort == "CreateUser" %]&nbsp;<span class="fa fa-chevron-[% if $sortorder == "DESC" %]down[% else %]up[% /if %]"></span>[% /if %]
                                        </td>
                                        <td style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "UpdateDate" %]
                                          'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                                  'sort'
                                                  ).value = 'UpdateDate'
                                            [% /if %];
                                                  submitForm();">
                                            [% $user->gettext('Aktualisiert am') %]
                                            [% if $sort == "UpdateDate" %]&nbsp;<span class="fa fa-chevron-[% if $sortorder == "DESC" %]down[% else %]up[% /if %]"></span>[% /if %]
                                        </td>
                                        <td style="cursor:pointer;" onclick="document.getElementById(
                                            [% if $sort == "UpdateUser" %]
                                          'sortorder').value = '[% if $sortorder == "DESC" %]ASC[% else %]DESC[% /if %]'
                                            [% else %]
                                                  'sort'
                                                  ).value = 'UpdateUser'
                                            [% /if %];
                                                  submitForm();">
                                            [% $user->gettext('Aktualisiert von') %]
                                            [% if $sort == "UpdateUser" %]&nbsp;<span class="fa fa-chevron-[% if $sortorder == "DESC" %]down[% else %]up[% /if %]"></span>[% /if %]
                                        </td>
                                        <td></td>
                                    </tr>
                                </thead>
                                <tbody>
                                    [% foreach from=$FAQEntries item=FAQEntry %]
                                        <tr>
                                            <td><input type="checkbox" name="Active[]" value="[% $FAQEntry->FAQDataID %]" /></td>
                                            <td>[% $FAQEntry->ShortDescription %]</td>
                                            <td>[% $FAQEntry->CreateDate %]</td>
                                            <td>[% $FAQEntry->CreateUser %]</td>
                                            <td>[% $FAQEntry->UpdateDate %]</td>
                                            <td>[% $FAQEntry->UpdateUser %]</td>
                                            <td><a href="index.php?module=knowledgebase&fid=[% $FAQEntry->FAQDataID %]" class="btn btn-outline-secondary"><span class="fa fa-search"></span></a></td>
                                        </tr>
                                    [% foreachelse %]
                                        <tr class="even">
                                            <td colspan="8">[% $user->gettext('Keine Einträge zum freigeben vorhanden') %]</td>
                                        </tr>
                                    [% /foreach %]
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</form>

<script>
    function switchPage(page) {
        document.getElementById('pos').value = page;
        submitForm();
    }

    function checkAll(obj) {

        var check = obj.checked;
        var elements = document.getElementsByName("Active[]");

        for (i = 0; i < elements.length; i++) {
            elements[i].checked = check;
        }
    }
</script>
