Files
itflow/agent/modals/document/document_add_from_template.php
johnnyq 1a613eab7b 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
2026-10-14 20:35:41 -04:00

99 lines
4.2 KiB
PHP

<?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();
$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="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">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="client_id" value="<?= $client_id ?>">
<div class="modal-body">
<?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 &rsaquo; Document Templates</a>
<?php } ?>
</div>
<?php } else { ?>
<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 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 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 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">
<?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>
<?php
require_once '../../../includes/modal_footer.php';