-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch-order.inc.php
101 lines (86 loc) · 3.82 KB
/
fetch-order.inc.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
<?php
include_once './functions.php';
include_once './src/inc/session.php';
if (isset($_POST['action']) && $_POST['action'] == "fetchData") {
$select = "SELECT * FROM otiosum.order";
$where = " WHERE date_created <= current_timestamp()";
$limit = "";
$orderBy = "";
$pdo = pdo_connect_mysql();
if (isset($_POST['search']) && !empty($_POST['search'])) {
$search = $_POST['search'];
$where .= " AND id LIKE '%$search%'";
}
if (isset($_POST['orderStatus']) && !empty($_POST['orderStatus'])) {
$status = $_POST['orderStatus'];
$where .= " AND order_status_id = $status";
}
if (isset($_POST['dateOrder']) && !empty($_POST['dateOrder'])) {
$dateOrder = $_POST['dateOrder'];
if($dateOrder == "up") {
$orderBy .= " ORDER BY date_created ASC";
} else {
$orderBy .= " ORDER BY date_created DESC";
}
}
if((isAdmin() || isMod()) && isset($_POST['o']) && $_POST['o'] == "list"){
$isPrivlage = true;
} else {
$aid = $_SESSION['id'];
$where .= " AND account_id = $aid";
$isPrivlage = false;
}
// limit per page
if (isset($_POST['limit']) && !empty($_POST['limit'])) {
$lim = $_POST['limit'];
if (isset($_POST['page']) >= 1) {
$start = (($_POST['page'])-1) * $lim;
$page = ($_POST['page']);
} else {
$start = 0;
}
$limit = " LIMIT $start, $lim";
}
$orders = $pdo->query($select.$where.$orderBy.$limit)->fetchAll(PDO::FETCH_ASSOC);
$output = orderList($orders, $isPrivlage, $pdo);
$totalOrders = $pdo->query($select.$where)->rowCount();
$totalPages = ceil($totalOrders/(int)$lim);
$pagination = ajaxPagination($page, $totalPages);
echo json_encode(['output'=>$output, 'pagination'=>$pagination]);
exit();
}
if (isset($_POST['action']) && $_POST['action'] == "updateOrder") {
if(isset($_POST['orderStatus'], $_POST['oid']) && !empty($_POST['orderStatus']) && !empty($_POST['oid'])) {
$pdo = pdo_connect_mysql();
$osID = $_POST['orderStatus'];
$oid = $_POST['oid'];
$stmt = $pdo->prepare("UPDATE otiosum.order SET order_status_id = :osID WHERE id = :oid");
$stmt->execute(['osID'=>$osID, 'oid'=>$oid]);
$stmtErr = $stmt->errorInfo();
if ($stmtErr[0] != 0) {
echo "err";
exit;
}
$orderMessage = [
'Naročeno'=>"Prejeli smo vaše naročilo! Hvala za nakup!",
'Odposlano'=>"Obdelali smo vaše naročilo in ga odposlali!",
'Dostavljeno'=>"Naročilo smo dostavili k vam!",
'Ne moremo dostaviti'=>"Naročila ne moremo dostaviti!",
'Preklicano'=>"Naročilo je bilo preklicano!"
];
$status = $pdo->query("SELECT * FROM order_status WHERE id = $osID")->fetch(PDO::FETCH_ASSOC);
$orderStatus = $status['status'];
foreach($orderMessage as $key => $value) {
if ($key == $orderStatus) {
$message = $value;
}
}
$order = $pdo->query("SELECT * FROM otiosum.order WHERE id = $oid")->fetch(PDO::FETCH_ASSOC);
$to_email = $pdo->query("SELECT email FROM account a INNER JOIN otiosum.order o ON a.id = o.account_id WHERE o.id=$oid")->fetch(PDO::FETCH_COLUMN);
include_once "./src/inc/order-email.inc.php";
send_order_email($to_email, $message, $orderStatus, $order, $oid);
echo "success";
exit();
}
}
?>