From 04b1b35761d8e46d335432c389512bcf8dce75c0 Mon Sep 17 00:00:00 2001 From: cookandy Date: Thu, 2 Oct 2014 16:47:39 +0100 Subject: [PATCH] Added Header and DB Status Added central header file and updated settings to allow for monitoring of plexWatch database (optional). --- charts.php | 19 +----- datafactory/get-library-stats.php | 6 ++ header.php | 96 +++++++++++++++++++++++++++++++ history.php | 16 +----- includes/process_settings.php | 13 ++++- index.php | 18 +----- info.php | 20 +------ settings.php | 67 +++++++++++++++------ stats.php | 19 +----- user.php | 18 +----- users.php | 21 +------ 11 files changed, 170 insertions(+), 143 deletions(-) mode change 100644 => 100755 charts.php mode change 100644 => 100755 datafactory/get-library-stats.php create mode 100755 header.php mode change 100644 => 100755 history.php mode change 100644 => 100755 includes/process_settings.php mode change 100644 => 100755 index.php mode change 100644 => 100755 info.php mode change 100644 => 100755 settings.php mode change 100644 => 100755 stats.php mode change 100644 => 100755 user.php mode change 100644 => 100755 users.php diff --git a/charts.php b/charts.php old mode 100644 new mode 100755 index 3952ad8..bf467b6 --- a/charts.php +++ b/charts.php @@ -34,24 +34,7 @@ -
- -
+
diff --git a/datafactory/get-library-stats.php b/datafactory/get-library-stats.php old mode 100644 new mode 100755 index 282ebf0..e3b8e6e --- a/datafactory/get-library-stats.php +++ b/datafactory/get-library-stats.php @@ -97,4 +97,10 @@ echo ""; +$plays = $db->querySingle("SELECT count(*) FROM processed") or die ("Failed to access plexWatch database. Please check your settings."); + +echo "
  • "; +echo "

    ".$plays."

    Total Plays
    "; +echo "
  • "; + echo ""; \ No newline at end of file diff --git a/header.php b/header.php new file mode 100755 index 0000000..b787f5e --- /dev/null +++ b/header.php @@ -0,0 +1,96 @@ +querySingle("SELECT min(date(time, 'unixepoch','localtime')) as startdate FROM processed"); + $databaseFile = $plexWatch['plexWatchDb']; + + if ($plexWatch['dbHeaderInfo'] == 'yes') + { + //set time of DB update, and max time for offline + $plexWatchhDBlastUpdateTime = date ('F d Y H:i:s', filemtime($databaseFile)); + + if ($plexWatch['plexWatchDbMin'] != '') + { + $plexWatchhDBtimeForOffline = date('F d Y H:i:s', strToTime('-'.($plexWatch['plexWatchDbMin']).' min')); + //convert times to strings for compare + $d1 = strtotime($plexWatchhDBlastUpdateTime); + $d2 = strtotime($plexWatchhDBtimeForOffline); + $d3 = strToTime(date('F d Y H:i:s')); + //time difference should never be negative, or it's offline + $d4 = ($d1 - $d2); + + if ($d4 < 0) + { + $dbStatus = "Offline  "; + $lastUpdate = $plexWatchhDBlastUpdateTime; + } + else + { + $dbStatus = "Online"; + $lastUpdate = ($d3 - $d1). " seconds ago"; + } + + } + else + { + $dbStatus = "plexWatch DB update interval not defined in settings!"; + $lastUpdate = $plexWatchhDBlastUpdateTime; + } + + $plexWatchhDBheader = "Statistics Since: ".date('F d, Y', strtotime($startDate))."
    Database: ".$databaseFile."
    Status: ".$dbStatus."
    Last Update: ".$lastUpdate."
    "; + } + else + if ($plexWatch['dbHeaderInfo'] == 'no') + { + $plexWatchhDBheader = ""; + } + + } + + ?> +
    + +
    \ No newline at end of file diff --git a/history.php b/history.php old mode 100644 new mode 100755 index 02e9141..e394613 --- a/history.php +++ b/history.php @@ -47,21 +47,7 @@ -
    - -
    +
    diff --git a/includes/process_settings.php b/includes/process_settings.php old mode 100644 new mode 100755 index c7f1a0a..ba54b48 --- a/includes/process_settings.php +++ b/includes/process_settings.php @@ -19,7 +19,14 @@ $myPlexUser = "\$plexWatch['myPlexUser'] = '".$_POST['myPlexUser']."';"; $myPlexPass = "\$plexWatch['myPlexPass'] = '".$_POST['myPlexPass']."';"; - + $plexWatchDb = "\$plexWatch['plexWatchDb'] = '".$_POST['plexWatchDb']."';"; + $plexWatchDbMin = "\$plexWatch['plexWatchDbMin'] = '".$_POST['plexWatchDbMin']."';"; + + if (!isset($_POST['dbHeaderInfo'])) { + $dbHeaderInfo = "\$plexWatch['dbHeaderInfo'] = 'no';"; + }else if ($_POST['dbHeaderInfo'] == "yes") { + $dbHeaderInfo = "\$plexWatch['dbHeaderInfo'] = '".$_POST['dbHeaderInfo']."';"; + } if (!isset($_POST['globalHistoryGrouping'])) { $globalHistoryGrping = "\$plexWatch['globalHistoryGrouping'] = 'no';"; @@ -42,7 +49,7 @@ } //combine all data into one variable - $data = "$dateFormat\r$timeFormat\r$pmsIp\r$pmsHttpPort\r$pmsHttpsPort\r$https\r$plexWatchDb\r$myPlexUser\r$myPlexPass\r$globalHistoryGrping\r$userHistoryGrping\r$chartsGrping"; + $data = "$dateFormat\r$timeFormat\r$pmsIp\r$pmsHttpPort\r$pmsHttpsPort\r$https\r$plexWatchDb\r$plexWatchDbMin\r$dbHeaderInfo\r$myPlexUser\r$myPlexPass\r$globalHistoryGrping\r$userHistoryGrping\r$chartsGrping"; $file = "../config/config.php"; $func_file = dirname(dirname(__FILE__)) . '/includes/functions.php'; @@ -62,7 +69,7 @@ $myPlexToken = "\$plexWatch['myPlexAuthToken'] = '".$myPlexAuthToken."';"; //include authentication code in saved data - $data = "$dateFormat\r$timeFormat\r$pmsIp\r$pmsHttpPort\r$pmsHttpsPort\r$https\r$plexWatchDb\r$myPlexUser\r$myPlexPass\r$myPlexToken\r$globalHistoryGrping\r$userHistoryGrping\r$chartsGrping"; + $data = "$dateFormat\r$timeFormat\r$pmsIp\r$pmsHttpPort\r$pmsHttpsPort\r$https\r$plexWatchDb\r$plexWatchDbMin\r$dbHeaderInfo\r$myPlexUser\r$myPlexPass\r$myPlexToken\r$globalHistoryGrping\r$userHistoryGrping\r$chartsGrping"; //rewrite data to config.php $fp = fopen($file, "w+") or die("Cannot open file $file."); diff --git a/index.php b/index.php old mode 100644 new mode 100755 index 6ff2cfb..05b5112 --- a/index.php +++ b/index.php @@ -34,21 +34,9 @@ -
    - -
    + + +
    diff --git a/info.php b/info.php old mode 100644 new mode 100755 index 37705af..49e9205 --- a/info.php +++ b/info.php @@ -31,25 +31,7 @@ -
    - - -
    +
    diff --git a/settings.php b/settings.php old mode 100644 new mode 100755 index 514f48a..55e0fd5 --- a/settings.php +++ b/settings.php @@ -34,25 +34,7 @@ - -
    - -
    +
    @@ -250,6 +232,12 @@ }else if ($plexWatch['https'] == "yes" ) { $https = "checked='yes'"; } + + if ($plexWatch['dbHeaderInfo'] == "no" ) { + $dbHeaderInfo = ''; + }else if ($plexWatch['dbHeaderInfo'] == "yes" ) { + $dbHeaderInfo = "checked='yes'"; + } ?> @@ -272,6 +260,27 @@
    + + +
    + +
    + +

    How often (in minutes) is your database updated? This will be used to calculate the status of your database.

    +
    +
    + + +
    + +
    + +
    +
    +
    @@ -558,6 +567,26 @@
    + + +
    + +
    + +

    How often (in minutes) is your database updated? This will be used to calculate the status of your database.

    +
    +
    + +
    + +
    + +
    +
    +
    diff --git a/stats.php b/stats.php old mode 100644 new mode 100755 index fb1e794..2f036db --- a/stats.php +++ b/stats.php @@ -34,24 +34,7 @@ -
    - - -
    +
    diff --git a/user.php b/user.php old mode 100644 new mode 100755 index e868147..10116ca --- a/user.php +++ b/user.php @@ -49,22 +49,8 @@ -
    - -
    - - - -
    - -
    +