-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
192 lines (144 loc) · 4.96 KB
/
admin.php
File metadata and controls
192 lines (144 loc) · 4.96 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
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
<?php
$servername = "localhost";
$username = "root";
$password = "147258369";
$dbname = "shop";
include 'products_sql.php';
include 'users_sql.php';
include 'basket_sql.php';
include 'category_sql.php';
session_start();
if (!isset($_SESSION[login]))
$_SESSION[id] = 1;
// echo "<a href='/'>Exit</a>";
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="admin.css">
</head>
<body>
<?php
if (isset($_POST['btnLogin'])) {
$login = $_POST['usrnm'];
$pass = $_POST['psw'];
if ($login == "admin" && $pass == "admin") {
$ifLogin = true;
$_SESSION[login] = "admin";
}
}?>
<?php if (!$ifLogin && $_SESSION[login] != "admin"): ?>
<form method="post" style="max-width:500px;margin:auto">
<h2 style="text-align: center; margin: 10px">Admin Panel</h2>
<div class="input-container">
<div class="imgCont">
<img src="./img/icon_user.png">
</div>
<input class="input-field" type="text" placeholder="Username" name="usrnm">
</div>
<div class="input-container">
<div class="imgCont">
<img src="./img/icon_key.png">
</div>
<input class="input-field" type="password" placeholder="Password" name="psw">
</div>
<button type="submit" name="btnLogin" class="btn">Login</button>
</form>
<?php endif?>
<?php if ($ifLogin || $_SESSION[login] == "admin"): ?>
<div id="Products" class="tabcontent">
<h3>Products</h3>
</div>
<div id="Categories" class="tabcontent">
<h3>Categories</h3>
</div>
<div id="Users" class="tabcontent">
<h3>Users</h3>
</div>
<button class="tablink" onclick="category('Products', this, 'prdc')" id="defaultOpen">Products</button>
<button class="tablink" onclick="category('Categories', this, 'cat')" id="defaultOpen">Categories</button>
<button class="tablink" onclick="category('Users', this, 'usrs')">Users</button>
<section id="cat" class="contAdmn">
<form method="post" action="function.php" >
<input type="text" name="name" placeholder="name">
<button type="submit" name="btnAddCat">Add Category</button>
</form>
<?php
$arr = getAllCategory();
foreach ($arr as $val):
?>
<form method="post" action="function.php">
<input type="text" name="id" value="<?php echo $val['id'];?>" style="display: none;">
<input type="text" name="name" value="<?php echo $val['name'];?>">
<button type="submit" name="btnSaveCat">Save Category</button>
<button type="submit" name="btnDellCat">Delete Category</button>
</form>
<?php endforeach; ?>
</section>
<section id="usrs">
<form method="post" action="function.php">
<input type="text" name="login" placeholder="login">
<input type="text" name="pass" placeholder="pass">
<button type="submit" name="btnAddUser">Add User</button>
</form>
<?php
$arr = getAllUser();
foreach ($arr as $val):
?>
<form method="post" action="function.php">
<input type="text" name="id" value="<?php echo $val['id'];?>" style="display: none;">
<input type="text" name="login" value="<?php echo $val['login'];?>">
<input type="text" name="pass" value="<?php echo $val['pass'];?>">
<button type="submit" name="btnSaveUser">Save User</button>
<button type="submit" name="btnDellUser">Delete User</button>
</form>
<?php endforeach; ?>
</section>
<section id="prdc">
<form method="post" action="function.php" >
<input type="text" name="name" placeholder="name">
<input type="text" name="description" placeholder="description">
<input type="number" name="price" placeholder="price">
<input type="text" name="img" placeholder="img link">
<input type="number" name="category" placeholder="category id">
<button type="submit" name="btnAddPdkt">Add Product</button>
</form>
<?php
$arr = getAllProduct();
foreach ($arr as $val):
?>
<form method="post" action="function.php">
<input type="text" name="id" value="<?php echo $val['id'];?>" style="display: none;">
<input type="text" name="name" value="<?php echo $val['name'];?>">
<input type="text" name="description" value="<?php echo $val['description'];?>">
<input type="text" name="price" value="<?php echo $val['price'];?>">
<input type="text" name="img" value="<?php echo $val['img'];?>">
<button type="submit" name="btnSavePdkt">Save Product</button>
<button type="submit" name="btnDellPdkt">Delete Product</button>
</form>
<?php endforeach; ?>
</section>
<?php
if (isset($_POST['logout'])) {
session_destroy();
$_SESSION[login] = "";
header('Location: http://localhost:8100/admin.php');
}
?>
<form method="post">
<button type="submit" name="logout">LOGOUT</button>
</form>
<?php endif?>
<script>
function category(cityName,elmnt,id) {
elmnt.style.backgroundColor = "grey";
document.getElementById('prdc').style.display = 'none';
document.getElementById('usrs').style.display = 'none';
document.getElementById('cat').style.display = 'none';
document.getElementById(id).style.display = 'block';
}
document.getElementById("defaultOpen").click();
</script>
</body>
</html>