update
This commit is contained in:
parent
46cbdfd484
commit
005b8cbc68
|
|
@ -7,17 +7,17 @@ if (!file_exists($jsonFile)) {
|
|||
}
|
||||
$data = json_decode(file_get_contents($jsonFile), true);
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["action"] === "add") {
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST" && $_POST["action"] === "add") {
|
||||
$new = [
|
||||
"id" => time(),
|
||||
"input_udp" => $_POST["input_udp"] ?? "",
|
||||
"output_udp" => $_POST["output_udp"] ?? "",
|
||||
"video_format" => $_POST["video_format"] ?? "",
|
||||
"audio_format" => $_POST["audio_format"] ?? "",
|
||||
"resolution" => $_POST["resolution"] ?? "",
|
||||
"video_bitrate" => $_POST["video_bitrate"] ?? "",
|
||||
"audio_bitrate" => $_POST["audio_bitrate"] ?? "",
|
||||
"status" => $_POST["status"] ?? ""
|
||||
"input_udp" => $_POST["input_udp"],
|
||||
"output_udp" => $_POST["output_udp"],
|
||||
"video_format" => $_POST["video_format"],
|
||||
"audio_format" => $_POST["audio_format"],
|
||||
"resolution" => $_POST["resolution"],
|
||||
"video_bitrate" => $_POST["video_bitrate"],
|
||||
"audio_bitrate" => $_POST["audio_bitrate"],
|
||||
"status" => $_POST["status"]
|
||||
];
|
||||
|
||||
$data[] = $new;
|
||||
|
|
@ -27,15 +27,29 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["
|
|||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST" && $_POST["action"] === "delete") {
|
||||
$id = intval($_POST["id"]);
|
||||
$newData = [];
|
||||
|
||||
foreach ($data as $row) {
|
||||
if ($row["id"] != $id) {
|
||||
$newData[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
file_put_contents($jsonFile, json_encode($newData, JSON_PRETTY_PRINT));
|
||||
echo "OK";
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<style>
|
||||
body {
|
||||
<style>body {
|
||||
font-family: Arial;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 8px 14px;
|
||||
padding: 6px 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
|
@ -76,6 +90,11 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["
|
|||
border: 1px solid #ccc;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
background: #b40000;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
<div class="containerindex">
|
||||
<div class="grid">
|
||||
|
|
@ -94,6 +113,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["
|
|||
<th>Video Bitrate</th>
|
||||
<th>Audio Bitrate</th>
|
||||
<th>Status</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
|
||||
<?php foreach ($data as $row): ?>
|
||||
|
|
@ -107,41 +127,41 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["
|
|||
<td><?= $row["video_bitrate"] ?></td>
|
||||
<td><?= $row["audio_bitrate"] ?></td>
|
||||
<td><?= $row["status"] ?></td>
|
||||
<td><button class="delete-btn" onclick="deleteService(<?= $row['id'] ?>)">Delete</button></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</table>
|
||||
|
||||
<!-- Overlay -->
|
||||
<!-- POPUP -->
|
||||
<div id="overlay"></div>
|
||||
|
||||
<!-- Popup form -->
|
||||
<div id="popup">
|
||||
<h3>Add Service</h3>
|
||||
|
||||
<input type="text" id="in_udp" name="input_udp" placeholder="Input UDP">
|
||||
<input type="text" id="out_udp" name="output_udp" placeholder="Output UDP">
|
||||
<input type="text" id="in_udp" placeholder="Input UDP">
|
||||
<input type="text" id="out_udp" placeholder="Output UDP">
|
||||
|
||||
<select id="video_format" name="video_format">
|
||||
<select id="video_format">
|
||||
<option value="h264">H.264</option>
|
||||
<option value="h265">H.265</option>
|
||||
</select>
|
||||
|
||||
<select id="audio_format" name="audio_format">
|
||||
<select id="audio_format">
|
||||
<option value="aac">AAC</option>
|
||||
<option value="mp3">MP3</option>
|
||||
</select>
|
||||
|
||||
<select id="resolution" name="resolution">
|
||||
<select id="resolution">
|
||||
<option value="1920x1080">1920x1080</option>
|
||||
<option value="1280x720">1280x720</option>
|
||||
<option value="720x576">720x576</option>
|
||||
</select>
|
||||
|
||||
<input type="text" id="video_bitrate" name="video_bitrate" placeholder="Video Bitrate (kbps)">
|
||||
<input type="text" id="audio_bitrate" name="audio_bitrate" placeholder="Audio Bitrate (kbps)">
|
||||
<input type="text" id="video_bitrate" placeholder="Video Bitrate (kbps)">
|
||||
<input type="text" id="audio_bitrate" placeholder="Audio Bitrate (kbps)">
|
||||
|
||||
<select id="status" name="status">
|
||||
<select id="status">
|
||||
<option value="enable">Enable</option>
|
||||
<option value="disable">Disable</option>
|
||||
</select>
|
||||
|
|
@ -163,6 +183,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["
|
|||
document.getElementById("popup").style.display = "none";
|
||||
}
|
||||
|
||||
// ---------- SAVE ----------
|
||||
function saveService() {
|
||||
let form = new FormData();
|
||||
form.append("action", "add");
|
||||
|
|
@ -182,11 +203,33 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["
|
|||
})
|
||||
.then(r => r.text())
|
||||
.then(res => {
|
||||
if (res.trim() === "OK") {
|
||||
if (res.includes("OK")) {
|
||||
location.reload();
|
||||
} else {
|
||||
console.log("Server response:", res);
|
||||
alert("Error saving data");
|
||||
alert("Error saving data: " + res);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- DELETE ----------
|
||||
function deleteService(id) {
|
||||
if (!confirm("Delete this service?")) return;
|
||||
|
||||
let form = new FormData();
|
||||
form.append("action", "delete");
|
||||
form.append("id", id);
|
||||
|
||||
fetch("input.php", {
|
||||
method: "POST",
|
||||
body: form,
|
||||
credentials: "same-origin"
|
||||
})
|
||||
.then(r => r.text())
|
||||
.then(res => {
|
||||
if (res.includes("OK")) {
|
||||
location.reload();
|
||||
} else {
|
||||
alert("Error deleting: " + res);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue