db fixes
db fixes

--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,15 +2,10 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="f90ee5b5-97e4-47ec-9b14-d4f4e896f100" name="Default" comment="">
-      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/encodings.xml" />
-      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/misc.xml" />
-      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/modules.xml" />
-      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/scannr.iml" />
-      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/scopes/scope_settings.xml" />
-      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/vcs.xml" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/calls.json.php" afterPath="$PROJECT_DIR$/calls.json.php" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/common.inc.php" afterPath="$PROJECT_DIR$/common.inc.php" />
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/scannr.py" afterPath="$PROJECT_DIR$/scannr.py" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/db.sql" afterPath="$PROJECT_DIR$/db.sql" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/viewcalls.php" afterPath="$PROJECT_DIR$/viewcalls.php" />
     </list>
     <ignored path="scannr.iws" />
@@ -31,14 +26,13 @@
   <component name="ExecutionTargetManager" SELECTED_TARGET="default_target" />
   <component name="FileEditorManager">
     <leaf>
-      <file leaf-file-name="viewcalls.php" pinned="false" current="true" current-in-tab="true">
+      <file leaf-file-name="viewcalls.php" pinned="false" current="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/viewcalls.php">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="66" column="38" selection-start="2349" selection-end="2349" vertical-scroll-proportion="0.31213874">
+            <state line="2" column="13" selection-start="46" selection-end="46" vertical-scroll-proportion="36.153847">
               <folding>
-                <element signature="n#style#0;n#span#0;n#td#0;n#tr#0;n#table#0;n#div#0;n#!!top" expanded="true" />
-                <element signature="n#style#0;n#div#0;n#td#1;n#tr#0;n#table#0;n#div#0;n#!!top" expanded="true" />
-                <element signature="n#style#0;n#span#0;n#td#2;n#tr#0;n#table#0;n#div#0;n#!!top" expanded="true" />
+                <element signature="e#255#287#0" expanded="true" />
+                <element signature="e#341#363#0" expanded="true" />
               </folding>
             </state>
           </provider>
@@ -47,34 +41,16 @@
       <file leaf-file-name="common.inc.php" pinned="false" current="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/common.inc.php">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="3" column="21" selection-start="90" selection-end="90" vertical-scroll-proportion="-1.9615384">
+            <state line="34" column="0" selection-start="1179" selection-end="1179" vertical-scroll-proportion="-22.23077">
               <folding />
             </state>
           </provider>
         </entry>
       </file>
-      <file leaf-file-name="scannr.py" pinned="false" current="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/scannr.py">
-          <provider selected="true" editor-type-id="text-editor">
-            <state line="66" column="23" selection-start="2084" selection-end="2084" vertical-scroll-proportion="0.0">
-              <folding />
-            </state>
-          </provider>
-        </entry>
-      </file>
-      <file leaf-file-name="trunklog.php" pinned="false" current="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/trunklog.php">
-          <provider selected="true" editor-type-id="text-editor">
-            <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="-0.0">
-              <folding />
-            </state>
-          </provider>
-        </entry>
-      </file>
-      <file leaf-file-name="calls.json.php" pinned="false" current="false" current-in-tab="false">
+      <file leaf-file-name="calls.json.php" pinned="false" current="true" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/calls.json.php">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="-0.0">
+            <state line="2" column="9" selection-start="42" selection-end="42" vertical-scroll-proportion="-1.2507788">
               <folding />
             </state>
           </provider>
@@ -93,8 +69,9 @@
   <component name="IdeDocumentHistory">
     <option name="changedFiles">
       <list>
+        <option value="$PROJECT_DIR$/scannr.py" />
         <option value="$PROJECT_DIR$/common.inc.php" />
-        <option value="$PROJECT_DIR$/scannr.py" />
+        <option value="$PROJECT_DIR$/calls.json.php" />
         <option value="$PROJECT_DIR$/viewcalls.php" />
       </list>
     </option>
@@ -159,12 +136,23 @@
     <property name="options.splitter.main.proportions" value="0.3" />
     <property name="WebServerToolWindowFactoryState" value="false" />
     <property name="options.lastSelected" value="project.propVCSSupport.Mappings" />
+    <property name="last_opened_file_path" value="$PROJECT_DIR$/../busui/myway/myway_timeliness.php" />
     <property name="options.searchVisible" value="true" />
     <property name="options.splitter.details.proportions" value="0.2" />
   </component>
   <component name="RunManager">
     <configuration default="true" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
       <TestRunner />
+      <method />
+    </configuration>
+    <configuration default="true" type="PhpLocalRunConfigurationType" factoryName="PHP Console">
+      <method />
+    </configuration>
+    <configuration default="true" type="JavascriptDebugSession" factoryName="Local">
+      <JSDebuggerConfigurationSettings>
+        <option name="engineId" />
+        <option name="fileUrl" />
+      </JSDebuggerConfigurationSettings>
       <method />
     </configuration>
     <list size="0" />
@@ -197,13 +185,13 @@
   </component>
   <component name="ToolWindowManager">
     <frame x="57" y="-8" width="1391" height="916" extended-state="6" />
-    <editor active="false" />
+    <editor active="true" />
     <layout>
       <window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
       <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
       <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
       <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="true" content_ui="tabs" />
-      <window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.24981189" sideWeight="0.6706349" order="0" side_tool="false" content_ui="combo" />
+      <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.24981189" sideWeight="0.6706349" order="0" side_tool="false" content_ui="combo" />
       <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
       <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
       <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32936507" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
@@ -278,35 +266,69 @@
         </state>
       </provider>
     </entry>
+    <entry file="file://$PROJECT_DIR$/../disclosr/include/template.inc.php">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="72" column="93" selection-start="2545" selection-end="2635" vertical-scroll-proportion="0.43404254">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/../disclosr/include/common.inc.php">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://C:/tmp/h5bp-html5-boilerplate-2279296/index.html">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="38" column="11" selection-start="1245" selection-end="1982" vertical-scroll-proportion="0.93352604">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/../busui/myway/myway_timeliness.php">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="27" column="5" selection-start="1003" selection-end="1018" vertical-scroll-proportion="26.346153">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/scannr.py">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="66" column="23" selection-start="2084" selection-end="2084" vertical-scroll-proportion="0.0">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/snd.py">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/viewcalls.php">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="2" column="13" selection-start="46" selection-end="46" vertical-scroll-proportion="36.153847">
+          <folding>
+            <element signature="e#255#287#0" expanded="true" />
+            <element signature="e#341#363#0" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/common.inc.php">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="34" column="0" selection-start="1179" selection-end="1179" vertical-scroll-proportion="-22.23077">
+          <folding />
+        </state>
+      </provider>
+    </entry>
     <entry file="file://$PROJECT_DIR$/calls.json.php">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/scannr.py">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="66" column="23" selection-start="2084" selection-end="2084" vertical-scroll-proportion="0.0">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/common.inc.php">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="3" column="21" selection-start="90" selection-end="90" vertical-scroll-proportion="-1.9615384">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/viewcalls.php">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="66" column="38" selection-start="2349" selection-end="2349" vertical-scroll-proportion="0.31213874">
-          <folding>
-            <element signature="n#style#0;n#span#0;n#td#0;n#tr#0;n#table#0;n#div#0;n#!!top" expanded="true" />
-            <element signature="n#style#0;n#div#0;n#td#1;n#tr#0;n#table#0;n#div#0;n#!!top" expanded="true" />
-            <element signature="n#style#0;n#span#0;n#td#2;n#tr#0;n#table#0;n#div#0;n#!!top" expanded="true" />
-          </folding>
+        <state line="2" column="9" selection-start="42" selection-end="42" vertical-scroll-proportion="-1.2507788">
+          <folding />
         </state>
       </provider>
     </entry>

--- a/calls.json.php
+++ b/calls.json.php
@@ -1,29 +1,51 @@
 <?php
+include('common.inc.php');
+function getSensorValuesByHour($sensorID, $timeFrom, $timeTo) {
+    global $conn;
+    $sth = $conn->prepare( 'select min(call_timestamp) as time, count(*), min(length), max(length), avg(length), stddev(length) from recordings
+            group by tgid, date_trunc(\'hour\', call_timestamp) order by time');
+
+    $sth->execute( Array($sensorID, $timeFrom, $timeTo));
+    return  $sth->fetchAll();
+}
+
+function getSensorValuesByDay($sensorID, $dayFrom, $dayTo) {
+    global $conn;
+    $sth = $conn->prepare('select min(time) as time, min(value), max(value), avg(value), stddev(value) from sensor_values where sensor_id = ?
+            group by sensor_id, date_trunc(\'day\', time) order by time');
+
+    $sth->execute( Array($sensorID));
+    return  $sth->fetchAll();
+}
+function getSensorDataYears($sensorID, $timeFrom, $timeTo) {
+    global $conn;
+    $sth = $conn->prepare("select distinct extract('year' from call_timestamp) as year from recordings where tgid = ? order by year");
+
+    $sth->execute(Array($sensorID));
+    return  $sth->fetchAll();
+}
+
+function getSensorDataMonths($sensorID, $timeFrom, $timeTo) {
+    global $conn;
+    $sth = $conn->prepare("select distinct extract('month' from call_timestamp) as month, extract('year' from call_timestamp) as year from recordings where tgid = ?  order by year, month");
+
+    $sth->execute(Array($sensorID));
+    return  $sth->fetchAll();
+}
+
+function getSensorDataDays($sensorID, $timeFrom, $timeTo) {
+    global $conn;
+    $sth = $conn->prepare("select distinct extract('day' from call_timestamp) as day, extract('month' from call_timestamp) as month, extract('year' from call_timestamp) as year from recordings where tgid = ?  order by year,month,day");
 
 
-function json_graph($sensorID, $timefrom, $timeto) {
-    $values = getSensorValuesByHour($sensorID, $timefrom, $timeto);
-    $label = $sensorID;
-    $data = Array();
-    $tzoffset = $this->get_timezone_offset("UTC");
-    foreach ($values as $value) {
-        $data[] = Array((strtotime($value['time']) + $tzoffset) * 1000, intval($value['avg']));
-    }
-    $this->output
-            ->set_content_type('application/json')
-            ->set_output(json_encode(Array("label" => $label, "data" => $data,
-                        "previous" => Array(
-                            "from" => $timefrom - (24 * 60 * 60),
-                            "to" => $timefrom)
-                        ,
-                        "next" => Array(
-                            "to" => $timeto + (24 * 60 * 60),
-                            "from" => $timeto)
-                            )
-                    ));
+    $sth->execute(Array($sensorID));
+    return  $sth->fetchAll();
 }
-
-function json_data_description($sensorID, $timefrom, $timeto) {
+$action = $_REQUEST['action'];
+    $sensorID = $_REQUEST['tgid'];
+$timefrom = $_REQUEST['from'];
+$timeto = $_REQUEST['to'];
+if ($action = "data_description") {
     $timefrom = strtotime($timefrom);
     $timeto = strtotime($timeto);
     $years = getSensorDataYears($sensorID, $timefrom, $timeto);
@@ -31,8 +53,29 @@
     $months = getSensorDataMonths($sensorID, $timefrom, $timeto);
     $days = getSensorDataDays($sensorID, $timefrom, $timeto);
 
-    return json_encode(Array("years" => $years, "months" => $months, "days" => $days
+    echo json_encode(Array("years" => $years, "months" => $months, "days" => $days
                     ));
+}
+
+
+if ($action = "graph") {
+    $values = getSensorValuesByHour($sensorID, $timefrom, $timeto);
+    $label = $sensorID;
+    $data = Array();
+    $tzoffset = get_timezone_offset("UTC");
+    foreach ($values as $value) {
+        $data[] = Array((strtotime($value['time']) + $tzoffset) * 1000, intval($value['avg']));
+    }
+   echo json_encode(Array("label" => $label, "data" => $data,
+            "previous" => Array(
+                "from" => $timefrom - (24 * 60 * 60),
+                "to" => $timefrom)
+        ,
+            "next" => Array(
+                "to" => $timeto + (24 * 60 * 60),
+                "from" => $timeto)
+        )
+    );
 }
 
 ?>

--- a/common.inc.php
+++ b/common.inc.php
@@ -1,5 +1,15 @@
 <?php
 date_default_timezone_set("Australia/Sydney");
+try {
+    $conn = new PDO("pgsql:dbname=scannr;user=postgres;password=snmc;host=localhost");
+    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+}
+catch(PDOException $e) {
+    die('Unable to connect to database server.');
+}
+catch(Exception $e) {
+    die('Unknown error in ' . __FILE__ . '.');
+}
 $basePath = "";
 $DATA_DIR = "./data";
 
@@ -22,96 +32,42 @@
     return $offset;
 }
 
-function getSensorValuesByHour($sensorID, $timeFrom, $timeTo) {
-    $sql = 'select min(call_timestamp) as time, count(*), min(length), max(length), avg(length), stddev(length) from recordings
-            group by tgid, date_trunc(\'hour\', call_timestamp) order by time';
 
-    $query = $this->db->query($sql, Array($sensorID, $timeFrom, $timeTo));
-    return $query->result_array();
-}
 
-function getSensorValuesByDay($sensorID, $dayFrom, $dayTo) {
-    $sql = 'select min(time) as time, min(value), max(value), avg(value), stddev(value) from sensor_values where sensor_id = ? 
-            group by sensor_id, date_trunc(\'day\', time) order by time';
 
-    $query = $this->db->query($sql, Array($sensorID));
-    return $query->result_array();
-}
-
-function getSensorDataYears($sensorID, $timeFrom, $timeTo) {
-    $sql = "select distinct extract('year' from call_timestamp) as year from recordings where tgid = ? order by year";
-
-    $query = $this->db->query($sql, Array($sensorID));
-    return $query->result_array();
-}
-
-function getSensorDataMonths($sensorID, $timeFrom, $timeTo) {
-    $sql = "select distinct extract('month' from time) as month, extract('year' from time) as year from sensor_values where sensor_id = ? order by year, month";
-
-    $query = $this->db->query($sql, Array($sensorID));
-    return $query->result_array();
-}
-
-function getSensorDataDays($sensorID, $timeFrom, $timeTo) {
-    $sql = "select distinct extract('day' from time) as day, extract('month' from time) as month, extract('year' from time) as year from sensor_values where sensor_id = ? order by year,month,day";
-
-    $query = $this->db->query($sql, Array($sensorID));
-    return $query->result_array();
-}
 
 function include_header($title) {
     global $basePath;
     ?>
-    <!DOCTYPE html>
+<!DOCTYPE html>
+<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
+<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
+<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
+<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
+<head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <title></title>
+    <meta name="description" content="">
+    <meta name="viewport" content="width=device-width">
 
-    <!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
-    <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
-    <!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
-    <!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
-    <!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
-        <head>
-            <meta charset="utf-8" />
+    <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
 
-            <!-- Set the viewport width to device width for mobile -->
-            <meta name="viewport" content="width=device-width" />
+    <link rel="stylesheet" href="css/normalize.css">
+    <link rel="stylesheet" href="css/main.css">
+    <script src="js/vendor/modernizr-2.6.1.min.js"></script>
+    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
+    <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.0.min.js"><\/script>')</script>
+    <script type="text/javascript" src="<?php echo $basePath ?>js/flotr2/flotr2.js"></script>
+    <script src="js/plugins.js"></script>
+    <script src="js/main.js"></script>
+</head>
+    <body>
+        <!--[if lt IE 7]>
+<p class="chromeframe">You are using an outdated browser. <a href="http://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p>
+<![endif]-->
 
-            <title><?php echo $title; ?> - Scannr</title>
-
-            <!-- Included CSS Files -->
-            <link rel="stylesheet" href="<?php echo $basePath ?>stylesheets/foundation.css">
-            <link rel="stylesheet" href="<?php echo $basePath ?>stylesheets/app.css">
-
-            <!--[if lt IE 9]>
-                    <link rel="stylesheet" href="<?php echo $basePath ?>stylesheets/ie.css">
-            <![endif]-->
-
-
-            <!-- IE Fix for HTML5 Tags -->
-            <!--[if lt IE 9]>
-                    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
-            <![endif]-->
-
-        </head>
-        <body xmlns:schema="http://schema.org/"  xmlns:foaf="http://xmlns.com/foaf/0.1/">
-
-            <!-- navBar -->
-            <div id="navbar" class="container">
-                <div class="row">
-                    <div class="four columns">
-                        <h1><a href="/">Disclosr</a></h1>
-                    </div>
-                    <div class="eight columns hide-on-phones">
-                        <strong class="right">
-                            <a href="getAgency.php">Agencies</a>
-                            <a href="about.php">About/FAQ</a>
-                        </strong>
-                    </div>
-                </div>
-            </div>
-            <!-- /navBar -->
-
-            <!-- container -->
-            <div class="container">
+<!-- Add your site or application content here -->
             <?php
             }
 
@@ -119,41 +75,19 @@
                 global $basePath;
                 ?>
 
-            </div>
-            <!-- container -->
 
-
-
-
-            <!-- Included JS Files -->
-            <script src="<?php echo $basePath; ?>js/foundation.js"></script>
-            <script src="<?php echo $basePath; ?>js/app.js"></script>
-            <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
-            <script>window.jQuery || document.write('<script src="js/jquery-1.8.2.min.js"><\/script>')</script>
-
-            <script type="text/javascript" src="<?php echo $basePath ?>js/flotr2/flotr2.js"></script>
-    <?php
-    if (strpos($_SERVER['SERVER_NAME'], ".gs")) {
-        ?>
-                <script type="text/javascript">
-
-                    var _gaq = _gaq || [];
-                    _gaq.push(['_setAccount', 'UA-12341040-2']);
-                    _gaq.push(['_trackPageview']);
-
-                    (function() {
-                        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
-                        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
-                        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
-                    })();
-
-                </script>
-
-            </body>
-        </html>
+            <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
+            <script>
+                var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
+                (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
+                    g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
+                    s.parentNode.insertBefore(g,s)}(document,'script'));
+            </script>
+    </body>
+</html>
 
     <?php
-    }
+
 }
 
 

file:b/cron.php (new)
--- /dev/null
+++ b/cron.php
@@ -1,1 +1,9 @@
+<?php
+/*- scheduled tasks
+- combine recordings into conversations 
+    - using ffmpeg
+    - conversations and recordings_to_conversations tables
+- remove all other wav files
+- delete old uninteresting conversations*/
+?>
 

file:a/db.sql -> file:b/db.sql
--- a/db.sql
+++ b/db.sql
@@ -4,7 +4,7 @@
 
 -- Dumped from database version 9.1.2
 -- Dumped by pg_dump version 9.1.2
--- Started on 2012-10-08 22:16:52
+-- Started on 2012-10-14 19:22:29
 
 SET statement_timeout = 0;
 SET client_encoding = 'UTF8';
@@ -3618,6 +3618,7619 @@
 2012-10-02-1349173673.11-demo.wav	30004	L GEORG	CanberraBlackMnt	2012-10-02 20:27:57.631+10	379652
 2012-10-02-1349174240.8-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-02 20:37:23.29+10	209534
 2012-10-02-1349174599.95-demo.wav	30004	L GEORG	CanberraBlackMnt	2012-10-02 20:43:25.506+10	466904
+2012-10-08-1349699874.2-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:37:56.958+11	231368
+2012-10-08-1349699877.42-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:37:59.927+11	213128
+2012-10-08-1349699880.15-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:38:02.993+11	239752
+2012-10-08-1349699883.11-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:38:06.839+11	315294
+2012-10-08-1349699887.1-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:38:15.471+11	704644
+2012-10-08-1349699896.83-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:38:26.594+11	821384
+2012-10-08-1349699906.73-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:38:29.213+11	211080
+2012-10-08-1349699909.68-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:38:33.167+11	295048
+2012-10-08-1349699913.28-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:38:35.817+11	215176
+2012-10-08-1349699917.94-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:38:58.011+11	1675536
+2012-10-08-1349699939.38-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:39:02.969+11	303240
+2012-10-08-1349700103.59-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:41:46.553+11	248162
+2012-10-08-1349700107.32-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:41:55.649+11	700552
+2012-10-08-1349700116.15-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:41:59.895+11	315528
+2012-10-08-1349700120.94-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:42:04.582+11	307328
+2012-10-08-1349700152.0-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:42:35.965+11	331912
+2012-10-08-1349700156.13-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:42:38.721+11	217224
+2012-10-08-1349700160.59-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:42:56.291+11	1319048
+2012-10-08-1349700176.65-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:43:00.057+11	286856
+2012-10-08-1349700270.5-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:44:33.009+11	210924
+2012-10-08-1349700275.12-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:44:42.248+11	598152
+2012-10-08-1349700282.44-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:44:45.106+11	225274
+2012-10-08-1349700442.35-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:47:25.405+11	251234
+2012-10-08-1349700446.71-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:47:29.445+11	223368
+2012-10-08-1349700449.64-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:47:32.942+11	278664
+2012-10-08-1349700680.1-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:51:22.612+11	208966
+2012-10-08-1349700683.66-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:51:27.154+11	290498
+2012-10-08-1349700956.88-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:56:00.039+11	264458
+2012-10-08-1349700960.19-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:56:07.384+11	604296
+2012-10-08-1349700967.52-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-08 23:56:11.519+11	338056
+2012-10-09-1349701268.66-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:01:11.178+11	210452
+2012-10-09-1349701271.48-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:01:13.724+11	188552
+2012-10-09-1349701777.66-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:09:40.176+11	209640
+2012-10-09-1349702668.55-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:24:31.109+11	210804
+2012-10-09-1349702685.87-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:24:48.372+11	206984
+2012-10-09-1349702689.37-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:24:56.84+11	620764
+2012-10-09-1349702697.28-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:25:00.036+11	231560
+2012-10-09-1349703088.38-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:31:30.892+11	210840
+2012-10-09-1349703091.11-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:31:33.322+11	186504
+2012-10-09-1349703093.63-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:31:46.363+11	1069192
+2012-10-09-1349703416.33-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:36:59.837+11	291010
+2012-10-09-1349703420.74-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:37:50.804+11	4210824
+2012-10-09-1349703471.45-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:37:55.254+11	319624
+2012-10-09-1349703476.12-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:38:01.174+11	421954
+2012-10-09-1349703618.09-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:40:20.603+11	209510
+2012-10-09-1349703915.88-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:45:18.858+11	248944
+2012-10-09-1349703919.07-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:45:24.362+11	444552
+2012-10-09-1349703924.59-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:45:27.574+11	249992
+2012-10-09-1349704461.95-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:54:24.833+11	240828
+2012-10-09-1349704465.21-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 00:54:27.668+11	206984
+2012-10-09-1349704879.67-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:01:22.193+11	210644
+2012-10-09-1349704883.69-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:01:26.012+11	194696
+2012-10-09-1349704888.43-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:01:38.19+11	821384
+2012-10-09-1349704898.74-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:01:43.831+11	428168
+2012-10-09-1349705113.12-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:05:15.744+11	213682
+2012-10-09-1349705133.07-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:05:36.421+11	280712
+2012-10-09-1349705137.69-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:05:47.157+11	791474
+2012-10-09-1349705148.17-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:05:51.724+11	294418
+2012-10-09-1349705194.19-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:06:36.751+11	214774
+2012-10-09-1349705199.13-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:06:42.768+11	305288
+2012-10-09-1349705203.0-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:06:45.995+11	249992
+2012-10-09-1349705236.47-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:07:21.015+11	381494
+2012-10-09-1349705241.29-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:07:23.981+11	225416
+2012-10-09-1349705244.24-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:07:28.311+11	342152
+2012-10-09-1349705248.99-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:07:32.175+11	264220
+2012-10-09-1349705336.29-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:08:59.34+11	254998
+2012-10-09-1349705341.32-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:09:05.893+11	385160
+2012-10-09-1349705346.4-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:09:09.847+11	288904
+2012-10-09-1349705493.26-demo.wav	10106	SYD 7	CanberraMtAinsli	2012-10-09 01:11:37.695+11	372252