-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
172 lines (160 loc) · 5.69 KB
/
index.php
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
<?php
//start session
session_start();
include_once("config.php");
include_once("include.php");
// if user not logged in, redirect to homepage
checkUserSession();
$uid = $_SESSION['login_user'];
//create json variable
$sResp = array();
// Open database connection
$conn = mysqli_connect(DB_HOST_NAME, DB_USER, DB_PASS, DB_NAME);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$query = "SELECT COUNT(postId) as 'count'
FROM Posts
WHERE isHidden = false;";
$result = mysqli_query($conn, $query);
$totalPages = 0;
if ($r = mysqli_fetch_assoc($result)){
$totalPages = ceil($r["count"]/POSTS_PER_PAGE);
}
$postsPerPage = POSTS_PER_PAGE;
$pageBegin = 0;
if (isset($_GET["page"])) {
$pageNum = $_GET["page"];
if ($pageNum == 0) {
$pageNum = 1;
} else if ($pageNum > $totalPages) {
$pageNum = $totalPages;
}
$pageBegin = ($pageNum-1) * POSTS_PER_PAGE;
} else {
$pageNum = 1;
}
$query = "SELECT p.*,
(SELECT COUNT(commentID)
FROM Comments c
WHERE parentPostId = postId) AS 'numOfComments',
(SELECT 1 FROM ReportedPosts
WHERE ReportedPosts.userId = '$uid' AND p.postId = ReportedPosts.postId) AS 'userReported'
FROM Posts p
WHERE isHidden = false
ORDER BY timestamp DESC
LIMIT $pageBegin, $postsPerPage;";
// perform database query
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) == 0) {
echo mysqli_error($db);
}
echo mysqli_error($conn);
mysqli_close($conn);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css"></link>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <!-- This is the link for bootstrap !-->
<!--<script type = "text/javascript" src = "java1.js" ></script>-->
<script type = "text/javascript" src = "scripts/report.js" ></script>
<script type = "text/javascript" src = "scripts/delete.js" ></script>
<title>Public Wall</title>
</head>
<body class="allPages">
<div class="container-fluid"> <!-- This is the container div for the page; it is flued so it spands the viewport !-->
<div class="row"> <!-- Header row !-->
<div class="col-xs-12">
<div class="header">
<h1>
<a href="<?=SIDEBAR_VIEW_POSTS?>" class="homeLink">
<img src="logo.png" class="placeHolder" alt="img"></img> <?php echo WEBSITE_NAME; ?>
</a>
</h1>
</div>
</div>
</div>
<div class="row">
<div class="row row-eq-height contentRow"> <!-- Content row!-->
<div class="col-xs-2 sideBarCol"> <!--Sidebar column !-->
<div class="sideBar">
<br/>
<p class="blankButton">View Posts</p>
<a class="buttons" href="<?php echo SIDEBAR_CREATE_POSTS; ?>">Create Post</a>
<a class="buttons" href="<?php echo SIDEBAR_VIEW_NOTES; ?>">View Notes</a>
<a class="buttons" href="<?php echo SIDEBAR_CREATE_NOTES; ?>">Create Notes</a>
<?php if (isAdmin($uid)) { ?><a class="buttons" href="<?php echo SIDEBAR_ADMIN; ?>">Admin</a><?php } ?>
<a class="buttons" href="<?php echo SIDEBAR_LOGOUT; ?>">Logout</a>
<br></br>
</div>
</div>
<div class="col-xs-10"> <!-- content column !-->
<div class="largeSec">
<div id="wallArea">
<?php while($row = mysqli_fetch_assoc($result)) {
$userReportedPost = $row["userReported"];
$reportButtonClass = $userReportedPost ? "reportButtonPressed" : "reportButton";
$reportButtonText = $userReportedPost ? "Post Reported" : "Report Post";
$postContent = htmlspecialchars($row['text']);
$image = false;
if (!is_null($row["uploadedFile"])) {
$image = true;
$postFile = USER_IMAGE_UPLOAD_DIRECTORY . $row["uploadedFile"];
}
$postId = $row["postId"];
$postTimestamp = $row["timestamp"];
$postNumComments = $row["numOfComments"];
?>
<div class="wallPost" id="post<?=$pid?>">
<div>
<?php if ($image) { ?>
<img src="<?php echo $postFile; ?>" class="wallImg" alt="img">
<?php } ?>
</div>
<p class="wallText"><?php echo $postContent; ?></p>
<p class="p3">
Posted Anonymously at <?php echo $postTimestamp; ?> -
<a href="comment.php?a=<?php echo $postId;?>">
<span id="commentCounter<?php echo $postId;?>">
<?php echo $postNumComments;
if ($postNumComments != 1) { ?>
Comments
<?php } else { ?>
Comment
<?php } ?>
</span>
</a>
</p>
<button id="report_<?php echo $postId;?>" class="<?php echo $reportButtonClass;?>"><?php echo $reportButtonText;?></button>
<?php if ($_SESSION['isAdmin'] || $uid == $row["creatorId"]) { ?>
<button id="delete_<?php echo $postId;?>" class="deleteButton">Delete</button>
<?php } ?>
</div>
<?php } ?>
</div>
<div id="linksArea" class="pageSelect">
<?php if ($pageNum > 1) { ?>
<a href="<?=SIDEBAR_VIEW_POSTS?>?page=<?=$pageNum-1?>"><button id="lastPage"><<</button></a>
<?php } ?>
<span id="pageIndicator"><?=$pageNum?></span>
<?php if ($pageNum < $totalPages) { ?>
<a href="<?=SIDEBAR_VIEW_POSTS?>?page=<?=$pageNum+1?>"><button id="nextPage">>></button></a>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="footer">
<p class="p2">UR Space Copyright © 2016 All Rights Reserved</p>
</div>
</div>
</div>
</div>
<script type = "text/javascript" src = "scripts/index1.js" ></script>
</body>
</html>