مشكلة في عدم ظهور صورة ناشر المنشور مع انها يجب ان تكون نفس صورة الملف الشخصي التي تظهر و تعمل بشكل صحيح اسفل وصف المستخدم
<?php
session_start(); // بدء الجلسة
// التحقق إذا كانت الجلسة تحتوي على بيانات المستخدم
if (!isset($_SESSION['user_email']) && !isset($_COOKIE['user_email'])) {
header('Location: register.php'); // إعادة التوجيه إذا لم تكن الجلسة أو ملفات تعريف الارتباط متوفرة
exit();
}
// استرجاع بيانات المستخدم
$userEmail = isset($_SESSION['user_email']) ? $_SESSION['user_email'] : $_COOKIE['user_email'];
$userUsername = isset($_SESSION['user_username']) ? $_SESSION['user_username'] : $_COOKIE['user_username'];
$userPassword = isset($_SESSION['user_password']) ? $_SESSION['user_password'] : $_COOKIE['user_password'];
$userDescription = isset($_SESSION['user_description']) ? $_SESSION['user_description'] : $_COOKIE['user_description'];
$userProfilePicture = isset($_SESSION['user_profile_picture']) ? $_SESSION['user_profile_picture'] : $_COOKIE['user_profile_picture'];
if ($userProfilePicture) {
$userProfilePicture = base64_decode($userProfilePicture);
}
require 'db.php'; // الاتصال بقاعدة البيانات
// استرجاع المنشورات الخاصة بالمستخدم مع بيانات صورة الملف الشخصي
$stmt = $pdo->prepare("
SELECT posts.content, posts.created_at, users.username, users.profile_picture
FROM posts
JOIN users ON posts.user_id = users.id
WHERE users.email = :email
ORDER BY posts.created_at DESC
");
$stmt->execute(['email' => $userEmail]);
$posts = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>الملف الشخصي</title>
</head>
<body>
<h1>الملف الشخصي</h1>
<!-- عرض بيانات المستخدم -->
<p><strong>البريد الإلكتروني:</strong> <input id="emailInput" type="text" value="<?= htmlspecialchars($userEmail) ?>" readonly></p>
<p><strong>اسم المستخدم:</strong> <?= htmlspecialchars($userUsername) ?></p>
<p><strong>الوصف:</strong> <?= nl2br(htmlspecialchars($userDescription)) ?></p>
<!-- عرض صورة الملف الشخصي -->
<?php if ($userProfilePicture): ?>
<img src="data:image/jpeg;base64,<?= base64_encode($userProfilePicture) ?>" alt="صورة الملف الشخصي" style="width: 100px; height: 100px; border-radius: 50%;">
<?php endif; ?>
<!-- عرض كلمة المرور -->
<p><strong>كلمة المرور:</strong> <input id="passwordInput" type="text" value="<?= htmlspecialchars($userPassword) ?>" readonly></p>
<!-- زر لنسخ البيانات -->
<button onclick="copyToClipboard('emailInput')">نسخ البريد الإلكتروني</button>
<button onclick="copyToClipboard('passwordInput')">نسخ كلمة المرور</button>
<!-- نموذج نشر منشور -->
<h2>نشر منشور جديد</h2>
<form method="POST" action="profile.php">
<textarea name="content" placeholder="اكتب منشورك هنا..." required></textarea><br>
<button type="submit" name="submit_post">نشر المنشور</button>
</form>
<?php
// إضافة منشور جديد
if (isset($_POST['submit_post'])) {
$content = $_POST['content'];
try {
$stmt = $pdo->prepare("INSERT INTO posts (user_id, content) VALUES ((SELECT id FROM users WHERE email = :email), :content)");
$stmt->execute(['email' => $userEmail, 'content' => $content]);
// إعادة تحميل الصفحة
header("Location: profile.php");
exit();
} catch (PDOException $e) {
echo "حدث خطأ: " . $e->getMessage();
}
}
?>
<!-- عرض المنشورات الخاصة بالمستخدم -->
<h2>منشوراتك</h2>
<?php if (count($posts) > 0): ?>
<ul>
<?php foreach ($posts as $post): ?>
<li style="margin-bottom: 20px; border-bottom: 1px solid #ccc; padding-bottom: 10px;">
<!-- صورة الناشر -->
<?php if ($post['$userProfilePicture']): ?>
<img src="data:image/jpeg;base64,<?= base64_encode($post['$userProfilePicture']) ?>" alt="صورة الملف الشخصي" style="width: 50px; height: 50px; border-radius: 50%; display: inline-block;">
<?php else: ?>
<img src="default-profile.png" alt="صورة افتراضية" style="width: 50px; height: 50px; border-radius: 50%; display: inline-block;">
<?php endif; ?>
<!-- اسم المستخدم -->
<span style="margin-left: 10px; font-weight: bold;"><?= htmlspecialchars($post['username']) ?></span>
<!-- محتوى المنشور -->
<p style="margin-left: 60px;"><?= nl2br(htmlspecialchars($post['content'])) ?></p>
<!-- وقت النشر -->
<small style="margin-left: 60px; color: #666;">تم النشر في: <?= $post['created_at'] ?></small>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p>لا توجد منشورات بعد.</p>
<?php endif; ?>
<script>
function copyToClipboard(elementId) {
var copyText = document.getElementById(elementId);
copyText.select();
document.execCommand("copy");
alert("تم نسخ النص: " + copyText.value);
}
</script>
</body>
</html>
التعليقات