Issues (2160)

main/lp/download.php (2 issues)

Labels
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
use ChamiloSession as Session;
5
6
/**
7
 * This file is responsible for  passing requested documents to the browser.
8
 *
9
 * @package chamilo.document
10
 */
11
session_cache_limiter('none');
12
require_once __DIR__.'/../inc/global.inc.php';
13
$this_section = SECTION_COURSES;
14
15
// Protection
16
api_protect_course_script();
17
$_course = api_get_course_info();
18
19
if (!isset($_course)) {
20
    api_not_allowed(true);
21
}
22
23
$doc_url = $_GET['doc_url'];
24
// Change the '&' that got rewritten to '///' by mod_rewrite back to '&'
25
$doc_url = str_replace('///', '&', $doc_url);
26
// Still a space present? it must be a '+' (that got replaced by mod_rewrite)
27
$doc_url = str_replace(' ', '+', $doc_url);
28
29
$doc_url = str_replace(['../', '\\..', '\\0', '..\\'], ['', '', '', ''], $doc_url); //echo $doc_url;
30
31
if (strpos($doc_url, '../') || strpos($doc_url, '/..')) {
32
    $doc_url = '';
33
}
34
$sys_course_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/scorm';
35
$user_id = api_get_user_id();
36
/** @var learnpath $lp */
37
$lp = Session::read('oLP');
38
if ($lp) {
0 ignored issues
show
$lp is of type learnpath, thus it always evaluated to true.
Loading history...
39
    $lp_id = $lp->get_id();
40
    $lp_item_id = $lp->current;
41
    $lp_item_info = new learnpathItem($lp_item_id);
42
    if (!empty($lp_item_info)) {
43
        $visible = learnpath::is_lp_visible_for_student($lp_id, $user_id);
44
45
        if ($visible) {
46
            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

46
            Event::/** @scrutinizer ignore-call */ 
47
                   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...
47
            if (Security::check_abs_path($sys_course_path.$doc_url, $sys_course_path.'/')) {
48
                $full_file_name = $sys_course_path.$doc_url;
49
                DocumentManager::file_send_for_download($full_file_name);
50
                exit;
51
            }
52
        }
53
        //}
54
    }
55
}
56
57
echo Display::return_message(get_lang('ProtectedDocument'), 'error');
58
//api_not_allowed backbutton won't work.
59
exit;
60