updated new entry handling

This commit is contained in:
Marcel Schwarz 2018-06-11 00:59:10 +02:00
parent 47934a70be
commit 09debbdc9d
6 changed files with 90 additions and 6 deletions

View File

@ -16,16 +16,18 @@
<?php include('segments/_header.html'); ?> <?php include('segments/_header.html'); ?>
<div id="content"> <div id="content">
<button id="btnCreateTan" type="button" class="btn btn-info">Erstelle Tan</button>
</div> </div>
<!-- Zum testen der Daten die ueber die Modals reinkommen --> <!-- Zum testen der Daten die ueber die Modals reinkommen -->
<!-- <?php include('segments/_indexTestLoginVals.php'); ?> --> <!-- <?php include('segments/_indexTestLoginVals.php'); ?> -->
<?php include('segments/_entryForm.php'); ?> <?php include('segments/_entryForm.php'); ?>
<!-- Include the footer--> <!-- Include the footer-->
<?php include('segments/_footer.html'); ?> <?php include('segments/_footer.html'); ?>
<!-- Optional JavaScript --> <!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS --> <!-- jQuery first, then Popper.js, then Bootstrap JS -->

View File

@ -1,7 +1,8 @@
window.addEventListener('load', async () => { window.addEventListener('load', async () => {
console.log("Seite geladen"); console.log("Seite geladen");
getNewUniqueLink(); //getNewUniqueLink();
document.getElementById('btnCreate').addEventListener('click' , async (event) => createEntry()); document.getElementById('btnCreateTan').addEventListener('click' , async (event) => getNewUniqueLink());
document.getElementById('btnAbsenden').addEventListener('click' , async (event) => createEntry());
}) })
async function getNewUniqueLink() { async function getNewUniqueLink() {
@ -18,7 +19,8 @@ async function getNewUniqueLink() {
} }
async function createEntry() { async function createEntry() {
event.preventDefault() event.preventDefault()
const formData = new formData(document.getElementById('create-form')); console.log("Absenden gedrueckt!!!!");
const formData = new formData(document.getElementById('entry-form'));
try { try {
const response = await fetch('php/login.php', { const response = await fetch('php/login.php', {

View File

View File

@ -1,9 +1,56 @@
<?php
if(isset($_POST['tan'])){
//echo "Tan ->" . $_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"] . '<br>';
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'];
}
?>
<!-- Container fuer entry form--> <!-- Container fuer entry form-->
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<form id="entry-form" action="index.php" method="post"> <form id="entry-form" action="" method="post">
<!-- Vorname--> <!-- Vorname-->
<div class="input-group input-group-sm mb-3"> <div class="input-group input-group-sm mb-3">
<div class="input-group-prepend"> <div class="input-group-prepend">
@ -174,7 +221,7 @@
</div> </div>
<!-- Absenden Button--> <!-- Absenden Button-->
<div class="modal-footer"> <div class="modal-footer">
<button id="entry" type="submit" class="btn btn-primary">Absenden</button> <button id="btnAbsenden" type="submit" class="btn btn-primary">Absenden</button>
</div> </div>
</form> </form>

33
sql/entiresTable.sql Normal file
View File

@ -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;