Repository navigation
Expand file tree
/
Copy pathdocumento_tutorato.php
More file actions
51 lines (48 loc) · 2.96 KB
/
Copy pathdocumento_tutorato.php
File metadata and controls
51 lines (48 loc) · 2.96 KB
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
<?php
// documento_tutorato.php - Scarica un documento del tutorato (serve l'accesso). I file stanno in cartelle bloccate al web.
// ?i=ID&f=decreto_bando|decreto_commissione|decreto_atti|unilav|lettera|registro|fine|dichiarazione documento di una pratica
// ?b=ID&f=decreto_bando|decreto_commissione|decreto_atti decreto di un bando (referente)
// Permessi: referente del tutorato e amministratori (tutto tranne la dichiarazione individuale, che ha l'IBAN), ufficio pagamenti
// (le pratiche che gli sono state passate), tutor (le sue). La dichiarazione si apre solo da tutor e ufficio, il file SCAFIS
// (con lo stesso IBAN) da tutor, referente e ufficio; ogni apertura si registra.
require_once __DIR__ . '/middleware.php';
$nega = function (string $msg = 'Documento non disponibile.'): never {
while (ob_get_level() > 0) ob_end_clean();
http_response_code(404);
exit($msg);
};
$f = preg_replace('/[^a-z_]/', '', (string)($_GET['f'] ?? ''));
$referente = $is_full_admin || ha_modulo($conn, (int)$u_id, 'didattica') || utente_operatore_ufficio($conn, $user_info, 'bandi');
$pag = \App\Core\App::per($conn)->get(\App\Tutorato\ServizioPagamenti::class);
if (isset($_GET['b'])) {
// Decreto di un bando: solo per chi lavora al tutorato
if (!$referente || !in_array($f, ['decreto_bando', 'decreto_commissione', 'decreto_atti'], true)) $nega();
$b = \App\Core\App::per($conn)->get(\App\Tutorato\BandoRepository::class)->perId((int)$_GET['b']);
$p = $b ? \App\Core\App::per($conn)->get(\App\Tutorato\FileTutorato::class)->percorsoDecreto($b, substr($f, 8)) : null;
if (!$p) $nega();
$doc = ['percorso' => $p, 'contenuto' => null, 'nome' => 'Tutorato_' . $f . '_bando' . (int)$b['id'] . '.pdf'];
} else {
$i = \App\Core\App::per($conn)->get(\App\Tutorato\IncaricoRepository::class)->perId((int)($_GET['i'] ?? 0));
if (!$i) $nega();
$ruolo = $pag->ruolo($user_info, $i, $referente);
if ($ruolo === null) $nega();
// L'IBAN è solo del tutor e dell'ufficio pagamenti
if ($f === 'dichiarazione' && !in_array($ruolo, ['tutor', 'ufficio'], true)) $nega();
// Il modello SCAFIS (ha l'IBAN) lo aprono il tutor, chi lavora al tutorato e l'ufficio pagamenti: ogni apertura si registra
if ($f === 'scafis' && !in_array($ruolo, ['tutor', 'referente', 'ufficio'], true)) $nega();
$doc = $pag->documento($i, $f, $user_info);
if (!$doc) $nega();
}
while (ob_get_level() > 0) ob_end_clean();
header('Content-Type: application/pdf');
header('Content-Disposition: ' . (isset($_GET['scarica']) ? 'attachment' : 'inline') . '; filename="' . preg_replace('/[^\w.\-]+/', '_', $doc['nome']) . '"');
header('X-Content-Type-Options: nosniff');
header('Cache-Control: private, no-store');
if ($doc['percorso'] !== null) {
header('Content-Length: ' . filesize($doc['percorso']));
readfile($doc['percorso']);
} else {
header('Content-Length: ' . strlen((string)$doc['contenuto']));
echo $doc['contenuto'];
}
exit;