article_overview.php aktualisiert

This commit is contained in:
M_Viper 2024-02-27 20:54:58 +00:00
parent 259178e7d4
commit 97d3e86652
1 changed files with 84 additions and 73 deletions

View File

@ -38,6 +38,7 @@
<li><a href="index.php">Home</a></li> <li><a href="index.php">Home</a></li>
<li><a href="add_material_form.php">Artikel hinzufügen</a></li> <li><a href="add_material_form.php">Artikel hinzufügen</a></li>
<li><a href="article_overview.php">Artikel Übersicht</a></li> <li><a href="article_overview.php">Artikel Übersicht</a></li>
<li><a href="backup_restore.php">Backup</a></li>
</ul> </ul>
</nav> </nav>
</div> </div>
@ -67,89 +68,99 @@
<th>Aktionen</th> <th>Aktionen</th>
</tr> </tr>
<?php <?php
// Datenbankverbindung herstellen // Protokollierungsereignis einbinden
include_once 'config/config.php'; include_once 'log_event.php';
// Verbindung zur Datenbank herstellen // Datenbankverbindung herstellen
$conn = new mysqli($host, $username, $password, $database); include_once 'config/config.php';
if ($conn->connect_error) {
die("Verbindung zur Datenbank fehlgeschlagen: " . $conn->connect_error);
}
// SQL-Abfrage vorbereiten // Verbindung zur Datenbank herstellen
$sql = "SELECT * FROM materials"; $conn = new mysqli($host, $username, $password, $database);
if ($conn->connect_error) {
die("Verbindung zur Datenbank fehlgeschlagen: " . $conn->connect_error);
}
// Wenn nach einem Artikel gesucht wird // SQL-Abfrage vorbereiten
if(isset($_GET['search']) && !empty($_GET['search'])){ $sql = "SELECT * FROM materials";
$search = $_GET['search'];
$sql .= " WHERE // Wenn nach einem Artikel gesucht wird
if(isset($_GET['search']) && !empty($_GET['search'])){
$search = $_GET['search'];
$sql .= " WHERE
item_name LIKE '%" . $search . "%' OR item_name LIKE '%" . $search . "%' OR
manufacturer LIKE '%" . $search . "%' OR manufacturer LIKE '%" . $search . "%' OR
location LIKE '%" . $search . "%' OR location LIKE '%" . $search . "%' OR
barcode LIKE '%" . $search . "%'"; barcode LIKE '%" . $search . "%'";
}
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Daten ausgeben
while($row = $result->fetch_assoc()) {
$expiration_date = date("d.m.Y", strtotime($row["expiration_date"]));
$notification_days = intval($row["notification_days"]); // Tage vor dem Ablaufdatum aus der Datenbank lesen
$ten_days_before_expiry = date("d.m.Y", strtotime("-" . $notification_days . " days", strtotime($row["expiration_date"]))); // Tage vor dem Ablaufdatum berechnen
$current_date = date("d.m.Y"); // Aktuelles Datum
echo "<tr";
if (strtotime($current_date) >= strtotime($ten_days_before_expiry) && strtotime($current_date) <= strtotime($expiration_date)) {
echo " class='expiring'"; // Klasse 'expiring' hinzufügen
} }
echo ">";
echo "<td"; $result = $conn->query($sql);
if (strtotime($current_date) >= strtotime($ten_days_before_expiry) && strtotime($current_date) <= strtotime($expiration_date)) {
echo " style='color: red;'"; // Schriftfarbe auf Rot setzen if ($result->num_rows > 0) {
} // Daten ausgeben
echo ">" . $row["item_name"] . "</td>"; while($row = $result->fetch_assoc()) {
echo "<td>" . $row["manufacturer"] . "</td>"; $expiration_date = date("d.m.Y", strtotime($row["expiration_date"]));
echo "<td>" . $row["location"] . "</td>"; $notification_days = intval($row["notification_days"]); // Tage vor dem Ablaufdatum aus der Datenbank lesen
echo "<td>" . $row["amount_should"] . "</td>"; $ten_days_before_expiry = date("d.m.Y", strtotime("-" . $notification_days . " days", strtotime($row["expiration_date"]))); // Tage vor dem Ablaufdatum berechnen
echo "<td"; $current_date = date("d.m.Y"); // Aktuelles Datum
if ($row["amount_is"] < $row["amount_should"]) {
echo " class='low-stock'"; echo "<tr";
} if (strtotime($current_date) >= strtotime($ten_days_before_expiry) && strtotime($current_date) <= strtotime($expiration_date)) {
echo ">" . $row["amount_is"] . "</td>"; echo " class='expiring'"; // Klasse 'expiring' hinzufügen
echo "<td>" . $expiration_date . "</td>"; }
echo "<td>" . $row["barcode"] . "</td>"; echo ">";
echo "<td>";
if (!empty($row["image"])) { echo "<td";
echo "<img src='" . $row["image"] . "' alt='Bild' style='width: 50px; height: 50px;' onclick='toggleEditForm(" . $row["id"] . ")'>"; if (strtotime($current_date) >= strtotime($ten_days_before_expiry) && strtotime($current_date) <= strtotime($expiration_date)) {
echo " style='color: red;'"; // Schriftfarbe auf Rot setzen
}
echo ">" . $row["item_name"] . "</td>";
echo "<td>" . $row["manufacturer"] . "</td>";
echo "<td>" . $row["location"] . "</td>";
echo "<td>" . $row["amount_should"] . "</td>";
echo "<td";
if ($row["amount_is"] < $row["amount_should"]) {
echo " class='low-stock'";
}
echo ">" . $row["amount_is"] . "</td>";
echo "<td>" . $expiration_date . "</td>";
echo "<td>" . $row["barcode"] . "</td>";
echo "<td>";
if (!empty($row["image"])) {
echo "<img src='" . $row["image"] . "' alt='Bild' style='width: 50px; height: 50px;' onclick='toggleEditForm(" . $row["id"] . ")'>";
} else {
echo "<img src='img/free.png' alt='Standardbild' style='width: 50px; height: 50px;' onclick='toggleEditForm(" . $row["id"] . ")'>";
}
echo "</td>";
echo "<td><img src='img/bearbeiten.png' alt='Bearbeiten' style='width: 20px; height: 20px;' onclick='toggleEditForm(" . $row["id"] . ")'> &nbsp; | &nbsp; <a href='remove_article.php?id=" . $row["id"] . "' onclick='return confirmDelete();'><img src='img/delete.png' alt='Löschen' style='width: 20px; height: 20px;' ></a></td>";
echo "</tr>";
// Bearbeitungsformular für jedes Element einfügen
echo "<tr class='edit-form' id='edit-form-" . $row["id"] . "'><td colspan='9'>
<form id='form-" . $row["id"] . "' onsubmit='updateItem(event, " . $row["id"] . ")'>
<input type='text' name='name' value='" . $row["item_name"] . "'>
<input type='text' name='manufacturer' value='" . $row["manufacturer"] . "'>
<input type='text' name='location' value='" . $row["location"] . "'>
<input type='number' name='amount_should' value='" . $row["amount_should"] . "'>
<input type='number' name='amount_is' value='" . $row["amount_is"] . "'>
<input type='date' name='expiration_date' value='" . $row["expiration_date"] . "'>
<input type='text' name='barcode' value='" . $row["barcode"] . "'>
<input type='hidden' name='id' value='" . $row["id"] . "'>
<input type='submit' value='Speichern'>
</form>
</td></tr>";
// Loggen des Löschens eines Artikels
echo "<script>function confirmDelete" . $row["id"] . "() {
if(confirm('Möchten Sie diesen Artikel wirklich löschen?')) {
window.location.href = 'remove_article.php?id=" . $row["id"] . "';
}
}</script>";
}
} else { } else {
echo "<img src='img/free.png' alt='Standardbild' style='width: 50px; height: 50px;' onclick='toggleEditForm(" . $row["id"] . ")'>"; echo "<tr><td colspan='9'>Keine Artikel gefunden</td></tr>";
} }
echo "</td>"; $conn->close();
echo "<td><img src='img/bearbeiten.png' alt='Bearbeiten' style='width: 20px; height: 20px;' onclick='toggleEditForm(" . $row["id"] . ")'> &nbsp; | &nbsp; <a href='remove_article.php?id=" . $row["id"] . "' onclick='return confirmDelete();'><img src='img/delete.png' alt='Löschen' style='width: 20px; height: 20px;' ></a></td>"; ?>
echo "</tr>";
// Bearbeitungsformular für jedes Element einfügen
echo "<tr class='edit-form' id='edit-form-" . $row["id"] . "'><td colspan='9'>
<form id='form-" . $row["id"] . "' onsubmit='updateItem(event, " . $row["id"] . ")'>
<input type='text' name='name' value='" . $row["item_name"] . "'>
<input type='text' name='manufacturer' value='" . $row["manufacturer"] . "'>
<input type='text' name='location' value='" . $row["location"] . "'>
<input type='number' name='amount_should' value='" . $row["amount_should"] . "'>
<input type='number' name='amount_is' value='" . $row["amount_is"] . "'>
<input type='date' name='expiration_date' value='" . $row["expiration_date"] . "'>
<input type='text' name='barcode' value='" . $row["barcode"] . "'>
<input type='hidden' name='id' value='" . $row["id"] . "'>
<input type='submit' value='Speichern'>
</form>
</td></tr>";
}
} else {
echo "<tr><td colspan='9'>Keine Artikel gefunden</td></tr>";
}
$conn->close();
?>
</table> </table>
</div> </div>