-
Notifications
You must be signed in to change notification settings - Fork 1
/
account.php
219 lines (177 loc) · 6.38 KB
/
account.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
<?php
session_start();
include_once('config.php');
//if user is not logged in, redirect to login page
if (!isset($_SESSION['username'])) {
header("Location: preauth.php");
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" , initial-scale="1.0" />
<title>Maida - My Profile</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- get bootstrap cdn -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
<link href="Profile.css" rel="stylesheet" />
<link rel="stylesheet" href="search.css" />
<link rel="stylesheet" href="account.css" />
<link rel="stylesheet" href="navbar.css" />
<link rel="stylesheet" href="footer.css" />
</head>
<body>
<!-- NavBar Start -->
<nav id="header">
</nav>
<!-- NavBar End -->
<div class="maincontainer" style="margin-top:100px; padding:20px;">
<div class="maintext">
<span class="profile">My Profile</span>
</div>
<div class="mainfixed" style="padding:20px;">
<h4 style="color:orangered;">Username</h4>
<div style="background-color:lightgrey; padding:5px; border-radius:3px; width:90%" contenteditable="false" id="usernamefield" name="username"><?php echo $_SESSION['username'] ?></div>
<br>
<h4 style="color:orangered;">My Address:</h4>
<div style="background-color:lightgrey; padding:5px; border-radius:3px; width:90%" contenteditable="false" id="addressfield" name="address"><?php
$sql = "SELECT * FROM users WHERE username = '" . $_SESSION['username'] . "'";
$query = $db->prepare($sql);
$query->execute();
$result = $query->fetchAll(PDO::FETCH_OBJ);
if ($query->rowCount() > 0) {
foreach ($result as $row) {
if ($row->address == "") {
echo "No address added";
} else {
echo $row->address;
}
}
}
?></div>
<br>
<h4 style="color:orangered;">Email:</h4>
<div style="background-color:lightgrey; padding:5px; border-radius:3px; width:90%" contenteditable="false" id="emailfield" name="email"><?php echo $_SESSION['email'] ?></div>
<br />
</div>
<div class="buttons">
<input type="submit" class="changes1" name="save" style="display: none;" value="Save">
<button class="changes2" style="display: none;"><i class="fa-solid fa-x"></i></button>
<button class="btn btn-success" style="margin-bottom:10px; margin-top:10px;" id="editbtn"><span>Edit My Profile</span></button>
</div>
</div>
<center>
<div class="container">
<div class="mydishesHeader">
<h2 class="dishesAvailable">My Dishes</h2>
<hr />
</div>
<div class="slider">
<center>
<div class="cardsList">
<?php
$sql = "SELECT * FROM dishes WHERE chefid LIKE '%{$_SESSION['username']}%'";
$query = $db->prepare($sql);
$query->execute();
$result = $query->fetchAll(PDO::FETCH_OBJ);
if ($query->rowCount() > 0) {
foreach ($result as $row) {
echo "
<div class='cardContainer'>
<a id='exists' href=" . "editing.php?dishid=$row->id" . ">
<div class='card'>
<img src='imageUploads/$row->image' alt='' />
</div>
<div class='cardDescription'>
<div class='name' style='color:black;'>$row->name</div>
<div class='price'>".$row->price."L.L.</div>
</div>
</a>
</div>
";
}
} else {
echo "<center id='noexist'><h2 style='color: black;'>You have not posted a dish yet.</h2>
<br>
<a id='postingbtn' class='mt-3' href='posting.php'><button class='btn btn-success'>Add Dish</button></a></center>";
}
?>
</div>
</center>
</div>
</div>
<br>
<br>
</center>
<footer id="footer">
</footer>
<script>
const editBtn = document.getElementById('editbtn');
const emailField = document.getElementById('emailfield');
const saveBtn = document.querySelector(".changes1");
const cancelBtn = document.querySelector(".changes2");
var email = emailField.innerHTML;
var toggle = 0;
editBtn.addEventListener('click', () => {
if (toggle == 0) {
saveBtn.style.display = "block";
cancelBtn.style.display = "block";
addressfield.contentEditable = true;
toggle = 1;
} else {
toggle = 0;
}
});
cancelBtn.addEventListener('click', () => {
saveBtn.style.display = "none";
cancelBtn.style.display = "none";
emailField.contentEditable = false;
addressfield.contentEditable = false;
usernameField.innerHTML = username;
emailField.innerHTML = email;
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("#header").load("navbar.php");
});
</script>
<script type="text/javascript">
$(function() {
$("#footer").load("footer.php");
});
</script>
<script>
var cardsList = document.querySelector(".cardsList");
var noexist = document.getElementById("noexist");
if (cardsList.contains(noexist)) {
cardsList.classList.add("d-flex", "align-items-center", "justify-content-center");
}
</script>
<script>
$(document).ready(function() {
$(".changes1").click(function() {
var username = $("#usernamefield").text();
var email = $("#emailfield").text();
var address = $("#addressfield").text();
$.ajax({
url: "process_profileupdate.php",
method: "POST",
data: {
username: username,
email: email,
address: address,
id: <?php echo $_SESSION['id'] ?>
},
success: function(data) {
location.reload();
}
});
});
});
</script>
</body>
</html>