-
Notifications
You must be signed in to change notification settings - Fork 1
/
seller-dashboard.php
395 lines (327 loc) · 13.3 KB
/
seller-dashboard.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<?php
session_start();
?>
<!DOCTYPE HTML>
<html>
<head>
<title>FullCashback - Seller Dashboard</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 15% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}
/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<?php
if (!isset($_COOKIE['seller-email'])) {
header('location:seller-home.php');
}
?>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$emailErr = $passwordErr = $paypalErr = $websiteErr = "";
$email = $password = $paypalusername = "";
$website = $_POST['website'];
$website = filter_var($website, FILTER_SANITIZE_URL);
if (filter_var($website, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) {
echo("$website is a valid URL");
} else {
$websiteErr = "Invalid URL";
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["password"])) {
$passwordErr = "Password is required";
} else {
$password = test_input($_POST["password"]);
}
$paypalusername = test_input($_POST["paypalusername"]);
if ($emailErr == "" && $passwordErr == "" && $websiteErr == "") {
$currentemail = $_COOKIE['seller-email'];
//$email = $_POST['email'];
//$password = $_POST['password'];
//$paypalusername = $_POST['paypalusername'];
// Create connection
$conn = mysqli_connect("localhost", "root", "PASSWORD", "fullcashback");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "UPDATE sellers SET email='$email', password='$password', website='$website', paypalusername='$paypalusername' WHERE email='$currentemail'";
if (mysqli_query($conn, $sql)) {
echo "Account details updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
mysqli_close($conn);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<?php
if (isset($_COOKIE['seller-email'])) {
$email = $_COOKIE['seller-email'];
$db = new PDO("mysql:host=localhost;dbname=fullcashback","root","PASSWORD");
$articlesor = $db->prepare("SELECT * FROM sellers WHERE email=:email");
$articlesor->execute(array(
'email' => $email
));
while($articlecek=$articlesor->fetch(PDO::FETCH_ASSOC)) {
?>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<div class="card-body">
<h1>Edit Your Account Details</h1>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" class="p-4 p-md-5 border rounded-3 bg-light">
<div class="form-floating mb-3">
<input type="email" name="email" value="<?php echo $articlecek['email'];?>" class="form-control" id="floatingInput" placeholder="[email protected]">
<label for="floatingInput">Email address</label>
<span style="color:red;"><?php echo $emailErr;?></span>
</div>
<div class="form-floating mb-3">
<input type="password" name="password" value="<?php echo $articlecek['password'];?>" class="form-control" id="floatingPassword" placeholder="Password">
<label for="floatingPassword">Password</label>
<span style="color:red;"><?php echo $passwordErr;?></span>
</div>
<div class="form-floating mb-3">
<input type="text" name="website" value="<?php echo $articlecek['website'];?>" class="form-control" id="floatingInput" placeholder="Website">
<label for="floatingInput">Website</label>
<span style="color:red;"><?php echo $websiteErr;?></span>
</div>
<div class="form-floating mb-3">
<input type="text" name="paypalusername" value="<?php echo $articlecek['paypalusername'];?>" class="form-control" id="floatingInput" placeholder="PayPal Username">
<label for="floatingPassword">PayPal Username</label>
<span style="color:red;"><?php echo $paypalErr;?></span>
</div>
<div class="form-floating mb-3 input-group">
<input type="text" disabled name="emailverified" value="<?php echo $articlecek['emailverified'];?>" class="form-control" id="floatingInput" placeholder="Email Verified">
<label for="floatingPassword">Email Verified</label>
<?php
if ($articlecek['emailverified'] == "false") {
?>
<button class="btn btn-outline-secondary">Verify Email</button><br>
<?php } ?>
</div>
<span style="color:red;"><?php echo $emailVerifiedErr;?></span>
<button class="w-100 btn btn-lg btn-primary" type="submit">Save Changes</button>
</form>
</div>
</div>
</div>
<?php
}
}
?>
<header class="p-3 mb-3 border-bottom">
<div class="container">
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
<a href="/" class="d-flex align-items-center mb-2 mb-lg-0 text-dark text-decoration-none">
<svg class="bi me-2" width="40" height="32" role="img" aria-label="Bootstrap"><use xlink:href="#bootstrap"></use></svg>
</a>
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
<li><a href="seller-dashboard.php" class="nav-link px-2 link-secondary">Seller Dashboard</a></li>
</ul>
<?php
if (isset($_COOKIE['seller-email'])) {
?>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
<?php echo $_COOKIE['seller-email']; ?>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item" onclick="deleteCookie();">Log Out</a></li>
<li><a class="dropdown-item" id="showModal">Edit Account Details</a></li>
<li><a class="dropdown-item" href="seller-applications.php">Product Applications</a></li>
<li><a class="dropdown-item" href="#">Payments</a></li>
</ul>
</div>
<?php } ?>
</div>
</div>
</header>
<!--
row py-lg-5
col-lg-6 col-md-8 mx-auto
p-4 p-md-5 border rounded-3 bg-light
-->
<main>
<section class="py-5 text-center container">
<div class="">
<div class="">
<h1 class="fw-light">Add A New Product</h1>
<br>
<form method="post" action="add-a-new-product.php" class="">
<div class="form-floating mb-3">
<input type="text" name="product-name" value="" class="form-control" id="floatingInput" placeholder="Product Name">
<label for="floatingInput">Product Name</label>
</div>
<div class="form-floating mb-3">
<input type="url" name="image-url" value="" class="form-control" id="floatingInput" placeholder="Image URL">
<label for="floatingPInput">Image URL</label>
<span style="color:red;"><?php echo $imageURLErr;?></span>
</div>
<div class="form-floating mb-3">
<input type="text" name="product-description" value="" class="form-control" id="floatingInput" placeholder="Short Description">
<label for="floatingInput">Short Description</label>
</div>
<div class="form-floating mb-3">
<!--<input type="text" name="product-details" value="" class="form-control" id="floatingInput" placeholder="Long Description (Include Details)">-->
<textarea rows="5" name="product-details" class="form-control" id="floatingInput" placeholder="Long Description (Include Details)"></textarea>
<label for="floatingInput">Long Description (Include Details)</label>
</div>
<div class="form-floating mb-3">
<input type="url" name="product-url" value="" class="form-control" id="floatingInput" placeholder="Product URL">
<label for="floatingPInput">Product URL</label>
<span style="color:red;"><?php echo $productURLErr;?></span>
</div>
<div class="form-floating mb-3">
<input step="0.01" type="number" name="product-price" value="" class="form-control" id="floatingInput" placeholder="Product Normal Price">
<label for="floatingInput">Product Normal Price</label>
</div>
<div class="form-floating mb-3">
<input step="0.01" type="number" name="product-discounted-price" value="" class="form-control" id="floatingInput" placeholder="Product Discounted Price">
<label for="floatingInput">Product Discounted Price</label>
</div>
<select name="product-category" class="form-select" aria-label="Choose a category">
<option value="all categories" selected>All Categories</option>
<option value="electronics">Electronics</option>
<option value="toys">Toys</option>
<option value="clothing">Clothing</option>
<option value="beauty">Makeup & Beauty</option>
</select><br>
<button class="w-100 btn btn-lg btn-primary" type="submit">Add Product</button>
</form>
</div>
</div>
</section>
<div class="album py-5 bg-light">
<div class="container">
<h2 style="text-align:center;">My Products</h2>
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
<?php
$db = new PDO("mysql:host=localhost;dbname=fullcashback","root","PASSWORD");
$selleremail = $_COOKIE['seller-email'];
$articlesor = $db->prepare("SELECT * FROM products WHERE selleremail=:selleremail");
$articlesor->execute(array(
'selleremail' => $selleremail
));
while($articlecek=$articlesor->fetch(PDO::FETCH_ASSOC)) {
?>
<div class="col">
<div class="card shadow-sm">
<img style="max-height:300px;" src="<?php echo $articlecek['imageurl'] ?>">
<div class="card-body">
<h3><?php echo $articlecek['name'] ?></h3>
<p class="card-text"><?php echo $articlecek['description'] ?></p>
<p style="color:green;">£<?php echo $articlecek['discountedprice'] ?></p>
<strike style="color:red;">£<?php echo $articlecek['price'] ?></strike>
<div class="d-flex justify-content-between align-items-center">
<div class="btn-group">
<form method="POST" action="edit-product.php">
<input type="hidden" name="productid" value="<?php echo $articlecek['id'] ?>">
<button type="submit" class="btn btn-primary">Edit Product Details</button>
</form>
<form method="POST" action="delete-product.php">
<input type="hidden" name="productid" value="<?php echo $articlecek['id'] ?>">
<button type="submit" class="btn btn-danger">Delete Product</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</main>
<script>
function deleteCookie() {
document.cookie = "seller-email=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
document.cookie = "seller-password=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
location.reload();
}
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("showModal");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>