-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.php
236 lines (208 loc) · 9.18 KB
/
mail.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer();
try {
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com;';
$mail->SMTPAuth = true;
$mail->Username = $_REQUEST['sender']; // Enter your gmail-id
$mail->Password = $_REQUEST['password']; // Enter your gmail app password that you generated
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom($_REQUEST['sender']); // This mail-id will be same as your gmail-id
$mail->addAddress($_REQUEST['receiver']); // Enter your reciever email-id
$mail->isHTML(true); // Set email format to HTML
$folder_name = $_REQUEST['folder_name'];
$mail->Subject = $folder_name;
if ($_REQUEST['action'] === 'shai1') {
$folder_path = $_REQUEST['path'];
$file_name = '00_ALL_' . $folder_name . '_CA Window Door.csv';
$mail->AddAttachment($folder_path . '\\' . $file_name, $file_name);
$mail->Body = " ";
}
if ($_REQUEST['action'] === 'shai2') {
$folder_path = $_REQUEST['path'];
$file_name1 = '01_ALL_' . $folder_name . '_KitchenBathDecksRenovate.csv';
$mail->AddAttachment($folder_path . '\\' . $file_name1, $file_name1);
$file_name2 = '02_LA_' . $folder_name . '.csv';
$mail->AddAttachment($folder_path . '\\' . $file_name2, $file_name2);
$file_name3 = '03_SD_' . $folder_name . '.csv';
$mail->AddAttachment($folder_path . '\\' . $file_name3, $file_name3);
$file_name4 = '04_WA_' . $folder_name . '.csv';
$mail->AddAttachment($folder_path . '\\' . $file_name4, $file_name4);
$file_name5 = '05_BAY_' . $folder_name . ' South.csv';
$mail->AddAttachment($folder_path . '\\' . $file_name5, $file_name5);
$file_name6 = '06_BAY_' . $folder_name . ' North.csv';
$mail->AddAttachment($folder_path . '\\' . $file_name6, $file_name6);
$file_name7 = '07_OR_' . $folder_name . '.csv';
$mail->AddAttachment($folder_path . '\\' . $file_name7, $file_name7);
$file_name8 = '08_TX_Austin_' . $folder_name . '.csv';
$mail->AddAttachment($folder_path . '\\' . $file_name8, $file_name8);
$file_name9 = '09_TX_Houston_' . $folder_name . '.csv';
$mail->AddAttachment($folder_path . '\\' . $file_name9, $file_name9);
$file_name10 = '10_TX_Dallas_' . $folder_name . '.csv';
$mail->AddAttachment($folder_path . '\\' . $file_name10, $file_name10);
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
date_default_timezone_set('America/Los_Angeles');
$count_path = $_REQUEST['count_path'];
$a_counts = [
0 => [
'c' => '0 Shai - W D, CA',
'k' => 'CA W, D',
'i' => -1,
'v' => 0,
],
1 => [
'c' => '1 Shai KBD',
'k' => 'KBDR',
'i' => -1,
'v' => 0,
],
2 => [
'c' => '2 ALIT Shai LA',
'k' => 'LA',
'i' => -1,
'v' => 0,
],
3 => [
'c' => '3 ALIT Shai SD',
'k' => 'SD',
'i' => -1,
'v' => 0,
],
4 => [
'c' => '4 ALIT Shai WA',
'k' => 'WA',
'i' => -1,
'v' => 0,
],
5 => [
'c' => '5 ALIT Shai BAY South',
'k' => 'BAY S.',
'i' => -1,
'v' => 0,
],
6 => [
'c' => '6 ALIT Shai BAY Noth',
'k' => 'BAY N.',
'i' => -1,
'v' => 0,
],
7 => [
'c' => '7 ALIT Shai OR',
'k' => 'OR',
'i' => -1,
'v' => 0,
],
8 => [
'c' => '8 ALIT Shai TX',
'k' => 'AUS',
'i' => -1,
'v' => 0,
],
9 => [
'c' => ' 9 ALIT Shai TX HOU',
'k' => 'HOU',
'i' => -1,
'v' => 0,
],
10 => [
'c' => '10 ALIT Shai TX DAL',
'k' => 'DAL',
'i' => -1,
'v' => 0,
]
];
$spreadsheet = $reader->load($count_path);
$d = $spreadsheet->getSheet(0)->toArray();
foreach($d as $r) {
foreach($r as $i => $c) {
foreach($a_counts as $j => $a_c) {
if ($a_c['c'] === $c) {
$a_counts[$j]['i'] = $i;
}
}
}
}
$sp = explode(' ', $folder_name);
$date = substr($sp[0], 0, 2) . '/' . substr($sp[0], 2, 2) . '/' . substr($sp[0], 4, 4);
$date_info = getDate(strtotime($date));
$time = ($sp[1] == '8AM' ? '8am' : '2pm');
if ($date_info['wday'] == 4) {
$cur_index = -1;
$cur_row = [];
foreach ($d as $i => $row) {
if (strtotime($row[0]) == strtotime($date) && strpos($row[1], "8am") > 0) {
$cur_index = $i; $cur_row = $row;
}
}
if ($cur_index !== -1) {
foreach($a_counts as $i => $a_c) {
$a_counts[$i]['v'] = $cur_row[$a_c['i']];
}
}
if ($time == "2pm") {
$cur_index = -1;
$cur_row = [];
foreach ($d as $i => $row) {
if (strtotime($row[0]) == strtotime($date) && strpos($row[1], "2pm") > 0) {
$cur_index = $i; $cur_row = $row;
}
}
if ($cur_index !== -1) {
foreach($a_counts as $i => $a_c) {
$a_counts[$i]['v'] = $a_counts[$i]['v'] . ' ' . $cur_row[$a_c['i']];
}
}
}
} else {
$cur_index = -1;
$cur_row = [];
foreach ($d as $i => $row) {
if (strtotime($row[0]) == strtotime($date)) {
$cur_index = $i; $cur_row = $row;
}
}
if ($cur_index !== -1) {
foreach($a_counts as $i => $a_c) {
if ($time == "2pm") {
$a_counts[$i]['v'] = $cur_row[$a_c['i']];
} else {
$sp1 = explode(' ', $cur_row[$a_c['i']]);
$a_counts[$i]['v'] = $sp1[0];
}
}
}
}
$mail->Body = "<table border='0' cellpadding='0' cellspacing='0' width='726' style='border-collapse:collapse;width:539pt'>
<colgroup><col width='66' span='11' style='width:49pt'>
</colgroup>
<tbody>
<tr height='18' style='height:13.4pt'>
<td height='18' width='66' style='height:13.4pt;width:49pt;font-size:9pt;font-weight:700;font-family:Calibri,sans-serif;text-align:center;border:1pt solid silver;padding-top:1px;padding-right:1px;padding-left:1px;color:windowtext;vertical-align:bottom'>". $a_counts[0]['v'] ."</td>";
for ($i = 1; $i < 11; $i++) {
$mail->Body .= "<td width='66' style='border-left:none;width:49pt;font-size:9pt;font-weight:700;font-family:Calibri,sans-serif;text-align:center;border-top:1pt solid silver;border-right:1pt solid silver;border-bottom:1pt solid silver;padding-top:1px;padding-right:1px;padding-left:1px;color:windowtext;vertical-align:bottom'>". $a_counts[$i]['v'] ."</td>";
}
$mail->Body .= "</tr>";
$mail->Body .= "<tr height='18' style='height:13.4pt'>
<td height='18' width='66' style='height:13.4pt;border-top:none;width:49pt;font-size:9pt;font-weight:700;font-family:Calibri,sans-serif;text-align:center;border-right:1pt solid silver;border-bottom:1pt solid silver;border-left:1pt solid silver;padding-top:1px;padding-right:1px;padding-left:1px;color:windowtext;vertical-align:bottom'>". $a_counts[0]['k'] ."</td>";
for ($i = 1; $i < 11; $i++) {
$mail->Body .= "<td width='66' style='border-top:none;border-left:none;width:49pt;font-size:9pt;font-weight:700;font-family:Calibri,sans-serif;text-align:center;border-right:1pt solid silver;border-bottom:1pt solid silver;padding-top:1px;padding-right:1px;padding-left:1px;color:windowtext;vertical-align:bottom'>". $a_counts[$i]['k'] ."</td>";
}
$mail->Body .= "</tr></tbody></table>";
}
if ($_REQUEST['action'] === 'palm1') {
$folder_path = $_REQUEST['path'];
$file_name = $folder_name . '_PALM.xls';
$mail->AddAttachment($folder_path . '\\' . $file_name, $file_name);
$mail->Body = " ";
}
$mail->send();
echo json_encode(array("status" => "success"));
} catch (Exception $e) {
echo json_encode(array("status" => "error"));
}
?>