-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftp_tuote_tiedot.php
executable file
·322 lines (247 loc) · 15.1 KB
/
ftp_tuote_tiedot.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
//* Tämä skripti käyttää slave-tietokantapalvelinta *//
$useslave = 1;
// Kutsutaanko CLI:stä
$php_cli = FALSE;
if (php_sapi_name() == 'cli') {
$php_cli = TRUE;
}
if (!$php_cli) {
require "inc/parametrit.inc";
$kyhtio = $kukarow['yhtio'];
}
else {
if ($argv[1] != "") $kyhtio = trim($argv[1]);
else die ("Yhtiö on annettava!");
require "/var/www/html/pupesoft/inc/connect.inc";
require "/var/www/html/pupesoft/inc/functions.inc";
// Logitetaan ajo
cron_log();
$tee = "aja";
}
// palautetaan $syy
function tee_file($result, $dirri, $tiedostonnimi, $ftpkuvahost, $ftpkuvauser, $ftpkuvapass) {
//lähetetään tiedosto
$conn_id = ftp_connect($ftpkuvahost);
// jos connectio ok, kokeillaan loginata
if ($conn_id) {
$login_result = ftp_login($conn_id, $ftpkuvauser, $ftpkuvapass);
if ($login_result === FALSE) {
$syy .= "Could not login to remote host ($conn_id, $ftpkuvauser, $ftpkuvapass)\n";
}
}
else {
$syy .= "Could not connect to remote host. ($ftpkuvahost)\n";
}
// jos login ok kokeillaan uploadata
if ($login_result) {
ftp_pasv($conn_id, true);
$kokonimi = $dirri."/".$tiedostonnimi;
if (!file_exists($kokonimi)) {
$handle = fopen("$kokonimi", "x");
if ($handle === FALSE) {
$syy .= "Tiedoston $kokonimi luonti epäonnistui!\n";
}
else {
$fields = mysqli_num_fields($result);
$ulos = "";
for ($i=0; $i < $fields; $i++) {
$ulos .= mysqli_field_name($result, $i);
if ($i == $fields-1) {
$ulos .= "\n";
}
else {
$ulos .= "\t";
}
}
$order = array("\r\n", "\n", "\r");
while ($row = mysqli_fetch_array($result)) {
for ($i=0; $i < $fields; $i++) {
if (mb_strpos($row[$i], '"') !== FALSE) {
$row[$i] = str_replace('"', "", $row[$i]);
}
if (mb_strpos(($temp = mysqli_field_name($result, $i)), "lyhytkuvaus") !== FALSE) {
$row[$i] = cut_text($row[$i], 100);
}
/*
if (mb_strpos(($temp = mysqli_field_name($result, $i)),"mainosteksti") !== FALSE or mb_strpos(($temp = mysqli_field_name($result, $i)),"kuvaus") !== FALSE) {
$from = array("[lihavoitu]", "[/lihavoitu]", "[kursivoitui]", "[/kursivoitu]", "[alleviivaus]", "[/alleviivaus]", "[lista]", "[/lista]");
$to = array("<b>", "</b>", "<i>", "</i>", "<u>", "</u>", "<ul>", "</li></ul>");
$row[$i] = str_replace($from,$to,$row[$i]);
$ulcount = mb_substr_count($row[$i], "<ul>");
$ulppos = 0;
for ($s=0; $s < $ulcount; $s++) {
$ulpos = mb_strpos($row[$i], "<ul>",$ulpos);
$ilpos = mb_strpos($row[$i], "[*]", $ulpos);
$row[$i] = substr_replace($row[$i],"<li>",$ilpos,3);
$ulpos = $ilpos;
}
$row[$i] = str_replace("[*]","</li><li>",$row[$i]);
}*/
$ulos .= str_replace($order, "<br>", $row[$i]);
if ($i == $fields-1) {
$ulos .= "\n";
}
else {
$ulos .= "\t";
}
}
}
fputs($handle, $ulos);
fclose($handle);
$upload = ftp_put($conn_id, $tiedostonnimi, realpath($kokonimi), FTP_BINARY);
//check upload
if ($upload === FALSE) {
$syy .= "Transfer failed ($conn_id, $tiedostonnimi, ".realpath($kokonimi).")\n";
}
}
//poistetaan filu
unlink($kokonimi);
}
}
if ($conn_id) {
ftp_close($conn_id);
}
return $syy;
}
function cut_text($text, $chars) {
if (mb_strlen($text) == 0 or mb_strlen($text) < $chars) {
return $text;
}
else {
if (mb_substr($text, $chars) == " ") {
return mb_substr($text, 0, $chars)."...";
}
elseif (mb_substr($text, $chars) == ".") {
return mb_substr($text, 0, $chars)."..";
}
elseif (mb_substr($text, $chars) == ",") {
return mb_substr($text, 0, $chars-1)."...";
}
else {
$text = mb_substr($text, 0, $chars);
$pos[0] = mb_strrpos($text, " ");
$pos[1] = mb_strrpos($text, ".");
$pos[2] = mb_strrpos($text, ",");
sort($pos);
if (mb_substr($text, $pos[2], 1) == " ") {
return mb_substr($text, 0, $pos[2])."...";
}
elseif (mb_substr($text, $pos[2], 1) == ".") {
return mb_substr($text, 0, $pos[2])."..";
}
elseif (mb_substr($text, $pos[2], 1) == ",") {
return mb_substr($text, 0, $pos[2]-1)."...";
}
}
}
return "";
}
$syy = "";
if ($tee == "aja") {
echo date("H:i:s").": Aloitetaan tuotetietojen siirto.\n";
// tarvitaan $ftpkuvahost $ftpkuvauser $ftpkuvapass
if ($ftpkuvahost=='' or $ftpkuvauser=='' or $ftpkuvapass=='') {
$syy .= "Lähetykseen tarvittavia tietoja puuttuu! (host, user, pass)";
}
else {
$dirri = "/tmp";
if (!is_writable($dirri)) {
die("$kokonimi ei ole määritelty kirjoitusoikeutta. Ei voida jatkaa!<br>");
}
/*tuotetieto haku*/
$query = "SELECT tuote.tuoteno, tuote.try, tuote.osasto, tuote.nimitys, ta_nimitys_se.selite as nimitys_se,
tuote.kuvaus, ta_kuvaus_se.selite as kuvaus_se,
group_concat(liitetiedostot.filename SEPARATOR ',') as tiedostot,
group_concat(liitetiedostot.selite SEPARATOR ',') as selitteet,
tuote.kuvaus as lyhytkuvaus, ta_kuvaus_se.selite as lyhytkuvaus_se,
ta_nimitys_en.selite as nimitys_en, ta_kuvaus_en.selite as kuvaus_en, ta_kuvaus_en.selite as lyhytkuvaus_en,
ta_nimitys_ru.selite as nimitys_ru, ta_kuvaus_ru.selite as kuvaus_ru, ta_kuvaus_ru.selite as lyhytkuvaus_ru,
ta_nimitys_ee.selite as nimitys_ee, ta_kuvaus_ee.selite as kuvaus_ee, ta_kuvaus_ee.selite as lyhytkuvaus_ee,
ta_nimitys_de.selite as nimitys_de, ta_kuvaus_de.selite as kuvaus_de, ta_kuvaus_de.selite as lyhytkuvaus_de,
tuote.myyntihinta
FROM tuote
LEFT JOIN liitetiedostot on tuote.yhtio = liitetiedostot.yhtio and tuote.tunnus = liitetiedostot.liitostunnus and liitetiedostot.liitos = 'tuote' and liitetiedostot.kayttotarkoitus in ('TK','MU')
LEFT JOIN tuotteen_avainsanat as ta_nimitys_se on tuote.yhtio = ta_nimitys_se.yhtio and tuote.tuoteno = ta_nimitys_se.tuoteno and ta_nimitys_se.laji = 'nimitys' and ta_nimitys_se.kieli='se'
LEFT JOIN tuotteen_avainsanat as ta_kuvaus_se on tuote.yhtio = ta_kuvaus_se.yhtio and tuote.tuoteno = ta_kuvaus_se.tuoteno and ta_kuvaus_se.laji = 'kuvaus' and ta_kuvaus_se.kieli='se'
LEFT JOIN tuotteen_avainsanat as ta_lyhyt_se on tuote.yhtio = ta_lyhyt_se.yhtio and tuote.tuoteno = ta_lyhyt_se.tuoteno and ta_lyhyt_se.laji = 'lyhyt' and ta_lyhyt_se.kieli='se'
LEFT JOIN tuotteen_avainsanat as ta_nimitys_en on tuote.yhtio = ta_nimitys_en.yhtio and tuote.tuoteno = ta_nimitys_en.tuoteno and ta_nimitys_en.laji = 'nimitys' and ta_nimitys_en.kieli='en'
LEFT JOIN tuotteen_avainsanat as ta_kuvaus_en on tuote.yhtio = ta_kuvaus_en.yhtio and tuote.tuoteno = ta_kuvaus_en.tuoteno and ta_kuvaus_en.laji = 'kuvaus' and ta_kuvaus_en.kieli='en'
LEFT JOIN tuotteen_avainsanat as ta_lyhyt_en on tuote.yhtio = ta_lyhyt_en.yhtio and tuote.tuoteno = ta_lyhyt_en.tuoteno and ta_lyhyt_en.laji = 'lyhyt' and ta_lyhyt_en.kieli='en'
LEFT JOIN tuotteen_avainsanat as ta_nimitys_ru on tuote.yhtio = ta_nimitys_ru.yhtio and tuote.tuoteno = ta_nimitys_ru.tuoteno and ta_nimitys_ru.laji = 'nimitys' and ta_nimitys_ru.kieli='ru'
LEFT JOIN tuotteen_avainsanat as ta_kuvaus_ru on tuote.yhtio = ta_kuvaus_ru.yhtio and tuote.tuoteno = ta_kuvaus_ru.tuoteno and ta_kuvaus_ru.laji = 'kuvaus' and ta_kuvaus_ru.kieli='ru'
LEFT JOIN tuotteen_avainsanat as ta_lyhyt_ru on tuote.yhtio = ta_lyhyt_ru.yhtio and tuote.tuoteno = ta_lyhyt_ru.tuoteno and ta_lyhyt_ru.laji = 'lyhyt' and ta_lyhyt_ru.kieli='ru'
LEFT JOIN tuotteen_avainsanat as ta_nimitys_ee on tuote.yhtio = ta_nimitys_ee.yhtio and tuote.tuoteno = ta_nimitys_ee.tuoteno and ta_nimitys_ee.laji = 'nimitys' and ta_nimitys_ee.kieli='ee'
LEFT JOIN tuotteen_avainsanat as ta_kuvaus_ee on tuote.yhtio = ta_kuvaus_ee.yhtio and tuote.tuoteno = ta_kuvaus_ee.tuoteno and ta_kuvaus_ee.laji = 'kuvaus' and ta_kuvaus_ee.kieli='ee'
LEFT JOIN tuotteen_avainsanat as ta_lyhyt_ee on tuote.yhtio = ta_lyhyt_ee.yhtio and tuote.tuoteno = ta_lyhyt_ee.tuoteno and ta_lyhyt_ee.laji = 'lyhyt' and ta_lyhyt_ee.kieli='ee'
LEFT JOIN tuotteen_avainsanat as ta_nimitys_de on tuote.yhtio = ta_nimitys_de.yhtio and tuote.tuoteno = ta_nimitys_de.tuoteno and ta_nimitys_de.laji = 'nimitys' and ta_nimitys_de.kieli='de'
LEFT JOIN tuotteen_avainsanat as ta_kuvaus_de on tuote.yhtio = ta_kuvaus_de.yhtio and tuote.tuoteno = ta_kuvaus_de.tuoteno and ta_kuvaus_de.laji = 'kuvaus' and ta_kuvaus_de.kieli='de'
LEFT JOIN tuotteen_avainsanat as ta_lyhyt_de on tuote.yhtio = ta_lyhyt_de.yhtio and tuote.tuoteno = ta_lyhyt_de.tuoteno and ta_lyhyt_de.laji = 'lyhyt' and ta_lyhyt_de.kieli='de'
join avainsana as avtry on tuote.yhtio = avtry.yhtio and tuote.try = avtry.selite and avtry.laji = 'TRY' and avtry.nakyvyys != 'E' and avtry.kieli = 'fi'
join avainsana as avosasto on tuote.yhtio = avosasto.yhtio and tuote.osasto = avosasto.selite and avosasto.laji = 'OSASTO' and avosasto.nakyvyys != 'E' and avosasto.kieli = 'fi'
WHERE tuote.yhtio = '$kyhtio'
AND tuote.hinnastoon = 'W'
AND tuote.status NOT IN ('P','X')
AND tuote.tuotetyyppi NOT IN ('A', 'B')
GROUP BY tuote.tuoteno, tuote.try, tuote.osasto, tuote.nimitys, substring(ta_nimitys_se.selite,1,1024), substring(tuote.kuvaus,1,1024), substring(ta_kuvaus_se.selite,1,1024),
substring(ta_nimitys_en.selite,1,1024), substring(ta_kuvaus_en.selite,1,1024), substring(ta_nimitys_ru.selite,1,1024), substring(ta_kuvaus_ru.selite,1,1024),
substring(ta_nimitys_ee.selite,1,1024), substring(ta_kuvaus_ee.selite,1,1024), substring(ta_nimitys_de.selite,1,1024), substring(ta_kuvaus_de.selite,1,1024)
ORDER BY tuote.tuoteno";
$result = pupe_query($query);
$syy .= tee_file($result, $dirri, "tuotetiedot.csv", $ftpkuvahost, $ftpkuvauser, $ftpkuvapass);
/*osastot*/
$query = "SELECT avainsana.selite as osasto, avainsana.selitetark as nimitys,
if(isnull(se.selitetark) or se.selitetark='', '', se.selitetark) as nimitys_se,
avainsana.selitetark_3 as kuvaus, if(isnull(se.selitetark_3) or se.selitetark_3='', '', se.selitetark_3) as kuvaus_se,
if(isnull(en.selitetark) or en.selitetark='', '', en.selitetark) as nimitys_en, if(isnull(en.selitetark_3) or en.selitetark_3='', '', en.selitetark_3) as kuvaus_en,
if(isnull(ru.selitetark) or ru.selitetark='', '', ru.selitetark) as nimitys_ru, if(isnull(ru.selitetark_3) or ru.selitetark_3='', '', ru.selitetark_3) as kuvaus_ru,
if(isnull(ee.selitetark) or ee.selitetark='', '', ee.selitetark) as nimitys_ee, if(isnull(ee.selitetark_3) or ee.selitetark_3='', '', ee.selitetark_3) as kuvaus_ee,
if(isnull(de.selitetark) or de.selitetark='', '', de.selitetark) as nimitys_de, if(isnull(de.selitetark_3) or de.selitetark_3='', '', de.selitetark_3) as kuvaus_de
FROM avainsana
LEFT JOIN avainsana AS se on avainsana.yhtio = se.yhtio and avainsana.selite = se.selite and se.laji = 'OSASTO' and se.kieli = 'se'
LEFT JOIN avainsana AS en on avainsana.yhtio = en.yhtio and avainsana.selite = en.selite and en.laji = 'OSASTO' and en.kieli = 'en'
LEFT JOIN avainsana AS ru on avainsana.yhtio = ru.yhtio and avainsana.selite = ru.selite and ru.laji = 'OSASTO' and ru.kieli = 'ru'
LEFT JOIN avainsana AS ee on avainsana.yhtio = ee.yhtio and avainsana.selite = ee.selite and ee.laji = 'OSASTO' and ee.kieli = 'ee'
LEFT JOIN avainsana AS de on avainsana.yhtio = de.yhtio and avainsana.selite = de.selite and de.laji = 'OSASTO' and de.kieli = 'de'
WHERE avainsana.yhtio = '$kyhtio'
AND avainsana.laji = 'OSASTO'
AND avainsana.kieli = 'fi'
AND avainsana.nakyvyys != 'E'
ORDER BY avainsana.jarjestys";
$result = pupe_query($query);
$syy .= tee_file($result, $dirri, "osastot.csv", $ftpkuvahost, $ftpkuvauser, $ftpkuvapass);
/*tuoteryhmät*/
$query = "SELECT avainsana.selite as try, avainsana.selitetark as nimitys,
if(isnull(se.selitetark) or se.selitetark='', '', se.selitetark) as nimitys_se,
avainsana.selitetark_3 as kuvaus, if(isnull(se.selitetark_3) or se.selitetark_3='', '', se.selitetark_3) as kuvaus_se,
if(isnull(en.selitetark) or en.selitetark='', '', en.selitetark) as nimitys_en, if(isnull(en.selitetark_3) or en.selitetark_3='', '', en.selitetark_3) as kuvaus_en,
if(isnull(ru.selitetark) or ru.selitetark='', '', ru.selitetark) as nimitys_ru, if(isnull(ru.selitetark_3) or ru.selitetark_3='', '', ru.selitetark_3) as kuvaus_ru,
if(isnull(ee.selitetark) or ee.selitetark='', '', ee.selitetark) as nimitys_ee, if(isnull(ee.selitetark_3) or ee.selitetark_3='', '', ee.selitetark_3) as kuvaus_ee,
if(isnull(de.selitetark) or de.selitetark='', '', de.selitetark) as nimitys_de, if(isnull(de.selitetark_3) or de.selitetark_3='', '', de.selitetark_3) as kuvaus_de
FROM avainsana
LEFT JOIN avainsana AS se on avainsana.yhtio = se.yhtio and avainsana.selite = se.selite and se.laji = 'TRY' and se.kieli = 'se'
LEFT JOIN avainsana AS en on avainsana.yhtio = en.yhtio and avainsana.selite = en.selite and en.laji = 'TRY' and en.kieli = 'en'
LEFT JOIN avainsana AS ru on avainsana.yhtio = ru.yhtio and avainsana.selite = ru.selite and ru.laji = 'TRY' and ru.kieli = 'ru'
LEFT JOIN avainsana AS ee on avainsana.yhtio = ee.yhtio and avainsana.selite = ee.selite and ee.laji = 'TRY' and ee.kieli = 'ee'
LEFT JOIN avainsana AS de on avainsana.yhtio = de.yhtio and avainsana.selite = de.selite and de.laji = 'TRY' and de.kieli = 'de'
WHERE avainsana.yhtio = '$kyhtio'
AND avainsana.laji = 'TRY'
AND avainsana.kieli = 'fi'
AND avainsana.nakyvyys != 'E'
ORDER BY avainsana.jarjestys";
$result = pupe_query($query);
$syy .= tee_file($result, $dirri, "tuoteryhmat.csv", $ftpkuvahost, $ftpkuvauser, $ftpkuvapass);
if ($syy != "") {
echo $syy;
}
}
echo date("H:i:s").": Tuotetietojen siirto valmis.\n\n";
}
if ($tee == "") {
echo "<font class='head'>".t("Tuotetietojen siirto verkkokauppaan")."</font><hr>";
echo "<table><form name='uliuli' method='post'>";
echo "<input type='hidden' name='tee' value='aja'>";
echo "<tr><td class='back' colspan='2'><br><input type='submit' value='".t("Siirrä tiedot")."'></td></tr>";
echo "</table>";
echo "</form>";
}