diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f8729f8d..d6aafc726 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -156,6 +156,14 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Tickets: rest the pointer on a ticket's Activity on the tickets list to see its last reply - who, when and what it said. - The browser tab shows how many open tickets are assigned to you, such as "(3) Real MSP - Tickets", on every page - kept up to date in the background, so you see it from another tab. - Desktop notifications: Turn on desktop notifications, at the bottom of the bell's panel, and a ticket assigned to you or a client's reply on one of yours shows as a notification on your computer while you're away from ITFlow. Each browser has its own switch, and asks your permission first. +- Documents: Edit opens a document on a page of its own, with the editor filling the window and its toolbar always in view - long documents no longer squeeze into a window over the page. +- Documents: Copy, in a document's menu, copies it for the same client or another - content, summary, tags and pictures, out of the client portal and linked to nothing. +- Documents: a document with three headings or more has a Contents list beside it, to jump to a section - Knowledge Base articles too. +- Documents: the arrows beside each version, and beside Now, show what that edit changed - lines taken out and put in, the changed words marked, the rest folded away. +- Documents: Favorite, in a document's menu, puts it on the client's overview under Favorites, with their favorite assets, licenses and logins. A star marks it on its page and in Files. +- Files: Choose a folder in the Upload window - or drop a folder on it, or on Files - uploads the folder with the folders inside it, made as needed. A folder goes up 20 files at a time, up to 1,000 files and 2 GB. +- Files: Download as zip, beside the folder's path, downloads the folder and everything under it - at the top level, all of the client's files. Bulk Action > Download as zip does the same for the ones ticked. Documents go in as web pages. +- Files: rename a file or document from the list - the pencil beside its name - and press Enter. - Modules: Admin > Settings > Modules has five more switches, to take out of ITFlow what your business doesn't use - Dispatch, which comes with Ticketing; Bookkeeping, Purchasing and Trips, which come with invoicing; and the Calendar. Each part is off while the one it comes with is, and shows faded under it. Switched off, a part leaves the menus, the dashboard, search, the reports and the API, and its pages and windows say it is off. Nothing in it is deleted - switched back on, it is all there. Dispatch, Bookkeeping, Trips and the Calendar start on, as before. - Bookkeeping: switch it off when your books are kept somewhere else. Accounts, Transactions, Transfers, Reconcile and the statement imports go, and nobody picks an account: payments and income go into the default payment account, and expenses come out of the default expense account - both in Admin > Settings > Defaults, or the first account when there's no default. An expense is paid by The business or Paid personally. The dashboard leaves out the account balances, and the Tax Package its Accounts section. - Calendar: switched off, the calendar, its events and the calendar feeds go - a subscribed calendar stops getting them. Tickets are still booked from the ticket and on Dispatch, and booked work still shows on the dashboard. @@ -337,6 +345,9 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Tickets: database 4.0.2 adds `ticket_reads` (ticket, agent, `read_at`; ticket 0 is the agent's starting point, made by `ticketReadsSince()` the first time their list loads). `functions/ticket_read.php` has `ticketReadsReady()`, `ticketMarkRead()` (from `agent/ticket.php`, the quick look and the new `bulk_mark_tickets_read`), `ticketUnreadSql()` - a Client reply, or a ticket raised by Email, Portal or Text, newer than the agent's read or starting point, on a ticket not closed, selected as `ticket_unread` on the list view - and `ticketReadsCleanup()`, run nightly for closed or deleted tickets and archived agents. On the list, open subjects that have been read are no longer semibold; unread ones are bold. - Tickets: list rows carry `data-ticket-id` and `data-ticket-sig`, a hash of what the row shows. `agent/js/tickets_live.js` fetches the same address once a minute while the tab is visible, swaps in rows whose signature changed (not ticked, no menu open), marks rows no longer there `itflow-row-gone`, counts new ones in `[data-tickets-live-bar]` and copies the pills' counts. `agent/js/ticket_reply_peek.js` shows `agent/ajax.php?ticket_reply_peek` - the last reply, or the details when there is none, as `emailPlainText()` - in a Bootstrap popover over `[data-reply-peek]`. - `js/ticket_pulse.js` (every agent page, for Support) asks `agent/ajax.php?ticket_pulse` once a minute per browser - localStorage keeps the answer and a lock, and other tabs pick it up from the `storage` event - and puts the count of open tickets assigned to the agent (`TICKET_OPEN_SQL` and `ticketAssignedSql()`, as the Mine view) in front of `document.title`. With desktop notifications on (localStorage, per agent and browser, switched from `[data-desktop-notify]` in the bell's panel) it also asks for the assigned tickets not closed and Client replies on them after the last `reply_max`, works out newly assigned ones against the last answer, asks `about=` for up to five, and shows a `Notification` for each - not while an ITFlow tab has had the focus in the last 10 seconds, nor after a gap of more than 10 minutes. +- Documents: `agent/document_edit.php` is Edit on a page, posting `edit_document` as the window did, with `document_form.php`'s editor as `.tinymce-page` - a second TinyMCE set-up in `js/app.js` sharing the document editor's options (`itflowDocumentEditor`), without autoresize and sized to the window on init and resize. The document page, Files' menus and "Start writing" link to it; other places still open `document_edit.php` the window. `copy_document` (`agent/modals/document/document_copy.php`) uses new `documentCopy()` in `functions/files.php`, which copies `uploads/documents/` and rewrites the content's paths to the copy's, as `kbArticleFromDocument()` does. `toggle_document_favorite` sets the existing, unused `document_favorite`, which `clientOverviewFavorites()` now lists as `documents`. +- Documents: new `functions/text_diff.php` - `textDiffLines()` (HTML to lines through `emailPlainText()`, pictures as `[Picture]`, table cells joined with |), `textDiffOps()` (longest common subsequence after matching the shared start and end, capped at 250,000 cells), `textDiffWordsHtml()` and `textDiffHtml()`, which pairs taken-out and put-in lines that `similar_text()` puts at 50% or more and folds unchanged lines more than two from a change. Shown by `agent/modals/document/document_changes.php` (`document_id`, and `version_id` or none for the last edit). `js/document_contents.js` builds `[data-document-contents]` from the `h1`-`h4` in `.itflow-document-body` when there are three or more, giving each an id. +- Files: `upload_files` takes `file_paths[]`, each file's path under the folder chosen, and `folderForUploadPath()` finds or makes its folders (matching names case-insensitively, ten levels at most); with `upload_json` it answers `{uploaded, skipped, folders}` instead of a flash, and `upload_folder_done` makes the flash from the totals. `file_upload.php` sends a folder (`webkitdirectory`, or dropped entries walked with `webkitGetAsEntry`) 20 files or 100 MB at a time, leaving out `.DS_Store`, `Thumbs.db`, `desktop.ini` and hidden folders; `agent/js/files.js` hands it dropped folders through `input.itflowWalk` and `input.itflowTakeFolder`. `download_folder_zip` (GET) and `bulk_download_files` build a `ZipArchive` in the temp folder with `filesZipSend()` and `filesZipFolderItems()` - files by their stored name, documents as purified HTML pages, names made safe and numbered when they clash, 2 GB at most. `files_rename` in `agent/ajax.php` renames from the list. ## [26.11.8] diff --git a/agent/ajax.php b/agent/ajax.php index e3ff064b1..430311ad5 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -866,6 +866,44 @@ if (isset($_GET['ticket_query_views'])) { echo json_encode($response); } +/* + * Rename a file or a document from its name on the files list (agent/js/files.js) - the name only; + * the Rename window still changes the description. Answers {ok, name} or {error}. + */ +if (isset($_POST['files_rename'])) { + validateCSRFToken(); + header('Content-Type: application/json'); + + if (lookupUserPermission('module_support') < 2) { + echo json_encode(['error' => "You can't rename files."]); + exit; + } + $kind = $_POST['kind'] ?? ''; + $id = intval($_POST['id'] ?? 0); + $new_name = trim((string) ($_POST['name'] ?? '')); + $table = ['file' => 'files', 'document' => 'documents'][$kind] ?? ''; + if ($table === '' || $new_name === '') { + echo json_encode(['error' => $new_name === '' ? 'It needs a name.' : 'Nothing to rename.']); + exit; + } + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT {$kind}_name AS name, {$kind}_client_id AS client_id, {$kind}_archived_at AS archived_at FROM $table WHERE {$kind}_id = $id")); + if (!$row || !hasClientAccess($row['client_id']) || $row['archived_at'] !== null) { + echo json_encode(['error' => 'That is no longer here to rename.']); + exit; + } + $new_name = mb_substr($new_name, 0, 200); + $name_sql = escapeSql($new_name); + if ($kind === 'file') { + mysqli_query($mysqli, "UPDATE files SET file_name = '$name_sql' WHERE file_id = $id"); + logAudit("File", "Rename", "$session_name renamed file " . escapeSql($row['name']) . " to $name_sql", intval($row['client_id']), $id); + } else { + mysqli_query($mysqli, "UPDATE documents SET document_name = '$name_sql', document_updated_at = document_updated_at WHERE document_id = $id"); + logAudit("Document", "Edit", "$session_name renamed document " . escapeSql($row['name']) . " to $name_sql", intval($row['client_id']), $id); + } + echo json_encode(['ok' => true, 'name' => $new_name]); + exit; +} + /* * The last reply on a ticket, as text - shown when the Activity cell on the tickets list is * hovered (agent/js/ticket_reply_peek.js). With no replies yet, what the ticket says. diff --git a/agent/client_overview.php b/agent/client_overview.php index 7c4fdd412..634cec241 100644 --- a/agent/client_overview.php +++ b/agent/client_overview.php @@ -255,7 +255,7 @@ $money_format = function ($amount) use ($currency_format, $client_currency_code, - +
@@ -263,6 +263,17 @@ $money_format = function ($amount) use ($currency_format, $client_currency_code,
+ +
+ + + + + + + +
+
diff --git a/agent/document.php b/agent/document.php index 298fbef23..a0186cb09 100644 --- a/agent/document.php +++ b/agent/document.php @@ -19,7 +19,7 @@ require_once "includes/inc_all_client.php"; $document_id = intval($_GET['document_id'] ?? 0); -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT document_archived_at, document_client_visible, document_content, document_created_at, +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT document_archived_at, document_client_visible, document_favorite, document_content, document_created_at, document_description, document_folder_id, document_name, document_updated_at, document_reviewed_at, document_template_id, document_template_name, document_template_review_months, document_template_archived_at, " . (documentReviewOwnReady() ? 'document_review_months' : 'NULL AS document_review_months') . ", creator.user_name AS created_by_name, updater.user_name AS updated_by_name, reviewer.user_name AS reviewed_by_name @@ -88,6 +88,7 @@ $page_title = $row['document_name'];

+ Archived Portal Review due @@ -109,9 +110,9 @@ $page_title = $row['document_name'];

- +
"; + require_once "../includes/footer.php"; + exit(); +} + +$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']); + +$folder_tree = folderTree($client_id); +$folder_path = folderPath($folder_tree, isset($folder_tree[$document_folder_id]) ? $document_folder_id : 0); + +// Tab title - used raw, the header escapes it +$page_title = 'Editing ' . $row['document_name']; + +?> + + + +
+ + + +
+
+

Editing

+ + Cancel +
+
+ +
+
+
+ + + +
'; - $html .= "Edit"; + $html .= "Edit"; $html .= "Rename"; + $html .= "Copy"; + $favorite = !empty($item['row']['document_favorite']); + $html .= "" . ($favorite ? 'Unfavorite' : 'Favorite') . ""; $html .= "Move"; $html .= "Link"; } @@ -440,6 +443,9 @@ $preview = []; // the grid's previewer payload Tags +
@@ -559,6 +570,7 @@ $preview = []; // the grid's previewer payload
+ @@ -626,7 +638,7 @@ $preview = []; // the grid's previewer payload
- + @@ -694,7 +706,8 @@ $preview = []; // the grid's previewer payload
- + + Portal @@ -702,7 +715,11 @@ $preview = []; // the grid's previewer payload Review due - + + + + + Shared diff --git a/agent/js/files.js b/agent/js/files.js index 8e097cacb..30159be89 100644 --- a/agent/js/files.js +++ b/agent/js/files.js @@ -1,7 +1,7 @@ /* * agent/files.php - the folder tree, the grid's previewer, dragging files, - * documents and folders onto a folder to move them, and dropping files from - * the computer to upload them. + * documents and folders onto a folder to move them, dropping files and folders + * from the computer to upload them, and renaming from the name on the list. */ (function () { 'use strict'; @@ -9,8 +9,16 @@ // What is being dragged within the page - files and documents, or a folder - while it is var dragging = null; - /** Open the upload window at url, and hand it the dropped files once it is on screen. */ - function uploadInto(url, files) { + /** The folders dropped, as entries to walk - read during the drop, while they can be - or null when it was only files. */ + function droppedFolders(e) { + var entries = Array.prototype.map.call((e.dataTransfer && e.dataTransfer.items) || [], function (item) { + return item.webkitGetAsEntry ? item.webkitGetAsEntry() : null; + }).filter(Boolean); + return entries.some(function (entry) { return entry.isDirectory; }) ? entries : null; + } + + /** Open the upload window at url, and hand it the dropped files - or folders, which it walks - once it is on screen. */ + function uploadInto(url, files, folders) { var trigger = document.createElement('a'); trigger.className = 'ajax-modal d-none'; trigger.href = '#'; @@ -21,7 +29,11 @@ var tries = 0; (function handOver() { var input = document.querySelector('.modal.show [data-upload-input]'); - if (input) { + if (input && folders && input.itflowWalk) { + Promise.all(folders.map(function (entry) { return input.itflowWalk(entry, ''); })).then(function (lists) { + input.itflowTakeFolder([].concat.apply([], lists)); + }); + } else if (input && !folders) { var transfer = new DataTransfer(); Array.prototype.forEach.call(files, function (file) { transfer.items.add(file); @@ -402,8 +414,9 @@ if (!dragging) { light(null); spring(null); - if (e.dataTransfer.files.length) { - uploadInto(mover.dataset.filesUpload + to, e.dataTransfer.files); + var folders = droppedFolders(e); + if (folders || e.dataTransfer.files.length) { + uploadInto(mover.dataset.filesUpload + to, e.dataTransfer.files, folders); } return; } @@ -466,8 +479,109 @@ e.preventDefault(); depth = 0; overlay.hidden = true; - if (e.dataTransfer.files.length) { - uploadInto(main.dataset.filesDrop, e.dataTransfer.files); + var folders = droppedFolders(e); + if (folders || e.dataTransfer.files.length) { + uploadInto(main.dataset.filesDrop, e.dataTransfer.files, folders); } }); })(); + +// ---- Rename a file or document from its name on the list (agent/ajax.php files_rename) ---- +(function () { + 'use strict'; + + document.addEventListener('click', function (e) { + var button = e.target.closest('[data-files-rename]'); + if (!button) { + return; + } + e.preventDefault(); + var cell = button.closest('td'); + var link = cell && cell.querySelector('[data-files-name]'); + if (!link || cell.querySelector('.itflow-files-rename-box')) { + return; + } + var row = cell.closest('tr'); + var wasDraggable = row && row.draggable; + var box = document.createElement('input'); + box.type = 'text'; + box.maxLength = 200; + box.className = 'form-control form-control-sm itflow-above-stretch itflow-files-rename-box'; + box.value = link.textContent; + box.setAttribute('aria-label', 'New name'); + link.hidden = true; + button.hidden = true; + if (row) { + row.draggable = false; // so dragging in the box selects text + } + link.after(box); + box.focus(); + // A file's name without its extension, ready to type over + var dot = button.dataset.filesRename === 'file' ? box.value.lastIndexOf('.') : -1; + box.setSelectionRange(0, dot > 0 ? dot : box.value.length); + + var finished = false; + function put(back) { + box.remove(); + link.hidden = false; + button.hidden = false; + if (row) { + row.draggable = wasDraggable; + } + if (back) { + button.focus(); + } + } + function finish(save) { + if (finished) { + return; + } + finished = true; + var name = box.value.trim(); + if (!save || name === '' || name === link.textContent) { + put(!save); + return; + } + box.disabled = true; + var body = new FormData(); + body.append('files_rename', '1'); + body.append('kind', button.dataset.filesRename); + body.append('id', button.dataset.id); + body.append('name', name); + body.append('csrf_token', button.dataset.csrf); + fetch('/agent/ajax.php', { method: 'POST', body: body, credentials: 'same-origin' }) + .then(function (r) { return r.json(); }) + .then(function (answer) { + if (answer.ok) { + link.textContent = answer.name; + if (row && row.dataset.name !== undefined) { + row.dataset.name = answer.name; + } + } else if (typeof itflowToast === 'function') { + itflowToast(answer.error || 'Couldn’t rename it', 'danger'); + } + }) + .catch(function () { + if (typeof itflowToast === 'function') { + itflowToast('Couldn’t rename it', 'danger'); + } + }) + .finally(function () { + put(false); + }); + } + box.addEventListener('keydown', function (ev) { + if (ev.key === 'Enter') { + ev.preventDefault(); + finish(true); + } else if (ev.key === 'Escape') { + ev.preventDefault(); + ev.stopPropagation(); + finish(false); + } + }); + box.addEventListener('blur', function () { + finish(true); + }); + }); +})(); diff --git a/agent/kb_article.php b/agent/kb_article.php index 700662f70..09f8e6fe9 100644 --- a/agent/kb_article.php +++ b/agent/kb_article.php @@ -203,6 +203,14 @@ $page_title = $row['kb_article_title'];
+ + +
@@ -395,6 +403,7 @@ $page_title = $row['kb_article_title'];
+ 'That document no longer exists.']); + exit; +} +$client_id = intval($document['document_client_id']); +enforceClientAccess(); + +$version_sql = "SELECT document_version_id AS id, document_version_name AS name, document_version_content AS content, document_version_created_at AS at, user_name + FROM document_versions LEFT JOIN users ON document_version_created_by = user_id + WHERE document_version_document_id = $document_id"; + +if ($version_id) { + $after = mysqli_fetch_assoc(mysqli_query($mysqli, "$version_sql AND document_version_id = $version_id LIMIT 1")); + if (!$after) { + echo json_encode(['error' => 'That version no longer exists.']); + exit; + } + $at = escapeSql($after['at']); + $before = mysqli_fetch_assoc(mysqli_query($mysqli, "$version_sql AND (document_version_created_at < '$at' OR (document_version_created_at = '$at' AND document_version_id < $version_id)) + ORDER BY document_version_created_at DESC, document_version_id DESC LIMIT 1")); +} else { + $after = ['id' => 0, 'name' => $document['document_name'], 'content' => $document['document_content'], + 'at' => $document['document_updated_at'] ?: $document['document_created_at'], 'user_name' => $document['user_name']]; + $before = mysqli_fetch_assoc(mysqli_query($mysqli, "$version_sql ORDER BY document_version_created_at DESC, document_version_id DESC LIMIT 1")); +} + +$changes = $before ? textDiffHtml($before['content'], $after['content']) : ''; + +ob_start(); + +?> + + + + + + + + 'That document no longer exists.']); + exit; +} +$client_id = intval($row['document_client_id']); +enforceClientAccess(); + +ob_start(); + +?> + + + + + + + + + + + +