source: trunk/www/flare_alerts/sent.php@ 19633

Last change on this file since 19633 was 19633, checked in by Daniela Dorner, 5 years ago
added (page to display sent alerts)
File size: 8.4 KB
Line 
1<!DOCTYPE HTML>
2<html>
3<head>
4 <link rel="stylesheet" type="text/css" href="checkstyle.css" />
5 <style>
6 .error {color: #FF0000;}
7 </style>
8
9 <script language="JavaScript" type="text/javascript">
10 if (document.getElementById) {
11 document.writeln('<style type="text/css"><!--')
12 document.writeln('.texter {display:none} @media print {.texter {display:block;}}')
13 document.writeln('//--></style>') }
14 function openClose(theID) {
15 if (document.getElementById(theID).style.display == "block") {
16 document.getElementById(theID).style.display = "none"
17 } else {
18 document.getElementById(theID).style.display = "block" }
19 }
20 </script>
21</head>
22<body>
23
24<?php
25
26 if (!empty($_GET["start"]))
27 $start=$_GET["start"];
28 else
29 $start="20140318";
30
31 if (!empty($_GET["type"]))
32 $type=$_GET["type"];
33 else
34 $type=-1;
35
36 if (!empty($_GET["stop"]))
37 {
38 $stop=$_GET["stop"];
39 }
40 else
41 {
42 if (date("H")>18)
43 $stop=date("Ymd", mktime(0,0,0,date("m"), date("d"), date("Y")));
44 else
45 $stop=date("Ymd",strtotime(date("Y-m-d", mktime(0,0,0,date("m"), date("d"), date("Y")))." -1 day"));
46 }
47 if (!empty($_GET["source"]))
48 $source=$_GET["source"];
49 else
50 $source="-1";
51
52 echo "<hr size='2px' style='border-width:5px'>\n";
53 echo "<h1>Flare Alerts Sent</h1>\n";
54 echo "<hr>\n";
55
56 echo "<h2>Display Alerts</h2>\n";
57 echo "<form method=\"get\" action=\"sent.php\" enctype=\"multipart/form-data\" >\n";
58 echo "<p>\n";
59 echo "From: <input type='text' name='start' size='8' maxlength='8' value='".$start."'/>\n";
60 echo "To: <input type='text' name='stop' size='8' maxlength='8' value='".$stop."'/> <br>\n";
61
62 include('/home/fact/php_credentials/factweb.php');
63 $db = new PDO(
64 'mysql:host='.$host.';dbname=FlareAlerts;charset=utf8mb4',
65 $user,
66 $pass);
67
68 $query="SELECT fRecepientKey, fRecepientName FROM Recepient ORDER BY fRecepientKey";
69 $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
70
71 echo "Recepient <select name='type' size='1'>\n";
72 if ($type == -1)
73 printf("<option value='-1' selected>all recepients</option>\n");
74 else
75 printf("<option value='-1'>all recepients</option>\n");
76 foreach($result as $row)
77 {
78 if ($type == $row["fRecepientKey"])
79 {
80 printf("<option value='%s' selected>%s</option>\n", $row["fRecepientKey"], $row["fRecepientName"]);
81 }
82 else
83 printf("<option value='%s'>%s</option>\n", $row["fRecepientKey"], $row["fRecepientName"]);
84 }
85 echo "</select>\n ";
86
87 $query="SELECT fSourceKey, fSourceName FROM Sent LEFT JOIN factdata.Source USING(fSourceKey) GROUP BY fSourceKey";
88 $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
89
90 echo "Source <select name='source' size='1'>\n";
91 if ($source == -1)
92 printf("<option value='-1' selected>all sources</option>\n");
93 else
94 printf("<option value='-1'>all sources</option>\n");
95 foreach($result as $row)
96 {
97 if ($source == $row["fSourceKey"])
98 {
99 printf("<option value='%s' selected>%s</option>\n", $row["fSourceKey"], $row["fSourceName"]);
100 }
101 else
102 printf("<option value='%s'>%s</option>\n", $row["fSourceKey"], $row["fSourceName"]);
103 }
104 echo "</select><br>\n";
105 echo "</p>\n";
106// mysql_free_result($result);
107 echo "<input type='submit' name='submit' value='Show Alerts' />\n";
108 echo "<input class='Width' type='button' value='Reset' onClick='self.location.href=\"sent.php\"'>";
109 echo "</form>\n";
110 echo "<hr>\n";
111
112
113 echo "<h2>Alert(s) from ".$start." to ".$stop.": </h2>";
114 if($_SERVER["HTTPS"] != "on")
115 {
116 header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
117 exit();
118 }
119
120 // table with alert from table FlareAlerts.FlareTriggers
121 echo "<table border='1' style='border-collapse:collapse'>\n";
122 $first_row = 0;
123 $colnames = "";
124
125
126 $query="SELECT fSourceName AS 'Source', fSentTime AS 'Sent', CONCAT(fRecepient, ' [', fRecepientKey, ']') AS 'To [key]', fComment AS 'Comment' ";
127 $query.="FROM Sent LEFT JOIN factdata.Source USING (fSourceKey) LEFT JOIN Recepient USING (fRecepientKey) WHERE fSentTime BETWEEN ".$start." AND ".$stop;
128 if ($source != -1)
129 $query.=" AND fSourceKey=".$source;
130 if ($type != -1)
131 $query.=" AND fRecepientKey=".$type;
132 $query.=" ORDER BY fSentTime";
133
134 $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
135 foreach($result as $row)
136 {
137 if ($first_row == 0)
138 {
139 $first_row = 1;
140 echo "<tr>\n";
141 $colnames = array_keys($row);
142 foreach($colnames as $colname){
143 echo "<th>".$colname."</th>\n";
144 }
145 echo "</tr>\n";
146 }
147 echo "<tr>\n";
148 foreach ($colnames as $key) {
149
150 echo "<td>".$row[$key]."</td>\n";
151 }
152 echo "</tr>\n";
153 }
154 echo "</table><br>\n";
155
156 echo "<hr>\n";
157 echo "<hr>\n";
158 echo "<h2>Alert Statistics: </h2>";
159 $query="SELECT fRecepientName AS 'To', Count(*) AS 'count' FROM Sent LEFT JOIN Recepient USING (fRecepientKey) WHERE fSentTime BETWEEN ".$start." AND ".$stop;
160 if ($source != -1)
161 $query.=" AND fSourceKey=".$source;
162 if ($type != -1)
163 $query.=" AND fRecepientKey=".$type;
164 $query.=" GROUP BY fRecepientName ORDER BY count DESC";
165
166 echo "<table border='1' style='border-collapse:collapse'>\n";
167 $first_row = 0;
168 $colnames = "";
169 $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
170 foreach($result as $row)
171 {
172 if ($first_row == 0)
173 {
174 $first_row = 1;
175 echo "<tr>\n";
176 $colnames = array_keys($row);
177 foreach($colnames as $colname){
178 echo "<th>".$colname."</th>\n";
179 }
180 echo "</tr>\n";
181 }
182 echo "<tr>\n";
183 foreach ($colnames as $key) {
184
185 echo "<td>".$row[$key]."</td>\n";
186 }
187 echo "</tr>\n";
188 }
189 echo "</table>\n";
190
191 echo "<hr>\n";
192 $query="SELECT fSourceName AS 'Source', Count(*) AS 'count' FROM Sent LEFT JOIN factdata.Source USING (fSourceKey) ";
193 $query.="WHERE fSentTime BETWEEN ".$start." AND ".$stop;
194 if ($source != -1)
195 $query.=" AND fSourceKey=".$source;
196 if ($type != -1)
197 $query.=" AND fRecepientKey=".$type;
198 $query.=" GROUP BY fSourceName ORDER BY count DESC";
199
200
201 echo "<table border='1' style='border-collapse:collapse'>\n";
202 $first_row = 0;
203 $colnames = "";
204 $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
205 foreach($result as $row)
206 {
207 if ($first_row == 0)
208 {
209 $first_row = 1;
210 echo "<tr>\n";
211 $colnames = array_keys($row);
212 foreach($colnames as $colname){
213 echo "<th>".$colname."</th>\n";
214 }
215 echo "</tr>\n";
216 }
217 echo "<tr>\n";
218 foreach ($colnames as $key) {
219
220 echo "<td>".$row[$key]."</td>\n";
221 }
222 echo "</tr>\n";
223 }
224 echo "</table>\n";
225
226 echo "<hr>\n";
227 $query="SELECT fSourceName AS 'Source', fRecepientName AS 'To', Count(*) AS 'count' FROM Sent ";
228 $query.="LEFT JOIN Recepient USING (fRecepientKey) LEFT JOIN factdata.Source USING (fSourceKey) ";
229 $query.="WHERE fSentTime BETWEEN ".$start." AND ".$stop;
230 if ($source != -1)
231 $query.=" AND fSourceKey=".$source;
232 if ($type != -1)
233 $query.=" AND fRecepientKey=".$type;
234 $query.=" GROUP BY fRecepientName, fSourceName ORDER BY fRecepientName ";
235
236
237 echo "<table border='1' style='border-collapse:collapse'>\n";
238 $first_row = 0;
239 $colnames = "";
240 $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
241 foreach($result as $row)
242 {
243 if ($first_row == 0)
244 {
245 $first_row = 1;
246 echo "<tr>\n";
247 $colnames = array_keys($row);
248 foreach($colnames as $colname){
249 echo "<th>".$colname."</th>\n";
250 }
251 echo "</tr>\n";
252 }
253 echo "<tr>\n";
254 foreach ($colnames as $key) {
255
256 echo "<td>".$row[$key]."</td>\n";
257 }
258 echo "</tr>\n";
259 }
260 echo "</table>\n";
261
262 echo "<hr size='2px' style='border-width:5px'>\n";
263
264
265?>
266</body>
267</html>
Note: See TracBrowser for help on using the repository browser.