diff --git a/phpCourse.code-workspace b/phpCourse.code-workspace index 362d7c2..9cb4822 100644 --- a/phpCourse.code-workspace +++ b/phpCourse.code-workspace @@ -3,5 +3,10 @@ { "path": "." } - ] + ], + "settings": { + "cSpell.words": [ + "benutzer" + ] + } } \ No newline at end of file diff --git a/tasks/functions/index.php b/tasks/functions/index.php index 46f36da..ee6ce46 100644 --- a/tasks/functions/index.php +++ b/tasks/functions/index.php @@ -3,7 +3,7 @@ - Counter + Functions diff --git a/tasks/functions2/index.php b/tasks/functions2/index.php new file mode 100644 index 0000000..c515077 --- /dev/null +++ b/tasks/functions2/index.php @@ -0,0 +1,96 @@ + + + + + + Functions 2 + + + + prepare($query); + $stmt->bindValue(":LAND", $land); + $stmt->execute(); + return $stmt->fetch(PDO::FETCH_COLUMN); + } + + function getArtikelname($artikelnr, $db) + { + $query = "SELECT Artikelname FROM Artikel WHERE ArtikelNr = :NR"; + $stmt = $db->prepare($query); + $stmt->bindValue(":NR", $artikelnr); + $stmt->execute(); + return $stmt->fetch(PDO::FETCH_COLUMN); + } + + function getArtikelAnzahl($firma, $db) + { + $query = "SELECT COUNT(*) FROM Artikel AS A, Lieferanten AS L WHERE A.LieferantenNr = L.LieferantenNr AND L.Firma = :FIRMA"; + $stmt = $db->prepare($query); + $stmt->bindValue(":FIRMA", $firma); + $stmt->execute(); + return $stmt->fetch(PDO::FETCH_COLUMN); + } + + function updPercArticle($firma, $perc, $db) + { + $query = " + UPDATE + Artikel AS A, Lieferanten AS L + SET + A.Einzelpreis = A.Einzelpreis * :PERC + WHERE + A.LieferantenNr = L.LieferantenNr AND + L.Firma = :FIRMA"; + $stmt = $db->prepare($query); + $stmt->bindValue(":FIRMA", $firma); + $stmt->bindValue(":PERC", 1 + $perc / 100); + $stmt->execute(); + } + + $anz_de = getFirmenAnzahl("Deutschland", $db); + $anz_fr = getFirmenAnzahl("Frankreich", $db); + $name = getArtikelname(1, $db); + $anz_exotic = getArtikelAnzahl("Exotic Liquids", $db); + + echo "

Es sind $anz_de Firmen in Deutschland ansässig.

"; + echo "

Es sind $anz_fr Firmen in Frankreich ansässig.

"; + + echo "

$name hat Art.Nr. 1

"; + + echo "

Exotic Liquids liefert $anz_exotic Artikel

"; + + echo "

Before price hike

"; + $query = "SELECT A.Einzelpreis FROM Artikel AS A, Lieferanten AS L WHERE A.LieferantenNr = L.LieferantenNr AND L.Firma = 'Tokyo Traders'"; + $stmt = $db->prepare($query); + $stmt->execute(); + echo "
";
+  var_dump($stmt->fetchAll());
+  echo "
"; + + updPercArticle("Tokyo Traders", 10, $db); + + echo "

After price hike

"; + $query = "SELECT A.Einzelpreis FROM Artikel AS A, Lieferanten AS L WHERE A.LieferantenNr = L.LieferantenNr AND L.Firma = 'Tokyo Traders'"; + $stmt = $db->prepare($query); + $stmt->execute(); + echo "
";
+  var_dump($stmt->fetchAll());
+  echo "
"; + + DB::closeConnection($db); + ?> + + + \ No newline at end of file diff --git a/tasks/guestBookDB/actions/comment.php b/tasks/guestBookDB/actions/comment.php new file mode 100644 index 0000000..d91f03f --- /dev/null +++ b/tasks/guestBookDB/actions/comment.php @@ -0,0 +1,45 @@ + 0) { + Headers::redirect("."); + return; +} + +$string = file_get_contents("../data/data.json") ?? "[]"; +$json = json_decode($string); + +array_push($json, ["time" => $time, "title" => $title, "name" => $name, "comment" => $comment]); + +file_put_contents("../data/data.json", json_encode($json)); + +Headers::redirect("../"); diff --git a/tasks/guestBookDB/components/.htaccess b/tasks/guestBookDB/components/.htaccess new file mode 100644 index 0000000..872a3ce --- /dev/null +++ b/tasks/guestBookDB/components/.htaccess @@ -0,0 +1,3 @@ +Order deny,allow +Deny from all +Allow from 127.0.0.1 \ No newline at end of file diff --git a/tasks/guestBookDB/components/comment.php b/tasks/guestBookDB/components/comment.php new file mode 100644 index 0000000..bb0c52a --- /dev/null +++ b/tasks/guestBookDB/components/comment.php @@ -0,0 +1,15 @@ +
+
+
+
+
+
+

+
+ +
+
\ No newline at end of file diff --git a/tasks/guestBookDB/components/error.php b/tasks/guestBookDB/components/error.php new file mode 100644 index 0000000..30a6855 --- /dev/null +++ b/tasks/guestBookDB/components/error.php @@ -0,0 +1,7 @@ +
+ + + + + +
\ No newline at end of file diff --git a/tasks/guestBookDB/components/newComment.php b/tasks/guestBookDB/components/newComment.php new file mode 100644 index 0000000..18d3869 --- /dev/null +++ b/tasks/guestBookDB/components/newComment.php @@ -0,0 +1,30 @@ +
+

Under Construction

+
+
+

Leave a Comment!

+
+ +
+ Please enter a title. +
+
+
+ +
+ Please enter a name. +
+
+
+ +
+ Please enter text. +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/tasks/guestBookDB/components/pagination.php b/tasks/guestBookDB/components/pagination.php new file mode 100644 index 0000000..ae47de8 --- /dev/null +++ b/tasks/guestBookDB/components/pagination.php @@ -0,0 +1,19 @@ + \ No newline at end of file diff --git a/tasks/guestBookDB/css/styles.css b/tasks/guestBookDB/css/styles.css new file mode 100644 index 0000000..e24f190 --- /dev/null +++ b/tasks/guestBookDB/css/styles.css @@ -0,0 +1,18 @@ +.opacity-50 { + opacity: 50% +} + +.construction { + z-index: 10; + rotate: -10deg; + width: fit-content; + height: fit-content; + left: 0; + right: 0; + margin-left: auto; + margin-right: auto; + top: 0; + bottom: 0; + margin-top: auto; + margin-bottom: auto; +} \ No newline at end of file diff --git a/tasks/guestBookDB/index.php b/tasks/guestBookDB/index.php new file mode 100644 index 0000000..a841dc7 --- /dev/null +++ b/tasks/guestBookDB/index.php @@ -0,0 +1,85 @@ + + + + + + + Guest Book DB + + + + + + + + + prepare($countQuery); + $stmt->execute(); + $maxPage = intdiv($stmt->fetch(PDO::FETCH_COLUMN), 9); + if ($page > $maxPage) { + Headers::redirect("./?p=$maxPage"); + return; + } + + $stmt = $db->prepare($dataQuery . $page * 9); + $stmt->execute(); + $data = $stmt->fetchAll(); + + DB::closeConnection($db); + ?> + +
+ + +
+
+ +
+
+ +
+ +
+ + + +
+ +
+ + + \ No newline at end of file diff --git a/tasks/guestBookDB/js/formValidation.js b/tasks/guestBookDB/js/formValidation.js new file mode 100644 index 0000000..95c9195 --- /dev/null +++ b/tasks/guestBookDB/js/formValidation.js @@ -0,0 +1,22 @@ +"use strict"; + +document.addEventListener("DOMContentLoaded", () => { + const handler = (event) => { + if (!event.target.checkValidity()) { + event.preventDefault(); + event.stopPropagation(); + } + + event.target.classList.add("was-validated"); + }; + + const addValidation = () => { + const forms = document.querySelectorAll(".needs-validation"); + + Array.from(forms).forEach((form) => { + form.addEventListener("submit", handler, false); + }); + }; + + addValidation(); +}); diff --git a/tasks/guestBookDB/js/textarea.js b/tasks/guestBookDB/js/textarea.js new file mode 100644 index 0000000..36b59ce --- /dev/null +++ b/tasks/guestBookDB/js/textarea.js @@ -0,0 +1,35 @@ +"use strict"; + +document.addEventListener("DOMContentLoaded", () => { + const handlerCounter = (event) => { + const comment = event.target; + const length = comment.value.length; + const maxLength = comment.maxLength; + const counter = document.getElementById("comment-count"); + + if (length >= 50) { + counter.innerText = `${length}/${maxLength}`; + } else { + counter.innerText = ""; + } + counter.style.width = `${(length / maxLength) * 100}%`; + + if (length === maxLength) { + counter.classList.remove("bg-warning"); + counter.classList.add("bg-danger"); + } else if (length > maxLength - 50) { + counter.classList.remove("bg-danger"); + counter.classList.add("bg-warning"); + } else { + counter.classList.remove("bg-warning"); + counter.classList.remove("bg-danger"); + } + }; + + const addValidation = () => { + const comment = document.getElementById("comment"); + comment.addEventListener("input", handlerCounter); + }; + + addValidation(); +}); diff --git a/tasks/guestBookDB/queries.php b/tasks/guestBookDB/queries.php new file mode 100644 index 0000000..6216b6e --- /dev/null +++ b/tasks/guestBookDB/queries.php @@ -0,0 +1,21 @@ +