-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprofile.php
More file actions
760 lines (698 loc) · 42 KB
/
Copy pathprofile.php
File metadata and controls
760 lines (698 loc) · 42 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
<?php
$title = "User Profiles";
$page_title = $title;
include_once "include/config.php";
include_once "include/" . HEADER_FILE;
// Database connection
if (function_exists('db')) {
$con = db();
} else {
$con = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
}
if (!$con) {
die("Database connection failed: " . mysqli_connect_error());
}
// --- HELPER: Get Online Status & Region (STRICT MODE) ---
function get_user_status_and_region($con, $userId, $lastLogin) {
$uid = mysqli_real_escape_string($con, $userId);
$rName = "";
// 1. STRICT CHECK: Presence Table
// The Presence table contains ACTIVE sessions. If you are not here, you are not online.
$presenceTables = ['Presence', 'presence'];
foreach ($presenceTables as $table) {
$sqlCheck = "SHOW TABLES LIKE '$table'";
if (mysqli_num_rows(mysqli_query($con, $sqlCheck)) > 0) {
$sql = "SELECT p.RegionID, r.regionName
FROM `$table` p
LEFT JOIN regions r ON p.RegionID = r.uuid
WHERE p.UserID = '$uid' LIMIT 1";
$res = mysqli_query($con, $sql);
if ($res && mysqli_num_rows($res) > 0) {
$row = mysqli_fetch_assoc($res);
$rName = !empty($row['regionName']) ? $row['regionName'] : "Region " . substr($row['RegionID'], 0, 8) . "...";
return ['online' => true, 'region' => $rName];
}
}
}
// 2. SHORT TIME BUFFER (Race Condition Fix)
// Only assume online if login was less than 120 seconds ago.
// This covers the split second between "Login Success" and "Presence Table Write".
// We removed the GridUser check because it often gets stuck as "True".
if ($lastLogin > (time() - 120)) {
return ['online' => true, 'region' => 'Logging in...'];
}
return ['online' => false, 'region' => ''];
}
// Profile functions
function getUserProfile($con, $userId) {
$uid = mysqli_real_escape_string($con, $userId);
// Try standard query
$sql = "SELECT ua.*, up.*, gu.Login as LastLogin, gu.Logout as LastLogout, gu.Online as IsOnline
FROM UserAccounts ua
LEFT JOIN userprofile up ON ua.PrincipalID = up.useruuid
LEFT JOIN GridUser gu ON ua.PrincipalID = gu.UserID
WHERE ua.PrincipalID = '{$uid}'";
$result = mysqli_query($con, $sql);
// Fallback if gu.Online column doesn't exist
if (!$result) {
$sql = "SELECT ua.*, up.*, gu.Login as LastLogin, gu.Logout as LastLogout
FROM UserAccounts ua
LEFT JOIN userprofile up ON ua.PrincipalID = up.useruuid
LEFT JOIN GridUser gu ON ua.PrincipalID = gu.UserID
WHERE ua.PrincipalID = '{$uid}'";
$result = mysqli_query($con, $sql);
}
return $result;
}
function getUserByName($con, $firstName, $lastName) {
$sql = "SELECT PrincipalID FROM UserAccounts
WHERE FirstName = '" . mysqli_real_escape_string($con, $firstName) . "'
AND LastName = '" . mysqli_real_escape_string($con, $lastName) . "'";
$result = mysqli_query($con, $sql);
return $result ? mysqli_fetch_assoc($result) : null;
}
function getPartnerInfo($con, $partnerUuid) {
if (!$partnerUuid || $partnerUuid == '00000000-0000-0000-0000-000000000000') {
return null;
}
$sql = "SELECT FirstName, LastName FROM UserAccounts
WHERE PrincipalID = '" . mysqli_real_escape_string($con, $partnerUuid) . "'";
$result = mysqli_query($con, $sql);
return $result ? mysqli_fetch_assoc($result) : null;
}
function getUserPicks($con, $userId, $limit = 6) {
$sql = "SELECT * FROM userpicks
WHERE creatoruuid = '" . mysqli_real_escape_string($con, $userId) . "'
AND enabled = 1
ORDER BY toppick DESC, name ASC
LIMIT " . intval($limit);
return mysqli_query($con, $sql);
}
function getUserClassifieds($con, $userId, $limit = 6) {
$sql = "SELECT * FROM classifieds
WHERE creatoruuid = '" . mysqli_real_escape_string($con, $userId) . "'
ORDER BY creationdate DESC
LIMIT " . intval($limit);
return mysqli_query($con, $sql);
}
function getFriendCount($con, $userId) {
$uid = mysqli_real_escape_string($con, $userId);
$sql = "SELECT COUNT(DISTINCT CASE
WHEN PrincipalID = '{$uid}' THEN Friend
ELSE PrincipalID
END) AS cnt
FROM Friends
WHERE (PrincipalID = '{$uid}' OR Friend = '{$uid}')
AND PrincipalID <> Friend
AND PrincipalID <> '00000000-0000-0000-0000-000000000000'
AND Friend <> '00000000-0000-0000-0000-000000000000'";
$result = mysqli_query($con, $sql);
if (!$result) return 0;
$row = mysqli_fetch_assoc($result);
return $row ? (int)$row['cnt'] : 0;
}
function getUserGroups($con, $userId) {
$sql = "SELECT ogm.GroupID, og.Name as GroupName, og.Charter, ogm.Contribution,
ogm.ListInProfile, ogr.Powers, ogr.Title
FROM os_groups_membership ogm
LEFT JOIN os_groups_groups og ON ogm.GroupID = og.GroupID
LEFT JOIN os_groups_rolemembership ogrm ON ogm.PrincipalID = ogrm.PrincipalID AND ogm.GroupID = ogrm.GroupID
LEFT JOIN os_groups_roles ogr ON ogrm.RoleID = ogr.RoleID AND ogrm.GroupID = ogr.GroupID
WHERE ogm.PrincipalID = '" . mysqli_real_escape_string($con, $userId) . "'
AND ogm.ListInProfile = 1
ORDER BY og.Name";
return mysqli_query($con, $sql);
}
// Handle parameters
$action = isset($_GET['action']) ? $_GET['action'] : 'search';
$userId = isset($_GET['user']) ? $_GET['user'] : '';
$firstName = isset($_GET['firstname']) ? trim($_GET['firstname']) : '';
$lastName = isset($_GET['lastname']) ? trim($_GET['lastname']) : '';
// Look up user by name
if ($firstName && $lastName && !$userId) {
$userResult = getUserByName($con, $firstName, $lastName);
if ($userResult) {
$userId = $userResult['PrincipalID'];
}
}
?>
<section class="page-hero">
<h1><i class="bi bi-person-badge me-2"></i> User Profiles</h1>
<p class="mb-0">Search for a resident by name, or view a profile directly.</p>
</section>
<div class="container-fluid mt-4 mb-4">
<div class="row g-3">
<div class="col-md-3">
<div class="card">
<div class="card-header">
<h5 class="mb-0"><i class="bi bi-search"></i> Search users</h5>
</div>
<div class="card-body">
<form method="GET" action="profile.php">
<div class="mb-3">
<label for="firstname" class="form-label">First name:</label>
<input type="text" class="form-control" id="firstname" name="firstname"
value="<?php echo htmlspecialchars($firstName); ?>"
placeholder="Enter first name">
</div>
<div class="mb-3">
<label for="lastname" class="form-label">Last name:</label>
<input type="text" class="form-control" id="lastname" name="lastname"
value="<?php echo htmlspecialchars($lastName); ?>"
placeholder="Enter last name">
</div>
<button type="submit" class="btn btn-primary w-100">
<i class="bi bi-search"></i> Find profile
</button>
</form>
</div>
</div>
<div class="card mt-3">
<div class="card-header">
<h5 class="mb-0"><i class="bi bi-clock-history"></i> Popular profiles</h5>
</div>
<div class="card-body">
<?php
$popularUsers = mysqli_query($con, "
SELECT ua.PrincipalID, ua.FirstName, ua.LastName,
COUNT(up.useruuid) as profile_completeness
FROM UserAccounts ua
LEFT JOIN userprofile up ON ua.PrincipalID = up.useruuid
WHERE up.useruuid IS NOT NULL
GROUP BY ua.PrincipalID
ORDER BY profile_completeness DESC, ua.FirstName ASC
LIMIT 5
");
?>
<div class="list-group list-group-flush">
<?php while ($user = mysqli_fetch_assoc($popularUsers)): ?>
<a href="profile.php?user=<?php echo $user['PrincipalID']; ?>"
class="list-group-item list-group-item-action">
<i class="bi bi-person"></i>
<?php echo htmlspecialchars($user['FirstName'] . ' ' . $user['LastName']); ?>
</a>
<?php endwhile; ?>
</div>
</div>
</div>
<div class="card mt-3">
<div class="card-header">
<h5 class="mb-0"><i class="bi bi-bar-chart"></i> Grid statistics</h5>
</div>
<div class="card-body">
<?php
$totalUsers = mysqli_fetch_row(mysqli_query($con, "SELECT COUNT(*) FROM UserAccounts"))[0];
$profilesWithPics = mysqli_fetch_row(mysqli_query($con, "SELECT COUNT(*) FROM userprofile WHERE profileImage != '00000000-0000-0000-0000-000000000000'"))[0];
$partneredUsers = mysqli_fetch_row(mysqli_query($con, "SELECT COUNT(*) FROM userprofile WHERE profilePartner != '00000000-0000-0000-0000-000000000000'"))[0];
$activeToday = mysqli_fetch_row(mysqli_query($con, "SELECT COUNT(*) FROM GridUser WHERE Login > (UNIX_TIMESTAMP() - 86400)"))[0];
?>
<div class="text-center">
<div class="mb-2">
<h5 class="text-primary"><?php echo number_format($totalUsers, 0, ',', '.'); ?></h5>
<small class="text-muted">Total users</small>
</div>
<div class="mb-2">
<h5 class="text-success"><?php echo number_format($profilesWithPics, 0, ',', '.'); ?></h5>
<small class="text-muted">Profiles with pictures</small>
</div>
<div class="mb-2">
<h5 class="text-warning"><?php echo number_format($partneredUsers, 0, ',', '.'); ?></h5>
<small class="text-muted">Partnerships</small>
</div>
<div>
<h5 class="text-info"><?php echo number_format($activeToday, 0, ',', '.'); ?></h5>
<small class="text-muted">Active today</small>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-9">
<?php if ($userId): ?>
<?php
$result = getUserProfile($con, $userId);
$profile = mysqli_fetch_assoc($result);
if ($profile):
$partner = getPartnerInfo($con, $profile['profilePartner']);
$friendCount = getFriendCount($con, $userId);
?>
<div class="card">
<div class="card-header bg-primary text-white">
<div class="row align-items-center">
<div class="col">
<h4 class="mb-0">
<i class="bi bi-person"></i>
<?php echo htmlspecialchars($profile['FirstName'] . ' ' . $profile['LastName']); ?>
</h4>
<?php
// Determine Status using Helper
$lastLogin = !empty($profile['LastLogin']) ? (int)$profile['LastLogin'] : 0;
$status = get_user_status_and_region($con, $profile['PrincipalID'], $lastLogin);
?>
<?php if ($status['online']): ?>
<div class="mt-1">
<span class="badge bg-success">
Online <?php echo !empty($status['region']) ? '@ ' . htmlspecialchars($status['region']) : ''; ?>
</span>
</div>
<?php elseif ($lastLogin > (time() - 86400) && $lastLogin > 0): ?>
<div class="mt-1">
<span class="badge bg-warning text-dark">Active today</span>
</div>
<?php endif; ?>
<?php if ($lastLogin > 0): ?>
<small class="d-block mt-1">
Last login: <?php echo date('d.m.Y H:i', $lastLogin); ?>
</small>
<?php endif; ?>
</div>
<div class="col-auto">
<a href="profile.php" class="btn btn-light">
<i class="bi bi-search"></i> Search another user
</a>
</div>
</div>
</div>
</div>
<div class="card mt-3">
<div class="card-header p-2">
<ul class="nav nav-pills gap-2 mb-0 justify-content-center" id="profileTabs" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active rounded-pill" data-bs-toggle="tab" data-bs-target="#about"
type="button" role="tab" aria-controls="about" aria-selected="true">
<i class="bi bi-info-circle"></i> About me
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link rounded-pill" data-bs-toggle="tab" data-bs-target="#picks"
type="button" role="tab" aria-controls="picks" aria-selected="false">
<i class="bi bi-geo-alt"></i> Picks
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link rounded-pill" data-bs-toggle="tab" data-bs-target="#classifieds"
type="button" role="tab" aria-controls="classifieds" aria-selected="false">
<i class="bi bi-megaphone"></i> Classifieds
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link rounded-pill" data-bs-toggle="tab" data-bs-target="#groups"
type="button" role="tab" aria-controls="groups" aria-selected="false">
<i class="bi bi-people"></i> Groups
</button>
</li>
</ul>
</div>
<div class="card-body">
<div class="tab-content">
<div class="tab-pane fade show active" id="about">
<div class="row">
<div class="col-md-8">
<div class="mb-4">
<h5>About me:</h5>
<?php if ($profile['profileAboutText']): ?>
<p class="text-justify"><?php echo nl2br(htmlspecialchars($profile['profileAboutText'])); ?></p>
<?php else: ?>
<p class="text-muted fst-italic">No information available.</p>
<?php endif; ?>
</div>
<?php if ($profile['profileFirstText']): ?>
<div class="mb-4">
<h5>First Life:</h5>
<p class="text-justify"><?php echo nl2br(htmlspecialchars($profile['profileFirstText'])); ?></p>
</div>
<?php endif; ?>
<?php if ($partner): ?>
<div class="mb-4">
<h5>Partner:</h5>
<div class="alert alert-info">
<i class="bi bi-heart-fill text-danger"></i>
Partnership with
<a href="profile.php?user=<?php echo $profile['profilePartner']; ?>" class="alert-link">
<?php echo htmlspecialchars($partner['FirstName'] . ' ' . $partner['LastName']); ?>
</a>
</div>
</div>
<?php endif; ?>
<?php if ($profile['profileSkillsMask'] || $profile['profileSkillsText']): ?>
<div class="mb-4">
<h5>Skills & interests:</h5>
<?php if ($profile['profileSkillsText']): ?>
<p><?php echo nl2br(htmlspecialchars($profile['profileSkillsText'])); ?></p>
<?php endif; ?>
<?php if ($profile['profileSkillsMask']): ?>
<div class="d-flex flex-wrap gap-2">
<?php
$skills = ['Building', 'Texturing', 'Scripting', 'Clothing', 'Photography', 'Modeling'];
foreach ($skills as $index => $skill) {
if ($profile['profileSkillsMask'] & (1 << $index)) {
echo '<span class="badge bg-secondary">' . $skill . '</span>';
}
}
?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($profile['profileLanguages']): ?>
<div class="mb-4">
<h5>Languages:</h5>
<p><?php echo htmlspecialchars($profile['profileLanguages']); ?></p>
</div>
<?php endif; ?>
</div>
<div class="col-md-4">
<?php if ($profile['profileImage'] && $profile['profileImage'] != '00000000-0000-0000-0000-000000000000'): ?>
<div class="text-center mb-4">
<h6>Profile picture:</h6>
<img src="<?php echo GRID_ASSETS_SERVER . $profile['profileImage']; ?>"
class="img-fluid rounded"
alt="Profile picture"
style="max-height: 250px;"
onerror="this.onerror=null;this.src='<?php echo ASSET_FEHLT; ?>';">
</div>
<?php endif; ?>
<?php if ($profile['profileFirstImage'] && $profile['profileFirstImage'] != '00000000-0000-0000-0000-000000000000'): ?>
<div class="text-center mb-4">
<h6>First Life image:</h6>
<img src="<?php echo GRID_ASSETS_SERVER . $profile['profileFirstImage']; ?>"
class="img-fluid rounded"
alt="First Life image"
style="max-height: 200px;"
onerror="this.onerror=null;this.src='<?php echo ASSET_FEHLT; ?>';">
</div>
<?php endif; ?>
<div class="card bg-light">
<div class="card-body">
<h6 class="card-title">Profile stats</h6>
<ul class="list-unstyled mb-0">
<li><strong>Friends:</strong> <?php echo number_format($friendCount, 0, ',', '.'); ?></li>
<li><strong>Account created:</strong>
<?php echo $profile['Created'] ? date('d.m.Y', $profile['Created']) : 'Unknown'; ?>
</li>
<?php if ($profile['profileWantToMask']): ?>
<li><strong>Wants to:</strong>
<?php
$wantTo = [];
if ($profile['profileWantToMask'] & 1) $wantTo[] = 'Build';
if ($profile['profileWantToMask'] & 2) $wantTo[] = 'Explore';
if ($profile['profileWantToMask'] & 4) $wantTo[] = 'Meet friends';
if ($profile['profileWantToMask'] & 8) $wantTo[] = 'Hang out';
echo implode(', ', $wantTo);
?>
</li>
<?php endif; ?>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="picks">
<?php
$picksResult = getUserPicks($con, $userId);
$picksCount = mysqli_num_rows($picksResult);
?>
<div class="d-flex justify-content-between align-items-center mb-3">
<h5><?php echo $picksCount; ?> picks by this user</h5>
<a href="picks.php?user=<?php echo urlencode($userId); ?>" class="btn btn-primary">
<i class="bi bi-box-arrow-up-right"></i> View all picks
</a>
</div>
<?php if ($picksCount > 0): ?>
<div class="row">
<?php while ($pick = mysqli_fetch_assoc($picksResult)): ?>
<div class="col-md-6 col-lg-4 mb-3">
<div class="card h-100 <?php echo $pick['toppick'] ? 'border-warning' : ''; ?>">
<?php if ($pick['toppick']): ?>
<div class="card-header bg-warning text-dark text-center py-1">
<small><i class="bi bi-star-fill"></i> TOP PICK</small>
</div>
<?php endif; ?>
<?php if ($pick['snapshotuuid'] && $pick['snapshotuuid'] != '00000000-0000-0000-0000-000000000000'): ?>
<img src="<?php echo GRID_ASSETS_SERVER . $pick['snapshotuuid']; ?>"
class="card-img-top"
alt="Pick image"
style="height: 120px; object-fit: cover;"
onerror="this.onerror=null;this.src='<?php echo ASSET_FEHLT; ?>';">
<?php endif; ?>
<div class="card-body">
<h6 class="card-title"><?php echo htmlspecialchars($pick['name']); ?></h6>
<p class="card-text text-muted small">
<?php echo htmlspecialchars(substr($pick['description'], 0, 80) . (strlen($pick['description']) > 80 ? '...' : '')); ?>
</p>
<a href="picks.php?action=view&id=<?php echo $pick['pickuuid']; ?>" class="btn btn-sm btn-outline-primary">
Details
</a>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php else: ?>
<div class="text-center py-5">
<i class="bi bi-geo-alt fs-1 text-muted mb-3"></i>
<h6>No picks</h6>
<p class="text-muted">This user hasn't created any picks yet.</p>
</div>
<?php endif; ?>
</div>
<div class="tab-pane fade" id="classifieds">
<?php
$classifiedsResult = getUserClassifieds($con, $userId);
$classifiedsCount = mysqli_num_rows($classifiedsResult);
?>
<div class="d-flex justify-content-between align-items-center mb-3">
<h5><?php echo $classifiedsCount; ?> classifieds</h5>
<a href="classifieds.php?user=<?php echo urlencode($userId); ?>" class="btn btn-primary">
<i class="bi bi-box-arrow-up-right"></i> View all classifieds
</a>
</div>
<?php if ($classifiedsCount > 0): ?>
<div class="row">
<?php while ($classified = mysqli_fetch_assoc($classifiedsResult)): ?>
<div class="col-md-6 col-lg-4 mb-3">
<div class="card h-100">
<?php if ($classified['snapshotuuid'] && $classified['snapshotuuid'] != '00000000-0000-0000-0000-000000000000'): ?>
<img src="<?php echo GRID_ASSETS_SERVER . $classified['snapshotuuid']; ?>"
class="card-img-top"
alt="Classified image"
style="height: 120px; object-fit: cover;"
onerror="this.onerror=null;this.src='<?php echo ASSET_FEHLT; ?>';">
<?php endif; ?>
<div class="card-body">
<h6 class="card-title"><?php echo htmlspecialchars($classified['name']); ?></h6>
<p class="card-text text-muted small">
<?php echo htmlspecialchars(substr($classified['description'], 0, 80) . (strlen($classified['description']) > 80 ? '...' : '')); ?>
</p>
<div class="d-flex justify-content-between align-items-center">
<span class="badge bg-success">FC$ <?php echo number_format($classified['priceforlisting'], 0, ',', '.'); ?></span>
<a href="classifieds.php?action=view&id=<?php echo $classified['classifieduuid']; ?>" class="btn btn-sm btn-outline-primary">
Details
</a>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php else: ?>
<div class="text-center py-5">
<i class="bi bi-megaphone fs-1 text-muted mb-3"></i>
<h6>No classifieds</h6>
<p class="text-muted">This user hasn't created any classifieds yet.</p>
</div>
<?php endif; ?>
</div>
<div class="tab-pane fade" id="groups">
<?php
$groupsResult = getUserGroups($con, $userId);
$groupsCount = mysqli_num_rows($groupsResult);
?>
<div class="d-flex justify-content-between align-items-center mb-3">
<h5><?php echo $groupsCount; ?> group memberships</h5>
<a href="groups.php?user=<?php echo urlencode($userId); ?>" class="btn btn-primary">
<i class="bi bi-box-arrow-up-right"></i> View all groups
</a>
</div>
<?php if ($groupsCount > 0): ?>
<div class="row">
<?php while ($group = mysqli_fetch_assoc($groupsResult)): ?>
<div class="col-md-6 mb-3">
<div class="card">
<div class="card-body">
<h6 class="card-title"><?php echo htmlspecialchars($group['GroupName']); ?></h6>
<?php if ($group['Title']): ?>
<p class="text-primary mb-2"><strong><?php echo htmlspecialchars($group['Title']); ?></strong></p>
<?php endif; ?>
<?php if ($group['Charter']): ?>
<p class="card-text text-muted small">
<?php echo htmlspecialchars(substr($group['Charter'], 0, 100) . (strlen($group['Charter']) > 100 ? '...' : '')); ?>
</p>
<?php endif; ?>
<div class="d-flex justify-content-between align-items-center">
<?php if ($group['Contribution']): ?>
<span class="badge bg-info">FC$ <?php echo number_format($group['Contribution'], 0, ',', '.'); ?></span>
<?php endif; ?>
<a href="groups.php?action=view&id=<?php echo $group['GroupID']; ?>" class="btn btn-sm btn-outline-primary">
Details
</a>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php else: ?>
<div class="text-center py-5">
<i class="bi bi-people fs-1 text-muted mb-3"></i>
<h6>No group memberships</h6>
<p class="text-muted">This user isn't in any public groups.</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php else: ?>
<div class="alert alert-warning">
<i class="bi bi-exclamation-triangle"></i>
User not found or no profile available.
</div>
<?php endif; ?>
<?php else: ?>
<div class="card">
<div class="card-header">
<h4><i class="bi bi-search"></i> Browse user profiles</h4>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-8 mx-auto">
<p class="text-center text-muted mb-4">
Enter a user's name to view their profile.
</p>
<form method="GET" action="profile.php" class="mb-4">
<div class="row">
<div class="col-md-5">
<input type="text" class="form-control form-control-lg"
name="firstname"
placeholder="First name"
required>
</div>
<div class="col-md-5">
<input type="text" class="form-control form-control-lg"
name="lastname"
placeholder="Last name"
required>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-primary btn-lg w-100">
<i class="bi bi-search"></i>
</button>
</div>
</div>
</form>
<?php if ($firstName && $lastName && !$userId): ?>
<div class="alert alert-warning">
<i class="bi bi-exclamation-triangle"></i>
User "<?php echo htmlspecialchars($firstName . ' ' . $lastName); ?>" not found.
</div>
<?php endif; ?>
</div>
</div>
<hr class="my-4">
<h5 class="text-center mb-4">Recently active users with profiles</h5>
<div class="row">
<?php
$recentUsers = mysqli_query($con, "
SELECT ua.PrincipalID, ua.FirstName, ua.LastName,
up.profileAboutText, up.profileImage, gu.Login
FROM UserAccounts ua
LEFT JOIN userprofile up ON ua.PrincipalID = up.useruuid
LEFT JOIN GridUser gu ON ua.PrincipalID = gu.UserID
WHERE up.useruuid IS NOT NULL
AND (up.profileAboutText IS NOT NULL OR up.profileImage != '00000000-0000-0000-0000-000000000000')
ORDER BY gu.Login DESC
LIMIT 6
");
while ($user = mysqli_fetch_assoc($recentUsers)):
?>
<div class="col-md-6 col-lg-4 mb-3">
<div class="card">
<?php if ($user['profileImage'] && $user['profileImage'] != '00000000-0000-0000-0000-000000000000'): ?>
<img src="<?php echo GRID_ASSETS_SERVER . $user['profileImage']; ?>"
class="card-img-top"
alt="Profile picture"
style="height: 150px; object-fit: cover;"
onerror="this.onerror=null;this.src='<?php echo ASSET_FEHLT; ?>';">
<?php endif; ?>
<div class="card-body">
<h6 class="card-title"><?php echo htmlspecialchars($user['FirstName'] . ' ' . $user['LastName']); ?></h6>
<p class="card-text text-muted small">
<?php
if ($user['profileAboutText']) {
echo htmlspecialchars(substr($user['profileAboutText'], 0, 80) . (strlen($user['profileAboutText']) > 80 ? '...' : ''));
} else {
echo "Full profile available";
}
?>
</p>
<a href="profile.php?user=<?php echo $user['PrincipalID']; ?>" class="btn btn-primary btn-sm w-100">
<i class="bi bi-eye"></i> View profile
</a>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
<style>
/* Image Hover Effects */
.card-img-top {
transition: transform 0.2s;
}
.card:hover .card-img-top {
transform: scale(1.02);
}
/* Text Formatting */
.text-justify {
text-align: justify;
}
</style>
<script>
// Tab hash navigation
if (window.location.hash) {
let hash = window.location.hash;
// Look for BUTTONS with this data-bs-target
let tabTrigger = document.querySelector(`button[data-bs-target="${hash}"]`);
if (tabTrigger) {
let tab = new bootstrap.Tab(tabTrigger);
tab.show();
}
}
// Add hash to URL on tab change
document.querySelectorAll('button[data-bs-toggle="tab"]').forEach(function(tabEl) {
tabEl.addEventListener('shown.bs.tab', function(event) {
// Get target from data attribute
let hash = event.target.getAttribute('data-bs-target');
if (history.pushState) {
history.pushState(null, null, hash);
} else {
location.hash = hash;
}
});
});
</script>
<?php
mysqli_close($con);
if (defined('FOOTER_FILE')) {
include_once "include/" . FOOTER_FILE;
} else {
include_once "include/footer.php";
}
?>