mirror of
https://github.com/itflow-org/itflow
synced 2026-11-22 04:17:24 +00:00
Files and documents overhaul: rebuilt files list with folder tree (counts, open/close remembered, phone collapse), current folder path and folder menu, All/Documents/Uploads tabs with counts, colour-coded type tiles, shared and portal pills, updated time and author, linked record counts, permission-gated row menus, search across every folder from the top level showing where each result lives, grid view with real previews (image thumbnails, PDF first page, document and text excerpts) and an arrow-key previewer with a Details button, drag and drop files onto the list to upload into the folder on show, bulk move/archive/restore/delete for files and documents together; document page rebuilt like the asset and contact pages with header actions (Edit, Share, PDF, Print, Rename, Move, Link, portal visibility, Archive, Delete), Linked card, folder and portal card and a History card where versions can be viewed, restored (current content kept as a version) or deleted, revision table moved to print only; new file quick look with preview, folder, uploader, share status and links; document quick look and version viewer redone; one link modal for every relation (files, documents, assets, contacts, licenses, vendors) with type tabs and multi-select, offering only the client's own unarchived, not yet linked records, old link modals now open it; upload modal with drop box, file list and size checks; new and edit document share one form with folder and client portal switch; template, rename, move, bulk move, visibility and folder add/rename/delete modals modernized with folder tree pickers; asset and contact pages show the same file and document tiles and open the file quick look; fixes: folder, contact and asset ownership checked on upload, new document, template, move and bulk move, links limited to records of the same client, linking an existing link no longer errors, deleting a folder now moves its files, documents and subfolders up instead of orphaning them, file delete confirmation no longer builds its name into inline JS, permission checks added to the upload, new document, folder, visibility and link modals, upload modal script error that skipped the size check, skipped uploads now reported, mime type read from the uploaded file, per-row link modals that broke grid view, search with quotes double escaped, document search text stored without tags and with words spaced, bulk messages with empty counts, visibility wording, file rename icon, PDF export redirecting after output and needing write access, file and document deletes now remove their links and skip missing files on disk, duplicate asset to file link handler removed; developer: new functions/links.php (relation registry, linkAdd, linkRemove, linkRemoveAll, linkedRecords, linkCandidates, linkGroupsHtml), post/link.php with link_items and unlink_item plus the legacy link and unlink names, functions/files.php gains fileTypeInfo, fileTypeTile, documentTile, folderTree, folderPath, folderSubtree, folderOptionsHtml, folderOwnedId, delete helpers, documentContentRaw and documentHtmlPurify, new agent/js/files.js, modals/link/link.php, modals/file/file.php, modals/folder/folder_delete.php and modals/document/document_form.php, removed unused document_bulk_move.php, document_add_file_relation.php and js/file_delete_modal.js
This commit is contained in:
@@ -900,7 +900,8 @@ if (isset($_GET['get_canned_response'])) {
|
||||
* and agent/document.php do it.
|
||||
*/
|
||||
if (isset($_GET['get_document_content'])) {
|
||||
enforceUserPermission('module_support');
|
||||
// Whoever can open the files list can preview its documents in the grid
|
||||
enforceUserPermission('module_client');
|
||||
|
||||
$document_id = intval($_GET['get_document_content']);
|
||||
|
||||
@@ -917,15 +918,8 @@ if (isset($_GET['get_document_content'])) {
|
||||
$client_id = intval($document_row['document_client_id']);
|
||||
enforceClientAccess();
|
||||
|
||||
require_once "../libs/htmlpurifier/HTMLPurifier.standalone.php";
|
||||
|
||||
$document_purifier_config = HTMLPurifier_Config::createDefault();
|
||||
$document_purifier_config->set('Cache.DefinitionImpl', null);
|
||||
$document_purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
|
||||
$document_purifier = new HTMLPurifier($document_purifier_config);
|
||||
|
||||
$response['name'] = $document_row['document_name'];
|
||||
$response['content'] = $document_purifier->purify($document_row['document_content']);
|
||||
$response['content'] = documentHtmlPurify($document_row['document_content']);
|
||||
} else {
|
||||
$response['name'] = '';
|
||||
$response['content'] = '';
|
||||
|
||||
@@ -356,7 +356,7 @@ if (mysqli_num_rows($sql) == 0) {
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/asset/asset_interface_add.php?&asset_id=<?= $asset_id ?>">
|
||||
<i class="fa fa-fw fa-ethernet text-secondary me-2"></i>Interface
|
||||
</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/document/document_add.php?<?= $client_url ?>&asset_id=<?= $asset_id ?>" data-modal-size="lg">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/document/document_add.php?<?= $client_url ?>&asset_id=<?= $asset_id ?>" data-modal-size="xl">
|
||||
<i class="fa fa-fw fa-file-alt text-secondary me-2"></i>Document
|
||||
</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/file/file_upload.php?<?= $client_url ?>&asset_id=<?= $asset_id ?>">
|
||||
@@ -1039,7 +1039,7 @@ if (mysqli_num_rows($sql) == 0) {
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary ajax-modal" data-modal-url="modals/asset/asset_link_document.php?id=<?= $asset_id ?>">
|
||||
<i class="fas fa-link me-2"></i>Link
|
||||
</button>
|
||||
<button type="button" class="btn btn-sm btn-primary ajax-modal" data-modal-size="lg" data-modal-url="modals/document/document_add.php?<?= $client_url ?>&asset_id=<?= $asset_id ?>">
|
||||
<button type="button" class="btn btn-sm btn-primary ajax-modal" data-modal-size="xl" data-modal-url="modals/document/document_add.php?<?= $client_url ?>&asset_id=<?= $asset_id ?>">
|
||||
<i class="fas fa-plus me-2"></i>New Document
|
||||
</button>
|
||||
</div>
|
||||
@@ -1066,8 +1066,13 @@ if (mysqli_num_rows($sql) == 0) {
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<a class="fw-semibold" href="document.php?client_id=<?= $client_id ?>&document_id=<?= $document_id ?>"><?= $document_name ?></a>
|
||||
<?php if ($document_description) { ?><div class="small text-body-secondary"><?= $document_description ?></div><?php } ?>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<?= documentTile('sm') ?>
|
||||
<div class="min-w-0">
|
||||
<a class="fw-semibold" href="document.php?client_id=<?= $client_id ?>&document_id=<?= $document_id ?>"><?= $document_name ?></a>
|
||||
<?php if ($document_description) { ?><div class="small text-body-secondary"><?= $document_description ?></div><?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td><?= $document_created_by ?></td>
|
||||
<td class="text-nowrap small" title="<?= $document_updated_at ?>"><?= timeAgo($document_updated_at) ?></td>
|
||||
@@ -1103,13 +1108,6 @@ if (mysqli_num_rows($sql) == 0) {
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php if ($files_count) {
|
||||
$file_icons = [
|
||||
'pdf' => 'file-pdf', 'gz' => 'file-archive', 'tar' => 'file-archive', 'zip' => 'file-archive', '7z' => 'file-archive', 'rar' => 'file-archive',
|
||||
'txt' => 'file-alt', 'md' => 'file-alt', 'msg' => 'envelope', 'doc' => 'file-word', 'docx' => 'file-word', 'odt' => 'file-word',
|
||||
'xls' => 'file-excel', 'xlsx' => 'file-excel', 'ods' => 'file-excel', 'csv' => 'file-csv', 'pptx' => 'file-powerpoint', 'odp' => 'file-powerpoint',
|
||||
'mp3' => 'file-audio', 'wav' => 'file-audio', 'ogg' => 'file-audio', 'mov' => 'file-video', 'mp4' => 'file-video', 'av1' => 'file-video',
|
||||
'jpg' => 'file-image', 'jpeg' => 'file-image', 'png' => 'file-image', 'gif' => 'file-image', 'webp' => 'file-image', 'bmp' => 'file-image', 'tif' => 'file-image',
|
||||
];
|
||||
?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
@@ -1125,13 +1123,17 @@ if (mysqli_num_rows($sql) == 0) {
|
||||
$file_id = intval($row['file_id']);
|
||||
$file_name = escapeHtml($row['file_name']);
|
||||
$file_description = escapeHtml($row['file_description']);
|
||||
$file_icon = $file_icons[strtolower((string) $row['file_ext'])] ?? 'file';
|
||||
$file_created_at = escapeHtml($row['file_created_at']);
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<i class="far fa-fw fa-<?= $file_icon ?> text-secondary me-2"></i><a class="fw-semibold" href="file.php?file_id=<?= $file_id ?>&action=view" target="_blank"><?= $file_name ?></a>
|
||||
<?php if ($file_description) { ?><div class="small text-body-secondary"><?= $file_description ?></div><?php } ?>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<?= fileTypeTile($row['file_ext'], 'sm') ?>
|
||||
<div class="min-w-0">
|
||||
<a class="fw-semibold ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/file/file.php?id=<?= $file_id ?>"><?= $file_name ?></a>
|
||||
<?php if ($file_description) { ?><div class="small text-body-secondary"><?= $file_description ?></div><?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-nowrap small" title="<?= $file_created_at ?>"><?= timeAgo($file_created_at) ?></td>
|
||||
<td class="text-end">
|
||||
|
||||
@@ -291,7 +291,7 @@ if (!$can_support) {
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($can_support_edit) { ?>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/document/document_add.php?<?= $client_url ?>&contact_id=<?= $contact_id ?>" data-modal-size="lg">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/document/document_add.php?<?= $client_url ?>&contact_id=<?= $contact_id ?>" data-modal-size="xl">
|
||||
<i class="fa fa-fw fa-file-alt text-secondary me-2"></i>Document
|
||||
</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/file/file_upload.php?<?= $client_url ?>&contact_id=<?= $contact_id ?>">
|
||||
@@ -767,7 +767,7 @@ if (!$can_support) {
|
||||
<i class="fas fa-link me-2"></i>Link
|
||||
</button>
|
||||
<?php if ($can_support_edit) { ?>
|
||||
<button type="button" class="btn btn-sm btn-primary ajax-modal" data-modal-size="lg" data-modal-url="modals/document/document_add.php?<?= $client_url ?>&contact_id=<?= $contact_id ?>">
|
||||
<button type="button" class="btn btn-sm btn-primary ajax-modal" data-modal-size="xl" data-modal-url="modals/document/document_add.php?<?= $client_url ?>&contact_id=<?= $contact_id ?>">
|
||||
<i class="fas fa-plus me-2"></i>New Document
|
||||
</button>
|
||||
<?php } ?>
|
||||
@@ -780,7 +780,7 @@ if (!$can_support) {
|
||||
$document_id = intval($row['document_id']);
|
||||
$document_last = $row['document_updated_at'] ?: $row['document_created_at']; ?>
|
||||
<div class="list-group-item d-flex align-items-center gap-3 py-2">
|
||||
<i class="fas fa-fw fa-file-alt text-secondary"></i>
|
||||
<?= documentTile('sm') ?>
|
||||
<div class="flex-grow-1 min-w-0">
|
||||
<a class="fw-semibold" href="document.php?client_id=<?= $client_id ?>&document_id=<?= $document_id ?>"><?= escapeHtml($row['document_name']) ?></a>
|
||||
<?php if ($row['document_description']) { ?><div class="small text-body-secondary text-truncate"><?= escapeHtml($row['document_description']) ?></div><?php } ?>
|
||||
@@ -820,9 +820,9 @@ if (!$can_support) {
|
||||
<?php while ($row = mysqli_fetch_assoc($sql_linked_files)) {
|
||||
$file_id = intval($row['file_id']); ?>
|
||||
<div class="list-group-item d-flex align-items-center gap-3 py-2">
|
||||
<i class="fas fa-fw fa-<?= getFileIcon((string) $row['file_ext']) ?> text-secondary"></i>
|
||||
<?= fileTypeTile($row['file_ext'], 'sm') ?>
|
||||
<div class="flex-grow-1 min-w-0">
|
||||
<a class="fw-semibold" href="file.php?file_id=<?= $file_id ?>&action=view" target="_blank" rel="noopener"><?= escapeHtml($row['file_name']) ?></a>
|
||||
<a class="fw-semibold ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/file/file.php?id=<?= $file_id ?>"><?= escapeHtml($row['file_name']) ?></a>
|
||||
<?php if ($row['file_description']) { ?><div class="small text-body-secondary text-truncate"><?= escapeHtml($row['file_description']) ?></div><?php } ?>
|
||||
</div>
|
||||
<span class="small text-body-secondary text-nowrap" title="<?= escapeHtml($row['file_created_at']) ?>"><?= formatBytes($row['file_size']) ?> · <?= timeAgo($row['file_created_at']) ?></span>
|
||||
|
||||
@@ -1,427 +1,236 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* A document - read it, edit it, share or print it, see what it is linked to
|
||||
* and every earlier version of it. Laid out like the asset and contact pages:
|
||||
* a header card with the actions, the content beside a column of what goes
|
||||
* with it.
|
||||
*
|
||||
* Open to anyone with access to the client, like the files list; changing it
|
||||
* takes support write access, like the handlers behind it.
|
||||
*/
|
||||
|
||||
require_once "includes/inc_all_client.php";
|
||||
|
||||
$document_id = intval($_GET['document_id'] ?? 0);
|
||||
|
||||
//Initialize the HTML Purifier to prevent XSS
|
||||
require "../libs/htmlpurifier/HTMLPurifier.standalone.php";
|
||||
|
||||
$purifier_config = HTMLPurifier_Config::createDefault();
|
||||
$purifier_config->set('Cache.DefinitionImpl', null); // Disable cache by setting a non-existent directory or an invalid one
|
||||
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
|
||||
$purifier = new HTMLPurifier($purifier_config);
|
||||
|
||||
if (isset($_GET['document_id'])) {
|
||||
$document_id = intval($_GET['document_id']);
|
||||
}
|
||||
|
||||
$folder_location = 0;
|
||||
|
||||
$sql_document = mysqli_query($mysqli, "SELECT document_archived_at, document_client_visible, document_content, document_created_at,
|
||||
document_created_by, document_description, document_folder_id, document_name,
|
||||
document_updated_at, folder_name, user_name FROM documents
|
||||
LEFT JOIN folders ON document_folder_id = folder_id
|
||||
LEFT JOIN users ON document_created_by = user_id
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT document_archived_at, document_client_visible, document_content, document_created_at,
|
||||
document_description, document_folder_id, document_name, document_updated_at,
|
||||
creator.user_name AS created_by_name, updater.user_name AS updated_by_name
|
||||
FROM documents
|
||||
LEFT JOIN users creator ON document_created_by = creator.user_id
|
||||
LEFT JOIN users updater ON document_updated_by = updater.user_id
|
||||
WHERE document_client_id = $client_id AND document_id = $document_id
|
||||
LIMIT 1"
|
||||
);
|
||||
LIMIT 1"));
|
||||
|
||||
if (mysqli_num_rows($sql_document) == 0) {
|
||||
echo "<center><h1 class='text-secondary mt-5'>Nothing to see here</h1><a class='btn btn-lg btn-secondary mt-3' href='javascript:history.back()'><i class='fa fa-fw fa-arrow-left'></i> Go Back</a></center>";
|
||||
if (!$row) {
|
||||
echo "<div class='text-center'><h1 class='text-secondary mt-5'>Nothing to see here</h1><a class='btn btn-lg btn-secondary mt-3' href='files.php?client_id=$client_id'><i class='fa fa-fw fa-arrow-left me-2'></i>Back to files</a></div>";
|
||||
require_once "../includes/footer.php";
|
||||
exit();
|
||||
}
|
||||
|
||||
$row = mysqli_fetch_assoc($sql_document);
|
||||
$can_edit = lookupUserPermission('module_support') >= 2;
|
||||
$can_delete = lookupUserPermission('module_support') >= 3;
|
||||
|
||||
$folder_name = escapeHtml($row['folder_name']);
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
$document_description = escapeHtml($row['document_description']);
|
||||
$document_content = $purifier->purify($row['document_content']);
|
||||
$document_created_by_id = intval($row['document_created_by']);
|
||||
$document_created_by_name = escapeHtml($row['user_name']);
|
||||
$document_created_at = escapeHtml($row['document_created_at']);
|
||||
$document_updated_at = escapeHtml($row['document_updated_at']);
|
||||
$document_archived_at = escapeHtml($row['document_archived_at']);
|
||||
$document_folder_id = intval($row['document_folder_id']);
|
||||
$document_client_visible = intval($row['document_client_visible']);
|
||||
$document_archived = !empty($row['document_archived_at']);
|
||||
$document_visible = intval($row['document_client_visible']);
|
||||
$document_updated_at = $row['document_updated_at'] ?: $row['document_created_at'];
|
||||
$document_updated_by = escapeHtml($row['updated_by_name'] ?: $row['created_by_name']);
|
||||
|
||||
// Override Tab Title // No Sanitizing needed as this var will opnly be used in the tab title
|
||||
$folder_tree = folderTree($client_id);
|
||||
$document_folder_id = isset($folder_tree[intval($row['document_folder_id'])]) ? intval($row['document_folder_id']) : 0;
|
||||
$folder_path = folderPath($folder_tree, $document_folder_id);
|
||||
|
||||
$versions = [];
|
||||
$sql_versions = mysqli_query($mysqli, "SELECT document_version_id, document_version_name, document_version_description, document_version_created_at, user_name
|
||||
FROM document_versions LEFT JOIN users ON document_version_created_by = user_id
|
||||
WHERE document_version_document_id = $document_id
|
||||
ORDER BY document_version_created_at DESC, document_version_id DESC");
|
||||
while ($version = mysqli_fetch_assoc($sql_versions)) {
|
||||
$versions[] = $version;
|
||||
}
|
||||
|
||||
$csrf = $_SESSION['csrf_token'];
|
||||
|
||||
// Tab title - used raw, the header escapes it
|
||||
$page_title = $row['document_name'];
|
||||
|
||||
?>
|
||||
|
||||
<ol class="breadcrumb d-print-none">
|
||||
<li class="breadcrumb-item">
|
||||
<a href="client_overview.php?client_id=<?= $client_id ?>"><?= $client_name ?></a>
|
||||
</li>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="files.php?client_id=<?= $client_id ?>">Files</a>
|
||||
</li>
|
||||
<?php
|
||||
// Build the full folder path
|
||||
$folder_id = $document_folder_id;
|
||||
$folder_path = array();
|
||||
|
||||
while ($folder_id > 0) {
|
||||
$sql_folder = mysqli_query($mysqli, "SELECT folder_name, parent_folder FROM folders WHERE folder_id = $folder_id");
|
||||
if ($row_folder = mysqli_fetch_assoc($sql_folder)) {
|
||||
$folder_name = escapeHtml($row_folder['folder_name']);
|
||||
$parent_folder = intval($row_folder['parent_folder']);
|
||||
|
||||
// Prepend the folder to the beginning of the array
|
||||
array_unshift($folder_path, array('folder_id' => $folder_id, 'folder_name' => $folder_name));
|
||||
|
||||
// Move up to the parent folder
|
||||
$folder_id = $parent_folder;
|
||||
} else {
|
||||
// If the folder is not found, break the loop
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Output breadcrumb items for each folder in the path
|
||||
foreach ($folder_path as $folder) {
|
||||
$bread_crumb_folder_id = $folder['folder_id']; // Sanitized before put in array
|
||||
$bread_crumb_folder_name = $folder['folder_name']; // Sanitized before put in array
|
||||
?>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="files.php?client_id=<?= $client_id ?>&folder_id=<?= $bread_crumb_folder_id ?>">
|
||||
<i class="fas fa-fw fa-folder-open me-2"></i><?= $bread_crumb_folder_name ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<li class="breadcrumb-item active">
|
||||
<i class="fas fa-file"></i> <?= $document_name ?>
|
||||
<?php if (!empty($document_archived_at)) {
|
||||
echo "<span class='text-danger ms-2'>(ARCHIVED on $document_archived_at)</span>";
|
||||
} ?>
|
||||
</li>
|
||||
<li class="breadcrumb-item"><a href="client_overview.php?client_id=<?= $client_id ?>"><?= $client_name ?></a></li>
|
||||
<li class="breadcrumb-item"><a href="files.php?client_id=<?= $client_id ?>">Files</a></li>
|
||||
<?php foreach ($folder_path as $crumb) { ?>
|
||||
<li class="breadcrumb-item"><a href="files.php?client_id=<?= $client_id ?>&folder_id=<?= $crumb['folder_id'] ?>"><?= escapeHtml($crumb['folder_name']) ?></a></li>
|
||||
<?php } ?>
|
||||
<li class="breadcrumb-item active"><?= $document_name ?></li>
|
||||
</ol>
|
||||
|
||||
<!-- What it is, and what you can do with it -->
|
||||
<div class="card mb-3 itflow-document-head">
|
||||
<div class="card-body d-flex flex-wrap align-items-start gap-3">
|
||||
<?= documentTile('lg') ?>
|
||||
<div class="min-w-0 flex-grow-1">
|
||||
<h1 class="h3 mb-1 d-flex flex-wrap align-items-center column-gap-2">
|
||||
<span class="text-break"><?= $document_name ?></span>
|
||||
<?php if ($document_archived) { ?><span class="badge rounded-pill text-bg-secondary fw-normal fs-6">Archived</span><?php } ?>
|
||||
<?php if ($document_visible) { ?><span class="badge rounded-pill bg-info-subtle text-info-emphasis fw-normal fs-6" title="Technical contacts can read this in the client portal">Portal</span><?php } ?>
|
||||
</h1>
|
||||
<?php if ($document_description) { ?>
|
||||
<div class="text-body-secondary"><?= $document_description ?></div>
|
||||
<?php } ?>
|
||||
<div class="small text-body-secondary mt-1">
|
||||
<span title="<?= escapeHtml($document_updated_at) ?>">Updated <?= timeAgo($document_updated_at) ?></span><?= $document_updated_by ? " by $document_updated_by" : '' ?>
|
||||
· Created <?= date('M j, Y', strtotime($row['document_created_at'])) ?><?= $row['created_by_name'] ? ' by ' . escapeHtml($row['created_by_name']) : '' ?>
|
||||
<?php if ($versions) { ?>· <a class="text-reset" href="#documentHistory"><?= count($versions) ?> earlier version<?= count($versions) === 1 ? '' : 's' ?></a><?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex flex-wrap gap-2 d-print-none">
|
||||
<?php if ($can_edit && !$document_archived) { ?>
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-size="xl" data-modal-url="modals/document/document_edit.php?id=<?= $document_id ?>">
|
||||
<i class="fas fa-edit me-2"></i>Edit
|
||||
</button>
|
||||
<?php } ?>
|
||||
<?php if (!$document_archived) { ?>
|
||||
<button type="button" class="btn btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#shareModal" onclick="populateShareModal(<?= "$client_id, 'Document', $document_id" ?>)" title="Share a link to it">
|
||||
<i class="fas fa-share me-2"></i>Share
|
||||
</button>
|
||||
<?php } ?>
|
||||
<a class="btn btn-outline-secondary" href="post.php?export_document=<?= $document_id ?>&csrf_token=<?= $csrf ?>" title="Export as PDF"><i class="fas fa-file-pdf"></i><span class="d-none d-md-inline ms-2">PDF</span></a>
|
||||
<button type="button" class="btn btn-outline-secondary" onclick="window.print();" title="Print"><i class="fas fa-print"></i></button>
|
||||
<?php if ($can_edit) { ?>
|
||||
<div class="dropdown">
|
||||
<button type="button" class="btn btn-outline-secondary" data-bs-toggle="dropdown" title="More"><i class="fas fa-ellipsis-v"></i></button>
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<?php if (!$document_archived) { ?>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/document/document_rename.php?id=<?= $document_id ?>"><i class="fas fa-fw fa-pen me-2"></i>Rename</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/document/document_move.php?id=<?= $document_id ?>"><i class="fas fa-fw fa-folder-open me-2"></i>Move</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/link/link.php?from=document&id=<?= $document_id ?>"><i class="fas fa-fw fa-link me-2"></i>Link</a>
|
||||
<?php if ($config_client_portal_enable) { ?>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/document/document_edit_visibility.php?document_id=<?= $document_id ?>"><i class="fas fa-fw fa-eye<?= $document_visible ? '-slash' : '' ?> me-2"></i><?= $document_visible ? 'Hide from' : 'Show in' ?> client portal</a>
|
||||
<?php } ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?archive_document=<?= $document_id ?>&csrf_token=<?= $csrf ?>" data-confirm-text="Archiving unlinks it from everything it is linked to."><i class="fas fa-fw fa-archive me-2"></i>Archive</a>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item" href="post.php?restore_document=<?= $document_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-redo me-2"></i>Restore</a>
|
||||
<?php } ?>
|
||||
<?php if ($can_delete) { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?delete_document=<?= $document_id ?>&csrf_token=<?= $csrf ?>&from=document_details" data-confirm-text="The document and all its versions are deleted for good."><i class="fas fa-fw fa-trash me-2"></i>Delete</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-9">
|
||||
<div class="card">
|
||||
<div class="card-header bg-dark">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="h4 mb-0"><?= $document_name ?></div>
|
||||
<?php if ($document_description) { ?>
|
||||
<div class="text-light"><?= $document_description ?></div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="float-end">
|
||||
<div>
|
||||
Date:
|
||||
<strong><?= date('Y-m-d', strtotime($document_updated_at)); ?></strong>
|
||||
</div>
|
||||
<?php if($document_created_by_name) { ?>
|
||||
<div>
|
||||
Prepared By:
|
||||
<strong><?= $document_created_by_name ?></strong>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- The document -->
|
||||
<div class="col-lg-8">
|
||||
<div class="card mb-3">
|
||||
<div class="card-body prettyContent itflow-document-body">
|
||||
<?= documentHtmlPurify($row['document_content']) ?: '<p class="text-body-secondary">This document is empty.' . ($can_edit && !$document_archived ? ' <a class="ajax-modal" href="#" data-modal-size="xl" data-modal-url="modals/document/document_edit.php?id=' . $document_id . '">Start writing</a>' : '') . '</p>' ?>
|
||||
</div>
|
||||
<div class="card-body prettyContent">
|
||||
<?= $document_content ?>
|
||||
<hr>
|
||||
<h4>Documentation Revision History</h4>
|
||||
</div>
|
||||
|
||||
<!-- On paper, the revision history goes at the end of the document -->
|
||||
<?php if ($versions) { ?>
|
||||
<div class="d-none d-print-block">
|
||||
<h4>Revision history</h4>
|
||||
<table class="table table-sm">
|
||||
<thead class="table-light">
|
||||
<th>Version</th>
|
||||
<th>Date</th>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Author</th>
|
||||
</thead>
|
||||
<thead><tr><th>Version</th><th>Date</th><th>Name</th><th>Summary</th><th>Author</th></tr></thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$sql_document_versions = mysqli_query($mysqli, "SELECT document_version_created_at, document_version_description, document_version_id,
|
||||
document_version_name, user_name FROM document_versions
|
||||
LEFT JOIN users ON document_version_created_by = user_id
|
||||
WHERE document_version_document_id = $document_id
|
||||
ORDER BY document_version_created_at ASC"
|
||||
);
|
||||
|
||||
$document_version_count = 1; // Initialize the document version counter
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_document_versions)) {
|
||||
$document_version_id = intval($row['document_version_id']);
|
||||
$document_version_name = escapeHtml($row['document_version_name']);
|
||||
$document_version_description = escapeHtml($row['document_version_description']);
|
||||
if ($document_version_description ) {
|
||||
$document_version_description_display = $document_version_description;
|
||||
} else {
|
||||
$document_version_description_display = "-";
|
||||
}
|
||||
$document_version_author = escapeHtml($row['user_name']);
|
||||
$document_version_created_date = date('Y-m-d', strtotime($row['document_version_created_at']));
|
||||
|
||||
?>
|
||||
<?php foreach (array_reverse($versions) as $number => $version) { ?>
|
||||
<tr>
|
||||
<td><?= $document_version_count ?></td>
|
||||
<td><?= $document_version_created_date ?></td>
|
||||
<td><?= $document_version_name ?></td>
|
||||
<td><?= $document_version_description_display ?></td>
|
||||
<td><?= $document_version_author ?></td>
|
||||
<td><?= $number + 1 ?></td>
|
||||
<td><?= date('Y-m-d', strtotime($version['document_version_created_at'])) ?></td>
|
||||
<td><?= escapeHtml($version['document_version_name']) ?></td>
|
||||
<td><?= escapeHtml($version['document_version_description']) ?: '-' ?></td>
|
||||
<td><?= escapeHtml($version['user_name']) ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
$document_version_count++; // Increment the counter
|
||||
}
|
||||
?>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3 d-print-none">
|
||||
<div class="row">
|
||||
<div class="col-12 mb-3">
|
||||
<button type="button" class="btn btn-primary ajax-modal me-1" title="Edit document"
|
||||
data-modal-size="lg"
|
||||
data-modal-url="modals/document/document_edit.php?id=<?= $document_id ?>">
|
||||
<i class="fas fa-fw fa-edit"></i>
|
||||
</button>
|
||||
<button type="button" class="btn btn-secondary me-1" title="Share" data-bs-toggle="modal" data-bs-target="#shareModal"
|
||||
onclick="populateShareModal(<?= "$client_id, 'Document', $document_id"; ?>)">
|
||||
<i class="fas fa-fw fa-share"></i>
|
||||
</button>
|
||||
<a class="btn btn-success me-1" title="Export PDF" href="post.php?export_document=<?= $document_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"><i class='fas fa-fw fa-file-pdf'></i></a>
|
||||
<button type="button" class="btn btn-secondary me-4" title="Print" onclick="window.print();"><i class="fas fa-fw fa-print"></i></button>
|
||||
<a class="btn btn-warning me-1 confirm-link" href="post.php?archive_document=<?= $document_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>" title="Archive"><i class='fas fa-fw fa-archive'></i></a>
|
||||
<a class="btn btn-danger confirm-link" href="post.php?delete_document=<?= $document_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>&from=document_details" title="Delete"><i class='fas fa-fw fa-trash-alt'></i></a>
|
||||
<div class="col-lg-4 d-print-none">
|
||||
|
||||
<!-- What goes with it -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header d-flex align-items-center">
|
||||
<h3 class="card-title mb-0 me-auto"><i class="fas fa-fw fa-link me-2 text-body-secondary"></i>Linked</h3>
|
||||
<?php if ($can_edit && !$document_archived) { ?>
|
||||
<a class="small ajax-modal" href="#" data-modal-url="modals/link/link.php?from=document&id=<?= $document_id ?>"><i class="fas fa-plus me-1"></i>Link</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?= linkGroupsHtml('document', $document_id, $client_id, $document_archived) ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card card-body bg-light mb-3">
|
||||
<h5 class="mb-3"><i class="fas fa-tags me-2"></i>Related Items</h5>
|
||||
<h6>
|
||||
<i class="fas fa-fw fa-paperclip text-secondary me-2"></i>Files
|
||||
<button type="button" class="btn btn-link btn-sm ajax-modal" title="Link file"
|
||||
data-modal-url="modals/document/document_link_file.php?document_id=<?= $document_id ?>">
|
||||
<i class="fas fa-fw fa-plus"></i>
|
||||
</button>
|
||||
</h6>
|
||||
<?php
|
||||
$sql_files = mysqli_query($mysqli, "SELECT file_folder_id, files.file_id, file_name FROM files, document_files
|
||||
WHERE document_files.file_id = files.file_id
|
||||
AND document_files.document_id = $document_id
|
||||
ORDER BY file_name ASC"
|
||||
);
|
||||
|
||||
$linked_files = array();
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_files)) {
|
||||
$file_id = intval($row['file_id']);
|
||||
$folder_id = intval($row['file_folder_id']);
|
||||
$file_name = escapeHtml($row['file_name']);
|
||||
|
||||
$linked_files[] = $file_id;
|
||||
|
||||
?>
|
||||
<div class="ms-2">
|
||||
<a href="file.php?file_id=<?= $file_id ?>&action=view" target="_blank"><?= $file_name ?></a>
|
||||
<a class="confirm-link" href="post.php?unlink_file_from_document&file_id=<?= $file_id ?>&document_id=<?= $document_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-unlink text-secondary float-end" title="Unlink File"></i>
|
||||
</a>
|
||||
<!-- Where it lives -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-body">
|
||||
<div class="itflow-glance-item" title="Folder">
|
||||
<i class="fas fa-fw fa-folder"></i>
|
||||
<span class="min-w-0 d-flex align-items-center">
|
||||
<a class="text-truncate" href="files.php?client_id=<?= $client_id ?>&folder_id=<?= $document_folder_id ?>"><?= escapeHtml($folder_path ? implode(' / ', array_column($folder_path, 'folder_name')) : 'Top level') ?></a>
|
||||
<?php if ($can_edit && !$document_archived) { ?>
|
||||
<a class="itflow-copy ajax-modal" href="#" data-modal-url="modals/document/document_move.php?id=<?= $document_id ?>" title="Move"><i class="fas fa-pen"></i></a>
|
||||
<?php } ?>
|
||||
</span>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<h6>
|
||||
<i class="fas fa-fw fa-users text-secondary mt-3 me-2"></i>Contacts
|
||||
<button type="button" class="btn btn-link btn-sm ajax-modal" title="Link contact"
|
||||
data-modal-url="modals/document/document_link_contact.php?document_id=<?= $document_id ?>">
|
||||
<i class="fas fa-fw fa-plus"></i>
|
||||
</button>
|
||||
</h6>
|
||||
<?php
|
||||
$sql_contacts = mysqli_query($mysqli, "SELECT contacts.contact_id, contact_client_id, contact_name, contact_photo FROM contacts, contact_documents
|
||||
WHERE contacts.contact_id = contact_documents.contact_id
|
||||
AND contact_documents.document_id = $document_id
|
||||
ORDER BY contact_name ASC"
|
||||
);
|
||||
|
||||
$linked_contacts = array();
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_contacts)) {
|
||||
$contact_id = intval($row['contact_id']);
|
||||
|
||||
$linked_contacts[] = $contact_id;
|
||||
|
||||
?>
|
||||
<div class="ms-2 mb-1 d-flex align-items-center">
|
||||
<span class="flex-grow-1 min-w-0"><?= contactLink($row['contact_client_id'], $contact_id, $row['contact_name'], $row['contact_photo']) ?></span>
|
||||
<a class="confirm-link ms-2" href="post.php?unlink_contact_from_document&contact_id=<?= $contact_id ?>&document_id=<?= $document_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-unlink text-secondary" title="Unlink Contact"></i>
|
||||
</a>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<h6>
|
||||
<i class="fas fa-fw fa-laptop text-secondary me-2 mt-3"></i>Assets
|
||||
<button type="button" class="btn btn-link btn-sm ajax-modal" title="Link asset" data-modal-url="modals/document/document_link_asset.php?document_id=<?= $document_id ?>">
|
||||
<i class="fas fa-fw fa-plus"></i>
|
||||
</button>
|
||||
</h6>
|
||||
<?php
|
||||
$sql_assets = mysqli_query($mysqli, "SELECT assets.asset_id, asset_name FROM assets, asset_documents
|
||||
WHERE assets.asset_id = asset_documents.asset_id
|
||||
AND asset_documents.document_id = $document_id
|
||||
ORDER BY asset_name ASC"
|
||||
);
|
||||
|
||||
$linked_assets = array();
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_assets)) {
|
||||
$asset_id = intval($row['asset_id']);
|
||||
$asset_name = escapeHtml($row['asset_name']);
|
||||
|
||||
$linked_assets[] = $asset_id;
|
||||
|
||||
?>
|
||||
<div class="ms-2">
|
||||
<a class="ajax-modal" href="#"
|
||||
data-modal-size="lg"
|
||||
data-modal-url="modals/asset/asset.php?id=<?= $asset_id ?>">
|
||||
<?= $asset_name ?>
|
||||
</a>
|
||||
<a class="confirm-link float-end" href="post.php?unlink_asset_from_document&asset_id=<?= $asset_id ?>&document_id=<?= $document_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-unlink text-secondary" title="Unlink Asset"></i>
|
||||
</a>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<h6>
|
||||
<i class="fas fa-fw fa-cube text-secondary me-2 mt-3"></i>Licenses
|
||||
<button type="button" class="btn btn-link btn-sm ajax-modal" title="Link software"
|
||||
data-modal-url="modals/document/document_link_software.php?document_id=<?= $document_id ?>">
|
||||
<i class="fas fa-fw fa-plus"></i>
|
||||
</button>
|
||||
</h6>
|
||||
<?php
|
||||
$sql_software = mysqli_query($mysqli, "SELECT software.software_id, software_name FROM software, software_documents
|
||||
WHERE software.software_id = software_documents.software_id
|
||||
AND software_documents.document_id = $document_id
|
||||
ORDER BY software_name ASC"
|
||||
);
|
||||
|
||||
$linked_software = array();
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_software)) {
|
||||
$software_id = intval($row['software_id']);
|
||||
$software_name = escapeHtml($row['software_name']);
|
||||
|
||||
$linked_software[] = $software_id;
|
||||
|
||||
?>
|
||||
<div class="ms-2">
|
||||
<a href="software.php?client_id=<?= $client_id ?>&q=<?= $software_name ?>" target="_blank"><?= $software_name ?></a>
|
||||
<a class="confirm-link float-end" href="post.php?unlink_software_from_document&software_id=<?= $software_id ?>&document_id=<?= $document_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-unlink text-secondary" title="Unlink License"></i>
|
||||
</a>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<h6>
|
||||
<i class="fas fa-fw fa-building text-secondary me-2 mt-3"></i>Vendors
|
||||
<button type="button" class="btn btn-link btn-sm ajax-modal" title="Link vendor"
|
||||
data-modal-url="modals/document/document_link_vendor.php?document_id=<?= $document_id ?>">
|
||||
<i class="fas fa-fw fa-plus"></i>
|
||||
</button>
|
||||
</h6>
|
||||
<?php
|
||||
$sql_vendors = mysqli_query($mysqli, "SELECT vendors.vendor_id, vendor_name FROM vendors, vendor_documents
|
||||
WHERE vendors.vendor_id = vendor_documents.vendor_id
|
||||
AND vendor_documents.document_id = $document_id
|
||||
ORDER BY vendor_name ASC"
|
||||
);
|
||||
|
||||
$associated_vendors = array();
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_vendors)) {
|
||||
$vendor_id = intval($row['vendor_id']);
|
||||
$vendor_name = escapeHtml($row['vendor_name']);
|
||||
|
||||
$associated_vendors[] = $vendor_id;
|
||||
|
||||
?>
|
||||
<div class="ms-2">
|
||||
<a class="ajax-modal" href="#" data-modal-url="modals/vendor/vendor.php?id=<?= $vendor_id ?>">
|
||||
<?= $vendor_name ?>
|
||||
</a>
|
||||
<a class="confirm-link float-end" href="post.php?unlink_vendor_from_document&vendor_id=<?= $vendor_id ?>&document_id=<?= $document_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-unlink text-secondary" title="Unlink Vendor"></i>
|
||||
</a>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php if ($config_client_portal_enable) { ?>
|
||||
<div class="itflow-glance-item" title="Client portal">
|
||||
<i class="fas fa-fw fa-eye<?= $document_visible ? '' : '-slash' ?>"></i>
|
||||
<span class="d-flex align-items-center">
|
||||
<?= $document_visible ? 'Shown in the client portal' : 'Not in the client portal' ?>
|
||||
<?php if ($can_edit && !$document_archived) { ?>
|
||||
<a class="itflow-copy ajax-modal" href="#" data-modal-url="modals/document/document_edit_visibility.php?document_id=<?= $document_id ?>" title="Change"><i class="fas fa-pen"></i></a>
|
||||
<?php } ?>
|
||||
</span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($config_client_portal_enable) { ?>
|
||||
<div class="card card-body bg-light mb-3">
|
||||
<h6><i class="fas fa-handshake me-2"></i>Portal Collaboration</h6>
|
||||
<div class="mt-1">
|
||||
<i class="fa fa-fw fa-eye<?php if (!$document_client_visible) { echo '-slash'; } ?> text-secondary me-2"></i>Document is
|
||||
<a class="ajax-modal" href="#"
|
||||
data-modal-url="modals/document/document_edit_visibility.php?document_id=<?= $document_id ?>">
|
||||
<?php
|
||||
if ($document_client_visible) {
|
||||
echo "<span class='text-bold text-dark'>visible</span>";
|
||||
} else {
|
||||
echo "<span class='text-muted'>not visible</span>";
|
||||
}
|
||||
?>
|
||||
</a>
|
||||
</div>
|
||||
<!-- Every earlier version -->
|
||||
<div class="card mb-3" id="documentHistory">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title mb-0"><i class="fas fa-fw fa-history me-2 text-body-secondary"></i>History</h3>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="card card-body bg-light">
|
||||
<h6><i class="fas fa-history me-2"></i>Revisions</h6>
|
||||
<?php
|
||||
|
||||
$sql_document_versions = mysqli_query($mysqli, "SELECT document_version_created_at, document_version_description, document_version_id,
|
||||
document_version_name, user_name FROM document_versions
|
||||
LEFT JOIN users ON document_version_created_by = user_id
|
||||
WHERE document_version_document_id = $document_id
|
||||
ORDER BY document_version_created_at DESC"
|
||||
);
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_document_versions)) {
|
||||
$document_version_id = intval($row['document_version_id']);
|
||||
$document_version_name = escapeHtml($row['document_version_name']);
|
||||
$document_version_description = escapeHtml($row['document_version_description']);
|
||||
$document_version_author = escapeHtml($row['user_name']);
|
||||
$document_version_created_date = escapeHtml($row['document_version_created_at']);
|
||||
|
||||
?>
|
||||
<div class="mt-1 <?php if($document_id === $document_version_id){ echo "text-bold"; } ?>">
|
||||
<i class="fas fa-fw fa-history text-secondary me-2"></i>
|
||||
<a class="ajax-modal" href="#"
|
||||
data-modal-size="lg"
|
||||
data-modal-url="modals/document/document_version_view.php?id=<?= $document_version_id ?>">
|
||||
<?= "$document_version_created_date | $document_version_author" ?>
|
||||
</a>
|
||||
<a class="confirm-link float-end" href="post.php?delete_document_version=<?= $document_version_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-trash-alt text-secondary"></i>
|
||||
</a>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<ul class="list-group list-group-flush itflow-document-history">
|
||||
<li class="list-group-item">
|
||||
<div class="fw-semibold small">Now</div>
|
||||
<div class="small text-body-secondary">Updated <?= timeAgo($document_updated_at) ?><?= $document_updated_by ? " by $document_updated_by" : '' ?></div>
|
||||
</li>
|
||||
<?php foreach ($versions as $version) {
|
||||
$version_id = intval($version['document_version_id']); ?>
|
||||
<li class="list-group-item d-flex align-items-center gap-2">
|
||||
<div class="min-w-0 flex-grow-1">
|
||||
<a class="small fw-semibold ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/document/document_version_view.php?id=<?= $version_id ?>" title="<?= escapeHtml($version['document_version_created_at']) ?>">
|
||||
<?= date('M j, Y g:ia', strtotime($version['document_version_created_at'])) ?>
|
||||
</a>
|
||||
<div class="small text-body-secondary text-truncate">
|
||||
<?= escapeHtml($version['user_name'] ?: 'Unknown') ?>
|
||||
<?php if ($version['document_version_name'] !== $row['document_name']) { ?> · was "<?= escapeHtml($version['document_version_name']) ?>"<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($can_delete) { ?>
|
||||
<a class="itflow-copy confirm-link text-danger" href="post.php?delete_document_version=<?= $version_id ?>&csrf_token=<?= $csrf ?>" title="Delete this version" data-confirm-text="This version is removed from the history for good."><i class="fas fa-trash-alt"></i></a>
|
||||
<?php } ?>
|
||||
</li>
|
||||
<?php } ?>
|
||||
<?php if (!$versions) { ?>
|
||||
<li class="list-group-item small text-body-secondary">No earlier versions - each edit keeps the one before it here.</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
1890
agent/files.php
1890
agent/files.php
File diff suppressed because it is too large
Load Diff
@@ -1,5 +0,0 @@
|
||||
function populateFileDeleteModal(file_id, file_name) {
|
||||
// Dynamically populate the file delete modal with the file id (hidden) and name
|
||||
document.getElementById("file_delete_id").value = file_id;
|
||||
document.getElementById("file_delete_name").innerText = file_name;
|
||||
}
|
||||
249
agent/js/files.js
Normal file
249
agent/js/files.js
Normal file
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* agent/files.php - the folder tree, the grid's previewer, and dropping files
|
||||
* onto the list to upload them.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
// ---- Folder tree: subfolders open and close in place, remembered per client ----
|
||||
|
||||
var tree = document.querySelector('.itflow-folder-tree');
|
||||
var storeKey = tree ? 'itflow.folders.' + tree.dataset.clientId : '';
|
||||
|
||||
function remembered() {
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem(storeKey) || '[]');
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function remember() {
|
||||
var open = [];
|
||||
tree.querySelectorAll('.itflow-folder.is-open[data-folder-id]').forEach(function (li) {
|
||||
open.push(li.dataset.folderId);
|
||||
});
|
||||
try {
|
||||
localStorage.setItem(storeKey, JSON.stringify(open));
|
||||
} catch (e) {
|
||||
// Private window - the tree just forgets
|
||||
}
|
||||
}
|
||||
|
||||
if (tree) {
|
||||
// The path to the folder on show is opened by the server; reopen anything else left open last time
|
||||
remembered().forEach(function (id) {
|
||||
var li = tree.querySelector('.itflow-folder[data-folder-id="' + CSS.escape(String(id)) + '"]');
|
||||
if (li) {
|
||||
li.classList.add('is-open');
|
||||
}
|
||||
});
|
||||
tree.addEventListener('click', function (e) {
|
||||
var toggle = e.target.closest('[data-folder-toggle]');
|
||||
if (toggle) {
|
||||
toggle.closest('.itflow-folder').classList.toggle('is-open');
|
||||
remember();
|
||||
}
|
||||
});
|
||||
document.querySelectorAll('[data-folder-expand-all], [data-folder-collapse-all]').forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
var open = button.hasAttribute('data-folder-expand-all');
|
||||
tree.querySelectorAll('.itflow-folder[data-folder-id]').forEach(function (li) {
|
||||
if (li.querySelector('ul')) {
|
||||
li.classList.toggle('is-open', open);
|
||||
}
|
||||
});
|
||||
remember();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ---- Grid previewer: arrows page through everything on show ----
|
||||
|
||||
var items = window.itflowFilesPreview || [];
|
||||
var current = 0;
|
||||
var modal = document.getElementById('viewFileModal');
|
||||
|
||||
function el(id) {
|
||||
return document.getElementById(id);
|
||||
}
|
||||
|
||||
function draw() {
|
||||
var item = items[current];
|
||||
var image = el('modalImage'), frame = el('modalFrame'), fallback = el('modalFallback'),
|
||||
text = el('modalText'), doc = el('modalDocument');
|
||||
|
||||
el('modalTitle').textContent = item.name;
|
||||
el('modalMeta').textContent = item.meta;
|
||||
el('modalPosition').textContent = (current + 1) + ' of ' + items.length;
|
||||
var action = el('modalDownload');
|
||||
action.href = item.download;
|
||||
action.innerHTML = '<i class="fas fa-fw fa-' + (item.kind === 'document' ? 'arrow-right' : 'download') + ' me-2"></i>';
|
||||
action.appendChild(document.createTextNode(item.action));
|
||||
var details = el('modalDetails');
|
||||
details.classList.toggle('d-none', !item.details);
|
||||
details.dataset.modalUrl = item.details || '';
|
||||
|
||||
// Blank the last one first, or a heavy PDF keeps rendering behind the next image
|
||||
[image, frame].forEach(function (node) {
|
||||
node.classList.add('d-none');
|
||||
node.removeAttribute('src');
|
||||
});
|
||||
[fallback, text, doc].forEach(function (node) {
|
||||
node.classList.add('d-none');
|
||||
});
|
||||
doc.innerHTML = '';
|
||||
|
||||
if (item.kind === 'document') {
|
||||
var requested = current;
|
||||
doc.innerHTML = '<p class="text-secondary mb-0">Loading...</p>';
|
||||
doc.classList.remove('d-none');
|
||||
fetch(item.preview, { headers: { 'X-Requested-With': 'XMLHttpRequest' }, credentials: 'same-origin' })
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (data) {
|
||||
if (requested !== current) {
|
||||
return;
|
||||
}
|
||||
// HTMLPurifier output - the same the document page renders
|
||||
doc.innerHTML = data.content || '<p class="text-secondary mb-0">This document is empty.</p>';
|
||||
if (typeof prettyContent === 'function') {
|
||||
prettyContent();
|
||||
}
|
||||
})
|
||||
.catch(function () {
|
||||
if (requested === current) {
|
||||
doc.innerHTML = '<p class="text-danger mb-0">Could not load this document.</p>';
|
||||
}
|
||||
});
|
||||
} else if (item.kind === 'image') {
|
||||
image.src = item.preview;
|
||||
image.alt = item.name;
|
||||
image.classList.remove('d-none');
|
||||
} else if (item.kind === 'pdf' || item.kind === 'text') {
|
||||
frame.src = item.preview;
|
||||
frame.classList.remove('d-none');
|
||||
} else {
|
||||
el('modalFallbackIcon').className = 'fas fa-' + item.icon + ' fa-4x text-secondary';
|
||||
fallback.classList.remove('d-none');
|
||||
}
|
||||
|
||||
var single = items.length < 2;
|
||||
el('modalPrev').classList.toggle('d-none', single);
|
||||
el('modalNext').classList.toggle('d-none', single);
|
||||
}
|
||||
|
||||
function step(by) {
|
||||
current = (current + by + items.length) % items.length;
|
||||
draw();
|
||||
}
|
||||
|
||||
if (modal && items.length) {
|
||||
document.addEventListener('click', function (e) {
|
||||
var tile = e.target.closest('[data-files-preview]');
|
||||
if (!tile) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
current = parseInt(tile.dataset.filesPreview, 10) || 0;
|
||||
draw();
|
||||
bootstrap.Modal.getOrCreateInstance(modal).show();
|
||||
});
|
||||
el('modalPrev').addEventListener('click', function () { step(-1); });
|
||||
el('modalNext').addEventListener('click', function () { step(1); });
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (!modal.classList.contains('show') || items.length < 2) {
|
||||
return;
|
||||
}
|
||||
if (e.key === 'ArrowRight') {
|
||||
step(1);
|
||||
} else if (e.key === 'ArrowLeft') {
|
||||
step(-1);
|
||||
}
|
||||
});
|
||||
// Details is a quick look - close the previewer first so the two never stack
|
||||
el('modalDetails').addEventListener('click', function () {
|
||||
var url = this.dataset.modalUrl;
|
||||
modal.addEventListener('hidden.bs.modal', function open() {
|
||||
modal.removeEventListener('hidden.bs.modal', open);
|
||||
var trigger = document.createElement('a');
|
||||
trigger.className = 'ajax-modal d-none';
|
||||
trigger.href = '#';
|
||||
trigger.dataset.modalUrl = url;
|
||||
trigger.dataset.modalSize = 'lg';
|
||||
document.body.appendChild(trigger);
|
||||
trigger.click();
|
||||
trigger.remove();
|
||||
});
|
||||
bootstrap.Modal.getInstance(modal).hide();
|
||||
});
|
||||
}
|
||||
|
||||
// ---- Drop files on the list to upload them into the folder on show ----
|
||||
|
||||
var main = document.querySelector('[data-files-drop]');
|
||||
var overlay = document.querySelector('.itflow-files-dropzone');
|
||||
if (!main || !overlay) {
|
||||
return;
|
||||
}
|
||||
var depth = 0;
|
||||
|
||||
function carriesFiles(e) {
|
||||
return e.dataTransfer && Array.prototype.indexOf.call(e.dataTransfer.types || [], 'Files') !== -1;
|
||||
}
|
||||
|
||||
main.addEventListener('dragenter', function (e) {
|
||||
if (!carriesFiles(e)) {
|
||||
return;
|
||||
}
|
||||
depth++;
|
||||
overlay.hidden = false;
|
||||
var box = main.getBoundingClientRect(), card = main.closest('.card').getBoundingClientRect();
|
||||
overlay.style.cssText = 'top:' + (box.top - card.top) + 'px;left:' + (box.left - card.left) + 'px;width:' + box.width + 'px;height:' + box.height + 'px';
|
||||
});
|
||||
main.addEventListener('dragover', function (e) {
|
||||
if (carriesFiles(e)) {
|
||||
e.preventDefault();
|
||||
e.dataTransfer.dropEffect = 'copy';
|
||||
}
|
||||
});
|
||||
main.addEventListener('dragleave', function () {
|
||||
depth = Math.max(0, depth - 1);
|
||||
if (!depth) {
|
||||
overlay.hidden = true;
|
||||
}
|
||||
});
|
||||
main.addEventListener('drop', function (e) {
|
||||
if (!carriesFiles(e)) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
depth = 0;
|
||||
overlay.hidden = true;
|
||||
var files = e.dataTransfer.files;
|
||||
if (!files.length) {
|
||||
return;
|
||||
}
|
||||
// Open the upload modal, then hand it the dropped files once it is on screen
|
||||
var trigger = document.createElement('a');
|
||||
trigger.className = 'ajax-modal d-none';
|
||||
trigger.href = '#';
|
||||
trigger.dataset.modalUrl = main.dataset.filesDrop;
|
||||
document.body.appendChild(trigger);
|
||||
trigger.click();
|
||||
trigger.remove();
|
||||
var tries = 0;
|
||||
(function handOver() {
|
||||
var input = document.querySelector('.modal.show [data-upload-input]');
|
||||
if (input) {
|
||||
var transfer = new DataTransfer();
|
||||
Array.prototype.forEach.call(files, function (file) {
|
||||
transfer.items.add(file);
|
||||
});
|
||||
input.files = transfer.files;
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
} else if (++tries < 50) {
|
||||
setTimeout(handOver, 100);
|
||||
}
|
||||
})();
|
||||
});
|
||||
})();
|
||||
@@ -1,68 +1,12 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
/*
|
||||
* Kept so existing links keep working. Every pair is linked in
|
||||
* agent/modals/link/link.php, here opened on its Documents tab.
|
||||
*/
|
||||
|
||||
$asset_id = intval($_GET['id']);
|
||||
$_GET['from'] = 'asset';
|
||||
$_GET['id'] = intval($_GET['id'] ?? 0);
|
||||
$_GET['to'] = 'document';
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT asset_client_id, asset_name 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-folder me-2"></i>Link Document to <strong><?= $asset_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></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="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
<select class="form-select select2" name="document_id">
|
||||
<option value="">- Select a Document -</option>
|
||||
<?php
|
||||
$sql_documents_select = mysqli_query($mysqli, "
|
||||
SELECT documents.document_id, document_name
|
||||
FROM documents
|
||||
LEFT JOIN asset_documents
|
||||
ON documents.document_id = asset_documents.document_id
|
||||
AND asset_documents.asset_id = $asset_id
|
||||
WHERE document_client_id = $client_id
|
||||
AND document_archived_at IS NULL
|
||||
AND asset_documents.asset_id IS NULL
|
||||
ORDER BY document_name ASC
|
||||
");
|
||||
while ($row = mysqli_fetch_assoc($sql_documents_select)) {
|
||||
$document_id = intval($row['document_id']);
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
?>
|
||||
<option value="<?= $document_id ?>"><?= $document_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="link_asset_to_document" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
require __DIR__ . '/../link/link.php';
|
||||
|
||||
@@ -1,73 +1,12 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
/*
|
||||
* Kept so existing links keep working. Every pair is linked in
|
||||
* agent/modals/link/link.php, here opened on its Files tab.
|
||||
*/
|
||||
|
||||
enforceUserPermission('module_credential', 2);
|
||||
$_GET['from'] = 'asset';
|
||||
$_GET['id'] = intval($_GET['id'] ?? 0);
|
||||
$_GET['to'] = 'file';
|
||||
|
||||
$asset_id = intval($_GET['id']);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT asset_client_id, asset_name 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-paperclip me-2"></i>Link File to <strong><?= $asset_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></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="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-paperclip"></i></span>
|
||||
<select class="form-select select2" name="file_id">
|
||||
<option value="">- Select a File -</option>
|
||||
<?php
|
||||
$sql_files_select = mysqli_query($mysqli, "
|
||||
SELECT files.file_id, files.file_name, folders.folder_name
|
||||
FROM files
|
||||
LEFT JOIN asset_files
|
||||
ON files.file_id = asset_files.file_id
|
||||
AND asset_files.asset_id = $asset_id
|
||||
LEFT JOIN folders
|
||||
ON folders.folder_id = files.file_folder_id
|
||||
WHERE files.file_client_id = $client_id
|
||||
AND asset_files.asset_id IS NULL
|
||||
ORDER BY folders.folder_name ASC, files.file_name ASC
|
||||
");
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_files_select)) {
|
||||
$file_id = intval($row['file_id']);
|
||||
$file_name = escapeHtml($row['file_name']);
|
||||
$folder_name = escapeHtml($row['folder_name']);
|
||||
?>
|
||||
<option value="<?= $file_id ?>"><?= "$folder_name/$file_name" ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="link_asset_to_file" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
require __DIR__ . '/../link/link.php';
|
||||
|
||||
@@ -1,68 +1,12 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
/*
|
||||
* Kept so existing links keep working. Every pair is linked in
|
||||
* agent/modals/link/link.php, here opened on its Documents tab.
|
||||
*/
|
||||
|
||||
$contact_id = intval($_GET['id']);
|
||||
$_GET['from'] = 'contact';
|
||||
$_GET['id'] = intval($_GET['id'] ?? 0);
|
||||
$_GET['to'] = 'document';
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT contact_client_id, contact_name FROM contacts
|
||||
WHERE contact_id = $contact_id
|
||||
LIMIT 1
|
||||
");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$contact_name = escapeHtml($row['contact_name']);
|
||||
$client_id = intval($row['contact_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-folder me-2"></i>Link Document to <strong><?= $contact_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="contact_id" value="<?= $contact_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
<select class="form-select select2" name="document_id">
|
||||
<option value="">- Select a Document -</option>
|
||||
<?php
|
||||
$sql_documents_select = mysqli_query($mysqli, "
|
||||
SELECT documents.document_id, documents.document_name
|
||||
FROM documents
|
||||
LEFT JOIN contact_documents
|
||||
ON documents.document_id = contact_documents.document_id
|
||||
AND contact_documents.contact_id = $contact_id
|
||||
WHERE documents.document_client_id = $client_id
|
||||
AND documents.document_archived_at IS NULL
|
||||
AND contact_documents.contact_id IS NULL
|
||||
ORDER BY documents.document_name ASC
|
||||
");
|
||||
while ($row = mysqli_fetch_assoc($sql_documents_select)) {
|
||||
$document_id = intval($row['document_id']);
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
?>
|
||||
<option value="<?= $document_id ?>"><?= $document_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="link_contact_to_document" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
?>
|
||||
require __DIR__ . '/../link/link.php';
|
||||
|
||||
@@ -1,70 +1,12 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
/*
|
||||
* Kept so existing links keep working. Every pair is linked in
|
||||
* agent/modals/link/link.php, here opened on its Files tab.
|
||||
*/
|
||||
|
||||
$contact_id = intval($_GET['id']);
|
||||
$_GET['from'] = 'contact';
|
||||
$_GET['id'] = intval($_GET['id'] ?? 0);
|
||||
$_GET['to'] = 'file';
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT contact_client_id, contact_name FROM contacts
|
||||
WHERE contact_id = $contact_id
|
||||
LIMIT 1
|
||||
");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$contact_name = escapeHtml($row['contact_name']);
|
||||
$client_id = intval($row['contact_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-paperclip me-2"></i>Link File to <strong><?= $contact_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="contact_id" value="<?= $contact_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-paperclip"></i></span>
|
||||
<select class="form-select select2" name="file_id">
|
||||
<option value="">- Select a File -</option>
|
||||
<?php
|
||||
$sql_files_select = mysqli_query($mysqli, "
|
||||
SELECT files.file_id, files.file_name, folders.folder_name
|
||||
FROM files
|
||||
LEFT JOIN contact_files
|
||||
ON files.file_id = contact_files.file_id
|
||||
AND contact_files.contact_id = $contact_id
|
||||
LEFT JOIN folders
|
||||
ON folders.folder_id = files.file_folder_id
|
||||
WHERE files.file_client_id = $client_id
|
||||
AND contact_files.contact_id IS NULL
|
||||
ORDER BY folders.folder_name ASC, files.file_name ASC
|
||||
");
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_files_select)) {
|
||||
$file_id = intval($row['file_id']);
|
||||
$file_name = escapeHtml($row['file_name']);
|
||||
$folder_name = escapeHtml($row['folder_name']);
|
||||
?>
|
||||
<option value="<?= $file_id ?>"><?= "$folder_name/$file_name" ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="link_contact_to_file" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
require __DIR__ . '/../link/link.php';
|
||||
|
||||
@@ -1,17 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* New document - in the folder it was opened from, or linked to the asset or
|
||||
* contact it was opened from.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$client_id = intval($_GET['client_id'] ?? 0);
|
||||
$contact_id = intval($_GET['contact_id'] ?? 0);
|
||||
$asset_id = intval($_GET['asset_id'] ?? 0);
|
||||
intval($_GET['folder_id'] ?? 0);
|
||||
enforceClientAccess();
|
||||
|
||||
$contact_id = assetClientOwnedId('contact', $_GET['contact_id'] ?? 0, $client_id);
|
||||
$asset = linkRecord('asset', $_GET['asset_id'] ?? 0);
|
||||
$asset_id = $asset && intval($asset['client_id']) === $client_id ? intval($asset['id']) : 0;
|
||||
$link_name = $asset_id ? $asset['name'] : ($contact_id ? getFieldById('contacts', $contact_id, 'contact_name') : '');
|
||||
|
||||
$document_form_mode = 'add';
|
||||
$document_name = $document_description = $document_content = '';
|
||||
$document_folder_id = folderOwnedId($_GET['folder_id'] ?? 0, $client_id);
|
||||
$document_client_visible = 0;
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-file-alt me-2"></i>New Document</h5>
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-file-alt me-2"></i>New document<?php if ($link_name) { ?> <small class="opacity-75 ms-1">for <?= escapeHtml($link_name) ?></small><?php } ?></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
@@ -20,36 +35,7 @@ ob_start();
|
||||
<input type="hidden" name="contact" value="<?= $contact_id ?>">
|
||||
<input type="hidden" name="asset" value="<?= $asset_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<input type="text" class="form-control" name="name" placeholder="Name" maxlength="200" required autofocus>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<textarea class="form-control tinymce" name="content"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Select Folder</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
<select class="form-select select2" name="folder">
|
||||
<option value="0">/</option>
|
||||
<?php
|
||||
// Start displaying folder options from the root (parent_folder = 0)
|
||||
displayFolderOptions(0, $client_id);
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Description</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-align-left"></i></span>
|
||||
<input type="text" class="form-control" name="description" placeholder="Short summary of the document">
|
||||
</div>
|
||||
</div>
|
||||
<?php require 'document_form.php'; ?>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="add_document" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Create</button>
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
<div class="modal" id="associateFileToDocumentModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-paperclip me-2"></i>Associate File to <strong><?= $document_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="document_id" value="<?= $document_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-paperclip"></i></span>
|
||||
<select class="form-select select2" name="file_id">
|
||||
<option value="">- Select a File -</option>
|
||||
<?php
|
||||
$sql_files_select = mysqli_query($mysqli, "SELECT file_id, file_name, folder_name FROM files
|
||||
LEFT JOIN folders ON folder_id = file_folder_id
|
||||
WHERE file_client_id = $client_id ORDER BY folder_name ASC, file_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql_files_select)) {
|
||||
$file_id = intval($row['file_id']);
|
||||
$file_name = escapeHtml($row['file_name']);
|
||||
$folder_name = escapeHtml($row['folder_name']);
|
||||
|
||||
?>
|
||||
<option value="<?= $file_id ?>"><?= "$folder_name/$file_name" ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="associate_file_to_document" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Associate</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,22 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* New document from one of the admin's document templates - its content and
|
||||
* its images, copied, in the folder it was opened from.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$client_id = intval($_GET['client_id'] ?? 0);
|
||||
|
||||
enforceClientAccess();
|
||||
$contact_id = intval($_GET['contact_id'] ?? 0);
|
||||
$asset_id = intval($_GET['asset_id'] ?? 0);
|
||||
intval($_GET['folder_id'] ?? 0);
|
||||
|
||||
$folder_id = folderOwnedId($_GET['folder_id'] ?? 0, $client_id);
|
||||
|
||||
$templates = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT document_template_id, document_template_name, document_template_description FROM document_templates
|
||||
WHERE document_template_archived_at IS NULL ORDER BY document_template_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$templates[] = $row;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-file-alt me-2"></i>New Document from Template</h5>
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-puzzle-piece me-2"></i>New document from a template</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
@@ -24,67 +34,63 @@ ob_start();
|
||||
<input type="hidden" name="client_id" value="<?= $client_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<label>Template</label>
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-puzzle-piece"></i></span>
|
||||
<select class="form-select" name="document_template_id" required>
|
||||
<option value="">- Select Template -</option>
|
||||
<?php
|
||||
$sql_document_templates = mysqli_query($mysqli, "SELECT document_template_id, document_template_name FROM document_templates WHERE document_template_archived_at IS NULL ORDER BY document_template_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql_document_templates)) {
|
||||
$document_template_id = intval($row['document_template_id']);
|
||||
$document_template_name = escapeHtml($row['document_template_name']);
|
||||
?>
|
||||
<option value="<?= $document_template_id ?>"><?= $document_template_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php if (!$templates) { ?>
|
||||
<div class="itflow-asset-empty py-4">
|
||||
<i class="fas fa-puzzle-piece fa-2x mb-2"></i>
|
||||
<div>No document templates yet.</div>
|
||||
<?php if ($session_user_role == 3) { ?>
|
||||
<a class="small" href="/admin/document_templates.php">Add one in Admin › Document Templates</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
|
||||
<label>Document name</label>
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-file"></i></span>
|
||||
<input type="text" class="form-control" name="name" placeholder="Name" maxlength="200" required>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Template <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-puzzle-piece"></i></span>
|
||||
<select class="form-select select2" name="document_template_id" required data-template-select>
|
||||
<option value="">- Pick a template -</option>
|
||||
<?php foreach ($templates as $template) { ?>
|
||||
<option value="<?= intval($template['document_template_id']) ?>"<?= selectOptionData(['icon' => 'fas fa-file-alt', 'description' => $template['document_template_description'] ?? '']) ?>><?= escapeHtml($template['document_template_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label>Description</label>
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-align-left"></i></span>
|
||||
<input type="text" class="form-control" name="description" placeholder="Short summary of the document">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Name</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-file-alt"></i></span>
|
||||
<input type="text" class="form-control" name="name" placeholder="The template's name, unless you give it another" maxlength="200">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label>Folder</label>
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
<select class="form-select" name="folder">
|
||||
<option value="0">/</option>
|
||||
<?php
|
||||
$sql_folders = mysqli_query($mysqli, "SELECT folder_id, folder_name FROM folders WHERE folder_client_id = $client_id ORDER BY folder_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql_folders)) {
|
||||
$folder_id = intval($row['folder_id']);
|
||||
$folder_name = escapeHtml($row['folder_name']);
|
||||
?>
|
||||
<option <?php if (isset($_GET['folder_id']) && $_GET['folder_id'] == $folder_id) echo "selected"; ?> value="<?= $folder_id ?>"><?= $folder_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Summary</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-align-left"></i></span>
|
||||
<input type="text" class="form-control" name="description" placeholder="One line on what it covers">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Folder</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-folder"></i></span>
|
||||
<select class="form-select select2" name="folder">
|
||||
<?= folderOptionsHtml($client_id, $folder_id) ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="add_document_from_template" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Create</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
<?php if ($templates) { ?>
|
||||
<button type="submit" name="add_document_from_template" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Create</button>
|
||||
<?php } ?>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i><?= $templates ? 'Cancel' : 'Close' ?></button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$client_id = intval($_GET['client_id']);
|
||||
$selected_ids = array_map('intval', $_GET['selected_ids'] ?? []);
|
||||
|
||||
$count = count($selected_ids);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-file-alt me-2"></i>Move <strong><?= $count ?></strong> Documents</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<?php foreach ($selected_ids as $id) { ?><input type="hidden" name="document_ids[]" value="<?= $id ?>"><?php } ?>
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Target Folder</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
<select class="form-select select2" name="bulk_folder_id">
|
||||
<option value="0">/</option>
|
||||
<?php
|
||||
// Fetch all folders for the client
|
||||
$sql_all_folders = mysqli_query($mysqli, "SELECT folder_id, folder_name, parent_folder FROM folders WHERE folder_location = 0 AND folder_client_id = $client_id ORDER BY folder_name ASC");
|
||||
$folders = array();
|
||||
|
||||
// Build an associative array of folders indexed by folder_id
|
||||
while ($row = mysqli_fetch_assoc($sql_all_folders)) {
|
||||
$folders[$row['folder_id']] = array(
|
||||
'folder_id' => intval($row['folder_id']),
|
||||
'folder_name' => escapeHtml($row['folder_name']),
|
||||
'parent_folder' => intval($row['parent_folder']),
|
||||
'children' => array()
|
||||
);
|
||||
}
|
||||
|
||||
// Build the folder hierarchy
|
||||
foreach ($folders as $id => &$folder) {
|
||||
if ($folder['parent_folder'] != 0 && isset($folders[$folder['parent_folder']])) {
|
||||
$folders[$folder['parent_folder']]['children'][] = &$folder;
|
||||
}
|
||||
}
|
||||
unset($folder); // Break the reference
|
||||
|
||||
// Prepare a list of root folders
|
||||
$root_folders = array();
|
||||
foreach ($folders as $id => $folder) {
|
||||
if ($folder['parent_folder'] == 0) {
|
||||
$root_folders[] = $folder;
|
||||
}
|
||||
}
|
||||
|
||||
// Display the folder options iteratively
|
||||
$stack = array();
|
||||
foreach (array_reverse($root_folders) as $folder) {
|
||||
$stack[] = array('folder' => $folder, 'level' => 0);
|
||||
}
|
||||
|
||||
while (!empty($stack)) {
|
||||
$node = array_pop($stack);
|
||||
$folder = $node['folder'];
|
||||
$level = $node['level'];
|
||||
|
||||
// Indentation for subfolders
|
||||
$indentation = str_repeat(' ', $level * 4);
|
||||
|
||||
// Check if this folder is selected
|
||||
$selected = '';
|
||||
if ($folder['folder_id'] == $get_folder_id) {
|
||||
$selected = 'selected';
|
||||
}
|
||||
|
||||
echo "<option value=\"{$folder['folder_id']}\" $selected>$indentation{$folder['folder_name']}</option>";
|
||||
|
||||
// Add children to the stack
|
||||
if (!empty($folder['children'])) {
|
||||
foreach (array_reverse($folder['children']) as $child_folder) {
|
||||
$stack[] = array('folder' => $child_folder, 'level' => $level + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="bulk_move_document" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Move Documents</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
@@ -1,54 +1,44 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Edit a document. Saving keeps what it said before as a version.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$document_id = intval($_GET['id']);
|
||||
$document_id = intval($_GET['id'] ?? 0);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT document_client_id, document_client_visible, document_content, document_description,
|
||||
document_folder_id, document_name FROM documents WHERE document_id = $document_id LIMIT 1");
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT document_client_id, document_client_visible, document_content, document_description,
|
||||
document_folder_id, document_name, document_archived_at FROM documents WHERE document_id = $document_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'That document no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
$client_id = intval($row['document_client_id']);
|
||||
enforceClientAccess();
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$document_form_mode = 'edit';
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
$document_description = escapeHtml($row['document_description']);
|
||||
$document_content = escapeHtml($row['document_content']);
|
||||
$document_folder_id = intval($row['document_folder_id']);
|
||||
$document_client_visible = intval($row['document_client_visible']);
|
||||
$client_id = intval($row['document_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-file-alt me-2"></i>Editing document: <strong><?= $document_name ?></strong></h5>
|
||||
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-edit me-2"></i>Editing <strong><?= $document_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="document_id" value="<?= $document_id ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<input type="text" class="form-control" name="name" maxlength="200" value="<?= $document_name ?>" placeholder="Name" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<textarea class="form-control tinymce" name="content"><?= $document_content ?></textarea>
|
||||
</div>
|
||||
|
||||
<label>Description</label>
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-align-left"></i></span>
|
||||
<input type="text" class="form-control" name="description" value="<?= $document_description ?>" placeholder="Short summary of the document">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require 'document_form.php'; ?>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="edit_document" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save</button>
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Whether the client portal shows a document to the client's technical contacts.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
$document_id = intval($_GET['document_id']);
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT document_client_id, document_client_visible, document_name FROM documents
|
||||
WHERE document_id = $document_id
|
||||
LIMIT 1
|
||||
");
|
||||
$document_id = intval($_GET['document_id'] ?? 0);
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
$document_client_visible = intval($row['document_client_visible']);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT document_client_id, document_client_visible, document_name FROM documents WHERE document_id = $document_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'That document no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
$client_id = intval($row['document_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
ob_start();
|
||||
@@ -21,36 +23,24 @@ ob_start();
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title">
|
||||
<i class="fa fa-fw fa-handshake me-2"></i>
|
||||
Edit Visibility Status for <strong><?= $document_name ?></strong>
|
||||
</h5>
|
||||
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-eye me-2"></i>Client portal · <strong><?= escapeHtml($row['document_name']) ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="document_id" value="<?= $document_id ?>">
|
||||
<input type="hidden" name="document_visible" value="0">
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label>Visibility</label>
|
||||
<p>Should this document be visible in the portal to client contacts with the 'Technical' role?</p>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-eye"></i></span>
|
||||
<select class="form-select" name="document_visible">
|
||||
<option <?php if ($document_client_visible == 1) { echo "selected"; } ?> value="1">Yes</option>
|
||||
<option <?php if ($document_client_visible == 0) { echo "selected"; } ?> value="0">No</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" name="document_visible" value="1" id="documentVisibleSwitch" <?= intval($row['document_client_visible']) ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="documentVisibleSwitch">Show this document in the client portal</label>
|
||||
</div>
|
||||
|
||||
<div class="form-text ms-5">Only the client's contacts with the Technical role can see documents there, and only to read.</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="toggle_document_visibility" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save changes</button>
|
||||
<button type="submit" name="toggle_document_visibility" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
59
agent/modals/document/document_form.php
Normal file
59
agent/modals/document/document_form.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The body of New Document and Edit Document (document_add.php,
|
||||
* document_edit.php): name and summary across the top, where it lives and
|
||||
* whether the portal shows it under them, the editor below.
|
||||
*
|
||||
* Expects $document_form_mode ('add' or 'edit'), $client_id, and the
|
||||
* escaped $document_name, $document_description, $document_content,
|
||||
* $document_folder_id, $document_client_visible.
|
||||
*/
|
||||
?>
|
||||
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-file-alt"></i></span>
|
||||
<input type="text" class="form-control" name="name" maxlength="200" value="<?= $document_name ?>" placeholder="e.g. Backup and recovery plan" required <?= $document_form_mode === 'add' ? 'autofocus' : '' ?>>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Summary</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-align-left"></i></span>
|
||||
<input type="text" class="form-control" name="description" value="<?= $document_description ?>" placeholder="One line on what it covers">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($document_form_mode === 'add') { ?>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Folder</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-folder"></i></span>
|
||||
<select class="form-select select2" name="folder">
|
||||
<?= folderOptionsHtml($client_id, $document_folder_id) ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (!empty($config_client_portal_enable)) { ?>
|
||||
<div class="col-md-6 d-flex align-items-end">
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input type="hidden" name="client_visible" value="0">
|
||||
<input class="form-check-input" type="checkbox" role="switch" name="client_visible" value="1" id="documentFormVisible" <?= $document_client_visible ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="documentFormVisible">
|
||||
<i class="fas fa-fw fa-eye text-body-secondary me-1"></i>Show in the client portal <span class="text-body-secondary small">- to their technical contacts</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<textarea class="form-control tinymce" name="content" aria-label="Content"><?= $document_content ?></textarea>
|
||||
|
||||
<?php if ($document_form_mode === 'edit') { ?>
|
||||
<div class="form-text"><i class="fas fa-history me-1"></i>Saving keeps what it says now in the document's history, so it can be put back.</div>
|
||||
<?php } ?>
|
||||
@@ -1,69 +1,12 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
/*
|
||||
* Kept so existing links keep working. Every pair is linked in
|
||||
* agent/modals/link/link.php, here opened on its Assets tab.
|
||||
*/
|
||||
|
||||
$document_id = intval($_GET['document_id']);
|
||||
$_GET['from'] = 'document';
|
||||
$_GET['id'] = intval($_GET['document_id'] ?? 0);
|
||||
$_GET['to'] = 'asset';
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT document_client_id, document_name FROM documents
|
||||
WHERE document_id = $document_id
|
||||
LIMIT 1
|
||||
");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
$client_id = intval($row['document_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-desktop me-2"></i>Link Asset to <strong><?= $document_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="document_id" value="<?= $document_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-desktop"></i></span>
|
||||
<select class="form-select select2" name="asset_id">
|
||||
<option value="">- Select an Asset -</option>
|
||||
<?php
|
||||
$sql_assets_select = mysqli_query($mysqli, "
|
||||
SELECT assets.asset_id, asset_name, asset_type, asset_make, asset_model
|
||||
FROM assets
|
||||
LEFT JOIN asset_documents
|
||||
ON assets.asset_id = asset_documents.asset_id
|
||||
AND asset_documents.document_id = $document_id
|
||||
WHERE asset_client_id = $client_id
|
||||
AND asset_archived_at IS NULL
|
||||
AND asset_documents.asset_id IS NULL
|
||||
ORDER BY asset_name ASC
|
||||
");
|
||||
while ($row = mysqli_fetch_assoc($sql_assets_select)) {
|
||||
$asset_id = intval($row['asset_id']);
|
||||
$asset_name = escapeHtml($row['asset_name']);
|
||||
|
||||
?>
|
||||
<option value="<?= $asset_id ?>"<?= selectOptionAsset($row['asset_type'] ?? '', trim(($row['asset_make'] ?? '') . ' ' . ($row['asset_model'] ?? ''))) ?>><?= $asset_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="link_asset_to_document" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
require __DIR__ . '/../link/link.php';
|
||||
|
||||
@@ -1,69 +1,12 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
/*
|
||||
* Kept so existing links keep working. Every pair is linked in
|
||||
* agent/modals/link/link.php, here opened on its Contacts tab.
|
||||
*/
|
||||
|
||||
$document_id = intval($_GET['document_id']);
|
||||
$_GET['from'] = 'document';
|
||||
$_GET['id'] = intval($_GET['document_id'] ?? 0);
|
||||
$_GET['to'] = 'contact';
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT document_client_id, document_name FROM documents
|
||||
WHERE document_id = $document_id
|
||||
LIMIT 1
|
||||
");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
$client_id = intval($row['document_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-user me-2"></i>Link Contact to <strong><?= $document_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="document_id" value="<?= $document_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
|
||||
<select class="form-select select2" name="contact_id">
|
||||
<option value="">- Select a Contact -</option>
|
||||
<?php
|
||||
$sql_contacts_select = mysqli_query($mysqli, "
|
||||
SELECT contacts.contact_id, contact_name, contact_client_id, contact_photo, contact_title
|
||||
FROM contacts
|
||||
LEFT JOIN contact_documents
|
||||
ON contacts.contact_id = contact_documents.contact_id
|
||||
AND contact_documents.document_id = $document_id
|
||||
WHERE contact_client_id = $client_id
|
||||
AND contact_archived_at IS NULL
|
||||
AND contact_documents.contact_id IS NULL
|
||||
ORDER BY contact_name ASC
|
||||
");
|
||||
while ($row = mysqli_fetch_assoc($sql_contacts_select)) {
|
||||
$contact_id = intval($row['contact_id']);
|
||||
$contact_name = escapeHtml($row['contact_name']);
|
||||
|
||||
?>
|
||||
<option value="<?= $contact_id ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '', $row['contact_id'] ?? 0) ?>><?= $contact_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="link_contact_to_document" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link Contact</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
require __DIR__ . '/../link/link.php';
|
||||
|
||||
@@ -1,72 +1,12 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
/*
|
||||
* Kept so existing links keep working. Every pair is linked in
|
||||
* agent/modals/link/link.php, here opened on its Files tab.
|
||||
*/
|
||||
|
||||
$document_id = intval($_GET['document_id']);
|
||||
$_GET['from'] = 'document';
|
||||
$_GET['id'] = intval($_GET['document_id'] ?? 0);
|
||||
$_GET['to'] = 'file';
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT document_client_id, document_name FROM documents
|
||||
WHERE document_id = $document_id
|
||||
LIMIT 1
|
||||
");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
$client_id = intval($row['document_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-paperclip me-2"></i>Link File to <strong><?= $document_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="document_id" value="<?= $document_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-paperclip"></i></span>
|
||||
<select class="form-select select2" name="file_id">
|
||||
<option value="">- Select a File -</option>
|
||||
<?php
|
||||
$sql_files_select = mysqli_query($mysqli, "
|
||||
SELECT files.file_id, file_name, folder_name
|
||||
FROM files
|
||||
LEFT JOIN folders
|
||||
ON folder_id = file_folder_id
|
||||
LEFT JOIN document_files
|
||||
ON files.file_id = document_files.file_id
|
||||
AND document_files.document_id = $document_id
|
||||
WHERE file_client_id = $client_id
|
||||
AND file_archived_at IS NULL
|
||||
AND document_files.file_id IS NULL
|
||||
ORDER BY folder_name ASC, file_name ASC
|
||||
");
|
||||
while ($row = mysqli_fetch_assoc($sql_files_select)) {
|
||||
$file_id = intval($row['file_id']);
|
||||
$file_name = escapeHtml($row['file_name']);
|
||||
$folder_name = escapeHtml($row['folder_name']);
|
||||
|
||||
?>
|
||||
<option value="<?= $file_id ?>"><?= "$folder_name/$file_name" ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="link_file_to_document" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link File</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
require __DIR__ . '/../link/link.php';
|
||||
|
||||
@@ -1,70 +1,12 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
/*
|
||||
* Kept so existing links keep working. Every pair is linked in
|
||||
* agent/modals/link/link.php, here opened on its Licenses tab.
|
||||
*/
|
||||
|
||||
$document_id = intval($_GET['document_id']);
|
||||
$_GET['from'] = 'document';
|
||||
$_GET['id'] = intval($_GET['document_id'] ?? 0);
|
||||
$_GET['to'] = 'software';
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT document_client_id, document_name FROM documents
|
||||
WHERE document_id = $document_id
|
||||
LIMIT 1
|
||||
");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
$client_id = intval($row['document_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-user me-2"></i>Link Software to <strong><?= $document_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="document_id" value="<?= $document_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-box-open"></i></span>
|
||||
<select class="form-select select2" name="software_id">
|
||||
<option value="">- Select a License -</option>
|
||||
<?php
|
||||
$sql_software_select = mysqli_query($mysqli, "
|
||||
SELECT software.software_id, software_name
|
||||
FROM software
|
||||
LEFT JOIN software_documents
|
||||
ON software.software_id = software_documents.software_id
|
||||
AND software_documents.document_id = $document_id
|
||||
WHERE software_client_id = $client_id
|
||||
AND software_archived_at IS NULL
|
||||
AND software_documents.software_id IS NULL
|
||||
ORDER BY software_name ASC
|
||||
");
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_software_select)) {
|
||||
$software_id = intval($row['software_id']);
|
||||
$software_name = escapeHtml($row['software_name']);
|
||||
|
||||
?>
|
||||
<option value="<?= $software_id ?>"><?= $software_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="link_software_to_document" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link License</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
require __DIR__ . '/../link/link.php';
|
||||
|
||||
@@ -1,69 +1,12 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
/*
|
||||
* Kept so existing links keep working. Every pair is linked in
|
||||
* agent/modals/link/link.php, here opened on its Vendors tab.
|
||||
*/
|
||||
|
||||
$document_id = intval($_GET['document_id']);
|
||||
$_GET['from'] = 'document';
|
||||
$_GET['id'] = intval($_GET['document_id'] ?? 0);
|
||||
$_GET['to'] = 'vendor';
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT document_client_id, document_name FROM documents
|
||||
WHERE document_id = $document_id
|
||||
LIMIT 1
|
||||
");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
$client_id = intval($row['document_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-building me-2"></i>Link Vendor to <strong><?= $document_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="document_id" value="<?= $document_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-building"></i></span>
|
||||
<select class="form-select select2" name="vendor_id">
|
||||
<option value="">- Select a Vendor -</option>
|
||||
<?php
|
||||
$sql_vendors_select = mysqli_query($mysqli, "
|
||||
SELECT vendors.vendor_id, vendor_name
|
||||
FROM vendors
|
||||
LEFT JOIN vendor_documents
|
||||
ON vendors.vendor_id = vendor_documents.vendor_id
|
||||
AND vendor_documents.document_id = $document_id
|
||||
WHERE vendor_client_id = $client_id
|
||||
AND vendor_archived_at IS NULL
|
||||
AND vendor_documents.vendor_id IS NULL
|
||||
ORDER BY vendor_name ASC
|
||||
");
|
||||
while ($row = mysqli_fetch_assoc($sql_vendors_select)) {
|
||||
$vendor_id = intval($row['vendor_id']);
|
||||
$vendor_name = escapeHtml($row['vendor_name']);
|
||||
|
||||
?>
|
||||
<option value="<?= $vendor_id ?>"><?= $vendor_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="link_vendor_to_document" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link Vendor</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
require __DIR__ . '/../link/link.php';
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Move a document to another of its client's folders.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$document_id = intval($_GET['id']);
|
||||
$document_id = intval($_GET['id'] ?? 0);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT document_client_id, document_folder_id, document_name FROM documents WHERE document_id = $document_id LIMIT 1");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT document_client_id, document_folder_id, document_name FROM documents WHERE document_id = $document_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'That document no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
$client_id = intval($row['document_client_id']);
|
||||
$document_folder_id = escapeHtml($row['document_folder_id']);
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
ob_start();
|
||||
@@ -20,7 +23,7 @@ ob_start();
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-file-alt me-2"></i>Moving document: <strong><?= $document_name ?></strong></h5>
|
||||
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-folder-open me-2"></i>Move <strong><?= escapeHtml($row['document_name']) ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
@@ -28,75 +31,12 @@ ob_start();
|
||||
<input type="hidden" name="document_id" value="<?= $document_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Move Document to</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
<select class="form-select select2" name="folder">
|
||||
<option value="0">/</option>
|
||||
<?php
|
||||
// Fetch all folders for the client
|
||||
$sql_all_folders = mysqli_query($mysqli, "SELECT folder_id, folder_name, parent_folder FROM folders WHERE folder_client_id = $client_id ORDER BY folder_name ASC");
|
||||
$folders = array();
|
||||
|
||||
// Build an associative array of folders indexed by folder_id
|
||||
while ($row = mysqli_fetch_assoc($sql_all_folders)) {
|
||||
$folders[$row['folder_id']] = array(
|
||||
'folder_id' => intval($row['folder_id']),
|
||||
'folder_name' => escapeHtml($row['folder_name']),
|
||||
'parent_folder' => intval($row['parent_folder']),
|
||||
'children' => array()
|
||||
);
|
||||
}
|
||||
|
||||
// Build the folder hierarchy
|
||||
foreach ($folders as $id => &$folder) {
|
||||
if ($folder['parent_folder'] != 0 && isset($folders[$folder['parent_folder']])) {
|
||||
$folders[$folder['parent_folder']]['children'][] = &$folder;
|
||||
}
|
||||
}
|
||||
unset($folder); // Break the reference
|
||||
|
||||
// Prepare a list of root folders
|
||||
$root_folders = array();
|
||||
foreach ($folders as $id => $folder) {
|
||||
if ($folder['parent_folder'] == 0) {
|
||||
$root_folders[] = $folder;
|
||||
}
|
||||
}
|
||||
|
||||
// Display the folder options iteratively
|
||||
$stack = array();
|
||||
foreach (array_reverse($root_folders) as $folder) {
|
||||
$stack[] = array('folder' => $folder, 'level' => 0);
|
||||
}
|
||||
|
||||
while (!empty($stack)) {
|
||||
$node = array_pop($stack);
|
||||
$folder = $node['folder'];
|
||||
$level = $node['level'];
|
||||
|
||||
// Indentation for subfolders
|
||||
$indentation = str_repeat(' ', $level * 4);
|
||||
|
||||
// Check if this folder is selected
|
||||
$selected = '';
|
||||
if ($folder['folder_id'] == $document_folder_id) {
|
||||
$selected = 'selected';
|
||||
}
|
||||
|
||||
echo "<option value=\"{$folder['folder_id']}\" $selected>$indentation{$folder['folder_name']}</option>";
|
||||
|
||||
// Add children to the stack
|
||||
if (!empty($folder['children'])) {
|
||||
foreach (array_reverse($folder['children']) as $child_folder) {
|
||||
$stack[] = array('folder' => $child_folder, 'level' => $level + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<label class="form-label">To folder</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-folder"></i></span>
|
||||
<select class="form-select select2" name="folder">
|
||||
<?= folderOptionsHtml($client_id, intval($row['document_folder_id'])) ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -1,25 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Rename a document and change its summary, without opening the editor.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$document_id = intval($_GET['id']);
|
||||
$document_id = intval($_GET['id'] ?? 0);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT document_client_id, document_name FROM documents WHERE document_id = $document_id LIMIT 1");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT document_client_id, document_name, document_description FROM documents WHERE document_id = $document_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'That document no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
$client_id = intval($row['document_client_id']);
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-file-alt me-2"></i>Renaming document: <strong><?= $document_name ?></strong></h5>
|
||||
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-pen me-2"></i>Rename <strong><?= $document_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
@@ -28,16 +34,24 @@ ob_start();
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Document Name <strong class="text-danger">*</strong></label>
|
||||
<label class="form-label">Name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-file-alt"></i></span>
|
||||
<input class="form-control" type="text" name="name" maxlength="200" value="<?= $document_name ?>" required>
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-file-alt"></i></span>
|
||||
<input class="form-control" type="text" name="name" maxlength="200" value="<?= $document_name ?>" required autofocus>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Summary</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-align-left"></i></span>
|
||||
<input class="form-control" type="text" name="description" value="<?= escapeHtml($row['document_description']) ?>" placeholder="One line on what it covers">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="rename_document" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Rename</button>
|
||||
<button type="submit" name="rename_document" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -1,38 +1,70 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* One saved version of a document - what it said before an edit - with a way
|
||||
* to put it back. Restoring keeps the current content as a version too.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support');
|
||||
enforceUserPermission('module_client');
|
||||
|
||||
// Initialize the HTML Purifier to prevent XSS
|
||||
require_once "../../../libs/htmlpurifier/HTMLPurifier.standalone.php";
|
||||
$document_version_id = intval($_GET['id'] ?? 0);
|
||||
|
||||
$purifier_config = HTMLPurifier_Config::createDefault();
|
||||
$purifier_config->set('Cache.DefinitionImpl', null); // Disable cache by setting a non-existent directory or an invalid one
|
||||
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
|
||||
$purifier = new HTMLPurifier($purifier_config);
|
||||
|
||||
$document_version_id = intval($_GET['id']);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT document_client_id, document_version_content, document_version_name FROM document_versions LEFT JOIN documents ON document_id = document_version_document_id WHERE document_version_id = $document_version_id LIMIT 1");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$document_version_name = escapeHtml($row['document_version_name']);
|
||||
$document_version_content = $purifier->purify($row['document_version_content']);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT document_version_id, document_version_name, document_version_description, document_version_content,
|
||||
document_version_created_at, document_version_document_id, document_client_id, document_archived_at, user_name
|
||||
FROM document_versions
|
||||
JOIN documents ON document_id = document_version_document_id
|
||||
LEFT JOIN users ON document_version_created_by = user_id
|
||||
WHERE document_version_id = $document_version_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'That version no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
$client_id = intval($row['document_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
$can_edit = lookupUserPermission('module_support') >= 2 && empty($row['document_archived_at']);
|
||||
$can_delete = lookupUserPermission('module_support') >= 3;
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title text-white"><i class="fa fa-fw fa-file-alt me-2"></i><?= $document_version_name ?></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
<div class="modal-header bg-dark" data-bs-theme="dark">
|
||||
<div class="d-flex align-items-center gap-3 min-w-0">
|
||||
<span class="itflow-file-icon itflow-file-icon-lg itflow-file-tone-text" aria-hidden="true"><i class="fas fa-fw fa-history"></i></span>
|
||||
<div class="min-w-0">
|
||||
<h5 class="modal-title fw-semibold text-break"><?= escapeHtml($row['document_version_name']) ?></h5>
|
||||
<div class="small text-body-secondary mt-1">
|
||||
Version of <?= date('M j, Y g:ia', strtotime($row['document_version_created_at'])) ?><?= $row['user_name'] ? ' by ' . escapeHtml($row['user_name']) : '' ?>
|
||||
<?php if ($row['document_version_description']) { ?> · <?= escapeHtml($row['document_version_description']) ?><?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body prettyContent">
|
||||
<?= $document_version_content ?>
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="prettyContent itflow-document-quick-content"><?= documentHtmlPurify($row['document_version_content']) ?: '<p class="text-body-secondary mb-0">This version was empty.</p>' ?></div>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<?php if ($can_delete) { ?>
|
||||
<a class="btn btn-outline-danger confirm-link me-auto" href="post.php?delete_document_version=<?= $document_version_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>" data-confirm-text="This version is removed from the history for good.">
|
||||
<i class="fas fa-trash me-2"></i>Delete version
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($can_edit) { ?>
|
||||
<form action="post.php" method="post" class="d-inline">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="document_version_id" value="<?= $document_version_id ?>">
|
||||
<button type="submit" name="restore_document_version" class="btn btn-primary text-bold confirm-link" data-confirm-title="Put this version back?" data-confirm-text="What the document says now is kept in its history." data-confirm-button="Restore">
|
||||
<i class="fas fa-undo me-2"></i>Restore this version
|
||||
</button>
|
||||
</form>
|
||||
<?php } ?>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Close</button>
|
||||
</div>
|
||||
|
||||
<script src="../js/pretty_content.js"></script>
|
||||
|
||||
@@ -1,38 +1,75 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* A document's quick look - its content, where it lives, and what it is linked
|
||||
* to, without leaving the page. Open goes to the full document page.
|
||||
*
|
||||
* Readable by anyone who can open the document page (client access).
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support');
|
||||
enforceUserPermission('module_client');
|
||||
|
||||
// Initialize the HTML Purifier to prevent XSS
|
||||
require_once "../../../libs/htmlpurifier/HTMLPurifier.standalone.php";
|
||||
$document_id = intval($_GET['id'] ?? 0);
|
||||
|
||||
$purifier_config = HTMLPurifier_Config::createDefault();
|
||||
$purifier_config->set('Cache.DefinitionImpl', null); // Disable cache by setting a non-existent directory or an invalid one
|
||||
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
|
||||
$purifier = new HTMLPurifier($purifier_config);
|
||||
|
||||
$document_id = intval($_GET['id']);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT document_client_id, document_content, document_name FROM documents WHERE document_id = $document_id LIMIT 1");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$document_name = escapeHtml($row['document_name']);
|
||||
$document_content = $purifier->purify($row['document_content']);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT document_client_id, document_content, document_name, document_description, document_folder_id,
|
||||
document_client_visible, document_archived_at, document_created_at, document_updated_at, COALESCE(updater.user_name, creator.user_name) AS user_name
|
||||
FROM documents
|
||||
LEFT JOIN users creator ON document_created_by = creator.user_id
|
||||
LEFT JOIN users updater ON document_updated_by = updater.user_id
|
||||
WHERE document_id = $document_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'That document no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
$client_id = intval($row['document_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
$can_edit = lookupUserPermission('module_support') >= 2;
|
||||
$document_archived = !empty($row['document_archived_at']);
|
||||
$folder_tree = folderTree($client_id);
|
||||
$folder_id = isset($folder_tree[intval($row['document_folder_id'])]) ? intval($row['document_folder_id']) : 0;
|
||||
$folder_label = $folder_id ? implode(' / ', array_column(folderPath($folder_tree, $folder_id), 'folder_name')) : 'Top level';
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title text-white"><i class="fa fa-fw fa-file-alt me-2"></i><?= $document_name ?></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
<div class="modal-header bg-dark" data-bs-theme="dark">
|
||||
<div class="d-flex align-items-center gap-3 min-w-0">
|
||||
<?= documentTile('lg') ?>
|
||||
<div class="min-w-0">
|
||||
<h5 class="modal-title d-flex flex-wrap align-items-center column-gap-2">
|
||||
<span class="fw-semibold text-break"><?= escapeHtml($row['document_name']) ?></span>
|
||||
<?php if ($document_archived) { ?><span class="badge rounded-pill text-bg-secondary fw-normal fs-6">Archived</span><?php } ?>
|
||||
<?php if (intval($row['document_client_visible'])) { ?><span class="badge rounded-pill bg-info-subtle text-info-emphasis fw-normal fs-6">Portal</span><?php } ?>
|
||||
</h5>
|
||||
<div class="small text-body-secondary mt-1">
|
||||
<?php if ($row['document_description']) { ?><?= escapeHtml($row['document_description']) ?> · <?php } ?>
|
||||
Updated <?= timeAgo($row['document_updated_at'] ?: $row['document_created_at']) ?><?= $row['user_name'] ? ' by ' . escapeHtml($row['user_name']) : '' ?>
|
||||
· <i class="fas fa-folder me-1"></i><?= escapeHtml($folder_label) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body prettyContent">
|
||||
<?= $document_content ?>
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="prettyContent itflow-document-quick-content"><?= documentHtmlPurify($row['document_content']) ?: '<p class="text-body-secondary mb-0">This document is empty.</p>' ?></div>
|
||||
|
||||
<div class="mt-3">
|
||||
<div class="small fw-semibold text-uppercase text-body-secondary mb-2">Linked</div>
|
||||
<?= linkGroupsHtml('document', $document_id, $client_id, $document_archived) ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<a href="document.php?client_id=<?= $client_id ?>&document_id=<?= $document_id ?>" class="btn btn-primary text-bold"><i class="fas fa-arrow-right me-2"></i>Open document</a>
|
||||
<?php if ($can_edit && !$document_archived) { ?>
|
||||
<button type="button" class="btn btn-outline-secondary ajax-modal" data-modal-size="xl" data-modal-url="modals/document/document_edit.php?id=<?= $document_id ?>"><i class="fas fa-edit me-2"></i>Edit</button>
|
||||
<?php } ?>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Close</button>
|
||||
</div>
|
||||
|
||||
<script src="../js/pretty_content.js"></script>
|
||||
|
||||
139
agent/modals/file/file.php
Normal file
139
agent/modals/file/file.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* A file's quick look - what it is, a preview where the browser can show one,
|
||||
* where it lives, who uploaded it, and everything it is linked to - opened
|
||||
* from the files list, the grid's previewer, and anywhere a linked file is
|
||||
* listed (a document, an asset, a contact).
|
||||
*
|
||||
* Readable by anyone who can open the file itself (agent/file.php asks for
|
||||
* client access, not support), changed by support write access.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_client');
|
||||
|
||||
$file_id = intval($_GET['id'] ?? 0);
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT file_id, file_name, file_description, file_reference_name, file_ext, file_size,
|
||||
file_mime_type, file_created_at, file_updated_at, file_archived_at, file_folder_id, file_client_id, user_name
|
||||
FROM files LEFT JOIN users ON file_created_by = user_id
|
||||
WHERE file_id = $file_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'That file no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$client_id = intval($row['file_client_id']);
|
||||
enforceClientAccess();
|
||||
|
||||
$can_edit = lookupUserPermission('module_support') >= 2;
|
||||
$file_name = escapeHtml($row['file_name']);
|
||||
$file_archived = !empty($row['file_archived_at']);
|
||||
$file_info = fileTypeInfo($row['file_ext']);
|
||||
$file_mime = $row['file_mime_type'];
|
||||
|
||||
// What the preview can show - the same rule agent/file.php serves inline by
|
||||
if (!in_array($file_mime, getInlineViewableMimeTypes(), true)) {
|
||||
$preview_kind = '';
|
||||
} elseif ($file_mime === 'application/pdf') {
|
||||
$preview_kind = 'pdf';
|
||||
} elseif ($file_mime === 'text/plain' || $file_mime === 'application/json') {
|
||||
$preview_kind = 'text';
|
||||
} else {
|
||||
$preview_kind = 'image';
|
||||
}
|
||||
|
||||
$folder_tree = folderTree($client_id);
|
||||
$folder_id = isset($folder_tree[intval($row['file_folder_id'])]) ? intval($row['file_folder_id']) : 0;
|
||||
$folder_label = $folder_id ? implode(' / ', array_column(folderPath($folder_tree, $folder_id), 'folder_name')) : 'Top level';
|
||||
|
||||
$share = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT item_recipient, item_expire_at FROM shared_items
|
||||
WHERE item_client_id = $client_id AND item_type = 'File' AND item_related_id = $file_id AND item_active = 1
|
||||
AND (COALESCE(item_view_limit, 0) = 0 OR item_views < item_view_limit) AND item_expire_at > NOW()
|
||||
ORDER BY item_expire_at DESC LIMIT 1"));
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark" data-bs-theme="dark">
|
||||
<div class="d-flex align-items-center gap-3 min-w-0">
|
||||
<?= fileTypeTile($row['file_ext'], 'lg') ?>
|
||||
<div class="min-w-0">
|
||||
<h5 class="modal-title d-flex flex-wrap align-items-center column-gap-2">
|
||||
<span class="fw-semibold text-break"><?= $file_name ?></span>
|
||||
<?php if ($file_archived) { ?><span class="badge rounded-pill text-bg-secondary fw-normal fs-6">Archived</span><?php } ?>
|
||||
</h5>
|
||||
<div class="small text-body-secondary mt-1"><?= escapeHtml($file_info['label']) ?> · <?= formatBytes(intval($row['file_size'])) ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<!-- Preview -->
|
||||
<div class="itflow-file-preview mb-3">
|
||||
<?php if ($preview_kind === 'image') { ?>
|
||||
<a href="file.php?file_id=<?= $file_id ?>&action=view" target="_blank" title="Open full size"><img src="file.php?file_id=<?= $file_id ?>&thumb=1" alt="<?= $file_name ?>"></a>
|
||||
<?php } elseif ($preview_kind === 'pdf') { ?>
|
||||
<iframe src="file.php?file_id=<?= $file_id ?>&action=view#view=FitH" title="<?= $file_name ?>"></iframe>
|
||||
<?php } elseif ($preview_kind === 'text') { ?>
|
||||
<pre><?= escapeHtml(getFileTextExcerpt($client_id, $row['file_reference_name'], 2000)) ?></pre>
|
||||
<?php } else { ?>
|
||||
<div class="itflow-asset-empty py-4">
|
||||
<?= fileTypeTile($row['file_ext'], 'lg') ?>
|
||||
<div class="mt-2">No preview for this kind of file - download it to open it.</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<!-- At a glance -->
|
||||
<div class="row g-2 itflow-asset-glance">
|
||||
<div class="col-sm-6">
|
||||
<div class="itflow-glance-item" title="Folder">
|
||||
<i class="fas fa-fw fa-folder"></i>
|
||||
<a class="text-truncate" href="files.php?client_id=<?= $client_id ?>&folder_id=<?= $folder_id ?>"><?= escapeHtml($folder_label) ?></a>
|
||||
</div>
|
||||
<div class="itflow-glance-item" title="Uploaded">
|
||||
<i class="fas fa-fw fa-cloud-upload-alt"></i>
|
||||
<span><span title="<?= escapeHtml($row['file_created_at']) ?>"><?= timeAgo($row['file_created_at']) ?></span><?php if ($row['user_name']) { ?> <span class="text-body-secondary">by <?= escapeHtml($row['user_name']) ?></span><?php } ?></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<?php if ($row['file_description']) { ?>
|
||||
<div class="itflow-glance-item" title="Description">
|
||||
<i class="fas fa-fw fa-align-left"></i>
|
||||
<span><?= escapeHtml($row['file_description']) ?></span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if ($share) { ?>
|
||||
<div class="itflow-glance-item" title="Shared">
|
||||
<i class="fas fa-fw fa-link"></i>
|
||||
<span>Shared<?= $share['item_recipient'] ? ' with ' . escapeHtml($share['item_recipient']) : '' ?> <span class="text-body-secondary">· link expires <?= timeAgo($share['item_expire_at']) ?></span></span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- What it is linked to -->
|
||||
<div class="mt-3">
|
||||
<div class="small fw-semibold text-uppercase text-body-secondary mb-2">Linked</div>
|
||||
<?= linkGroupsHtml('file', $file_id, $client_id, $file_archived) ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<a class="btn btn-primary text-bold" href="file.php?file_id=<?= $file_id ?>"><i class="fas fa-download me-2"></i>Download</a>
|
||||
<?php if ($can_edit && !$file_archived) { ?>
|
||||
<button type="button" class="btn btn-outline-secondary ajax-modal" data-modal-url="modals/file/file_rename.php?id=<?= $file_id ?>"><i class="fas fa-pen me-2"></i>Rename</button>
|
||||
<button type="button" class="btn btn-outline-secondary ajax-modal" data-modal-url="modals/file/file_move.php?id=<?= $file_id ?>"><i class="fas fa-folder-open me-2"></i>Move</button>
|
||||
<?php } ?>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Close</button>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
@@ -1,131 +1,63 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Move the ticked files and documents to one folder. The ids come from the
|
||||
* ticked rows (js/bulk_actions.js adds them to this modal's URL).
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$client_id = intval($_GET['client_id'] ?? 0);
|
||||
$current_folder_id = intval($_GET['current_folder_id'] ?? 0);
|
||||
|
||||
// Selected IDs from JS (may be empty arrays)
|
||||
$file_ids = array_map('intval', $_GET['file_ids'] ?? []);
|
||||
$document_ids = array_map('intval', $_GET['document_ids'] ?? []);
|
||||
|
||||
$count_files = count($file_ids);
|
||||
$count_docs = count($document_ids);
|
||||
$total = $count_files + $count_docs;
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
$current_folder_id = folderOwnedId($_GET['current_folder_id'] ?? 0, $client_id);
|
||||
$file_ids = array_values(array_unique(array_filter(array_map('intval', (array) ($_GET['file_ids'] ?? [])))));
|
||||
$document_ids = array_values(array_unique(array_filter(array_map('intval', (array) ($_GET['document_ids'] ?? [])))));
|
||||
$total = count($file_ids) + count($document_ids);
|
||||
|
||||
if (!$total) {
|
||||
echo json_encode(['error' => 'Tick the files or documents to move first.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$summary = implode(' and ', array_filter([
|
||||
$document_ids ? count($document_ids) . ' document' . (count($document_ids) === 1 ? '' : 's') : '',
|
||||
$file_ids ? count($file_ids) . ' file' . (count($file_ids) === 1 ? '' : 's') : '',
|
||||
]));
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title">
|
||||
<i class="fa fa-fw fa-exchange-alt me-2"></i>
|
||||
Move <strong><?= $total ?></strong> Item<?= $total === 1 ? '' : 's' ?>
|
||||
</h5>
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-folder-open me-2"></i>Move <?= $summary ?></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
|
||||
<?php foreach ($file_ids as $id): ?>
|
||||
<?php foreach ($file_ids as $id) { ?>
|
||||
<input type="hidden" name="file_ids[]" value="<?= $id ?>">
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php foreach ($document_ids as $id): ?>
|
||||
<?php } ?>
|
||||
<?php foreach ($document_ids as $id) { ?>
|
||||
<input type="hidden" name="document_ids[]" value="<?= $id ?>">
|
||||
<?php endforeach; ?>
|
||||
<?php } ?>
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<p>
|
||||
Files: <strong><?= $count_files ?></strong><br>
|
||||
Documents: <strong><?= $count_docs ?></strong>
|
||||
</p>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Target Folder</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
<select class="form-select select2" name="bulk_folder_id">
|
||||
<option value="0">/</option>
|
||||
<?php
|
||||
// NOTE: folder_location is gone now, so just use folder_client_id
|
||||
$sql_all_folders = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT folder_id, folder_name, parent_folder
|
||||
FROM folders
|
||||
WHERE folder_client_id = $client_id
|
||||
ORDER BY folder_name ASC"
|
||||
);
|
||||
|
||||
$folders = [];
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_all_folders)) {
|
||||
$folders[$row['folder_id']] = [
|
||||
'folder_id' => (int)$row['folder_id'],
|
||||
'folder_name' => escapeHtml($row['folder_name']),
|
||||
'parent_folder'=> (int)$row['parent_folder'],
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
// Build hierarchy
|
||||
foreach ($folders as $id => &$folder) {
|
||||
if ($folder['parent_folder'] != 0 && isset($folders[$folder['parent_folder']])) {
|
||||
$folders[$folder['parent_folder']]['children'][] = &$folder;
|
||||
}
|
||||
}
|
||||
unset($folder);
|
||||
|
||||
$root_folders = [];
|
||||
foreach ($folders as $id => $folder) {
|
||||
if ($folder['parent_folder'] == 0) {
|
||||
$root_folders[] = $folder;
|
||||
}
|
||||
}
|
||||
|
||||
// Optional: if you want to default-select current folder, pass it in GET
|
||||
$current_folder_id = intval($_GET['current_folder_id'] ?? 0);
|
||||
|
||||
$stack = [];
|
||||
foreach (array_reverse($root_folders) as $folder) {
|
||||
$stack[] = ['folder' => $folder, 'level' => 0];
|
||||
}
|
||||
|
||||
while (!empty($stack)) {
|
||||
$node = array_pop($stack);
|
||||
$folder = $node['folder'];
|
||||
$level = $node['level'];
|
||||
|
||||
$indentation = str_repeat(' ', $level * 4);
|
||||
|
||||
$selected = ($folder['folder_id'] === $current_folder_id) ? 'selected' : '';
|
||||
|
||||
echo "<option value=\"{$folder['folder_id']}\" $selected>$indentation{$folder['folder_name']}</option>";
|
||||
|
||||
if (!empty($folder['children'])) {
|
||||
foreach (array_reverse($folder['children']) as $child) {
|
||||
$stack[] = ['folder' => $child, 'level' => $level + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<label class="form-label">To folder</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-folder"></i></span>
|
||||
<select class="form-select select2" name="bulk_folder_id">
|
||||
<?= folderOptionsHtml($client_id, $current_folder_id) ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="bulk_move_files" class="btn btn-primary text-bold">
|
||||
<i class="fa fa-check me-2"></i>Move Files
|
||||
</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal">
|
||||
<i class="fa fa-times me-2"></i>Cancel
|
||||
</button>
|
||||
<button type="submit" name="bulk_move_files" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Move</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
@@ -1,21 +1,41 @@
|
||||
<script src="js/file_delete_modal.js"></script>
|
||||
<div class="modal" id="deleteFileModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body">
|
||||
<div class="mb-4" style="text-align: center;">
|
||||
<i class="far fa-10x fa-times-circle text-danger mb-3 mt-3"></i>
|
||||
<h2>Are you sure?</h2>
|
||||
<h6 class="mb-4 text-secondary">Do you really want to delete this file?</h6>
|
||||
<h5 class="mb-4 text-secondary text-bold" id="file_delete_name">Name</h5>
|
||||
<form action="post.php" method="POST">
|
||||
<input type="hidden" name="file_id" id="file_delete_id" value="id">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<button type="button" name="cancel" class="btn btn-outline-secondary btn-lg px-5 me-4" data-bs-dismiss="modal">Cancel</button>
|
||||
<input type="submit" name="delete_file" class="btn btn-danger btn-lg px-5" value="Yes, Delete!">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Delete an archived file for good - the file on disk and every link to it.
|
||||
* An ajax modal so the file's name is drawn by the server, escaped, rather
|
||||
* than written into an onclick handler.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 3);
|
||||
|
||||
$file_id = intval($_GET['id'] ?? 0);
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT file_client_id, file_ext, file_name, file_size FROM files WHERE file_id = $file_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'That file no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
$client_id = intval($row['file_client_id']);
|
||||
enforceClientAccess();
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-body text-center py-4">
|
||||
<div class="mb-3"><?= fileTypeTile($row['file_ext'], 'lg') ?></div>
|
||||
<h5 class="mb-1">Delete this file for good?</h5>
|
||||
<div class="fw-semibold text-break"><?= escapeHtml($row['file_name']) ?></div>
|
||||
<div class="small text-body-secondary mb-4"><?= formatBytes(intval($row['file_size'])) ?> · it is removed from the server and unlinked from everything. This cannot be undone.</div>
|
||||
<form action="post.php" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="file_id" value="<?= $file_id ?>">
|
||||
<button type="button" class="btn btn-light px-4 me-2" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="submit" name="delete_file" class="btn btn-danger px-4"><i class="fas fa-trash me-2"></i>Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
|
||||
@@ -1,72 +1,12 @@
|
||||
<div class="modal" id="linkAssetToFileModal<?= $file_id ?>" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-desktop me-2"></i>Link Asset to <strong><?= $file_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="file_id" value="<?= $file_id ?>">
|
||||
<div class="modal-body">
|
||||
<?php
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-desktop"></i></span>
|
||||
<select class="form-select select2" name="asset_id">
|
||||
<option value="">- Select an Asset -</option>
|
||||
<?php
|
||||
/*
|
||||
* Kept so existing links keep working. Every pair is linked in
|
||||
* agent/modals/link/link.php, here opened on its Assets tab.
|
||||
*/
|
||||
|
||||
$sql_assets_select = mysqli_query($mysqli, "SELECT asset_id, asset_name, asset_type, asset_make, asset_model FROM assets
|
||||
WHERE asset_client_id = $client_id
|
||||
AND asset_archived_at IS NULL
|
||||
ORDER BY asset_name ASC"
|
||||
);
|
||||
while ($row = mysqli_fetch_assoc($sql_assets_select)) {
|
||||
$asset_id = intval($row['asset_id']);
|
||||
$asset_name = escapeHtml($row['asset_name']);
|
||||
$_GET['from'] = 'file';
|
||||
$_GET['id'] = intval($_GET['id'] ?? 0);
|
||||
$_GET['to'] = 'asset';
|
||||
|
||||
?>
|
||||
<option value="<?= $asset_id ?>"<?= selectOptionAsset($row['asset_type'] ?? '', trim(($row['asset_make'] ?? '') . ' ' . ($row['asset_model'] ?? ''))) ?>><?= $asset_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$sql_assets = mysqli_query($mysqli, "SELECT assets.asset_id, asset_name FROM assets, asset_files
|
||||
WHERE assets.asset_id = asset_files.asset_id
|
||||
AND asset_files.file_id = $file_id
|
||||
ORDER BY asset_name ASC"
|
||||
);
|
||||
|
||||
$linked_assets = array();
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_assets)) {
|
||||
$asset_id = intval($row['asset_id']);
|
||||
$asset_name = escapeHtml($row['asset_name']);
|
||||
|
||||
$linked_assets[] = $asset_id;
|
||||
|
||||
?>
|
||||
<div class="ms-2">
|
||||
<a href="asset.php?client_id=<?= $client_id ?>&asset_id=<?= $asset_id ?>" target="_blank"><?= $asset_name ?></a>
|
||||
<a class="confirm-link float-end" href="post.php?unlink_asset_from_file&asset_id=<?= $asset_id ?>&file_id=<?= $file_id ?>">
|
||||
<i class="fas fa-fw fa-trash-alt text-secondary"></i>
|
||||
</a>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="link_asset_to_file" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
require __DIR__ . '/../link/link.php';
|
||||
|
||||
@@ -1,50 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Move a file to another of its client's folders.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$file_id = intval($_GET['id']);
|
||||
$file_id = intval($_GET['id'] ?? 0);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT file_client_id, file_ext, file_folder_id, file_name FROM files WHERE file_id = $file_id LIMIT 1");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
$file_folder_id = escapeHtml($row['file_folder_id']);
|
||||
$file_name = escapeHtml($row['file_name']);
|
||||
$file_ext = escapeHtml($row['file_ext']);
|
||||
if ($file_ext == 'pdf') {
|
||||
$file_icon = "file-pdf";
|
||||
} elseif ($file_ext == 'gz' || $file_ext == 'tar' || $file_ext == 'zip' || $file_ext == '7z' || $file_ext == 'rar') {
|
||||
$file_icon = "file-archive";
|
||||
} elseif ($file_ext == 'txt' || $file_ext == 'md') {
|
||||
$file_icon = "file-alt";
|
||||
} elseif ($file_ext == 'msg') {
|
||||
$file_icon = "envelope";
|
||||
} elseif ($file_ext == 'doc' || $file_ext == 'docx' || $file_ext == 'odt') {
|
||||
$file_icon = "file-word";
|
||||
} elseif ($file_ext == 'xls' || $file_ext == 'xlsx' || $file_ext == 'ods') {
|
||||
$file_icon = "file-excel";
|
||||
} elseif ($file_ext == 'pptx' || $file_ext == 'odp') {
|
||||
$file_icon = "file-powerpoint";
|
||||
} elseif ($file_ext == 'mp3' || $file_ext == 'wav' || $file_ext == 'ogg') {
|
||||
$file_icon = "file-audio";
|
||||
} elseif ($file_ext == 'mov' || $file_ext == 'mp4' || $file_ext == 'av1') {
|
||||
$file_icon = "file-video";
|
||||
} elseif ($file_ext == 'jpg' || $file_ext == 'jpeg' || $file_ext == 'png' || $file_ext == 'gif' || $file_ext == 'webp' || $file_ext == 'bmp' || $file_ext == 'tif') {
|
||||
$file_icon = "file-image";
|
||||
} else {
|
||||
$file_icon = "file";
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT file_client_id, file_ext, file_folder_id, file_name FROM files WHERE file_id = $file_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'That file no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$client_id = intval($row['file_client_id']);
|
||||
enforceClientAccess();
|
||||
|
||||
$file_name = escapeHtml($row['file_name']);
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-<?= $file_icon ?> me-2"></i>Moving File: <strong><?= $file_name ?></strong></h5>
|
||||
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-folder-open me-2"></i>Move <strong><?= $file_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
@@ -52,75 +32,12 @@ ob_start();
|
||||
<input type="hidden" name="file_id" value="<?= $file_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Move File to</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
<select class="form-select select2" name="folder_id">
|
||||
<option value="0">/</option>
|
||||
<?php
|
||||
// Fetch all folders for the client
|
||||
$sql_all_folders = mysqli_query($mysqli, "SELECT folder_id, folder_name, parent_folder FROM folders WHERE folder_client_id = $client_id ORDER BY folder_name ASC");
|
||||
$folders = array();
|
||||
|
||||
// Build an associative array of folders indexed by folder_id
|
||||
while ($row = mysqli_fetch_assoc($sql_all_folders)) {
|
||||
$folders[$row['folder_id']] = array(
|
||||
'folder_id' => intval($row['folder_id']),
|
||||
'folder_name' => escapeHtml($row['folder_name']),
|
||||
'parent_folder' => intval($row['parent_folder']),
|
||||
'children' => array()
|
||||
);
|
||||
}
|
||||
|
||||
// Build the folder hierarchy
|
||||
foreach ($folders as $id => &$folder) {
|
||||
if ($folder['parent_folder'] != 0 && isset($folders[$folder['parent_folder']])) {
|
||||
$folders[$folder['parent_folder']]['children'][] = &$folder;
|
||||
}
|
||||
}
|
||||
unset($folder); // Break the reference
|
||||
|
||||
// Prepare a list of root folders
|
||||
$root_folders = array();
|
||||
foreach ($folders as $id => $folder) {
|
||||
if ($folder['parent_folder'] == 0) {
|
||||
$root_folders[] = $folder;
|
||||
}
|
||||
}
|
||||
|
||||
// Display the folder options iteratively
|
||||
$stack = array();
|
||||
foreach (array_reverse($root_folders) as $folder) {
|
||||
$stack[] = array('folder' => $folder, 'level' => 0);
|
||||
}
|
||||
|
||||
while (!empty($stack)) {
|
||||
$node = array_pop($stack);
|
||||
$folder = $node['folder'];
|
||||
$level = $node['level'];
|
||||
|
||||
// Indentation for subfolders
|
||||
$indentation = str_repeat(' ', $level * 4);
|
||||
|
||||
// Check if this folder is selected
|
||||
$selected = '';
|
||||
if ($folder['folder_id'] == $file_folder_id) {
|
||||
$selected = 'selected';
|
||||
}
|
||||
|
||||
echo "<option value=\"{$folder['folder_id']}\" $selected>$indentation{$folder['folder_name']}</option>";
|
||||
|
||||
// Add children to the stack
|
||||
if (!empty($folder['children'])) {
|
||||
foreach (array_reverse($folder['children']) as $child_folder) {
|
||||
$stack[] = array('folder' => $child_folder, 'level' => $level + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<label class="form-label">To folder</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-folder"></i></span>
|
||||
<select class="form-select select2" name="folder_id">
|
||||
<?= folderOptionsHtml($client_id, intval($row['file_folder_id'])) ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -1,49 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Rename a file and change its description.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$file_id = intval($_GET['id']);
|
||||
$file_id = intval($_GET['id'] ?? 0);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT file_client_id, file_description, file_name FROM files WHERE file_id = $file_id LIMIT 1");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT file_client_id, file_description, file_ext, file_name FROM files WHERE file_id = $file_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'That file no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
$client_id = intval($row['file_client_id']);
|
||||
enforceClientAccess();
|
||||
|
||||
$file_name = escapeHtml($row['file_name']);
|
||||
$file_description = escapeHtml($row['file_description']);
|
||||
$file_ext = escapeHtml($row['file_description']);
|
||||
|
||||
if ($file_ext == 'pdf') {
|
||||
$file_icon = "file-pdf";
|
||||
} elseif ($file_ext == 'gz' || $file_ext == 'tar' || $file_ext == 'zip' || $file_ext == '7z' || $file_ext == 'rar') {
|
||||
$file_icon = "file-archive";
|
||||
} elseif ($file_ext == 'txt' || $file_ext == 'md') {
|
||||
$file_icon = "file-alt";
|
||||
} elseif ($file_ext == 'msg') {
|
||||
$file_icon = "envelope";
|
||||
} elseif ($file_ext == 'doc' || $file_ext == 'docx' || $file_ext == 'odt') {
|
||||
$file_icon = "file-word";
|
||||
} elseif ($file_ext == 'xls' || $file_ext == 'xlsx' || $file_ext == 'ods') {
|
||||
$file_icon = "file-excel";
|
||||
} elseif ($file_ext == 'pptx' || $file_ext == 'odp') {
|
||||
$file_icon = "file-powerpoint";
|
||||
} elseif ($file_ext == 'mp3' || $file_ext == 'wav' || $file_ext == 'ogg') {
|
||||
$file_icon = "file-audio";
|
||||
} elseif ($file_ext == 'mov' || $file_ext == 'mp4' || $file_ext == 'av1') {
|
||||
$file_icon = "file-video";
|
||||
} elseif ($file_ext == 'jpg' || $file_ext == 'jpeg' || $file_ext == 'png' || $file_ext == 'gif' || $file_ext == 'webp' || $file_ext == 'bmp' || $file_ext == 'tif') {
|
||||
$file_icon = "file-image";
|
||||
} else {
|
||||
$file_icon = "file";
|
||||
}
|
||||
|
||||
enforceClientAccess();
|
||||
$file_info = fileTypeInfo($row['file_ext']);
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-<?= $file_icon ?> me-2"></i>Renaming file: <strong><?= $file_name ?></strong></h5>
|
||||
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-<?= $file_info['icon'] ?> me-2"></i>Rename <strong><?= $file_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
@@ -52,24 +35,24 @@ ob_start();
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>File Name <strong class="text-danger">*</strong></label>
|
||||
<label class="form-label">Name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
<input type="text" class="form-control" name="file_name" placeholder="File Name" maxlength="200" value="<?= $file_name ?>" required>
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-<?= $file_info['icon'] ?>"></i></span>
|
||||
<input type="text" class="form-control" name="file_name" placeholder="File name" maxlength="200" value="<?= $file_name ?>" required autofocus>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Description</label>
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Description</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
<input type="text" class="form-control" name="file_description" placeholder="Description" maxlength="250" value="<?= $file_description ?>">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-align-left"></i></span>
|
||||
<input type="text" class="form-control" name="file_description" placeholder="What this is" maxlength="250" value="<?= $file_description ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="rename_file" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Rename</button>
|
||||
<button type="submit" name="rename_file" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -1,98 +1,168 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Upload files into a folder - dropped onto the box, picked with the button,
|
||||
* or dropped straight onto the files list (agent/js/files.js opens this and
|
||||
* hands them over). Opened from an asset or a contact, the uploads are also
|
||||
* linked to it.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
$client_id = intval($_GET['client_id'] ?? 0);
|
||||
$contact_id = intval($_GET['contact_id'] ?? 0);
|
||||
$asset_id = intval($_GET['asset_id'] ?? 0);
|
||||
intval($_GET['folder_id'] ?? 0);
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$client_id = intval($_GET['client_id'] ?? 0);
|
||||
enforceClientAccess();
|
||||
|
||||
$folder_id = folderOwnedId($_GET['folder_id'] ?? 0, $client_id);
|
||||
$contact_id = assetClientOwnedId('contact', $_GET['contact_id'] ?? 0, $client_id);
|
||||
$asset = linkRecord('asset', $_GET['asset_id'] ?? 0);
|
||||
$asset_id = $asset && intval($asset['client_id']) === $client_id ? intval($asset['id']) : 0;
|
||||
$link_name = $asset_id ? $asset['name'] : ($contact_id ? getFieldById('contacts', $contact_id, 'contact_name') : '');
|
||||
|
||||
// The extensions agent/post/file.php accepts - offered to the picker so the wrong kind is never chosen
|
||||
$upload_extensions = ['jpg', 'jpeg', 'gif', 'png', 'webp', 'pdf', 'txt', 'md', 'doc', 'docx', 'odt', 'csv', 'xls', 'xlsx', 'ods',
|
||||
'pptx', 'odp', 'zip', 'tar', 'gz', 'msg', 'json', 'wav', 'mp3', 'ogg', 'mov', 'mp4', 'av1', 'ovpn', 'cfg', 'ps1', 'vsdx',
|
||||
'drawio', 'pfx', 'pages', 'numbers', 'unf', 'unifi', 'key', 'stk', 'bat', 'swb'];
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-cloud-upload-alt me-2"></i>Upload File(s)</h5>
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-cloud-upload-alt me-2"></i>Upload files</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
|
||||
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off" data-upload-form>
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="client_id" value="<?= $client_id ?>">
|
||||
<input type="hidden" name="contact_id" value="<?= $contact_id ?>">
|
||||
<input type="hidden" name="asset_id" value="<?= $asset_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Description</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-align-left"></i></span>
|
||||
<input type="text" class="form-control" name="description" maxlength="250" placeholder="Description of the file(s)">
|
||||
</div>
|
||||
</div>
|
||||
<label class="itflow-upload-drop" data-upload-drop>
|
||||
<input type="file" class="visually-hidden" name="file[]" multiple data-upload-input
|
||||
accept="<?= escapeHtml(implode(',', array_map(function ($extension) { return ".$extension"; }, $upload_extensions))) ?>">
|
||||
<i class="fas fa-cloud-upload-alt fa-2x mb-2"></i>
|
||||
<span class="fw-semibold">Drop files here, or click to choose</span>
|
||||
<span class="small text-body-secondary">Up to 20 at a time, 500 MB in all</span>
|
||||
</label>
|
||||
<ul class="list-unstyled mb-0 mt-2 itflow-upload-list" data-upload-list></ul>
|
||||
<div class="text-danger small mt-1" data-upload-error hidden></div>
|
||||
|
||||
<div class="mb-3 mb-4">
|
||||
<label>Folder</label>
|
||||
<div class="mt-3 mb-3">
|
||||
<label class="form-label">Folder</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-folder"></i></span>
|
||||
<select class="form-select select2" name="folder_id">
|
||||
<option value="0">/</option>
|
||||
<?php
|
||||
// Start displaying folder options from the root (parent_folder = 0)
|
||||
displayFolderOptions(0, $client_id, 1);
|
||||
?>
|
||||
<?= folderOptionsHtml($client_id, $folder_id) ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<input type="file" class="form-control" name="file[]" multiple id="fileInput" accept=".jpg, .jpeg, .gif, .png, .webp, .pdf, .txt, .md, .doc, .docx, .odt, .csv, .xls, .xlsx, .ods, .pptx, .odp, .zip, .tar, .gz, .msg, .json, .wav, .mp3, .ogg, .mov, .mp4, .av1, .ovpn, .cfg, .ps1, .vsdx, .drawio, .pfx, .unf, .key, .stk, .bat, .swb">
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Description <span class="text-body-secondary small">- optional, given to every file</span></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-align-left"></i></span>
|
||||
<input type="text" class="form-control" name="description" maxlength="250" placeholder="What these are">
|
||||
</div>
|
||||
</div>
|
||||
<small class="text-secondary">Up to 20 files can be uploaded at once by holding down CTRL and selecting files</small>
|
||||
|
||||
<?php if ($link_name) { ?>
|
||||
<div class="small text-body-secondary mt-3">
|
||||
<i class="fas fa-link me-1"></i>They will be linked to <strong><?= escapeHtml($link_name) ?></strong>.
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="upload_files" class="btn btn-primary text-bold"><i class="fa fa-upload me-2"></i>Upload</button>
|
||||
<button type="submit" name="upload_files" class="btn btn-primary text-bold" data-upload-submit disabled><i class="fa fa-upload me-2"></i>Upload</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
const maxFiles = 20; // Set the maximum number of allowed files
|
||||
const maxTotalSize = 500 * 1024 * 1024; // 500MB in bytes
|
||||
|
||||
const fileInput = document.getElementById('fileInput');
|
||||
const uploadForm = document.getElementById('uploadForm');
|
||||
|
||||
fileInput.addEventListener('change', function () {
|
||||
const totalSize = calculateTotalFileSize(fileInput.files);
|
||||
if (fileInput.files.length > maxFiles || totalSize > maxTotalSize) {
|
||||
alert(`You can only upload up to ${maxFiles} files at a time and the total file size must not exceed 500MB.`);
|
||||
resetFileInput();
|
||||
(function () {
|
||||
var form = document.querySelector('form[data-upload-form]:not([data-wired])');
|
||||
if (!form) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
form.dataset.wired = '1';
|
||||
|
||||
uploadForm.addEventListener('submit', function (event) {
|
||||
const totalSize = calculateTotalFileSize(fileInput.files);
|
||||
if (fileInput.files.length > maxFiles || totalSize > maxTotalSize) {
|
||||
event.preventDefault();
|
||||
alert(`You can only upload up to ${maxFiles} files at a time and the total file size must not exceed 500MB.`);
|
||||
resetFileInput();
|
||||
var MAX_FILES = 20;
|
||||
var MAX_BYTES = 500 * 1024 * 1024;
|
||||
var input = form.querySelector('[data-upload-input]');
|
||||
var drop = form.querySelector('[data-upload-drop]');
|
||||
var list = form.querySelector('[data-upload-list]');
|
||||
var error = form.querySelector('[data-upload-error]');
|
||||
var submit = form.querySelector('[data-upload-submit]');
|
||||
|
||||
function size(bytes) {
|
||||
var units = ['B', 'KB', 'MB', 'GB'], i = 0;
|
||||
while (bytes >= 1024 && i < units.length - 1) {
|
||||
bytes /= 1024;
|
||||
i++;
|
||||
}
|
||||
return (i ? bytes.toFixed(1) : bytes) + ' ' + units[i];
|
||||
}
|
||||
});
|
||||
|
||||
function calculateTotalFileSize(files) {
|
||||
let totalSize = 0;
|
||||
for (const file of files) {
|
||||
totalSize += file.size;
|
||||
function show() {
|
||||
var files = Array.prototype.slice.call(input.files || []);
|
||||
var total = files.reduce(function (sum, file) { return sum + file.size; }, 0);
|
||||
list.innerHTML = '';
|
||||
files.forEach(function (file) {
|
||||
var li = document.createElement('li');
|
||||
li.className = 'd-flex align-items-center gap-2 small';
|
||||
var icon = document.createElement('i');
|
||||
icon.className = 'fas fa-fw fa-file text-body-secondary';
|
||||
var name = document.createElement('span');
|
||||
name.className = 'text-truncate';
|
||||
name.textContent = file.name;
|
||||
var bytes = document.createElement('span');
|
||||
bytes.className = 'text-body-secondary ms-auto text-nowrap';
|
||||
bytes.textContent = size(file.size);
|
||||
li.append(icon, name, bytes);
|
||||
list.appendChild(li);
|
||||
});
|
||||
var problem = files.length > MAX_FILES ? 'That is ' + files.length + ' files - upload up to ' + MAX_FILES + ' at a time.'
|
||||
: total > MAX_BYTES ? 'That is ' + size(total) + ' - keep each upload under 500 MB.' : '';
|
||||
error.textContent = problem;
|
||||
error.hidden = !problem;
|
||||
submit.disabled = !files.length || !!problem;
|
||||
drop.classList.toggle('has-files', files.length > 0);
|
||||
}
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
function resetFileInput() {
|
||||
fileInput.value = ''; // Clear the selected files
|
||||
}
|
||||
input.addEventListener('change', show);
|
||||
['dragenter', 'dragover'].forEach(function (type) {
|
||||
drop.addEventListener(type, function (e) {
|
||||
e.preventDefault();
|
||||
drop.classList.add('is-over');
|
||||
});
|
||||
});
|
||||
['dragleave', 'drop'].forEach(function (type) {
|
||||
drop.addEventListener(type, function () {
|
||||
drop.classList.remove('is-over');
|
||||
});
|
||||
});
|
||||
drop.addEventListener('drop', function (e) {
|
||||
e.preventDefault();
|
||||
if (e.dataTransfer && e.dataTransfer.files.length) {
|
||||
input.files = e.dataTransfer.files;
|
||||
show();
|
||||
}
|
||||
});
|
||||
form.addEventListener('submit', function (e) {
|
||||
if (submit.disabled) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
// Disabled after the browser has read the submitter, so upload_files still posts
|
||||
setTimeout(function () {
|
||||
submit.disabled = true;
|
||||
submit.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Uploading...';
|
||||
}, 0);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
@@ -1,66 +1,53 @@
|
||||
<?php
|
||||
/*
|
||||
* ITFlow - File preview modal for the gallery view on agent/files.php
|
||||
*
|
||||
* Included ONCE, after the tile loop - it used to be required inside it, which
|
||||
* emitted a copy per file, all sharing these element ids.
|
||||
*
|
||||
* What renders is chosen per file by updateModalContent() in files.php, from
|
||||
* the "kind" the page worked out against getInlineViewableMimeTypes(). Anything
|
||||
* not viewable inline gets the fallback panel rather than a broken frame.
|
||||
* The previewer for agent/files.php's grid - one at a time, full size, with
|
||||
* the arrow keys paging through everything on show. Driven by agent/js/files.js
|
||||
* from the payload files.php writes; what each item can show was worked out
|
||||
* against getInlineViewableMimeTypes(), so anything else gets the fallback
|
||||
* panel rather than a frame of a download.
|
||||
*/
|
||||
?>
|
||||
<div class="modal" id="viewFileModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-xl modal-dialog-centered">
|
||||
<div class="modal-content bg-dark text-white">
|
||||
<div class="modal-header bg-dark">
|
||||
<h6 class="modal-title text-truncate" id="modalTitle"></h6>
|
||||
<span class="text-secondary ms-2 small" id="modalMeta"></span>
|
||||
<div class="modal-content bg-dark text-white" data-bs-theme="dark">
|
||||
<div class="modal-header">
|
||||
<div class="min-w-0">
|
||||
<h6 class="modal-title text-truncate" id="modalTitle"></h6>
|
||||
<div class="small text-body-secondary" id="modalMeta"></div>
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white ms-auto" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<div class="position-relative text-center">
|
||||
|
||||
<button type="button" class="btn btn-dark position-absolute top-50 start-0 translate-middle-y ms-2" title="Previous file"
|
||||
id="modalPrev" onclick="prevFile()">
|
||||
<button type="button" class="btn btn-dark position-absolute top-50 start-0 translate-middle-y ms-2 itflow-preview-nav" title="Previous (left arrow)" id="modalPrev">
|
||||
<i class="fas fa-chevron-left"></i>
|
||||
</button>
|
||||
|
||||
<img id="modalImage" class="img-fluid my-3 d-none" src="" alt="">
|
||||
<img id="modalImage" class="img-fluid my-3 d-none" src="" alt="" style="max-height: 75vh;">
|
||||
|
||||
<iframe id="modalFrame" class="w-100 my-3 d-none bg-white" style="height:75vh; border:0;"
|
||||
title="File preview"></iframe>
|
||||
<iframe id="modalFrame" class="w-100 my-3 d-none bg-white" style="height:75vh; border:0;" title="File preview"></iframe>
|
||||
|
||||
<pre id="modalText" class="text-start text-white bg-black p-3 my-3 mx-5 d-none overflow-auto"
|
||||
style="max-height:70vh; white-space:pre-wrap; word-break:break-word;"></pre>
|
||||
<pre id="modalText" class="text-start text-white bg-black p-3 my-3 mx-5 d-none overflow-auto" style="max-height:70vh; white-space:pre-wrap; word-break:break-word;"></pre>
|
||||
|
||||
<?php /* Documents render as HTML rather than in a frame. White panel and
|
||||
prettyContent so they read the same as document.php. */ ?>
|
||||
<div id="modalDocument" class="text-start bg-white text-dark p-4 my-3 mx-5 d-none overflow-auto prettyContent"
|
||||
style="max-height:70vh;"></div>
|
||||
<?php /* Documents render as HTML, on white like the document page */ ?>
|
||||
<div id="modalDocument" class="text-start bg-white text-dark p-4 my-3 mx-5 d-none overflow-auto prettyContent" data-bs-theme="light" style="max-height:70vh;"></div>
|
||||
|
||||
<div id="modalFallback" class="my-5 d-none">
|
||||
<i class="fas fa-file fa-4x text-secondary" id="modalFallbackIcon"></i>
|
||||
<p class="mt-3 mb-0">This file type cannot be previewed in the browser.</p>
|
||||
<p class="mt-3 mb-0">This kind of file cannot be previewed in the browser - download it to open it.</p>
|
||||
</div>
|
||||
|
||||
<button type="button" class="btn btn-dark position-absolute top-50 end-0 translate-middle-y me-2" title="Next file"
|
||||
id="modalNext" onclick="nextFile()">
|
||||
<button type="button" class="btn btn-dark position-absolute top-50 end-0 translate-middle-y me-2 itflow-preview-nav" title="Next (right arrow)" id="modalNext">
|
||||
<i class="fas fa-chevron-right"></i>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<span class="text-secondary small me-auto" id="modalPosition"></span>
|
||||
<a class="btn btn-primary" id="modalDownload" href="#">
|
||||
<i class="fas fa-fw fa-cloud-download-alt me-2"></i>Download
|
||||
</a>
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
||||
<i class="fas fa-fw fa-times me-2"></i>Close
|
||||
</button>
|
||||
<span class="text-body-secondary small me-auto" id="modalPosition"></span>
|
||||
<button type="button" class="btn btn-outline-light" id="modalDetails"><i class="fas fa-fw fa-info-circle me-2"></i>Details</button>
|
||||
<a class="btn btn-primary" id="modalDownload" href="#"><i class="fas fa-fw fa-download me-2"></i>Download</a>
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><i class="fas fa-fw fa-times me-2"></i>Close</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,32 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* New folder - inside the folder it was opened from, or anywhere else picked.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
$client_id = intval($_GET['client_id'] ?? 0);
|
||||
$current_folder_id = intval($_GET['current_folder_id'] ?? 0);
|
||||
$folder_name = escapeHtml(getFieldByID('folders', $current_folder_id, 'folder_name') ?? '/');
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$client_id = intval($_GET['client_id'] ?? 0);
|
||||
enforceClientAccess();
|
||||
|
||||
$parent_folder = folderOwnedId($_GET['current_folder_id'] ?? 0, $client_id);
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-folder-plus me-2"></i>Creating folder in <strong><?= $folder_name ?></strong></h5>
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-folder-plus me-2"></i>New folder</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="client_id" value="<?= $client_id ?>">
|
||||
<input type="hidden" name="parent_folder" value="<?= $current_folder_id ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Folder Name <strong class="text-danger">*</strong></label>
|
||||
<label class="form-label">Name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
<input type="text" class="form-control" name="folder_name" placeholder="Folder Name" maxlength="200" required>
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-folder"></i></span>
|
||||
<input type="text" class="form-control" name="folder_name" placeholder="e.g. Contracts" maxlength="200" required autofocus>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Inside</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-sitemap"></i></span>
|
||||
<select class="form-select select2" name="parent_folder">
|
||||
<?= folderOptionsHtml($client_id, $parent_folder) ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
55
agent/modals/folder/folder_delete.php
Normal file
55
agent/modals/folder/folder_delete.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Delete a folder. Nothing in it is lost: its files, documents and
|
||||
* subfolders move up into the folder it sat in.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 3);
|
||||
|
||||
$folder_id = intval($_GET['id'] ?? 0);
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT folder_client_id, folder_name, parent_folder FROM folders WHERE folder_id = $folder_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'That folder no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
$client_id = intval($row['folder_client_id']);
|
||||
enforceClientAccess();
|
||||
|
||||
$parent_folder = folderOwnedId($row['parent_folder'], $client_id);
|
||||
$parent_name = escapeHtml(folderDisplayName($parent_folder));
|
||||
$inside = array_filter([
|
||||
intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM files WHERE file_folder_id = $folder_id AND file_client_id = $client_id"))[0]) . ' file(s)',
|
||||
intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM documents WHERE document_folder_id = $folder_id AND document_client_id = $client_id"))[0]) . ' document(s)',
|
||||
intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM folders WHERE parent_folder = $folder_id AND folder_client_id = $client_id"))[0]) . ' folder(s)',
|
||||
], function ($part) {
|
||||
return intval($part) > 0;
|
||||
});
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-body text-center py-4">
|
||||
<i class="fas fa-folder fa-3x text-body-secondary mb-3"></i>
|
||||
<h5 class="mb-1">Delete <strong><?= escapeHtml($row['folder_name']) ?></strong>?</h5>
|
||||
<div class="small text-body-secondary mb-4">
|
||||
<?php if ($inside) { ?>
|
||||
The <?= implode(', ', $inside) ?> inside move up to <strong><?= $parent_name ?></strong> - nothing is deleted with it.
|
||||
<?php } else { ?>
|
||||
It is empty.
|
||||
<?php } ?>
|
||||
</div>
|
||||
<form action="post.php" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="folder_id" value="<?= $folder_id ?>">
|
||||
<button type="button" class="btn btn-light px-4 me-2" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="submit" name="delete_folder" class="btn btn-danger px-4"><i class="fas fa-trash me-2"></i>Delete folder</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
@@ -1,25 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Rename a folder, or move it - with everything in it - under another one.
|
||||
* The folder and its own subfolders are left out of the picker, so it can
|
||||
* never end up inside itself.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$folder_id = intval($_GET['id']);
|
||||
$folder_id = intval($_GET['id'] ?? 0);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT folder_client_id, folder_name FROM folders WHERE folder_id = $folder_id LIMIT 1");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$folder_name = escapeHtml($row['folder_name']);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT folder_client_id, folder_name, parent_folder FROM folders WHERE folder_id = $folder_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'That folder no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
$client_id = intval($row['folder_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
$folder_name = escapeHtml($row['folder_name']);
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-folder me-2"></i>Renaming folder: <strong><?= $folder_name ?></strong></h5>
|
||||
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-folder me-2"></i><?= $folder_name ?></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
@@ -28,16 +36,27 @@ ob_start();
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Name <strong class="text-danger">*</strong></label>
|
||||
<label class="form-label">Name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
<input type="text" class="form-control" name="folder_name" placeholder="Folder Name" maxlength="200" value="<?= $folder_name ?>" required>
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-folder"></i></span>
|
||||
<input type="text" class="form-control" name="folder_name" placeholder="Folder name" maxlength="200" value="<?= $folder_name ?>" required autofocus>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Inside</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-sitemap"></i></span>
|
||||
<select class="form-select select2" name="parent_folder">
|
||||
<?= folderOptionsHtml($client_id, intval($row['parent_folder']), $folder_id) ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-text">Moving it takes everything inside along with it.</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="rename_folder" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Rename</button>
|
||||
<button type="submit" name="rename_folder" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
158
agent/modals/link/link.php
Normal file
158
agent/modals/link/link.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Link things to a document or a file - or a document or file to an asset or
|
||||
* contact. One modal for every pair in LINK_RELATIONS (functions/links.php):
|
||||
* ?from=document&id=81&to=asset opens on Assets; the pills along the top
|
||||
* switch to anything else this record can be linked to. Pick as many as you
|
||||
* like; only the client's own, unarchived, not-yet-linked records are offered.
|
||||
*
|
||||
* The old one-pair modals (document_link_asset.php, asset_link_file.php...)
|
||||
* are thin wrappers that set from/id/to and include this.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
$link_from = (string) ($_GET['from'] ?? '');
|
||||
$link_id = intval($_GET['id'] ?? 0);
|
||||
$link_source = linkRecord($link_from, $link_id);
|
||||
if (!$link_source) {
|
||||
echo json_encode(['error' => 'That record no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$client_id = intval($link_source['client_id']);
|
||||
enforceClientAccess();
|
||||
|
||||
// Only the kinds this agent may change
|
||||
$link_types = array_values(array_filter(linkTypesFor($link_from), function ($to) use ($link_from) {
|
||||
return linkCanEdit($link_from, $to);
|
||||
}));
|
||||
if (!$link_types) {
|
||||
echo json_encode(['error' => 'You do not have permission to change these links.']);
|
||||
exit;
|
||||
}
|
||||
$link_to = in_array($_GET['to'] ?? '', $link_types, true) ? $_GET['to'] : $link_types[0];
|
||||
|
||||
$from_entity = LINK_ENTITIES[$link_from];
|
||||
$link_name = escapeHtml($link_source['name']);
|
||||
|
||||
/** The option extras for one candidate - its icon or avatar, and a line under it. */
|
||||
function linkOptionData($to, $row, $client_id) {
|
||||
switch ($to) {
|
||||
case 'asset':
|
||||
return selectOptionAsset($row['asset_type'], trim($row['asset_make'] . ' ' . $row['asset_model']));
|
||||
case 'contact':
|
||||
return selectOptionContact($row['contact_client_id'], $row['name'], $row['contact_photo'], $row['contact_title'], $row['id']);
|
||||
case 'file':
|
||||
$info = fileTypeInfo($row['file_ext']);
|
||||
return selectOptionData(['icon' => 'fas fa-' . $info['icon'], 'description' => ($row['folder_name'] ?: 'Top level') . ' · ' . formatBytes(intval($row['file_size'])), 'keywords' => $row['file_description']]);
|
||||
case 'document':
|
||||
return selectOptionData(['icon' => 'fas fa-file-alt', 'description' => $row['document_description'] ?: 'Updated ' . timeAgo($row['document_updated_at'] ?: $row['document_created_at'])]);
|
||||
case 'software':
|
||||
return selectOptionData(['icon' => 'fas fa-cube', 'description' => trim($row['software_type'] . ' ' . $row['software_version'])]);
|
||||
case 'vendor':
|
||||
return selectOptionData(['icon' => 'fas fa-building', 'description' => $row['vendor_description']]);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
$panes = [];
|
||||
foreach ($link_types as $to) {
|
||||
$panes[$to] = [
|
||||
'entity' => LINK_ENTITIES[$to],
|
||||
'linked' => count(linkedRecords($link_from, $link_id, $to)),
|
||||
'candidates' => linkCandidates($link_from, $link_id, $to, $client_id),
|
||||
];
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-link me-2"></i>Link to <strong><?= $link_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off" data-link-form>
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="from" value="<?= escapeHtml($link_from) ?>">
|
||||
<input type="hidden" name="id" value="<?= $link_id ?>">
|
||||
<input type="hidden" name="to" value="<?= escapeHtml($link_to) ?>" data-link-to>
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<?php if (count($panes) > 1) { ?>
|
||||
<nav class="nav nav-pills itflow-asset-pills itflow-link-types mb-3" role="tablist">
|
||||
<?php foreach ($panes as $to => $pane) { ?>
|
||||
<button type="button" class="nav-link <?= $to === $link_to ? 'active' : '' ?>" data-bs-toggle="pill" data-bs-target="#linkPane-<?= $to ?>" data-link-type="<?= $to ?>" role="tab">
|
||||
<i class="fas fa-fw <?= $pane['entity']['icon'] ?> me-1"></i><?= $pane['entity']['plural'] ?>
|
||||
<?php if ($pane['linked']) { ?><span class="badge rounded-pill ms-1" title="Already linked"><?= $pane['linked'] ?></span><?php } ?>
|
||||
</button>
|
||||
<?php } ?>
|
||||
</nav>
|
||||
<?php } ?>
|
||||
|
||||
<div class="tab-content">
|
||||
<?php foreach ($panes as $to => $pane) {
|
||||
$entity = $pane['entity']; ?>
|
||||
<div class="tab-pane fade <?= $to === $link_to ? 'show active' : '' ?>" id="linkPane-<?= $to ?>" role="tabpanel">
|
||||
<?php if ($pane['candidates']) { ?>
|
||||
<label class="form-label">Which <?= strtolower($entity['plural']) ?>?</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw <?= $entity['icon'] ?>"></i></span>
|
||||
<select class="form-select select2" name="ids[]" multiple data-placeholder="Pick one or more <?= strtolower($entity['plural']) ?>" <?= $to === $link_to ? '' : 'disabled' ?> data-link-select="<?= $to ?>">
|
||||
<?php foreach ($pane['candidates'] as $row) { ?>
|
||||
<option value="<?= intval($row['id']) ?>"<?= linkOptionData($to, $row, $client_id) ?>><?= escapeHtml($row['name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-text"><?= count($pane['candidates']) ?> <?= count($pane['candidates']) === 1 ? $entity['label'] : strtolower($entity['plural']) ?> not linked yet<?= $pane['linked'] ? ', ' . $pane['linked'] . ' already linked' : '' ?>.</div>
|
||||
<?php } else { ?>
|
||||
<div class="itflow-asset-empty py-4">
|
||||
<i class="fas <?= $entity['icon'] ?> fa-2x mb-2"></i>
|
||||
<div><?= $pane['linked'] ? 'Every ' . $entity['label'] . ' this client has is already linked.' : 'This client has no ' . strtolower($entity['plural']) . ' to link.' ?></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="link_items" class="btn btn-primary text-bold"><i class="fas fa-link me-2"></i>Link</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
// Only the pane on show posts its picks
|
||||
var form = document.querySelector('form[data-link-form]:not([data-wired])');
|
||||
if (!form) {
|
||||
return;
|
||||
}
|
||||
form.dataset.wired = '1';
|
||||
var to = form.querySelector('[data-link-to]');
|
||||
form.querySelectorAll('[data-link-type]').forEach(function (pill) {
|
||||
pill.addEventListener('shown.bs.tab', function () {
|
||||
to.value = pill.dataset.linkType;
|
||||
form.querySelectorAll('[data-link-select]').forEach(function (select) {
|
||||
select.disabled = select.dataset.linkSelect !== to.value;
|
||||
});
|
||||
});
|
||||
});
|
||||
form.addEventListener('submit', function (e) {
|
||||
var select = form.querySelector('[data-link-select="' + to.value + '"]');
|
||||
if (!select || !select.selectedOptions.length) {
|
||||
e.preventDefault();
|
||||
if (select && select.itflowSelect) {
|
||||
select.itflowSelect.open();
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
@@ -1037,70 +1037,8 @@ if (isset($_GET['unlink_service_from_asset'])) {
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['link_asset_to_file'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$file_id = intval($_POST['file_id']);
|
||||
$asset_id = intval($_POST['asset_id']);
|
||||
|
||||
// Get file Name and Client ID for logging
|
||||
$sql_file = mysqli_query($mysqli,"SELECT file_name, file_client_id FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql_file);
|
||||
$file_name = escapeSql($row['file_name']);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Get Asset Name for logging
|
||||
$asset_name = escapeSql(getFieldById('assets', $asset_id, 'asset_name'));
|
||||
|
||||
// asset add query
|
||||
mysqli_query($mysqli,"INSERT INTO asset_files SET asset_id = $asset_id, file_id = $file_id");
|
||||
|
||||
logAudit("File", "Link", "$session_name linked asset $asset_name to file $file_name", $client_id, $file_id);
|
||||
|
||||
flashAlert("Asset <strong>$asset_name</strong> linked with File <strong>$file_name</strong>");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['unlink_asset_from_file'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$asset_id = intval($_GET['asset_id']);
|
||||
$file_id = intval($_GET['file_id']);
|
||||
|
||||
// Get file Name and Client ID for logging
|
||||
$sql_file = mysqli_query($mysqli,"SELECT file_name, file_client_id FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql_file);
|
||||
$file_name = escapeSql($row['file_name']);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Get Asset Name for logging
|
||||
$asset_name = escapeSql(getFieldById('assets', $asset_id, 'asset_name'));
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM asset_files WHERE asset_id = $asset_id AND file_id = $file_id");
|
||||
|
||||
logAudit("File", "Unlink", "$session_name unlinked asset $asset_name from file $file_name", $client_id, $file_id);
|
||||
|
||||
flashAlert("Asset <strong>$asset_name</strong> unlinked from file <strong>$file_name</strong>", 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
// END LINKING
|
||||
|
||||
|
||||
if (isset($_POST["import_assets_csv"])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
@@ -617,7 +617,6 @@ if (isset($_POST['bulk_archive_contacts'])) {
|
||||
mysqli_query($mysqli,"UPDATE users SET user_archived_at = NOW() WHERE user_id = $contact_user_id");
|
||||
}
|
||||
|
||||
|
||||
if($contact_primary == 0) {
|
||||
mysqli_query($mysqli,"UPDATE contacts SET contact_important = 0, contact_billing = 0, contact_technical = 0, contact_archived_at = NOW() WHERE contact_id = $contact_id");
|
||||
|
||||
@@ -778,7 +777,6 @@ if (isset($_GET['anonymize_contact'])) {
|
||||
mysqli_query($mysqli,"UPDATE users SET user_name = 'Archived - $unix_timestamp', user_email = 'Archived - $unix_timestamp', user_archived_at = NOW() WHERE user_id = $contact_user_id");
|
||||
}
|
||||
|
||||
|
||||
// Redact audit logs
|
||||
$log_sql = mysqli_query($mysqli, "SELECT log_description, log_id FROM logs WHERE log_client_id = $client_id");
|
||||
while ($log = mysqli_fetch_assoc($log_sql)) {
|
||||
@@ -790,7 +788,6 @@ if (isset($_GET['anonymize_contact'])) {
|
||||
mysqli_query($mysqli,"UPDATE logs SET log_description = '$description' WHERE log_id = $log_id AND log_client_id = $client_id");
|
||||
}
|
||||
|
||||
|
||||
// Get all tickets this contact raised
|
||||
$contact_tickets_sql = mysqli_query($mysqli, "SELECT ticket_details, ticket_id, ticket_subject FROM tickets WHERE ticket_client_id = $client_id AND ticket_contact_id = $contact_id");
|
||||
while ($ticket = mysqli_fetch_assoc($contact_tickets_sql)) {
|
||||
@@ -1173,67 +1170,6 @@ if (isset($_GET['unlink_service_from_contact'])) {
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['link_contact_to_file'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_client', 2);
|
||||
|
||||
$file_id = intval($_POST['file_id']);
|
||||
$contact_id = intval($_POST['contact_id']);
|
||||
|
||||
// Get file Name and Client ID for logging
|
||||
$sql_file = mysqli_query($mysqli,"SELECT file_name, file_client_id FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql_file);
|
||||
$file_name = escapeSql($row['file_name']);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Get Contact Name for logging
|
||||
$contact_name = escapeSql(getFieldById('contacts', $contact_id, 'contact_name'));
|
||||
|
||||
// Contact add query
|
||||
mysqli_query($mysqli,"INSERT INTO contact_files SET contact_id = $contact_id, file_id = $file_id");
|
||||
|
||||
logAudit("File", "Link", "$session_name linked contact $contact_name to file $file_name", $client_id, $file_id);
|
||||
|
||||
flashAlert("Contact <strong>$contact_name</strong> linked with File <strong>$file_name</strong>");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['unlink_contact_from_file'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_client', 2);
|
||||
|
||||
$contact_id = intval($_GET['contact_id']);
|
||||
$file_id = intval($_GET['file_id']);
|
||||
|
||||
// Get file Name and Client ID for logging
|
||||
$sql_file = mysqli_query($mysqli,"SELECT file_name, file_client_id FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql_file);
|
||||
$file_name = escapeSql($row['file_name']);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Get Contact Name for logging
|
||||
$contact_name = escapeSql(getFieldById('contacts', $contact_id, 'contact_name'));
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM contact_files WHERE contact_id = $contact_id AND file_id = $file_id");
|
||||
|
||||
logAudit("File", "Unlink", "$session_name unlinked contact $contact_name from file $file_name", $client_id, $file_id);
|
||||
|
||||
flashAlert("Contact <strong>$contact_name</strong> unlinked from file <strong>$file_name</strong>", 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isExportRequest('export_contacts')) {
|
||||
|
||||
validateCSRFToken();
|
||||
@@ -1430,7 +1366,6 @@ if (isset($_POST["import_contacts_csv"])) {
|
||||
}
|
||||
// Potentially import the rest in the future?
|
||||
|
||||
|
||||
// Check if duplicate was detected
|
||||
if ($duplicate_detect == 0) {
|
||||
//Add
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
$name = escapeSql($_POST['name']);
|
||||
$folder = intval($_POST['folder']);
|
||||
$description = escapeSql($_POST['description']);
|
||||
$content = mysqli_real_escape_string($mysqli,$_POST['content']);
|
||||
$content_raw = escapeSql($_POST['name'] . " " . str_replace("<", " <", $_POST['content']));
|
||||
// Content Raw is used for FULL INDEX searching. Adding a space before HTML tags to allow spaces between newlines, bulletpoints, etc. for searching.
|
||||
$name = escapeSql(trim($_POST['name'] ?? ''));
|
||||
$folder = intval($_POST['folder'] ?? 0);
|
||||
$description = escapeSql($_POST['description'] ?? '');
|
||||
$content = mysqli_real_escape_string($mysqli, $_POST['content'] ?? '');
|
||||
// For the FULLTEXT search - see documentContentRaw()
|
||||
$content_raw = escapeSql(documentContentRaw($_POST['name'] ?? '', $_POST['content'] ?? ''));
|
||||
|
||||
@@ -2,32 +2,42 @@
|
||||
|
||||
/*
|
||||
* ITFlow - GET/POST request handler for client files/uploads
|
||||
*
|
||||
* Linking files to assets, contacts and documents lives in post/link.php.
|
||||
*/
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
/** "2 documents and 3 files" - for the bulk messages. */
|
||||
function filesCountPhrase($document_count, $file_count) {
|
||||
return implode(' and ', array_filter([
|
||||
$document_count ? "<strong>$document_count</strong> document" . ($document_count === 1 ? '' : 's') : '',
|
||||
$file_count ? "<strong>$file_count</strong> file" . ($file_count === 1 ? '' : 's') : '',
|
||||
])) ?: 'nothing';
|
||||
}
|
||||
|
||||
if (isset($_POST['upload_files'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
// Sanitize and initialize inputs
|
||||
$client_id = intval($_POST['client_id']);
|
||||
$folder_id = intval($_POST['folder_id']);
|
||||
$description = escapeSql($_POST['description']);
|
||||
$contact_id = intval($_POST['contact_id'] ?? 0);
|
||||
$asset_id = intval($_POST['asset_id'] ?? 0);
|
||||
$client_dir = "../uploads/clients/$client_id";
|
||||
$client_id = intval($_POST['client_id']);
|
||||
$description = escapeSql($_POST['description'] ?? '');
|
||||
$client_dir = "../uploads/clients/$client_id";
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Create client directory if it doesn't exist
|
||||
// Only the client's own folder, contact and asset
|
||||
$folder_id = folderOwnedId($_POST['folder_id'] ?? 0, $client_id);
|
||||
$contact_id = assetClientOwnedId('contact', $_POST['contact_id'] ?? 0, $client_id);
|
||||
$asset = linkRecord('asset', $_POST['asset_id'] ?? 0);
|
||||
$asset_id = $asset && intval($asset['client_id']) === $client_id ? intval($asset['id']) : 0;
|
||||
|
||||
if (!is_dir($client_dir)) {
|
||||
mkdir($client_dir, 0755, true);
|
||||
}
|
||||
|
||||
// Allowed file extensions list
|
||||
$allowedExtensions = [
|
||||
'jpg', 'jpeg', 'gif', 'png', 'webp', 'pdf', 'txt', 'md', 'doc', 'docx',
|
||||
'odt', 'csv', 'xls', 'xlsx', 'ods', 'pptx', 'odp', 'zip', 'tar', 'gz',
|
||||
@@ -36,73 +46,75 @@ if (isset($_POST['upload_files'])) {
|
||||
'key', 'bat', 'stk', 'swb'
|
||||
];
|
||||
|
||||
// Loop through each uploaded file
|
||||
foreach ($_FILES['file']['name'] as $index => $originalName) {
|
||||
$uploaded = [];
|
||||
$skipped = [];
|
||||
$names = $_FILES['file']['name'] ?? [];
|
||||
|
||||
foreach ((array) $names as $index => $original_name) {
|
||||
|
||||
// Build a file array for this iteration
|
||||
$single_file = [
|
||||
'name' => $_FILES['file']['name'][$index],
|
||||
'type' => $_FILES['file']['type'][$index],
|
||||
'name' => $_FILES['file']['name'][$index],
|
||||
'type' => $_FILES['file']['type'][$index],
|
||||
'tmp_name' => $_FILES['file']['tmp_name'][$index],
|
||||
'error' => $_FILES['file']['error'][$index],
|
||||
'size' => $_FILES['file']['size'][$index]
|
||||
'error' => $_FILES['file']['error'][$index],
|
||||
'size' => $_FILES['file']['size'][$index]
|
||||
];
|
||||
|
||||
// Validate and get a safe file reference name
|
||||
if ($file_reference_name = checkFileUpload($single_file, $allowedExtensions)) {
|
||||
|
||||
$file_tmp_path = $single_file['tmp_name'];
|
||||
$file_name = escapeSql($originalName);
|
||||
$extParts = explode('.', $file_name);
|
||||
$file_extension = strtolower(end($extParts));
|
||||
$file_mime_type = escapeSql($single_file['type']);
|
||||
$file_size = intval($single_file['size']);
|
||||
|
||||
// Define destination path and move the uploaded file
|
||||
$upload_file_dir = $client_dir . "/";
|
||||
$dest_path = $upload_file_dir . $file_reference_name;
|
||||
|
||||
if (!move_uploaded_file($file_tmp_path, $dest_path)) {
|
||||
flashAlert('Error moving file to upload directory. Please ensure the directory is writable.', 'error');
|
||||
continue; // Skip processing this file
|
||||
}
|
||||
|
||||
// Use the file reference (without extension) as the file hash
|
||||
$file_hash = strstr($file_reference_name, '.', true) ?: $file_reference_name;
|
||||
|
||||
// Insert file metadata into the database
|
||||
$query = "INSERT INTO files SET
|
||||
file_reference_name = '$file_reference_name',
|
||||
file_name = '$file_name',
|
||||
file_description = '$description',
|
||||
file_ext = '$file_extension',
|
||||
file_mime_type = '$file_mime_type',
|
||||
file_size = $file_size,
|
||||
file_created_by = $session_user_id,
|
||||
file_folder_id = $folder_id,
|
||||
file_client_id = $client_id";
|
||||
mysqli_query($mysqli, $query);
|
||||
$file_id = mysqli_insert_id($mysqli);
|
||||
|
||||
if ($contact_id) {
|
||||
mysqli_query($mysqli,"INSERT INTO contact_files SET contact_id = $contact_id, file_id = $file_id");
|
||||
}
|
||||
|
||||
if ($asset_id) {
|
||||
mysqli_query($mysqli,"INSERT INTO asset_files SET asset_id = $asset_id, file_id = $file_id");
|
||||
}
|
||||
|
||||
logAudit("File", "Upload", "$session_name uploaded file $file_name", $client_id, $file_id);
|
||||
|
||||
flashAlert("Uploaded file <strong>$file_name</strong>");
|
||||
$file_reference_name = checkFileUpload($single_file, $allowedExtensions);
|
||||
if (!$file_reference_name) {
|
||||
$skipped[] = $original_name;
|
||||
continue;
|
||||
}
|
||||
|
||||
$dest_path = "$client_dir/$file_reference_name";
|
||||
if (!move_uploaded_file($single_file['tmp_name'], $dest_path)) {
|
||||
$skipped[] = $original_name;
|
||||
continue;
|
||||
}
|
||||
|
||||
$file_name = escapeSql(basename($original_name));
|
||||
$file_extension = escapeSql(strtolower(pathinfo($original_name, PATHINFO_EXTENSION)));
|
||||
// What the file is, read from the file - not what the browser said it was
|
||||
$detected_mime = function_exists('finfo_open') ? (string) finfo_file(finfo_open(FILEINFO_MIME_TYPE), $dest_path) : '';
|
||||
$file_mime_type = escapeSql($detected_mime !== '' && $detected_mime !== 'application/octet-stream' ? $detected_mime : $single_file['type']);
|
||||
$file_size = intval($single_file['size']);
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO files SET
|
||||
file_reference_name = '$file_reference_name',
|
||||
file_name = '$file_name',
|
||||
file_description = '$description',
|
||||
file_ext = '$file_extension',
|
||||
file_mime_type = '$file_mime_type',
|
||||
file_size = $file_size,
|
||||
file_created_by = $session_user_id,
|
||||
file_folder_id = $folder_id,
|
||||
file_client_id = $client_id");
|
||||
$file_id = mysqli_insert_id($mysqli);
|
||||
|
||||
if ($contact_id) {
|
||||
mysqli_query($mysqli, "INSERT IGNORE INTO contact_files SET contact_id = $contact_id, file_id = $file_id");
|
||||
}
|
||||
if ($asset_id) {
|
||||
mysqli_query($mysqli, "INSERT IGNORE INTO asset_files SET asset_id = $asset_id, file_id = $file_id");
|
||||
}
|
||||
|
||||
logAudit("File", "Upload", "$session_name uploaded file $file_name", $client_id, $file_id);
|
||||
|
||||
$uploaded[] = basename($original_name);
|
||||
}
|
||||
|
||||
if ($uploaded && !$skipped) {
|
||||
flashAlert(count($uploaded) === 1 ? "Uploaded <strong>{$uploaded[0]}</strong>" : "Uploaded <strong>" . count($uploaded) . "</strong> files");
|
||||
} elseif ($uploaded) {
|
||||
flashAlert("Uploaded <strong>" . count($uploaded) . "</strong>, skipped <strong>" . count($skipped) . "</strong> (not an allowed type, empty or too big): " . implode(', ', $skipped), 'warning');
|
||||
} else {
|
||||
flashAlert($skipped ? "Nothing uploaded - not an allowed type, empty or too big: " . implode(', ', $skipped) : 'Choose a file to upload.', 'error');
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (isset($_POST['rename_file'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
@@ -110,23 +122,29 @@ if (isset($_POST['rename_file'])) {
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$file_id = intval($_POST['file_id']);
|
||||
$file_name = escapeSql($_POST['file_name']);
|
||||
$file_description = escapeSql($_POST['file_description']);
|
||||
$file_name = escapeSql(trim($_POST['file_name'] ?? ''));
|
||||
$file_description = escapeSql($_POST['file_description'] ?? '');
|
||||
|
||||
// Get File Details Client ID for Logging
|
||||
$sql = mysqli_query($mysqli,"SELECT file_name, file_client_id FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT file_name, file_client_id FROM files WHERE file_id = $file_id"));
|
||||
if (!$row) {
|
||||
flashAlert('That file no longer exists.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$old_file_name = escapeSql($row['file_name']);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// file edit query
|
||||
mysqli_query($mysqli,"UPDATE files SET file_name = '$file_name' ,file_description = '$file_description' WHERE file_id = $file_id");
|
||||
if ($file_name === '') {
|
||||
flashAlert('A file needs a name.', 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
mysqli_query($mysqli, "UPDATE files SET file_name = '$file_name', file_description = '$file_description' WHERE file_id = $file_id");
|
||||
|
||||
logAudit("File", "Rename", "$session_name renamed file $old_file_name to $file_name", $client_id, $file_id);
|
||||
|
||||
flashAlert("Renamed file <strong>$old_file_name</strong> to <strong>$file_name</strong>");
|
||||
flashAlert("File <strong>" . trim($_POST['file_name']) . "</strong> saved");
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -139,24 +157,26 @@ if (isset($_POST['move_file'])) {
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$file_id = intval($_POST['file_id']);
|
||||
$folder_id = intval($_POST['folder_id']);
|
||||
|
||||
// Get File Name and Client ID for Logging
|
||||
$sql = mysqli_query($mysqli,"SELECT file_name, file_client_id FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT file_name, file_client_id FROM files WHERE file_id = $file_id"));
|
||||
if (!$row) {
|
||||
flashAlert('That file no longer exists.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$file_name = escapeSql($row['file_name']);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Get Folder Name for Logging
|
||||
$folder_name = escapeSql(getFieldById('folders', $folder_id, 'folder_name'));
|
||||
// Only into one of this client's folders
|
||||
$folder_id = folderOwnedId($_POST['folder_id'] ?? 0, $client_id);
|
||||
$folder_name = folderDisplayName($folder_id);
|
||||
|
||||
mysqli_query($mysqli,"UPDATE files SET file_folder_id = $folder_id WHERE file_id = $file_id");
|
||||
mysqli_query($mysqli, "UPDATE files SET file_folder_id = $folder_id WHERE file_id = $file_id");
|
||||
|
||||
logAudit("File", "Move", "$session_name moved file $file_name to $folder_name", $client_id, $file_id);
|
||||
logAudit("File", "Move", "$session_name moved file $file_name to " . escapeSql($folder_name), $client_id, $file_id);
|
||||
|
||||
flashAlert("File <strong>$file_name</strong> moved to <strong>$folder_name</strong>");
|
||||
flashAlert("File <strong>{$row['file_name']}</strong> moved to <strong>$folder_name</strong>");
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -170,19 +190,20 @@ if (isset($_GET['archive_file'])) {
|
||||
|
||||
$file_id = intval($_GET['archive_file']);
|
||||
|
||||
// Get Contact Name and Client ID for logging and alert message
|
||||
$sql = mysqli_query($mysqli,"SELECT file_name, file_client_id FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$file_name = escapeSql($row['file_name']);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT file_name, file_client_id FROM files WHERE file_id = $file_id"));
|
||||
if (!$row) {
|
||||
flashAlert('That file no longer exists.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$client_id = intval($row['file_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli,"UPDATE files SET file_archived_at = NOW() WHERE file_id = $file_id");
|
||||
mysqli_query($mysqli, "UPDATE files SET file_archived_at = NOW() WHERE file_id = $file_id");
|
||||
|
||||
logAudit("File", "Archive", "$session_name archived file $file_name", $client_id, $file_id);
|
||||
logAudit("File", "Archive", "$session_name archived file " . escapeSql($row['file_name']), $client_id, $file_id);
|
||||
|
||||
flashAlert("File <strong>$file_name</strong> archived", 'error');
|
||||
flashAlert("File <strong>{$row['file_name']}</strong> archived", 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -196,19 +217,20 @@ if (isset($_GET['restore_file'])) {
|
||||
|
||||
$file_id = intval($_GET['restore_file']);
|
||||
|
||||
// Get Document Name and Client ID for logging and alert message
|
||||
$sql = mysqli_query($mysqli,"SELECT file_name, file_client_id FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$file_name = escapeSql($row['file_name']);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT file_name, file_client_id FROM files WHERE file_id = $file_id"));
|
||||
if (!$row) {
|
||||
flashAlert('That file no longer exists.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$client_id = intval($row['file_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli,"UPDATE files SET file_archived_at = NULL WHERE file_id = $file_id");
|
||||
mysqli_query($mysqli, "UPDATE files SET file_archived_at = NULL WHERE file_id = $file_id");
|
||||
|
||||
logAudit("File", "Restore", "$session_name restored file $file_name", $client_id, $file_id);
|
||||
logAudit("File", "Restore", "$session_name restored file " . escapeSql($row['file_name']), $client_id, $file_id);
|
||||
|
||||
flashAlert("File <strong>$file_name</strong> Restored");
|
||||
flashAlert("File <strong>{$row['file_name']}</strong> restored");
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -220,176 +242,58 @@ if (isset($_POST['delete_file'])) {
|
||||
|
||||
enforceUserPermission('module_support', 3);
|
||||
|
||||
$file_id = intval($_POST['file_id']);
|
||||
$file_name = fileDeleteForGood(intval($_POST['file_id']));
|
||||
|
||||
$sql_file = mysqli_query($mysqli,"SELECT * FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql_file);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
$file_name = escapeSql($row['file_name']);
|
||||
$file_reference_name = escapeSql($row['file_reference_name']);
|
||||
$file_has_thumbnail = intval($row['file_has_thumbnail']);
|
||||
$file_has_preview = intval($row['file_has_preview']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
unlink("../uploads/clients/$client_id/$file_reference_name");
|
||||
|
||||
if ($file_has_thumbnail == 1) {
|
||||
unlink("../uploads/clients/$client_id/thumbnail_$file_reference_name");
|
||||
if ($file_name === null) {
|
||||
flashAlert('That file no longer exists.', 'error');
|
||||
} else {
|
||||
flashAlert("File <strong>$file_name</strong> deleted", 'error');
|
||||
}
|
||||
if ($file_has_preview == 1) {
|
||||
unlink("../uploads/clients/$client_id/preview_$file_reference_name");
|
||||
}
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM files WHERE file_id = $file_id");
|
||||
|
||||
logAudit("File", "Delete", "$session_name deleted file $file_name", $client_id);
|
||||
|
||||
flashAlert("File <strong>$file_name</strong> deleted", 'alert');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The bulk actions take files and documents together - the files list ticks
|
||||
* both - and each item is checked against the agent's client access on its
|
||||
* own, since nothing ties the ticked ids to one client.
|
||||
*/
|
||||
|
||||
if (isset($_POST['bulk_archive_files'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
// Archive file loop
|
||||
if (isset($_POST['file_ids'])) {
|
||||
$file_count = 0;
|
||||
$document_count = 0;
|
||||
|
||||
// Get selected file Count
|
||||
$file_count = count($_POST['file_ids']);
|
||||
|
||||
foreach($_POST['file_ids'] as $file_id) {
|
||||
|
||||
$file_id = intval($file_id);
|
||||
|
||||
$sql_file = mysqli_query($mysqli,"SELECT file_client_id, file_name FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql_file);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
$file_name = escapeSql($row['file_name']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli,"UPDATE files SET file_archived_at = NOW() WHERE file_id = $file_id");
|
||||
|
||||
logAudit("File", "Archive", "$session_name archived file $file_name", $client_id, $file_id);
|
||||
foreach (array_map('intval', (array) ($_POST['file_ids'] ?? [])) as $file_id) {
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT file_client_id, file_name FROM files WHERE file_id = $file_id AND file_archived_at IS NULL"));
|
||||
if (!$row) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$client_id = intval($row['file_client_id']);
|
||||
enforceClientAccess();
|
||||
mysqli_query($mysqli, "UPDATE files SET file_archived_at = NOW() WHERE file_id = $file_id");
|
||||
logAudit("File", "Archive", "$session_name archived file " . escapeSql($row['file_name']), $client_id, $file_id);
|
||||
$file_count++;
|
||||
}
|
||||
|
||||
// Archive documents loop
|
||||
if (isset($_POST['document_ids'])) {
|
||||
|
||||
// Get selected document count
|
||||
$document_count = count($_POST['document_ids']);
|
||||
|
||||
// Delete document loop
|
||||
foreach($_POST['document_ids'] as $document_id) {
|
||||
$document_id = intval($document_id);
|
||||
// Get document name for logging
|
||||
$sql = mysqli_query($mysqli,"SELECT document_name, document_client_id FROM documents WHERE document_id = $document_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$document_name = escapeSql($row['document_name']);
|
||||
$client_id = intval($row['document_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli,"UPDATE documents SET document_archived_at = NOW(), document_updated_at = document_updated_at WHERE document_id = $document_id");
|
||||
|
||||
logAudit("Document", "Archive", "$session_name archived document $document_name", $client_id, $document_id);
|
||||
|
||||
foreach (array_map('intval', (array) ($_POST['document_ids'] ?? [])) as $document_id) {
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT document_name, document_client_id FROM documents WHERE document_id = $document_id AND document_archived_at IS NULL"));
|
||||
if (!$row) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$client_id = intval($row['document_client_id']);
|
||||
enforceClientAccess();
|
||||
mysqli_query($mysqli, "UPDATE documents SET document_archived_at = NOW(), document_updated_at = document_updated_at WHERE document_id = $document_id");
|
||||
logAudit("Document", "Archive", "$session_name archived document " . escapeSql($row['document_name']), $client_id, $document_id);
|
||||
$document_count++;
|
||||
}
|
||||
|
||||
logAudit("File", "Bulk Archive", "$session_name archived $document_count document(s) and $file_count file(s)", $client_id);
|
||||
|
||||
flashAlert("Archived <strong>$document_count</strong> Documents and <strong>$file_count</strong> files", 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_delete_files'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 3);
|
||||
|
||||
// Delete file loop
|
||||
if (isset($_POST['file_ids'])) {
|
||||
|
||||
// Get selected file Count
|
||||
$file_count = count($_POST['file_ids']);
|
||||
|
||||
foreach($_POST['file_ids'] as $file_id) {
|
||||
|
||||
$file_id = intval($file_id);
|
||||
|
||||
$sql_file = mysqli_query($mysqli,"SELECT * FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql_file);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
$file_name = escapeSql($row['file_name']);
|
||||
$file_reference_name = escapeSql($row['file_reference_name']);
|
||||
$file_has_thumbnail = intval($row['file_has_thumbnail']);
|
||||
$file_has_preview = intval($row['file_has_preview']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
unlink("../uploads/clients/$client_id/$file_reference_name");
|
||||
|
||||
if ($file_has_thumbnail == 1) {
|
||||
unlink("../uploads/clients/$client_id/thumbnail_$file_reference_name");
|
||||
}
|
||||
if ($file_has_preview == 1) {
|
||||
unlink("../uploads/clients/$client_id/preview_$file_reference_name");
|
||||
}
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM files WHERE file_id = $file_id");
|
||||
|
||||
logAudit("File", "Delete", "$session_name deleted file $file_name", $client_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Delete documents loop
|
||||
if (isset($_POST['document_ids'])) {
|
||||
|
||||
// Get selected document count
|
||||
$document_count = count($_POST['document_ids']);
|
||||
|
||||
// Delete document loop
|
||||
foreach($_POST['document_ids'] as $document_id) {
|
||||
$document_id = intval($document_id);
|
||||
// Get Document Name and Client ID for logging
|
||||
$sql = mysqli_query($mysqli,"SELECT document_name, document_client_id FROM documents WHERE document_id = $document_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$client_id = intval($row['document_client_id']);
|
||||
$document_name = escapeSql($row['document_name']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM documents WHERE document_id = $document_id");
|
||||
|
||||
// Delete all versions associated with the master document
|
||||
mysqli_query($mysqli,"DELETE FROM document_versions WHERE document_version_document_id = $document_id");
|
||||
|
||||
// Delete uploads/document/$document_id if exists
|
||||
removeDirectory($_SERVER['DOCUMENT_ROOT'] . "/uploads/documents/" . $document_id);
|
||||
|
||||
logAudit("Document", "Delete", "$session_name deleted document $document_name and all versions", $client_id);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
logAudit("File", "Bulk Delete", "$session_name deleted $document_count document(s) and $file_count file(s)", $client_id);
|
||||
|
||||
flashAlert("Deleted <strong>$document_count</strong> Documents and <strong>$file_count</strong> files", 'error');
|
||||
flashAlert("Archived " . filesCountPhrase($document_count, $file_count), 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -401,237 +305,111 @@ if (isset($_POST['bulk_restore_files'])) {
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
// Restore file loop
|
||||
if (isset($_POST['file_ids'])) {
|
||||
$file_count = 0;
|
||||
$document_count = 0;
|
||||
|
||||
// Get selected file Count
|
||||
$file_count = count($_POST['file_ids']);
|
||||
|
||||
foreach($_POST['file_ids'] as $file_id) {
|
||||
|
||||
$file_id = intval($file_id);
|
||||
|
||||
$sql_file = mysqli_query($mysqli,"SELECT file_client_id, file_name FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql_file);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
$file_name = escapeSql($row['file_name']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli,"UPDATE files SET file_archived_at = NULL WHERE file_id = $file_id");
|
||||
|
||||
logAudit("File", "Restore", "$session_name restored file $file_name", $client_id, $file_id);
|
||||
foreach (array_map('intval', (array) ($_POST['file_ids'] ?? [])) as $file_id) {
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT file_client_id, file_name FROM files WHERE file_id = $file_id AND file_archived_at IS NOT NULL"));
|
||||
if (!$row) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$client_id = intval($row['file_client_id']);
|
||||
enforceClientAccess();
|
||||
mysqli_query($mysqli, "UPDATE files SET file_archived_at = NULL WHERE file_id = $file_id");
|
||||
logAudit("File", "Restore", "$session_name restored file " . escapeSql($row['file_name']), $client_id, $file_id);
|
||||
$file_count++;
|
||||
}
|
||||
|
||||
// Restore documents loop
|
||||
if (isset($_POST['document_ids'])) {
|
||||
|
||||
// Get selected document count
|
||||
$document_count = count($_POST['document_ids']);
|
||||
|
||||
// Restore document loop
|
||||
foreach($_POST['document_ids'] as $document_id) {
|
||||
$document_id = intval($document_id);
|
||||
// Get document name for logging
|
||||
$sql = mysqli_query($mysqli,"SELECT document_name, document_client_id FROM documents WHERE document_id = $document_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$document_name = escapeSql($row['document_name']);
|
||||
$client_id = intval($row['document_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli,"UPDATE documents SET document_archived_at = NULL, document_updated_at = document_updated_at WHERE document_id = $document_id");
|
||||
|
||||
logAudit("Document", "Restore", "$session_name restored document $document_name", $client_id, $document_id);
|
||||
|
||||
foreach (array_map('intval', (array) ($_POST['document_ids'] ?? [])) as $document_id) {
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT document_name, document_client_id FROM documents WHERE document_id = $document_id AND document_archived_at IS NOT NULL"));
|
||||
if (!$row) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$client_id = intval($row['document_client_id']);
|
||||
enforceClientAccess();
|
||||
mysqli_query($mysqli, "UPDATE documents SET document_archived_at = NULL, document_updated_at = document_updated_at WHERE document_id = $document_id");
|
||||
logAudit("Document", "Restore", "$session_name restored document " . escapeSql($row['document_name']), $client_id, $document_id);
|
||||
$document_count++;
|
||||
}
|
||||
|
||||
logAudit("File", "Bulk Restore", "$session_name restored $document_count document(s) and $file_count file(s)", $client_id);
|
||||
|
||||
flashAlert("Restored <strong>$document_count</strong> Documents and <strong>$file_count</strong> files");
|
||||
flashAlert("Restored " . filesCountPhrase($document_count, $file_count));
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_delete_files'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 3);
|
||||
|
||||
$file_count = 0;
|
||||
$document_count = 0;
|
||||
|
||||
foreach (array_map('intval', (array) ($_POST['file_ids'] ?? [])) as $file_id) {
|
||||
if (fileDeleteForGood($file_id) !== null) {
|
||||
$file_count++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array_map('intval', (array) ($_POST['document_ids'] ?? [])) as $document_id) {
|
||||
if (documentDeleteForGood($document_id) !== null) {
|
||||
$document_count++;
|
||||
}
|
||||
}
|
||||
|
||||
flashAlert("Deleted " . filesCountPhrase($document_count, $file_count), 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
// Unified bulk move for Files + Documents
|
||||
if (isset($_POST['bulk_move_files'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$folder_id = intval($_POST['bulk_folder_id']);
|
||||
$target_folder = intval($_POST['bulk_folder_id'] ?? 0);
|
||||
$folder_name = folderDisplayName($target_folder);
|
||||
|
||||
// Default values (for root or missing folder)
|
||||
$folder_name = "/";
|
||||
$log_client_id = 0;
|
||||
|
||||
// If moving into a real folder, get folder name + client for logging
|
||||
if ($folder_id > 0) {
|
||||
$sql = mysqli_query($mysqli,"SELECT folder_name, folder_client_id FROM folders WHERE folder_id = $folder_id");
|
||||
if ($row = mysqli_fetch_assoc($sql)) {
|
||||
$folder_name = escapeSql($row['folder_name']);
|
||||
$log_client_id = intval($row['folder_client_id']);
|
||||
}
|
||||
}
|
||||
|
||||
$file_count = 0;
|
||||
$file_count = 0;
|
||||
$document_count = 0;
|
||||
|
||||
// -------------------------
|
||||
// Move FILES (if any)
|
||||
// -------------------------
|
||||
if (!empty($_POST['file_ids']) && is_array($_POST['file_ids'])) {
|
||||
|
||||
$file_ids = array_map('intval', $_POST['file_ids']);
|
||||
$file_count = count($file_ids);
|
||||
|
||||
foreach ($file_ids as $file_id) {
|
||||
|
||||
// Get file name for logging
|
||||
$file_name = escapeSql(getFieldById('files', $file_id, 'file_name'));
|
||||
$client_id = intval(getFieldById('files', $file_id, 'file_client_id'));
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Move file
|
||||
mysqli_query($mysqli,"UPDATE files SET file_folder_id = $folder_id WHERE file_id = $file_id");
|
||||
|
||||
// Per-file log
|
||||
logAudit(
|
||||
"File",
|
||||
"Move",
|
||||
"$session_name moved file $file_name to folder $folder_name",
|
||||
$log_client_id,
|
||||
$file_id
|
||||
);
|
||||
// Each item only moves into a folder of its own client - one of another
|
||||
// client's folders would take it out of sight of both
|
||||
foreach (array_map('intval', (array) ($_POST['file_ids'] ?? [])) as $file_id) {
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT file_client_id, file_name FROM files WHERE file_id = $file_id"));
|
||||
if (!$row) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Bulk summary log for files
|
||||
logAudit(
|
||||
"File",
|
||||
"Bulk Move",
|
||||
"$session_name moved $file_count file(s) to folder $folder_name",
|
||||
$log_client_id
|
||||
);
|
||||
}
|
||||
|
||||
// -------------------------
|
||||
// Move DOCUMENTS (if any)
|
||||
// -------------------------
|
||||
if (!empty($_POST['document_ids']) && is_array($_POST['document_ids'])) {
|
||||
|
||||
$document_ids = array_map('intval', $_POST['document_ids']);
|
||||
$document_count = count($document_ids);
|
||||
|
||||
foreach ($document_ids as $document_id) {
|
||||
|
||||
// Get document name for logging
|
||||
$document_name = escapeSql(getFieldById('documents', $document_id, 'document_name'));
|
||||
$client_id = intval(getFieldById('documents', $document_id, 'document_client_id'));
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Move document
|
||||
mysqli_query($mysqli,"UPDATE documents SET document_folder_id = $folder_id, document_updated_at = document_updated_at WHERE document_id = $document_id");
|
||||
|
||||
// Per-document log
|
||||
logAudit(
|
||||
"Document",
|
||||
"Move",
|
||||
"$session_name moved document $document_name to folder $folder_name",
|
||||
$log_client_id,
|
||||
$document_id
|
||||
);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
enforceClientAccess();
|
||||
if ($target_folder && folderOwnedId($target_folder, $client_id) !== $target_folder) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Bulk summary log for documents
|
||||
logAudit(
|
||||
"Document",
|
||||
"Bulk Move",
|
||||
"$session_name moved $document_count document(s) to folder $folder_name",
|
||||
$log_client_id
|
||||
);
|
||||
mysqli_query($mysqli, "UPDATE files SET file_folder_id = $target_folder WHERE file_id = $file_id");
|
||||
logAudit("File", "Move", "$session_name moved file " . escapeSql($row['file_name']) . " to " . escapeSql($folder_name), $client_id, $file_id);
|
||||
$file_count++;
|
||||
}
|
||||
|
||||
// -------------------------
|
||||
// Flash message
|
||||
// -------------------------
|
||||
if ($file_count && $document_count) {
|
||||
flashAlert("Moved <strong>$file_count</strong> file(s) and <strong>$document_count</strong> document(s) to the folder <strong>$folder_name</strong>");
|
||||
} elseif ($file_count) {
|
||||
flashAlert("Moved <strong>$file_count</strong> file(s) to the folder <strong>$folder_name</strong>");
|
||||
} elseif ($document_count) {
|
||||
flashAlert("Moved <strong>$document_count</strong> document(s) to the folder <strong>$folder_name</strong>");
|
||||
} else {
|
||||
flashAlert("No items were moved.");
|
||||
foreach (array_map('intval', (array) ($_POST['document_ids'] ?? [])) as $document_id) {
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT document_client_id, document_name FROM documents WHERE document_id = $document_id"));
|
||||
if (!$row) {
|
||||
continue;
|
||||
}
|
||||
$client_id = intval($row['document_client_id']);
|
||||
enforceClientAccess();
|
||||
if ($target_folder && folderOwnedId($target_folder, $client_id) !== $target_folder) {
|
||||
continue;
|
||||
}
|
||||
mysqli_query($mysqli, "UPDATE documents SET document_folder_id = $target_folder, document_updated_at = document_updated_at WHERE document_id = $document_id");
|
||||
logAudit("Document", "Move", "$session_name moved document " . escapeSql($row['document_name']) . " to " . escapeSql($folder_name), $client_id, $document_id);
|
||||
$document_count++;
|
||||
}
|
||||
|
||||
redirect();
|
||||
}
|
||||
|
||||
|
||||
if (isset($_POST['link_asset_to_file'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$file_id = intval($_POST['file_id']);
|
||||
$asset_id = intval($_POST['asset_id']);
|
||||
|
||||
// Get File Name and Client ID for Logging
|
||||
$sql = mysqli_query($mysqli,"SELECT file_name, file_client_id FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$file_name = escapeSql($row['file_name']);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Get Asset Name for Logging
|
||||
$asset_name = escapeSql(getFieldById('assets', $asset_id, 'asset_name'));
|
||||
|
||||
// Contact add query
|
||||
mysqli_query($mysqli,"INSERT INTO asset_files SET asset_id = $asset_id, file_id = $file_id");
|
||||
|
||||
logAudit("File", "Link", "$session_name linked asset $asset_name to file $file_name", $client_id, $file_id);
|
||||
|
||||
flashAlert("Asset <strong>$asset_name</strong> linked to File <strong>$file_name</strong>");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['unlink_asset_from_file'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$asset_id = intval($_GET['asset_id']);
|
||||
$file_id = intval($_GET['file_id']);
|
||||
|
||||
// Get File Name and Client ID for Logging
|
||||
$sql = mysqli_query($mysqli,"SELECT file_name, file_client_id FROM files WHERE file_id = $file_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$file_name = escapeSql($row['file_name']);
|
||||
$client_id = intval($row['file_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Get Asset Name for Logging
|
||||
$asset_name = escapeSql(getFieldById('assets', $asset_id, 'asset_name'));
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM asset_files WHERE asset_id = $asset_id AND file_id = $file_id");
|
||||
|
||||
logAudit("File", "Link", "$session_name unlinked asset $asset_name from file $file_name", $client_id, $file_id);
|
||||
|
||||
flashAlert("Asset <strong>$asset_name</strong> unlinked from File <strong>$file_name</strong>");
|
||||
flashAlert("Moved " . filesCountPhrase($document_count, $file_count) . " to <strong>$folder_name</strong>");
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -13,21 +13,26 @@ if (isset($_POST['create_folder'])) {
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$client_id = intval($_POST['client_id']);
|
||||
$folder_location = intval($_POST['folder_location']);
|
||||
$folder_name = escapeSql($_POST['folder_name']);
|
||||
$parent_folder = intval($_POST['parent_folder']);
|
||||
$folder_name = escapeSql(trim($_POST['folder_name'] ?? ''));
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Document folder add query
|
||||
$add_folder = mysqli_query($mysqli,"INSERT INTO folders SET folder_name = '$folder_name', parent_folder = $parent_folder, folder_location = $folder_location, folder_client_id = $client_id");
|
||||
// Under one of this client's folders, or at the top level
|
||||
$parent_folder = folderOwnedId($_POST['parent_folder'] ?? 0, $client_id);
|
||||
|
||||
if ($folder_name === '') {
|
||||
flashAlert('A folder needs a name.', 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO folders SET folder_name = '$folder_name', parent_folder = $parent_folder, folder_location = 0, folder_client_id = $client_id");
|
||||
$folder_id = mysqli_insert_id($mysqli);
|
||||
|
||||
logAudit("Folder", "Create", "$session_name created folder $folder_name", $client_id, $folder_id);
|
||||
|
||||
flashAlert("Folder <strong>$folder_name</strong> created");
|
||||
flashAlert("Folder <strong>" . trim($_POST['folder_name']) . "</strong> created");
|
||||
|
||||
redirect();
|
||||
redirect("files.php?client_id=$client_id&folder_id=$folder_id");
|
||||
|
||||
}
|
||||
|
||||
@@ -38,57 +43,82 @@ if (isset($_POST['rename_folder'])) {
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$folder_id = intval($_POST['folder_id']);
|
||||
$folder_name = escapeSql($_POST['folder_name']);
|
||||
$folder_name = escapeSql(trim($_POST['folder_name'] ?? ''));
|
||||
|
||||
// Get old Folder Name Client ID for Logging
|
||||
$sql = mysqli_query($mysqli,"SELECT folder_name, folder_client_id FROM folders WHERE folder_id = $folder_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT folder_name, folder_client_id, parent_folder FROM folders WHERE folder_id = $folder_id"));
|
||||
if (!$row) {
|
||||
flashAlert('That folder no longer exists.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$old_folder_name = escapeSql($row['folder_name']);
|
||||
$client_id = intval($row['folder_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Folder edit query
|
||||
mysqli_query($mysqli,"UPDATE folders SET folder_name = '$folder_name' WHERE folder_id = $folder_id");
|
||||
if ($folder_name === '') {
|
||||
flashAlert('A folder needs a name.', 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
logAudit("Folder", "Rename", "$session_name renamed folder $old_folder_name to $folder_name", $client_id, $folder_id);
|
||||
// Moved as well? Only under one of this client's folders, and never into itself or below itself
|
||||
$parent_folder = intval($row['parent_folder']);
|
||||
if (isset($_POST['parent_folder'])) {
|
||||
$new_parent = folderOwnedId($_POST['parent_folder'], $client_id);
|
||||
if (!in_array($new_parent, folderSubtree(folderTree($client_id), $folder_id), true)) {
|
||||
$parent_folder = $new_parent;
|
||||
}
|
||||
}
|
||||
|
||||
flashAlert("Folder <strong>$old_folder_name</strong> renamed to <strong>$folder_name</strong>");
|
||||
mysqli_query($mysqli, "UPDATE folders SET folder_name = '$folder_name', parent_folder = $parent_folder WHERE folder_id = $folder_id");
|
||||
|
||||
if ($old_folder_name !== $folder_name) {
|
||||
logAudit("Folder", "Rename", "$session_name renamed folder $old_folder_name to $folder_name", $client_id, $folder_id);
|
||||
}
|
||||
if ($parent_folder !== intval($row['parent_folder'])) {
|
||||
logAudit("Folder", "Move", "$session_name moved folder $folder_name into " . escapeSql(folderDisplayName($parent_folder)), $client_id, $folder_id);
|
||||
}
|
||||
|
||||
flashAlert("Folder <strong>" . trim($_POST['folder_name']) . "</strong> saved");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['delete_folder'])) {
|
||||
/*
|
||||
* Deleting a folder never deletes what is in it: files, documents and
|
||||
* subfolders move up to the folder it sat in. (Only documents used to be
|
||||
* moved - files and subfolders were left pointing at a folder that no
|
||||
* longer existed, and dropped out of sight.)
|
||||
*/
|
||||
if (isset($_POST['delete_folder']) || isset($_GET['delete_folder'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 3);
|
||||
|
||||
$folder_id = intval($_GET['delete_folder']);
|
||||
$folder_id = intval($_POST['folder_id'] ?? $_GET['delete_folder']);
|
||||
|
||||
// Get Folder Name Client ID for Logging
|
||||
$sql = mysqli_query($mysqli,"SELECT folder_name, folder_client_id FROM folders WHERE folder_id = $folder_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT folder_name, folder_client_id, parent_folder FROM folders WHERE folder_id = $folder_id"));
|
||||
if (!$row) {
|
||||
flashAlert('That folder no longer exists.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$folder_name = escapeSql($row['folder_name']);
|
||||
$client_id = intval($row['folder_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM folders WHERE folder_id = $folder_id");
|
||||
$parent_folder = folderOwnedId($row['parent_folder'], $client_id);
|
||||
|
||||
// Move files in deleted folder back to the root folder /
|
||||
$sql_documents = mysqli_query($mysqli,"SELECT document_id FROM documents WHERE document_folder_id = $folder_id");
|
||||
while($row = mysqli_fetch_assoc($sql_documents)) {
|
||||
$document_id = intval($row['document_id']);
|
||||
mysqli_query($mysqli, "UPDATE files SET file_folder_id = $parent_folder WHERE file_folder_id = $folder_id AND file_client_id = $client_id");
|
||||
mysqli_query($mysqli, "UPDATE documents SET document_folder_id = $parent_folder, document_updated_at = document_updated_at WHERE document_folder_id = $folder_id AND document_client_id = $client_id");
|
||||
mysqli_query($mysqli, "UPDATE folders SET parent_folder = $parent_folder WHERE parent_folder = $folder_id AND folder_client_id = $client_id");
|
||||
mysqli_query($mysqli, "DELETE FROM folders WHERE folder_id = $folder_id");
|
||||
|
||||
mysqli_query($mysqli,"UPDATE documents SET document_folder_id = 0 WHERE document_id = $document_id");
|
||||
}
|
||||
logAudit("Folder", "Delete", "$session_name deleted folder $folder_name, its contents moved to " . escapeSql(folderDisplayName($parent_folder)), $client_id);
|
||||
|
||||
logAudit("Folder", "Delete", "$session_name deleted folder $folder_name", $client_id);
|
||||
flashAlert("Folder <strong>{$row['folder_name']}</strong> deleted", 'error');
|
||||
|
||||
flashAlert("Folder <strong>$folder_name</strong> deleted", 'error');
|
||||
|
||||
redirect();
|
||||
redirect("files.php?client_id=$client_id&folder_id=$parent_folder");
|
||||
|
||||
}
|
||||
|
||||
82
agent/post/link.php
Normal file
82
agent/post/link.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - links between documents, files and what they are about.
|
||||
*
|
||||
* One handler for every pair LINK_RELATIONS knows (functions/links.php):
|
||||
* link_items links any number of records at once, unlink_item drops one.
|
||||
* The older one-pair-each names (link_asset_to_document, unlink_contact_from_file
|
||||
* and so on) are still answered here, so a link built by any page or older
|
||||
* modal keeps working - and gets the same checks: the same client, nothing
|
||||
* archived, no 500 on a link that already exists.
|
||||
*/
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
/** Link or unlink, permission and client checks included. Ends the request. */
|
||||
function linkHandle($action, $from, $id, $to, $ids) {
|
||||
global $client_id;
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$relation = linkRelation($from, $to);
|
||||
$source = linkRecord($from, $id);
|
||||
if (!$relation || !$source) {
|
||||
flashAlert('That link no longer exists.', 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
enforceUserPermission($relation['module'], 2);
|
||||
|
||||
$client_id = intval($source['client_id']);
|
||||
enforceClientAccess();
|
||||
|
||||
$to_entity = LINK_ENTITIES[$to];
|
||||
|
||||
if ($action === 'link') {
|
||||
$added = linkAdd($from, $source['id'], $to, $ids);
|
||||
if (!$added) {
|
||||
flashAlert("Nothing new to link to <strong>{$source['name']}</strong>.", 'warning');
|
||||
} elseif (count($added) === 1) {
|
||||
flashAlert(ucfirst($to_entity['label']) . " <strong>{$added[0]}</strong> linked to <strong>{$source['name']}</strong>");
|
||||
} else {
|
||||
flashAlert("Linked <strong>" . count($added) . "</strong> " . strtolower($to_entity['plural']) . " to <strong>{$source['name']}</strong>");
|
||||
}
|
||||
} else {
|
||||
$removed = linkRemove($from, $source['id'], $to, intval($ids[0] ?? 0));
|
||||
if ($removed !== '') {
|
||||
flashAlert(ucfirst($to_entity['label']) . " <strong>$removed</strong> unlinked from <strong>{$source['name']}</strong>", 'error');
|
||||
}
|
||||
}
|
||||
|
||||
redirect();
|
||||
}
|
||||
|
||||
if (isset($_POST['link_items'])) {
|
||||
$ids = $_POST['ids'] ?? [];
|
||||
linkHandle('link', (string) ($_POST['from'] ?? ''), intval($_POST['id'] ?? 0), (string) ($_POST['to'] ?? ''), is_array($ids) ? $ids : [$ids]);
|
||||
}
|
||||
|
||||
if (isset($_GET['unlink_item'])) {
|
||||
linkHandle('unlink', (string) ($_GET['from'] ?? ''), intval($_GET['id'] ?? 0), (string) ($_GET['to'] ?? ''), [intval($_GET['other'] ?? 0)]);
|
||||
}
|
||||
|
||||
// The older names: [from, its id field, to, its id field]
|
||||
$legacy_links = [
|
||||
'asset_to_document' => ['document', 'document_id', 'asset', 'asset_id'],
|
||||
'contact_to_document' => ['document', 'document_id', 'contact', 'contact_id'],
|
||||
'file_to_document' => ['document', 'document_id', 'file', 'file_id'],
|
||||
'software_to_document' => ['document', 'document_id', 'software', 'software_id'],
|
||||
'vendor_to_document' => ['document', 'document_id', 'vendor', 'vendor_id'],
|
||||
'asset_to_file' => ['file', 'file_id', 'asset', 'asset_id'],
|
||||
'contact_to_file' => ['file', 'file_id', 'contact', 'contact_id'],
|
||||
];
|
||||
foreach ($legacy_links as $legacy => [$from, $from_field, $to, $to_field]) {
|
||||
if (isset($_POST["link_$legacy"])) {
|
||||
linkHandle('link', $from, intval($_POST[$from_field] ?? 0), $to, [intval($_POST[$to_field] ?? 0)]);
|
||||
}
|
||||
$unlink = 'unlink_' . str_replace('_to_', '_from_', $legacy);
|
||||
if (isset($_GET[$unlink])) {
|
||||
linkHandle('unlink', $from, intval($_GET[$from_field] ?? 0), $to, [intval($_GET[$to_field] ?? 0)]);
|
||||
}
|
||||
}
|
||||
@@ -3991,3 +3991,463 @@ img.itflow-contact-avatar {
|
||||
.itflow-contact-chip.is-alert i {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
/* Files & documents - agent/files.php, agent/document.php, the file and
|
||||
document quick looks, the upload and link modals.
|
||||
|
||||
A file's type is a tinted tile like an asset's type (fileTypeTile() in
|
||||
functions/files.php): the colour family says what it is at a glance -
|
||||
PDFs red, Word blue, spreadsheets green - and created documents take the
|
||||
app's own blue. */
|
||||
.itflow-file-icon {
|
||||
display: inline-flex;
|
||||
flex: 0 0 auto;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
border-radius: var(--bs-border-radius-lg);
|
||||
background-color: color-mix(in srgb, var(--itflow-file-tone) 14%, transparent);
|
||||
color: var(--itflow-file-tone);
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
.itflow-file-icon-sm {
|
||||
width: 1.75rem;
|
||||
height: 1.75rem;
|
||||
border-radius: var(--bs-border-radius);
|
||||
font-size: .8rem;
|
||||
}
|
||||
.itflow-file-icon-lg {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
font-size: 1.6rem;
|
||||
}
|
||||
.itflow-file-tone-pdf { --itflow-file-tone: #c8372d; }
|
||||
.itflow-file-tone-word { --itflow-file-tone: #2b5797; }
|
||||
.itflow-file-tone-excel { --itflow-file-tone: #1e7145; }
|
||||
.itflow-file-tone-slides { --itflow-file-tone: #c4501c; }
|
||||
.itflow-file-tone-image { --itflow-file-tone: #13857d; }
|
||||
.itflow-file-tone-media { --itflow-file-tone: #8e44ad; }
|
||||
.itflow-file-tone-archive { --itflow-file-tone: #8a6a2f; }
|
||||
.itflow-file-tone-text { --itflow-file-tone: #5c6773; }
|
||||
.itflow-file-tone-code { --itflow-file-tone: #4b5d8a; }
|
||||
.itflow-file-tone-drawing { --itflow-file-tone: #d97706; }
|
||||
.itflow-file-tone-cert { --itflow-file-tone: #a1781b; }
|
||||
.itflow-file-tone-other { --itflow-file-tone: #6c757d; }
|
||||
.itflow-file-tone-document { --itflow-file-tone: var(--itflow-accent, #0d6efd); }
|
||||
[data-bs-theme="dark"] .itflow-file-tone-pdf { --itflow-file-tone: #f08a80; }
|
||||
[data-bs-theme="dark"] .itflow-file-tone-word { --itflow-file-tone: #8ab4f0; }
|
||||
[data-bs-theme="dark"] .itflow-file-tone-excel { --itflow-file-tone: #6fcf9a; }
|
||||
[data-bs-theme="dark"] .itflow-file-tone-slides { --itflow-file-tone: #f2a072; }
|
||||
[data-bs-theme="dark"] .itflow-file-tone-image { --itflow-file-tone: #5fd1c6; }
|
||||
[data-bs-theme="dark"] .itflow-file-tone-media { --itflow-file-tone: #c99ae0; }
|
||||
[data-bs-theme="dark"] .itflow-file-tone-archive { --itflow-file-tone: #d9b878; }
|
||||
[data-bs-theme="dark"] .itflow-file-tone-text { --itflow-file-tone: #b4bec8; }
|
||||
[data-bs-theme="dark"] .itflow-file-tone-code { --itflow-file-tone: #a3b3dc; }
|
||||
[data-bs-theme="dark"] .itflow-file-tone-drawing { --itflow-file-tone: #f5b257; }
|
||||
[data-bs-theme="dark"] .itflow-file-tone-cert { --itflow-file-tone: #e3c46b; }
|
||||
[data-bs-theme="dark"] .itflow-file-tone-other { --itflow-file-tone: #adb5bd; }
|
||||
[data-bs-theme="dark"] .itflow-file-tone-document { --itflow-file-tone: #8ab4f8; }
|
||||
|
||||
/* The folder tree beside the list */
|
||||
.itflow-files-tree {
|
||||
background-color: var(--bs-tertiary-bg);
|
||||
}
|
||||
@media (min-width: 992px) {
|
||||
.itflow-files-tree #filesFolderTree {
|
||||
position: sticky;
|
||||
top: 4rem;
|
||||
max-height: calc(100vh - 5rem);
|
||||
overflow-y: auto;
|
||||
}
|
||||
}
|
||||
.itflow-folder > ul {
|
||||
display: none;
|
||||
}
|
||||
.itflow-folder.is-open > ul {
|
||||
display: block;
|
||||
}
|
||||
.itflow-folder-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-left: calc(var(--itflow-folder-depth, 0) * .9rem);
|
||||
border-radius: var(--bs-border-radius);
|
||||
}
|
||||
.itflow-folder-row:hover {
|
||||
background-color: var(--bs-secondary-bg);
|
||||
}
|
||||
.itflow-folder-row.active {
|
||||
background-color: var(--bs-primary-bg-subtle);
|
||||
}
|
||||
.itflow-folder-row.active .itflow-folder-link {
|
||||
color: var(--bs-primary-text-emphasis);
|
||||
font-weight: 600;
|
||||
}
|
||||
.itflow-folder-toggle {
|
||||
flex: 0 0 1.25rem;
|
||||
width: 1.25rem;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
font-size: .65rem;
|
||||
color: var(--bs-secondary-color);
|
||||
transition: transform .12s ease-in-out;
|
||||
}
|
||||
.itflow-folder.is-open > .itflow-folder-row .itflow-folder-toggle {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
.itflow-folder-link {
|
||||
display: flex;
|
||||
flex: 1 1 auto;
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
padding: .3rem .4rem .3rem .1rem;
|
||||
font-size: .875rem;
|
||||
color: var(--bs-body-color);
|
||||
text-decoration: none;
|
||||
}
|
||||
.itflow-folder-link .fa-folder,
|
||||
.itflow-folder-link .fa-folder-open,
|
||||
.itflow-folder-link .fa-home {
|
||||
color: #d4a72c;
|
||||
}
|
||||
.itflow-folder-link .fa-home {
|
||||
color: var(--bs-secondary-color);
|
||||
}
|
||||
.itflow-folder-link .badge {
|
||||
background-color: var(--bs-secondary-bg);
|
||||
color: var(--bs-secondary-color);
|
||||
font-weight: 500;
|
||||
}
|
||||
.itflow-folder-menu .btn {
|
||||
padding: 0 .4rem;
|
||||
color: var(--bs-secondary-color);
|
||||
opacity: 0;
|
||||
}
|
||||
.itflow-folder-row:hover .itflow-folder-menu .btn,
|
||||
.itflow-folder-menu .btn[aria-expanded="true"],
|
||||
.itflow-folder-menu .btn:focus-visible {
|
||||
opacity: 1;
|
||||
}
|
||||
@media (hover: none) {
|
||||
.itflow-folder-menu .btn {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* The list */
|
||||
.itflow-files-main {
|
||||
position: relative;
|
||||
}
|
||||
.itflow-files-path .breadcrumb {
|
||||
font-size: .875rem;
|
||||
}
|
||||
.itflow-files-table td {
|
||||
padding-top: .55rem;
|
||||
padding-bottom: .55rem;
|
||||
}
|
||||
.itflow-files-name-cell {
|
||||
min-width: 14rem;
|
||||
}
|
||||
.itflow-files-desc {
|
||||
max-width: 32rem;
|
||||
}
|
||||
.itflow-files-linked {
|
||||
min-width: 8.5rem;
|
||||
}
|
||||
.itflow-files-name-cell .itflow-above-stretch {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
/* The grid */
|
||||
.itflow-file-card {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
transition: box-shadow .12s ease-in-out;
|
||||
}
|
||||
.itflow-file-card:hover {
|
||||
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .08);
|
||||
}
|
||||
.itflow-file-card:has(.bulk-select:checked) {
|
||||
outline: 2px solid var(--bs-primary);
|
||||
background-color: var(--bs-primary-bg-subtle);
|
||||
}
|
||||
.itflow-file-card-check {
|
||||
position: absolute;
|
||||
top: .4rem;
|
||||
left: .4rem;
|
||||
z-index: 3;
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
margin: 0;
|
||||
padding: .2rem;
|
||||
border-radius: var(--bs-border-radius-sm);
|
||||
background-color: var(--bs-body-bg);
|
||||
box-shadow: 0 0 0 1px var(--bs-border-color-translucent);
|
||||
/* Out of the way of the preview until the card is pointed at or ticked */
|
||||
opacity: 0;
|
||||
transition: opacity .12s ease-in-out;
|
||||
}
|
||||
.itflow-file-card:hover .itflow-file-card-check,
|
||||
.itflow-file-card-check:has(:checked),
|
||||
.itflow-file-card-check:has(:focus-visible),
|
||||
.itflow-files-grid:has(.bulk-select:checked) .itflow-file-card-check {
|
||||
opacity: 1;
|
||||
}
|
||||
@media (hover: none) {
|
||||
.itflow-file-card-check {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.itflow-file-card-check .form-check-input {
|
||||
margin: 0;
|
||||
background-color: var(--bs-body-bg);
|
||||
}
|
||||
.itflow-file-card-preview {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 9.5rem;
|
||||
overflow: hidden;
|
||||
border-bottom: 1px solid var(--bs-border-color-translucent);
|
||||
background-color: var(--bs-tertiary-bg);
|
||||
text-decoration: none;
|
||||
}
|
||||
.itflow-file-card-preview img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
.itflow-file-card-preview iframe {
|
||||
width: 100%;
|
||||
/* Taller than the box and pulled up, so a viewer's toolbar is clipped away */
|
||||
height: calc(100% + 56px);
|
||||
margin-top: -56px;
|
||||
border: 0;
|
||||
pointer-events: none;
|
||||
background: #fff;
|
||||
}
|
||||
.itflow-file-card-preview pre {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: .6rem .7rem;
|
||||
overflow: hidden;
|
||||
font-size: .65rem;
|
||||
line-height: 1.35;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
color: var(--bs-secondary-color);
|
||||
background-color: var(--bs-body-bg);
|
||||
}
|
||||
.itflow-file-card.is-document .itflow-file-card-preview pre {
|
||||
font-family: var(--bs-body-font-family);
|
||||
font-size: .7rem;
|
||||
}
|
||||
|
||||
/* Files dragged over the list */
|
||||
.itflow-files-dropzone {
|
||||
position: absolute;
|
||||
z-index: 20;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
border: 2px dashed var(--bs-primary);
|
||||
border-radius: var(--bs-border-radius-lg);
|
||||
background-color: color-mix(in srgb, var(--bs-body-bg) 82%, transparent);
|
||||
color: var(--bs-primary-text-emphasis);
|
||||
pointer-events: none;
|
||||
}
|
||||
.itflow-files-dropzone[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Upload modal */
|
||||
.itflow-upload-drop {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: .15rem;
|
||||
padding: 1.6rem 1rem;
|
||||
border: 2px dashed var(--bs-border-color);
|
||||
border-radius: var(--bs-border-radius-lg);
|
||||
color: var(--bs-secondary-color);
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
transition: border-color .12s, background-color .12s;
|
||||
}
|
||||
.itflow-upload-drop:hover,
|
||||
.itflow-upload-drop.is-over {
|
||||
border-color: var(--bs-primary);
|
||||
background-color: var(--bs-primary-bg-subtle);
|
||||
color: var(--bs-primary-text-emphasis);
|
||||
}
|
||||
.itflow-upload-drop.has-files {
|
||||
padding: .9rem 1rem;
|
||||
}
|
||||
.itflow-upload-drop:focus-within {
|
||||
outline: 2px solid var(--bs-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.itflow-upload-list {
|
||||
max-height: 12rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.itflow-upload-list li {
|
||||
padding: .2rem .25rem;
|
||||
border-bottom: 1px solid var(--bs-border-color-translucent);
|
||||
}
|
||||
|
||||
/* File quick look preview */
|
||||
.itflow-file-preview {
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--bs-border-color);
|
||||
border-radius: var(--bs-border-radius-lg);
|
||||
background-color: var(--bs-tertiary-bg);
|
||||
text-align: center;
|
||||
}
|
||||
.itflow-file-preview img {
|
||||
max-width: 100%;
|
||||
max-height: 22rem;
|
||||
object-fit: contain;
|
||||
}
|
||||
.itflow-file-preview iframe {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 26rem;
|
||||
border: 0;
|
||||
background: #fff;
|
||||
}
|
||||
.itflow-file-preview pre {
|
||||
max-height: 20rem;
|
||||
margin: 0;
|
||||
padding: .75rem 1rem;
|
||||
overflow: auto;
|
||||
font-size: .75rem;
|
||||
text-align: left;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
.itflow-file-preview .itflow-asset-empty {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
/* Linked records - linkGroupsHtml() in functions/links.php */
|
||||
.itflow-link-group + .itflow-link-group,
|
||||
.itflow-link-group + .itflow-link-empty {
|
||||
margin-top: .9rem;
|
||||
}
|
||||
.itflow-link-group-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: .35rem;
|
||||
font-size: .75rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: .02em;
|
||||
text-transform: uppercase;
|
||||
color: var(--bs-secondary-color);
|
||||
}
|
||||
.itflow-link-group-head .badge {
|
||||
background-color: var(--bs-secondary-bg);
|
||||
color: var(--bs-secondary-color);
|
||||
font-weight: 500;
|
||||
}
|
||||
.itflow-link-group-head a {
|
||||
text-transform: none;
|
||||
letter-spacing: 0;
|
||||
font-weight: 500;
|
||||
}
|
||||
.itflow-link-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .6rem;
|
||||
padding: .3rem .4rem;
|
||||
margin: 0 -.4rem;
|
||||
border-radius: var(--bs-border-radius);
|
||||
font-size: .875rem;
|
||||
}
|
||||
.itflow-link-row:hover {
|
||||
background-color: var(--bs-tertiary-bg);
|
||||
}
|
||||
.itflow-link-icon {
|
||||
display: inline-flex;
|
||||
flex: 0 0 auto;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 1.75rem;
|
||||
height: 1.75rem;
|
||||
border-radius: var(--bs-border-radius);
|
||||
background-color: var(--bs-secondary-bg);
|
||||
color: var(--bs-secondary-color);
|
||||
font-size: .8rem;
|
||||
}
|
||||
.itflow-link-remove {
|
||||
flex: 0 0 auto;
|
||||
padding: 0 .25rem;
|
||||
font-size: .8rem;
|
||||
color: var(--bs-secondary-color);
|
||||
opacity: 0;
|
||||
transition: opacity .12s ease-in-out;
|
||||
}
|
||||
.itflow-link-row:hover .itflow-link-remove,
|
||||
.itflow-link-remove:focus-visible {
|
||||
opacity: 1;
|
||||
}
|
||||
.itflow-link-remove:hover {
|
||||
color: var(--bs-danger);
|
||||
}
|
||||
@media (hover: none) {
|
||||
.itflow-link-remove {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.itflow-link-empty {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: .35rem;
|
||||
}
|
||||
.itflow-link-types .nav-link {
|
||||
padding: .3rem .7rem;
|
||||
font-size: .875rem;
|
||||
}
|
||||
.itflow-link-types .nav-link:not(.active) {
|
||||
color: var(--bs-body-color);
|
||||
}
|
||||
|
||||
/* The document page and quick looks */
|
||||
.itflow-document-body {
|
||||
min-height: 12rem;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.itflow-document-quick-content {
|
||||
max-height: 55vh;
|
||||
overflow: auto;
|
||||
padding: 1rem 1.25rem;
|
||||
border: 1px solid var(--bs-border-color);
|
||||
border-radius: var(--bs-border-radius-lg);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.itflow-document-history .list-group-item {
|
||||
padding-top: .5rem;
|
||||
padding-bottom: .5rem;
|
||||
}
|
||||
.itflow-document-history .list-group-item:hover .itflow-copy {
|
||||
opacity: 1;
|
||||
}
|
||||
.itflow-preview-nav {
|
||||
z-index: 2;
|
||||
}
|
||||
@media print {
|
||||
.itflow-document-head .card-body {
|
||||
padding: 0;
|
||||
}
|
||||
.itflow-document-head,
|
||||
.itflow-document-body {
|
||||
border: 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ require_once __DIR__ . '/functions/network.php';
|
||||
require_once __DIR__ . '/functions/rack.php';
|
||||
require_once __DIR__ . '/functions/asset.php';
|
||||
require_once __DIR__ . '/functions/contact.php';
|
||||
require_once __DIR__ . '/functions/links.php';
|
||||
require_once __DIR__ . '/functions/auth.php';
|
||||
require_once __DIR__ . '/functions/logging.php';
|
||||
require_once __DIR__ . '/functions/app.php';
|
||||
|
||||
@@ -456,3 +456,224 @@ function getFileTextExcerpt($client_id, $file_reference_name, $length = 400) {
|
||||
|
||||
return cleanTextExcerpt($raw, $length);
|
||||
}
|
||||
|
||||
/*
|
||||
* Files & documents section - how a file's type is shown, and the client's
|
||||
* folder tree. Shared by agent/files.php, the document page, the file and
|
||||
* document quick looks and the upload, move and link modals.
|
||||
*/
|
||||
|
||||
/**
|
||||
* What kind of file an extension is: its icon, a short label, and the colour
|
||||
* family its tile is drawn in (.itflow-file-tone-* in itflow_custom.css).
|
||||
* Leans on getFileIcon() for the icon where the two agree, so the portal and
|
||||
* the agent side still read from one list of extensions.
|
||||
*/
|
||||
function fileTypeInfo($extension) {
|
||||
$extension = strtolower(trim((string) $extension));
|
||||
$kinds = [
|
||||
['pdf', ['pdf'], 'file-pdf', 'PDF'],
|
||||
['word', ['doc', 'docx', 'odt', 'rtf', 'pages'], 'file-word', 'Word'],
|
||||
['excel', ['xls', 'xlsx', 'ods', 'csv', 'numbers'], 'file-excel', 'Spreadsheet'],
|
||||
['slides', ['ppt', 'pptx', 'odp'], 'file-powerpoint', 'Presentation'],
|
||||
['image', ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'tif', 'tiff', 'heic', 'svg'], 'file-image', 'Image'],
|
||||
['media', ['mp4', 'mov', 'av1', 'avi', 'mkv', 'webm', 'wmv'], 'file-video', 'Video'],
|
||||
['media', ['mp3', 'wav', 'ogg', 'flac', 'm4a'], 'file-audio', 'Audio'],
|
||||
['archive', ['zip', 'tar', 'gz', 'tgz', '7z', 'rar'], 'file-archive', 'Archive'],
|
||||
['text', ['txt', 'md', 'log'], 'file-alt', 'Text'],
|
||||
['text', ['msg', 'eml'], 'envelope', 'Email'],
|
||||
['code', ['json', 'cfg', 'conf', 'ini', 'xml', 'yaml', 'yml', 'ovpn', 'ps1', 'bat', 'sh', 'unf', 'unifi', 'stk', 'swb'], 'file-code', 'Config / script'],
|
||||
['drawing', ['vsdx', 'drawio'], 'project-diagram', 'Diagram'],
|
||||
['cert', ['pfx', 'p12', 'cer', 'crt', 'pem', 'key'], 'certificate', 'Certificate / key'],
|
||||
];
|
||||
foreach ($kinds as [$tone, $extensions, $icon, $label]) {
|
||||
if (in_array($extension, $extensions, true)) {
|
||||
return ['tone' => $tone, 'icon' => $icon, 'label' => $label];
|
||||
}
|
||||
}
|
||||
return ['tone' => 'other', 'icon' => getFileIcon($extension), 'label' => $extension !== '' ? strtoupper($extension) . ' file' : 'File'];
|
||||
}
|
||||
|
||||
/** A file's type as a coloured tile - the files list, linked items, the quick look. $size is '', 'sm' or 'lg'. */
|
||||
function fileTypeTile($extension, $size = '') {
|
||||
$info = fileTypeInfo($extension);
|
||||
return '<span class="itflow-file-icon itflow-file-tone-' . $info['tone'] . ($size ? " itflow-file-icon-$size" : '') . '" title="' . escapeHtml($info['label']) . '" aria-hidden="true"><i class="fas fa-fw fa-' . $info['icon'] . '"></i></span>';
|
||||
}
|
||||
|
||||
/** A created document's tile, in the same family as fileTypeTile(). */
|
||||
function documentTile($size = '') {
|
||||
return '<span class="itflow-file-icon itflow-file-tone-document' . ($size ? " itflow-file-icon-$size" : '') . '" title="Document" aria-hidden="true"><i class="fas fa-fw fa-file-alt"></i></span>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Every folder a client has, in one query: id => [folder_id, folder_name,
|
||||
* parent_folder, children => [ids]], with 0 standing in for the root.
|
||||
* Folders whose parent no longer exists hang off the root, so nothing in
|
||||
* them is ever out of reach.
|
||||
*/
|
||||
function folderTree($client_id) {
|
||||
global $mysqli;
|
||||
$client_id = intval($client_id);
|
||||
$tree = [0 => ['folder_id' => 0, 'folder_name' => '/', 'parent_folder' => -1, 'children' => []]];
|
||||
$sql = mysqli_query($mysqli, "SELECT folder_id, folder_name, parent_folder FROM folders WHERE folder_client_id = $client_id ORDER BY folder_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$tree[intval($row['folder_id'])] = ['folder_id' => intval($row['folder_id']), 'folder_name' => $row['folder_name'], 'parent_folder' => intval($row['parent_folder']), 'children' => []];
|
||||
}
|
||||
foreach ($tree as $folder_id => $folder) {
|
||||
if ($folder_id === 0) {
|
||||
continue;
|
||||
}
|
||||
$parent = isset($tree[$folder['parent_folder']]) && $folder['parent_folder'] !== $folder_id ? $folder['parent_folder'] : 0;
|
||||
$tree[$folder_id]['parent_folder'] = $parent;
|
||||
$tree[$parent]['children'][] = $folder_id;
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/** The folders from the root down to $folder_id, root left out: [[folder_id, folder_name], ...]. */
|
||||
function folderPath($tree, $folder_id) {
|
||||
$path = [];
|
||||
$seen = [];
|
||||
$folder_id = intval($folder_id);
|
||||
while ($folder_id && isset($tree[$folder_id]) && !isset($seen[$folder_id])) {
|
||||
$seen[$folder_id] = true;
|
||||
array_unshift($path, ['folder_id' => $folder_id, 'folder_name' => $tree[$folder_id]['folder_name']]);
|
||||
$folder_id = $tree[$folder_id]['parent_folder'];
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
/** $folder_id and every folder under it. */
|
||||
function folderSubtree($tree, $folder_id) {
|
||||
$ids = [];
|
||||
$stack = [intval($folder_id)];
|
||||
while ($stack) {
|
||||
$id = array_pop($stack);
|
||||
if (!isset($tree[$id]) || isset($ids[$id])) {
|
||||
continue;
|
||||
}
|
||||
$ids[$id] = true;
|
||||
foreach ($tree[$id]['children'] as $child) {
|
||||
$stack[] = $child;
|
||||
}
|
||||
}
|
||||
return array_keys($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* <option>s for a folder picker: the root, then each folder indented under
|
||||
* its parent, with $selected chosen. $exclude leaves out a folder and
|
||||
* everything under it - a folder cannot be moved into itself.
|
||||
*/
|
||||
function folderOptionsHtml($client_id, $selected = 0, $exclude = 0) {
|
||||
$tree = folderTree($client_id);
|
||||
$skip = $exclude ? array_flip(folderSubtree($tree, $exclude)) : [];
|
||||
$selected = intval($selected);
|
||||
$html = '<option value="0"' . ($selected === 0 ? ' selected' : '') . selectOptionData(['icon' => 'fas fa-home']) . '>Top level</option>';
|
||||
$walk = function ($parent_id, $depth) use (&$walk, $tree, $skip, $selected, &$html) {
|
||||
foreach ($tree[$parent_id]['children'] as $folder_id) {
|
||||
if (isset($skip[$folder_id])) {
|
||||
continue;
|
||||
}
|
||||
$path = implode(' / ', array_column(folderPath($tree, $tree[$folder_id]['parent_folder']), 'folder_name'));
|
||||
$html .= '<option value="' . $folder_id . '"' . ($folder_id === $selected ? ' selected' : '')
|
||||
. selectOptionData(['icon' => 'fas fa-folder', 'description' => $path])
|
||||
. '>' . str_repeat(' ', $depth) . escapeHtml($tree[$folder_id]['folder_name']) . '</option>';
|
||||
$walk($folder_id, $depth + 1);
|
||||
}
|
||||
};
|
||||
$walk(0, 0);
|
||||
return $html;
|
||||
}
|
||||
|
||||
/** $folder_id if it is one of the client's folders (0, the top level, always is), otherwise 0. */
|
||||
function folderOwnedId($folder_id, $client_id) {
|
||||
global $mysqli;
|
||||
$folder_id = intval($folder_id);
|
||||
if (!$folder_id) {
|
||||
return 0;
|
||||
}
|
||||
$sql = mysqli_query($mysqli, "SELECT 1 FROM folders WHERE folder_id = $folder_id AND folder_client_id = " . intval($client_id) . " LIMIT 1");
|
||||
return mysqli_num_rows($sql) ? $folder_id : 0;
|
||||
}
|
||||
|
||||
/** A folder's name for messages and logs - "Top level" for the root. Raw. */
|
||||
function folderDisplayName($folder_id) {
|
||||
$folder_id = intval($folder_id);
|
||||
return $folder_id ? (string) getFieldById('folders', $folder_id, 'folder_name') : 'Top level';
|
||||
}
|
||||
|
||||
/*
|
||||
* Deleting for good - shared by the single and bulk delete handlers in
|
||||
* agent/post/file.php and agent/post/document.php. Each checks the agent's
|
||||
* access to the record's client itself, and takes every link with it.
|
||||
*/
|
||||
|
||||
/** Remove a stored file from disk - quietly, when it is already gone. */
|
||||
function fileRemoveFromDisk($client_id, $file_reference_name) {
|
||||
$path = __DIR__ . "/../uploads/clients/" . intval($client_id) . "/" . basename((string) $file_reference_name);
|
||||
if ((string) $file_reference_name !== '' && is_file($path)) {
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
|
||||
/** Delete one file for good: the file on disk, its links and its row. Returns its name, or null if it is not there. */
|
||||
function fileDeleteForGood($file_id) {
|
||||
global $mysqli, $session_name, $client_id;
|
||||
$file_id = intval($file_id);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT file_client_id, file_name, file_reference_name FROM files WHERE file_id = $file_id"));
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
$client_id = intval($row['file_client_id']);
|
||||
enforceClientAccess();
|
||||
fileRemoveFromDisk($client_id, $row['file_reference_name']);
|
||||
linkRemoveAll('file', $file_id);
|
||||
mysqli_query($mysqli, "DELETE FROM files WHERE file_id = $file_id");
|
||||
logAudit("File", "Delete", "$session_name deleted file " . escapeSql($row['file_name']), $client_id);
|
||||
return $row['file_name'];
|
||||
}
|
||||
|
||||
/** Delete one document for good, with its versions, images and links. Returns its name, or null. */
|
||||
function documentDeleteForGood($document_id) {
|
||||
global $mysqli, $session_name, $client_id;
|
||||
$document_id = intval($document_id);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT document_client_id, document_name FROM documents WHERE document_id = $document_id"));
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
$client_id = intval($row['document_client_id']);
|
||||
enforceClientAccess();
|
||||
mysqli_query($mysqli, "DELETE FROM documents WHERE document_id = $document_id");
|
||||
mysqli_query($mysqli, "DELETE FROM document_versions WHERE document_version_document_id = $document_id");
|
||||
linkRemoveAll('document', $document_id);
|
||||
removeDirectory($_SERVER['DOCUMENT_ROOT'] . "/uploads/documents/" . $document_id);
|
||||
logAudit("Document", "Delete", "$session_name deleted document " . escapeSql($row['document_name']) . " and all versions", $client_id);
|
||||
return $row['document_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* What a document's full-text search runs over (document_content_raw): its
|
||||
* name and its text, tags stripped. A space goes in front of every tag first,
|
||||
* so "<li>one</li><li>two</li>" reads "one two", not "onetwo". Raw - escape
|
||||
* it for the query.
|
||||
*/
|
||||
function documentContentRaw($name, $html) {
|
||||
return trim(trim((string) $name) . ' ' . trim(preg_replace('/\s+/u', ' ', strip_tags(str_replace('<', ' <', (string) $html)))));
|
||||
}
|
||||
|
||||
/**
|
||||
* A document's HTML made safe to show - the HTMLPurifier setup the document
|
||||
* page, the document quick look and the version viewer all use.
|
||||
*/
|
||||
function documentHtmlPurify($html) {
|
||||
static $purifier = null;
|
||||
if ($purifier === null) {
|
||||
require_once __DIR__ . '/../libs/htmlpurifier/HTMLPurifier.standalone.php';
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->set('Cache.DefinitionImpl', null);
|
||||
$config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
|
||||
$purifier = new HTMLPurifier($config);
|
||||
}
|
||||
return $purifier->purify((string) $html);
|
||||
}
|
||||
|
||||
331
functions/links.php
Normal file
331
functions/links.php
Normal file
@@ -0,0 +1,331 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Links between documents, files and the things they are about - the assets,
|
||||
* contacts, licenses and vendors a document covers, the files attached to a
|
||||
* document, the assets and contacts a file belongs to.
|
||||
*
|
||||
* Every link is a row in a two-column table (asset_documents, document_files,
|
||||
* contact_files...) and they all work the same way, so they are described once
|
||||
* here and linked, unlinked, listed and offered by the same few functions -
|
||||
* one link modal (agent/modals/link/link.php), one handler
|
||||
* (agent/post/link.php) and one list (linkGroupsHtml()) on the document page
|
||||
* and the file and document quick looks.
|
||||
*
|
||||
* A link only ever joins two records of the same client, and never to an
|
||||
* archived one; linkAdd() checks both rather than trusting the form.
|
||||
*/
|
||||
|
||||
/** The record types a link can join. */
|
||||
const LINK_ENTITIES = [
|
||||
'asset' => ['table' => 'assets', 'id' => 'asset_id', 'name' => 'asset_name', 'client' => 'asset_client_id', 'archived' => 'asset_archived_at', 'label' => 'asset', 'plural' => 'Assets', 'icon' => 'fa-desktop'],
|
||||
'contact' => ['table' => 'contacts', 'id' => 'contact_id', 'name' => 'contact_name', 'client' => 'contact_client_id', 'archived' => 'contact_archived_at', 'label' => 'contact', 'plural' => 'Contacts', 'icon' => 'fa-user'],
|
||||
'document' => ['table' => 'documents', 'id' => 'document_id', 'name' => 'document_name', 'client' => 'document_client_id', 'archived' => 'document_archived_at', 'label' => 'document', 'plural' => 'Documents', 'icon' => 'fa-file-alt'],
|
||||
'file' => ['table' => 'files', 'id' => 'file_id', 'name' => 'file_name', 'client' => 'file_client_id', 'archived' => 'file_archived_at', 'label' => 'file', 'plural' => 'Files', 'icon' => 'fa-paperclip'],
|
||||
'software' => ['table' => 'software', 'id' => 'software_id', 'name' => 'software_name', 'client' => 'software_client_id', 'archived' => 'software_archived_at', 'label' => 'license', 'plural' => 'Licenses', 'icon' => 'fa-cube'],
|
||||
'vendor' => ['table' => 'vendors', 'id' => 'vendor_id', 'name' => 'vendor_name', 'client' => 'vendor_client_id', 'archived' => 'vendor_archived_at', 'label' => 'vendor', 'plural' => 'Vendors', 'icon' => 'fa-building'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Which pairs can be linked, keyed by the two types in alphabetical order, and
|
||||
* the permission it takes. Linking a contact to a file has always been a
|
||||
* contacts permission; everything else is documentation, a support one.
|
||||
*/
|
||||
const LINK_RELATIONS = [
|
||||
'asset|document' => ['table' => 'asset_documents', 'module' => 'module_support'],
|
||||
'contact|document' => ['table' => 'contact_documents', 'module' => 'module_support'],
|
||||
'document|file' => ['table' => 'document_files', 'module' => 'module_support'],
|
||||
'document|software' => ['table' => 'software_documents', 'module' => 'module_support'],
|
||||
'document|vendor' => ['table' => 'vendor_documents', 'module' => 'module_support'],
|
||||
'asset|file' => ['table' => 'asset_files', 'module' => 'module_support'],
|
||||
'contact|file' => ['table' => 'contact_files', 'module' => 'module_client'],
|
||||
];
|
||||
|
||||
/** The relation between two types, or null when they cannot be linked. */
|
||||
function linkRelation($a, $b) {
|
||||
$pair = [(string) $a, (string) $b];
|
||||
sort($pair);
|
||||
return LINK_RELATIONS[implode('|', $pair)] ?? null;
|
||||
}
|
||||
|
||||
/** What a $from record can be linked to, in the order the pages list them. */
|
||||
function linkTypesFor($from) {
|
||||
$order = ['file', 'document', 'asset', 'contact', 'software', 'vendor'];
|
||||
return array_values(array_filter($order, function ($to) use ($from) {
|
||||
return $to !== $from && linkRelation($from, $to);
|
||||
}));
|
||||
}
|
||||
|
||||
/** May this agent change links between these two types? */
|
||||
function linkCanEdit($from, $to) {
|
||||
$relation = linkRelation($from, $to);
|
||||
return $relation && lookupUserPermission($relation['module']) >= 2;
|
||||
}
|
||||
|
||||
/** One record's id, name, client and archived date - or null if it does not exist. */
|
||||
function linkRecord($type, $id) {
|
||||
global $mysqli;
|
||||
$entity = LINK_ENTITIES[$type] ?? null;
|
||||
$id = intval($id);
|
||||
if (!$entity || !$id) {
|
||||
return null;
|
||||
}
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT {$entity['id']} AS id, {$entity['name']} AS name,
|
||||
{$entity['client']} AS client_id, {$entity['archived']} AS archived_at
|
||||
FROM {$entity['table']} WHERE {$entity['id']} = $id LIMIT 1"));
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
/** Extra columns each type brings to a linked row, beyond id and name. */
|
||||
function linkDisplayColumns($type) {
|
||||
return [
|
||||
'asset' => 'asset_type, asset_make, asset_model',
|
||||
'contact' => 'contact_title, contact_photo, contact_client_id',
|
||||
'document' => 'document_description, document_updated_at, document_created_at',
|
||||
'file' => 'file_ext, file_size, file_mime_type, file_description',
|
||||
'software' => 'software_type, software_version',
|
||||
'vendor' => 'vendor_description',
|
||||
][$type] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* The $to records linked to one $from record, ready to draw: each row has id
|
||||
* and name plus linkDisplayColumns(). Archived records are left out - they
|
||||
* come back when they are restored.
|
||||
*/
|
||||
function linkedRecords($from, $id, $to) {
|
||||
global $mysqli;
|
||||
$relation = linkRelation($from, $to);
|
||||
$from_entity = LINK_ENTITIES[$from] ?? null;
|
||||
$to_entity = LINK_ENTITIES[$to] ?? null;
|
||||
if (!$relation || !$from_entity || !$to_entity) {
|
||||
return [];
|
||||
}
|
||||
$id = intval($id);
|
||||
$extra = linkDisplayColumns($to);
|
||||
$sql = mysqli_query($mysqli, "SELECT t.{$to_entity['id']} AS id, t.{$to_entity['name']} AS name" . ($extra ? ", $extra" : '') . "
|
||||
FROM {$relation['table']} l
|
||||
JOIN {$to_entity['table']} t ON t.{$to_entity['id']} = l.{$to_entity['id']}
|
||||
WHERE l.{$from_entity['id']} = $id AND t.{$to_entity['archived']} IS NULL
|
||||
ORDER BY t.{$to_entity['name']} ASC");
|
||||
$rows = [];
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/** The client's $to records not yet linked to this $from record, and not archived. */
|
||||
function linkCandidates($from, $id, $to, $client_id) {
|
||||
global $mysqli;
|
||||
$relation = linkRelation($from, $to);
|
||||
$from_entity = LINK_ENTITIES[$from] ?? null;
|
||||
$to_entity = LINK_ENTITIES[$to] ?? null;
|
||||
if (!$relation || !$from_entity || !$to_entity) {
|
||||
return [];
|
||||
}
|
||||
$id = intval($id);
|
||||
$client_id = intval($client_id);
|
||||
$extra = linkDisplayColumns($to);
|
||||
// Files show their folder, so two files with the same name can be told apart
|
||||
$folder_join = $to === 'file' ? 'LEFT JOIN folders ON folder_id = t.file_folder_id' : '';
|
||||
$folder_column = $to === 'file' ? ', folder_name' : '';
|
||||
$sql = mysqli_query($mysqli, "SELECT t.{$to_entity['id']} AS id, t.{$to_entity['name']} AS name" . ($extra ? ", $extra" : '') . "$folder_column
|
||||
FROM {$to_entity['table']} t
|
||||
$folder_join
|
||||
LEFT JOIN {$relation['table']} l ON l.{$to_entity['id']} = t.{$to_entity['id']} AND l.{$from_entity['id']} = $id
|
||||
WHERE t.{$to_entity['client']} = $client_id AND t.{$to_entity['archived']} IS NULL AND l.{$to_entity['id']} IS NULL
|
||||
ORDER BY t.{$to_entity['name']} ASC");
|
||||
$rows = [];
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/** How many $to records each type has linked to this $from record - for tab and section counts. */
|
||||
function linkCounts($from, $id) {
|
||||
$counts = [];
|
||||
foreach (linkTypesFor($from) as $to) {
|
||||
$counts[$to] = count(linkedRecords($from, $id, $to));
|
||||
}
|
||||
return $counts;
|
||||
}
|
||||
|
||||
/** The audit log entry a link change is filed under - the document or file side of it. */
|
||||
function linkLogSide($from, $id, $to, $other_id) {
|
||||
foreach (['document', 'file'] as $side) {
|
||||
if ($from === $side) {
|
||||
return [ucfirst($side), $id];
|
||||
}
|
||||
if ($to === $side) {
|
||||
return [ucfirst($side), $other_id];
|
||||
}
|
||||
}
|
||||
return [ucfirst($from), $id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Link $ids ($to records) to one $from record. Only records of the same
|
||||
* client that are not archived are linked; anything else in $ids is skipped,
|
||||
* as is anything already linked. The caller has checked the permission and
|
||||
* the client access of $from. Returns the names that were linked.
|
||||
*/
|
||||
function linkAdd($from, $id, $to, $ids) {
|
||||
global $mysqli, $session_name;
|
||||
$relation = linkRelation($from, $to);
|
||||
$source = linkRecord($from, $id);
|
||||
if (!$relation || !$source) {
|
||||
return [];
|
||||
}
|
||||
$from_entity = LINK_ENTITIES[$from];
|
||||
$to_entity = LINK_ENTITIES[$to];
|
||||
$client_id = intval($source['client_id']);
|
||||
$added = [];
|
||||
foreach (array_unique(array_map('intval', (array) $ids)) as $other_id) {
|
||||
$other = linkRecord($to, $other_id);
|
||||
if (!$other || intval($other['client_id']) !== $client_id || $other['archived_at'] !== null) {
|
||||
continue;
|
||||
}
|
||||
// The pair is the table's primary key, so a second link of the same two is a no-op rather than an error
|
||||
mysqli_query($mysqli, "INSERT IGNORE INTO {$relation['table']} SET {$from_entity['id']} = " . intval($source['id']) . ", {$to_entity['id']} = $other_id");
|
||||
if (mysqli_affected_rows($mysqli) < 1) {
|
||||
continue;
|
||||
}
|
||||
$added[] = $other['name'];
|
||||
[$log_type, $log_id] = linkLogSide($from, intval($source['id']), $to, $other_id);
|
||||
$log_from = $log_type === ucfirst($from) ? $source['name'] : $other['name'];
|
||||
$log_other = $log_type === ucfirst($from) ? $other['name'] : $source['name'];
|
||||
$log_other_label = $log_type === ucfirst($from) ? $to_entity['label'] : $from_entity['label'];
|
||||
logAudit($log_type, "Link", "$session_name linked $log_other_label " . escapeSql($log_other) . " to " . strtolower($log_type) . " " . escapeSql($log_from), $client_id, $log_id);
|
||||
}
|
||||
return $added;
|
||||
}
|
||||
|
||||
/** Unlink one $to record from a $from record. Returns its name, or '' if there was no such link. */
|
||||
function linkRemove($from, $id, $to, $other_id) {
|
||||
global $mysqli, $session_name;
|
||||
$relation = linkRelation($from, $to);
|
||||
$source = linkRecord($from, $id);
|
||||
$other = linkRecord($to, $other_id);
|
||||
if (!$relation || !$source || !$other) {
|
||||
return '';
|
||||
}
|
||||
$from_entity = LINK_ENTITIES[$from];
|
||||
$to_entity = LINK_ENTITIES[$to];
|
||||
mysqli_query($mysqli, "DELETE FROM {$relation['table']} WHERE {$from_entity['id']} = " . intval($source['id']) . " AND {$to_entity['id']} = " . intval($other['id']));
|
||||
if (mysqli_affected_rows($mysqli) < 1) {
|
||||
return '';
|
||||
}
|
||||
[$log_type, $log_id] = linkLogSide($from, intval($source['id']), $to, intval($other['id']));
|
||||
$log_from = $log_type === ucfirst($from) ? $source['name'] : $other['name'];
|
||||
$log_other = $log_type === ucfirst($from) ? $other['name'] : $source['name'];
|
||||
$log_other_label = $log_type === ucfirst($from) ? $to_entity['label'] : $from_entity['label'];
|
||||
logAudit($log_type, "Unlink", "$session_name unlinked $log_other_label " . escapeSql($log_other) . " from " . strtolower($log_type) . " " . escapeSql($log_from), intval($source['client_id']), $log_id);
|
||||
return $other['name'];
|
||||
}
|
||||
|
||||
/** Drop every link a record has - for when it is deleted for good. */
|
||||
function linkRemoveAll($type, $id) {
|
||||
global $mysqli;
|
||||
$entity = LINK_ENTITIES[$type] ?? null;
|
||||
if (!$entity) {
|
||||
return;
|
||||
}
|
||||
$id = intval($id);
|
||||
foreach (LINK_RELATIONS as $pair => $relation) {
|
||||
if (in_array($type, explode('|', $pair), true)) {
|
||||
mysqli_query($mysqli, "DELETE FROM {$relation['table']} WHERE {$entity['id']} = $id");
|
||||
}
|
||||
}
|
||||
if ($type === 'document') {
|
||||
mysqli_query($mysqli, "DELETE FROM service_documents WHERE document_id = $id");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* How one linked record is drawn: its icon or avatar, its name linked to where
|
||||
* it opens, and a quieter detail. Raw row in, HTML out.
|
||||
*/
|
||||
function linkRowHtml($to, $row, $client_id) {
|
||||
$id = intval($row['id']);
|
||||
$name = escapeHtml($row['name']);
|
||||
switch ($to) {
|
||||
case 'asset':
|
||||
$lead = '<span class="itflow-asset-icon itflow-asset-icon-sm itflow-asset-tone-' . assetTypeTone($row['asset_type']) . '" aria-hidden="true"><i class="fas fa-fw fa-' . getAssetIcon($row['asset_type']) . '"></i></span>';
|
||||
$link = "<a class=\"ajax-modal text-truncate\" href=\"#\" data-modal-size=\"lg\" data-modal-url=\"modals/asset/asset.php?id=$id\">$name</a>";
|
||||
$detail = trim($row['asset_make'] . ' ' . $row['asset_model']);
|
||||
break;
|
||||
case 'contact':
|
||||
$lead = contactAvatar($row['contact_client_id'], $id, $row['name'], $row['contact_photo'], 'sm');
|
||||
$link = "<a class=\"ajax-modal text-truncate\" href=\"#\" data-modal-size=\"lg\" data-modal-url=\"modals/contact/contact.php?id=$id\">$name</a>";
|
||||
$detail = $row['contact_title'];
|
||||
break;
|
||||
case 'file':
|
||||
$lead = fileTypeTile($row['file_ext'], 'sm');
|
||||
$link = "<a class=\"ajax-modal text-truncate\" href=\"#\" data-modal-size=\"lg\" data-modal-url=\"modals/file/file.php?id=$id\">$name</a>";
|
||||
$detail = fileTypeInfo($row['file_ext'])['label'] . ($row['file_size'] ? ' · ' . formatBytes(intval($row['file_size'])) : '');
|
||||
break;
|
||||
case 'document':
|
||||
$lead = documentTile('sm');
|
||||
$link = "<a class=\"text-truncate\" href=\"document.php?client_id=" . intval($client_id) . "&document_id=$id\">$name</a>";
|
||||
$detail = 'Updated ' . timeAgo($row['document_updated_at'] ?: $row['document_created_at']);
|
||||
break;
|
||||
case 'software':
|
||||
$lead = '<span class="itflow-link-icon" aria-hidden="true"><i class="fas fa-fw fa-cube"></i></span>';
|
||||
$link = "<a class=\"ajax-modal text-truncate\" href=\"#\" data-modal-url=\"modals/software/software_edit.php?id=$id\">$name</a>";
|
||||
$detail = trim($row['software_type'] . ' ' . $row['software_version']);
|
||||
break;
|
||||
case 'vendor':
|
||||
$lead = '<span class="itflow-link-icon" aria-hidden="true"><i class="fas fa-fw fa-building"></i></span>';
|
||||
$link = "<a class=\"ajax-modal text-truncate\" href=\"#\" data-modal-url=\"modals/vendor/vendor.php?id=$id\">$name</a>";
|
||||
$detail = $row['vendor_description'];
|
||||
break;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
$detail = (string) $detail !== '' ? '<div class="small text-body-secondary text-truncate">' . escapeHtml($detail) . '</div>' : '';
|
||||
return "$lead<div class=\"min-w-0 flex-grow-1\"><div class=\"d-flex\">$link</div>$detail</div>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Everything linked to one document or file, grouped by type - the "Linked"
|
||||
* card on the document page and the section in the file and document quick
|
||||
* looks. Each group has its count and, for an agent who may change it, a
|
||||
* Link button and an unlink button on each row (shown on hover, like the copy
|
||||
* buttons). Empty groups collapse to a single "Link a ..." line, so the card
|
||||
* says what can be linked without a wall of empty headings.
|
||||
*/
|
||||
function linkGroupsHtml($from, $id, $client_id, $archived = false) {
|
||||
$id = intval($id);
|
||||
$groups = '';
|
||||
$empty = [];
|
||||
foreach (linkTypesFor($from) as $to) {
|
||||
$entity = LINK_ENTITIES[$to];
|
||||
$rows = linkedRecords($from, $id, $to);
|
||||
$can_edit = !$archived && linkCanEdit($from, $to);
|
||||
$link_url = "modals/link/link.php?from=$from&id=$id&to=$to";
|
||||
if (!$rows) {
|
||||
if ($can_edit) {
|
||||
$empty[] = "<a class=\"ajax-modal btn btn-xs btn-outline-secondary\" href=\"#\" data-modal-url=\"$link_url\"><i class=\"fas {$entity['icon']} me-1\"></i>{$entity['plural']}</a>";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$items = '';
|
||||
foreach ($rows as $row) {
|
||||
$unlink = $can_edit
|
||||
? '<a class="itflow-link-remove confirm-link" href="post.php?unlink_item&from=' . $from . '&id=' . $id . '&to=' . $to . '&other=' . intval($row['id']) . '&csrf_token=' . escapeHtml($_SESSION['csrf_token'] ?? '') . '" title="Unlink ' . $entity['label'] . '"><i class="fas fa-unlink"></i></a>'
|
||||
: '';
|
||||
$items .= '<li class="itflow-link-row">' . linkRowHtml($to, $row, $client_id) . $unlink . '</li>';
|
||||
}
|
||||
$add = $can_edit ? "<a class=\"ajax-modal ms-auto small\" href=\"#\" data-modal-url=\"$link_url\" title=\"Link {$entity['label']}\"><i class=\"fas fa-plus me-1\"></i>Link</a>" : '';
|
||||
$groups .= "<div class=\"itflow-link-group\"><div class=\"itflow-link-group-head\"><i class=\"fas fa-fw {$entity['icon']} me-1\"></i>{$entity['plural']}<span class=\"badge rounded-pill ms-1\">" . count($rows) . "</span>$add</div><ul class=\"list-unstyled mb-0\">$items</ul></div>";
|
||||
}
|
||||
if ($empty) {
|
||||
$groups .= '<div class="itflow-link-empty"><span class="small text-body-secondary me-1">Link</span>' . implode(' ', $empty) . '</div>';
|
||||
}
|
||||
if ($groups === '') {
|
||||
$groups = '<div class="small text-body-secondary">Nothing linked.</div>';
|
||||
}
|
||||
return "<div class=\"itflow-links\">$groups</div>";
|
||||
}
|
||||
Reference in New Issue
Block a user