-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.php
225 lines (187 loc) · 8.78 KB
/
home.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
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
<?php
require_once 'header.php';
$prof = $TA = FALSE;
/** Get the userid of whoever is logged in **/
$error = $text = $title = $saveto = "";
$query1 = queryMysql("SELECT * FROM user WHERE netid='$netid'"); //Getting userid of logged on user
$row = mysqli_fetch_array($query1);
$user = $row['userid'];
/** Figure out if logged in user is a student, professor, TA **/
if($row['isProfessor']!=NULL)
$prof = TRUE;
else if($row['isTA']!=NULL)
$TA = TRUE;
if (!$loggedin) die();
if (isset($_GET['view']))
$view = sanitizeString($_GET['view']);
else
$view = $netid;
/** MAIN PART **/
if (isset($_POST['like']))
{
$like = $_POST['liked'];
queryMysql("UPDATE post SET likes=likes+1 WHERE artid=$like");
}
if(!$prof) /** If it is a student or a TA **/
{
$query = "SELECT * FROM class, roster WHERE class.courseid = roster.courseid AND roster.studentid = '$user'";
$result = queryMysql($query);
/** Posting list of courses**/
if($result)
{
echo "<div id='sidebar'>".
"<div id='right-border'></div>".
"<a href='post.php' id='post-button'>POST ARTWORK</a>" .
"<div id='classes'".
"<p class='small-title list-1'>COURSES</p>" .
"<form id='form' method='post'>";
while($row = mysqli_fetch_array($result))
{
$coursename = $row['coursename'];
$courseid = $row['courseid'];
echo "<input id='$courseid' class='checkbox-toggle gray' type='checkbox' value='$courseid' checked>".
"<label for='$courseid' data-on='$coursename'></label><br><br>";
}
echo
"<script>" .
"function change(){" .
"document.getElementById('form').submit();" .
"}".
"</script>".
"</div>";
}
$query = "SELECT DISTINCT user.name, user.netid FROM class, roster, user WHERE class.courseid = roster.courseid AND roster.studentid = '$user' AND class.profid != user.userid AND user.userid != '$user'";
$result = queryMysql($query);
/** Posting list of students **/
if($result)
{
echo "<p class='small-title list-2'>PEERS</p><p>";
while($row = mysqli_fetch_array($result))
{
$peername = $row['name'];
$id = $row['netid'];
echo "<a href='profile.php?view=$id'>".$peername."</a><br>";
}
echo "</p></div>";
}
/** Posting all posts from courses **/
if($_POST['course'] == '')
{
$query = "SELECT DISTINCT * FROM picture, post, roster, class, user WHERE picture.timestamp = post.timestamp AND post.userid = user.userid AND post.courseid = roster.courseid AND class.courseid = roster.courseid AND roster.studentid = '$user' ORDER BY artid DESC";
$result = queryMysql($query);
$num = $result->num_rows;
}
else{
$query = "SELECT DISTINCT * FROM picture, post, roster, class, user WHERE picture.timestamp = post.timestamp AND post.userid = user.userid AND post.courseid = roster.courseid AND class.courseid = roster.courseid AND roster.courseid = '$courseid' ORDER BY artid DESC";
$result = queryMysql($query);
$num = $result->num_rows;
}
echo "<div style='position:absolute; margin-left: 270px;'>";
for ($j = 0 ; $j < $num ; ++$j)
{
$row = mysqli_fetch_array($result);
$like = $row['artid'];
$image = $row['image'];
$type = $row['imagetype'];
$imagename = $row['imagename'];
$query5= "SELECT COUNT(*) as comments FROM comment WHERE artid = '$like' ORDER BY artid DESC";
$result5 = queryMysql($query5);
$row5 = mysqli_fetch_array($result5);
echo "<div id='post'>" ;
echo "<p id='title'>".$row['coursename']."</p>";
echo '<div class="pic-container"><img src="data:$type;base64,' . base64_encode($image).'"/>';
echo "<br><a href='viewpost.php?view=".$row['artid']."'><b>".$row['title']."</b><br>By ".$row['name']."</a>".
"</div>".
"<div id='comments-likes'>".
"<div id='comment-section'>".
"<img id='comment-pic' src='paint.png' style='width:15px;'><p id='comment-count'>".$row5['comments']."</p></div>".
"<div id='like-section'>".
"<td><form action='home.php?view=$view' method='post'>".
"<input type='hidden' name='liked' value='$like'>".
"<input id='like-button' type='submit' name='like' value=''></form></td>".
"<p id='likes'>".$row['likes']."</p></div></div>".
"</div>" ;
}
echo "</div>";
}
else /** If it is the professor **/
{
$query1 = "SELECT * FROM class WHERE profid = '$user'";
$result1 = queryMysql($query1);
/** Printing list of courses **/
if($result1)
{
echo "<div id='sidebar'>".
"<div id='right-border'></div>".
"<a href='addclass.php' class='add-button' style='margin-bottom: -15px;'><b> + </b> COURSES</a><br><br><br>" .
"<a href='addstudents.php' class='add-button'><b> + </b>STUDENTS</a>" .
"<div id='classes'".
"<p class='small-title list-1'>COURSES</p>" .
"<form id='form' method='post'>";
while($row1 = mysqli_fetch_array($result1))
{
$coursename = $row1['coursename'];
$courseid = $row1['courseid'];
echo "<input id='$courseid' class='checkbox-toggle gray' type='checkbox' value='$courseid' checked>".
"<label for='$courseid' data-on='$coursename'></label><br><br>";
}
echo
"<script>" .
"function change(){" .
"document.getElementById('form').submit();" .
"}".
"</script>".
"</div>";
}
$query2 = "SELECT DISTINCT user.name, user.netid FROM class, roster, user WHERE class.courseid = roster.courseid AND class.profid = '$user' AND user.userid != '$user'";
$result2 = queryMysql($query2);
/** Printing list of students in all courses **/
if($result2)
{
echo "<h3>STUDENTS</h3>";
echo "<p>";
while($row2 = mysqli_fetch_array($result2))
{
$peername = $row2['name'];
$id = $row2['netid'];
echo "<a href='profile.php?view=$id'>".$peername."</a><br>";
}
echo "</p></div>";
}
$query = "SELECT * FROM picture, post, class, user WHERE picture.timestamp = post.timestamp AND post.userid = user.userid AND post.courseid = class.courseid AND class.profid = '$user' ORDER BY artid DESC";
$result = queryMysql($query);
$num = $result->num_rows;
/** Posting all posts from courses **/
date_default_timezone_set('America/New_York');
echo "<div style='position:absolute; margin-left: 270px;'>";
for ($j = 0 ; $j < $num ; ++$j)
{
$row = mysqli_fetch_array($result);
$like = $row['artid'];
$image = $row['image'];
$type = $row['imagetype'];
$imagename = $row['imagename'];
$query5= "SELECT COUNT(*) as comments FROM comment WHERE artid = '$like' ORDER BY artid DESC";
$result5 = queryMysql($query5);
$row5 = mysqli_fetch_array($result5);
echo "<div id='post'>" ;
echo "<p id='title'>".$row['coursename']."</p>";
echo '<div class="pic-container"><img src="data:$type;base64,' . base64_encode($image).'"/>';
echo "<br><a href='viewpost.php?view=".$row['artid']."'><b>".$row['title']."</b><br>By ".$row['name']."</a>".
"</div>".
"<div id='comments-likes'>".
"<div id='comment-section'>".
"<img id='comment-pic' src='paint.png' style='width:15px;'><p id='comment-count'>".$row5['comments']."</p></div>".
"<div id='like-section'>".
"<td><form action='home.php?view=$view' method='post'>".
"<input type='hidden' name='liked' value='$like'>".
"<input id='like-button' type='submit' name='like' value=''></form></td>".
"<p id='likes'>".$row['likes']."</p></div></div>".
"</div>" ;
}
echo "</div>";
}
?>
</div><br>
</body>
</html>