From a3094caeb564821870870d57efb4a4fc3fd659e7 Mon Sep 17 00:00:00 2001 From: Mateja Date: Sun, 4 Oct 2020 00:16:49 +0200 Subject: A whole lot of shaking going on... --- admin.php | 105 ++++++++++++++++++++++++++++--------------------- edit.php | 2 +- handle-reservation.php | 8 ++-- login.php | 32 +++++++++++++++ request-edit.js | 33 ++++++++++++++++ reservation.php | 7 +++- style.css | 29 +++++++++++++- test/notes.sql | 6 +-- 8 files changed, 168 insertions(+), 54 deletions(-) create mode 100644 login.php create mode 100644 request-edit.js diff --git a/admin.php b/admin.php index 39f268c..32f6b03 100644 --- a/admin.php +++ b/admin.php @@ -1,33 +1,5 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - $stmt = $conn->prepare("SELECT * FROM admins WHERE email=:email"); - $stmt->bindParam(':email', $_POST['email']); - $stmt->execute(); - $row = $stmt->fetch(); - - if (password_verify($_POST['password'], $row['password'])){ - $_SESSION['admin'] = true; - } else { - $_SESSION['admin'] = false; - } - } catch (PDOException $e) { - echo "

Error!: " . $e->getMessage() . "

"; - } - $stmt=null; - $conn=null; -} ?> @@ -52,35 +24,79 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['email']) && isset($_PO ?>
+

setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + echo '
'; - echo "\n"; + echo "
\n"; echo ""; - echo ""; - echo ""; - echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; echo ""; - echo "\n"; - foreach($conn->query("SELECT * FROM activities WHERE approved = false") as $row) { + echo "\n"; + + foreach($conn->query("SELECT * FROM activities ORDER BY `id` DESC") as $row) { echo ""; - echo ""; - echo ""; - echo ""; - echo ''; - echo "\n"; + echo ""; + + if ($row['approved']) + echo ""; + else + echo ""; + + //echo ""; + //echo ""; + //echo ""; + //echo ""; + //echo ""; + //echo ""; + //echo ""; + //echo ""; + //echo ""; + //echo ""; + + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + echo "\n"; } - echo "
ImePrezimeGodineIDApprovedOperator SignQSOFromToFrequenciesModesSpecial signOperator NameOperator EmailOperator PhoneActions
" . $row['name'] . "" . $row['surname'] . "" . $row['age'] . "
'; - echo ''; - echo ''; - echo '
" . $row['id'] . "" . $row['operatorCall'] . "" . $row['fromTime'] . "" . $row['toTime'] . "" . $row['frequencies'] . "" . $row['modes'] . "" . $row['specialCall'] . "" . $row['operatorName'] . "" . $row['operatorEmail'] . "" . $row['operatorPhone'] . "" . $row['qso'] . "
" . $row['operatorCall'] . "
" . $row['qso'] . "
" . $row['fromTime'] . "
" . $row['toTime'] . "
" . $row['frequencies'] . "
" . $row['modes'] . "
" . $row['specialCall'] . "
" . $row['operatorName'] . "
" . $row['operatorEmail'] . "
" . $row['operatorPhone'] . "
"; + echo ""; + echo ""; + echo ""; + echo "
\n
\n"; + echo "\n\n"; } catch (PDOException $e) { echo "

Error!: " . $e->getMessage() . "

"; } } else { # Bad pass check... - if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_SESSION['admin']) && $_SESSION['admin'] == false) echo "Bad credentials!"; + if (isset($_SESSION['admin']) && $_SESSION['admin'] == false) + echo "Bad credentials!"; # Login form echo '
'; echo ''; @@ -92,5 +108,6 @@ if (isset($_SESSION['admin']) && $_SESSION['admin'] == true) { } ?>
+ diff --git a/edit.php b/edit.php index 3ddada5..4ff5b5e 100644 --- a/edit.php +++ b/edit.php @@ -1,7 +1,7 @@ All fields must be filed!

"; + $_SESSION["msg"] = "All fields must be filed!"; } else { // Send to DB @@ -79,9 +79,9 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { $stmt->bindParam(':operatorEmail', $operatorEmail); $stmt->bindParam(':operatorPhone', $operatorPhone); $stmt->execute(); - echo "

Data inserted.

"; + $_SESSION["msg"] = "Data inserted."; } catch (PDOException $e) { - echo "

Error!: " . $e->getMessage() . "

"; + $_SESSION["msg"] = "Error!: " . $e->getMessage(); } } } @@ -92,3 +92,5 @@ function clear_input($data) { $data = htmlspecialchars($data); return $data; } + +header("Location: reservation.php"); diff --git a/login.php b/login.php new file mode 100644 index 0000000..6d51326 --- /dev/null +++ b/login.php @@ -0,0 +1,32 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $stmt = $conn->prepare("SELECT * FROM admins WHERE email=:email"); + $stmt->bindParam(':email', $_POST['email']); + $stmt->execute(); + $row = $stmt->fetch(); + + if (password_verify($_POST['password'], $row['password'])) { + $_SESSION['admin'] = true; + } else { + $_SESSION['admin'] = false; + } + } catch (PDOException $e) { + die("Error!: " . $e->getMessage()); + } + $stmt=null; + $conn=null; +} + +header("Location: admin.php"); diff --git a/request-edit.js b/request-edit.js new file mode 100644 index 0000000..4d8a245 --- /dev/null +++ b/request-edit.js @@ -0,0 +1,33 @@ +function btnAction(action, btn) { + var trDom = btn.parentElement.parentElement; + var trData = trDom.children; + + var actionData = { + action: action, + id: trData[0].innerHTML, + approved: trData[1].firstElementChild.checked, + operatorSign: trData[2].firstElementChild.innerHTML, + qso: trData[3].firstElementChild.innerHTML, + fromTime: trData[4].firstElementChild.innerHTML, + toTime: trData[5].firstElementChild.innerHTML, + freqs: trData[6].firstElementChild.innerHTML, + modes: trData[7].firstElementChild.innerHTML, + specialSign: trData[8].firstElementChild.innerHTML, + operatorName: trData[9].firstElementChild.innerHTML, + operatorEmail: trData[10].firstElementChild.innerHTML, + operatorPhone: trData[11].firstElementChild.innerHTML + } + + if (actionData.action == 'delete') + if (confirm("Are you sure you want to delete reservation #" + actionData.id + " made by " + actionData.operatorSign + "?")) + trDom.remove(); + + //var xhr = new XMLHttpRequest(); + //xhr.onreadystatechange = function () { + //if (this.readyState == 4 && status == 200) { + + //} + //}; + //xhr.open("POST", "edit.php", true); + //xhr.send(JSON.stringify(actionData)); +} diff --git a/reservation.php b/reservation.php index ec46440..05f6fa7 100644 --- a/reservation.php +++ b/reservation.php @@ -24,11 +24,14 @@ session_start(); ?>
+ " . $_SESSION["msg"] . "

"; +} ?> - +