1
1
<?php
2
2
/**
3
- * (c) Copyright Ascensio System SIA 2021.
3
+ *
4
+ * (c) Copyright Ascensio System SIA 2021
4
5
*
5
6
* Licensed under the Apache License, Version 2.0 (the "License");
6
7
* you may not use this file except in compliance with the License.
13
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
15
* See the License for the specific language governing permissions and
15
16
* limitations under the License.
17
+ *
16
18
*/
19
+
17
20
require_once __DIR__ .'/../../main/inc/global.inc.php ' ;
18
21
19
22
use ChamiloSession as Session ;
20
23
21
24
$ plugin = OnlyofficePlugin::create ();
22
25
23
26
$ mapFileFormat = [
24
- "text " => $ plugin ->get_lang ("document " ),
27
+ "text " => $ plugin ->get_lang ("document " ),
25
28
"spreadsheet " => $ plugin ->get_lang ("spreadsheet " ),
26
- "presentation " => $ plugin ->get_lang ("presentation " ),
29
+ "presentation " => $ plugin ->get_lang ("presentation " )
27
30
];
28
31
29
- $ userId = !empty ($ _GET ["userId " ])? $ _GET ['userId ' ] : 0 ;
30
- $ sessionId = !empty ($ _GET ["sessionId " ])? $ _GET ["sessionId " ] :0 ;
31
- $ docId = !empty ($ _GET ["folderId " ])? $ _GET ["folderId " ] :0 ;
32
- $ courseId = !empty ($ _GET ["courseId " ])? $ _GET ["courseId " ] :0 ;
33
- $ groupId = !empty ($ _GET ["groupId " ])? $ _GET ["groupId " ] :0 ;
34
- $ folderId = !empty ($ _GET ["folderId " ])? $ _GET ["folderId " ] :0 ;
32
+ $ userId = $ _GET ["userId " ];
33
+ $ sessionId = $ _GET ["sessionId " ];
34
+ $ docId = $ _GET ["folderId " ];
35
+ $ courseId = $ _GET ["courseId " ];
35
36
36
37
$ courseInfo = api_get_course_info_by_id ($ courseId );
37
38
$ courseCode = $ courseInfo ["code " ];
38
39
39
- $ isMyDir = false ;
40
- if (!empty ($ docId )) {
41
- $ docInfo = DocumentManager::get_document_data_by_id (
42
- $ docId ,
43
- $ courseCode ,
44
- true ,
45
- $ sessionId
46
- );
47
- $ isMyDir = DocumentManager::is_my_shared_folder (
48
- $ userId ,
49
- $ docInfo ["absolute_path " ],
50
- $ sessionId
51
- );
52
- }
40
+ $ docInfo = DocumentManager::get_document_data_by_id ($ docId , $ courseCode , true , $ sessionId );
41
+
53
42
$ groupRights = Session::read ('group_member_with_upload_rights ' );
54
43
$ isAllowToEdit = api_is_allowed_to_edit (true , true );
44
+ $ isMyDir = DocumentManager::is_my_shared_folder ($ userId , $ docInfo ["absolute_path " ], $ sessionId );
55
45
if (!($ isAllowToEdit || $ isMyDir || $ groupRights )) {
56
46
api_not_allowed (true );
57
47
}
58
48
59
- $ form = new FormValidator (
60
- "doc_create " ,
61
- "post " ,
62
- api_get_path (WEB_PLUGIN_PATH )."onlyoffice/create.php "
63
- );
49
+ $ form = new FormValidator ("doc_create " ,
50
+ "post " ,
51
+ api_get_path (WEB_PLUGIN_PATH ) . "onlyoffice/create.php " );
64
52
65
53
$ form ->addText ("fileName " , $ plugin ->get_lang ("title " ), true );
66
54
$ form ->addSelect ("fileFormat " , $ plugin ->get_lang ("chooseFileFormat " ), $ mapFileFormat );
67
55
$ form ->addButtonCreate ($ plugin ->get_lang ("create " ));
68
56
69
- $ form ->addHidden ("groupId " , $ groupId );
70
- $ form ->addHidden ("courseId " , $ courseId );
71
- $ form ->addHidden ("sessionId " , $ sessionId );
72
- $ form ->addHidden ("userId " , $ userId );
73
- $ form ->addHidden ("folderId " , $ folderId );
74
- $ form ->addHidden ("goBackUrl " , Security::remove_XSS ($ _SERVER ["HTTP_REFERER " ]));
75
- $ goBackUrl = api_get_path (WEB_CODE_PATH ).'document/document.php? ' .api_get_cidreq ();
57
+ $ form ->addHidden ("groupId " , (int ) $ _GET ["groupId " ]);
58
+ $ form ->addHidden ("courseId " , (int ) $ _GET ["courseId " ]);
59
+ $ form ->addHidden ("sessionId " , (int ) $ _GET ["sessionId " ]);
60
+ $ form ->addHidden ("userId " , (int ) $ _GET ["userId " ]);
61
+ $ form ->addHidden ("folderId " , (int ) $ _GET ["folderId " ]);
62
+ $ form ->addHidden ("goBackUrl " , $ _SERVER ["HTTP_REFERER " ]);
76
63
77
64
if ($ form ->validate ()) {
78
65
$ values = $ form ->exportValues ();
82
69
$ groupId = $ values ["groupId " ];
83
70
$ sessionId = $ values ["sessionId " ];
84
71
$ courseId = $ values ["courseId " ];
85
- $ goBackUrl = Security:: remove_XSS ( $ values ["goBackUrl " ]) ;
72
+ $ goBackUrl = $ values ["goBackUrl " ];
86
73
87
74
$ fileType = $ values ["fileFormat " ];
88
75
$ fileExt = FileUtility::getDocExt ($ fileType );
89
- $ fileTitle = Security:: remove_XSS ( $ values ["fileName " ]). ". " . $ fileExt ;
76
+ $ fileTitle = $ values ["fileName " ] . ". " . $ fileExt ;
90
77
91
78
$ courseInfo = api_get_course_info_by_id ($ courseId );
92
79
$ courseCode = $ courseInfo ["code " ];
93
-
80
+
94
81
$ fileNamePrefix = DocumentManager::getDocumentSuffix ($ courseInfo , $ sessionId , $ groupId );
95
- $ fileName = preg_replace ('/\.\./ ' , '' , $ values ["fileName " ]).$ fileNamePrefix .". " .$ fileExt ;
82
+ $ fileName = $ values ["fileName " ] . $ fileNamePrefix . ". " . $ fileExt ;
83
+
96
84
$ groupInfo = GroupManager::get_group_properties ($ groupId );
97
85
98
86
$ emptyTemplatePath = TemplateManager::getEmptyTemplate ($ fileExt );
99
87
100
- $ folderPath = '' ;
101
88
$ fileRelatedPath = "/ " ;
102
89
if (!empty ($ folderId )) {
103
- $ document_data = DocumentManager::get_document_data_by_id (
104
- $ folderId ,
105
- $ courseCode ,
106
- true ,
107
- $ sessionId
108
- );
90
+ $ document_data = DocumentManager::get_document_data_by_id ($ folderId , $ courseCode , true , $ sessionId );
109
91
$ folderPath = $ document_data ["absolute_path " ];
110
- $ fileRelatedPath = $ fileRelatedPath. substr ($ document_data ["absolute_path_from_document " ], 10 ). "/ " . $ fileName ;
92
+ $ fileRelatedPath = $ fileRelatedPath . substr ($ document_data ["absolute_path_from_document " ], 10 ) . "/ " . $ fileName ;
111
93
} else {
112
- $ folderPath = api_get_path (SYS_COURSE_PATH ). api_get_course_path ($ courseCode ). "/document " ;
94
+ $ folderPath = api_get_path (SYS_COURSE_PATH ) . api_get_course_path ($ courseCode ) . "/document " ;
113
95
if (!empty ($ groupId )) {
114
- $ folderPath = $ folderPath. "/ " . $ groupInfo ["directory " ];
115
- $ fileRelatedPath = $ groupInfo ["directory " ]. "/ " ;
96
+ $ folderPath = $ folderPath . "/ " . $ groupInfo ["directory " ];
97
+ $ fileRelatedPath = $ groupInfo ["directory " ] . "/ " ;
116
98
}
117
- $ fileRelatedPath = $ fileRelatedPath. $ fileName ;
99
+ $ fileRelatedPath = $ fileRelatedPath . $ fileName ;
118
100
}
119
- $ filePath = $ folderPath. "/ " . $ fileName ;
101
+ $ filePath = $ folderPath . "/ " . $ fileName ;
120
102
121
103
if (file_exists ($ filePath )) {
122
104
Display::addFlash (Display::return_message ($ plugin ->get_lang ("fileIsExist " ), "error " ));
130
112
131
113
chmod ($ filePath , api_get_permissions_for_new_files ());
132
114
133
- $ documentId = add_document (
134
- $ courseInfo ,
135
- $ fileRelatedPath ,
136
- "file " ,
137
- filesize ($ filePath ),
138
- $ fileTitle ,
139
- null ,
140
- false
141
- );
115
+ $ documentId = add_document ($ courseInfo ,
116
+ $ fileRelatedPath ,
117
+ "file " ,
118
+ filesize ($ filePath ),
119
+ $ fileTitle ,
120
+ null ,
121
+ false );
142
122
if ($ documentId ) {
143
- api_item_property_update (
144
- $ courseInfo ,
145
- TOOL_DOCUMENT ,
146
- $ documentId ,
147
- "DocumentAdded " ,
148
- $ userId ,
149
- $ groupInfo ,
150
- null ,
151
- null ,
152
- null ,
153
- $ sessionId
154
- );
155
-
156
- header ("Location: " .$ goBackUrl );
123
+ api_item_property_update ($ courseInfo ,
124
+ TOOL_DOCUMENT ,
125
+ $ documentId ,
126
+ "DocumentAdded " ,
127
+ $ userId ,
128
+ $ groupInfo ,
129
+ null ,
130
+ null ,
131
+ null ,
132
+ $ sessionId );
133
+
134
+ header ("Location: " . $ goBackUrl );
157
135
exit ();
158
136
}
137
+
159
138
} else {
160
- Display::addFlash (
161
- Display::return_message (
162
- $ plugin ->get_lang ("impossibleCreateFile " ),
163
- "error "
164
- )
165
- );
139
+ Display::addFlash (Display::return_message ($ plugin ->get_lang ("impossibleCreateFile " ), "error " ));
166
140
}
167
141
}
168
142
169
143
display:
170
- $ goBackUrl = $ goBackUrl ?: Security:: remove_XSS ( $ _SERVER ["HTTP_REFERER " ]) ;
171
- $ actionsLeft = '<a href=" ' .$ goBackUrl. '"> ' . Display::return_icon ("back.png " , get_lang ("Back " ). " " . get_lang ("To " ). " " . get_lang ("DocumentsOverview " ), "" , ICON_SIZE_MEDIUM ). "</a> " ;
144
+ $ 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> " ;
172
146
173
147
Display::display_header ($ plugin ->get_lang ("createNewDocument " ));
174
148
echo Display::toolbarAction ("actions-documents " , [$ actionsLeft ]);
175
149
echo $ form ->returnForm ();
176
150
Display::display_footer ();
151
+ ?>
0 commit comments