-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.php
155 lines (129 loc) · 4.05 KB
/
response.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
<?php
include("initial.php");
include("classes/User.php");
include("current_user.php");
if(isset($_POST['response'])){
$id = $_GET['id'];
//fetch form details of that id
$stmt = $currentUser->getCon()->prepare("SELECT * FROM form_list WHERE id=?");
$stmt->bind_param('i',$id);
$stmt->execute();
$result = $stmt->get_result();
if(mysqli_num_rows($result) == 1){
$row = $result->fetch_assoc();
//if user who's viewing responses is not the same as the creator
if($userLoggedIn != $row['username']){
die("Not Authorised to view Responses");
}
}
else{
die("terminate");
}
}
else{
die("Not authorised to view responses");
}
//displays responses of each question
function displayAnswers($link){
$output = '';
while($row = $link->fetch_assoc()){
$output .= '<div class="p-1 rounded">'.$row['answer'].'</div>';
}
$output .= '</div></li><hr>';
echo $output;
}
function displayFile($link){
$output = '<div class="row">';
while($row = $link->fetch_assoc()){
$output .= '<div class="row m-2"><a href="'.$row['answer'].'">'.$row['answer'].'</a></div>';
//<img src="'.$row['answer'].'" alt="image"> cannot display image because of browser block
}
$output .= '</div></li><hr>';
return $output;
}
//display title of form
function getTitle($id,$conn){
$query = "SELECT * FROM form_list WHERE id ='$id'";
$link = mysqli_query($conn,$query);
$row = $link->fetch_assoc();
return $row['form_title'];
}
//display form question
function displayQuestion($string){
$output = '<li class="p-lg-1"><div class="p-lg-2">'.$string.'</div><div class="d-flex flex-column">';
return $output;
}
?>
<!DOCTYPE html>
<html>
<head>
<title><?php if(isset($_POST['response'])){
$conn = $currentUser->getCon();
echo getTitle($id,$conn);
}
?>
:Responses</title>
<link href="https://fonts.googleapis.com/css?family=Rubik&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">
<link rel="stylesheet" type="text/css" href="assets/stylesheets/response.css">
</head>
<body>
<!-- navbar -->
<nav class="navbar navbar-expand navbar-light" id="navBar">
<a class="navbar-brand" href="index.php"><i style="color:white;" class="fas fa-arrow-left"></i></a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto align-items-center">
<li class="nav-item">
<a class="nav-link" style="color:white;" href="register.php">SIGN OUT</a>
</li>
</ul>
</div>
</nav>
<!-- Response list -->
<div class="container justify-content-center border rounded p-lg-3 p-sm-1 mx-auto mt-4">
<div class="card border-0">
<div class="card-body">
<h2><?php
if(isset($_POST['response'])){
$conn = $currentUser->getCon();
echo getTitle($id,$conn);
} ?>
</h2>
<hr>
</div>
</div>
<ol class="list rounded p-lg-4 p-sm-1">
<?php
if(isset($_POST['response'])){
//get questions from db
$stmt = $currentUser->getCon()->prepare("SELECT * FROM form_questions WHERE form_id= ? ORDER BY id");
$stmt->bind_param('i',$id);
$stmt->execute();
$getQuestion = $stmt->get_result();
//display answers for each question
while($row = $getQuestion->fetch_assoc()){
$question = $row['question'];
echo displayQuestion($question);
$question_id = $row['id'];
//get answers from db
$stmt = $currentUser->getCon()->prepare("SELECT * FROM answers WHERE question_id = ?");
$stmt->bind_param('i',$question_id);
$stmt->execute();
$link = $stmt->get_result();
$stmt->close();
if($row['answer_type'] == "number" || $row['answer_type'] == "text" || $row['answer_type'] == "mcq" || $row['answer_type'] == "dropdown"){
$output = displayAnswers($link);
}
else if($row['answer_type'] == "file"){
echo '<small>Copy Paste Link address to view Image</small>';
$output = displayFile($link);
}
echo $output;
}
}
?>
</ol>
</div>
</body>
</html>