-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprint_letter.php
executable file
·195 lines (158 loc) · 8.24 KB
/
print_letter.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
require_once('common.php');
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
session_start();
/*
echo '<pre>';
print_r($GLOBALS);
echo '</pre>';
*/
class MYPDF_NABL extends TCPDF {
public $letter;
public function Header()
{
$border=0;
//A4=210x297
$this->SetXY(10,10);
$this->SetFont('helvetica', 'B', 20);
$this->Cell(190, $h=0, $txt='Page:'.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), $border, $ln=0, $align='R', $fill=false, $link='', $stretch=1, $ignore_min_height=false, $calign='T', $valign='M');
$this->SetFont('helvetica', 'B', 10);
$this->SetXY(105,20);
$this->Cell(95, $h=0,'From', $border, $ln=0, $align='L', $fill=false, $link='', $stretch=1, $ignore_min_height=false, $calign='T', $valign='M');
$this->SetFont('helvetica', '', 10);
$this->SetXY(105,25);
$this->MultiCell($w=95, $h=0, $txt=$this->letter['from'], $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=10, $valign='T', $fitcell=true);
$this->SetFont('helvetica', 'B', 10);
$this->SetXY(105,35);
$this->MultiCell($w=95, $h=0, $txt='No: '.$this->letter['id'].' / '.$this->letter['type'].' / '.$this->letter['date'], $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=5, $valign='T', $fitcell=true);
$this->SetFont('helvetica', 'B', 10);
$this->SetXY(10,20);
$this->Cell(95, $h=0,'To', $border, $ln=0, $align='L', $fill=false, $link='', $stretch=1, $ignore_min_height=false, $calign='T', $valign='M');
$this->SetFont('helvetica', '', 10);
$this->SetXY(10,25);
$this->MultiCell($w=95, $h=0, $txt=$this->letter['to'], $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=15, $valign='T', $fitcell=true);
}
// Page footer
public function Footer()
{
}
}
function save_letter($letter)
{
$sql='insert into letter (id,type,`from`,`to`,`date`,greeting,subject,sub_subject,`reference`,`body`,closing,thanks,signature,attachment_list,copy_to)
values
(
\'\',
\''. mysql_real_escape_string($letter['type']).'\',
\''. mysql_real_escape_string($letter['from']).'\',
\''. mysql_real_escape_string($letter['to']).'\',
\''. mysql_real_escape_string($letter['year'].'-'.$letter['month'].'-'.$letter['day']).'\',
\''. mysql_real_escape_string($letter['greeting']).'\',
\''. mysql_real_escape_string($letter['subject']).'\',
\''. mysql_real_escape_string($letter['sub_subject']).'\',
\''. mysql_real_escape_string($letter['reference']).'\',
\''. mysql_real_escape_string($letter['body']).'\',
\''. mysql_real_escape_string($letter['closing']).'\',
\''. mysql_real_escape_string($letter['thanks']).'\',
\''. mysql_real_escape_string($letter['signature']).'\',
\''. mysql_real_escape_string($letter['attachment_list']).'\',
\''. mysql_real_escape_string($letter['copy_to']).'\')';
$link=start_nchsls();
if(!$result=mysql_query($sql,$link)){echo mysql_error();}
return mysql_insert_id($link);
}
function print_letter($id)
{
$sql='select * from letter where id=\''.$id.'\'';
$link=start_nchsls();
if(!$result=mysql_query($sql,$link)){echo mysql_error();}
$letter=mysql_fetch_assoc($result);
$pdf = new MYPDF_NABL('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->letter=$letter;
$pdf->SetMargins(10, 50);
$pdf->SetAutoPageBreak(TRUE, 10);
$pdf->SetFont('helvetica', '', 8);
$pdf->AddPage();
$border=0;
$pdf->SetFont('helvetica', 'B', 10);
$pdf->SetXY(10,50);
$pdf->MultiCell($w=20, $h=0, $txt='Subject:', $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=5, $valign='T', $fitcell=true);
$pdf->SetFont('helvetica', '', 10);
$pdf->SetXY(30,50);
$pdf->MultiCell($w=210-10-30, $h=0, $txt=$pdf->letter['subject'], $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=5, $valign='T', $fitcell=true);
$pdf->SetFont('helvetica', 'B', 10);
$pdf->SetXY(10,55);
$pdf->MultiCell($w=20, $h=0, $txt='Sub-subject:', $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=2, $ishtml=false, $autopadding=true, $maxh=5, $valign='T', $fitcell=true);
$pdf->SetFont('helvetica', '', 10);
$pdf->SetXY(30,55);
$pdf->MultiCell($w=210-10-30, $h=0, $txt=$pdf->letter['sub_subject'], $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=5, $valign='T', $fitcell=true);
$border=0;
$max_height=0;
if(strlen($pdf->letter['reference'])>0)
{
$c_str=count_chars($pdf->letter['reference'],0);
$max_height=$c_str[13]*5+5;
$pdf->SetFont('helvetica', 'B', 10);
$pdf->SetXY(10,60);
$pdf->MultiCell($w=20, $h=0, $txt='Reference:', $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=5, $valign='T', $fitcell=true);
$pdf->SetFont('helvetica', '', 10);
$pdf->SetXY(30,60);
$pdf->MultiCell($w=210-10-30, $h=0, $txt=$pdf->letter['reference'], $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=$max_height, $valign='T', $fitcell=true);
}
$my_y=55+5+$max_height;
$pdf->SetFont('helvetica', 'B', 10);
$pdf->SetXY(10,$my_y);
$pdf->MultiCell($w=190, $h=0, $txt=$pdf->letter['greeting'].',', $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=5, $valign='T', $fitcell=true);
$pdf->SetFont('helvetica', '', 10);
$pdf->SetXY(10,$my_y+5);
$pdf->MultiCell($w=190, $h=0, $txt=$pdf->letter['body'].',', $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=0, $valign='T', $fitcell=true);
$x=$pdf->getX();
$y=$pdf->getY();
$pdf->SetFont('helvetica', '', 10);
$pdf->SetXY($x,$y+10);
$pdf->MultiCell($w=190, $h=0, $txt=$pdf->letter['thanks'].',', $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=0, $valign='T', $fitcell=true);
$x=$pdf->getX();
$y=$pdf->getY();
$pdf->SetFont('helvetica', '', 10);
$pdf->SetXY($x,$y+5);
$pdf->MultiCell($w=190, $h=0, $txt=$pdf->letter['closing'].',', $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=0, $valign='T', $fitcell=true);
$x=$pdf->getX();
$y=$pdf->getY();
$pdf->SetFont('helvetica', 'B', 10);
$pdf->SetXY($x,$y+5);
$pdf->MultiCell($w=190, $h=0, $txt=$pdf->letter['signature'].',', $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=0, $valign='T', $fitcell=true);
if(strlen($pdf->letter['attachment_list'])>0)
{
$x=$pdf->getX();
$y=$pdf->getY();
$pdf->SetFont('helvetica', 'B', 10);
$pdf->SetXY(10,$y+10);
$pdf->MultiCell($w=20, $h=0, $txt='Attachments:', $border, $align='L', $fill=false, $ln=0, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=5, $valign='T', $fitcell=true);
$pdf->SetFont('helvetica', '', 10);
$pdf->MultiCell($w=210-10-30, $h=0, $txt=$pdf->letter['attachment_list'], $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=$max_height, $valign='T', $fitcell=true);
}
if(strlen($pdf->letter['copy_to'])>0)
{
$x=$pdf->getX();
$y=$pdf->getY();
$pdf->SetFont('helvetica', 'B', 10);
$pdf->SetXY(10,$y+10);
$pdf->MultiCell($w=20, $h=0, $txt='Copy to:', $border, $align='L', $fill=false, $ln=0, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=5, $valign='T', $fitcell=true);
$pdf->SetFont('helvetica', '', 10);
$pdf->MultiCell($w=210-10-30, $h=0, $txt=$pdf->letter['copy_to'], $border, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=1, $ishtml=false, $autopadding=true, $maxh=$max_height, $valign='T', $fitcell=true);
}
$filename=$pdf->letter['id'].'-'.$pdf->letter['type'].'-'.$pdf->letter['date'].'.pdf';
$pdf->Output($filename, 'I');
}
if(!login_varify())
{
exit();
}
if($_POST['action'])
{
if($_POST['action']=='save')
{
save_letter($_POST);
}
}