From 43c33b55d6b673a3bad6a1ad29deeeca0dfb1df3 Mon Sep 17 00:00:00 2001 From: Grisu Date: Fri, 10 Jun 2022 14:10:34 +0200 Subject: [PATCH] select table rows and edit user --- app/public/css/styles.css | 8 ++++ app/public/edit_user.php | 72 +++++++++++++++++++++++++++++ app/public/header_footer/header.php | 2 + app/public/js/edit_user.js | 17 +++++++ app/public/js/select_table.js | 43 +++++++++++++++++ app/public/manage_user.php | 9 +++- app/public/mannschaft.php | 2 +- app/public/stationen.php | 2 +- app/public/statistik.php | 2 +- app/scripts/database_queries.php | 47 ++++++++++++++++++- app/scripts/functions.php | 2 +- 11 files changed, 200 insertions(+), 6 deletions(-) create mode 100644 app/public/edit_user.php create mode 100644 app/public/js/edit_user.js create mode 100644 app/public/js/select_table.js diff --git a/app/public/css/styles.css b/app/public/css/styles.css index 406463d..da5cf86 100644 --- a/app/public/css/styles.css +++ b/app/public/css/styles.css @@ -81,3 +81,11 @@ div.headline h2{ padding: 10px 0px; font-weight: 400; } + +tr.highlight { + background: #eef; +} + +tr.clicked { + background: #ccd; +} \ No newline at end of file diff --git a/app/public/edit_user.php b/app/public/edit_user.php new file mode 100644 index 0000000..5137d1d --- /dev/null +++ b/app/public/edit_user.php @@ -0,0 +1,72 @@ +fetch(); + include("header_footer/header.php"); + } + + if($_SERVER['REQUEST_METHOD'] == "POST") { + $user = get_user($con, $_POST['id'])->fetch(); + + if($user['user_name'] != $_POST['user_name']) { + change_user_name($con, $_POST['id'], $_POST['user_name']); + } + + if($user['user_group'] != $_POST['user_group']) { + if($_POST['user_group'] == "station") { + change_user_group($con, $_POST['id'], $_POST['user_group'], $_POST['bind_station']); + } else { + change_user_group($con, $_POST['id'], $_POST['user_group'], NULL); + } + } + + if(!empty($_POST['password'])) { + $phash = generate_password_hash($_POST['password'], $user['salt']); + change_password($con, $_POST['id'], $phash); + } + + header("Location: manage_user.php"); + die; + } + +?> + +
+

Benutzer bearbeiten

+
+
+
+ + />
+ +
+ +
+ + +
+ name="id"/> + +
+
+ + \ No newline at end of file diff --git a/app/public/header_footer/header.php b/app/public/header_footer/header.php index 0d18442..4208c0e 100644 --- a/app/public/header_footer/header.php +++ b/app/public/header_footer/header.php @@ -6,9 +6,11 @@ +
+
+
+
+ + +
+
+
- +
diff --git a/app/public/mannschaft.php b/app/public/mannschaft.php index a781a92..44cbcec 100644 --- a/app/public/mannschaft.php +++ b/app/public/mannschaft.php @@ -18,7 +18,7 @@
-
Name
+
diff --git a/app/public/stationen.php b/app/public/stationen.php index 6616925..6401289 100644 --- a/app/public/stationen.php +++ b/app/public/stationen.php @@ -18,7 +18,7 @@
-
Name
+
diff --git a/app/public/statistik.php b/app/public/statistik.php index f5b0a18..fb9ce65 100644 --- a/app/public/statistik.php +++ b/app/public/statistik.php @@ -47,7 +47,7 @@ ?>
-
Name
+
prepare("SELECT user_name, user_group, s_id FROM users"); + $stmt = $con->prepare("SELECT id, user_name, user_group, s_id FROM users"); $stmt->execute(); $stmt->setFetchMode(PDO::FETCH_ASSOC); return $stmt; @@ -200,6 +200,17 @@ function get_users($con) { } } +function get_user($con, $id) { + try { + $stmt = $con->prepare("SELECT * FROM users WHERE id = :id"); + $stmt->execute(['id' => $id]); + $stmt->setFetchMode(PDO::FETCH_ASSOC); + return $stmt; + } catch(PDOException $e) { + handle_pdo_exception($e); + } +} + function write_user($con, $user_name, $user_id, $phash, $salt, $user_group, $s_id) { try { $stmt = $con->prepare("INSERT INTO users (user_id, password, user_name, salt, user_group, s_id) VALUES (?, ?, ?, ?, ?, ?)"); @@ -213,4 +224,38 @@ function write_user($con, $user_name, $user_id, $phash, $salt, $user_group, $s_i } catch(PDOException $e) { handle_pdo_exception($e); } +} + +function change_user_name($con, $id, $user_name) { + try { + $stmt = $con->prepare("UPDATE users SET user_name = ? WHERE id= ?"); + $stmt->bindParam(1, $user_name, PDO::PARAM_STR); + $stmt->bindParam(2, $id, PDO::PARAM_STR); + $stmt->execute(); + } catch(PDOExeption $e) { + handle_pdo_exception($e); + } +} + +function change_user_group($con, $id, $user_group, $s_id) { + try { + $stmt = $con->prepare("UPDATE users SET user_group = ?, s_id = ? WHERE id= ?"); + $stmt->bindParam(1, $user_group, PDO::PARAM_STR); + $stmt->bindParam(2, $s_id, PDO::PARAM_INT); + $stmt->bindParam(3, $id, PDO::PARAM_INT); + $stmt->execute(); + } catch(PDOExeption $e) { + handle_pdo_exception($e); + } +} + +function change_password($con, $id, $password) { + try { + $stmt = $con->prepare("UPDATE users SET password = ? WHERE id= ?"); + $stmt->bindParam(1, $password, PDO::PARAM_STR); + $stmt->bindParam(2, $id, PDO::PARAM_STR); + $stmt->execute(); + } catch(PDOExeption $e) { + handle_pdo_exception($e); + } } \ No newline at end of file diff --git a/app/scripts/functions.php b/app/scripts/functions.php index dccd485..007d1dc 100644 --- a/app/scripts/functions.php +++ b/app/scripts/functions.php @@ -143,7 +143,7 @@ function check_admin($con) { function load_users($con) { $stmt = get_users($con); foreach($stmt->fetchAll() as $row) { - echo "\n"; + echo "\n"; echo "\n"; echo "\n"; echo "\n";
" . $row['user_name'] . "" . $row['user_group'] . "" . $row['s_id'] . "