-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.php
More file actions
198 lines (176 loc) · 6.73 KB
/
comment.php
File metadata and controls
198 lines (176 loc) · 6.73 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
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
<?php
session_start();
$conn=mysqli_connect("sophia.cs.hku.hk", "agupta", "anmol17", "agupta") or die ("Error! ".mysqli_connect_error());
function Redirect($url, $dur) {
header("refresh:$dur; url=$url");
}
$html = "
<html>
<head>
<meta charset=\"utf-8\" />
<title>Comments Page</title>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
</head>
<body>
<div class='header-div'>
<input class='header-button header-left-button' onclick=\"location.href='buywelcome.php'\" type=\"button\" value=\"Buy a ticket\"/>
<div class='header-right-div'>
<input class='header-button' onclick=\"location.href='comment.php'\" type=\"button\" value=\"Movie Review\"/>
<input class='header-button' onclick=\"location.href='history.php'\" type=\"button\" value=\"Purchase History\"/>
<input class='header-button' onclick=\"location.href='logout.php'\" type=\"button\" value=\"Logout\"/>
</div>
</div>
</body>
<style>
.heading {
text-align: center;
}
.header-right-div {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: flex-end;
}
.header-div {
background-color: rgba(241, 241, 241, 1);
height: 75px;
display: flex;
flex-direction: row;
padding: 0px 1%;
align-items: center;
position: fixed;
width: 100%;
}
body {
margin: 0;
}
.header-button {
background: linear-gradient(0.45turn, red, orange);
width: 250px;
height: 90%;
font-size: 30px;
white-space: normal;
}
.login-buttons {
margin: 5px;
width: 100%;
height: 60px;
cursor: pointer;
font-size: 25px;
}
.login-buttons-div {
width: 70%;
display: flex;
flex-direction: row;
height: auto;
align-self: center;
}
.main-div {
display: flex;
flex-direction: column;
width: 800px;
margin: auto;
padding-top: 100px;
}
.film-select-div {
display: flex;
flex-direction: row;
justify-content: center;
margin : 10px;
align-items: center;
}
.comments-div {
width :800px;
display: flex;
align-items: center;
margin-left: auto;
margin-right: auto;
flex-direction: column;
}
@media only screen and (max-width: 1000px) {
.header-button {
width: 150px;
font-size: 25px;
}
}
@media only screen and (max-width: 600px) {
.header-div {
align-items: center;
justify-content: center;
flex-direction: column;
height: 150px;
}
.header-right-div {
justify-content: center;
}
.header-button {
font-size: 18px;
width: 33%;
}
.header-left-button {
width: 80%;
font-size: 30px;
}
.main-div {
padding-top: 175px;
}
}
</style>
</html>
";
if(isset($_SESSION['userId'])) {
print $html;
$query = 'select * from FilmTable';
$result = mysqli_query($conn, $query) or die ('Failed to query '.mysqli_error($conn));
print "<form method='post' name='comment-form' action='comment_submit.php'>";
print "<div class='main-div'>";
print "<div class='film-select-div'>";
print "<label style='font-size: 30px; margin: 0px 10px;'>Film Name: </label>";
print "<select style='width: 400px; height: 50px; font-size: 25px;' id='comment-film' name='comment-film'>";
while($row = mysqli_fetch_array($result)) {
print '<option value="'.$row['filmId'].'">'.$row['filmName'].'</option>';
}
print "</select>";
print "</div>";
print "<textarea style='font-size: 20px; padding : 10px;' id='comment' rows='20' cols='80' name='comment-message' placeholder='Please input comment here'></textarea>";
print "<div class='login-buttons-div'>";
print "<input style='color: white; background-color: rgba(255, 102, 110, 1)' class='login-buttons' type='button' value='View comment' onclick='getComments()' />";
print "<input style='background-color: rgba(221,221,221, 1)' class='login-buttons' type='submit' value='Submit comment' onclick='validateMessage(event)' />";
print "</div>";
print "</div>";
print "<div class='comments-div' id='comments'>";
print "</div>";
print "</form>";
}
else {
print "<h1>You have not logged in!</h1>";
Redirect("index.html", 3);
}
?>
<script>
function validateMessage(e) {
var message = document.getElementById('comment').value;
if(message.length === 0) {
alert('Enter a comment before submitting!');
e.preventDefault();
}
}
function getComments() {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var mesgs = document.getElementById("comments");
mesgs.innerHTML = xmlhttp.responseText;
}
};
var selectedFilm = document.getElementById('comment-film').value;
xmlhttp.open("GET", "comment_retrieve.php?filmId=" + selectedFilm.toString(), true);
xmlhttp.send();
}
</script>