-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_invites.php
More file actions
265 lines (237 loc) · 13.3 KB
/
client_invites.php
File metadata and controls
265 lines (237 loc) · 13.3 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
<?php
// client_invites.php - View All Client Invites
require_once 'auth_check.php';
require_client(); // Only clients can access
$client_id = get_user_id();
// Handle revoke action
if (isset($_GET['revoke']) && is_numeric($_GET['revoke'])) {
$invite_id = intval($_GET['revoke']);
// Verify ownership
$stmt = $conn->prepare("UPDATE invites SET used = 1 WHERE id = ? AND client_id = ?");
if ($stmt) {
$stmt->bind_param("ii", $invite_id, $client_id);
if ($stmt->execute() && $stmt->affected_rows > 0) {
set_flash_message("Invite revoked successfully.", "success");
} else {
set_flash_message("Failed to revoke invite.", "error");
}
$stmt->close();
}
header("Location: client_invites.php");
exit;
}
// Fetch invites for this client
$stmt = $conn->prepare("SELECT id, token, customer_name, customer_contact, note, diamonds_shared, expires_at, created_at, used, access_count, last_accessed_at
FROM invites
WHERE client_id = ?
ORDER BY created_at DESC");
if ($stmt === false) {
die("SQL Error: " . $conn->error);
}
$stmt->bind_param("i", $client_id);
$stmt->execute();
$result = $stmt->get_result();
$invites = [];
if ($result) {
while ($row = $result->fetch_assoc()) {
$invites[] = $row;
}
}
$stmt->close();
$base_url = get_base_url();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Invites - DS Diamonds</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
<style>
body {
font-family: 'Inter', sans-serif;
}
.sidebar {
width: 260px;
}
.main-content {
margin-left: 260px;
}
.gradient-bg {
background: linear-gradient(135deg, #7b2ff7, #f83077);
}
</style>
</head>
<body class="bg-gray-50">
<div class="flex">
<!-- Sidebar -->
<aside class="sidebar fixed h-screen bg-white border-r border-gray-200 overflow-y-auto">
<div class="p-6">
<div class="flex items-center mb-8">
<i class="far fa-gem text-3xl text-purple-600 mr-2"></i>
<span class="text-xl font-bold">DS<span class="text-pink-600">Diamonds</span></span>
</div>
<nav class="space-y-2">
<a href="client_dashboard.php"
class="flex items-center px-4 py-3 text-gray-700 hover:bg-gray-100 rounded-lg">
<i class="fas fa-th-large w-5"></i>
<span class="ml-3">Dashboard</span>
</a>
<a href="client_invites.php" class="flex items-center px-4 py-3 text-white gradient-bg rounded-lg">
<i class="fas fa-link w-5"></i>
<span class="ml-3">My Invites</span>
</a>
<a href="client_invite_create.php"
class="flex items-center px-4 py-3 text-gray-700 hover:bg-gray-100 rounded-lg">
<i class="fas fa-plus-circle w-5"></i>
<span class="ml-3">Create Invite</span>
</a>
<a href="home.php" class="flex items-center px-4 py-3 text-gray-700 hover:bg-gray-100 rounded-lg">
<i class="fas fa-home w-5"></i>
<span class="ml-3">Home</span>
</a>
<a href="logout.php" class="flex items-center px-4 py-3 text-red-600 hover:bg-red-50 rounded-lg">
<i class="fas fa-sign-out-alt w-5"></i>
<span class="ml-3">Logout</span>
</a>
</nav>
</div>
</aside>
<!-- Main Content -->
<main class="main-content flex-1 p-8">
<div class="max-w-6xl">
<!-- Header -->
<div class="flex justify-between items-center mb-8">
<div>
<h1 class="text-3xl font-bold text-gray-800 mb-2">My Invite Links</h1>
<p class="text-gray-600">Manage and track all your customer invite links.</p>
</div>
<a href="client_invite_create.php"
class="gradient-bg text-white px-6 py-3 rounded-lg font-semibold hover:opacity-90 transition flex items-center">
<i class="fas fa-plus mr-2"></i>Create New
</a>
</div>
<!-- Flash Messages -->
<?php echo get_flash_message(); ?>
<!-- Invites List -->
<?php if (empty($invites)): ?>
<div class="bg-white rounded-xl shadow-sm p-12 text-center">
<i class="far fa-link text-6xl text-gray-300 mb-4"></i>
<h3 class="text-xl font-semibold text-gray-700 mb-2">No invites yet</h3>
<p class="text-gray-500 mb-6">Create your first invite link to share diamonds with customers.</p>
<a href="client_invite_create.php"
class="inline-flex items-center gradient-bg text-white px-6 py-3 rounded-lg font-semibold hover:opacity-90 transition">
<i class="fas fa-plus mr-2"></i>Create Invite
</a>
</div>
<?php else: ?>
<div class="space-y-4">
<?php foreach ($invites as $invite):
$invite_url = $base_url . "/invite_view.php?token=" . $invite['token'];
$is_expired = strtotime($invite['expires_at']) < time();
$is_active = !$invite['used'] && !$is_expired;
$status_color = $is_active ? 'green' : ($invite['used'] ? 'gray' : 'red');
$status_text = $is_active ? 'Active' : ($invite['used'] ? 'Revoked' : 'Expired');
$diamonds_array = json_decode($invite['diamonds_shared'], true);
$diamond_count = is_array($diamonds_array) ? count($diamonds_array) : 0;
?>
<div class="bg-white rounded-xl shadow-sm p-6">
<div class="grid md:grid-cols-4 gap-6">
<!-- Left: Info -->
<div class="md:col-span-2">
<div class="flex items-start justify-between mb-3">
<div>
<h3 class="text-lg font-semibold text-gray-800">
<?php echo $invite['customer_name'] ? h($invite['customer_name']) : 'Unnamed Customer'; ?>
</h3>
<?php if ($invite['customer_contact']): ?>
<div class="text-sm text-gray-600 mt-1">
<i
class="fas fa-phone mr-1"></i><?php echo h($invite['customer_contact']); ?>
</div>
<?php endif; ?>
</div>
<span
class="px-3 py-1 text-xs font-semibold bg-<?php echo $status_color; ?>-100 text-<?php echo $status_color; ?>-800 rounded-full">
<?php echo $status_text; ?>
</span>
</div>
<?php if ($invite['note']): ?>
<div class="text-sm text-gray-600 bg-gray-50 p-3 rounded-lg mb-3">
<i class="fas fa-sticky-note mr-1"></i><?php echo h($invite['note']); ?>
</div>
<?php endif; ?>
<div class="flex flex-wrap gap-3 text-xs text-gray-500">
<div><i class="fas fa-gem mr-1"></i><?php echo $diamond_count; ?> diamonds</div>
<div><i class="fas fa-calendar mr-1"></i>Created
<?php echo format_date($invite['created_at'], 'M d, Y'); ?></div>
<div><i class="fas fa-clock mr-1"></i>Expires
<?php echo format_date($invite['expires_at'], 'M d, Y'); ?></div>
<?php if ($invite['access_count'] > 0): ?>
<div><i class="fas fa-eye mr-1"></i>Viewed <?php echo $invite['access_count']; ?>x
</div>
<?php endif; ?>
</div>
</div>
<!-- Right: Actions -->
<div class="md:col-span-2 flex flex-col justify-between">
<!-- Invite URL -->
<div class="mb-3">
<label class="block text-xs font-medium text-gray-600 mb-1">Invite Link</label>
<div class="flex gap-2">
<input type="text" readonly value="<?php echo h($invite_url); ?>"
id="invite_url_<?php echo $invite['id']; ?>"
class="flex-1 text-sm border border-gray-300 rounded-lg px-3 py-2 bg-gray-50">
<button onclick="copyToClipboard('invite_url_<?php echo $invite['id']; ?>')"
class="bg-purple-100 text-purple-700 px-4 py-2 rounded-lg hover:bg-purple-200 transition">
<i class="fas fa-copy"></i>
</button>
</div>
</div>
<!-- Action Buttons -->
<div class="flex gap-2">
<a href="<?php echo h($invite_url); ?>" target="_blank"
class="flex-1 text-center bg-gray-100 text-gray-700 px-4 py-2 rounded-lg font-medium hover:bg-gray-200 transition text-sm">
<i class="fas fa-external-link-alt mr-1"></i>Preview
</a>
<?php if ($is_active): ?>
<a href="client_invites.php?revoke=<?php echo $invite['id']; ?>"
onclick="return confirm('Are you sure you want to revoke this invite? The link will stop working.');"
class="flex-1 text-center bg-red-100 text-red-700 px-4 py-2 rounded-lg font-medium hover:bg-red-200 transition text-sm">
<i class="fas fa-ban mr-1"></i>Revoke
</a>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</main>
</div>
<script>
function copyToClipboard(elementId) {
const input = document.getElementById(elementId);
input.select();
input.setSelectionRange(0, 99999); // For mobile
navigator.clipboard.writeText(input.value).then(() => {
// Show toast notification
const toast = document.createElement('div');
toast.className = 'fixed bottom-4 right-4 bg-green-600 text-white px-6 py-3 rounded-lg shadow-lg z-50';
toast.innerHTML = '<i class="fas fa-check mr-2"></i>Link copied to clipboard!';
document.body.appendChild(toast);
setTimeout(() => {
toast.remove();
}, 3000);
}).catch(err => {
alert('Failed to copy link. Please copy manually.');
});
}
</script>
</body>
</html>
<?php $conn->close(); ?>