forked from chilek/lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattachments.php
119 lines (103 loc) · 3.28 KB
/
attachments.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
112
113
114
115
116
117
118
119
<?php
/*
* LMS version 1.11-git
*
* (C) Copyright 2001-2018 LMS Developers
*
* Please, see the doc/AUTHORS for more information about authors!
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
* $Id$
*/
if (isset($_GET['type']))
$attachmenttype = $_GET['type'];
if (!preg_match('/^[a-z0-9_]+$/', $attachmenttype))
die;
switch ($attachmenttype) {
case 'netdevid':
case 'netnodeid':
if (!ConfigHelper::checkPrivilege('network_management'))
if (isset($_GET['type']))
access_denied();
else
return;
break;
}
if (isset($_GET['attachmentaction'])) {
switch ($_GET['attachmentaction']) {
case 'deletecontainer':
$LMS->DeleteFileContainer($_GET['id']);
break;
case 'viewfile':
$file = $LMS->GetFile($_GET['fileid']);
if (empty($file))
die;
header('Content-Type: ' . $file['contenttype']);
if (!preg_match('/^text/i', $file['contenttype'])) {
$pdf = preg_match('/pdf/i', $file['contenttype']);
if (!isset($_GET['save']))
if ($pdf) {
header('Content-Disposition: inline; filename="'.$file['filename'] . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file['filepath']) . ' bytes');
} else
header('Content-Disposition: attachment; filename="' . $file['filename'] . '"');
else
header('Content-Disposition: attachment; filename="' . $file['filename'] . '"');
header('Pragma: public');
}
readfile($file['filepath']);
die;
break;
case 'downloadzippedcontainer':
$LMS->GetZippedFileContainer($_GET['id']);
die;
break;
}
$SESSION->redirect('?' . $SESSION->get('backto'));
}
if (isset($_GET['resourceid']))
$attachmentresourceid = $_GET['resourceid'];
if (!preg_match('/^[0-9]+$/', $attachmentresourceid))
die;
if (isset($_POST['upload'])) {
$result = handle_file_uploads('files', $error);
extract($result);
$SMARTY->assign('fileupload', $fileupload);
$upload = $_POST['upload'];
if (!$error) {
if (!empty($files)) {
foreach ($files as &$file)
$file['name'] = $tmppath . DIRECTORY_SEPARATOR . $file['name'];
unset($file);
$LMS->AddFileContainer(array(
'description' => $upload['description'],
'files' => $files,
'type' => $attachmenttype,
'resourceid' => $attachmentresourceid,
));
}
// deletes uploaded files
if (!empty($files))
rrmdir($tmppath);
$SESSION->redirect('?' . $SESSION->get('backto'));
}
$SMARTY->assign('upload', $upload);
}
$SESSION->save('backto', $_SERVER['QUERY_STRING']);
$SMARTY->assign('attachmenttype', $attachmenttype);
$SMARTY->assign('attachmentresourceid', $attachmentresourceid);
$SMARTY->assign('filecontainers', $LMS->GetFileContainers($attachmenttype, $attachmentresourceid));