| Server IP : 173.209.174.21 / Your IP : 216.73.216.89 Web Server : Apache/2.4.58 (Ubuntu) System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : nodor ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/wcsd/School-alert/ |
Upload File : |
<?php
session_start();
require 'config/db.php';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Check if the user is logged in and has admin privileges
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
header('Location: dashboard.php');
exit();
}
// Ensure district_id is set in the session
if (!isset($_SESSION['district_id'])) {
die('Error: district_id is not set in the session.');
}
$district_id = $_SESSION['district_id'];
$success_message = "";
// Fetch the current district and its schools
$stmt = $pdo->prepare("SELECT * FROM districts WHERE district_id = ?");
$stmt->execute([$district_id]);
$district = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$district) {
die('Error: No district found for the specified district_id.');
}
$schools_stmt = $pdo->prepare("SELECT * FROM schools WHERE district_id = ?");
$schools_stmt->execute([$district_id]);
$schools = $schools_stmt->fetchAll(PDO::FETCH_ASSOC);
// Handle adding a new school
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_school'])) {
$school_name = $_POST['school_name'];
$school_address = $_POST['school_address'];
$school_phone = $_POST['school_phone'];
$notification_emails = $_POST['school_notification_emails'];
try {
$stmt = $pdo->prepare("INSERT INTO schools (district_id, name, address, phone, notification_emails) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$district_id, $school_name, $school_address, $school_phone, $notification_emails]);
header('Location: profile.php?message=New school added successfully');
exit();
} catch (PDOException $e) {
echo "Error adding school: " . $e->getMessage();
}
}
// Handle deleting a school
if (isset($_GET['delete_school'])) {
$school_id = $_GET['delete_school'];
try {
$stmt = $pdo->prepare("DELETE FROM schools WHERE school_id = ?");
$stmt->execute([$school_id]);
header('Location: profile.php?message=School deleted successfully');
exit();
} catch (PDOException $e) {
echo "Error deleting school: " . $e->getMessage();
}
}
?>
<?php include __DIR__ . '/views/header.php'; ?>
<h2 style="margin-bottom: 10px;">District Profile</h2>
<?php if ($success_message): ?>
<p style="color: green; font-size: 1.2em; font-weight: bold; margin-bottom: 20px;"><?= $success_message ?></p>
<?php endif; ?>
<form method="POST" action="profile.php" style="margin-bottom: 20px;">
<input type="hidden" name="update_district" value="1">
<label for="district_name">District Name:</label>
<input type="text" id="district_name" name="district_name" value="<?= htmlspecialchars($district['district_name']) ?>" required style="margin-bottom: 10px;">
<label for="contact_email">Contact Email:</label>
<input type="email" id="contact_email" name="contact_email" value="<?= htmlspecialchars($district['contact_email']) ?>" required style="margin-bottom: 10px;">
<button type="submit" style="padding: 8px 16px; margin-top: 10px;">Update District Info</button>
</form>
<h3 style="margin-bottom: 10px;">Schools in This District</h3>
<ul style="margin-bottom: 20px;">
<?php foreach ($schools as $school): ?>
<li style="margin-bottom: 15px;">
<strong><?= htmlspecialchars($school['name']) ?></strong><br>
Address: <?= htmlspecialchars($school['address']) ?><br>
Phone: <?= htmlspecialchars($school['phone']) ?><br>
Notification Emails: <?= htmlspecialchars($school['notification_emails']) ?><br>
Location: <?= htmlspecialchars($school['location']) ?><br>
<!-- Delete link -->
<a href="profile.php?delete_school=<?= $school['school_id'] ?>" style="color: red;" onclick="return confirm('Are you sure you want to delete this school?');">Delete</a>
</li>
<?php endforeach; ?>
</ul>
<h3 style="margin-bottom: 10px;">Add a New School</h3>
<form method="POST" action="profile.php" style="margin-bottom: 20px;">
<input type="hidden" name="add_school" value="1">
<label for="school_name">School Name:</label>
<input type="text" id="school_name" name="school_name" required style="margin-bottom: 10px;">
<label for="school_address">Address:</label>
<input type="text" id="school_address" name="school_address" required style="margin-bottom: 10px;">
<label for="school_phone">Phone:</label>
<input type="text" id="school_phone" name="school_phone" required style="margin-bottom: 10px;">
<label for="school_notification_emails">Notification Emails (separate with commas):</label>
<textarea id="school_notification_emails" name="school_notification_emails" rows="3" required style="margin-bottom: 10px;"></textarea>
<label for="school_location">Location:</label>
<input type="text" id="school_location" name="school_location" style="margin-bottom: 10px;">
<button type="submit" style="padding: 8px 16px;">Add School</button>
</form>
<?php include __DIR__ . '/views/footer.php'; ?>