-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
136 lines (127 loc) · 4.5 KB
/
index.php
File metadata and controls
136 lines (127 loc) · 4.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
<?php
require("station.php");
require("db.php");
if (!isset($_GET['action'])) {
$_GET['action'] = "";
}
if ($_GET['action'] == "list") {
?>
<html>
<head>
<link rel="stylesheet" href="assets/css/foundation.css" type="text/css" />
<link rel="stylesheet" href="assets/css/normalize.css" type="text/css" />
<link rel="stylesheet" href="assets/css/style.css" type="text/css" />
<title>Multitude Control Panel</title>
</head>
<body>
<div id="container">
<header class="row">
<img id="banner-logo" src="Multitude.png" height="100px"/>
<form method="get" id="search">
<input name="filter" type="text" size="40" placeholder="Search" />
</form>
<!-- DEPRECRATED: Testing new search bar
<form method="GET">
<input name="filter"></input>
<input type="submit" value="Search"></input>
<input type="hidden" name="action" value="list"></input>
</form>
-->
</header>
<table>
<?php
if(isset($_GET['filter'])) {
$line = htmlspecialchars($_GET['filter']);
$filter = "WHERE `station` LIKE '%".$line."%'";
} else {
$filter = "";
}
$sql = "SELECT `station`, COUNT(*) as freq FROM `responses` ".$filter." GROUP BY `station`";
$result = mysqli_query($con, $sql);
$rows = mysqli_num_rows($result);
$stations = array();
while ($array = mysqli_fetch_array($result)) {
$station = new Station($array[0]);
array_push($stations, $station);
}
foreach ($stations as &$station) {
$sql = "SELECT COUNT(*) as freq FROM `responses` WHERE feedback = 1 AND station = '".$station->name."'";
$result = mysqli_query($con, $sql);
$value = mysqli_fetch_object($result);
$station->positive = $value->freq;;
}
foreach ($stations as &$station) {
$sql = "SELECT COUNT(*) as freq FROM `responses` WHERE feedback = 0 AND station = '".$station->name."'";
$result = mysqli_query($con, $sql);
$value = mysqli_fetch_object($result);
$station->negative = $value->freq;;
}
function displayLogo($name, $mainArray) {
$result = "";
foreach ($mainArray as $temp) {
foreach ($temp as $key => $value) {
if ($value == $name) {
$result = $key;
break;
}
}
if ($result != "") {
break;
}
}
$code = substr($result, 0, 2);
echo '<p class="icon stn-code '.$code.'">'.$result.'</p>';
}
for ($i = 0; $i < count($stations); $i++) {
$station = $stations[$i];
if ($i % 3 == 0) {
echo "</tr><tr>";
}
echo '<td class="btn" onclick="window.location=\'details.php?station='.urlencode($station->name).'\';">';
displayLogo($station->name, $mainStationArray);
echo '<h3 class="name">'.$station->name.'</h3>';
echo '<p class="rating">'.round($station->getRating()*100,0).'%</p>';
echo "</td>";
}
?>
</table>
</div>
<script>
setTimeout('location.reload()',30000);
var ele = document.getElementsByClassName('name');
for (var i = 0; i < ele.length; i++) {
var rating = ele[i].parentNode.childNodes[2].innerHTML;
ele[i].parentNode.style.background = getColor(rating);
}
function getColor(percent) {
var R = parseInt((100 - percent)/100 * 255);
var G = parseInt((0 + percent)/100 * 255);
var B = 0;
return "rgb(" + R + "," + G + "," + B + ")";
}
</script>
<?php
} else if ($_POST["action"] == "add") {
header('Content-Type: application/json');
$feedback = htmlspecialchars($_POST['feedback']);
$station = htmlspecialchars($_POST['station']);
if (!isset($_POST['message'])) {
$_POST['message'] = "";
}
if (!isset($_POST['reply'])) {
$_POST['reply'] = "";
}
$message = htmlspecialchars($_POST['message']);
$reply = htmlspecialchars($_POST['reply']);
$sql = "INSERT INTO responses (`UID`, `timestamp`, `station`, `feedback`, `message`, `replyTo`) VALUES (NULL, NULL, '".$station."', ".$feedback.", '".$message."', '".$reply."');";
$result = mysqli_query($con, $sql);
if ($result) {
$array = array("status" => "success");
} else {
$array = array("status" => "failure");
}
echo json_encode($array);
} else {
echo("Invalid Action defined");
}
?>