forked from Lake-Tuggeranong-College/CyberCity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
userEdit.php
116 lines (90 loc) · 3.82 KB
/
userEdit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php include "template.php";
/** @var $conn */
if (!authorisedAccess(false, false, true)) {
header("Location:index.php");
}
?>
<title>User Edit</title>
<?php
if (isset($_GET["UserID"])) {
$userToLoad = $_GET["UserID"];
$sql = $conn->query("SELECT * FROM Users WHERE ID= " . $userToLoad);
$userInformation = $sql->fetch();
$userID = $userInformation["ID"];
$userHashedPassword = $userInformation["HashedPassword"];
$userName = $userInformation["Username"];
$userAccessLevel = $userInformation["AccessLevel"];
$userEnabled = $userInformation["Enabled"];
$userScore = $userInformation["Score"];
} else {
header("location:userList.php");
}
?>
<h1 class='text-primary'>Edit Module Information</h1>
<form action="userEdit.php?UserID=<?= $userToLoad ?>" method="post" enctype="multipart/form-data">
<div class="container-fluid">
<div class="row">
<!--Customer Details-->
<div class="col-md-6">
<h2>User Details</h2>
<p>User Name<label>
<input type="text" name="userName" class="form-control" required="required"
value="<?= $userName ?>">
</label></p>
<!-- <p>Password-->
<!-- <label>-->
<!-- <input type="text" name="password" class="form-control" required="required"-->
<!-- value="--><?php //= $userHashedPassword ?><!--">-->
<!-- </label></p>-->
</div>
<div class="col-md-6">
<h2>More Details</h2>
<!--Product List-->
<p>Access Level
<label>
<input type="text" name="AccessLevel" class="form-control" required="required"
value="<?= $userAccessLevel ?>">
</label></p>
<p>Enabled/Disabled
<label>
<input type="text" name="Enabled" class="form-control" required="required"
value="<?= $userEnabled ?>">
</label></p>
<p>Current Score
<label>
<input type="text" name="Score" class="form-control" required="required"
value="<?= $userScore ?>">
</label></p>
</div>
</div>
</div>
<input type="submit" name="formSubmit" value="Update">
</form>
<!-- If the user presses update, this code runs-->
<?php
// Back End
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$userName = sanitise_data($_POST["userName"]);
// $userPassword = sanitise_data($_POST["moduleLocation"]);
$userAccessLevel = sanitise_data($_POST["AccessLevel"]);
$userEnabled = sanitise_data($_POST["Enabled"]);
$userScore = sanitise_data($_POST["Score"]);
// $userHashedPassword = password_hash($userPassword, PASSWORD_DEFAULT);
$userToLoad = $_GET["UserID"];
$sql = "UPDATE Users SET Username= :newusername, AccessLevel= :newaccesslevel, Enabled= :newEnabled, Score=:newscore WHERE ID ='$userToLoad'";
//$sql = "INSERT INTO `RegisteredModules` (Location, Module, HashedAPIKey, Enabled) VALUES (:newLocation, :newModule, :newHashedAPIkey, :enabled)";
$stmt = $conn->prepare($sql);
$stmt->bindValue(":newusername", $userName);
// $stmt->bindValue(":newpassword", $userHashedPassword);
$stmt->bindValue(":newaccesslevel", $userAccessLevel);
$stmt->bindValue(":newEnabled", $userEnabled);
$stmt->bindValue(":newscore", $userScore);
$stmt->execute();
// header("location:moduleInformation.php?ModuleID=$moduleToLoad");
}
?>
<?php
/*echo '<h2 class="text-danger">Debug Information. Comment out as necessary</h2><pre>';
print_r($moduleInformation);
echo '</pre>';
*/ ?>