diff --git a/hae_harjoittelupaikat.php b/hae_harjoittelupaikat.php
new file mode 100644
index 0000000..213ae26
--- /dev/null
+++ b/hae_harjoittelupaikat.php
+<?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
+<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 396b6e5..1bbf0e8 100644
--- a/header.php
+++ b/header.php
<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){
diff --git a/index.php b/index.php
index a6b2008..465eea2 100755
--- a/index.php
+++ b/index.php
<th>Status</th>
<th>Ruokaraha</th>
<th>Muuta</th>
- <th>Muokkaus</th>
</tr>
<!-- Ota tiedot tiedot kannasta -->
<?php
diff --git a/kirjautunut.php b/kirjautunut.php
index 2b27396..6bdf36c 100644
--- a/kirjautunut.php
+++ b/kirjautunut.php
<?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
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
+<?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/luku.php b/luku.php
index 9da5f7f..721b98b 100755
--- a/luku.php
+++ b/luku.php
<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>";
}
}
diff --git a/muokkaa.php b/muokkaa.php
new file mode 100644
index 0000000..1d4fc9d
--- /dev/null
+++ b/muokkaa.php
+<?php
+include "connect.php";
+
+$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;
+}
+$conn->close();
+
+$newURL = "index.php";
+header('Location: '.$newURL);
+die();
+?>
diff --git a/uusharjoittelupaikka.php b/uusharjoittelupaikka.php
new file mode 100644
index 0000000..d72f364
--- /dev/null
+++ b/uusharjoittelupaikka.php
+<!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>© Harjoittelupaikat 2025</p>
+ <a href="index.php">Takaisin alkuun</a>
+</footer>
+</body>
+</html>