68 lines
2.8 KiB
PHP
Executable File
68 lines
2.8 KiB
PHP
Executable File
<?php
|
||
/*+***********************************************************************************
|
||
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||
* ("License"); You may not use this file except in compliance with the License
|
||
* The Original Code is: vtiger CRM Open Source
|
||
* The Initial Developer of the Original Code is vtiger.
|
||
* Portions created by vtiger are Copyright (C) vtiger.
|
||
* All Rights Reserved.
|
||
*************************************************************************************/
|
||
|
||
class ModComments_FilePreview_View extends Vtiger_Index_View {
|
||
|
||
public function checkPermission(Vtiger_Request $request) {
|
||
$moduleName = $request->getModule();
|
||
$moduleModel = Vtiger_Module_Model::getInstance($moduleName);
|
||
|
||
$currentUserPrivilegesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
|
||
if(!$currentUserPrivilegesModel->hasModulePermission($moduleModel->getId())) {
|
||
throw new AppException(vtranslate('LBL_PERMISSION_DENIED'));
|
||
}
|
||
}
|
||
|
||
public function process(Vtiger_Request $request) {
|
||
$recordId = $request->get('record');
|
||
$attachmentId = $request->get('attachmentid');
|
||
|
||
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_FILEPREVIEW: recordId=' . $recordId . ', attachmentId=' . $attachmentId . PHP_EOL, FILE_APPEND);
|
||
|
||
if (empty($attachmentId)) {
|
||
throw new AppException('Attachment ID is required');
|
||
}
|
||
|
||
// Проверяем что файл связан с этим комментарием
|
||
global $adb;
|
||
$query = "SELECT COUNT(*) as count FROM vtiger_seattachmentsrel WHERE crmid = ? AND attachmentsid = ?";
|
||
$result = $adb->pquery($query, array($recordId, $attachmentId));
|
||
$row = $adb->fetchByAssoc($result);
|
||
|
||
if ($row['count'] == 0) {
|
||
throw new AppException('File not found or not accessible');
|
||
}
|
||
|
||
// Получаем информацию о файле
|
||
$query = "SELECT * FROM vtiger_attachments WHERE attachmentsid = ?";
|
||
$result = $adb->pquery($query, array($attachmentId));
|
||
|
||
if ($adb->num_rows($result) == 0) {
|
||
throw new AppException('File not found');
|
||
}
|
||
|
||
$fileInfo = $adb->fetchByAssoc($result);
|
||
|
||
// Создаем URL для просмотра файла через ViewFile action
|
||
$viewUrl = 'index.php?module=ModComments&action=ViewFile&record=' . $recordId . '&fileid=' . $attachmentId;
|
||
|
||
$viewer = $this->getViewer($request);
|
||
$viewer->assign('FILE_NAME', $fileInfo['name']);
|
||
$viewer->assign('FILE_TYPE', $fileInfo['type']);
|
||
$viewer->assign('VIEW_URL', $viewUrl);
|
||
$viewer->assign('ATTACHMENT_ID', $attachmentId);
|
||
$viewer->assign('RECORD_ID', $recordId);
|
||
|
||
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_FILEPREVIEW_URL: ' . $viewUrl . PHP_EOL, FILE_APPEND);
|
||
|
||
echo $viewer->view('FilePreview.tpl', 'ModComments', true);
|
||
}
|
||
}
|
||
?>
|