Mini Kabibi Habibi
<?php
session_start();
@include 'include/config.php';
if (!isset($_SESSION['username_school'])) {
die("Error: User not logged in.");
}
$username = $_SESSION['username_school'];
// Fetch draft plans
$sql = "SELECT * FROM mista_plans WHERE username = ? AND status = 'draft'";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
echo "<h2>Your Saved Drafts</h2>";
echo "<table class='table table-bordered'>";
echo "<thead>
<tr>
<th>Division</th>
<th>Section</th>
<th>District</th>
<th>Month</th>
<th>Year</th>
<th>Status</th>
<th>Activities</th>
<th>Actions</th>
</tr>
</thead>";
echo "<tbody>";
while ($row = $result->fetch_assoc()) {
$plan_id = $row['id'];
// Fetch related activities
$activity_sql = "SELECT * FROM mista_plan_activities WHERE plan_id = ?";
$activity_stmt = $conn->prepare($activity_sql);
$activity_stmt->bind_param("i", $plan_id);
$activity_stmt->execute();
$activity_result = $activity_stmt->get_result();
// Format activities as nested table
$activity_html = "<table class='table table-sm table-striped'>";
$activity_html .= "<thead><tr>
<th>Date</th>
<th>Activity</th>
<th>School</th>
<th>School Head</th>
<th>Remarks</th>
</tr></thead><tbody>";
if ($activity_result->num_rows > 0) {
while ($activity = $activity_result->fetch_assoc()) {
$activity_html .= "<tr>
<td>" . htmlspecialchars($activity['date']) . "</td>
<td>" . htmlspecialchars($activity['activity']) . "</td>
<td>" . htmlspecialchars($activity['school']) . "</td>
<td>" . htmlspecialchars($activity['school_head']) . "</td>
<td>" . htmlspecialchars($activity['remarks']) . "</td>
</tr>";
}
} else {
$activity_html .= "<tr><td colspan='5'>No activities found.</td></tr>";
}
$activity_html .= "</tbody></table>";
// Output plan row
echo "<tr>";
echo "<td>" . htmlspecialchars($row['division']) . "</td>";
echo "<td>" . htmlspecialchars($row['section']) . "</td>";
echo "<td>" . htmlspecialchars($row['district']) . "</td>";
echo "<td>" . htmlspecialchars($row['month']) . "</td>";
echo "<td>" . htmlspecialchars($row['year']) . "</td>";
echo "<td>" . htmlspecialchars($row['status']) . "</td>";
echo "<td>" . $activity_html . "</td>";
echo "<td>
<a href='edit_draft.php?id=" . $plan_id . "' class='btn btn-primary btn-sm'>Edit</a>
<a href='submit_draft.php?id=" . $plan_id . "' class='btn btn-success btn-sm'>Submit</a>
</td>";
echo "</tr>";
$activity_stmt->close();
}
echo "</tbody></table>";
} else {
echo "<p>No drafts found.</p>";
}
$stmt->close();
?>