-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.php
More file actions
138 lines (117 loc) · 5.46 KB
/
profile.php
File metadata and controls
138 lines (117 loc) · 5.46 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
<?php
require "realconfig.php";
session_start();
$dbh = new PDO(DB_DSN, DB_USER, DB_PASSWORD);
if (!isset(($_GET['id']))) {
http_response_code(404);
echo "Error 404: Page not found";
exit();
}
//Checking valid get
try {
$usersTableCheck = $dbh->prepare("SELECT `id` from `bi_users`");
$usersTableCheck->execute();
$usersCheck = $usersTableCheck->fetchAll();
$check = false;
foreach ($usersCheck as $id) {
if ($id['id'] == $_GET['id']) {
$check = true;
}
}
if ($check == false) {
http_response_code(404);
echo "<h1 style='text-align: center;'>Error 404: Page not found</h1>";
echo "<h1 style='text-align: center;'>This Profile does not exist or it was deleted by a moderator</h1>";
exit();
}
} catch (PDOException $e) {
echo "<p>Error: {$e->getMessage()}</p>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Profile</title>
<link rel="stylesheet" href="style.css">
<link rel="icon" type="image/x-icon" href="images/reddit-logo.ico">
</head>
<body>
<div class="container">
<?php
require_once "header.php";
?>
<!-- Profile Display -->
<div class="posts-container">
<div class="post-div">
<?php
try {
$userTable = $dbh->prepare("SELECT `creation_time`, `username`, `is_admin`, `last_login_time`, `id` FROM `bi_users` WHERE :id = `id`;");
$userTable->bindValue(":id", $_GET['id']);
$userTable->execute();
$user = $userTable->fetch();
echo "<h1>" . htmlspecialchars($user["username"]) . "</h1>";
if (isset($_SESSION['user'])) {
if ($user['id'] == $_SESSION['user']) {
echo "<h2><a href=deleteuser.php?id=self class='red'>Delete Account</a></h2>";
}
}
if ($user["is_admin"] == 0) {
echo "<p>Bro is not an admin</p>";
} else {
echo "<p>Bro is a admin</p>";
}
$datetime = strtotime($user["creation_time"]);
$formatted_date = date('m/d/Y h:i:s A', $datetime);
echo "<p>Bro made his account on " . $formatted_date;
$datetime = strtotime($user["last_login_time"]);
$formatted_date = date('m/d/Y h:i:s A', $datetime);
echo "<p>Bro last logged in on " . $formatted_date;
$interactionsTable = $dbh->prepare("SELECT bi_interactions.interaction_type, bi_interactions.user_id, bi_interactions.post_id FROM `bi_interactions` JOIN `bi_posts` ON bi_posts.author_id = :userId AND bi_posts.id = bi_interactions.post_id;");
$interactionsTable->bindValue("userId", $user['id']);
$interactionsTable->execute();
$interactions = $interactionsTable->fetchAll();
$upvotes = 0;
$downvotes = 0;
foreach ($interactions as $interaction) {
if ($interaction['interaction_type'] == 2) {
$downvotes += 1;
} else if ($interaction['interaction_type'] == 1) {
$upvotes += 1;
}
}
echo "<h2>Bro has garnered " . $upvotes . " upvotes on his posts and comments</h2>";
echo "<h2>Bro has garnered " . $downvotes . " downvotes on his posts and comments</h2>";
$sublewitTable = $dbh->prepare("SELECT * FROM `bi_communities` WHERE :userId = user_id;");
$sublewitTable->bindValue(":userId", $user['id']);
$sublewitTable->execute();
$sublewits = $sublewitTable->fetchAll();
foreach ($sublewits as $sublewit) {
echo "<p>Bro is the founder of the <a href='sublewit.php?id=" . $sublewit['id'] . "'>" . htmlspecialchars($sublewit['name']) . " sublewit</a></p>";
}
$userPostTable = $dbh->prepare("SELECT * FROM `bi_posts` WHERE :userId = `author_id`");
$userPostTable->bindValue(":userId", $_GET['id']);
$userPostTable->execute();
$userPosts = $userPostTable->fetchAll();
if (!empty($userPosts)) {
echo "<h2>Bro's posts</h2>";
}
foreach ($userPosts as $userPost) {
$datetime = strtotime($userPost['creation_time']);
$formatted_date = date('m/d/Y h:i:s A', $datetime);
if ($userPost['reply_id'] == NULL) {
echo "<p><a href = 'post.php?id=" . $userPost['id'] . "'>Post created on " . $formatted_date . "</a></p>";
} else {
echo "<p><a href = 'post.php?id=" . $userPost['id'] . "'>Comment created on " . $formatted_date . "</a></p>";
}
}
} catch (PDOException $e) {
echo "<p>Error: {$e->getMessage()}</p>";
}
?>
</div>
</div>
</div>
</body>
</html>