<?php
include "../Functions/crudplan.php";
$pdo = new PDO("mysql:host=127.0.0.1;dbname=janya763", "janya763", "vOOxhXUhWhgCPWFC");
// Delete or edit plan
if (isset($_GET["edit"])) {
if ($_GET["edit"] > 0) {
}
} else if (isset($_GET["delete"])) {
if ($_GET["delete"] > 0) {
$result = getPlan($pdo, $_GET["delete"]);
if ($result != null && $result["is_active"] == 1) {
deletePlan($pdo, $_GET["delete"]);
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Plan</title>
</head>
<body>
<div class="plan">
<form action="plan.php">
<?php
$result = getAllActivePlan($pdo);
foreach ($result as $row) {
$week = $row["week"];
$startDate = new DateTime(datetime: $row["fromDate"]); // Start date
$endDate = (clone $startDate)->modify("+$week week"); // End date is start + week
?>
<div class="plan" id=<?= $row['pk_plan'] ?>>
<p><?= $startDate->format("d/m/Y") ?>
until <?= $endDate->format("d/m/Y") ?></p>
<button type="submit" name="edit" value=<?= $row["pk_plan"] ?>>Edit</button>
<button type="submit" name="delete" value=<?= $row["pk_plan"] ?>>Delete</button>
</div>
<?php
}
?>
</form>
</div>
</body>
</html>