01.
<?php
02.
03.
session_start();
04.
if
(
$_SESSION
[
'Idcard'
] !=
"admin@iveb"
)
05.
{
06.
echo
"Please Login!"
;
07.
exit
();
08.
}
09.
include
"connect.php"
;
10.
11.
$Idcard
=
$_SESSION
[
"Idcard"
];
12.
$IdStudent
=
$_SESSION
[
"IdStudent"
];
13.
14.
15.
16.
$date
=
$_POST
[
'date'
];
17.
$strSQL
=
"SELECT * FROM datastd, address where datastd.IdStudent Like '64%' AND datastd.status = 'confirm' AND datastd.refer ='complete' AND datastd.Idcard = address.Idcard AND dateRefer='$date' ORDER BY datastd.Dateupload"
;
18.
$objQuery
= mysqli_query(
$link
,
$strSQL
);
19.
$objResult
= mysqli_num_rows(
$objQuery
);
20.
21.
require_once
'PHPWord.php'
;
22.
$i
=1;
23.
while
(
$objResult
= mysqli_fetch_array(
$objQuery
))
24.
{
25.
26.
$PHPWord
=
new
PHPWord();
27.
28.
$document
=
$PHPWord
->loadTemplate(
'Template.docx'
);
29.
30.
31.
$amount
=
$objResult
[
'cashBack'
];
32.
$cashBack
=
substr
(
$amount
,1);
33.
34.
$document
->setValue(
'print_cashBack'
,
$cashBack
);
35.
$document
->setValue(
'print_dateRefer'
,
$objResult
[
'dateRefer'
]);
36.
$document
->setValue(
'print_PrefixTH'
,
$objResult
[
'PrefixTH'
]);
37.
$document
->setValue(
'print_FirstnameTH'
,
$objResult
[
'FirstnameTH'
]);
38.
$document
->setValue(
'print_LastnameTH'
,
$objResult
[
'LastnameTH'
]);
39.
$document
->setValue(
'print_IdStudent'
,
$objResult
[
'IdStudent'
]);
40.
$document
->setValue(
'print_subject'
,
$objResult
[
'subject'
]);
41.
$document
->setValue(
'print_TLB'
,
$objResult
[
'TLB'
]);
42.
$document
->setValue(
'print_college'
,
$objResult
[
'college'
]);
43.
$document
->setValue(
'print_NoH'
,
$objResult
[
'NoH'
]);
44.
$document
->setValue(
'print_Moo'
,
$objResult
[
'Moo'
]);
45.
$document
->setValue(
'print_Soi'
,
$objResult
[
'Soi'
]);
46.
$document
->setValue(
'print_Road'
,
$objResult
[
'Road'
]);
47.
$document
->setValue(
'print_canton'
,
$objResult
[
'canton'
]);
48.
$document
->setValue(
'print_District'
,
$objResult
[
'District'
]);
49.
$document
->setValue(
'print_province'
,
$objResult
[
'province'
]);
50.
$document
->setValue(
'print_postID'
,
$objResult
[
'postID'
]);
51.
$document
->setValue(
'print_tell'
,
$objResult
[
'tell'
]);
52.
$document
->setValue(
'print_email'
,
$objResult
[
'email'
]);
53.
$document
->setValue(
'print_accountCode'
,
$objResult
[
'accountCode'
]);
54.
$document
->setValue(
'print_bank'
,
$objResult
[
'bank'
]);
55.
$document
->setValue(
'print_major'
,
$objResult
[
'major'
]);
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
$file
=
'MemberLetters.docx'
.
$objResult
[0];
72.
$document
->save(
$file
);
73.
74.
if
(!
$file
) {
75.
76.
die
(
'file not found'
);
77.
}
78.
else
{
79.
header(
"Cache-Control: public"
);
80.
header(
"Content-Description: File Transfer"
);
81.
header(
"Content-Disposition: attachment; filename=$file"
);
82.
header(
"Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document"
);
83.
header(
"Content-Transfer-Encoding: binary"
);
84.
85.
readfile(
$file
);
86.
}
87.
$i
++;
88.
unlink(
$file
);
89.
90.
exit
;
91.
}
92.
93.
94.
?>