This repository has been archived by the owner on May 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorders.php
134 lines (116 loc) · 4.79 KB
/
orders.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
<?php
require_once 'back/header.php';
require_once 'back/page-settings.php';
require_once 'back/shop-list.php';
require_once 'back/footer.php';
require_once 'back/db.php';
require_once 'back/utils.php';
require_once 'back/users.php';
$page_title = "СарИсскуство";
if(!$_SESSION["isAdmin"]){
header("Location: /coursephp/login.php?admin");
die();
}
$page = 0;
if($_GET['page'] && intval($_GET['page'])){
$page = intval($_GET['page']) - 1;
}
$perPage = 15;
$offset = $page * $perPage;
$q = "SELECT COUNT(id) AS count FROM `orders`";
$count = mysql_fetch_assoc(mysql_query($q))['count'];
$q = "SELECT `id`, (SELECT `name` FROM `user` WHERE user.id = orders.user_id) as `user`, `date`, `address`, `price`, `status` FROM `orders` LIMIT $perPage OFFSET $offset";
$orders = mysql_query($q);
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<? renderHeader(); ?>
<script>
$(function() {
$(".spoiler-trigger").click(function() {
$(this).next().collapse('toggle');
});
});
function statusChanged(id){
let s = document.getElementById("orders-status-" + id);
$.get( "back/admin.php?edit_item="+encodeURIComponent(id)+"&status="+encodeURIComponent(s.value),
function( data ) {
console.log( "Load was performed. " + data);
}
);
}
</script>
</head>
<body>
<? renderTop(); ?>
<div class="container content">
<h1>Заказы</h1>
<div class="table orders-table">
<div class="row">
<div class="col">#</div>
<div class="col">Пользователь</div>
<div class="col">Дата</div>
<div class="col">Адрес</div>
<div class="col">Сумма</div>
<div class="col">Статус</div>
</div>
<?
while($o = mysql_fetch_assoc($orders)){
$its = mysql_query("SELECT items.id, name, price FROM orders_items INNER JOIN items ON items.id = item_id WHERE order_id = '".$o['id']."'");
?>
<div class="row spoiler-trigger" >
<div class="col"><?=$o["id"]?></div>
<div class="col"><?=$o["user"]?></div>
<div class="col"><?=$o["date"]?></div>
<div class="col"><?=$o["address"]?></div>
<div class="col"><?=$o["price"]?> РУБ</div>
<div class="col">
<select title="" id="orders-status-<?=$o['id']?>" onchange="statusChanged(<?=$o['id']?>)">
<option value="0" <?=$o['status'] == 0 ? "selected" : ""?>>В ожидании</option>
<option value="1" <?=$o['status'] == 1 ? "selected" : ""?>>Проверка</option>
<option value="2" <?=$o['status'] == 2 ? "selected" : ""?>>Отправка</option>
<option value="3" <?=$o['status'] == 3 ? "selected" : ""?>>Завершена</option>
</select>
</div>
</div>
<div class="inner-items-table panel-collapse collapse out">
<?
if(mysql_num_rows($its)) {
?>
<div class="row inner-items">
<div class="col">#</div>
<div class="col">Товар</div>
<div class="col">Сумма</div>
<div class="col"><br></div>
</div>
<?
}
while ($i = mysql_fetch_assoc($its)) {
?>
<a href="item.php?id=<?=$i['id']?>" target="_blank" class="row inner-items">
<div class="col"><?=$i['id']?></div>
<div class="col"><?=$i['name']?></div>
<div class="col"><?=$i['price']?> РУБ</div>
<div class="col flex-grow-1"><br></div>
</a>
<? } ?>
</div>
<? } ?>
</div>
<div class="row">
<div class="col-5"></div>
<div class="col-2 d-flex justify-content-center">
<?
$cpage = $page + 1;
?>
<? if($cpage > 1) { ?><a href="?page=<?=$cpage - 1?>"><?=$cpage - 1?></a> <? } ?>
<?=$cpage?>
<? if($offset + $perPage < $count) { ?><a href="?page=<?=$cpage + 1?>"><?=$cpage + 1?></a> <? } ?>
</div>
<div class="col-5"></div>
</div>
</div>
<? renderBottom(); ?>
</body>
</html>