diff --git a/admin.php b/admin.php
new file mode 100644
index 0000000..61c3e68
--- /dev/null
+++ b/admin.php
+<?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
+<?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 8e629d2..62befe9 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){
- 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
+<?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>
<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
<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
<?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/logic.register.php b/logic.register.php
new file mode 100644
index 0000000..adcd76d
--- /dev/null
+++ b/logic.register.php
+<?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
-<?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
<?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
<?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
+<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>© 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
}
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
+<!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>