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); } } ?>