From 7c68757f672691d29c749fcbf3a95b22baffcede Mon Sep 17 00:00:00 2001 From: Mateja Date: Sun, 4 Oct 2020 14:46:33 +0200 Subject: finished. polishing --- admin.php | 6 +++--- edit.php | 60 ++++++++++++++++++++++++++++++++------------------------- index.php | 4 +++- request-edit.js | 31 +++++++++++++++-------------- style.css | 20 ++++++++++++++++++- 5 files changed, 74 insertions(+), 47 deletions(-) diff --git a/admin.php b/admin.php index cb2a5fd..ee50227 100644 --- a/admin.php +++ b/admin.php @@ -24,7 +24,6 @@ session_start(); ?>
-

setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - echo '
'; + echo '

Reservation records:

'; + echo '
'; echo "\n"; echo ""; echo ""; @@ -57,7 +57,7 @@ if (isset($_SESSION['admin']) && $_SESSION['admin'] == true) { echo ""; if ($row['approved']) - echo ""; + echo ""; else echo ""; diff --git a/edit.php b/edit.php index c3cd0db..c515de7 100644 --- a/edit.php +++ b/edit.php @@ -22,7 +22,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_SESSION['admin']) && $_SESSI try { $recvData = json_decode(file_get_contents("php://input")); $recvData->id = clear_input($recvData->id); - $recvData->approved = clear_input($recvData->approved); + $recvData->approved = filter_var($recvData->approved, FILTER_VALIDATE_BOOLEAN); $recvData->specialCall = clear_input($recvData->specialCall); $recvData->fromTime = clear_input($recvData->fromTime); $recvData->toTime = clear_input($recvData->toTime); @@ -53,21 +53,25 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_SESSION['admin']) && $_SESSI qso=:qso WHERE id=:id"; - $stmt = $conn->prepare($sql); - $stmt->bindParam(':approved', $recvData->approved); - $stmt->bindParam(':specialCall', $recvData->specialCall); - $stmt->bindParam(':fromTime', $recvData->fromTime); - $stmt->bindParam(':toTime', $recvData->toTime); - $stmt->bindParam(':frequencies', $recvData->frequencies); - $stmt->bindParam(':modes', $recvData->modes); - $stmt->bindParam(':operatorCall', $recvData->operatorCall); - $stmt->bindParam(':operatorName', $recvData->operatorName); - $stmt->bindParam(':operatorEmail', $recvData->operatorEmail); - $stmt->bindParam(':operatorPhone', $recvData->operatorPhone); - $stmt->bindParam(':qso', $recvData->qso); - $stmt->execute(); + $recvData->approved = $recvData->approved === true ? "1" : "0"; + + $stmt = $conn->prepare($sql); + $stmt->bindParam(':id', $recvData->id); + $stmt->bindParam(':approved', $recvData->approved); + $stmt->bindParam(':specialCall', $recvData->specialCall); + $stmt->bindParam(':fromTime', $recvData->fromTime); + $stmt->bindParam(':toTime', $recvData->toTime); + $stmt->bindParam(':frequencies', $recvData->frequencies); + $stmt->bindParam(':modes', $recvData->modes); + $stmt->bindParam(':operatorCall', $recvData->operatorCall); + $stmt->bindParam(':operatorName', $recvData->operatorName); + $stmt->bindParam(':operatorEmail', $recvData->operatorEmail); + $stmt->bindParam(':operatorPhone', $recvData->operatorPhone); + $stmt->bindParam(':qso', $recvData->qso); + $stmt->execute(); $sendData->action=$recvData->action; + echo json_encode($sendData); } else if ($recvData->action == "restore") { @@ -77,20 +81,24 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_SESSION['admin']) && $_SESSI $stmt->execute(); $row = $stmt->fetch(); + $sendData = null; $sendData->action=$recvData->action; - $sendData->id=$row->id; - $sendData->approved=$row->approved; - $sendData->specialCall=$row->specialCall; - $sendData->fromTime=$row->fromTime; - $sendData->toTime=$row->toTime; - $sendData->frequencies=$row->frequencies; - $sendData->modes=$row->modes; - $sendData->operatorCall=$row->operatorCall; - $sendData->operatorName=$row->operatorName; - $sendData->operatorEmail=$row->operatorEmail; - $sendData->operatorPhone=$row->operatorPhone; - $sendData->qso=$row->qso; + $sendData->id=$row["id"]; + + $sendData->approved=$row["approved"]; + + $sendData->specialCall=$row["specialCall"]; + $sendData->fromTime=$row["fromTime"]; + $sendData->toTime=$row["toTime"]; + $sendData->frequencies=$row["frequencies"]; + $sendData->modes=$row["modes"]; + $sendData->operatorCall=$row["operatorCall"]; + $sendData->operatorName=$row["operatorName"]; + $sendData->operatorEmail=$row["operatorEmail"]; + $sendData->operatorPhone=$row["operatorPhone"]; + $sendData->qso=$row["qso"]; + $recvData->approved = filter_var($recvData->approved, FILTER_VALIDATE_BOOLEAN); echo json_encode($sendData); } else if ($recvData->action == "delete") { diff --git a/index.php b/index.php index 6fd938b..39a38ab 100644 --- a/index.php +++ b/index.php @@ -14,6 +14,7 @@ session_start();
QSO"; echo "
\n"; - foreach($db->query("SELECT * FROM $table where approved=false ORDER BY `id` DESC") as $row) { + foreach($db->query("SELECT * FROM $table where approved=true ORDER BY `id` DESC") as $row) { echo ""; echo ""; echo ""; diff --git a/request-edit.js b/request-edit.js index 60c0d55..f6d2c05 100644 --- a/request-edit.js +++ b/request-edit.js @@ -6,42 +6,41 @@ function btnAction(action, btn) { action: action, id: trData[0].innerHTML, approved: trData[1].firstElementChild.checked, - operatorSign: trData[2].firstElementChild.innerHTML, + operatorCall: trData[2].firstElementChild.innerHTML, qso: trData[3].firstElementChild.innerHTML, fromTime: trData[4].firstElementChild.innerHTML, toTime: trData[5].firstElementChild.innerHTML, - freqs: trData[6].firstElementChild.innerHTML, + frequencies: trData[6].firstElementChild.innerHTML, modes: trData[7].firstElementChild.innerHTML, - specialSign: trData[8].firstElementChild.innerHTML, + specialCall: trData[8].firstElementChild.innerHTML, operatorName: trData[9].firstElementChild.innerHTML, operatorEmail: trData[10].firstElementChild.innerHTML, operatorPhone: trData[11].firstElementChild.innerHTML } - console.log(actionData); - if (actionData.action == 'delete') - if (confirm("Are you sure you want to delete reservation #" + actionData.id + " made by " + actionData.operatorSign + "?")) + if (confirm("Are you sure you want to delete reservation #" + actionData.id + " made by " + actionData.operatorCall + "?")) trDom.remove(); - var xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function () { - if (this.readyState == 4 && status == 200) { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { + if (this.readyState == 4 && this.status == 200) { try { // JSON response to object var response = JSON.parse(this.responseText); + console.log(response); // Handle various actions if (response.action == "update") { document.getElementById("notice").innerHTML = "Record #" + actionData.id + " updated."; } else if (response.action == "restore") { - trData[1].firstElementChild.checked = response.approved; - trData[2].firstElementChild.innerHTML = response.operatorSign; + trData[1].firstElementChild.checked = response.approved === "1"; + trData[2].firstElementChild.innerHTML = response.operatorCall; trData[3].firstElementChild.innerHTML = response.qso; trData[4].firstElementChild.innerHTML = response.fromTime; trData[5].firstElementChild.innerHTML = response.toTime; - trData[6].firstElementChild.innerHTML = response.freqs; + trData[6].firstElementChild.innerHTML = response.frequencies; trData[7].firstElementChild.innerHTML = response.modes; - trData[8].firstElementChild.innerHTML = response.specialSign; + trData[8].firstElementChild.innerHTML = response.specialCall; trData[9].firstElementChild.innerHTML = response.operatorName; trData[10].firstElementChild.innerHTML = response.operatorEmail; trData[11].firstElementChild.innerHTML = response.operatorPhone; @@ -49,7 +48,7 @@ function btnAction(action, btn) { } else if (response.action == "delete") { document.getElementById("notice").innerHTML = "Record #" + actionData.id + " deleted."; } else { - console.log("Nothing?"); + console.log("No action?"); console.log(this.responseText); } } catch { @@ -58,6 +57,6 @@ function btnAction(action, btn) { } } }; - xhr.open("POST", "edit.php", true); - xhr.send(JSON.stringify(actionData)); + xhttp.open("POST", "edit.php", true); + xhttp.send(JSON.stringify(actionData)); } diff --git a/style.css b/style.css index 8d68726..ed88e24 100644 --- a/style.css +++ b/style.css @@ -74,7 +74,7 @@ a { /* TABEL STYLING */ table { - margin: 1rem 0; + margin: 0; border-collapse: collapse; width: 100%; } @@ -93,6 +93,24 @@ td, th { white-space: nowrap; } +.tablediv { + overflow-x: scroll; + height: 70vh; +} + +/*div.tablediv {*/ + /*overflow:scroll;*/ + /*height: 80vh;*/ + /*width: 100%;*/ + /*display: block;*/ +/*}*/ + +/*tbody {*/ + /*overflow:scroll;*/ + /*height: 80vh;*/ + /*width: 80vw;*/ +/*}*/ + .center { text-align: center; } -- cgit v1.2.3
ID" . $row['id'] . "
" . $row['operatorCall'] . "" . $row['fromTime'] . "