get('enable_onlyoffice_plugin'); if (!$isEnable) { return ''; } $urlToEdit = api_get_path(WEB_PLUGIN_PATH).'onlyoffice/editor.php'; $extension = strtolower(pathinfo($document_data['title'], PATHINFO_EXTENSION)); $canEdit = null !== $documentManager->getFormatInfo($extension) ? $documentManager->getFormatInfo($extension)->isEditable() : false; $canView = null !== $documentManager->getFormatInfo($extension) ? $documentManager->getFormatInfo($extension)->isViewable() : false; $groupId = api_get_group_id(); if (!empty($groupId)) { $urlToEdit = $urlToEdit.'?groupId='.$groupId.'&'; } else { $urlToEdit = $urlToEdit.'?'; } $documentId = $document_data['id']; $urlToEdit = $urlToEdit.'docId='.$documentId; if ($canEdit || $canView) { $tooltip = $plugin->get_lang('openByOnlyoffice'); if ('pdf' === $extension) { $tooltip = $plugin->get_lang('fillInFormInOnlyoffice'); } return Display::url( Display::return_icon( '../../plugin/onlyoffice/resources/onlyoffice_edit.png', $tooltip ), $urlToEdit ); } return ''; } /** * Return button-link to onlyoffice editor for view file. */ public static function getButtonView(array $document_data): string { $plugin = OnlyofficePlugin::create(); $appSettings = new OnlyofficeAppsettings($plugin); $documentManager = new OnlyofficeDocumentManager($appSettings, []); $isEnable = 'true' === $plugin->get('enable_onlyoffice_plugin'); if (!$isEnable) { return ''; } $urlToEdit = api_get_path(WEB_PLUGIN_PATH).'onlyoffice/editor.php'; $sessionId = api_get_session_id(); $courseInfo = api_get_course_info(); $documentId = $document_data['id']; $userId = api_get_user_id(); $docInfo = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code'], false, $sessionId); $extension = strtolower(pathinfo($document_data['title'], PATHINFO_EXTENSION)); $canView = null !== $documentManager->getFormatInfo($extension) ? $documentManager->getFormatInfo($extension)->isViewable() : false; $isGroupAccess = false; $groupId = api_get_group_id(); if (!empty($groupId)) { $groupProperties = GroupManager::get_group_properties($groupId); $docInfoGroup = api_get_item_property_info(api_get_course_int_id(), 'document', $documentId, $sessionId); $isGroupAccess = GroupManager::allowUploadEditDocument($userId, $courseInfo['code'], $groupProperties, $docInfoGroup); $urlToEdit = $urlToEdit.'?groupId='.$groupId.'&'; } else { $urlToEdit = $urlToEdit.'?'; } $isAllowToEdit = api_is_allowed_to_edit(true, true); $isMyDir = DocumentManager::is_my_shared_folder($userId, $docInfo['absolute_parent_path'], $sessionId); $accessRights = $isAllowToEdit || $isMyDir || $isGroupAccess; $urlToEdit = $urlToEdit.'docId='.$documentId; if ($canView && !$accessRights) { return Display::url(Display::return_icon('../../plugin/onlyoffice/resources/onlyoffice_view.png', $plugin->get_lang('openByOnlyoffice')), $urlToEdit, ['style' => 'float:right; margin-right:8px']); } return ''; } /** * Return button-link to onlyoffice create new. */ public static function getButtonCreateNew(): string { $plugin = OnlyofficePlugin::create(); $isEnable = 'true' === $plugin->get('enable_onlyoffice_plugin'); if (!$isEnable) { return ''; } $courseId = api_get_course_int_id(); $sessionId = api_get_session_id(); $groupId = api_get_group_id(); $userId = api_get_user_id(); $urlToCreate = api_get_path(WEB_PLUGIN_PATH).'onlyoffice/create.php' .'?folderId='.(empty($_GET['id']) ? '0' : (int) $_GET['id']) .'&courseId='.$courseId .'&groupId='.$groupId .'&sessionId='.$sessionId .'&userId='.$userId; return Display::url( Display::return_icon( '../../plugin/onlyoffice/resources/onlyoffice_create.png', $plugin->get_lang('createNew') ), $urlToCreate ); } /** * Return path to OnlyOffice viewer for a given file. * * @param int $documentId The ID from c_document.iid * @param bool $showHeaders Whether to show Chamilo headers on top of the OnlyOffice frame or not * * @return string A link to open the OnlyOffice viewer */ public static function getPathToView(int $documentId, bool $showHeaders = true): string { $plugin = OnlyofficePlugin::create(); $appSettings = new OnlyofficeAppsettings($plugin); $documentManager = new OnlyofficeDocumentManager($appSettings, []); $isEnable = 'true' === $plugin->get('enable_onlyoffice_plugin'); if (!$isEnable) { return ''; } $urlToEdit = api_get_path(WEB_PLUGIN_PATH).'onlyoffice/editor.php'; $sessionId = api_get_session_id(); $courseInfo = api_get_course_info(); $userId = api_get_user_id(); $docInfo = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code'], false, $sessionId); $extension = strtolower(pathinfo($docInfo['path'], PATHINFO_EXTENSION)); $canView = null !== $documentManager->getFormatInfo($extension) ? $documentManager->getFormatInfo($extension)->isViewable() : false; $isGroupAccess = false; $groupId = api_get_group_id(); if (!empty($groupId)) { $groupProperties = GroupManager::get_group_properties($groupId); $docInfoGroup = api_get_item_property_info(api_get_course_int_id(), 'document', $documentId, $sessionId); $isGroupAccess = GroupManager::allowUploadEditDocument($userId, $courseInfo['code'], $groupProperties, $docInfoGroup); $urlToEdit = $urlToEdit.'?groupId='.$groupId.'&'; } else { $urlToEdit = $urlToEdit.'?'; } error_log(__LINE__.' '.$urlToEdit); $isMyDir = DocumentManager::is_my_shared_folder($userId, $docInfo['absolute_parent_path'], $sessionId); $accessRights = $isMyDir || $isGroupAccess; $urlToEdit = $urlToEdit.'docId='.$documentId; if (false === $showHeaders) { $urlToEdit .= '&nh=1'; } if ($canView && !$accessRights) { error_log(__LINE__.' '.$urlToEdit); return $urlToEdit; } return ''; } }