-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadminPanel.php
More file actions
156 lines (147 loc) · 5.89 KB
/
adminPanel.php
File metadata and controls
156 lines (147 loc) · 5.89 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
<?php
/**
* Created by PhpStorm.
* User: ivanj
* Date: 20-Jul-17
* Time: 12:41
*/
require ("functions.php");
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(isset($_SESSION['userId'])&&!empty($_SESSION['userId']))
{
$usrId = $_SESSION['userId'];
if(!checkIfAdmin($usrId))
{
echo "<script>alert('You must be admin in order to view the page!'); window.location.href=('home.php');</script>";
}
}
else
{
echo "<script>alert('You must log in first!'); window.location.href=('home.php');</script>";
}
if(isset($_FILES)&&!empty($_FILES))
{
$name = $_POST['name'];
$desc = $_POST['description'];
$price = $_POST['price'];
$sourcePath = $_FILES['picture']['tmp_name'];
$targetDir="images/products/".$name.".jpeg";
if(file_exists($targetDir))
{
unlink($targetDir);
}
if(move_uploaded_file($sourcePath,$targetDir))
{
$msg = addProduct($name,$desc,$price,$targetDir);
echo $msg;
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Admin Panel</title>
<!--Bootstrap js and css along with jquery-->
<script src="js/jquery-3.1.1.js"></script>
<script src="js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<!--Custom Js-->
<script src="js/adminPanel.js"></script>
</head>
<body style="margin-bottom: 10px;margin-top: 10px;">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<img src="images/datapanel-logo.png" class="img-responsive" style="margin: auto">
</div>
</div>
<br>
<div class="row">
<div class="col-md-6 col-md-offset-3 text-center uploadDiv">
<h2>Adding a product</h2>
<hr>
<form action="adminPanel.php" method="post" enctype="multipart/form-data" class="form-group">
<label for="name">Product name: </label>
<input type="text" id="name" name="name" class="form-control" required>
<label for="description">Product description: </label>
<textarea class="form-control" name="description" id="description" rows="3" required></textarea>
<label for="price">Product price: </label>
<input type="number" id="price" name="price" class="form-control" required>
<label for="picture">Product picture: </label>
<input type="file" id="picture" name="picture" style="margin: auto" required>
<br>
<input type="submit" value="Create" name="btnAddProduct" id="btnAddProduct" class="btn btn-primary">
</form>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-md-6 col-md-offset-3 text-center uploadDiv">
<h2>Delete a product</h2>
<hr>
<label for="selectProductForDelete">Select product: </label>
<select class="form-control" id="selectProductForDelete">
<!--products are added dinamically-->
</select>
<br>
<input type="submit" value="Delete" id="btnDeleteProduct" class="btn btn-primary">
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-md-6 col-md-offset-3 text-center uploadDiv">
<h2>Update a product</h2>
<hr>
<label for="selectProductForUpdate">Select product: </label>
<select class="form-control" id="selectProductForUpdate">
<!--products are added dinamically-->
</select>
<label for="selectAttForUpdate">Select attribute: </label>
<select class="form-control" id="selectAttForUpdate">
<option value="name">Name</option>
<option value="description">Description</option>
<option value="price">Price</option>
</select>
<label for="valueToUpdate">Value:</label>
<input type="text" class="form-control" id="valueToUpdate" name="valueToUpdate" required>
<br>
<input type="submit" value="Update" id="btnUpdateProduct" class="btn btn-primary">
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3 text-center uploadDiv">
<h2>Reports</h2>
<hr>
<h3>Reports By Date</h3>
<label for="reportFromDate">From Date:</label>
<input type="date" class="form-control" id="reportFromDate" name="reportFromDate" value="<?php echo date('Y-m-d');?>">
<label for="reportToDate">To Date:</label>
<input type="date" class="form-control" id="reportToDate" name="reportToDate" value="<?php echo date('Y-m-d');?>">
<br>
<input type="submit" value="Show Reports" id="btnShowReportsByDate" class="btn btn-primary">
<br>
<br>
<h3>Reports By User</h3>
<hr>
<label for="selectReportByUser">Select User:</label>
<select class="form-control" id="selectReportByUser">
</select>
<br>
<input type="submit" value="Show Reports" id="btnShowReportsByUser" class="btn btn-primary">
<br>
<table class="table" id="reportTable">
<!--elements are added dinamically-->
</table>
</div>
</div>
</div>
</body>
</html>