From 47934a70be26a467aa0857bb6e45cbe764770878 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 11 Jun 2018 00:24:37 +0200 Subject: [PATCH 1/3] reordered Project --- index.php | 353 +------------------------------ js/contentloader.js | 2 +- readme.md | 3 - segments/_entryForm.php | 183 ++++++++++++++++ segments/_header.html | 114 ++++++++++ segments/_indexTestLoginVals.php | 10 + sql/userTableSQL | 4 +- 7 files changed, 313 insertions(+), 356 deletions(-) create mode 100644 segments/_entryForm.php create mode 100644 segments/_indexTestLoginVals.php diff --git a/index.php b/index.php index 99dd1f4..afeba51 100644 --- a/index.php +++ b/index.php @@ -14,362 +14,15 @@ - - - - - -
-
- LoginModalData: - Welcome
- Your Password is:
-
- RegisterModalData: - Welcome
- Your Password is:
- Your Mail Adress is:
-
- - -
-
-
- 1 of 3 -
- -
-
- -
-
- Vorname* -
- -
- -
-
- Nachname* -
- -
- -
-
- Geburtstag -
- -
- -
-
- Wohnort -
- -
- -
-
- Straße -
- -
- -
-
- Woher kennen wir uns?* -
- -
- -
-
- Festnetz -
- -
- -
-
- Handynummer -
- -
- -
-
- E-Mail* -
- -
- -
-
- Hobbys -
- -
- -
-
- Berufswunsch -
- -
- -
-
- Das könnte ich jeden Tag essen -
- -
- -
-
- Was ich auf eine Insel mitnehmen würde -
- -
- -
-
- Lieblingsfilm -
- -
- -
-
- Lieblingssport -
- -
- -
-
- Coolster Film oder Spielecharaker -
- -
- -
-
- Mein Lieblingstier -
- -
- -
-
- Lieblingsmusik(Genre, Interpret, Titel) -
- -
- -
-
- Geilstes Game -
- -
- -
-
- Lieblings alkoholisches Getränk -
- -
- -
-
- Meine heftigste Suffstory -
- -
- -
-
- Letzer Absturz -
- -
- -
-
- Lieblings Trinkspiel -
- -
- -
-
- friendsTAN* -
- -
- - - -
-
- - -
- 3 of 3 -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + diff --git a/js/contentloader.js b/js/contentloader.js index a6ce3fb..ddffced 100644 --- a/js/contentloader.js +++ b/js/contentloader.js @@ -1,7 +1,7 @@ window.addEventListener('load', async () => { console.log("Seite geladen"); getNewUniqueLink(); - document.getElementById('create').addEventListener('click' , async (event) => createEntry()); + document.getElementById('btnCreate').addEventListener('click' , async (event) => createEntry()); }) async function getNewUniqueLink() { diff --git a/readme.md b/readme.md index f42fbb4..23068f1 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,3 @@ Link to Project: https://icaotix.github.io/ipr-projekt/ - -Info: index.php -form with php_post in line 61 and 97, feel free to change the destination path. diff --git a/segments/_entryForm.php b/segments/_entryForm.php new file mode 100644 index 0000000..6f80bee --- /dev/null +++ b/segments/_entryForm.php @@ -0,0 +1,183 @@ + +
+
+ +
+
+ +
+
+ Vorname* +
+ +
+ +
+
+ Nachname* +
+ +
+ +
+
+ Geburtstag +
+ +
+ +
+
+ Wohnort +
+ +
+ +
+
+ Straße +
+ +
+ +
+
+ Woher kennen wir uns?* +
+ +
+ +
+
+ Festnetz +
+ +
+ +
+
+ Handynummer +
+ +
+ +
+
+ E-Mail* +
+ +
+ +
+
+ Hobbies +
+ +
+ +
+
+ Berufswunsch +
+ +
+ +
+
+ Das könnte ich jeden Tag essen +
+ +
+ +
+
+ Was ich auf eine Insel mitnehmen würde +
+ +
+ +
+
+ Lieblingsfilm +
+ +
+ +
+
+ Lieblingssport +
+ +
+ +
+
+ Coolster Film oder Spielecharaker +
+ +
+ +
+
+ Mein Lieblingstier +
+ +
+ +
+
+ Lieblingsmusik(Genre, Interpret, Titel) +
+ +
+ +
+
+ Geilstes Game +
+ +
+ +
+
+ Lieblings alkoholisches Getränk +
+ +
+ +
+
+ Meine heftigste Suffstory +
+ +
+ +
+
+ Letzer Absturz +
+ +
+ +
+
+ Lieblings Trinkspiel +
+ +
+ +
+
+ Eintrags-TAN* +
+ +
+ + + +
+
+
+
diff --git a/segments/_header.html b/segments/_header.html index 46d3cb9..f10e2d1 100644 --- a/segments/_header.html +++ b/segments/_header.html @@ -13,3 +13,117 @@ + + + + + + + diff --git a/segments/_indexTestLoginVals.php b/segments/_indexTestLoginVals.php new file mode 100644 index 0000000..fb9e96d --- /dev/null +++ b/segments/_indexTestLoginVals.php @@ -0,0 +1,10 @@ +
+ LoginModalData: + Welcome
+ Your Password is:
+
+ RegisterModalData: + Welcome
+ Your Password is:
+ Your Mail Adress is:
+
diff --git a/sql/userTableSQL b/sql/userTableSQL index d232441..b015f21 100644 --- a/sql/userTableSQL +++ b/sql/userTableSQL @@ -3,6 +3,6 @@ CREATE TABLE `user` ( `user` VARCHAR(50) NOT NULL DEFAULT '0', `email` VARCHAR(100) NOT NULL DEFAULT '0', `password` VARCHAR(100) NOT NULL DEFAULT '0', - PRIMARY KEY (`ID`) + PRIMARY KEY (`ID`), UNIQUE INDEX `user` (`user`) -) +); From 09debbdc9d658a51ae72283c1d391380443a5896 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 11 Jun 2018 00:59:10 +0200 Subject: [PATCH 2/3] 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 From 268a8ea290224c0d4de615683d4c8529df7d5252 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 11 Jun 2018 02:00:39 +0200 Subject: [PATCH 3/3] switched tan from unique id to index --- index.php | 3 ++- js/contentloader.js | 17 ----------------- php/generateLink.php | 23 ++++++++++++++++++++--- segments/_entryForm.php | 35 +++++++++++++++-------------------- sql/entiresTable.sql | 4 ++-- 5 files changed, 39 insertions(+), 43 deletions(-) diff --git a/index.php b/index.php index 5e13b41..ea405c7 100644 --- a/index.php +++ b/index.php @@ -13,6 +13,7 @@ +
@@ -22,7 +23,7 @@ - + diff --git a/js/contentloader.js b/js/contentloader.js index 25c259d..c541829 100644 --- a/js/contentloader.js +++ b/js/contentloader.js @@ -2,7 +2,6 @@ window.addEventListener('load', async () => { console.log("Seite geladen"); //getNewUniqueLink(); document.getElementById('btnCreateTan').addEventListener('click' , async (event) => getNewUniqueLink()); - document.getElementById('btnAbsenden').addEventListener('click' , async (event) => createEntry()); }) async function getNewUniqueLink() { @@ -17,19 +16,3 @@ async function getNewUniqueLink() { } } -async function createEntry() { - event.preventDefault() - console.log("Absenden gedrueckt!!!!"); - const formData = new formData(document.getElementById('entry-form')); - - try { - const response = await fetch('php/login.php', { - method: 'post', - body: formData - }); - const jsonData = await response.json(); - - } catch (e) { - console.log("Fehler"); - } -} diff --git a/php/generateLink.php b/php/generateLink.php index 2bfb25d..a3d60a1 100644 --- a/php/generateLink.php +++ b/php/generateLink.php @@ -8,22 +8,39 @@ insertTan($uniqueID); + $resultStr = getTanID($uniqueID); + $HTMLJSON = array('html' => $resultStr); echo json_encode($HTMLJSON); function insertTan($tan) { require('../dbConnect.php'); //Erstellt variable mit dem namen $database - $stmt = $database->prepare("INSERT INTO tans (tan, used) VALUES (?, ?)"); + $stmt = $database->prepare("INSERT INTO tans (tan, userID, used) VALUES (?, ?, ?)"); - $false = false; - $stmt->bind_param("si", $tan, $false); + $used = false; + $userid = 1; + $stmt->bind_param("ssi", $tan, $userid, $used); try { $stmt->execute(); + $database->close(); } catch (PDOException $e) { $e->getMessage(); } } + function getTanID($tan){ + require('../dbConnect.php'); //Erstellt variable mit dem namen $database + $abfrage = "SELECT `id` FROM `tans` WHERE `tan` = '" . $tan . "'"; + + $ergebnis = mysqli_query($database, $abfrage); + + $row = $ergebnis->fetch_object(); + $resultStr = $row->id; + + + return $resultStr; + } + ?> diff --git a/segments/_entryForm.php b/segments/_entryForm.php index 33436c8..7bd8d50 100644 --- a/segments/_entryForm.php +++ b/segments/_entryForm.php @@ -1,10 +1,10 @@ " . $_POST['tan'] . "<-"; - if($_POST['tan'] != ""){ + if($_POST['tanID'] != ""){ addEntry(); - consumeTan($_POST['tan']); + consumeTan($_POST['tanID']); } } @@ -12,11 +12,11 @@ } -function consumeTan($tan) { - require('../dbConnect.php'); //Erstellt variable mit dem namen $database +function consumeTan($tanID) { + 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 . "'"; + $abfrage = "SELECT `used`, `tan` FROM `tans` WHERE `id` = '" . $tanID . "'"; $ergebnis = mysqli_query($database, $abfrage); if($ergebnis->num_rows == 0){ @@ -26,21 +26,16 @@ function consumeTan($tan) { $resultStr = ""; - while ($row = $ergebnis->fetch_assoc()) { - $resultStr = $resultStr . $row["used"] . ' ' . $row["tan"] . '
'; - if($row["used"] == 1){ - echo "Tan schon verbraucht"; - return; - } - + $row = $ergebnis->fetch_object(); + 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'] . "'"); + $update = $database->query("UPDATE `tans` SET `used`= true WHERE `id` = '" . $_POST['tanID'] . "'"); - echo "Tan verbraucht " . $_POST['tan']; + echo "Tan verbraucht " . $_POST['tanID']; } ?> @@ -50,7 +45,7 @@ function consumeTan($tan) {
-
+
@@ -217,14 +212,14 @@ function consumeTan($tan) {
Eintrags-TAN*
- +
- +
diff --git a/sql/entiresTable.sql b/sql/entiresTable.sql index aefa654..1069354 100644 --- a/sql/entiresTable.sql +++ b/sql/entiresTable.sql @@ -1,5 +1,5 @@ CREATE TABLE `kd42696_ipr-projekt`.`entries` ( - `entryID` INT NOT NULL AUTO_INCREMENT , + `id` INT NOT NULL AUTO_INCREMENT , `userID` INT NOT NULL , `tanID` INT NOT NULL , `vorname` LONGTEXT NOT NULL , @@ -25,7 +25,7 @@ CREATE TABLE `kd42696_ipr-projekt`.`entries` ( `story` LONGTEXT NOT NULL , `absturz` LONGTEXT NOT NULL , `trinkspiel` LONGTEXT NOT NULL , - PRIMARY KEY (`entryID`), + PRIMARY KEY (`id`), UNIQUE (`userID`), UNIQUE (`tanID`)) ENGINE = InnoDB;