This repository has been archived by the owner on Jun 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.php
executable file
·74 lines (56 loc) · 1.88 KB
/
app.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
<?php
ini_set('display_errors', true);
set_time_limit(600);
session_start();
require 'config.php';
require 'vendor/autoload.php';
function dd($content) {
var_dump($content);
die();
}
function logThis($message) {
file_put_contents('sync.log', date('Y-m-d H:i:s') . ' - ' . $message . PHP_EOL, FILE_APPEND);
echo $message . PHP_EOL;
}
use Picqer\Api\Client as PicqerClient;
// Picqer connection
$picqerclient = new PicqerClient($config['picqer-company'], $config['picqer-apikey']);
if (!isset($_GET['step'])) {
header('Location: app.php?step=upload');
exit;
}
switch ($_GET['step']) {
case 'upload':
include('view-form.php');
break;
case 'preview':
if (is_uploaded_file($_FILES['file']['tmp_name']) && isset($_POST['customerid']) && !empty($_POST['customerid'])) {
$excelextrator = new PicqerImporter\SingleExcelExtractor($config);
$products = $excelextrator->processExcel(
$_FILES['file']['tmp_name']
);
$_SESSION['products'] = $products;
$_SESSION['customerid'] = $_POST['customerid'];
$_SESSION['reference'] = $_POST['reference'];
include('view-preview.php');
} else {
include('view-no-data.php');
exit;
}
break;
case 'import':
if (!isset($_SESSION['products']) || empty($_SESSION['products'])) {
include('view-no-data.php');
exit;
}
$importer = new PicqerImporter\SingleOrderImporter($picqerclient, $config);
$orderid = $importer->importOrder($_SESSION['customerid'], $_SESSION['products'], $_SESSION['reference']);
unset($_SESSION['products']);
include('view-done.php');
break;
case 'cancel':
unset($_SESSION['products']);
header('Location: app.php?step=upload');
exit;
break;
}