diff --git a/activities.php b/activities.php
new file mode 100644
index 0000000..b27936c
--- /dev/null
+++ b/activities.php
@@ -0,0 +1,110 @@
+exec($sql);
+} catch (PDOException $e) {
+ die("ERROR: Could not connect. " . $e->getMessage());
+}
+?>
+
+
+
+
+ Exam management page.
+
+
diff --git a/index.php b/index.php
index 94f8a65..5652639 100644
--- a/index.php
+++ b/index.php
@@ -39,6 +39,9 @@
diff --git a/login.php b/login.php
index 3885ff3..99512da 100644
--- a/login.php
+++ b/login.php
@@ -28,6 +28,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $username;
$_SESSION['role_id'] = $user['role_id'];
+
+ // Log attendance
+ $login_time = date('Y-m-d H:i:s');
+ $ip_address = $_SERVER['REMOTE_ADDR'];
+ $attendance_stmt = $db->prepare("INSERT INTO attendance (user_id, login_time, ip_address) VALUES (:user_id, :login_time, :ip_address)");
+ $attendance_stmt->bindParam(':user_id', $user['id']);
+ $attendance_stmt->bindParam(':login_time', $login_time);
+ $attendance_stmt->bindParam(':ip_address', $ip_address);
+ $attendance_stmt->execute();
+ $_SESSION['attendance_id'] = $db->lastInsertId();
+
header("Location: index.php");
exit();
} else {
diff --git a/logout.php b/logout.php
index e4bc3fa..afbb213 100644
--- a/logout.php
+++ b/logout.php
@@ -1,5 +1,17 @@
prepare("UPDATE attendance SET logout_time = :logout_time WHERE id = :id");
+ $attendance_stmt->bindParam(':logout_time', $logout_time);
+ $attendance_stmt->bindParam(':id', $_SESSION['attendance_id']);
+ $attendance_stmt->execute();
+}
+
session_unset();
session_destroy();
header("Location: login.php");
diff --git a/roles.php b/roles.php
index 9bff98a..93fa978 100644
--- a/roles.php
+++ b/roles.php
@@ -18,6 +18,13 @@ try {
name VARCHAR(255) NOT NULL UNIQUE
)");
+ // Function to log activity
+ function log_activity($user_id, $action) {
+ global $pdo;
+ $stmt = $pdo->prepare("INSERT INTO activities (user_id, action) VALUES (:user_id, :action)");
+ $stmt->execute(['user_id' => $user_id, 'action' => $action]);
+ }
+
// Handle Create and Update
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['add_role'])) {
@@ -25,6 +32,8 @@ try {
if (!empty($name)) {
$stmt = $pdo->prepare("INSERT INTO roles (name) VALUES (:name)");
$stmt->execute(['name' => $name]);
+ $new_role_id = $pdo->lastInsertId();
+ log_activity($_SESSION['user_id'], "Created role {$name} (ID: {$new_role_id})");
}
} elseif (isset($_POST['update_role'])) {
$id = $_POST['role_id'];
@@ -32,6 +41,7 @@ try {
if (!empty($name) && !empty($id)) {
$stmt = $pdo->prepare("UPDATE roles SET name = :name WHERE id = :id");
$stmt->execute(['name' => $name, 'id' => $id]);
+ log_activity($_SESSION['user_id'], "Updated role {$name} (ID: {$id})");
}
}
header("Location: roles.php");
@@ -41,8 +51,17 @@ try {
// Handle Delete
if (isset($_GET['delete_id'])) {
$id = $_GET['delete_id'];
+ // Get role name for logging
+ $stmt = $pdo->prepare("SELECT name FROM roles WHERE id = :id");
+ $stmt->execute(['id' => $id]);
+ $deleted_role = $stmt->fetch();
+
$stmt = $pdo->prepare("DELETE FROM roles WHERE id = :id");
$stmt->execute(['id' => $id]);
+
+ if ($deleted_role) {
+ log_activity($_SESSION['user_id'], "Deleted role {$deleted_role['name']} (ID: {$id})");
+ }
header("Location: roles.php");
exit;
}
@@ -86,6 +105,9 @@ try {
خانه
مدیریت نقشها
مدیریت کاربران
+
Activities
+
Exams
+
Attendance
diff --git a/users.php b/users.php
index f775aba..b3d162f 100644
--- a/users.php
+++ b/users.php
@@ -26,6 +26,13 @@ try {
// Fetch all roles for the dropdown
$roles = $pdo->query("SELECT * FROM roles ORDER BY name")->fetchAll();
+ // Function to log activity
+ function log_activity($user_id, $action) {
+ global $pdo;
+ $stmt = $pdo->prepare("INSERT INTO activities (user_id, action) VALUES (:user_id, :action)");
+ $stmt->execute(['user_id' => $user_id, 'action' => $action]);
+ }
+
// Handle Create and Update
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['add_user'])) {
@@ -43,6 +50,8 @@ try {
'password' => $hashed_password,
'role_id' => $role_id
]);
+ $new_user_id = $pdo->lastInsertId();
+ log_activity($_SESSION['user_id'], "Created user {$username} (ID: {$new_user_id})");
}
} elseif (isset($_POST['update_user'])) {
$id = $_POST['user_id'];
@@ -71,6 +80,7 @@ try {
'id' => $id
]);
}
+ log_activity($_SESSION['user_id'], "Updated user {$username} (ID: {$id})");
}
}
header("Location: users.php");
@@ -80,8 +90,17 @@ try {
// Handle Delete
if (isset($_GET['delete_id'])) {
$id = $_GET['delete_id'];
+ // Get username for logging
+ $stmt = $pdo->prepare("SELECT username FROM users WHERE id = :id");
+ $stmt->execute(['id' => $id]);
+ $deleted_user = $stmt->fetch();
+
$stmt = $pdo->prepare("DELETE FROM users WHERE id = :id");
$stmt->execute(['id' => $id]);
+
+ if ($deleted_user) {
+ log_activity($_SESSION['user_id'], "Deleted user {$deleted_user['username']} (ID: {$id})");
+ }
header("Location: users.php");
exit;
}
@@ -130,6 +149,9 @@ try {
خانه
مدیریت نقشها
مدیریت کاربران
+
Activities
+
Exams
+
Attendance