Skip to content

Commit

Permalink
v1.5.2
Browse files Browse the repository at this point in the history
* Fix:  settings.php: form portion of settings page was inaccessible if
plexWatch database location value was set incorrectly
* Fix:  global: date columns were still not sorting properly in all data
tables if a date format other than m/d/y was used
  • Loading branch information
ecleese committed Feb 2, 2014
1 parent e6e36f0 commit 029985b
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 116 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
plexWatch/Web - v1.5.1
plexWatch/Web - v1.5.2
=======================

A web front-end for plexWatch.
Expand Down
6 changes: 5 additions & 1 deletion change.log
@@ -1,5 +1,9 @@
1.5.2 master
* Fix: settings.php: form portion of settings page was inaccessible if plexWatch database location value was set incorrectly
* Fix: global: date columns were still not sorting properly in all data tables if a date format other than m/d/y was used

1.5.1 master
*Fix: global: date columns were not sorting properly in all data tables
* Fix: global: date columns were not sorting properly in all data tables

1.5.0 master
* Change: version bump to master
Expand Down
24 changes: 17 additions & 7 deletions history.php
Expand Up @@ -109,14 +109,14 @@
if ($plexWatch['globalHistoryGrouping'] == "yes") {
$plexWatchDbTable = "grouped";
$numRows = $db->querySingle("SELECT COUNT(*) as count FROM $plexWatchDbTable ");
$results = $db->query("SELECT title, user, platform, time, stopped, ip_address, xml, paused_counter FROM processed WHERE stopped IS NULL UNION ALL SELECT title, user, platform, time, stopped, ip_address, xml, paused_counter FROM $plexWatchDbTable ORDER BY time DESC") or die ("Failed to access plexWatch database. Please check your settings.");
$results = $db->query("SELECT title, user, platform, time, stopped, ip_address, xml, paused_counter, strftime('%Y%m%d', datetime(time, 'unixepoch', 'localtime')) as date FROM processed WHERE stopped IS NULL UNION ALL SELECT title, user, platform, time, stopped, ip_address, xml, paused_counter, strftime('%Y%m%d', datetime(time, 'unixepoch', 'localtime')) as date FROM $plexWatchDbTable ORDER BY time DESC") or die ("Failed to access plexWatch database. Please check your settings.");


}else if ($plexWatch['globalHistoryGrouping'] == "no") {
$plexWatchDbTable = "processed";

$numRows = $db->querySingle("SELECT COUNT(*) as count FROM $plexWatchDbTable ");
$results = $db->query("SELECT title, user, platform, time, stopped, ip_address, xml, paused_counter FROM $plexWatchDbTable ORDER BY time DESC") or die ("Failed to access plexWatch database. Please check settings.");
$results = $db->query("SELECT title, user, platform, time, stopped, ip_address, xml, paused_counter, strftime('%Y%m%d', datetime(time, 'unixepoch', 'localtime')) as date FROM $plexWatchDbTable ORDER BY time DESC") or die ("Failed to access plexWatch database. Please check settings.");
}


Expand Down Expand Up @@ -153,9 +153,9 @@
$rowCount++;
echo "<tr>";
if (empty($row['stopped'])) {
echo "<td class='currentlyWatching' align='center'>Currently watching...</td>";
echo "<td data-order='".$row['date']."' class='currentlyWatching' align='center'>Currently watching...</td>";
}else{
echo "<td align='center'>".date($plexWatch['dateFormat'],$row['time'])."</td>";
echo "<td data-order='".$row['date']."' align='center'>".date($plexWatch['dateFormat'],$row['time'])."</td>";
}

echo "<td align='left'><a href='user.php?user=".$row['user']."'>".FriendlyName($row['user'],$row['platform'])."</td>";
Expand Down Expand Up @@ -410,9 +410,19 @@
"bStateSave": false,
"bSortClasses": false,
"sPaginationType": "bootstrap",
"aoColumnDefs": [
{ "aTargets": [ 1 ], "bSortable": true, "sType": "us_date", }
]
"aoColumns": [
{"sSortDataType": "dom-data-order", "sType": "numeric"},
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
]
} );
} );
</script>
Expand Down
15 changes: 13 additions & 2 deletions includes/functions.php
@@ -1,6 +1,7 @@
<?php
ini_set('display_errors', 0); // for debugging - we might want this set to 0 in production */


if(!isset($_SESSION)) { session_start(); }

/* either load or return the plexWatch config
Expand Down Expand Up @@ -48,12 +49,22 @@ function FriendlyName($user,$platform = NULL) {
/* db connector */
function dbconnect() {
global $plexWatch;
$db = new SQLite3($plexWatch['plexWatchDb']);

try {
$db = new SQLite3($plexWatch['plexWatchDb']);
}
catch (Exception $exception) {
// sqlite3 throws an exception when it is unable to connect
echo "<div class=\"alert alert-warning \">Failed to access plexWatch database. Please check settings.</div>";
die;
}

$db->busyTimeout(10*1000);
return $db;

}

/* dbtable -- processed of grouped */
/* dbtable -- processed or grouped */
function dbTable() {
global $plexWatch;
if ($plexWatch['globalHistoryGrouping'] == "yes") {
Expand Down
22 changes: 16 additions & 6 deletions info.php
Expand Up @@ -181,7 +181,7 @@

$title = $db->querySingle("SELECT title FROM $plexWatchDbTable WHERE session_id LIKE '%/metadata/".$id."\_%' ESCAPE '\' ");
$numRows = $db->querySingle("SELECT COUNT(*) as count FROM $plexWatchDbTable WHERE session_id LIKE '%/metadata/".$id."\_%' ESCAPE '\' ORDER BY time DESC");
$results = $db->query("SELECT * FROM $plexWatchDbTable WHERE session_id LIKE '%/metadata/".$id."\_%' ESCAPE '\' ORDER BY time DESC");
$results = $db->query("SELECT title, user, platform, time, stopped, ip_address, xml, paused_counter, strftime('%Y%m%d', datetime(time, 'unixepoch', 'localtime')) as date FROM $plexWatchDbTable WHERE session_id LIKE '%/metadata/".$id."\_%' ESCAPE '\' ORDER BY time DESC");

echo "<div class='dashboard-wellheader'>";
echo"<h3>Watching history for <strong>".$xml->Video['title']."</strong> (".$numRows." Views)</h3>";
Expand Down Expand Up @@ -214,7 +214,7 @@
while ($row = $results->fetchArray()) {
$rowCount++;
echo "<tr>";
echo "<td align='center'>".date($plexWatch['dateFormat'],$row['time'])."</td>";
echo "<td data-order='".$row['date']."' align='center'>".date($plexWatch['dateFormat'],$row['time'])."</td>";
echo "<td align='left'><a href='user.php?user=".$row['user']."'>".FriendlyName($row['user'],$row['platform'])."</td>";

$rowXml = simplexml_load_string($row['xml']);
Expand Down Expand Up @@ -812,7 +812,7 @@
while ($row = $results->fetchArray()) {
$rowCount++;
echo "<tr>";
echo "<td align='center'>".date($plexWatch['dateFormat'],$row['time'])."</td>";
echo "<td data-order='".$row['date']."' align='center'>".date($plexWatch['dateFormat'],$row['time'])."</td>";
echo "<td align='left'><a href='user.php?user=".$row['user']."'>".FriendlyName($row['user'],$row['platform'])."</td>";

$rowXml = simplexml_load_string($row['xml']);
Expand Down Expand Up @@ -1060,9 +1060,19 @@
"bStateSave": false,
"bSortClasses": false,
"sPaginationType": "bootstrap",
"aoColumnDefs": [
{ "aTargets": [ 1 ], "bSortable": true, "sType": "us_date", }
]
"aoColumns": [
{"sSortDataType": "dom-data-order", "sType": "numeric"},
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
]
} );
} );
</script>
Expand Down
89 changes: 6 additions & 83 deletions js/jquery.dataTables.plugin.date_sorting.js
@@ -1,83 +1,6 @@
function trim(str) {
str = str.replace(/^\s+/, '');
for (var i = str.length - 1; i >= 0; i--) {
if (/\S/.test(str.charAt(i))) {
str = str.substring(0, i + 1);
break;
}
}
return str;
}

jQuery.fn.dataTableExt.oSort['us_date-asc'] = function(a, b) {
if (trim(a) != '' && a!="&nbsp;") {
if (a.indexOf(' ') == -1) {
var frDatea = trim(a).split(' ');
var frDatea2 = frDatea[0].split('/');
var x = (frDatea2[2] + frDatea2[1] + frDatea2[0]) * 1;
}
else {
var frDatea = trim(a).split(' ');
var frTimea = frDatea[1].split(':');
var frDatea2 = frDatea[0].split('/');
var x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1;
}
} else {
var x = 10000000; // = l'an 1000 ...
}

if (trim(b) != '' && b!="&nbsp;") {
if (b.indexOf(' ') == -1) {
var frDateb = trim(b).split(' ');
frDateb = frDateb[0].split('/');
var y = (frDateb[2] + frDateb[1] + frDateb[0]) * 1;
}
else {
var frDateb = trim(b).split(' ');
var frTimeb = frDateb[1].split(':');
frDateb = frDateb[0].split('/');
var y = (frDateb[2] + frDateb[1] + frDateb[0] + frTimeb[0] + frTimeb[1] + frTimeb[2]) * 1;
}
} else {
var y = 10000000;
}
var z = ((x < y) ? -1 : ((x > y) ? 1 : 0));
return z;
};

jQuery.fn.dataTableExt.oSort['us_date-desc'] = function(a, b) {
if (trim(a) != '' && a!="&nbsp;") {
if (a.indexOf(' ') == -1) {
var frDatea = trim(a).split(' ');
var frDatea2 = frDatea[0].split('/');
var x = (frDatea2[2] + frDatea2[1] + frDatea2[0]) * 1;
}
else {
var frDatea = trim(a).split(' ');
var frTimea = frDatea[1].split(':');
var frDatea2 = frDatea[0].split('/');
var x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1;
}
} else {
var x = 10000000;
}

if (trim(b) != '' && b!="&nbsp;") {
if (b.indexOf(' ') == -1) {
var frDateb = trim(b).split(' ');
frDateb = frDateb[0].split('/');
var y = (frDateb[2] + frDateb[1] + frDateb[0]) * 1;
}
else {
var frDateb = trim(b).split(' ');
var frTimeb = frDateb[1].split(':');
frDateb = frDateb[0].split('/');
var y = (frDateb[2] + frDateb[1] + frDateb[0] + frTimeb[0] + frTimeb[1] + frTimeb[2]) * 1;
}
} else {
var y = 10000000;
}

var z = ((x < y) ? 1 : ((x > y) ? -1 : 0));
return z;
};
$.fn.dataTableExt.afnSortData['dom-data-order'] = function ( oSettings, iColumn )
{
return $.map( oSettings.oApi._fnGetTrNodes(oSettings), function (tr, i) {
return $('td:eq('+iColumn+')', tr).attr('data-order');
} );
}
30 changes: 26 additions & 4 deletions settings.php
Expand Up @@ -111,14 +111,36 @@
<div class="settings-general-info">

<ul>
<li>plexWatch/Web Version: <strong>v1.5.1</strong></li>
<li>plexWatch/Web Version: <strong>v1.5.2</strong></li>

<?php
$db = new SQLite3($plexWatch['plexWatchDb']);
$plexWatchVersion = $db->querySingle("SELECT version FROM config ");
do {
try {
$db = new SQLite3($plexWatch['plexWatchDb']);
}
catch (Exception $exception) {
// sqlite3 throws an exception when it is unable to connect
echo "<li>plexWatch Version: <div class=\"alert alert-warning \">Failed to access plexWatch database. Please check settings.</div>";
break;
}

if (!$db) {
break;
}else{
$plexWatchVersion = $db->querySingle("SELECT version FROM config ");
?>
<li>plexWatch Version: <strong>v<?php echo $plexWatchVersion ?></strong></li>
<?php
}
} while (0);
?>







<li>plexWatch Version: <strong>v<?php echo $plexWatchVersion ?></strong></li>
</ul>
</div>
</div>
Expand Down
37 changes: 25 additions & 12 deletions user.php
Expand Up @@ -158,9 +158,9 @@
}

if ($plexWatch['userHistoryGrouping'] == "yes") {
$results = $db->query("SELECT title, user, platform, time, stopped, ip_address, xml, paused_counter FROM processed WHERE user = '$user' AND stopped IS NULL UNION ALL SELECT title, user, platform, time, stopped, ip_address, xml, paused_counter FROM ".$plexWatchDbTable." WHERE user = '$user' ORDER BY time DESC") or die ("Failed to access plexWatch database. Please check your settings.");
$results = $db->query("SELECT title, user, platform, time, stopped, ip_address, xml, paused_counter, strftime('%Y%m%d', datetime(time, 'unixepoch', 'localtime')) as date FROM processed WHERE user = '$user' AND stopped IS NULL UNION ALL SELECT title, user, platform, time, stopped, ip_address, xml, paused_counter, strftime('%Y%m%d', datetime(time, 'unixepoch', 'localtime')) as date FROM ".$plexWatchDbTable." WHERE user = '$user' ORDER BY time DESC") or die ("Failed to access plexWatch database. Please check your settings.");
}else if ($plexWatch['userHistoryGrouping'] == "no") {
$results = $db->query("SELECT title, user, platform, time, stopped, ip_address, xml, paused_counter FROM ".$plexWatchDbTable." WHERE user = '$user' ORDER BY time DESC") or die ("Failed to access plexWatch database. Please check your settings.");
$results = $db->query("SELECT title, user, platform, time, stopped, ip_address, xml, paused_counter, strftime('%Y%m%d', datetime(time, 'unixepoch', 'localtime')) as date FROM ".$plexWatchDbTable." WHERE user = '$user' ORDER BY time DESC") or die ("Failed to access plexWatch database. Please check your settings.");
}

echo "<div class='container-fluid'>";
Expand Down Expand Up @@ -583,7 +583,7 @@

echo "<div class='tab-pane' id='userAddresses'>";

$userIpAddressesQuery = $db->query("SELECT time,ip_address,platform,xml, COUNT(ip_address) as play_count FROM processed WHERE user = '$user' GROUP BY ip_address ORDER BY time DESC");
$userIpAddressesQuery = $db->query("SELECT time,ip_address,platform,xml, COUNT(ip_address) as play_count, strftime('%Y%m%d', datetime(time, 'unixepoch', 'localtime')) as date FROM processed WHERE user = '$user' GROUP BY ip_address ORDER BY time DESC");

echo "<div class='container-fluid'>";
echo "<div class='row-fluid'>";
Expand Down Expand Up @@ -627,7 +627,7 @@
$userIpAddressesData = simplexml_load_file($userIpAddressesUrl) or die ("<div class=\"alert alert-warning \">Cannot access http://www.geoplugin.net.</div>");

echo "<tr>";
echo "<td align='center'>".date($plexWatch['dateFormat'],$userIpAddresses['time'])."</td>";
echo "<td data-order='".$row['date']."' align='center'>".date($plexWatch['dateFormat'],$userIpAddresses['time'])."</td>";
echo "<td align='center'>".$userIpAddresses['ip_address']."</td>";
echo "<td align='left'>".$userIpAddresses['play_count']."</td>";

Expand Down Expand Up @@ -712,9 +712,9 @@

echo "<tr>";
if (empty($row['stopped'])) {
echo "<td class='currentlyWatching' align='center'>Currently watching...</td>";
echo "<td data-order='".$row['date']."' class='currentlyWatching' align='center'>Currently watching...</td>";
}else{
echo "<td align='center'>".date($plexWatch['dateFormat'],$row['time'])."</td>";
echo "<td data-order='".$row['date']."' align='center'>".date($plexWatch['dateFormat'],$row['time'])."</td>";
}

if ($platform == "Chromecast") {
Expand Down Expand Up @@ -953,9 +953,18 @@
"bStateSave": false,
"bSortClasses": false,
"sPaginationType": "bootstrap",
"aoColumnDefs": [
{ "aTargets": [ 1 ], "bSortable": true, "sType": "us_date", }
]
"aoColumns": [
{"sSortDataType": "dom-data-order", "sType": "numeric"},
null,
null,
null,
null,
null,
null,
null,
null,
null
]
} );
} );
</script>
Expand All @@ -972,9 +981,13 @@
"bStateSave": false,
"bSortClasses": false,
"sPaginationType": "bootstrap",
"aoColumnDefs": [
{ "aTargets": [ 1 ], "bSortable": true, "sType": "us_date", }
]
"aoColumns": [
{"sSortDataType": "dom-data-order", "sType": "numeric"},
null,
null,
null,
null
]
} );
} );
</script>
Expand Down

0 comments on commit 029985b

Please sign in to comment.