Files
crm.clientright.ru/crm_extensions/simple_editor.php
Fedor 1f96ab6e10 feat: Полная интеграция CRM → Nextcloud редактор
 Что реализовано:
- SSL/HTTPS для Nextcloud (Let's Encrypt R13)
- Redis кэширование для производительности
- Collabora Online редактор документов
- WOPI allow list настроен (0.0.0.0/0)
- Динамическое получение fileId через WebDAV
- Поддержка файлов из S3 и локальных файлов
- Автоматическое извлечение имени файла из URL
- Промежуточная страница для обхода CSRF

🚀 Как работает:
1. JavaScript передает recordId и fileName
2. PHP получает fileId через WebDAV PROPFIND
3. PHP делает редирект на рабочий URL Nextcloud
4. Файл открывается в редакторе Collabora

📁 Файлы:
- layouts/v7/lib/nextcloud-editor.js - JavaScript интеграция
- crm_extensions/file_storage/api/open_file.php - PHP редирект
- modules/Documents/actions/NcPrepareEdit.php - API подготовка
- crm_extensions/docs/ - документация

🎯 Результат: Каждый документ в CRM открывает СВОЙ файл в Nextcloud редакторе!
2025-10-21 22:10:47 +03:00

94 lines
3.7 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Простой редактор документов через внешние сервисы
*/
// Получаем параметры
$recordId = $_GET['recordId'] ?? '';
$fileName = $_GET['fileName'] ?? '';
if (!$recordId || !$fileName) {
die('Не указаны параметры recordId и fileName');
}
// Декодируем имя файла
$fileName = urldecode($fileName);
// Создаем различные варианты открытия
$baseUrl = 'https://office.clientright.ru';
$filePath = "/crm/crm2/CRM_Active_Files/Documents/{$recordId}/" . urlencode($fileName);
// Подключаем конфигурацию
$config = require_once __DIR__ . '/file_storage/config.php';
require_once __DIR__ . '/file_storage/NextcloudClient.php';
// Получаем fileId из Nextcloud
$nextcloudClient = new NextcloudClient($config['nextcloud']);
$remotePath = 'Documents/' . $recordId . '/' . $fileName;
$fileId = $nextcloudClient->getFileId($remotePath);
?>
<!DOCTYPE html>
<html>
<head>
<title>Редактирование документа</title>
<meta charset="utf-8">
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
.option { margin: 10px 0; padding: 10px; border: 1px solid #ddd; border-radius: 5px; }
.option h3 { margin-top: 0; color: #333; }
.btn { display: inline-block; padding: 10px 20px; background: #007cba; color: white; text-decoration: none; border-radius: 3px; margin: 5px; }
.btn:hover { background: #005a87; }
.btn-success { background: #28a745; }
.btn-success:hover { background: #1e7e34; }
</style>
</head>
<body>
<h1>Редактирование документа: <?= htmlspecialchars($fileName) ?></h1>
<div class="option">
<h3>📝 Варианты редактирования:</h3>
<h4>1. Collabora Online (рекомендуется)</h4>
<a href="<?= $baseUrl ?>/apps/richdocuments/open?path=<?= urlencode($filePath) ?>" target="_blank" class="btn btn-success">
Открыть в Collabora
</a>
<h4>2. Только просмотр</h4>
<a href="<?= $baseUrl ?>/apps/files/files/<?= $fileId ?>?dir=/crm/crm2/CRM_Active_Files/Documents/<?= $recordId ?>&openfile=true" target="_blank" class="btn">
Просмотр в Nextcloud
</a>
<h4>3. Скачать и редактировать локально</h4>
<a href="<?= $baseUrl ?>/remote.php/dav/files/admin<?= $filePath ?>" target="_blank" class="btn">
Скачать файл
</a>
<h4>4. Google Docs (если файл публично доступен)</h4>
<a href="https://docs.google.com/document/d/1/edit?usp=sharing" target="_blank" class="btn">
Открыть в Google Docs
</a>
<h4>5. Microsoft Office Online</h4>
<a href="https://office.com" target="_blank" class="btn">
Открыть в Office Online
</a>
</div>
<div class="option">
<h3> Информация о файле:</h3>
<p><strong>Файл:</strong> <?= htmlspecialchars($fileName) ?></p>
<p><strong>ID записи:</strong> <?= htmlspecialchars($recordId) ?></p>
<p><strong>File ID:</strong> <?= $fileId ?: 'Не найден' ?></p>
<p><strong>Путь:</strong> <?= htmlspecialchars($filePath) ?></p>
</div>
<script>
// Автоматически открываем Collabora через 2 секунды
setTimeout(function() {
window.open('<?= $baseUrl ?>/apps/richdocuments/open?path=<?= urlencode($filePath) ?>', '_blank');
}, 2000);
</script>
</body>
</html>