forked from elabftw/elabftw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.php
75 lines (63 loc) · 1.95 KB
/
make.php
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* make.php
*
* @author Nicolas CARPi <[email protected]>
* @copyright 2012 Nicolas CARPi
* @see https://www.elabftw.net Official website
* @license AGPL-3.0
* @package elabftw
*/
namespace Elabftw\Elabftw;
use Exception;
use Symfony\Component\HttpFoundation\Response;
/**
* Create a csv, zip or pdf file
*
*/
require_once 'app/init.inc.php';
$App->pageTitle = _('Export');
try {
if ($Request->query->get('type') === 'experiments') {
$Entity = new Experiments($App->Users);
} else {
$Entity = new Database($App->Users);
}
switch ($Request->query->get('what')) {
case 'csv':
$Make = new MakeCsv($Entity, $Request->query->get('id'));
break;
case 'zip':
$Make = new MakeZip($Entity, $Request->query->get('id'));
break;
case 'pdf':
$Entity->setId($Request->query->get('id'));
$Entity->canOrExplode('read');
$Make = new MakePdf($Entity);
$Make->output();
break;
default:
throw new Exception(Tools::error());
}
// the pdf is shown directly, but for csv or zip we want a download page
if ($Request->query->get('what') === 'csv' || $Request->query->get('what') === 'zip') {
$filesize = Tools::formatBytes(filesize($Make->filePath));
$template = 'make.html';
$renderArr = array(
'what' => $Request->query->get('what'),
'Make' => $Make,
'filesize' => $filesize
);
$Response = new Response();
$Response->prepare($Request);
$Response->setContent($App->render($template, $renderArr));
$Response->send();
}
} catch (Exception $e) {
$template = 'error.html';
$renderArr = array('error' => $e->getMessage());
$Response = new Response();
$Response->prepare($Request);
$Response->setContent($App->render($template, $renderArr));
$Response->send();
}