+
+
+\n";
+echo "var eventMonitorId = [];\n";
+echo "var eventId = [];\n";
+echo "var eventStartTimeSecs = [];\n";
+echo "var eventEndTimeSecs = [];\n";
+echo "var eventPath = [];\n";
+echo "var eventFrames = [];\n"; // this is going to presume all frames equal durationlength
+
+// Because we might not have time as the criteria, figure out the min/max time when we run the query
+
+$minTimeSecs = strtotime("2036-01-01 01:01:01");
+$maxTimeSecs = strtotime("1950-01-01 01:01:01");
+
+$index=0;
+$anyAlarms=false;
+$eventsMonitorsFound = array(); // this will just flag which ones found
+
+foreach( dbFetchAll( $eventsSql ) as $event )
+{
+ if( $minTimeSecs > strtotime($event['StartTime'])) $minTimeSecs=strtotime($event['StartTime']);
+ if( $maxTimeSecs < strtotime($event['CalcEndTime'])) $maxTimeSecs=strtotime($event['CalcEndTime']);
+ echo "eventMonitorId[$index]=" . $event['MonitorId'] . "; eventId[$index]=" . $event['Id'] . "; ";
+ echo "eventStartTimeSecs[$index]=" . strtotime($event['StartTime']) . "; eventEndTimeSecs[$index]=" . strtotime($event['CalcEndTime']) . "; ";
+ echo "eventFrames[$index]=" . $event['Frames'] . "; ";
+
+ if ( ZM_USE_DEEP_STORAGE )
+ echo "eventPath[$index] = \"events/" . $event['MonitorId'] . "/" . strftime("%y/%m/%d/%H/%M/%S", strtotime($event['StartTime'])) . "/\";" ;
+ else
+ echo "eventPath[$index] = \"events/" . $event['MonitorId'] . "/" . $event['Id'] . "/\";" ;
+ $eventsMonitorsFound[$event['MonitorId']] = true;
+ $index=$index+1;
+ if($event['MaxScore']>0)
+ $anyAlarms=true;
+ echo "\n";
+}
+
+if($index == 0) // if there is no data set the min/max to the passed in values
+{
+ if(isset($minTime) && isset($maxTime))
+ {
+ $minTimeSecs = strtotime($minTime);
+ $maxTimeSecs = strtotime($maxTime);
+ }
+ else // this is the case of no passed in times AND no data -- just set something arbitrary
+ {
+ $minTimeSecs=strtotime('1950-06-01 01:01:01'); // random time so there's something to display
+ $maxTimeSecs=strtotime('2020-06-02 02:02:02');
+ }
+}
+
+// We only reset the calling time if there was no calling time
+if(!isset($minTime) || !isset($maxTime))
+{
+ $maxTime = strftime($maxTimeSecs);
+ $minTime = strftime($minTimeSecs);
+}
+else
+{
+ $minTimeSecs = strtotime($minTime);
+ $maxTimeSecs = strtotime($maxTime);
+}
+
+// If we had any alarms in those events, this builds the list of all alarm frames (thought for later - should these be ranges, so as to minimize list if very long?)
+
+echo "var frameMonitorId = [];\n";
+echo "var frameTimeStampSecs = [];\n";
+echo "var frameScore = [];\n";
+$maxScore=0;
+$index=0;
+
+if($anyAlarms)
+ foreach( dbFetchAll ($frameSql) as $frame )
+ {
+ echo " frameMonitorId[$index]=" . $frame['MonitorId'] . ";";
+ echo " frameTimeStampSecs[$index]=" . strtotime($frame['TimeStamp']) . ";";
+ echo " frameScore[$index]=" . $frame['Score'] . ";\n";
+ if($maxScore <= $frame['Score'])
+ $maxScore=$frame['Score'];
+ $index += 1;
+ }
+
+// This is where we have to display the canvases -- AFTER determining which monitors we use (above in events) and BEFORE we loop through them to cache the objects
+// This splits up the javascript and html a bit, but it's a lot simpler than trying in php to cache one while completing the other
+
+// Monitor images - these had to be loaded after the monitors used were determined (after loading events)
+
+echo "\n";
+
+foreach ($monitors as $m)
+{
+ if(!empty($eventsMonitorsFound[$m['Id']])) // only save the monitor if it's part of these events
+ {
+ echo "\n";
+ }
+}
+echo "
+
+