<?php
include('../include/headscript.php');
include('../class/company.php');
$conn = new mysqli($servername, $username, $password, $database);

$query = "SELECT * FROM laboratories";
$result = $conn->query($query);

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        echo "<tr>";
        echo "<td>" . $row['idlab'] . "</td>";
        echo "<td>" . $row['name'] . "</td>";
        echo "<td>" . $row['reflab'] . "</td>";
        echo "<td>" . $row['country'] . "</td>";
        echo "<td>" . $row['status'] . "</td>";
        echo "<td>" . substr($row['api_key'], 0, 5) . "*****" . "</td>";
        echo "<td>
                <button class='btn btn-primary btn-sm' onclick='editLab(" . $row['idlab'] . ")'>Edit</button>
                <button class='btn btn-danger btn-sm' onclick='deleteLab(" . $row['idlab'] . ")'>Delete</button>
                <button class='btn btn-warning btn-sm' onclick='regenerateKeys(" . $row['idlab'] . ")'>Regenerate Keys</button>
              </td>";
        echo "</tr>";
    }
} else {
    echo "<tr><td colspan='7'>No laboratories found</td></tr>";
}

$conn->close();
