Skip to content

Commit ee6c847

Browse files
committed
Merge branch '1.11.x' of https://github.com/chamilo/chamilo-lms into 1.11.x
2 parents 1e3a1e2 + 7b69619 commit ee6c847

File tree

4 files changed

+126
-20
lines changed

4 files changed

+126
-20
lines changed

main/forum/forumfunction.inc.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6420,6 +6420,8 @@ function getAttachedFiles(
64206420
if ($result !== false && Database::num_rows($result) > 0) {
64216421
while ($row = Database::fetch_array($result, 'ASSOC')) {
64226422
// name contains an URL to download attachment file and its filename
6423+
$json['filename'] = $row['filename'];
6424+
$json['path'] = $row['path'];
64236425
$json['name'] = Display::url(
64246426
api_htmlentities($row['filename']),
64256427
api_get_path(WEB_CODE_PATH).'forum/download.php?file='.$row['path'].'&'.api_get_cidreq(),

main/inc/lib/webservices/Rest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Rest extends WebService
3232
const POST_USER_MESSAGE_UNREAD = 'user_message_unread';
3333
const SAVE_USER_MESSAGE = 'save_user_message';
3434
const GET_MESSAGE_USERS = 'message_users';
35+
const VIEW_MESSAGE = 'view_message';
3536

3637
const GET_USER_COURSES = 'user_courses';
3738
const GET_USER_SESSIONS = 'user_sessions';
@@ -59,6 +60,7 @@ class Rest extends WebService
5960
const SAVE_FORUM_POST = 'save_forum_post';
6061
const SAVE_FORUM_THREAD = 'save_forum_thread';
6162
const SET_THREAD_NOTIFY = 'set_thread_notify';
63+
const DOWNLOAD_FORUM_ATTACHMENT = 'download_forum_attachment';
6264

6365
const GET_WORK_LIST = 'get_work_list';
6466
const GET_WORK_STUDENTS_WITHOUT_PUBLICATIONS = 'get_work_students_without_publications';
@@ -67,6 +69,9 @@ class Rest extends WebService
6769
const PUT_WORK_STUDENT_ITEM_VISIBILITY = 'put_course_work_visibility';
6870
const DELETE_WORK_STUDENT_ITEM = 'delete_work_student_item';
6971
const DELETE_WORK_CORRECTIONS = 'delete_work_corrections';
72+
const DOWNLOAD_WORK_FOLDER = 'download_work_folder';
73+
const DOWNLOAD_WORK_COMMENT_ATTACHMENT = 'download_work_comment_attachment';
74+
const DOWNLOAD_WORK = 'download_work';
7075

7176
const VIEW_DOCUMENT_IN_FRAME = 'view_document_in_frame';
7277

@@ -878,6 +883,13 @@ public function getCourseForumThread($forumId, $threadId)
878883
'author' => api_get_person_name($postInfo['firstname'], $postInfo['lastname']),
879884
'date' => api_convert_and_format_date($postInfo['post_date'], DATE_TIME_FORMAT_LONG_24H),
880885
'parentId' => $postInfo['post_parent_id'],
886+
'attachments' => getAttachedFiles(
887+
$forumId,
888+
$threadId,
889+
$postInfo['iid'],
890+
0,
891+
$this->course->getId()
892+
),
881893
];
882894
}
883895

@@ -2925,6 +2937,68 @@ public function viewSurveyTool()
29252937
exit;
29262938
}
29272939

2940+
public function viewMessage(int $messageId)
2941+
{
2942+
$url = api_get_path(WEB_CODE_PATH).'messages/view_message.php?'.http_build_query(['id' => $messageId]);
2943+
2944+
header("Location: $url");
2945+
exit;
2946+
}
2947+
2948+
public function downloadForumPostAttachment(string $path)
2949+
{
2950+
$courseCode = $this->course->getCode();
2951+
$sessionId = $this->session ? $this->session->getId() : 0;
2952+
2953+
$url = api_get_path(WEB_CODE_PATH).'forum/download.php?'
2954+
.http_build_query(
2955+
[
2956+
'cidReq' => $courseCode,
2957+
'id_session' => $sessionId,
2958+
'gidReq' => 0,
2959+
'gradebook' => 0,
2960+
'origin' => self::SERVICE_NAME,
2961+
'file' => Security::remove_XSS($path),
2962+
]
2963+
);
2964+
2965+
header("Location: $url");
2966+
exit;
2967+
}
2968+
2969+
public function downloadWorkFolder(int $workId)
2970+
{
2971+
$cidReq = api_get_cidreq();
2972+
$url = api_get_path(WEB_CODE_PATH)."work/downloadfolder.inc.php?id=$workId&$cidReq";
2973+
2974+
header("Location: $url");
2975+
exit;
2976+
}
2977+
2978+
public function downloadWorkCommentAttachment(int $commentId)
2979+
{
2980+
$cidReq = api_get_cidreq();
2981+
$url = api_get_path(WEB_CODE_PATH)."work/download_comment_file.php?comment_id=$commentId&$cidReq";
2982+
2983+
header("Location: $url");
2984+
exit;
2985+
}
2986+
2987+
public function downloadWork(int $workId, bool $isCorrection = false)
2988+
{
2989+
$cidReq = api_get_cidreq();
2990+
$url = api_get_path(WEB_CODE_PATH)."work/download.php?$cidReq&"
2991+
.http_build_query(
2992+
[
2993+
'id' => $workId,
2994+
'correction' => $isCorrection ? 1 : null,
2995+
]
2996+
);
2997+
2998+
header("Location: $url");
2999+
exit;
3000+
}
3001+
29283002
public static function isAllowedByRequest(bool $inpersonate = false): bool
29293003
{
29303004
$username = $_GET['username'] ?? null;

main/webservices/api/v2.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@
151151
$data = $restApi->getMessageUsers($search);
152152
$restResponse->setData($data);
153153
break;
154+
case Rest::VIEW_MESSAGE:
155+
$messageId = isset($_GET['message']) ? (int) $_GET['message'] : 0;
156+
157+
$restApi->viewMessage($messageId);
158+
break;
154159

155160
case Rest::GET_USER_COURSES:
156161
$userId = isset($_REQUEST['user_id']) ? (int) $_REQUEST['user_id'] : 0;
@@ -295,6 +300,13 @@
295300
]
296301
);
297302
break;
303+
case Rest::DOWNLOAD_FORUM_ATTACHMENT:
304+
if (empty($_GET['path'])) {
305+
throw new Exception(get_lang('ActionNotAllowed'));
306+
}
307+
308+
$restApi->downloadForumPostAttachment($_GET['path']);
309+
break;
298310

299311
case Rest::GET_WORK_LIST:
300312
if (!isset($_GET['work'])) {
@@ -390,6 +402,29 @@
390402
]
391403
);
392404
break;
405+
case Rest::DOWNLOAD_WORK_FOLDER:
406+
if (!isset($_GET['work'])) {
407+
throw new Exception(get_lang('ActionNotAllowed'));
408+
}
409+
410+
$restApi->downloadWorkFolder((int) $_GET['work']);
411+
break;
412+
case Rest::DOWNLOAD_WORK_COMMENT_ATTACHMENT:
413+
if (!isset($_GET['comment'])) {
414+
throw new Exception(get_lang('ActionNotAllowed'));
415+
}
416+
417+
$restApi->downloadWorkCommentAttachment((int) $_GET['comment']);
418+
break;
419+
case Rest::DOWNLOAD_WORK:
420+
if (!isset($_GET['work'])) {
421+
throw new Exception(get_lang('ActionNotAllowed'));
422+
}
423+
424+
$isCorrection = isset($_GET['correction']);
425+
426+
$restApi->downloadWork((int) $_GET['work'], $isCorrection);
427+
break;
393428

394429
case Rest::VIEW_DOCUMENT_IN_FRAME:
395430
$lpId = isset($_REQUEST['document']) ? (int) $_REQUEST['document'] : 0;

plugin/onlyoffice/create.php

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
/**
3-
*
4-
* (c) Copyright Ascensio System SIA 2021
3+
* (c) Copyright Ascensio System SIA 2021.
54
*
65
* Licensed under the Apache License, Version 2.0 (the "License");
76
* you may not use this file except in compliance with the License.
@@ -14,19 +13,17 @@
1413
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1514
* See the License for the specific language governing permissions and
1615
* limitations under the License.
17-
*
1816
*/
19-
2017
require_once __DIR__.'/../../main/inc/global.inc.php';
2118

2219
use ChamiloSession as Session;
2320

2421
$plugin = OnlyofficePlugin::create();
2522

2623
$mapFileFormat = [
27-
"text" => $plugin->get_lang("document"),
24+
"text" => $plugin->get_lang("document"),
2825
"spreadsheet" => $plugin->get_lang("spreadsheet"),
29-
"presentation" => $plugin->get_lang("presentation")
26+
"presentation" => $plugin->get_lang("presentation"),
3027
];
3128

3229
$userId = $_GET["userId"];
@@ -48,7 +45,7 @@
4845

4946
$form = new FormValidator("doc_create",
5047
"post",
51-
api_get_path(WEB_PLUGIN_PATH) . "onlyoffice/create.php");
48+
api_get_path(WEB_PLUGIN_PATH)."onlyoffice/create.php");
5249

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

7471
$fileType = $values["fileFormat"];
7572
$fileExt = FileUtility::getDocExt($fileType);
76-
$fileTitle = $values["fileName"] . "." . $fileExt;
73+
$fileTitle = $values["fileName"].".".$fileExt;
7774

7875
$courseInfo = api_get_course_info_by_id($courseId);
7976
$courseCode = $courseInfo["code"];
80-
77+
8178
$fileNamePrefix = DocumentManager::getDocumentSuffix($courseInfo, $sessionId, $groupId);
82-
$fileName = $values["fileName"] . $fileNamePrefix . "." . $fileExt;
79+
$fileName = $values["fileName"].$fileNamePrefix.".".$fileExt;
8380

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

@@ -89,16 +86,16 @@
8986
if (!empty($folderId)) {
9087
$document_data = DocumentManager::get_document_data_by_id($folderId, $courseCode, true, $sessionId);
9188
$folderPath = $document_data["absolute_path"];
92-
$fileRelatedPath = $fileRelatedPath . substr($document_data["absolute_path_from_document"], 10) . "/" . $fileName;
89+
$fileRelatedPath = $fileRelatedPath.substr($document_data["absolute_path_from_document"], 10)."/".$fileName;
9390
} else {
94-
$folderPath = api_get_path(SYS_COURSE_PATH) . api_get_course_path($courseCode) . "/document";
91+
$folderPath = api_get_path(SYS_COURSE_PATH).api_get_course_path($courseCode)."/document";
9592
if (!empty($groupId)) {
96-
$folderPath = $folderPath . "/" . $groupInfo["directory"];
97-
$fileRelatedPath = $groupInfo["directory"] . "/";
93+
$folderPath = $folderPath."/".$groupInfo["directory"];
94+
$fileRelatedPath = $groupInfo["directory"]."/";
9895
}
99-
$fileRelatedPath = $fileRelatedPath . $fileName;
96+
$fileRelatedPath = $fileRelatedPath.$fileName;
10097
}
101-
$filePath = $folderPath . "/" . $fileName;
98+
$filePath = $folderPath."/".$fileName;
10299

103100
if (file_exists($filePath)) {
104101
Display::addFlash(Display::return_message($plugin->get_lang("fileIsExist"), "error"));
@@ -131,21 +128,19 @@
131128
null,
132129
$sessionId);
133130

134-
header("Location: " . $goBackUrl);
131+
header("Location: ".$goBackUrl);
135132
exit();
136133
}
137-
138134
} else {
139135
Display::addFlash(Display::return_message($plugin->get_lang("impossibleCreateFile"), "error"));
140136
}
141137
}
142138

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

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

0 commit comments

Comments
 (0)