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 ); } ?>