| 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/Backup files/ |
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();
}
// Fetch the current district and its schools
$district_id = $_SESSION['district_id'];
$stmt = $pdo->prepare("SELECT * FROM districts WHERE district_id = ?");
$stmt->execute([$district_id]);
$district = $stmt->fetch(PDO::FETCH_ASSOC);
$schools_stmt = $pdo->prepare("SELECT * FROM schools WHERE district_id = ?");
$schools_stmt->execute([$district_id]);
$schools = $schools_stmt->fetchAll(PDO::FETCH_ASSOC);
// Handle updating district information
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['update_district'])) {
$district_name = $_POST['district_name'];
$contact_email = $_POST['contact_email'];
try {
$stmt = $pdo->prepare("UPDATE districts SET district_name = ?, contact_email = ? WHERE district_id = ?");
$stmt->execute([$district_name, $contact_email, $district_id]);
header('Location: profile.php?message=District information updated successfully');
exit();
} catch (PDOException $e) {
echo "Error updating district information: " . $e->getMessage();
}
}
// 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();
}
}
?>
<?php include __DIR__ . '/views/header.php'; ?>
<h2>District Profile</h2>
<form method="POST" action="profile.php">
<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>
<label for="contact_email">Contact Email:</label>
<input type="email" id="contact_email" name="contact_email" value="<?= htmlspecialchars($district['contact_email']) ?>" required>
<button type="submit">Update District Info</button>
</form>
<h3>Schools in This District</h3>
<ul>
<?php foreach ($schools as $school): ?>
<li>
<strong><?= htmlspecialchars($school['name']) ?></strong><br>
Address: <?= htmlspecialchars($school['address']) ?><br>
Phone: <?= htmlspecialchars($school['phone']) ?><br>
Notification Emails: <?= htmlspecialchars($school['notification_emails']) ?>
</li>
<?php endforeach; ?>
</ul>
<h3>Add a New School</h3>
<form method="POST" action="profile.php">
<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>
<label for="school_address">Address:</label>
<input type="text" id="school_address" name="school_address" required>
<label for="school_phone">Phone:</label>
<input type="text" id="school_phone" name="school_phone" required>
<label for="school_notification_emails">Notification Emails (separate with commas):</label>
<textarea id="school_notification_emails" name="school_notification_emails" rows="3" required></textarea>
<button type="submit">Add School</button>
</form>
<?php include __DIR__ . '/views/footer.php'; ?>