Skip to content

Commit

Permalink
hoan thien UI
Browse files Browse the repository at this point in the history
  • Loading branch information
hung1605 committed May 24, 2024
1 parent 009c5dd commit 72d672c
Show file tree
Hide file tree
Showing 18 changed files with 602 additions and 311 deletions.
37 changes: 37 additions & 0 deletions abc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>

<head>
<!-- Add Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>

<body>

<!-- Button with primary color -->
<button type="button" class="btn btn-primary">Primary Button</button>

<!-- Button with secondary color -->
<button type="button" class="btn btn-secondary">Secondary Button</button>

<!-- Button with success color -->
<button type="button" class="btn btn-success">Success Button</button>

<!-- Button with danger color -->
<button type="button" class="btn btn-danger">Danger Button</button>

<!-- Button with warning color -->
<button type="button" class="btn btn-warning">Warning Button</button>

<!-- Button with info color -->
<button type="button" class="btn btn-info">Info Button</button>

<!-- Button with light color -->
<button type="button" class="btn btn-light">Light Button</button>

<!-- Button with dark color -->
<button type="button" class="btn btn-dark">Dark Button</button>

</body>

</html>
69 changes: 56 additions & 13 deletions classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,64 @@
$classes = getAllClasses();
?>

<h2>Classes</h2>

<div>
<label for="classSelect">Select Class:</label>
<select id="classSelect">
<option value="">Select a class</option>
<?php
while ($row = $classes->fetch_assoc()) {
echo "<option value='{$row['MaLop']}'>{$row['TenLop']}</option>";
}
?>
</select>
<style>
table {
width: 100%;
/* Table takes full width of its container */
border-collapse: collapse;
/* Remove default spacing between table cells */
}

th,
td {
padding: 8px;
border: 1px solid #ddd;
color: black;
}

body {
background-color: #f8f9fa;
font-family: Arial, sans-serif;
margin-bottom: 60px;
}

.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h2 {
color: #333;
margin-bottom: 20px;
}
</style>


<h2 class="d-flex justify-content-center">Classes</h2>

<div class="d-flex justify-content-center">
<div class="form-group w-50">
<label for="classSelect">Select Class:</label>
<select id="classSelect" class="form-control">
<option value="">Select a class</option>
<?php
while ($row = $classes->fetch_assoc()) {
echo "<option value='{$row['MaLop']}'>{$row['TenLop']}</option>";
}
?>
</select>
</div>
</div>

<div class="container">
<h2 class="d-flex justify-content-center">Student List</h2>
<div id="studentList"></div>
</div>

<div id="studentList"></div>

<script>
document.addEventListener("DOMContentLoaded", function() {
Expand Down
17 changes: 14 additions & 3 deletions db/ini_data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ INSERT INTO lop (MaLop, TenLop, MaNganh, KhoaHoc, HeDT, NamNhapHoc) VALUES
INSERT INTO sinhvien (HoTen, MaLop, GioiTinh, NgaySinh, DiaChi) VALUES
('John Doe', 'L01', 'Male', '2000-01-01', '123 Main St'),
('Jane Smith', 'L02', 'Female', '2000-02-01', '456 Oak St'),
('Alice Johnson', 'L03', 'Female', '2000-03-01', '789 Pine St');
('Alice Johnson', 'L03', 'Female', '2000-03-01', '789 Pine St'),
('Michael Johnson', 'L01', 'Male', '2000-04-05', '321 Elm St'),
('Emily Wilson', 'L02', 'Female', '1999-11-15', '654 Birch St'),
('David Lee', 'L03', 'Male', '2000-07-20', '987 Maple St');

-- Insert sample data into 'hocphan' table
INSERT INTO hocphan (MaHP, TenHP, SoDVHT, MaNganh, HocKy) VALUES
Expand All @@ -34,11 +37,19 @@ INSERT INTO diemhp (MaSV, MaHP, DiemHP) VALUES
(1, 'HP02', 90),
(2, 'HP03', 95),
(3, 'HP01', 75),
(3, 'HP03', 80);
(3, 'HP03', 80),
(4, 'HP01', 80),
(4, 'HP02', 85),
(4, 'HP03', 70),
(5, 'HP02', 88),
(6, 'HP03', 92);

-- Insert sample data into 'user' table
INSERT INTO user (username, password, studentid, role) VALUES
('admin', '1', NULL, 'admin'),
('s1', '1', 1, 'student'),
('s2', '1', 2, 'student'),
('s3', '1', 3, 'student');
('s3', '1', 3, 'student'),
('s4', '1', 4, 'student'),
('s5', '1', 5, 'student'),
('s6', '1', 6, 'student');
3 changes: 3 additions & 0 deletions functions/student_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ function deleteStudent($id)
$sql_delete_related = "DELETE FROM diemhp WHERE MaSV='$id'";
$conn->query($sql_delete_related);

$sql_delete_related = "DELETE FROM user WHERE studentid='$id'";
$conn->query($sql_delete_related);

// Then delete the student record
$sql_delete_student = "DELETE FROM sinhvien WHERE MaSV='$id'";
return $conn->query($sql_delete_student);
Expand Down
7 changes: 4 additions & 3 deletions get_all_students.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$result = $conn->query($sql);

if ($result->num_rows > 0) {
echo "<table><tr><th>ID</th><th>Name</th><th>Class</th><th>DOB</th><th>Address</th></tr>";
echo "<table><tr><th>ID</th><th>Name</th><th>Class</th><th>DOB</th><th>Address</th><th>Actions</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>{$row['MaSV']}</td>
Expand All @@ -14,8 +14,9 @@
<td>{$row['NgaySinh']}</td>
<td>{$row['DiaChi']}</td>
<td>
<button onclick=\"openPopup('update_student.php?id={$row['MaSV']}')\">Update</button>
<button onclick=\"openPopup('delete_student.php?id={$row['MaSV']}')\">Delete</button>
<button class=\"btn btn-info\" onclick=\"openPopup('update_student.php?id={$row['MaSV']}')\">Update</button>
<button class=\"btn btn-info\" onclick=\"openPopup('show_gpa.php?id={$row['MaSV']}')\">Xem Điểm</button>
<button class=\"btn btn-danger\" onclick=\"openPopup('delete_student.php?id={$row['MaSV']}')\">Delete</button>
</td>
</tr>";
}
Expand Down
77 changes: 56 additions & 21 deletions get_students_by_class.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
<?php
include_once 'db/config.php';

if (isset($_GET['classId'])) {
$classId = $_GET['classId'];

$sql = "SELECT MaSV, HoTen, NgaySinh, DiaChi FROM sinhvien WHERE MaLop = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $classId);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
echo "<table><tr><th>ID</th><th>Name</th><th>DOB</th><th>Address</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr>
<!DOCTYPE html>
<html>

<head>
<title>Student List</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}

th,
td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}

th {
background-color: #f2f2f2;
}

tr:hover {
background-color: #f5f5f5;
}
</style>
</head>

<body>

<?php
include_once 'db/config.php';

if (isset($_GET['classId'])) {
$classId = $_GET['classId'];

$sql = "SELECT MaSV, HoTen, NgaySinh, DiaChi FROM sinhvien WHERE MaLop = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $classId);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
echo "<table id=\"classSelectionContainer\"><tr><th>ID</th><th>Name</th><th>DOB</th><th>Address</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>{$row['MaSV']}</td>
<td>{$row['HoTen']}</td>
<td>{$row['NgaySinh']}</td>
<td>{$row['DiaChi']}</td>
</tr>";
}
echo "</table>";
} else {
echo "No students found for the selected class.";
}
echo "</table>";
} else {
echo "No students found for the selected class.";

$stmt->close();
}
?>

</body>

$stmt->close();
}
</html>
61 changes: 0 additions & 61 deletions gpa_manager.php
Original file line number Diff line number Diff line change
@@ -1,61 +0,0 @@
<?php
session_start();
if (!isset($_SESSION['loggedin'])) {
header("Location: login.php");
exit();
}

include 'templates/header.php';
include 'functions/student_functions.php';
include 'functions/gpa_functions.php';
?>

<!-- Include JavaScript for dynamic search suggestions -->
<script>
document.addEventListener("DOMContentLoaded", function () {
var suggestionBox = document.getElementById("suggestionBox");

// Fetch all students when the page finishes loading
fetchSuggestions("")

var searchInput = document.getElementById("searchInput");
var timeout = null;

searchInput.addEventListener("input", function () {
clearTimeout(timeout);
var searchQuery = searchInput.value.trim();
if (searchQuery.length >= 0) {
// Fetch suggestions after a short delay to avoid excessive requests
timeout = setTimeout(function () {
fetchSuggestions(searchQuery);
}, 300);
}
});

function fetchSuggestions(query) {
fetch("search_gpa.php?search=" + query)
.then(response => response.text())
.then(data => {
suggestionBox.innerHTML = data;
});
}
});
</script>


<!-- HTML for search input and suggestion box -->
<h2>Student Subjects Point</h2>

<div>
<input type="text" id="searchInput" placeholder="Search by Name" class="d-inline">
<button onclick="window.location.href='add_student.php'">Add Student</button>
<div id="suggestionBox"></div>
</div>

<script>
function openPopup(url) {
window.open(url, '_self', 'width=600,height=400');
}
</script>

<?php include 'templates/footer.php'; ?>
20 changes: 0 additions & 20 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,4 @@
header("Location: login.php");
exit();
}

include 'templates/header.php';

$role = $_SESSION['role'];

?>

<div class="container">
<h1>Welcome, <?php echo $_SESSION['username']; ?>!</h1>

<?php if ($role == 'admin') { ?>
<button onclick="window.location.href='gpa_manager.php'">GPA manager</button>
<button onclick="window.location.href='students_manager.php'">Students manager</button>
<button onclick="window.location.href='classes.php'">Classes</button>
<?php } else { ?>
<button onclick="window.location.href='view_gpa.php'">View GPA</button>
<button onclick="window.location.href='classmates.php'">View Classmates</button>
<?php } ?>
</div>

<?php include 'templates/footer.php'; ?>
10 changes: 8 additions & 2 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
$_SESSION['username'] = $user['username'];
$_SESSION['role'] = $user['role'];
$_SESSION['studentid'] = $user['studentid'];
header("Location: index.php");
exit();

if($user['role'] == 'student') {
header("Location: student_view.php");
exit();
} else {
header("Location: students_manager.php");
exit();
}
} else {
$login_error = "Invalid username or password.";
}
Expand Down
4 changes: 2 additions & 2 deletions search_gpa.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<td>{$row['HocKy']}</td>
<td><span id='diemHP{$row['MaHP']}'>{$row['DiemHP']}</span></td>
<td>
<button id='buttonDiemHP{$row['MaHP']}' onclick=\"editDiemHP('{$row['MaHP']}')\">Sửa Điểm</button>
<button class=\"btn btn-info\" id='buttonDiemHP{$row['MaHP']}' onclick=\"editDiemHP('{$row['MaHP']}')\">Sửa</button>
</td>
</tr>";
}
Expand Down Expand Up @@ -93,7 +93,7 @@
<td>{$subject['HocKy']}</td>
<td><span id='diemHP{$subject['MaHP']}'>{$subject['DiemHP']}</span></td>
<td>
<button id='buttonDiemHP{$subject['MaHP']}' onclick=\"editDiemHP('{$subject['MaHP']}')\">Sửa Điểm</button>
<button id='buttonDiemHP{$subject['MaHP']}' onclick=\"editDiemHP('{$subject['MaHP']}')\">Sửa</button>
</td>
</tr>";
}
Expand Down
Loading

0 comments on commit 72d672c

Please sign in to comment.