diff --git a/index.cfm b/index.cfm
index fd14637..3c562bd 100644
--- a/index.cfm
+++ b/index.cfm
@@ -64,7 +64,7 @@

-
Сверка договоров v1.0.34 — Lucee
+
Сверка договоров v1.0.35 — Lucee
@@ -221,7 +221,7 @@ fileInput.addEventListener('change', function() {
renderTable();
});
-// ── Загрузка через iframe (отдельный контекст на каждый файл) ─
+// ── Загрузка через iframe (base64 в скрытом поле) ────────
uploadBtn.addEventListener('click', function() {
if (fileQueue.length === 0) return;
uploadBtn.disabled = true;
@@ -231,7 +231,7 @@ uploadBtn.addEventListener('click', function() {
var pending = fileQueue.filter(function(f) { return !f.doc_id; });
var done = 0;
- function uploadNext(i) {
+ function readThenUpload(i) {
if (i >= pending.length) {
uploadTimer.style.display = 'none';
uploadBtn.disabled = false;
@@ -242,18 +242,34 @@ uploadBtn.addEventListener('click', function() {
return;
}
var f = pending[i];
- f.status = '0%';
+ f.status = 'читаю...';
renderTable();
- uploadTimer.textContent = 'Загрузка ' + (i+1) + '/' + pending.length;
+ uploadTimer.textContent = 'Чтение ' + (i+1) + '/' + pending.length;
- // Создаём уникальный iframe
- var iframeId = 'up_iframe_' + Date.now() + '_' + i;
+ var reader = new FileReader();
+ reader.onload = function(e) {
+ var b64 = e.target.result.split(',')[1];
+ f.status = '0%';
+ renderTable();
+ uploadTimer.textContent = 'Загрузка ' + (i+1) + '/' + pending.length;
+ submitFile(i, f, b64);
+ };
+ reader.onerror = function() {
+ f.status = 'error: чтение';
+ renderTable();
+ readThenUpload(i + 1);
+ };
+ reader.readAsDataURL(f.file);
+ }
+
+ function submitFile(i, f, b64) {
var iframe = document.createElement('iframe');
- iframe.name = iframeId;
+ iframe.name = 'upfrm_' + Date.now() + '_' + i;
iframe.style.display = 'none';
iframe.onload = function() {
try {
- var resp = iframe.contentDocument.body.textContent;
+ var resp = iframe.contentDocument.body.textContent.trim();
+ if (!resp) { throw new Error('пустой ответ'); }
var r = JSON.parse(resp);
if (r.OK) {
contractId = r.CONTRACT_ID;
@@ -272,38 +288,26 @@ uploadBtn.addEventListener('click', function() {
}
renderTable();
document.body.removeChild(iframe);
- uploadNext(i + 1);
+ readThenUpload(i + 1);
};
document.body.appendChild(iframe);
- // Форма внутри iframe
- var form = iframe.contentDocument.createElement('form');
+ // Форма с скрытыми полями, target = iframe
+ var form = document.createElement('form');
form.method = 'POST';
form.action = '/upload.cfm';
- form.enctype = 'multipart/form-data';
-
- var input = iframe.contentDocument.createElement('input');
- input.type = 'file';
- input.name = 'files';
- // Копируем файл в форму через DataTransfer
- var dt = new DataTransfer();
- dt.items.add(f.file);
- input.files = dt.files;
- form.appendChild(input);
-
- if (contractId) {
- var cidInput = iframe.contentDocument.createElement('input');
- cidInput.type = 'hidden';
- cidInput.name = 'contract_id';
- cidInput.value = contractId;
- form.appendChild(cidInput);
- }
-
- iframe.contentDocument.body.appendChild(form);
+ form.target = iframe.name;
+ form.style.display = 'none';
+ form.innerHTML =
+ '' +
+ '' +
+ (contractId ? '' : '');
+ document.body.appendChild(form);
form.submit();
+ setTimeout(function() { document.body.removeChild(form); }, 100);
}
- uploadNext(0);
+ readThenUpload(0);
});
// ── Инфо ──────────────────────────────────────────────────
diff --git a/upload.cfm b/upload.cfm
index 2a92f88..b145f35 100644
--- a/upload.cfm
+++ b/upload.cfm
@@ -12,8 +12,44 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ INSERT INTO documents (filename, mime_type, original_bytes, status) VALUES (,,,'uploaded')
+
+
+ SELECT id FROM documents WHERE filename= AND status='uploaded' ORDER BY created_at DESC LIMIT 1
+
+
+
+
+
+ INSERT INTO contracts (number, client) VALUES (,'')
+
+
+ SELECT id FROM contracts ORDER BY created_at DESC LIMIT 1
+
+
+
+
+
+ INSERT INTO supplements (contract_id, document_id, type) VALUES (,,)
+
+
+
+
+