1 | <?php |
||
2 | /* For licensing terms, see /license.txt */ |
||
3 | |||
4 | /** |
||
5 | * This file is responsible for passing requested file attachments from messages |
||
6 | * Html files are parsed to fix a few problems with URLs, |
||
7 | * but this code will hopefully be replaced soon by an Apache URL |
||
8 | * rewrite mechanism. |
||
9 | * |
||
10 | * @package chamilo.messages |
||
11 | */ |
||
12 | session_cache_limiter('public'); |
||
13 | |||
14 | require_once __DIR__.'/../inc/global.inc.php'; |
||
15 | |||
16 | $file_url = isset($_GET['file']) ? $_GET['file'] : ''; |
||
17 | $type = isset($_GET['type']) ? $_GET['type'] : ''; |
||
18 | |||
19 | if (empty($file_url)) { |
||
20 | api_not_allowed(); |
||
21 | } |
||
22 | |||
23 | // IMPORTANT to avoid caching of documents |
||
24 | header('Expires: Wed, 01 Jan 1990 00:00:00 GMT'); |
||
25 | header('Cache-Control: public'); |
||
26 | header('Pragma: no-cache'); |
||
27 | |||
28 | //change the '&' that got rewritten to '///' by mod_rewrite back to '&' |
||
29 | $file_url = str_replace('///', '&', $file_url); |
||
30 | //still a space present? it must be a '+' (that got replaced by mod_rewrite) |
||
31 | $file_url = str_replace(' ', '+', $file_url); |
||
32 | $file_url = str_replace('/..', '', $file_url); //echo $doc_url; |
||
33 | |||
34 | $tbl_messsage = Database::get_main_table(TABLE_MESSAGE); |
||
35 | $tbl_messsage_attachment = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT); |
||
36 | |||
37 | $file_url = Database::escape_string($file_url); |
||
38 | $sql = "SELECT filename, message_id |
||
39 | FROM $tbl_messsage_attachment |
||
40 | WHERE path LIKE BINARY '$file_url'"; |
||
41 | |||
42 | $result = Database::query($sql); |
||
43 | $row = Database::fetch_array($result, 'ASSOC'); |
||
44 | $title = str_replace(' ', '_', $row['filename']); |
||
45 | $message_id = $row['message_id']; |
||
46 | |||
47 | // allow download only for user sender and user receiver |
||
48 | $sql = "SELECT user_sender_id, user_receiver_id, group_id |
||
49 | FROM $tbl_messsage WHERE id = '$message_id'"; |
||
50 | $rs = Database::query($sql); |
||
51 | $row_users = Database::fetch_array($rs, 'ASSOC'); |
||
52 | $current_uid = api_get_user_id(); |
||
53 | |||
54 | // get message user id for inbox/outbox |
||
55 | $message_uid = ''; |
||
56 | switch ($type) { |
||
57 | case MessageManager::MESSAGE_TYPE_INBOX: |
||
58 | $message_uid = $row_users['user_receiver_id']; |
||
59 | break; |
||
60 | case MessageManager::MESSAGE_TYPE_OUTBOX: |
||
61 | $message_uid = $row_users['user_sender_id']; |
||
62 | break; |
||
63 | } |
||
64 | |||
65 | // allow to the correct user for download this file |
||
66 | $not_allowed_to_edit = false; |
||
67 | $userGroup = new UserGroup(); |
||
68 | |||
69 | if (!empty($row_users['group_id'])) { |
||
70 | $users_group = $userGroup->get_all_users_by_group($row_users['group_id']); |
||
71 | if (!in_array($current_uid, array_keys($users_group))) { |
||
72 | $not_allowed_to_edit = true; |
||
73 | } |
||
74 | } else { |
||
75 | if ($current_uid != $message_uid) { |
||
76 | $not_allowed_to_edit = true; |
||
77 | } |
||
78 | } |
||
79 | |||
80 | if ($not_allowed_to_edit) { |
||
81 | api_not_allowed(true); |
||
82 | exit; |
||
83 | } |
||
84 | |||
85 | // set the path directory file |
||
86 | if (!empty($row_users['group_id'])) { |
||
87 | $path_user_info = $userGroup->get_group_picture_path_by_id( |
||
88 | $row_users['group_id'], |
||
89 | 'system', |
||
90 | true |
||
91 | ); |
||
92 | } else { |
||
93 | $path_user_info['dir'] = UserManager::getUserPathById($message_uid, 'system'); |
||
94 | } |
||
95 | |||
96 | $full_file_name = $path_user_info['dir'].'message_attachments/'.$file_url; |
||
97 | |||
98 | if (Security::check_abs_path($full_file_name, $path_user_info['dir'].'message_attachments/')) { |
||
99 | // launch event |
||
100 | Event::event_download($file_url); |
||
0 ignored issues
–
show
|
|||
101 | $result = DocumentManager::file_send_for_download( |
||
102 | $full_file_name, |
||
103 | true, |
||
104 | $title |
||
105 | ); |
||
106 | if ($result === false) { |
||
107 | api_not_allowed(true); |
||
108 | } |
||
109 | } |
||
110 | exit; |
||
111 |
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.