Index: trunk/www/flare_alerts/sent.php
===================================================================
--- trunk/www/flare_alerts/sent.php	(revision 19633)
+++ trunk/www/flare_alerts/sent.php	(revision 19633)
@@ -0,0 +1,267 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+    <link rel="stylesheet" type="text/css" href="checkstyle.css" />
+    <style>
+        .error {color: #FF0000;}
+    </style>
+
+    <script language="JavaScript" type="text/javascript">
+        if (document.getElementById) {
+        document.writeln('<style type="text/css"><!--')
+        document.writeln('.texter {display:none} @media print {.texter {display:block;}}')
+        document.writeln('//--></style>') }
+        function openClose(theID) {
+            if (document.getElementById(theID).style.display == "block") {
+                document.getElementById(theID).style.display = "none"
+            } else {
+                document.getElementById(theID).style.display = "block" }
+        }
+    </script>
+</head>
+<body>
+
+<?php
+
+    if (!empty($_GET["start"]))
+        $start=$_GET["start"];
+    else
+        $start="20140318";
+
+    if (!empty($_GET["type"]))
+        $type=$_GET["type"];
+    else
+        $type=-1;
+
+    if (!empty($_GET["stop"]))
+    {
+        $stop=$_GET["stop"];
+    }
+    else
+    {
+        if (date("H")>18)
+            $stop=date("Ymd", mktime(0,0,0,date("m"), date("d"), date("Y")));
+        else
+            $stop=date("Ymd",strtotime(date("Y-m-d", mktime(0,0,0,date("m"), date("d"), date("Y")))." -1 day"));
+    }
+    if (!empty($_GET["source"]))
+        $source=$_GET["source"];
+    else
+        $source="-1";
+
+    echo "<hr size='2px' style='border-width:5px'>\n";
+    echo "<h1>Flare Alerts Sent</h1>\n";
+    echo "<hr>\n";
+
+    echo "<h2>Display Alerts</h2>\n";
+    echo "<form method=\"get\" action=\"sent.php\"  enctype=\"multipart/form-data\" >\n";
+    echo "<p>\n";
+    echo "From:   <input type='text' name='start' size='8' maxlength='8' value='".$start."'/>\n";
+    echo "To:    <input type='text' name='stop' size='8' maxlength='8' value='".$stop."'/> <br>\n";
+
+    include('/home/fact/php_credentials/factweb.php');
+    $db = new PDO(
+            'mysql:host='.$host.';dbname=FlareAlerts;charset=utf8mb4',
+            $user,
+            $pass);
+
+    $query="SELECT fRecepientKey, fRecepientName FROM Recepient ORDER BY fRecepientKey";
+    $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
+
+    echo "Recepient <select name='type' size='1'>\n";
+    if ($type == -1)
+        printf("<option value='-1' selected>all recepients</option>\n");
+    else
+        printf("<option value='-1'>all recepients</option>\n");
+    foreach($result as $row) 
+    {
+        if ($type == $row["fRecepientKey"])
+        {
+            printf("<option value='%s' selected>%s</option>\n", $row["fRecepientKey"], $row["fRecepientName"]);
+        }
+        else
+            printf("<option value='%s'>%s</option>\n", $row["fRecepientKey"], $row["fRecepientName"]);
+    }
+    echo "</select>\n ";
+
+    $query="SELECT fSourceKey, fSourceName FROM Sent LEFT JOIN factdata.Source USING(fSourceKey) GROUP BY fSourceKey";
+    $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
+
+    echo "Source <select name='source' size='1'>\n";
+    if ($source == -1)
+        printf("<option value='-1' selected>all sources</option>\n");
+    else
+        printf("<option value='-1'>all sources</option>\n");
+    foreach($result as $row) 
+    {
+        if ($source == $row["fSourceKey"])
+        {
+            printf("<option value='%s' selected>%s</option>\n", $row["fSourceKey"], $row["fSourceName"]);
+        }
+        else
+            printf("<option value='%s'>%s</option>\n", $row["fSourceKey"], $row["fSourceName"]);
+    }
+    echo "</select><br>\n";
+    echo "</p>\n";
+//    mysql_free_result($result);
+    echo "<input type='submit' name='submit' value='Show Alerts' />\n";
+    echo "<input class='Width' type='button' value='Reset' onClick='self.location.href=\"sent.php\"'>";
+    echo "</form>\n";
+    echo "<hr>\n";
+
+
+    echo "<h2>Alert(s) from ".$start." to ".$stop.": </h2>";
+    if($_SERVER["HTTPS"] != "on")
+    {
+        header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
+        exit();
+    }
+
+    // table with alert from table FlareAlerts.FlareTriggers
+    echo "<table border='1' style='border-collapse:collapse'>\n";
+    $first_row = 0;
+    $colnames = "";
+
+
+    $query="SELECT fSourceName AS 'Source', fSentTime AS 'Sent', CONCAT(fRecepient, ' [', fRecepientKey, ']') AS 'To [key]', fComment AS 'Comment' ";
+    $query.="FROM Sent LEFT JOIN factdata.Source USING (fSourceKey) LEFT JOIN Recepient USING (fRecepientKey) WHERE fSentTime BETWEEN ".$start." AND ".$stop;
+    if ($source != -1)
+        $query.=" AND fSourceKey=".$source;
+    if ($type != -1)
+        $query.=" AND fRecepientKey=".$type;
+    $query.=" ORDER BY fSentTime";
+
+    $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
+    foreach($result as $row) 
+    {
+        if ($first_row == 0)
+        {
+            $first_row = 1;
+            echo "<tr>\n";
+            $colnames = array_keys($row);
+            foreach($colnames as $colname){
+                echo "<th>".$colname."</th>\n";
+            }
+            echo "</tr>\n";
+        }
+        echo "<tr>\n";
+        foreach ($colnames as $key) {
+            
+            echo "<td>".$row[$key]."</td>\n";
+        }
+        echo "</tr>\n";
+    }
+    echo "</table><br>\n";
+
+    echo "<hr>\n";
+    echo "<hr>\n";
+    echo "<h2>Alert Statistics: </h2>";
+    $query="SELECT fRecepientName AS 'To', Count(*) AS 'count' FROM Sent LEFT JOIN Recepient USING (fRecepientKey) WHERE fSentTime BETWEEN ".$start." AND ".$stop;
+    if ($source != -1)
+        $query.=" AND fSourceKey=".$source;
+    if ($type != -1)
+        $query.=" AND fRecepientKey=".$type;
+    $query.=" GROUP BY fRecepientName ORDER BY count DESC";
+
+    echo "<table border='1' style='border-collapse:collapse'>\n";
+    $first_row = 0;
+    $colnames = "";
+    $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
+    foreach($result as $row) 
+    {
+        if ($first_row == 0)
+        {
+            $first_row = 1;
+            echo "<tr>\n";
+            $colnames = array_keys($row);
+            foreach($colnames as $colname){
+                echo "<th>".$colname."</th>\n";
+            }
+            echo "</tr>\n";
+        }
+        echo "<tr>\n";
+        foreach ($colnames as $key) {
+            
+            echo "<td>".$row[$key]."</td>\n";
+        }
+        echo "</tr>\n";
+    }
+    echo "</table>\n";
+
+    echo "<hr>\n";
+    $query="SELECT fSourceName AS 'Source', Count(*) AS 'count' FROM Sent LEFT JOIN factdata.Source USING (fSourceKey) ";
+    $query.="WHERE fSentTime BETWEEN ".$start." AND ".$stop;
+    if ($source != -1)
+        $query.=" AND fSourceKey=".$source;
+    if ($type != -1)
+        $query.=" AND fRecepientKey=".$type;
+    $query.=" GROUP BY fSourceName ORDER BY count DESC";
+
+
+    echo "<table border='1' style='border-collapse:collapse'>\n";
+    $first_row = 0;
+    $colnames = "";
+    $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
+    foreach($result as $row) 
+    {
+        if ($first_row == 0)
+        {
+            $first_row = 1;
+            echo "<tr>\n";
+            $colnames = array_keys($row);
+            foreach($colnames as $colname){
+                echo "<th>".$colname."</th>\n";
+            }
+            echo "</tr>\n";
+        }
+        echo "<tr>\n";
+        foreach ($colnames as $key) {
+            
+            echo "<td>".$row[$key]."</td>\n";
+        }
+        echo "</tr>\n";
+    }
+    echo "</table>\n";
+
+    echo "<hr>\n";
+    $query="SELECT fSourceName AS 'Source', fRecepientName AS 'To', Count(*) AS 'count' FROM Sent ";
+    $query.="LEFT JOIN Recepient USING (fRecepientKey) LEFT JOIN factdata.Source USING (fSourceKey) ";
+    $query.="WHERE fSentTime BETWEEN ".$start." AND ".$stop;
+    if ($source != -1)
+        $query.=" AND fSourceKey=".$source;
+    if ($type != -1)
+        $query.=" AND fRecepientKey=".$type;
+    $query.=" GROUP BY fRecepientName, fSourceName ORDER BY fRecepientName ";
+
+
+    echo "<table border='1' style='border-collapse:collapse'>\n";
+    $first_row = 0;
+    $colnames = "";
+    $result = $db->query($query)->fetchAll(PDO::FETCH_ASSOC);
+    foreach($result as $row) 
+    {
+        if ($first_row == 0)
+        {
+            $first_row = 1;
+            echo "<tr>\n";
+            $colnames = array_keys($row);
+            foreach($colnames as $colname){
+                echo "<th>".$colname."</th>\n";
+            }
+            echo "</tr>\n";
+        }
+        echo "<tr>\n";
+        foreach ($colnames as $key) {
+            
+            echo "<td>".$row[$key]."</td>\n";
+        }
+        echo "</tr>\n";
+    }
+    echo "</table>\n";
+
+    echo "<hr size='2px' style='border-width:5px'>\n";
+
+
+?>
+</body>
+</html>
