|
|
<?php require_once('../ajax_asm.php'); if( $CUser->Data['id'] > 1 ){ $DTS = intval( $_POST['DTS'] ); if( $DTS ){ $TZ = new DateTimeZone( date_default_timezone_get() ); $DT = new DateTime("now", $TZ ); $DIDI = $TZ->getOffset( $DT ); $Data['tz_offset']=$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 ); $S = 0; $V = 0; $E = 0; if( count( $LOLO ) ){ $S = intval( $LOLO[0]['session_count'] ); $V = intval( $LOLO[0]['videos_count'] ); $E = intval( $LOLO[0]['evt_count'] ); // 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 == 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} }"; }; }; // 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 ); 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} }" ); }; }; } else { // 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} }" ); }; }; }; 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 }"; if( $EVEVE=='' ) $EVEVE = "{ text: 'No Events', leaf: true }"; echo "{tz_off: {$DIDI}, base_path: '{$DS}', expanded: true, children: [{$NONO},{$EVEVE}], sessions:{$S}, events:{$E}, videos:{$V} }"; } else { echo "[]"; }; } else { header('location: /'); };?>
|