From adfbe17f385b46a958d09b483298f9820d7ee5fb Mon Sep 17 00:00:00 2001 From: Peter Hoppe Date: Tue, 7 Feb 2023 15:56:46 +0100 Subject: [PATCH] storeEmail --- docs/contactEmails.sql | 62 +++++++++++++++++++++++++++++++ php/php-dog/classes/lib.php | 31 ++++++++++++++++ php/php-dog/foundEmail.php | 17 +++++++++ php/php-dog/getDog.php | 27 +------------- src/components/ContactForm.css | 35 +++++++++++------ src/components/ContactForm2.css | 60 ------------------------------ src/components/DogContactForm.tsx | 16 ++++---- src/components/test.html | 24 ++++++++---- 8 files changed, 159 insertions(+), 113 deletions(-) create mode 100644 docs/contactEmails.sql delete mode 100644 src/components/ContactForm2.css diff --git a/docs/contactEmails.sql b/docs/contactEmails.sql new file mode 100644 index 0000000..8cb046e --- /dev/null +++ b/docs/contactEmails.sql @@ -0,0 +1,62 @@ +-- phpMyAdmin SQL Dump +-- version 5.2.0 +-- https://www.phpmyadmin.net/ +-- +-- Host: localhost +-- Erstellungszeit: 07. Feb 2023 um 14:51 +-- Server-Version: 10.4.27-MariaDB +-- PHP-Version: 8.1.12 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +START TRANSACTION; +SET time_zone = "+00:00"; + +-- +-- Datenbank: `k200835_dog` +-- + +-- -------------------------------------------------------- + +-- +-- Tabellenstruktur für Tabelle `contact_emails` +-- + +CREATE TABLE `contact_emails` ( + `id` int(11) NOT NULL, + `dogs_id` int(11) NOT NULL, + `from_email` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, + `msg` varchar(1023) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp() +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; + +-- +-- Indizes der exportierten Tabellen +-- + +-- +-- Indizes für die Tabelle `contact_emails` +-- +ALTER TABLE `contact_emails` + ADD PRIMARY KEY (`id`), + ADD KEY `FK_dogs_id` (`dogs_id`); + +-- +-- AUTO_INCREMENT für exportierte Tabellen +-- + +-- +-- AUTO_INCREMENT für Tabelle `contact_emails` +-- +ALTER TABLE `contact_emails` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; + +-- +-- Constraints der exportierten Tabellen +-- + +-- +-- Constraints der Tabelle `contact_emails` +-- +ALTER TABLE `contact_emails` + ADD CONSTRAINT `FK_dogs_id` FOREIGN KEY (`dogs_id`) REFERENCES `dogs` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; +COMMIT; \ No newline at end of file diff --git a/php/php-dog/classes/lib.php b/php/php-dog/classes/lib.php index e3c9bfe..170d0d1 100644 --- a/php/php-dog/classes/lib.php +++ b/php/php-dog/classes/lib.php @@ -120,4 +120,35 @@ function getNewFilename($targetDir, $fileExt, $length) return $newFname .".".$fileExt; } +function getDogByQrId($qr_id, $conn, $fields = null) +{ + if(strcmp($qr_id, 'SESS') === 0) + { + $allHeaders = getallheaders(); + $auth = new Auth($conn, $allHeaders); + $data = json_decode($auth->isValid()); + $user = $data->data; + $qr_id = $user->qr_id; + } + $fetch_user_qr_id = + "SELECT id, qr_id, email, name, phone, + qr_width_cm, qr_height_cm, qr_fontsize, qr_visible_items, qr_item_sequence, + qr_code, picture FROM `dogs` WHERE `qr_id`=:qr_id"; + $query_stmt = $conn->prepare($fetch_user_qr_id); + $query_stmt->bindValue(':qr_id', $qr_id,PDO::PARAM_STR); + $query_stmt->execute(); + + // IF THE dog IS FOUNDED BY qr_id + if($query_stmt->rowCount()) + { + $row = $query_stmt->fetch(PDO::FETCH_ASSOC); + $returnData = new CMsg(1,200,'get dog',$fields,$row); + } + else + { + $returnData = new CMsg(0,422,'no dog',$fields); + } + return $returnData; +} + ?> diff --git a/php/php-dog/foundEmail.php b/php/php-dog/foundEmail.php index 8a2841d..32f03c9 100644 --- a/php/php-dog/foundEmail.php +++ b/php/php-dog/foundEmail.php @@ -73,6 +73,7 @@ try if($ret) { $result = new CMsg(1, 200, "Email send successfully."); + $storeResult = storeEmail(); } else { @@ -85,4 +86,20 @@ catch (Exception $e) $result = new CMsg(0, 500, $e->getMessage() ); echo $result->jsonarray(); } + + +function storeEmail() +{ + global $qr_id, $conn, $msg, $fromEmail; + + $dogRes = getDogByQrId($qr_id, $conn); + + if($dogRes->success) + { + $sql = "INSERT INTO contact_email (dogs_id, from_email, msg) VALUES (?,?,?)"; + $conn->prepare($sql)->execute([$dogRes->data->id, $fromEmail, $msg]); // throw PDO::exception when failed + } + + return $dogRes; +} ?> \ No newline at end of file diff --git a/php/php-dog/getDog.php b/php/php-dog/getDog.php index 4dbc515..148fdee 100644 --- a/php/php-dog/getDog.php +++ b/php/php-dog/getDog.php @@ -42,32 +42,7 @@ else $qr_id = trim($data->qr_id); try { - if(strcmp($qr_id, 'SESS') === 0) - { - $allHeaders = getallheaders(); - $auth = new Auth($conn, $allHeaders); - $data = json_decode($auth->isValid()); - $user = $data->data; - $qr_id = $user->qr_id; - } - $fetch_user_qr_id = - "SELECT id, qr_id, email, name, phone, - qr_width_cm, qr_height_cm, qr_fontsize, qr_visible_items, qr_item_sequence, - qr_code, picture FROM `dogs` WHERE `qr_id`=:qr_id"; - $query_stmt = $conn->prepare($fetch_user_qr_id); - $query_stmt->bindValue(':qr_id', $qr_id,PDO::PARAM_STR); - $query_stmt->execute(); - - // IF THE dog IS FOUNDED BY qr_id - if($query_stmt->rowCount()) - { - $row = $query_stmt->fetch(PDO::FETCH_ASSOC); - $returnData = new CMsg(1,200,'get dog',$fields,$row); - } - else - { - $returnData = new CMsg(0,422,'no dog',$fields); - } + $returnData = getDogByQrId($qr_id, $conn, $fields); } catch(PDOException $e) { diff --git a/src/components/ContactForm.css b/src/components/ContactForm.css index 728e307..d54879a 100644 --- a/src/components/ContactForm.css +++ b/src/components/ContactForm.css @@ -1,30 +1,37 @@ /* Style inputs, select elements and textareas */ -input[type=email], select, textarea{ +.contactInput +input[type=email], select, textarea +{ width: 100%; padding: 3px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; resize: vertical; - background-color: #f26e0a; + background-color: white; } -input[type=submit] { +.formForm input[type=submit] +{ background-color: #aa0404; color: white; - padding: 6px 10px; border: none; border-radius: 4px; cursor: pointer; - width: 50%; + width: auto; height: 25px; } +div.flexCenter +{ + display: flex; +} /* Style the label to display next to the inputs */ - label + .flexCenter label { + margin-left: 0; padding: 2px 12px 2px 0; display: inline-block; } @@ -34,6 +41,8 @@ input[type=submit] { display: flex; flex-direction: row; justify-content: center; + text-align: left; + } .containerForm { @@ -43,30 +52,31 @@ input[type=submit] { background-color: #f6602e; padding: 20px; justify-content: center; - width: 400px; + width: 60%; } .formForm { display: flex; flex-direction: column; - max-width: 600px; + width: 100%; + align-items: flex-end; } /* Floating column for labels: 25% width */ - .col-25 + .col-30 { float: left; - width: 25%; + width: 30%; margin-top: 6px; } /* Floating column for inputs: 75% width */ - .col-75 + .col-70 { float: left; - width: 75%; + width: 70%; margin-top: 6px; } @@ -75,6 +85,7 @@ input[type=submit] { display: flex; flex-direction: row; justify-content: space-between; + width: 100%; } .row diff --git a/src/components/ContactForm2.css b/src/components/ContactForm2.css deleted file mode 100644 index 14279ab..0000000 --- a/src/components/ContactForm2.css +++ /dev/null @@ -1,60 +0,0 @@ -/* Style inputs, select elements and textareas */ - - /* Style the label to display next to the inputs */ - label - { - padding: 12px 12px 12px 0; - display: inline-block; - } - - - .formForm - { - display: flex; - flex-direction: column; - - } - /* Style the container */ - .containerForm - { - display: flex; - flex-direction: row; - border-radius: 5px; - background-color: #f2f2f2; - padding: 20px; - width: 600px; - } - - /* Floating column for labels: 25% width */ - .col-25 - { - float: left; - width: 25%; - margin-top: 6px; - } - - /* Floating column for inputs: 75% width */ - .col-75 - { - float: left; - width: 75%; - margin-top: 6px; - } - - .rowForm - { - display: flex; - flex-direction: column; - } - - .row - { - display: flex; - flex-direction: column; - } - - .textArea - { - height: 200px; - } - \ No newline at end of file diff --git a/src/components/DogContactForm.tsx b/src/components/DogContactForm.tsx index 98de99b..65e62d4 100644 --- a/src/components/DogContactForm.tsx +++ b/src/components/DogContactForm.tsx @@ -81,28 +81,30 @@ const data = {
-

Bitte schreib eine Email:

-
+
Bitte schreib eine Email:
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+ +