Issues (165)

src/scripts/download_documentation.php (2 issues)

1
<?php
2
/**
3
 Copyright (C) 2018-2020 KANOUN Salim
4
 This program is free software; you can redistribute it and/or modify
5
 it under the terms of the Affero GNU General Public v.3 License as published by
6
 the Free Software Foundation;
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
 Affero GNU General Public Public for more details.
11
 You should have received a copy of the Affero GNU General Public Public along
12
 with this program; if not, write to the Free Software Foundation, Inc.,
13
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
14
 **/
15
16
/**
17
 * Output the called Documentation
18
 */
19
20
header('content-type: text/html; charset=utf-8');
21
require_once($_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php');
22
23
Session::checkSession();
24
$linkpdo=Session::getLinkpdo();
25
26
@Session::logInfo('Username : '.$_SESSION['username'].
0 ignored issues
show
Are you sure the usage of Session::logInfo('Userna...GET['idDocumentation']) targeting Session::logInfo() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
27
	' Role: '.$_SESSION ['role'].' Study: '.$_SESSION['study'].' Documentation ID: '.$_GET['idDocumentation']);
28
29
$idDocumentation=$_GET['idDocumentation'];
30
$documentationObject=new Documentation($linkpdo, $idDocumentation);
31
$roleAllowed=$documentationObject->isDocumentationAllowedForRole($_SESSION['role']);
32
33
$userObject=new User($_SESSION['username'], $linkpdo);
34
$studyAllowed=$userObject->isRoleAllowed($documentationObject->study, $_SESSION['role']);
35
36
if ($roleAllowed && $studyAllowed) {
37
    
38
	header($_SERVER['SERVER_PROTOCOL'].' 200 OK');
39
	header("Content-Type: application/pdf");
40
	header("Content-Transfer-Encoding: Binary");
41
	header("Cache-Control: no-cache");
42
	header("Content-Length: ".filesize($documentationObject->documentFileLocation));
43
	header('Content-Disposition: attachment; filename="Documentation-'.$_SESSION['study'].'_'.$documentationObject->documentName.'.pdf"');
44
    
45
	$file=@fopen($documentationObject->documentFileLocation, "rb");
46
	if ($file) {
0 ignored issues
show
$file is of type false|resource, thus it always evaluated to false.
Loading history...
47
48
		while (!feof($file))
49
		{
50
			print(@fread($file, 1024*1024));
51
			flush();
52
		}
53
54
		fclose($file);
55
56
	}else {
57
		throw new Exception("Can't Find Documentation");
58
	}
59
60
    
61
 
62
    
63
    
64
}else {
65
	require $_SERVER['DOCUMENT_ROOT'].'/includes/no_access.php';
66
}