diff --git a/images/12w3oetrhz.jpeg b/images/12w3oetrhz.jpeg
new file mode 100644
index 0000000..4e76254
Binary files /dev/null and b/images/12w3oetrhz.jpeg differ
diff --git a/images/ah9cu4mwxb.png b/images/ah9cu4mwxb.png
new file mode 100644
index 0000000..56e12ff
Binary files /dev/null and b/images/ah9cu4mwxb.png differ
diff --git a/images/i6gyk018fu.jpeg b/images/i6gyk018fu.jpeg
new file mode 100644
index 0000000..218ece5
Binary files /dev/null and b/images/i6gyk018fu.jpeg differ
diff --git a/images/qur2xziw6p.png b/images/qur2xziw6p.png
new file mode 100644
index 0000000..56e12ff
Binary files /dev/null and b/images/qur2xziw6p.png differ
diff --git a/images/rb54a98ctd.png b/images/rb54a98ctd.png
new file mode 100644
index 0000000..56e12ff
Binary files /dev/null and b/images/rb54a98ctd.png differ
diff --git a/index.php b/index.php
index 77a002e..36bb68e 100644
--- a/index.php
+++ b/index.php
<main>
<?php foreach ($artikkelit as $artikkeli): ?>
<?php if ( !isset($sivu_cat) or $sivu_cat == $artikkeli["kategoria_id"] ): ?>
- <section>
- <a href="#">
+ <section id="<?php echo $artikkeli["otsikko"] ?>">
+ <a href="#<?php echo $artikkeli["otsikko"] ?>">
<div class="imgcontainer">
<img src="images/<?php echo $artikkeli["kuva"]; ?>">
</div>
diff --git a/logged_in.php b/logged_in.php
index f16d77f..90eecfe 100644
--- a/logged_in.php
+++ b/logged_in.php
$kayttaja = $result->fetch_assoc();
if (password_verify($_SESSION["pass"], $kayttaja["salasana"] )) {
$logged_in = true;
+ $_SESSION["id"] = $kayttaja["id"];
}
}
?>
diff --git a/theme-switch.js b/theme-switch.js
index 2cf6b5a..8a379f8 100644
--- a/theme-switch.js
+++ b/theme-switch.js
const grey = "#737373";
+if (localStorage.getItem("theme") === "true") {
+ $("body").toggleClass("dark-theme light-theme");
+ waitForElm('object').then((elm) => {
+ switchTheme(true);
+ });
+}
+
document.getElementById('themebtn').addEventListener('click', function() {
- // Svg element
- const rootSvg = $($("object")[0].contentDocument);
// Vaihda js class
$("body").toggleClass("dark-theme light-theme");
- var dark = document.body.className == "dark-theme";
+ switchTheme(document.body.className == "dark-theme");
+});
+
+function switchTheme(dark = true) {
+ // Svg element
+ const rootSvg = $($("object")[0].contentDocument);
// Muuta logon värejä
if (dark) {
- dark = false;
+ // Dark
rootSvg.find("#path4000").attr("style", "fill:" + "white" );
rootSvg.find("#path4004").attr("style", "fill:" + grey );
rootSvg.find("#path4006").attr("style", "fill:" + grey );
rootSvg.find("#path4008").attr("style", "fill:" + grey );
rootSvg.find("#text1").attr("style", "fill:" + grey );
+ localStorage.setItem("theme", true);
} else {
- dark = true;
+ // Light
rootSvg.find("#path4000").attr("style", "fill:" + grey );
rootSvg.find("#path4004").attr("style", "fill:" + "white" );
rootSvg.find("#path4006").attr("style", "fill:" + "white" );
rootSvg.find("#path4008").attr("style", "fill:" + "white" );
rootSvg.find("#text1").attr("style", "fill:" + "white" );
+ localStorage.setItem("theme", false);
}
-});
+}
+
+// Source - https://stackoverflow.com/a
+// Posted by Yong Wang, modified by community. See post 'Timeline' for change history
+// Retrieved 2025-11-18, License - CC BY-SA 4.0
+
+function waitForElm(selector) {
+ return new Promise(resolve => {
+ if (document.querySelector(selector).contentDocument) {
+ return resolve(document.querySelector(selector).contentDocument);
+ }
+
+ const observer = new MutationObserver(mutations => {
+ if (document.querySelector(selector).contentDocument) {
+ observer.disconnect();
+ resolve(document.querySelector(selector).contentDocument);
+ }
+ });
+
+ // If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
+ observer.observe(document.body, {
+ childList: true,
+ subtree: true
+ });
+ });
+}
diff --git a/write.php b/write.php
index 6e5b3b0..e42844e 100644
--- a/write.php
+++ b/write.php
<?php
-
-
-
+include "connect.php";
+include "logged_in.php";
+// Hanki kategoriat
+$sql = "SELECT * FROM kategoriat";
+$result = $conn->query($sql); // Aja komento
+// Jos tuloksia
+$kategoriat = [];
+if ($result->num_rows>0){
+ while($row = $result->fetch_assoc()){
+ $kategoriat[] = $row;
+ }
+}
+// Upload
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $user_id = $_SESSION["id"];
+ $otsikko = $_POST["title"];
+ $teksti = $_POST["text"];
+ $kat = $_POST["cat"];
+ // Random nimi tiedostolle jotta ei tule kollisioita
+ $permittedchars = 'abcdefghijklmnopqrstuvwxyz1234567890';
+ $random = substr(str_shuffle($permittedchars), 0, 10);
+ // Ota tärkeät tiedot tiedostosta
+ $filename = $_FILES['file']["name"];
+ $tmp = $_FILES['file']["tmp_name"];
+ $size = $_FILES['file']["size"];
+ $error = $_FILES['file']["error"];
+ $filetype = $_FILES['file']["type"];
+ // Tarskista tyyppi
+ $allowed = array('jpg', 'png', 'tiff', 'jpeg', 'webp');
+ $ext = end(explode("/", $filetype));
+ if (in_array($ext, $allowed) and $error === 0 and $size < 5000000000) {
+ echo "Tiedosto meni läpi...";
+ $filenameNew = $random . "." . $ext;
+ $upload = "./images/" . $filenameNew;
+ move_uploaded_file($tmp, $upload);
+ echo "Success!";
+ $sql = "INSERT INTO `uutiset` (`id`, `otsikko`, `teksti`, `kuva`, `kategoria_id`, `toimittaja_id`) VALUES (NULL, '$otsikko', '$teksti', '$filenameNew', '$kat', '$user_id'); ";
+ $result = $conn->query($sql); // Aja komento
+ // Redirect
+ header("Location: .#$otsikko");
+ die();
+ }
+}
?>
-<form>
- <label for="text">Teksti</label>
- <input type="text" id="text" name="text">
+<form action="" method="POST" enctype="multipart/form-data">
+ <label for="title">Otsikko</label> <br>
+ <input type="text" id="title" name="title">
+ <br>
+ <label for="text">Teksti</label> <br>
+ <textarea id="text" name="text" rows="5" cols="60"></textarea>
+ <br>
+ <label for="file">Kuva</label> <br>
+ <input type="file" id="file" name="file">
+ <br>
+ <label for="cat">Kategoria</label> <br>
+ <select id="cat" name="cat">
+ <?php foreach ($kategoriat as $kategoria): ?>
+ <option value="<?php echo $kategoria["id"] ?>"><?php echo $kategoria["nimi"] ?></option>
+ <?php endforeach; ?>
+ </select>
+ <br>
+ <button type="submit">Lähetä</button>
</form>