2013-05-02 22:20:06 +08:00
< ? php
//
// ZoneMinder web timeline view file, $Date$, $Revision$
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
2016-12-26 23:23:16 +08:00
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2013-05-02 22:20:06 +08:00
//
2018-04-21 02:25:38 +08:00
if ( ! canView ( 'Events' ) ) {
2017-05-19 02:04:24 +08:00
$view = 'error' ;
return ;
2013-05-02 22:20:06 +08:00
}
2018-04-21 02:25:38 +08:00
foreach ( getSkinIncludes ( 'includes/timeline_functions.php' ) as $includeFile )
2017-05-19 02:04:24 +08:00
require_once $includeFile ;
2013-05-02 22:20:06 +08:00
//
// Date/time formats used in charts
//
// These are the time axis range text. The first of each pair is the start date/time
// and the second is the last so often contains additional information
//
// When the chart range is years
2017-05-19 03:11:26 +08:00
define ( 'STRF_TL_AXIS_RANGE_YEAR1' , '%b %Y' );
define ( 'STRF_TL_AXIS_RANGE_YEAR2' , STRF_TL_AXIS_RANGE_YEAR1 );
2013-05-02 22:20:06 +08:00
// When the chart range is months
2017-07-14 05:34:45 +08:00
define ( 'STRF_TL_AXIS_RANGE_MONTH1' , '%b' );
define ( 'STRF_TL_AXIS_RANGE_MONTH2' , STRF_TL_AXIS_RANGE_MONTH1 . ' %Y' );
2013-05-02 22:20:06 +08:00
// When the chart range is days
2017-07-14 05:34:45 +08:00
define ( 'STRF_TL_AXIS_RANGE_DAY1' , '%d' );
define ( 'STRF_TL_AXIS_RANGE_DAY2' , STRF_TL_AXIS_RANGE_DAY1 . ' %b %Y' );
2013-05-02 22:20:06 +08:00
// When the chart range is less than a day
2017-07-14 05:34:45 +08:00
define ( 'STRF_TL_AXIS_RANGE_TIME1' , '%H:%M' );
define ( 'STRF_TL_AXIS_RANGE_TIME2' , STRF_TL_AXIS_RANGE_TIME1 . ', %d %b %Y' );
2013-05-02 22:20:06 +08:00
//
// These are the time axis tick labels
//
2019-09-29 02:23:23 +08:00
define ( 'STRF_TL_AXIS_LABEL_YEAR' , '%Y' );
define ( 'STRF_TL_AXIS_LABEL_MONTH' , '%M' );
define ( 'STRF_TL_AXIS_LABEL_WEEK' , '%d/%m' );
define ( 'STRF_TL_AXIS_LABEL_DAY' , '%d' );
define ( 'STRF_TL_AXIS_LABEL_4HOUR' , '%H:00' );
define ( 'STRF_TL_AXIS_LABEL_HOUR' , '%H:00' );
define ( 'STRF_TL_AXIS_LABEL_10MINUTE' , '%H:%M' );
define ( 'STRF_TL_AXIS_LABEL_MINUTE' , '%H:%M' );
define ( 'STRF_TL_AXIS_LABEL_10SECOND' , '%S' );
define ( 'STRF_TL_AXIS_LABEL_SECOND' , '%S' );
$mouseover = isset ( $_REQUEST [ 'mouseover' ]) ? $_REQUEST [ 'mouseover' ] : true ;
$mode = isset ( $_REQUEST [ 'mode' ]) ? $_REQUEST [ 'mode' ] : 'overlay' ;
2013-05-02 22:20:06 +08:00
$minEventWidth = 3 ;
$maxEventWidth = 6 ;
$chart = array (
2017-07-14 05:34:45 +08:00
'width' => 700 ,
'height' => 460 ,
'image' => array (
'width' => 264 ,
'height' => 220 ,
'topOffset' => 20 ,
2017-05-19 03:11:26 +08:00
),
2017-07-14 05:34:45 +08:00
'imageText' => array (
'width' => 400 ,
'height' => 30 ,
'topOffset' => 20 ,
2017-05-19 03:11:26 +08:00
),
2017-07-14 05:34:45 +08:00
'graph' => array (
'width' => 600 ,
'height' => 160 ,
'topOffset' => 30 ,
2017-05-19 03:11:26 +08:00
),
2017-07-14 05:34:45 +08:00
'title' => array (
'topOffset' => 50
2017-05-19 03:11:26 +08:00
),
2017-07-14 05:34:45 +08:00
'key' => array (
'topOffset' => 50
2017-05-19 03:11:26 +08:00
),
2017-07-14 05:34:45 +08:00
'axes' => array (
'x' => array (
'height' => 20 ,
2017-05-19 03:11:26 +08:00
),
2017-07-14 05:34:45 +08:00
'y' => array (
'width' => 30 ,
2017-05-19 03:11:26 +08:00
),
2013-05-02 22:20:06 +08:00
),
2017-07-14 05:34:45 +08:00
'grid' => array (
'x' => array (
'major' => array (
'max' => 12 ,
'min' => 4 ,
2013-05-02 22:20:06 +08:00
),
2017-07-14 05:34:45 +08:00
'minor' => array (
'max' => 48 ,
'min' => 12 ,
2013-05-02 22:20:06 +08:00
),
2017-05-19 03:11:26 +08:00
),
2017-07-14 05:34:45 +08:00
'y' => array (
'major' => array (
'max' => 8 ,
'min' => 1 ,
2013-05-02 22:20:06 +08:00
),
2017-07-14 05:34:45 +08:00
'minor' => array (
'max' => 0 ,
'min' => 0 ,
2013-05-02 22:20:06 +08:00
),
2017-05-19 03:11:26 +08:00
),
2013-05-02 22:20:06 +08:00
),
);
$monitors = array ();
2017-05-19 23:00:37 +08:00
# The as E, and joining with Monitors is required for the filterSQL filters.
2017-05-19 03:11:26 +08:00
$rangeSql = 'SELECT min(E.StartTime) AS MinTime, max(E.EndTime) AS MaxTime FROM Events AS E INNER JOIN Monitors AS M ON (E.MonitorId = M.Id) WHERE NOT isnull(E.StartTime) AND NOT isnull(E.EndTime)' ;
2018-04-21 02:25:38 +08:00
$eventsSql = 'SELECT E.* FROM Events AS E INNER JOIN Monitors AS M ON (E.MonitorId = M.Id) WHERE NOT isnull(StartTime)' ;
2019-09-29 02:23:23 +08:00
$eventIdsSql = 'SELECT E.Id FROM Events AS E INNER JOIN Monitors AS M ON (E.MonitorId = M.Id) WHERE NOT isnull(StartTime)' ;
2018-04-21 01:10:38 +08:00
$eventsValues = array ();
2013-05-02 22:20:06 +08:00
2017-05-19 02:04:24 +08:00
if ( ! empty ( $user [ 'MonitorIds' ]) ) {
$monFilterSql = ' AND MonitorId IN (' . $user [ 'MonitorIds' ] . ')' ;
2013-05-02 22:20:06 +08:00
2017-05-19 02:04:24 +08:00
$rangeSql .= $monFilterSql ;
$eventsSql .= $monFilterSql ;
2019-09-29 02:23:23 +08:00
$eventIdsSql .= $monFilterSql ;
2013-05-02 22:20:06 +08:00
}
2019-09-29 02:23:23 +08:00
$tree = false ;
2013-05-02 22:20:06 +08:00
if ( isset ( $_REQUEST [ 'filter' ]) )
2018-04-21 01:10:38 +08:00
$tree = parseFilterToTree ( $_REQUEST [ 'filter' ][ 'Query' ]);
2013-05-02 22:20:06 +08:00
if ( isset ( $_REQUEST [ 'range' ]) )
2017-05-19 03:11:26 +08:00
$range = validHtmlStr ( $_REQUEST [ 'range' ]);
2013-05-02 22:20:06 +08:00
if ( isset ( $_REQUEST [ 'minTime' ]) )
2017-05-19 03:11:26 +08:00
$minTime = validHtmlStr ( $_REQUEST [ 'minTime' ]);
2013-05-02 22:20:06 +08:00
if ( isset ( $_REQUEST [ 'midTime' ]) )
2017-05-19 03:11:26 +08:00
$midTime = validHtmlStr ( $_REQUEST [ 'midTime' ]);
2013-05-02 22:20:06 +08:00
if ( isset ( $_REQUEST [ 'maxTime' ]) )
2017-05-19 03:11:26 +08:00
$maxTime = validHtmlStr ( $_REQUEST [ 'maxTime' ]);
2013-05-02 22:20:06 +08:00
2020-05-15 23:33:10 +08:00
if ( isset ( $range ) and validInt ( $range ) ) {
2017-05-19 03:11:26 +08:00
$halfRange = ( int )( $range / 2 );
if ( isset ( $midTime ) ) {
$midTimeT = strtotime ( $midTime );
$minTimeT = $midTimeT - $halfRange ;
$maxTimeT = $midTimeT + $halfRange ;
if ( ! ( $range % 1 ) ) {
$maxTimeT -- ;
2013-05-02 22:20:06 +08:00
}
2018-04-21 02:25:38 +08:00
$minTime = strftime ( STRF_FMT_DATETIME_DB , $minTimeT );
$maxTime = strftime ( STRF_FMT_DATETIME_DB , $maxTimeT );
2017-05-19 03:11:26 +08:00
} elseif ( isset ( $minTime ) ) {
2013-05-02 22:20:06 +08:00
$minTimeT = strtotime ( $minTime );
2017-05-19 03:11:26 +08:00
$maxTimeT = $minTimeT + $range ;
2013-05-02 22:20:06 +08:00
$midTimeT = $minTimeT + $halfRange ;
2018-04-21 02:25:38 +08:00
$midTime = strftime ( STRF_FMT_DATETIME_DB , $midTimeT );
$maxTime = strftime ( STRF_FMT_DATETIME_DB , $maxTimeT );
2017-05-19 03:11:26 +08:00
} elseif ( isset ( $maxTime ) ) {
2013-05-02 22:20:06 +08:00
$maxTimeT = strtotime ( $maxTime );
2017-05-19 03:11:26 +08:00
$minTimeT = $maxTimeT - $range ;
2013-05-02 22:20:06 +08:00
$midTimeT = $minTimeT + $halfRange ;
2018-04-21 02:25:38 +08:00
$minTime = strftime ( STRF_FMT_DATETIME_DB , $minTimeT );
$midTime = strftime ( STRF_FMT_DATETIME_DB , $midTimeT );
2017-05-19 03:11:26 +08:00
}
} elseif ( isset ( $minTime ) && isset ( $maxTime ) ) {
$minTimeT = strtotime ( $minTime );
$maxTimeT = strtotime ( $maxTime );
$range = ( $maxTimeT - $minTimeT ) + 1 ;
$halfRange = ( int )( $range / 2 );
$midTimeT = $minTimeT + $halfRange ;
2018-04-21 02:25:38 +08:00
$midTime = strftime ( STRF_FMT_DATETIME_DB , $midTimeT );
2013-05-02 22:20:06 +08:00
}
2017-05-19 02:04:24 +08:00
if ( isset ( $minTime ) && isset ( $maxTime ) ) {
2017-05-19 03:11:26 +08:00
$tempMinTime = $tempMaxTime = $tempExpandable = false ;
2018-04-21 01:10:38 +08:00
extractDatetimeRange ( $tree , $tempMinTime , $tempMaxTime , $tempExpandable );
$filterSql = parseTreeToSQL ( $tree );
2013-05-02 22:20:06 +08:00
2017-05-19 03:11:26 +08:00
if ( $filterSql ) {
2018-04-21 01:10:38 +08:00
$filterSql = " AND $filterSql " ;
2017-05-19 03:11:26 +08:00
$eventsSql .= $filterSql ;
2019-09-29 02:23:23 +08:00
$eventIdsSql .= $filterSql ;
2017-05-19 03:11:26 +08:00
}
2017-05-19 02:04:24 +08:00
} else {
2018-04-21 01:10:38 +08:00
$filterSql = parseTreeToSQL ( $tree );
2017-05-19 03:11:26 +08:00
$tempMinTime = $tempMaxTime = $tempExpandable = false ;
2018-04-21 01:10:38 +08:00
extractDatetimeRange ( $tree , $tempMinTime , $tempMaxTime , $tempExpandable );
2017-05-19 03:11:26 +08:00
if ( $filterSql ) {
2018-04-21 01:10:38 +08:00
$filterSql = " AND $filterSql " ;
2017-05-19 03:11:26 +08:00
$rangeSql .= $filterSql ;
$eventsSql .= $filterSql ;
2019-09-29 02:23:23 +08:00
$eventIdsSql .= $filterSql ;
2017-05-19 03:11:26 +08:00
}
2013-05-02 22:20:06 +08:00
2017-05-19 03:11:26 +08:00
if ( ! isset ( $minTime ) || ! isset ( $maxTime ) ) {
// Dynamically determine range
2018-04-21 01:10:38 +08:00
$row = dbFetchOne ( $rangeSql );
2020-03-02 00:07:31 +08:00
if ( $row ) {
if ( ! isset ( $minTime ) )
$minTime = $row [ 'MinTime' ];
if ( ! isset ( $maxTime ) )
$maxTime = $row [ 'MaxTime' ];
} else {
# Errors will be reported by db functions
}
2017-05-19 03:11:26 +08:00
}
2013-05-02 22:20:06 +08:00
2017-05-19 03:11:26 +08:00
if ( empty ( $minTime ) )
$minTime = $tempMinTime ;
if ( empty ( $maxTime ) )
$maxTime = $tempMaxTime ;
if ( empty ( $maxTime ) )
2018-04-21 01:10:38 +08:00
$maxTime = 'now' ;
2017-05-19 03:11:26 +08:00
$minTimeT = strtotime ( $minTime );
$maxTimeT = strtotime ( $maxTime );
$range = ( $maxTimeT - $minTimeT ) + 1 ;
$halfRange = ( int )( $range / 2 );
$midTimeT = $minTimeT + $halfRange ;
$midTime = strftime ( STRF_FMT_DATETIME_DB , $midTimeT );
2013-05-02 22:20:06 +08:00
}
//echo "MnT: $tempMinTime, MxT: $tempMaxTime, ExP: $tempExpandable<br>";
2017-05-19 02:04:24 +08:00
if ( $tree ) {
2018-04-21 02:25:38 +08:00
appendDatetimeRange ( $tree , $minTime , $maxTime );
2013-05-02 22:20:06 +08:00
2018-04-21 02:25:38 +08:00
$filterQuery = parseTreeToQuery ( $tree );
2017-05-19 02:04:24 +08:00
} else {
2017-05-19 03:11:26 +08:00
$filterQuery = false ;
2013-05-02 22:20:06 +08:00
}
$scales = array (
2018-04-21 01:10:38 +08:00
array ( 'name' => 'year' , 'factor' => 60 * 60 * 24 * 365 , 'align' => 1 , 'zoomout' => 2 , 'label' => STRF_TL_AXIS_LABEL_YEAR ),
array ( 'name' => 'month' , 'factor' => 60 * 60 * 24 * 30 , 'align' => 1 , 'zoomout' => 12 , 'label' => STRF_TL_AXIS_LABEL_MONTH ),
2019-09-29 02:23:23 +08:00
array ( 'name' => 'week' , 'factor' => 60 * 60 * 24 * 7 , 'align' => 1 , 'zoomout' => 4.25 , 'label' => STRF_TL_AXIS_LABEL_WEEK , 'labelCheck' => '%W' ),
2018-04-21 01:10:38 +08:00
array ( 'name' => 'day' , 'factor' => 60 * 60 * 24 , 'align' => 1 , 'zoomout' => 7 , 'label' => STRF_TL_AXIS_LABEL_DAY ),
2019-10-23 21:50:49 +08:00
array ( 'name' => 'hour4' , 'factor' => 60 * 60 , 'align' => 4 , 'zoomout' => 6 , 'label' => STRF_TL_AXIS_LABEL_4HOUR , 'labelCheck' => '%H' ),
2019-09-29 02:23:23 +08:00
array ( 'name' => 'hour' , 'factor' => 60 * 60 , 'align' => 1 , 'zoomout' => 4 , 'label' => STRF_TL_AXIS_LABEL_HOUR , 'labelCheck' => '%H' ),
2019-10-23 21:50:49 +08:00
array ( 'name' => 'minute10' , 'factor' => 60 , 'align' => 10 , 'zoomout' => 6 , 'label' => STRF_TL_AXIS_LABEL_10MINUTE , 'labelCheck' => '%M' ),
2019-09-29 02:23:23 +08:00
array ( 'name' => 'minute' , 'factor' => 60 , 'align' => 1 , 'zoomout' => 10 , 'label' => STRF_TL_AXIS_LABEL_MINUTE , 'labelCheck' => '%M' ),
2019-10-23 21:50:49 +08:00
array ( 'name' => 'second10' , 'factor' => 1 , 'align' => 10 , 'zoomout' => 6 , 'label' => STRF_TL_AXIS_LABEL_10SECOND ),
2018-04-21 01:10:38 +08:00
array ( 'name' => 'second' , 'factor' => 1 , 'align' => 1 , 'zoomout' => 10 , 'label' => STRF_TL_AXIS_LABEL_SECOND ),
2013-05-02 22:20:06 +08:00
);
2018-04-21 02:25:38 +08:00
$majXScale = getDateScale ( $scales , $range , $chart [ 'grid' ][ 'x' ][ 'major' ][ 'min' ], $chart [ 'grid' ][ 'x' ][ 'major' ][ 'max' ]);
2013-05-02 22:20:06 +08:00
// Adjust the range etc for scale
$minTimeT -= $minTimeT % ( $majXScale [ 'factor' ] * $majXScale [ 'align' ]);
2018-04-21 02:25:38 +08:00
$minTime = strftime ( STRF_FMT_DATETIME_DB , $minTimeT );
2013-05-02 22:20:06 +08:00
$maxTimeT += (( $majXScale [ 'factor' ] * $majXScale [ 'align' ]) - $maxTimeT % ( $majXScale [ 'factor' ] * $majXScale [ 'align' ])) - 1 ;
if ( $maxTimeT > time () )
2017-05-19 03:11:26 +08:00
$maxTimeT = time ();
2018-04-21 02:25:38 +08:00
$maxTime = strftime ( STRF_FMT_DATETIME_DB , $maxTimeT );
2013-05-02 22:20:06 +08:00
$range = ( $maxTimeT - $minTimeT ) + 1 ;
$halfRange = ( int )( $range / 2 );
$midTimeT = $minTimeT + $halfRange ;
2018-04-21 02:25:38 +08:00
$midTime = strftime ( STRF_FMT_DATETIME_DB , $midTimeT );
2013-05-02 22:20:06 +08:00
2017-05-19 02:04:24 +08:00
if ( isset ( $minTime ) && isset ( $maxTime ) ) {
2018-04-21 01:10:38 +08:00
$eventsSql .= " AND EndTime >= ' $minTime ' AND StartTime <= ' $maxTime ' " ;
2019-09-29 02:23:23 +08:00
$eventIdsSql .= " AND EndTime >= ' $minTime ' AND StartTime <= ' $maxTime ' " ;
2013-05-02 22:20:06 +08:00
}
2019-09-29 02:23:23 +08:00
if ( 0 ) {
$framesByEventId = array ();
2018-04-21 01:10:38 +08:00
$eventsSql .= ' ORDER BY E.Id ASC' ;
2019-09-29 02:23:23 +08:00
$framesSql = " SELECT EventId,FrameId,Delta,Score FROM Frames WHERE EventId IN( $eventIdsSql ) AND Score > 0 ORDER BY Score DESC " ;
$frames_result = dbQuery ( $framesSql );
while ( $row = $frames_result -> fetch ( PDO :: FETCH_ASSOC ) ) {
if ( ! isset ( $framesByEventId [ $row [ 'EventId' ]]) ) {
$framesByEventId [ $row [ 'EventId' ]] = array ();
}
$framesByEventId [ $row [ 'EventId' ]][] = $row ;
}
}
2013-05-02 22:20:06 +08:00
$chart [ 'data' ] = array (
2017-07-14 05:34:45 +08:00
'x' => array (
2018-04-21 02:25:38 +08:00
'lo' => strtotime ( $minTime ),
'hi' => strtotime ( $maxTime ),
2017-05-19 03:11:26 +08:00
),
2017-07-14 05:34:45 +08:00
'y' => array (
'lo' => 0 ,
'hi' => 0 ,
2017-05-19 03:11:26 +08:00
)
2013-05-02 22:20:06 +08:00
);
$chart [ 'data' ][ 'x' ][ 'range' ] = ( $chart [ 'data' ][ 'x' ][ 'hi' ] - $chart [ 'data' ][ 'x' ][ 'lo' ]) + 1 ;
$chart [ 'data' ][ 'x' ][ 'density' ] = $chart [ 'data' ][ 'x' ][ 'range' ] / $chart [ 'graph' ][ 'width' ];
$monEventSlots = array ();
$monFrameSlots = array ();
2019-09-18 23:10:40 +08:00
$events_result = dbQuery ( $eventsSql );
if ( ! $events_result ) {
2020-03-02 00:07:31 +08:00
ZM\Fatal ( 'SQL-ERR' );
2017-07-14 05:34:45 +08:00
return ;
}
2019-09-29 02:23:23 +08:00
$max_aspect_ratio = 0 ;
while ( $event = $events_result -> fetch ( PDO :: FETCH_ASSOC ) ) {
if ( ! isset ( $monitors [ $event [ 'MonitorId' ]]) ) {
$monitor = $monitors [ $event [ 'MonitorId' ]] = ZM\Monitor :: find_one ( array ( 'Id' => $event [ 'MonitorId' ]));
$monEventSlots [ $event [ 'MonitorId' ]] = array ();
$monFrameSlots [ $event [ 'MonitorId' ]] = array ();
$aspect_ratio = round ( $monitor -> Width () / $monitor -> Height (), 2 );
if ( $aspect_ratio > $max_aspect_ratio )
$max_aspect_ratio = $aspect_ratio ;
}
2017-05-19 03:11:26 +08:00
2019-09-29 02:23:23 +08:00
$currEventSlots = & $monEventSlots [ $event [ 'MonitorId' ]];
$currFrameSlots = & $monFrameSlots [ $event [ 'MonitorId' ]];
2017-05-19 03:11:26 +08:00
2019-09-29 02:23:23 +08:00
$startTimeT = strtotime ( $event [ 'StartTime' ]);
$startIndex = $rawStartIndex = ( int )(( $startTimeT - $chart [ 'data' ][ 'x' ][ 'lo' ]) / $chart [ 'data' ][ 'x' ][ 'density' ]);
if ( $startIndex < 0 )
$startIndex = 0 ;
2017-05-19 03:11:26 +08:00
2019-09-29 02:23:23 +08:00
if ( isset ( $event [ 'EndTime' ]) )
$endTimeT = strtotime ( $event [ 'EndTime' ]);
else
$endTimeT = time ();
$endIndex = $rawEndIndex = ( int )(( $endTimeT - $chart [ 'data' ][ 'x' ][ 'lo' ]) / $chart [ 'data' ][ 'x' ][ 'density' ]);
2017-05-19 03:11:26 +08:00
2019-09-29 02:23:23 +08:00
if ( $endIndex >= $chart [ 'graph' ][ 'width' ] )
$endIndex = $chart [ 'graph' ][ 'width' ] - 1 ;
2017-05-19 03:11:26 +08:00
2019-09-29 02:23:23 +08:00
for ( $i = $startIndex ; $i <= $endIndex ; $i ++ ) {
if ( ! isset ( $currEventSlots [ $i ]) ) {
if ( $rawStartIndex == $rawEndIndex ) {
$offset = 1 ;
2017-05-19 03:11:26 +08:00
} else {
2019-09-29 02:23:23 +08:00
$offset = 1 + ( $event [ 'Frames' ] ? (( int )(( $event [ 'Frames' ] - 1 ) * (( $i - $rawStartIndex ) / ( $rawEndIndex - $rawStartIndex )))) : 0 );
2017-05-19 03:11:26 +08:00
}
2019-09-29 02:23:23 +08:00
$currEventSlots [ $i ] = array ( 'count' => 0 , 'width' => 1 , 'offset' => $offset , 'event' => $event );
} else {
$currEventSlots [ $i ][ 'count' ] ++ ;
2013-05-02 22:20:06 +08:00
}
2019-09-29 02:23:23 +08:00
}
if ( $event [ 'MaxScore' ] > 0 ) {
if ( $startIndex == $endIndex ) {
# Only fills 1 slot, so just get the max Score
$framesSql = 'SELECT FrameId, Score FROM Frames WHERE EventId = ? AND Score > 0 ORDER BY Score DESC LIMIT 1' ;
$frame = dbFetchOne ( $framesSql , NULL , array ( $event [ 'Id' ]));
2017-10-17 23:50:47 +08:00
2019-09-29 02:23:23 +08:00
$i = $startIndex ;
if ( ! isset ( $currFrameSlots [ $i ]) ) {
$currFrameSlots [ $i ] = array ( 'count' => 1 , 'value' => $event [ 'MaxScore' ], 'event' => $event , 'frame' => $frame );
} else {
$currFrameSlots [ $i ][ 'count' ] ++ ;
if ( $event [ 'MaxScore' ] > $currFrameSlots [ $i ][ 'value' ] ) {
$currFrameSlots [ $i ][ 'value' ] = $event [ 'MaxScore' ];
$currFrameSlots [ $i ][ 'event' ] = $event ;
$currFrameSlots [ $i ][ 'frame' ] = $frame ;
}
}
if ( $event [ 'MaxScore' ] > $chart [ 'data' ][ 'y' ][ 'hi' ] ) {
$chart [ 'data' ][ 'y' ][ 'hi' ] = $event [ 'MaxScore' ];
}
} else {
# Fills multiple Slots, so need multiple scores to generate the graph over multiple slots.
$framesSql = 'SELECT FrameId,Delta,Score FROM Frames WHERE EventId = ? AND Score > 0' ;
$result = dbQuery ( $framesSql , array ( $event [ 'Id' ]));
while ( $frame = dbFetchNext ( $result ) ) {
#foreach ( $framesByEventId[$event['Id']] as $frame ) {
$frameTimeT = $startTimeT + $frame [ 'Delta' ];
$frameIndex = ( int )(( $frameTimeT - $chart [ 'data' ][ 'x' ][ 'lo' ]) / $chart [ 'data' ][ 'x' ][ 'density' ]);
if ( $frameIndex < 0 )
continue ;
if ( $frameIndex >= $chart [ 'graph' ][ 'width' ] )
continue ;
2017-07-14 05:34:45 +08:00
2019-09-29 02:23:23 +08:00
if ( ! isset ( $currFrameSlots [ $frameIndex ]) ) {
$currFrameSlots [ $frameIndex ] = array ( 'count' => 1 , 'value' => $frame [ 'Score' ], 'event' => $event , 'frame' => $frame );
2017-05-19 02:04:24 +08:00
} else {
2019-09-29 02:23:23 +08:00
$currFrameSlots [ $frameIndex ][ 'count' ] ++ ;
if ( $frame [ 'Score' ] > $currFrameSlots [ $frameIndex ][ 'value' ] ) {
$currFrameSlots [ $frameIndex ][ 'value' ] = $frame [ 'Score' ];
$currFrameSlots [ $frameIndex ][ 'event' ] = $event ;
$currFrameSlots [ $frameIndex ][ 'frame' ] = $frame ;
2017-05-19 03:11:26 +08:00
}
2013-05-02 22:20:06 +08:00
}
2019-09-29 02:23:23 +08:00
if ( $frame [ 'Score' ] > $chart [ 'data' ][ 'y' ][ 'hi' ] ) {
$chart [ 'data' ][ 'y' ][ 'hi' ] = $frame [ 'Score' ];
2013-05-02 22:20:06 +08:00
}
2019-09-29 02:23:23 +08:00
} // end foreach frame
}
} // end if MaxScore > 0
} // end foreach event
2013-05-02 22:20:06 +08:00
2019-09-29 02:23:23 +08:00
//ksort( $monitorIds, SORT_NUMERIC );
2013-05-02 22:20:06 +08:00
ksort ( $monEventSlots , SORT_NUMERIC );
ksort ( $monFrameSlots , SORT_NUMERIC );
// No longer needed?
2017-05-19 02:04:24 +08:00
if ( false ) {
2017-05-19 03:11:26 +08:00
// Add on missing frames
foreach ( array_keys ( $monFrameSlots ) as $monitorId ) {
unset ( $currFrameSlots );
$currFrameSlots = & $monFrameSlots [ $monitorId ];
for ( $i = 0 ; $i < $chart [ 'graph' ][ 'width' ]; $i ++ ) {
if ( isset ( $currFrameSlots [ $i ]) ) {
if ( ! isset ( $currFrameSlots [ $i ][ 'frame' ]) ) {
2019-09-29 02:23:23 +08:00
$framesSql = 'SELECT FrameId, Score FROM Frames WHERE EventId = ? AND Score > 0 ORDER BY FrameId LIMIT 1' ;
2017-05-19 03:11:26 +08:00
$currFrameSlots [ $i ][ 'frame' ] = dbFetchOne ( $framesSql , NULL , array ( $currFrameSlots [ $i ][ 'event' ][ 'Id' ] ) );
2013-05-02 22:20:06 +08:00
}
2017-05-19 03:11:26 +08:00
}
2013-05-02 22:20:06 +08:00
}
2017-05-19 03:11:26 +08:00
}
2013-05-02 22:20:06 +08:00
}
$chart [ 'data' ][ 'y' ][ 'range' ] = ( $chart [ 'data' ][ 'y' ][ 'hi' ] - $chart [ 'data' ][ 'y' ][ 'lo' ]) + 1 ;
$chart [ 'data' ][ 'y' ][ 'density' ] = $chart [ 'data' ][ 'y' ][ 'range' ] / $chart [ 'graph' ][ 'height' ];
2018-04-21 02:25:38 +08:00
$majYScale = getYScale (
$chart [ 'data' ][ 'y' ][ 'range' ],
$chart [ 'grid' ][ 'y' ][ 'major' ][ 'min' ],
$chart [ 'grid' ][ 'y' ][ 'major' ][ 'max' ]);
2013-05-02 22:20:06 +08:00
// Optimise boxes
2017-05-19 02:04:24 +08:00
foreach ( array_keys ( $monEventSlots ) as $monitorId ) {
2017-05-19 03:11:26 +08:00
unset ( $currEventSlots );
$currEventSlots = & $monEventSlots [ $monitorId ];
for ( $i = 0 ; $i < $chart [ 'graph' ][ 'width' ]; $i ++ ) {
if ( isset ( $currEventSlots [ $i ]) ) {
if ( isset ( $currSlot ) ) {
if ( $currSlot [ 'event' ][ 'Id' ] == $currEventSlots [ $i ][ 'event' ][ 'Id' ] ) {
if ( $currSlot [ 'width' ] < $maxEventWidth ) {
// Merge slots for the same long event
$currSlot [ 'width' ] ++ ;
unset ( $currEventSlots [ $i ] );
continue ;
2019-09-29 02:23:23 +08:00
} else if ( $currSlot [ 'offset' ] < $currEventSlots [ $i ][ 'offset' ] ) {
2017-05-19 03:11:26 +08:00
// Split very long events
$currEventSlots [ $i ][ 'frame' ] = array ( 'FrameId' => $currEventSlots [ $i ][ 'offset' ] );
}
2019-09-29 02:23:23 +08:00
} else if ( $currSlot [ 'width' ] < $minEventWidth ) {
2017-05-19 03:11:26 +08:00
// Merge multiple small events
$currSlot [ 'width' ] ++ ;
unset ( $currEventSlots [ $i ] );
continue ;
2013-05-02 22:20:06 +08:00
}
2017-05-19 03:11:26 +08:00
}
$currSlot = & $currEventSlots [ $i ];
} else {
2019-09-29 02:23:23 +08:00
unset ( $currSlot );
2013-05-02 22:20:06 +08:00
}
2019-09-29 02:23:23 +08:00
} # end foreach x
unset ( $currSlot );
2018-04-21 02:25:38 +08:00
} // end foreach Event Monitors
2013-05-02 22:20:06 +08:00
//print_r( $monEventSlots );
// Stack events
$frameSlots = array ();
$frameMonitorIds = array_keys ( $monFrameSlots );
2017-05-19 02:04:24 +08:00
for ( $i = 0 ; $i < $chart [ 'graph' ][ 'width' ]; $i ++ ) {
2017-05-19 03:11:26 +08:00
foreach ( $frameMonitorIds as $frameMonitorId ) {
$currFrameSlots = & $monFrameSlots [ $frameMonitorId ];
if ( isset ( $currFrameSlots [ $i ]) ) {
if ( ! isset ( $frameSlots [ $i ]) ) {
$frameSlots [ $i ] = array ();
$frameSlots [ $i ][] = & $currFrameSlots [ $i ];
} else {
$slotCount = count ( $frameSlots [ $i ]);
for ( $j = 0 ; $j < $slotCount ; $j ++ ) {
if ( $currFrameSlots [ $i ][ 'value' ] > $frameSlots [ $i ][ $j ][ 'value' ] ) {
for ( $k = $slotCount ; $k > $j ; $k -- ) {
$frameSlots [ $i ][ $k ] = $frameSlots [ $i ][ $k - 1 ];
2013-05-02 22:20:06 +08:00
}
2017-05-19 03:11:26 +08:00
$frameSlots [ $i ][ $j ] = & $currFrameSlots [ $i ];
break 2 ;
}
2013-05-02 22:20:06 +08:00
}
2017-05-19 03:11:26 +08:00
$frameSlots [ $i ][] = & $currFrameSlots [ $i ];
}
2013-05-02 22:20:06 +08:00
}
2019-09-29 02:23:23 +08:00
unset ( $currFrameSlots );
2017-05-19 23:00:37 +08:00
} # end foreach MonitorId
2019-09-29 02:23:23 +08:00
} # end foreach x
2013-05-02 22:20:06 +08:00
2020-08-12 01:47:48 +08:00
//ZM\Logger::Debug(print_r( $monEventSlots,true ));
2013-05-02 22:20:06 +08:00
//print_r( $monFrameSlots );
//print_r( $chart );
$graphHeight = $chart [ 'graph' ][ 'height' ];
2017-05-19 23:00:37 +08:00
if ( $mode == 'overlay' ) {
2017-05-19 03:11:26 +08:00
$minEventBarHeight = 10 ;
$maxEventBarHeight = 40 ;
2013-05-02 22:20:06 +08:00
2019-09-29 02:23:23 +08:00
if ( count ( $monitors ) ) {
2017-05-19 03:11:26 +08:00
$chart [ 'graph' ][ 'eventBarHeight' ] = $minEventBarHeight ;
2019-09-29 02:23:23 +08:00
while ( ( $chart [ 'graph' ][ 'eventsHeight' ] = (( $chart [ 'graph' ][ 'eventBarHeight' ] * count ( $monitors )) + ( count ( $monitors ) - 1 ))) < $maxEventBarHeight ) {
2017-05-19 03:11:26 +08:00
$chart [ 'graph' ][ 'eventBarHeight' ] ++ ;
2013-05-02 22:20:06 +08:00
}
2017-05-19 03:11:26 +08:00
} else {
$chart [ 'graph' ][ 'eventBarHeight' ] = $maxEventBarHeight ;
$chart [ 'graph' ][ 'eventsHeight' ] = $maxEventBarHeight ;
}
$chart [ 'graph' ][ 'activityHeight' ] = ( $graphHeight - $chart [ 'graph' ][ 'eventsHeight' ]);
$chart [ 'data' ][ 'y' ][ 'density' ] = $chart [ 'data' ][ 'y' ][ 'range' ] / $chart [ 'graph' ][ 'activityHeight' ];
$chart [ 'eventBars' ] = array ();
$top = $chart [ 'graph' ][ 'activityHeight' ];
2019-09-29 02:23:23 +08:00
foreach ( array_keys ( $monitors ) as $monitorId ) {
2017-05-19 03:11:26 +08:00
$chart [ 'eventBars' ][ $monitorId ] = array ( 'top' => $top );
$top += $chart [ 'graph' ][ 'eventBarHeight' ] + 1 ;
}
2017-05-19 23:00:37 +08:00
} else if ( $mode == 'split' ) {
2017-05-19 03:11:26 +08:00
$minActivityBarHeight = 30 ;
$minEventBarHeight = 10 ;
$maxEventBarHeight = 40 ;
2019-09-29 02:23:23 +08:00
if ( count ( $monitors ) ) {
2017-05-19 03:11:26 +08:00
$chart [ 'graph' ][ 'eventBarHeight' ] = $minEventBarHeight ;
$chart [ 'graph' ][ 'activityBarHeight' ] = $minActivityBarHeight ;
2019-09-29 02:23:23 +08:00
while ( ((( $chart [ 'graph' ][ 'eventBarHeight' ] + $chart [ 'graph' ][ 'activityBarHeight' ]) * count ( $monitors )) + (( 2 * count ( $monitors )) - 1 )) < $graphHeight ) {
2017-05-19 03:11:26 +08:00
$chart [ 'graph' ][ 'activityBarHeight' ] ++ ;
if ( $chart [ 'graph' ][ 'eventBarHeight' ] < $maxEventBarHeight ) {
$chart [ 'graph' ][ 'eventBarHeight' ] ++ ;
}
2013-05-02 22:20:06 +08:00
}
2017-05-19 03:11:26 +08:00
} else {
$chart [ 'graph' ][ 'eventBarHeight' ] = $maxEventBarHeight ;
$chart [ 'graph' ][ 'activityBarHeight' ] = $graphHeight - $chart [ 'graph' ][ 'eventBarHeight' ];
}
$chart [ 'data' ][ 'y' ][ 'density' ] = $chart [ 'data' ][ 'y' ][ 'range' ] / $chart [ 'graph' ][ 'activityBarHeight' ];
2013-05-02 22:20:06 +08:00
2017-05-19 23:00:37 +08:00
$chart [ 'activityBars' ] = array ();
2017-05-19 03:11:26 +08:00
$chart [ 'eventBars' ] = array ();
$top = 0 ;
$barCount = 1 ;
2019-09-29 02:23:23 +08:00
foreach ( array_keys ( $monitors ) as $monitorId ) {
2017-05-19 03:11:26 +08:00
$chart [ 'eventBars' ][ $monitorId ] = array ( 'top' => $top );
$chart [ 'eventBars' ][ $monitorId ] = array ( 'top' => $top + $chart [ 'graph' ][ 'activityBarHeight' ] + 1 );
$top += $chart [ 'graph' ][ 'activityBarHeight' ] + 1 + $chart [ 'graph' ][ 'eventBarHeight' ] + 1 ;
}
2019-09-29 02:23:23 +08:00
} else {
2020-03-02 00:07:31 +08:00
ZM\Warning ( " No mode $mode " );
2013-05-02 22:20:06 +08:00
}
2019-09-29 02:23:23 +08:00
preg_match ( '/^(\d+)-(\d+)-(\d+) (\d+):(\d+)/' , $minTime , $startMatches );
preg_match ( '/^(\d+)-(\d+)-(\d+) (\d+):(\d+)/' , $maxTime , $endMatches );
2013-05-02 22:20:06 +08:00
2017-05-19 02:04:24 +08:00
if ( $startMatches [ 1 ] != $endMatches [ 1 ] ) {
2017-05-19 23:00:37 +08:00
// Different years
2019-09-29 02:23:23 +08:00
$title = strftime ( STRF_TL_AXIS_RANGE_YEAR1 , $chart [ 'data' ][ 'x' ][ 'lo' ] ) . ' - ' . strftime ( STRF_TL_AXIS_RANGE_YEAR2 , $chart [ 'data' ][ 'x' ][ 'hi' ] );
} else if ( $startMatches [ 2 ] != $endMatches [ 2 ] ) {
2017-05-19 23:00:37 +08:00
// Different months
2019-09-29 02:23:23 +08:00
$title = strftime ( STRF_TL_AXIS_RANGE_MONTH1 , $chart [ 'data' ][ 'x' ][ 'lo' ] ) . ' - ' . strftime ( STRF_TL_AXIS_RANGE_MONTH2 , $chart [ 'data' ][ 'x' ][ 'hi' ] );
} else if ( $startMatches [ 3 ] != $endMatches [ 3 ] ) {
2017-05-19 23:00:37 +08:00
// Different dates
2019-09-29 02:23:23 +08:00
$title = strftime ( STRF_TL_AXIS_RANGE_DAY1 , $chart [ 'data' ][ 'x' ][ 'lo' ] ) . ' - ' . strftime ( STRF_TL_AXIS_RANGE_DAY2 , $chart [ 'data' ][ 'x' ][ 'hi' ] );
2017-05-19 02:04:24 +08:00
} else {
2017-05-19 23:00:37 +08:00
// Different times
2019-09-29 02:23:23 +08:00
$title = strftime ( STRF_TL_AXIS_RANGE_TIME1 , $chart [ 'data' ][ 'x' ][ 'lo' ] ) . ' - ' . strftime ( STRF_TL_AXIS_RANGE_TIME2 , $chart [ 'data' ][ 'x' ][ 'hi' ] );
2013-05-02 22:20:06 +08:00
}
2017-05-19 02:04:24 +08:00
function drawXGrid ( $chart , $scale , $labelClass , $tickClass , $gridClass , $zoomClass = false ) {
2017-05-19 23:00:37 +08:00
$html = '' ;
ob_start ();
$labelCount = 0 ;
$lastTick = 0 ;
unset ( $lastLabel );
$labelCheck = isset ( $scale [ 'labelCheck' ]) ? $scale [ 'labelCheck' ] : $scale [ 'label' ];
2019-09-29 02:23:23 +08:00
echo '<div id="xScale">' ;
2017-05-19 23:00:37 +08:00
for ( $i = 0 ; $i < $chart [ 'graph' ][ 'width' ]; $i ++ ) {
2019-09-29 02:23:23 +08:00
$x = round ( 100 * (( $i ) / $chart [ 'graph' ][ 'width' ]), 1 );
2017-05-19 23:00:37 +08:00
$timeOffset = ( int )( $chart [ 'data' ][ 'x' ][ 'lo' ] + ( $i * $chart [ 'data' ][ 'x' ][ 'density' ]));
if ( $scale [ 'align' ] > 1 ) {
$label = ( int )( strftime ( $labelCheck , $timeOffset ) / $scale [ 'align' ]);
} else {
$label = strftime ( $labelCheck , $timeOffset );
}
if ( ! isset ( $lastLabel ) || ( $lastLabel != $label ) ) {
$labelCount ++ ;
}
if ( $labelCount >= $scale [ 'divisor' ] ) {
$labelCount = 0 ;
if ( isset ( $lastLabel ) ) {
if ( $labelClass ) {
2013-05-02 22:20:06 +08:00
?>
2019-09-29 02:23:23 +08:00
< div class = " <?php echo $labelClass ?> " style = " left: <?php echo $x -round(100*(11/ $chart['graph'] ['width']),1) ?>%; " >< ? php echo strftime ( $scale [ 'label' ], $timeOffset ); ?> </div>
2013-05-02 22:20:06 +08:00
< ? php
2017-05-19 23:00:37 +08:00
}
if ( $tickClass ) {
2013-05-02 22:20:06 +08:00
?>
2019-09-29 02:23:23 +08:00
< div class = " <?php echo $tickClass ?> " style = " left: <?php echo $x ?>%; " ></ div >
2013-05-02 22:20:06 +08:00
< ? php
2017-05-19 23:00:37 +08:00
}
if ( $gridClass ) {
2013-05-02 22:20:06 +08:00
?>
2019-09-29 02:23:23 +08:00
< div class = " <?php echo $gridClass ?> " style = " left: <?php echo $x ?>%; " ></ div >
2013-05-02 22:20:06 +08:00
< ? php
2017-05-19 23:00:37 +08:00
}
if ( $scale [ 'name' ] != 'second' && $zoomClass ) {
$zoomMinTime = strftime ( STRF_FMT_DATETIME_DB , ( int )( $chart [ 'data' ][ 'x' ][ 'lo' ] + ( $lastTick * $chart [ 'data' ][ 'x' ][ 'density' ])) );
$zoomMaxTime = strftime ( STRF_FMT_DATETIME_DB , ( int )( $chart [ 'data' ][ 'x' ][ 'lo' ] + ( $i * $chart [ 'data' ][ 'x' ][ 'density' ])) );
2013-05-02 22:20:06 +08:00
?>
2020-05-15 23:33:10 +08:00
< div class = " <?php echo $zoomClass ?> " style = " left: <?php echo 100*( $lastTick -1)/ $chart['graph'] ['width'] ?>%; width: <?php echo round(100*( $i - $lastTick )/ $chart['graph'] ['width'],1) ?>%; " title = " <?php echo translate('ZoomIn') ?> " data - on - click = " tlZoomBounds " data - zoom - min - time = " <?php echo $zoomMinTime ?> " data - zoom - max - time = " <?php echo $zoomMaxTime ?> " ></ div >
2013-05-02 22:20:06 +08:00
< ? php
}
2017-05-19 23:00:37 +08:00
$lastTick = $i ;
} # end if $lastLabel
2013-05-02 22:20:06 +08:00
}
2017-05-19 23:00:37 +08:00
$lastLabel = $label ;
} # end foreach width segment
if ( $zoomClass ) {
$zoomMinTime = strftime ( STRF_FMT_DATETIME_DB , ( int )( $chart [ 'data' ][ 'x' ][ 'lo' ] + ( $lastTick * $chart [ 'data' ][ 'x' ][ 'density' ])) );
$zoomMaxTime = strftime ( STRF_FMT_DATETIME_DB , ( int )( $chart [ 'data' ][ 'x' ][ 'lo' ] + ( $i * $chart [ 'data' ][ 'x' ][ 'density' ])) );
2013-05-02 22:20:06 +08:00
?>
2020-05-15 23:33:10 +08:00
< div class = " <?php echo $zoomClass ?> " style = " left: <?php echo $lastTick -1 ?>px; width: <?php echo $i - $lastTick ?>px; " title = " <?php echo translate('ZoomIn') ?> " data - on - click = " tlZoomBounds " data - zoom - min - time = " <?php echo $zoomMinTime ?> " data - zoom - max - time = " <?php echo $zoomMaxTime ?> " ></ div >
2013-05-02 22:20:06 +08:00
< ? php
2017-05-19 23:00:37 +08:00
}
2013-05-02 22:20:06 +08:00
?>
</ div >
< ? php
2019-10-23 21:50:49 +08:00
return ob_get_clean ();
2017-05-19 23:00:37 +08:00
} # end function drawXGrid
2013-05-02 22:20:06 +08:00
2017-05-19 02:04:24 +08:00
function drawYGrid ( $chart , $scale , $labelClass , $tickClass , $gridClass ) {
2017-05-19 23:00:37 +08:00
ob_start ();
2013-05-02 22:20:06 +08:00
?>
2019-09-29 02:23:23 +08:00
< div id = " yScale " >
2013-05-02 22:20:06 +08:00
< ? php
2017-05-19 23:00:37 +08:00
for ( $i = 0 ; $i < $scale [ 'lines' ]; $i ++ ) {
$label = ( int )( $i * $scale [ 'divisor' ]);
$y = $chart [ 'graph' ][ 'eventsHeight' ] + ( int )(( $i * $scale [ 'divisor' ]) / $chart [ 'data' ][ 'y' ][ 'density' ]) - 1 ;
if ( $labelClass ) {
2013-05-02 22:20:06 +08:00
?>
2017-05-19 23:00:37 +08:00
< div class = " <?php echo $labelClass ?> " style = " top: <?php echo $chart['graph'] ['height']-( $y +8) ?>px; " >< ? php echo $label ?> </div>
2013-05-02 22:20:06 +08:00
< ? php
2017-05-19 23:00:37 +08:00
}
if ( $tickClass ) {
2013-05-02 22:20:06 +08:00
?>
2017-05-19 23:00:37 +08:00
< div class = " <?php echo $tickClass ?> " style = " top: <?php echo $chart['graph'] ['height']-( $y +2) ?>px; " ></ div >
2013-05-02 22:20:06 +08:00
< ? php
2017-05-19 23:00:37 +08:00
}
if ( $gridClass ) {
2013-05-02 22:20:06 +08:00
?>
2017-05-19 23:00:37 +08:00
< div class = " <?php echo $gridClass ?> " style = " top: <?php echo $chart['graph'] ['height']-( $y +2) ?>px;<?php echo $i <= 0?' border-top: solid 1px black;':'' ?> " ></ div >
2013-05-02 22:20:06 +08:00
< ? php
}
2017-05-19 23:00:37 +08:00
} # end foreach line segment
2013-05-02 22:20:06 +08:00
?>
2017-05-19 23:00:37 +08:00
</ div >
2013-05-02 22:20:06 +08:00
< ? php
2019-10-23 21:50:49 +08:00
return ob_get_clean ();
2017-05-19 23:00:37 +08:00
} # end function drawYGrid
2013-05-02 22:20:06 +08:00
$focusWindow = true ;
2019-09-29 02:23:23 +08:00
xhtmlHeaders ( __FILE__ , translate ( 'Timeline' ));
2013-05-02 22:20:06 +08:00
?>
< body >
2017-11-28 02:43:15 +08:00
< ? php echo getNavBarHTML () ?>
2020-08-25 03:33:01 +08:00
< div id = " page p-0 " >
< div class = " d-flex p-1 " >
< div class = " mr-auto " id = " toolbar " >
< button id = " backBtn " class = " btn btn-normal " data - toggle = " tooltip " data - placement = " top " title = " <?php echo translate('Back') ?> " disabled >< i class = " fa fa-arrow-left " ></ i ></ button >
< button id = " refreshBtn " class = " btn btn-normal " data - toggle = " tooltip " data - placement = " top " title = " <?php echo translate('Refresh') ?> " >< i class = " fa fa-refresh " ></ i ></ button >
< button id = " listBtn " class = " btn btn-normal " data - toggle = " tooltip " data - placement = " top " title = " <?php echo translate('List') ?> " >< i class = " fa fa-list " ></ i ></ button >
2013-05-02 22:20:06 +08:00
</ div >
2020-08-25 03:33:01 +08:00
< h2 class = " align-self-end " >< ? php echo translate ( 'Timeline' ) ?> </h2>
2013-05-02 22:20:06 +08:00
</ div >
2020-08-25 03:33:01 +08:00
2019-09-29 02:23:23 +08:00
< div id = " content " class = " chartSize " >
< div id = " topPanel " class = " graphWidth " >
< div id = " imagePanel " >
< div id = " image " class = " imageHeight " >
< img id = " imageSrc " class = " imageWidth " src = " graphics/transparent.png " alt = " <?php echo translate('ViewEvent') ?> " title = " <?php echo translate('ViewEvent') ?> " />
2017-05-19 23:00:37 +08:00
</ div >
2013-05-02 22:20:06 +08:00
</ div >
2019-09-29 02:23:23 +08:00
< div id = " dataPanel " >
< div id = " textPanel " >
< div id = " instruction " >
2015-05-10 21:10:30 +08:00
< p >< ? php echo translate ( 'TimelineTip1' ) ?> </p>
< p >< ? php echo translate ( 'TimelineTip2' ) ?> </p>
< p >< ? php echo translate ( 'TimelineTip3' ) ?> </p>
< p >< ? php echo translate ( 'TimelineTip4' ) ?> </p>
2013-08-16 00:58:08 +08:00
</ div >
2019-09-29 02:23:23 +08:00
< div id = " eventData " >
2013-05-02 22:20:06 +08:00
</ div >
</ div >
2019-09-29 02:23:23 +08:00
< div id = " navPanel " >
< button type = " button " title = " <?php echo translate('PanLeft') ?> " data - on - click = " tlPanLeft " >
< i class = " material-icons md-18 " > fast_rewind </ i >
</ button >
< button type = " button " title = " <?php echo translate('ZoomOut') ?> " data - on - click = " tlZoomOut " >
< i class = " material-icons md-18 " > zoom_out </ i >
</ button >
< button type = " button " title = " <?php echo translate('PanRight') ?> " data - on - click = " tlPanRight " >
< i class = " material-icons md-18 " > fast_forward </ i >
</ button >
2013-05-02 22:20:06 +08:00
</ div >
</ div >
</ div >
2019-09-29 02:23:23 +08:00
< div id = " chartPanel " >
< div id = " chart " class = " graphSize " >
2013-05-02 22:20:06 +08:00
< ? php
2019-09-29 02:23:23 +08:00
function drawSlot ( $slot , $index ) {
global $chart ;
global $monitors ;
global $mouseover ;
$height = ( int )( $slot [ 'value' ] / $chart [ 'data' ][ 'y' ][ 'density' ]);
if ( $height <= 0 )
return '' ;
$left = round ( 100 * ( $index / $chart [ 'graph' ][ 'width' ]), 1 );
return " <div class= \" activity monitorColour { $slot [ 'event' ][ 'MonitorId' ] } \"
style = \ " left: { $left } %; height: { $height } px; \"
data - event - id = \ " { $slot [ 'event' ][ 'Id' ] } \" data-frame-id= \" " . getSlotFrame ( $slot ) . " \" " .
( $mouseover ? ' data-on-mouseover-this="previewEvent" data-on-click-this="showEvent"' : ' data-on-click-this="previewEvent"' ) .
'></div>' ;
}
2017-05-19 23:00:37 +08:00
if ( $mode == 'overlay' ) {
echo drawYGrid ( $chart , $majYScale , 'majLabelY' , 'majTickY' , 'majGridY graphWidth' );
2013-05-02 22:20:06 +08:00
}
2017-05-19 23:00:37 +08:00
echo drawXGrid ( $chart , $majXScale , 'majLabelX' , 'majTickX' , 'majGridX graphHeight' , 'zoom graphHeight' );
if ( $mode == 'overlay' ) {
2013-05-02 22:20:06 +08:00
?>
2019-09-29 02:23:23 +08:00
< div id = " activity " class = " activitySize " >
2013-05-02 22:20:06 +08:00
< ? php
2017-05-19 02:04:24 +08:00
foreach ( $frameSlots as $index => $slots ) {
2017-05-19 23:00:37 +08:00
foreach ( $slots as $slot ) {
2019-09-29 02:23:23 +08:00
echo drawSlot ( $slot , $index );
2017-05-19 23:00:37 +08:00
}
2013-05-02 22:20:06 +08:00
}
?>
</ div >
< ? php
2019-09-29 02:23:23 +08:00
} else if ( $mode == 'split' ) {
foreach ( array_keys ( $monFrameSlots ) as $monitorId ) {
2013-05-02 22:20:06 +08:00
?>
2019-09-29 02:23:23 +08:00
< div id = " activity<?php echo $monitorId ?> " class = " activitySize " >
2013-05-02 22:20:06 +08:00
< ? php
2017-05-19 02:04:24 +08:00
$currFrameSlots = & $monFrameSlots [ $monitorId ];
foreach ( $currFrameSlots as $index => $slot ) {
2019-09-29 02:23:23 +08:00
echo drawSlot ( $slot , $index );
2017-05-19 23:00:37 +08:00
} # end foreach $currFrameSlots
2019-09-29 02:23:23 +08:00
unset ( $currFrameSlots );
2017-05-19 02:04:24 +08:00
?>
</ div >
< ? php
2017-05-19 23:00:37 +08:00
} # end foreach $MonitorId
2013-05-02 22:20:06 +08:00
}
2019-09-29 02:23:23 +08:00
foreach ( array_keys ( $monEventSlots ) as $monitorId ) {
2013-05-02 22:20:06 +08:00
?>
2014-12-05 07:44:23 +08:00
< div id = " events<?php echo $monitorId ?> " class = " events eventsSize eventsPos<?php echo $monitorId ?> " >
2013-05-02 22:20:06 +08:00
< ? php
2017-05-19 02:04:24 +08:00
$currEventSlots = & $monEventSlots [ $monitorId ];
for ( $i = 0 ; $i < $chart [ 'graph' ][ 'width' ]; $i ++ ) {
if ( isset ( $currEventSlots [ $i ]) ) {
$slot = & $currEventSlots [ $i ];
2019-09-29 02:23:23 +08:00
$left = round ( 100 * ( $i / $chart [ 'graph' ][ 'width' ]), 1 );
$width = round ( 100 * ( $slot [ 'width' ] / $chart [ 'graph' ][ 'width' ]), 1 );
echo " <div class= \" event monitorColour { $slot [ 'event' ][ 'MonitorId' ] } \"
style = \ " left: { $left } %; width: { $width } %; \"
data - event - id = \ " { $slot [ 'event' ][ 'Id' ] } \" data-frame-id= \" " . getSlotFrame ( $slot ) . " \" " .
( $mouseover ? ' data-on-mouseover-this="previewEvent" data-on-click-this="showEvent"' : ' data-on-click-this="previewEvent"' ) .
'></div>' ;
unset ( $slot );
2017-05-19 23:00:37 +08:00
} # end if isset($currEventSlots[$i])
} # end foreach width segment
2019-09-29 02:23:23 +08:00
unset ( $currEventSlots );
2013-05-02 22:20:06 +08:00
?>
</ div >
< ? php
}
?>
</ div >
</ div >
2019-09-29 02:23:23 +08:00
< div id = " chartLabels " class = " graphWidth " >
< div id = " key " >
2013-05-02 22:20:06 +08:00
< ? php
2017-05-19 02:04:24 +08:00
foreach ( array_keys ( $monEventSlots ) as $monitorId ) {
2013-05-02 22:20:06 +08:00
?>
2019-09-29 02:23:23 +08:00
< span class = " keyEntry " >< ? php echo $monitors [ $monitorId ] -> Name () ?>
< div id = " keyBox<?php echo $monitorId ?> " class = " keyBox monitorColour<?php echo $monitorId ?> " title = " <?php echo $monitors[$monitorId] ->Name() ?> " style = " background-color: <?php echo $monitors[$monitorId] ->WebColour() ?>; " ></ div >
2017-05-19 03:11:26 +08:00
</ span >
2013-05-02 22:20:06 +08:00
< ? php
}
?>
</ div >
2019-09-29 02:23:23 +08:00
< div id = " range " >< ? php echo $title ?> </div>
2013-05-02 22:20:06 +08:00
</ div >
</ div >
</ div >
</ body >
</ html >