<?php
include("../includes/db_connection.php");
include("../includes/auth.php");
include("partials/header.php");

$id = $_GET['id'] ?? '';
$name="";
$status="Active";

if($id){

$stmt=$conn->prepare("SELECT * FROM accreditations WHERE id=?");
$stmt->bind_param("i",$id);
$stmt->execute();
$data=$stmt->get_result()->fetch_assoc();

$name=$data['name'];
$status=$data['status'];

}
?>

<div class="container py-4">

<h4><?= $id?'Edit':'Add' ?> Accreditation</h4>

<form method="POST" action="accreditation_save.php">

<input type="hidden" name="id" value="<?= $id ?>">

<div class="mb-3">
<label>Name</label>
<input type="text" name="name" class="form-control" required value="<?= $name ?>">
</div>

<div class="mb-3">
<label>Status</label>

<select name="status" class="form-select">

<option value="Active" <?= $status=="Active"?'selected':'' ?>>Active</option>
<option value="Inactive" <?= $status=="Inactive"?'selected':'' ?>>Inactive</option>

</select>

</div>

<button class="btn btn-success">Save</button>

<a href="accreditations.php" class="btn btn-secondary">Back</a>

</form>

</div>

<?php include("partials/footer.php"); ?>