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

Last change on this file since 19752 was 19643, checked in by Daniela Dorner, 5 years ago
added total number of alerts
File size: 9.0 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 if($_SERVER["HTTPS"] != "on")
114 {
115 header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
116 exit();
117 }
118
119
120 $query="SELECT fSourceName AS 'Source', fSentTime AS 'Sent', CONCAT(fRecepient, ' [', fRecepientKey, ']') AS 'To [key]', fComment AS 'Comment' ";
121 $query.="FROM Sent LEFT JOIN factdata.Source USING (fSourceKey) LEFT JOIN Recepient USING (fRecepientKey) WHERE fSentTime BETWEEN ".$start." AND ".$stop;
122 if ($source != -1)
123 $query.=" AND fSourceKey=".$source;
124 if ($type != -1)
125 $query.=" AND fRecepientKey=".$type;
126 $query.=" ORDER BY fSentTime";
127
128 $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
129 echo "<h2>Found ".sizeOf($result)." Alert(s) from ".$start." to ".$stop." (";
130 if ($source == -1)
131 echo "all sources";
132 else
133 echo "source key ".$source;
134 echo ", ";
135 if ($type == -1)
136 echo "all recepients";
137 else
138 echo "recepient key ".$type;
139 echo "): </h2>";
140 // table with alerts
141 echo "<table border='1' style='border-collapse:collapse'>\n";
142 $first_row = 0;
143 $colnames = "";
144 foreach($result as $row)
145 {
146 if ($first_row == 0)
147 {
148 $first_row = 1;
149 echo "<tr>\n";
150 $colnames = array_keys($row);
151 foreach($colnames as $colname){
152 echo "<th>".$colname."</th>\n";
153 }
154 echo "</tr>\n";
155 }
156 echo "<tr>\n";
157 foreach ($colnames as $key)
158 {
159 if ($key=="Comment")
160 {
161 if (strpos($row[$key],"ATel") !== false)
162 echo "<td>".preg_replace("/ATel\ \#(\d{4,5})/", "<a href='http://www.astronomerstelegram.org/?read=$1'>ATel #$1</a>", $row[$key])."</td>\n";
163 else
164 echo "<td>".$row[$key]."</td>\n";
165 }
166 else
167 echo "<td>".$row[$key]."</td>\n";
168 }
169 echo "</tr>\n";
170 }
171 echo "</table><br>\n";
172
173 echo "<hr>\n";
174 echo "<hr>\n";
175 echo "<h2>Alert Statistics: </h2>";
176 $query="SELECT fRecepientName AS 'To', Count(*) AS 'count' FROM Sent LEFT JOIN Recepient USING (fRecepientKey) WHERE fSentTime BETWEEN ".$start." AND ".$stop;
177 if ($source != -1)
178 $query.=" AND fSourceKey=".$source;
179 if ($type != -1)
180 $query.=" AND fRecepientKey=".$type;
181 $query.=" GROUP BY fRecepientName ORDER BY count DESC";
182
183 echo "<table border='1' style='border-collapse:collapse'>\n";
184 $first_row = 0;
185 $colnames = "";
186 $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
187 foreach($result as $row)
188 {
189 if ($first_row == 0)
190 {
191 $first_row = 1;
192 echo "<tr>\n";
193 $colnames = array_keys($row);
194 foreach($colnames as $colname){
195 echo "<th>".$colname."</th>\n";
196 }
197 echo "</tr>\n";
198 }
199 echo "<tr>\n";
200 foreach ($colnames as $key) {
201
202 echo "<td>".$row[$key]."</td>\n";
203 }
204 echo "</tr>\n";
205 }
206 echo "</table>\n";
207
208 echo "<hr>\n";
209 $query="SELECT fSourceName AS 'Source', Count(*) AS 'count' FROM Sent LEFT JOIN factdata.Source USING (fSourceKey) ";
210 $query.="WHERE fSentTime BETWEEN ".$start." AND ".$stop;
211 if ($source != -1)
212 $query.=" AND fSourceKey=".$source;
213 if ($type != -1)
214 $query.=" AND fRecepientKey=".$type;
215 $query.=" GROUP BY fSourceName ORDER BY count DESC";
216
217
218 echo "<table border='1' style='border-collapse:collapse'>\n";
219 $first_row = 0;
220 $colnames = "";
221 $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
222 foreach($result as $row)
223 {
224 if ($first_row == 0)
225 {
226 $first_row = 1;
227 echo "<tr>\n";
228 $colnames = array_keys($row);
229 foreach($colnames as $colname){
230 echo "<th>".$colname."</th>\n";
231 }
232 echo "</tr>\n";
233 }
234 echo "<tr>\n";
235 foreach ($colnames as $key) {
236
237 echo "<td>".$row[$key]."</td>\n";
238 }
239 echo "</tr>\n";
240 }
241 echo "</table>\n";
242
243 echo "<hr>\n";
244 $query="SELECT fSourceName AS 'Source', fRecepientName AS 'To', Count(*) AS 'count' FROM Sent ";
245 $query.="LEFT JOIN Recepient USING (fRecepientKey) LEFT JOIN factdata.Source USING (fSourceKey) ";
246 $query.="WHERE fSentTime BETWEEN ".$start." AND ".$stop;
247 if ($source != -1)
248 $query.=" AND fSourceKey=".$source;
249 if ($type != -1)
250 $query.=" AND fRecepientKey=".$type;
251 $query.=" GROUP BY fRecepientName, fSourceName ORDER BY fRecepientName ";
252
253
254 echo "<table border='1' style='border-collapse:collapse'>\n";
255 $first_row = 0;
256 $colnames = "";
257 $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
258 foreach($result as $row)
259 {
260 if ($first_row == 0)
261 {
262 $first_row = 1;
263 echo "<tr>\n";
264 $colnames = array_keys($row);
265 foreach($colnames as $colname){
266 echo "<th>".$colname."</th>\n";
267 }
268 echo "</tr>\n";
269 }
270 echo "<tr>\n";
271 foreach ($colnames as $key) {
272
273 echo "<td>".$row[$key]."</td>\n";
274 }
275 echo "</tr>\n";
276 }
277 echo "</table>\n";
278
279 echo "<hr size='2px' style='border-width:5px'>\n";
280
281
282?>
283</body>
284</html>
Note: See TracBrowser for help on using the repository browser.