Version 0.7

-Man kann die Profile öffnen
-Paar kleine Verbesserungen

Signed-off-by: erik <micheler@steinbeis.schule>
This commit is contained in:
Erik M 2025-02-24 22:02:51 +01:00
parent 005c33dae9
commit 65c6d9a45c
19 changed files with 281 additions and 75 deletions

8
FVS-Social/.idea/.gitignore generated vendored Normal file
View file

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

8
FVS-Social/.idea/FVS-Social.iml generated Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

12
FVS-Social/.idea/dataSources.xml generated Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="@134.255.227.143" uuid="9fc2f862-e06f-4785-9910-0fdcd315bfb8">
<driver-ref>mariadb</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mariadb://134.255.227.143:3306</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

View file

@ -0,0 +1,12 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PhpMissingStrictTypesDeclarationInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpUndefinedVariableInspection" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />
<option name="processComments" value="true" />
</inspection_tool>
</profile>
</component>

8
FVS-Social/.idea/modules.xml generated Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/FVS-Social.iml" filepath="$PROJECT_DIR$/.idea/FVS-Social.iml" />
</modules>
</component>
</project>

19
FVS-Social/.idea/php.xml generated Normal file
View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MessDetectorOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCSFixerOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCodeSnifferOptionsConfiguration">
<option name="highlightLevel" value="WARNING" />
<option name="transferred" value="true" />
</component>
<component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PsalmOptionsConfiguration">
<option name="transferred" value="true" />
</component>
</project>

8
FVS-Social/.idea/sqldialects.xml generated Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/index.php" dialect="MariaDB" />
<file url="file://$PROJECT_DIR$/profile.php" dialect="MariaDB" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/9fc2f862-e06f-4785-9910-0fdcd315bfb8/console.sql" dialect="MariaDB" />
</component>
</project>

View file

@ -0,0 +1,22 @@
<?php
session_start();
include 'db_connect.php';
$user_id = $_SESSION['user_id'];
if ($_SERVER['REQUEST_METHOD'] == "POST"){
echo "Server Method funktioniert";
$username = $_POST['username'];
$stmt = $pdo->prepare("UPDATE users SET username = :username WHERE id = :user_id");
$stmt->execute([':username'=> $username,
':user_id' => $user_id]);
header("Location: index.php");
exit();
}
?>

View file

@ -1,12 +1,11 @@
<?php
global $pdo;
session_start();
$page = isset($_GET['page']) ? $_GET['page'] : 'posts';
$user_page = isset($_GET['user']) ? $_GET['user'] : 'posts';
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>");
if(!isset($_SESSION['user_id'])) {
header("Location: login/login-page.html");
}
include 'db_connect.php';
@ -37,18 +36,13 @@ session_start();
} else {
$profile_image = 'profile-pics/default.jpeg';
}
if(!$user){
die("Benutzer nicht gefunden!");
}
}catch (PDOException $e){
die("Fehler: " . $e->getMessage());
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
@ -79,10 +73,10 @@ session_start();
<ul>
<?php foreach ($users as $benutzer): ?>
<li>
<form action="profile.php" method="post">
<img src="<?= htmlspecialchars($benutzer['file_path']) ?: 'profile-pics/default.jpeg' ?>" alt="Profilbild">
<a href="index.php?user=<?= urlencode($benutzer['username']) ?>"><?= htmlspecialchars($benutzer['username']) ?></a>
<a href="profile.php?user=<?= urlencode($benutzer['username']) ?>"><?= htmlspecialchars($benutzer['username']) ?></a>
</form>
</li>
<?php endforeach; ?>
</ul>
@ -99,17 +93,20 @@ session_start();
<a href="?page=posts">Posts</a>
<a href="?page=about">Über mich</a>
<a href="?page=settings">Einstellungen</a>
<?php
if($user_page == $user['username']) {
echo htmlspecialchars($user['username']);
}
?>
</div>
<div class="posts-body">
<?php
if($page == 'posts'){
echo "<h1>Posts</h1>
<button>Post</button>
";
}elseif($page == 'about'){
echo "<h1>Über mich</h1>";
}elseif($page == 'settings'){
@ -126,45 +123,48 @@ session_start();
<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>
";
echo $profile_image;
}
?>
</div>
<!--------------------Vorübergehende anzeige--->
<div class="post-formular-body">
<?php
if($page == 'posts'){
echo "
<form action='upload-post/upload-post.php' method='post' enctype='multipart/form-data'>
<textarea name='text_content' required placeholder='Schreibe etwas...'></textarea>
<input type='file' name='image'>
<button type='submit'>Posten</button>
</form>
";
$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 posts.user_id = :user_id
ORDER BY posts.created_at DESC
");
$stmt45->execute([':user_id' => $userId]);
$stmt45->execute();
$posts = $stmt45->fetchAll(PDO::FETCH_ASSOC);
}
?>
</div>
<?php foreach ($posts as $post): ?>
<div class="post">
<img src="<?= htmlspecialchars($post['profile_picture']) ?: 'profile-pics/default.jpeg'; ?>" width="50px" alt="">
<p><strong>User #<?php echo $post['user_id']; ?></strong> schrieb:</p>
<p><strong><?php echo $post['username']; ?></strong></p>
<p><?php echo nl2br(htmlspecialchars($post['text_content'])); ?></p>
<?php if (!empty($post['image_path'])): ?>
@ -179,11 +179,6 @@ session_start();
</div>
<?php endforeach; ?>
<!--------------------Vorübergehende anzeige ende--->
</div>
</div>
</body>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

BIN
FVS-Social/posts/8_url.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

142
FVS-Social/profile.php Normal file
View file

@ -0,0 +1,142 @@
<?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.");
}
$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';
}
} 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">
<h1>
<?php echo "<img class = 'profile-pictures' src='$selected_profile_image1' alt='pv' width='50'>";?>
<a href=""><?php echo htmlspecialchars($user['username']); ?></a>
</h1>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="index.php?page=settings">Profil</a></li>
<li><a href="">Nachrichten</a></li>
<li><a href="">Benachrichtiungen</a></li>
</ul>
</div>
<div class="navigation-body">
<ul>
<?php foreach ($users as $benutzer): ?>
<li>
<form action="profile.php" method="post">
<img src="<?= htmlspecialchars($benutzer['file_path']) ?: 'profile-pics/default.jpeg' ?>" alt="Profilbild">
<a href="profile.php?user=<?= urlencode($benutzer['username']) ?>"><?= htmlspecialchars($benutzer['username']) ?></a>
</form>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<div class="profile-body col-9">
<div class="profile-header">
<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>
<a href="index.php">Zurück zur Startseite</a>
</div>
<?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);
?>
<?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; ?>
<p><small>Erstellt am: <?php echo $post['created_at']; ?></small></p>
</div>
<?php endforeach; ?>
</div>
</div>
</body>
</html>

View file

@ -46,11 +46,12 @@ body {
text-align: center;
background-color: #FFFFFF;
border: solid 1px #ECF0F5;
box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.25);
padding: 12px;
border-radius: 20px;
display: flex;
flex-direction: column;
box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.25);
align-items: center;
}

View file

@ -21,49 +21,20 @@ body {
}
.navigation-body{
background-color: #FFFFFF;
border: solid 1px #ECF0F5;
width: 100%;
border-radius: 20px;
}
.profile-header{
background-color: #FFFFFF;
border: solid 1px #ECF0F5;
width: 100%;
border-radius: 20px;
}
.post-pics{
max-width: 500px;
height: auto;
}
.posts-body {
.post-formular-body, .post, .posts-body, .all-posts-body, .profile-header, .navigation-body{
background-color: #FFFFFF;
border: solid 1px #ECF0F5;
box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.25);
width: 100%;
border-radius: 20px;
}
.post-formular-body, .post{
background-color: #FFFFFF;
border: solid 1px #ECF0F5;
width: 100%;
border-radius: 20px;
}
.all-posts-body{
background-color: #FFFFFF;
border: solid 1px #ECF0F5;
width: 100%;
border-radius: 20px;
}
[class*="col-"] {
padding: 15px;

View file

@ -32,7 +32,6 @@ if($_SERVER["REQUEST_METHOD"] == "POST") {
':image_path' => $image_path
]);
header("Location: ../index.php");
exit();
}

View file

@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">