WowPress-Tailwind/theme/pages/sks.php

173 lines
8.9 KiB
PHP

<?php
use Wenprise\Eloquent\Database;
use Wenprise\Eloquent\Facades\DB;
use WoWPress\Frontend\Icon;
use WoWPress\Models\Log;
use WoWPress\Models\SKS;
use WoWPress\Models\SKSHistory;
set_sidebar_status('top', false);
get_header();
if (empty($GLOBALS['wowpress']['liste'])):
$listen = SKSHistory::groupBy('list_name')->get();
?>
<div class="top-title flex flex-row gap-2" style="margin-top:calc(-1 * var(--wowp-gap))">
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
<?= $GLOBALS['wowpress']['page_title'] ?>
</div>
</div>
<section id="primary">
<main id="main">
<div class="bg-glass shadow p-auto flex flex-col gap-3">
<?php foreach ($listen as $list) : ?>
<a class="btn btn-outline" href="/sks/<?= $list->list_name ?>"><?= $list->list_name ?></a>
<?php endforeach; ?>
</div>
</main>
</section>
<?php else:
$liste = SKSHistory::getLatestList($GLOBALS['wowpress']['liste']);
?>
<div class="top-title flex flex-col gap-2" style="margin-top:calc(-1 * var(--wowp-gap))">
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
SKS-Liste "<?= $liste->list_name ?>"
</div>
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<div class="flex flex-row justify-center gap-2">
<?php
if ($prevList = $liste->getPreviousList()):
?>
<form action="/request" method="POST" class="hidden" id="undoSKS">
<?php wp_nonce_field('undoSKS', 'undoSKS_nonce'); ?>
<input type="hidden" name="action" value="undoSKS">
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
</form>
<button type="submit" form="undoSKS" class="btn btn-outline btn-deepblue text-white hover:text-alliance">
Rückgängig (Stand vom <?= format_date($prevList->created_at, "dd.MM.yyyy HH:mm") ?>)
</button>
<?php endif;
if ($nextList = $liste->getNextList()):
?>
<form action="/request" method="POST" class="hidden" id="redoSKS">
<?php wp_nonce_field('redoSKS', 'redoSKS_nonce'); ?>
<input type="hidden" name="action" value="redoSKS">
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
</form>
<button type="submit" form="redoSKS" class="btn btn-outline btn-deepblue text-white hover:text-alliance">
Wiederherstellen (Stand vom <?= format_date($nextList->created_at, "dd.MM.yyyy HH:mm") ?>)
</button>
<?php endif; ?>
</div>
<? endif; ?>
</div>
<section id="primary">
<main id="main">
<div class="bg-glass shadow p-auto flex flex-col gap-2">
<table class="table-auto w-full">
<thead>
<tr class="bg-glass">
<th class="p-auto w-40">Rang</th>
<th class="p-auto">Charakter</th>
<th class="p-auto hidden lg:table-cell">Server</th>
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<th class="p-auto hidden lg:table-cell">Status</th>
<th class="p-auto w-0">Aktion</th>
<?php endif; ?>
</tr>
</thead>
<?php foreach ($liste->list_array as $list_item) :
switch ($list_item['rank']) {
case 1:
$rank_color = "text-[#bfac1d]";
break;
case 2:
$rank_color = "text-[#9c9b9a]";
break;
case 3:
$rank_color = "text-[#9e4f00]";
break;
default:
$rank_color = "text-white";
}
$char = $liste->getCharData($list_item['char']);
?>
<tr class="text-<?= $list_item['active'] ? $char->color : "slate-500" ?> odd:bg-slate-900">
<td class="p-auto text-center <?= $rank_color ?>"><?= $list_item['rank'] ?></td>
<td class="p-auto text-center" style="font-size:1.3em"><?= $char->name ?></td>
<td class="p-auto text-center hidden lg:table-cell" style="font-size:1.3em"><?= $char->realm ?></td>
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<td class="p-auto text-center hidden lg:table-cell">
<form action="/request" method="POST">
<?php wp_nonce_field('toggleSKS', 'toggleSKS_nonce'); ?>
<input type="hidden" name="action" value="toggleSKS">
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
<input type="hidden" name="rank" value="<?= $list_item['rank'] ?>">
<button type="submit" class="btn w-full btn-outline btn-<?= $list_item['active'] ? $char->color : "slate" ?>"><?= $list_item['active'] ? "Aktiv" : "Inaktiv" ?></button>
</form>
</td>
<td class="p-auto">
<div class="flex gap-2 flex-col lg:flex-row justify-end">
<?php if ($list_item['active']) : ?>
<form action="/request" method="POST">
<?php wp_nonce_field('lootSKS', 'lootSKS_nonce'); ?>
<input type="hidden" name="action" value="lootSKS">
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
<input type="hidden" name="char" value="<?= $list_item['char'] ?>">
<button type="submit" title="Looten" class="btn btn-outline btn-<?= $char->color ?>"><?= Icon::get('o-sparkles') ?></button>
</form>
<?php else : ?>
<form action="/request" method="POST">
<?php wp_nonce_field('deleteSKS', 'deleteSKS_nonce'); ?>
<input type="hidden" name="action" value="deleteSKS">
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
<input type="hidden" name="char" value="<?= $list_item['char'] ?>">
<button type="submit" title="Löschen" class="btn btn-outline btn-red"><?= Icon::get('o-trash') ?></button>
</form>
<? endif; ?>
</div>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</table>
</div>
</main>
</section>
<?php
if (current_user_can('wowpress_edit_raids')) : ?>
<div x-data>
<template x-teleport="#sidebar_right">
<div class="bg-glass shadow p-auto order-1">
<h4 class="text-xl font-bold text-center mb-2">Charakter Hinzufügen</h4>
<form action="/request" method="POST">
<div class="flex flex-col gap-2">
<?php wp_nonce_field('addSKS', 'addSKS_nonce'); ?>
<input type="hidden" name="action" value="addSKS">
<input type="hidden" name="list_name" value="<?=$liste->list_name?>">
<input type="text" name="name" placeholder="Name" class="text-black">
<input type="text" name="realm" placeholder="Server" class="text-black">
<button type="submit" class="btn btn-outline btn-hunter">Hinzufügen</a>
</div>
</form>
</div>
</template>
</div>
<?php
endif;
endif;
get_footer();