2025-02-24 22:02:51 +01:00
|
|
|
<?php
|
|
|
|
session_start();
|
|
|
|
if(!isset($_SESSION['user_id'])) {
|
|
|
|
die("<p>Du musst dich zuerst Einloggen oder Regestrieren <br> <a href='login/login-page.html'>Hier Einloggen</a> <br> <a href='signup/signup-page.html'>Hier Regestrieren</a>");
|
|
|
|
}
|
|
|
|
|
|
|
|
include "db_connect.php";
|
|
|
|
|
|
|
|
if (!isset($_GET['user'])) {
|
|
|
|
die("Kein Benutzer angegeben.");
|
|
|
|
}
|
|
|
|
|
2025-03-10 10:48:39 +01:00
|
|
|
$page = isset($_GET['page']) ? $_GET['page'] : 'posts';
|
|
|
|
|
2025-02-24 22:02:51 +01:00
|
|
|
$username = $_GET['user'];
|
|
|
|
$userId = $_SESSION['user_id'];
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Benutzerdaten abrufen
|
|
|
|
$stmt = $pdo->prepare("SELECT id, username, email, created_at FROM users WHERE username = :username");
|
|
|
|
$stmt->execute([':username' => $username]);
|
|
|
|
$selected_user = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
$stmt1 = $pdo->prepare("SELECT username, email, created_at FROM users WHERE id = :id");
|
|
|
|
$stmt1->execute([':id' => $userId]);
|
|
|
|
$user = $stmt1->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
$stmt2 = $pdo->prepare("SELECT file_path FROM profile_pictures WHERE user_id = :user_id");
|
|
|
|
$stmt2->execute([':user_id' => $userId]);
|
|
|
|
$profile_pic2 = $stmt2->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
$stmt3 = $pdo->prepare("
|
|
|
|
SELECT users.username, profile_pictures.file_path
|
|
|
|
FROM users
|
|
|
|
LEFT JOIN profile_pictures ON users.id = profile_pictures.user_id
|
|
|
|
ORDER BY profile_pictures.uploaded_at DESC
|
|
|
|
");
|
|
|
|
$stmt3->execute();
|
|
|
|
$users = $stmt3->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
if (!$selected_user) {
|
|
|
|
die("Benutzer nicht gefunden!");
|
|
|
|
}
|
|
|
|
|
|
|
|
$stmt2 = $pdo->prepare("SELECT file_path FROM profile_pictures WHERE user_id = :user_id");
|
|
|
|
$stmt2->execute([':user_id' => $selected_user['id']]);
|
|
|
|
$profile_pic = $stmt2->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
|
|
|
|
if ($profile_pic) {
|
|
|
|
$selected_profile_image = $profile_pic['file_path'];
|
|
|
|
} else {
|
|
|
|
$selected_profile_image = 'profile-pics/default.jpeg';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($profile_pic2) {
|
|
|
|
$selected_profile_image1 = $profile_pic2['file_path'];
|
|
|
|
} else {
|
|
|
|
$selected_profile_image1 = 'profile-pics/default.jpeg';
|
|
|
|
}
|
|
|
|
|
2025-03-10 10:48:39 +01:00
|
|
|
|
2025-02-26 08:56:42 +01:00
|
|
|
$stmt3 = $pdo->prepare("SELECT COUNT(following_id) AS following_count FROM followers WHERE following_id = :user_id ");
|
|
|
|
$stmt3->execute([':user_id' => $selected_user['id']]);
|
|
|
|
$follower_count = $stmt3->fetch(PDO::FETCH_ASSOC)['following_count'];
|
|
|
|
|
2025-02-24 22:02:51 +01:00
|
|
|
} catch (PDOException $e) {
|
|
|
|
die("Fehler: " . $e->getMessage());
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="de">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>Profil von <?php echo htmlspecialchars($selected_user['username']); ?></title>
|
|
|
|
<link rel="stylesheet" href="style.css?v=<?php echo time(); ?>">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="container">
|
|
|
|
<div class="col-3">
|
|
|
|
<div class="navigation-body">
|
2025-03-10 10:48:39 +01:00
|
|
|
<div class="profile-name-header">
|
|
|
|
<?php echo "<img class = 'profile-pictures-header' src='$selected_profile_image1' alt='pv' width='50'>";?>
|
|
|
|
<h1>
|
|
|
|
<a href="">@<?php echo htmlspecialchars($user['username']); ?></a>
|
|
|
|
</h1>
|
|
|
|
</div>
|
|
|
|
<ul class="icons">
|
|
|
|
<li><a href="index.php"><img src="icons/home.svg" alt="">Home</a></li>
|
|
|
|
<li><a href="profile.php?user=<?= htmlspecialchars($user['username']) ?>"><img src="icons/user.svg" alt="">Profil</a></li>
|
|
|
|
<li><a href="chat.php"><img src="icons/envelope.svg" alt="">Nachrichten</a></li>
|
|
|
|
<li><a href="logout.php"><img src="icons/exit.svg" alt="">Abmelden</a></li>
|
2025-02-24 22:02:51 +01:00
|
|
|
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="navigation-body">
|
|
|
|
<ul>
|
|
|
|
<?php foreach ($users as $benutzer): ?>
|
|
|
|
<li>
|
2025-03-10 10:48:39 +01:00
|
|
|
<form class="user-card" action="profile.php" method="post">
|
|
|
|
<a href="profile.php?user=<?= urlencode($benutzer['username']) ?>"> <img class="profile-pictures" src="<?= htmlspecialchars($benutzer['file_path']) ?: 'profile-pics/default.jpeg' ?>" alt="Profilbild"><?= htmlspecialchars($benutzer['username']) ?></a>
|
2025-02-24 22:02:51 +01:00
|
|
|
</form>
|
|
|
|
</li>
|
|
|
|
<?php endforeach; ?>
|
|
|
|
</ul>
|
2025-03-10 10:48:39 +01:00
|
|
|
|
2025-02-24 22:02:51 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<div class="profile-body col-9">
|
|
|
|
<div class="profile-header">
|
2025-03-10 10:48:39 +01:00
|
|
|
|
2025-02-24 22:02:51 +01:00
|
|
|
<h1>Profil von <?php echo htmlspecialchars($selected_user['username']); ?></h1>
|
|
|
|
<img src="<?php echo htmlspecialchars($selected_profile_image); ?>" alt="Profilbild" width="100">
|
|
|
|
<p>Email: <?php echo htmlspecialchars($selected_user['email']); ?></p>
|
|
|
|
<p>Registriert seit: <?php echo htmlspecialchars($selected_user['created_at']); ?></p>
|
2025-02-26 08:56:42 +01:00
|
|
|
<h3>Follower: <?php echo htmlspecialchars($follower_count) ?></h3>
|
2025-03-10 10:48:39 +01:00
|
|
|
<?php if($selected_user['id'] != $userId): ?>
|
|
|
|
|
2025-02-26 08:56:42 +01:00
|
|
|
<?php
|
|
|
|
$follower_id = $_SESSION['user_id'];
|
|
|
|
|
|
|
|
$stmt7 = $pdo->prepare("SELECT follower_id, following_id FROM followers WHERE follower_id = :user_id AND following_id = :id");
|
|
|
|
$stmt7->execute([':user_id' => $follower_id, ':id' => $selected_user['id']]);
|
|
|
|
$isfollower = $stmt7->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
?>
|
|
|
|
<?php if(!$isfollower):?>
|
|
|
|
<form action="follow/follow.php" method="post">
|
|
|
|
<input type="hidden" name="following_id" value="<?= htmlspecialchars($selected_user['id']) ?>">
|
|
|
|
<input type="hidden" name="username" value="<?= htmlspecialchars($selected_user['username']) ?>">
|
|
|
|
<button type="submit">Folgen</button>
|
|
|
|
</form>
|
|
|
|
<?php else: ?>
|
|
|
|
<form action="follow/unfollow.php" method="post">
|
|
|
|
<input type="hidden" name="following_id" value="<?= htmlspecialchars($selected_user['id']) ?>">
|
|
|
|
<input type="hidden" name="username" value="<?= htmlspecialchars($selected_user['username']) ?>">
|
|
|
|
<button type="submit">Nicht mehr Folgen</button>
|
|
|
|
</form>
|
|
|
|
<?php endif;?>
|
2025-03-10 10:48:39 +01:00
|
|
|
<form action="chat.php" method="get">
|
|
|
|
<input type="hidden" name="user" value="<?php echo $selected_user['id'] ?>">
|
|
|
|
<button type="submit">Nachricht Schreiben</button>
|
|
|
|
</form>
|
|
|
|
<?php endif; ?>
|
2025-02-24 22:02:51 +01:00
|
|
|
<a href="index.php">Zurück zur Startseite</a>
|
2025-03-10 10:48:39 +01:00
|
|
|
<a href="?user=<?= urlencode($selected_user['username'])?>&page=posts">Posts</a>
|
|
|
|
<a href="?user=<?= urlencode($selected_user['username'])?>&page=about">Über mich</a>
|
|
|
|
<?php if($selected_user['id'] == $userId):?>
|
|
|
|
<a href="?user=<?= urlencode($selected_user['username'])?>&page=settings">Einstellungen</a>
|
|
|
|
<?php endif;?>
|
2025-02-24 22:02:51 +01:00
|
|
|
</div>
|
2025-03-10 10:48:39 +01:00
|
|
|
<?php if($page == "settings"): ?>
|
|
|
|
<div class="posts-body">
|
|
|
|
|
|
|
|
<h1>Einstellungen</h1>
|
|
|
|
<h3>Profilbild änderen</h3>
|
|
|
|
<form action='upload-profile/upload.php' method='post' enctype='multipart/form-data'>
|
|
|
|
<input type='file' name='profile_picture' accept='image/*' required>
|
|
|
|
<br>
|
|
|
|
<button type='submit'>Profilbild hochladen</button>
|
|
|
|
</form>
|
|
|
|
<h3>Profilbild löschen</h3>
|
|
|
|
<form action='upload-profile/delete-pb.php'>
|
|
|
|
<button type='submit'>Profilbild löschen</button>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<h3>Profilbild änderm</h3>
|
|
|
|
<form action='change-username.php' method='post'>
|
|
|
|
<input type='text' required placeholder='Benutzername' name='username'>
|
|
|
|
<button type='submit'>Ändern</button>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<h3>Profilbild änderm</h3>
|
|
|
|
<form action='delete-user.php' method='post'>
|
|
|
|
<button type='submit'>Profil löschen</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
2025-02-24 22:02:51 +01:00
|
|
|
|
|
|
|
<?php
|
|
|
|
$stmt45 = $pdo->prepare("
|
|
|
|
SELECT posts.*, profile_pictures.file_path AS profile_picture, users.username
|
|
|
|
FROM posts
|
|
|
|
LEFT JOIN profile_pictures ON posts.user_id = profile_pictures.user_id
|
|
|
|
LEFT JOIN users ON posts.user_id = users.id
|
|
|
|
WHERE users.username = :username
|
|
|
|
ORDER BY posts.created_at DESC
|
|
|
|
");
|
|
|
|
$stmt45->execute([':username' => $username]);
|
|
|
|
$posts = $stmt45->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
?>
|
2025-03-10 10:48:39 +01:00
|
|
|
<?php if($page == "posts"): ?>
|
2025-02-24 22:02:51 +01:00
|
|
|
<?php foreach ($posts as $post): ?>
|
|
|
|
<div class="post">
|
|
|
|
<img src="<?= htmlspecialchars($post['profile_picture']) ?: 'profile-pics/default.jpeg'; ?>" width="50px" alt="">
|
|
|
|
<p><strong><?php echo $post['username']; ?></strong></p>
|
|
|
|
<p><?php echo nl2br(htmlspecialchars($post['text_content'])); ?></p>
|
|
|
|
|
|
|
|
<?php if (!empty($post['image_path'])): ?>
|
|
|
|
<img class="post-pics" src="<?php echo htmlspecialchars($post['image_path']); ?>" alt="Bild zum Post">
|
|
|
|
<?php endif; ?>
|
|
|
|
|
2025-02-26 08:56:42 +01:00
|
|
|
|
2025-02-24 22:02:51 +01:00
|
|
|
<p><small>Erstellt am: <?php echo $post['created_at']; ?></small></p>
|
2025-02-24 22:15:30 +01:00
|
|
|
<?php if ($userId == $post['user_id']): ?>
|
|
|
|
<form action="upload-post/delete-post.php" method="post">
|
|
|
|
<input type="hidden" name="post_id" value="<?= htmlspecialchars($post['id']) ?>">
|
|
|
|
<button type="submit">Löschen</button>
|
|
|
|
</form>
|
|
|
|
<?php endif; ?>
|
2025-02-24 22:02:51 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
<?php endforeach; ?>
|
2025-03-10 10:48:39 +01:00
|
|
|
<?php endif; ?>
|
2025-02-24 22:02:51 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|