-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreate.php
111 lines (96 loc) · 3.88 KB
/
create.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* (c) Copyright Ascensio System SIA 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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();
$appSettings = new OnlyofficeAppsettings($plugin);
$documentManager = new OnlyofficeDocumentManager($appSettings, []);
$mapFileFormat = [
'text' => $plugin->get_lang('document'),
'spreadsheet' => $plugin->get_lang('spreadsheet'),
'presentation' => $plugin->get_lang('presentation'),
'formTemplate' => $plugin->get_lang('formTemplate'),
];
$userId = !empty($_GET['userId']) ? $_GET['userId'] : 0;
$sessionId = !empty($_GET['sessionId']) ? $_GET['sessionId'] : 0;
$courseId = !empty($_GET['courseId']) ? $_GET['courseId'] : 0;
$groupId = !empty($_GET['groupId']) ? $_GET['groupId'] : 0;
$folderId = !empty($_GET['folderId']) ? $_GET['folderId'] : 0;
$courseInfo = api_get_course_info_by_id($courseId);
$courseCode = $courseInfo['code'];
$isMyDir = false;
if (!empty($folderId)) {
$folderInfo = DocumentManager::get_document_data_by_id(
$folderId,
$courseCode,
true,
$sessionId
);
$isMyDir = DocumentManager::is_my_shared_folder(
$userId,
$folderInfo['absolute_path'],
$sessionId
);
}
$groupRights = Session::read('group_member_with_upload_rights');
$isAllowToEdit = api_is_allowed_to_edit(true, true);
if (!($isAllowToEdit || $isMyDir || $groupRights)) {
api_not_allowed(true);
}
$form = new FormValidator(
'doc_create',
'post',
api_get_path(WEB_PLUGIN_PATH).'onlyoffice/create.php?userId='.Security::remove_XSS($userId)
.'&groupId='.Security::remove_XSS($groupId)
.'&courseId='.Security::remove_XSS($courseId)
.'&sessionId='.Security::remove_XSS($sessionId)
.'&folderId='.Security::remove_XSS($folderId)
);
$form->addText('fileName', $plugin->get_lang('title'), true);
$form->addSelect('fileFormat', $plugin->get_lang('chooseFileFormat'), $mapFileFormat);
$form->addButtonCreate($plugin->get_lang('create'));
if ($form->validate()) {
$values = $form->exportValues();
$fileType = $values['fileFormat'];
$fileExt = $documentManager->getDocExtByType($fileType);
$result = OnlyofficeDocumentManager::createFile(
$values['fileName'],
$fileExt,
$folderId,
$userId,
$sessionId,
$courseId,
$groupId
);
if (isset($result['error'])) {
Display::addFlash(
Display::return_message(
$plugin->get_lang($result['error']),
'error'
)
);
} else {
header('Location: '.OnlyofficeDocumentManager::getUrlToLocation($courseCode, $sessionId, $groupId, $folderId));
exit;
}
}
$goBackUrl = OnlyofficeDocumentManager::getUrlToLocation($courseCode, $sessionId, $groupId, $folderId);
$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();