Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
4.5 KiB

​
​
4 years ago
3 years ago
3 years ago
​
​
3 years ago
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
3 years ago
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
3 years ago
​
4 years ago
​
​
​
​
​
  1. <?php
  2. require_once('../ajax_asm.php');
  3. if( $CUser->Data['id'] > 1 ){
  4. $DTS = intval( $_POST['DTS'] );
  5. if( $DTS ){
  6. $TZ = new DateTimeZone( date_default_timezone_get() );
  7. $DT = new DateTime("now", $TZ );
  8. $DIDI = $TZ->getOffset( $DT );
  9. $Data['tz_offset']=$DIDI;
  10. // DTS is the day key from getHistoryDates (host local noon of the day) - no offset correction needed
  11. $Y = date("Y", $DTS );
  12. $M = date("m", $DTS );
  13. $D = date("d", $DTS );
  14. $DS = date("Y/m/d", $DTS );
  15. $NONO = '';
  16. $EVEVE = '';
  17. $MUMU = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/stat.db' );
  18. $QS = "SELECT * FROM `days` WHERE `year`={$Y} AND `month`={$M} AND `day`={$D}";
  19. $LOLO = $MUMU->Query( $QS );
  20. $S = 0;
  21. $V = 0;
  22. $E = 0;
  23. if( count( $LOLO ) ){
  24. $S = intval( $LOLO[0]['session_count'] );
  25. $V = intval( $LOLO[0]['videos_count'] );
  26. $E = intval( $LOLO[0]['evt_count'] );
  27. // One report file per hour (report_HH.db) and/or the legacy day report.db - ids are global (see report_files.php)
  28. $JIGA = array();
  29. $SIGA = array();
  30. foreach( reportDayFiles( $DS ) as $SLOT => $RFILE ){
  31. $ZIZI = new SQLite_DB( $RFILE, SQLITE3_OPEN_READWRITE );
  32. // Sessions (START=52, END=53/54) - with hourly files a session never spans two files
  33. $QS = "SELECT `id`, `ts`, `evt_type` FROM `events` WHERE ( `evt_type`=52 OR `evt_type`=53 OR `evt_type`=54 ) ORDER BY `id`";
  34. $NDD = $ZIZI->Query( $QS );
  35. if( count( $NDD ) ){
  36. $st_ignore = true;
  37. $DH = 0;
  38. $BID = 0;
  39. $EID = 0;
  40. $BTM = 0;
  41. foreach( $NDD as $N ){
  42. if( $st_ignore && $N['evt_type']!=52 ) continue;
  43. if( $st_ignore && $N['evt_type']==52 ) $st_ignore = false;
  44. if( $N['evt_type']==52 ) {
  45. $DH = 0;
  46. $BID = reportEncodeId( $SLOT, $N['id'] );
  47. $BTM = date( "H:i:s", $N['ts'] );
  48. } else {
  49. $DH = 1;
  50. $EID = reportEncodeId( $SLOT, $N['id'] );
  51. };
  52. if( $st_ignore == false && $DH == 1 ){
  53. $JIGA[] = "{ text: '{$BTM}', leaf: true, bid: {$BID}, eid: {$EID} }";
  54. };
  55. };
  56. if( $st_ignore == false && $DH == 0 ){
  57. // Session still open in this file (ongoing, or the file was not closed) - up to the end of the file
  58. $EID = reportEncodeId( $SLOT, REPORT_RAW_ID_MAX );
  59. $JIGA[] = "{ text: '{$BTM}', leaf: true, bid: {$BID}, eid: {$EID} }";
  60. };
  61. };
  62. // Events by hours
  63. if( $SLOT == REPORT_LEGACY_SLOT ){
  64. // Legacy day file: split by hour
  65. $QS = "SELECT DISTINCT `ts`/3600 AS JUJA FROM `events`";
  66. $NDD = $ZIZI->Query( $QS );
  67. foreach( $NDD as $N ){
  68. $BTS = intval($N['JUJA'])*3600;
  69. $DADA = date( "H:i", $BTS );
  70. $ETS = $BTS+3600;
  71. $BID = 0;
  72. $EID = 0;
  73. $QS="SELECT `id` FROM `events` WHERE `ts`>({$BTS}-1) LIMIT 1";
  74. $KK = $ZIZI->Query( $QS );
  75. if( count( $KK ) ) $BID = $KK[0]['id'];
  76. $QS="SELECT `id` FROM `events` WHERE `ts`<({$ETS}-1) ORDER BY `id` DESC LIMIT 1";
  77. $KK = $ZIZI->Query( $QS );
  78. if( count( $KK ) ) $EID = $KK[0]['id']; else $EID = $BID;
  79. if( $BID && $EID ){
  80. $BID = reportEncodeId( $SLOT, $BID );
  81. $EID = reportEncodeId( $SLOT, $EID );
  82. $SIGA[] = array( 'k' => $BTS, 'n' => "{ text: '{$DADA}', leaf: true, bid: {$BID}, eid: {$EID} }" );
  83. };
  84. };
  85. } else {
  86. // Hourly file: one node for the whole file
  87. $KK = $ZIZI->Query( "SELECT MIN(`id`) AS `b`, MAX(`id`) AS `e`, MIN(`ts`) AS `t` FROM `events`" );
  88. if( count( $KK ) && intval( $KK[0]['b'] ) ){
  89. $BID = reportEncodeId( $SLOT, $KK[0]['b'] );
  90. $EID = reportEncodeId( $SLOT, $KK[0]['e'] );
  91. $DADA = sprintf( "%02d:00", $SLOT );
  92. $SIGA[] = array( 'k' => intval( $KK[0]['t'] ), 'n' => "{ text: '{$DADA}', leaf: true, bid: {$BID}, eid: {$EID} }" );
  93. };
  94. };
  95. };
  96. if( count( $JIGA ) ){
  97. $NONO = "{ text: 'Sessions', leaf: false, expanded: true, children:[". implode( ",", $JIGA ) . "]}";
  98. } else {
  99. $NONO = "{ text: 'No Sessions', leaf: true }";
  100. };
  101. if( count( $SIGA ) ){
  102. usort( $SIGA, function( $A, $B ){ return $A['k'] - $B['k']; } );
  103. $EVEVE = "{ text: 'Events by Hours', leaf: false, expanded: true, children:[". implode( ",", array_column( $SIGA, 'n' ) ) . "]}";
  104. };
  105. };
  106. if( $NONO=='' ) $NONO = "{ text: 'No Sessions', leaf: true }";
  107. if( $EVEVE=='' ) $EVEVE = "{ text: 'No Events', leaf: true }";
  108. echo "{tz_off: {$DIDI}, base_path: '{$DS}', expanded: true, children: [{$NONO},{$EVEVE}], sessions:{$S}, events:{$E}, videos:{$V} }";
  109. } else {
  110. echo "[]";
  111. };
  112. } else {
  113. header('location: /');
  114. };
  115. ?>