-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin_control_panel.php
301 lines (271 loc) · 10.1 KB
/
admin_control_panel.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
<!DOCTYPE html>
<html>
<?php
ob_start();
session_start();
$_SESSION['items'] = 0;
error_reporting(E_ERROR | E_PARSE);
$serverName = "DESKTOP-4OJ4H1R\SQLEXPRESS"; //serverName\instanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"TSQL");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
?>
<head>
<link rel = "stylesheet" href = "style.css">
</head>
<body>
<a href = "login.php" tite = "main page" style="text-decoration:none" ><h1>Herb shop</h1></a>
<form method="post" style="float:right">
Click here to clean session - <a href = "logout.php" tite = "Logout">Logout</a>
</form><br><br>
Admin options enabled<br>
<form method="POST" style="float:left">Sort:
<input type="submit" VALUE="ID ASC" name="sort_asc"/>
</form>
<form method="POST" style="float:left">
<input type="submit" VALUE="ID DESC" name="sort_desc"/>
</form>
<form method="POST" style="float:left">
<input type="submit" VALUE="Date ASC" name="date_asc"/>
</form>
<form method="POST" style="float:left">
<input type="submit" VALUE="Date DESC" name="date_desc"/>
</form>
<form method="POST" style="float:left">
<input type="submit" VALUE="Orders" name="actual_orders"/>
</form>
<form method="POST" style="float:right">Search:
<input type="text" VALUE="" name="searched_word"/>
<input type="submit" VALUE="Login" name="search_login"/>
<input type="submit" VALUE="Name" name="search_name"/>
<input type="submit" VALUE="Surname" name="search_surname"/>
</form> <br><br><br><br>
<form method="POST" style="float:left">User Login:
<input type="text" VALUE="" name="user_dlt_clr"/>
<input type="submit" VALUE="Delete acc" name="delete_acc"/>
<input type="submit" VALUE="Clear order" name="clr_order"/>
</form><br><br><br>
<?php
//if ($_SESSION['permission'] == 'admin'){
echo "<h3><table border='1' style='background-color:white;'>
<tr>
<th>UserID</th>
<th>Permission</th>
<th>Name</th>
<th>Surname</th>
<th>Login</th>
<th>Password</th>
<th>Mail</th>
<th>Address</th>
<th>City</th>
<th>Order date</th>
<th>Order cost [$]</th>
<th>PR1 cart</th>
<th>PR2 cart</th>
<th>PR3 cart</th>
<th>PR1</th>
<th>PR2</th>
<th>PR3</th>
</tr>";
$sql = "SELECT * FROM Shop";
if(isset($_POST['sort_asc'])){
$sql = "SELECT * FROM Shop ORDER BY PersonID ASC;";}
if(isset($_POST['sort_desc'])){
$sql = "SELECT * FROM Shop ORDER BY PersonID DESC;";}
if(isset($_POST['date_asc'])){
$sql = "SELECT * FROM Shop WHERE order_date IS NOT NULL ORDER BY order_date ASC;";}
if(isset($_POST['date_desc'])){
$sql = "SELECT * FROM Shop WHERE order_date IS NOT NULL ORDER BY order_date DESC;";}
if(isset($_POST['actual_orders'])){
$sql = "SELECT * FROM Shop WHERE ordered_cart_cost != 0;";}
if(isset($_POST['search_login'])){
$sql = "SELECT * FROM Shop WHERE Login = '{$_POST['searched_word']}';";}
if(isset($_POST['search_name'])){
$sql = "SELECT * FROM Shop WHERE FirstName = '{$_POST['searched_word']}';";}
if(isset($_POST['search_surname'])){
$sql = "SELECT * FROM Shop WHERE LastName = '{$_POST['searched_word']}';";}
if(isset($_POST['delete_acc'])){
$sql = "DELETE FROM Shop WHERE Login = '{$_POST['user_dlt_clr']}';";}
if(isset($_POST['clr_order'])){
$sql = "UPDATE Shop
SET order_date = NULL, ordered_cart_cost = NULL, product1 = 0,product2 = 0 ,product3 = 0,PR1 = 0,PR2 = 0 ,PR3 = 0 WHERE Login = '{$_POST['user_dlt_clr']}';";}
$stmt = sqlsrv_query($conn, $sql);
while($users = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_NUMERIC)){
echo "<tr>";
echo "<td>" . $users[0] . "</td>";
echo "<td>" . $users[1] . "</td>";
echo "<td>" . $users[2] . "</td>";
echo "<td>" . $users[3] . "</td>";
echo "<td>" . $users[4] . "</td>";
echo "<td>" . $users[5] . "</td>";
echo "<td>" . $users[6] . "</td>";
echo "<td>" . $users[7] . "</td>";
echo "<td>" . $users[8] . "</td>";
echo "<td>" . $users[9] . "</td>";
echo "<td>" . $users[10] . "</td>";
echo "<td>" . $users[11] . "</td>";
echo "<td>" . $users[12] . "</td>";
echo "<td>" . $users[13] . "</td>";
echo "<td>" . $users[14] . "</td>"; $userssum1 = $userssum1 + $users[13];
echo "<td>" . $users[15] . "</td>"; $userssum2 = $userssum2 + $users[14];
echo "<td>" . $users[16] . "</td>"; $userssum3 = $userssum3 + $users[15];
echo "</tr>";
}
echo "</table></h3>";
sqlsrv_free_stmt( $stmt);
?>
<?php
$sql = "SELECT SUM(ordered_cart_cost)
FROM Shop
WHERE MONTH(order_date) = 1;";
$stmt = sqlsrv_query($conn, $sql);
while(sqlsrv_fetch($stmt) === true) {$order_cost_month_1 = sqlsrv_get_field($stmt, 0);}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(ordered_cart_cost)
FROM Shop
WHERE MONTH(order_date) = 2;";
$stmt = sqlsrv_query($conn, $sql);
while(sqlsrv_fetch($stmt) === true) {$order_cost_month_2 = sqlsrv_get_field($stmt, 0);}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(ordered_cart_cost)
FROM Shop
WHERE MONTH(order_date) = 3;";
$stmt = sqlsrv_query($conn, $sql);
while(sqlsrv_fetch($stmt) === true) {$order_cost_month_3 = sqlsrv_get_field($stmt, 0);}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(ordered_cart_cost)
FROM Shop
WHERE MONTH(order_date) = 4;";
$stmt = sqlsrv_query($conn, $sql);
while(sqlsrv_fetch($stmt) === true) {$order_cost_month_4 = sqlsrv_get_field($stmt, 0);}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(ordered_cart_cost)
FROM Shop
WHERE MONTH(order_date) = 5;";
$stmt = sqlsrv_query($conn, $sql);
while(sqlsrv_fetch($stmt) === true) {$order_cost_month_5 = sqlsrv_get_field($stmt, 0);}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(ordered_cart_cost)
FROM Shop
WHERE MONTH(order_date) = 6;";
$stmt = sqlsrv_query($conn, $sql);
while(sqlsrv_fetch($stmt) === true) {$order_cost_month_6 = sqlsrv_get_field($stmt, 0);}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(ordered_cart_cost)
FROM Shop
WHERE MONTH(order_date) = 7;";
$stmt = sqlsrv_query($conn, $sql);
while(sqlsrv_fetch($stmt) === true) {$order_cost_month_7 = sqlsrv_get_field($stmt, 0);}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(ordered_cart_cost)
FROM Shop
WHERE MONTH(order_date) = 8;";
$stmt = sqlsrv_query($conn, $sql);
while(sqlsrv_fetch($stmt) === true) {$order_cost_month_8 = sqlsrv_get_field($stmt, 0);}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(ordered_cart_cost)
FROM Shop
WHERE MONTH(order_date) = 9;";
$stmt = sqlsrv_query($conn, $sql);
while(sqlsrv_fetch($stmt) === true) {$order_cost_month_9 = sqlsrv_get_field($stmt, 0);}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(ordered_cart_cost)
FROM Shop
WHERE MONTH(order_date) = 10;";
$stmt = sqlsrv_query($conn, $sql);
while(sqlsrv_fetch($stmt) === true) {$order_cost_month_10 = sqlsrv_get_field($stmt, 0);}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(ordered_cart_cost)
FROM Shop
WHERE MONTH(order_date) = 11;";
$stmt = sqlsrv_query($conn, $sql);
while(sqlsrv_fetch($stmt) === true) {$order_cost_month_11 = sqlsrv_get_field($stmt, 0);}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(ordered_cart_cost)
FROM Shop
WHERE MONTH(order_date) = 12;";
$stmt = sqlsrv_query($conn, $sql);
while(sqlsrv_fetch($stmt) === true) {$order_cost_month_12 = sqlsrv_get_field($stmt, 0);}
sqlsrv_free_stmt($stmt);
//$dataPoints = array(
// array("label"=> "Product 1", "y"=> $userssum1),
// array("label"=> "Product 2", "y"=> $userssum2),
// array("label"=> "Product 3", "y"=> $userssum3)
//);
$dataPoints = array(
array("label"=> "January", "y"=> $order_cost_month_1),
array("label"=> "February", "y"=> $order_cost_month_2),
array("label"=> "March", "y"=> $order_cost_month_3),
array("label"=> "April", "y"=> $order_cost_month_4),
array("label"=> "May", "y"=> $order_cost_month_5),
array("label"=> "June", "y"=> $order_cost_month_6),
array("label"=> "July", "y"=> $order_cost_month_7),
array("label"=> "August", "y"=> $order_cost_month_8),
array("label"=> "September", "y"=> $order_cost_month_9),
array("label"=> "October", "y"=> $order_cost_month_10),
array("label"=> "November", "y"=> $order_cost_month_11),
array("label"=> "December", "y"=> $order_cost_month_12)
);
?>
<script>
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
theme: "light2",
title: {
text: "Products ordered"
},
axisY: {
prefix: "$",
scaleBreaks: {
autoCalculate: true
}
},
data: [{
type: "column",
yValueFormatString: "$#######.00",
indexLabel: "{y}",
indexLabelPlacement: "inside",
indexLabelFontColor: "white",
dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
}]
});
chart.render();
}
</script>
<div id="chartContainer" style="height: 370px; width: 50%; margin: 0 auto"></div>
<script src="https://cdn.canvasjs.com/canvasjs.min.js"></script>
<?php
$sql = "SELECT TOP 1 ordered_cart_cost
FROM Shop
ORDER BY ordered_cart_cost DESC;";
$stmt = sqlsrv_query($conn, $sql);
while($biggest_order = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_NUMERIC)){echo "<h3>Biggest order cost: ",$biggest_order[0];}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(PR1)
FROM Shop;";
$stmt = sqlsrv_query($conn, $sql);
while($biggest_p1_order = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_NUMERIC)){echo "<br>Total product1 orders: ",$biggest_p1_order[0];}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(PR2)
FROM Shop;";
$stmt = sqlsrv_query($conn, $sql);
while($biggest_p2_order = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_NUMERIC)){echo "<br>Total product2 orders: ",$biggest_p2_order[0];}
sqlsrv_free_stmt($stmt);
$sql = "SELECT SUM(PR3)
FROM Shop;";
$stmt = sqlsrv_query($conn, $sql);
while($biggest_p3_order = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_NUMERIC)){echo "<br>Total product3 orders: ",$biggest_p3_order[0];}
sqlsrv_free_stmt($stmt);
$sql = "SELECT ordered_cart_cost
FROM Shop
ORDER BY ordered_cart_cost DESC;";
$stmt = sqlsrv_query($conn, $sql);
$total_order_cost = 0;
while($total_order_cost_fetch = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_NUMERIC)){$total_order_cost=$total_order_cost+$total_order_cost_fetch[0];}
echo "<br>Total order cost: ",$total_order_cost,"</h3>";
sqlsrv_free_stmt($stmt);
?>
</body>
</html>