0; foreach (self::$SECS_LIST as $k) { if (isset($entry[$k])) { $entry[$k . '_s'] = self::formatSeconds($entry[$k]); if ($perc && $k !== 'totalTime') { $entry[$k . '_p'] = round($entry[$k] / $entry['totalTime'] * 100); } } } foreach (self::$TS_LIST as $k) { if (isset($entry[$k])) { $entry[$k . '_s'] = Util::prettyTime($entry[$k]); } } } // total public static function total($flags = 0) { $printable = 0 !== ($flags & GETDATA_PRINTABLE); // total time online, average time online, total number of logins $data = Queries::getOverallStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); if ($printable) { self::addPrintables($data); } $data['uniqueUsers'] = Queries::getUniqueUserCount(self::$from, self::$to); return $data; } // per location public static function perLocation($flags = 0) { $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); $printable = 0 !== ($flags & GETDATA_PRINTABLE); $data = Queries::getLocationStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); foreach ($data as &$entry) { //self::nullToZero($entry); self::fillLocation($entry, $anonymize); if ($printable) { self::addPrintables($entry); } } return $data; } // per client public static function perClient($flags = 0, $new = false) { $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); $printable = 0 !== ($flags & GETDATA_PRINTABLE); $data = Queries::getClientStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); foreach ($data as &$entry) { //self::nullToZero($entry); $entry['hostname'] = ($anonymize ? md5($entry['clientName'] . self::$salt) : $entry['clientName']); self::fillLocation($entry, $anonymize); if ($printable) { self::addPrintables($entry); } } return $data; } // per user public static function perUser($flags = 0) { $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); $res = Queries::getUserStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { if ($anonymize && $row['name'] !== 'anonymous') { $row['name'] = md5($row['name'] . self::$salt); } $data[] = array('user' => $row['name'], 'sessions' => $row['count']); } return $data; } // per vm public static function perVM($flags = 0) { $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); $res = Queries::getVMStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { self::nullToZero($row); if ($anonymize) { $row['name'] = md5($row['name'] . self::$salt); } $data[] = array('vm' => $row['name'], 'sessions' => $row['count']); } return $data; } private static function nullToZero(&$row) { foreach ($row as &$field) { if (is_null($field)) { $field = 0; } } } // Format $seconds into ".d .h .m .s" format (day, hour, minute, second) private static function formatSeconds($seconds) { return sprintf('%dd, %02d:%02d:%02d', $seconds / (3600*24), ($seconds % (3600*24)) / 3600, ($seconds%3600) / 60, $seconds%60); } }