From d22fc18f5109c85dad2bfe117924d479d80992c5 Mon Sep 17 00:00:00 2001 From: Rosiak Date: Sun, 3 Jan 2016 02:12:41 +0100 Subject: [PATCH 1/2] Add Port Notes Field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a “Notes” field for ports to accommodate #1897 --- html/includes/forms/update-port-notes.inc.php | 32 +++++++++++ html/pages/device/port.inc.php | 1 + html/pages/device/port/notes.inc.php | 56 +++++++++++++++++++ sql-schema/085.sql | 1 + 4 files changed, 90 insertions(+) create mode 100644 html/includes/forms/update-port-notes.inc.php create mode 100644 html/pages/device/port/notes.inc.php create mode 100644 sql-schema/085.sql diff --git a/html/includes/forms/update-port-notes.inc.php b/html/includes/forms/update-port-notes.inc.php new file mode 100644 index 000000000..8100cedb6 --- /dev/null +++ b/html/includes/forms/update-port-notes.inc.php @@ -0,0 +1,32 @@ + + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +$status = 'error'; +$message = 'unknown error'; + +$port_id = mres($_POST['port_id']); +$notes = mres($_POST['notes']); + +if (isset($notes) && (dbUpdate(array('notes' => $notes), 'ports', 'port_id = ?', array($port_id)))) { + $status = 'ok'; + $message = 'Updated'; +} +else { + $status = 'error'; + $message = 'ERROR: Could not update'; +} +die(json_encode(array( + 'status' => $status, + 'message' => $message, + 'notes' => $notes, + 'port_id' => $port_id +))); diff --git a/html/pages/device/port.inc.php b/html/pages/device/port.inc.php index bdaacd127..b00b36855 100644 --- a/html/pages/device/port.inc.php +++ b/html/pages/device/port.inc.php @@ -73,6 +73,7 @@ $menu_options['realtime'] = 'Real time'; // FIXME CONDITIONAL $menu_options['arp'] = 'ARP Table'; $menu_options['events'] = 'Eventlog'; +$menu_options['notes'] = 'Notes'; if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = '".$port['port_id']."'")) { $menu_options['adsl'] = 'ADSL'; diff --git a/html/pages/device/port/notes.inc.php b/html/pages/device/port/notes.inc.php new file mode 100644 index 000000000..87a637f7f --- /dev/null +++ b/html/pages/device/port/notes.inc.php @@ -0,0 +1,56 @@ + + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ +$pagetitle[] = 'Notes'; +$data = dbFetchRow("SELECT `notes` FROM `ports` WHERE port_id = ?", array( + $port['port_id'] +)); +?> + +
+

Port Notes

+
+
+
+ +
+
+
+
+ Submit + '; +?> +
+
+
+ diff --git a/sql-schema/085.sql b/sql-schema/085.sql new file mode 100644 index 000000000..181ad4c52 --- /dev/null +++ b/sql-schema/085.sql @@ -0,0 +1 @@ +ALTER TABLE `ports` ADD COLUMN `notes` text; From 869234579a4fa02705ad2613bdd7faf3586d6f07 Mon Sep 17 00:00:00 2001 From: Rosiak Date: Mon, 4 Jan 2016 20:23:32 +0100 Subject: [PATCH 2/2] Convert to device_attribs --- html/includes/forms/update-port-notes.inc.php | 13 ++++++++----- html/pages/device/port/notes.inc.php | 15 ++++++++------- sql-schema/085.sql | 1 - 3 files changed, 16 insertions(+), 13 deletions(-) delete mode 100644 sql-schema/085.sql diff --git a/html/includes/forms/update-port-notes.inc.php b/html/includes/forms/update-port-notes.inc.php index 8100cedb6..9678cab64 100644 --- a/html/includes/forms/update-port-notes.inc.php +++ b/html/includes/forms/update-port-notes.inc.php @@ -13,10 +13,11 @@ $status = 'error'; $message = 'unknown error'; -$port_id = mres($_POST['port_id']); -$notes = mres($_POST['notes']); +$device_id = mres($_POST['device_id']); +$port_id_notes = mres($_POST['port_id_notes']); +$attrib_value = mres($_POST['notes']); -if (isset($notes) && (dbUpdate(array('notes' => $notes), 'ports', 'port_id = ?', array($port_id)))) { +if (isset($attrib_value) && set_dev_attrib(array('device_id' => $device_id), $port_id_notes, $attrib_value)) { $status = 'ok'; $message = 'Updated'; } @@ -27,6 +28,8 @@ else { die(json_encode(array( 'status' => $status, 'message' => $message, - 'notes' => $notes, - 'port_id' => $port_id + 'attrib_type' => $port_id_notes, + 'attrib_value' => $attrib_value, + 'device_id' => $device_id + ))); diff --git a/html/pages/device/port/notes.inc.php b/html/pages/device/port/notes.inc.php index 87a637f7f..4ca852897 100644 --- a/html/pages/device/port/notes.inc.php +++ b/html/pages/device/port/notes.inc.php @@ -10,9 +10,9 @@ * the source code distribution for details. */ $pagetitle[] = 'Notes'; -$data = dbFetchRow("SELECT `notes` FROM `ports` WHERE port_id = ?", array( - $port['port_id'] -)); +$port_id_notes = 'port_id_notes:' . $port['port_id']; +$device_id = $device['device_id']; +$data = get_dev_attrib($device,$port_id_notes); ?>
@@ -21,14 +21,14 @@ $data = dbFetchRow("SELECT `notes` FROM `ports` WHERE port_id = ?", array(
+echo htmlentities($data); ?>
Submit + '; ?>
@@ -38,12 +38,13 @@ echo ' $("[name='btn-update-notes']").on('click', function(event) { event.preventDefault(); var $this = $(this); - var port_id = $(this).data("port_id"); + var device_id = ""; + var port_id_notes = ""; var notes = $("#port-notes").val(); $.ajax({ type: 'POST', url: 'ajax_form.php', - data: { type: "update-port-notes", notes: notes, port_id: port_id}, + data: { type: "update-port-notes", notes: notes, port_id_notes: port_id_notes, device_id: device_id }, dataType: "html", success: function(data){ toastr.success('Saved'); diff --git a/sql-schema/085.sql b/sql-schema/085.sql deleted file mode 100644 index 181ad4c52..000000000 --- a/sql-schema/085.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `ports` ADD COLUMN `notes` text;