-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathget_ups_xml.php
133 lines (103 loc) · 3.69 KB
/
get_ups_xml.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
<?php
// Kutsutaanko CLI:stä
if (php_sapi_name() != 'cli') {
die ("Tätä scriptiä voi ajaa vain komentoriviltä!");
}
date_default_timezone_set('Europe/Helsinki');
require 'inc/connect.inc';
require 'inc/functions.inc';
// Logitetaan ajo
cron_log();
foreach ($ups_path as $ups_key => $ups_val) {
$ups_host_temp = $ups_host[$ups_key];
$ups_user_temp = $ups_user[$ups_key];
$ups_pass_temp = $ups_pass[$ups_key];
$ups_path_temp = $ups_val;
if ($ups_host_temp != "" and $ups_user_temp != "" and $ups_pass_temp != "" and $ups_path_temp != "") {
unset($conn_id, $login, $changedir, $files_xxx, $files, $fileget, $xml);
$ups_dellattuja = 0;
$ups_lisattuja = 0;
// avataan yhteys
$conn_id = ftp_connect($ups_host_temp) or die("Connection failed @ $ups_host_temp!\n");
// kokeillaan login
if ($conn_id) {
$login = @ftp_login($conn_id, $ups_user_temp, $ups_pass_temp);
}
// vaihdetaan dirikka
if ($login) {
$changedir = ftp_chdir($conn_id, $ups_path_temp);
}
// haetaan filet active modella
if ($changedir) {
ftp_pasv($conn_id, false);
$files_xxx = @ftp_nlist($conn_id, "*.xxx");
$files = @ftp_nlist($conn_id, "*.Out");
}
// joe epäonnistu, haetaaan filet passive modella
if (!$files_xxx) {
ftp_pasv($conn_id, true);
$files_xxx = ftp_nlist($conn_id, "*.xxx");
$files = ftp_nlist($conn_id, "*.Out");
}
// dellataan löydetyt *.xxx filet
if ($files_xxx) {
foreach ($files_xxx as $file) {
ftp_delete($conn_id, $file);
$ups_dellattuja++;
}
}
// käydään läpi kaikki *.out filet
if ($files) {
foreach ($files as $file) {
$fileget = ftp_get($conn_id, '/tmp/ups_temp_file.xml', $file, FTP_BINARY);
if ($fileget) {
$xml = simplexml_load_file('/tmp/ups_temp_file.xml');
}
if ($xml) {
foreach ($xml->children() as $children) {
$reference_number = '';
$ups_tracking_number = '';
$xml_yhtio = '';
foreach ($children as $child) {
if ($child->getName() == 'ShipmentInformation') {
$reference_number = $child->Reference1;
}
elseif ($child->getName() == 'ProcessMessage') {
foreach ($child->TrackingNumbers->children() as $ups_tracking_num) {
$ups_tracking_number .= " UPS:$ups_tracking_num";
}
}
elseif ($child->getName() == 'ShipFrom') {
$xml_yhtio = $child->CustomerID;
}
}
if ($reference_number != '' and $ups_tracking_number != '' and $xml_yhtio != '') {
$query = "SELECT yhtio
FROM yhtio
WHERE ytunnus = '$xml_yhtio'";
$result = pupe_query($query);
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_assoc($result);
$query = "UPDATE rahtikirjat SET
rahtikirjanro = concat(rahtikirjanro, '$ups_tracking_number')
WHERE yhtio = '$row[yhtio]'
AND otsikkonro = $reference_number";
$result = pupe_query($query);
$ups_lisattuja++;
}
else {
echo "Ei loydetty yhtiota ytunnuksella $xml_yhtio!!!\n";
}
}
}
ftp_delete($conn_id, $file);
$ups_dellattuja++;
}
}
echo date("d.m.Y @ G:i:s").": Päivitettiin $ups_lisattuja rahtikirjanumeroa. Dellattiin $ups_dellattuja tiedostoa.\n";
}
if ($conn_id) {
ftp_close($conn_id);
}
}
}