-
Notifications
You must be signed in to change notification settings - Fork 6
/
getPersonCMRReport.php
125 lines (107 loc) · 4.83 KB
/
getPersonCMRReport.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
Copyright 2006-2018 Felix Rudolphi and Lukas Goossen
open enventory is distributed under the terms of the GNU Affero General Public License, see COPYING for details. You can also find the license under http://www.gnu.org/licenses/agpl.txt
open enventory is a registered trademark of Felix Rudolphi and Lukas Goossen. Usage of the name "open enventory" or the logo requires prior written permission of the trademark holders.
This file is part of open enventory.
open enventory is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
open enventory is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with open enventory. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Zeigt ein GIF an, das a) in der Datenbank (molecule_id=xyz) oder in der Session[gifFile12345678] (timestamp=12345678) abgelegt wurde
oder (save=true) läßt es den Browser herunterladen und unter dem Namen filename=xyz speichern
*/
require_once "lib_global_funcs.php";
require_once "lib_db_query.php";
require_once "lib_formatting.php";
require_once "Spreadsheet/Excel/Writer.php";
set_time_limit(10);
pageHeader(true,false,true,false);
if (!empty($_REQUEST["person_id"])) {
$categories=array(
"Carc. Cat 1" => array("filter" => "molecule.safety_cancer IN(\"1\",\"I\")"),
"Mutagen Cat 1" => array("filter" => "molecule.safety_mutagen IN(\"1\",\"I\")"),
"Teratogen Cat 1" => array("filter" => "molecule.safety_reprod IN(\"1\",\"I\")"),
);
// get person name
list($person)=mysql_select_array(array(
"dbs" => -1,
"table" => "person",
"filter" => "person.person_id=".fixNull($_REQUEST["person_id"]),
));
$person_name=formatPersonNameCommas($person);
$tmp_filename=oe_tempnam(@System::tmpdir(), "OLE_PPS_Root"); // use PEAR function like OLE module
$workbook=new Spreadsheet_Excel_Writer($tmp_filename); // write to temp file, unfortunately, impossible to get as variable content directly
$headline_format=& $workbook->addFormat(array("Bold" => 1, ));
$columns=array(
// event
array("headline" => s("reaction_started_when"), "field" => "reaction_started_when"),
array("headline" => s("lab_journal_entry"), "field" => "lab_journal_entry"),
array("headline" => s("reaction_carried_out_by"), "field" => "reaction_carried_out_by"),
// identification
array("headline" => s("molecule_name"), "field" => "standard_name"),
array("headline" => s("cas_nr"), "field" => "cas_nr"),
array("headline" => s("emp_formula"), "field" => "emp_formula"),
// amount
array("headline" => s("m_brutto")." (g)", "field" => "m_brutto"),
array("headline" => s("volume")." (ml)", "field" => "volume"),
array("headline" => s("rc_conc"), "field" => "rc_conc_text"),
// GHS
array("headline" => s("safety_sym_ghs"), "field" => "safety_sym_ghs"),
array("headline" => s("safety_h"), "field" => "safety_h"),
array("headline" => s("safety_p"), "field" => "safety_p"),
array("headline" => s("safety_text"), "field" => "safety_text"),
// old system
array("headline" => s("safety_sym"), "field" => "safety_sym"),
array("headline" => s("safety_r"), "field" => "safety_r"),
array("headline" => s("safety_s"), "field" => "safety_s"),
// CMR cats
array("headline" => s("safety_cancer"), "field" => "safety_cancer"),
array("headline" => s("safety_mutagen"), "field" => "safety_mutagen"),
array("headline" => s("safety_reprod"), "field" => "safety_reprod"),
);
$has_entries=false;
foreach ($categories as $name => $category) {
$results=mysql_select_array(array(
"table" => "person_cmr",
"filter" => "lab_journal.person_id=".fixNull($_REQUEST["person_id"])." AND (".$category["filter"].")",
"dbs" => -1,
));
//~ var_dump($results);die();
if (!count($results)) {
continue;
}
$has_entries=true;
// create worksheet
$worksheet=& $workbook->addWorksheet(strcut($name,31));
// headlines
foreach ($columns as $idx => $column) {
$worksheet->write(0,$idx,html_entity_decode(utf8_decode(trimNbsp($column["headline"]))),$headline_format);
}
$worksheet->repeatRows(0);
// data
foreach ($results as $rowIdx => $result) {
foreach ($columns as $idx => $column) {
$worksheet->write($rowIdx+1,$idx,html_entity_decode(utf8_decode(trimNbsp($result[ $column["field"] ]))));
}
}
}
mysqli_close($db);
$workbook->close();
if ($has_entries) {
$workbook->send($person_name.".xls"); // output xls headers
@readfile($tmp_filename);
} else {
echo "<html><body>".s("no_results")."</body></html>";
}
@unlink($tmp_filename);
}
?>