-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreferrals.php
More file actions
287 lines (263 loc) · 10.6 KB
/
referrals.php
File metadata and controls
287 lines (263 loc) · 10.6 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Looma | Referrals</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link href="style.css" rel="stylesheet">
<style>
</style>
</head>
<body>
<?php
session_start();
// Redirect if not logged in
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit();
}
// Security headers
header('X-Frame-Options: DENY');
header('X-Content-Type-Options: nosniff');
require_once 'includes/db.php';
$user_id = $_SESSION['user_id'];
$full_name = $_SESSION['full_name'];
$error = '';
try {
// Fetch user data and referral code
$stmt = $conn->prepare('SELECT full_name, username, referral_code FROM users WHERE user_id = ?');
if ($stmt === false) {
throw new Exception('Prepare failed: ' . $conn->error);
}
$stmt->bind_param('i', $user_id);
$stmt->execute();
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
// Count referrals
$stmt = $conn->prepare('SELECT COUNT(*) as referral_count FROM users WHERE referred_by = ?');
if ($stmt === false) {
throw new Exception('Prepare failed: ' . $conn->error);
}
$stmt->bind_param('s', $user['referral_code']);
$stmt->execute();
$referral_count = $stmt->get_result()->fetch_assoc()['referral_count'];
$stmt->close();
// Fetch referred users
$stmt = $conn->prepare('SELECT full_name, username, created_at FROM users WHERE referred_by = ? ORDER BY created_at DESC');
if ($stmt === false) {
throw new Exception('Prepare failed: ' . $conn->error);
}
$stmt->bind_param('s', $user['referral_code']);
$stmt->execute();
$referred_users = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
$stmt->close();
} catch (Exception $e) {
$error = 'Error: ' . htmlspecialchars($e->getMessage());
}
// Get user initials
$initials = '';
$name_parts = explode(' ', $user['full_name']);
if (count($name_parts) >= 1) {
$initials .= strtoupper(substr($name_parts[0], 0, 1));
if (count($name_parts) > 1) {
$initials .= strtoupper(substr($name_parts[1], 0, 1));
}
}
// Referral link
$referral_link = 'http://localhost/new/looma/register.php?ref=' . urlencode($user['referral_code']);
?>
<!-- Desktop Sidebar -->
<div class="sidebar" id="sidebar">
<div class="sidebar-brand">
<h2>LOOMA</h2>
<p>Earn While You Play</p>
</div>
<nav class="nav flex-column">
<a href="index1.php" class="nav-link">
<i class="fas fa-home"></i>
<span>Dashboard</span>
</a>
<a href="games.php" class="nav-link">
<i class="fas fa-gamepad"></i>
<span>Games</span>
</a>
<a href="wallet1.php" class="nav-link">
<i class="fas fa-chart-line"></i>
<span>Earnings</span>
</a>
<a href="referrals.php" class="nav-link active">
<i class="fas fa-users"></i>
<span>Referrals</span>
</a>
<a href="settings.php" class="nav-link">
<i class="fas fa-cog"></i>
<span>Settings</span>
</a>
<a href="logout.php" class="nav-link">
<i class="fas fa-sign-out-alt"></i>
<span>Log out</span>
</a>
</nav>
<div class="sidebar-footer">
<p>© 2025 Looma</p>
</div>
</div>
<!-- Main Content -->
<div class="main-content" id="mainContent">
<!-- Top Navbar -->
<div class="top-navbar">
<h2>LOOMA</h2>
<div class="user-profile">
<div class="user-avatar"><?php echo htmlspecialchars($initials); ?></div>
<div>
<div class="fw-bold"><?php echo htmlspecialchars($user['username']); ?></div>
</div>
</div>
</div>
<!-- Content Container -->
<div class="content-container">
<?php if ($error): ?>
<div class="alert alert-danger">
<i class="fas fa-exclamation-circle"></i>
<?php echo $error; ?>
</div>
<?php endif; ?>
<!-- Referral Stats -->
<div class="row animate-fadeIn">
<div class="col-md-4 delay-2">
<div class="dashboard-card">
<div class="card-icon accent">
<i class="fas fa-users"></i>
</div>
<div class="card-value"><?php echo htmlspecialchars($referral_count); ?></div>
<div class="card-title">Referrals</div>
<button class="btn btn-sm btn-outline-danger" onclick="copyReferralLink()">Invite Friends</button>
</div>
</div>
</div>
<!-- Referral Link Section -->
<div class="card mt-4 animate-fadeIn">
<div class="card-body">
<h3 class="card-title">Your Referral Link</h3>
<p>Share this link with friends to earn rewards when they join Looma!</p>
<div class="input-group mb-3">
<input type="text" class="form-control" id="referral-link" value="<?php echo htmlspecialchars($referral_link); ?>" readonly>
<button class="btn btn-primary" onclick="copyReferralLink()" aria-label="Copy referral link">
<i class="fas fa-copy"></i> Copy
</button>
</div>
</div>
</div>
<!-- Referred Users Table -->
<div class="card mt-4 animate-fadeIn">
<div class="card-body">
<h3 class="card-title">Your Referrals</h3>
<?php if (empty($referred_users)): ?>
<p>You haven't referred anyone yet. Start sharing your link!</p>
<?php else: ?>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Username</th>
<th>Joined</th>
</tr>
</thead>
<tbody>
<?php foreach ($referred_users as $referred): ?>
<tr>
<td><?php echo htmlspecialchars($referred['full_name']); ?></td>
<td><?php echo htmlspecialchars($referred['username']); ?></td>
<td><?php echo date('M d, Y', strtotime($referred['created_at'])); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</div>
</div>
</div>
<!-- Mobile Bottom Navigation -->
<div class="mobile-bottom-nav">
<a href="index1.php" class="mobile-nav-item">
<i class="fas fa-home"></i>
<span>Home</span>
</a>
<a href="games.php" class="mobile-nav-item">
<i class="fas fa-gamepad"></i>
<span>Games</span>
</a>
<a href="wallet1.php" class="mobile-nav-item">
<i class="fas fa-wallet"></i>
<span>Earnings</span>
</a>
<a href="referrals.php" class="mobile-nav-item active">
<i class="fas fa-users"></i>
<span>Refer</span>
</a>
<a href="settings.php" class="mobile-nav-item">
<i class="fas fa-user"></i>
<span>Account</span>
</a>
<a href="logout.php" class="mobile-nav-item">
<i class="fas fa-sign-out-alt"></i>
<span>Log out</span>
</a>
</div>
<script>
// Toggle sidebar for desktop and mobile
function toggleSidebar() {
const sidebar = document.getElementById('sidebar');
const mainContent = document.getElementById('mainContent');
sidebar.classList.toggle('active');
mainContent.classList.toggle('main-content-expanded');
}
// Responsive navigation handling
function handleResize() {
const sidebar = document.getElementById('sidebar');
const mainContent = document.getElementById('mainContent');
if (window.innerWidth < 992) {
sidebar.classList.remove('active'); // Ensure sidebar is hidden on mobile
mainContent.classList.remove('main-content-expanded');
} else {
sidebar.classList.add('active'); // Show sidebar on desktop
mainContent.classList.remove('main-content-expanded');
}
}
window.addEventListener('resize', handleResize);
document.addEventListener('DOMContentLoaded', handleResize);
// Add animation classes as elements come into view
const animateElements = document.querySelectorAll('.animate-fadeIn');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate');
}
});
}, { threshold: 0.1 });
animateElements.forEach(element => {
observer.observe(element);
});
// Copy referral link
function copyReferralLink() {
const linkInput = document.getElementById('referral-link');
linkInput.select();
try {
document.execCommand('copy');
const btn = document.querySelector('.btn-primary');
const originalText = btn.innerHTML;
btn.innerHTML = '<i class="fas fa-check"></i> Copied!';
setTimeout(() => {
btn.innerHTML = originalText;
}, 2000);
} catch (err) {
alert('Failed to copy link.');
}
}
</script>
</body>
</html>