Fixes agent types selection on add/edit

main
Yasen Pramatarov 2024-10-03 11:28:23 +03:00
parent d0ef53a176
commit 1468843cac
4 changed files with 37 additions and 10 deletions

View File

@ -40,6 +40,17 @@ class Agent {
return $query->fetchAll(PDO::FETCH_ASSOC);
}
// get agent types
public function getAgentTypes() {
$sql = 'SELECT *
FROM jilo_agent_types
ORDER BY id';
$query = $this->db->prepare($sql);
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
}
// add new agent
public function addAgent($platform_id, $newAgent) {
try {

View File

@ -20,8 +20,8 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// new agent adding
if (isset($_POST['new']) && isset($_POST['item']) && $_POST['new'] === 'true' && $_POST['item'] === 'agent') {
$newAgent = [
'type_id' => 1,
'url' => $_POST['url'],
'type_id' => $_POST['type'],
'url' => $_POST['url'],
'secret_key' => $_POST['secret_key'],
];
$result = $agentObject->addAgent($platform_id, $newAgent);
@ -34,7 +34,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// new platform adding
} elseif (isset($_POST['new']) && $_POST['new'] === 'true') {
$newPlatform = [
'name' => $_POST['name'],
'name' => $_POST['name'],
'jitsi_url' => $_POST['jitsi_url'],
'jilo_database' => $_POST['jilo_database'],
];
@ -57,9 +57,9 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// an update to an existing agent
} elseif (isset($_POST['agent'])) {
$updatedAgent = [
'id' => $agent,
'agent_type_id' => 1,
'url' => $_POST['url'],
'id' => $agent,
'agent_type_id' => $_POST['type'],
'url' => $_POST['url'],
'secret_key' => $_POST['secret_key'],
];
$result = $agentObject->editAgent($platform_id, $updatedAgent);
@ -73,7 +73,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
} else {
$platform = $_POST['platform'];
$updatedPlatform = [
'name' => $_POST['name'],
'name' => $_POST['name'],
'jitsi_url' => $_POST['jitsi_url'],
'jilo_database' => $_POST['jilo_database'],
];
@ -126,6 +126,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
default:
switch ($action) {
case 'add-agent':
$jilo_agent_types = $agentObject->getAgentTypes();
include '../app/templates/config-add-agent.php';
break;
case 'add':
@ -134,6 +135,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
case 'edit':
if (isset($_GET['agent'])) {
$agentDetails = $agentObject->getAgentDetails($platform_id, $agent);
$jilo_agent_types = $agentObject->getAgentTypes();
include '../app/templates/config-edit-agent.php';
} else {
include '../app/templates/config-edit-platform.php';

View File

@ -3,7 +3,7 @@
<div class="card text-center w-50 mx-auto">
<p class="h4 card-header">Add new Jilo Agent to Jitsi platform "<strong><?= htmlspecialchars($platformDetails[0]['name']) ?></strong>"</p>
<div class="card-body">
<!--p class="card-text">add new platform:</p-->
<!--p class="card-text">add new agent:</p-->
<form method="POST" action="<?= $app_root ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=config">
<div class="row mb-3">
@ -12,7 +12,14 @@
<span class="text-danger" style="margin-right: -12px;">*</span>
</div>
<div class="col-md-8">
<input class="form-control" type="text" name="type" value="" required autofocus />
<select class="form-control" type="text" name="type" id="agent_type_id" required>
<option></option>
<?php foreach ($jilo_agent_types as $agent_type) { ?>
<option value="<?= $agent_type['id']?>">
<?= $agent_type['description'] ?>
</option>
<?php } ?>
</select>
<p class="text-start"><small>type of agent (meet, jvb, jibri, all)</small></p>
</div>
</div>

View File

@ -12,7 +12,14 @@
<span class="text-danger" style="margin-right: -12px;">*</span>
</div>
<div class="col-md-8">
<input class="form-control" type="text" name="type_id" value="<?= htmlspecialchars($agentDetails[0]['agent_type_id'])?>" required autofocus />
<select class="form-control" type="text" name="type" id="agent_type_id" required>
<option></option>
<?php foreach ($jilo_agent_types as $agent_type) { ?>
<option value="<?= $agent_type['id']?>" <?php if ($agentDetails[0]['agent_type_id'] === $agent_type['id']) echo 'selected'; ?>>
<?= $agent_type['description'] ?>
</option>
<?php } ?>
</select>
<p class="text-start"><small>type of agent (meet, jvb, jibri, all)</small></p>
</div>
</div>