This commit is contained in:
devdatt 2026-01-08 07:41:24 +05:30
parent 46cbdfd484
commit 005b8cbc68
1 changed files with 67 additions and 24 deletions

View File

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