Diff between 06c956d92255311f3eb7b0d6f83bcf604a6e0f47 and a953d2c3e87edb9ee0d7f862bf8b5ac1009c4aaf

Changed Files

File Additions Deletions Status
public/admin.php +14 -1 modified
public/index.php +1 -1 modified
src/nollaus.php +22 -0 added

Full Patch

diff --git a/public/admin.php b/public/admin.php
index b58231c..f1d2b92 100644
--- a/public/admin.php
+++ b/public/admin.php
@@ -62,6 +62,7 @@
                 <tr>
                     <th>Nimi</th>
                     <th>Rooli</th>
+                    <th>Nollaus</th>
                 </tr>
             </thead>
             <tbody>
@@ -84,7 +85,19 @@
                                     <option value="1" <?= ($kayttaja['opettaja'] === '1') ? 'selected' : '' ?> >Opettaja</option>
                                 </select>
                             </form>
-                        </td>
+						</td>
+						<!-- Nollaus nappi -->
+						<td>
+							<?php
+								//if ($kayttaja["nimi"] !== $tunnus) // Ei voi muuttaa omaa salasanaa
+								{
+									echo "<form action='../src/nollaus.php' method='POST'>";
+									echo "<input type='hidden' id='id' name='id' value={$kayttaja['id']}>";
+									echo "<button type='submit'>Nollaa salasana</button>";
+									echo "</form>";
+								}
+							?>
+						</td>
                     </tr>
                 <?php endforeach; ?>
             </tbody>
diff --git a/public/index.php b/public/index.php
index 2720622..7c197d7 100755
--- a/public/index.php
+++ b/public/index.php
@@ -26,7 +26,7 @@ if ($result->num_rows>0){
 <body>
 	<?php include "../src/header.php"; ?>
 	<h1>
-		Harjoittelupaikkoja
+		Opiskelijat
 	</h1>
     <main>
 		<div class="table-container">
diff --git a/src/nollaus.php b/src/nollaus.php
new file mode 100644
index 0000000..29461bc
--- /dev/null
+++ b/src/nollaus.php
@@ -0,0 +1,22 @@
+<?php
+include "../src/connect.php";
+include "../src/kirjautunut.php";
+
+// Jos kirjautunut sisään (../src/kirjautunut.php)
+if ($logged_in and $op) {
+	$id = $_POST["id"];
+	// Muuta salasana arvoksi 0
+	$sql = "UPDATE kayttajat SET salasana='0' WHERE id='{$id}';";
+	echo $sql;
+	if ($conn->query($sql) === TRUE) {
+	  echo "Salasana muutettu";
+	} else {
+	  echo "Error: " . $sql . "<br>" . $conn->error;
+	}
+	$conn->close();
+}
+// Redirect
+$newURL = "../public/admin.php";
+header('Location: '.$newURL);
+die();
+?>