-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathreport.php
126 lines (114 loc) · 3.32 KB
/
report.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
126
<?php
require_once('pdf/html2pdf.class.php');
require_once('.class/render.class.php');
require_once('.class/database.class.php');
$forms = array(
'1' => array(
'Title' => 'Patients',
'Dir' => 'P', //Direciton = Landscape L or P
'Query' => 'SELECT * FROM patients;',
'Fields' => array(
'id' => 'Patient ID',
'first_name' => 'Patient Name'
)
),
'2' => array(
'Title' => 'Staff',
'Dir' => 'P', //Direciton = Landscape L or P
'Query' => 'SELECT firstname, lastname FROM staff;',
'Fields' => array(
'firstname' => 'First Name',
'lastname' => 'Last Name'
)
),
'3' => array(
'Title' => 'Notes',
'Dir' => 'P', //Direciton = Landscape L or P
'Query' => 'SELECT * FROM notes;',
'Fields' => array(
'id' => 'Note ID',
'description' => 'Description',
'date' => 'Date'
)
),
'4' => array(
'Title' => 'Resources',
'Dir' => 'P', //Direciton = Landscape L or P
'Query' => 'SELECT * FROM resources;',
'Fields' => array(
'id' => 'Resource ID',
'name' => 'Name',
'description' => 'Description'
)
),
'5' => array(
'Title' => 'Billable',
'Dir' => 'P', //Direciton = Landscape L or P
'Query' => 'SELECT * FROM billable;',
'Fields' => array(
'id' => 'Item ID',
'item' => 'Item',
'description' => 'Description',
'price' => 'Price'
)
)
);
if($_POST){
if(array_key_exists($_POST['report_type'], $forms) == false){
die('Invalid report key');
}
$form = $forms[$_POST['report_type']];
ob_start();
echo "<html><head><style media='print'>h1{ color:red;}</head><body>";
echo "<hr>";
echo "<h1>Report</h1>";
echo "<h2>".$form['Title']."</h2>";
echo "<table>";
echo "<tr>";
foreach($form['Fields'] as $field => $title){
echo "<td>".$title."</td>";
}
echo "</tr>";
$db = Database::getInstance();
foreach($db->getQueryResults($form['Query']) as $row){
echo '<tr>';
foreach($form['Fields'] as $field => $title){
echo "<td>".$row[$field]."</td>";
}
echo '</tr>';
}
echo "</table></body></html>";
$content = ob_get_clean();
try
{
$html2pdf = new HTML2PDF($form['Dir'], 'A4', 'fr');
$html2pdf->setDefaultFont('Arial');
$html2pdf->writeHTML($content);
$html2pdf->Output('report.pdf');
}
catch(HTML2PDF_exception $e) {
die('Error whilst generating report');
}
}
include(".views/header.php");
?>
<div class="container-fluid" id="login-page">
<form name="create" method="post" role="form">
<h2>Generate Report</h2>
<div class="form-group">
<h3>Generate this type of report:</h3>
<select class="form-control" name="report_type">
<option value="1">Patients in system</option>
<option value="2">Staff in system</option>
<option value="3">Notes in system</option>
<option value="4">Resources in system</option>
<option value="5">Billable Items in system</option>
</select>
<hr/>
<input type="submit" value="Create" class="btn btn-primary">
</div>
</form>
</div>
<?php
include(".views/footer.php");
?>