-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.php
More file actions
221 lines (184 loc) · 8.26 KB
/
Copy pathprofile.php
File metadata and controls
221 lines (184 loc) · 8.26 KB
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
<?php
include_once 'includes/header.php';
// Giriş yapmamış kullanıcıyı giriş sayfasına yönlendir
if (!$is_logged_in) {
header("Location: login.php");
exit();
}
$user_id = $_SESSION['user_id'];
$error = '';
$success = '';
// Kullanıcı bilgilerini çekme
$stmt = $conn->prepare("SELECT ad, email, kayit_tarihi FROM kullanicilar WHERE id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
$user_info = $result->fetch_assoc();
$stmt->close();
// Yorumları çekme
$comments_stmt = $conn->prepare("
SELECT y.id AS yorum_id, y.metin, y.tarih, p.ad as yapim_ad
FROM yorumlar y
JOIN yapimlar p ON y.yapim_id = p.id
WHERE y.kullanici_id = ?
ORDER BY y.tarih DESC
");
$comments_stmt->bind_param("i", $user_id);
$comments_stmt->execute();
$comments_result = $comments_stmt->get_result();
$comments_stmt->close();
// Favorileri Çekme
$favorites_stmt = $conn->prepare("
SELECT f.id AS fav_id, p.ad, p.tur, p.yil
FROM favoriler f
JOIN yapimlar p ON f.yapim_id = p.id
WHERE f.kullanici_id = ?
ORDER BY f.id DESC
");
$favorites_stmt->bind_param("i", $user_id);
$favorites_stmt->execute();
$favorites_result = $favorites_stmt->get_result();
$favorites_stmt->close();
?>
<h2 style="color: #2b1055">Hoş Geldin, <?php echo htmlspecialchars($user_info['ad']); ?>!</h2>
<hr>
<section class="profile-info">
<h3>Kişisel Bilgiler</h3>
<p><strong>Ad:</strong> <?php echo htmlspecialchars($user_info['ad']); ?></p>
<p><strong>E-posta:</strong> <?php echo htmlspecialchars($user_info['email']); ?></p>
<p><strong>Kayıt Tarihi:</strong> <?php echo htmlspecialchars($user_info['kayit_tarihi']); ?></p>
</section>
<hr>
<div class="profile-layout">
<div class="profile-column">
<h3>💬 Yorumlarım (<span id="comment-count-profile"><?php echo $comments_result->num_rows; ?></span>)</h3>
<ul class="activity-list">
<?php if ($comments_result->num_rows > 0): ?>
<?php while ($comment = $comments_result->fetch_assoc()): ?>
<li class="activity-card" id="comment-<?php echo $comment['yorum_id']; ?>">
<button class="card-action-btn btn-delete"
data-id="<?php echo $comment['yorum_id']; ?>"
data-type="comment">🗑️ Sil</button>
<span class="card-title"><?php echo htmlspecialchars($comment['yapim_ad']); ?></span>
<p>"<?php echo htmlspecialchars($comment['metin']); ?>"</p>
<small><?php echo date('d.m.Y', strtotime($comment['tarih'])); ?></small>
</li>
<?php endwhile; ?>
<?php else: ?>
<p>Henüz herhangi bir yorum yapmadınız.</p>
<?php endif; ?>
</ul>
</div>
<div class="profile-column">
<h3>⭐ Favorilerim (<span id="favorite-count-profile"><?php echo $favorites_result->num_rows; ?></span>)</h3>
<ul class="activity-list">
<?php if ($favorites_result->num_rows > 0): ?>
<?php while ($favorite = $favorites_result->fetch_assoc()): ?>
<li class="activity-card" id="fav-<?php echo $favorite['fav_id']; ?>">
<button class="card-action-btn btn-delete"
data-id="<?php echo $favorite['fav_id']; ?>"
data-type="favorite">❌ Kaldır</button>
<span class="card-title"><?php echo htmlspecialchars($favorite['ad']); ?> (<?php echo htmlspecialchars($favorite['yil']); ?>)</span>
<p>Tür: <?php echo htmlspecialchars($favorite['tur']); ?></p>
</li>
<?php endwhile; ?>
<?php else: ?>
<p>Henüz favorilerinize yapım eklemediniz.</p>
<?php endif; ?>
</ul>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const activityList = document.querySelector('.profile-layout');
const modal = document.getElementById('custom-confirm-modal');
const confirmMessage = document.getElementById('confirm-message');
const modalConfirmBtn = document.getElementById('modal-confirm-btn');
const modalCancelBtn = document.getElementById('modal-cancel-btn');
let actionContext = null; // Silinecek öğenin tipini ve ID'sini tutar
// Modal'ı gösterme fonksiyonu
const showModal = (message) => {
confirmMessage.innerText = message;
modal.style.display = 'flex';
};
// Modal'ı gizleme fonksiyonu
const hideModal = () => {
modal.style.display = 'none';
actionContext = null;
};
// İptal butonları
modalCancelBtn.addEventListener('click', hideModal);
modal.addEventListener('click', (e) => { // Overlay'e tıklanırsa kapat
if (e.target.id === 'custom-confirm-modal') {
hideModal();
}
});
// Ana olay dinleyicisi (Sil/Kaldır butonlarına tıklama)
activityList.addEventListener('click', (e) => {
const button = e.target.closest('.card-action-btn');
if (!button) return;
const id = button.dataset.id;
const type = button.dataset.type; // 'comment' veya 'favorite'
// Silinecek öğe bilgisini kaydet
actionContext = { id, type, button };
// Özelleştirilmiş mesajı göster
const message = `${type === 'comment' ? 'Yorumu' : 'Favoriyi'} silmek istediğinizden emin misiniz?`;
showModal(message);
});
// Onay butonu (Modal içindeki 'Sil' butonuna tıklama)
modalConfirmBtn.addEventListener('click', async () => {
if (!actionContext) return;
const { id, type, button } = actionContext;
const action = type === 'comment' ? 'delete_comment' : 'remove_favorite';
hideModal(); // Modal'ı hemen kapat
button.disabled = true;
let formData = new FormData();
formData.append('id', id);
try {
const response = await fetch(`api.php?action=${action}`, {
method: 'POST',
body: formData
});
const data = await response.json();
if (data.success) {
// Başarılı olursa kartı sayfadan kaldır
const cardId = type === 'comment' ? `comment-${id}` : `fav-${id}`;
document.getElementById(cardId).style.opacity = 0; // Hızlı kaybolma
setTimeout(() => {
document.getElementById(cardId).remove();
}, 300);
// SAYI GÜNCELLEME MANTIĞI
// Hangi sayacı güncelleyeceğimizi belirle
const countElementId = type === 'comment' ? 'comment-count-profile' : 'favorite-count-profile';
const countElement = document.getElementById(countElementId);
if (countElement) {
let currentCount = parseInt(countElement.innerText);
if (!isNaN(currentCount) && currentCount > 0) {
countElement.innerText = currentCount - 1; // Sayıyı 1 azalt
}
}
} else {
alert(data.message); // Hata durumunda alert
}
} catch (error) {
console.error('AJAX Hatası:', error);
alert('İşlem sırasında sunucu hatası oluştu.');
} finally {
button.disabled = false;
}
});
});
</script>
<div id="custom-confirm-modal" class="modal-overlay">
<div class="modal-content">
<h3 id="confirm-message">Emin misiniz?</h3>
<p>Bu öğeyi geri alınamaz bir şekilde silmek üzeresiniz.</p>
<div class="modal-actions">
<button id="modal-cancel-btn" class="btn btn-secondary">İptal</button>
<button id="modal-confirm-btn" class="btn btn-delete">Sil</button>
</div>
</div>
</div>
<?php
include_once 'includes/footer.php';
?>