diff --git a/add_student.php b/add_student.php new file mode 100644 index 0000000..c3c1294 --- /dev/null +++ b/add_student.php @@ -0,0 +1,147 @@ +exec("CREATE TABLE IF NOT EXISTS students ( + id INT AUTO_INCREMENT PRIMARY KEY, + first_name VARCHAR(100) NOT NULL, + last_name VARCHAR(100) NOT NULL, + date_of_birth DATE NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + );"); + + if ($_SERVER["REQUEST_METHOD"] == "POST") { + $first_name = trim($_POST['first_name']); + $last_name = trim($_POST['last_name']); + $date_of_birth = trim($_POST['date_of_birth']); + + if (empty($first_name) || empty($last_name) || empty($date_of_birth)) { + $notification = ["type" => "danger", "message" => "All fields are required."]; + } else { + $stmt = $pdo->prepare("INSERT INTO students (first_name, last_name, date_of_birth) VALUES (?, ?, ?)"); + if ($stmt->execute([$first_name, $last_name, $date_of_birth])) { + $notification = ["type" => "success", "message" => "Student added successfully!"]; + } else { + $notification = ["type" => "danger", "message" => "Error: Could not add student."]; + } + } + } +} catch (Exception $e) { + $notification = ["type" => "danger", "message" => "Database error: " . $e->getMessage()]; + error_log("DB Error: " . $e->getMessage()); +} +?> + + + + + + <?= htmlspecialchars($page_title) ?> - <?= htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'WebApp') ?> + + + + + + + + + + +
+
+
+
+
+

New Student Admission

+
+
+ + +
Please enter a first name.
+
+
+ + +
Please enter a last name.
+
+
+ + +
Please enter a valid date of birth.
+
+
+ +
+
+
+
+
+
+
+ +
+ +
+ + + + + + + + + + diff --git a/admin.php b/admin.php new file mode 100644 index 0000000..771392a --- /dev/null +++ b/admin.php @@ -0,0 +1,154 @@ +query("SELECT users.id, users.username, roles.role_name FROM users JOIN roles ON users.role_id = roles.id ORDER BY users.username"); +$users = $stmt->fetchAll(PDO::FETCH_ASSOC); + +// Handle role change +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'change_role') { + $user_id = isset($_POST['user_id']) ? (int)$_POST['user_id'] : 0; + $role_id = isset($_POST['role_id']) ? (int)$_POST['role_id'] : 0; + + if ($user_id && $role_id) { + $stmt = $pdo->prepare("UPDATE users SET role_id = ? WHERE id = ?"); + $stmt->execute([$role_id, $user_id]); + header("Location: admin.php?success=role_changed"); + exit(); + } +} + +// Fetch all roles for the dropdown +$roles_stmt = $pdo->query("SELECT id, role_name FROM roles"); +$roles = $roles_stmt->fetchAll(PDO::FETCH_ASSOC); + +$page_title = "Admin - User Management"; +?> + + + + + + <?= htmlspecialchars($page_title) ?> - Bhuddi School + + + + + + + +
+

User Management

+ +
+
+
+ + + + + + + + + + + + + + + + + +
UsernameRoleActions
+ + + +
+
+
+
+
+ + + + + + + + diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..7148272 --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,43 @@ +body { + font-family: 'Poppins', sans-serif; + background-color: #F4F7F6; +} + +.navbar-brand { + font-weight: 600; + color: #4A90E2 !important; +} + +.btn-primary { + background-color: #4A90E2; + border-color: #4A90E2; + padding: 0.75rem 1rem; + font-weight: 600; + transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out; +} + +.btn-primary:hover { + background-color: #357ABD; + border-color: #357ABD; +} + +.card { + border-radius: 0.75rem; +} + +.form-control { + border-radius: 0.5rem; + padding: 0.75rem 1rem; +} + +.form-control:focus { + border-color: #4A90E2; + box-shadow: 0 0 0 0.25rem rgba(74, 144, 226, 0.25); +} + +.toast-header .btn-close { + background: none; +} + +.toast.bg-success { color: #fff; } +.toast.bg-danger { color: #fff; } diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..6286b6d --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,52 @@ +/** + * Shows a Bootstrap toast notification. + * @param {string} message The message to display. + * @param {string} type The type of toast (e.g., 'success', 'danger', 'warning'). + */ +function showToast(message, type = 'info') { + const toastElement = document.getElementById('notificationToast'); + if (!toastElement) return; + + const toastBody = toastElement.querySelector('.toast-body'); + const toastHeader = toastElement.querySelector('.toast-header'); + + toastBody.textContent = message; + + // Reset classes + toastElement.classList.remove('bg-success', 'bg-danger', 'bg-warning', 'bg-info'); + + // Add new class + if (type) { + toastElement.classList.add(`bg-${type}`); + // Make text readable on dark backgrounds + if (type === 'success' || type === 'danger') { + toastHeader.classList.add('text-white'); + toastBody.classList.add('text-white'); + } else { + toastHeader.classList.remove('text-white'); + toastBody.classList.remove('text-white'); + } + } + + const toast = new bootstrap.Toast(toastElement); + toast.show(); +} + +// Basic form validation script +document.addEventListener('DOMContentLoaded', function () { + 'use strict' + + var forms = document.querySelectorAll('.needs-validation') + + Array.prototype.slice.call(forms) + .forEach(function (form) { + form.addEventListener('submit', function (event) { + if (!form.checkValidity()) { + event.preventDefault() + event.stopPropagation() + } + + form.classList.add('was-validated') + }, false) + }) +}); diff --git a/auth.php b/auth.php new file mode 100644 index 0000000..8d61f78 --- /dev/null +++ b/auth.php @@ -0,0 +1,32 @@ +exec("CREATE TABLE IF NOT EXISTS roles ( + id INT AUTO_INCREMENT PRIMARY KEY, + role_name VARCHAR(50) NOT NULL UNIQUE + );"); + + // Create users table + $pdo->exec("CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(50) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + role_id INT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (role_id) REFERENCES roles(id) + );"); + + // Insert default roles if they don't exist + $stmt = $pdo->query("SELECT COUNT(*) FROM roles"); + if ($stmt->fetchColumn() == 0) { + $pdo->exec("INSERT INTO roles (role_name) VALUES ('admin'), ('teacher');"); + } + +} catch (PDOException $e) { + die("Database error during auth setup: " . $e->getMessage()); +} +?> \ No newline at end of file diff --git a/index.php b/index.php index 7205f3d..f08fb87 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,133 @@ exec("CREATE TABLE IF NOT EXISTS students ( + id INT AUTO_INCREMENT PRIMARY KEY, + first_name VARCHAR(100) NOT NULL, + last_name VARCHAR(100) NOT NULL, + date_of_birth DATE NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + );"); + $stmt = $pdo->query("SELECT id, first_name, last_name, created_at FROM students ORDER BY created_at DESC LIMIT 5"); + if($stmt) { + $students = $stmt->fetchAll(PDO::FETCH_ASSOC); + } +} catch (Exception $e) { + error_log("DB Error on dashboard: " . $e->getMessage()); +} ?> - + - - - New Style - - - - - - - - - - - - - - - - - - - + + + <?= htmlspecialchars($page_title) ?> - <?= htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'WebApp') ?> + + + + + + + + + + + + - -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

-
-
- + + + + +
+
+

Dashboard

+ + Add New Student + +
+ +
+
+
Recently Added Students
+
+
+ +

No students have been added yet. Add the first one!

+ +
+ + + + + + + + + + + + + + + + + + + + + +
#First NameLast NameDate AddedActions
+ View +
+
+ +
+
+
+ + + + + diff --git a/login.php b/login.php new file mode 100644 index 0000000..b427674 --- /dev/null +++ b/login.php @@ -0,0 +1,91 @@ +prepare("SELECT users.id, users.username, users.password_hash, roles.role_name FROM users JOIN roles ON users.role_id = roles.id WHERE users.username = ?"); + $stmt->execute([$username]); + $user = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($user && password_verify($password, $user['password_hash'])) { + // Password is correct, start a new session + session_regenerate_id(); + $_SESSION['loggedin'] = true; + $_SESSION['id'] = $user['id']; + $_SESSION['username'] = $user['username']; + $_SESSION['role'] = $user['role_name']; + + header("location: index.php"); + exit; + } else { + // Display an error message if password or username is not valid + $error = "The username or password you entered was not valid."; + } + } +} +?> + + + + + + Login - Bhuddi School + + + + +
+
+
+
+
+ Login +
+
+ + + + + + +
+
+ + +
+
+ + +
+ +
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..e46f75d --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/signup.php b/signup.php new file mode 100644 index 0000000..b1f54fb --- /dev/null +++ b/signup.php @@ -0,0 +1,93 @@ +prepare("SELECT id FROM users WHERE username = ?"); + $stmt->execute([$username]); + if ($stmt->fetch()) { + $error = "Username already exists. Please choose another one."; + } else { + // Get 'teacher' role ID + $stmt = $pdo->prepare("SELECT id FROM roles WHERE role_name = 'teacher'"); + $stmt->execute(); + $role = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$role) { + // This is a fallback, 'teacher' role should exist from auth.php + $error = "Default role 'teacher' not found. Please contact admin."; + } else { + $role_id = $role['id']; + $password_hash = password_hash($password, PASSWORD_BCRYPT); + + $sql = "INSERT INTO users (username, password_hash, role_id) VALUES (?, ?, ?)"; + $stmt= $pdo->prepare($sql); + if ($stmt->execute([$username, $password_hash, $role_id])) { + $_SESSION['success_message'] = "Registration successful! You can now login."; + header("Location: login.php"); + exit(); + } else { + $error = "Something went wrong. Please try again later."; + } + } + } + } +} +?> + + + + + + Sign Up - Bhuddi School + + + + +
+
+
+
+
+ Sign Up +
+
+ + + +
+
+ + +
+
+ + +
+ +
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/student.php b/student.php new file mode 100644 index 0000000..5e29e8d --- /dev/null +++ b/student.php @@ -0,0 +1,819 @@ +prepare("SELECT * FROM students WHERE id = ?"); + $stmt->execute([$student_id]); + $student = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$student) { + // Optional: Show a "not found" message or redirect + header("Location: index.php?error=not_found"); + exit(); + } + + // -- Behavior Insights Logic -- + + // 2.1. Create behaviors table if it doesn't exist and add rating column + $pdo->exec("CREATE TABLE IF NOT EXISTS behaviors ( + id INT AUTO_INCREMENT PRIMARY KEY, + student_id INT NOT NULL, + behavior_description TEXT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE + );"); + try { + $pdo->exec("ALTER TABLE behaviors ADD COLUMN rating INT NOT NULL DEFAULT 5"); + } catch (PDOException $e) { + // Ignore errors, especially if the column already exists. + } + + // 2.2. Handle form submission for adding a new behavior + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_behavior') { + $behavior_description = trim($_POST['behavior_description'] ?? ''); + $behavior_rating = isset($_POST['behavior_rating']) ? (int)$_POST['behavior_rating'] : 5; + + if (!empty($behavior_description)) { + $stmt = $pdo->prepare("INSERT INTO behaviors (student_id, behavior_description, rating) VALUES (?, ?, ?)"); + $stmt->execute([$student_id, $behavior_description, $behavior_rating]); + + // Redirect to the same page to prevent form resubmission + header("Location: student.php?id=" . $student_id . "&success=behavior_logged"); + exit(); + } + } + + // 2.3. Handle form submission for editing a behavior + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'edit_behavior') { + $behavior_id = isset($_POST['behavior_id']) ? (int)$_POST['behavior_id'] : 0; + $behavior_description = trim($_POST['behavior_description'] ?? ''); + $behavior_rating = isset($_POST['behavior_rating']) ? (int)$_POST['behavior_rating'] : 5; + + if ($behavior_id && !empty($behavior_description)) { + $stmt = $pdo->prepare("UPDATE behaviors SET behavior_description = ?, rating = ? WHERE id = ? AND student_id = ?"); + $stmt->execute([$behavior_description, $behavior_rating, $behavior_id, $student_id]); + + header("Location: student.php?id=" . $student_id . "&success=behavior_updated"); + exit(); + } + } + + // 2.3. Handle form submission for deleting a behavior + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete_behavior') { + $behavior_id = isset($_POST['behavior_id']) ? (int)$_POST['behavior_id'] : 0; + + if ($behavior_id) { + $stmt = $pdo->prepare("DELETE FROM behaviors WHERE id = ? AND student_id = ?"); + $stmt->execute([$behavior_id, $student_id]); + + header("Location: student.php?id=" . $student_id . "&success=behavior_deleted"); + exit(); + } + } + + // 2.4. Fetch all behaviors for this student + $stmt = $pdo->prepare("SELECT * FROM behaviors WHERE student_id = ? ORDER BY created_at DESC"); + $stmt->execute([$student_id]); + $behaviors = $stmt->fetchAll(PDO::FETCH_ASSOC); + + // -- Academic Insights Logic -- + + // 2.4. Create academics table if it doesn't exist + $pdo->exec("CREATE TABLE IF NOT EXISTS academics ( + id INT AUTO_INCREMENT PRIMARY KEY, + student_id INT NOT NULL, + subject VARCHAR(100) NOT NULL, + grade VARCHAR(2) NOT NULL, + comments TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE + );"); + + // 2.5. Handle form submission for adding a new academic record + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_academic') { + $subject = trim($_POST['subject'] ?? ''); + $grade = trim($_POST['grade'] ?? ''); + $comments = trim($_POST['comments'] ?? ''); + + if (!empty($subject) && !empty($grade)) { + $stmt = $pdo->prepare("INSERT INTO academics (student_id, subject, grade, comments) VALUES (?, ?, ?, ?)"); + $stmt->execute([$student_id, $subject, $grade, $comments]); + + header("Location: student.php?id=" . $student_id . "&success=academic_logged"); + exit(); + } + } + + // Handle form submission for editing an academic record + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'edit_academic') { + $academic_id = isset($_POST['academic_id']) ? (int)$_POST['academic_id'] : 0; + $subject = trim($_POST['subject'] ?? ''); + $grade = trim($_POST['grade'] ?? ''); + $comments = trim($_POST['comments'] ?? ''); + + if ($academic_id && !empty($subject) && !empty($grade)) { + $stmt = $pdo->prepare("UPDATE academics SET subject = ?, grade = ?, comments = ? WHERE id = ? AND student_id = ?"); + $stmt->execute([$subject, $grade, $comments, $academic_id, $student_id]); + + header("Location: student.php?id=" . $student_id . "&success=academic_updated"); + exit(); + } + } + + // Handle form submission for deleting an academic record + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete_academic') { + $academic_id = isset($_POST['academic_id']) ? (int)$_POST['academic_id'] : 0; + + if ($academic_id) { + $stmt = $pdo->prepare("DELETE FROM academics WHERE id = ? AND student_id = ?"); + $stmt->execute([$academic_id, $student_id]); + + header("Location: student.php?id=" . $student_id . "&success=academic_deleted"); + exit(); + } + } + + // 2.6. Fetch all academic records for this student + $stmt = $pdo->prepare("SELECT * FROM academics WHERE student_id = ? ORDER BY created_at DESC"); + $stmt->execute([$student_id]); + $academics = $stmt->fetchAll(PDO::FETCH_ASSOC); + + // -- Student Details Logic -- + + // Create student_details table + $pdo->exec("CREATE TABLE IF NOT EXISTS student_details ( + id INT AUTO_INCREMENT PRIMARY KEY, + student_id INT NOT NULL, + title VARCHAR(255) NOT NULL, + details TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE + );") + + // Fetch all details for this student + $stmt = $pdo->prepare("SELECT * FROM student_details WHERE student_id = ? ORDER BY created_at DESC"); + $stmt->execute([$student_id]); + $student_details = $stmt->fetchAll(PDO::FETCH_ASSOC); + + // Handle form submission for adding a new student detail + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_student_detail') { + $title = trim($_POST['detail_title'] ?? ''); + $details = trim($_POST['detail_content'] ?? ''); + + if (!empty($title)) { + $stmt = $pdo->prepare("INSERT INTO student_details (student_id, title, details) VALUES (?, ?, ?)"); + $stmt->execute([$student_id, $title, $details]); + + header("Location: student.php?id=" . $student_id . "&success=detail_added"); + exit(); + } + } + + // Handle form submission for deleting a student detail + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete_student_detail') { + $detail_id = isset($_POST['detail_id']) ? (int)$_POST['detail_id'] : 0; + + if ($detail_id) { + $stmt = $pdo->prepare("DELETE FROM student_details WHERE id = ? AND student_id = ?"); + $stmt->execute([$detail_id, $student_id]); + + header("Location: student.php?id=" . $student_id . "&success=detail_deleted"); + exit(); + } + } + + // Handle form submission for editing a student detail + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'edit_student_detail') { + $detail_id = isset($_POST['detail_id']) ? (int)$_POST['detail_id'] : 0; + $title = trim($_POST['detail_title'] ?? ''); + $details = trim($_POST['detail_content'] ?? ''); + + if ($detail_id && !empty($title)) { + $stmt = $pdo->prepare("UPDATE student_details SET title = ?, details = ? WHERE id = ? AND student_id = ?"); + $stmt->execute([$title, $details, $detail_id, $student_id]); + + header("Location: student.php?id=" . $student_id . "&success=detail_updated"); + exit(); + } + } + +} catch (PDOException $e) { + // For development, you might want to log this error. + // For production, show a generic error message. + die("Database error: Could not retrieve student data."); +} + +$pageTitle = htmlspecialchars($student['first_name'] . ' ' . $student['last_name']); +?> + + + + + + <?php echo $pageTitle; ?> - Student Details + + + + + + + + + + + +
+
+
+
+ +
+

+

Student Profile

+
+
+ +
+
+
+ First Name: +

+
+
+
+
+ Last Name: +

+
+
+
+
+ Date of Birth: +

+
+
+
+
+ Admission Date: +

+
+
+
+ + +
+
+ + +
+
+

Behavior Insights

+ + + +
+

Log New Behavior

+
+ +
+ + +
+
+ + +
+ +
+
+ + + +
+

Behavior History

+ +

No behavior entries have been logged for this student yet.

+ +
    + +
  • +
    +
    + Logged on: +
    + Rating: + +
    + + +
    + +
  • + +
+ +
+
+
+ + +
+
+

Academic Insights

+ + + +
+

Log New Academic Record

+
+ +
+
+ + +
+
+ + +
+
+
+ + +
+ +
+
+ + + +
+

Academic History

+ +

No academic records have been logged for this student yet.

+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
SubjectGradeCommentsDateActions
+ + +
+
+ +
+
+
+ + +
+
+

Additional Student Details

+ + + +
+

Add New Detail

+
+ +
+
+ + +
+
+
+ + +
+ +
+
+ + + +
+

Details History

+ +

No additional details have been logged for this student yet.

+ +
+ + + + + + + + + + + + + + + + + + + + + +
TitleDetailsDateActions
+ + +
+
+ +
+
+
+
+ + + + + + + + + + + +
+ + + + +
+ + + + +