YaWK  24.1
Yet another WebKit
stats.php
Go to the documentation of this file.
1 <?php
2 namespace YAWK
3 {
4  /**
5  * @brief Statistics - get and set user and page stats
6  * @author Daniel Retzl <[email protected]>
7  * @version 1.0.0
8  *
9  */
10  class stats
11  {
12  /** * @param int id for every entry */
13  public $id;
14  /** * @param int uid (user id) who affected this entry */
15  public $uid = 0;
16  /** * @param int gid (group id) who affected this entry */
17  public $gid = 0;
18  /** * @param int phpSessionID current php session ID */
19  public $phpSessionID;
20  /** * @param string currentTimeStamp current time stamp */
21  public $currentTimeStamp;
22  /** * @param int currentOnline how many users are currently online */
23  public $currentOnline = 0;
24  /** * @param int 0|1 was the user logged in? */
25  public $logged_in = 0;
26  /** * @param string detected user language */
27  public $acceptLanguage;
28  /** * @param string IP address who affected this entry */
29  public $remoteAddr;
30  /** * @param string complete useragent info*/
31  public $userAgent;
32  /** * @param string detected device (eg. iPhone, iPad, iPod) */
33  public $device;
34  /** * @param string detected device type (desktop, phone, tablet) */
35  public $deviceType;
36  /** * @param string detected users operating system */
37  public $os;
38  /** * @param string detected users operating system version */
39  public $osVersion;
40  /** * @param string detected users browser */
41  public $browser;
42  /** * @param string detected users browser version */
43  public $browserVersion;
44  /** * @param string datetime when entry was created */
45  public $date_created;
46  /** * @param string users url referer string */
47  public $referer;
48  /** * @param string page that the user requested */
49  public $page;
50  /** * @param string the currently open sessions (active users) */
51  public $activeSessions;
52 
53  // stats variables
54  /** * @param int total hits overall */
55  public $i_hits = 0;
56  /** * @param int how many logins were successful? */
57  public $i_loggedUsers = 0;
58  /** * @param int how many logins were successful? (in percent) */
59  public $i_loggedUsersPercentage = 0;
60  /** * @param int how many users did not log in and visited as public guest? */
61  public $i_publicUsers = 0;
62  /** * @param int how many users did not log in and visited as public guest? (in percent) */
63  public $i_publicUsersPercentage = 0;
64 
65  // user stats
66  /** *@param int total users overall */
67  public $i_users = 0;
68  /** *@param int total logged in users */
69  public $i_loggedInUsers = 0;
70  /** *@param int total blocked users */
71  public $i_blockedUsers = 0;
72 
73  // os types
74  /** * @param int how many users came with windows? */
75  public $i_osWindows = 0;
76  /** * @param int how many users came with macOS? */
77  public $i_osMac = 0;
78  /** * @param int how many users came with linux? */
79  public $i_osLinux = 0;
80  /** * @param int how many users came with android? */
81  public $i_osAndroid = 0;
82  /** * @param int how many users came with iOS? */
83  public $i_iOS = 0;
84  /** * @param int how many operating systems were unable to detect? */
85  public $i_osUnknown = 0;
86 
87  // os versions
88  /** * @param int how many users came with windows11? */
89  public $i_windows11 = 0;
90  /** * @param int how many users came with windows10? */
91  public $i_windows10 = 0;
92  /** * @param int how many users came with windows8? */
93  public $i_windows8 = 0;
94  /** * @param int how many users came with windows7? */
95  public $i_windows7 = 0;
96  /** * @param int how many users came with windows vista? */
97  public $i_windowsVista = 0;
98  /** * @param int how many users came with windows server? */
99  public $i_windowsServer = 0;
100  /** * @param int how many users came with windows xp? */
101  public $i_windowsXP = 0;
102  /** * @param int how many users came with windows 2000? */
103  public $i_windows2000 = 0;
104  /** * @param int how many users came with windows me? */
105  public $i_windowsME = 0;
106  /** * @param int how many users came with windows 98? */
107  public $i_windows98 = 0;
108  /** * @param int how many users came with windows 95? */
109  public $i_windows95 = 0;
110  /** * @param int how many users came with windows 3.11? */
111  public $i_windows311 = 0;
112  /** * @param int how many users came with mac os x? */
113  public $i_macosX = 0;
114  /** * @param int how many users came with mac os 9? */
115  public $i_macos9 = 0;
116  /** * @param int how many users came with linux? */
117  public $i_linux = 0;
118  /** * @param int how many users came with ubuntu? */
119  public $i_ubuntu = 0;
120  /** * @param int how many users came with iPhone? */
121  public $i_iPhone = 0;
122  /** * @param int how many users came with iPod? */
123  public $i_iPod = 0;
124  /** * @param int how many users came with iPad? */
125  public $i_iPad = 0;
126  /** * @param int how many users came with android? */
127  public $i_android = 0;
128  /** * @param int how many users came with blackberry? */
129  public $i_blackberry = 0;
130  /** * @param int how many users came with unknown mobile system? */
131  public $i_mobile = 0;
132  /** * @param int how many users came with other systems? */
133  public $i_others = 0;
134 
135  // devices
136  /** * @param int how many users came with desktop systems? */
137  public $i_desktop = 0;
138  /** * @param int how many users came with desktopdevices (in percent) ? */
139  public $i_desktopPercent = 0;
140  /** * @param int how many users came with tablet devices? */
141  public $i_tablet = 0;
142  /** * @param int how many users came with tablet devices (in percent) ? */
143  public $i_tabletPercent = 0;
144  /** * @param int how many users came with mobile devices? */
145  public $i_phone = 0;
146  /** * @param int how many users came with mobile devices (in percent) ? */
147  public $i_phonePercent = 0;
148 
149  // logins
150  /** * @param int how logins were totally made? */
151  public $i_totalLogins = 0;
152  /** * @param int how many logins were successful? */
153  public $i_loginSuccessful = 0;
154  /** * @param int how many logins failed? */
155  public $i_loginFailed = 0;
156  /** * @param int how many logins were made to frontend? */
157  public $i_loginFrontend = 0;
158  /** * @param int how many logins were made to backend? */
159  public $i_loginBackend = 0;
160  /** * @param int how many backend logins were successful? */
161  public $i_loginBackendSuccess = 0;
162  /** * @param int how many backend logins failed? */
163  public $i_loginBackendFailed = 0;
164  /** * @param int how many frontend logins were successful? */
165  public $i_loginFrontendSuccess = 0;
166  /** * @param int how many frontend logins failed? */
167  public $i_loginFrontendFailed = 0;
168  /** * @param int how many logins were successful? (in percent) */
169  public $i_loginSuccessPercentage = 0;
170  /** * @param int how many logins failed? (in percent) */
171  public $i_loginFailedPercentage = 0;
172 
173  // date + time
174  /** * @param int number of hits in the morningtime */
175  public $i_morning = 0;
176  /** * @param int number of hits in the afternoon */
177  public $i_afternoon = 0;
178  /** * @param int number of hits in the evening */
179  public $i_evening = 0;
180  /** * @param int number of hits in the night */
181  public $i_night = 0;
182  /** * @param int number of hits in the morningtime (in percent) */
183  public $i_morningPercent = 0;
184  /** * @param int number of hits in the afternoon (in percent) */
185  public $i_afternoonPercent = 0;
186  /** * @param int number of hits in the evening (in percent) */
187  public $i_eveningPercent = 0;
188  /** * @param int number of hits in the night (in percent) */
189  public $i_nightPercent = 0;
190 
191  // weekdays
192  /** * @param int number of hits on monday */
193  public $i_monday = 0;
194  /** * @param int number of hits on tuesday */
195  public $i_tuesday = 0;
196  /** * @param int number of hits on wednesday */
197  public $i_wednesday = 0;
198  /** * @param int number of hits on thursday */
199  public $i_thursday = 0;
200  /** * @param int number of hits on friday */
201  public $i_friday = 0;
202  /** * @param int number of hits on saturday */
203  public $i_saturday = 0;
204  /** * @param int number of hits on sunday */
205  public $i_sunday = 0;
206  /** * @param int number of hits on all days (sum) */
207  public $i_totalDays = 0;
208 
209  /** * @param int number of hits on monday (in percent) */
210  public $i_mondayPercent = 0;
211  /** * @param int number of hits on tuesday (in percent) */
212  public $i_tuesdayPercent = 0;
213  /** * @param int number of hits on wednesday (in percent) */
214  public $i_wednesdayPercent = 0;
215  /** * @param int number of hits on thursday (in percent) */
216  public $i_thursdayPercent = 0;
217  /** * @param int number of hits on friday (in percent) */
218  public $i_fridayPercent = 0;
219  /** * @param int number of hits on saturday (in percent) */
220  public $i_saturdayPercent = 0;
221  /** * @param int number of hits on sunday (in percent) */
222  public $i_sundayPercent = 0;
223 
224  public function construct()
225  {
226 
227  }
228 
229 
230  /**
231  * @brief Return the number of all currently online users
232  * @param object $db Database Object
233  * @return int|null
234  */
235  public function getOnlineUsers($db)
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  }
255  }
256 
257  /**
258  * @brief Check and delete outdated sessions if they are expired
259  * @param object $db Database Object
260  * @param int $expireAfter Time in seconds after a session will be deleted
261  * @return bool
262  */
263  public function deleteOutdatedSessions($db)
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  }
278  }
279 
280  /**
281  * @brief Set users online in database (stores and check sessions and timestamps)
282  * @param object $db Database Object
283  * @return null
284  */
285  public function setOnlineUsers($db)
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;
362  }
363 
364  /**
365  * @brief Insert statistics data into database
366  * @param object $db Database Object
367  * @return null
368  */
369  public function setStats($db)
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;
384  }
385 
386 
387  /**
388  * @brief Prepare data: get and collect, detect OS and device type
389  * @return null
390  */
391  public function prepareData()
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;
512  }
513 
514 
515  /**
516  * @brief Count all messages that are stored in the database
517  * @param object $db Database Object
518  * @return mixed
519  */
520  public function countMessages($db)
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  }
532  }
533 
534  /**
535  * @brief Count and set user stats like, how many users are registered, currently online or blocked
536  * @param object $db Database Object
537  * @return bool
538  */
539  public function getUserStats($db)
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  }
567  }
568 
569 
570  /**
571  * @brief Count system logins
572  * @param object $db Database Object
573  * @param int $limit Contains an i number to limit the sql request
574  * @return array|bool
575  */
576  public function countLogins($db)
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  }
665  }
666 
667 
668  /**
669  * @brief Output JS: PIE CHART login data
670  * @param object $db Database Object
671  * @param object $lang language
672  * @param array $logins data array
673  * @return string output the javascript data
674  */
675  public function getJsonLogins($db, $logins, $lang)
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;
706  }
707 
708 
709 
710  /**
711  * @brief Output JS: PIE CHART daytime data
712  * @param object $db Database Object
713  * @param array $daytime data array
714  * @param array language array
715  * @return string return the javascript data
716  */
717  public function getJsonDaytimePieChart($db, $daytimes, $lang)
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;
754  }
755 
756 
757  /**
758  * @brief Output JS: LINE CHART daytime data
759  * @param object $db Database Object
760  * @param array $daytimes data array
761  * @param array $lang language array
762  * @return string output the javascript data
763  */
764  public function getJsonDaytimeLineChart($db, $daytimes, $lang)
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;
786  }
787 
788 
789  /**
790  * @brief Output JS: BAR CHART daytime data
791  * @param object $db Database Object
792  * @param array $daytimes data array
793  * @return string output the javascript data
794  */
795  public function getJsonDaytimeBarChart($db, $daytimes, $lang)
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;
817  }
818 
819 
820  /**
821  * @brief Output JS: WEEKDAY BAR CHART
822  * @return string output the javascript data
823  */
824  public function getJsonWeekdayBarChart($lang)
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;
840  }
841 
842 
843  /**
844  * @brief Output JS: PIE CHART browser data
845  * @param object $db Database Object
846  * @param array $browsers data array
847  * @return string output the javascript data
848  */
849  public function getJsonBrowsers($db, $browsers)
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;
887  }
888 
889 
890  /**
891  * @brief Output JS: PIE CHART OS data
892  * @param object $db Database Object
893  * @param array $oss data array
894  * @return string output the javascript data
895  */
896  public function getJsonOS($db, $oss)
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;
931  }
932 
933 
934  /**
935  * @brief Output JS: BAR CHART OS versions
936  * @param object $db Database Object
937  * @param array $osVersions data array
938  * @return string output the javascript data
939  */
940  public function getJsonOSVersions($db, $osVersions)
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;
992  }
993 
994 
995  /**
996  * @brief Output JS: BAR CHART device types
997  * @param object $db Database Object
998  * @param object $lang language
999  * @param array $deviceTypes data array
1000  * @return string output the javascript
1001  */
1002  public function getJsonDeviceTypes($db, $deviceTypes, $lang)
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;
1024  }
1025 
1026 
1027  /**
1028  * @brief Set and return the legend textcolor for each browser
1029  * @param object $db Database Object
1030  * @param string $browser contains the browser as string
1031  * @return string returns the textcolor for this browser as string
1032  */
1033  public function getBrowserColors($browser)
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;
1073  }
1074 
1075 
1076  /**
1077  * @brief Set and return the legend textcolor for each operating system
1078  * @param string $os contains the operating system as string
1079  * @return string returns the textcolor for this OS as string
1080  */
1081  public function getOsColors($os)
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;
1103  }
1104 
1105 
1106  /**
1107  * @brief Set and return the legend textcolor for each device type
1108  * @param string $deviceType contains the type (desktop, phone, tablet) as string
1109  * @return string returns the textcolor for this device type as string
1110  */
1111  public function getDeviceTypeColors($deviceType)
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;
1127  }
1128 
1129  /**
1130  * @brief Set and return the legend textcolor for each daytime
1131  * @param string $daytime contains the daytime (morning, afternoon, evening, night) as string
1132  * @return string returns the textcolor for this daytime as string
1133  */
1134  public function getDaytimeColors($daytime, $lang)
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;
1153  }
1154 
1155  /**
1156  * @brief Set and return the legend textcolor for logins (failed | success)
1157  * @param string $login contains the status (Failes, Successful...) as string
1158  * @return string returns the textcolor for this login status as string
1159  */
1160  public function getLoginColors($login)
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;
1185  }
1186 
1187 
1188  /**
1189  * @brief Set and return the legend textcolor for each OS Version
1190  * @param string $osVersions contains the operating system as string
1191  * @return string returns the textcolor for this os as string
1192  */
1193  public function getOsVersionsColors($osVersions)
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;
1269  }
1270 
1271 
1272  /**
1273  * @brief Count and set the number of hits for each weekday
1274  * @param object $db the database object
1275  * @param string $data array containing all the stats data
1276  * @param string $limit contains i number for sql limitation
1277  * @param object $lang language array
1278  * @return array|bool containing weekdays and number of hits
1279  */
1280  public function countWeekdays($db, $data, $lang, $limit)
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;
1383  }
1384 
1385 
1386  /**
1387  * @brief Calculate hits in percent for each weekday
1388  * @return array|bool containing weekdays and number of hits in percent
1389  */
1390  public function getWeekdaysPercent($lang)
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  }
1421  }
1422 
1423 
1424  /**
1425  * @brief Count and set the number of hits for each daytime
1426  * @param object $db the database object
1427  * @param string $data array containing all the stats data
1428  * @param string $limit contains i number for sql limitation
1429  * @return array|bool containing daytimes (and number of hits
1430  */
1431  public function countDaytime($db, $data, $lang)
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;
1526  }
1527 
1528 
1529 
1530  /**
1531  * @brief Calculate hits per daytime and return data in percent
1532  * @param object $db the database object
1533  * @return array containing daytimes and number of hits in percent
1534  */
1535  public function getDayTimesPercent($lang)
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  }
1564  }
1565 
1566 
1567  /**
1568  * @brief Count and return browsers
1569  * @param object $db the database object
1570  * @param string $data array containing all the stats data
1571  * @param string $limit contains i number for sql limitation
1572  * @return array|bool returning array containing the browsers and their hits
1573  */
1574  public function countBrowsers($db, $data)
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;
1664  }
1665 
1666 
1667  /**
1668  * @brief Count device types (desktop, phone or tablet)
1669  * @param object $db the database object
1670  * @param string $data array containing all the stats data
1671  * @param string $limit contains i number for sql limitation
1672  * @return array|bool returning array containing device types and their hits
1673  */
1674  public function countDeviceTypes($db, $data)
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  }
1750  }
1751 
1752 
1753  /**
1754  * @brief Count operating systems
1755  * @param object $db the database object
1756  * @param string $data array containing all the stats data
1757  * @param string $limit contains i number for sql limitation
1758  * @return array|bool returning array containing all detected operating systems and their hits
1759  */
1760  public function countOS($db, $data)
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;
1834  }
1835 
1836 
1837  /**
1838  * @brief Count operating systems versions
1839  * @param object $db the database object
1840  * @param string $data array containing all the stats data
1841  * @return array|bool returning array containing all detected OS versions and their hits
1842  */
1843  public function countOSVersions($db, $data)
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;
2016  }
2017 
2018 
2019  /**
2020  * @brief Returns an array with all stats, ordered by date_created.
2021  * @param object $db Database Object
2022  * @param string $interval The interval to get data
2023  * @param string $period The time period (YEAR, MONTH, DAY, HOUR, MINUTE or SECOND)
2024  * @return bool|array containing all stats from database
2025  */
2026  public function getStatsArray($db, $interval, $period) // get all settings from db like property
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  }
2090  }
2091 
2092 
2093  /**
2094  * @brief Calculate some basic stats (almost outdated)
2095  * @param object $db Database Object
2096  * @param array $data Stats Data Array
2097  */
2098  public function calculateStatsFromArray($db, $data)
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  */
2141  }
2142 
2143 
2144  /**
2145  * @brief Insert data into database
2146  * @param object $db Database Object
2147  * @return bool
2148  */
2149  public function insertData($db)
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  }
2189  }
2190 
2191 
2192  /**
2193  * @brief Draw a default box containing user statistics
2194  * @param object $db Database Object
2195  * @param object $lang language object
2196  */
2197  public function drawUserStats($db, $lang)
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  }
2215  }
2216 
2217 
2218  /**
2219  * @brief Draw default box containing OS Statistics
2220  * @param object $db Database Object
2221  * @param object $lang language
2222  * @param string $data array containing all the stats data
2223  * @param string $limit contains i number for sql limitation
2224  */
2225  public function drawOsBox($db, $data, $lang)
2226  { /** @var $db \YAWK\db */
2227  // get data for this box
2228  $oss = $this->countOS($db, $data);
2229 
2230  echo "<!-- donut box: -->
2231  <div class=\"box box-default\">
2232  <div class=\"box-header with-border\">
2233  <h3 class=\"box-title\">$lang[OPERATING_SYSTEMS] <small>($lang[BETA])</small></h3>
2234 
2235  <div class=\"box-tools pull-right\">
2236  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"collapse\"><i class=\"fa fa-minus\"></i>
2237  </button>
2238  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"remove\"><i class=\"fa fa-times\"></i></button>
2239  </div>
2240  </div>
2241  <!-- /.box-header -->
2242  <div class=\"box-body\">
2243  <div class=\"row\">
2244  <div class=\"col-md-8\">
2245  <div class=\"chart-responsive\">
2246  <canvas id=\"pieChartOS\" height=\"150\"></canvas>
2247  </div>
2248  <!-- ./chart-responsive -->
2249  </div>
2250  <!-- /.col -->
2251  <div class=\"col-md-4\">
2252  <ul class=\"chart-legend clearfix\">
2253 
2254  <script> //-------------
2255  //- PIE CHART -
2256  //-------------
2257 
2258  // Get context with jQuery - using jQuery's .get() method.
2259  var pieChartCanvas = $('#pieChartOS').get(0).getContext('2d');
2260  var pieChart = new Chart(pieChartCanvas);
2261  // get browsers array
2262  // output js data with php function getJsonBrowsers
2263  var PieData = "; echo $this->getJsonOS($db, $oss);
2264  echo"
2265  var pieOptions = {
2266  //Boolean - Whether we should show a stroke on each segment
2267  segmentShowStroke: true,
2268  //String - The colour of each segment stroke
2269  segmentStrokeColor: '#fff',
2270  //Number - The width of each segment stroke
2271  segmentStrokeWidth: 1,
2272  //Number - The percentage of the chart that we cut out of the middle
2273  percentageInnerCutout: 50, // This is 0 for Pie charts
2274  //Number - Amount of animation steps
2275  animationSteps: 100,
2276  //String - Animation easing effect
2277  animationEasing: 'easeOutBounce',
2278  //Boolean - Whether we animate the rotation of the Doughnut
2279  animateRotate: true,
2280  //Boolean - Whether we animate scaling the Doughnut from the centre
2281  animateScale: false,
2282  //Boolean - whether to make the chart responsive to window resizing
2283  responsive: true,
2284  // Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
2285  maintainAspectRatio: false,
2286  //String - A legend template
2287  legendTemplate: '<ul class=\"<%=name.toLowerCase() %>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor %>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>',
2288  //String - A tooltip template
2289  tooltipTemplate: '<%=value %> <%=label%>'
2290  };
2291  //Create pie or douhnut chart
2292  // You can switch between pie and douhnut using the method below.
2293  pieChart.Doughnut(PieData, pieOptions);
2294  //-----------------
2295  //- END PIE CHART -
2296  //-----------------</script>";
2297 
2298  // walk through array and draw data beneath pie chart
2299  foreach ($oss AS $os => $value)
2300  { // get text colors
2301  $textcolor = $this->getOsColors($os);
2302  // show browsers their value is greater than zero and exclude totals
2303  if ($value > 0 && ($os !== "Total"))
2304  { // 1 line for every browser
2305  echo "<li><i class=\"fa fa-circle-o $textcolor\"></i> <b>$value</b> $os</li>";
2306  }
2307  // show totals
2308  if ($os === "Total")
2309  { // of how many visits
2310  echo "<li class=\"small\">$lang[LATEST] $value $lang[USERS]</li>";
2311  }
2312  }
2313  echo"
2314  </ul>
2315  </div>
2316  <!-- /.col -->
2317  </div>
2318  <!-- /.row -->
2319  </div>
2320  <!-- /.box-body -->
2321  <div class=\"box-footer no-padding\">
2322  <ul class=\"nav nav-pills nav-stacked\">";
2323 
2324  // sort array by value high to low to display most browsers first
2325  $oss[] = arsort($oss);
2326  // walk through array and display browsers as nav pills
2327  foreach ($oss as $os => $value)
2328  { // show only items where browser got a value
2329  if ($value !== 0 && $os !== 0)
2330  { // get different textcolors
2331  $textcolor = $this->getOsColors($os);
2332  echo "<li><a href=\"#\" class=\"$textcolor\">$os
2333  <span class=\"pull-right $textcolor\" ><i class=\"fa fa-angle-down\"></i>$value</span></a></li>";
2334  }
2335  }
2336 
2337  echo "</ul>
2338  </div>
2339  <!-- /.footer -->
2340  </div>
2341  <!-- /.box -->";
2342  }
2343 
2344 
2345 
2346  /**
2347  * @brief Draw default box containing browser statistics
2348  * @param object $db Database Object
2349  * @param object $db language
2350  * @param string $data array containing all the stats data
2351  * @param string $limit contains i number for sql limitation
2352  */
2353  public function drawBrowserBox($db, $data, $lang)
2354  { /** @var $db \YAWK\db */
2355  // get data for this box
2356  $browsers = $this->countBrowsers($db, $data);
2357 
2358  echo "<!-- donut box: -->
2359  <div class=\"box box-default\">
2360  <div class=\"box-header with-border\">
2361  <h3 class=\"box-title\">$lang[BROWSER] <small>$lang[USAGE]</small></h3>
2362 
2363  <div class=\"box-tools pull-right\">
2364  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"collapse\"><i class=\"fa fa-minus\"></i>
2365  </button>
2366  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"remove\"><i class=\"fa fa-times\"></i></button>
2367  </div>
2368  </div>
2369  <!-- /.box-header -->
2370  <div class=\"box-body\">
2371  <div class=\"row\">
2372  <div class=\"col-md-8\">
2373  <div class=\"chart-responsive\">
2374  <canvas id=\"pieChartBrowser\" height=\"150\"></canvas>
2375  </div>
2376  <!-- ./chart-responsive -->
2377  </div>
2378  <!-- /.col -->
2379  <div class=\"col-md-4\">
2380  <ul class=\"chart-legend clearfix\">
2381 
2382  <script> //-------------
2383  //- PIE CHART -
2384  //-------------
2385 
2386  // Get context with jQuery - using jQuery's .get() method.
2387  var pieChartCanvas = $('#pieChartBrowser').get(0).getContext('2d');
2388  var pieChart = new Chart(pieChartCanvas);
2389  // get browsers array
2390  // output js data with php function getJsonBrowsers
2391  var PieData = "; echo $this->getJsonBrowsers($db, $browsers);
2392  echo"
2393  var pieOptions = {
2394  //Boolean - Whether we should show a stroke on each segment
2395  segmentShowStroke: true,
2396  //String - The colour of each segment stroke
2397  segmentStrokeColor: '#fff',
2398  //Number - The width of each segment stroke
2399  segmentStrokeWidth: 1,
2400  //Number - The percentage of the chart that we cut out of the middle
2401  percentageInnerCutout: 50, // This is 0 for Pie charts
2402  //Number - Amount of animation steps
2403  animationSteps: 100,
2404  //String - Animation easing effect
2405  animationEasing: 'easeOutBounce',
2406  //Boolean - Whether we animate the rotation of the Doughnut
2407  animateRotate: true,
2408  //Boolean - Whether we animate scaling the Doughnut from the centre
2409  animateScale: false,
2410  //Boolean - whether to make the chart responsive to window resizing
2411  responsive: true,
2412  // Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
2413  maintainAspectRatio: false,
2414  //String - A legend template
2415  legendTemplate: '<ul class=\"<%=name.toLowerCase() %>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor %>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>',
2416  //String - A tooltip template
2417  tooltipTemplate: '<%=value %> <%=label%> users'
2418  };
2419  //Create pie or douhnut chart
2420  // You can switch between pie and douhnut using the method below.
2421  pieChart.Doughnut(PieData, pieOptions);
2422  //-----------------
2423  //- END PIE CHART -
2424  //-----------------</script>";
2425 
2426  // walk through array and draw data beneath pie chart
2427  foreach ($browsers AS $browser => $value)
2428  { // get text colors
2429  $textcolor = $this->getBrowserColors($browser);
2430  // show browsers their value is greater than zero and exclude totals
2431  if ($value > 0 && ($browser !== "Total"))
2432  { // 1 line for every browser
2433  echo "<li><i class=\"fa fa-circle-o $textcolor\"></i> <b>$value</b> $browser</li>";
2434  }
2435  // show totals
2436  if ($browser === "Total")
2437  { // of how many visits
2438  echo "<li class=\"small\">$lang[LATEST] $value $lang[VISITORS]</li>";
2439  }
2440  }
2441  echo"
2442  </ul>
2443  </div>
2444  <!-- /.col -->
2445  </div>
2446  <!-- /.row -->
2447  </div>
2448  <!-- /.box-body -->
2449  <div class=\"box-footer no-padding\">
2450  <ul class=\"nav nav-pills nav-stacked\">";
2451 
2452  // sort array by value high to low to display most browsers first
2453  $browsers[] = arsort($browsers);
2454  // walk through array and display browsers as nav pills
2455  foreach ($browsers as $browser => $value)
2456  { // show only items where browser got a value
2457  if ($value !== 0 && $browser !== 0)
2458  { // get different textcolors
2459  $textcolor = $this->getBrowserColors($browser);
2460  echo "<li><a href=\"#\" class=\"$textcolor\">$browser
2461  <span class=\"pull-right $textcolor\" ><i class=\"fa fa-angle-down\"></i>$value</span></a></li>";
2462  }
2463  }
2464 
2465  echo "</ul>
2466  </div>
2467  <!-- /.footer -->
2468  </div>
2469  <!-- /.box -->";
2470  }
2471 
2472 
2473  /**
2474  * @brief Draw default box containing OS versions statistics
2475  * @param object $db Database Object
2476  * @param object $lang language
2477  * @param string $data array containing all the stats data
2478  * @param string $limit contains i number for sql limitation
2479  */
2480  public function drawOsVersionBox($db, $data, $lang)
2481  { /** @var $db \YAWK\db */
2482  // get data for this box
2483 
2484  $osVersions = $this->countOSVersions($db, $data);
2485 
2486  echo "<!-- donut box: -->
2487  <div class=\"box box-default\">
2488  <div class=\"box-header with-border\">
2489  <h3 class=\"box-title\">$lang[OPERATING_SYSTEM] $lang[VERSIONS] <small>($lang[BETA])</small></h3>
2490 
2491  <div class=\"box-tools pull-right\">
2492  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"collapse\"><i class=\"fa fa-minus\"></i>
2493  </button>
2494  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"remove\"><i class=\"fa fa-times\"></i></button>
2495  </div>
2496  </div>
2497  <!-- /.box-header -->
2498  <div class=\"box-body\">
2499  <div class=\"row\">
2500  <div class=\"col-md-8\">
2501  <div class=\"chart-responsive\">
2502  <canvas id=\"pieChartOSVersion\" height=\"150\"></canvas>
2503  </div>
2504  <!-- ./chart-responsive -->
2505  </div>
2506  <!-- /.col -->
2507  <div class=\"col-md-4\">
2508  <ul class=\"chart-legend clearfix\">
2509 
2510  <script> //-------------
2511  //- PIE CHART -
2512  //-------------
2513 
2514  // Get context with jQuery - using jQuery's .get() method.
2515  var pieChartCanvas = $('#pieChartOSVersion').get(0).getContext('2d');
2516  var pieChart = new Chart(pieChartCanvas);
2517  // get browsers array
2518  // output js data with php function getJsonBrowsers
2519  var PieData = "; echo $this->getJsonOSVersions($db, $osVersions);
2520  echo"
2521  var pieOptions = {
2522  //Boolean - Whether we should show a stroke on each segment
2523  segmentShowStroke: true,
2524  //String - The colour of each segment stroke
2525  segmentStrokeColor: '#fff',
2526  //Number - The width of each segment stroke
2527  segmentStrokeWidth: 1,
2528  //Number - The percentage of the chart that we cut out of the middle
2529  percentageInnerCutout: 50, // This is 0 for Pie charts
2530  //Number - Amount of animation steps
2531  animationSteps: 100,
2532  //String - Animation easing effect
2533  animationEasing: 'easeOutBounce',
2534  //Boolean - Whether we animate the rotation of the Doughnut
2535  animateRotate: true,
2536  //Boolean - Whether we animate scaling the Doughnut from the centre
2537  animateScale: false,
2538  //Boolean - whether to make the chart responsive to window resizing
2539  responsive: true,
2540  // Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
2541  maintainAspectRatio: false,
2542  //String - A legend template
2543  legendTemplate: '<ul class=\"<%=name.toLowerCase() %>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor %>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>',
2544  //String - A tooltip template
2545  tooltipTemplate: '<%=value %> <%=label%>'
2546  };
2547  //Create pie or douhnut chart
2548  // You can switch between pie and douhnut using the method below.
2549  pieChart.Doughnut(PieData, pieOptions);
2550  //-----------------
2551  //- END PIE CHART -
2552  //-----------------</script>";
2553 
2554  // walk through array and draw data beneath pie chart
2555  foreach ($osVersions AS $osVersion => $value)
2556  { // get text colors
2557  $textcolor = $this->getOsVersionsColors($osVersion);
2558  // show browsers their value is greater than zero and exclude totals
2559  if ($value > 0 && ($osVersion !== "Total"))
2560  { // 1 line for every browser
2561  echo "<li><i class=\"fa fa-circle-o $textcolor\"></i> <b>$value</b> $osVersion</li>";
2562  }
2563  // show totals
2564  if ($osVersion === "Total")
2565  { // of how many visits
2566  echo "<li class=\"small\">$lang[LATEST] $value $lang[HITS]</li>";
2567  }
2568  }
2569  echo"
2570  </ul>
2571  </div>
2572  <!-- /.col -->
2573  </div>
2574  <!-- /.row -->
2575  </div>
2576  <!-- /.box-body -->
2577  <div class=\"box-footer no-padding\">
2578  <ul class=\"nav nav-pills nav-stacked\">";
2579 
2580  // sort array by value high to low to display most browsers first
2581  $osVersions[] = arsort($osVersions);
2582  // walk through array and display browsers as nav pills
2583  foreach ($osVersions as $osVersion => $value)
2584  { // show only items where browser got a value
2585  if ($value !== 0 && $osVersion !== 0)
2586  { // get different textcolors
2587  $textcolor = $this->getOsVersionsColors($osVersion);
2588  echo "<li><a href=\"#\" class=\"$textcolor\">$osVersion
2589  <span class=\"pull-right $textcolor\" ><i class=\"fa fa-angle-down\"></i>$value</span></a></li>";
2590  }
2591  }
2592 
2593  echo "</ul>
2594  </div>
2595  <!-- /.footer -->
2596  </div>
2597  <!-- /.box -->";
2598  }
2599 
2600  /**
2601  * @brief Draw default box containing device types
2602  * @param object $db Database Object
2603  * @param object $lang language
2604  * @param string $data array containing all the stats data
2605  * @param string $limit contains i number for sql limitation
2606  */
2607  public function drawDeviceTypeBox($db, $data, $lang)
2608  { /** @var $db \YAWK\db */
2609  // get data for this box
2610  $deviceTypes = $this->countDeviceTypes($db, $data);
2611 
2612  echo "<!-- donut box: -->
2613  <div class=\"box box-default\">
2614  <div class=\"box-header with-border\">
2615  <h3 class=\"box-title\">$lang[DEVICE_TYPE] <small>($lang[DESKTOP_MOBILE_TABLET])</small></h3>
2616 
2617  <div class=\"box-tools pull-right\">
2618  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"collapse\"><i class=\"fa fa-minus\"></i>
2619  </button>
2620  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"remove\"><i class=\"fa fa-times\"></i></button>
2621  </div>
2622  </div>
2623  <!-- /.box-header -->
2624  <div class=\"box-body\">
2625  <div class=\"row\">
2626  <div class=\"col-md-8\">
2627  <div class=\"chart-responsive\">
2628  <canvas id=\"barChartDeviceType\" height=\"150\"></canvas>
2629  </div>
2630  <!-- ./chart-responsive -->
2631  </div>
2632  <!-- /.col -->
2633  <div class=\"col-md-4\">
2634  <ul class=\"chart-legend clearfix\">
2635 
2636  <script>
2637  //-------------
2638  //- BAR CHART -
2639  //-------------
2640 
2641  var barChartData = {";echo $this->getJsonDeviceTypes($db, $deviceTypes, $lang); echo "};
2642  var barChartCanvas = $('#barChartDeviceType').get(0).getContext('2d');
2643  var barChart = new Chart(barChartCanvas);
2644  barChartData.datasets.fillColor = '#00a65a';
2645  barChartData.datasets.strokeColor = '#00a65a';
2646  barChartData.datasets.pointColor = '#00a65a';
2647  var barChartOptions = {
2648  //Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
2649  scaleBeginAtZero: true,
2650  //Boolean - Whether grid lines are shown across the chart
2651  scaleShowGridLines: true,
2652  //String - Colour of the grid lines
2653  scaleGridLineColor: 'rgba(0,0,0,.05)',
2654  //Number - Width of the grid lines
2655  scaleGridLineWidth: 1,
2656  //Boolean - Whether to show horizontal lines (except X axis)
2657  scaleShowHorizontalLines: true,
2658  //Boolean - Whether to show vertical lines (except Y axis)
2659  scaleShowVerticalLines: true,
2660  //Boolean - If there is a stroke on each bar
2661  barShowStroke: true,
2662  //Number - Pixel width of the bar stroke
2663  barStrokeWidth: 2,
2664  //Number - Spacing between each of the X value sets
2665  barValueSpacing: 5,
2666  //Number - Spacing between data sets within X values
2667  barDatasetSpacing: 1,
2668  //String - A legend template
2669  legendTemplate: '<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets.fillColor %>\"></span><%if(datasets[i].label){%><%=datasets.label%><%}%></li><%}%></ul>',
2670  //Boolean - whether to make the chart responsive
2671  responsive: true,
2672  maintainAspectRatio: true
2673  };
2674 
2675  barChartOptions.datasetFill = false;
2676  barChart.Bar(barChartData, barChartOptions);
2677  </script>";
2678 
2679  // walk through array and draw data beneath pie chart
2680  if ($deviceTypes)
2681  {
2682  foreach ($deviceTypes AS $deviceType => $value)
2683  { // get text colors
2684  $textcolor = $this->getDeviceTypeColors($deviceType);
2685  // show browsers their value is greater than zero and exclude totals
2686  if ($value > 0 && ($deviceType !== "Total"))
2687  { // 1 line for every browser
2688  echo "<li><i class=\"fa fa-circle-o $textcolor\"></i> <b>$value</b> $deviceType</li>";
2689  }
2690  // show totals
2691  if ($deviceType === "Total")
2692  { // of how many visits
2693  echo "<li class=\"small\">$lang[LATEST] $value $lang[USERS]</li>";
2694  }
2695  }
2696  }
2697  echo"
2698  </ul>
2699  </div>
2700  <!-- /.col -->
2701  </div>
2702  <!-- /.row -->
2703  </div>
2704  <!-- /.box-body -->
2705  <div class=\"box-footer no-padding\">
2706  <ul class=\"nav nav-pills nav-stacked\">";
2707 
2708  // sort array by value high to low to display most browsers first
2709  if (is_array($deviceTypes) && (!empty($deviceTypes)))
2710  {
2711  $deviceTypes[] = arsort($deviceTypes);
2712  // walk through array and display browsers as nav pills
2713  foreach ($deviceTypes as $deviceType => $value)
2714  { // show only items where browser got a value
2715  if ($value !== 0 && $deviceType !== 0)
2716  { // get different textcolors
2717  $textcolor = $this->getDeviceTypeColors($deviceType);
2718  echo "<li><a href=\"#\" class=\"$textcolor\">$deviceType
2719  <span class=\"pull-right $textcolor\" ><i class=\"fa fa-angle-down\"></i>$value</span></a></li>";
2720  }
2721  }
2722  }
2723 
2724  echo "</ul>
2725  </div>
2726  <!-- /.footer -->
2727  </div>
2728  <!-- /.box -->";
2729  }
2730 
2731 
2732  /**
2733  * @brief Draw default box containing login statistics
2734  * @param object $db Database Object
2735  * @param object $lang language
2736  * @param string $data array containing all the stats data
2737  * @param string $limit contains i number for sql limitation
2738  */
2739  public function drawLoginBox($db, $lang)
2740  { /** @var $db \YAWK\db */
2741  // get data for this box
2742  $logins = $this->countLogins($db);
2743 
2744  echo "<!-- donut box: -->
2745  <div class=\"box box-default\">
2746  <div class=\"box-header with-border\">
2747  <h3 class=\"box-title\">$lang[LOGINS] <small>$lang[OVERVIEW_LOGINS]</small></h3>
2748 
2749  <div class=\"box-tools pull-right\">
2750  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"collapse\"><i class=\"fa fa-minus\"></i>
2751  </button>
2752  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"remove\"><i class=\"fa fa-times\"></i></button>
2753  </div>
2754  </div>
2755  <!-- /.box-header -->
2756  <div class=\"box-body\">
2757  <div class=\"row\">
2758  <div class=\"col-md-8\">
2759  <div class=\"chart-responsive\">
2760  <canvas id=\"pieChartLogins\" height=\"150\"></canvas>
2761  </div>
2762  <!-- ./chart-responsive -->
2763  </div>
2764  <!-- /.col -->
2765  <div class=\"col-md-4\">
2766  <ul class=\"chart-legend clearfix\">
2767 
2768  <script> //-------------
2769  //- PIE CHART -
2770  //-------------
2771 
2772  // Get context with jQuery - using jQuery's .get() method.
2773  var pieChartCanvas = $('#pieChartLogins').get(0).getContext('2d');
2774  var pieChart = new Chart(pieChartCanvas);
2775  // get browsers array
2776  // output js data with php function getJsonBrowsers
2777  var PieData = ";echo $this->getJsonLogins($db, $logins, $lang);
2778  echo"
2779  var pieOptions = {
2780  //Boolean - Whether we should show a stroke on each segment
2781  segmentShowStroke: true,
2782  //String - The colour of each segment stroke
2783  segmentStrokeColor: '#fff',
2784  //Number - The width of each segment stroke
2785  segmentStrokeWidth: 1,
2786  //Number - The percentage of the chart that we cut out of the middle
2787  percentageInnerCutout: 50, // This is 0 for Pie charts
2788  //Number - Amount of animation steps
2789  animationSteps: 100,
2790  //String - Animation easing effect
2791  animationEasing: 'easeOutBounce',
2792  //Boolean - Whether we animate the rotation of the Doughnut
2793  animateRotate: true,
2794  //Boolean - Whether we animate scaling the Doughnut from the centre
2795  animateScale: false,
2796  //Boolean - whether to make the chart responsive to window resizing
2797  responsive: true,
2798  // Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
2799  maintainAspectRatio: false,
2800  //String - A legend template
2801  legendTemplate: '<ul class=\"<%=name.toLowerCase() %>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor %>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>',
2802  //String - A tooltip template
2803  tooltipTemplate: '<%=value %> <%=label%>'
2804  };
2805  //Create pie or douhnut chart
2806  // You can switch between pie and douhnut using the method below.
2807  pieChart.Doughnut(PieData, pieOptions);
2808  //-----------------
2809  //- END PIE CHART -
2810  //-----------------</script>";
2811 
2812  // walk through array and draw data beneath pie chart
2813  foreach ($logins AS $login => $value)
2814  { // get text colors
2815  $textcolor = $this->getLoginColors($login);
2816  // show browsers their value is greater than zero and exclude totals
2817  if ($value > 0 && ($login !== "Total") && ($login === "FailedPercentage") || ($login === "SuccessPercentage"))
2818  { // 1 line for every browser
2819  if ($login === "FailedPercentage") { $login = $lang['FAILED']; }
2820  if ($login === "SuccessPercentage") { $login = $lang['SUCCESSFUL']; }
2821  echo "<li><i class=\"fa fa-circle-o $textcolor\"></i> <b>$value%</b> $login</li>";
2822  }
2823  // show totals
2824  if ($login === "Total")
2825  { // of how many visits
2826  echo "<li class=\"small\">$lang[LATEST] $value $lang[LOGINS]</li>";
2827  }
2828  }
2829  echo"
2830  </ul>
2831  </div>
2832  <!-- /.col -->
2833  </div>
2834  <!-- /.row -->
2835  </div>
2836  <!-- /.box-body -->
2837  <div class=\"box-footer no-padding\">
2838  <ul class=\"nav nav-pills nav-stacked\">";
2839 
2840  // sort array by value high to low to display most browsers first
2841  $logins[] = arsort($logins);
2842  // walk through array and display browsers as nav pills
2843  foreach ($logins as $login => $value)
2844  { // show only items where browser got a value
2845  if ($value !== 0 && $login !== 0)
2846  { // get different textcolors
2847  $textcolor = $this->getLoginColors($login);
2848  if ($login !== "Failed"
2849  && ($login !== "Successful")
2850  && ($login !== "Total"))
2851  {
2852  $spacer = "&nbsp;&nbsp;&nbsp;&nbsp;<small>";
2853  $spacerEnd ="</small>";
2854  }
2855  else
2856  {
2857  $spacer = '';
2858  $spacerEnd = '';
2859  }
2860  if ($login !== "FailedPercentage" && ($login !== "SuccessPercentage"))
2861  {
2862  echo "<li><a href=\"#\" class=\"$textcolor\">$spacer$login$spacerEnd
2863  <span class=\"pull-right $textcolor\" ><i class=\"fa fa-angle-down\"></i>$value</span></a></li>";
2864 
2865  }
2866  }
2867  }
2868 
2869  echo "</ul>
2870  </div>
2871  <!-- /.footer -->
2872  </div>
2873  <!-- /.box -->";
2874  }
2875 
2876 
2877  /**
2878  * @brief Draw default box containing daytime statistics
2879  * @param object $db Database Object
2880  * @param string $data array containing all the stats data
2881  * @param string $limit contains i number for sql limitation
2882  * @param object $lang language object
2883  */
2884  public function drawDaytimeBox($db, $data, $lang)
2885  { /** @var $db \YAWK\db */
2886  // get data for this box
2887  $dayTimes = $this->countDaytime($db, $data, $lang);
2888  $dayTimesPercent = $this->getDayTimesPercent($lang);
2889 
2890  echo "<!-- donut box: -->
2891  <div class=\"box box-default\">
2892  <div class=\"box-header with-border\">
2893  <h3 class=\"box-title\">$lang[DAYTIME] <small>$lang[PRIMETIME_QUESTION]</small></h3>
2894 
2895  <div class=\"box-tools pull-right\">
2896  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"collapse\"><i class=\"fa fa-minus\"></i>
2897  </button>
2898  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"remove\"><i class=\"fa fa-times\"></i></button>
2899  </div>
2900  </div>
2901  <!-- /.box-header -->
2902  <div class=\"box-body\">
2903  <div class=\"row\">
2904  <div class=\"col-md-8\">
2905  <div class=\"chart-responsive\">
2906  <canvas id=\"pieChartDaytime\" height=\"150\"></canvas>
2907  </div><!-- ./chart-responsive -->
2908 
2909  <div class=\"chart-responsive\">
2910  <canvas id=\"barChartDaytime\" height=\"150\"></canvas>
2911  </div><!-- ./chart-responsive -->
2912 
2913  <!--
2914  <div class=\"chart-responsive\">
2915  <canvas id=\"lineChartDaytime\" height=\"150\"></canvas>
2916  </div><!-- ./chart-responsive
2917  -->
2918  </div>
2919  <!-- /.col -->
2920  <div class=\"col-md-4\">
2921  <ul class=\"chart-legend clearfix\">
2922 
2923  <script>
2924  //-------------
2925  //- PIE CHART -
2926  //-------------
2927 
2928  // Get context with jQuery - using jQuery's .get() method.
2929  var pieChartCanvas = $('#pieChartDaytime').get(0).getContext('2d');
2930  var pieChart = new Chart(pieChartCanvas);
2931  // get browsers array
2932  // output js data with php function getJsonBrowsers
2933  var PieData = ";echo $this->getJsonDaytimePieChart($db, $dayTimes, $lang);
2934  echo "
2935  var pieOptions = {
2936  //Boolean - Whether we should show a stroke on each segment
2937  segmentShowStroke: true,
2938  //String - The colour of each segment stroke
2939  segmentStrokeColor: '#fff',
2940  //Number - The width of each segment stroke
2941  segmentStrokeWidth: 1,
2942  //Number - The percentage of the chart that we cut out of the middle
2943  percentageInnerCutout: 0, // This is 0 for Pie charts
2944  //Number - Amount of animation steps
2945  animationSteps: 100,
2946  //String - Animation easing effect
2947  animationEasing: 'easeOutBounce',
2948  //Boolean - Whether we animate the rotation of the Doughnut
2949  animateRotate: true,
2950  //Boolean - Whether we animate scaling the Doughnut from the centre
2951  animateScale: false,
2952  //Boolean - whether to make the chart responsive to window resizing
2953  responsive: true,
2954  // Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
2955  maintainAspectRatio: false,
2956  //String - A legend template
2957  legendTemplate: '<ul class=\" <%=name.toLowerCase() %>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor %>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>',
2958  //String - A tooltip template
2959  tooltipTemplate: '<%=value %> <%=label%>'
2960  };
2961  //Create pie or douhnut chart
2962  // You can switch between pie and douhnut using the method below.
2963  pieChart.Doughnut(PieData, pieOptions);
2964  //-----------------
2965  //- END PIE CHART -
2966  //-----------------
2967  </script>";
2968 
2969 
2970  echo"<script>
2971  //-------------
2972  //- BAR CHART -
2973  //-------------
2974 
2975  var barChartData = {";echo $this->getJsonDaytimeBarChart($db, $dayTimes, $lang);echo "};
2976  var barChartCanvas = $('#barChartDaytime').get(0).getContext('2d');
2977  var barChart = new Chart(barChartCanvas);
2978  barChartData.datasets.fillColor = '#00a65a';
2979  barChartData.datasets.strokeColor = '#00a65a';
2980  barChartData.datasets.pointColor = '#00a65a';
2981  var barChartOptions = {
2982  //Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
2983  scaleBeginAtZero: true,
2984  //Boolean - Whether grid lines are shown across the chart
2985  scaleShowGridLines: true,
2986  //String - Colour of the grid lines
2987  scaleGridLineColor: 'rgba(0,0,0,.05)',
2988  //Number - Width of the grid lines
2989  scaleGridLineWidth: 1,
2990  //Boolean - Whether to show horizontal lines (except X axis)
2991  scaleShowHorizontalLines: true,
2992  //Boolean - Whether to show vertical lines (except Y axis)
2993  scaleShowVerticalLines: true,
2994  //Boolean - If there is a stroke on each bar
2995  barShowStroke: true,
2996  //Number - Pixel width of the bar stroke
2997  barStrokeWidth: 2,
2998  //Number - Spacing between each of the X value sets
2999  barValueSpacing: 5,
3000  //Number - Spacing between data sets within X values
3001  barDatasetSpacing: 1,
3002  //String - A legend template
3003  legendTemplate: '<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets.fillColor %>\"></span><%if(datasets[i].label){%><%=datasets.label%><%}%></li><%}%></ul>',
3004  //Boolean - whether to make the chart responsive
3005  responsive: true,
3006  maintainAspectRatio: true
3007  };
3008 
3009  barChartOptions.datasetFill = false;
3010  barChart.Bar(barChartData, barChartOptions);
3011  </script>";
3012 
3013 
3014  echo "<script>
3015  //------------------
3016  // LINE CHART
3017  //------------------
3018  var lineChartData = {";print $this->getJsonDaytimeLineChart($db, $dayTimes, $lang);echo "};
3019  var lineChartOptions = {
3020  //Boolean - If we should show the scale at all
3021  showScale: true,
3022  //Boolean - Whether grid lines are shown across the chart
3023  scaleShowGridLines: false,
3024  //String - Colour of the grid lines
3025  scaleGridLineColor: 'rgba(0, 0, 0, .05)',
3026  //Number - Width of the grid lines
3027  scaleGridLineWidth: 1,
3028  //Boolean - Whether to show horizontal lines (except X axis)
3029  scaleShowHorizontalLines: true,
3030  //Boolean - Whether to show vertical lines (except Y axis)
3031  scaleShowVerticalLines: true,
3032  //Boolean - Whether the line is curved between points
3033  bezierCurve: true,
3034  //Number - Tension of the bezier curve between points
3035  bezierCurveTension: 0.3,
3036  //Boolean - Whether to show a dot for each point
3037  pointDot: false,
3038  //Number - Radius of each point dot in pixels
3039  pointDotRadius: 4,
3040  //Number - Pixel width of point dot stroke
3041  pointDotStrokeWidth: 1,
3042  //Number - amount extra to add to the radius to cater for hit detection outside the drawn point
3043  pointHitDetectionRadius: 20,
3044  //Boolean - Whether to show a stroke for datasets
3045  datasetStroke: true,
3046  //Number - Pixel width of dataset stroke
3047  datasetStrokeWidth: 2,
3048  //Boolean - Whether to fill the dataset with a color
3049  datasetFill: true,
3050  //String - A legend template
3051  legendTemplate: '<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].lineColor %>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>',
3052  //Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
3053  maintainAspectRatio: true,
3054  //Boolean - whether to make the chart responsive to window resizing
3055  responsive: true
3056  };
3057 
3058  // Create the line chart
3059  lineChart.Line(lineChartData, lineChartOptions);
3060  var lineChartCanvas = $('#lineChartDaytime').get(0).getContext('2d');
3061  var lineChart = new Chart(lineChartCanvas);
3062  lineChartOptions.datasetFill = false;
3063  lineChart.Line(lineChartData, lineChartOptions);
3064 
3065  </script>";
3066 
3067  // walk through array and draw data beneath pie chart
3068  if ($dayTimesPercent)
3069  {
3070  foreach ($dayTimesPercent AS $daytime => $value)
3071  { // get text colors
3072  $textcolor = $this->getDaytimeColors($daytime, $lang);
3073  // show browsers their value is greater than zero and exclude totals
3074  if ($value > 0 && ($daytime !== "$lang[TOTAL]"))
3075  { // 1 line for every browser
3076  $spacer = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
3077  if ($daytime === "$lang[MORNING]")
3078  { $legend = "$spacer<small>06:00 - 11:00</small>"; }
3079  elseif ($daytime === "$lang[AFTERNOON]")
3080  { $legend = "$spacer<small>12:00 - 17:00</small>"; }
3081  elseif ($daytime === "$lang[EVENING]")
3082  { $legend = "$spacer<small>18:00 - 23:00</small>"; }
3083  elseif ($daytime === "$lang[NIGHT]")
3084  { $legend = "$spacer<small>00:00 - 05:00</small>"; }
3085  else { $legend = ''; }
3086  echo "<li><i class=\"fa fa-circle-o $textcolor\"></i> <b>$value%</b> $daytime <br><small>$legend</small></li>";
3087  }
3088  // show totals
3089  if ($daytime === "Total")
3090  { // of how many visits
3091  echo "<li class=\"small\">latest $value hits</li>";
3092  }
3093  }
3094  }
3095  echo"
3096  </ul>
3097  </div>
3098  <!-- /.col -->
3099  </div>
3100  <!-- /.row -->
3101  </div>
3102  <!-- /.box-body -->
3103  <div class=\"box-footer no-padding\">
3104  <ul class=\"nav nav-pills nav-stacked\">";
3105 
3106  // sort array by value high to low to display most browsers first
3107  $dayTimes[] = arsort($dayTimes);
3108  // walk through array and display browsers as nav pills
3109  foreach ($dayTimes as $dayTime => $value)
3110  { // show only items where browser got a value
3111  if ($value !== 0 && $dayTime !== 0)
3112  { // get different textcolors
3113  $textcolor = $this->getDaytimeColors($dayTime, $lang);
3114  echo "<li><a href=\"#\" class=\"$textcolor\">$dayTime
3115  <span class=\"pull-right $textcolor\" ><i class=\"fa fa-angle-down\"></i>$value</span></a></li>";
3116  }
3117  }
3118 
3119  echo "</ul>
3120  </div>
3121  <!-- /.footer -->
3122  </div>
3123  <!-- /.box -->";
3124  }
3125 
3126 
3127  /**
3128  * @brief Draw default box containing weekday statistics
3129  * @param object $db Database Object
3130  * @param string $data array containing all the stats data
3131  * @param string $limit contains i number for sql limitation
3132  * @param object $lang language array
3133  */
3134  public function drawWeekdayBox($db, $data, $lang, $limit)
3135  { /** @var $db \YAWK\db */
3136  // get data for this box
3137  $weekdays = $this->countWeekdays($db, $data, $lang, $limit);
3138  $weekdaysPercent = $this->getWeekdaysPercent($lang);
3139 
3140  if ($limit == 0)
3141  {
3142  $heading = $lang['WHOLE_PERIOD'];
3143  }
3144  else
3145  {
3146  $heading = "$lang[THE_LATEST] $limit $lang[DAYS]";
3147  }
3148 
3149  echo "<!-- donut box: -->
3150  <div class=\"box box-default\">
3151  <div class=\"box-header with-border\">
3152  <h3 class=\"box-title\">$lang[WEEKDAYS] <small>$lang[WEEKDAY_OVERVIEW] $heading</small></h3>
3153 
3154  <div class=\"box-tools pull-right\">
3155  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"collapse\"><i class=\"fa fa-minus\"></i>
3156  </button>
3157  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"remove\"><i class=\"fa fa-times\"></i></button>
3158  </div>
3159  </div>
3160  <!-- /.box-header -->
3161  <div class=\"box-body\">
3162  <div class=\"row\">
3163  <div class=\"col-md-8\">
3164  <div class=\"chart-responsive\">
3165  <canvas id=\"barChartWeekdays\" height=\"150\"></canvas>
3166  </div>
3167  <!-- ./chart-responsive -->
3168  </div>
3169  <!-- /.col -->
3170  <div class=\"col-md-4\">
3171  <ul class=\"chart-legend clearfix\">
3172 
3173  <script>
3174  //-------------
3175  //- BAR CHART -
3176  //-------------
3177 
3178  var barChartData = {";echo $this->getJsonWeekdayBarChart($lang);echo "};
3179  var barChartCanvas = $('#barChartWeekdays').get(0).getContext('2d');
3180  var barChart = new Chart(barChartCanvas);
3181  barChartData.datasets.fillColor = '#00a65a';
3182  barChartData.datasets.strokeColor = '#00a65a';
3183  barChartData.datasets.pointColor = '#00a65a';
3184  var barChartOptions = {
3185  //Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
3186  scaleBeginAtZero: true,
3187  //Boolean - Whether grid lines are shown across the chart
3188  scaleShowGridLines: true,
3189  //String - Colour of the grid lines
3190  scaleGridLineColor: 'rgba(0,0,0,.05)',
3191  //Number - Width of the grid lines
3192  scaleGridLineWidth: 1,
3193  //Boolean - Whether to show horizontal lines (except X axis)
3194  scaleShowHorizontalLines: true,
3195  //Boolean - Whether to show vertical lines (except Y axis)
3196  scaleShowVerticalLines: true,
3197  //Boolean - If there is a stroke on each bar
3198  barShowStroke: true,
3199  //Number - Pixel width of the bar stroke
3200  barStrokeWidth: 2,
3201  //Number - Spacing between each of the X value sets
3202  barValueSpacing: 5,
3203  //Number - Spacing between data sets within X values
3204  barDatasetSpacing: 1,
3205  //String - A legend template
3206  legendTemplate: '<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets.fillColor %>\"></span><%if(datasets[i].label){%><%=datasets.label%><%}%></li><%}%></ul>',
3207  //Boolean - whether to make the chart responsive
3208  responsive: true,
3209  maintainAspectRatio: true
3210  };
3211 
3212  barChartOptions.datasetFill = false;
3213  barChart.Bar(barChartData, barChartOptions);
3214  </script>";
3215  if ($weekdaysPercent)
3216  {
3217  // walk through array and draw data beneath pie chart
3218  foreach ($weekdaysPercent AS $weekday => $value)
3219  { // get text colors
3220  // show browsers their value is greater than zero and exclude totals
3221  if ($value > 0 && ($weekday !== "$lang[TOTAL]"))
3222  { // 1 line for every browser
3223  if (strlen($value) === 1) { $spacer = "&nbsp;&nbsp;"; } else { $spacer = ''; }
3224  echo "<li><b>$spacer$value%</b> $weekday</li>";
3225  }
3226  // show totals
3227  if ($weekday === "Total")
3228  { // of how many visits
3229  echo "<li class=\"small\">latest $value hits</li>";
3230  }
3231  }
3232  }
3233 
3234  echo"</ul>
3235  </div>
3236  <!-- /.col -->
3237  </div>
3238  <!-- /.row -->
3239  </div>
3240  <!-- /.box-body -->
3241  </div>
3242  <!-- /.box -->";
3243  }
3244 
3245  /**
3246  * @brief Draw default box containing overview statistics
3247  * @param array $lang language array
3248  */
3249  public function drawOverviewBox($lang)
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>";
3271  }
3272 
3273  /**
3274  * @brief Draw default box containing pages statistics
3275  * @param array $data stats data array
3276  * @param array $lang language array
3277  */
3278  public function drawPagesBox($data, $lang)
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>";
3312  }
3313 
3314  /**
3315  * @brief Draw default box containing days of month statistics
3316  * @param array $lang language array
3317  */
3318  public function getDaysOfMonthBox($lang)
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
3331  }
3332 
3333  }
3334 }
print $lang['FILEMAN_UPLOAD']
$data
Definition: stats.php:78
$blog gid
Definition: blog-setup.php:139
if(!isset($language)||(!isset($lang))) $item
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30
The default pages class. Provide all functions to handle static pages.
Definition: page.php:20
static getSetting($db, $property)
Get and return value for property from settings database.
Definition: settings.php:470
Statistics - get and set user and page stats.
Definition: stats.php:10
$logged_in
Definition: stats.php:24
countWeekdays($db, $data, $lang, $limit)
Count and set the number of hits for each weekday.
Definition: stats.php:1279
setStats($db)
Insert statistics data into database.
Definition: stats.php:368
$i_loggedInUsers
Definition: stats.php:68
$i_nightPercent
Definition: stats.php:188
construct()
Definition: stats.php:223
$i_osLinux
Definition: stats.php:78
$i_osUnknown
Definition: stats.php:84
getDaytimeColors($daytime, $lang)
Set and return the legend textcolor for each daytime.
Definition: stats.php:1133
$i_loginFailedPercentage
Definition: stats.php:170
$activeSessions
Definition: stats.php:50
$i_fridayPercent
Definition: stats.php:217
$i_eveningPercent
Definition: stats.php:186
$i_blockedUsers
Definition: stats.php:70
$i_windowsME
Definition: stats.php:104
$i_publicUsers
Definition: stats.php:60
$currentTimeStamp
Definition: stats.php:20
getJsonDeviceTypes($db, $deviceTypes, $lang)
Output JS: BAR CHART device types.
Definition: stats.php:1001
countLogins($db)
Count system logins.
Definition: stats.php:575
getUserStats($db)
Count and set user stats like, how many users are registered, currently online or blocked.
Definition: stats.php:538
getLoginColors($login)
Set and return the legend textcolor for logins (failed | success)
Definition: stats.php:1159
getJsonDaytimePieChart($db, $daytimes, $lang)
Output JS: PIE CHART daytime data.
Definition: stats.php:716
calculateStatsFromArray($db, $data)
Calculate some basic stats (almost outdated)
Definition: stats.php:2097
getDaysOfMonthBox($lang)
Draw default box containing days of month statistics.
Definition: stats.php:3317
$i_totalLogins
Definition: stats.php:150
drawOverviewBox($lang)
Draw default box containing overview statistics.
Definition: stats.php:3248
$i_wednesday
Definition: stats.php:196
getOnlineUsers($db)
Return the number of all currently online users.
Definition: stats.php:234
$date_created
Definition: stats.php:44
getDeviceTypeColors($deviceType)
Set and return the legend textcolor for each device type.
Definition: stats.php:1110
$browserVersion
Definition: stats.php:42
$i_loginFailed
Definition: stats.php:154
$i_windows2000
Definition: stats.php:102
$i_loggedUsers
Definition: stats.php:56
$i_saturdayPercent
Definition: stats.php:219
$i_phonePercent
Definition: stats.php:146
countMessages($db)
Count all messages that are stored in the database.
Definition: stats.php:519
$phpSessionID
Definition: stats.php:18
insertData($db)
Insert data into database.
Definition: stats.php:2148
$i_windowsVista
Definition: stats.php:96
$i_loginBackendSuccess
Definition: stats.php:160
$i_sundayPercent
Definition: stats.php:221
$i_thursdayPercent
Definition: stats.php:215
getOsColors($os)
Set and return the legend textcolor for each operating system.
Definition: stats.php:1080
$i_desktopPercent
Definition: stats.php:138
$i_windows10
Definition: stats.php:90
$userAgent
Definition: stats.php:30
$i_windowsServer
Definition: stats.php:98
$i_afternoonPercent
Definition: stats.php:184
countDaytime($db, $data, $lang)
Count and set the number of hits for each daytime.
Definition: stats.php:1430
drawUserStats($db, $lang)
Draw a default box containing user statistics.
Definition: stats.php:2196
$i_loginSuccessPercentage
Definition: stats.php:168
$i_tabletPercent
Definition: stats.php:142
$i_osAndroid
Definition: stats.php:80
setOnlineUsers($db)
Set users online in database (stores and check sessions and timestamps)
Definition: stats.php:284
getJsonWeekdayBarChart($lang)
Output JS: WEEKDAY BAR CHART.
Definition: stats.php:823
countDeviceTypes($db, $data)
Count device types (desktop, phone or tablet)
Definition: stats.php:1673
$i_osWindows
Definition: stats.php:74
$i_windows8
Definition: stats.php:92
$i_windows311
Definition: stats.php:110
$i_tuesdayPercent
Definition: stats.php:211
$i_loginSuccessful
Definition: stats.php:152
getDayTimesPercent($lang)
Calculate hits per daytime and return data in percent.
Definition: stats.php:1534
$i_windows98
Definition: stats.php:106
$i_loginFrontendFailed
Definition: stats.php:166
$i_publicUsersPercentage
Definition: stats.php:62
drawPagesBox($data, $lang)
Draw default box containing pages statistics.
Definition: stats.php:3277
countOS($db, $data)
Count operating systems.
Definition: stats.php:1759
$i_loginBackendFailed
Definition: stats.php:162
getWeekdaysPercent($lang)
Calculate hits in percent for each weekday.
Definition: stats.php:1389
$i_windows7
Definition: stats.php:94
$i_loginBackend
Definition: stats.php:158
$i_totalDays
Definition: stats.php:206
getBrowserColors($browser)
Set and return the legend textcolor for each browser.
Definition: stats.php:1032
getStatsArray($db, $interval, $period)
Returns an array with all stats, ordered by date_created.
Definition: stats.php:2025
$i_mondayPercent
Definition: stats.php:209
prepareData()
Prepare data: get and collect, detect OS and device type.
Definition: stats.php:390
$i_loginFrontend
Definition: stats.php:156
getOsVersionsColors($osVersions)
Set and return the legend textcolor for each OS Version.
Definition: stats.php:1192
countOSVersions($db, $data)
Count operating systems versions.
Definition: stats.php:1842
$acceptLanguage
Definition: stats.php:26
$i_afternoon
Definition: stats.php:176
$i_wednesdayPercent
Definition: stats.php:213
$i_windows11
Definition: stats.php:88
getJsonDaytimeLineChart($db, $daytimes, $lang)
Output JS: LINE CHART daytime data.
Definition: stats.php:763
$i_windows95
Definition: stats.php:108
countBrowsers($db, $data)
Count and return browsers.
Definition: stats.php:1573
$remoteAddr
Definition: stats.php:28
$currentOnline
Definition: stats.php:22
$i_morningPercent
Definition: stats.php:182
$i_loggedUsersPercentage
Definition: stats.php:58
getJsonDaytimeBarChart($db, $daytimes, $lang)
Output JS: BAR CHART daytime data.
Definition: stats.php:794
getJsonOS($db, $oss)
Output JS: PIE CHART OS data.
Definition: stats.php:895
$osVersion
Definition: stats.php:38
$deviceType
Definition: stats.php:34
$i_loginFrontendSuccess
Definition: stats.php:164
getJsonBrowsers($db, $browsers)
Output JS: PIE CHART browser data.
Definition: stats.php:848
getJsonLogins($db, $logins, $lang)
Output JS: PIE CHART login data.
Definition: stats.php:674
$i_windowsXP
Definition: stats.php:100
getJsonOSVersions($db, $osVersions)
Output JS: BAR CHART OS versions.
Definition: stats.php:939
deleteOutdatedSessions($db)
Check and delete outdated sessions if they are expired.
Definition: stats.php:262
$i_blackberry
Definition: stats.php:128
static getWeekday($date, $lang)
return weekday from given date
Definition: sys.php:1735
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
$heading
Definition: jplayer.php:18
return window window jQBrowser a &&a browser
Definition: browser.js:14
This class serves methods to create backup from files.
Definition: AdminLTE.php:2
print $_GET['id']
Definition: page-edit.php:357
print $tourdates date
$date
Definition: user-edit.php:285
$value
$i
$total
Definition: yawk-stats.php:102