<?php
    defined('BASEPATH') OR exit('No direct script access allowed');

    use Coduo\PHPHumanizer\DateTimeHumanizer;

?>
<!-- page content -->
<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>Projekte</h2>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <p class="text-muted font-13 m-b-30">
                            Alle derzeit vorhandenen Einträge im Portfolio sind hier aufgelistet
                        </p>
                        <div style="overflow-x: auto">
                            <table id="datatable-fixed-header" class="table table-striped table-bordered" data-order='[[ 0, "desc" ]]'>
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Name</th>
                                    <th>Titel</th>
                                    <th>Kategorie</th>
                                    <th>Headline</th>
                                    <th>Datum</th>
                                    <th>Bild</th>
                                    <th>Tools</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                    foreach ($entries as $entry) {
                                        $pCategories = $this->projectsModel->getEntryCategories($entry['ID']);
                                        $pCategoriesList = "";
                                        foreach ($pCategories as $pCategory) {
                                            $pCategoriesList .= $pCategory['displayname'] . "<br>";
                                        }
                                        ?>
                                        <tr id="entry-<?= $entry['ID'] ?>">
                                            <td><?= $entry['ID'] ?></td>
                                            <td><?= $entry['name'] ?></td>
                                            <td>
                                                <a href="<?= base_url('projects/entry/' . $entry['name']) ?>" target="_blank"><?= $entry['title'] ?></a>
                                            </td>
                                            <td><?= $pCategoriesList ?></td>
                                            <td><?= $entry['description'] ?></td>
                                            <?php $datetime = strtotime($entry['datetime']) ?>
                                            <td><?= date("d.m.Y", $datetime) . " - " . DateTimeHumanizer::difference(new \DateTime(), new \DateTime("@$datetime"), $_SESSION['site_lang']) ?></td>
                                            <td>
                                                <img src="<?= $entry['source'] ?>?h=110" class="img-fluid" style="max-height:110px;max-width:200px;">
                                            </td>
                                            <td>
                                                <a data-toggle="tooltip" data-placement="top" title="" data-original-title="Bearbeiten" href="<?= base_url('admin/projects/edit/' . $entry['ID']) ?>">
                                                    <button type="button" class="btn btn-xs btn-default">
                                                        <i class="fa fa-edit"></i>
                                                    </button>
                                                </a>
                                                <button type="button" class="btn btn-xs btn-red" data-toggle="modal" data-target="#deleteModal" data-type="Projekt" data-title="<?= $entry['title'] ?>" data-id="<?= $entry['ID'] ?>">
                                                    <i class="fa fa-trash"></i>
                                                </button>
                                            </td>
                                        </tr>
                                        <?php
                                    }
                                ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>Projekt-Kategorien</h2>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <p class="text-muted font-13 m-b-30">
                            Alle derzeit vorhandenen Kategorien sind hier aufgelistet
                        </p>
                        <table id="datatable-fixed-header" class="table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>Name</th>
                                <th>Titel - Deutsch</th>
                                <th>Titel - English</th>
                                <th>Titel - Französisch</th>
                                <th>Anzahl Einträge</th>
                                <th>Tools</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php foreach ($categories as $c) { ?>
                                <tr id="category-<?= $c['ID'] ?>">
                                    <td><?= $c['ID'] ?></td>
                                    <td><?= $c['collection'] ?></td>
                                    <td><?= $c['displayname'] ?></td>
                                    <td><?= $c['displaynameEnglish'] ?></td>
                                    <td><?= $c['displaynameFrench'] ?></td>
                                    <td><?= $c['count'] ?></td>
                                    <td>
                                        <button type="button" class="btn btn-xs btn-red" data-toggle="modal" data-target="#deleteModal" data-type="Projekt-Kategorie" data-title="<?= $c['displayname'] ?>" data-id="<?= $c['ID'] ?>">
                                            <i class="fa fa-trash"></i>
                                        </button>
                                    </td>
                                </tr>
                            <?php } ?>
                            </tbody>
                        </table>

                        <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalTitle">
                            <div class="modal-dialog" 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>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>