Skip to content

Commit

Permalink
Merge branch '1.11.x' of https://github.com/chamilo/chamilo-lms into …
Browse files Browse the repository at this point in the history
…1.11.x
  • Loading branch information
ywarnier committed Aug 25, 2021
2 parents 1e3a1e2 + 7b69619 commit ee6c847
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 20 deletions.
2 changes: 2 additions & 0 deletions main/forum/forumfunction.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -6420,6 +6420,8 @@ function getAttachedFiles(
if ($result !== false && Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result, 'ASSOC')) {
// name contains an URL to download attachment file and its filename
$json['filename'] = $row['filename'];
$json['path'] = $row['path'];
$json['name'] = Display::url(
api_htmlentities($row['filename']),
api_get_path(WEB_CODE_PATH).'forum/download.php?file='.$row['path'].'&'.api_get_cidreq(),
Expand Down
74 changes: 74 additions & 0 deletions main/inc/lib/webservices/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Rest extends WebService
const POST_USER_MESSAGE_UNREAD = 'user_message_unread';
const SAVE_USER_MESSAGE = 'save_user_message';
const GET_MESSAGE_USERS = 'message_users';
const VIEW_MESSAGE = 'view_message';

const GET_USER_COURSES = 'user_courses';
const GET_USER_SESSIONS = 'user_sessions';
Expand Down Expand Up @@ -59,6 +60,7 @@ class Rest extends WebService
const SAVE_FORUM_POST = 'save_forum_post';
const SAVE_FORUM_THREAD = 'save_forum_thread';
const SET_THREAD_NOTIFY = 'set_thread_notify';
const DOWNLOAD_FORUM_ATTACHMENT = 'download_forum_attachment';

const GET_WORK_LIST = 'get_work_list';
const GET_WORK_STUDENTS_WITHOUT_PUBLICATIONS = 'get_work_students_without_publications';
Expand All @@ -67,6 +69,9 @@ class Rest extends WebService
const PUT_WORK_STUDENT_ITEM_VISIBILITY = 'put_course_work_visibility';
const DELETE_WORK_STUDENT_ITEM = 'delete_work_student_item';
const DELETE_WORK_CORRECTIONS = 'delete_work_corrections';
const DOWNLOAD_WORK_FOLDER = 'download_work_folder';
const DOWNLOAD_WORK_COMMENT_ATTACHMENT = 'download_work_comment_attachment';
const DOWNLOAD_WORK = 'download_work';

const VIEW_DOCUMENT_IN_FRAME = 'view_document_in_frame';

Expand Down Expand Up @@ -878,6 +883,13 @@ public function getCourseForumThread($forumId, $threadId)
'author' => api_get_person_name($postInfo['firstname'], $postInfo['lastname']),
'date' => api_convert_and_format_date($postInfo['post_date'], DATE_TIME_FORMAT_LONG_24H),
'parentId' => $postInfo['post_parent_id'],
'attachments' => getAttachedFiles(
$forumId,
$threadId,
$postInfo['iid'],
0,
$this->course->getId()
),
];
}

Expand Down Expand Up @@ -2925,6 +2937,68 @@ public function viewSurveyTool()
exit;
}

public function viewMessage(int $messageId)
{
$url = api_get_path(WEB_CODE_PATH).'messages/view_message.php?'.http_build_query(['id' => $messageId]);

header("Location: $url");
exit;
}

public function downloadForumPostAttachment(string $path)
{
$courseCode = $this->course->getCode();
$sessionId = $this->session ? $this->session->getId() : 0;

$url = api_get_path(WEB_CODE_PATH).'forum/download.php?'
.http_build_query(
[
'cidReq' => $courseCode,
'id_session' => $sessionId,
'gidReq' => 0,
'gradebook' => 0,
'origin' => self::SERVICE_NAME,
'file' => Security::remove_XSS($path),
]
);

header("Location: $url");
exit;
}

public function downloadWorkFolder(int $workId)
{
$cidReq = api_get_cidreq();
$url = api_get_path(WEB_CODE_PATH)."work/downloadfolder.inc.php?id=$workId&$cidReq";

header("Location: $url");
exit;
}

public function downloadWorkCommentAttachment(int $commentId)
{
$cidReq = api_get_cidreq();
$url = api_get_path(WEB_CODE_PATH)."work/download_comment_file.php?comment_id=$commentId&$cidReq";

header("Location: $url");
exit;
}

public function downloadWork(int $workId, bool $isCorrection = false)
{
$cidReq = api_get_cidreq();
$url = api_get_path(WEB_CODE_PATH)."work/download.php?$cidReq&"
.http_build_query(
[
'id' => $workId,
'correction' => $isCorrection ? 1 : null,
]
);

header("Location: $url");
exit;
}

public static function isAllowedByRequest(bool $inpersonate = false): bool
{
$username = $_GET['username'] ?? null;
Expand Down
35 changes: 35 additions & 0 deletions main/webservices/api/v2.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@
$data = $restApi->getMessageUsers($search);
$restResponse->setData($data);
break;
case Rest::VIEW_MESSAGE:
$messageId = isset($_GET['message']) ? (int) $_GET['message'] : 0;

$restApi->viewMessage($messageId);
break;

case Rest::GET_USER_COURSES:
$userId = isset($_REQUEST['user_id']) ? (int) $_REQUEST['user_id'] : 0;
Expand Down Expand Up @@ -295,6 +300,13 @@
]
);
break;
case Rest::DOWNLOAD_FORUM_ATTACHMENT:
if (empty($_GET['path'])) {
throw new Exception(get_lang('ActionNotAllowed'));
}

$restApi->downloadForumPostAttachment($_GET['path']);
break;

case Rest::GET_WORK_LIST:
if (!isset($_GET['work'])) {
Expand Down Expand Up @@ -390,6 +402,29 @@
]
);
break;
case Rest::DOWNLOAD_WORK_FOLDER:
if (!isset($_GET['work'])) {
throw new Exception(get_lang('ActionNotAllowed'));
}

$restApi->downloadWorkFolder((int) $_GET['work']);
break;
case Rest::DOWNLOAD_WORK_COMMENT_ATTACHMENT:
if (!isset($_GET['comment'])) {
throw new Exception(get_lang('ActionNotAllowed'));
}

$restApi->downloadWorkCommentAttachment((int) $_GET['comment']);
break;
case Rest::DOWNLOAD_WORK:
if (!isset($_GET['work'])) {
throw new Exception(get_lang('ActionNotAllowed'));
}

$isCorrection = isset($_GET['correction']);

$restApi->downloadWork((int) $_GET['work'], $isCorrection);
break;

case Rest::VIEW_DOCUMENT_IN_FRAME:
$lpId = isset($_REQUEST['document']) ? (int) $_REQUEST['document'] : 0;
Expand Down
35 changes: 15 additions & 20 deletions plugin/onlyoffice/create.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,19 +13,17 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

require_once __DIR__.'/../../main/inc/global.inc.php';

use ChamiloSession as Session;

$plugin = OnlyofficePlugin::create();

$mapFileFormat = [
"text" => $plugin->get_lang("document"),
"text" => $plugin->get_lang("document"),
"spreadsheet" => $plugin->get_lang("spreadsheet"),
"presentation" => $plugin->get_lang("presentation")
"presentation" => $plugin->get_lang("presentation"),
];

$userId = $_GET["userId"];
Expand All @@ -48,7 +45,7 @@

$form = new FormValidator("doc_create",
"post",
api_get_path(WEB_PLUGIN_PATH) . "onlyoffice/create.php");
api_get_path(WEB_PLUGIN_PATH)."onlyoffice/create.php");

$form->addText("fileName", $plugin->get_lang("title"), true);
$form->addSelect("fileFormat", $plugin->get_lang("chooseFileFormat"), $mapFileFormat);
Expand All @@ -73,13 +70,13 @@

$fileType = $values["fileFormat"];
$fileExt = FileUtility::getDocExt($fileType);
$fileTitle = $values["fileName"] . "." . $fileExt;
$fileTitle = $values["fileName"].".".$fileExt;

$courseInfo = api_get_course_info_by_id($courseId);
$courseCode = $courseInfo["code"];

$fileNamePrefix = DocumentManager::getDocumentSuffix($courseInfo, $sessionId, $groupId);
$fileName = $values["fileName"] . $fileNamePrefix . "." . $fileExt;
$fileName = $values["fileName"].$fileNamePrefix.".".$fileExt;

$groupInfo = GroupManager::get_group_properties($groupId);

Expand All @@ -89,16 +86,16 @@
if (!empty($folderId)) {
$document_data = DocumentManager::get_document_data_by_id($folderId, $courseCode, true, $sessionId);
$folderPath = $document_data["absolute_path"];
$fileRelatedPath = $fileRelatedPath . substr($document_data["absolute_path_from_document"], 10) . "/" . $fileName;
$fileRelatedPath = $fileRelatedPath.substr($document_data["absolute_path_from_document"], 10)."/".$fileName;
} else {
$folderPath = api_get_path(SYS_COURSE_PATH) . api_get_course_path($courseCode) . "/document";
$folderPath = api_get_path(SYS_COURSE_PATH).api_get_course_path($courseCode)."/document";
if (!empty($groupId)) {
$folderPath = $folderPath . "/" . $groupInfo["directory"];
$fileRelatedPath = $groupInfo["directory"] . "/";
$folderPath = $folderPath."/".$groupInfo["directory"];
$fileRelatedPath = $groupInfo["directory"]."/";
}
$fileRelatedPath = $fileRelatedPath . $fileName;
$fileRelatedPath = $fileRelatedPath.$fileName;
}
$filePath = $folderPath . "/" . $fileName;
$filePath = $folderPath."/".$fileName;

if (file_exists($filePath)) {
Display::addFlash(Display::return_message($plugin->get_lang("fileIsExist"), "error"));
Expand Down Expand Up @@ -131,21 +128,19 @@
null,
$sessionId);

header("Location: " . $goBackUrl);
header("Location: ".$goBackUrl);
exit();
}

} else {
Display::addFlash(Display::return_message($plugin->get_lang("impossibleCreateFile"), "error"));
}
}

display:
$goBackUrl = $goBackUrl ?: $_SERVER["HTTP_REFERER"];
$actionsLeft = '<a href="'. $goBackUrl . '">' . Display::return_icon("back.png", get_lang("Back") . " " . get_lang("To") . " " . get_lang("DocumentsOverview"), "", ICON_SIZE_MEDIUM) . "</a>";
$actionsLeft = '<a href="'.$goBackUrl.'">'.Display::return_icon("back.png", get_lang("Back")." ".get_lang("To")." ".get_lang("DocumentsOverview"), "", ICON_SIZE_MEDIUM)."</a>";

Display::display_header($plugin->get_lang("createNewDocument"));
echo Display::toolbarAction("actions-documents", [$actionsLeft]);
echo $form->returnForm();
Display::display_footer();
?>

0 comments on commit ee6c847

Please sign in to comment.