1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
use ChamiloSession as Session; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* This file allows editing documents. |
8
|
|
|
* |
9
|
|
|
* Based on create_document, this file allows |
10
|
|
|
* - edit name |
11
|
|
|
* - edit comments |
12
|
|
|
* - edit metadata (requires a document table entry) |
13
|
|
|
* - edit html content (only for htm/html files) |
14
|
|
|
* |
15
|
|
|
* For all files |
16
|
|
|
* - show editable name field |
17
|
|
|
* - show editable comments field |
18
|
|
|
* Additionally, for html and text files |
19
|
|
|
* - show RTE |
20
|
|
|
* |
21
|
|
|
* Remember, all files and folders must always have an entry in the |
22
|
|
|
* database, regardless of wether they are visible/invisible, have |
23
|
|
|
* comments or not. |
24
|
|
|
* |
25
|
|
|
* @package chamilo.document |
26
|
|
|
* |
27
|
|
|
* @todo improve script structure (FormValidator is used to display form, but |
28
|
|
|
* not for validation at the moment) |
29
|
|
|
*/ |
30
|
|
|
require_once __DIR__.'/../inc/global.inc.php'; |
31
|
|
|
|
32
|
|
|
$groupRights = Session::read('group_member_with_upload_rights'); |
33
|
|
|
|
34
|
|
|
// Template's javascript |
35
|
|
|
$htmlHeadXtra[] = ' |
36
|
|
|
<script> |
37
|
|
|
$(function() { |
38
|
|
|
$(".scrollbar-light").scrollbar(); |
39
|
|
|
|
40
|
|
|
expandColumnToogle("#hide_bar_template", { |
41
|
|
|
selector: "#template_col", |
42
|
|
|
width: 3 |
43
|
|
|
}, { |
44
|
|
|
selector: "#doc_form", |
45
|
|
|
width: 9 |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
CKEDITOR.on("instanceReady", function (e) { |
49
|
|
|
showTemplates(); |
50
|
|
|
|
51
|
|
|
e.editor.on("beforeCommandExec", function (event) { |
52
|
|
|
if (event.data.name == "save") { |
53
|
|
|
$("#formEdit").append("<input type=hidden name=button_ck value=1 />"); |
54
|
|
|
} |
55
|
|
|
}); |
56
|
|
|
}); |
57
|
|
|
}); |
58
|
|
|
|
59
|
|
|
</script>'; |
60
|
|
|
|
61
|
|
|
$this_section = SECTION_COURSES; |
62
|
|
|
$lib_path = api_get_path(LIBRARY_PATH); |
63
|
|
|
|
64
|
|
|
$course_info = api_get_course_info(); |
65
|
|
|
$group_id = api_get_group_id(); |
66
|
|
|
$sessionId = api_get_session_id(); |
67
|
|
|
$dir = '/'; |
68
|
|
|
$currentDirPath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null; |
69
|
|
|
$readonly = false; |
70
|
|
|
if (isset($_GET['id'])) { |
71
|
|
|
$document_data = DocumentManager::get_document_data_by_id( |
72
|
|
|
$_GET['id'], |
73
|
|
|
api_get_course_id(), |
74
|
|
|
true, |
75
|
|
|
0 |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
if (!empty($sessionId) && empty($document_data)) { |
79
|
|
|
$document_data = DocumentManager::get_document_data_by_id( |
80
|
|
|
$_REQUEST['id'], |
81
|
|
|
api_get_course_id(), |
82
|
|
|
true, |
83
|
|
|
$sessionId |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$document_id = $document_data['id']; |
88
|
|
|
$file = $document_data['path']; |
89
|
|
|
$parent_id = DocumentManager::get_document_id($course_info, dirname($file)); |
90
|
|
|
$dir = dirname($document_data['path']); |
91
|
|
|
$dir_original = $dir; |
92
|
|
|
$doc = basename($file); |
93
|
|
|
$readonly = $document_data['readonly']; |
94
|
|
|
$file_type = $document_data['filetype']; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
if (empty($document_data)) { |
98
|
|
|
api_not_allowed(true); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if (api_is_in_group()) { |
102
|
|
|
$group_properties = GroupManager::get_group_properties($group_id); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$is_certificate_mode = DocumentManager::is_certificate_mode($dir); |
106
|
|
|
|
107
|
|
|
//Call from |
108
|
|
|
$call_from_tool = api_get_origin(); |
109
|
|
|
$slide_id = isset($_GET['origin_opt']) ? Security::remove_XSS($_GET['origin_opt']) : null; |
110
|
|
|
$file_name = $doc; |
111
|
|
|
$group_document = false; |
112
|
|
|
$_course = api_get_course_info(); |
113
|
|
|
$sessionId = api_get_session_id(); |
114
|
|
|
$user_id = api_get_user_id(); |
115
|
|
|
$doc_tree = explode('/', $file); |
116
|
|
|
$count_dir = count($doc_tree) - 2; // "2" because at the begin and end there are 2 "/" |
117
|
|
|
|
118
|
|
|
// Level correction for group documents. |
119
|
|
|
if (!empty($group_properties['directory'])) { |
120
|
|
|
$count_dir = $count_dir > 0 ? $count_dir - 1 : 0; |
121
|
|
|
} |
122
|
|
|
$relative_url = ''; |
123
|
|
|
for ($i = 0; $i < ($count_dir); $i++) { |
124
|
|
|
$relative_url .= '../'; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
$editorConfig = [ |
128
|
|
|
'ToolbarSet' => (api_is_allowed_to_edit(null, true) ? 'Documents' : 'DocumentsStudent'), |
129
|
|
|
'Width' => '100%', |
130
|
|
|
'Height' => '400', |
131
|
|
|
'cols-size' => [2, 10, 0], |
132
|
|
|
'FullPage' => true, |
133
|
|
|
'InDocument' => true, |
134
|
|
|
'CreateDocumentDir' => $relative_url, |
135
|
|
|
'CreateDocumentWebDir' => (empty($group_properties['directory'])) |
136
|
|
|
? api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/' |
137
|
|
|
: api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/', |
138
|
|
|
'BaseHref' => api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir, |
139
|
|
|
]; |
140
|
|
|
|
141
|
|
|
if ($is_certificate_mode) { |
142
|
|
|
$editorConfig['CreateDocumentDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/'; |
143
|
|
|
$editorConfig['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/'; |
144
|
|
|
$editorConfig['BaseHref'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
$is_allowed_to_edit = api_is_allowed_to_edit(null, true) || $groupRights || |
148
|
|
|
DocumentManager::is_my_shared_folder(api_get_user_id(), $dir, $sessionId); |
149
|
|
|
|
150
|
|
|
$dbTable = Database::get_course_table(TABLE_DOCUMENT); |
151
|
|
|
$course_id = api_get_course_int_id(); |
152
|
|
|
|
153
|
|
|
if (!empty($group_id)) { |
154
|
|
|
$interbreadcrumb[] = [ |
155
|
|
|
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(), |
156
|
|
|
'name' => get_lang('GroupSpace'), |
157
|
|
|
]; |
158
|
|
|
$group_document = true; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
if (!$is_certificate_mode) { |
162
|
|
|
$interbreadcrumb[] = [ |
163
|
|
|
"url" => api_get_path(WEB_CODE_PATH)."document/document.php?curdirpath=".urlencode($currentDirPath).'&'.api_get_cidreq(), |
164
|
|
|
"name" => get_lang('Documents'), |
165
|
|
|
]; |
166
|
|
|
} else { |
167
|
|
|
$interbreadcrumb[] = [ |
168
|
|
|
'url' => Category::getUrl(), |
169
|
|
|
'name' => get_lang('Gradebook'), |
170
|
|
|
]; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
if (empty($document_data['parents'])) { |
174
|
|
|
$interbreadcrumb[] = ['url' => '#', 'name' => $document_data['title']]; |
175
|
|
|
} else { |
176
|
|
|
foreach ($document_data['parents'] as $document_sub_data) { |
177
|
|
|
if ($document_data['title'] == $document_sub_data['title']) { |
178
|
|
|
continue; |
179
|
|
|
} |
180
|
|
|
$interbreadcrumb[] = ['url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']]; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
if (!($is_allowed_to_edit || |
185
|
|
|
$groupRights || |
186
|
|
|
DocumentManager::is_my_shared_folder($user_id, $dir, api_get_session_id())) |
187
|
|
|
) { |
188
|
|
|
api_not_allowed(true); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
Event::event_access_tool(TOOL_DOCUMENT); |
|
|
|
|
192
|
|
|
|
193
|
|
|
//TODO:check the below code and his funcionality |
194
|
|
|
if (!api_is_allowed_to_edit()) { |
195
|
|
|
if (DocumentManager::check_readonly($course_info, $user_id, $file)) { |
196
|
|
|
api_not_allowed(); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
$document_info = api_get_item_property_info( |
201
|
|
|
api_get_course_int_id(), |
202
|
|
|
'document', |
203
|
|
|
$document_id, |
204
|
|
|
0 |
205
|
|
|
); |
206
|
|
|
|
207
|
|
|
// Try to find this document in the session |
208
|
|
|
if (!empty($sessionId)) { |
209
|
|
|
$document_info = api_get_item_property_info( |
210
|
|
|
api_get_course_int_id(), |
211
|
|
|
'document', |
212
|
|
|
$document_id, |
213
|
|
|
$sessionId |
214
|
|
|
); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
if (api_is_in_group()) { |
218
|
|
|
$group_properties = GroupManager::get_group_properties($group_id); |
219
|
|
|
GroupManager::allowUploadEditDocument( |
220
|
|
|
api_get_user_id(), |
221
|
|
|
api_get_course_int_id(), |
222
|
|
|
$group_properties, |
223
|
|
|
$document_info, |
224
|
|
|
true |
225
|
|
|
); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/* MAIN TOOL CODE */ |
229
|
|
|
/* Code to change the comment */ |
230
|
|
|
if (isset($_POST['comment'])) { |
231
|
|
|
// Fixing the path if it is wrong |
232
|
|
|
$comment = trim($_POST['comment']); |
233
|
|
|
$title = trim($_POST['title']); |
234
|
|
|
|
235
|
|
|
// Just in case see BT#3525 |
236
|
|
|
if (empty($title)) { |
237
|
|
|
$title = $document_data['title']; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
if (empty($title)) { |
241
|
|
|
$title = get_document_title($_POST['filename']); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
if (!empty($document_id)) { |
245
|
|
|
$linkExists = false; |
246
|
|
|
if ($file_type == 'link') { |
247
|
|
|
$linkExists = DocumentManager::cloudLinkExists($course_info, $file, $_POST['comment']); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
if (!$linkExists || $linkExists == $document_id) { |
251
|
|
|
$params = [ |
252
|
|
|
'comment' => $comment, |
253
|
|
|
'title' => $title, |
254
|
|
|
]; |
255
|
|
|
Database::update( |
256
|
|
|
$dbTable, |
257
|
|
|
$params, |
258
|
|
|
['c_id = ? AND id = ?' => [$course_id, $document_id]] |
259
|
|
|
); |
260
|
|
|
|
261
|
|
|
if ($file_type != 'link') { |
262
|
|
|
Display::addFlash(Display::return_message(get_lang('fileModified'))); |
263
|
|
|
} else { |
264
|
|
|
Display::addFlash(Display::return_message(get_lang('CloudLinkModified'))); |
265
|
|
|
} |
266
|
|
|
} else { |
267
|
|
|
Display::addFlash(Display::return_message(get_lang('UrlAlreadyExists'), 'warning')); |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/* WYSIWYG HTML EDITOR - Program Logic */ |
273
|
|
|
if ($is_allowed_to_edit) { |
274
|
|
|
if (isset($_POST['formSent']) && $_POST['formSent'] == 1 && !empty($document_id)) { |
275
|
|
|
//$content = isset($_POST['content']) ? trim(str_replace(["\r", "\n"], '', stripslashes($_POST['content']))) : null; |
276
|
|
|
$content = isset($_POST['content']) ? trim(stripslashes($_POST['content'])) : null; |
277
|
|
|
$content = Security::remove_XSS($content, COURSEMANAGERLOWSECURITY); |
278
|
|
|
if ($dir == '/') { |
279
|
|
|
$dir = ''; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
$read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null; |
283
|
|
|
$read_only_flag = empty($read_only_flag) ? 0 : 1; |
284
|
|
|
|
285
|
|
|
if ($file_type != 'link') { |
286
|
|
|
$file_size = filesize($document_data['absolute_path']); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
if ($read_only_flag == 0) { |
290
|
|
|
if (!empty($content)) { |
291
|
|
|
if ($fp = @fopen($document_data['absolute_path'], 'w')) { |
292
|
|
|
// For flv player, change absolute path temporarily to prevent |
293
|
|
|
// from erasing it in the following lines |
294
|
|
|
$content = str_replace(['flv=h', 'flv=/'], ['flv=h|', 'flv=/|'], $content); |
295
|
|
|
fputs($fp, $content); |
296
|
|
|
fclose($fp); |
297
|
|
|
$filepath = $document_data['absolute_parent_path']; |
298
|
|
|
|
299
|
|
|
update_existing_document( |
300
|
|
|
$_course, |
301
|
|
|
$document_id, |
302
|
|
|
$file_size, |
303
|
|
|
$read_only_flag |
304
|
|
|
); |
305
|
|
|
api_item_property_update( |
306
|
|
|
$_course, |
307
|
|
|
TOOL_DOCUMENT, |
308
|
|
|
$document_id, |
309
|
|
|
'DocumentUpdated', |
310
|
|
|
api_get_user_id(), |
311
|
|
|
null, |
312
|
|
|
null, |
313
|
|
|
null, |
314
|
|
|
null, |
315
|
|
|
$sessionId |
316
|
|
|
); |
317
|
|
|
// Update parent folders |
318
|
|
|
item_property_update_on_folder( |
319
|
|
|
$_course, |
320
|
|
|
$dir, |
321
|
|
|
api_get_user_id() |
322
|
|
|
); |
323
|
|
|
} else { |
324
|
|
|
Display::addFlash(Display::return_message(get_lang('Impossible'), 'warning')); |
325
|
|
|
} |
326
|
|
|
} else { |
327
|
|
|
if ($document_id) { |
328
|
|
|
update_existing_document($_course, $document_id, $file_size, $read_only_flag); |
329
|
|
|
} |
330
|
|
|
} |
331
|
|
|
} else { |
332
|
|
|
if ($document_id) { |
333
|
|
|
update_existing_document($_course, $document_id, $file_size, $read_only_flag); |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
// It saves extra fields values |
338
|
|
|
$extraFieldValue = new ExtraFieldValue('document'); |
339
|
|
|
$values = $_REQUEST; |
340
|
|
|
$values['item_id'] = $document_id; |
341
|
|
|
$extraFieldValue->saveFieldValues($values); |
342
|
|
|
|
343
|
|
|
$url = 'document.php?id='.$document_data['parent_id'].'&'.api_get_cidreq().($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : ''); |
344
|
|
|
|
345
|
|
|
$redirectToEditPage = isset($_POST['button_ck']) && 1 === (int) $_POST['button_ck']; |
346
|
|
|
if ($redirectToEditPage) { |
347
|
|
|
$url = 'edit_document.php?'.api_get_cidreq().'&id='.$document_id.($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : ''); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
header('Location: '.$url); |
351
|
|
|
exit; |
352
|
|
|
} |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
// Replace relative paths by absolute web paths (e.g. './' => 'http://www.chamilo.org/courses/ABC/document/') |
356
|
|
|
$content = null; |
357
|
|
|
$extension = null; |
358
|
|
|
$filename = null; |
359
|
|
|
if (file_exists($document_data['absolute_path'])) { |
360
|
|
|
$path_info = pathinfo($document_data['absolute_path']); |
361
|
|
|
$filename = $path_info['filename']; |
362
|
|
|
|
363
|
|
|
if (is_file($document_data['absolute_path'])) { |
364
|
|
|
$extension = $path_info['extension']; |
365
|
|
|
|
366
|
|
|
if (in_array($extension, ['html', 'htm'])) { |
367
|
|
|
$content = file($document_data['absolute_path']); |
368
|
|
|
$content = implode('', $content); |
369
|
|
|
} |
370
|
|
|
} |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
// Display the header |
374
|
|
|
$nameTools = get_lang('EditDocument').': '.Security::remove_XSS($document_data['title']); |
375
|
|
|
Display::display_header($nameTools, 'Doc'); |
376
|
|
|
|
377
|
|
|
$owner_id = $document_info['insert_user_id']; |
378
|
|
|
$last_edit_date = $document_info['lastedit_date']; |
379
|
|
|
$createdDate = $document_info['insert_date']; |
380
|
|
|
$groupInfo = GroupManager::get_group_properties(api_get_group_id()); |
381
|
|
|
|
382
|
|
|
if ($owner_id == api_get_user_id() || |
383
|
|
|
api_is_platform_admin() || |
384
|
|
|
$is_allowed_to_edit || GroupManager::is_user_in_group( |
385
|
|
|
api_get_user_id(), |
386
|
|
|
$groupInfo |
387
|
|
|
) |
388
|
|
|
) { |
389
|
|
|
$action = api_get_self().'?id='.$document_data['id'].'&'.api_get_cidreq(); |
390
|
|
|
if ($is_certificate_mode) { |
391
|
|
|
$action .= '&curdirpath=/certificates&selectcat=1'; |
392
|
|
|
} |
393
|
|
|
$form = new FormValidator( |
394
|
|
|
'formEdit', |
395
|
|
|
'post', |
396
|
|
|
$action, |
397
|
|
|
null, |
398
|
|
|
['class' => 'form-vertical'] |
399
|
|
|
); |
400
|
|
|
|
401
|
|
|
// Form title |
402
|
|
|
$form->addHeader($nameTools); |
403
|
|
|
$key_label_title = $file_type != 'link' ? 'Title' : 'LinkName'; |
404
|
|
|
$form->addText( |
405
|
|
|
'title', |
406
|
|
|
get_lang($key_label_title), |
407
|
|
|
true, |
408
|
|
|
['cols-size' => [2, 10, 0], 'autofocus'] |
409
|
|
|
); |
410
|
|
|
|
411
|
|
|
$defaults['title'] = $document_data['title']; |
412
|
|
|
$read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null; |
413
|
|
|
|
414
|
|
|
// Desactivation of IE proprietary commenting tags inside the text before loading it on the online editor. |
415
|
|
|
// This fix has been proposed by Hubert Borderiou, see Bug #573, http://support.chamilo.org/issues/573 |
416
|
|
|
$defaults['content'] = str_replace('<!--[', '<!-- [', $content); |
417
|
|
|
// HotPotatoes tests are html files, but they should not be edited in order their functionality to be preserved. |
418
|
|
|
$showSystemFolders = api_get_course_setting('show_system_folders'); |
419
|
|
|
$condition = stripos($dir, '/HotPotatoes_files') === false; |
420
|
|
|
if ($showSystemFolders == 1) { |
421
|
|
|
$condition = true; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
if (($extension == 'htm' || $extension == 'html') && $condition) { |
425
|
|
|
if (empty($readonly) && $readonly == 0) { |
426
|
|
|
$form->addHtmlEditor('content', get_lang('Content'), true, true, $editorConfig); |
427
|
|
|
} |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
if (!empty($createdDate)) { |
431
|
|
|
$form->addLabel(get_lang('CreatedOn'), Display::dateToStringAgoAndLongDate($createdDate)); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
if ($file_type != 'link') { |
435
|
|
|
if (!$group_document && !DocumentManager::is_my_shared_folder(api_get_user_id(), $currentDirPath, $sessionId)) { |
436
|
|
|
$form->addLabel(get_lang('UpdatedOn'), Display::dateToStringAgoAndLongDate($last_edit_date)); |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
if (!empty($document_info['insert_user_id'])) { |
440
|
|
|
$insertByUserInfo = api_get_user_info($document_info['insert_user_id']); |
441
|
|
|
if (!empty($insertByUserInfo)) { |
442
|
|
|
$form->addLabel(get_lang('Author'), $insertByUserInfo['complete_name_with_message_link']); |
443
|
|
|
} |
444
|
|
|
} |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
if ($file_type == 'link') { |
448
|
|
|
// URLs in whitelist |
449
|
|
|
$urlWL = DocumentManager::getFileHostingWhiteList(); |
450
|
|
|
sort($urlWL); |
451
|
|
|
//Matches any of the whitelisted urls preceded by // or . |
452
|
|
|
$urlWLRegEx = '/(\/\/|\.)('.implode('|', $urlWL).')/i'; |
453
|
|
|
$urlWLText = "\n\t* ".implode("\n\t* ", $urlWL); |
454
|
|
|
$urlWLHTML = "<ul><li>".implode("</li><li>", $urlWL)."</li></ul>"; |
455
|
|
|
$form->addText('comment', get_lang('Url')); |
456
|
|
|
$form->addElement( |
457
|
|
|
'static', |
458
|
|
|
'info', |
459
|
|
|
'', |
460
|
|
|
'<span class="text-primary" data-toggle="tooltip" title="'.$urlWLHTML.'">'.get_lang( |
461
|
|
|
'ValidDomainList' |
462
|
|
|
).' <span class="glyphicon glyphicon-question-sign"></span></span>' |
463
|
|
|
); |
464
|
|
|
} else { |
465
|
|
|
$form->addElement('textarea', 'comment', get_lang('Comment'), ['cols-size' => [2, 10, 0]]); |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
$itemId = isset($_GET['id']) ? (int) $_GET['id'] : 0; |
469
|
|
|
$extraField = new ExtraField('document'); |
470
|
|
|
$extraField->addElements( |
471
|
|
|
$form, |
472
|
|
|
$itemId, |
473
|
|
|
[], //exclude |
474
|
|
|
false, // filter |
475
|
|
|
false, // tag as select |
476
|
|
|
[], //show only fields |
477
|
|
|
[], // order fields |
478
|
|
|
[] // extra data |
479
|
|
|
); |
480
|
|
|
|
481
|
|
|
if ($file_type != 'link') { |
482
|
|
|
if ($owner_id == api_get_user_id() || api_is_platform_admin()) { |
483
|
|
|
$checked = &$form->addElement('checkbox', 'readonly', null, get_lang('ReadOnly')); |
484
|
|
|
if ($readonly == 1) { |
485
|
|
|
$checked->setChecked(true); |
486
|
|
|
} |
487
|
|
|
} |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
if ($file_type == 'link') { |
491
|
|
|
$form->addRule('title', get_lang('PleaseEnterCloudLinkName'), 'required'); |
492
|
|
|
$form->addRule('comment', get_lang('PleaseEnterURL'), 'required'); |
493
|
|
|
// Well formed url pattern (must have the protocol) |
494
|
|
|
$urlRegEx = DocumentManager::getWellFormedUrlRegex(); |
495
|
|
|
$form->addRule('comment', get_lang('NotValidURL'), 'regex', $urlRegEx, 'client'); |
496
|
|
|
$form->addRule('comment', get_lang('NotValidURL'), 'regex', $urlRegEx, 'server'); |
497
|
|
|
$form->addRule('comment', get_lang('NotValidDomain').$urlWLText, 'regex', $urlWLRegEx, 'client'); |
498
|
|
|
$form->addRule('comment', get_lang('NotValidDomain').$urlWLHTML, 'regex', $urlWLRegEx, 'server'); |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
if ($is_certificate_mode) { |
502
|
|
|
$form->addButtonUpdate(get_lang('SaveCertificate')); |
503
|
|
|
} elseif ($file_type == 'link') { |
504
|
|
|
$form->addButtonUpdate(get_lang('SaveLink')); |
505
|
|
|
} else { |
506
|
|
|
$form->addButtonUpdate(get_lang('SaveDocument')); |
507
|
|
|
} |
508
|
|
|
$form->addHidden('formSent', 1); |
509
|
|
|
$form->addHidden('filename', $filename); |
510
|
|
|
|
511
|
|
|
$defaults['extension'] = $extension; |
512
|
|
|
$defaults['file_path'] = isset($_GET['file']) ? Security::remove_XSS($_GET['file']) : null; |
513
|
|
|
$defaults['commentPath'] = $file; |
514
|
|
|
$defaults['renameTo'] = $file_name; |
515
|
|
|
$defaults['comment'] = $document_data['comment']; |
516
|
|
|
$defaults['origin'] = api_get_origin(); |
517
|
|
|
$defaults['origin_opt'] = isset($_GET['origin_opt']) ? Security::remove_XSS($_GET['origin_opt']) : null; |
518
|
|
|
|
519
|
|
|
$form->setDefaults($defaults); |
520
|
|
|
|
521
|
|
|
show_return( |
522
|
|
|
$parent_id, |
523
|
|
|
$dir_original, |
524
|
|
|
$call_from_tool, |
525
|
|
|
$slide_id, |
526
|
|
|
$is_certificate_mode |
527
|
|
|
); |
528
|
|
|
|
529
|
|
|
if ($is_certificate_mode) { |
530
|
|
|
$all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate( |
531
|
|
|
api_get_user_id(), |
532
|
|
|
api_get_course_id(), |
533
|
|
|
api_get_session_id() |
534
|
|
|
); |
535
|
|
|
$str_info = ''; |
536
|
|
|
foreach ($all_information_by_create_certificate[0] as $info_value) { |
537
|
|
|
$str_info .= $info_value.'<br/>'; |
538
|
|
|
} |
539
|
|
|
$create_certificate = get_lang('CreateCertificateWithTags'); |
540
|
|
|
echo Display::return_message( |
541
|
|
|
$create_certificate.': <br /><br />'.$str_info, |
542
|
|
|
'normal', |
543
|
|
|
false |
544
|
|
|
); |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
if ($extension == 'svg' && !api_browser_support('svg') && |
548
|
|
|
api_get_setting('enabled_support_svg') == 'true' |
549
|
|
|
) { |
550
|
|
|
echo Display::return_message(get_lang('BrowserDontSupportsSVG'), 'warning'); |
551
|
|
|
} |
552
|
|
|
if ($file_type != 'link') { |
553
|
|
|
// HTML-editor |
554
|
|
|
echo '<div class="page-create"> |
555
|
|
|
<div class="row" style="overflow:hidden"> |
556
|
|
|
<div id="template_col" class="col-md-3"> |
557
|
|
|
<div class="panel panel-default"> |
558
|
|
|
<div class="panel-body"> |
559
|
|
|
<div id="frmModel" class="items-templates scrollbar-light"></div> |
560
|
|
|
</div> |
561
|
|
|
</div> |
562
|
|
|
</div> |
563
|
|
|
<div id="doc_form" class="col-md-9"> |
564
|
|
|
'.$form->returnForm().' |
565
|
|
|
</div> |
566
|
|
|
</div></div>'; |
567
|
|
|
} else { |
568
|
|
|
// Add tooltip and correctly parse its inner HTML |
569
|
|
|
echo '<script> |
570
|
|
|
$(function() { |
571
|
|
|
$("[data-toggle=\'tooltip\']").tooltip( |
572
|
|
|
{ |
573
|
|
|
content: |
574
|
|
|
function() { |
575
|
|
|
return $(this).attr("title"); |
576
|
|
|
} |
577
|
|
|
} |
578
|
|
|
); |
579
|
|
|
}); |
580
|
|
|
</script>'; |
581
|
|
|
|
582
|
|
|
echo $form->returnForm(); |
583
|
|
|
} |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
Display::display_footer(); |
587
|
|
|
|
588
|
|
|
// return button back to |
589
|
|
|
function show_return($document_id, $path, $call_from_tool = '', $slide_id = 0, $is_certificate_mode = false) |
590
|
|
|
{ |
591
|
|
|
$actionsLeft = null; |
592
|
|
|
global $parent_id; |
593
|
|
|
$url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id='.$parent_id; |
594
|
|
|
|
595
|
|
|
if ($is_certificate_mode) { |
596
|
|
|
$selectedCategory = (isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : ''); |
597
|
|
|
$actionsLeft .= '<a href="document.php?curdirpath='.$selectedCategory.'&selectcat='.$selectedCategory.'">'. |
598
|
|
|
Display::return_icon('back.png', get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview'), '', ICON_SIZE_MEDIUM).'</a>'; |
599
|
|
|
$actionsLeft .= '<a id="hide_bar_template" href="#" role="button">'.Display::return_icon('expand.png', get_lang('Expand'), ['id' => 'expand'], ICON_SIZE_MEDIUM).Display::return_icon('contract.png', get_lang('Collapse'), ['id' => 'contract', 'class' => 'hide'], ICON_SIZE_MEDIUM).'</a>'; |
600
|
|
|
} elseif ($call_from_tool == 'slideshow') { |
601
|
|
|
$actionsLeft .= '<a href="'.api_get_path(WEB_PATH).'main/document/slideshow.php?slide_id='.$slide_id.'&curdirpath='.Security::remove_XSS(urlencode($_GET['curdirpath'])).'">'. |
602
|
|
|
Display::return_icon('slideshow.png', get_lang('BackTo').' '.get_lang('ViewSlideshow'), '', ICON_SIZE_MEDIUM).'</a>'; |
603
|
|
|
} elseif ($call_from_tool == 'editdraw') { |
604
|
|
|
$actionsLeft .= '<a href="'.$url.'">'. |
605
|
|
|
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM).'</a>'; |
606
|
|
|
$actionsLeft .= '<a href="javascript:history.back(1)">'.Display::return_icon('draw.png', get_lang('BackTo').' '.get_lang('Draw'), [], 32).'</a>'; |
607
|
|
|
} elseif ($call_from_tool == 'editodf') { |
608
|
|
|
$actionsLeft .= '<a href="'.$url.'">'. |
609
|
|
|
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM).'</a>'; |
610
|
|
|
$actionsLeft .= '<a href="javascript:history.back(1)">'.Display::return_icon('draw.png', get_lang('BackTo').' '.get_lang('Write'), [], 32).'</a>'; |
611
|
|
|
$actionsLeft .= '<a id="hide_bar_template" href="#" role="button">'.Display::return_icon('expand.png', get_lang('Expand'), ['id' => 'expand'], ICON_SIZE_MEDIUM).Display::return_icon('contract.png', get_lang('Collapse'), ['id' => 'contract', 'class' => 'hide'], ICON_SIZE_MEDIUM).'</a>'; |
612
|
|
|
} elseif ($call_from_tool == 'editpaint' && api_get_setting('enabled_support_pixlr') === 'true') { |
613
|
|
|
$actionsLeft .= '<a href="'.$url.'">'. |
614
|
|
|
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), [], ICON_SIZE_MEDIUM).'</a>'; |
615
|
|
|
$actionsLeft .= '<a href="javascript:history.back(1)">'.Display::return_icon('paint.png', get_lang('BackTo').' '.get_lang('Paint'), [], 32).'</a>'; |
616
|
|
|
} else { |
617
|
|
|
$actionsLeft .= '<a href="'.$url.'">'. |
618
|
|
|
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM).'</a>'; |
619
|
|
|
$actionsLeft .= '<a id="hide_bar_template" href="#" role="button">'.Display::return_icon('expand.png', get_lang('Expand'), ['id' => 'expand'], ICON_SIZE_MEDIUM).Display::return_icon('contract.png', get_lang('Collapse'), ['id' => 'contract', 'class' => 'hide'], ICON_SIZE_MEDIUM).'</a>'; |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
echo $toolbar = Display::toolbarAction('actions-documents', [$actionsLeft]); |
623
|
|
|
} |
624
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.