diff --git a/groups-clients.php b/groups-clients.php
index 53aa7e3f..259ccd01 100644
--- a/groups-clients.php
+++ b/groups-clients.php
@@ -30,11 +30,12 @@
+
+
' + data.name + "";
$("td:eq(0)", row).html(ip_name);
- $("td:eq(1)", row).empty();
- $("td:eq(1)", row).append(
+ $("td:eq(1)", row).html(
+ ''
+ );
+ $("#comment", row).val(data.comment);
+ $("#comment", row).on("change", editClient);
+
+ $("td:eq(2)", row).empty();
+ $("td:eq(2)", row).append(
''
@@ -161,7 +176,7 @@ function initTable() {
'">' +
'' +
"";
- $("td:eq(2)", row).html(button);
+ $("td:eq(3)", row).html(button);
},
dom:
"<'row'<'col-sm-4'l><'col-sm-8'f>>" +
@@ -212,6 +227,7 @@ function initTable() {
function addClient() {
var ip = $("#select").val();
+ var comment = $("#new_comment").val();
if (ip === "custom") {
ip = $("#ip-custom").val();
}
@@ -229,7 +245,7 @@ function addClient() {
url: "scripts/pi-hole/php/groups.php",
method: "post",
dataType: "json",
- data: { action: "add_client", ip: ip, token: token },
+ data: { action: "add_client", ip: ip, comment: comment, token: token },
success: function(response) {
utils.enableAll();
if (response.success) {
@@ -255,12 +271,16 @@ function editClient() {
var groups = tr.find("#multiselect").val();
var ip = tr.find("#ip").text();
var name = tr.find("#name").text();
+ var comment = tr.find("#comment").val();
var done = "edited";
var not_done = "editing";
if (elem === "multiselect") {
done = "edited groups of";
not_done = "editing groups of";
+ } else if (elem === "comment") {
+ done = "edited comment of";
+ not_done = "editing comment of";
}
var ip_name = ip;
@@ -274,7 +294,13 @@ function editClient() {
url: "scripts/pi-hole/php/groups.php",
method: "post",
dataType: "json",
- data: { action: "edit_client", id: id, groups: groups, token: token },
+ data: {
+ action: "edit_client",
+ id: id,
+ groups: groups,
+ token: token,
+ comment: comment
+ },
success: function(response) {
utils.enableAll();
if (response.success) {
diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php
index ad606110..8ede068b 100644
--- a/scripts/pi-hole/php/groups.php
+++ b/scripts/pi-hole/php/groups.php
@@ -232,7 +232,7 @@ if ($_POST['action'] == 'get_groups') {
} elseif ($_POST['action'] == 'add_client') {
// Add new client
try {
- $stmt = $db->prepare('INSERT INTO client (ip) VALUES (:ip)');
+ $stmt = $db->prepare('INSERT INTO client (ip,comment) VALUES (:ip,:comment)');
if (!$stmt) {
throw new Exception('While preparing statement: ' . $db->lastErrorMsg());
}
@@ -241,6 +241,15 @@ if ($_POST['action'] == 'get_groups') {
throw new Exception('While binding ip: ' . $db->lastErrorMsg());
}
+ $comment = $_POST['comment'];
+ if (strlen($comment) == 0) {
+ // Store NULL in database for empty comments
+ $comment = null;
+ }
+ if (!$stmt->bindValue(':comment', $comment, SQLITE3_TEXT)) {
+ throw new Exception('While binding comment: ' . $db->lastErrorMsg());
+ }
+
if (!$stmt->execute()) {
throw new Exception('While executing: ' . $db->lastErrorMsg());
}
@@ -253,6 +262,28 @@ if ($_POST['action'] == 'get_groups') {
} elseif ($_POST['action'] == 'edit_client') {
// Edit client identified by ID
try {
+ $stmt = $db->prepare('UPDATE client SET comment=:comment WHERE id = :id');
+ if (!$stmt) {
+ throw new Exception('While preparing statement: ' . $db->lastErrorMsg());
+ }
+
+ $comment = $_POST['comment'];
+ if (strlen($comment) == 0) {
+ // Store NULL in database for empty comments
+ $comment = null;
+ }
+ if (!$stmt->bindValue(':comment', $comment, SQLITE3_TEXT)) {
+ throw new Exception('While binding comment: ' . $db->lastErrorMsg());
+ }
+
+ if (!$stmt->bindValue(':id', intval($_POST['id']), SQLITE3_INTEGER)) {
+ throw new Exception('While binding id: ' . $db->lastErrorMsg());
+ }
+
+ if (!$stmt->execute()) {
+ throw new Exception('While executing: ' . $db->lastErrorMsg());
+ }
+
$stmt = $db->prepare('DELETE FROM client_by_group WHERE client_id = :id');
if (!$stmt) {
throw new Exception('While preparing DELETE statement: ' . $db->lastErrorMsg());