aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2020-10-04 14:46:33 +0200
committerMateja <mail@matejamaric.com>2020-10-04 14:46:33 +0200
commit7c68757f672691d29c749fcbf3a95b22baffcede (patch)
tree78457ad839089834094d741f4bb7c1a9696ab622
parent49a53b71175f14d988ee79ef202743700eab0661 (diff)
downloadold-php-yota-7c68757f672691d29c749fcbf3a95b22baffcede.tar.gz
old-php-yota-7c68757f672691d29c749fcbf3a95b22baffcede.zip
finished. polishing
-rw-r--r--admin.php6
-rw-r--r--edit.php60
-rw-r--r--index.php4
-rw-r--r--request-edit.js31
-rw-r--r--style.css20
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();
?>
</nav>
<main>
-<p id="notice"></p>
<?php
if (isset($_SESSION['admin']) && $_SESSION['admin'] == true) {
try {
@@ -34,7 +33,8 @@ if (isset($_SESSION['admin']) && $_SESSION['admin'] == true) {
$conn = new PDO("mysql:host=localhost;dbname=$database", $user, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- echo '<div style="overflow-x:auto;">';
+ echo '<p id="notice">Reservation records: </p>';
+ echo '<div class="tablediv">';
echo "<table><thead>\n";
echo "<tr>";
echo "<th>ID</th>";
@@ -57,7 +57,7 @@ if (isset($_SESSION['admin']) && $_SESSION['admin'] == true) {
echo "<td>" . $row['id'] . "</td>";
if ($row['approved'])
- echo "<td><input type=\"checkbox\" checked></td>";
+ echo "<td class=\"center\"><input type=\"checkbox\" checked></td>";
else
echo "<td class=\"center\"><input type=\"checkbox\"></td>";
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();
<nav>
<a class="active" href="index.php">Activity Plan</a>
<a href="reservation.php">Make reservation</a>
+ <span class="right">
<?php
if (isset($_SESSION['admin']) && $_SESSION['admin'] == true) {
echo '<a class="right" href="/logout.php">Logout</a>';
@@ -22,6 +23,7 @@ session_start();
echo '<a class="right" href="/admin.php">Login</a>';
}
?>
+ </span>
</nav>
<main>
<?php
@@ -45,7 +47,7 @@ session_start();
echo "<th>QSO</th>";
echo "</tr></thead><tbody>\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 "<tr>";
echo "<td>" . $row['operatorCall'] . "</td>";
echo "<td>" . $row['fromTime'] . "</td>";
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;
}