-
Notifications
You must be signed in to change notification settings - Fork 0
/
favorites.php
289 lines (261 loc) · 12.4 KB
/
favorites.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
<!DOCTYPE html>
<html>
<?php include 'head.php'; ?>
<body style="background: #2b343b; color: white;">
<div class="row vhw">
<?php include 'favorite_navbar.php'; ?>
<div class="col p-3 m-2 overflow-auto scrollbar1">
<nav class="navbar text-white">
<div class="container-fluid">
<?php
include 'config.php';
// get total number of favorite contacts
$query = mysqli_query($conn, "SELECT COUNT(*) as num_favorites FROM contacts WHERE favorite = true");
$result = mysqli_fetch_assoc($query);
$num_favorites = $result['num_favorites'];
?>
<h4 class="navbar-brand text-white"><i class="fa-solid fa-list-ul"></i> You have <?php echo $result['num_favorites']; ?> Favorite Contacts</h4>
</div>
</nav>
<hr class="bg-secondary">
<!-- Table -->
<div class="container-fluid my-3 p-3 rounded shadow-lg overflow-auto scrollbar1 w-75">
<div class="row">
<div class="col">
<table class="table table-dark table-striped table-hover table-responsive-md text-white py-3" id="table1">
<thead>
<tr>
<th class="text-center">Contact Name</th>
<th class="text-center">Actions</th>
</tr>
</thead>
<tbody>
<?php
include 'config.php';
$query = "SELECT * FROM contacts WHERE favorite='1' ORDER BY id DESC";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0) {
while ($data = mysqli_fetch_assoc($result)) {
?>
<tr>
<td class='text-center'><?php echo $data['F_name']; ?> <?php echo $data['L_name']; ?></td>
<td class="text-center">
<!-- Favorite Action -->
<?php if ($data['favorite'] === '0') { ?>
<button class="btn btn-outline-primary text-white fav" onclick="toggleFavoriteStatus('<?php echo $data['id']; ?>')">
<i class="fa-regular fa-star"></i>
</button>
<?php } else { ?>
<button class="btn btn-outline-warning text-white unfav" onclick="toggleRemoveFavoriteStatus('<?php echo $data['id']; ?>')">
<i class="fa-solid fa-star"></i>
</button>
<?php } ?>
<!-- View Action -->
<button class="btn btn-outline-success text-white" onclick="viewModal
('<?php echo $data['id']; ?>',
'<?php echo $data['F_name']; ?>',
'<?php echo $data['L_name']; ?>',
'<?php echo $data['phone_number']; ?>',
'<?php echo $data['c_address']; ?>')">
<i class="fa-solid fa-eye"></i>
</button>
<!-- Edit Action -->
<button class="btn btn-outline-info text-white" onclick="editModal
('<?php echo $data['F_name']; ?>',
'<?php echo $data['L_name']; ?>',
'<?php echo $data['phone_number']; ?>',
'<?php echo $data['c_address']; ?>',
'<?php echo $data['id']; ?>')">
<i class="fa-solid fa-pen-to-square"></i>
</button>
<!-- Delete Action -->
<button class="btn btn-outline-danger text-white" onclick="deleteModal('<?php echo $data['id']; ?>')">
<i class="fa-solid fa-trash-can"></i>
</button>
</td>
</tr>
<?php
}
} else {
echo "";
}
?>
</tbody>
</table>
</div>
</div>
</div>
<!-- End of Table -->
</div>
</div>
<!-- Actions Modals -->
<?php include 'add_modal.php'; ?>
<?php include 'edit_modal.php'; ?>
<!-- Loader -->
<div class='loaderClass'>
<div class='preloader'>
<div class='loader'></div>
</div>
</div>
</div>
</div>
</div>
</body>
<!-- JavaScripts -->
<!-- SweetAlert -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<link href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-dark@4/dark.css" rel="stylesheet">
<!-- Ionicons -->
<script type="module" src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js"></script>
<!-- Bootstrap -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<!-- Jquery -->
<script src="js/jquery.min.js" ></script>
<!-- FontAwesome -->
<script src="js/fontawesome.min.js"></script>
<script src="js/all.min.js"></script>
<script src="js/solid.min.js"></script>
<script src="js/regular.min.js"></script>
<script src="js/v4-shims.min.js"></script>
<!-- Jquery DataTables -->
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.js"></script>
<!-- CustomScript -->
<script src="js/custom.js"></script>
<script type="text/javascript">
// Add Favorite
function toggleFavoriteStatus(contact_id) {
Swal.fire({
title: 'Add to favorites?',
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: 'add_favorite.php',
type: 'POST',
data: {
id: contact_id,
favorite: 1,
},
success: function(response) {
if (response === 'success') {
Swal.fire({
title: 'Success!',
text: 'Contact added to favorites successfully!',
icon: 'success',
confirmButtonText: 'Ok'
}).then(function() {
window.location.href = "index.php";
});
} else {
// show an error message
Swal.fire({
title: 'Error!',
text: 'Failed to update contact favorite status!',
icon: 'error',
confirmButtonText: 'Ok'
}).then(function() {
window.location.href = "index.php";
});
}
}
});
}
})
}
// Remove Favorite
function toggleRemoveFavoriteStatus(contact_id) {
Swal.fire({
title: 'Remove from favorites?',
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: 'add_favorite.php',
type: 'POST',
data: {
id: contact_id,
favorite: 0,
},
success: function(response) {
if (response === 'success') {
Swal.fire({
title: 'Success!',
text: 'Contact removed from favorites successfully!',
icon: 'success',
confirmButtonText: 'Ok'
}).then(function() {
window.location.href = "index.php";
});
} else {
// show an error message
Swal.fire({
title: 'Error!',
text: 'Failed to update contact favorite status!',
icon: 'error',
confirmButtonText: 'Ok'
}).then(function() {
window.location.href = "index.php";
});
}
}
});
}
})
}
// View Contact
function viewModal(id, F_name, L_name, phone, address) {
Swal.fire({
title: '',
html: `
<h1 class="text-white"><i class="fa-solid fa-circle-user fa-2xl"></i> ${F_name} ${L_name}</h1><br>
<p>Contact Information</p>
<div class="form-floating mb-2" data-bs-theme="dark">
<input type="text" class="form-control" id="floatingInputDisabled" placeholder="" value="${F_name}" disabled>
<label for="floatingInputDisabled">First Name</label>
</div>
<div class="form-floating mb-2" data-bs-theme="dark">
<input type="text" class="form-control " id="floatingInputDisabled" placeholder="" value="${L_name}" disabled>
<label for="floatingInputDisabled">Last Name</label>
</div>
<div class="form-floating mb-2" data-bs-theme="dark">
<input type="text" class="form-control " id="floatingInputDisabled" placeholder="" value="${phone}" disabled>
<label for="floatingInputDisabled">Phone Number</label>
</div>
<div class="form-floating mb-2" data-bs-theme="dark">
<input type="text" class="form-control " id="floatingInputDisabled" placeholder="" value="${address}" disabled>
<label for="floatingInputDisabled">Address</label>
</div>
`,
showConfirmButton: false,
showCancelButton: true,
cancelButtonText: '<i class="fa-solid fa-x"></i> Close',
focusCancel: true,
cancelButtonColor: '#d33'
});
}
// Loader
$(window).on('load', function() {
$('.preloader').addClass('complete')
})
// Custom SideNavbar
const list = document.querySelectorAll('.list');
function activelink() {
list.forEach((item) =>
item.classList.remove('active'));
this.classList.add('active');
}
list.forEach((item) =>
item.addEventListener('click', activelink));
</script>
<!-- JavaScripts End -->
</html>