diff --git a/create_user.php b/create_user.php index e43ba32..3b23125 100644 --- a/create_user.php +++ b/create_user.php @@ -14,21 +14,32 @@ $success = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = trim($_POST['username']); $password = $_POST['password']; + $full_name = trim($_POST['full_name']); + $department = trim($_POST['department']); + $position = trim($_POST['position']); $role = $_POST['role']; if (empty($username) || empty($password) || empty($role)) { - $error = 'All fields are required.'; + $error = 'Username, password and role are required.'; } else { $pdo = db(); $stmt = $pdo->prepare('SELECT id FROM users WHERE username = :username'); $stmt->execute(['username' => $username]); if ($stmt->fetch()) { - $error = 'Username or email already exists.'; + $error = 'Username already exists.'; } else { $hashed_password = password_hash($password, PASSWORD_DEFAULT); - $stmt = $pdo->prepare('INSERT INTO users (username, password, role) VALUES (:username, :password, :role)'); - if ($stmt->execute(['username' => $username, 'password' => $hashed_password, 'role' => $role])) { + $stmt = $pdo->prepare('INSERT INTO users (username, password, full_name, department, position, role) VALUES (:username, :password, :full_name, :department, :position, :role)'); + $params = [ + 'username' => $username, + 'password' => $hashed_password, + 'full_name' => $full_name, + 'department' => $department, + 'position' => $position, + 'role' => $role + ]; + if ($stmt->execute($params)) { $success = 'User created successfully.'; } else { $error = 'Failed to create user.'; @@ -55,7 +66,30 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { - +
+ + +
+
+ + +
+
+ + +
diff --git a/db/migrations/005_add_fields_to_users_table.sql b/db/migrations/005_add_fields_to_users_table.sql new file mode 100644 index 0000000..91f65d7 --- /dev/null +++ b/db/migrations/005_add_fields_to_users_table.sql @@ -0,0 +1,6 @@ +-- Add full_name, department, position, and role to the users table +ALTER TABLE `users` +ADD COLUMN `full_name` VARCHAR(255) NULL, +ADD COLUMN `department` VARCHAR(255) NULL, +ADD COLUMN `position` VARCHAR(255) NULL, +ADD COLUMN `role` VARCHAR(255) NULL; diff --git a/edit_user.php b/edit_user.php index 8e7c6ac..9649f0e 100644 --- a/edit_user.php +++ b/edit_user.php @@ -21,14 +21,24 @@ $success = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = trim($_POST['username']); + $full_name = trim($_POST['full_name']); + $department = trim($_POST['department']); + $position = trim($_POST['position']); $role = $_POST['role']; $password = $_POST['password']; if (empty($username) || empty($role)) { $error = 'Username and role are required.'; } else { - $sql = 'UPDATE users SET username = :username, role = :role'; - $params = ['username' => $username, 'role' => $role, 'id' => $user_id]; + $sql = 'UPDATE users SET username = :username, full_name = :full_name, department = :department, position = :position, role = :role'; + $params = [ + 'username' => $username, + 'full_name' => $full_name, + 'department' => $department, + 'position' => $position, + 'role' => $role, + 'id' => $user_id + ]; if (!empty($password)) { $sql .= ', password = :password'; @@ -46,7 +56,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } } -$stmt = $pdo->prepare('SELECT username, role FROM users WHERE id = :id'); +$stmt = $pdo->prepare('SELECT username, full_name, department, position, role FROM users WHERE id = :id'); $stmt->execute(['id' => $user_id]); $user = $stmt->fetch(); @@ -73,7 +83,29 @@ if (!$user) {
- +
+ + +
+
+ + +
+
+ + +