commit 9a5eae5ce1a08f4a304b25b05fee86e236364cc2 Author: MatMasIt Date: Mon Nov 1 22:58:00 2021 +0100 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..1bf70e1 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# adamoCellar diff --git a/api.php b/api.php new file mode 100644 index 0000000..b478f3b --- /dev/null +++ b/api.php @@ -0,0 +1,103 @@ +prepare($sql); + $p->execute($data); + $res = []; + $res["rows"] = $p->fetchAll(PDO::FETCH_ASSOC); + $sql = "SELECT COUNT(*) AS c FROM Bottiglie WHERE $addition"; + $p = $pdo->prepare($sql); + $p->execute($data); + $res["pagTot"] = (int)($p->fetch(PDO::FETCH_ASSOC)["c"] / $_GET["pageSize"]) + 1; + echo json_encode($res); + break; + case "get": + $p = $pdo->prepare("SELECT * FROM Bottiglie WHERE id=:id"); + $p->execute([":id" => $_GET["id"]]); + echo json_encode($p->fetch(PDO::FETCH_ASSOC)); + break; + case "delete": + $p = $pdo->prepare("DELETE FROM Bottiglie WHERE id=:id"); + $p->execute([":id" => $_GET["id"]]); + echo json_encode(["ok" => true]); + break; + case "update": + $p = $pdo->prepare("UPDATE Bottiglie SET vino=:vino, cantina=:cantina, annata=:annata, volume=:volume, quantita=:quantita, note=:note, lastEdit=:lastEdit WHERE id=:id"); + $e = $p->execute([ + ":id" => $_GET["id"], + ":vino" => $_GET["vino"], + ":cantina" => $_GET["cantina"], + ":annata" => $_GET["annata"], + ":volume" => $_GET["volume"], + ":quantita" => $_GET["quantita"], + ":note" => $_GET["note"], + ":lastEdit" => time() + ]); + echo json_encode(["ok" => $e]); + break; + case "add": + $p = $pdo->prepare("INSERT INTO Bottiglie(vino, cantina, annata, volume, quantita, note, createdAt, lastEdit) VALUES(:vino, :cantina, :annata, :volume, :quantita, :note, :createdAt, :lastEdit)"); + $e = $p->execute([ + ":vino" => $_GET["vino"], + ":cantina" => $_GET["cantina"], + ":annata" => $_GET["annata"], + ":volume" => $_GET["volume"], + ":quantita" => $_GET["quantita"], + ":note" => $_GET["note"], + ":createdAt" => time(), + ":lastEdit" => time() + ]); + echo json_encode(["ok" => $e]); + break; + case "complete": + $type = $_GET["type"]; + if (!in_array($type, ["vino", "cantina", "annata", "volume", "quantita", "note"])) { + echo json_encode([]); + break; + } + $p = $pdo->prepare("SELECT DISTINCT $type FROM Bottiglie"); + $p->execute(); + $list = []; + foreach ($p->fetchAll(PDO::FETCH_ASSOC) as $e) { + $list[] = $e[$type]; + } + $userInput = $_GET["query"]; + usort($list, function ($a, $b) use ($userInput) { + similar_text($userInput, $a, $percentA); + similar_text($userInput, $b, $percentB); + + return $percentA === $percentB ? 0 : ($percentA > $percentB ? -1 : 1); + }); + echo json_encode(array_slice($list, 0, 20)); + break; + case "access": + echo json_encode(["ok" => password_verify($_GET["password"], file_get_contents("password.txt"))]); + break; + case "updatePassword": + file_put_contents("password.txt", password_hash($_GET["password"], PASSWORD_DEFAULT)); + echo json_encode([]); + break; +} diff --git a/database.db b/database.db new file mode 100644 index 0000000..939af61 Binary files /dev/null and b/database.db differ diff --git a/img/CantinaBotti.jpg b/img/CantinaBotti.jpg new file mode 100644 index 0000000..777d9bf Binary files /dev/null and b/img/CantinaBotti.jpg differ diff --git a/img/bin.png b/img/bin.png new file mode 100644 index 0000000..38557a7 Binary files /dev/null and b/img/bin.png differ diff --git a/img/edit.png b/img/edit.png new file mode 100644 index 0000000..caab42f Binary files /dev/null and b/img/edit.png differ diff --git a/img/favicon.ico b/img/favicon.ico new file mode 100644 index 0000000..7a25b11 Binary files /dev/null and b/img/favicon.ico differ diff --git a/img/icon.png b/img/icon.png new file mode 100644 index 0000000..81ad821 Binary files /dev/null and b/img/icon.png differ diff --git a/img/plus.png b/img/plus.png new file mode 100644 index 0000000..ac620e0 Binary files /dev/null and b/img/plus.png differ diff --git a/img/view.png b/img/view.png new file mode 100644 index 0000000..2810628 Binary files /dev/null and b/img/view.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..1ed732c --- /dev/null +++ b/index.html @@ -0,0 +1,311 @@ + + + + + + + + + + + + + + Cantina + + + +
+
+ +

Cantina Adamo

+
+
+ + + +
+
+ + + Ricerca +
+ + +
+
+ Vino +
+ +
+
+
+ Cantina +
+ +
+
+
+ Annata +
+ +
+
+
+ Volume +
+ +
+ L +
+
+
+
+ Quantità +
+ +
+
+
+ Note +
+ +
+
+ + +
+
+
+ Ordina per + + +
+
+
+ + + + + + + + + + +
+
+
+
+ + + + + + + + + + + + + + + +
#VinoCantinaAnnataVolumeQuantitàNote
+

Pagina a di b

+ + +
+
+
+ + + Aggiungi Bottiglia +
+ + +
+
+ Vino +
+ +
+
+
+ Cantina +
+ +
+
+
+ Annata +
+ +
+
+
+ Volume +
+ +
+ L +
+
+
+
+ Quantità +
+ +
+
+
+ Note +
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#
Vino
Cantina
Annata
Volume
Quantità
Note
+ + + + +
+ +
+
+ + + Accesso +
+ + +
+
+ Password +
+ +
+
+ +
+
+ + +
+
+ + + Nuova password +
+ + +
+
+ Password +
+ +
+
+ + +
+
+
+ +
+ +

© 2021 Mattia Mascarello, Giorgio Adamo


+
+ + + + + + + + + \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..ec68936 --- /dev/null +++ b/main.js @@ -0,0 +1,240 @@ +function htmlEntities(str) { + return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); +} +$(".addP").click(function addItem() { + $("[name=vino]").val(""); + $("[name=cantina]").val(""); + $("[name=annata]").val(""); + $("[name=volume]").val(""); + $("[name=quantita]").val(""); + $("[name=note]").val(""); + $("#tableview").hide(); + $("#saveedit").show(); + formAction = "new"; +}); +$(".closeForm").click(function addItem() { + $("#tableview").show(); + $("#saveedit").hide(); + $("#view").hide(); + $("#chpass").hide(); + $("#find").hide(); +}); +$("#saveedit").hide(); +var pageSize = 20, lastPage = 0, formAction = "new", lastId = 0; +function updateTable(pageNum) { + lastPage = pageNum; + $.getJSON("api.php?intent=list&pageSize=" + pageSize + "&pageNum=" + pageNum + ("&" + $("#find").serialize()).replaceAll("&S", "&") + "&orderBy=" + $("[name=orderBy]").val() + "&orderHow=" + $("[name=orderHow]").val(), function (data) { + $("#pageIndicator").text("Pagina " + (parseInt(pageNum) + 1) + " di " + data["pagTot"]); + $("#tabnav").html(""); + for (let i = 0; i < data["pagTot"]; i++) { + var act = ""; + if (i == pageNum) act = "active"; + $("#tabnav").append('
  • ' + (i + 1) + '
  • ') + } + $("#tabbody").html(""); + data["rows"].forEach(function iterate(value) { + $("#tabbody").append(` + `+ htmlEntities(value["id"]) + ` + `+ htmlEntities(value["vino"]) + ` + `+ htmlEntities(value["cantina"]) + ` + `+ htmlEntities(value["annata"]) + ` + `+ htmlEntities(value["volume"]) + ` ℓ + `+ htmlEntities(value["quantita"]) + ` + `+ htmlEntities(value["note"]) + ` + + + + +     + + + +     + + + + + `); + }); + }); +} +updateTable(0); +$(document).delegate(".page-link", "click", function pageChange() { + updateTable($(this).attr("data-pageNum")); +}); +$(document).delegate("[data-action=delete]", "click", function delElEvent() { + if (confirm("Eliminare? (questa azione è irreversibile)")) { + $.getJSON("api.php?intent=delete&id=" + $(this).attr("data-id"), function delSend() { + updateTable(lastPage); + $("#tableview").show(); + $("#saveedit").hide(); + $("#view").hide(); + }); + } +}); +$(document).delegate("[data-action=edit]", "click", function editElEvent() { + lastId = $(this).attr("data-id"); + $.getJSON("api.php?intent=get&id=" + $(this).attr("data-id"), function editEvent(data) { + formAction = "edit"; + $("[name=vino]").val(data["vino"]); + $("[name=cantina]").val(data["cantina"]); + $("[name=annata]").val(data["annata"]); + $("[name=volume]").val(data["volume"]); + $("[name=quantita]").val(data["quantita"]); + $("[name=note]").val(data["note"]); + $("#tableview").hide(); + $("#saveedit").show(); + }); +}) +$(document).delegate("[data-action=view]", "click", function editElEvent() { + var idTemp = $(this).attr("data-id"); + $.getJSON("api.php?intent=get&id=" + idTemp, function editEvent(data) { + $("#Vid").html(idTemp); + $("#Vvino").html(data["vino"]); + $("#Vcantina").html(data["cantina"]); + $("#Vannata").html(data["annata"]); + $("#Vvolume").html(data["volume"] + " ℓ"); + $("#Vquantita").html(data["quantita"]); + $("#Vnote").html(data["note"]); + $("#Vdelete").attr("data-id", idTemp); + $("#view").show(); + $("#tableview").hide(); + }); +}) +$("#saveedit").submit(function (e) { + e.preventDefault(); + switch (formAction) { + case "edit": + $.getJSON("api.php?intent=update&id=" + lastId + "&" + $(this).serialize(), function editEvent(data) { + $("#tableview").show(); + $("#saveedit").hide(); + updateTable(lastPage); + }); + break; + + case "new": + $.getJSON("api.php?intent=add&" + $(this).serialize(), function editEvent(data) { + $("#tableview").show(); + $("#saveedit").hide(); + updateTable(lastPage); + }); + break; + } + return false; +}); +$('[name=vino]').autoComplete({ + resolver: 'custom', + events: { + search: function (qry, callback) { + // let's do a custom ajax call + $.ajax( + 'api.php', + { + data: { "intent": "complete", 'query': qry, "type": "vino" } + } + ).done(function (res) { + callback(res) + }); + } + } +}); +$('[name=cantina]').autoComplete({ + resolver: 'custom', + events: { + search: function (qry, callback) { + // let's do a custom ajax call + $.ajax( + 'api.php', + { + data: { "intent": "complete", 'query': qry, "type": "cantina" } + } + ).done(function (res) { + callback(res) + }); + } + } +}); +$('[name=annata]').autoComplete({ + resolver: 'custom', + events: { + search: function (qry, callback) { + // let's do a custom ajax call + $.ajax( + 'api.php', + { + data: { "intent": "complete", 'query': qry, "type": "annata" } + } + ).done(function (res) { + callback(res) + }); + } + } +}); +$('[name=note]').autoComplete({ + resolver: 'custom', + events: { + search: function (qry, callback) { + // let's do a custom ajax call + $.ajax( + 'api.php', + { + data: { "intent": "complete", 'query': qry, "type": "note" } + } + ).done(function (res) { + callback(res) + }); + } + } +}); +$("#passwAccess").submit(function access(e) { + e.preventDefault(); + $.getJSON("api.php?intent=access&password=" + $("[name=password]").val(), function editEvent(data) { + if (data["ok"]) { + $("#passwAccess").hide(); + $("#tableview").show(); + $(".loggedInMenu").show(); + } + else { + alert("Credenziali errate"); + } + }); + return false; +}); +$("#chpass").submit(function access(e) { + e.preventDefault(); + $.getJSON("api.php?intent=updatePassword&password=" + $("[name=Upassword]").val(), function editEvent(data) { + $("#chpass").hide(); + $("#tableview").show(); + }); + return false; +}); +$(".logout").click(function () { + location.reload(); +}) +$(".chpassBtn").click(function () { + $("#find").hide(); + $("#tableview").hide(); + $("#chpass").show(); +}); +$(".search").click(function () { + $("#find").show(); + $("#tableview").show(); + $("#chpass").hide(); +}); +$("#find").submit(function access(e) { + e.preventDefault(); + updateTable(lastPage); + return false; +}); +$(".resetR").click(function () { + $("#find")[0].reset(); + $("#tableview").show(); + $("#saveedit").hide(); + $("#view").hide(); + $("#chpass").hide(); + $("#find").hide(); + updateTable(lastPage); +}); +$('[name=orderBy],[name=orderHow]').on('change', function () { + updateTable(lastPage); +}); \ No newline at end of file diff --git a/password.txt b/password.txt new file mode 100644 index 0000000..1f201dd --- /dev/null +++ b/password.txt @@ -0,0 +1 @@ +$2y$10$/f913leBtTSRuwfmCy2jiuw1C5QOZReY5i.spuNNrrfLPKx39KhOW \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..bf7b2bf --- /dev/null +++ b/run.sh @@ -0,0 +1,5 @@ +php -S 127.0.0.1:8080 & +SERVER_PID=$! +firefox --kiosk http://127.0.0.1:8080 +kill $SERVER_PID +pkill firefox \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..2749a00 --- /dev/null +++ b/style.css @@ -0,0 +1,49 @@ +body { + background: url("img/CantinaBotti.jpg"); + min-height: 500px; + /* Create the parallax scrolling effect */ + background-attachment: fixed; + background-position: center; + background-repeat: no-repeat; + background-size: cover; + color: white; +} + +table, tr, td, th { + color: white; + background-color: black; + opacity: 0.88; +} + +.actionIcon { + filter: invert(1); + width: 20px; +} + +.actionsCell { + text-align: center; +} + +* { + scrollbar-width: none; +} + +#view { + display: none; +} + +#tableview { + display: none; +} + +.loggedInMenu { + display: none; +} + +#chpass { + display: none; +} + +#find { + display: none; +} \ No newline at end of file