Mini Kabibi Habibi
Current Path : C:/xampp/htdocs/cid/system/ |
|
Current File : C:/xampp/htdocs/cid/system/get_mista_report_data.php |
<?php
session_start();
@include 'include/config.php';
header('Content-Type: application/json');
if (!isset($_SESSION['username_school'])) {
echo json_encode(['error' => 'User not authenticated']);
exit;
}
$username = $_SESSION['username_school'];
if (!isset($_GET['month']) || empty(trim($_GET['month']))) {
echo json_encode(['error' => 'Missing month']);
exit;
}
$month = trim($_GET['month']);
// Get latest matching report ID
$sql = "SELECT id FROM mista_reports
WHERE username = ? AND month = ?
ORDER BY id DESC LIMIT 1";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss", $username, $month);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 0) {
echo json_encode([]);
exit;
}
$report = $result->fetch_assoc();
$plan_id = $report['id'];
$stmt->close();
// Get associated monitoring data
$sql = "SELECT
dates,
no_of_schools_monitored_and_provided_ta,
activities_undertaken,
findings,
technical_assistance_provided,
agreement
FROM mista_monitoring_reports
WHERE plan_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $plan_id);
$stmt->execute();
$result = $stmt->get_result();
$data = [];
while ($row = $result->fetch_assoc()) {
$data[] = [
'date' => $row['dates'],
'no_of_schools_monitored_and_provided_ta' => $row['no_of_schools_monitored_and_provided_ta'],
'activities_undertaken' => $row['activities_undertaken'],
'findings' => $row['findings'],
'technical_assistance_provided' => $row['technical_assistance_provided'],
'agreement' => $row['agreement'],
];
}
echo json_encode($data);
$stmt->close();
$conn->close();
?>