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

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