From 88e77f71efe09c748da8a40e8c6a615b5195cffd Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Fri, 20 Sep 2024 12:13:18 +0300 Subject: [PATCH] Fixes config pages --- app/pages/agents.php | 38 ++++++++-------- app/pages/config.php | 43 +++++++++++++++++-- .../{agent-add.php => config-add-agent.php} | 0 .../{agent-edit.php => config-edit-agent.php} | 0 app/templates/config-list.php | 2 +- 5 files changed, 59 insertions(+), 24 deletions(-) rename app/templates/{agent-add.php => config-add-agent.php} (100%) rename app/templates/{agent-edit.php => config-edit-agent.php} (100%) diff --git a/app/pages/agents.php b/app/pages/agents.php index 6a4bb2e..ca6bf68 100644 --- a/app/pages/agents.php +++ b/app/pages/agents.php @@ -10,27 +10,27 @@ $agentObject = new Agent($dbWeb); if ($_SERVER['REQUEST_METHOD'] == 'POST') { // new agent adding - if (isset($_POST['new']) && $_POST['new'] === 'true') { - $newAgent = [ - 'type_id' => 1, - 'url' => $_POST['url'], - 'secret_key' => $_POST['secret_key'], - ]; - $result = $agentObject->addAgent($platform_id, $newAgent); - if ($result === true) { - $_SESSION['notice'] = "New Jilo Agent added."; - } else { - $_SESSION['error'] = "Adding the agent failed. Error: $result"; - } +// if (isset($_POST['new']) && $_POST['new'] === 'true') { +// $newAgent = [ +// 'type_id' => 1, +// 'url' => $_POST['url'], +// 'secret_key' => $_POST['secret_key'], +// ]; +// $result = $agentObject->addAgent($platform_id, $newAgent); +// if ($result === true) { +// $_SESSION['notice'] = "New Jilo Agent added."; +// } else { +// $_SESSION['error'] = "Adding the agent failed. Error: $result"; +// } // deleting an agent - } elseif (isset($_POST['delete']) && $_POST['delete'] === 'true') { - $result = $agentObject->deleteAgent($agent); - if ($result === true) { - $_SESSION['notice'] = "Agent id \"{$_REQUEST['agent']}\" deleted."; - } else { - $_SESSION['error'] = "Deleting the agent failed. Error: $result"; - } +// } elseif (isset($_POST['delete']) && $_POST['delete'] === 'true') { +// $result = $agentObject->deleteAgent($agent); +// if ($result === true) { +// $_SESSION['notice'] = "Agent id \"{$_REQUEST['agent']}\" deleted."; +// } else { +// $_SESSION['error'] = "Deleting the agent failed. Error: $result"; +// } // an update to an existing agent } else { diff --git a/app/pages/config.php b/app/pages/config.php index ee2fcaf..9e4c4ee 100644 --- a/app/pages/config.php +++ b/app/pages/config.php @@ -1,9 +1,13 @@ 1, + 'url' => $_POST['url'], + 'secret_key' => $_POST['secret_key'], + ]; + $result = $agentObject->addAgent($platform_id, $newAgent); + if ($result === true) { + $_SESSION['notice'] = "New Jilo Agent added."; + } else { + $_SESSION['error'] = "Adding the agent failed. Error: $result"; + } + // new platform adding - if (isset($_POST['new']) && $_POST['new'] === 'true') { + } elseif (isset($_POST['new']) && $_POST['new'] === 'true') { $newPlatform = [ 'name' => $_POST['name'], 'jitsi_url' => $_POST['jitsi_url'], @@ -22,6 +40,15 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { ]; $platformObject->addPlatform($newPlatform); + // deleting an agent + } elseif (isset($_POST['delete']) && isset($_POST['item']) && $_POST['delete'] === 'true' && $_POST['item'] === 'agent') { + $result = $agentObject->deleteAgent($agent); + if ($result === true) { + $_SESSION['notice'] = "Agent id \"{$_REQUEST['agent']}\" deleted."; + } else { + $_SESSION['error'] = "Deleting the agent failed. Error: $result"; + } + // deleting a platform } elseif (isset($_POST['delete']) && $_POST['delete'] === 'true') { $platform = $_POST['platform']; @@ -83,19 +110,27 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { // if there is no $item, we work on the local config file default: switch ($action) { + case 'add-agent': + include '../app/templates/config-add-agent.php'; + break; case 'add': include '../app/templates/config-add-platform.php'; break; case 'edit': - include '../app/templates/config-edit-platform.php'; + if (isset($_GET['agent'])) { + $agentDetails = $agentObject->getAgentDetails($platform_id, $agent); + include '../app/templates/config-edit-agent.php'; + } else { + include '../app/templates/config-edit-platform.php'; + } break; case 'delete': include '../app/templates/config-delete-platform.php'; break; default: if ($userObject->hasRight($user_id, 'view config file')) { - require '../app/classes/agent.php'; - $agentObject = new Agent($dbWeb); +// require '../app/classes/agent.php'; +// $agentObject = new Agent($dbWeb); include '../app/templates/config-list.php'; } else { include '../app/templates/unauthorized.php'; diff --git a/app/templates/agent-add.php b/app/templates/config-add-agent.php similarity index 100% rename from app/templates/agent-add.php rename to app/templates/config-add-agent.php diff --git a/app/templates/agent-edit.php b/app/templates/config-edit-agent.php similarity index 100% rename from app/templates/agent-edit.php rename to app/templates/config-edit-agent.php diff --git a/app/templates/config-list.php b/app/templates/config-list.php index e5c30ef..ba16acc 100644 --- a/app/templates/config-list.php +++ b/app/templates/config-list.php @@ -61,7 +61,7 @@ echo "\n";

jilo agents on platform ()
total   - + add new