Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
500 lines (454 loc) · 22.4 KB
/
Copy pathindex.php
File metadata and controls
500 lines (454 loc) · 22.4 KB
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<?php
session_start();
// Returns a file size limit in bytes based on the PHP upload_max_filesize
// and post_max_size
function file_upload_max_size() {
static $max_size = -1;
if ($max_size < 0) {
// Start with post_max_size.
$post_max_size = parse_size(ini_get('post_max_size'));
if ($post_max_size > 0) {
$max_size = $post_max_size;
}
// If upload_max_size is less, then reduce. Except if upload_max_size is
// zero, which indicates no limit.
$upload_max = parse_size(ini_get('upload_max_filesize'));
if ($upload_max > 0 && $upload_max < $max_size) {
$max_size = $upload_max;
}
}
return $max_size;
}
function parse_size($size) {
$unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size.
$size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size.
if ($unit) {
// Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by.
return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
} else {
return round($size);
}
}
function sec_file_upload($f_name, $ext) {
$sess_id = session_id();
$target_dir = "tmp_uploads/";
$target_file = $target_dir . $sess_id . '_' . basename($_FILES[$f_name]["name"]);
$extension = pathinfo($target_file, PATHINFO_EXTENSION);
if (strpos($_FILES[$f_name]["name"], '/') || strpos($_FILES[$f_name]["name"], '\\')) {
return 4;
}
if (strcasecmp($extension, $ext)) {
return 1;
}
// Check file size up to 50MB
if ($_FILES[$f_name]["size"] > file_upload_max_size()) {
echo "Sorry, your file is too large(Limit:" . file_upload_max_size() . "). Contact system administrator.";
return 2;
}
if (move_uploaded_file($_FILES[$f_name]["tmp_name"], $target_file)) {
return 0;
} else {
return 3;
}
}
function clean_tmp($farray) {
$target_dir = "tmp_uploads/";
$sess_id = session_id();
foreach ($farray as $ffile) {
if (is_file($target_dir . $sess_id . '_' . $ffile)) {
unlink($target_dir . $sess_id . '_' . $ffile);
}
}
}
function rrmdir($dir,$archive) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (is_dir($dir . "/" . $object)) {
rrmdir($dir . "/" . $object,$archive);
} else if ($archive==0){
if(stripos($object, "mrp_import.zip") === false) {
unlink($dir . "/" . $object);
}
}else {
unlink($dir . "/" . $object);
}
}
}
rmdir($dir);
}
}
function mrpkssklad(){
echo '<header class="w3-container" style="padding-top:22px">
<h5><b><i class="fa fa-dashboard"></i> Prevody do MRP K/S</b></h5>
</header>
<form method="post" target="index.php" enctype="multipart/form-data">
<div class="w3-row-padding w3-margin-bottom">
<div class="w3-threequarter">
<h4>Pre úpravu vygenerovaných XML súborov pre import do MRP K/S, priložte nasledovné súbory</h4>
<p>Súbor XML s vystavenými faktúrami: <input type="file" name="f_xml_fakodb" id="f_xml_fakodb"></input><i id="sf_xml_fakodb" aria-hidden="true" class="fa fa-square-o"></i></p>
<hr>
Kliknutím na nasledovné tlačidlo zahájite tvorbu XML súboru pre import do MRP: <input type="submit" class="button" name="generujks_sklad2007" value="Vygenerovať">
</div>
</div>
</form>
<div class="w3-panel">
<div class="w3-row-padding" style="margin:0 -16px">
</div>
</div>';
}
function ecosunmrpks(){
echo '<header class="w3-container" style="padding-top:22px">
<h5><b><i class="fa fa-dashboard"></i> Prevod zo Sunsoft EcoSun K/S XML do MRP K/S</b></h5>
</header>
<form method="post" target="index.php" enctype="multipart/form-data">
<div class="w3-row-padding w3-margin-bottom">
<div class="w3-threequarter">
<h4>Pre úpravu vygenerovaných XML súborov pre efektívnejši import do MRP K/S(typ polozky, typ sumy dph), priložte nasledovné súbory</h4>
<p>Súbor XML s vystavenými faktúrami: <input type="file" name="f_xml_fakodb" id="f_xml_fakodb"></input><i id="sf_xml_fakodb" aria-hidden="true" class="fa fa-square-o"></i></p>
<hr>
Kliknutím na nasledovné tlačidlo zahájite tvorbu XML súboru pre import do MRP: <input type="submit" class="button" name="generujks_ecosun" value="Vygenerovať">
</div>
</div>
</form>
<div class="w3-panel">
<div class="w3-row-padding" style="margin:0 -16px">
</div>
</div>';
}
function omegatxtfvydanemrpks(){
echo '<header class="w3-container" style="padding-top:22px">
<h5><b><i class="fa fa-dashboard"></i> Prevod vydaných faktúr z KROS OMEGA vo formáte TXT(CSV) do MRP K/S</b></h5>
</header>
<form method="post" target="index.php" enctype="multipart/form-data">
<div class="w3-row-padding w3-margin-bottom">
<div class="w3-threequarter">
<h4>Pre vytvorenie XML súborov pre import vydaných faktúr do MRP K/S, priložte nasledovné súbory</h4>
<p>Súbor TXT s vystavenými faktúrami: <input type="file" name="f_txt" id="f_txt"></input><i id="sf_txt" aria-hidden="true" class="fa fa-square-o"></i></p>
<hr>
Kliknutím na nasledovné tlačidlo zahájite tvorbu XML súboru pre import do MRP: <input type="submit" class="button" name="generujks_omegafv" value="Vygenerovať">
</div>
</div>
</form>
<div class="w3-panel">
<div class="w3-row-padding" style="margin:0 -16px">
</div>
</div>';
}
function omegatxtfprijatemrpks(){
echo '<header class="w3-container" style="padding-top:22px">
<h5><b><i class="fa fa-dashboard"></i> Prevod prijatých faktúr z KROS OMEGA vo formáte TXT(CSV) do MRP K/S</b></h5>
</header>
<form method="post" target="index.php" enctype="multipart/form-data">
<div class="w3-row-padding w3-margin-bottom">
<div class="w3-threequarter">
<h4>Pre vytvorenie XML súborov pre import prijatých faktúr do MRP K/S, priložte nasledovné súbory</h4>
<p>Súbor TXT s prijatými faktúrami: <input type="file" name="f_txt" id="f_txt"></input><i id="sf_txt" aria-hidden="true" class="fa fa-square-o"></i></p>
<hr>
Kliknutím na nasledovné tlačidlo zahájite tvorbu XML súboru pre import do MRP: <input type="submit" class="button" name="generujks_omegafp" value="Vygenerovať">
</div>
</div>
</form>
<div class="w3-panel">
<div class="w3-row-padding" style="margin:0 -16px">
</div>
</div>';
}
function faonlinexlsxfvydanemrpks(){
echo '<header class="w3-container" style="padding-top:22px">
<h5><b><i class="fa fa-dashboard"></i> Prevod vydaných faktúr z Faktury-Online.com vo formáte XLSX do MRP K/S</b></h5>
</header>
<form method="post" target="index.php" enctype="multipart/form-data">
<div class="w3-row-padding w3-margin-bottom">
<div class="w3-threequarter">
<h4>Pre vytvorenie XML súborov pre import vydaných faktúr do MRP K/S, priložte nasledovné súbory</h4>
<p>Súbor XLSX s vystavenými faktúrami: <input type="file" name="f_xlsx" id="f_xlsx"></input><i id="sf_xlsx" aria-hidden="true" class="fa fa-square-o"></i></p>
<hr>
Kliknutím na nasledovné tlačidlo zahájite tvorbu XML súboru pre import do MRP K/S: <input type="submit" class="button" name="generujks_faonlinefv" value="Vygenerovať">
</div>
</div>
</form>
<div class="w3-panel">
<div class="w3-row-padding" style="margin:0 -16px">
</div>
</div>';
}
function generujks($typ){
if(!isset($typ)){
die('Nieje zvolený typ importu, kontaktuj správcu systému.');
}
//1. nacitat subory do tmp lokacie
switch($typ){
case 'sklad2007':
case 'ecosun':
if (!isset($_FILES['f_xml_fakodb'])) {
die('Nenahrali ste všetky požadované súbory');
}
if (isset($_FILES['f_xml_fakodb'])) {
$fu_res = sec_file_upload('f_xml_fakodb', "XML");
if ($fu_res) {
die('Problem pri nahravani XML suboru s vystavenými faktúrami, detail:' . $fu_res . '.');
}
}
break;
case 'omegafv':
if (!isset($_FILES['f_txt'])) {
die('Nenahrali ste všetky požadované súbory');
}
if (isset($_FILES['f_txt'])) {
$fu_res = sec_file_upload('f_txt', "TXT");
if ($fu_res) {
die('Problem pri nahravani TXT suboru s vystavenými faktúrami, detail:' . $fu_res . '.');
}
}
break;
case 'omegafp':
if (!isset($_FILES['f_txt'])) {
die('Nenahrali ste všetky požadované súbory');
}
if (isset($_FILES['f_txt'])) {
$fu_res = sec_file_upload('f_txt', "TXT");
if ($fu_res) {
die('Problem pri nahravani TXT suboru s prijatými faktúrami, detail:' . $fu_res . '.');
}
}
break;
case 'faonlinefv':
if (!isset($_FILES['f_xlsx'])) {
die('Nenahrali ste všetky požadované súbory');
}
if (isset($_FILES['f_xlsx'])) {
$fu_res = sec_file_upload('f_xlsx', "XLSX");
if ($fu_res) {
die('Problem pri nahravani XLSX suboru s vystavenými faktúrami, detail:' . $fu_res . '.');
}
}
break;
default:
die('Neznámy typ súboru, kontaktujte správcu systému.');
}
//2. spracovat obsah a vytvorit txt
switch($typ){
case 'sklad2007':
require_once('sklad2mrpks.php');
$res = sklad2mrpks_generate();
break;
case 'ecosun':
require_once('ecosun2mrpks.php');
$res = ecosun2mrpks_generate();
break;
case 'omegafv':
require_once('omegavfa2mrpks.php');
$res = omegavfa2mrpks_generate();
break;
case 'omegafp':
require_once('omegapfa2mrpks.php');
$res = omegapfa2mrpks_generate();
break;
case 'faonlinefv':
require_once('faonlinevfa2mrpks.php');
$res = faonlinevfa2mrpks_generate();
break;
}
//3.vycisti po sebe
switch($typ){
case 'sklad2007':
case 'ecosun':
$ffiles = array($_FILES['f_xml_fakodb']['name']);
clean_tmp($ffiles);
break;
case 'omegafv':
case 'omegafp':
$ffiles = array($_FILES['f_txt']['name']);
clean_tmp($ffiles);
break;
case 'faonlinefv':
$ffiles = array($_FILES['f_xlsx']['name']);
clean_tmp($ffiles);
break;
}
//4. vrati txt do browseru na ulozenie
if ($res[0] == 0) {
echo "<h3>Konverzia prebehla úspešne.</h3>";
} else {
echo "<h3>Pozor, nie všetky faktúry bolo možné importovať! Skontroluj obsah súboru FNespracovane.txt!</h3>";
}
echo "<p>Súbor s dátami pre import stiahnete <a href=\"" . $res[1] ."\" target=\"_blank\">tu</a></p>";
if( isset($res[2]) && count($res[2])>0){
echo "<p>V nasledovných faktúrach sa nachádza položka typu kľúčová služba:<br />";
foreach ($res[2] as $faktura) {
echo "<strong> {$faktura}</strong><br />";
}
echo "</p>";
}
echo "<p>Po stiahnutí súboru s archívom, odstránte všetky nahraté dáta týkajúce sa tohto prevodu zo servera, kliknutím <a href=\"index.php?action=delete\">sem</a></p>";
}
//spracovanie formulara
if (isset($_GET['action']) && $_GET["action"] == "delete") {
$ses = session_id();
if (strlen($ses) > 0) {
rrmdir("downloads/" . $ses . "/",1);
echo "Hotovo, citlivé dáta boli odstrátené.";
}
} else if (isset($_POST['generujks_sklad2007'])) {
//generuj sklad 2007 do mrp ks
generujks('sklad2007');
} else if (isset($_POST['generujks_ecosun'])) {
//generuj ecosun do rp ks
generujks('ecosun');
} else if (isset($_POST['generujks_omegafv'])) {
//generuj omega FV do mrp ks
generujks('omegafv');
} else if (isset($_POST['generujks_omegafp'])) {
//generuj omega FV do mrp ks
generujks('omegafp');
} else if (isset($_POST['generujks_faonlinefv'])) {
//generuj faktura online FV do mrp ks
generujks('faonlinefv');
}
else {
?>
<!DOCTYPE html>
<html>
<title>Generátor súborov pre import do MRP</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
html,body,h1,h2,h3,h4,h5 {font-family: "Raleway", sans-serif}
</style>
<body class="w3-light-grey">
<!-- Top container -->
<div class="w3-bar w3-top w3-black w3-large" style="z-index:4">
<button class="w3-bar-item w3-button w3-hide-large w3-hover-none w3-hover-text-light-grey" onclick="w3_open();"><i class="fa fa-bars"></i> Menu</button>
<span class="w3-bar-item w3-right">Logo</span>
</div>
<!-- Sidebar/menu -->
<nav class="w3-sidebar w3-collapse w3-white w3-animate-left" style="z-index:3;width:300px;" id="mySidebar"><br>
<div class="w3-container w3-row">
<div class="w3-col s4">
</div>
<div class="w3-col s8 w3-bar">
<span>Vitajte!</span><br>
</div>
</div>
<hr>
<div class="w3-container">
<h5>Prevody do MRP K/S</h5>
</div>
<div class="w3-bar-block">
<a href="#" class="w3-bar-item w3-button w3-padding-16 w3-hide-large w3-dark-grey w3-hover-black" onclick="w3_close()" title="close menu"><i class="fa fa-remove fa-fw"></i> Close Menu</a>
<a href="index.php?tool=mrpkssklad" class="w3-bar-item w3-button w3-padding"><i class="fa fa-users fa-fw"></i>APK SW - SPED (*.XML)</a>
<a href="index.php?tool=ecosunmrpks" class="w3-bar-item w3-button w3-padding"><i class="fa fa-users fa-fw"></i>Sunsoft ECOSUN (*.XML)</a>
<a href="index.php?tool=omegatxtfprijatemrpks" class="w3-bar-item w3-button w3-padding"><i class="fa fa-users fa-fw"></i>KROS OMEGA FA prijate (*.TXT)</a>
<a href="index.php?tool=omegatxtfvydanemrpks" class="w3-bar-item w3-button w3-padding"><i class="fa fa-users fa-fw"></i>KROS OMEGA FA vydane (*.TXT)</a>
<a href="index.php?tool=faonlinexlsxfvydanemrpks" class="w3-bar-item w3-button w3-padding"><i class="fa fa-users fa-fw"></i>Faktury-online.com (*.XLSX)</a>
<br><br>
</div>
</nav>
<!-- Overlay effect when opening sidebar on small screens -->
<div class="w3-overlay w3-hide-large w3-animate-opacity" onclick="w3_close()" style="cursor:pointer" title="close side menu" id="myOverlay"></div>
<!-- !PAGE CONTENT! -->
<div class="w3-main" style="margin-left:300px;margin-top:43px;">
<?php
if (isset($_GET['tool'])){
$tool = htmlspecialchars(addslashes($_GET['tool']));
switch($tool){
case 'mrpkssklad':
mrpkssklad();
break;
case 'ecosunmrpks':
ecosunmrpks();
break;
case 'omegatxtfvydanemrpks':
omegatxtfvydanemrpks();
break;
case 'omegatxtfprijatemrpks':
omegatxtfprijatemrpks();
break;
case 'faonlinexlsxfvydanemrpks':
faonlinexlsxfvydanemrpks();
break;
}
}
?>
<hr>
<!-- Footer -->
<footer class="w3-container w3-padding-16 w3-light-grey">
<p>Created by <a href="https://www.itriesenia.eu/" target="_blank">PVi1<a></p>
<p>Template by <a href="https://www.w3schools.com/w3css/default.asp" target="_blank">w3.css</a></p>
</footer>
<!-- End page content -->
</div>
<script>
// Get the Sidebar
var mySidebar = document.getElementById("mySidebar");
// Get the DIV with overlay effect
var overlayBg = document.getElementById("myOverlay");
// Toggle between showing and hiding the sidebar, and add overlay effect
function w3_open() {
if (mySidebar.style.display === 'block') {
mySidebar.style.display = 'none';
overlayBg.style.display = "none";
} else {
mySidebar.style.display = 'block';
overlayBg.style.display = "block";
}
}
// Close the sidebar with the close button
function w3_close() {
mySidebar.style.display = "none";
overlayBg.style.display = "none";
}
$(document).ready(function () {
var go = 0;
$(function () {
$("input:file").change(function () {
var fileName = $(this).val().split(/[\\ ]+/).pop();
var inputName = $(this).attr('name');
var patMatch = "";
switch (inputName) {
case 'f_xml_fakodb':
fileName = fileName.split('.').pop();
patMatch = "xml";
break;
case 'f_txt':
fileName = fileName.split('.').pop();
patMatch = "txt";
break;
case 'f_xlsx':
fileName = fileName.split('.').pop();
patMatch = "xlsx";
break;
}
if (fileName === patMatch) {
go = 1;
$('#s' + inputName).removeClass("fa fa-square-o");
$('#s' + inputName).addClass("fa fa-check-square-o");
} else {
go = 0;
$('#s' + inputName).removeClass("fa fa-check-square-o");
$('#s' + inputName).addClass("fa fa-square-o");
}
});
});
$("form").submit(function (event) {
if (go == 1) {
//posli form
return;
} else {
alert('Neplatne data na vstupe');
event.preventDefault();
}
});
});
</script>
</body>
</html>
<?php
}
?>