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 division, section, and learning area from the database
$sql = "SELECT division, section, learning_area FROM information WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$rows = $result->fetch_assoc();
} else {
die("Error: User information not found.");
}
$stmt->close();
// Handle form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$division = $_POST['division'] ?? null;
$section = $_POST['section'] ?? null;
$district = $_POST['learning_area'] ?? null;
$school_year = $_POST['school_year'] ?? null;
$period_type = $_POST['period_type'] ?? null;
$month = $_POST['month'] ?? null;
$quarter = $_POST['quarter'] ?? null;
$time_period = ($period_type === 'month') ? $month : $quarter;
$stmt = $conn->prepare("INSERT INTO mqcais_reports (division, section, district, month, school_year, username) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssss", $division, $section, $district, $time_period, $school_year, $username);
if (!$stmt->execute()) {
die("Error saving MQCAIS report: " . $stmt->error);
}
$report_id = $conn->insert_id;
if (!empty($_POST['date'])) {
$date = $_POST['date'] ?? [];
$no_of_schools = $_POST['no_of_schools_monitored_and_provided_ta'] ?? [];
$activities = $_POST['activities_undertaken'] ?? [];
$findings = $_POST['findings'] ?? [];
$assistances = $_POST['technical_assistance_provided'] ?? [];
$agreements = $_POST['agreement'] ?? [];
$stmt_report = $conn->prepare("INSERT INTO mqcais_monitoring_reports
(report_id, date, no_of_schools_monitored_and_provided_ta, activities_undertaken, findings, technical_assistance_provided, agreement)
VALUES (?, ?, ?, ?, ?, ?, ?)");
if (!$stmt_report) die("Prepare failed for monitoring report: " . $conn->error);
for ($i = 0; $i < count($date); $i++) {
$stmt_report->bind_param(
"issssss",
$report_id,
$date[$i],
$no_of_schools[$i],
$activities[$i],
$findings[$i],
$assistances[$i],
$agreements[$i]
);
if (!$stmt_report->execute()) {
die("Insert failed for row $i: " . $stmt_report->error);
}
}
$stmt_report->close();
}
if (isset($_POST['generate_report'])) {
header("Location: generate_mais_word.php?report_id=" . $report_id);
exit();
} elseif (isset($_POST['save_only'])) {
header("Location: view_mqcais_reports.php");
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create MQCAIS Report</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="../vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.form-control-sm { font-size: 0.875rem; padding: 0.25rem 0.5rem; }
th, td { vertical-align: middle !important; white-space: nowrap; }
@media (max-width: 576px) {
h3 { font-size: 1.2rem; }
label { font-size: 0.9rem; }
.btn { font-size: 0.875rem; padding: 0.4rem 0.75rem; }
}
</style>
</head>
<body class="container-fluid mt-4">
<h3 class="text-center mb-4">Create Monthly Consolidated and Analyzed Instructional Supervisory Report</h3>
<form action="" method="POST" onsubmit="return confirm('Are you sure you want to create this MQCAIS report?');">
<div class="row mb-3">
<div class="col-sm-12 col-md-6 col-lg-2 mb-2">
<label>Division</label>
<input type="text" name="division" class="form-control form-control-sm" value="<?php echo htmlspecialchars($rows['division']); ?>" readonly required>
</div>
<div class="col-sm-12 col-md-6 col-lg-2 mb-2">
<label>Section/Unit</label>
<input type="text" name="section" class="form-control form-control-sm" value="<?php echo htmlspecialchars($rows['section']); ?>" readonly required>
</div>
<div class="col-sm-12 col-md-6 col-lg-3 mb-2">
<label>District/Learning Area</label>
<input type="text" name="learning_area" class="form-control form-control-sm" value="<?php echo htmlspecialchars($rows['learning_area']); ?>" readonly required>
</div>
<div class="col-sm-12 col-md-6 col-lg-2 mb-2">
<label>Period Type</label>
<select id="periodType" name="period_type" class="form-control form-control-sm" required>
<option value="month" selected>Month</option>
</select>
</div>
<div class="col-sm-12 col-md-6 col-lg-2 mb-2">
<label>Month</label>
<select id="monthDropdown" name="month" class="form-control form-control-sm" required>
<option value="">Select Month</option>
<?php
$months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
foreach ($months as $month) {
echo "<option value=\"$month\">$month</option>";
}
?>
</select>
</div>
<div class="col-sm-12 col-md-6 col-lg-3 mb-2">
<label>School Year</label>
<input type="text" name="school_year" class="form-control form-control-sm" value="<?php echo date('Y'); ?>" readonly required>
</div>
</div>
<div class="form-group text-center mb-3">
<h4 class="text-center mb-2" style="font-size: 1.2rem; font-weight: bold; background-color: #007bff; color: white; padding: 5px 15px; display: inline-block; border-radius: 5px;">
Your Activities
</h4>
</div>
<!-- ADD and REMOVE ACTIVITY buttons -->
<div class="form-group text-center mb-3">
<button type="button" id="addRowBtn" class="btn btn-success btn-sm">Add Activity</button>
<button type="button" id="removeRowBtn" class="btn btn-danger btn-sm">Remove Last Activity</button>
</div>
<div class="table-responsive mb-4">
<table class="table table-bordered table-sm text-center" id="activityTable">
<thead class="thead-light">
<tr>
<th>Date</th>
<th>No. of Schools Monitored and Provided TA</th>
<th>Activities Undertaken</th>
<th>Findings</th>
<th>Technical Assistance</th>
<th>Agreement</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="date" name="date[]" class="form-control form-control-sm" required></td>
<td><input type="text" name="no_of_schools_monitored_and_provided_ta[]" class="form-control form-control-sm" required></td>
<td><input type="text" name="activities_undertaken[]" class="form-control form-control-sm" required></td>
<td><input type="text" name="findings[]" class="form-control form-control-sm"></td>
<td><input type="text" name="technical_assistance_provided[]" class="form-control form-control-sm"></td>
<td><input type="text" name="agreement[]" class="form-control form-control-sm"></td>
</tr>
</tbody>
</table>
</div>
<div class="form-group text-center">
<button type="submit" name="save_only" class="btn btn-warning">Save</button>
</div>
</form>
<script>
const addRowBtn = document.getElementById('addRowBtn');
const removeRowBtn = document.getElementById('removeRowBtn');
const tableBody = document.querySelector('#activityTable tbody');
addRowBtn.addEventListener('click', () => {
const lastRow = tableBody.querySelector('tr:last-child');
const newRow = lastRow.cloneNode(true);
newRow.querySelectorAll('input').forEach(input => {
input.value = '';
});
tableBody.appendChild(newRow);
});
removeRowBtn.addEventListener('click', () => {
const rows = tableBody.querySelectorAll('tr');
if (rows.length > 1) {
tableBody.removeChild(rows[rows.length - 1]);
} else {
alert('At least one activity row is required.');
}
});
</script>
</body>
</html>