Main 6
Main 6
Main 6
addEventListener("click",
function () {
document.getElementById("sidebar").classList.toggle("open");
});
$(document).ready(function () {
// Add a click event listener to the post menu button
$('.custom-icon-btn').on('click', function () {
// Get the post ID from the data attribute
var postId = $(this).parent().data('post-id');
// Toggle the display of the sliding menu for the specific post
$('[data-post-id="' + postId + '"] .sliding-menu').slideToggle();
});
});
$(document).ready(function () {
// Add a click event listener to the post menu button
$('.custom-icon-btn').on('click', function (e) {
e.stopPropagation(); // Prevent the click event from bubbling up to the
document
// Toggle the display of the sliding menu for the specific post
slidingMenu.slideToggle();
});
if (currentUserId == postAuthorId) {
// User is the author, handle edit logic
console.log('Edit post clicked');
} else {
// User is not the author, handle unauthorized access
console.log('Unauthorized access to edit post');
}
});
if (currentUserId == postAuthorId) {
// User is the author, handle delete logic
console.log('Delete post clicked');
} else {
// User is not the author, handle unauthorized access
console.log('Unauthorized access to delete post');
}
});
});
*/
function deletep() {
if (confirm("Do you really want to delete your account permanently?"))
{
window.location.href = "../waste1/remove_account.php";
}
}
function logout() {
if (confirm("Are you sure you want to log out?")) {
// Add your logout logic here
// For example, you can redirect to a logout page or clear user
session data.
window.location.href = "logs/logout.php";
}
}
$(document).ready(function () {
// Fetch user profile picture using AJAX
$.ajax({
url: 'profile/get_images.php', // Path to your PHP script for fetching
profile picture
type: 'GET',
dataType: 'json',
success: function (data) {
if (data.success) {
var profilePicPath = data.profilePicPath;
// Check if the profile picture path is empty or null
if (profilePicPath && profilePicPath.trim() !== '') {
// If not empty, display the fetched profile picture
var imgElement = $('<img>').attr('src', 'profile/' +
profilePicPath).addClass('img-fluid rounded-circle profile-avatar');
$('#profile-picture-container').html(imgElement);
} else {
// If empty, display a default image
var defaultImgPath = 'messages/profile_pics/5022.jpeg'; // Path
to your default profile picture
var imgElement = $('<img>').attr('src',
defaultImgPath).addClass('img-fluid rounded-circle profile-avatar');
$('#profile-picture-container').html(imgElement);
}
} else {
// Handle errors when profile picture is not fetched
console.error(data.message);
}
},
error: function (xhr, status, error) {
// Handle AJAX errors, such as network issues
console.error('Error fetching profile picture: ' + error);
}
});
});
darkModeToggle.addEventListener('click', function () {
if (body.classList.contains('dark-mode')) {
disableDarkMode();
} else {
enableDarkMode();
}
});
if (navbarCollapse.classList.contains('show')) {
navbarCollapse.classList.remove('show');
}
});
}
});
/*
$(document).ready(function () {
// Find all elements with the class 'profile-picture-container'
var profilePictureContainers = document.querySelectorAll('.profile-picture-
container');
// Iterate through each container and make AJAX request for profile picture
profilePictureContainers.forEach(function(container) {
var userId = container.getAttribute('data-user-id');
$.ajax({
url: 'profile/get_image.php', // Path to your PHP script for fetching
profile picture
type: 'GET',
data: { user_id: userId }, // Pass user ID as data to the server-side
script
dataType: 'json',
success: function (data) {
if (data.success) {
var profilePicPath = data.profilePicPath;
// Check if the profile picture path is empty or null
if (profilePicPath && profilePicPath.trim() !== '') {
// If not empty, display the fetched profile picture
var imgElement = $('<img>').attr('src','profile/' +
profilePicPath).addClass('img-fluid rounded-circle profile-avatar');
$(container).html(imgElement);
} else {
// If empty, display a default image
var defaultImgPath = 'messages/profile_pics/5022.jpeg'; //
Path to your default profile picture
var imgElement = $('<img>').attr('src',
defaultImgPath).addClass('img-fluid rounded-circle profile-avatar');
$(container).html(imgElement);
}
} else {
// Handle errors when profile picture is not fetched
console.error(data.message);
}
},
error: function (xhr, status, error) {
// Handle AJAX errors, such as network issues
console.error('Error fetching profile picture: ' + error);
}
});
});
});
*/
$(document).ready(function () {
// Find all elements with the class 'profile-picture-container'
var profilePictureContainers = document.querySelectorAll('.profile-picture-
container');
// Iterate through each container and make AJAX request for profile picture and
username
profilePictureContainers.forEach(function(container) {
var userId = container.getAttribute('data-user-id');
$.ajax({
url: 'profile/get_image.php', // Path to your PHP script for fetching
profile picture and username
type: 'GET',
data: { user_id: userId }, // Pass user ID as data to the server-side
script
dataType: 'json',
success: function (data) {
if (data.success) {
var profilePicPath = data.profilePicPath;
var username = data.username;
// Check if the profile picture path and username are not empty
or null
if (profilePicPath && profilePicPath.trim() !== '' && username
&& username.trim() !== '') {
// If not empty, display the fetched profile picture and
username
var usernameElement = $
('<span>').text(username).addClass('profile-username');
var imgElement = $('<img>').attr('src', 'profile/' +
profilePicPath).addClass('img-fluid rounded-circle profile-avatar');
$(container).html(usernameElement).append(imgElement);
} else {
// If empty, display a default image and a placeholder
username
var defaultImgPath = 'messages/profile_pics/5022.jpeg'; //
Path to your default profile picture
var imgElement = $('<img>').attr('src',
defaultImgPath).addClass('img-fluid rounded-circle profile-avatar');
var placeholderUsername = 'Unknown User';
var usernameElement = $
('<span>').text(username).addClass('profile-username');
$(container).html(usernameElement).append(imgElement);
}
} else {
// Handle errors when profile picture and username are not
fetched
console.error(data.message);
}
},
error: function (xhr, status, error) {
// Handle AJAX errors, such as network issues
console.error('Error fetching profile picture and username: ' +
error);
}
});
});
});