* JavaScript for FileArchiv Document Browser */ if (!defined('NOTOKENRENEWAL')) { define('NOTOKENRENEWAL', '1'); } if (!defined('NOLOGIN')) { define('NOLOGIN', '1'); } if (!defined('NOCSRFCHECK')) { define('NOCSRFCHECK', '1'); } // Load Dolibarr environment for translations $res = 0; if (!$res && file_exists("../../main.inc.php")) { $res = @include "../../main.inc.php"; } if (!$res && file_exists("../../../main.inc.php")) { $res = @include "../../../main.inc.php"; } if (!$res && file_exists("../../../../main.inc.php")) { $res = @include "../../../../main.inc.php"; } header('Content-Type: application/javascript; charset=UTF-8'); // Load translations $langs->load('filearchiv@filearchiv'); $ajaxUrl = dol_buildpath('/filearchiv/ajax/getdocuments.php', 1); $addFileUrl = dol_buildpath('/filearchiv/ajax/addfile.php', 1); ?> /** * FileArchiv Document Browser * Injects document browser into email presend forms */ (function() { 'use strict'; // Only run on presend pages if (window.location.href.indexOf('action=presend') === -1) { return; } // Configuration var config = { ajaxUrl: '', addFileUrl: '', token: '', element: '', id: 0, trackid: '', translations: { browseDocuments: 'trans("BrowseRelatedDocuments")); ?>', selectDocuments: 'trans("SelectDocumentsToAttach")); ?>', loading: 'trans("Loading")); ?>', noDocuments: 'trans("NoRelatedDocumentsFound")); ?>', errorLoading: 'trans("ErrorLoadingDocuments")); ?>', filesSelected: 'trans("FilesSelected")); ?>', cancel: 'trans("Cancel")); ?>', addSelected: 'trans("AddSelectedFiles")); ?>', adding: 'trans("Adding")); ?>', errorAdding: 'trans("ErrorAddingFiles")); ?>' } }; // Detect element type and ID from URL function detectContext() { var url = window.location.href; var params = new URLSearchParams(window.location.search); config.id = parseInt(params.get('id')) || 0; config.token = typeof token !== 'undefined' ? token : ''; // Detect element type from URL path if (url.indexOf('/comm/propal/') !== -1) { config.element = 'propal'; } else if (url.indexOf('/commande/') !== -1) { config.element = 'commande'; } else if (url.indexOf('/compta/facture/') !== -1) { config.element = 'facture'; } else if (url.indexOf('/expedition/') !== -1) { config.element = 'expedition'; } else if (url.indexOf('/fourn/commande/') !== -1) { config.element = 'order_supplier'; } else if (url.indexOf('/fourn/facture/') !== -1) { config.element = 'invoice_supplier'; } // Get trackid from form var trackidInput = document.querySelector('input[name="trackid"]'); if (trackidInput) { config.trackid = trackidInput.value; } // Get token from form var tokenInput = document.querySelector('input[name="token"]'); if (tokenInput) { config.token = tokenInput.value; } } // Create and inject the document browser UI function injectDocumentBrowser() { // Find the mail form var mailForm = document.getElementById('mailform'); if (!mailForm) { mailForm = document.querySelector('form[name="mailform"]'); } if (!mailForm) { return; } // Find attachment section (look for file input or attachment table) var attachSection = mailForm.querySelector('input[name="addedfile"]'); if (!attachSection) { attachSection = mailForm.querySelector('.linked-medias'); } if (!attachSection) { // Try to find any file-related section attachSection = mailForm.querySelector('table.liste'); } // Create button container var buttonHtml = '