Skip to content

Commit

Permalink
Refactor avconfig details showform to reduce redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Hamon committed Dec 13, 2016
1 parent bab29ed commit 9109b68
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions inc/avconfigdetail.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,36 +121,35 @@ function showForm($id, $options = array())
echo "<th >" . __('Value', 'armadito') . "</th>";
echo "</tr>";

$agent_entries = $this->findEntries($agent_id);
$this->showEntriesForAgent($agent_id);
$this->showEntriesForAgent(0);

echo "<tr class='tab_bg_1'>";
echo "<th colspan='2' > Configuration specific to agent n° ". htmlspecialchars($agent_id) ."</th>";
echo "</tr>";
echo "</table>";
}

foreach ($agent_entries as $data) {
echo "<tr class='tab_bg_1'>";
echo "<td align='center'>" . htmlspecialchars($data["type"]) . "</td>";
echo "<td align='center'>" . htmlspecialchars($data["value"]) . "</td>";
echo "</tr>";
}

$common_entries = $this->findEntries(0);
function showEntriesForAgent($agent_id)
{
$agent_entries = $this->findEntries($agent_id);
$table_header = "Configuration specific to agent n° ". htmlspecialchars($agent_id);

if($agent_id == 0) {
$table_header = "Common configuration";
}

echo "<tr class='tab_bg_1'>";
echo "<th colspan='2' > Common configuration </th>";
echo "<th colspan='2' >".$table_header."</th>";
echo "</tr>";

foreach ($common_entries as $data) {
foreach ($agent_entries as $data) {
echo "<tr class='tab_bg_1'>";
echo "<td align='center'>" . htmlspecialchars($data["type"]) . "</td>";
echo "<td align='center'>" . htmlspecialchars($data["value"]) . "</td>";
echo "</tr>";
}


echo "</table>";
}


function findEntries($agent_id)
{
global $DB;
Expand Down

0 comments on commit 9109b68

Please sign in to comment.