This repository was archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStats.php
More file actions
170 lines (165 loc) · 6.5 KB
/
Stats.php
File metadata and controls
170 lines (165 loc) · 6.5 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
<!--Joy Taylor Aug 9th Base for creating sites updated -->
<?php
?>
<!DOCTYPE html>
<html id = "classPage">
<head>
<!--Samuel Anozie, July 29, 2017. This is the Stats page. -->
<title>Stats - SchoolBoard</title>
<meta charset = "UTF-8"/>
<link rel = "stylesheet" type = "text/css" href = "styles.css"/>
<link rel = "icon" href = "favicon.jpg" type = "image/jpg"/>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
html {
height: 100%;
}
body {
text-align: center;
height: 100%;
background-image: url('backpic.jpg');
background-size: cover;
overflow: auto;
margin: auto;
}
</style>
</head>
<body>
<div class = "img" id = "Stats">
<a href = "index.html">
<img src = "Picture1.png" id = "Stats"/>
</a>
</div>
<div class = "classname" id = "Stats">
<div class = "heading">
<h1> Stats </h1>
</div>
<div class = "statement">
<p>Q u e s t i o n s</p>
</div>
</div>
<div class = "outerContainer">
<div class = "innerContainter">
<?php
include("config.php");
include("cookiecheck.php");
mysqli_select_db($conn, 'SchoolBoard');
?>
<script>
function vote(div) {
var num = parseInt(document.getElementById("num_" + div).innerHTML);
document.getElementById("num_" + div).innerHTML = num + 1;
console.log("num_" + div)
num += 1;
/*for (var i = (div-1); i > 0; i--) {
var compare = parseInt(document.getElementById("num_" + i).innerHTML);
if (num > compare) {
var higher = document.getElementById("div_" + div);
var lower = document.getElementById("div_" + i);
document.getElementById("div_" + div).innerHTML = lower.innerHTML;
document.getElementById("div_" + i).innerHTML = higher.innerHTML;
}
}*/
}
function disable(input) {
var vote = document.getElementById(input);
vote.disabled = true;
vote.style.opacity = 0.2;
}
function visible(form, button) {
var div = document.getElementById(form).style;
var clicked = document.getElementById(button);
if (button == 'answerButton') {
div.display = 'block';
}
else {
div.display = 'none';
}
}
function removeElement(elementId) {
// Removes an element from the document
var element = document.getElementById(elementId);
element.parentNode.removeChild(element);
}
</script>
<!--in the event that a question has to be deleted from the database, all of the question Id's will be thrown off. Proceed with caution-->
<?php
$teach = false;
$sql = "SELECT status FROM users WHERE username = '".$_COOKIE["user"] ."'";
$result = mysqli_query($conn, $sql);
$row = $result->fetch_assoc();
if( $row["status"] == "teacher"){
$teach= true;
}
echo "<div class = 'time'><h3>This Week</h3><div class = 'strip'></div></div>";
static $num = 1;
$sql= "SELECT * FROM question WHERE subject = 'stats'";
$result = mysqli_query($conn, $sql);
$numrows = mysqli_num_rows($result);
for ($i = 1; $i <= $numrows; $i++) {
$sql= "SELECT * FROM question WHERE subject = 'stats' AND questionid = $i ORDER BY dateOfAsk DESC";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($result)) {
echo "<span id = 'div_$num'>
<div id = 'question'>";
//make sure that teachers are not able to vote on questions, or I guess they could?
if($teach == true){
echo "
<button class = 'answerButton' id = 'answerButton' onclick = visible('answerForm_$num','answerButton')>ANSWER</button>
";
}
echo "<div id = 'text'>
<h6> ". $row['question']. "</h6>
</div>
<div class = 'vote'>
<div class = 'votecontainer'>
<form id = 'voteform' method='POST' action='votes.php'>
<span class = 'num' id = 'num_$num'>" . $row['votes'] . "</span>
<input type= 'hidden' name='question' value=". $row['questionid']."><br>
<input class = 'vote' id = 'vote_$num' type = 'submit' name = 'submit' value = 'VOTE' >
</form>
</div>
</div>
</div>";
if ($teach == true) {
echo "
<form class = 'answerForm' id = 'answerForm_$num' action='teacherprocess.php' method = 'POST'>
<input type = 'hidden' name='question' value='".$row['question']."'>
<input type='hidden' name='subject' value='stats'>
<textarea name='teacher' placeholder = 'Type your answer here'></textarea><br>
<input type = 'submit' name = 'submit' value = 'SUBMIT' id='submit'><br>
<button id = 'closeButton' onclick = visible('answerForm_$num', 'closeButton')>CLOSE FORM</button>
</form>";
}
echo "</span>";
if ($row['teacherResponce'] != NULL){
echo "<div id = 'answer'><div id = 'text'><h6> ". $row['teacherResponce']."</h6></div></div>";
}
echo "<script>";
$sql = "SELECT `studentHasVoted` FROM `studentVotes` WHERE `questionid` = $i AND `studentid` = ".
"'".$_COOKIE['user_id']."'";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
if ($row['studentHasVoted'] == 1) {
echo "disable('vote_$num');";
}
}
echo "</script>";
$num++;
}
}
?>
<div id = "ask" class = "ask"><a href = "StatsQuestionPage.html"><h3>ASK A QUESTION</h3></a></div>
<h4><a class = "backLink" href = "SchoolBoardAccountPage.php">GO BACK TO ACCOUNT</a></h4>
<?php
if ($teach == true) {
echo "<script>removeElement('ask')</script>";
}
?>
</div>
</div>
</body>
</html>