Diff between 9069db30e6a07c7c3b534f1d9517aa07a5ab637d and e4353fc2ef1f5dfdfa566b7d1d1adc6a92c18926

Changed Files

File Additions Deletions Status
admin.php +80 -0 added
hae_harjoittelupaikat.php +20 -0 added
harjoittelupaikat.php +29 -0 added
header.php +8 -2 modified
index.php +75 -5 modified
kirjautuminen.php +1 -1 modified
kirjautunut.php +9 -4 modified
lisaa.php +3 -2 modified
lisaa_harjoittelupaikka.php +18 -0 added
logic.register.php +23 -0 added
luku.php +0 -40 deleted
muokkaa.php +12 -9 modified
poista.php +13 -8 modified
register.php +31 -0 added
style.css +3 -1 modified
uusharjoittelupaikka.php +38 -0 added

Full Patch

diff --git a/admin.php b/admin.php
new file mode 100644
index 0000000..61c3e68
--- /dev/null
+++ b/admin.php
@@ -0,0 +1,80 @@
+<?php
+    include "connect.php";
+
+    // Vaihda rooli
+    if (isset($_POST['rooli']) && $_SERVER['REQUEST_METHOD'] === 'POST') {
+        $id = $_POST["id"];
+        $rooli = $_POST['rooli'];
+
+        echo $id, $rooli;
+        $stmt = $conn->prepare("UPDATE kayttajat SET opettaja=(?) WHERE id=(?);");
+        $stmt->bind_param("ss", $rooli, $id);
+        
+        if ($stmt->execute()) {
+            header("Location: " . $_SERVER['PHP_SELF']);
+            exit();
+        } else {
+            echo "Virhe: " . $stmt->error;
+        }
+        
+        $stmt->close();
+    }
+
+    // Hae käyttäjät
+    $sql = "SELECT * FROM kayttajat";
+    $result = $conn->query($sql);
+
+    $kayttajat = [];
+    if ($result->num_rows > 0) {
+        while($row = $result->fetch_assoc()) {
+            $kayttajat[] = $row;
+        }
+    } else {
+        echo "Käyttäjiä ei löytynyt";
+    }
+
+    $conn->close();  
+?>
+
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Hallintapaneeli</title>
+    <link rel="stylesheet" type="text/css" href="style.css">
+
+</head>
+<body>
+    <?php include "header.php"; ?>
+    <h1>
+        Käyttäjät
+    </h1>
+    <main>
+        <table>
+            <?php foreach ($kayttajat as $kayttaja): ?>
+                <tr>
+                    <th>Nimi</th>
+                    <th>Rooli</th>
+                </tr>
+                <tr>
+                    <?php 
+                        echo "<td>" . $kayttaja["nimi"] . "</td>";
+                    ?>
+                    <td>
+                        <form action="" method="POST" id="rooli-form">
+                             <?php 
+                                echo "<input type='hidden' id='id' name='id' value={$kayttaja['id']}>"
+                            ?>
+                            <select name="rooli">
+                                <option value="0" <?= ($kayttaja['opettaja'] === '0') ? 'selected' : '' ?>>Opiskelija</option>
+                                <option value="1" <?= ($kayttaja['opettaja'] === '1') ? 'selected' : '' ?>>Opettaja</option>
+                            </select>
+                        </form>
+                    </td>
+                </tr>
+            <?php endforeach; ?>
+        </table>
+    </main>
+    <input type="submit" form="rooli-form" value="Tallenna"/>
+</body>
+</html>
\ No newline at end of file
diff --git a/hae_harjoittelupaikat.php b/hae_harjoittelupaikat.php
new file mode 100644
index 0000000..213ae26
--- /dev/null
+++ b/hae_harjoittelupaikat.php
@@ -0,0 +1,20 @@
+<?php
+include "connect.php";
+
+$sql = "SELECT * FROM harjoittelupaikat";
+$result = $conn->query($sql);
+
+if ($result->num_rows>0) {
+	while($row = $result->fetch_assoc()) {
+		echo "<tr>";
+			echo "<td>" . $row["nimi"] . "</td>";
+			echo "<td>" . $row["ohjaaja"] . "</td>";
+			echo "<td>" . $row["yhteystiedot"] . "</td>";
+		echo "</tr>";
+	}
+} else {
+	echo "Harjoittelupaikkoja ei löytynyt";
+}
+
+$conn->close();
+?>
diff --git a/harjoittelupaikat.php b/harjoittelupaikat.php
new file mode 100644
index 0000000..2e241f2
--- /dev/null
+++ b/harjoittelupaikat.php
@@ -0,0 +1,29 @@
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Harjoittelupaikat</title>
+    <link rel="stylesheet" type="text/css" href="style.css">
+</head>
+<body>
+    <?php include "header.php"; ?>
+    <h1>
+        Harjoittelupaikat
+    </h1>
+    <a href="uusharjoittelupaikka.php">Lisää harjoittelupaikka</a>
+    <main>
+        <section>
+            <div class="table-container">
+                <table>
+                    <tr>
+                        <th>Nimi</th>
+                        <th>Ohjaaja</th>
+                        <th>Yhteystiedot</th>
+                    </tr>
+                    <?php include "hae_harjoittelupaikat.php"; ?>
+                </table> 
+            </div>
+        </section>
+    </main>
+</body>
+</html>
\ No newline at end of file
diff --git a/header.php b/header.php
index 8e629d2..62befe9 100644
--- a/header.php
+++ b/header.php
@@ -1,19 +1,25 @@
 <header>
 <?php
 include "kirjautunut.php";
+$conn->close();
 ?>
 	<hr>
 	<nav>
-	  <a href="index.php">Harjoittelupaikat</a>
+	  <a href="index.php">Opiskelijoiden harjoittelupaikat</a>
+	  <span>·</span>
+	  <a href="harjoittelupaikat.php">Harjoittelupaikat</a>
 	  <span>·</span>
 		<?php
 		if ($logged_in){
-			echo	"Kirjauduttu sisään";
+			echo	"Kirjauduttu sisään, tervetuloa {$tunnus}";
 			echo 	"<span>·</span>";
 			echo 	"<a href='kirjaudu_ulos.php'>Kirjaudu ulos</a>";
 		}
 		else {
 			echo	"<a href='kirjautuminen.php'>Kirjaudu sisään</a>";
+			echo 	"<span>·</span>";
+			echo	"<a href='register.php'>Rekistöröidy</a>";
+			
 		}
 		?>
 	  <span>·</span>
diff --git a/index.php b/index.php
index f4088d0..e9bb522 100755
--- a/index.php
+++ b/index.php
@@ -1,3 +1,19 @@
+<?php
+// Täällä teemme listan henkilöistä jotka ovat taulukossa, alempana tiedostossa renderöimme ne
+include "kirjautunut";
+// Käytä connect.php
+include "connect.php";
+// SQL komento: saadaan oppilaat
+$sql = "SELECT * FROM oppilaat";
+$result = $conn->query($sql); // Aja komento
+// Jos tuloksia
+$henkilot = [];
+if ($result->num_rows>0){
+	while($row = $result->fetch_assoc()){
+		$henkilot[] = $row;
+	}
+}
+?>
 <!DOCTYPE html>
 <html lang="en">
 <head>
@@ -29,12 +45,66 @@
 				<th>Status</th>
 				<th>Ruokaraha</th>
 				<th>Muuta</th>
-				<th>Muokkaus</th>
+				<?php // Ei muokkaus riviä, jos ei ole oikeuksia muokata
+				if ($logged_in)
+				{
+					echo "<th>Muokkaus</th>";
+				}
+				?>
 			</tr>
-		<!-- Ota tiedot tiedot kannasta -->
- 		<?php
-		include "luku.php";
-		?>
+		<!-- Ota tiedot tiedot muuttujasta henkilot -->
+		<?php foreach ($henkilot as $tyyppi): ?>
+			<tr>
+				<?php // Renderöi taulukko tyypin tiedoilla
+				if ($tyyppi['id'] === $_GET['id']) // Jos tyyppi on muokattavissa
+					{
+						// Muuttaa normaalin tr rivin tableksi
+						echo "<form action='muokkaa.php' method='POST'>";
+						echo "<input type='hidden' id='id' name='id' value={$tyyppi['id']}>";
+						echo "<td> <input type='text' name='nimi' id='nimi' value='" . $tyyppi["nimi"] . "'> </td>";
+						echo "<td> <input type='text' name='paikka' id='paikka' value='" . $tyyppi["paikka"] . "'> </td>";
+						echo "<td> <input type='text' name='ohjaaja' id='ohjaaja' value='" . $tyyppi["ohjaaja"] . "'> </td>";
+						echo "<td> <input type='text' name='yhteystiedot' id='yhteystiedot' value='" . $tyyppi["yhteystiedot"] . "'> </td>";
+						echo "<td> <input type='date' name='aloitus' id='aloitus' value='" . $tyyppi["aloitus"] . "'> </td>";
+						echo "<td> <input type='date' name='lopetus' id='lopetus' value='" . $tyyppi["lopetus"] . "'> </td>";
+						echo "<td> <input type='text' name='status' id='status' value='" . $tyyppi["status"] . "'> </td>";
+						echo "<td> <input type='text' name='ruokaraha' id='ruokaraha' value='" . $tyyppi["ruokaraha"] . "'> </td>";
+						echo "<td> <input type='text' name='muuta' id='muuta' value='" . $tyyppi["muuta"] . "'> </td>";
+						// Täällä emme tarkista onko kirjauduttu sisään, koska ainoa tapa päästä tänne on kirjautumalla
+						// sisään. Tietysti voit muokata url:llää itse, mutta sitten ongelma on sinun syy, ja muokkaa
+						// nappi ei tule toimimaan
+						echo "<td> <input type='submit' value='Tallenna muutokset' > </td>"; 
+						echo "</form>";
+					}
+					else // Tyyppiä ei muokata, näytä vaan normaalisti
+					{
+						echo "<td>" . $tyyppi["nimi"] . "</td>";
+						echo "<td>" . $tyyppi["paikka"] . "</td>";
+						echo "<td>" . $tyyppi["ohjaaja"] . "</td>";
+						echo "<td>" . $tyyppi["yhteystiedot"] . "</td>";
+						echo "<td>" . $tyyppi["aloitus"] . "</td>";
+						echo "<td>" . $tyyppi["lopetus"] . "</td>";
+						echo "<td>" . $tyyppi["status"] . "</td>";
+						echo "<td>" . $tyyppi["ruokaraha"] . "</td>";
+						echo "<td>" . $tyyppi["muuta"] . "</td>";
+						if ($op or ($logged_in and $tunnus === $tyyppi['nimi'])) { // Jos opettaja tai muokkaa omia tietoja
+							echo "<td>" . // Poista nappi
+								"<form action='poista.php' method='POST'>
+								<input type='hidden' id='nimi' name='nimi' value={$tyyppi['nimi']}>
+								<input type='submit' value='Poista'>
+								</form>";
+							echo "" . // Muokkaa nappi
+								"<form action='index.php?id={$tyyppi['id']}' method='GET'>
+								<input type='hidden' id='id' name='id' value={$tyyppi['id']}>
+								<input type='submit' value='Muokkaa'>
+								</form>"
+									. "</td>";
+						}
+					}
+				?>
+			</tr>
+
+        <?php endforeach; ?>
 	   </table> 
 	  </div>
 	  <script src="./search ja sort table/scripts/searchTable.js"></script>
diff --git a/kirjautuminen.php b/kirjautuminen.php
index a756323..5637023 100644
--- a/kirjautuminen.php
+++ b/kirjautuminen.php
@@ -27,7 +27,7 @@
                     <label for="nimi">Nimi:</label>
                     <input type="text" id="nimi" name="nimi">
                     <label for="salasana">Salasana:</label>
-                    <input type="text" id="salasana" name="salasana">
+                    <input type="password" id="salasana" name="salasana">
                     <input type="submit" name="submit" value="Kirjaudu">
                 </fieldset>
             </form>
diff --git a/kirjautunut.php b/kirjautunut.php
index 2b27396..6bdf36c 100644
--- a/kirjautunut.php
+++ b/kirjautunut.php
@@ -1,20 +1,25 @@
 <?php
 // Katsoo onko kirjauduttu sisään, ja laittaa sen mukaan arvon $logged_in
 $logged_in = false;
+// Onko opettaja käyttäjä (overpowered)
+$op = false;
 include "connect.php";
 if(isset($_COOKIE["nimi"]) and isset($_COOKIE["salasana"])){
 	// TIEDOT
 	$tunnus = mysqli_real_escape_string($conn, $_COOKIE['nimi']);
-	$salasana = mysqli_real_escape_string($conn, $_COOKIE['salasana']); // Hashaa salasana samalla
+	$salasana = mysqli_real_escape_string($conn, $_COOKIE['salasana']);
 	// Etsi tiedot tietokentästä
 	$sql = "SELECT * FROM `kayttajat` WHERE nimi='{$_COOKIE['nimi']}' LIMIT 1;";
-	$result = $conn->query($sql); // Aja komento
+	$kayttaja = $conn->query($sql)->fetch_assoc(); // Aja komento
 	// Salasana tietokentästä
-	$salasana_tietokanta = $result->fetch_assoc()['salasana'];
+	$salasana_tietokanta = $kayttaja['salasana'];
 	// Vertaa salasanoja
 	if (password_verify($salasana, $salasana_tietokanta)){
 		$logged_in = true;
+		if ($kayttaja['opettaja'])
+		{
+			$op = true;
+		}
 	}
 }
-$conn->close();
 ?>
diff --git a/lisaa.php b/lisaa.php
index 2299812..08222cf 100644
--- a/lisaa.php
+++ b/lisaa.php
@@ -2,9 +2,10 @@
 include "connect.php";
 include "kirjautunut.php";
 
-if ($logged_in) {
+// Jos kirjautunut sisään (kirjautunut.php)
+if ($logged_in and $op) {
+	// Lisää SQL
 	$sql = "INSERT INTO `oppilaat` (`id`, `nimi`, `paikka`, `ohjaaja`, `yhteystiedot`, `aloitus`, `lopetus`, `status`, `ruokaraha`, `muuta`) VALUES (NULL, '{$_POST["nimi"]}', '{$_POST["paikka"]}', '{$_POST["ohjaaja"]}', '{$_POST["yhteystiedot"]}', '{$_POST["aloitus"]}', '{$_POST["lopetus"]}', '{$_POST["status"]}', '{$_POST["ruokaraha"]}', '{$_POST["muuta"]}')";
-
 	if ($conn->query($sql) === TRUE) {
 	  echo "New record created successfully";
 	} else {
diff --git a/lisaa_harjoittelupaikka.php b/lisaa_harjoittelupaikka.php
new file mode 100644
index 0000000..dfd577b
--- /dev/null
+++ b/lisaa_harjoittelupaikka.php
@@ -0,0 +1,18 @@
+<?php
+include "connect.php";
+include "kirjautunut.php";
+
+if ($logged_in and $op) {
+	$sql = "INSERT INTO `harjoittelupaikat` (`id`, `nimi`, `ohjaaja`, `yhteystiedot`) VALUES (NULL, '{$_POST["nimi"]}', '{$_POST["ohjaaja"]}', '{$_POST["yhteystiedot"]}')";
+	if ($conn->query($sql) === TRUE) {
+	  echo "New record created successfully";
+	} else {
+	  echo "Error: " . $sql . "<br>" . $conn->error;
+	}
+	$conn->close();
+}
+// Redirect
+$newURL = "harjoittelupaikat.php";
+header('Location: '.$newURL);
+die();
+?> 
diff --git a/logic.register.php b/logic.register.php
new file mode 100644
index 0000000..adcd76d
--- /dev/null
+++ b/logic.register.php
@@ -0,0 +1,23 @@
+<?php
+include "connect.php";
+
+$nimi =  mysqli_real_escape_string($conn, $_POST["nimi"]);
+$salasana =  mysqli_real_escape_string($conn, $_POST["salasana"]);
+$vsalasana =  mysqli_real_escape_string($conn, $_POST["vsalasana"]);
+
+if ($salasana === $vsalasana) {
+	$suolattusalasana = password_hash($salasana, PASSWORD_DEFAULT);
+	$sql = "INSERT INTO `kayttajat` (`id`, `nimi`, `salasana`,`opettaja`) VALUES (NULL,'{$nimi}', '{$suolattusalasana}',false ); ";
+	echo $sql;
+	$conn->query($sql);
+	echo "it is alive!";
+}
+else {
+	echo "Vitun tymä";
+}
+$conn->close();
+// Redirect
+$newURL = "index.php";
+header('Location: '.$newURL);
+die();
+?>
diff --git a/luku.php b/luku.php
deleted file mode 100755
index 721b98b..0000000
--- a/luku.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-// Käytä connect.php
-include "connect.php";
-// SQL komento: saadaan oppilaat
-$sql = "SELECT * FROM oppilaat";
-$result = $conn->query($sql); // Aja komento
-// Jos tuloksia
-if ($result->num_rows>0){
-	while($row = $result->fetch_assoc()){
-
-		echo "<tr>";
-			echo "<td>" . $row["nimi"] . "</td>";
-			echo "<td>" . $row["paikka"] . "</td>";
-			echo "<td>" . $row["ohjaaja"] . "</td>";
-			echo "<td>" . $row["yhteystiedot"] . "</td>";
-			echo "<td>" . $row["aloitus"] . "</td>";
-			echo "<td>" . $row["lopetus"] . "</td>";
-			echo "<td>" . $row["status"] . "</td>";
-			echo "<td>" . $row["ruokaraha"] . "</td>";
-			echo "<td>" . $row["muuta"] . "</td>";
-			echo "<td>" . // Poista nappi
-				"<form action='poista.php' method='POST'>
-				<input type='hidden' id='id' name='id' value={$row['id']}>
-				<input type='submit' value='Poista'>
-				</form>"
-			       	. "</td>";
-			echo "<td>" . // Muokkaa nappi
-				"<form action='muokkaa.php' method='POST'>
-				<input type='hidden' id='id' name='id' value={$row['id']}>
-				<input type='submit' value='Muokkaa'>
-				</form>"
-			       	. "</td>";
-		echo "</tr>";
-	}
-}
-else{
-	echo "Oppilaita ei löytynyt";
-}
-$conn->close();
-?>
diff --git a/muokkaa.php b/muokkaa.php
index 1d4fc9d..71d59cc 100644
--- a/muokkaa.php
+++ b/muokkaa.php
@@ -1,16 +1,19 @@
 <?php
+// Yhdistä tietokantaan
 include "connect.php";
+include "kirjautunut.php"; // Ehkä ei vaadittu?
 
-$id = $_POST["id"];
-$sql = "UPDATE oppilaat SET nimi='katti' WHERE id={$id}";
-
-if ($conn->query($sql) === TRUE) {
-  echo "Muutettu onnistuneesti";
-} else {
-  echo "Virhe muokkaessa arvoa: " . $conn->error;
+if ($op or ($logged_in and $tunnus === $_POST['nimi'])) { // Jos opettaja tai muokkaa omia tietoja // ONKO TÄMÄ TURVALLINEN??
+	$id = $_POST["id"];
+	$sql = "UPDATE oppilaat SET nimi='{$_POST["nimi"]}' , paikka='{$_POST["paikka"]}' , ohjaaja='{$_POST["ohjaaja"]}' , yhteystiedot='{$_POST["yhteystiedot"]}' , aloitus='{$_POST["aloitus"]}' , lopetus='{$_POST["lopetus"]}' , status='{$_POST["status"]}' , ruokaraha='{$_POST["ruokaraha"]}' , muuta='{$_POST["muuta"]}' WHERE id={$id};";
+	echo $sql;
+	if ($conn->query($sql) === TRUE) {
+	  echo "Muutettu onnistuneesti";
+	} else {
+	  echo "Virhe muokkaessa arvoa: " . $conn->error;
+	}
 }
-$conn->close();
-
+// Redirect
 $newURL = "index.php";
 header('Location: '.$newURL);
 die();
diff --git a/poista.php b/poista.php
index 113b830..9680773 100644
--- a/poista.php
+++ b/poista.php
@@ -1,16 +1,21 @@
 <?php
 // Yhdistä tietokantaan
 include "connect.php";
-// Poista tietokannasta yksi tyyppi ideen avulla
-$id = $_POST["id"];
-$sql = "DELETE FROM oppilaat WHERE id={$id}";
+include "kirjautunut.php"; // Ehkä ei vaadittu?
 
-if ($conn->query($sql) === TRUE) {
-  echo "Arvo poistettu onnistuneesti";
-} else {
-  echo "Virhe poistaessa arvoa: " . $conn->error;
+if ($op or ($logged_in and $tunnus === $_POST['nimi'])) { // Jos opettaja tai muokkaa omia tietoja // ONKO TÄMÄ TURVALLINEN??
+	// Poista tietokannasta yksi tyyppi ideen avulla
+	$nimi = $_POST["nimi"];
+	$sql = "DELETE FROM oppilaat WHERE nimi='{$nimi}'";
+	
+	echo $sql;
+	if ($conn->query($sql) === TRUE) {
+	  echo "Arvo poistettu onnistuneesti";
+	} else {
+	  echo "Virhe poistaessa arvoa: " . $conn->error;
+	}
+	$conn->close();
 }
-$conn->close();
 // Redirect
 $newURL = "index.php";
 header('Location: '.$newURL);
diff --git a/register.php b/register.php
new file mode 100644
index 0000000..eee8aee
--- /dev/null
+++ b/register.php
@@ -0,0 +1,31 @@
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Rekisteröidy</title>
+</head>
+<body>
+    <?php include "header.php" ?>
+    <main>
+        <section>
+            <form action="logic.register.php" method="POST">
+                <fieldset>
+                    <legend>Luo Käyttäjä</legend>
+                    <label for="nimi">Nimi:</label>
+                    <input type="text" id="nimi" name="nimi">
+                    <label for="salasana">Salasana:</label>
+                    <input type="password" id="salasana" name="salasana">
+                    <label for="salasana">Vahvista salasana:</label>
+                    <input type="password" id="vsalasana" name="vsalasana">
+                    <input type="submit" name="submit" value="Luo käyttäjä">
+                </fieldset>
+            </form>
+        </section>
+    </main>
+    <footer>
+        <hr>
+        <p>&copy; Harjoittelupaikat 2025</p>
+        <a href="index.php">Takaisin alkuun</a>
+    </footer>
+</body>
+</html>
diff --git a/style.css b/style.css
index b9a3c20..7984b23 100755
--- a/style.css
+++ b/style.css
@@ -24,4 +24,6 @@ aside{
 }
 footer{
     text-align: center;
-}
\ No newline at end of file
+}
+input{
+}
diff --git a/uusharjoittelupaikka.php b/uusharjoittelupaikka.php
new file mode 100644
index 0000000..d72f364
--- /dev/null
+++ b/uusharjoittelupaikka.php
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Lisää Harjoittelupaikka</title>
+    <link rel="stylesheet" type="text/css" href="style.css">
+</head>
+<body>
+	<?php include "header.php"; ?>
+	<main>
+	<section>
+	  <h1>
+		  Lisää harjoittelupaikka
+	  </h1>
+	<form action="lisaa_harjoittelupaikka.php" method="POST">
+		<fieldset>
+			<legend>
+				 Harjoittelupaikan tiedot
+			</legend>
+			<label for="nimi">Nimi:</label>
+			<input required type="text" id="nimi" name="nimi" placeholder="Käpypaja Oy" required>
+			<label for="ohjaaja">Ohjaaja:</label>
+			<input type="text" id="ohjaaja" name="ohjaaja" placeholder="Matti Meikäläinen">
+            <label for="ohjaaja">Yhteystiedot:</label>
+			<input type="text" id="yhteystiedot" name="yhteystiedot" placeholder="04012345678">
+		</fieldset>
+		<input type="submit" name="submit" value="Lisää">
+		</form>
+	</section>
+</main>
+  <footer>
+	<hr>
+	<p>&copy; Harjoittelupaikat 2025</p>
+	<a href="index.php">Takaisin alkuun</a>
+</footer>
+</body>
+</html>