-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.php
98 lines (86 loc) · 2.99 KB
/
main.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
<?php
session_set_cookie_params(30 * 60, "/; samesite=Strict", $_SERVER['HTTP_HOST'], 1, 0);
session_start();
if (!isset($_SESSION["user"])){
header("location:login.php");
exit();
}
?>
<!DOCTYPE html>
<!--
Project Name: Cougar Rescue Forum
Course: CIS444
Description: This file is the html/php for the main/home page.
The file contains the layout for the student's home page,
which consists of their course forums and subforum overviews.
This page is filled dynamically with the corresponding javascript
file.
-->
<html lang="en">
<head>
<title>Cougar Rescue Forum</title>
<meta charset="utf-8"/>
<script src='https://kit.fontawesome.com/a076d05399.js' crossorigin="anonymous"></script>
<link rel="icon" href="images/cr_logo.png" type="image/x-icon" />
<script type="text/javascript" src="nav.js"></script>
<script type="text/javascript" src="main.js"></script>
<link rel="stylesheet" href="cougar_rescue.css"/>
</head>
<body id="admin" class="pagestyle" onload="writeTable();">
<div id="navlist" class="navlist">
<div>
<img class = "logo" src="images/cr_logo_plain.png" alt="Cougar Rescue Forum Logo"/>
</div>
<form id="logoutForm" method="post" action="logout.php">
<input name="logout" aria-label="logout" type="submit" class="logoutNav" value="Logout"/>
</form>
<a href="search.php">Search</a>
<a href="view_profile.php">Profile</a>
<a href="main.php">Home</a>
</div>
<div class="forum-div" id="forum-div">
<h1> Welcome to the Cougar Rescue Forum!</h1>
</div>
<?php
$db = mysqli_connect("db", "root", "test", "myDb");
//$db = mysqli_connect("db", "root", "test", "myDB");
//$db = mysqli_connect("db", "group3", "g5tw9ShSexHH", "group3");
if (mysqli_connect_errno()) {
print "Connect failed: " . mysqli_connect_error();
exit();
}
//Create query
$email = $_SESSION["user"];
$query = "SELECT s.crsNumber, s.subType,
(SELECT COUNT(DISTINCT p.postID) FROM Posts p
WHERE s.subType = p.subType
AND s.crsNumber = p.crsNumber)
as 'Posts',
MAX(p.postDate) as 'Date'
FROM Subforums s, Posts p, Replies r, Users u, User_Courses c
WHERE r.postID = p.postID AND u.email='". $email ."'
AND u.email = c.email
AND s.crsNumber = c.crsNumber
GROUP BY s.crsNumber, s.subType;";
//print $query;
//Execute query
$result = mysqli_query($db, $query);
if (!$result) {
print '<script type="text/javascript"> alert("Error: the query could not be executed."' . mysqli_error() . ');</script>';
exit();
}
// Encode query results to send to JS
// Get the number of rows in the result
//$num_rows = mysqli_num_rows($result);
//$num_fields = mysqli_num_fields($result);
$rows = array();
while($r = mysqli_fetch_assoc($result)) {
$values = array_values($r);
$rows[] = $values;
}
//print(json_encode($rows));
print "<script type='text/javascript'>writeTable(" . json_encode($rows) . ");</script>";
mysqli_close($db);
?>
</body>
</html>