<?php
    defined('BASEPATH') OR exit('No direct script access allowed');
?>
<div class="right_col" role="main">
    <div class="">
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2><?= isset($trashbin) && $trashbin ? 'Gelöschte ' : '' ?>Blog-Posts</h2>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <p class="text-muted font-13 m-b-30">
                            <?=
                                isset($trashbin) && $trashbin ? 'Hier sind alle bisher in den Papierkorb verschobenen Blog-Posts zu finden, zu verwalten, zu wiederherstellen und zum endgültigen Löschen!' : 'Hier sind alle bisher verfassten Blog-Posts zu finden und zu verwalten.'
                            ?>
                        </p>
                        <div style="overflow-x: auto">
                            <table id="datatable-fixed-header" class="table table-striped table-bordered" data-order='[[ 0, "desc" ]]' data-page-length="25">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Titel</th>
                                    <th>Beschreibung</th>
                                    <th>Status</th>
                                    <th>Veröffentlichung</th>
                                    <th>Letzte Änderung</th>
                                    <th>Author</th>
                                    <th>Kategorie</th>
                                    <th>Aufrufe</th>
                                    <th>Likes</th>
                                    <th>Kommentare</th>
                                    <th>Aktionen</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php foreach ($posts as $post) { ?>
                                    <tr id="post-<?= $post['postID'] ?>">
                                        <td>
                                            <?= $post['postID'] ?>
                                        </td>
                                        <td>
                                            <a href="<?= base_url('blog/post/' . $post['postUrl']) ?>" target="_blank"><?= $post['postTitle'] ?></a>
                                        </td>
                                        <td>
                                            <?= $post['postDesc'] ?>
                                        </td>
                                        <td>
                                            <?= $post['postStateDisplay'] ?>
                                        </td>
                                        <td>
                                            <?= date('d.m.Y H:i', strtotime($post['postPublishDate'])) ?>
                                        </td>
                                        <td>
                                            <?= date('d.m.Y H:i', strtotime($post['postLastEdit'])) ?>
                                        </td>
                                        <td>
                                            <a href="<?= base_url('user/' . $post['postAuthorUsername']) ?>" target="_blank"><?= $post['postAuthorDisplayname'] ?></a>
                                        </td>
                                        <td>
                                            <a href="<?= base_url('blog/category/' . $post['categoryName']) ?>" target="_blank"><?= $post['categoryDisplayName'] ?></a>
                                        </td>
                                        <td>
                                            <?= $post['postViews'] ?>
                                            <i class="fa fa-eye"></i>
                                        </td>
                                        <td>
                                            <?= $post['likeCount'] ?>
                                            <i class="fa fa-heart"
                                        </td>
                                        <td>
                                            <?= $post['commentCount'] ?>
                                            <i class="fa fa-comment"></i>
                                        </td>
                                        <?php if (isset($trashbin) && $trashbin): ?>
                                            <td>
                                                <a data-toggle="tooltip" data-placement="top" title="" data-original-title="Bearbeiten" href="<?= base_url('admin/blog/edit/' . $post['postID']) ?>" target="_blank" class="btn btn-xs btn-default">
                                                    <i class="fa fa-edit"></i>
                                                </a>
                                                <a data-toggle="tooltip" data-placement="top" title="" data-original-title="History" href="<?= base_url('admin/blog/history/' . $post['postID']) ?>" target="_blank" class="btn btn-xs btn-default">
                                                    <i class="fa fa-history"></i>
                                                </a>
                                                <a data-toggle="tooltip" data-placement="top" title="" data-original-title="Wiederherstellen" onclick="restorePost(<?= $post['postID'] ?>)" class="btn btn-xs btn-green">
                                                    <i class="fa fa-undo"></i>
                                                </a>
                                                <a href="" data-toggle="tooltip" data-placement="top" title="Endgültig löschen">
                                                    <button type="button" class="btn btn-xs btn-red" data-toggle="modal" data-target="#deleteModal" data-type="Blog-Post" data-title="<?= $post['postTitle'] ?>" data-id="<?= $post['postID'] ?>">
                                                        <i class="fa fa-trash"></i>
                                                    </button>
                                                </a>
                                            </td>
                                        <?php else: ?>
                                            <td>
                                                <a data-toggle="tooltip" data-placement="top" title="" data-original-title="Bearbeiten" href="<?= base_url('admin/blog/edit/' . $post['postID'] . '/') ?>" target="_blank" class="btn btn-xs btn-default">
                                                    <i class="fa fa-edit"></i>
                                                </a>
                                                <a data-toggle="tooltip" data-placement="top" title="" data-original-title="History" href="<?= base_url('admin/blog/history/' . $post['postID']) ?>" target="_blank" class="btn btn-xs btn-default">
                                                    <i class="fa fa-history"></i>
                                                </a>
                                                <a data-toggle="tooltip" data-placement="top" title="" data-original-title="Löschen" onclick="deletePost(<?= $post['postID'] ?>)" class="btn btn-xs btn-red">
                                                    <i class="fa fa-trash"></i>
                                                </a>
                                            </td>
                                        <?php endif; ?>
                                    </tr>
                                <?php } ?>
                                </tbody>
                            </table>
                        </div>
                        <?php if (isset($trashbin) && $trashbin): ?>
                            <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog"
                                 aria-labelledby="deleteModalTitle">
                                <div class="modal-dialog modal-dialog-centered" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal"
                                                    aria-label="Schließen">
                                                <span aria-hidden="true">&times;</span>
                                            </button>
                                            <h4 class="modal-title" id="deleteModalTitle">Bist du dir WIRKLICH sicher?</h4>
                                        </div>
                                        <div class="modal-body">
                                            <h3>
                                                <i class="fa fa-spinner fa-spin"></i>
                                            </h3>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="reset" class="btn btn-default" data-dismiss="modal">Nicht
                                                                                                              löschen!
                                            </button>
                                            <button type="button" class="btn btn-red">Ja, löschen!</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>