From 09debbdc9d658a51ae72283c1d391380443a5896 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 11 Jun 2018 00:59:10 +0200 Subject: [PATCH] updated new entry handling --- index.php | 4 ++- js/contentloader.js | 8 +++-- js/entry.js | 0 segments/_entryForm.php | 51 +++++++++++++++++++++++++++-- sql/entiresTable.sql | 33 +++++++++++++++++++ sql/{userTableSQL => userTable.sql} | 0 6 files changed, 90 insertions(+), 6 deletions(-) delete mode 100644 js/entry.js create mode 100644 sql/entiresTable.sql rename sql/{userTableSQL => userTable.sql} (100%) diff --git a/index.php b/index.php index afeba51..5e13b41 100644 --- a/index.php +++ b/index.php @@ -16,16 +16,18 @@
- +
+ + diff --git a/js/contentloader.js b/js/contentloader.js index ddffced..25c259d 100644 --- a/js/contentloader.js +++ b/js/contentloader.js @@ -1,7 +1,8 @@ window.addEventListener('load', async () => { console.log("Seite geladen"); - getNewUniqueLink(); - document.getElementById('btnCreate').addEventListener('click' , async (event) => createEntry()); + //getNewUniqueLink(); + document.getElementById('btnCreateTan').addEventListener('click' , async (event) => getNewUniqueLink()); + document.getElementById('btnAbsenden').addEventListener('click' , async (event) => createEntry()); }) async function getNewUniqueLink() { @@ -18,7 +19,8 @@ async function getNewUniqueLink() { } async function createEntry() { event.preventDefault() - const formData = new formData(document.getElementById('create-form')); + console.log("Absenden gedrueckt!!!!"); + const formData = new formData(document.getElementById('entry-form')); try { const response = await fetch('php/login.php', { diff --git a/js/entry.js b/js/entry.js deleted file mode 100644 index e69de29..0000000 diff --git a/segments/_entryForm.php b/segments/_entryForm.php index 6f80bee..33436c8 100644 --- a/segments/_entryForm.php +++ b/segments/_entryForm.php @@ -1,9 +1,56 @@ +" . $_POST['tan'] . "<-"; + if($_POST['tan'] != ""){ + addEntry(); + consumeTan($_POST['tan']); + } + } + + function addEntry() { + + } + +function consumeTan($tan) { + require('../dbConnect.php'); //Erstellt variable mit dem namen $database + + //Stelle sicher dass die Tan noch verfügbar ist. + $abfrage = "SELECT `used`, `tan` FROM `tans` WHERE `tan` = '" . $tan . "'"; + $ergebnis = mysqli_query($database, $abfrage); + + if($ergebnis->num_rows == 0){ + echo "Tan nicht vergeben"; + return; + } + + $resultStr = ""; + + while ($row = $ergebnis->fetch_assoc()) { + $resultStr = $resultStr . $row["used"] . ' ' . $row["tan"] . '
'; + if($row["used"] == 1){ + echo "Tan schon verbraucht"; + return; + } + + } + + //echo $resultStr; + + //Setzte Tan auf verbraucht + $update = $database->query("UPDATE `tans` SET `used`= true WHERE `tan` = '" . $_POST['tan'] . "'"); + + echo "Tan verbraucht " . $_POST['tan']; +} + +?> +
-
+
@@ -174,7 +221,7 @@
diff --git a/sql/entiresTable.sql b/sql/entiresTable.sql new file mode 100644 index 0000000..aefa654 --- /dev/null +++ b/sql/entiresTable.sql @@ -0,0 +1,33 @@ +CREATE TABLE `kd42696_ipr-projekt`.`entries` ( + `entryID` INT NOT NULL AUTO_INCREMENT , + `userID` INT NOT NULL , + `tanID` INT NOT NULL , + `vorname` LONGTEXT NOT NULL , + `nachname` LONGTEXT NOT NULL , + `geburtstag` LONGTEXT NOT NULL , + `wohnort` LONGTEXT NOT NULL , + `strasse` LONGTEXT NOT NULL , + `kennenUns` LONGTEXT NOT NULL , + `festnetz` LONGTEXT NOT NULL , + `handynummer` LONGTEXT NOT NULL , + `email` LONGTEXT NOT NULL , + `hobbies` LONGTEXT NOT NULL , + `berufswunsch` LONGTEXT NOT NULL , + `essen` LONGTEXT NOT NULL , + `insel` LONGTEXT NOT NULL , + `film` LONGTEXT NOT NULL , + `sport` LONGTEXT NOT NULL , + `charakter` LONGTEXT NOT NULL , + `tier` LONGTEXT NOT NULL , + `musik` LONGTEXT NOT NULL , + `game` LONGTEXT NOT NULL , + `alk` LONGTEXT NOT NULL , + `story` LONGTEXT NOT NULL , + `absturz` LONGTEXT NOT NULL , + `trinkspiel` LONGTEXT NOT NULL , + PRIMARY KEY (`entryID`), + UNIQUE (`userID`), + UNIQUE (`tanID`)) ENGINE = InnoDB; + + ALTER TABLE `entries` ADD FOREIGN KEY (`userID`) REFERENCES `user`(`ID`) ON DELETE CASCADE ON UPDATE CASCADE; + ALTER TABLE `entries` ADD FOREIGN KEY (`tanID`) REFERENCES `tans`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/sql/userTableSQL b/sql/userTable.sql similarity index 100% rename from sql/userTableSQL rename to sql/userTable.sql