1
|
<?php
|
2
|
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
3
|
// System Section : PDF Report Generation
|
4
|
// Title : Section 2.1 About the Property
|
5
|
// Author : Jerry Quinnell
|
6
|
// Date : Jan 2017
|
7
|
// Change Log : 6/2/17 - Check no text and issue warning in report and error page at the end
|
8
|
// Change Log : 6/2/17 - Enhance - pictures 1/2 width or full width as per surveyors pref
|
9
|
// 16/3 - Changed echos to error_log to help debugging
|
10
|
// CH200717 - Check for any XX's left in template paragraphs by mistake
|
11
|
// CH231017 - 2.1 Data Splat cos Session vars used - taken them all out and changed $sqltext[$k] = trim($jqdata);
|
12
|
// Completely re-written in DEC17 to encompass all three seciton 3 sections
|
13
|
// CHXMAS17 - Added ROWSPAN to cure picture and caption on same page
|
14
|
// CH030119 - Put in picture not found check - inserts white error blank jpg in its place
|
15
|
|
16
|
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
17
|
|
18
|
// session_start();
|
19
|
ob_start(); // Required to use the header redirect down below
|
20
|
|
21
|
|
22
|
|
23
|
|
24
|
|
25
|
$prrn = $_SESSION['prrn'];
|
26
|
$hbbsid = $_SESSION['user'];
|
27
|
|
28
|
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
29
|
// Get product data
|
30
|
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
31
|
|
32
|
// $type is set in PDF0-AACONTROL.php
|
33
|
|
34
|
for ($section = 21; $section < 23; $section++){
|
35
|
// echo ("<br>Section=" . $section);
|
36
|
$query = "SELECT * FROM DBxyz
|
37
|
|
38
|
$result = $connection->query($query);
|
39
|
if (!$result) die ("<br><br>Database access failed: " . $conn->error);
|
40
|
|
41
|
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
|
42
|
$elementdesc = $rs["elementdesc"];
|
43
|
$rating = $rs["rating"];
|
44
|
$dbfield = $rs["dbfield"];
|
45
|
$count = $rs["elecount"];
|
46
|
$labels[1] = $rs["f1"];
|
47
|
$labels[2] = $rs["f2"];
|
48
|
$labels[3] = $rs["f3"];
|
49
|
$labels[4] = $rs["f4"];
|
50
|
$labels[5] = $rs["f5"];
|
51
|
$labels[6] = $rs["f6"];
|
52
|
$labels[7] = $rs["f7"];
|
53
|
$labels[8] = $rs["f8"];
|
54
|
$labels[9] = $rs["f9"];
|
55
|
$labels[10] = $rs["f10"];
|
56
|
$labels[11] = $rs["f11"];
|
57
|
$labels[12] = $rs["f12"];
|
58
|
$labels[13] = $rs["f13"];
|
59
|
$labels[14] = $rs["f14"];
|
60
|
$labels[15] = $rs["f15"];
|
61
|
$headertext[1] = $rs["headertext1"];
|
62
|
$headertext[2] = $rs["headertext2"];
|
63
|
$headertext[3] = $rs["headertext3"];
|
64
|
$watermark = $rs["watermark"];
|
65
|
}
|
66
|
|
67
|
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
68
|
// Get Reportdata2
|
69
|
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
70
|
|
71
|
$query = "SELECT * FROM reportdata2 WHERE datarecord='" . $prrn . "'";
|
72
|
$result = $connection->query($query);
|
73
|
if (!$result) die ("<br>Database access failed: " . $connection->error);
|
74
|
|
75
|
while($rs = $result->fetch_array(MYSQLI_ASSOC)) { // Only one record obtained
|
76
|
for ($i = 0; $i < $count; $i++) {
|
77
|
$k = $i + 1;
|
78
|
$rid = $dbfield . $k;
|
79
|
$jqdata = $rs[$rid] . ' ';
|
80
|
if ($rs[$rid] == 'undefined') {
|
81
|
$jqdata = "";
|
82
|
}
|
83
|
$sqltext[$k] = trim($jqdata); // CH231017 - 2.1 Data Splat cos Session vars used
|
84
|
}
|
85
|
}
|
86
|
|
87
|
// ------------------------------------------------------------------------------------------------------------------------
|
88
|
// Colour code decoding text - it comes to us with text delimited by #colour# to start the string then ends with ##
|
89
|
// We swap the ## bits to <colour> and </colour> using special characters as str_replace wont put in the '<' '/>' bits
|
90
|
// then we decode the string from the codes to HMTLchars
|
91
|
// ------------------------------------------------------------------------------------------------------------------------
|
92
|
for ($i = 1; $i < $count+1; $i++) {
|
93
|
$sqltext[$i] = str_replace('#red#','<red>',$sqltext[$i]); // Swaps the #red# to a <red>
|
94
|
$sqltext[$i]= str_replace('##','</red>',$sqltext[$i]); // Swaps the ## to a </red>
|
95
|
$sqltext[$i] = html_entity_decode($sqltext[$i]); // Decode to visible html chars for the PDF bit to work
|
96
|
}
|
97
|
// -----------------------------------------Colour code ends --------------------------------------------------------------
|
98
|
|
99
|
// @@@@@@@@@@@@@@@@@@ Process Pictures now - use Function GetPix defined in hbbsreport1 to get this elements pictures and captions.
|
100
|
|
101
|
$repimages = array(); // To contain the filenames
|
102
|
$repcaption = array(); // To contain the captions
|
103
|
$repwidth = array(); // To contain the picture wdith (for portrait or landscape) // CH6/2/17
|
104
|
$pixpos = array(); // To contain the picture wdith (for portrait or landscape) // CH6/2/17
|
105
|
//$dir = 'PRRN' . $prrn . '/'; // build the folder name
|
106
|
$dir = 'PRRN' . $prrn . $hbbsid .'/'; // build the folder name
|
107
|
|
108
|
$query = "SELECT * FROM db
|
109
|
$result = $connection->query($query);
|
110
|
if (!$result) die ("Database access failed: " . $connection>error);
|
111
|
|
112
|
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
|
113
|
$file = $rs["filename"]; // Build filename
|
114
|
$repimages[] = $dir . $file; // yes we need the picture so save the original uploaded filename (which doesnt change in its lifetime) in the array
|
115
|
$repcaption[] = $rs["pixcap"]; // yes we need the picture so save the caption which does get change by the users in the array
|
116
|
$pixpos[] = $rs["pixpos"]; // yes we need the picture so save the caption which does get change by the users in the array
|
117
|
// error_log('filename=' . $dir . $file . ' : caption=' . $rs["pixcap"]);
|
118
|
|
119
|
} // While
|
120
|
|
121
|
$elepixno = count($repimages);
|
122
|
|
123
|
//error_log('pix count=' . $elepixno);
|
124
|
|
125
|
for ($i=0; $i<$elepixno; $i++) {
|
126
|
if (@getimagesize($repimages[$i])) { // CH030119 Is the image present ? - Process if YES, error log msg if NO (System error basically)
|
127
|
|
128
|
$size = getimagesize($repimages[$i]); // CH6/2/17
|
129
|
$width = $size[0]; // CH6/2/17
|
130
|
$height = $size[1]; // CH6/2/17
|
131
|
$aspect = $height / $width; // CH6/2/17
|
132
|
|
133
|
if ($prefpixwidth == 1){
|
134
|
if ($aspect >= 1) $repwidth[$i] = 50; // CH6/2/17 Portrait
|
135
|
else $repwidth[$i] = 70; // CH6/2/17 Landscape
|
136
|
}
|
137
|
else {
|
138
|
if ($aspect >= 1) $repwidth[$i] = 85; // CH6/2/17 Portrait
|
139
|
else $repwidth[$i] = 130; // CH6/2/17 Landscape
|
140
|
} // CH6/2/17 Landscape
|
141
|
}
|
142
|
else { // CH030119 - Put in picture not found check - inserts white error blank jpg in its place
|
143
|
$reportmsg = $reportmsg . '- Section 2 - Picture Not found - Database Mismatch advise Skyline Tech Support: ' . $repimages[$i] . '
|
144
|
'; // Put this on next line to create a line break <br> equivalent // CH070218 - put the fullstop inbetween the section element $substring number - for the error report
|
145
|
$repimages[$i]= 'images/skypixnotfound.jpg'; // CH030119 Put in the white NOT FOUND IMAGE instead
|
146
|
$repwidth[$i]= 55; // CH030119 Set the repwidth as otherwise array element will generate 'Undefined Offset' warning in PHP log
|
147
|
} // If @getimagesize
|
148
|
} // For Loop
|
149
|
// ----------------------------- END of GET PICTURES -----------------------------------
|
150
|
|
151
|
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ PDF CODE START @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
152
|
|
153
|
$oTable->SetStyle( "red", $oPdf->getDefaultFontName(), "", 9, "255,0,0" );
|
154
|
$oTable->SetStyle( "blue", $oPdf->getDefaultFontName(), "", 9, "0,0,255" );
|
155
|
// $oTable->SetStyle( "red", $oPdf->getDefaultFontName(), B=Bold I=Italic U=Underline, Fontsize, Color array );
|
156
|
|
157
|
$oTable->initialize( array( 24,78,78 ) );
|
158
|
|
159
|
$aRow = array();
|
160
|
$aRow[ 0 ] = array( 'TYPE' => 'IMAGE','FILE' => $logo, 'WIDTH' => 16,'PADDING_BOTTOM' => 5,'VERTICAL_ALIGN' => 'T');
|
161
|
$aRow[ 1 ] = array( 'TEXT' => 'Section 2 Property information
|
162
|
|
163
|
' . $elementdesc ,'TEXT_TYPE' => 'B', 'TEXT_COLOR' => $white,'BACKGROUND_COLOR' => $colour,'TEXT_ALIGN' => 'L','TEXT_SIZE' => '10','COLSPAN' => 2,);
|
164
|
$oTable->addRow( $aRow );
|
165
|
|
166
|
if ($section == 22) {
|
167
|
$text = "This section is a summary of matters that are of particular interest but you should consider ALL information contained in this report.";
|
168
|
$aRow[ 0 ] = array( 'TEXT' => $text,'TEXT_ALIGN' => 'L','COLSPAN' => 3,'TEXT_SIZE' => 9,'PADDING_LEFT' => 2,'PADDING_RIGHT' => 2,'PADDING_TOP' =>2,'PADDING_BOTTOM' => 5,'BORDER_TYPE' => 'LRTB');
|
169
|
$oTable->addRow( $aRow );
|
170
|
}
|
171
|
|
172
|
|
173
|
for($i=1;$i<$count+1;$i++) {
|
174
|
|
175
|
if ($i==$count && $sqltext[$i] == "") continue; // If last field = Miscellaneous and there's no text then dont print the line - skip to next field (which is techinically the end)
|
176
|
|
177
|
if (strpos(strtoupper($sqltext[$i]), 'XX') !== false) { // CH200717 - Check for any XX's left in template paragraphs by mistake
|
178
|
$reportmsg = $reportmsg . '- Section ' . substr($section,0,1) . '.' . substr($section,1) . ' - XXs left in Field : ' . $labels[$i] . '
|
179
|
'; // Put this on next line to create a line break <br> equivalent
|
180
|
}
|
181
|
|
182
|
if (strpos(strtoupper($sqltext[$i]), '%20') !== false) { // CH200717 - Check for any %20's left in template paragraphs by mistake
|
183
|
$reportmsg = $reportmsg . '- Section ' . substr($section,0,1) . '.' . substr($section,1) . ' - %20s are present due to a data error - go back and hit SAVE DATA twice to remove them -Field - : ' . $labels[$i] . '
|
184
|
'; // Put this on next line to create a line break <br> equivalent
|
185
|
}
|
186
|
|
187
|
if ($sqltext[$i] == "") {
|
188
|
$sqltext[$i] = 'YOU MUST ENTER SOME TEXT INTO THIS FIELD';
|
189
|
$reportmsg = $reportmsg . '- Section ' . substr($section,0,1) . '.' . substr($section,1) . ' - Missing Text in Field : ' . $labels[$i] . '
|
190
|
'; // Put this on next line to create a line break <br> equivalent
|
191
|
$textcolour = array (255,0,0); // Red Text
|
192
|
}
|
193
|
else {
|
194
|
if (strtoupper($sqltext[$i]) == "NO ISSUE NOTED BY SURVEYOR") $textcolour = array (135,206,235); // Light Blue Text
|
195
|
else $textcolour = array (0,0,0); // Black Text
|
196
|
}
|
197
|
|
198
|
$aRow = array();
|
199
|
$aRow[ 0 ] = array('TEXT' => $labels[$i],'TEXT_TYPE' => 'B','PADDING_LEFT' => 2,'PADDING_RIGHT' => 2,
|
200
|
'PADDING_TOP' => 5,'PADDING_BOTTOM' => 5,'VERTICAL_ALIGN' => 'T','TEXT_ALIGN' => 'L','TEXT_SIZE' => 7,'TEXT_TYPE' => 'B','BORDER_TYPE' => 'LRTB');
|
201
|
$aRow[ 1 ] = array('TEXT' => $sqltext[$i],'TEXT_COLOR' => $textcolour, 'TEXT_ALIGN' => 'L','TEXT_SIZE' => 9,
|
202
|
'PADDING_LEFT' => 2,'PADDING_RIGHT' => 2,'PADDING_TOP' =>5,'PADDING_BOTTOM' => 5,'BORDER_TYPE' => 'LRTB','COLSPAN' => 2,);
|
203
|
$oTable->addRow( $aRow );
|
204
|
|
205
|
// Any pictures now ?
|
206
|
$subelecnt = 0; // Reset Picture count for this sub element
|
207
|
for ($j=0; $j<$elepixno; $j++) { // Loop round the number of pix found for the whole of section 2 - could be none but a max of 2.
|
208
|
$subele = $pixpos[$j]; // Get the sub element - 1 -12 in section 2.1
|
209
|
if ($subele == $i) { // if chars 3 and 4 of the pic filename equals the sub section 1-12 then insert the picture
|
210
|
|
211
|
$subelecnt = $subelecnt + 1; // add 1 to element pix count = max of two allowed
|
212
|
|
213
|
if ($subelecnt < 12) { // CH16/3 - changed from max of 2 to 12 - If picture 1 - 12 then allow thru - max of 12 allowed
|
214
|
|
215
|
$aRow = array();
|
216
|
$aRow[ 0 ] = array('ROWSPAN' => 2, 'TEXT' => ' ','BORDER_TYPE' => 'LRB',); // CHXMAS17 - Added ROWSPAN to cure picture and caption on same page
|
217
|
// $aRow[ 0 ] = array( 'TEXT' => ' ','BORDER_TYPE' => 'LR',);
|
218
|
|
219
|
$aRow[ 1 ] = array( 'TYPE' => 'IMAGE', 'FILE' => $repimages[$j], 'WIDTH' => $repwidth[$j], 'BORDER_TYPE' => 'LRB','ALIGN' => 'C', 'COLSPAN' => 2);
|
220
|
$oTable->addRow( $aRow );
|
221
|
|
222
|
$aRow = array();
|
223
|
$aRow[ 0 ] = array( 'TEXT' => ' ', 'BORDER_TYPE' => 'LRB', );
|
224
|
$aRow[ 1 ] = array( 'TEXT' => $repcaption[$j], 'TEXT_SIZE' => 8, 'BORDER_TYPE' => 'LR','ALIGN' => 'C', 'COLSPAN' => 2,);
|
225
|
$oTable->addRow( $aRow );
|
226
|
|
227
|
if (strpos(strtoupper($repcaption[$j]), 'XX') !== false) { // CH131117 - Check for any XX's left in template paragraphs by mistake
|
228
|
$reportmsg = $reportmsg . '- Section ' . substr($section,0,1) . '.' . substr($section,1) . ' - XXs left in Picture Caption : ' .$repcaption[$j] . '
|
229
|
'; // Put this on next line to create a line break <br> equivalent
|
230
|
}
|
231
|
}
|
232
|
}
|
233
|
}
|
234
|
}
|
235
|
|
236
|
$oTable->close();
|
237
|
|
238
|
if ($section != 22) $oPdf->AddPage(); // Dont throw a page on last section
|
239
|
|
240
|
} // for $section
|
241
|
$connection->close();
|
242
|
|
243
|
//echo "<br> Before 2.1.2 NEW Table Close";
|
244
|
|
245
|
ob_end_clean();
|