Add UI Elements for Asset Notes similar to contact notes

This commit is contained in:
johnnyq
2026-07-29 14:13:55 -04:00
parent bb1f0d5489
commit fc5cdeea82
8 changed files with 386 additions and 0 deletions

View File

@@ -262,6 +262,23 @@ if (isset($_GET['asset_id'])) {
$linked_services = array();
// Notes - 1 to many relationship
$sql_related_notes = mysqli_query($mysqli, "SELECT * FROM asset_notes
LEFT JOIN users ON asset_note_created_by = user_id
WHERE asset_note_asset_id = $asset_id
AND asset_note_archived_at IS NULL
ORDER BY asset_note_created_at DESC"
);
$note_count = mysqli_num_rows($sql_related_notes);
// Note type icons, read from the categories list so the seeded icons
// stay the single source of truth
$note_type_icons = array();
$sql_note_type_icons = mysqli_query($mysqli, "SELECT category_name, category_icon FROM categories WHERE category_type = 'asset_note_type'");
while ($row = mysqli_fetch_assoc($sql_note_type_icons)) {
$note_type_icons[escapeHtml($row['category_name'])] = escapeHtml($row['category_icon']);
}
?>
<div class="row">
@@ -416,6 +433,11 @@ if (isset($_GET['asset_id'])) {
<a class="dropdown-item text-dark ajax-modal" href="#" data-modal-url="modals/file/file_upload.php?<?= $client_url ?>&asset_id=<?= $asset_id ?>">
<i class="fa fa-fw fa-upload mr-2"></i>Upload file(s)
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-dark ajax-modal" href="#"
data-modal-url="modals/asset/asset_note_add.php?id=<?= $asset_id ?>">
<i class="fas fa-fw fa-sticky-note mr-2"></i>New Note
</a>
</div>
</div>
@@ -1213,6 +1235,80 @@ if (isset($_GET['asset_id'])) {
</div>
</div>
<div class="card card-dark <?php if ($note_count == 0) { echo "d-none"; } ?>">
<div class="card-header py-2">
<h3 class="card-title mt-2"><i class="fa fa-fw fa-sticky-note mr-2"></i>Notes</h3>
<div class="card-tools">
<button type="button" class="btn btn-primary ajax-modal"
data-modal-url="modals/asset/asset_note_add.php?id=<?= $asset_id ?>">
<i class="fas fa-plus mr-2"></i>New Note
</button>
</div>
</div>
<div class="card-body">
<div class="table-responsive-sm">
<table class="table table-striped table-borderless table-hover dataTables" style="width:100%">
<thead class="text-dark">
<tr>
<th>Type</th>
<th>Note</th>
<th>By</th>
<th>Created</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_assoc($sql_related_notes)) {
$asset_note_id = intval($row['asset_note_id']);
$asset_note_type = escapeHtml($row['asset_note_type']);
$asset_note = nl2br(escapeHtml($row['asset_note']));
$note_by = escapeHtml($row['user_name']);
$asset_note_created_at = escapeHtml($row['asset_note_created_at']);
// Get the corresponding icon for the note type
$note_type_icon = !empty($note_type_icons[$asset_note_type]) ? $note_type_icons[$asset_note_type] : 'fa-sticky-note';
?>
<tr>
<td><i class="fa fa-fw <?= $note_type_icon ?> mr-2"></i><?= $asset_note_type ?></td>
<td><?= $asset_note ?></td>
<td><?= $note_by ?></td>
<td><?= $asset_note_created_at ?></td>
<td>
<div class="dropdown dropleft text-center">
<button class="btn btn-secondary btn-sm" type="button" data-toggle="dropdown">
<i class="fas fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-item text-danger" href="post.php?archive_asset_note=<?= $asset_note_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-archive mr-2"></i>Archive
</a>
<?php if (lookupUserPermission("module_support") >= 3) { ?>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger text-bold" href="post.php?delete_asset_note=<?= $asset_note_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-trash mr-2"></i>Delete
</a>
<?php } ?>
</div>
</div>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>

View File

@@ -218,6 +218,22 @@ $sql_related_software = mysqli_query(
$software_count = mysqli_num_rows($sql_related_software);
// Related Notes
$sql_related_notes = mysqli_query($mysqli, "SELECT * FROM asset_notes
LEFT JOIN users ON asset_note_created_by = user_id
WHERE asset_note_asset_id = $asset_id
AND asset_note_archived_at IS NULL
ORDER BY asset_note_created_at DESC"
);
$note_count = mysqli_num_rows($sql_related_notes);
// Note type icons, read from the categories list
$note_type_icons = array();
$sql_note_type_icons = mysqli_query($mysqli, "SELECT category_name, category_icon FROM categories WHERE category_type = 'asset_note_type'");
while ($row = mysqli_fetch_assoc($sql_note_type_icons)) {
$note_type_icons[escapeHtml($row['category_name'])] = escapeHtml($row['category_icon']);
}
if (isset($_GET['client_id'])) {
$client_url = "client_id=$client_id&";
} else {
@@ -293,6 +309,13 @@ ob_start();
<i class="fas fa-fw fa-briefcase mr-2"></i>Files (<?= $file_count ?>)</a>
</li>
<?php } ?>
<?php if ($note_count) { ?>
<li class="nav-item">
<a class="nav-link" data-toggle="pill" href="#pills-asset-notes">
<i class="fas fa-fw fa-sticky-note mr-2"></i>Notes (<?= $note_count ?>)
</a>
</li>
<?php } ?>
</ul>
<hr>
@@ -913,6 +936,47 @@ ob_start();
</div>
<?php } ?>
<?php if ($note_count) { ?>
<div class="tab-pane fade" id="pills-asset-notes">
<div class="table-responsive-sm">
<table class="table table-sm table-striped table-borderless table-hover">
<thead class="text-dark">
<tr>
<th>Type</th>
<th>Note</th>
<th>By</th>
<th>Created</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_assoc($sql_related_notes)) {
$asset_note_type = escapeHtml($row['asset_note_type']);
$asset_note = nl2br(escapeHtml($row['asset_note']));
$note_by = escapeHtml($row['user_name']);
$asset_note_created_at = escapeHtml($row['asset_note_created_at']);
$note_type_icon = !empty($note_type_icons[$asset_note_type]) ? $note_type_icons[$asset_note_type] : 'fa-sticky-note';
?>
<tr>
<td><i class="fa fa-fw <?= $note_type_icon ?> mr-2"></i><?= $asset_note_type ?></td>
<td><?= $asset_note ?></td>
<td><?= $note_by ?></td>
<td><?= $asset_note_created_at ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<?php } ?>
</div>
</div>

View File

@@ -0,0 +1,70 @@
<?php
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support', 2);
$asset_id = intval($_GET['id']);
$sql = mysqli_query($mysqli, "SELECT asset_name, asset_client_id FROM assets WHERE asset_id = $asset_id LIMIT 1");
$row = mysqli_fetch_assoc($sql);
$asset_name = escapeHtml($row['asset_name']);
$client_id = intval($row['asset_client_id']);
enforceClientAccess();
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class='fa fa-fw fa-sticky-note mr-2'></i>Creating note: <strong><?= $asset_name ?></strong></h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="asset_id" value="<?= $asset_id ?>">
<div class="modal-body">
<div class="form-group">
<label>Type</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-comment"></i></span>
</div>
<select class="form-control select2" name="type">
<?php
$sql_asset_note_types_select = mysqli_query($mysqli, "
SELECT category_name FROM categories
WHERE category_type = 'asset_note_type'
AND category_archived_at IS NULL
ORDER BY category_order ASC, category_name ASC
");
while ($row = mysqli_fetch_assoc($sql_asset_note_types_select)) {
$asset_note_type_select = escapeHtml($row['category_name']);
?>
<option><?= $asset_note_type_select ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<textarea class="form-control" rows="6" name="note" placeholder="Notes, eg what was done, parts replaced, config changed, etc"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="add_asset_note" class="btn btn-primary text-bold"><i class="fas fa-check mr-2"></i>Create</button>
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -231,6 +231,121 @@ if (isset($_GET['delete_asset'])) {
}
if (isset($_POST['add_asset_note'])) {
validateCSRFToken();
enforceUserPermission('module_support', 2);
$asset_id = intval($_POST['asset_id']);
$type = escapeSql($_POST['type']);
$note = escapeSql($_POST['note']);
// Get Asset details for logging and alerting
$sql = mysqli_query($mysqli,"SELECT asset_name, asset_client_id FROM assets WHERE asset_id = $asset_id");
$row = mysqli_fetch_assoc($sql);
$asset_name = escapeSql($row['asset_name']);
$client_id = intval($row['asset_client_id']);
enforceClientAccess();
mysqli_query($mysqli, "INSERT INTO asset_notes SET asset_note_type = '$type', asset_note = '$note', asset_note_created_by = $session_user_id, asset_note_asset_id = $asset_id");
$asset_note_id = mysqli_insert_id($mysqli);
//Logging
logAudit("Asset", "Edit", "$session_name created a $type note for asset $asset_name", $client_id, $asset_id);
$_SESSION['alert_message'] = "Note <strong>$type</strong> created for <strong>$asset_name</strong>";
redirect();
}
if (isset($_GET['archive_asset_note'])) {
validateCSRFToken();
enforceUserPermission('module_support', 2);
$asset_note_id = intval($_GET['archive_asset_note']);
// Get Asset Name and Client ID for logging and alert message
$sql = mysqli_query($mysqli,"SELECT asset_note_type, asset_id, asset_name, asset_client_id FROM asset_notes LEFT JOIN assets ON asset_id = asset_note_asset_id WHERE asset_note_id = $asset_note_id");
$row = mysqli_fetch_assoc($sql);
$asset_note_type = escapeSql($row['asset_note_type']);
$asset_name = escapeSql($row['asset_name']);
$client_id = intval($row['asset_client_id']);
$asset_id = intval($row['asset_id']);
enforceClientAccess();
mysqli_query($mysqli,"UPDATE asset_notes SET asset_note_archived_at = NOW() WHERE asset_note_id = $asset_note_id");
logAudit("Asset", "Edit", "$session_name archived note $asset_note_type for $asset_name", $client_id, $asset_id);
flashAlert("Note <strong>$asset_note_type</strong> archived", 'error');
redirect();
}
if (isset($_GET['restore_asset_note'])) {
validateCSRFToken();
enforceUserPermission('module_support', 2);
$asset_note_id = intval($_GET['restore_asset_note']);
// Get Asset Name and Client ID for logging and alert message
$sql = mysqli_query($mysqli,"SELECT asset_note_type, asset_id, asset_name, asset_client_id FROM asset_notes LEFT JOIN assets ON asset_id = asset_note_asset_id WHERE asset_note_id = $asset_note_id");
$row = mysqli_fetch_assoc($sql);
$asset_note_type = escapeSql($row['asset_note_type']);
$asset_name = escapeSql($row['asset_name']);
$client_id = intval($row['asset_client_id']);
$asset_id = intval($row['asset_id']);
enforceClientAccess();
mysqli_query($mysqli,"UPDATE asset_notes SET asset_note_archived_at = NULL WHERE asset_note_id = $asset_note_id");
logAudit("Asset", "Edit", "$session_name restored note $asset_note_type for $asset_name", $client_id, $asset_id);
flashAlert("Note <strong>$asset_note_type</strong> restored");
redirect();
}
if (isset($_GET['delete_asset_note'])) {
validateCSRFToken();
enforceUserPermission('module_support', 3);
$asset_note_id = intval($_GET['delete_asset_note']);
// Get Asset Name and Client ID for logging and alert message
$sql = mysqli_query($mysqli,"SELECT asset_note_type, asset_id, asset_name, asset_client_id FROM asset_notes LEFT JOIN assets ON asset_id = asset_note_asset_id WHERE asset_note_id = $asset_note_id");
$row = mysqli_fetch_assoc($sql);
$asset_note_type = escapeSql($row['asset_note_type']);
$asset_name = escapeSql($row['asset_name']);
$client_id = intval($row['asset_client_id']);
$asset_id = intval($row['asset_id']);
enforceClientAccess();
mysqli_query($mysqli,"DELETE FROM asset_notes WHERE asset_note_id = $asset_note_id");
logAudit("Asset", "Edit", "$session_name deleted $asset_note_type note for $asset_name", $client_id, $asset_id);
flashAlert("Note <strong>$asset_note_type</strong> deleted.", 'error');
redirect();
}
if (isset($_POST['bulk_assign_asset_tags'])) {
validateCSRFToken();