1: <?php
2:
3: /**
4: * pdf.php
5: *
6: * PHP version 8
7: *
8: * LICENSE: This program is free software: you can redistribute it and/or modify
9: * it under the terms of the GNU Affero General Public License as
10: * published by the Free Software Foundation, either version 3 of the
11: * License, or (at your option) any later version.
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU Affero General Public License for more details.
16: * You should have received a copy of the GNU Affero General Public License
17: * along with this program. If not, see <http://www.gnu.org/licenses/>.
18: *
19: * @category PDF
20: * @package PDF
21: * @author Henri Schumacher <henri.hulski@gazeta.pl>
22: * @copyright 2007-2014 Henri Schumacher
23: * @license http://www.gnu.org/licenses/agpl.html GNU Affero General Public License v3
24: * @version 1.0
25: * @link https://research.openhomeo.info/download/OpenHomeopath_1.0.2.tar.gz
26: * @see FPDF
27: */
28:
29: require('mc_table.php');
30:
31: /**
32: * The PDF class extends the FPDF class and the PDF_MC_Table class for creating an PDF with the repertorization result
33: *
34: * The PDF class writes a customized header and footer on each PDF page
35: * and creates the result table prepared for PDF.
36: *
37: * @category PDF
38: * @package PDF
39: * @author Henri Schumacher <henri.hulski@gazeta.pl>
40: * @copyright 2007-2014 Henri Schumacher
41: * @license http://www.gnu.org/licenses/agpl.html GNU Affero General Public License v3
42: */
43: class PDF extends PDF_MC_Table {
44:
45: /**
46: * Header writes the header of the PDF page
47: *
48: * @return void
49: * @access public
50: */
51: function Header() {
52: // Arial bold 15
53: $this->SetFont('Arial','B',18);
54: // Title
55: $h1 = _("Repertorization result");
56: $this->Cell(0,0,$h1,0,0,'C');
57: // Line break
58: $this->Ln(12);
59: }
60:
61: /**
62: * Footer writes the footer of the PDF page
63: *
64: * @return void
65: * @access public
66: */
67: function Footer() {
68: // Position at 1.5 cm from bottom
69: $this->SetY(-15);
70: // Arial italic 8
71: $this->SetFont('Arial','I',9);
72: // powered by
73: $this->Cell(0,7,'powered by OpenHomeopath',0,0,'C',false,'https://openhomeo.info');
74: }
75:
76: /**
77: * create_result_table creates the result table for the PDF
78: *
79: * @param array $header_ar contains the data for the table header
80: * @param array $first_row_ar contains the data of the first row of the table
81: * @param array $data_ar contains the data of the table body
82: * @param integer $symptom_col_width Column width for the second column containing the symptom.
83: * If 0 it will be calculated.
84: * @param integer $col_width Column width for the following columns.
85: * If 0 it will be calculated.
86: * @return void
87: * @access public
88: */
89: function create_result_table($header_ar, $first_row_ar, $data_ar, $symptom_col_width = 0, $col_width = 0) {
90: $col_num = count($header_ar);
91: $this->SetFont('Arial','B',8.5);
92:
93: // column width for the first column containing the rubric degree
94: $col_width_ar[0] = 9.2;
95: if ($symptom_col_width === 0) {
96: $symptom_col_width = $this->GetStringWidth($first_row_ar[1]);
97: $this->SetFont('','');
98: foreach($data_ar as $row_ar) {
99: if ($this->GetStringWidth($row_ar[1]) > $symptom_col_width) {
100: $symptom_col_width = $this->GetStringWidth($row_ar[1]);
101: }
102: }
103: $this->SetFont('','B');
104: }
105: $col_width_ar[1] = $symptom_col_width;
106: $cur_col_width = $col_width;
107: for($i=2;$i<$col_num;$i++) {
108: if ($col_width === 0) {
109: $cur_col_width = max($this->GetStringWidth($header_ar[$i]), $this->GetStringWidth($first_row_ar[$i])) + 2.4;
110: }
111: $col_width_ar[$i] = $cur_col_width;
112: }
113: $aligns_ar[0] = 'C';
114: $aligns_ar[1] = 'L';
115: for($i=2;$i<$col_num;$i++) {
116: $aligns_ar[$i] = 'C';
117: }
118: $this->SetWidths($col_width_ar);
119: $this->table_header($header_ar, $first_row_ar, $aligns_ar);
120: // Data
121: $fill = false;
122: foreach($data_ar as $row_ar) {
123: $this->SetFill($fill);
124: if ($this->Row($row_ar) === false) {
125: $this->table_header($header_ar, $first_row_ar, $aligns_ar);
126: $fill = false;
127: $this->SetFill($fill);
128: $this->Row($row_ar);
129: }
130: $fill = !$fill;
131: }
132: }
133:
134:
135: /**
136: * table_header builds the table header
137: *
138: * table_header builds the table header including the first row of the repertorization table.
139: * The header row contains the remedies and the first row the grades/hits.
140: *
141: * @param array $header_ar contains the content of the header row
142: * @param array $first_row_ar contains the content of the first row
143: * @param array $aligns_ar contains the column alignments
144: * @return void
145: * @access public
146: */
147: function table_header($header_ar, $first_row_ar, $aligns_ar) {
148: $this->SetFont('Arial','B',14);
149: $h2 = _("Result table");
150: if ($this->table_page > 1) {
151: $h2 .= " (" . _("page") . " " . $this->table_page . ")";
152: }
153: $this->Cell(0,0,$h2,0,0,'C');
154: $this->Ln(8);
155: $this->SetFont('','B',8.5);
156: $this->SetAligns('C');
157: $this->SetCellHeight(7);
158: // Colors, line width
159: $this->SetDrawColor(153);
160: $this->SetLineWidth(.3);
161: // Header
162: $this->SetFill(true);
163: $this->SetFillColor(230,230,127);
164: $this->Row($header_ar);
165: // Color restoration
166: $this->SetFillColor(253,247,181);
167: // first row
168: $this->Row($first_row_ar);
169: $this->SetFont('','');
170: // reset for Data
171: $this->SetAligns($aligns_ar);
172: $this->SetCellHeight(6);
173: }
174:
175: }
176: