-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.php
362 lines (324 loc) · 17 KB
/
profile.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
<?php session_start();
include('data-base/constant.php');
?>
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Customer</title>
<link rel="stylesheet" type="text/CSS" href="css/main.css">
<link rel="stylesheet" type="text/CSS" href="css/profile.css">
<?php include('loader/loading-div.html') ?>
<script src="js/responsiveNavigation.js" defer></script>
</head>
<body>
<!-- menu start -->
<nav class="nav-bar" responsiveNavigation=false>
<ul>
<a href="index.php" class="no-text-decoration">
<li class="index ">home</li>
</a>
<a href="search.php" class="no-text-decoration">
<li class="category ">search</li>
</a>
<a href="order.php" class="no-text-decoration">
<li class="order">orders</li>
</a>
<a href="profile.php" class="no-text-decoration">
<li class="profile highlight">profile</li>
</a>
<?php
$user = (!isset($_SESSION['customer-id'])) ? "<a href='log-in.php' class='no-text-decoration'><li class='login'>log in</li></a>" :
"<a href='log-out.php' class='no-text-decoration'><li class='login'>log out</li></a>";
echo $user;
?>
<?php
if (isset($_SESSION['customer-id'])) {
// include('data-base/constant.php');
$id = $_SESSION['customer-id'];
$sql1 = "select profile_image from customer where id=$id";
$res = mysqli_query($conn, $sql1);
while ($row = $res->fetch_assoc()) {
echo "
<li class='sre-icon-list'>
<a href='profile.php' class='sre-icon-link'>
<div class='sre-main-small-image-container'>
<div class='sre-profile-image-small-container'>
<img src='" . $row['profile_image'] . "' class='sre-img'>
</div>
</div>
</a></li>
";
}
}
?>
</ul>
<button class="nav-button"></button>
</nav>
<!-- menu end -->
<!--body-->
<?php
if (!isset($_SESSION['customer-id'])) {
echo "<div class='user-not-found'>
<div class='user-not-logged-in-container'>
";
include('animated/user-not-logged-in.html');
echo "
<div class='question'>It seems like you are not logged in...!</div>
<a href='log-in.php' class='p-t-l-link'>
<div class='profile-to-log-in-page-link-container'>log in</div>
</a>
</div>
</div>";
}
?>
<div class="body1 main-height">
<div class="container-1">
<?php
$name = "";
$location = "";
$address = "";
$email = "";
$phone_one = "";
$phone_two = "";
$pin = "";
$nameErr = "";
$locationErr = "";
$addressErr = "";
$emailErr = "";
$phone1Err = "";
$phone2Err = "";
$pinErr = "";
$whiteflag = 1;
$total = 0;
$total_order = 0;
$coverImageError = "";
$fileName = "";
$coverImageError = "";
$fileDestination_new = "";
if (isset($_POST['submit'])) {
$name = $_POST['customername'];
$location = $_POST['customerlocation'];
$address = $_POST['customeraddress'];
$email = $_POST['customermail'];
$phone_one = $_POST['customerphone1'];
$phone_two = $_POST['customerphone2'];
$pin = $_POST['customerpin'];
if (isset($_FILES['image']['name'])) {
$cover_image = $_FILES['image'];
$fileName = $_FILES['image']['name'];
$fileTempName = $_FILES['image']['tmp_name'];
$fileSize = $_FILES['image']['size'];
$fileError = $_FILES['image']['error'];
$fileType = $_FILES['image']['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
}
if ($name == "") {
$nameErr = "border-bottom:2px solid red;border-radius:0px;box-shadow:none;";
}
if ($location == "") {
$locationErr = "border-bottom:2px solid red;border-radius:0px;";
}
if (!preg_match("/.{15,}/", $address)) {
$addressErr = "border-bottom:2px solid red;border-radius:0px;";
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "border-bottom:2px solid red;border-radius:0px;";
}
if (!preg_match("/^[0-9]{10}+$/", $phone_one)) {
$phone1Err = "border-bottom:2px solid red;border-radius:0px;";
}
if ($phone_two != "") {
if (!preg_match("/^[0-9]{10}+$/", $phone_two)) {
$phone2Err = "border-bottom:2px solid red;border-radius:0px;";
}
}
if (!preg_match("/^[0-9]{6}+$/", $pin)) {
$pinErr = "border-bottom:2px solid red;border-radius:0px;";
}
if ($nameErr == "" && $locationErr == "" && $addressErr == "" && $emailErr == "" && $phone1Err == "" && $phone2Err == "" && $pinErr == "") {
if (!$fileName == "") {
if ($fileError === 0) {
if ($fileSize < 1000000) {
$fileNewName = uniqid('', true) . "." . $fileActualExt;
$fileDestination = 'profile-images/' . $fileNewName;
move_uploaded_file($fileTempName, $fileDestination);
$fileDestination_new = 'profile-images/' . $fileNewName;
} else {
$coverImageError = "*Image size is too big";
}
} else {
$coverImageError = "*Some error occurred.Please choose an image one more time.";
}
} else {
$coverImageError = "*image is empty";
}
$r = $_SESSION['customer-id'];
$s = "select profile_image from customer where id=$r";
$profile_image_name_from_database = mysqli_query($conn, $s);
if ($fileDestination_new == "") {
while ($row = $profile_image_name_from_database->fetch_assoc()) {
$fileDestination_new = $row['profile_image'];
}
} else {
while ($row = $profile_image_name_from_database->fetch_assoc()) {
unlink($row['profile_image']);
}
}
if (($coverImageError == "" || $coverImageError == "*image is empty")) {
$id = $_SESSION['customer-id'];
$sql_query = "update customer SET name='$name' , location='$location' , address='$address' , email='$email' , phone1='$phone_one' , phone2='$phone_two' , pin='$pin' , profile_image='$fileDestination_new' where id=$id";
mysqli_query($conn, $sql_query);
} else {
$whiteflag = 0;
}
} else $whiteflag = 0;
}
?>
<?php
if (isset($_SESSION['customer-id'])) {
$id = $_SESSION['customer-id'];
$sql = "select * from customer where id=$id";
$result = mysqli_query($conn, $sql);
while ($row = $result->fetch_assoc()) {
$total_order = $row['t_order'];
$total = $row['t_money'];
if ($whiteflag == 1) {
echo "
<form action='?from=true' method='POST' id='profile-form' autocomplete='off' enctype='multipart/form-data'>
<div class='profile-image-container'>
<div class='circle'><img src='" . $row['profile_image'] . "' class='img'>
<div class='edit-btn1 hidden' id='edit-img-btn'>
<div class='upload-image'><input type='file' class='upload-img-input' name='image' accept='image/*'>
</div>
</div>
</div>
</div>
<input name='customername' id='wrap1' class='name' type='text' value='" . $row['name'] . "' style='box-shadow:none;width=100%;padding:1%;' disabled>
<div class='wrap-content'>
<div class='location'><input name='customerlocation' id='wrap2' class='ex-name' type='text' value='" . ucfirst($row['location']) . "' disabled></div>
<div class='address'><input name='customeraddress' id='wrap3' class='ex-name' type='text' value='" . $row['address'] . "' disabled></div>
<div class='email'><input name='customermail' id='wrap4' class='ex-name' type='text' value='" . $row['email'] . "' disabled></div>
<div class='phone1'><input name='customerphone1' id='wrap5' class='ex-name' type='text' value='" . $row['phone1'] . "' disabled></div>
";
echo "<div class='phone2'><input name='customerphone2' id='wrap6' class='ex-name' type='text' value='" . $row['phone2'] . "' disabled></div>";
echo "<div class='pin'><input name='customerpin' id='wrap7' class='ex-name' type='text' value='" . $row['pin'] . "' disabled></div>";
echo "</div></form>";
} else {
echo "
<form action='' method='POST' id='profile-form' autocomplete='off' enctype='multipart/form-data'>
<div class='profile-image-container'>
<div class='circle'><img src='" . $row['profile_image'] . "' class='img'>
<div class='edit-btn1 hidden' id='edit-img-btn'>
<div class='upload-image'><input type='file' class='upload-img-input' name='image' accept='image/*'>
</div>
</div>
</div>
</div>";
if (!($coverImageError == "*image is empty")) {
echo "<div class='sreyas-image-error'>" . $coverImageError . "</div>";
}
echo "
<input name='customername' id='wrap1' class='name' style='" . $nameErr . "box-shadow:none;width=100%;padding:0 1% 1%;' type='text' value='" . $name . "' disabled>
<div class='wrap-content'>
<div class='location'><input name='customerlocation' id='wrap2' class='ex-name' style='" . $locationErr . "' type='text' value='" . $location . "' disabled></div>
<div class='address'><input name='customeraddress' id='wrap3' class='ex-name' style='" . $addressErr . "' type='text' value='" . $address . "' disabled></div>
<div class='email'><input name='customermail' id='wrap4' class='ex-name' style='" . $emailErr . "' type='text' value='" . $email . "' disabled></div>
<div class='phone1 bor'><input name='customerphone1' id='wrap5' class='ex-name' style='" . $phone1Err . "' type='text' value='" . $phone_one . "' disabled></div>
";
echo "<div class='phone2'><input name='customerphone2' id='wrap6' class='ex-name' style='" . $phone2Err . "' type='text' value='" . $phone_two . "' disabled></div>";
echo "<div class='pin'><input name='customerpin' id='wrap7' class='ex-name' style='" . $pinErr . "' type='text' value='" . $pin . "' disabled></div>";
echo "</div></form>";
}
}
}
?>
<div class="update-button-container">
<?php
if (!($nameErr == "" && $locationErr == "" && $addressErr == "" && $emailErr == "" && $phone1Err == "" && $phone2Err == "" && $pinErr == "" && ($coverImageError == "" || $coverImageError == "*image is empty"))) {
echo "<a href='profile.php' class='fix'><div class='fix-container'>fix</div></a>";
}
?>
<button id="edit-btn" type="submit" name="submit" form="profile-form" class="update-btn" value="update">update</button>
<button id="edit-button" form="profile-form" class="update-button" value="hello" onclick="editProfile()">Edit</button>
</div>
</div>
<div class="image-container-1">
<?php include('animated/profile.html'); ?>
</div>
<div class="image-container-2">
<?php include('animated/profile2.html'); ?>
</div>
<div class="container-2">
<div class="container-2-div-1">
<div class="money-spent">
Total money spent
</div>
<div class="money-container">
<?php echo $total . "<span class='indian-money'>₹</span>"; ?>
</div>
</div>
<div class="container-2-div-2">
<div class="total-order">
Total order placed
</div>
<div class="total-order-container">
<?php echo $total_order; ?>
</div>
</div>
</div>
</div>
<!--footer-->
<script>
document.getElementById("edit-button").setAttribute("type", "button");
function editProfile() {
let wrap1 = document.getElementById("wrap1")
wrap1.removeAttribute("disabled")
wrap1.style.backgroundColor = "#303a41"
wrap1.style.borderBottom = "2px solid #252f33"
wrap1.style.borderRadius = "0"
wrap1.style.boxShadow = "0 0 0 0 #303a41"
//$("edit-button").childern().foreach(v => v.removeAttribute("diabled))
let wrap2 = document.getElementById("wrap2")
wrap2.removeAttribute("disabled")
wrap2.style.backgroundColor = "#303a41"
wrap2.style.borderBottom = "2px solid #252f33"
wrap2.style.borderRadius = "0"
wrap2.style.boxShadow = "0 0 0 0 #303a41"
let wrap3 = document.getElementById("wrap3")
wrap3.removeAttribute("disabled")
wrap3.style.backgroundColor = "#303a41"
wrap3.style.borderBottom = "2px solid #252f33"
wrap3.style.borderRadius = "0"
wrap3.style.boxShadow = "0 0 0 0 #303a41"
let wrap4 = document.getElementById("wrap4")
wrap4.removeAttribute("disabled")
wrap4.style.backgroundColor = "#303a41"
wrap4.style.borderBottom = "2px solid #252f33"
wrap4.style.borderRadius = "0"
wrap4.style.boxShadow = "0 0 0 0 #303a41"
let wrap5 = document.getElementById("wrap5")
wrap5.removeAttribute("disabled")
wrap5.style.backgroundColor = "#303a41"
wrap5.style.borderBottom = "2px solid #252f33"
wrap5.style.borderRadius = "0"
wrap5.style.boxShadow = "0 0 0 0 #303a41"
let wrap6 = document.getElementById("wrap6")
wrap6.removeAttribute("disabled")
wrap6.style.backgroundColor = "#303a41"
wrap6.style.borderBottom = "2px solid #252f33"
wrap6.style.borderRadius = "0"
wrap6.style.boxShadow = "0 0 0 0 #303a41"
let wrap7 = document.getElementById("wrap7")
wrap7.removeAttribute("disabled")
wrap7.style.backgroundColor = "#303a41"
wrap7.style.borderBottom = "2px solid #252f33"
wrap7.style.borderRadius = "0"
wrap7.style.boxShadow = "0 0 0 0 #303a41"
document.getElementById("edit-btn").setAttribute("class", "clickable");
// making the image edit button visible when clicking on the edit button
let editBtn = document.getElementById("edit-img-btn")
editBtn.classList.remove('hidden')
}
</script>
<?php include('elements/footer.html') ?>