Quelltext des aktuellen Standes
<?php
/**
* Template: Meine zugewiesenen IT-Geräte
*
* Verfügbare Variablen:
* $assets – Array mit zugewiesenen Assets (inkl. image_url, warranty_until, location_name)
* $text_no_devices – Hinweistext wenn keine Geräte vorhanden
* $text_email_hint – Hinweis zur E-Mail-Verknüpfung
*/
if (!defined('ABSPATH')) exit;
/**
* Berechnet Garantie-Status und -Text.
* Gibt ['text' => '...', 'class' => '...'] zurück.
*/
if (!function_exists('opennit_warranty_info')) {
function opennit_warranty_info(string $warranty_until): array {
$today = new DateTime('today');
try {
$until = new DateTime($warranty_until);
} catch (Exception $e) {
return ['text' => '', 'class' => ''];
}
$diff = (int)$today->diff($until)->days;
$sign = $until >= $today ? 1 : -1;
$days = $diff * $sign;
$formatted = $until->format('d.m.Y');
if ($days < 0) {
return ['text' => 'Garantie abgelaufen (' . $formatted . ')', 'class' => 'opennit-warranty-exp'];
} elseif ($days <= 90) {
return ['text' => 'Garantie bis ' . $formatted . ' (noch ' . $days . ' Tage)', 'class' => 'opennit-warranty-warn'];
} else {
return ['text' => 'Garantie bis ' . $formatted, 'class' => 'opennit-warranty-ok'];
}
}
}
?>
<div class="opennit-wrap">
<div class="opennit-card">
<div class="opennit-card__head">
<div class="opennit-card__head-icon" aria-hidden="true">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="4" width="16" height="16" rx="2"/><rect x="9" y="9" width="6" height="6"/><line x1="9" y1="2" x2="9" y2="4"/><line x1="15" y1="2" x2="15" y2="4"/><line x1="9" y1="20" x2="9" y2="22"/><line x1="15" y1="20" x2="15" y2="22"/><line x1="20" y1="9" x2="22" y2="9"/><line x1="20" y1="15" x2="22" y2="15"/><line x1="2" y1="9" x2="4" y2="9"/><line x1="2" y1="15" x2="4" y2="15"/></svg>
</div>
<div class="opennit-card__head-text">
<h2 class="opennit-card__title">Meine Geräte</h2>
<p class="opennit-card__subtitle">IT-Geräte, die Ihnen aktuell zugewiesen sind.</p>
</div>
</div>
<?php if (empty($assets)): ?>
<div class="opennit-card__body">
<div class="opennit-notice opennit-notice-info">
<?= esc_html($text_no_devices ?? 'Ihnen sind aktuell keine Geräte zugewiesen.') ?>
<small><?= esc_html($text_email_hint ?? 'Hinweis: Ihre E-Mail-Adresse muss im IT-System hinterlegt sein, damit Geräte hier angezeigt werden.') ?></small>
</div>
</div>
<?php else: ?>
<div class="opennit-devices-list">
<?php foreach ($assets as $asset):
$title = trim(implode(' ', array_filter([
$asset['manufacturer'] ?? '',
$asset['type'] ?? '',
])));
if (!$title) $title = $asset['inventory_number'] ?? '–';
$inv = $asset['inventory_number'] ?? '';
$category = $asset['category'] ?? '';
$image_url = $asset['image_url'] ?? null;
$warranty_until= $asset['warranty_until'] ?? '';
$location_name = $asset['location_name'] ?? '';
$warranty = $warranty_until ? opennit_warranty_info($warranty_until) : null;
?>
<div class="opennit-device-item">
<?php if ($image_url): ?>
<div class="opennit-device-image">
<img src="<?= esc_url($image_url) ?>"
alt="<?= esc_attr($title) ?>"
loading="lazy">
</div>
<?php endif; ?>
<div class="opennit-device-info">
<div class="opennit-device-title-row">
<span class="opennit-device-name"><?= esc_html($title) ?></span>
<?php if ($category): ?>
<span class="opennit-device-type"><?= esc_html($category) ?></span>
<?php endif; ?>
</div>
<?php if ($inv): ?>
<span class="opennit-device-inv"><?= esc_html($inv) ?></span>
<?php endif; ?>
<div class="opennit-device-extra">
<?php if ($location_name): ?>
<span class="opennit-device-extra-item">
<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0 1 18 0z"/><circle cx="12" cy="10" r="3"/></svg>
<?= esc_html($location_name) ?>
</span>
<?php endif; ?>
<?php if ($warranty): ?>
<span class="opennit-device-extra-item <?= esc_attr($warranty['class']) ?>">
<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
<?= esc_html($warranty['text']) ?>
</span>
<?php endif; ?>
</div>
</div>
<div class="opennit-device-status-col">
<span class="opennit-badge opennit-badge-active">Zugewiesen</span>
<?php if (!empty($ticket_page_url) && !empty($asset['id'])): ?>
<a href="<?= esc_url($ticket_page_url . '?opennit_asset_id=' . intval($asset['id'])) ?>"
class="opennit-btn opennit-btn-ticket"
title="Ticket für dieses Gerät erstellen">
Ticket melden
</a>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>