From 405f58124d2699a3ed98901710addebe3c06d9ca Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Mon, 20 Jan 2025 21:17:54 +0200 Subject: [PATCH] Redesigns the whole config page --- app/pages/config.php | 80 +++- app/templates/config-platform.php | 614 +++++++++++++++++++++++++++--- 2 files changed, 623 insertions(+), 71 deletions(-) diff --git a/app/pages/config.php b/app/pages/config.php index 0e3e33c..0e0b6c8 100644 --- a/app/pages/config.php +++ b/app/pages/config.php @@ -115,18 +115,42 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { } // an update to an existing host - } elseif (isset($_POST['host'])) { + } elseif (isset($_POST['item']) && $_POST['item'] === 'host') { + $host_id = $_POST['host']; + $platform_id = $_POST['platform']; $updatedHost = [ - 'id' => $host, - 'address' => $address, - 'port' => $port, - 'name' => $name, + 'id' => $host_id, + 'address' => $_POST['address'], + 'name' => $_POST['name'] ]; $result = $hostObject->editHost($platform_id, $updatedHost); - if ($result === true) { - $_SESSION['notice'] = "Host \"{$_REQUEST['address']}:{$_REQUEST['port']}\" edited."; + + // Check if it's an AJAX request + if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && + strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { + + // Clear any output buffers to ensure clean JSON + while (ob_get_level()) ob_end_clean(); + + header('Content-Type: application/json'); + if ($result === true) { + echo json_encode(['success' => true]); + } else { + echo json_encode([ + 'success' => false, + 'message' => "Editing the host failed. Error: $result" + ]); + } + exit(); } else { - $_SESSION['error'] = "Editing the host failed. Error: $result"; + // Regular form submission + if ($result === true) { + $_SESSION['notice'] = "Host edited."; + } else { + $_SESSION['error'] = "Editing the host failed. Error: $result"; + } + header("Location: $app_root?page=config&item=$item"); + exit(); } // an update to an existing agent @@ -147,19 +171,41 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { // an update to an existing platform } else { - $platform = $_POST['platform']; + $platform = $_POST['platform_id']; $updatedPlatform = [ - 'name' => $name, - 'jitsi_url' => $_POST['jitsi_url'], - 'jilo_database' => $_POST['jilo_database'], + 'name' => $_POST['name'], + 'jitsi_url' => $_POST['jitsi_url'], + 'jilo_database' => $_POST['jilo_database'] ]; $result = $platformObject->editPlatform($platform, $updatedPlatform); - if ($result === true) { - $_SESSION['notice'] = "Platform \"{$_REQUEST['name']}\" edited."; + + // Check if it's an AJAX request + if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && + strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { + + // Clear any output buffers to ensure clean JSON + while (ob_get_level()) ob_end_clean(); + + header('Content-Type: application/json'); + if ($result === true) { + echo json_encode(['success' => true]); + } else { + echo json_encode([ + 'success' => false, + 'message' => "Editing the platform failed. Error: $result" + ]); + } + exit(); } else { - $_SESSION['error'] = "Editing the platform failed. Error: $result"; + // Regular form submission + if ($result === true) { + $_SESSION['notice'] = "Platform edited."; + } else { + $_SESSION['error'] = "Editing the platform failed. Error: $result"; + } + header("Location: $app_root?page=config&item=$item"); + exit(); } - } // FIXME the new file is not loaded on first page load @@ -219,7 +265,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { include '../app/templates/config-agent-add.php'; } else { $_SESSION['error'] = "Platform ID is required to add an agent."; - header("Location: $app_root?page=config"); + header("Location: $app_root?page=config&item=agent"); exit(); } } elseif (isset($action) && $action === 'edit') { diff --git a/app/templates/config-platform.php b/app/templates/config-platform.php index 2a4e446..40c9123 100644 --- a/app/templates/config-platform.php +++ b/app/templates/config-platform.php @@ -1,60 +1,566 @@ - -
-

Jilo configuration :: Jitsi Meet platforms

-
-

Jitsi platforms configuration  add new

-getHostDetails($platform_array['id']); - $agents = $agentObject->getAgentDetails($platform_array['id']); -?> - -
-

- platform id - -   - edit platform - - delete platform - - delete platform - -

-
- $value) { - if ($key === 'id') continue; -?> -
-
- : -
-
- - - - - - - - -
+ +
+
+
+

Jitsi Meet platforms configuration

+
+ +
+ + + +
+ $platform): ?> + getHostDetails($platform['id']); + $agents = $agentObject->getAgentDetails($platform['id']); + ?> +
+ +
+
+ + + Platform # +
- -
-
-
- -
-
-
-
-
- -
+
+ + + + + + + +
+ +
+ + + $value): ?> + + + + + + + +
+
+ + + + + + + + +
+ +
+
+ + +
+
+
+ + + + for platform "" + +
+ + Add new host + +
+ + + + +
+
+
+
+ +
Host id # in platform ""
+
+
+ +
+
+
Host description
+
+
+
+
DNS name or IP
+
+
+
+
+ +
+
+
+ + + + + Delete host + +
+
+ +
+ + getAgentDetails($platform['id']); ?> +
+
+ + + + for this host + +
+ + Add new agent + +
+ + +
+ + + + + + + + + + + + + + + + + + + +
Agent TypeEndpoint URLCheck period (minutes)Actions
+
+ + +
+
+ + + + - + + + +
+
+ +
+ + No agents configured for this host. +
+ +
+
+ + +
+ + No hosts configured for platform . +
+ +
- -
+
- + +
+ + No platforms available. Use the button above to add your first platform. +
+ +
+
+
+ + +