-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.php
More file actions
127 lines (101 loc) · 3.53 KB
/
Copy pathprofile.php
File metadata and controls
127 lines (101 loc) · 3.53 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
<?php
session_start();
require_once __DIR__ . '/db/db_connect.php';
require_once __DIR__ . '/db/queries.php';
$user_id = $_SESSION['user_id'] ?? null;
if (!$user_id) {
die("You must be logged in to view your profile.");
}
// Get user info
$stmt = $conn->prepare("SELECT * FROM users WHERE id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$user = $stmt->get_result()->fetch_assoc();
if (!$user) {
die("User not found.");
}
$stmt = $conn->prepare("SELECT COUNT(id) as total FROM games WHERE host_user_id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$games_hosted = $stmt->get_result()->fetch_assoc();
if (!$games_hosted) {
die("Games Hosted not found.");
}
$stmt = $conn->prepare("SELECT COUNT(game_id) as total FROM game_players WHERE user_id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$games_played = $stmt->get_result()->fetch_assoc();
if (!$games_played) {
die("Games Played not found.");
}
/* Votes made */
$stmt = $conn->prepare("SELECT COUNT(id) AS total FROM votes WHERE voter_id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$votes_made = $stmt->get_result()->fetch_assoc();
if (!$votes_made) {
die("Votes Made not found.");
}
$stmt = $conn->prepare("SELECT COUNT(id) AS total FROM votes WHERE vote_for_id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$votes_received = $stmt->get_result()->fetch_assoc();
if (!$votes_received) {
die("Votes Received not found.");
}
?>
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<meta content = "width=device-width, initial-scale=1, shrink-to-fit=no" name = "viewport">
<meta content = "ie=edge" http-equiv = "X-UA-Compatible">
<title>Profile | Most Likely To</title>
<link href = "./css/profile.css" rel = "stylesheet">
</head>
<body id = "game-body">
<nav>
<div id = "navbar-container"></div>
<div id = "game-nav" class = "container-fluid"></div>
</nav>
<main class = "game-container">
<h1>Welcome <?php echo htmlspecialchars($_SESSION['username']); ?>!</h1>
<h2>Profile</h2>
<p>Welcome to your profile page! Here you can track your stats and log out!</p>
<section class = "profile-stats">
<!--
Stats to do
- Total Votes gave
- Total Votes received
- Total Questions
- Total Games Hosted
- Total Games Played
- Favorite Nickname
- Last Login Time
- Account Creation Time
-->
<h3>Stats</h3>
<ul class = "stats-list">
<li>Total Votes Given: <strong><?= $votes_made['total'] ?></strong></li>
<li>Total Votes Received: <strong><?= $votes_received['total'] ?></strong></li>
<li>Total Games Hosted: <strong><?= $games_hosted['total'] ?></strong></li>
<li>Total Games Played: <strong><?= $games_played['total'] ?></strong></li>
</li>
<li>Last Login Time:
<strong class = "long-date"><?= date("F j, Y, g:i a", strtotime($user['last_login'])) ?></strong>
</li>
<li>Account Creation Time:
<strong class = "long-date"><?= date("F j, Y", strtotime($user['created_at'])) ?></strong>
</ul>
</section>
<section class = "profile-options">
<h3>Options</h3>
<ul>
<li><a href = "user/logout.php">Logout</a></li>
<!-- Maybe we can add question set deletion/modification here?-->
</ul>
</section>
</main>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script rel = "text/javascript" src = "scripts/includes.js"></script>
</body>