Issues (2126)

main/calendar/download.php (1 issue)

Labels
Severity
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * This file is responsible for  passing requested documents to the browser.
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.calendar
11
 */
12
session_cache_limiter('public');
13
14
require_once __DIR__.'/../inc/global.inc.php';
15
$this_section = SECTION_COURSES;
16
17
// IMPORTANT to avoid caching of documents
18
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
19
header('Cache-Control: public');
20
header('Pragma: no-cache');
21
22
$course_id = isset($_REQUEST['course_id']) ? (int) $_REQUEST['course_id'] : api_get_course_int_id();
23
$user_id = api_get_user_id();
24
$course_info = api_get_course_info_by_id($course_id);
25
$doc_url = $_REQUEST['file'];
26
27
if (empty($course_id) || empty($doc_url)) {
28
    api_not_allowed();
29
}
30
$session_id = api_get_session_id();
31
32
$is_user_is_subscribed = CourseManager::is_user_subscribed_in_course(
33
    $user_id,
34
    $course_info['code'],
35
    true,
36
    $session_id
37
);
38
39
if (!api_is_allowed_to_edit() && !$is_user_is_subscribed) {
40
    api_not_allowed();
41
}
42
43
//change the '&' that got rewritten to '///' by mod_rewrite back to '&'
44
$doc_url = str_replace('///', '&', $doc_url);
45
//still a space present? it must be a '+' (that got replaced by mod_rewrite)
46
$doc_url = str_replace(' ', '+', $doc_url);
47
$doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
48
49
$full_file_name = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/upload/calendar/'.$doc_url;
50
51
//if the rewrite rule asks for a directory, we redirect to the document explorer
52
if (is_dir($full_file_name)) {
53
    while ($doc_url[$dul = strlen($doc_url) - 1] == '/') {
54
        $doc_url = substr($doc_url, 0, $dul);
55
    }
56
    // create the path
57
    $document_explorer = api_get_path(WEB_COURSE_PATH).$course_info['path']; // home course path
58
    // redirect
59
    header('Location: '.$document_explorer);
60
    exit;
61
}
62
63
$tbl_agenda_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
64
65
// launch event
66
Event::event_download($doc_url);
0 ignored issues
show
The method event_download() does not exist on Event. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
Event::/** @scrutinizer ignore-call */ 
67
       event_download($doc_url);

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.

Loading history...
67
68
$sql = 'SELECT filename FROM '.$tbl_agenda_attachment.'
69
  	    WHERE
70
  	        c_id = '.$course_id.' AND
71
  	        path LIKE BINARY "'.Database::escape_string($doc_url).'"';
72
73
$result = Database::query($sql);
74
if (Database::num_rows($result)) {
75
    $row = Database::fetch_array($result);
76
    $title = str_replace(' ', '_', $row['filename']);
77
    if (Security::check_abs_path(
78
        $full_file_name,
79
        api_get_path(SYS_COURSE_PATH).$course_info['path'].'/upload/calendar/'
80
    )) {
81
        $result = DocumentManager::file_send_for_download($full_file_name, true, $title);
82
        if ($result === false) {
83
            api_not_allowed(true);
84
        }
85
    }
86
}
87
88
api_not_allowed();
89