From 7c68757f672691d29c749fcbf3a95b22baffcede Mon Sep 17 00:00:00 2001 From: Mateja Date: Sun, 4 Oct 2020 14:46:33 +0200 Subject: finished. polishing --- edit.php | 60 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 26 deletions(-) (limited to 'edit.php') 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") { -- cgit v1.2.3