Schwarzes-Web-Brett/public/index.php

137 lines
4.5 KiB
PHP

<?php
require_once "../src/categories.php";
require_once "../src/adverts.php";
// Hole alle Kategorien und Inserate
$categories = Categories::getAllCategories();
$adverts = Adverts::getAllAdverts();
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Schwarzes Brett</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
h1, h2 {
color: #333;
}
ul {
list-style-type: none;
padding: 0;
}
li {
margin-bottom: 10px;
}
.category-link {
display: block;
padding: 10px 15px;
background-color: #f5f5f5;
border-radius: 5px;
text-decoration: none;
color: #333;
transition: background-color 0.2s;
}
.category-link:hover {
background-color: #e0e0e0;
}
.no-categories, .no-inserate {
color: #666;
font-style: italic;
}
.inserat {
border: 1px solid #ddd;
padding: 15px;
margin-bottom: 15px;
border-radius: 5px;
}
.inserat h2 {
margin-top: 0;
}
.inserat-date {
color: #666;
font-size: 0.8em;
}
.filter-form {
margin: 20px 0;
padding: 15px;
background-color: #f5f5f5;
border-radius: 5px;
}
.filter-form select {
padding: 8px;
border-radius: 4px;
border: 1px solid #ddd;
margin-right: 10px;
}
.filter-form button {
padding: 8px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.filter-form button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h1>Schwarzes Brett</h1>
<div style="margin-bottom: 20px;">
<a href="create_advert.php" style="display: inline-block; padding: 10px 15px; background-color: #4CAF50; color: white; text-decoration: none; border-radius: 5px;">Neues Inserat erstellen</a>
</div>
<h2>Kategorien</h2>
<?php if (empty($categories)): ?>
<p class="no-categories">Keine Kategorien gefunden.</p>
<?php else: ?>
<ul>
<?php foreach ($categories as $category): ?>
<li>
<a class="category-link" href="category.php?id=<?php echo $category['id']; ?>">
<?php echo htmlspecialchars($category['name']); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<h2>Aktuelle Inserate</h2>
<?php if (empty($adverts)): ?>
<p class="no-inserate">Keine Inserate gefunden.</p>
<?php else: ?>
<?php foreach ($adverts as $advert): ?>
<div class="inserat">
<h2><?php echo htmlspecialchars($advert['name']); ?></h2>
<p><?php echo htmlspecialchars($advert['description']); ?></p>
<p class="inserat-date">Erstellt am: <?php echo htmlspecialchars($advert['date']); ?></p>
<?php if (isset($advert['user_name']) || isset($advert['user_email']) || isset($advert['user_telephone'])): ?>
<div class="user-contact">
<h3>Kontaktinformationen:</h3>
<?php if (isset($advert['user_name'])): ?>
<p><strong>Name:</strong> <?php echo htmlspecialchars($advert['user_name']); ?></p>
<?php endif; ?>
<?php if (isset($advert['user_email'])): ?>
<p><strong>E-Mail:</strong> <?php echo htmlspecialchars($advert['user_email']); ?></p>
<?php endif; ?>
<?php if (isset($advert['user_telephone'])): ?>
<p><strong>Telefon:</strong> <?php echo htmlspecialchars($advert['user_telephone']); ?></p>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
</body>
</html>