-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAuditor_surveys.php
320 lines (288 loc) · 8.54 KB
/
Auditor_surveys.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<html>
<head>
<title> Auditor - Survey</title>
<link rel="icon" href="images/admin.jfif" type="image/x-icon">
<link href="CSS/simple-sidebar.css" rel="stylesheet">
<style>
table {
border-collapse: collapse;
margin-top: 15px;
width: 100%;
}
th, td {
text-align: left;
padding: 8px 0px;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #292b2c;
color: white;
}
</style>
</head>
<?php
session_start();
if (!$_SESSION['loggedIn'] || $_SESSION['user']['Role'] != 4) {
echo "<script> location.href='home.php'; </script>";
}
include "menu.php";
?>
<body>
<div class="d-flex" id="wrapper">
<div class="bg-dark border-right" id="sidebar-wrapper">
<div class="list-group list-group-flush bg-dark">
<a href="Auditor_surveys.php" class="list-group-item list-group-item-action bg-secondary text-light show"><span class="text-nowrap"><i class="fa fa-plus-square"></i> surveys</a></span>
<a href="messagesMenu.php" class="list-group-item list-group-item-action bg-dark text-light show"><span class="text-nowrap"><i class="fa fa-plus-square"></i>Messages</a></span>
</div>
</div>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="row d-flex justify-content-center">
<!--Grid column-->
<div class="col-md-6" style="margin-top: 15px;">
<div class="input-group rounded">
<input type="search" id="searchBar" class="form-control rounded" placeholder="Search" aria-label="Search"
aria-describedby="search-addon" />
<span onclick="search()" style="margin-left: 10px;" class="btn input-group-text border-0" id="search-addon">
<i class="fa fa-search"></i>
</span>
<span onclick="show()" style="margin-left: 10px;" class="btn input-group-text border-0" id="searchoptions">
Show search options
</span>
</div>
</div>
</div>
<div class="row d-flex justify-content-center" >
<div class="col-md-3 fade-in" style="display: none;" id="options">
Search by:
<div class="form-check">
<input class="form-check-input" type="radio" name="filter" checked>
<label class="form-check-label" for="exampleRadios1">
Name
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="filter" id="radioRating">
<label class="form-check-label" for="exampleRadios2">
rating
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="filter" id="radioPrice">
<label class="form-check-label" for="exampleRadios2">
price
</label>
</div>
</div>
</div>
<div class="container-fluid">
<?php
$servername = "localhost";
$username = "root";
$password = "";
$DB = "mydb";
$conn = mysqli_connect($servername, $username, $password, $DB);
if (!$conn) {
error_log(mysqli_connect_error(),3,"../errors/db-errors.log");
die("Connection failed: " .mysqli_connect_error());
}
if (isset($_GET['delete'])) {
$valuesToDelete = explode (",", $_GET['delete']);
for ($i = 0; $i < count($valuesToDelete); $i++) {
$v = $valuesToDelete[$i];
//echo "<script>alert('".$v."');</script>";
$conn->query("DELETE FROM question WHERE survey_id=$v");
$conn->query("DELETE FROM survey WHERE survey_id=$v");
$conn->query("DELETE FROM survey_answer WHERE survey_id=$v");
//if (file_exists("images/products/".$v)) {
// unlink("images/products/".$v);
}
}
if (isset($_GET['search'])) {
$val = $_GET['search'];
$val2 = $_GET['searchBy'];
$res = $conn->query("select * from survey where survey_name like '%$val%' OR survey_name like '%$val' OR survey_name like '$val%'");
} else {
$res = $conn->query("SELECT * FROM survey");
}
if (!$res) {
//die "Query failed: (" . $res->errno . ") " . $res->error;
}
$rownumber = 1;
$page = 1;
$where = 0;
$firstrow = 0;
echo "<table style='width:100%'>\n";
if (isset($_GET['page'])) {
$do = $_GET['page'];
$page = $do;
}
while ($row = $res->fetch_assoc()) {
if (0 == $firstrow) {
/* first result set row? look at the keys=column nanes */
echo "<tr>";
foreach (array_keys($row) as $colname) {
if ($colname == "reg_date") {
echo "<th>date added</th>";
} else if ($colname == "Id") {
echo "<th> #</th>";
} else {
echo "<th>$colname</th>";
}
}
echo "<th>Action</th>";
echo "<th></th>";
echo "</tr>\n";
}
$firstrow = 1;
echo "<tr>";
$where = 0;
$id = 0;
foreach (array_values($row) as $colval) {
if (($rownumber <= $page*10 && abs($page*10 - $rownumber < 10))) {
if ($where == 0) {
$id = $colval;
echo "<td> <input type='checkbox' id='check".$id."' onclick='checkBoxes(".$id.")' name='select' value='".$id."'></td>";
} else {
echo "<td>$colval</td>";
}
}
$where++;
}
if (($rownumber <= $page*10 && abs($page*10 - $rownumber < 10))) {
echo "<td><a href='Auditor_users.php?Id=".$id."' class='btn btn-dark'>send survey</a></td>";
echo "<td><a href='Auditor_surveyresponses.php?Id=".$id."' class='btn btn-dark'>see responses</a></td>";
}
$rownumber ++;
echo "</tr>\n";
}
echo "</table>\n";
$amountOfRows = $res->num_rows;
if ($amountOfRows == 0) {
echo "No results found";
}
$res->close();
?>
<?php
if (isset($_GET['search'])) {
$s = $_GET['search'];
$s2 = $_GET['searchBy'];
$do = $page - 1;
$change = true;
if ($do <= 0) {
$change = false;
} else if ($do > (ceil(($amountOfRows) / 10))) {
$change = false;
}
if ($change) {
echo '<a class="btn btn-dark" href="Auditor_surveys.php?search='.$s.'&page='.($page-1).'&searchBy='.$s2.'"><</a>';
}
} else {
$do = $page - 1;
$change = true;
if ($do <= 0) {
$change = false;
} else if ($do > (ceil(($amountOfRows) / 10))) {
$change = false;
}
if ($change) {
echo '<a class="btn btn-dark" href="Auditor_surveys.php?page='.($page-1).'"><</a>';
}
}
?>
<?php if ($amountOfRows > 0) { echo"<a>\t".$page." of ".(ceil(($amountOfRows) / 10))."\t</a>"; }?>
<?php
if (isset($_GET['search'])) {
$s = $_GET['search'];
$s2 = $_GET['searchBy'];
$do = $page + 1;
$change = true;
if ($do <= 0) {
$change = false;
} else if ($do > (ceil(($amountOfRows) / 10))) {
$change = false;
}
if ($change) {
echo '<a class="btn btn-dark" href="Auditor_surveys.php?search='.$s.'&page='.($page+1).'&searchBy='.$s2.'">></a>';
}
} else {
$do = $page + 1;
$change = true;
if ($do <= 0) {
$change = false;
} else if ($do > (ceil(($amountOfRows) / 10))) {
$change = false;
}
if ($change) {
echo '<a class="btn btn-dark" href="Auditor_surveys.php?page='.($page+1).'">></a>';
}
}
?>
<?php echo '<a id="delete" class="btn float-right bg-warning text-light" href="">delete</a>' ?>
<?php echo ' <a class="btn bg-success text-light" href="Auditor_editsurvey.php?action=add">add survey</a>' ?>
</div>
</div>
<script>
var selected = [];
var link = document.getElementById("delete");
var searchBy = "Name";
link.setAttribute("href", "Auditor_surveys.php");
function checkBoxes(id) {
var check = document.getElementById("check"+id);
if (check.checked) {
selected.push(id);
} else {
var ind = selected.indexOf(id);
if (ind > -1) {
selected.splice(ind, 1);
}
}
if (selected.length > 0) {
link.setAttribute("href", "Auditor_surveys.php?delete="+selected.join(",")+"");
} else {
link.setAttribute("href", "Auditor_surveys.php");
}
}
var searchBar = document.getElementById("searchBar");
searchBar.addEventListener("keydown", function (e) {
if (e.keyCode === 13) {
search();
}
});
function search() {
var searchBar = document.getElementById("searchBar");
if (searchBar.value != "") {
if (document.getElementById('radioRating').checked) {
searchBy = "rating";
} else if (document.getElementById('radioPrice').checked) {
searchBy = "price";
}
if (searchBy != "Name") {
if (isNaN(searchBar.value)) {
alert("Must be a number");
return;
}
}
window.location = "Auditor_surveys.php?search="+searchBar.value+"&searchBy="+searchBy;
}
}
function show() {
var options = document.getElementById("options");
var text = document.getElementById("searchoptions");
searchoptions
if (options.style.display == "none") {
options.style.display = "block";
text.innerHTML = "Hide search options";
} else {
options.style.display = "none";
text.innerHTML = "Show search options";
}
}
</script>
</div>
<?php
include 'footer.php'
?>
</body>
</html>