Reports: read hourly report_HH.db files #1

Merged
ClaudeAI merged 2 commits from feature/hourly-report-db into master 2 hours ago
  1. 2
      files.list
  2. 2
      lib/ajax_asm.php
  3. 1
      lib/assembler.php
  4. 8
      lib/controller/getBubbleAnalysis.php
  5. 7
      lib/controller/getFrames.php
  6. 6
      lib/controller/getHistoryDates.php
  7. 127
      lib/controller/getHistoryDay.php
  8. 10
      lib/controller/getHistoryEvents.php
  9. 9
      lib/controller/getPictureInfo.php
  10. 25
      lib/controller/getStatus.php
  11. 15
      lib/controller/getVideoInfo.php
  12. 8
      lib/controller/setPermanentBubbles.php
  13. 4
      lib/javascript/jsapi_dynamic/mojo_reports.js
  14. 1
      lib/js_asm.php
  15. 74
      lib/php/db/report_files.php
  16. 30
      lib/php/host_timezone.php
  17. 1
      lib/soap_asm.php
  18. 1
      lib/ui_asm.php

2
files.list

@ -5711,6 +5711,8 @@
./lib/php/db/user_class.php
./lib/php/db/VS_Object_class.php
./lib/php/db/SQLite_Class.php
./lib/php/db/report_files.php
./lib/php/host_timezone.php
./lib/php/db/VS_Tree_class.php
./lib/php/db/language_class.php
./lib/php/db/external.php

2
lib/ajax_asm.php

@ -1,6 +1,7 @@
<?php
error_reporting( E_ALL );
require_once('settings.php');
require_once( __DIR__ . '/php/host_timezone.php'); // PHP must use the host's local time zone
require_once('defines.php');
// SET DATA CONNECTION AND GLOBAL USER VARIABLES
@ -16,6 +17,7 @@ if( $TT_123[0] == '4' ){
};
*/
require_once( 'php/db/SQLite_Class.php');
require_once( 'php/db/report_files.php'); // hourly report_HH.db files + global report ids
$DATABASE = new SQLite_DB( $SYSPath . '/lib/controller/data/mysqlitedb.db');

1
lib/assembler.php

@ -1,6 +1,7 @@
<?php
error_reporting( E_ALL );
require_once('settings.php');
require_once( __DIR__ . '/php/host_timezone.php'); // PHP must use the host's local time zone
require_once('defines.php');
// SET DATA CONNECTION AND GLOBAL USER VARIABLES

8
lib/controller/getBubbleAnalysis.php

@ -75,9 +75,11 @@
};
if( $UID > 1 && $DTS ){
$DS = date("Y/m/d", $DTS );
$QS = "SELECT * FROM `events` WHERE ( `evt_type`=13 OR `evt_type`=14 ) AND `id`>={$BID} AND `id`<={$EID} ORDER BY `ts` ASC, `ts_ms` ASC";
$ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db');
$LREC = $ZIZI->Query( $QS );
// BID/EID are global ids of one report file (see report_files.php)
list( $SLOT, $RBID, $REID ) = reportResolveRange( $BID, $EID );
$QS = "SELECT * FROM `events` WHERE ( `evt_type`=13 OR `evt_type`=14 ) AND `id`>={$RBID} AND `id`<={$REID} ORDER BY `ts` ASC, `ts_ms` ASC";
$ZIZI = reportOpenSlot( $DS, $SLOT );
$LREC = $ZIZI ? $ZIZI->Query( $QS ) : array();
if( count( $LREC ) ){
foreach( $LREC as $REC ){
$bid = serchInBubbles( $REC );

7
lib/controller/getFrames.php

@ -8,9 +8,10 @@
if( isset( $_GET['sf'] ) ) $START_FRAME = intval( $_GET['sf'] );
if( $VID && $DTS ){
$DS = date("Y/m/d", $DTS );
$QS = "SELECT * FROM `videos` WHERE `id` = {$VID}";
$ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db');
$LREC = $ZIZI->Query( $QS );
// VID is a global video id (see report_files.php)
$QS = "SELECT * FROM `videos` WHERE `id` = " . reportRawId( $VID );
$ZIZI = reportOpenSlot( $DS, reportSlotOf( $VID ) );
$LREC = $ZIZI ? $ZIZI->Query( $QS ) : array();
if( count( $LREC ) ){
$Data = $LREC[0];

6
lib/controller/getHistoryDates.php

@ -11,8 +11,10 @@
$DD = array();
foreach( $RR as $R ){
$CC = intval( $R['evt_count'] );
$DS = $R['year'] . '-' . $R['month'] . '-' . $R['day'] . ' 00:00:00';
$TS = strtotime( $DS ) + $DIDI;
// Day key = local noon of the day in the host time zone: maps back to the same date on the
// server in any time zone, and shows the right day in a browser within 12 h of the host
$DS = sprintf( "%04d-%02d-%02d 12:00:00", intval( $R['year'] ), intval( $R['month'] ), intval( $R['day'] ) );
$TS = strtotime( $DS );
if( $CC > 100 ) $CC = 100;
$DD[] = '{"t": '.( $TS * 1000 ).',"v":'.$CC.'}';
//echo '[{"t": 1285891200000,"v": 20},{"t": 1285804800000,"v": 100},{"t": 1672249854000,"v": 50},{"t": 1672279854000,"v": 80}]';

127
lib/controller/getHistoryDay.php

@ -7,12 +7,13 @@
$DT = new DateTime("now", $TZ );
$DIDI = $TZ->getOffset( $DT );
$Data['tz_offset']=$DIDI;
$DTS += $DIDI;
// DTS is the day key from getHistoryDates (host local noon of the day) - no offset correction needed
$Y = date("Y", $DTS );
$M = date("m", $DTS );
$D = date("d", $DTS );
$DS = date("Y/m/d", $DTS );
$NONO = '';
$EVEVE = '';
$MUMU = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/stat.db' );
$QS = "SELECT * FROM `days` WHERE `year`={$Y} AND `month`={$M} AND `day`={$D}";
$LOLO = $MUMU->Query( $QS );
@ -23,71 +24,83 @@
$S = intval( $LOLO[0]['session_count'] );
$V = intval( $LOLO[0]['videos_count'] );
$E = intval( $LOLO[0]['evt_count'] );
$ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/' . $DS . '/report.db' );
$QS = "SELECT `id`, `ts`, `evt_type` FROM `events` WHERE ( `evt_type`=52 OR `evt_type`=53 OR `evt_type`=54 )";
$NDD = $ZIZI->Query( $QS );
if( count( $NDD ) ){
$st_ignore = true;
$DH = 0;
$BID = 0;
$EID = 0;
$BTM = 0;
$JIGA = array();
foreach( $NDD as $N ){
if( $st_ignore && $N['evt_type']!=52 ) continue;
if( $st_ignore && $N['evt_type']==52 ) $st_ignore = false;
if( $N['evt_type']==52 ) {
$DH = 0;
$BID = intval( $N['id'] );
$BTM = date( "H:i:s", $N['ts'] );
} else {
$DH = 1;
$EID = intval( $N['id'] );
// One report file per hour (report_HH.db) and/or the legacy day report.db - ids are global (see report_files.php)
$JIGA = array();
$SIGA = array();
foreach( reportDayFiles( $DS ) as $SLOT => $RFILE ){
$ZIZI = new SQLite_DB( $RFILE, SQLITE3_OPEN_READWRITE );
// Sessions (START=52, END=53/54) - with hourly files a session never spans two files
$QS = "SELECT `id`, `ts`, `evt_type` FROM `events` WHERE ( `evt_type`=52 OR `evt_type`=53 OR `evt_type`=54 ) ORDER BY `id`";
$NDD = $ZIZI->Query( $QS );
if( count( $NDD ) ){
$st_ignore = true;
$DH = 0;
$BID = 0;
$EID = 0;
$BTM = 0;
foreach( $NDD as $N ){
if( $st_ignore && $N['evt_type']!=52 ) continue;
if( $st_ignore && $N['evt_type']==52 ) $st_ignore = false;
if( $N['evt_type']==52 ) {
$DH = 0;
$BID = reportEncodeId( $SLOT, $N['id'] );
$BTM = date( "H:i:s", $N['ts'] );
} else {
$DH = 1;
$EID = reportEncodeId( $SLOT, $N['id'] );
};
if( $st_ignore == false && $DH == 1 ){
$JIGA[] = "{ text: '{$BTM}', leaf: true, bid: {$BID}, eid: {$EID} }";
};
};
if( $st_ignore == false && $DH == 1 ){
if( $st_ignore == false && $DH == 0 ){
// Session still open in this file (ongoing, or the file was not closed) - up to the end of the file
$EID = reportEncodeId( $SLOT, REPORT_RAW_ID_MAX );
$JIGA[] = "{ text: '{$BTM}', leaf: true, bid: {$BID}, eid: {$EID} }";
};
};
if( $DH == 0 ){
//Ongoing Event goes next day - must catch up
$QS = "SELECT `id`, `ts`, `evt_type` FROM `events` WHERE `id` > {$BID} AND ( `evt_type`=53 OR `evt_type`=54 ) LIMIT 1";
// Events by hours
if( $SLOT == REPORT_LEGACY_SLOT ){
// Legacy day file: split by hour
$QS = "SELECT DISTINCT `ts`/3600 AS JUJA FROM `events`";
$NDD = $ZIZI->Query( $QS );
if( count( $NDD ) ){
$EID = intval( $NDD[0]['id'] );
} else {
$EID = 1000000000;//Infinity
foreach( $NDD as $N ){
$BTS = intval($N['JUJA'])*3600;
$DADA = date( "H:i", $BTS );
$ETS = $BTS+3600;
$BID = 0;
$EID = 0;
$QS="SELECT `id` FROM `events` WHERE `ts`>({$BTS}-1) LIMIT 1";
$KK = $ZIZI->Query( $QS );
if( count( $KK ) ) $BID = $KK[0]['id'];
$QS="SELECT `id` FROM `events` WHERE `ts`<({$ETS}-1) ORDER BY `id` DESC LIMIT 1";
$KK = $ZIZI->Query( $QS );
if( count( $KK ) ) $EID = $KK[0]['id']; else $EID = $BID;
if( $BID && $EID ){
$BID = reportEncodeId( $SLOT, $BID );
$EID = reportEncodeId( $SLOT, $EID );
$SIGA[] = array( 'k' => $BTS, 'n' => "{ text: '{$DADA}', leaf: true, bid: {$BID}, eid: {$EID} }" );
};
};
$JIGA[] = "{ text: '{$BTM}', leaf: true, bid: {$BID}, eid: {$EID} }";
};
if( count( $JIGA ) ){
$NONO = "{ text: 'Sessions', leaf: false, expanded: true, children:[". implode( ",", $JIGA ) . "]}";
} else {
$NONO = "{ text: 'No Sessions', leaf: true }";
// Hourly file: one node for the whole file
$KK = $ZIZI->Query( "SELECT MIN(`id`) AS `b`, MAX(`id`) AS `e`, MIN(`ts`) AS `t` FROM `events`" );
if( count( $KK ) && intval( $KK[0]['b'] ) ){
$BID = reportEncodeId( $SLOT, $KK[0]['b'] );
$EID = reportEncodeId( $SLOT, $KK[0]['e'] );
$DADA = sprintf( "%02d:00", $SLOT );
$SIGA[] = array( 'k' => intval( $KK[0]['t'] ), 'n' => "{ text: '{$DADA}', leaf: true, bid: {$BID}, eid: {$EID} }" );
};
};
};
$QS = "SELECT DISTINCT `ts`/3600 AS JUJA FROM `events`";
$NDD = $ZIZI->Query( $QS );
if( count( $NDD ) ){
$st_ignore = true;
$DH = 0;
$SIGA = array();
foreach( $NDD as $N ){
$BTS = intval($N['JUJA'])*3600;
$DADA = date( "H:i", $BTS );
$ETS = $BTS+3600;
$BID = 0;
$EID = 0;
$QS="SELECT `id` FROM `events` WHERE `ts`>({$BTS}-1) LIMIT 1";
$KK = $ZIZI->Query( $QS );
if( count( $KK ) ) $BID = $KK[0]['id'];
$QS="SELECT `id` FROM `events` WHERE `ts`<({$ETS}-1) ORDER BY `id` DESC LIMIT 1";
$KK = $ZIZI->Query( $QS );
if( count( $KK ) ) $EID = $KK[0]['id']; else $EID = $BID;
if( $BID && $EID ){
$SIGA[] = "{ text: '{$DADA}', leaf: true, bid: {$BID}, eid: {$EID} }";
};
};
$EVEVE = "{ text: 'Events by Hours', leaf: false, expanded: true, children:[". implode( ",", $SIGA ) . "]}";
if( count( $JIGA ) ){
$NONO = "{ text: 'Sessions', leaf: false, expanded: true, children:[". implode( ",", $JIGA ) . "]}";
} else {
$NONO = "{ text: 'No Sessions', leaf: true }";
};
if( count( $SIGA ) ){
usort( $SIGA, function( $A, $B ){ return $A['k'] - $B['k']; } );
$EVEVE = "{ text: 'Events by Hours', leaf: false, expanded: true, children:[". implode( ",", array_column( $SIGA, 'n' ) ) . "]}";
};
};
if( $NONO=='' ) $NONO = "{ text: 'No Sessions', leaf: true }";

10
lib/controller/getHistoryEvents.php

@ -15,14 +15,16 @@
foreach( $result as $R ) $NodeNames[$R['id']] = $R['name'];
$DS = date("Y/m/d", $DTS );
//$QS = "SELECT `events`.*, `events_2_videos`.* FROM `events` LEFT JOIN `events_2_videos` ON( `events`.`id` = `events_2_videos`.`evt_id` ) WHERE `events`.`id` >= {$BID} AND `events`.`id`<={$EID} ORDER BY `ts` ASC, `ts_ms` ASC";
$QS = "SELECT `events`.*, `events_2_videos`.`video_id`, `events_2_pictures`.`picture_id` FROM `events` LEFT JOIN `events_2_videos` ON( `events`.`id` = `events_2_videos`.`evt_id` ) LEFT JOIN `events_2_pictures` ON( `events`.`id` = `events_2_pictures`.`evt_id` ) WHERE `events`.`id`>={$BID} AND `events`.`id`<={$EID} ORDER BY `events`.`ts` ASC, `events`.`ts_ms` ASC";
$ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db');
// BID/EID are global ids of one report file (see report_files.php)
list( $SLOT, $RBID, $REID ) = reportResolveRange( $BID, $EID );
$QS = "SELECT `events`.*, `events_2_videos`.`video_id`, `events_2_pictures`.`picture_id` FROM `events` LEFT JOIN `events_2_videos` ON( `events`.`id` = `events_2_videos`.`evt_id` ) LEFT JOIN `events_2_pictures` ON( `events`.`id` = `events_2_pictures`.`evt_id` ) WHERE `events`.`id`>={$RBID} AND `events`.`id`<={$REID} ORDER BY `events`.`ts` ASC, `events`.`ts_ms` ASC";
$ZIZI = reportOpenSlot( $DS, $SLOT );
//$LREC = array_reverse( $ZIZI->Query( $QS ) );
$LREC = $ZIZI->Query( $QS );
$LREC = $ZIZI ? $ZIZI->Query( $QS ) : array();
$Data['log'] = array();
//date_default_timezone_set('America/New_York');
foreach( $LREC as $REC ){
$CR['id'] = intval( $REC['id'] );
$CR['id'] = reportEncodeId( $SLOT, $REC['id'] );
$CR['node_id'] = intval( $REC['node_id'] );
$CR['node_name'] = $NodeNames[$CR['node_id']];
$CR['rts'] = $DTS;

9
lib/controller/getPictureInfo.php

@ -6,9 +6,12 @@
if( $EID ){
$DS = date("Y/m/d", $DTS );
//$QS = "SELECT * FROM `videos` WHERE `id` = {$VID}";
$QS = "SELECT `pictures`.`media_stream_id`, `pictures`.`md5`, `pictures`.`ext` FROM `events_2_pictures` LEFT JOIN `pictures` ON( `pictures`.`id` = `events_2_pictures`.`picture_id` ) WHERE `events_2_pictures`.`evt_id`={$EID}";
$ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db');
$LREC = $ZIZI->Query( $QS );
// ID is a global event id (see report_files.php)
$SLOT = reportSlotOf( $EID );
$REID = reportRawId( $EID );
$QS = "SELECT `pictures`.`media_stream_id`, `pictures`.`md5`, `pictures`.`ext` FROM `events_2_pictures` LEFT JOIN `pictures` ON( `pictures`.`id` = `events_2_pictures`.`picture_id` ) WHERE `events_2_pictures`.`evt_id`={$REID}";
$ZIZI = reportOpenSlot( $DS, $SLOT );
$LREC = $ZIZI ? $ZIZI->Query( $QS ) : array();
if( count( $LREC ) ){
$Pack = array();
$Pack['pictures'] = array();

25
lib/controller/getStatus.php

@ -22,18 +22,33 @@
$STR = $STATS->Query( $QS );
if( count( $STR ) ){
$DTS = sprintf("%04d/%02d/%02d", intval($STR[0]['year']), intval($STR[0]['month']), intval($STR[0]['day']));
$ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DTS.'/report.db');
$QS = "SELECT `id` FROM `events` WHERE `id` > {$LLID} LIMIT 1";
$CH = $ZIZI->Query( $QS );
// Newest report file of the newest day: last hourly report_HH.db (or legacy report.db)
// LSID is the global id of the last event the browser has (see report_files.php)
$RFILES = reportDayFiles( $DTS );
$CH = array();
if( count( $RFILES ) ){
$HOURS = array_diff( array_keys( $RFILES ), array( REPORT_LEGACY_SLOT ) );
$SLOT = count( $HOURS ) ? max( $HOURS ) : REPORT_LEGACY_SLOT;
$ZIZI = new SQLite_DB( $RFILES[$SLOT], SQLITE3_OPEN_READWRITE );
$RLLID = reportRawId( $LLID );
if( reportSlotOf( $LLID ) != $SLOT ){
$RLLID = 0; // new file (next hour / day): everything in it is new
} else {
$MX = $ZIZI->Query( "SELECT MAX(`id`) AS `m` FROM `events`" );
if( count( $MX ) && intval( $MX[0]['m'] ) < $RLLID ) $RLLID = 0; // same hour of another day
};
$QS = "SELECT `id` FROM `events` WHERE `id` > {$RLLID} LIMIT 1";
$CH = $ZIZI->Query( $QS );
};
if( count( $CH ) ){
$QS = "SELECT * FROM nodes";
$result = $DATABASE->Query( $QS, false );
$NodeNames = array();
foreach( $result as $R ) $NodeNames[$R['id']] = $R['name'];
$QS = "SELECT `id`,`node_id`, `evt_type`, `ts`, `ts_ms`, `range_digital`, `azimuth`, `elevation`, `range`, `area`, `lrf_id` FROM `events` WHERE `id` > {$LLID} ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 32";
$QS = "SELECT `id`,`node_id`, `evt_type`, `ts`, `ts_ms`, `range_digital`, `azimuth`, `elevation`, `range`, `area`, `lrf_id` FROM `events` WHERE `id` > {$RLLID} ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 32";
$LREC = $ZIZI->Query( $QS );
foreach( $LREC as $REC ){
$CR['id'] = intval( $REC['id'] );
$CR['id'] = reportEncodeId( $SLOT, $REC['id'] );
$CR['node_id'] = intval( $REC['node_id'] );
$CR['node_name'] = $NodeNames[$CR['node_id']];
$CR['ts'] = intval( $REC['ts'] );

15
lib/controller/getVideoInfo.php

@ -6,14 +6,21 @@
if( $EID ){
$DS = date("Y/m/d", $DTS );
//$QS = "SELECT * FROM `videos` WHERE `id` = {$VID}";
$QS = "SELECT `videos`.`id`, `videos`.`fps`,`videos`.`uts` as `ts`, `videos`.`md5`, `videos`.`ext`, `videos`.`media_stream_id`, `events_2_videos`.`frame` FROM `events_2_videos` LEFT JOIN `videos` ON( `videos`.`id` = `events_2_videos`.`video_id` ) WHERE `events_2_videos`.`evt_id`={$EID}";
$ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db');
$LREC = $ZIZI->Query( $QS );
// ID is a global event id (see report_files.php); video ids are returned as global ids of the same file
$SLOT = reportSlotOf( $EID );
$REID = reportRawId( $EID );
$QS = "SELECT `videos`.`id`, `videos`.`fps`,`videos`.`uts` as `ts`, `videos`.`md5`, `videos`.`ext`, `videos`.`media_stream_id`, `events_2_videos`.`frame` FROM `events_2_videos` LEFT JOIN `videos` ON( `videos`.`id` = `events_2_videos`.`video_id` ) WHERE `events_2_videos`.`evt_id`={$REID}";
$ZIZI = reportOpenSlot( $DS, $SLOT );
$LREC = $ZIZI ? $ZIZI->Query( $QS ) : array();
if( count( $LREC ) ){
$Pack = array();
$Pack['ts'] = $DTS;
$Pack['videos'] = array();
foreach( $LREC as $Data ) $Pack['videos'][] = $Data;
foreach( $LREC as $Data ){
$Data['id'] = reportEncodeId( $SLOT, $Data['id'] );
$Data['fname'] = date( "Y_m_d_H-i-s", intval( $Data['ts'] ) ); // download file name in host local time
$Pack['videos'][] = $Data;
};
echo json_encode( $Pack );
exit();
};

8
lib/controller/setPermanentBubbles.php

@ -76,9 +76,11 @@
};
if( $UID > 1 && $DTS ){
$DS = date("Y/m/d", $DTS );
$QS = "SELECT * FROM `events` WHERE ( `evt_type`=13 OR `evt_type`=14 ) AND `id`>={$BID} AND `id`<={$EID} ORDER BY `ts` ASC, `ts_ms` ASC";
$ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db');
$LREC = $ZIZI->Query( $QS );
// BID/EID are global ids of one report file (see report_files.php)
list( $SLOT, $RBID, $REID ) = reportResolveRange( $BID, $EID );
$QS = "SELECT * FROM `events` WHERE ( `evt_type`=13 OR `evt_type`=14 ) AND `id`>={$RBID} AND `id`<={$REID} ORDER BY `ts` ASC, `ts_ms` ASC";
$ZIZI = reportOpenSlot( $DS, $SLOT );
$LREC = $ZIZI ? $ZIZI->Query( $QS ) : array();
if( count( $LREC ) ){
foreach( $LREC as $REC ){
$bid = serchInBubbles( $REC );

4
lib/javascript/jsapi_dynamic/mojo_reports.js

@ -1047,6 +1047,7 @@ function loadEventData( record ){
videoNfo[data.videos[i].media_stream_id][1] = data.videos[i].md5;
videoNfo[data.videos[i].media_stream_id][2] = data.videos[i].fps;
videoNfo[data.videos[i].media_stream_id][3] = data.videos[i].ext;
videoNfo[data.videos[i].media_stream_id][4] = data.videos[i].fname; // host local time stamp for file name
data.videos[i].frame -= 20;
if( data.videos[i].frame < 0 ) data.videos[i].frame = 0;
@ -1898,7 +1899,8 @@ function showVideos(){
function downloadCurrentVideo( stid ){
var d = new Date( videoNfo[stid][0] * 1000 );
var videoFileDownloadTarget = d.getFullYear().toString().padStart(4, '0')+'_'+(d.getMonth()+1).toString().padStart(2, '0')+'_'+d.getDate().toString().padStart(2, '0')+'_'+d.getHours().toString().padStart(2, '0')+'-'+d.getMinutes().toString().padStart(2, '0')+'-'+d.getSeconds().toString().padStart(2, '0');
// File name in the host's local time (from the server); browser local time only as a fallback
var videoFileDownloadTarget = videoNfo[stid][4] ? videoNfo[stid][4] : d.getFullYear().toString().padStart(4, '0')+'_'+(d.getMonth()+1).toString().padStart(2, '0')+'_'+d.getDate().toString().padStart(2, '0')+'_'+d.getHours().toString().padStart(2, '0')+'-'+d.getMinutes().toString().padStart(2, '0')+'-'+d.getSeconds().toString().padStart(2, '0');
// TS, MD5, FPS, EXT
downloadVideoFile( videoNfo[stid][0], videoNfo[stid][1], videoNfo[stid][2], videoFileDownloadTarget, videoNfo[stid][3] );
};

1
lib/js_asm.php

@ -1,6 +1,7 @@
<?php
error_reporting( E_ALL );
require_once('settings.php');
require_once( __DIR__ . '/php/host_timezone.php'); // PHP must use the host's local time zone
require_once('defines.php');
// SET DATA CONNECTION AND GLOBAL USER VARIABLES

74
lib/php/db/report_files.php

@ -0,0 +1,74 @@
<?php
/*
* Report database files of a day folder.
*
* la_mojo writes one report database per local hour into the day folder:
* data/reports/YYYY/MM/DD/report_HH.db (HH = 00..23)
* Days recorded before that change have a single data/reports/YYYY/MM/DD/report.db
* (the "legacy" file); a day during the upgrade can have both.
*
* Row ids (events, pictures, videos) are AUTOINCREMENT per file, so ids sent to the browser
* carry the file ("slot") they belong to:
* global id = slot * REPORT_ID_SLOT + rowid slot: 0..23 = hour file, 24 = legacy report.db
* The browser treats ids as opaque values and sends them back unchanged; controllers decode them
* with reportSlotOf() / reportRawId(). The largest id (24 * 10^7 + 9999999) fits a 32-bit int.
*/
define('REPORT_ID_SLOT', 10000000);
define('REPORT_LEGACY_SLOT', 24);
define('REPORT_RAW_ID_MAX', REPORT_ID_SLOT - 1);
function reportDayDir( $DS ){
global $SYSPath;
return $SYSPath . '/lib/controller/data/reports/' . $DS;
}
// Path of the report file of a slot (does not check existence)
function reportSlotPath( $DS, $slot ){
if( $slot == REPORT_LEGACY_SLOT ) return reportDayDir( $DS ) . '/report.db';
return reportDayDir( $DS ) . sprintf( '/report_%02d.db', $slot );
}
// Existing report files of a day: array( slot => path ), legacy report.db first, then hours ascending
function reportDayFiles( $DS ){
$RV = array();
$P = reportSlotPath( $DS, REPORT_LEGACY_SLOT );
if( file_exists( $P ) ) $RV[REPORT_LEGACY_SLOT] = $P;
for( $H = 0; $H < 24; $H++ ){
$P = reportSlotPath( $DS, $H );
if( file_exists( $P ) ) $RV[$H] = $P;
};
return $RV;
}
// Opens the report file of a slot; NULL if it does not exist (never creates a file)
function reportOpenSlot( $DS, $slot ){
if( $slot < 0 || $slot > REPORT_LEGACY_SLOT ) return NULL;
$P = reportSlotPath( $DS, $slot );
if( !file_exists( $P ) ) return NULL;
return new SQLite_DB( $P, SQLITE3_OPEN_READWRITE );
}
function reportEncodeId( $slot, $id ){
return intval( $slot ) * REPORT_ID_SLOT + intval( $id );
}
function reportSlotOf( $gid ){
return intdiv( intval( $gid ), REPORT_ID_SLOT );
}
function reportRawId( $gid ){
return intval( $gid ) % REPORT_ID_SLOT;
}
/*
* Resolves a BID..EID range of global ids (always inside one report file) to
* array( slot, raw_bid, raw_eid ). If EID points past the file of BID (e.g. "until the end"),
* the range runs to the end of BID's file.
*/
function reportResolveRange( $BID, $EID ){
$slot = reportSlotOf( $BID > 0 ? $BID : $EID );
$rb = ( reportSlotOf( $BID ) == $slot ) ? reportRawId( $BID ) : 0;
$re = ( reportSlotOf( $EID ) == $slot ) ? reportRawId( $EID ) : REPORT_RAW_ID_MAX;
return array( $slot, $rb, $re );
}
?>

30
lib/php/host_timezone.php

@ -0,0 +1,30 @@
<?php
/*
* Use the host system's local time zone for all PHP date/time formatting.
*
* PHP does not follow the host time zone: without date.timezone in php.ini it uses UTC, so
* report days, session and event times were shown in UTC instead of the local time that
* la_mojo uses for report folders/files (data/reports/YYYY/MM/DD/report_HH.db).
*
* Source of the host zone, in order:
* /etc/localtime symlink (what timedatectl set-timezone maintains), /etc/timezone, TZ variable.
*/
function hostTimezoneName(){
$Candidates = array();
$L = @readlink( '/etc/localtime' );
if( $L !== false && ( $P = strpos( $L, 'zoneinfo/' ) ) !== false ){
$Candidates[] = substr( $L, $P + 9 );
};
$T = @file_get_contents( '/etc/timezone' );
if( $T !== false ) $Candidates[] = trim( $T );
$E = getenv( 'TZ' );
if( $E !== false ) $Candidates[] = ltrim( trim( $E ), ':' );
foreach( $Candidates as $C ){
if( $C !== '' && in_array( $C, timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ) ) ) return $C;
};
return NULL;
}
$HOST_TZ = hostTimezoneName();
if( $HOST_TZ !== NULL ) date_default_timezone_set( $HOST_TZ );
?>

1
lib/soap_asm.php

@ -1,6 +1,7 @@
<?php
error_reporting( E_ALL );
require_once('settings.php');
require_once( __DIR__ . '/php/host_timezone.php'); // PHP must use the host's local time zone
require_once('defines.php');
require_once('php/onvif/toto.php');

1
lib/ui_asm.php

@ -1,6 +1,7 @@
<?php
require_once('settings.php');
require_once( __DIR__ . '/php/host_timezone.php'); // PHP must use the host's local time zone
require_once('defines.php');
Loading…
Cancel
Save