YaWK  24.1
Yet another WebKit
YAWK\stats Class Reference

Statistics - get and set user and page stats. More...

Public Member Functions

 calculateStatsFromArray ($db, $data)
 Calculate some basic stats (almost outdated) More...
 
 construct ()
 
 countBrowsers ($db, $data)
 Count and return browsers. More...
 
 countDaytime ($db, $data, $lang)
 Count and set the number of hits for each daytime. More...
 
 countDeviceTypes ($db, $data)
 Count device types (desktop, phone or tablet) More...
 
 countLogins ($db)
 Count system logins. More...
 
 countMessages ($db)
 Count all messages that are stored in the database. More...
 
 countOS ($db, $data)
 Count operating systems. More...
 
 countOSVersions ($db, $data)
 Count operating systems versions. More...
 
 countWeekdays ($db, $data, $lang, $limit)
 Count and set the number of hits for each weekday. More...
 
 deleteOutdatedSessions ($db)
 Check and delete outdated sessions if they are expired. More...
 
 drawOverviewBox ($lang)
 Draw default box containing overview statistics. More...
 
 drawPagesBox ($data, $lang)
 Draw default box containing pages statistics. More...
 
 drawUserStats ($db, $lang)
 Draw a default box containing user statistics. More...
 
 getBrowserColors ($browser)
 Set and return the legend textcolor for each browser. More...
 
 getDaysOfMonthBox ($lang)
 Draw default box containing days of month statistics. More...
 
 getDaytimeColors ($daytime, $lang)
 Set and return the legend textcolor for each daytime. More...
 
 getDayTimesPercent ($lang)
 Calculate hits per daytime and return data in percent. More...
 
 getDeviceTypeColors ($deviceType)
 Set and return the legend textcolor for each device type. More...
 
 getJsonBrowsers ($db, $browsers)
 Output JS: PIE CHART browser data. More...
 
 getJsonDaytimeBarChart ($db, $daytimes, $lang)
 Output JS: BAR CHART daytime data. More...
 
 getJsonDaytimeLineChart ($db, $daytimes, $lang)
 Output JS: LINE CHART daytime data. More...
 
 getJsonDaytimePieChart ($db, $daytimes, $lang)
 Output JS: PIE CHART daytime data. More...
 
 getJsonDeviceTypes ($db, $deviceTypes, $lang)
 Output JS: BAR CHART device types. More...
 
 getJsonLogins ($db, $logins, $lang)
 Output JS: PIE CHART login data. More...
 
 getJsonOS ($db, $oss)
 Output JS: PIE CHART OS data. More...
 
 getJsonOSVersions ($db, $osVersions)
 Output JS: BAR CHART OS versions. More...
 
 getJsonWeekdayBarChart ($lang)
 Output JS: WEEKDAY BAR CHART. More...
 
 getLoginColors ($login)
 Set and return the legend textcolor for logins (failed | success) More...
 
 getOnlineUsers ($db)
 Return the number of all currently online users. More...
 
 getOsColors ($os)
 Set and return the legend textcolor for each operating system. More...
 
 getOsVersionsColors ($osVersions)
 Set and return the legend textcolor for each OS Version. More...
 
 getStatsArray ($db, $interval, $period)
 Returns an array with all stats, ordered by date_created. More...
 
 getUserStats ($db)
 Count and set user stats like, how many users are registered, currently online or blocked. More...
 
 getWeekdaysPercent ($lang)
 Calculate hits in percent for each weekday. More...
 
 insertData ($db)
 Insert data into database. More...
 
 prepareData ()
 Prepare data: get and collect, detect OS and device type. More...
 
 setOnlineUsers ($db)
 Set users online in database (stores and check sessions and timestamps) More...
 
 setStats ($db)
 Insert statistics data into database. More...
 

Public Attributes

 $acceptLanguage
 
 $activeSessions
 
 $browser
 
 $browserVersion
 
 $currentOnline = 0
 
 $currentTimeStamp
 
 $date_created
 
 $device
 
 $deviceType
 
 $gid = 0
 
 $i_afternoon = 0
 
 $i_afternoonPercent = 0
 
 $i_android = 0
 
 $i_blackberry = 0
 
 $i_blockedUsers = 0
 
 $i_desktop = 0
 
 $i_desktopPercent = 0
 
 $i_evening = 0
 
 $i_eveningPercent = 0
 
 $i_friday = 0
 
 $i_fridayPercent = 0
 
 $i_hits = 0
 
 $i_iOS = 0
 
 $i_iPad = 0
 
 $i_iPhone = 0
 
 $i_iPod = 0
 
 $i_linux = 0
 
 $i_loggedInUsers = 0
 
 $i_loggedUsers = 0
 
 $i_loggedUsersPercentage = 0
 
 $i_loginBackend = 0
 
 $i_loginBackendFailed = 0
 
 $i_loginBackendSuccess = 0
 
 $i_loginFailed = 0
 
 $i_loginFailedPercentage = 0
 
 $i_loginFrontend = 0
 
 $i_loginFrontendFailed = 0
 
 $i_loginFrontendSuccess = 0
 
 $i_loginSuccessful = 0
 
 $i_loginSuccessPercentage = 0
 
 $i_macos9 = 0
 
 $i_macosX = 0
 
 $i_mobile = 0
 
 $i_monday = 0
 
 $i_mondayPercent = 0
 
 $i_morning = 0
 
 $i_morningPercent = 0
 
 $i_night = 0
 
 $i_nightPercent = 0
 
 $i_osAndroid = 0
 
 $i_osLinux = 0
 
 $i_osMac = 0
 
 $i_osUnknown = 0
 
 $i_osWindows = 0
 
 $i_others = 0
 
 $i_phone = 0
 
 $i_phonePercent = 0
 
 $i_publicUsers = 0
 
 $i_publicUsersPercentage = 0
 
 $i_saturday = 0
 
 $i_saturdayPercent = 0
 
 $i_sunday = 0
 
 $i_sundayPercent = 0
 
 $i_tablet = 0
 
 $i_tabletPercent = 0
 
 $i_thursday = 0
 
 $i_thursdayPercent = 0
 
 $i_totalDays = 0
 
 $i_totalLogins = 0
 
 $i_tuesday = 0
 
 $i_tuesdayPercent = 0
 
 $i_ubuntu = 0
 
 $i_users = 0
 
 $i_wednesday = 0
 
 $i_wednesdayPercent = 0
 
 $i_windows10 = 0
 
 $i_windows11 = 0
 
 $i_windows2000 = 0
 
 $i_windows311 = 0
 
 $i_windows7 = 0
 
 $i_windows8 = 0
 
 $i_windows95 = 0
 
 $i_windows98 = 0
 
 $i_windowsME = 0
 
 $i_windowsServer = 0
 
 $i_windowsVista = 0
 
 $i_windowsXP = 0
 
 $id
 
 $logged_in = 0
 
 $os
 
 $osVersion
 
 $page
 
 $phpSessionID
 
 $referer
 
 $remoteAddr
 
 $uid = 0
 
 $userAgent
 

Detailed Description

Statistics - get and set user and page stats.

Author
Daniel Retzl danie.nosp@m.lret.nosp@m.zl@gm.nosp@m.ail..nosp@m.com
Version
1.0.0

Definition at line 9 of file stats.php.

Member Function Documentation

◆ calculateStatsFromArray()

YAWK\stats::calculateStatsFromArray (   $db,
  $data 
)

Calculate some basic stats (almost outdated)

Parameters
object$dbDatabase Object
array$dataStats Data Array

Definition at line 2097 of file stats.php.

2099  { // get stats data
2100  if (!isset($data) || (empty($data)))
2101  {
2102  // get statistics into array
2103  $data = $this->getStatsArray($db, '', '');
2104  }
2105  // count and analyze the stats data in a loop
2106  foreach ($data as $value => $item)
2107  {
2108  // count hits
2109  $this->i_hits++;
2110 
2111  // count how many users were logged in
2112  if ($item['logged_in'] === "1")
2113  {
2114  $this->i_loggedUsers++;
2115  }
2116 
2117  // count how many users were guests (or not logged in)
2118  if ($item['logged_in'] === "0")
2119  {
2120  $this->i_publicUsers++;
2121  }
2122 
2123  // calculate percentage of guests vs logged in users
2124  $percentage = 100 / $this->i_hits;
2125  $this->i_loggedUsersPercentage = $this->i_loggedUsers * $percentage;
2126  $this->i_publicUsersPercentage = $this->i_publicUsers * $percentage;
2127  $this->i_loggedUsersPercentage = round($this->i_loggedUsersPercentage, 1, PHP_ROUND_HALF_UP);
2128  $this->i_publicUsersPercentage = round($this->i_publicUsersPercentage, 1, PHP_ROUND_HALF_UP);
2129 
2130  }
2131 
2132  /*
2133  echo "Total hits: ".$this->i_hits."<br>";
2134  echo "davon Phone: ".$this->i_phone."<br>";
2135  echo "davon Tablet: ".$this->i_tablet."<br>";
2136  echo "davon Desktop: ".$this->i_desktop." Win: $this->i_osWindows Mac: $this->i_osMac Linux: $this->i_osLinux<br>";
2137  echo "<pre>";
2138  print_r($data);
2139  echo "</pre>";
2140  */
$data
Definition: stats.php:78
if(!isset($language)||(!isset($lang))) $item
getStatsArray($db, $interval, $period)
Returns an array with all stats, ordered by date_created.
Definition: stats.php:2025
$value

References $data, $db, YAWK\stats\$i_hits, $item, $value, and YAWK\stats\getStatsArray().

Referenced by YAWK\stats\getStatsArray().

◆ construct()

YAWK\stats::construct ( )

Definition at line 223 of file stats.php.

225  {
226 

◆ countBrowsers()

YAWK\stats::countBrowsers (   $db,
  $data 
)

Count and return browsers.

Parameters
object$dbthe database object
string$dataarray containing all the stats data
string$limitcontains i number for sql limitation
Returns
array|bool returning array containing the browsers and their hits

Definition at line 1573 of file stats.php.

1575  { /* @param $db \YAWK\db */
1576 
1577  /*
1578  // check if limit (i) is set
1579  if (!isset($limit) || (empty($limit)))
1580  { // set default value
1581  $limit = 100;
1582  }
1583  */
1584 
1585  // this vars stores the counting for each browser
1586  $n_msie = 0;
1587  $n_chrome = 0;
1588  $n_firefox = 0;
1589  $n_opera = 0;
1590  $n_safari = 0;
1591  $n_netscape = 0;
1592  $n_others = 0;
1593  $total = 0;
1594 
1595  // check if data array is set, if not load data from db
1596  if (!isset($data) || (empty($data) || (!is_array($data))))
1597  { // data is not set or in false format, try to get it from database
1598  // \YAWK\alert::draw("warning", "database needed", "need to get browser data - array not set, empty or not an array.", "", 0);
1599  if ($res = $db->query("SELECT browser FROM {stats} ORDER BY id DESC"))
1600  { // create array
1601  $data = array();
1602  while ($row = mysqli_fetch_assoc($res))
1603  { // add data to array
1604  $data[] = $row;
1605  $total++;
1606  }
1607  }
1608  else
1609  { // data array not set and unable to get data from db
1610  return false;
1611  }
1612  }
1613 
1614  /*
1615  // LIMIT the data to x entries
1616  if (isset($limit) && (!empty($limit)))
1617  { // if limit is set, cut array to limited range
1618  $data = array_slice($data, 0, $limit, true);
1619  }
1620  */
1621 
1622  // count browsers
1623  foreach ($data AS $item => $browser) { // add +1 for each found
1624  switch ($browser['browser']) {
1625  case "Google Chrome":
1626  $n_chrome++;
1627  break;
1628  case "Internet Explorer":
1629  $n_msie++;
1630  break;
1631  case "Mozilla Firefox":
1632  $n_firefox++;
1633  break;
1634  case "Apple Safari":
1635  $n_safari++;
1636  break;
1637  case "Opera":
1638  $n_opera++;
1639  break;
1640  case "Netscape":
1641  $n_netscape++;
1642  break;
1643  default:
1644  $n_others++;
1645  }
1646  }
1647  // get the sum of all detected browsers
1648  $total = $n_chrome+$n_msie+$n_firefox+$n_safari+$n_opera+$n_netscape+$n_others;
1649 
1650  // build an array, cointaining the browsers and the number how often it's been found
1651  $browsers = array(
1652  "Chrome" => $n_chrome,
1653  "IE" => $n_msie,
1654  "Firefox" => $n_firefox,
1655  "Safari" => $n_safari,
1656  "Opera" => $n_opera,
1657  "Netscape" => $n_netscape,
1658  "Others" => $n_others,
1659  "Total" => $total
1660  );
1661 
1662  // return browser data array
1663  return $browsers;
$total
Definition: yawk-stats.php:102

References YAWK\stats\$browser, $data, $db, $item, $res, and $total.

Referenced by YAWK\stats\getJsonBrowsers().

◆ countDaytime()

YAWK\stats::countDaytime (   $db,
  $data,
  $lang 
)

Count and set the number of hits for each daytime.

Parameters
object$dbthe database object
string$dataarray containing all the stats data
string$limitcontains i number for sql limitation
Returns
array|bool containing daytimes (and number of hits

Definition at line 1430 of file stats.php.

1432  { /* @param $db \YAWK\db */
1433 
1434  /*
1435  // check if limit (i) is set
1436  if (!isset($limit) || (empty($limit)))
1437  { // set default value
1438  $limit = 100;
1439  }
1440  */
1441 
1442  // check if data array is set, if not load data from db
1443  if (!isset($data) || (empty($data) || (!is_array($data))))
1444  { // data is not set or in false format, try to get it from database
1445  if ($res = $db->query("SELECT date_created FROM {stats} ORDER BY id DESC"))
1446  { // create array
1447  $data = array();
1448  while ($row = mysqli_fetch_assoc($res))
1449  { // add data to array
1450  $data[] = $row;
1451  }
1452  }
1453  else
1454  { // data array not set and unable to get data from db
1455  return false;
1456  }
1457  }
1458 
1459  /*
1460  // LIMIT the data to x entries
1461  if (isset($limit) && (!empty($limit)))
1462  { // if limit is set, cut array to limited range
1463  $data = array_slice($data, 0, $limit, true);
1464  }
1465  */
1466 
1467  // break up the date & extract the hour to calculate
1468  foreach ($data as $date => $value)
1469  {
1470  // get only the hour in a new array
1471  $hour = substr($value['date_created'], 11, -6);
1472 
1473  // identify morning, afternoon, evening + night
1474  if ($hour === "06" ||
1475  ($hour === "07") ||
1476  ($hour === "08") ||
1477  ($hour === "09") ||
1478  ($hour === "10") ||
1479  ($hour === "11"))
1480  {
1481  $this->i_morning++;
1482  }
1483  if ($hour === "12" ||
1484  ($hour === "13") ||
1485  ($hour === "14") ||
1486  ($hour === "15") ||
1487  ($hour === "16") ||
1488  ($hour === "17"))
1489  {
1490  $this->i_afternoon++;
1491  }
1492  if ($hour === "18" ||
1493  ($hour === "19") ||
1494  ($hour === "20") ||
1495  ($hour === "21") ||
1496  ($hour === "22") ||
1497  ($hour === "23"))
1498  {
1499  $this->i_evening++;
1500  }
1501  if ($hour === "00" ||
1502  ($hour === "01") ||
1503  ($hour === "02") ||
1504  ($hour === "03") ||
1505  ($hour === "04") ||
1506  ($hour === "05"))
1507  {
1508  $this->i_night++;
1509  }
1510  }
1511 
1512  // count daytimes
1513  $total = $this->i_morning+$this->i_afternoon+$this->i_evening+$this->i_night;
1514 
1515  // build an array, cointaining the daytimes
1516  $dayTimes = array(
1517  "$lang[MORNING]" => $this->i_morning,
1518  "$lang[AFTERNOON]" => $this->i_afternoon,
1519  "$lang[EVENING]" => $this->i_evening,
1520  "$lang[NIGHT]" => $this->i_night,
1521  "$lang[TOTAL]" => $total
1522  );
1523 
1524  // return OS data array
1525  return $dayTimes;
$date
Definition: user-edit.php:285

References $data, $date, $db, YAWK\stats\$i_night, $res, $total, and $value.

Referenced by YAWK\stats\getJsonDaytimeBarChart(), YAWK\stats\getJsonDaytimeLineChart(), and YAWK\stats\getJsonDaytimePieChart().

◆ countDeviceTypes()

YAWK\stats::countDeviceTypes (   $db,
  $data 
)

Count device types (desktop, phone or tablet)

Parameters
object$dbthe database object
string$dataarray containing all the stats data
string$limitcontains i number for sql limitation
Returns
array|bool returning array containing device types and their hits

Definition at line 1673 of file stats.php.

1675  { /* @param $db \YAWK\db */
1676 
1677  /*
1678  // check if limit (i) is set
1679  if (!isset($limit) || (empty($limit)))
1680  { // set default value
1681  $limit = 100;
1682  }
1683  */
1684 
1685  // check if data array is set, if not load data from db
1686  if (!isset($data) || (empty($data) || (!is_array($data))))
1687  { // data is not set or in false format, try to get it from database
1688  $intervalQuery = "WHERE {stats}.date_created > DATE_SUB(CURDATE(), INTERVAL 1 DAY)";
1689  if ($res = $db->query("SELECT deviceType FROM {stats} $intervalQuery ORDER BY id DESC"))
1690  { // create array
1691  $data = array();
1692  while ($row = mysqli_fetch_assoc($res))
1693  { // add data to array
1694  $data[] = $row;
1695  }
1696  }
1697  else
1698  { // data array not set and unable to get data from db
1699  return false;
1700  }
1701  }
1702 
1703  /*
1704  // LIMIT the data to x entries
1705  if (isset($limit) && (!empty($limit)))
1706  { // if limit is set, cut array to limited range
1707  $data = array_slice($data, 0, $limit, true);
1708  }
1709  */
1710  foreach ($data as $deviceType => $value)
1711  {
1712  // count device types
1713  switch ($value['deviceType'])
1714  {
1715  case "Desktop":
1716  $this->i_desktop++;
1717  break;
1718  case "Tablet":
1719  $this->i_tablet++;
1720  break;
1721  case "Phone":
1722  $this->i_phone++;
1723  break;
1724  }
1725  }
1726 
1727  // count device types
1728  $total = $this->i_desktop+$this->i_tablet+$this->i_phone;
1729  // calculate percentage of device types
1730  if ($total > 0)
1731  {
1732  $a = 100 / $total;
1733  $this->i_desktopPercent = $a * $this->i_desktop;
1734  $this->i_tabletPercent = $a * $this->i_tablet;
1735  $this->i_phonePercent = $a * $this->i_phone;
1736  // build an array, cointaining the device types and the number how often it's been found
1737  $deviceTypes = array(
1738  "Desktop" => $this->i_desktop,
1739  "Tablet" => $this->i_tablet,
1740  "Phone" => $this->i_phone,
1741  "Total" => $total
1742  );
1743  // return device type array
1744  return $deviceTypes;
1745  }
1746  else
1747  { // no result,
1748  return null;
1749  }
$deviceType
Definition: stats.php:34

References $data, $db, YAWK\stats\$deviceType, YAWK\stats\$i_desktop, YAWK\stats\$i_phone, YAWK\stats\$i_tablet, $res, $total, and $value.

Referenced by YAWK\stats\getJsonDeviceTypes().

◆ countLogins()

YAWK\stats::countLogins (   $db)

Count system logins.

Parameters
object$dbDatabase Object
int$limitContains an i number to limit the sql request
Returns
array|bool

Definition at line 575 of file stats.php.

577  { /* @param $db \YAWK\db */
578  /*
579  if (!isset($limit) || (empty($limit)))
580  {
581  $limit = 100;
582  }
583  */
584  if ($res = $db->query("SELECT * FROM {logins}"))
585  { // fetch and return how many messages have been sent
586  $loginDataArray = array();
587  // count login data
588  while ($row = mysqli_fetch_assoc($res))
589  {
590  // GET AN ARRAY CONTAINING ALL DATA FROM LOGIN DB
591  // $loginDataArray[] = $row;
592 
593  // count +1 to all logins
594  $this->i_totalLogins++;
595 
596  // count frontend logins
597  if ($row['location'] === "frontend")
598  {
599  // add total frontendlogins +1
600  $this->i_loginFrontend++;
601  if ($row['failed'] === "1")
602  { // frontend login failed +1
603  $this->i_loginFrontendFailed++;
604  }
605  else
606  { // frontend login success +1
607  $this->i_loginFrontendSuccess++;
608  }
609  }
610  // count backend logins
611  if ($row['location'] === "backend")
612  { // add total backend login +1
613  $this->i_loginBackend++;
614  if ($row['failed'] === "1")
615  { // backend login failed +1
616  $this->i_loginBackendFailed++;
617  }
618  else
619  { // backend login success +1
620  $this->i_loginBackendSuccess++;
621  }
622  }
623  // total success logins +1
624  if ($row['failed'] === "0")
625  { // success +1
626  $this->i_loginSuccessful++;
627  }
628  // total failed logins +1
629  if ($row['failed'] === "1")
630  { // failed +1
631  $this->i_loginFailed++;
632  }
633  }
634  if ($this->i_totalLogins > 0)
635  {
636  // calculate percentage
638  $failed = $this->i_loginFailed;
639  $success = $this->i_loginSuccessful;
640  $total = 100 / $total;
641  $this->i_loginFailedPercentage = round($total * $failed);
642  $this->i_loginSuccessPercentage = round($total * $success);
643  }
644 
645 
646  // build an array, cointaining the failed and successful logins
647  $loginDataArray = array(
648  "Failed" => $this->i_loginFailed,
649  "Successful" => $this->i_loginSuccessful,
650  "BackendSuccess" => $this->i_loginBackendSuccess,
651  "BackendFailed" => $this->i_loginBackendFailed,
652  "FrontendSuccess" => $this->i_loginFrontendSuccess,
653  "FrontendFailed" => $this->i_loginFrontendFailed,
654  "FailedPercentage" => $this->i_loginFailedPercentage,
655  "SuccessPercentage" => $this->i_loginSuccessPercentage,
656  "Total" => $this->i_totalLogins
657  );
658  return $loginDataArray;
659  }
660  else
661  {
662  \YAWK\alert::draw("warning", "Could not get login data array.", "error getting data into array", "", 5200);
663  return false;
664  }
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30
$i_totalLogins
Definition: stats.php:150
$i_loginFailed
Definition: stats.php:154
$i_loginSuccessful
Definition: stats.php:152

References $db, YAWK\stats\$i_loginFailed, YAWK\stats\$i_loginSuccessful, YAWK\stats\$i_totalLogins, $res, $total, and YAWK\alert\draw().

Referenced by YAWK\stats\getJsonLogins().

◆ countMessages()

YAWK\stats::countMessages (   $db)

Count all messages that are stored in the database.

Parameters
object$dbDatabase Object
Returns
mixed

Definition at line 519 of file stats.php.

521  { /* @param $db \YAWK\db */
522  if ($res = $db->query("SELECT COUNT(*) FROM {plugin_msg}"))
523  { // fetch and return how many messages have been sent
524  $messageCount = mysqli_fetch_row($res);
525  return $messageCount[0];
526  }
527  else
528  {
529  $messageCount = "db error: could not count messages";
530  return $messageCount;
531  }

References $db, and $res.

◆ countOS()

YAWK\stats::countOS (   $db,
  $data 
)

Count operating systems.

Parameters
object$dbthe database object
string$dataarray containing all the stats data
string$limitcontains i number for sql limitation
Returns
array|bool returning array containing all detected operating systems and their hits

Definition at line 1759 of file stats.php.

1761  { /* @param $db \YAWK\db */
1762 
1763  /*
1764  // check if limit (i) is set
1765  if (!isset($limit) || (empty($limit)))
1766  { // set default value
1767  $limit = 100;
1768  }
1769  */
1770  // check if data array is set, if not load data from db
1771  if (!isset($data) || (empty($data) || (!is_array($data))))
1772  { // data is not set or in false format, try to get it from database
1773  // \YAWK\alert::draw("warning", "database needed", "need to get browser data - array not set, empty or not an array.", "", 0);
1774  if ($res = $db->query("SELECT os FROM {stats} ORDER BY id DESC"))
1775  { // create array
1776  $data = array();
1777  while ($row = mysqli_fetch_assoc($res))
1778  { // add data to array
1779  $data[] = $row;
1780  }
1781  }
1782  else
1783  { // data array not set and unable to get data from db
1784  return false;
1785  }
1786  }
1787 
1788  /*
1789  // LIMIT the data to x entries
1790  if (isset($limit) && (!empty($limit)))
1791  { // if limit is set, cut array to limited range
1792  $data = array_slice($data, 0, $limit, true);
1793  }
1794  */
1795  foreach ($data as $os => $value)
1796  {
1797  // count Operating Systems
1798  switch ($value['os'])
1799  {
1800  case "Windows";
1801  $this->i_osWindows++;
1802  break;
1803  case "Linux";
1804  $this->i_osLinux++;
1805  break;
1806  case "Mac";
1807  $this->i_osMac++;
1808  break;
1809  case "Android";
1810  $this->i_osAndroid++;
1811  break;
1812  case "iOS";
1813  $this->i_iOS++;
1814  break;
1815  default: $this->i_osUnknown++;
1816  }
1817  }
1818 
1819  // count Operating Systems
1820  $total = $this->i_osWindows+$this->i_osLinux+$this->i_osMac+$this->i_osAndroid+$this->i_iOS+$this->i_osUnknown;
1821  // build an array, cointaining the browsers and the number how often it's been found
1822  $os = array(
1823  "Windows" => $this->i_osWindows,
1824  "Linux" => $this->i_osLinux,
1825  "Mac" => $this->i_osMac,
1826  "Android" => $this->i_osAndroid,
1827  "iOS" => $this->i_iOS,
1828  "Unknown" => $this->i_osUnknown,
1829  "Total" => $total
1830  );
1831 
1832  // return OS data array
1833  return $os;
$i_osUnknown
Definition: stats.php:84

References $data, $db, YAWK\stats\$i_osUnknown, YAWK\stats\$os, $res, $total, and $value.

Referenced by YAWK\stats\getJsonOS().

◆ countOSVersions()

YAWK\stats::countOSVersions (   $db,
  $data 
)

Count operating systems versions.

Parameters
object$dbthe database object
string$dataarray containing all the stats data
Returns
array|bool returning array containing all detected OS versions and their hits

Definition at line 1842 of file stats.php.

1844  { /* @param $db \YAWK\db */
1845 
1846  /*
1847  // check if limit (i) is set
1848  if (!isset($limit) || (empty($limit)))
1849  { // set default value
1850  $limit = 100;
1851  }
1852  */
1853  // check if data array is set, if not load data from db
1854  if (!isset($data) || (empty($data) || (!is_array($data))))
1855  { // data is not set or in false format, try to get it from database
1856  // \YAWK\alert::draw("warning", "database needed", "need to get browser data - array not set, empty or not an array.", "", 0);
1857  if ($res = $db->query("SELECT osVersion FROM {stats} ORDER BY id DESC"))
1858  { // create array
1859  $data = array();
1860  while ($row = mysqli_fetch_assoc($res))
1861  { // add data to array
1862  $data[] = $row;
1863  }
1864  return $data;
1865  }
1866  else
1867  { // data array not set and unable to get data from db
1868  return false;
1869  }
1870  }
1871 
1872  /*
1873  // LIMIT the data to x entries
1874  if (isset($limit) && (!empty($limit)))
1875  { // if limit is set, cut array to limited range
1876  $data = array_slice($data, 0, $limit, true);
1877  }
1878  */
1879 
1880  // count browsers
1881  foreach ($data AS $item => $osVersion) { // add +1 for each found
1882  // count Operating Systems Versions
1883  if ($osVersion['os'] === "Android")
1884  {
1885  $osVersion['osVersion'] .= "Android ".$osVersion['osVersion'];
1886  }
1887  switch ($osVersion['osVersion'])
1888  {
1889  case "Windows 11";
1890  $this->i_windows11++;
1891  break;
1892  case "Windows 10";
1893  $this->i_windows10++;
1894  break;
1895  case "Windows 8";
1896  $this->i_windows8++;
1897  break;
1898  case "Windows 7";
1899  $this->i_windows7++;
1900  break;
1901  case "Windows Vista";
1902  $this->i_windowsVista++;
1903  break;
1904  case "Windows Server 2003/XP x64";
1905  $this->i_windowsServer++;
1906  break;
1907  case "Windows XP";
1908  $this->i_windowsXP++;
1909  break;
1910  case "Windows 2000";
1911  $this->i_windows2000++;
1912  break;
1913  case "Windows ME";
1914  $this->i_windowsME++;
1915  break;
1916  case "Windows 98";
1917  $this->i_windows98++;
1918  break;
1919  case "Windows 95";
1920  $this->i_windows95++;
1921  break;
1922  case "Windows 3.11";
1923  $this->i_windows311++;
1924  break;
1925  case "Max OS X";
1926  $this->i_macosX++;
1927  break;
1928  case "Max OS 9";
1929  $this->i_macos9++;
1930  break;
1931  case "Linux";
1932  $this->i_linux++;
1933  break;
1934  case "Ubuntu";
1935  $this->i_ubuntu++;
1936  break;
1937  case "iPhone";
1938  $this->i_iPhone++;
1939  break;
1940  case "iPad";
1941  $this->i_iPad++;
1942  break;
1943  case "iPod";
1944  $this->i_iPod++;
1945  break;
1946  case "Android":
1947  $this->i_android++;
1948  break;
1949  case "BlackBerry";
1950  $this->i_blackberry++;
1951  break;
1952  case "Mobile";
1953  $this->i_mobile++;
1954  break;
1955 
1956  // could not detect OS Version
1957  default:
1958  $this->i_others++;
1959  }
1960  }
1961 
1962  // count OS Versions
1963  $total = $this->i_windows11
1964  +$this->i_windows10
1965  +$this->i_windows8
1966  +$this->i_windows7
1967  +$this->i_windowsVista
1968  +$this->i_windowsServer
1969  +$this->i_windows2000
1970  +$this->i_windowsXP
1971  +$this->i_windowsME
1972  +$this->i_windows98
1973  +$this->i_windows95
1974  +$this->i_windows311
1975  +$this->i_macosX
1976  +$this->i_macos9
1977  +$this->i_linux
1978  +$this->i_ubuntu
1979  +$this->i_iPhone
1980  +$this->i_iPad
1981  +$this->i_iPod
1982  +$this->i_android
1983  +$this->i_blackberry
1984  +$this->i_mobile
1985  +$this->i_others;
1986  // build an array, cointaining the counted OS Versions and the sum overall
1987  $osVersions = array(
1988  "Windows 11" => $this->i_windows11,
1989  "Windows 10" => $this->i_windows10,
1990  "Windows 8" => $this->i_windows8,
1991  "Windows 7" => $this->i_windows7,
1992  "Windows Vista" => $this->i_windowsVista,
1993  "Windows Server" => $this->i_windowsServer,
1994  "Windows 2000" => $this->i_windows2000,
1995  "Windows XP" => $this->i_windowsXP,
1996  "Windows ME" => $this->i_windowsME,
1997  "Windows 98" => $this->i_windows98,
1998  "Windows 95" => $this->i_windows95,
1999  "Windows 3.11" => $this->i_windows311,
2000  "Mac OS X" => $this->i_macosX,
2001  "Mac OS 9" => $this->i_macos9,
2002  "Linux" => $this->i_linux,
2003  "Ubuntu" => $this->i_ubuntu,
2004  "iPhone" => $this->i_iPhone,
2005  "iPad" => $this->i_iPad,
2006  "iPod" => $this->i_iPod,
2007  "Android" => $this->i_android,
2008  "Blackberry" => $this->i_blackberry,
2009  "Mobile" => $this->i_mobile,
2010  "Unknown" => $this->i_others,
2011  "Total" => $total
2012  );
2013 
2014  // return OS data array
2015  return $osVersions;
$osVersion
Definition: stats.php:38

References $data, $db, YAWK\stats\$i_others, $item, YAWK\stats\$osVersion, $res, and $total.

Referenced by YAWK\stats\getJsonOSVersions().

◆ countWeekdays()

YAWK\stats::countWeekdays (   $db,
  $data,
  $lang,
  $limit 
)

Count and set the number of hits for each weekday.

Parameters
object$dbthe database object
string$dataarray containing all the stats data
string$limitcontains i number for sql limitation
object$langlanguage array
Returns
array|bool containing weekdays and number of hits

Definition at line 1279 of file stats.php.

1281  { /* @param $db \YAWK\db */
1282 
1283  // check if limit (i) is set
1284  if (!isset($limit) || (empty($limit)))
1285  { // set default value
1286  $limitSql = '';
1287  }
1288  else
1289  {
1290  $limitSql = ' LIMIT '.$limit;
1291  }
1292  // check if data array is set, if not load data from db
1293  if (!isset($data) || (empty($data) || (!is_array($data))))
1294  { // data is not set or in false format, try to get it from database
1295  if ($res = $db->query("SELECT date_created FROM {stats} ORDER BY id DESC$limitSql"))
1296  { // create array
1297  $data = array();
1298  while ($row = mysqli_fetch_assoc($res))
1299  { // add data to array
1300  $data[] = $row;
1301  }
1302  }
1303  else
1304  { // data array not set and unable to get data from db
1305  return false;
1306  }
1307  }
1308 
1309  /*
1310  // LIMIT the data to x entries
1311  if (isset($limit) && (!empty($limit)))
1312  { // if limit is set, cut array to limited range
1313  $data = array_slice($data, 0, $limit, true);
1314  }
1315  */
1316 
1317  // break up the date & extract the hour to calculate
1318  foreach ($data as $date => $value)
1319  {
1320  $weekday = \YAWK\sys::getWeekday($value['date_created'], $lang);
1321 
1322  // identify days
1323  if ($weekday === "Monday" ||
1324  ($weekday === "$lang[MONDAY]"))
1325  {
1326  $this->i_monday++;
1327  }
1328  elseif ($weekday === "Tuesday" ||
1329  ($weekday === "$lang[TUESDAY]"))
1330  {
1331  $this->i_tuesday++;
1332  }
1333  elseif ($weekday === "Wednesday" ||
1334  ($weekday === "$lang[WEDNESDAY]"))
1335  {
1336  $this->i_wednesday++;
1337  }
1338  elseif ($weekday === "Thursday" ||
1339  ($weekday === "$lang[THURSDAY]"))
1340  {
1341  $this->i_thursday++;
1342  }
1343  elseif ($weekday === "Friday" ||
1344  ($weekday === "$lang[FRIDAY]"))
1345  {
1346  $this->i_friday++;
1347  }
1348  elseif ($weekday === "Saturday" ||
1349  ($weekday === "$lang[SATURDAY]"))
1350  {
1351  $this->i_saturday++;
1352  }
1353  elseif ($weekday === "Sunday" ||
1354  ($weekday === "$lang[SUNDAY]"))
1355  {
1356  $this->i_sunday++;
1357  }
1358  }
1359 
1360  // count daytimes
1361  $this->i_totalDays = $this->i_monday
1362  +$this->i_tuesday
1363  +$this->i_wednesday
1364  +$this->i_thursday
1365  +$this->i_friday
1366  +$this->i_saturday
1367  +$this->i_sunday;
1368 
1369  // build an array, cointaining the daytimes
1370  $weekdays = array(
1371  "$lang[MONDAY]" => $this->i_monday,
1372  "$lang[TUESDAY]" => $this->i_tuesday,
1373  "$lang[WEDNESDAY]" => $this->i_wednesday,
1374  "$lang[THURSDAY]" => $this->i_thursday,
1375  "$lang[FRIDAY]" => $this->i_friday,
1376  "$lang[SATURDAY]" => $this->i_saturday,
1377  "$lang[SUNDAY]" => $this->i_sunday,
1378  "$lang[TOTAL]" => $this->i_totalDays
1379  );
1380 
1381  // return OS data array
1382  return $weekdays;
print $lang['FILEMAN_UPLOAD']
static getWeekday($date, $lang)
return weekday from given date
Definition: sys.php:1735

References $data, $date, $db, YAWK\stats\$i_sunday, $lang, $res, $value, and YAWK\sys\getWeekday().

◆ deleteOutdatedSessions()

YAWK\stats::deleteOutdatedSessions (   $db)

Check and delete outdated sessions if they are expired.

Parameters
object$dbDatabase Object
int$expireAfterTime in seconds after a session will be deleted
Returns
bool

Definition at line 262 of file stats.php.

264  { /* @param $db \YAWK\db */
265  // set default expire to 60 seconds
266  $sessionExpire = time()-60;
267  // DELETE OUTDATED SESSIONS
268  if ($db->query("DELETE FROM {users_online} WHERE currentTimeStamp < $sessionExpire"))
269  {
270  return true;
271  }
272  else
273  {
274  // could not delete outdated sessions
275  // todo: add syslog entry
276  return false;
277  }

References $db.

Referenced by YAWK\stats\getOnlineUsers().

◆ drawOverviewBox()

YAWK\stats::drawOverviewBox (   $lang)

Draw default box containing overview statistics.

Parameters
array$langlanguage array

Definition at line 3248 of file stats.php.

3250  {
3251  echo "
3252 <div class=\"row\">
3253  <div class=\"col-md-12\">
3254  <!-- box -->
3255  <div class=\"box\">
3256  <div class=\"box-header with-border\">
3257  <h3 class=\"box-title\">$lang[STATS] <small>$lang[HITS_AND_USER_BEHAVIOR] </small></h3>
3258  </div>
3259  <div class=\"box-body\">";
3260  $this->i_hits = number_format($this->i_hits, 0, '.', '.');
3261 
3262  echo "$lang[ACTIVE_SESSIONS]: <b>$this->currentOnline</b><br>
3263  $lang[HITS] $lang[OVERALL]:<b> $this->i_hits</b><br>
3264  $lang[GUESTS]: <b> $this->i_publicUsersPercentage</b> % <small>($this->i_publicUsers)</small><br>
3265  $lang[MEMBERS]: <b> $this->i_loggedUsersPercentage</b> % <small>($this->i_loggedUsers)</small><br>
3266  </div>
3267  </div>
3268  <!-- / box -->
3269  </div>
3270 </div>";

◆ drawPagesBox()

YAWK\stats::drawPagesBox (   $data,
  $lang 
)

Draw default box containing pages statistics.

Parameters
array$datastats data array
array$langlanguage array

Definition at line 3277 of file stats.php.

3279  {
3280  echo "
3281  <!-- box -->
3282  <div class=\"box\">
3283  <div class=\"box-header with-border\">
3284  <h3 class=\"box-title\">$lang[PAGE_VIEWS] <small> $lang[HITS_FROM_MOST_TO_LEAST]</small></h3>
3285  </div>";
3286  $res = array();
3287  if (is_array($data))
3288  {
3289  // $data = array_slice($data, 0, $limit, true);
3290  foreach ($data AS $page => $value)
3291  {
3292  $res[] = $value['page'];
3293  }
3294  }
3295 
3296  $res = (array_count_values($res));
3297  arsort($res);
3298  echo "<div class=\"box-footer no-padding\">
3299  <ul class=\"nav nav-pills nav-stacked\">";
3300 
3301  // walk through array and display pages as nav pills
3302  foreach ($res as $page => $value)
3303  { // show only items where browser got a value
3304  if ($value !== 0 && $page !== 0)
3305  { // get different textcolors
3306  echo "<li><a href=\"../$page\" target=\"_blank\"><b>$value</b> &nbsp;<span class=\"text-blue\">$page</span></a></li>";
3307  }
3308  }
3309 
3310  echo "</ul>
3311  </div>";

References $data, YAWK\stats\$page, $res, and $value.

◆ drawUserStats()

YAWK\stats::drawUserStats (   $db,
  $lang 
)

Draw a default box containing user statistics.

Parameters
object$dbDatabase Object
object$langlanguage object

Definition at line 2196 of file stats.php.

2198  {
2199  if (self::getUserStats($db))
2200  {
2201  echo "<!-- user settings box -->
2202  <div class=\"box\">
2203  <div class=\"box-header with-border\">
2204  <h3 class=\"box-title\">$lang[USER] $lang[STATS] <small>$lang[TOTAL_LOGGED_BLOCKED]</small></h3>
2205  </div>
2206  <div class=\"box-body\">
2207  $lang[USERS]: <b>$this->i_users</b><br>
2208  $lang[BLOCKED]: <b>$this->i_blockedUsers</b><br>
2209  $lang[LOGGED_IN]: <b>$this->i_loggedInUsers</b>
2210  </div>
2211  </div>
2212  <!-- / stats settings box -->";
2213 
2214  }

References $db.

◆ getBrowserColors()

YAWK\stats::getBrowserColors (   $browser)

Set and return the legend textcolor for each browser.

Parameters
object$dbDatabase Object
string$browsercontains the browser as string
Returns
string returns the textcolor for this browser as string

Definition at line 1032 of file stats.php.

1034  {
1035  switch ($browser) {
1036  case "Chrome":
1037  $textcolor = "text-red";
1038  break;
1039  case "Google Chrome":
1040  $textcolor = "text-red";
1041  break;
1042  case "IE":
1043  $textcolor = "text-green";
1044  break;
1045  case "Internet Explorer":
1046  $textcolor = "text-green";
1047  break;
1048  case "Firefox":
1049  $textcolor = "text-yellow";
1050  break;
1051  case "Mozilla Firefox":
1052  $textcolor = "text-yellow";
1053  break;
1054  case "Safari":
1055  $textcolor = "text-aqua";
1056  break;
1057  case "Apple Safari":
1058  $textcolor = "text-aqua";
1059  break;
1060  case "Opera":
1061  $textcolor = "text-light-blue";
1062  break;
1063  case "Netscape":
1064  $textcolor = "text-grey";
1065  break;
1066  case "Navigator":
1067  $textcolor = "text-grey";
1068  break;
1069  default:
1070  $textcolor = "text-black";
1071  }
1072  return $textcolor;

References YAWK\stats\$browser.

◆ getDaysOfMonthBox()

YAWK\stats::getDaysOfMonthBox (   $lang)

Draw default box containing days of month statistics.

Parameters
array$langlanguage array

Definition at line 3317 of file stats.php.

3319  {
3320  echo "<div class=\"box\">";
3321  echo "<div class=\"box-header\"><h3 class=\"box-title\">$lang[DAYS_OF_MONTH]</h3></div>";
3322  echo "<div class=\"box-body\">";
3323 
3324  $daysOfMonth = date("t",mktime(0, 0, 0, 9, 1, 2017));
3325  $daysOfMonth++; // Zähler bei 1
3326  for($i = 1; $i < $daysOfMonth; $i++){
3327  echo $i."\n";
3328  }
3329  echo "</div>";
3330  echo "</div>"; // end box
print $tourdates date
$i

References $i, and date.

◆ getDaytimeColors()

YAWK\stats::getDaytimeColors (   $daytime,
  $lang 
)

Set and return the legend textcolor for each daytime.

Parameters
string$daytimecontains the daytime (morning, afternoon, evening, night) as string
Returns
string returns the textcolor for this daytime as string

Definition at line 1133 of file stats.php.

1135  {
1136  switch ($daytime) {
1137  case "$lang[MORNING]":
1138  $textcolor = "text-orange";
1139  break;
1140  case "$lang[AFTERNOON]":
1141  $textcolor = "text-green";
1142  break;
1143  case "$lang[EVENING]":
1144  $textcolor = "text-blue";
1145  break;
1146  case "$lang[NIGHT]":
1147  $textcolor = "text-navy";
1148  break;
1149  default:
1150  $textcolor = "text-black";
1151  }
1152  return $textcolor;

◆ getDayTimesPercent()

YAWK\stats::getDayTimesPercent (   $lang)

Calculate hits per daytime and return data in percent.

Parameters
object$dbthe database object
Returns
array containing daytimes and number of hits in percent

Definition at line 1534 of file stats.php.

1536  {
1537  // count daytimes
1538  $total = $this->i_morning+$this->i_afternoon+$this->i_evening+$this->i_night;
1539 
1540  if ($total > 0)
1541  {
1542  // calculate percentage
1543  $a = 100 / $total;
1544  $this->i_morningPercent = round($a * $this->i_morning);
1545  $this->i_afternoonPercent = round($a * $this->i_afternoon);
1546  $this->i_eveningPercent = round($a * $this->i_evening);
1547  $this->i_nightPercent = round($a * $this->i_night);
1548 
1549 
1550  // build an array, cointaining the device types and the number how often it's been found
1551  $dayTimesPercent = array(
1552  "$lang[MORNING]" => $this->i_morningPercent,
1553  "$lang[AFTERNOON]" => $this->i_afternoonPercent,
1554  "$lang[EVENING]" => $this->i_eveningPercent,
1555  "$lang[NIGHT]" => $this->i_nightPercent
1556  );
1557  arsort($dayTimesPercent);
1558  return $dayTimesPercent;
1559  }
1560  else
1561  {
1562  return null;
1563  }

References YAWK\stats\$i_night, and $total.

◆ getDeviceTypeColors()

YAWK\stats::getDeviceTypeColors (   $deviceType)

Set and return the legend textcolor for each device type.

Parameters
string$deviceTypecontains the type (desktop, phone, tablet) as string
Returns
string returns the textcolor for this device type as string

Definition at line 1110 of file stats.php.

1112  {
1113  switch ($deviceType) {
1114  case "Desktop":
1115  $textcolor = "text-orange";
1116  break;
1117  case "Phone":
1118  $textcolor = "text-green";
1119  break;
1120  case "Tablet":
1121  $textcolor = "text-blue";
1122  break;
1123  default:
1124  $textcolor = "text-black";
1125  }
1126  return $textcolor;

References YAWK\stats\$deviceType.

◆ getJsonBrowsers()

YAWK\stats::getJsonBrowsers (   $db,
  $browsers 
)

Output JS: PIE CHART browser data.

Parameters
object$dbDatabase Object
array$browsersdata array
Returns
string output the javascript data

Definition at line 848 of file stats.php.

850  { /* @param $db \YAWK\db */
851  // check if browsers are set
852  if (!isset($browsers) || (empty($browsers)))
853  { // nope, get them from db
854  $browsers = $this->countBrowsers($db, '');
855  }
856  $jsonData = "[";
857  foreach ($browsers AS $browser => $value)
858  {
859  // init textcolor
860  $textcolor = '';
861  // set different colors for each browser
862  if ($browser === "Chrome") { $textcolor = "#f56954"; }
863  if ($browser === "IE") { $textcolor = "#00a65a"; }
864  if ($browser === "Edge") { $textcolor = "#00a65a"; }
865  if ($browser === "Kindle") { $textcolor = "#239330"; }
866  if ($browser === "Firefox") { $textcolor = "#f39c12"; }
867  if ($browser === "Safari") { $textcolor = "#00c0ef"; }
868  if ($browser === "Opera") { $textcolor = "#3c8dbc"; }
869  if ($browser === "Netscape") { $textcolor = "#d2d6de"; }
870  if ($browser === "Others") { $textcolor = "#cccccc"; }
871 
872  // only browsers, not the total value
873  if ($browser !== ("Total"))
874  {
875  $jsonData .= "
876  {
877  value: $value,
878  color: \"$textcolor\",
879  highlight: \"$textcolor\",
880  label: \"$browser\"
881  },";
882  }
883  }
884 
885  $jsonData .= "]";
886  return $jsonData;
countBrowsers($db, $data)
Count and return browsers.
Definition: stats.php:1573

References YAWK\stats\$browser, $db, $value, and YAWK\stats\countBrowsers().

◆ getJsonDaytimeBarChart()

YAWK\stats::getJsonDaytimeBarChart (   $db,
  $daytimes,
  $lang 
)

Output JS: BAR CHART daytime data.

Parameters
object$dbDatabase Object
array$daytimesdata array
Returns
string output the javascript data

Definition at line 794 of file stats.php.

796  { /* @param $db \YAWK\db */
797  // check if device types are set
798  if (!isset($daytimes) || (empty($daytimes)))
799  { // nope, get them from db
800  $daytimes = $this->countDaytime($db, '', $lang);
801  }
802 
803  $jsonData = "labels: ['$lang[MORNING]', '$lang[AFTERNOON]', '$lang[EVENING]', '$lang[NIGHT]'],
804  datasets: [
805  {
806  label: '$lang[HITS]',
807  fillColor: ['#f39c12', '#00a65a', '#00c0ef', '#003D4C'],
808  strokeColor: 'rgba(210, 214, 222, 1)',
809  pointColor: 'rgba(210, 214, 222, 1)',
810  pointStrokeColor: '#c1c7d1',
811  pointHighlightFill: '#fff',
812  pointHighlightStroke: 'rgba(220,220,220,1)',
813  data: [$this->i_morning, $this->i_afternoon, $this->i_evening, $this->i_night]
814  }
815  ]";
816  return $jsonData;
countDaytime($db, $data, $lang)
Count and set the number of hits for each daytime.
Definition: stats.php:1430

References $db, $lang, and YAWK\stats\countDaytime().

◆ getJsonDaytimeLineChart()

YAWK\stats::getJsonDaytimeLineChart (   $db,
  $daytimes,
  $lang 
)

Output JS: LINE CHART daytime data.

Parameters
object$dbDatabase Object
array$daytimesdata array
array$langlanguage array
Returns
string output the javascript data

Definition at line 763 of file stats.php.

765  { /* @param $db \YAWK\db */
766  // check if device types are set
767  if (!isset($daytimes) || (empty($daytimes)))
768  { // nope, get them from db
769  $daytimes = $this->countDaytime($db, '', $lang);
770  }
771 
772  $jsonData = "labels: ['$lang[MORNING]', '$lang[AFTERNOON]', '$lang[EVENING]', '$lang[NIGHT]'],
773  datasets: [
774  {
775  label: '$lang[HITS]',
776  fillColor: ['#f39c12', '#00a65a', '#00c0ef', '#003D4C'],
777  strokeColor: 'rgba(210, 214, 222, 1)',
778  pointColor: 'rgba(210, 214, 222, 1)',
779  pointStrokeColor: '#c1c7d1',
780  pointHighlightFill: '#fff',
781  pointHighlightStroke: 'rgba(220,220,220,1)',
782  data: [$this->i_morning, $this->i_afternoon, $this->i_evening, $this->i_night]
783  }
784  ]";
785  return $jsonData;

References $db, $lang, and YAWK\stats\countDaytime().

◆ getJsonDaytimePieChart()

YAWK\stats::getJsonDaytimePieChart (   $db,
  $daytimes,
  $lang 
)

Output JS: PIE CHART daytime data.

Parameters
object$dbDatabase Object
array$daytimedata array
arraylanguage array
Returns
string return the javascript data

Definition at line 716 of file stats.php.

718  { /* @param $db \YAWK\db */
719  // check if logins are set
720  if (!isset($daytimes) || (empty($daytimes)))
721  { // nope, get them from db
722  $daytimes = $this->countDaytime($db, '', $lang);
723  }
724  $jsonData = "[";
725  foreach ($daytimes AS $daytime => $value)
726  {
727  // init textcolor
728  $textcolor = '';
729  // set different colors for each status
730  if ($daytime === "$lang[MORNING]") { $textcolor = "#f39c12"; }
731  if ($daytime === "$lang[AFTERNOON]") { $textcolor = "#00a65a"; }
732  if ($daytime === "$lang[EVENING]") { $textcolor = "#00c0ef"; }
733  if ($daytime === "$lang[NIGHT]") { $textcolor = "#003D4C"; }
734 
735  // only failed + successful logins, exclude all other values
736  if ($daytime !== ("$lang[TOTAL]") &&
737  ($daytime === ("$lang[MORNING]") ||
738  ($daytime === ("$lang[AFTERNOON]") ||
739  ($daytime === ("$lang[EVENING]") ||
740  ($daytime === ("$lang[NIGHT]"))))))
741  {
742  $jsonData .= "
743  {
744  value: $value,
745  color: \"$textcolor\",
746  highlight: \"$textcolor\",
747  label: \"$daytime\"
748  },";
749  }
750  }
751 
752  $jsonData .= "]";
753  return $jsonData;

References $db, $lang, $value, and YAWK\stats\countDaytime().

◆ getJsonDeviceTypes()

YAWK\stats::getJsonDeviceTypes (   $db,
  $deviceTypes,
  $lang 
)

Output JS: BAR CHART device types.

Parameters
object$dbDatabase Object
object$langlanguage
array$deviceTypesdata array
Returns
string output the javascript

Definition at line 1001 of file stats.php.

1003  { /* @param $db \YAWK\db */
1004  // check if device types are set
1005  if (!isset($deviceTypes) || (empty($deviceTypes)))
1006  { // device types are note set - get them from db
1007  $deviceTypes = $this->countDeviceTypes($db, '');
1008  }
1009 
1010  $jsonData = "labels: ['$lang[DESKTOP]', '$lang[PHONE]', '$lang[TABLET]'],
1011  datasets: [
1012  {
1013  label: 'Hits',
1014  fillColor: ['#f39c12', '#00a65a', '#00c0ef'],
1015  strokeColor: 'rgba(210, 214, 222, 1)',
1016  pointColor: 'rgba(210, 214, 222, 1)',
1017  pointStrokeColor: '#c1c7d1',
1018  pointHighlightFill: '#fff',
1019  pointHighlightStroke: 'rgba(220,220,220,1)',
1020  data: [$this->i_desktop, $this->i_phone, $this->i_tablet]
1021  }
1022  ]";
1023  return $jsonData;
countDeviceTypes($db, $data)
Count device types (desktop, phone or tablet)
Definition: stats.php:1673

References $db, and YAWK\stats\countDeviceTypes().

◆ getJsonLogins()

YAWK\stats::getJsonLogins (   $db,
  $logins,
  $lang 
)

Output JS: PIE CHART login data.

Parameters
object$dbDatabase Object
object$langlanguage
array$loginsdata array
Returns
string output the javascript data

Definition at line 674 of file stats.php.

676  { /* @param $db \YAWK\db */
677  // check if logins are set
678  if (!isset($logins) || (empty($logins)))
679  { // nope, get them from db
680  $logins = $this->countLogins($db);
681  }
682  $jsonData = "[";
683  foreach ($logins AS $login => $value)
684  {
685  // init textcolor
686  $textcolor = '';
687  // set different colors for each status
688  if ($login === "Failed") { $textcolor = "#f56954"; }
689  if ($login === "Successful") { $textcolor = "#00a65a"; }
690 
691  // only failed + successful logins, exclude all other values
692  if ($login !== ("Total") && ($login === ("Failed") || ($login === ("Successful"))))
693  {
694  $jsonData .= "
695  {
696  value: $value,
697  color: \"$textcolor\",
698  highlight: \"$textcolor\",
699  label: \"$login\"
700  },";
701  }
702  }
703 
704  $jsonData .= "]";
705  return $jsonData;
countLogins($db)
Count system logins.
Definition: stats.php:575

References $db, $value, and YAWK\stats\countLogins().

◆ getJsonOS()

YAWK\stats::getJsonOS (   $db,
  $oss 
)

Output JS: PIE CHART OS data.

Parameters
object$dbDatabase Object
array$ossdata array
Returns
string output the javascript data

Definition at line 895 of file stats.php.

897  { /* @param $db \YAWK\db */
898  // check if browsers are set
899  if (!isset($oss) || (empty($oss)))
900  { // nope, get them from db
901  $oss = $this->countOS($db, '');
902  }
903  $jsonData = "[";
904  foreach ($oss AS $os => $value)
905  {
906  // init textcolor
907  $textcolor = '';
908  // set different colors for each browser
909  if ($os === "Windows") { $textcolor = "#00c0ef"; }
910  if ($os === "Linux") { $textcolor = "#f56954"; }
911  if ($os === "Mac") { $textcolor = "#f39c12"; }
912  if ($os === "Android") { $textcolor = "#00a65a"; }
913  if ($os === "iOS") { $textcolor = "#000000"; }
914  if ($os === "Unknown") { $textcolor = "#cccccc"; }
915 
916  // only browsers, not the total value
917  if ($os !== ("Total"))
918  {
919  $jsonData .= "
920  {
921  value: $value,
922  color: \"$textcolor\",
923  highlight: \"$textcolor\",
924  label: \"$os\"
925  },";
926  }
927  }
928 
929  $jsonData .= "]";
930  return $jsonData;
countOS($db, $data)
Count operating systems.
Definition: stats.php:1759

References $db, YAWK\stats\$os, $value, and YAWK\stats\countOS().

◆ getJsonOSVersions()

YAWK\stats::getJsonOSVersions (   $db,
  $osVersions 
)

Output JS: BAR CHART OS versions.

Parameters
object$dbDatabase Object
array$osVersionsdata array
Returns
string output the javascript data

Definition at line 939 of file stats.php.

941  { /* @param $db \YAWK\db */
942  // check if browsers are set
943  if (!isset($osVersions) || (empty($osVersions)))
944  { // nope, get them from db
945  $osVersions = $this->countOSVersions($db, '');
946  }
947  $jsonData = "[";
948  foreach ($osVersions AS $osVersion => $value)
949  {
950  // init textcolor
951  $textcolor = '';
952  // set different colors for each OS version
953  if ($osVersion === "Windows 11") { $textcolor = "#00c0ef"; }
954  if ($osVersion === "Windows 10") { $textcolor = "#00c0ef"; }
955  if ($osVersion === "Windows 8") { $textcolor = "#00c0ef"; }
956  if ($osVersion === "Windows 7") { $textcolor = "#00A0C7"; }
957  if ($osVersion === "Windows Vista") { $textcolor = "#00B5E1"; }
958  if ($osVersion === "Windows Server") { $textcolor = "#004E61"; }
959  if ($osVersion === "Windows 2000") { $textcolor = "#005A7F"; }
960  if ($osVersion === "Windows XP") { $textcolor = "#00B5FF"; }
961  if ($osVersion === "Windows ME") { $textcolor = "#0090C9"; }
962  if ($osVersion === "Windows 98") { $textcolor = "#00A5E5"; }
963  if ($osVersion === "Windows 95") { $textcolor = "#0089BF"; }
964  if ($osVersion === "Windows 3.11") { $textcolor = "#00ACBF"; }
965  if ($osVersion === "Mac OS X") { $textcolor = "#f39c12"; }
966  if ($osVersion === "Mac OS 9") { $textcolor = "#BD7A0E"; }
967  if ($osVersion === "Linux") { $textcolor = "#f56954"; }
968  if ($osVersion === "Ubuntu") { $textcolor = "#BF5242"; }
969  if ($osVersion === "iPhone") { $textcolor = "#212121"; }
970  if ($osVersion === "iPad") { $textcolor = "#131313"; }
971  if ($osVersion === "iPod") { $textcolor = "#212121"; }
972  if ($osVersion === "Android") { $textcolor = "#6FF576"; }
973  if ($osVersion === "Blackberry") { $textcolor = "#187521"; }
974  if ($osVersion === "Mobile") { $textcolor = "#437540"; }
975  if ($osVersion === "Unknown") { $textcolor = "#6B756D"; }
976 
977  // only browsers, not the total value
978  if ($osVersion !== ("Total"))
979  {
980  $jsonData .= "
981  {
982  value: $value,
983  color: \"$textcolor\",
984  highlight: \"$textcolor\",
985  label: \"$osVersion\"
986  },";
987  }
988  }
989 
990  $jsonData .= "]";
991  return $jsonData;
countOSVersions($db, $data)
Count operating systems versions.
Definition: stats.php:1842

References $db, YAWK\stats\$osVersion, $value, and YAWK\stats\countOSVersions().

◆ getJsonWeekdayBarChart()

YAWK\stats::getJsonWeekdayBarChart (   $lang)

Output JS: WEEKDAY BAR CHART.

Returns
string output the javascript data

Definition at line 823 of file stats.php.

825  { /* @param $db \YAWK\db */
826  $jsonData = "labels: ['$lang[MONDAY]', '$lang[TUESDAY]', '$lang[WEDNESDAY]', '$lang[THURSDAY]', '$lang[FRIDAY]', '$lang[SATURDAY]', '$lang[SUNDAY]'],
827  datasets: [
828  {
829  label: 'Hits',
830  fillColor: ['#ebebeb', '#ebebeb', '#ebebeb', '#ebebeb', '#ebebeb', '#ebebeb', '#ebebeb'],
831  strokeColor: 'rgba(210, 214, 222, 1)',
832  pointColor: 'rgba(210, 214, 222, 1)',
833  pointStrokeColor: '#c1c7d1',
834  pointHighlightFill: '#fff',
835  pointHighlightStroke: 'rgba(220,220,220,1)',
836  data: [$this->i_monday, $this->i_tuesday, $this->i_wednesday, $this->i_thursday, $this->i_friday, $this->i_saturday, $this->i_sunday]
837  }
838  ]";
839  return $jsonData;

◆ getLoginColors()

YAWK\stats::getLoginColors (   $login)

Set and return the legend textcolor for logins (failed | success)

Parameters
string$logincontains the status (Failes, Successful...) as string
Returns
string returns the textcolor for this login status as string

Definition at line 1159 of file stats.php.

1161  {
1162  switch ($login) {
1163  case "Failed":
1164  $textcolor = "text-red";
1165  break;
1166  case "FailedPercentage":
1167  $textcolor = "text-red";
1168  break;
1169  case "SuccessPercentage":
1170  $textcolor = "text-green";
1171  break;
1172  case "Successful":
1173  $textcolor = "text-green";
1174  break;
1175  case "Frontend":
1176  $textcolor = "text-blue";
1177  break;
1178  case "Backend":
1179  $textcolor = "text-orange";
1180  break;
1181  default:
1182  $textcolor = "text-black";
1183  }
1184  return $textcolor;

◆ getOnlineUsers()

YAWK\stats::getOnlineUsers (   $db)

Return the number of all currently online users.

Parameters
object$dbDatabase Object
Returns
int|null

Definition at line 234 of file stats.php.

236  { /* @param $db \YAWK\db */
237  // first of all: delete all outdated sessions
238  $this->deleteOutdatedSessions($db);
239  // init count var
240  $i = 0;
241  // get online users from database
242  if ($res = $db->query("SELECT phpSessionID FROM {users_online}"))
243  { // gogo
244  while ($row = $res->fetch_assoc())
245  { // count entries
246  $i++;
247  }
248  $this->currentOnline = $i;
249  return $i;
250  }
251  else
252  {
253  return null;
254  }
deleteOutdatedSessions($db)
Check and delete outdated sessions if they are expired.
Definition: stats.php:262

References $db, $i, $res, and YAWK\stats\deleteOutdatedSessions().

Referenced by YAWK\stats\getStatsArray().

◆ getOsColors()

YAWK\stats::getOsColors (   $os)

Set and return the legend textcolor for each operating system.

Parameters
string$oscontains the operating system as string
Returns
string returns the textcolor for this OS as string

Definition at line 1080 of file stats.php.

1082  {
1083  switch ($os) {
1084  case "Windows":
1085  $textcolor = "text-blue";
1086  break;
1087  case "Linux":
1088  $textcolor = "text-red";
1089  break;
1090  case "Mac":
1091  $textcolor = "text-orange";
1092  break;
1093  case "Android":
1094  $textcolor = "text-green";
1095  break;
1096  case "Unknown":
1097  $textcolor = "text-grey";
1098  break;
1099  default:
1100  $textcolor = "text-black";
1101  }
1102  return $textcolor;

References YAWK\stats\$os.

◆ getOsVersionsColors()

YAWK\stats::getOsVersionsColors (   $osVersions)

Set and return the legend textcolor for each OS Version.

Parameters
string$osVersionscontains the operating system as string
Returns
string returns the textcolor for this os as string

Definition at line 1192 of file stats.php.

1194  {
1195  switch ($osVersions) {
1196  case "Windows 10":
1197  $textcolor = "text-blue";
1198  break;
1199  case "Windows 8":
1200  $textcolor = "text-blue";
1201  break;
1202  case "Windows 7":
1203  $textcolor = "text-blue";
1204  break;
1205  case "Windows Vista":
1206  $textcolor = "text-blue";
1207  break;
1208  case "Windows Server":
1209  $textcolor = "text-blue";
1210  break;
1211  case "Windows 2000":
1212  $textcolor = "text-blue";
1213  break;
1214  case "Windows XP":
1215  $textcolor = "text-blue";
1216  break;
1217  case "Windows ME":
1218  $textcolor = "text-blue";
1219  break;
1220  case "Windows 98":
1221  $textcolor = "text-blue";
1222  break;
1223  case "Windows 95":
1224  $textcolor = "text-blue";
1225  break;
1226  case "Windows 3.11":
1227  $textcolor = "text-blue";
1228  break;
1229  case "Windows 311":
1230  $textcolor = "text-blue";
1231  break;
1232  case "Mac OS X":
1233  $textcolor = "text-orange";
1234  break;
1235  case "Mac OS 9":
1236  $textcolor = "text-orange";
1237  break;
1238  case "Linux":
1239  $textcolor = "text-red";
1240  break;
1241  case "Ubuntu":
1242  $textcolor = "text-red";
1243  break;
1244  case "iPhone":
1245  $textcolor = "text-black";
1246  break;
1247  case "iPad":
1248  $textcolor = "text-black";
1249  break;
1250  case "iPod":
1251  $textcolor = "text-black";
1252  break;
1253  case "Android":
1254  $textcolor = "text-green";
1255  break;
1256  case "Blackberry":
1257  $textcolor = "text-green";
1258  break;
1259  case "Mobile":
1260  $textcolor = "text-green";
1261  break;
1262  case "Unknown":
1263  $textcolor = "text-grey";
1264  break;
1265  default:
1266  $textcolor = "text-black";
1267  }
1268  return $textcolor;

◆ getStatsArray()

YAWK\stats::getStatsArray (   $db,
  $interval,
  $period 
)

Returns an array with all stats, ordered by date_created.

Parameters
object$dbDatabase Object
string$intervalThe interval to get data
string$periodThe time period (YEAR, MONTH, DAY, HOUR, MINUTE or SECOND)
Returns
bool|array containing all stats from database

Definition at line 2025 of file stats.php.

2027  {
2028  /* @param $db \YAWK\db */
2029  // get online users
2030  $this->currentOnline = $this->getOnlineUsers($db);
2031 
2032  // check if period is set
2033  if (!isset($period) || (empty($period)))
2034  { // set default to show data of the last day (last 24 hours)
2035  $period = "DAY";
2036  }
2037  // check if interval is set, empty and be sure that it is an integer
2038  if (!isset($interval) || (empty($interval)))
2039  { // if no interval is given or wrong datatype, show all data
2040  $intervalQuery = ''; // leave empty in this case
2041  }
2042  // check if interval is correct int data type
2043  if (isset($interval) && (isset($period)))
2044  { // ok. lets check it
2045  switch ($interval)
2046  { // if zero
2047  case 0:
2048  // no additional query, leave empty
2049  $intervalQuery = '';
2050  break;
2051 
2052  // if any other value than zero
2053  default:
2054  // extend the query to get data for given time period
2055  $intervalQuery = "WHERE {stats}.date_created > DATE_SUB(NOW(), INTERVAL $interval $period)";
2056  }
2057  }
2058  else
2059  { // in any other case leave empty and get all data
2060  $intervalQuery = '';
2061  }
2062 
2063  // get stats data from database feat. prepared string
2064  if ($res = $db->query("SELECT * FROM {stats} $intervalQuery ORDER BY date_created DESC"))
2065  { // this array helds all stats data
2066  $statsArray = array();
2067  // gogo
2068  while ($row = $res->fetch_assoc())
2069  { // fill array
2070  $statsArray[] = $row;
2071  }
2072  }
2073  else
2074  { // q failed, set syslog and throw error
2075  \YAWK\sys::setSyslog($db, 43, 1, "failed to get stats from database.", 0, 0, 0, 0);
2076  \YAWK\alert::draw("warning", "Warning!", "Fetch database error: getStatsArray failed.","","4800");
2077  return false;
2078  }
2079  // check if there is a stats array
2080  if (is_array($statsArray) && (!empty($statsArray)))
2081  { // ok, go ahead with the data
2082  $this->calculateStatsFromArray($db, $statsArray);
2083  // and finally...
2084  return $statsArray;
2085  }
2086  else
2087  { // stats array is not an array or empty - in this case
2088  return null;
2089  }
calculateStatsFromArray($db, $data)
Calculate some basic stats (almost outdated)
Definition: stats.php:2097
getOnlineUsers($db)
Return the number of all currently online users.
Definition: stats.php:234

References $db, $res, YAWK\stats\calculateStatsFromArray(), YAWK\alert\draw(), and YAWK\stats\getOnlineUsers().

Referenced by YAWK\stats\calculateStatsFromArray().

◆ getUserStats()

YAWK\stats::getUserStats (   $db)

Count and set user stats like, how many users are registered, currently online or blocked.

Parameters
object$dbDatabase Object
Returns
bool

Definition at line 538 of file stats.php.

540  { /* @param $db \YAWK\db */
541  // count all users
542  if ($res = $db->query("SELECT id, blocked, online, logged_in FROM {users}"))
543  {
544  while ($user = mysqli_fetch_assoc($res))
545  {
546  // add user
547  $this->i_users++;
548 
549  // add blocked users
550  if ($user['blocked'] === "1")
551  {
552  $this->i_blockedUsers++;
553  }
554 
555  // add current online users
556  if ($user['online'] === "1")
557  {
558  $this->i_loggedInUsers++;
559  }
560  }
561  return true;
562  }
563  else
564  {
565  return false;
566  }

References $db, and $res.

◆ getWeekdaysPercent()

YAWK\stats::getWeekdaysPercent (   $lang)

Calculate hits in percent for each weekday.

Returns
array|bool containing weekdays and number of hits in percent

Definition at line 1389 of file stats.php.

1391  {
1392  if ($this->i_totalDays > 0)
1393  {
1394  // calculate percentage
1395  $a = 100 / $this->i_totalDays;
1396  $this->i_mondayPercent = round($a * $this->i_monday);
1397  $this->i_tuesdayPercent = round($a * $this->i_tuesday);
1398  $this->i_wednesdayPercent = round($a * $this->i_wednesday);
1399  $this->i_thursdayPercent = round($a * $this->i_thursday);
1400  $this->i_fridayPercent = round($a * $this->i_friday);
1401  $this->i_saturdayPercent = round($a * $this->i_saturday);
1402  $this->i_sundayPercent = round($a * $this->i_sunday);
1403 
1404  // build an array, cointaining the device types and the number how often it's been found
1405  $weekdaysPercent = array(
1406  "$lang[MONDAY]" => $this->i_mondayPercent,
1407  "$lang[TUESDAY]" => $this->i_tuesdayPercent,
1408  "$lang[WEDNESDAY]" => $this->i_wednesdayPercent,
1409  "$lang[THURSDAY]" => $this->i_thursdayPercent,
1410  "$lang[FRIDAY]" => $this->i_fridayPercent,
1411  "$lang[SATURDAY]" => $this->i_saturdayPercent,
1412  "$lang[SUNDAY]" => $this->i_sundayPercent
1413  );
1414  arsort($weekdaysPercent);
1415  return $weekdaysPercent;
1416  }
1417  else
1418  {
1419  return null;
1420  }
$i_totalDays
Definition: stats.php:206

References YAWK\stats\$i_totalDays.

◆ insertData()

YAWK\stats::insertData (   $db)

Insert data into database.

Parameters
object$dbDatabase Object
Returns
bool

Definition at line 2148 of file stats.php.

2150  { /* @param $db \YAWK\db */
2151  if ($db->query("INSERT INTO {stats}
2152  (uid,
2153  gid,
2154  logged_in,
2155  acceptLanguage,
2156  remoteAddr,
2157  userAgent,
2158  device,
2159  deviceType,
2160  os,
2161  osVersion,
2162  browser,
2163  browserVersion,
2164  date_created,
2165  referer,
2166  page)
2167  VALUES ('".$this->uid."',
2168  '".$this->gid."',
2169  '".$this->logged_in."',
2170  '".$this->acceptLanguage."',
2171  '".$this->remoteAddr."',
2172  '".$this->userAgent."',
2173  '".$this->device."',
2174  '".$this->deviceType."',
2175  '".$this->os."',
2176  '".$this->osVersion."',
2177  '".$this->browser."',
2178  '".$this->browserVersion."',
2179  '".$this->date_created."',
2180  '".$this->referer."',
2181  '".$this->page."')"))
2182  {
2183  return true;
2184  }
2185  else
2186  {
2187  return false;
2188  }

References $db.

Referenced by YAWK\stats\setStats().

◆ prepareData()

YAWK\stats::prepareData ( )

Prepare data: get and collect, detect OS and device type.

Returns
null

Definition at line 390 of file stats.php.

392  {
393  // check if a session is set
394  if (isset($_SESSION) && (!empty($_SESSION)))
395  {
396  // store current session ID
397  $this->phpSessionID = session_id();
398  // store current timestamp (will be used for users online counter)
399  $this->currentTimeStamp=time();
400 
401  // prepare all session user data
402  if (isset($_SESSION['uid']) && (!empty($_SESSION['uid'])))
403  { // user id (if logged in)
404  $this->uid = $_SESSION['uid'];
405  }
406  if (isset($_SESSION['gid']) && (!empty($_SESSION['gid'])))
407  { // user group id (if logged in)
408  $this->gid = $_SESSION['gid'];
409  }
410  if (isset($_SESSION['logged_in']) && (!empty($_SESSION['logged_in'])))
411  { // user group id (if logged in)
412  $this->logged_in = $_SESSION['logged_in'];
413  }
414  }
415  else
416  { // no session is set
417  // user is a guest - or obviously not logged in
418  $this->uid = 0;
419  $this->gid = 0;
420  $this->logged_in = 0;
421  }
422  // user IP address
423  $this->remoteAddr = $_SERVER['REMOTE_ADDR'];
424  // user client username
425  // $this->remoteUser = $_SERVER['REMOTE_HOST'];
426  // user agent information
427  $this->userAgent = $_SERVER['HTTP_USER_AGENT'];
428  // user browser
429 
430  // Include and instantiate the class.
431  require_once 'system/engines/mobiledetect/Mobile_Detect.php';
432  $detect = new \YAWK\Mobile_Detect();
433 
434  $this->deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'Tablet' : 'Phone') : 'Desktop');
435 
436  // Any mobile device (phones or tablets).
437  if ( $detect->isMobile() ) {
438  // $this->deviceType = "Mobile";
439  $browser = array();
440  $browser = \YAWK\sys::getBrowser($this->userAgent);
441  $this->browser = $browser['name'];
442  $this->browserVersion = $browser['version'];
443  }
444 
445  // Any tablet device.
446  if( $detect->isTablet() ){
447  // $this->deviceType = "Tablet";
448  $browser = array();
449  $browser = \YAWK\sys::getBrowser($this->userAgent);
450  $this->browser = $browser['name'];
451  $this->browserVersion = $browser['version'];
452  }
453 
454  // No Mobile, no tablet - must be a computer
455  if( !$detect->isMobile() && !$detect->isTablet() ){
456  // $this->deviceType = "Computer";
457  $browser = array();
458  $browser = \YAWK\sys::getBrowser($this->userAgent);
459  $this->browser = $browser['name'];
460  $this->browserVersion = $browser['version'];
461  $this->os = ucfirst($browser['platform']);
462  $this->osVersion = \YAWK\sys::getOS($this->userAgent);
463  }
464 
465  // detect wheter its a phone, pad or pod
466  if ( $detect->version('iPhone') ) {
467  $this->device = "iPhone";
468  $this->os = "iOS";
469  $this->osVersion = $detect->version('iPhone');
470  }
471  if ( $detect->version('iPad') ) {
472  $this->device = "iPad";
473  $this->os = "iOS";
474  $this->osVersion = $detect->version('iPad');
475  }
476  if ( $detect->version('iPod') ) {
477  $this->device = "iPod";
478  $this->os = "iOS";
479  $this->osVersion = $detect->version('iPod');
480  }
481  if( $detect->version('Android') ){
482  $this->os = "Android";
483  $this->osVersion = $detect->version('Android');
484  }
485 
486 
487  // set remote user
488  $this->acceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
489 
490  // the referer page from which the user came
491  if (!isset($_SERVER['HTTP_REFERER']) || (empty($_SERVER['HTTP_REFERER'])))
492  { // empty referer
493  $this->referer = '';
494  }
495  else
496  { // set referer
497  $this->referer = $_SERVER['HTTP_REFERER'];
498  }
499  // check if include (page request) is set
500  if (!isset($_GET['include']) || (empty($_GET['include'])))
501  { // if no page is set, take server variable
502  $this->page = $_SERVER['REQUEST_URI'];
503  }
504  else
505  { // set requested page
506  $this->page = $_GET['include'];
507  }
508 
509  // current datetime
510  $this->date_created = \YAWK\sys::now();
511  return null;
$blog gid
Definition: blog-setup.php:139
static getBrowser($useragent)
extract browser from useragent
Definition: sys.php:911
static getOS($useragent)
get operating system from useragent string
Definition: sys.php:1027
static now()
returns the current datetime
Definition: sys.php:1492
return window window jQBrowser a &&a browser
Definition: browser.js:14
print $_GET['id']
Definition: page-edit.php:357

References $_GET, YAWK\stats\$browser, browser, YAWK\sys\getBrowser(), YAWK\sys\getOS(), gid, and YAWK\sys\now().

Referenced by YAWK\stats\setStats().

◆ setOnlineUsers()

YAWK\stats::setOnlineUsers (   $db)

Set users online in database (stores and check sessions and timestamps)

Parameters
object$dbDatabase Object
Returns
null

Definition at line 284 of file stats.php.

286  { /* @param $db \YAWK\db */
287 
288  // how long
289  $this->phpSessionID = session_id();
290  $this->currentTimeStamp = time();
291  if (!isset($_SESSION['uid']) || (empty($_SESSION['uid'])))
292  { $this->uid = 0; }
293  else
294  { $this->uid = $_SESSION['uid']; }
295 
296  // check, if phpSessionID and currentTimeStamp is set
297  if (isset($this->phpSessionID) && (isset($this->currentTimeStamp)))
298  {
299  // check, if this phpSessionID is already in database
300  if ($row = $db->query("SELECT * from {users_online}
301  WHERE phpSessionID = '$this->phpSessionID'"))
302  {
303  // fetch data from users_online
304  if ($res = $row->fetch_assoc())
305  {
306  // create currentTimeStamp
307  $this->currentTimeStamp = time();
308  // user is still online, update currentTimeStamp for this phpSessionID
309  if ($row = $db->query("UPDATE {users_online}
310  SET currentTimeStamp = '$this->currentTimeStamp'
311  WHERE phpSessionID = '$this->phpSessionID'"))
312  {
313  // user updated
314  }
315  else
316  {
317  // could not update user status
318  // todo: add syslog entry
319  }
320  }
321  else
322  { // failed to fetch data, add new phpSessionID and currentTimeStamp
323  if ($db->query("INSERT INTO {users_online}
324  (phpSessionID,
325  uid,
326  currentTimeStamp)
327  VALUES ('".$this->phpSessionID."',
328  '".$this->uid."',
329  '".$this->currentTimeStamp."')"))
330  {
331  // all good
332  }
333  else
334  { // insert failed
335  // todo: add syslog entry
336  }
337  }
338  }
339  else
340  { // failed to fetch data, add new phpSessionID and currentTimeStamp
341  if ($db->query("INSERT INTO {users_online}
342  (phpSessionID,
343  currentTimeStamp)
344  VALUES ('".$this->phpSessionID."',
345  '".$this->currentTimeStamp."')"))
346  {
347  // all good
348  }
349  else
350  { // insert failed
351  // todo: add syslog entry
352  }
353  }
354  }
355  else
356  {
357  // session ID or currentTimeStamp are not set
358  // todo: add syslog entry
359  }
360 
361  return true;

References $db, and $res.

Referenced by YAWK\stats\setStats().

◆ setStats()

YAWK\stats::setStats (   $db)

Insert statistics data into database.

Parameters
object$dbDatabase Object
Returns
null

Definition at line 368 of file stats.php.

370  { /* @param $db \YAWK\db */
371  // check if stats are enabled
372  if (\YAWK\settings::getSetting($db, "statsEnable") == 1)
373  { // prepare user information that we can easily collect
374  $this->prepareData();
375  // set online users
376  $this->setOnlineUsers($db);
377  // insert statistics into database
378  if ($this->insertData($db) === false)
379  { // insert stats failed, add syslog entry
380  \YAWK\sys::setSyslog($db, 43, 1, "could not insert stats into database.", "", "", "","");
381  }
382  }
383  return null;
static getSetting($db, $property)
Get and return value for property from settings database.
Definition: settings.php:470
insertData($db)
Insert data into database.
Definition: stats.php:2148
setOnlineUsers($db)
Set users online in database (stores and check sessions and timestamps)
Definition: stats.php:284
prepareData()
Prepare data: get and collect, detect OS and device type.
Definition: stats.php:390
This class serves methods to create backup from files.
Definition: AdminLTE.php:2

References $db, YAWK\settings\getSetting(), YAWK\stats\insertData(), YAWK\stats\prepareData(), and YAWK\stats\setOnlineUsers().

Member Data Documentation

◆ $acceptLanguage

YAWK\stats::$acceptLanguage
  • Parameters
    stringdetected user language

Definition at line 26 of file stats.php.

◆ $activeSessions

YAWK\stats::$activeSessions
  • Parameters
    stringthe currently open sessions (active users)

Definition at line 50 of file stats.php.

◆ $browser

YAWK\stats::$browser
  • Parameters
    stringdetected users browser

Definition at line 40 of file stats.php.

Referenced by YAWK\stats\countBrowsers(), YAWK\stats\getBrowserColors(), YAWK\stats\getJsonBrowsers(), and YAWK\stats\prepareData().

◆ $browserVersion

YAWK\stats::$browserVersion
  • Parameters
    stringdetected users browser version

Definition at line 42 of file stats.php.

◆ $currentOnline

YAWK\stats::$currentOnline = 0
  • Parameters
    intcurrentOnline how many users are currently online

Definition at line 22 of file stats.php.

◆ $currentTimeStamp

YAWK\stats::$currentTimeStamp
  • Parameters
    stringcurrentTimeStamp current time stamp

Definition at line 20 of file stats.php.

◆ $date_created

YAWK\stats::$date_created
  • Parameters
    stringdatetime when entry was created

Definition at line 44 of file stats.php.

◆ $device

YAWK\stats::$device
  • Parameters
    stringdetected device (eg. iPhone, iPad, iPod)

Definition at line 32 of file stats.php.

◆ $deviceType

YAWK\stats::$deviceType
  • Parameters
    stringdetected device type (desktop, phone, tablet)

Definition at line 34 of file stats.php.

Referenced by YAWK\stats\countDeviceTypes(), and YAWK\stats\getDeviceTypeColors().

◆ $gid

YAWK\stats::$gid = 0
  • Parameters
    intgid (group id) who affected this entry

Definition at line 16 of file stats.php.

◆ $i_afternoon

YAWK\stats::$i_afternoon = 0
  • Parameters
    intnumber of hits in the afternoon

Definition at line 176 of file stats.php.

◆ $i_afternoonPercent

YAWK\stats::$i_afternoonPercent = 0
  • Parameters
    intnumber of hits in the afternoon (in percent)

Definition at line 184 of file stats.php.

◆ $i_android

YAWK\stats::$i_android = 0
  • Parameters
    inthow many users came with android?

Definition at line 126 of file stats.php.

◆ $i_blackberry

YAWK\stats::$i_blackberry = 0
  • Parameters
    inthow many users came with blackberry?

Definition at line 128 of file stats.php.

◆ $i_blockedUsers

YAWK\stats::$i_blockedUsers = 0

*

Parameters
inttotal blocked users

Definition at line 70 of file stats.php.

◆ $i_desktop

YAWK\stats::$i_desktop = 0
  • Parameters
    inthow many users came with desktop systems?

Definition at line 136 of file stats.php.

Referenced by YAWK\stats\countDeviceTypes().

◆ $i_desktopPercent

YAWK\stats::$i_desktopPercent = 0
  • Parameters
    inthow many users came with desktopdevices (in percent) ?

Definition at line 138 of file stats.php.

◆ $i_evening

YAWK\stats::$i_evening = 0
  • Parameters
    intnumber of hits in the evening

Definition at line 178 of file stats.php.

◆ $i_eveningPercent

YAWK\stats::$i_eveningPercent = 0
  • Parameters
    intnumber of hits in the evening (in percent)

Definition at line 186 of file stats.php.

◆ $i_friday

YAWK\stats::$i_friday = 0
  • Parameters
    intnumber of hits on friday

Definition at line 200 of file stats.php.

◆ $i_fridayPercent

YAWK\stats::$i_fridayPercent = 0
  • Parameters
    intnumber of hits on friday (in percent)

Definition at line 217 of file stats.php.

◆ $i_hits

YAWK\stats::$i_hits = 0
  • Parameters
    inttotal hits overall

Definition at line 54 of file stats.php.

Referenced by YAWK\stats\calculateStatsFromArray().

◆ $i_iOS

YAWK\stats::$i_iOS = 0
  • Parameters
    inthow many users came with iOS?

Definition at line 82 of file stats.php.

◆ $i_iPad

YAWK\stats::$i_iPad = 0
  • Parameters
    inthow many users came with iPad?

Definition at line 124 of file stats.php.

◆ $i_iPhone

YAWK\stats::$i_iPhone = 0
  • Parameters
    inthow many users came with iPhone?

Definition at line 120 of file stats.php.

◆ $i_iPod

YAWK\stats::$i_iPod = 0
  • Parameters
    inthow many users came with iPod?

Definition at line 122 of file stats.php.

◆ $i_linux

YAWK\stats::$i_linux = 0
  • Parameters
    inthow many users came with linux?

Definition at line 116 of file stats.php.

◆ $i_loggedInUsers

YAWK\stats::$i_loggedInUsers = 0

*

Parameters
inttotal logged in users

Definition at line 68 of file stats.php.

◆ $i_loggedUsers

YAWK\stats::$i_loggedUsers = 0
  • Parameters
    inthow many logins were successful?

Definition at line 56 of file stats.php.

◆ $i_loggedUsersPercentage

YAWK\stats::$i_loggedUsersPercentage = 0
  • Parameters
    inthow many logins were successful? (in percent)

Definition at line 58 of file stats.php.

◆ $i_loginBackend

YAWK\stats::$i_loginBackend = 0
  • Parameters
    inthow many logins were made to backend?

Definition at line 158 of file stats.php.

◆ $i_loginBackendFailed

YAWK\stats::$i_loginBackendFailed = 0
  • Parameters
    inthow many backend logins failed?

Definition at line 162 of file stats.php.

◆ $i_loginBackendSuccess

YAWK\stats::$i_loginBackendSuccess = 0
  • Parameters
    inthow many backend logins were successful?

Definition at line 160 of file stats.php.

◆ $i_loginFailed

YAWK\stats::$i_loginFailed = 0
  • Parameters
    inthow many logins failed?

Definition at line 154 of file stats.php.

Referenced by YAWK\stats\countLogins().

◆ $i_loginFailedPercentage

YAWK\stats::$i_loginFailedPercentage = 0
  • Parameters
    inthow many logins failed? (in percent)

Definition at line 170 of file stats.php.

◆ $i_loginFrontend

YAWK\stats::$i_loginFrontend = 0
  • Parameters
    inthow many logins were made to frontend?

Definition at line 156 of file stats.php.

◆ $i_loginFrontendFailed

YAWK\stats::$i_loginFrontendFailed = 0
  • Parameters
    inthow many frontend logins failed?

Definition at line 166 of file stats.php.

◆ $i_loginFrontendSuccess

YAWK\stats::$i_loginFrontendSuccess = 0
  • Parameters
    inthow many frontend logins were successful?

Definition at line 164 of file stats.php.

◆ $i_loginSuccessful

YAWK\stats::$i_loginSuccessful = 0
  • Parameters
    inthow many logins were successful?

Definition at line 152 of file stats.php.

Referenced by YAWK\stats\countLogins().

◆ $i_loginSuccessPercentage

YAWK\stats::$i_loginSuccessPercentage = 0
  • Parameters
    inthow many logins were successful? (in percent)

Definition at line 168 of file stats.php.

◆ $i_macos9

YAWK\stats::$i_macos9 = 0
  • Parameters
    inthow many users came with mac os 9?

Definition at line 114 of file stats.php.

◆ $i_macosX

YAWK\stats::$i_macosX = 0
  • Parameters
    inthow many users came with mac os x?

Definition at line 112 of file stats.php.

◆ $i_mobile

YAWK\stats::$i_mobile = 0
  • Parameters
    inthow many users came with unknown mobile system?

Definition at line 130 of file stats.php.

◆ $i_monday

YAWK\stats::$i_monday = 0
  • Parameters
    intnumber of hits on monday

Definition at line 192 of file stats.php.

◆ $i_mondayPercent

YAWK\stats::$i_mondayPercent = 0
  • Parameters
    intnumber of hits on monday (in percent)

Definition at line 209 of file stats.php.

◆ $i_morning

YAWK\stats::$i_morning = 0
  • Parameters
    intnumber of hits in the morningtime

Definition at line 174 of file stats.php.

◆ $i_morningPercent

YAWK\stats::$i_morningPercent = 0
  • Parameters
    intnumber of hits in the morningtime (in percent)

Definition at line 182 of file stats.php.

◆ $i_night

YAWK\stats::$i_night = 0
  • Parameters
    intnumber of hits in the night

Definition at line 180 of file stats.php.

Referenced by YAWK\stats\countDaytime(), and YAWK\stats\getDayTimesPercent().

◆ $i_nightPercent

YAWK\stats::$i_nightPercent = 0
  • Parameters
    intnumber of hits in the night (in percent)

Definition at line 188 of file stats.php.

◆ $i_osAndroid

YAWK\stats::$i_osAndroid = 0
  • Parameters
    inthow many users came with android?

Definition at line 80 of file stats.php.

◆ $i_osLinux

YAWK\stats::$i_osLinux = 0
  • Parameters
    inthow many users came with linux?

Definition at line 78 of file stats.php.

◆ $i_osMac

YAWK\stats::$i_osMac = 0
  • Parameters
    inthow many users came with macOS?

Definition at line 76 of file stats.php.

◆ $i_osUnknown

YAWK\stats::$i_osUnknown = 0
  • Parameters
    inthow many operating systems were unable to detect?

Definition at line 84 of file stats.php.

Referenced by YAWK\stats\countOS().

◆ $i_osWindows

YAWK\stats::$i_osWindows = 0
  • Parameters
    inthow many users came with windows?

Definition at line 74 of file stats.php.

◆ $i_others

YAWK\stats::$i_others = 0
  • Parameters
    inthow many users came with other systems?

Definition at line 132 of file stats.php.

Referenced by YAWK\stats\countOSVersions().

◆ $i_phone

YAWK\stats::$i_phone = 0
  • Parameters
    inthow many users came with mobile devices?

Definition at line 144 of file stats.php.

Referenced by YAWK\stats\countDeviceTypes().

◆ $i_phonePercent

YAWK\stats::$i_phonePercent = 0
  • Parameters
    inthow many users came with mobile devices (in percent) ?

Definition at line 146 of file stats.php.

◆ $i_publicUsers

YAWK\stats::$i_publicUsers = 0
  • Parameters
    inthow many users did not log in and visited as public guest?

Definition at line 60 of file stats.php.

◆ $i_publicUsersPercentage

YAWK\stats::$i_publicUsersPercentage = 0
  • Parameters
    inthow many users did not log in and visited as public guest? (in percent)

Definition at line 62 of file stats.php.

◆ $i_saturday

YAWK\stats::$i_saturday = 0
  • Parameters
    intnumber of hits on saturday

Definition at line 202 of file stats.php.

◆ $i_saturdayPercent

YAWK\stats::$i_saturdayPercent = 0
  • Parameters
    intnumber of hits on saturday (in percent)

Definition at line 219 of file stats.php.

◆ $i_sunday

YAWK\stats::$i_sunday = 0
  • Parameters
    intnumber of hits on sunday

Definition at line 204 of file stats.php.

Referenced by YAWK\stats\countWeekdays().

◆ $i_sundayPercent

YAWK\stats::$i_sundayPercent = 0
  • Parameters
    intnumber of hits on sunday (in percent)

Definition at line 221 of file stats.php.

◆ $i_tablet

YAWK\stats::$i_tablet = 0
  • Parameters
    inthow many users came with tablet devices?

Definition at line 140 of file stats.php.

Referenced by YAWK\stats\countDeviceTypes().

◆ $i_tabletPercent

YAWK\stats::$i_tabletPercent = 0
  • Parameters
    inthow many users came with tablet devices (in percent) ?

Definition at line 142 of file stats.php.

◆ $i_thursday

YAWK\stats::$i_thursday = 0
  • Parameters
    intnumber of hits on thursday

Definition at line 198 of file stats.php.

◆ $i_thursdayPercent

YAWK\stats::$i_thursdayPercent = 0
  • Parameters
    intnumber of hits on thursday (in percent)

Definition at line 215 of file stats.php.

◆ $i_totalDays

YAWK\stats::$i_totalDays = 0
  • Parameters
    intnumber of hits on all days (sum)

Definition at line 206 of file stats.php.

Referenced by YAWK\stats\getWeekdaysPercent().

◆ $i_totalLogins

YAWK\stats::$i_totalLogins = 0
  • Parameters
    inthow logins were totally made?

Definition at line 150 of file stats.php.

Referenced by YAWK\stats\countLogins().

◆ $i_tuesday

YAWK\stats::$i_tuesday = 0
  • Parameters
    intnumber of hits on tuesday

Definition at line 194 of file stats.php.

◆ $i_tuesdayPercent

YAWK\stats::$i_tuesdayPercent = 0
  • Parameters
    intnumber of hits on tuesday (in percent)

Definition at line 211 of file stats.php.

◆ $i_ubuntu

YAWK\stats::$i_ubuntu = 0
  • Parameters
    inthow many users came with ubuntu?

Definition at line 118 of file stats.php.

◆ $i_users

YAWK\stats::$i_users = 0

*

Parameters
inttotal users overall

Definition at line 66 of file stats.php.

◆ $i_wednesday

YAWK\stats::$i_wednesday = 0
  • Parameters
    intnumber of hits on wednesday

Definition at line 196 of file stats.php.

◆ $i_wednesdayPercent

YAWK\stats::$i_wednesdayPercent = 0
  • Parameters
    intnumber of hits on wednesday (in percent)

Definition at line 213 of file stats.php.

◆ $i_windows10

YAWK\stats::$i_windows10 = 0
  • Parameters
    inthow many users came with windows10?

Definition at line 90 of file stats.php.

◆ $i_windows11

YAWK\stats::$i_windows11 = 0
  • Parameters
    inthow many users came with windows11?

Definition at line 88 of file stats.php.

◆ $i_windows2000

YAWK\stats::$i_windows2000 = 0
  • Parameters
    inthow many users came with windows 2000?

Definition at line 102 of file stats.php.

◆ $i_windows311

YAWK\stats::$i_windows311 = 0
  • Parameters
    inthow many users came with windows 3.11?

Definition at line 110 of file stats.php.

◆ $i_windows7

YAWK\stats::$i_windows7 = 0
  • Parameters
    inthow many users came with windows7?

Definition at line 94 of file stats.php.

◆ $i_windows8

YAWK\stats::$i_windows8 = 0
  • Parameters
    inthow many users came with windows8?

Definition at line 92 of file stats.php.

◆ $i_windows95

YAWK\stats::$i_windows95 = 0
  • Parameters
    inthow many users came with windows 95?

Definition at line 108 of file stats.php.

◆ $i_windows98

YAWK\stats::$i_windows98 = 0
  • Parameters
    inthow many users came with windows 98?

Definition at line 106 of file stats.php.

◆ $i_windowsME

YAWK\stats::$i_windowsME = 0
  • Parameters
    inthow many users came with windows me?

Definition at line 104 of file stats.php.

◆ $i_windowsServer

YAWK\stats::$i_windowsServer = 0
  • Parameters
    inthow many users came with windows server?

Definition at line 98 of file stats.php.

◆ $i_windowsVista

YAWK\stats::$i_windowsVista = 0
  • Parameters
    inthow many users came with windows vista?

Definition at line 96 of file stats.php.

◆ $i_windowsXP

YAWK\stats::$i_windowsXP = 0
  • Parameters
    inthow many users came with windows xp?

Definition at line 100 of file stats.php.

◆ $id

YAWK\stats::$id
  • Parameters
    intid for every entry

Definition at line 12 of file stats.php.

◆ $logged_in

YAWK\stats::$logged_in = 0
  • Parameters
    int0|1 was the user logged in?

Definition at line 24 of file stats.php.

◆ $os

YAWK\stats::$os
  • Parameters
    stringdetected users operating system

Definition at line 36 of file stats.php.

Referenced by YAWK\stats\countOS(), YAWK\stats\getJsonOS(), and YAWK\stats\getOsColors().

◆ $osVersion

YAWK\stats::$osVersion
  • Parameters
    stringdetected users operating system version

Definition at line 38 of file stats.php.

Referenced by YAWK\stats\countOSVersions(), and YAWK\stats\getJsonOSVersions().

◆ $page

YAWK\stats::$page
  • Parameters
    stringpage that the user requested

Definition at line 48 of file stats.php.

Referenced by YAWK\stats\drawPagesBox().

◆ $phpSessionID

YAWK\stats::$phpSessionID
  • Parameters
    intphpSessionID current php session ID

Definition at line 18 of file stats.php.

◆ $referer

YAWK\stats::$referer
  • Parameters
    stringusers url referer string

Definition at line 46 of file stats.php.

◆ $remoteAddr

YAWK\stats::$remoteAddr
  • Parameters
    stringIP address who affected this entry

Definition at line 28 of file stats.php.

◆ $uid

YAWK\stats::$uid = 0
  • Parameters
    intuid (user id) who affected this entry

Definition at line 14 of file stats.php.

◆ $userAgent

YAWK\stats::$userAgent
  • Parameters
    stringcomplete useragent info

Definition at line 30 of file stats.php.


The documentation for this class was generated from the following file: